From 6bb45a87268157aab961a6a4a728d9a9bbe043b0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 15 Dec 2023 23:04:29 +0100 Subject: Add filter actions (auto mark read) at category and global levels (#5942) * Add filter actions (auto mark read) at category level fix https://github.com/FreshRSS/FreshRSS/issues/3497 * Add filter actions (auto mark read) at global level fix https://github.com/FreshRSS/FreshRSS/issues/2788 * Fix feed category ID * Minor comment --- app/Controllers/categoryController.php | 79 ++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 22 deletions(-) (limited to 'app/Controllers/categoryController.php') diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php index de6399e27..daee1666a 100644 --- a/app/Controllers/categoryController.php +++ b/app/Controllers/categoryController.php @@ -80,45 +80,80 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { /** * This action updates the given category. - * @todo Check whether this function is used at all - * @see FreshRSS_subscription_Controller::categoryAction() (consider merging) - * - * Request parameters are: - * - id - * - name */ public function updateAction(): void { - $catDAO = FreshRSS_Factory::createCategoryDao(); - $url_redirect = ['c' => 'subscription', 'a' => 'index']; + if (Minz_Request::paramBoolean('ajax')) { + $this->view->_layout(null); + } + + $categoryDAO = FreshRSS_Factory::createCategoryDao(); + + $id = Minz_Request::paramInt('id'); + $category = $categoryDAO->searchById($id); + if ($id === 0 || null === $category) { + Minz_Error::error(404); + return; + } + $this->view->category = $category; + + FreshRSS_View::prependTitle($category->name() . ' · ' . _t('sub.title') . ' · '); if (Minz_Request::isPost()) { - invalidateHttpCache(); + $category->_filtersAction('read', Minz_Request::paramTextToArray('filteractions_read')); - $id = Minz_Request::paramInt('id'); - $name = Minz_Request::paramString('name'); - if (strlen($name) <= 0) { - Minz_Request::bad(_t('feedback.sub.category.no_name'), $url_redirect); + if (Minz_Request::paramBoolean('use_default_purge_options')) { + $category->_attributes('archiving', null); + } else { + if (!Minz_Request::paramBoolean('enable_keep_max')) { + $keepMax = false; + } elseif (($keepMax = Minz_Request::paramInt('keep_max')) !== 0) { + $keepMax = FreshRSS_Feed::ARCHIVING_RETENTION_COUNT_LIMIT; + } + if (Minz_Request::paramBoolean('enable_keep_period')) { + $keepPeriod = FreshRSS_Feed::ARCHIVING_RETENTION_PERIOD; + if (is_numeric(Minz_Request::paramString('keep_period_count')) && preg_match('/^PT?1[YMWDH]$/', Minz_Request::paramString('keep_period_unit'))) { + $keepPeriod = str_replace('1', Minz_Request::paramString('keep_period_count'), Minz_Request::paramString('keep_period_unit')); + } + } else { + $keepPeriod = false; + } + $category->_attributes('archiving', [ + 'keep_period' => $keepPeriod, + 'keep_max' => $keepMax, + 'keep_min' => Minz_Request::paramInt('keep_min'), + 'keep_favourites' => Minz_Request::paramBoolean('keep_favourites'), + 'keep_labels' => Minz_Request::paramBoolean('keep_labels'), + 'keep_unreads' => Minz_Request::paramBoolean('keep_unreads'), + ]); } - $cat = $catDAO->searchById($id); - if ($cat === null) { - Minz_Request::bad(_t('feedback.sub.category.not_exist'), $url_redirect); + $position = Minz_Request::paramInt('position') ?: null; + $category->_attributes('position', $position); + + $opml_url = checkUrl(Minz_Request::paramString('opml_url')); + if ($opml_url != '') { + $category->_kind(FreshRSS_Category::KIND_DYNAMIC_OPML); + $category->_attributes('opml_url', $opml_url); + } else { + $category->_kind(FreshRSS_Category::KIND_NORMAL); + $category->_attributes('opml_url', null); } $values = [ - 'name' => $cat->name(), - 'kind' => $cat->kind(), - 'attributes' => $cat->attributes(), + 'kind' => $category->kind(), + 'name' => Minz_Request::paramString('name'), + 'attributes' => $category->attributes(), ]; - if ($catDAO->updateCategory($id, $values)) { + invalidateHttpCache(); + + $url_redirect = ['c' => 'subscription', 'params' => ['id' => $id, 'type' => 'category']]; + if (false !== $categoryDAO->updateCategory($id, $values)) { Minz_Request::good(_t('feedback.sub.category.updated'), $url_redirect); } else { Minz_Request::bad(_t('feedback.sub.category.error'), $url_redirect); } } - - Minz_Request::forward($url_redirect, true); } /** -- cgit v1.2.3