From 0c066cb4285feb54cd9947c01dd759afdc0f37fb Mon Sep 17 00:00:00 2001 From: perrinjerome Date: Thu, 1 Mar 2018 04:08:32 +0900 Subject: Feed parsing: use author email when there's no author name (#1801) This is especially useful because when author is given as `Author Name` ( as in this example https://cyber.harvard.edu/rss/rss.html#ltauthorgtSubelementOfLtitemgt ), SimplePie will expose *Author Name* as `email`. --- app/Models/Feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/Models') diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 13ab13df9..196d94931 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -355,7 +355,7 @@ class FreshRSS_Feed extends Minz_Model { $this->id(), $item->get_id(false, false), $title === null ? '' : $title, - $author === null ? '' : html_only_entity_decode(strip_tags($author->name)), + $author === null ? '' : html_only_entity_decode(strip_tags($author->name == null ? $author->email : $author->name)), $content === null ? '' : $content, $link === null ? '' : $link, $date ? $date : time() -- cgit v1.2.3 From 5872a11eb75958f12fd37c144a26c12c693d8a4a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 1 Mar 2018 19:25:40 +0100 Subject: cleanOldEntries call autoUpdateDb (#1804) * cleanOldEntries call autoUpdateDb https://github.com/FreshRSS/FreshRSS/issues/1803 * Fix feedDAO autoUpdateDb * Move cleanOldEntries to EntryDAO Only the entry table is concerned --- app/Controllers/entryController.php | 3 ++- app/Controllers/feedController.php | 2 +- app/Models/EntryDAO.php | 27 +++++++++++++++++++++++++++ app/Models/FeedDAO.php | 24 ------------------------ 4 files changed, 30 insertions(+), 26 deletions(-) (limited to 'app/Models') diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 9c6b248a9..28f0cb745 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -169,6 +169,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { $nb_month_old = max(FreshRSS_Context::$user_conf->old_entries, 1); $date_min = time() - (3600 * 24 * 30 * $nb_month_old); + $entryDAO = FreshRSS_Factory::createEntryDao(); $feedDAO = FreshRSS_Factory::createFeedDao(); $feeds = $feedDAO->listFeeds(); $nb_total = 0; @@ -182,7 +183,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { } if ($feed_history >= 0) { - $nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feed_history); + $nb = $entryDAO->cleanOldEntries($feed->id(), $date_min, $feed_history); if ($nb > 0) { $nb_total += $nb; Minz_Log::debug($nb . ' old entries cleaned in feed [' . $feed->url() . ']'); diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 7f66b10db..af732951f 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -408,7 +408,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $entryDAO->beginTransaction(); } - $nb = $feedDAO->cleanOldEntries($feed->id(), + $nb = $entryDAO->cleanOldEntries($feed->id(), $date_min, max($feed_history, count($entries) + 10)); if ($nb > 0) { diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 70135e7a0..8cdebedc5 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -560,6 +560,33 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable { return $affected; } + public function cleanOldEntries($id_feed, $date_min, $keep = 15) { //Remember to call updateCachedValue($id_feed) or updateCachedValues() just after + $sql = 'DELETE FROM `' . $this->prefix . 'entry` ' + . 'WHERE id_feed=:id_feed AND id<=:id_max ' + . 'AND is_favorite=0 ' //Do not remove favourites + . 'AND `lastSeen` < (SELECT maxLastSeen FROM (SELECT (MAX(e3.`lastSeen`)-99) AS maxLastSeen FROM `' . $this->prefix . 'entry` e3 WHERE e3.id_feed=:id_feed) recent) ' //Do not remove the most newly seen articles, plus a few seconds of tolerance + . 'AND id NOT IN (SELECT id FROM (SELECT e2.id FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=:id_feed ORDER BY id DESC LIMIT :keep) keep)'; //Double select: MySQL doesn't support 'LIMIT & IN/ALL/ANY/SOME subquery' + $stm = $this->bd->prepare($sql); + + if ($stm) { + $id_max = intval($date_min) . '000000'; + $stm->bindParam(':id_feed', $id_feed, PDO::PARAM_INT); + $stm->bindParam(':id_max', $id_max, PDO::PARAM_STR); + $stm->bindParam(':keep', $keep, PDO::PARAM_INT); + } + + if ($stm && $stm->execute()) { + return $stm->rowCount(); + } else { + $info = $stm == null ? array(0 => '', 1 => '', 2 => 'syntax error') : $stm->errorInfo(); + if ($this->autoUpdateDb($info)) { + return $this->cleanOldEntries($id_feed, $date_min, $keep); + } + Minz_Log::error('SQL error cleanOldEntries: ' . $info[2]); + return false; + } + } + public function searchByGuid($id_feed, $guid) { // un guid est unique pour un flux donné $sql = 'SELECT id, guid, title, author, ' diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 011b3d112..0c25ab0ba 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -353,30 +353,6 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { return $affected; } - public function cleanOldEntries($id, $date_min, $keep = 15) { //Remember to call updateCachedValue($id) or updateCachedValues() just after - $sql = 'DELETE FROM `' . $this->prefix . 'entry` ' - . 'WHERE id_feed=:id_feed AND id<=:id_max ' - . 'AND is_favorite=0 ' //Do not remove favourites - . 'AND `lastSeen` < (SELECT maxLastSeen FROM (SELECT (MAX(e3.`lastSeen`)-99) AS maxLastSeen FROM `' . $this->prefix . 'entry` e3 WHERE e3.id_feed=:id_feed) recent) ' //Do not remove the most newly seen articles, plus a few seconds of tolerance - . 'AND id NOT IN (SELECT id FROM (SELECT e2.id FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=:id_feed ORDER BY id DESC LIMIT :keep) keep)'; //Double select: MySQL doesn't support 'LIMIT & IN/ALL/ANY/SOME subquery' - $stm = $this->bd->prepare($sql); - - if ($stm) { - $id_max = intval($date_min) . '000000'; - $stm->bindParam(':id_feed', $id, PDO::PARAM_INT); - $stm->bindParam(':id_max', $id_max, PDO::PARAM_STR); - $stm->bindParam(':keep', $keep, PDO::PARAM_INT); - } - - if ($stm && $stm->execute()) { - return $stm->rowCount(); - } else { - $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); - Minz_Log::error('SQL error cleanOldEntries: ' . $info[2]); - return false; - } - } - public static function daoToFeed($listDAO, $catID = null) { $list = array(); -- cgit v1.2.3 From e22d4dfdd3e708f4558735e3dc2864361e2cacc2 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 3 Mar 2018 10:33:40 +0100 Subject: Fix bug when using double authentication (#1809) https://github.com/FreshRSS/FreshRSS/issues/1807 --- app/Models/Auth.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/Models') diff --git a/app/Models/Auth.php b/app/Models/Auth.php index 32b673b6d..8c711308c 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -63,7 +63,6 @@ class FreshRSS_Auth { $login_ok = $current_user != ''; if ($login_ok) { Minz_Session::_param('currentUser', $current_user); - Minz_Session::_param('REMOTE_USER', $current_user); } return $login_ok; case 'none': @@ -102,6 +101,7 @@ class FreshRSS_Auth { } Minz_Session::_param('loginOk', self::$login_ok); + Minz_Session::_param('REMOTE_USER', httpAuthUser()); } /** @@ -133,6 +133,7 @@ class FreshRSS_Auth { self::$login_ok = false; Minz_Session::_param('loginOk'); Minz_Session::_param('csrf'); + Minz_Session::_param('REMOTE_USER'); $system_conf = Minz_Configuration::get('system'); $username = ''; -- cgit v1.2.3