From 8c2113f9e6eb86b630a4e861513229d7abf219b8 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Mon, 1 Jan 2018 20:34:06 +0100 Subject: Add mute strategy configuration (#1750) --- app/Controllers/feedController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index fff20f798..2793577d5 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -24,6 +24,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { Minz_Error::error(403); } } + $this->updateTTL(); } /** @@ -282,11 +283,11 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $mtime = 0; $ttl = $feed->ttl(); - if ($ttl == -1) { + if ($ttl < FreshRSS_Feed::TTL_DEFAULT) { continue; //Feed refresh is disabled } if ((!$simplePiePush) && (!$feed_id) && - ($feed->lastUpdate() + 10 >= time() - ($ttl == -2 ? FreshRSS_Context::$user_conf->ttl_default : $ttl))) { + ($feed->lastUpdate() + 10 >= time() - ($ttl == FreshRSS_Feed::TTL_DEFAULT ? FreshRSS_Context::$user_conf->ttl_default : $ttl))) { //Too early to refresh from source, but check whether the feed was updated by another user $mtime = $feed->cacheModifiedTime(); if ($feed->lastUpdate() + 10 >= $mtime) { @@ -639,4 +640,14 @@ class FreshRSS_feed_Controller extends Minz_ActionController { Minz_Request::bad(_t('feedback.sub.feed.error'), $redirect_url); } } + + /** + * This method update TTL values for feeds if needed. + * It changes the old default value (-2) to the new default value (0). + * It changes the old disabled value (-1) to the default disabled value. + */ + private function updateTTL() { + $feedDAO = FreshRSS_Factory::createFeedDao(); + $feedDAO->updateTTL(); + } } -- cgit v1.2.3 From 7642d334f827d1c077bb1444dfc4e79acf022891 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Tue, 2 Jan 2018 23:53:35 +0100 Subject: Replace "keep history" magic value by a constant (#1759) I think the use of a magic value repeated many times in the code is prone to have some errors made by people not knowing its meaning. Using a constant is a bit more safe. Judging by some comments in the code, I am not the only one. --- app/Controllers/entryController.php | 4 +--- app/Controllers/feedController.php | 6 ++---- app/Controllers/subscriptionController.php | 2 +- app/Models/ConfigurationSetter.php | 4 ++-- app/Models/Feed.php | 7 +++++-- app/Models/FeedDAO.php | 5 +++-- app/views/configure/archiving.phtml | 4 ++-- app/views/helpers/feed/update.phtml | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index bd8b65b2b..9c6b248a9 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -177,9 +177,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { foreach ($feeds as $feed) { $feed_history = $feed->keepHistory(); - if ($feed_history == -2) { - // TODO: -2 must be a constant! - // -2 means we take the default value from configuration + if (FreshRSS_Feed::KEEP_HISTORY_DEFAULT === $feed_history) { $feed_history = FreshRSS_Context::$user_conf->keep_history_default; } diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 2793577d5..884172112 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -317,10 +317,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feed_history = $feed->keepHistory(); if ($isNewFeed) { - $feed_history = -1; //∞ - } elseif ($feed_history == -2) { - // TODO: -2 must be a constant! - // -2 means we take the default value from configuration + $feed_history = FreshRSS_Feed::KEEP_HISTORY_INFINITE; + } elseif (FreshRSS_Feed::KEEP_HISTORY_DEFAULT === $feed_history) { $feed_history = FreshRSS_Context::$user_conf->keep_history_default; } $needFeedCacheRefresh = false; diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php index b3f3df46e..37efd3b57 100644 --- a/app/Controllers/subscriptionController.php +++ b/app/Controllers/subscriptionController.php @@ -104,7 +104,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController { 'pathEntries' => Minz_Request::param('path_entries', ''), 'priority' => intval(Minz_Request::param('priority', FreshRSS_Feed::PRIORITY_MAIN_STREAM)), 'httpAuth' => $httpAuth, - 'keep_history' => intval(Minz_Request::param('keep_history', -2)), + 'keep_history' => intval(Minz_Request::param('keep_history', FreshRSS_Feed::KEEP_HISTORY_DEFAULT)), 'ttl' => $ttl * ($mute ? -1 : 1), ); diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php index ca4709903..645ef644e 100644 --- a/app/Models/ConfigurationSetter.php +++ b/app/Models/ConfigurationSetter.php @@ -81,7 +81,7 @@ class FreshRSS_ConfigurationSetter { private function _keep_history_default(&$data, $value) { $value = intval($value); - $data['keep_history_default'] = $value >= -1 ? $value : 0; + $data['keep_history_default'] = $value >= FreshRSS_Feed::KEEP_HISTORY_INFINITE ? $value : 0; } // It works for system config too! @@ -154,7 +154,7 @@ class FreshRSS_ConfigurationSetter { private function _ttl_default(&$data, $value) { $value = intval($value); - $data['ttl_default'] = $value >= -1 ? $value : 3600; + $data['ttl_default'] = $value > FreshRSS_Feed::TTL_DEFAULT ? $value : 3600; } private function _view_mode(&$data, $value) { diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 216a26d44..13ab13df9 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -7,6 +7,9 @@ class FreshRSS_Feed extends Minz_Model { const TTL_DEFAULT = 0; + const KEEP_HISTORY_DEFAULT = -2; + const KEEP_HISTORY_INFINITE = -1; + private $id = 0; private $url; private $category = 1; @@ -21,7 +24,7 @@ class FreshRSS_Feed extends Minz_Model { private $pathEntries = ''; private $httpAuth = ''; private $error = false; - private $keep_history = -2; + private $keep_history = self::KEEP_HISTORY_DEFAULT; private $ttl = self::TTL_DEFAULT; private $mute = false; private $hash = null; @@ -222,7 +225,7 @@ class FreshRSS_Feed extends Minz_Model { public function _keepHistory($value) { $value = intval($value); $value = min($value, 1000000); - $value = max($value, -2); + $value = max($value, self::KEEP_HISTORY_DEFAULT); $this->keep_history = $value; } public function _ttl($value) { diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index deda02c63..011b3d112 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -18,7 +18,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { ttl ) VALUES - (?, ?, ?, ?, ?, ?, 10, ?, 0, -2, ?)'; + (?, ?, ?, ?, ?, ?, 10, ?, 0, ?, ?)'; $stm = $this->bd->prepare($sql); $valuesTmp['url'] = safe_ascii($valuesTmp['url']); @@ -32,6 +32,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { substr($valuesTmp['description'], 0, 1023), $valuesTmp['lastUpdate'], base64_encode($valuesTmp['httpAuth']), + FreshRSS_Feed::KEEP_HISTORY_DEFAULT, FreshRSS_Feed::TTL_DEFAULT, ); @@ -406,7 +407,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { $myFeed->_pathEntries(isset($dao['pathEntries']) ? $dao['pathEntries'] : ''); $myFeed->_httpAuth(isset($dao['httpAuth']) ? base64_decode($dao['httpAuth']) : ''); $myFeed->_error(isset($dao['error']) ? $dao['error'] : 0); - $myFeed->_keepHistory(isset($dao['keep_history']) ? $dao['keep_history'] : -2); + $myFeed->_keepHistory(isset($dao['keep_history']) ? $dao['keep_history'] : FreshRSS_Feed::KEEP_HISTORY_DEFAULT); $myFeed->_ttl(isset($dao['ttl']) ? $dao['ttl'] : FreshRSS_Feed::TTL_DEFAULT); $myFeed->_nbNotRead(isset($dao['cache_nbUnreads']) ? $dao['cache_nbUnreads'] : 0); $myFeed->_nbEntries(isset($dao['cache_nbEntries']) ? $dao['cache_nbEntries'] : 0); diff --git a/app/views/configure/archiving.phtml b/app/views/configure/archiving.phtml index 2254f5dba..09be55fd9 100644 --- a/app/views/configure/archiving.phtml +++ b/app/views/configure/archiving.phtml @@ -19,7 +19,7 @@
() @@ -34,7 +34,7 @@ 3600 => '1h', 5400 => '1.5h', 7200 => '2h', 10800 => '3h', 14400 => '4h', 18800 => '5h', 21600 => '6h', 25200 => '7h', 28800 => '8h', 36000 => '10h', 43200 => '12h', 64800 => '18h', 86400 => '1d', 129600 => '1.5d', 172800 => '2d', 259200 => '3d', 345600 => '4d', 432000 => '5d', 518400 => '6d', - 604800 => '1wk', -1 => '∞') as $v => $t) { + 604800 => '1wk') as $v => $t) { echo ''; if (FreshRSS_Context::$user_conf->ttl_default == $v) { $found = true; diff --git a/app/views/helpers/feed/update.phtml b/app/views/helpers/feed/update.phtml index 595309f49..d379c5df8 100644 --- a/app/views/helpers/feed/update.phtml +++ b/app/views/helpers/feed/update.phtml @@ -101,7 +101,7 @@
-- cgit v1.2.3 From 5faa7aaf66aa2e762922b293cb9b7293a5003a7d Mon Sep 17 00:00:00 2001 From: Django Janny Date: Fri, 2 Feb 2018 13:59:48 +0100 Subject: Trim spaces from user given url --- app/Controllers/feedController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 884172112..985b943d2 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -39,12 +39,14 @@ class FreshRSS_feed_Controller extends Minz_ActionController { * @throws FreshRSS_Feed_Exception * @throws Minz_FileNotExistException */ - public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') { + public static function addFeed($param_url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') { FreshRSS_UserDAO::touch(); @set_time_limit(300); $catDAO = new FreshRSS_CategoryDAO(); + $url = trim($param_url); + $cat = null; if ($new_cat_name != '') { $new_cat_id = $catDAO->addCategory(array('name' => $new_cat_name)); -- cgit v1.2.3 From 80168545eaa9e0183e72931ff7e50bfff36d7c33 Mon Sep 17 00:00:00 2001 From: Django Janny Date: Mon, 5 Feb 2018 20:48:16 +0100 Subject: param name --- app/Controllers/feedController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 985b943d2..7f66b10db 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -39,13 +39,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController { * @throws FreshRSS_Feed_Exception * @throws Minz_FileNotExistException */ - public static function addFeed($param_url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') { + public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') { FreshRSS_UserDAO::touch(); @set_time_limit(300); $catDAO = new FreshRSS_CategoryDAO(); - $url = trim($param_url); + $url = trim($url); $cat = null; if ($new_cat_name != '') { -- cgit v1.2.3