diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index a263db99c..76df3580b 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -121,6 +121,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController { FreshRSS_Context::$user_conf->sort_order = Minz_Request::param('sort_order', 'DESC'); FreshRSS_Context::$user_conf->mark_when = array( 'article' => Minz_Request::param('mark_open_article', false), + 'gone' => Minz_Request::param('read_upon_gone', false), 'max_n_unread' => Minz_Request::paramBoolean('enable_keep_max_n_unread') ? Minz_Request::param('keep_max_n_unread', false) : false, 'reception' => Minz_Request::param('mark_upon_reception', false), 'same_title_in_feed' => Minz_Request::paramBoolean('enable_read_when_same_title_in_feed') ? diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index dd87650bc..fe5641642 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -503,10 +503,11 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { } $feedDAO->updateLastUpdate($feed->id(), false, $mtime); + $needFeedCacheRefresh |= ($feed->keepMaxUnread() != false); + $needFeedCacheRefresh |= ($feed->markAsReadUponGone() != false); if ($needFeedCacheRefresh) { $feedDAO->updateCachedValues($feed->id()); } - $feed->keepMaxUnread(); if ($entryDAO->inTransaction()) { $entryDAO->commit(); } diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php index 1994a2164..8c7cf7e4a 100644 --- a/app/Controllers/subscriptionController.php +++ b/app/Controllers/subscriptionController.php @@ -126,6 +126,7 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController { $ttl = FreshRSS_Context::$user_conf->ttl_default; } + $feed->_attributes('read_upon_gone', Minz_Request::paramTernary('read_upon_gone')); $feed->_attributes('mark_updated_article_unread', Minz_Request::paramTernary('mark_updated_article_unread')); $feed->_attributes('read_upon_reception', Minz_Request::paramTernary('read_upon_reception')); $feed->_attributes('clear_cache', Minz_Request::paramTernary('clear_cache')); diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 1fc2eebf4..6f6b83af0 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -649,15 +649,37 @@ class FreshRSS_Feed extends Minz_Model { $this->nbPendingNotRead += $n; } + /** + * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after. + * @return int|false the number of lines affected, or false if not applicable + */ public function keepMaxUnread() { $keepMaxUnread = $this->attributes('keep_max_n_unread'); - if ($keepMaxUnread == false) { + if ($keepMaxUnread === null) { $keepMaxUnread = FreshRSS_Context::$user_conf->mark_when['max_n_unread']; } if ($keepMaxUnread > 0 && $this->nbNotRead(false) + $this->nbPendingNotRead > $keepMaxUnread) { $feedDAO = FreshRSS_Factory::createFeedDao(); - $feedDAO->keepMaxUnread($this->id(), max(0, $keepMaxUnread - $this->nbPendingNotRead)); + return $feedDAO->keepMaxUnread($this->id(), max(0, $keepMaxUnread - $this->nbPendingNotRead)); } + return false; + } + + /** + * Applies the *mark as read upon gone* policy, if enabled. + * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after. + * @return int|false the number of lines affected, or false if not applicable + */ + public function markAsReadUponGone() { + $readUponGone = $this->attributes('read_upon_gone'); + if ($readUponGone === null) { + $readUponGone = FreshRSS_Context::$user_conf->mark_when['gone']; + } + if ($readUponGone) { + $feedDAO = FreshRSS_Factory::createFeedDao(); + return $feedDAO->markAsReadUponGone($this->id()); + } + return false; } /** diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 86ba70d5c..ec507b324 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -447,7 +447,8 @@ SQL; } /** - * @return int|false + * Remember to call updateCachedValues() after calling this function + * @return int|false number of lines affected or false in case of error */ public function keepMaxUnread(int $id, int $n) { //Double SELECT for MySQL workaround ERROR 1093 (HY000) @@ -461,32 +462,41 @@ WHERE id_feed=:id_feed1 AND is_read=0 AND id <= (SELECT e3.id FROM ( OFFSET :limit) e3) SQL; - $stm = $this->pdo->prepare($sql); - $stm->bindParam(':id_feed1', $id, PDO::PARAM_INT); - $stm->bindParam(':id_feed2', $id, PDO::PARAM_INT); - $stm->bindParam(':limit', $n, PDO::PARAM_INT); - - if (!$stm || !$stm->execute()) { + if (($stm = $this->pdo->prepare($sql)) && + $stm->bindParam(':id_feed1', $id, PDO::PARAM_INT) && + $stm->bindParam(':id_feed2', $id, PDO::PARAM_INT) && + $stm->bindParam(':limit', $n, PDO::PARAM_INT) && + $stm->execute()) { + return $stm->rowCount(); + } else { $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo(); Minz_Log::error('SQL error keepMaxUnread: ' . json_encode($info)); return false; } - $affected = $stm->rowCount(); + } - if ($affected > 0) { - $sql = 'UPDATE `_feed` ' - . 'SET `cache_nbUnreads`=`cache_nbUnreads`-' . $affected - . ' WHERE id=:id'; - $stm = $this->pdo->prepare($sql); - $stm->bindParam(':id', $id, PDO::PARAM_INT); - if (!($stm && $stm->execute())) { - $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo(); - Minz_Log::error('SQL error keepMaxUnread cache: ' . json_encode($info)); - return false; - } + /** + * Remember to call updateCachedValues() after calling this function + * @return int|false number of lines affected or false in case of error + */ + public function markAsReadUponGone(int $id) { + //Double SELECT for MySQL workaround ERROR 1093 (HY000) + $sql = <<<'SQL' +UPDATE `_entry` SET is_read=1 +WHERE id_feed=:id_feed1 AND is_read=0 AND `lastSeen` < (SELECT e3.maxlastseen FROM ( + SELECT MAX(e2.`lastSeen`) AS maxlastseen FROM `_entry` e2 WHERE e2.id_feed = :id_feed2) e3) +SQL; + + if (($stm = $this->pdo->prepare($sql)) && + $stm->bindParam(':id_feed1', $id, PDO::PARAM_INT) && + $stm->bindParam(':id_feed2', $id, PDO::PARAM_INT) && + $stm->execute()) { + return $stm->rowCount(); + } else { + $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo(); + Minz_Log::error('SQL error markAsReadUponGone: ' . json_encode($info)); + return false; } - - return $affected; } /** diff --git a/app/i18n/cz/conf.php b/app/i18n/cz/conf.php index c20ab19aa..a381a834c 100644 --- a/app/i18n/cz/conf.php +++ b/app/i18n/cz/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'když je článek zobrazen', 'keep_max_n_unread' => 'Maximální počet článků, které ponechat jako nepřečtené', 'scroll' => 'během posouvání', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'po obdržení článku', 'when' => 'Označit článek jako přečtený…', 'when_same_title' => 'když shodný název již existuje v top n nejnovějších článcích', diff --git a/app/i18n/de/conf.php b/app/i18n/de/conf.php index 1f90cd19f..bf7662feb 100644 --- a/app/i18n/de/conf.php +++ b/app/i18n/de/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'wenn der Artikel angesehen wird', 'keep_max_n_unread' => 'Max. Anzahl von ungelesenen Artikeln', 'scroll' => 'beim Scrollen bzw. Überspringen', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'beim Empfang des Artikels', 'when' => 'Artikel als gelesen markieren…', 'when_same_title' => 'falls der identische Titel bereit in den n neusten Artikel vorhanden ist.', diff --git a/app/i18n/en-us/conf.php b/app/i18n/en-us/conf.php index e84740ab6..3f2d21a16 100644 --- a/app/i18n/en-us/conf.php +++ b/app/i18n/en-us/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'when the article is viewed', // IGNORE 'keep_max_n_unread' => 'Max number of articles to keep unread', // IGNORE 'scroll' => 'while scrolling', // IGNORE + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'upon receiving the article', // IGNORE 'when' => 'Mark an article as read…', // IGNORE 'when_same_title' => 'if an identical title already exists in the top n newest articles', // IGNORE diff --git a/app/i18n/en/conf.php b/app/i18n/en/conf.php index 4dee522d9..4bd229c31 100644 --- a/app/i18n/en/conf.php +++ b/app/i18n/en/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'when the article is viewed', 'keep_max_n_unread' => 'Max number of articles to keep unread', 'scroll' => 'while scrolling', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'upon receiving the article', 'when' => 'Mark an article as read…', 'when_same_title' => 'if an identical title already exists in the top n newest articles', diff --git a/app/i18n/es/conf.php b/app/i18n/es/conf.php index fc4a41ca5..6e08913d3 100755 --- a/app/i18n/es/conf.php +++ b/app/i18n/es/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'cuando se muestre el artículo', 'keep_max_n_unread' => 'Número máximo de artículos para mantener sin leer', 'scroll' => 'durante el desplazamiento', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'al recibir el artículo', 'when' => 'Marcar el artículo como leído…', 'when_same_title' => 'Si ya existe un título idéntico en la parte superior n artículos más recientes', diff --git a/app/i18n/fr/conf.php b/app/i18n/fr/conf.php index e96c695d4..ff07ff91a 100644 --- a/app/i18n/fr/conf.php +++ b/app/i18n/fr/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'lorsque l’article est affiché', 'keep_max_n_unread' => 'Nombre maximum d’articles conservés non lus', 'scroll' => 'au défilement de la page', + 'upon_gone' => 'lorsqu’il n’est plus dans le flux d’actualités en amont', 'upon_reception' => 'dès la réception du nouvel article', 'when' => 'Marquer un article comme lu…', 'when_same_title' => 'si un même titre existe déjà dans les n articles plus récents', diff --git a/app/i18n/he/conf.php b/app/i18n/he/conf.php index 140667169..d0edbb849 100644 --- a/app/i18n/he/conf.php +++ b/app/i18n/he/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'כאשר מאמר נצפה', 'keep_max_n_unread' => 'Max number of articles to keep unread', // TODO 'scroll' => 'כאשר גוללים', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'כאשר המאמר מתקבל', 'when' => 'סימון מאמרים כנקראו…', 'when_same_title' => 'if an identical title already exists in the top n newest articles', // TODO diff --git a/app/i18n/it/conf.php b/app/i18n/it/conf.php index af5b9051e..08348c625 100644 --- a/app/i18n/it/conf.php +++ b/app/i18n/it/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'Quando un articolo viene letto', 'keep_max_n_unread' => 'Max number of articles to keep unread', // TODO 'scroll' => 'Scorrendo la pagina', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'Alla ricezione del contenuto', 'when' => 'Segna articoli come letti…', 'when_same_title' => 'if an identical title already exists in the top n newest articles', // TODO diff --git a/app/i18n/ja/conf.php b/app/i18n/ja/conf.php index 6f5b77118..841a360d5 100644 --- a/app/i18n/ja/conf.php +++ b/app/i18n/ja/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => '記事を読んだとき', 'keep_max_n_unread' => '未読の記事として残す最大数', 'scroll' => 'スクロールしているとき', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => '記事を受け取ったとき', 'when' => '記事を既読にする…', 'when_same_title' => '同一タイトルの新しい記事があるときには、上部へ表示する', diff --git a/app/i18n/ko/conf.php b/app/i18n/ko/conf.php index 8f8ba276d..971ff1a85 100644 --- a/app/i18n/ko/conf.php +++ b/app/i18n/ko/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => '글을 읽었을 때', 'keep_max_n_unread' => '읽지 않은 상태로 유지할 최대 글 개수', 'scroll' => '스크롤을 하며 지나갈 때', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => '글을 가져오자마자', 'when' => '읽음으로 표시…', 'when_same_title' => '상위 n개의 최신 글에 동일한 제목이 이미 있는 경우', diff --git a/app/i18n/nl/conf.php b/app/i18n/nl/conf.php index 3608a7001..cb86238be 100644 --- a/app/i18n/nl/conf.php +++ b/app/i18n/nl/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'als het artikel wordt bekeken', 'keep_max_n_unread' => 'Max aantal artikelen ongelezen houden', 'scroll' => 'tijdens het scrollen', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'bij ontvangst van het artikel', 'when' => 'Markeer artikel als gelezen…', 'when_same_title' => 'als een zelfde titel al voorkomt in de top n nieuwste artikelen', diff --git a/app/i18n/oc/conf.php b/app/i18n/oc/conf.php index e29380d08..284eafc7e 100644 --- a/app/i18n/oc/conf.php +++ b/app/i18n/oc/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'quand l’article es mostrat', 'keep_max_n_unread' => 'Nombre max d’articles a gardar pas legits', 'scroll' => 'en davalar la pagina', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'en recebre un article novèl', 'when' => 'Marcar un article coma legit…', 'when_same_title' => 'se un títol identic existís ja demest lo n articles mai recents', diff --git a/app/i18n/pl/conf.php b/app/i18n/pl/conf.php index c5910f22e..74f511f96 100644 --- a/app/i18n/pl/conf.php +++ b/app/i18n/pl/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'gdy wiadomość jest otworzona', 'keep_max_n_unread' => 'Maksymalna liczba nieprzeczytanych wiadomości', 'scroll' => 'podczas przewijania', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'po otrzymaniu wiadomości', 'when' => 'Oznacz wiadomość jako przeczytaną…', 'when_same_title' => 'gdy identyczny tytuł już istnieje w n najnowszych wiadomościach', diff --git a/app/i18n/pt-br/conf.php b/app/i18n/pt-br/conf.php index 11de40423..66dcebed7 100644 --- a/app/i18n/pt-br/conf.php +++ b/app/i18n/pt-br/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'Quando o artigo é visualizado', 'keep_max_n_unread' => 'Número máximo de artigos para manter como não lido', 'scroll' => 'enquanto scrolling', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'ao receber um artigo', 'when' => 'Marcar artigo como lido…', 'when_same_title' => 'Se um título idêntico já existir nos últimosn artigos mais novos', diff --git a/app/i18n/ru/conf.php b/app/i18n/ru/conf.php index ca094d5f8..9a4f25564 100644 --- a/app/i18n/ru/conf.php +++ b/app/i18n/ru/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'когда статья просматривается', 'keep_max_n_unread' => 'Максимальное количество непрочитанных статей', 'scroll' => 'во время прокрутки', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'по получении статьи', 'when' => 'Отмечать статью прочитанной…', 'when_same_title' => 'если идентичный заголовок уже существует в верхних n новейших статьях', diff --git a/app/i18n/sk/conf.php b/app/i18n/sk/conf.php index c773e7991..dfd05b2b7 100644 --- a/app/i18n/sk/conf.php +++ b/app/i18n/sk/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'keď je článok zobrazený', 'keep_max_n_unread' => 'Maximálny počet článkov ponechať ako neprečítané', 'scroll' => 'počas skrolovania', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'po načítaní článku', 'when' => 'Označiť článok ako prečítaný…', 'when_same_title' => 'ak rovnaký nadpis už existuje v TOP n najnovších článkoch', diff --git a/app/i18n/tr/conf.php b/app/i18n/tr/conf.php index ff656f95f..e9f12de7c 100644 --- a/app/i18n/tr/conf.php +++ b/app/i18n/tr/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => 'makale görüntülendiğinde', 'keep_max_n_unread' => 'Max number of articles to keep unread', // TODO 'scroll' => 'kaydırma yapılırken', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => 'makale üzerinde gelince', 'when' => 'Makaleyi okundu olarak işaretle…', 'when_same_title' => 'if an identical title already exists in the top n newest articles', // TODO diff --git a/app/i18n/zh-cn/conf.php b/app/i18n/zh-cn/conf.php index 96583e05a..44808c141 100644 --- a/app/i18n/zh-cn/conf.php +++ b/app/i18n/zh-cn/conf.php @@ -160,6 +160,7 @@ return array( 'article_viewed' => '在文章被浏览后', 'keep_max_n_unread' => '未读最多保留 n 条', 'scroll' => '在滚动浏览后', + 'upon_gone' => 'when it is no longer in the upstream news feed', // TODO 'upon_reception' => '在接收文章后', 'when' => '何时将文章标记为已读', 'when_same_title' => '已存在 n 条相同标题文章', diff --git a/app/views/configure/reading.phtml b/app/views/configure/reading.phtml index 825655102..251981397 100644 --- a/app/views/configure/reading.phtml +++ b/app/views/configure/reading.phtml @@ -69,7 +69,7 @@ - +
@@ -200,21 +200,6 @@
-
- -
- -
-
-
@@ -236,7 +221,7 @@ data-leave-validation="mark_when['site'] ?>"/> -
+
@@ -248,7 +233,46 @@ data-leave-validation="mark_when['scroll'] ?>"/> -
+ + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
@@ -263,17 +287,6 @@
- -
-
- -
-
diff --git a/app/views/helpers/feed/update.phtml b/app/views/helpers/feed/update.phtml index 1acf570ea..dc0f53a52 100644 --- a/app/views/helpers/feed/update.phtml +++ b/app/views/helpers/feed/update.phtml @@ -186,9 +186,17 @@
- +
- + +
@@ -205,17 +213,14 @@
- +
- + + + - +
@@ -231,6 +236,13 @@ +
+ +
+ +
+
+
diff --git a/config-user.default.php b/config-user.default.php index 1e6cacb64..01f2764c0 100644 --- a/config-user.default.php +++ b/config-user.default.php @@ -49,6 +49,7 @@ return array ( 'anon_access' => false, 'mark_when' => array ( 'article' => true, + 'gone' => false, 'max_n_unread' => false, 'reception' => false, 'same_title_in_feed' => false,