diff --git a/Modules/Frontend/Http/Controllers/PageController.php b/Modules/Frontend/Http/Controllers/PageController.php
index 131f870..de5ed72 100644
--- a/Modules/Frontend/Http/Controllers/PageController.php
+++ b/Modules/Frontend/Http/Controllers/PageController.php
@@ -3,6 +3,7 @@
namespace Modules\Frontend\Http\Controllers;
use App\Models\Page;
+use App\Models\Rss\Country;
use App\Repositories\Interfaces\ArticleRepositoryInterface;
use App\Repositories\Interfaces\ChannelRepositoryInterface;
use App\Repositories\Interfaces\CountryRepositoryInterface;
@@ -63,6 +64,16 @@ public function allRss(Page $page)
return view('frontend::rss.index', compact('page'), ['orderName' => 'all-rss']);
}
+ public function redDeMedios(Page $page)
+ {
+ $international = $this->channelRepository->getInternational();
+ $chile = $this->channelRepository->getByCountry(
+ Country::whereSlug('chile')->orWhereIn('id', [11])->first()
+ );
+
+ return view("frontend::pages.red-de-medios", compact('page', 'international', 'chile'));
+ }
+
public function show(Page $pageModel)
{
$page = $pageModel;
@@ -79,7 +90,7 @@ public function show(Page $pageModel)
} elseif ($page->id === 3 || $page->slug === 'contacto') {
$view = 'contacto';
} elseif ($page->id === 4 || $page->slug === 'red-de-medios') {
- $view = 'red-de-medios';
+ return $this->redDeMedios($page);
} elseif ($page->slug == 'all-rss') {
return $this->allRss($page);
}
diff --git a/Modules/Frontend/Providers/FrontendServiceProvider.php b/Modules/Frontend/Providers/FrontendServiceProvider.php
index d086402..d9925d8 100644
--- a/Modules/Frontend/Providers/FrontendServiceProvider.php
+++ b/Modules/Frontend/Providers/FrontendServiceProvider.php
@@ -85,6 +85,12 @@ protected function viewComposer()
'sidebarChannel' => $channelRepository->getSidebar()
]);
});
+ View::composer('frontend::pages.red-de-medios', function ($view) {
+ $channelRepository = app(ChannelRepositoryInterface::class);
+ share([
+ 'sidebarChannels' => $channelRepository->getSidebar(2)
+ ]);
+ });
}
protected function getCountries()
diff --git a/Modules/Frontend/Resources/js/app.js b/Modules/Frontend/Resources/js/app.js
index eed0eb8..c231840 100644
--- a/Modules/Frontend/Resources/js/app.js
+++ b/Modules/Frontend/Resources/js/app.js
@@ -66,6 +66,7 @@ const app = new Vue({
},
],
sidebarChannel: this.shared('sidebarChannel') || null,
+ sidebarChannels: this.shared('sidebarChannels') || [],
}
},
components,
diff --git a/Modules/Frontend/Resources/views/pages/red-de-medios.blade.php b/Modules/Frontend/Resources/views/pages/red-de-medios.blade.php
index dc6951d..67f6c27 100644
--- a/Modules/Frontend/Resources/views/pages/red-de-medios.blade.php
+++ b/Modules/Frontend/Resources/views/pages/red-de-medios.blade.php
@@ -1,4 +1,8 @@
-@php /* @var $page \App\Models\Page */ @endphp
+@php
+ /* @var $page \App\Models\Page
+ * @var $channel \App\Models\Rss\Channel
+ */
+@endphp
@extends('frontend::layouts.master')
@section('content')
@@ -21,27 +25,12 @@
RED DE MEDIOS-INTERNACIONAL
-
-
-
-
-
-
-
+ @foreach($international as $channel)
+
+ @endforeach
@@ -52,27 +41,12 @@
-
-
-
-
-
-
-
+ @foreach($chile as $channel)
+
+ @endforeach
@@ -81,21 +55,11 @@
-
+
-
+ @include('frontend::articles.includes.banner-bottom')
-
+
diff --git a/Modules/Parser/Services/ParserService.php b/Modules/Parser/Services/ParserService.php
index 6377fc7..358c9c5 100644
--- a/Modules/Parser/Services/ParserService.php
+++ b/Modules/Parser/Services/ParserService.php
@@ -52,62 +52,60 @@ public function __construct(Command $command)
public function start(): void
{
$this->categories = Category::all('id', 'keywords');
- while ($this->run) {
- $channels = $this->getChannels();
- if (empty($channels)) {
- $this->error('No active channels');
- return;
- }
+ $channels = $this->getChannels();
+ if (empty($channels)) {
+ $this->error('No active channels');
+ return;
+ }
- foreach ($channels as $channel) {
- $timeStart = microtime(true);
+ foreach ($channels as $channel) {
+ $timeStart = microtime(true);
- $channel->refresh();
- if ($channel->status === Channel::WORKING) {
- if ($channel->last_run === null || $channel->last_run->diffInMinutes() < 2) continue;
- }
+ //$channel->refresh();
+ if ($channel->status === Channel::WORKING) {
+ if ($channel->last_run === null || $channel->last_run->diffInMinutes() < 2) continue;
+ }
- $this->info("Start working on channel #$channel->id $channel->slug");
- $this->updateLastRun($channel);
- $channel->update(['status' => Channel::WORKING]);
- /* @var $feed SimplePie */
- $feed = Feeds::make($channel->feed, null, true);
- if ($feed->error() === null) {
- $this->info('Feed has been fetched');
+ $this->info("Start working on channel #$channel->id $channel->slug");
+ $this->updateLastRun($channel);
+ $channel->update(['status' => Channel::WORKING]);
+ /* @var $feed SimplePie */
+ $feed = Feeds::make($channel->feed, null, true);
+ if ($feed->error() === null) {
+ $this->info('Feed has been fetched');
- $items = $this->filterNewItems($feed, $channel);
+ $items = $this->filterNewItems($feed, $channel);
- $count = 0;
+ $count = 0;
- DB::transaction(function () use ($items, $channel, &$count) {
- foreach ($items as $item) {
- $this->html = null;
+ DB::transaction(function () use ($items, $channel, &$count) {
+ foreach ($items as $item) {
+ $this->html = null;
- if ($post = $this->createItem($item, $channel)) {
- $count++;
- $this->attachImage($item, $post, $channel->use_og);
- $this->attachToCategories($item, $post);
- }
+ if ($post = $this->createItem($item, $channel)) {
+ $count++;
+ $this->attachImage($item, $post, $channel->use_og);
+ $this->attachToCategories($item, $post);
}
- });
+ }
+ });
- $this->info("Created $count items");
+ $this->info("Created $count items");
- if (in_array($channel->id, setting('international_medias'))) {
- Cacher::channelsInternational();
- }
- if ($country = $channel->country) {
- if ($count > 0) Cacher::countyByCode($country->code);
- }
- } else {
- $this->error('SimplePie returned error: ' . $feed->error());
+ if (in_array($channel->id, setting('international_medias'))) {
+ Cacher::channelsInternational();
}
-
- $timeEnd = microtime(true);
- $executionTime = round($timeEnd - $timeStart, 1);
- $this->info("End working on channel #$channel->id $channel->slug. Total Execution Time: {$executionTime}s");
- $channel->update(['status' => Channel::IDLE]);
+ if ($country = $channel->country) {
+ if ($count > 0) Cacher::countyByCode($country->code);
+ }
+ } else {
+ $this->error('SimplePie returned error: ' . $feed->error());
}
+
+ $timeEnd = microtime(true);
+ $executionTime = round($timeEnd - $timeStart, 1);
+ $this->info("End working on channel #$channel->id $channel->slug. Total Execution Time: {$executionTime}s");
+ $channel->update(['status' => Channel::IDLE]);
}
}
@@ -138,7 +136,13 @@ protected function createItem(SimplePie_Item $item, Channel $channel): ?Post
$date = Carbon::create($item->get_date());
if ($channel->use_og | $channel->use_fulltext) {
- $this->html = Http::get($item->get_link());
+ try {
+ $this->html = Http::get($item->get_link());
+ } catch (Exception $e) {
+ $this->error("Error while trying to get post origin:\n"
+ . $e->getFile() . ' line: ' . $e->getLine() . "\n"
+ . $e->getMessage());
+ }
if ($channel->use_fulltext) {
try {
$content = $this->parseFullContent($item) ?? $content;
diff --git a/app/Repositories/ChannelRepository.php b/app/Repositories/ChannelRepository.php
index 1b1b2c2..a3bb836 100644
--- a/app/Repositories/ChannelRepository.php
+++ b/app/Repositories/ChannelRepository.php
@@ -47,10 +47,11 @@ public function getByCountry(Country $country): Collection
);
}
- public function getSidebar(): Channel
+ /* @return Channel[] */
+ public function getSidebar(int $number = 1): iterable
{
$international = $this->getInternational();
- return $international->random();
+ return $international->random($number);
}
public function transformChannels(Collection $channels)
diff --git a/app/Repositories/Interfaces/ChannelRepositoryInterface.php b/app/Repositories/Interfaces/ChannelRepositoryInterface.php
index 0cff68e..6696acd 100644
--- a/app/Repositories/Interfaces/ChannelRepositoryInterface.php
+++ b/app/Repositories/Interfaces/ChannelRepositoryInterface.php
@@ -17,5 +17,6 @@ public function getInternational(): Collection;
public function getByCountry(Country $country);
- public function getSidebar(): Channel;
+ /* @return Channel[] */
+ public function getSidebar(int $number = 1): iterable;
}