diff --git a/application/controllers/FeedController.php b/application/controllers/FeedController.php index c854193..4bcc3a9 100644 --- a/application/controllers/FeedController.php +++ b/application/controllers/FeedController.php @@ -42,7 +42,7 @@ public function indexAction(): void $this->addTitle($this->translate('Feed'), $controlWrapper); - [$url, $type, $name] = $this->getFeedInfo(); + [$url, $type, $name, $isActive] = $this->getFeedInfo(); if ($url === null) { $this->displayError($this->translate('No such feed configured')); @@ -97,16 +97,16 @@ protected function getFeedInfo(): array $feed = $storage->getFeedByName($name); if ($feed === null) { - return [null, null, null]; + return [null, null, null, null]; } - return [$feed->url, $feed->type, 'feed-' . $feed->name]; + return [$feed->url, $feed->type, 'feed-' . $feed->name, $feed->isActive]; } $url = $this->params->shift('url'); if ($url === null or $url === '') { - return [null, null, null]; + return [null, null, null, null]; } $this->assertPermission('feeds/view/arbitrary'); @@ -114,7 +114,7 @@ protected function getFeedInfo(): array $type = $this->params->shift('type') ?? 'auto'; $name = 'url-' . sha1($url . ':' . $type); - return [$url, FeedType::fromDisplay($type), $name]; + return [$url, FeedType::fromDisplay($type), $name, true]; } public function createAction(): void @@ -175,6 +175,7 @@ public function editAction(): void 'name' => $feed->name, 'url' => $feed->url, 'description' => $feed->description, + 'is_active' => $feed->isActive, 'type' => $feed->type->display(), ]); diff --git a/application/controllers/FeedsController.php b/application/controllers/FeedsController.php index aa8bba7..370511c 100644 --- a/application/controllers/FeedsController.php +++ b/application/controllers/FeedsController.php @@ -90,6 +90,11 @@ public function indexAction(): void continue; } + // Skip inactive feeds + if (!$feed->isActive) { + continue; + } + try { $reader = new FeedReader($feed->url, $this->Config(), $feed->type); $data = $reader->fetch('feed-' . $feed->name); diff --git a/application/forms/FeedForm.php b/application/forms/FeedForm.php index a989e6a..3cb2b2f 100644 --- a/application/forms/FeedForm.php +++ b/application/forms/FeedForm.php @@ -86,6 +86,18 @@ protected function assemble(): void ], ]); + $this->addElement( + 'checkbox', + 'is_active', + [ + 'label' => $this->translate('Active'), + 'value' => true, + 'description' => $this->translate( + 'Enable or disable this feed. Disabled feeds will not be fetched in the feed view' + ) + ] + ); + $this->addElement('textarea', 'description', [ 'label' => $this->translate('Description'), 'description' => $this->translate( @@ -167,6 +179,7 @@ protected function onSuccess(): void } elseif ($this->getSubmitButton()->hasBeenPressed() ?? false) { $name = trim($this->getValue('name')); $url = trim($this->getValue('url')); + $isActive = $this->getElement('is_active')->isChecked(); $type = FeedType::fromDisplay($this->getValue('type') ?? 'auto'); $description = trim($this->getValue('description')); @@ -175,6 +188,7 @@ protected function onSuccess(): void $name, $url, $description, + $isActive, $type, ); @@ -202,6 +216,7 @@ protected function onSuccess(): void $this->feed->name = $name; $this->feed->url = $url; $this->feed->type = $type; + $this->feed->isActive = $isActive; $this->feed->description = $description; if ($isRename) { diff --git a/library/Feeds/Storage/FeedDefinition.php b/library/Feeds/Storage/FeedDefinition.php index 31086d8..d633057 100644 --- a/library/Feeds/Storage/FeedDefinition.php +++ b/library/Feeds/Storage/FeedDefinition.php @@ -13,6 +13,7 @@ public function __construct( public string $name, public string $url, public string $description = '', + public bool $isActive = true, public FeedType $type = FeedType::Auto, ) { } @@ -23,6 +24,7 @@ public function toArray(): array 'name' => trim($this->name), 'url' => trim($this->url), 'description' => trim($this->description), + 'is_active' => $this->isActive, 'type' => $this->type->display(), ]; } @@ -35,6 +37,7 @@ public static function fromArray(array $data): FeedDefinition trim($data['name']), trim($data['url']), trim($data['description']), + $data['is_active'], FeedType::fromDisplay(trim($data['type']) ?? 'auto'), ); } diff --git a/library/Feeds/Web/FeedsTable.php b/library/Feeds/Web/FeedsTable.php index 1d5173e..91f717e 100644 --- a/library/Feeds/Web/FeedsTable.php +++ b/library/Feeds/Web/FeedsTable.php @@ -36,6 +36,7 @@ protected function assemble(): void $this->getHeader()->addHtml(self::row([ $this->translate('Name'), $this->translate('Type'), + $this->translate('Active'), '', // For QuickActions ], null, 'th')); @@ -67,10 +68,12 @@ protected function assemble(): void $r = Table::tr(); $rname = Table::td($name); $rtype = Table::td(Text::create($feed->type->display()), ['class' => 'text-dim']); + $ractive = Table::td($feed->isActive ? $this->translate('yes') : $this->translate('no')); $ractions = Table::td($quickActions, ['class' => 'action-col']); $r->addHtml($rname); $r->addHtml($rtype); + $r->addHtml($ractive); $r->addHtml($ractions); $tbody->addHtml($r);