From 509c8cae6381ec46af7c8303eb92fda6ce496a4a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 4 Jul 2022 09:53:26 +0200 Subject: Dynamic OPML (#4407) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Dynamic OPML draft #fix https://github.com/FreshRSS/FreshRSS/issues/4191 * Export dynamic OPML http://opml.org/spec2.opml#1629043127000 * Restart with simpler approach * Minor revert * Export dynamic OPML also for single feeds * Special category type for importing dynamic OPML * Parameter for excludeMutedFeeds * Details * More draft * i18n * Fix update * Draft manual import working * Working manual refresh * Draft automatic update * Working Web refresh + fixes * Import/export dynamic OPML settings * Annoying numerous lines in SQL logs * Fix minor JavaScript error * Fix auto adding new columns * Add require * Add missing 🗲 * Missing space * Disable adding new feeds to dynamic categories * Link from import * i18n typo * Improve theme icon function * Fix pink-dark --- app/Controllers/categoryController.php | 86 ++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 9 deletions(-) (limited to 'app/Controllers/categoryController.php') diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php index 7226e44af..62901c78e 100644 --- a/app/Controllers/categoryController.php +++ b/app/Controllers/categoryController.php @@ -40,8 +40,8 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { if (Minz_Request::isPost()) { invalidateHttpCache(); - $cat_name = Minz_Request::param('new-category'); - if (!$cat_name) { + $cat_name = trim(Minz_Request::param('new-category', '')); + if ($cat_name == '') { Minz_Request::bad(_t('feedback.sub.category.no_name'), $url_redirect); } @@ -51,12 +51,16 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { Minz_Request::bad(_t('feedback.sub.category.name_exists'), $url_redirect); } - $values = array( - 'id' => $cat->id(), - 'name' => $cat->name(), - ); + $opml_url = checkUrl(Minz_Request::param('opml_url', '')); + if ($opml_url != '') { + $cat->_kind(FreshRSS_Category::KIND_DYNAMIC_OPML); + $cat->_attributes('opml_url', $opml_url); + } else { + $cat->_kind(FreshRSS_Category::KIND_NORMAL); + $cat->_attributes('opml_url', null); + } - if ($catDAO->addCategory($values)) { + if ($catDAO->addCategoryObject($cat)) { $url_redirect['a'] = 'index'; Minz_Request::good(_t('feedback.sub.category.created', $cat->name()), $url_redirect); } else { @@ -156,6 +160,7 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { * * Request parameter is: * - id (of a category) + * - muted (truthy to remove only muted feeds, or falsy otherwise) */ public function emptyAction() { $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -169,10 +174,15 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { Minz_Request::bad(_t('feedback.sub.category.no_id'), $url_redirect); } + $muted = Minz_Request::param('muted', null); + if ($muted !== null) { + $muted = boolval($muted); + } + // List feeds to remove then related user queries. - $feeds = $feedDAO->listByCategory($id); + $feeds = $feedDAO->listByCategory($id, $muted); - if ($feedDAO->deleteFeedByCategory($id)) { + if ($feedDAO->deleteFeedByCategory($id, $muted)) { // TODO: Delete old favicons // Remove related queries @@ -190,4 +200,62 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { Minz_Request::forward($url_redirect, true); } + + /** + * Request parameter is: + * - id (of a category) + */ + public function refreshOpmlAction() { + $catDAO = FreshRSS_Factory::createCategoryDao(); + $url_redirect = array('c' => 'subscription', 'a' => 'index'); + + if (Minz_Request::isPost()) { + invalidateHttpCache(); + + $id = Minz_Request::param('id'); + if (!$id) { + Minz_Request::bad(_t('feedback.sub.category.no_id'), $url_redirect); + } + + $category = $catDAO->searchById($id); + if ($category == null) { + Minz_Request::bad(_t('feedback.sub.category.not_exist'), $url_redirect); + } + + invalidateHttpCache(); + + $ok = $category->refreshDynamicOpml(); + + if (Minz_Request::param('ajax')) { + Minz_Request::setGoodNotification(_t('feedback.sub.category.updated')); + $this->view->_layout(false); + } else { + if ($ok) { + 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); + } + } + } + + /** @return array */ + public static function refreshDynamicOpmls() { + $successes = 0; + $errors = 0; + $catDAO = FreshRSS_Factory::createCategoryDao(); + $categories = $catDAO->listCategoriesOrderUpdate(FreshRSS_Context::$user_conf->dynamic_opml_ttl_default ?? 86400); + foreach ($categories as $category) { + if ($category->refreshDynamicOpml()) { + $successes++; + } else { + $errors++; + } + } + return [ + 'successes' => $successes, + 'errors' => $errors, + ]; + } } -- cgit v1.2.3