aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-12-15 23:04:29 +0100
committerGravatar GitHub <noreply@github.com> 2023-12-15 23:04:29 +0100
commit6bb45a87268157aab961a6a4a728d9a9bbe043b0 (patch)
treed1c36638d5ee61e2e663d214d724a71f07a89354 /app/Controllers
parenta3ed8269132303eebc03d3e6df822f1f101fa95b (diff)
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
Diffstat (limited to 'app/Controllers')
-rw-r--r--app/Controllers/categoryController.php79
-rw-r--r--app/Controllers/configureController.php1
-rw-r--r--app/Controllers/feedController.php13
-rw-r--r--app/Controllers/subscriptionController.php75
4 files changed, 72 insertions, 96 deletions
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);
}
/**
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index bca47319e..d7c087620 100644
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -142,6 +142,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {
'site' => Minz_Request::paramBoolean('mark_open_site'),
'focus' => Minz_Request::paramBoolean('mark_focus'),
];
+ FreshRSS_Context::$user_conf->_filtersAction('read', Minz_Request::paramTextToArray('filteractions_read'));
FreshRSS_Context::$user_conf->save();
invalidateHttpCache();
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index bba5870dd..aec39587e 100644
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -361,6 +361,19 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
}
} else {
$feeds = $feedDAO->listFeedsOrderUpdate(-1);
+
+ // Hydrate category for each feed to avoid that each feed has to make an SQL request
+ $categories = [];
+ $catDAO = FreshRSS_Factory::createCategoryDao();
+ foreach ($catDAO->listCategories(false, false) as $category) {
+ $categories[$category->id()] = $category;
+ }
+ foreach ($feeds as $feed) {
+ $category = $categories[$feed->categoryId()] ?? null;
+ if ($category !== null) {
+ $feed->_category($category);
+ }
+ }
}
// WebSub (PubSubHubbub) support
diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php
index 8d1fc0b68..21c5abb30 100644
--- a/app/Controllers/subscriptionController.php
+++ b/app/Controllers/subscriptionController.php
@@ -197,7 +197,7 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController {
]);
}
- $feed->_filtersAction('read', preg_split('/[\n\r]+/', Minz_Request::paramString('filteractions_read')) ?: []);
+ $feed->_filtersAction('read', Minz_Request::paramTextToArray('filteractions_read'));
$feed->_kind(Minz_Request::paramInt('feed_kind') ?: FreshRSS_Feed::KIND_RSS);
if ($feed->kind() === FreshRSS_Feed::KIND_HTML_XPATH || $feed->kind() === FreshRSS_Feed::KIND_XML_XPATH) {
@@ -279,79 +279,6 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController {
}
}
- public function categoryAction(): void {
- 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()) {
- 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'),
- ]);
- }
-
- $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 = [
- 'kind' => $category->kind(),
- 'name' => Minz_Request::paramString('name'),
- 'attributes' => $category->attributes(),
- ];
-
- 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);
- }
- }
- }
-
/**
* This action displays the bookmarklet page.
*/