From b4463cb69e64ff2dfe840ef69f1b825ecdbee43e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 15 Dec 2013 11:28:27 +0100 Subject: Problème casse renommage répertoire MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controllers/feedController.php | 428 +++++++++++++++++++++++++++++++++++++ 1 file changed, 428 insertions(+) create mode 100755 app/Controllers/feedController.php (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php new file mode 100755 index 000000000..a85877724 --- /dev/null +++ b/app/Controllers/feedController.php @@ -0,0 +1,428 @@ +view->conf->token(); + $token_param = Minz_Request::param ('token', ''); + $token_is_ok = ($token != '' && $token == $token_param); + $action = Minz_Request::actionName (); + + if (login_is_conf ($this->view->conf) && + !is_logged () && + !($token_is_ok && $action == 'actualize')) { + Minz_Error::error ( + 403, + array ('error' => array (Minz_Translate::t ('access_denied'))) + ); + } + + $this->catDAO = new FreshRSS_CategoryDAO (); + $this->catDAO->checkDefault (); + } + + private static function entryDateComparer($e1, $e2) { + $d1 = $e1->date(true); + $d2 = $e2->date(true); + if ($d1 === $d2) { + return 0; + } + return ($d1 < $d2) ? -1 : 1; + } + + public function addAction () { + @set_time_limit(300); + + if (Minz_Request::isPost ()) { + $url = Minz_Request::param ('url_rss'); + $cat = Minz_Request::param ('category', false); + if ($cat === false) { + $def_cat = $this->catDAO->getDefault (); + $cat = $def_cat->id (); + } + + $user = Minz_Request::param ('username'); + $pass = Minz_Request::param ('password'); + $params = array (); + + $transactionStarted = false; + try { + $feed = new FreshRSS_Feed ($url); + $feed->_category ($cat); + + $httpAuth = ''; + if ($user != '' || $pass != '') { + $httpAuth = $user . ':' . $pass; + } + $feed->_httpAuth ($httpAuth); + + $feed->load (); + + $feedDAO = new FreshRSS_FeedDAO (); + $values = array ( + 'url' => $feed->url (), + 'category' => $feed->category (), + 'name' => $feed->name (), + 'website' => $feed->website (), + 'description' => $feed->description (), + 'lastUpdate' => time (), + 'httpAuth' => $feed->httpAuth (), + ); + + if ($feedDAO->searchByUrl ($values['url'])) { + // on est déjà abonné à ce flux + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('already_subscribed', $feed->name ()) + ); + Minz_Session::_param ('notification', $notif); + } else { + $id = $feedDAO->addFeed ($values); + if (!$id) { + // problème au niveau de la base de données + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('feed_not_added', $feed->name ()) + ); + Minz_Session::_param ('notification', $notif); + } else { + $feed->_id ($id); + $feed->faviconPrepare(); + + $is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0; + + $entryDAO = new FreshRSS_EntryDAO (); + $entries = $feed->entries (); + usort($entries, 'self::entryDateComparer'); + + // on calcule la date des articles les plus anciens qu'on accepte + $nb_month_old = $this->view->conf->oldEntries (); + $date_min = time () - (3600 * 24 * 30 * $nb_month_old); + + $transactionStarted = true; + $feedDAO->beginTransaction (); + // on ajoute les articles en masse sans vérification + foreach ($entries as $entry) { + if ($entry->date (true) >= $date_min || + $feed->keepHistory ()) { + $values = $entry->toArray (); + $values['id_feed'] = $feed->id (); + $values['id'] = min(time(), $entry->date (true)) . uSecString(); + $values['is_read'] = $is_read; + $entryDAO->addEntry ($values); + } + } + $feedDAO->updateLastUpdate ($feed->id ()); + $feedDAO->commit (); + $transactionStarted = false; + + // ok, ajout terminé + $notif = array ( + 'type' => 'good', + 'content' => Minz_Translate::t ('feed_added', $feed->name ()) + ); + Minz_Session::_param ('notification', $notif); + + // permet de rediriger vers la page de conf du flux + $params['id'] = $feed->id (); + } + } + } catch (FreshRSS_BadUrl_Exception $e) { + Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('invalid_url', $url) + ); + Minz_Session::_param ('notification', $notif); + } catch (FreshRSS_Feed_Exception $e) { + Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('internal_problem_feed') + ); + Minz_Session::_param ('notification', $notif); + } catch (Minz_FileNotExistException $e) { + // Répertoire de cache n'existe pas + Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('internal_problem_feed') + ); + Minz_Session::_param ('notification', $notif); + } + if ($transactionStarted) { + $feedDAO->rollBack (); + } + + Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => $params), true); + } + } + + public function truncateAction () { + if (Minz_Request::isPost ()) { + $id = Minz_Request::param ('id'); + $feedDAO = new FreshRSS_FeedDAO (); + $n = $feedDAO->truncate($id); + $notif = array( + 'type' => $n === false ? 'bad' : 'good', + 'content' => Minz_Translate::t ('n_entries_deleted', $n) + ); + Minz_Session::_param ('notification', $notif); + invalidateHttpCache(); + Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array('id' => $id)), true); + } + } + + public function actualizeAction () { + @set_time_limit(300); + + $feedDAO = new FreshRSS_FeedDAO (); + $entryDAO = new FreshRSS_EntryDAO (); + + $id = Minz_Request::param ('id'); + $force = Minz_Request::param ('force', false); + + // on créé la liste des flux à mettre à actualiser + // si on veut mettre un flux à jour spécifiquement, on le met + // dans la liste, mais seul (permet d'automatiser le traitement) + $feeds = array (); + if ($id) { + $feed = $feedDAO->searchById ($id); + if ($feed) { + $feeds = array ($feed); + } + } else { + $feeds = $feedDAO->listFeedsOrderUpdate (); + } + + // on calcule la date des articles les plus anciens qu'on accepte + $nb_month_old = $this->view->conf->oldEntries (); + $date_min = time () - (3600 * 24 * 30 * $nb_month_old); + + $i = 0; + $flux_update = 0; + foreach ($feeds as $feed) { + try { + $feed->load (); + $feed->faviconPrepare(); + $entries = $feed->entries (); + usort($entries, 'self::entryDateComparer'); + + $is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0; + + //For this feed, check last n entry GUIDs already in database + $existingGuids = array_fill_keys ($entryDAO->listLastGuidsByFeed ($feed->id (), count($entries) + 10), 1); + + // On ne vérifie pas strictement que l'article n'est pas déjà en BDD + // La BDD refusera l'ajout car (id_feed, guid) doit être unique + $feedDAO->beginTransaction (); + foreach ($entries as $entry) { + if ((!isset ($existingGuids[$entry->guid ()])) && + ($entry->date (true) >= $date_min || + $feed->keepHistory ())) { + $values = $entry->toArray (); + //Use declared date at first import, otherwise use discovery date + $values['id'] = empty($existingGuids) ? min(time(), $entry->date (true)) . uSecString() : uTimeString(); + $values['is_read'] = $is_read; + $entryDAO->addEntry ($values); + } + } + + if ((!$feed->keepHistory()) && (rand(0, 30) === 1)) { + $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, count($entries) + 10); + Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG); + } + + // on indique que le flux vient d'être mis à jour en BDD + $feedDAO->updateLastUpdate ($feed->id ()); + $feedDAO->commit (); + $flux_update++; + } catch (FreshRSS_Feed_Exception $e) { + Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); + $feedDAO->updateLastUpdate ($feed->id (), 1); + } + + // On arrête à 10 flux pour ne pas surcharger le serveur + // sauf si le paramètre $force est à vrai + $i++; + if ($i >= 10 && !$force) { + break; + } + } + + $url = array (); + if ($flux_update === 1) { + // on a mis un seul flux à jour + $notif = array ( + 'type' => 'good', + 'content' => Minz_Translate::t ('feed_actualized', $feed->name ()) + ); + } elseif ($flux_update > 1) { + // plusieurs flux on été mis à jour + $notif = array ( + 'type' => 'good', + 'content' => Minz_Translate::t ('n_feeds_actualized', $flux_update) + ); + } else { + // aucun flux n'a été mis à jour, oups + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('no_feed_actualized') + ); + } + + if ($i === 1) { + // Si on a voulu mettre à jour qu'un flux + // on filtre l'affichage par ce flux + $feed = reset ($feeds); + $url['params'] = array ('get' => 'f_' . $feed->id ()); + } + + if (Minz_Request::param ('ajax', 0) === 0) { + Minz_Session::_param ('notification', $notif); + Minz_Request::forward ($url, true); + } else { + // Une requête Ajax met un seul flux à jour. + // Comme en principe plusieurs requêtes ont lieu, + // on indique que "plusieurs flux ont été mis à jour". + // Cela permet d'avoir une notification plus proche du + // ressenti utilisateur + $notif = array ( + 'type' => 'good', + 'content' => Minz_Translate::t ('feeds_actualized') + ); + Minz_Session::_param ('notification', $notif); + // et on désactive le layout car ne sert à rien + $this->view->_useLayout (false); + } + } + + public function massiveImportAction () { + @set_time_limit(300); + + $entryDAO = new FreshRSS_EntryDAO (); + $feedDAO = new FreshRSS_FeedDAO (); + + $categories = Minz_Request::param ('categories', array (), true); + $feeds = Minz_Request::param ('feeds', array (), true); + + // on ajoute les catégories en masse dans une fonction à part + $this->addCategories ($categories); + + // on calcule la date des articles les plus anciens qu'on accepte + $nb_month_old = $this->view->conf->oldEntries (); + $date_min = time () - (3600 * 24 * 30 * $nb_month_old); + + // la variable $error permet de savoir si une erreur est survenue + // Le but est de ne pas arrêter l'import même en cas d'erreur + // L'utilisateur sera mis au courant s'il y a eu des erreurs, mais + // ne connaîtra pas les détails. Ceux-ci seront toutefois logguées + $error = false; + $i = 0; + foreach ($feeds as $feed) { + try { + $values = array ( + 'id' => $feed->id (), + 'url' => $feed->url (), + 'category' => $feed->category (), + 'name' => $feed->name (), + 'website' => $feed->website (), + 'description' => $feed->description (), + 'lastUpdate' => 0, + 'httpAuth' => $feed->httpAuth () + ); + + // ajout du flux que s'il n'est pas déjà en BDD + if (!$feedDAO->searchByUrl ($values['url'])) { + $id = $feedDAO->addFeed ($values); + if ($id) { + $feed->_id ($id); + $feed->faviconPrepare(); + } else { + $error = true; + } + } + } catch (FreshRSS_Feed_Exception $e) { + $error = true; + Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); + } + } + + if ($error) { + $res = Minz_Translate::t ('feeds_imported_with_errors'); + } else { + $res = Minz_Translate::t ('feeds_imported'); + } + + $notif = array ( + 'type' => 'good', + 'content' => $res + ); + Minz_Session::_param ('notification', $notif); + Minz_Session::_param ('actualize_feeds', true); + + // et on redirige vers la page d'accueil + Minz_Request::forward (array ( + 'c' => 'index', + 'a' => 'index' + ), true); + } + + public function deleteAction () { + if (Minz_Request::isPost ()) { + $type = Minz_Request::param ('type', 'feed'); + $id = Minz_Request::param ('id'); + + $feedDAO = new FreshRSS_FeedDAO (); + if ($type == 'category') { + if ($feedDAO->deleteFeedByCategory ($id)) { + $notif = array ( + 'type' => 'good', + 'content' => Minz_Translate::t ('category_emptied') + ); + //TODO: Delete old favicons + } else { + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('error_occured') + ); + } + } else { + if ($feedDAO->deleteFeed ($id)) { + $notif = array ( + 'type' => 'good', + 'content' => Minz_Translate::t ('feed_deleted') + ); + Feed::faviconDelete($id); + } else { + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('error_occured') + ); + } + } + + Minz_Session::_param ('notification', $notif); + + if ($type == 'category') { + Minz_Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true); + } else { + Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed'), true); + } + } + } + + private function addCategories ($categories) { + $catDAO = new FreshRSS_CategoryDAO (); + + foreach ($categories as $cat) { + if (!$catDAO->searchByName ($cat->name ())) { + $values = array ( + 'id' => $cat->id (), + 'name' => $cat->name (), + 'color' => $cat->color () + ); + $catDAO->addCategory ($values); + } + } + } +} -- cgit v1.2.3 From ce3801e5acf22e64cb53cfad21ced1b962674a91 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 15 Dec 2013 12:17:20 +0100 Subject: Message debug nettoyage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message dans le log uniquement lorsque des articles ont été supprimés https://github.com/marienfressinaud/FreshRSS/issues/323 --- 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 a85877724..18476d559 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -229,7 +229,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if ((!$feed->keepHistory()) && (rand(0, 30) === 1)) { $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, count($entries) + 10); - Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG); + if ($nb > 0) { + Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG); + } } // on indique que le flux vient d'être mis à jour en BDD -- cgit v1.2.3 From 1c0e7a49528d1fb972a0fa0e9551d70dc5636442 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 19 Dec 2013 21:53:21 +0100 Subject: Refactorisation : FreshRSS_Feed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Un préfixe FreshRSS_ oublié --- app/Controllers/feedController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 18476d559..27b76dd42 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -394,7 +394,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { 'type' => 'good', 'content' => Minz_Translate::t ('feed_deleted') ); - Feed::faviconDelete($id); + FreshRSS_Feed::faviconDelete($id); } else { $notif = array ( 'type' => 'bad', -- cgit v1.2.3 From 87bfa195a6ff4ff73baadd3c04b7b6f28c9f9b73 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 24 Dec 2013 01:21:11 +0100 Subject: Permet de configurer plus finement le nombre d’articles minimum à conserver par flux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 1 + app/Controllers/feedController.php | 20 ++++++++------------ app/Models/EntryDAO.php | 2 +- app/Models/Feed.php | 17 +++++------------ app/Models/FeedDAO.php | 4 ++-- app/i18n/en.php | 7 +++++-- app/i18n/fr.php | 8 ++++++-- app/views/configure/display.phtml | 29 +++++++++++++++++++++-------- app/views/configure/feed.phtml | 22 ++++++++++++++++++---- public/install.php | 2 +- 10 files changed, 68 insertions(+), 44 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/CHANGELOG b/CHANGELOG index af6936204..0c816dbd7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ * Améliorations partage vers Shaarli, Poche, Diaspora*, Facebook, Twitter, Google+, courriel * Permet la suppression de tous les articles d’un flux * Option pour marquer les articles comme lus dès la réception + * Permet de configurer plus finement le nombre d’articles minimum à conserver par flux * Permet de modifier la description et l’adresse d’un flux RSS ainsi que le site Web associé * Nouveau raccourci pour ouvrir/fermer un article (‘c’ par défaut) * Bouton pour effacer les logs diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 27b76dd42..e7d9c97c3 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -102,14 +102,11 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feedDAO->beginTransaction (); // on ajoute les articles en masse sans vérification foreach ($entries as $entry) { - if ($entry->date (true) >= $date_min || - $feed->keepHistory ()) { - $values = $entry->toArray (); - $values['id_feed'] = $feed->id (); - $values['id'] = min(time(), $entry->date (true)) . uSecString(); - $values['is_read'] = $is_read; - $entryDAO->addEntry ($values); - } + $values = $entry->toArray (); + $values['id_feed'] = $feed->id (); + $values['id'] = min(time(), $entry->date (true)) . uSecString(); + $values['is_read'] = $is_read; + $entryDAO->addEntry ($values); } $feedDAO->updateLastUpdate ($feed->id ()); $feedDAO->commit (); @@ -217,8 +214,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feedDAO->beginTransaction (); foreach ($entries as $entry) { if ((!isset ($existingGuids[$entry->guid ()])) && - ($entry->date (true) >= $date_min || - $feed->keepHistory ())) { + ($entry->date (true) >= $date_min)) { $values = $entry->toArray (); //Use declared date at first import, otherwise use discovery date $values['id'] = empty($existingGuids) ? min(time(), $entry->date (true)) . uSecString() : uTimeString(); @@ -227,8 +223,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } - if ((!$feed->keepHistory()) && (rand(0, 30) === 1)) { - $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, count($entries) + 10); + if (($feed->keepHistory() >= 0) && (rand(0, 30) === 1)) { + $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feed->keepHistory(), count($entries) + 10)); if ($nb > 0) { Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG); } diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index c6bd5c404..f0207e96d 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -307,7 +307,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $where .= 'AND e1.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' '; } if (($date_min > 0) && ($type !== 's')) { - $where .= 'AND (e1.id >= ' . $date_min . '000000 OR e1.is_favorite = 1 OR f.keep_history = 1) '; + $where .= 'AND (e1.id >= ' . $date_min . '000000 OR e1.is_favorite = 1 OR f.keep_history <> 0) '; $joinFeed = true; } $search = ''; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 70efb0fa3..5bdf5e6d7 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -15,7 +15,7 @@ class FreshRSS_Feed extends Minz_Model { private $pathEntries = ''; private $httpAuth = ''; private $error = false; - private $keep_history = false; + private $keep_history = 0; public function __construct ($url, $validate=true) { if ($validate) { @@ -163,19 +163,12 @@ class FreshRSS_Feed extends Minz_Model { $this->httpAuth = $value; } public function _error ($value) { - if ($value) { - $value = true; - } else { - $value = false; - } - $this->error = $value; + $this->error = (bool)$value; } public function _keepHistory ($value) { - if ($value) { - $value = true; - } else { - $value = false; - } + $value = intval($value); + $value = min($value, 1000000); + $value = max($value, -1); $this->keep_history = $value; } public function _nbNotRead ($value) { diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 9bd480544..451fc3850 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -193,7 +193,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { } public function listFeedsOrderUpdate () { - $sql = 'SELECT * FROM `' . $this->prefix . 'feed` ORDER BY lastUpdate'; + $sql = 'SELECT id, url, pathEntries, httpAuth, keep_history FROM `' . $this->prefix . 'feed` ORDER BY lastUpdate'; $stm = $this->bd->prepare ($sql); $stm->execute (); @@ -326,7 +326,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { $myFeed->_pathEntries (isset($dao['pathEntries']) ? $dao['pathEntries'] : ''); $myFeed->_httpAuth (isset($dao['httpAuth']) ? base64_decode ($dao['httpAuth']) : ''); $myFeed->_error ($dao['error']); - $myFeed->_keepHistory (isset($dao['keep_history']) ? $dao['keep_history'] : ''); + $myFeed->_keepHistory (isset($dao['keep_history']) ? $dao['keep_history'] : 0); $myFeed->_nbNotRead ($dao['cache_nbUnreads']); $myFeed->_nbEntries ($dao['cache_nbEntries']); if (isset ($dao['id'])) { diff --git a/app/i18n/en.php b/app/i18n/en.php index 9c30573e8..b6417d8db 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -137,7 +137,8 @@ return array ( 'feed_url' => 'Feed URL', 'articles' => 'articles', 'number_articles' => 'Number of articles', - 'keep_history' => 'Keep old articles?', + 'keep_history' => 'Minimum number of articles to keep', + 'keep_history_help' => 'Set to -1 to keep everything', 'categorize' => 'Store in a category', 'truncate' => 'Delete all articles', 'advanced' => 'Advanced', @@ -157,13 +158,15 @@ return array ( 'general_configuration' => 'General configuration', 'language' => 'Language', - 'delete_articles_every' => 'Remove articles after', 'month' => 'months', 'default_user' => 'Username of the default user (maximum 16 alphanumeric characters)', 'persona_connection_email' => 'Login mail address (use Mozilla Persona)', 'allow_anonymous' => 'Allow anonymous reading', 'auth_token' => 'Authentication token', 'explain_token' => 'Allows to access RSS output without authentication.
%s?token=%s', + 'archiving_configuration' => 'Archiving configuration', + 'delete_articles_every' => 'Remove articles after', + 'archiving_configuration_help' => 'More options are available in the individual stream settings', 'reading_configuration' => 'Reading configuration', 'articles_per_page' => 'Number of articles per page', 'default_view' => 'Default view', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 85bbeb4b7..b27f29940 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -137,7 +137,8 @@ return array ( 'feed_url' => 'URL du flux', 'articles' => 'articles', 'number_articles' => 'Nombre d’articles', - 'keep_history' => 'Garder les vieux articles ?', + 'keep_history' => 'Nombre minimum d’articles à conserver', + 'keep_history_help' => 'Mettre à -1 pour tout conserver', 'categorize' => 'Ranger dans une catégorie', 'truncate' => 'Supprimer tous les articles', 'advanced' => 'Avancé', @@ -157,13 +158,16 @@ return array ( 'general_configuration' => 'Configuration générale', 'language' => 'Langue', - 'delete_articles_every' => 'Supprimer les articles après', + 'month' => 'mois', 'default_user' => 'Nom de l’utilisateur par défaut (16 caractères alphanumériques maximum)', 'persona_connection_email' => 'Adresse courriel de connexion (utilise Mozilla Persona)', 'allow_anonymous' => 'Autoriser la lecture anonyme', 'auth_token' => 'Jeton d’identification', 'explain_token' => 'Permet d’accéder à la sortie RSS sans besoin de s’authentifier.
%s?output=rss&token=%s', + 'archiving_configuration' => 'Configuration de l’archivage', + 'delete_articles_every' => 'Supprimer les articles après', + 'archiving_configuration_help' => 'D’autres options sont disponibles dans la configuration individuelle des flux', 'reading_configuration' => 'Configuration de lecture', 'articles_per_page' => 'Nombre d’articles par page', 'default_view' => 'Vue par défaut', diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index ad35d7c71..68ef26bbf 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -31,13 +31,6 @@ -
- -
- -
-
-
conf->mailLogin (); ?> @@ -59,7 +52,27 @@
- + + + +
+ +
+ + + + + + + + + + +
+ +
+
+
diff --git a/app/views/configure/feed.phtml b/app/views/configure/feed.phtml index 4504b8d76..3fe7d1b3a 100644 --- a/app/views/configure/feed.phtml +++ b/app/views/configure/feed.phtml @@ -52,6 +52,9 @@
+ + +
@@ -64,10 +67,21 @@
flux->nbEntries (); ?> - +
+
+
+ +
+ + + + + + + + + +
diff --git a/public/install.php b/public/install.php index afef7e473..3885f143e 100644 --- a/public/install.php +++ b/public/install.php @@ -93,7 +93,7 @@ FROM `%1$scategory006` ORDER BY id2; INSERT IGNORE INTO `%2$sfeed` (url, category, name, website, description, priority, pathEntries, httpAuth, keep_history) -SELECT url, category2, name, website, description, priority, pathEntries, httpAuth, keep_history +SELECT url, category2, name, website, description, priority, pathEntries, httpAuth, -1 * keep_history FROM `%1$sfeed006` ORDER BY id2; -- cgit v1.2.3 From 06d4b8d10247146d9c6f7c78ff9fc584438dd8fe Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 25 Dec 2013 17:37:52 +0100 Subject: Option globale pour la taille minimale de l'historique par défaut MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plus une réorganisation des options --- app/Controllers/configureController.php | 5 ++- app/Controllers/feedController.php | 9 +++-- app/Controllers/indexController.php | 5 +-- app/Models/Configuration.php | 14 +++++++- app/Models/ConfigurationDAO.php | 8 +++-- app/Models/EntryDAO.php | 8 +++-- app/Models/Feed.php | 4 +-- app/Models/FeedDAO.php | 4 +-- app/i18n/en.php | 8 +++-- app/i18n/fr.php | 8 +++-- app/views/configure/display.phtml | 35 ++++++++++++------- app/views/configure/feed.phtml | 62 ++++++++++++++++++--------------- public/install.php | 4 +-- public/themes/default/freshrss.css | 4 +++ public/themes/default/global.css | 3 ++ public/themes/flat-design/freshrss.css | 4 +++ public/themes/flat-design/global.css | 3 ++ 17 files changed, 124 insertions(+), 64 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index b83501f0b..762134dd0 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -97,7 +97,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $description = sanitizeHTML(Minz_Request::param('description', '', true)); $website = Minz_Request::param('website', ''); $url = Minz_Request::param('url', ''); - $keep_history = intval(Minz_Request::param ('keep_history', 0)); + $keep_history = intval(Minz_Request::param ('keep_history', -2)); $cat = Minz_Request::param ('category', 0); $path = Minz_Request::param ('path_entries', ''); $priority = Minz_Request::param ('priority', 0); @@ -160,6 +160,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $lazyload = Minz_Request::param ('lazyload', 'no'); $sort = Minz_Request::param ('sort_order', 'DESC'); $old = Minz_Request::param ('old_entries', 3); + $keepHistoryDefault = Minz_Request::param('keep_history_default', 0); $mail = Minz_Request::param ('mail_login', false); $anon = Minz_Request::param ('anon_access', 'no'); $token = Minz_Request::param ('token', $current_token); @@ -189,6 +190,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $this->view->conf->_lazyload ($lazyload); $this->view->conf->_sortOrder ($sort); $this->view->conf->_oldEntries ($old); + $this->view->conf->_keepHistoryDefault($keepHistoryDefault); $this->view->conf->_mailLogin ($mail); $this->view->conf->_anonAccess ($anon); $this->view->conf->_token ($token); @@ -221,6 +223,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { 'lazyload' => $this->view->conf->lazyload (), 'sort_order' => $this->view->conf->sortOrder (), 'old_entries' => $this->view->conf->oldEntries (), + 'keep_history_default' => $this->view->conf->keepHistoryDefault(), 'mail_login' => $this->view->conf->mailLogin (), 'anon_access' => $this->view->conf->anonAccess (), 'token' => $this->view->conf->token (), diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index e7d9c97c3..836044da6 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -223,8 +223,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } - if (($feed->keepHistory() >= 0) && (rand(0, 30) === 1)) { - $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feed->keepHistory(), count($entries) + 10)); + $feedHistory = $feed->keepHistory(); + if ($feedHistory == -2) { //default + $feedHistory = $this->view->conf->keepHistoryDefault(); + } + + if (($feedHistory >= 0) && (rand(0, 30) === 1)) { + $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feedHistory, count($entries) + 10)); if ($nb > 0) { Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG); } diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index e3c253518..6c0ba9058 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -130,16 +130,17 @@ class FreshRSS_index_Controller extends Minz_ActionController { // on calcule la date des articles les plus anciens qu'on affiche $nb_month_old = $this->view->conf->oldEntries (); $date_min = $today - (3600 * 24 * 30 * $nb_month_old); //Do not use a fast changing value such as time() to allow SQL caching + $keepHistoryDefault = $this->view->conf->keepHistoryDefault(); try { - $entries = $this->entryDAO->listWhere($getType, $getId, $state, $order, $nb + 1, $first, $filter, $date_min); + $entries = $this->entryDAO->listWhere($getType, $getId, $state, $order, $nb + 1, $first, $filter, $date_min, $keepHistoryDefault); // Si on a récupéré aucun article "non lus" // on essaye de récupérer tous les articles if ($state === 'not_read' && empty($entries)) { //TODO: Remove in v0.8 Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG); $this->view->state = 'all'; - $entries = $this->entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter, $date_min); + $entries = $this->entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter, $date_min, $keepHistoryDefault); } if (count($entries) <= $nb) { diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index d5f69601f..47509636f 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -14,6 +14,7 @@ class FreshRSS_Configuration extends Minz_Model { private $lazyload; private $sort_order; private $old_entries; + private $keep_history_default; private $shortcuts = array (); private $mail_login = ''; private $mark_when = array (); @@ -44,6 +45,7 @@ class FreshRSS_Configuration extends Minz_Model { $this->_lazyload ($confDAO->lazyload); $this->_sortOrder ($confDAO->sort_order); $this->_oldEntries ($confDAO->old_entries); + $this->_keepHistoryDefault($confDAO->keep_history_default); $this->_shortcuts ($confDAO->shortcuts); $this->_mailLogin ($confDAO->mail_login); $this->_markWhen ($confDAO->mark_when); @@ -95,6 +97,9 @@ class FreshRSS_Configuration extends Minz_Model { public function oldEntries () { return $this->old_entries; } + public function keepHistoryDefault() { + return $this->keep_history_default; + } public function shortcuts () { return $this->shortcuts; } @@ -217,11 +222,18 @@ class FreshRSS_Configuration extends Minz_Model { } public function _oldEntries ($value) { if (ctype_digit ($value) && $value > 0) { - $this->old_entries = $value; + $this->old_entries = intval($value); } else { $this->old_entries = 3; } } + public function _keepHistoryDefault($value) { + if (ctype_digit($value) && $value >= -1) { + $this->keep_history_default = intval($value); + } else { + $this->keep_history_default = 0; + } + } public function _shortcuts ($values) { foreach ($values as $key => $value) { $this->shortcuts[$key] = $value; diff --git a/app/Models/ConfigurationDAO.php b/app/Models/ConfigurationDAO.php index 0eebf2d90..91210e701 100644 --- a/app/Models/ConfigurationDAO.php +++ b/app/Models/ConfigurationDAO.php @@ -10,6 +10,7 @@ class FreshRSS_ConfigurationDAO extends Minz_ModelArray { public $lazyload = 'yes'; public $sort_order = 'DESC'; public $old_entries = 3; + public $keep_history_default = 0; public $shortcuts = array ( 'mark_read' => 'r', 'mark_favorite' => 'f', @@ -62,7 +63,7 @@ class FreshRSS_ConfigurationDAO extends Minz_ModelArray { $this->language = $this->array['language']; } if (isset ($this->array['posts_per_page'])) { - $this->posts_per_page = $this->array['posts_per_page']; + $this->posts_per_page = intval($this->array['posts_per_page']); } if (isset ($this->array['view_mode'])) { $this->view_mode = $this->array['view_mode']; @@ -83,7 +84,10 @@ class FreshRSS_ConfigurationDAO extends Minz_ModelArray { $this->sort_order = $this->array['sort_order']; } if (isset ($this->array['old_entries'])) { - $this->old_entries = $this->array['old_entries']; + $this->old_entries = intval($this->array['old_entries']); + } + if (isset ($this->array['keep_history_default'])) { + $this->keep_history_default = intval($this->array['keep_history_default']); } if (isset ($this->array['shortcuts'])) { $this->shortcuts = array_merge ( diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index f0207e96d..14d3ddcff 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -260,7 +260,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { return isset ($entries[0]) ? $entries[0] : false; } - public function listWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) { + public function listWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $keepHistoryDefault = 0) { $where = ''; $joinFeed = false; $values = array(); @@ -307,7 +307,11 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $where .= 'AND e1.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' '; } if (($date_min > 0) && ($type !== 's')) { - $where .= 'AND (e1.id >= ' . $date_min . '000000 OR e1.is_favorite = 1 OR f.keep_history <> 0) '; + $where .= 'AND (e1.id >= ' . $date_min . '000000 OR e1.is_favorite = 1 OR (f.keep_history <> 0'; + if (intval($keepHistoryDefault) === 0) { + $where .= ' AND f.keep_history <> -2'; //default + } + $where .= ')) '; $joinFeed = true; } $search = ''; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 5bdf5e6d7..ef554e083 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -15,7 +15,7 @@ class FreshRSS_Feed extends Minz_Model { private $pathEntries = ''; private $httpAuth = ''; private $error = false; - private $keep_history = 0; + private $keep_history = -2; public function __construct ($url, $validate=true) { if ($validate) { @@ -168,7 +168,7 @@ class FreshRSS_Feed extends Minz_Model { public function _keepHistory ($value) { $value = intval($value); $value = min($value, 1000000); - $value = max($value, -1); + $value = max($value, -2); $this->keep_history = $value; } public function _nbNotRead ($value) { diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 7d91a032a..c1d1f24e8 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -2,7 +2,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { public function addFeed ($valuesTmp) { - $sql = 'INSERT INTO `' . $this->prefix . 'feed` (url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history) VALUES(?, ?, ?, ?, ?, ?, 10, ?, 0, 0)'; + $sql = 'INSERT INTO `' . $this->prefix . 'feed` (url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history) VALUES(?, ?, ?, ?, ?, ?, 10, ?, 0, -2)'; $stm = $this->bd->prepare ($sql); $values = array ( @@ -326,7 +326,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { $myFeed->_pathEntries (isset($dao['pathEntries']) ? $dao['pathEntries'] : ''); $myFeed->_httpAuth (isset($dao['httpAuth']) ? base64_decode ($dao['httpAuth']) : ''); $myFeed->_error ($dao['error']); - $myFeed->_keepHistory (isset($dao['keep_history']) ? $dao['keep_history'] : 0); + $myFeed->_keepHistory(isset($dao['keep_history']) ? $dao['keep_history'] : -2); $myFeed->_nbNotRead ($dao['cache_nbUnreads']); $myFeed->_nbEntries ($dao['cache_nbEntries']); if (isset ($dao['id'])) { diff --git a/app/i18n/en.php b/app/i18n/en.php index b6417d8db..ca72d885c 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -137,8 +137,9 @@ return array ( 'feed_url' => 'Feed URL', 'articles' => 'articles', 'number_articles' => 'Number of articles', + 'by_feed' => 'by feed', + 'by_default' => 'By default', 'keep_history' => 'Minimum number of articles to keep', - 'keep_history_help' => 'Set to -1 to keep everything', 'categorize' => 'Store in a category', 'truncate' => 'Delete all articles', 'advanced' => 'Advanced', @@ -164,10 +165,11 @@ return array ( 'allow_anonymous' => 'Allow anonymous reading', 'auth_token' => 'Authentication token', 'explain_token' => 'Allows to access RSS output without authentication.
%s?token=%s', - 'archiving_configuration' => 'Archiving configuration', + 'login_configuration' => 'Login', + 'archiving_configuration' => 'Archiving', 'delete_articles_every' => 'Remove articles after', 'archiving_configuration_help' => 'More options are available in the individual stream settings', - 'reading_configuration' => 'Reading configuration', + 'reading_configuration' => 'Reading', 'articles_per_page' => 'Number of articles per page', 'default_view' => 'Default view', 'sort_order' => 'Sort order', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index b27f29940..053a97c8a 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -137,8 +137,9 @@ return array ( 'feed_url' => 'URL du flux', 'articles' => 'articles', 'number_articles' => 'Nombre d’articles', + 'by_feed' => 'par flux', + 'by_default' => 'Par défaut', 'keep_history' => 'Nombre minimum d’articles à conserver', - 'keep_history_help' => 'Mettre à -1 pour tout conserver', 'categorize' => 'Ranger dans une catégorie', 'truncate' => 'Supprimer tous les articles', 'advanced' => 'Avancé', @@ -165,10 +166,11 @@ return array ( 'allow_anonymous' => 'Autoriser la lecture anonyme', 'auth_token' => 'Jeton d’identification', 'explain_token' => 'Permet d’accéder à la sortie RSS sans besoin de s’authentifier.
%s?output=rss&token=%s', - 'archiving_configuration' => 'Configuration de l’archivage', + 'login_configuration' => 'Identification', + 'archiving_configuration' => 'Archivage', 'delete_articles_every' => 'Supprimer les articles après', 'archiving_configuration_help' => 'D’autres options sont disponibles dans la configuration individuelle des flux', - 'reading_configuration' => 'Configuration de lecture', + 'reading_configuration' => 'Lecture', 'articles_per_page' => 'Nombre d’articles par page', 'default_view' => 'Vue par défaut', 'sort_order' => 'Ordre de tri', diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 8995dc839..3280f657f 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -31,6 +31,15 @@
+
+
+ + +
+
+ + +
conf->mailLogin (); ?> @@ -61,22 +70,22 @@
- +

+
- - - - - - - - - - -
- + +
+
+
+ +
+
diff --git a/app/views/configure/feed.phtml b/app/views/configure/feed.phtml index 5940055ed..e738ab64f 100644 --- a/app/views/configure/feed.phtml +++ b/app/views/configure/feed.phtml @@ -52,6 +52,15 @@ +
+ +
+ +
+
@@ -78,16 +87,11 @@
- - - - - - - - - - +
@@ -97,24 +101,7 @@
- -
- -
- -
-
-
- -
- - -
-
- + flux->httpAuth (false); ?>
@@ -131,7 +118,24 @@
- + + +
+
+ + +
+ +
+ + +
+
+ +
+
+ +
diff --git a/public/install.php b/public/install.php index 3885f143e..13abb010b 100644 --- a/public/install.php +++ b/public/install.php @@ -33,7 +33,7 @@ define ('SQL_FEED', 'CREATE TABLE IF NOT EXISTS `%1$sfeed` ( `pathEntries` varchar(511) DEFAULT NULL, `httpAuth` varchar(511) DEFAULT NULL, `error` boolean DEFAULT 0, - `keep_history` MEDIUMINT NOT NULL DEFAULT 0, + `keep_history` MEDIUMINT NOT NULL DEFAULT -2, -- v0.7, -2 = default `cache_nbEntries` int DEFAULT 0, -- v0.7 `cache_nbUnreads` int DEFAULT 0, -- v0.7 PRIMARY KEY (`id`), @@ -93,7 +93,7 @@ FROM `%1$scategory006` ORDER BY id2; INSERT IGNORE INTO `%2$sfeed` (url, category, name, website, description, priority, pathEntries, httpAuth, keep_history) -SELECT url, category2, name, website, description, priority, pathEntries, httpAuth, -1 * keep_history +SELECT url, category2, name, website, description, priority, pathEntries, httpAuth, IF(keep_history = 1, -1, -2) FROM `%1$sfeed006` ORDER BY id2; diff --git a/public/themes/default/freshrss.css b/public/themes/default/freshrss.css index e3c4c3c3b..2b157b27a 100644 --- a/public/themes/default/freshrss.css +++ b/public/themes/default/freshrss.css @@ -667,6 +667,10 @@ padding:.5em; } +select.number option { + text-align:right; +} + @media(max-width: 840px) { .header, .aside .btn-important, diff --git a/public/themes/default/global.css b/public/themes/default/global.css index 1c554d2dc..440fc6e41 100644 --- a/public/themes/default/global.css +++ b/public/themes/default/global.css @@ -99,6 +99,9 @@ input, select, textarea { vertical-align: middle; box-shadow: 0 2px 2px #eee inset; } + option { + padding:0 .5em 0 .5em; + } input[type="radio"], input[type="checkbox"] { width: 15px !important; diff --git a/public/themes/flat-design/freshrss.css b/public/themes/flat-design/freshrss.css index fa1ed13e6..7e3f4c81a 100644 --- a/public/themes/flat-design/freshrss.css +++ b/public/themes/flat-design/freshrss.css @@ -662,6 +662,10 @@ body { padding:.5em; } +select.number option { + text-align:right; +} + @media(max-width: 840px) { .header, .aside .btn-important, diff --git a/public/themes/flat-design/global.css b/public/themes/flat-design/global.css index 8cf6412b3..90b59d002 100644 --- a/public/themes/flat-design/global.css +++ b/public/themes/flat-design/global.css @@ -101,6 +101,9 @@ input, select, textarea { vertical-align: middle; border-radius: 5px; } + option { + padding:0 .5em 0 .5em; + } input[type="radio"], input[type="checkbox"] { width: 15px !important; -- cgit v1.2.3 From 7eda2793bbc3210ae37aa66511fd7ad7661c2149 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 25 Dec 2013 19:53:09 +0100 Subject: Nouveau bouton pour lancer manuellement la purge des vieux articles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Attention, si on supprime des articles qui sont encore dans les flux RSS, ils risquent de réapparaitre en cas de date manquante ou erronée, ou si l'utilisateur augmente la date d'expiration. Ce bouton est plus strict que la purge automatique qui conserve toujours au moins le même nombre d'articles que dans le flux RSS en cours + 10. --- app/Controllers/entryController.php | 41 +++++++++++++++++++++++++++++++++++++ app/Controllers/feedController.php | 2 +- app/Models/FeedDAO.php | 27 +++++++++++++----------- app/i18n/en.php | 2 ++ app/i18n/fr.php | 2 ++ app/views/configure/display.phtml | 1 + 6 files changed, 62 insertions(+), 13 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index a332ca8a9..1c3c56c4d 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -109,4 +109,45 @@ class FreshRSS_entry_Controller extends Minz_ActionController { 'a' => 'display' ), true); } + + public function purgeAction() { + @set_time_limit(300); + + $nb_month_old = max($this->view->conf->oldEntries(), 1); + $date_min = time() - (3600 * 24 * 30 * $nb_month_old); + + $feedDAO = new FreshRSS_FeedDAO(); + $feeds = $feedDAO->listFeedsOrderUpdate(); + $nbTotal = 0; + + invalidateHttpCache(); + + foreach ($feeds as $feed) { + $feedHistory = $feed->keepHistory(); + if ($feedHistory == -2) { //default + $feedHistory = $this->view->conf->keepHistoryDefault(); + } + if ($feedHistory >= 0) { + $nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feedHistory); + if ($nb > 0) { + $nbTotal += $nb; + Minz_Log::record($nb . ' old entries cleaned in feed ' . $feed->id(), Minz_Log::DEBUG); + $feedDAO->updateLastUpdate($feed->id()); + } + } + } + + invalidateHttpCache(); + + $notif = array( + 'type' => 'good', + 'content' => Minz_Translate::t('purge_completed', $nbTotal) + ); + Minz_Session::_param('notification', $notif); + + Minz_Request::forward(array( + 'c' => 'configure', + 'a' => 'display' + ), true); + } } diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 836044da6..04d0aa98b 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -192,7 +192,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = $this->view->conf->oldEntries (); + $nb_month_old = max($this->view->conf->oldEntries(), 1); $date_min = time () - (3600 * 24 * 30 * $nb_month_old); $i = 0; diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index c1d1f24e8..d517f9580 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -315,20 +315,23 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { if (isset ($dao['id'])) { $key = $dao['id']; } + if ($catID === null) { + $catID = isset($dao['category']) ? $dao['category'] : 0; + } - $myFeed = new FreshRSS_Feed (isset($dao['url']) ? $dao['url'] : '', false); - $myFeed->_category ($catID === null ? $dao['category'] : $catID); - $myFeed->_name ($dao['name']); - $myFeed->_website ($dao['website'], false); - $myFeed->_description (isset($dao['description']) ? $dao['description'] : ''); - $myFeed->_lastUpdate (isset($dao['lastUpdate']) ? $dao['lastUpdate'] : 0); - $myFeed->_priority ($dao['priority']); - $myFeed->_pathEntries (isset($dao['pathEntries']) ? $dao['pathEntries'] : ''); - $myFeed->_httpAuth (isset($dao['httpAuth']) ? base64_decode ($dao['httpAuth']) : ''); - $myFeed->_error ($dao['error']); + $myFeed = new FreshRSS_Feed(isset($dao['url']) ? $dao['url'] : '', false); + $myFeed->_category(intval($catID)); + $myFeed->_name($dao['name']); + $myFeed->_website(isset($dao['website']) ? $dao['website'] : '', false); + $myFeed->_description(isset($dao['description']) ? $dao['description'] : ''); + $myFeed->_lastUpdate(isset($dao['lastUpdate']) ? $dao['lastUpdate'] : 0); + $myFeed->_priority(isset($dao['priority']) ? $dao['priority'] : 10); + $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->_nbNotRead ($dao['cache_nbUnreads']); - $myFeed->_nbEntries ($dao['cache_nbEntries']); + $myFeed->_nbNotRead(isset($dao['cache_nbUnreads']) ? $dao['cache_nbUnreads'] : 0); + $myFeed->_nbEntries(isset($dao['cache_nbEntries']) ? $dao['cache_nbEntries'] : 0); if (isset ($dao['id'])) { $myFeed->_id ($dao['id']); } diff --git a/app/i18n/en.php b/app/i18n/en.php index ca72d885c..498fccd14 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -168,6 +168,8 @@ return array ( 'login_configuration' => 'Login', 'archiving_configuration' => 'Archiving', 'delete_articles_every' => 'Remove articles after', + 'purge_now' => 'Purge now', + 'purge_completed' => 'Purge completed (%d articles deleted)', 'archiving_configuration_help' => 'More options are available in the individual stream settings', 'reading_configuration' => 'Reading', 'articles_per_page' => 'Number of articles per page', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 053a97c8a..c918daa44 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -169,6 +169,8 @@ return array ( 'login_configuration' => 'Identification', 'archiving_configuration' => 'Archivage', 'delete_articles_every' => 'Supprimer les articles après', + 'purge_now' => 'Purger maintenant', + 'purge_completed' => 'Purge effectuée (%d articles supprimés)', 'archiving_configuration_help' => 'D’autres options sont disponibles dans la configuration individuelle des flux', 'reading_configuration' => 'Lecture', 'articles_per_page' => 'Nombre d’articles par page', diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 3280f657f..fca533752 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -76,6 +76,7 @@
+  
-- cgit v1.2.3 From 574d37bddc4e00ddbc6af57c28838e1dea6a730b Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 26 Dec 2013 19:58:17 +0100 Subject: Favicons compatibles multi-utilisateurs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contribue à https://github.com/marienfressinaud/FreshRSS/issues/126 --- app/Controllers/feedController.php | 2 +- app/Models/CategoryDAO.php | 2 +- app/Models/Feed.php | 13 +++++++++---- lib/Minz/Configuration.php | 2 +- p/f.php | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 04d0aa98b..dc8a854a9 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -395,7 +395,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { 'type' => 'good', 'content' => Minz_Translate::t ('feed_deleted') ); - FreshRSS_Feed::faviconDelete($id); + //TODO: Delete old favicon } else { $notif = array ( 'type' => 'bad', diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 6b07ab063..1cc616ac0 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -90,7 +90,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { if ($prePopulateFeeds) { $sql = 'SELECT c.id AS c_id, c.name AS c_name, ' . ($details ? 'c.color AS c_color, ' : '') - . ($details ? 'f.* ' : 'f.id, f.name, f.website, f.priority, f.error, f.cache_nbEntries, f.cache_nbUnreads ') + . ($details ? 'f.* ' : 'f.id, f.name, f.url, f.website, f.priority, f.error, f.cache_nbEntries, f.cache_nbUnreads ') . 'FROM `' . $this->prefix . 'category` c ' . 'LEFT OUTER JOIN `' . $this->prefix . 'feed` f ON f.category = c.id ' . 'GROUP BY f.id ' diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 3008e33d7..f9a586122 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -28,6 +28,11 @@ class FreshRSS_Feed extends Minz_Model { public function id () { return $this->id; } + + public function hash() { + return hash('crc32b', Minz_Configuration::salt() . $this->url); + } + public function url () { return $this->url; } @@ -96,7 +101,7 @@ class FreshRSS_Feed extends Minz_Model { return $this->nbNotRead; } public function faviconPrepare() { - $file = DATA_PATH . '/favicons/' . $this->id () . '.txt'; + $file = DATA_PATH . '/favicons/' . $this->hash() . '.txt'; if (!file_exists ($file)) { $t = $this->website; if (empty($t)) { @@ -105,13 +110,13 @@ class FreshRSS_Feed extends Minz_Model { file_put_contents($file, $t); } } - public static function faviconDelete($id) { - $path = DATA_PATH . '/favicons/' . $id; + public static function faviconDelete($hash) { + $path = DATA_PATH . '/favicons/' . $hash; @unlink($path . '.ico'); @unlink($path . '.txt'); } public function favicon () { - return Minz_Url::display ('/f.php?' . $this->id ()); + return Minz_Url::display ('/f.php?' . $this->hash()); } public function _id ($value) { diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 1b108dcdf..6c7206988 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -63,7 +63,7 @@ class Minz_Configuration { /* * Getteurs */ - public static function selApplication () { + public static function salt () { return self::$sel_application; } public static function environment () { diff --git a/p/f.php b/p/f.php index a56d58617..872b8cc2c 100644 --- a/p/f.php +++ b/p/f.php @@ -37,7 +37,7 @@ function download_favicon ($website, $dest) { } $id = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '0'; -if (!ctype_digit($id)) { +if (!ctype_xdigit($id)) { $id = '0'; } -- cgit v1.2.3 From 43fd0a543900866f4feaf0713e1726b98a60b22d Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 26 Dec 2013 22:20:24 +0100 Subject: Mise à jour de f.url en base de données lorsque SimplePie découvre que l'adresse a changé MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Et correction problème favicon lorsque l'adresse du flux a changé du point de vue de SimplePie. Plus petites optimisations. --- app/Controllers/entryController.php | 2 +- app/Controllers/feedController.php | 27 ++++++++++----------------- app/Models/Feed.php | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 24 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 1c3c56c4d..26f3422ca 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -131,7 +131,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { $nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feedHistory); if ($nb > 0) { $nbTotal += $nb; - Minz_Log::record($nb . ' old entries cleaned in feed ' . $feed->id(), Minz_Log::DEBUG); + Minz_Log::record($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG); $feedDAO->updateLastUpdate($feed->id()); } } diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index dc8a854a9..ca230232f 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -20,15 +20,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $this->catDAO->checkDefault (); } - private static function entryDateComparer($e1, $e2) { - $d1 = $e1->date(true); - $d2 = $e2->date(true); - if ($d1 === $d2) { - return 0; - } - return ($d1 < $d2) ? -1 : 1; - } - public function addAction () { @set_time_limit(300); @@ -55,7 +46,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } $feed->_httpAuth ($httpAuth); - $feed->load (); + $feed->load(true); $feedDAO = new FreshRSS_FeedDAO (); $values = array ( @@ -91,8 +82,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0; $entryDAO = new FreshRSS_EntryDAO (); - $entries = $feed->entries (); - usort($entries, 'self::entryDateComparer'); + $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order // on calcule la date des articles les plus anciens qu'on accepte $nb_month_old = $this->view->conf->oldEntries (); @@ -199,10 +189,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $flux_update = 0; foreach ($feeds as $feed) { try { - $feed->load (); - $feed->faviconPrepare(); - $entries = $feed->entries (); - usort($entries, 'self::entryDateComparer'); + $url = $feed->url(); + $feed->load(false); + $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order $is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0; @@ -231,7 +220,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if (($feedHistory >= 0) && (rand(0, 30) === 1)) { $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feedHistory, count($entries) + 10)); if ($nb > 0) { - Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG); + Minz_Log::record ($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG); } } @@ -239,6 +228,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feedDAO->updateLastUpdate ($feed->id ()); $feedDAO->commit (); $flux_update++; + if ($feed->url() !== $url) { //URL has changed (auto-discovery) + $feedDAO->updateFeed($feed->id(), array('url' => $feed->url())); + } + $feed->faviconPrepare(); } catch (FreshRSS_Feed_Exception $e) { Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); $feedDAO->updateLastUpdate ($feed->id (), 1); diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 4f90b9872..0f467f776 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -16,6 +16,7 @@ class FreshRSS_Feed extends Minz_Model { private $httpAuth = ''; private $error = false; private $keep_history = -2; + private $hash = null; public function __construct ($url, $validate=true) { if ($validate) { @@ -30,7 +31,10 @@ class FreshRSS_Feed extends Minz_Model { } public function hash() { - return hash('crc32b', Minz_Configuration::salt() . $this->url); + if ($this->hash === null) { + $this->hash = hash('crc32b', Minz_Configuration::salt() . $this->url); + } + return $this->hash; } public function url () { @@ -184,7 +188,7 @@ class FreshRSS_Feed extends Minz_Model { $this->nbEntries = intval($value); } - public function load () { + public function load ($loadDetails = false) { if (!is_null ($this->url)) { if (CACHE_PATH === false) { throw new Minz_FileNotExistException ( @@ -256,11 +260,13 @@ class FreshRSS_Feed extends Minz_Model { $this->_url ($subscribe_url); } - $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8'); - $this->_name (!is_null ($title) ? $title : $this->url); + if ($loadDetails) { + $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8'); + $this->_name (!is_null ($title) ? $title : $this->url); - $this->_website(html_only_entity_decode($feed->get_link())); - $this->_description(html_only_entity_decode($feed->get_description())); + $this->_website(html_only_entity_decode($feed->get_link())); + $this->_description(html_only_entity_decode($feed->get_description())); + } // et on charge les articles du flux $this->loadEntries ($feed); -- cgit v1.2.3 From badc60910a21774512034027bbb394ffeb477629 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 27 Dec 2013 15:16:53 +0100 Subject: Petites corrections et sortie 0.7-beta3 --- app/Controllers/feedController.php | 12 ++++++------ p/i/install.php | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index ca230232f..a3371a43e 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -198,12 +198,17 @@ class FreshRSS_feed_Controller extends Minz_ActionController { //For this feed, check last n entry GUIDs already in database $existingGuids = array_fill_keys ($entryDAO->listLastGuidsByFeed ($feed->id (), count($entries) + 10), 1); + $feedHistory = $feed->keepHistory(); + if ($feedHistory == -2) { //default + $feedHistory = $this->view->conf->keepHistoryDefault(); + } + // On ne vérifie pas strictement que l'article n'est pas déjà en BDD // La BDD refusera l'ajout car (id_feed, guid) doit être unique $feedDAO->beginTransaction (); foreach ($entries as $entry) { if ((!isset ($existingGuids[$entry->guid ()])) && - ($entry->date (true) >= $date_min)) { + (($feedHistory != 0) || ($entry->date (true) >= $date_min))) { $values = $entry->toArray (); //Use declared date at first import, otherwise use discovery date $values['id'] = empty($existingGuids) ? min(time(), $entry->date (true)) . uSecString() : uTimeString(); @@ -212,11 +217,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } - $feedHistory = $feed->keepHistory(); - if ($feedHistory == -2) { //default - $feedHistory = $this->view->conf->keepHistoryDefault(); - } - if (($feedHistory >= 0) && (rand(0, 30) === 1)) { $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feedHistory, count($entries) + 10)); if ($nb > 0) { diff --git a/p/i/install.php b/p/i/install.php index 0e8a972c6..132cd5508 100644 --- a/p/i/install.php +++ b/p/i/install.php @@ -573,7 +573,7 @@ function checkStep2 () { if ($defaultUser === null) { $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user']; } - $data = file_exists (DATA_PATH . '/' . $defaultUser . '_user.php'); + $data = is_writable(DATA_PATH . '/' . $defaultUser . '_user.php'); if ($data) { @unlink(DATA_PATH . '/Configuration.array.php'); //v0.6 } @@ -585,7 +585,7 @@ function checkStep2 () { ); } function checkStep3 () { - $conf = file_exists (DATA_PATH . '/config.php'); + $conf = is_writable(DATA_PATH . '/config.php'); $bd = isset ($_SESSION['bd_type']) && isset ($_SESSION['bd_host']) && -- cgit v1.2.3 From a1249e56a7151ea20f64ac3091c0a3383d21049c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 27 Dec 2013 16:24:40 +0100 Subject: Petit changement utilisation de la date déclarée des articles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 2 +- app/Controllers/feedController.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/CHANGELOG b/CHANGELOG index 9d91544c4..108e29195 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -62,7 +62,7 @@ * Utilise un nom poli “FreshRSS” (évite des problèmes avec certains filtres) * Se limite au répertoire “./FreshRSS/p/i/” pour de meilleures performances HTTP * Les images, CSS, scripts sont servis sans cookie - * utilise “HttpOnly” pour plus de sécurité + * Utilise “HttpOnly” pour plus de sécurité * Nouvel “agent utilisateur” exposé lors du téléchargement des flux, par exemple : * “FreshRSS/0.7 (Linux; http://freshrss.org) SimplePie/1.3.1” * Affichage du numéro de version dans "À propos" diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index a3371a43e..77d36e977 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -197,6 +197,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { //For this feed, check last n entry GUIDs already in database $existingGuids = array_fill_keys ($entryDAO->listLastGuidsByFeed ($feed->id (), count($entries) + 10), 1); + $useDeclaredDate = empty($existingGuids); $feedHistory = $feed->keepHistory(); if ($feedHistory == -2) { //default @@ -207,11 +208,14 @@ class FreshRSS_feed_Controller extends Minz_ActionController { // La BDD refusera l'ajout car (id_feed, guid) doit être unique $feedDAO->beginTransaction (); foreach ($entries as $entry) { + $eDate = $entry->date (true); if ((!isset ($existingGuids[$entry->guid ()])) && - (($feedHistory != 0) || ($entry->date (true) >= $date_min))) { + (($feedHistory != 0) || ($eDate >= $date_min))) { $values = $entry->toArray (); //Use declared date at first import, otherwise use discovery date - $values['id'] = empty($existingGuids) ? min(time(), $entry->date (true)) . uSecString() : uTimeString(); + $values['id'] = ($useDeclaredDate || $eDate < $date_min) ? + min(time(), $eDate) . uSecString() : + uTimeString(); $values['is_read'] = $is_read; $entryDAO->addEntry ($values); } -- cgit v1.2.3 From 96bdbafceac44af2159e6b80d3d403e0608991d9 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 28 Dec 2013 23:09:39 +0100 Subject: Refactorisation FreshRSS_Configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implémente https://github.com/marienfressinaud/FreshRSS/issues/260 (évite les comparaisons de chaînes au profit des vrais booléens et entiers) Grosse simplification et réduction du code relatif à la configuration. Supprime ConfigurationDAO. Permet de simplifier considérablement configureController. Évite de multiples copies des mêmes données en mémoire. Évite de garder plusieurs versions de la configuration en mémoire (auparavant : dans un tableau au niveau de ModelArray + au niveau de FreshRSS_Configuration + en Session + des copies temporaires comme ConfigurationDAO). Ne stocke plus 'conf' en Session (n'était presque pas utilisé). Évite de recharger plusieurs fois Translate inutilement. Contribue à https://github.com/marienfressinaud/FreshRSS/issues/303 --- app/Controllers/configureController.php | 194 ++++----------- app/Controllers/entryController.php | 4 +- app/Controllers/feedController.php | 15 +- app/Controllers/indexController.php | 14 +- app/FreshRSS.php | 17 +- app/Models/Configuration.php | 397 ++++++++++++------------------- app/Models/ConfigurationDAO.php | 154 ------------ app/i18n/en.php | 2 +- app/i18n/fr.php | 2 +- app/layout/layout.phtml | 2 +- app/layout/nav_menu.phtml | 2 +- app/views/configure/archiving.phtml | 8 +- app/views/configure/display.phtml | 62 ++--- app/views/configure/sharing.phtml | 2 +- app/views/configure/shortcut.phtml | 2 +- app/views/configure/users.phtml | 6 +- app/views/helpers/javascript_vars.phtml | 18 +- app/views/helpers/view/global_view.phtml | 4 +- app/views/helpers/view/normal_view.phtml | 24 +- app/views/helpers/view/reader_view.phtml | 2 +- app/views/index/index.phtml | 2 +- lib/Minz/Configuration.php | 4 +- lib/Minz/ModelArray.php | 20 +- lib/Minz/Session.php | 6 +- lib/lib_rss.php | 2 +- 25 files changed, 311 insertions(+), 654 deletions(-) delete mode 100644 app/Models/ConfigurationDAO.php (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index f458cddf1..aabc3e4af 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -52,7 +52,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController { } } - // notif $notif = array ( 'type' => 'good', 'content' => Minz_Translate::t ('categories_updated') @@ -139,94 +138,40 @@ class FreshRSS_configure_Controller extends Minz_ActionController { } public function displayAction () { - if (Minz_Request::isPost ()) { - $current_token = $this->view->conf->token (); - - $language = Minz_Request::param ('language', 'en'); - $nb = Minz_Request::param ('posts_per_page', 10); - $mode = Minz_Request::param ('view_mode', 'normal'); - $view = Minz_Request::param ('default_view', 'a'); - $auto_load_more = Minz_Request::param ('auto_load_more', 'no'); - $display = Minz_Request::param ('display_posts', 'no'); - $onread_jump_next = Minz_Request::param ('onread_jump_next', 'no'); - $lazyload = Minz_Request::param ('lazyload', 'no'); - $sort = Minz_Request::param ('sort_order', 'DESC'); - $openArticle = Minz_Request::param ('mark_open_article', 'no'); - $openSite = Minz_Request::param ('mark_open_site', 'no'); - $scroll = Minz_Request::param ('mark_scroll', 'no'); - $reception = Minz_Request::param ('mark_upon_reception', 'no'); - $theme = Minz_Request::param ('theme', 'default'); - $topline_read = Minz_Request::param ('topline_read', 'no'); - $topline_favorite = Minz_Request::param ('topline_favorite', 'no'); - $topline_date = Minz_Request::param ('topline_date', 'no'); - $topline_link = Minz_Request::param ('topline_link', 'no'); - $bottomline_read = Minz_Request::param ('bottomline_read', 'no'); - $bottomline_favorite = Minz_Request::param ('bottomline_favorite', 'no'); - $bottomline_sharing = Minz_Request::param ('bottomline_sharing', 'no'); - $bottomline_tags = Minz_Request::param ('bottomline_tags', 'no'); - $bottomline_date = Minz_Request::param ('bottomline_date', 'no'); - $bottomline_link = Minz_Request::param ('bottomline_link', 'no'); - - $this->view->conf->_language ($language); - $this->view->conf->_postsPerPage ($nb); - $this->view->conf->_viewMode ($mode); - $this->view->conf->_defaultView ($view); - $this->view->conf->_autoLoadMore ($auto_load_more); - $this->view->conf->_displayPosts ($display); - $this->view->conf->_onread_jump_next ($onread_jump_next); - $this->view->conf->_lazyload ($lazyload); - $this->view->conf->_sortOrder ($sort); - $this->view->conf->_markWhen (array ( - 'article' => $openArticle, - 'site' => $openSite, - 'scroll' => $scroll, - 'reception' => $reception, + if (Minz_Request::isPost()) { + $this->view->conf->_language(Minz_Request::param('language', 'en')); + $this->view->conf->_posts_per_page(Minz_Request::param('posts_per_page', 10)); + $this->view->conf->_view_mode(Minz_Request::param('view_mode', 'normal')); + $this->view->conf->_default_view (Minz_Request::param('default_view', 'a')); + $this->view->conf->_auto_load_more(Minz_Request::param('auto_load_more', false)); + $this->view->conf->_display_posts(Minz_Request::param('display_posts', false)); + $this->view->conf->_onread_jump_next(Minz_Request::param('onread_jump_next', false)); + $this->view->conf->_lazyload (Minz_Request::param('lazyload', false)); + $this->view->conf->_sort_order(Minz_Request::param('sort_order', 'DESC')); + $this->view->conf->_mark_when (array( + 'article' => Minz_Request::param('mark_open_article', false), + 'site' => Minz_Request::param('mark_open_site', false), + 'scroll' => Minz_Request::param('mark_scroll', false), + 'reception' => Minz_Request::param('mark_upon_reception', false), )); - $this->view->conf->_theme ($theme); - $this->view->conf->_topline_read ($topline_read); - $this->view->conf->_topline_favorite ($topline_favorite); - $this->view->conf->_topline_date ($topline_date); - $this->view->conf->_topline_link ($topline_link); - $this->view->conf->_bottomline_read ($bottomline_read); - $this->view->conf->_bottomline_favorite ($bottomline_favorite); - $this->view->conf->_bottomline_sharing ($bottomline_sharing); - $this->view->conf->_bottomline_tags ($bottomline_tags); - $this->view->conf->_bottomline_date ($bottomline_date); - $this->view->conf->_bottomline_link ($bottomline_link); - - $values = array ( - 'language' => $this->view->conf->language (), - 'posts_per_page' => $this->view->conf->postsPerPage (), - 'view_mode' => $this->view->conf->viewMode (), - 'default_view' => $this->view->conf->defaultView (), - 'auto_load_more' => $this->view->conf->autoLoadMore (), - 'display_posts' => $this->view->conf->displayPosts (), - 'onread_jump_next' => $this->view->conf->onread_jump_next (), - 'lazyload' => $this->view->conf->lazyload (), - 'sort_order' => $this->view->conf->sortOrder (), - 'mark_when' => $this->view->conf->markWhen (), - 'theme' => $this->view->conf->theme (), - 'topline_read' => $this->view->conf->toplineRead () ? 'yes' : 'no', - 'topline_favorite' => $this->view->conf->toplineFavorite () ? 'yes' : 'no', - 'topline_date' => $this->view->conf->toplineDate () ? 'yes' : 'no', - 'topline_link' => $this->view->conf->toplineLink () ? 'yes' : 'no', - 'bottomline_read' => $this->view->conf->bottomlineRead () ? 'yes' : 'no', - 'bottomline_favorite' => $this->view->conf->bottomlineFavorite () ? 'yes' : 'no', - 'bottomline_sharing' => $this->view->conf->bottomlineSharing () ? 'yes' : 'no', - 'bottomline_tags' => $this->view->conf->bottomlineTags () ? 'yes' : 'no', - 'bottomline_date' => $this->view->conf->bottomlineDate () ? 'yes' : 'no', - 'bottomline_link' => $this->view->conf->bottomlineLink () ? 'yes' : 'no', - ); - - $confDAO = new FreshRSS_ConfigurationDAO (); - $confDAO->update ($values); - Minz_Session::_param ('conf', $this->view->conf); - Minz_Session::_param ('mail', $this->view->conf->mailLogin ()); - - Minz_Session::_param ('language', $this->view->conf->language ()); + $this->view->conf->_theme(Minz_Request::param('theme', 'default')); + $this->view->conf->_topline_read(Minz_Request::param('topline_read', false)); + $this->view->conf->_topline_favorite(Minz_Request::param('topline_favorite', false)); + $this->view->conf->_topline_date(Minz_Request::param('topline_date', false)); + $this->view->conf->_topline_link(Minz_Request::param('topline_link', false)); + $this->view->conf->_bottomline_read(Minz_Request::param('bottomline_read', false)); + $this->view->conf->_bottomline_favorite(Minz_Request::param('bottomline_favorite', false)); + $this->view->conf->_bottomline_sharing(Minz_Request::param('bottomline_sharing', false)); + $this->view->conf->_bottomline_tags(Minz_Request::param('bottomline_tags', false)); + $this->view->conf->_bottomline_date(Minz_Request::param('bottomline_date', false)); + $this->view->conf->_bottomline_link(Minz_Request::param('bottomline_link', false)); + $this->view->conf->save(); + + Minz_Session::_param ('mail', $this->view->conf->mail_login); + + Minz_Session::_param ('language', $this->view->conf->language); Minz_Translate::reset (); - // notif $notif = array ( 'type' => 'good', 'content' => Minz_Translate::t ('configuration_updated') @@ -243,22 +188,18 @@ class FreshRSS_configure_Controller extends Minz_ActionController { public function sharingAction () { if (Minz_Request::isPost ()) { - $this->view->conf->_sharing (array ( - 'shaarli' => Minz_Request::param ('shaarli', ''), - 'poche' => Minz_Request::param ('poche', ''), - 'diaspora' => Minz_Request::param ('diaspora', ''), - 'twitter' => Minz_Request::param ('twitter', 'no') === 'yes', - 'g+' => Minz_Request::param ('g+', 'no') === 'yes', - 'facebook' => Minz_Request::param ('facebook', 'no') === 'yes', - 'email' => Minz_Request::param ('email', 'no') === 'yes', - 'print' => Minz_Request::param ('print', 'no') === 'yes' + $this->view->conf->_sharing (array( + 'shaarli' => Minz_Request::param ('shaarli', false), + 'poche' => Minz_Request::param ('poche', false), + 'diaspora' => Minz_Request::param ('diaspora', false), + 'twitter' => Minz_Request::param ('twitter', false), + 'g+' => Minz_Request::param ('g+', false), + 'facebook' => Minz_Request::param ('facebook', false), + 'email' => Minz_Request::param ('email', false), + 'print' => Minz_Request::param ('print', false), )); + $this->view->conf->save(); - $confDAO = new FreshRSS_ConfigurationDAO (); - $confDAO->update ($this->view->conf->sharing ()); - Minz_Session::_param ('conf', $this->view->conf); - - // notif $notif = array ( 'type' => 'good', 'content' => Minz_Translate::t ('configuration_updated') @@ -269,9 +210,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController { } Minz_View::prependTitle (Minz_Translate::t ('sharing_management') . ' - '); - - $entryDAO = new FreshRSS_EntryDAO (); - $this->view->nb_total = $entryDAO->count (); } public function importExportAction () { @@ -347,32 +285,20 @@ class FreshRSS_configure_Controller extends Minz_ActionController { '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12'); $this->view->list_keys = $list_keys; - $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry', - 'prev_entry', 'next_page', 'prev_page', 'collapse_entry', - 'load_more'); if (Minz_Request::isPost ()) { $shortcuts = Minz_Request::param ('shortcuts'); $shortcuts_ok = array (); foreach ($shortcuts as $key => $value) { - if (in_array ($key, $list_names) - && in_array ($value, $list_keys)) { + if (in_array($value, $list_keys)) { $shortcuts_ok[$key] = $value; } } $this->view->conf->_shortcuts ($shortcuts_ok); + $this->view->conf->save(); - $values = array ( - 'shortcuts' => $this->view->conf->shortcuts () - ); - - $confDAO = new FreshRSS_ConfigurationDAO (); - $confDAO->update ($values); - Minz_Session::_param ('conf', $this->view->conf); - - // notif $notif = array ( 'type' => 'good', 'content' => Minz_Translate::t ('shortcuts_updated') @@ -388,26 +314,20 @@ class FreshRSS_configure_Controller extends Minz_ActionController { public function usersAction() { if (Minz_Request::isPost()) { $ok = true; - $current_token = $this->view->conf->token(); + $current_token = $this->view->conf->token; $mail = Minz_Request::param('mail_login', false); $token = Minz_Request::param('token', $current_token); - $this->view->conf->_mailLogin($mail); + $this->view->conf->_mail_login($mail); $this->view->conf->_token($token); + $ok &= $this->view->conf->save(); - $values = array( - 'mail_login' => $this->view->conf->mailLogin(), - 'token' => $this->view->conf->token(), - ); - - $confDAO = new FreshRSS_ConfigurationDAO(); - $ok &= $confDAO->update($values); - Minz_Session::_param('conf', $this->view->conf); - Minz_Session::_param('mail', $this->view->conf->mailLogin()); + Minz_Session::_param('mail', $this->view->conf->mail_login); if (Minz_Configuration::isAdmin()) { - $anon = (bool)(Minz_Request::param('anon_access', false)); + $anon = (Minz_Request::param('anon_access', false)); + $anon = ((bool)$anon) && ($anon !== 'no'); if ($anon != Minz_Configuration::allowAnonymous()) { Minz_Configuration::_allowAnonymous($anon); $ok &= Minz_Configuration::writeFile(); @@ -432,20 +352,10 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $old = Minz_Request::param('old_entries', 3); $keepHistoryDefault = Minz_Request::param('keep_history_default', 0); - $this->view->conf->_oldEntries($old); - $this->view->conf->_keepHistoryDefault($keepHistoryDefault); - - $values = array( - 'old_entries' => $this->view->conf->oldEntries(), - 'keep_history_default' => $this->view->conf->keepHistoryDefault(), - ); - - $confDAO = new FreshRSS_ConfigurationDAO(); - $confDAO->update($values); - Minz_Session::_param('conf', $this->view->conf); - Minz_Session::_param('mail', $this->view->conf->mailLogin ()); + $this->view->conf->_old_entries($old); + $this->view->conf->_keep_history_default($keepHistoryDefault); + $this->view->conf->save(); - // notif $notif = array( 'type' => 'good', 'content' => Minz_Translate::t('configuration_updated') diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 9b5081894..b0fc37cdf 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -113,7 +113,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { public function purgeAction() { @set_time_limit(300); - $nb_month_old = max($this->view->conf->oldEntries(), 1); + $nb_month_old = max($this->view->conf->old_entries, 1); $date_min = time() - (3600 * 24 * 30 * $nb_month_old); $feedDAO = new FreshRSS_FeedDAO(); @@ -125,7 +125,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { foreach ($feeds as $feed) { $feedHistory = $feed->keepHistory(); if ($feedHistory == -2) { //default - $feedHistory = $this->view->conf->keepHistoryDefault(); + $feedHistory = $this->view->conf->keep_history_default; } if ($feedHistory >= 0) { $nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feedHistory); diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 77d36e977..42a0dcb11 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -2,7 +2,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { public function firstAction () { - $token = $this->view->conf->token(); + $token = $this->view->conf->token; $token_param = Minz_Request::param ('token', ''); $token_is_ok = ($token != '' && $token == $token_param); $action = Minz_Request::actionName (); @@ -79,13 +79,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feed->_id ($id); $feed->faviconPrepare(); - $is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0; + $is_read = $this->view->conf->mark_when['reception'] ? 1 : 0; $entryDAO = new FreshRSS_EntryDAO (); $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = $this->view->conf->oldEntries (); + $nb_month_old = $this->view->conf->old_entries; $date_min = time () - (3600 * 24 * 30 * $nb_month_old); $transactionStarted = true; @@ -182,26 +182,25 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = max($this->view->conf->oldEntries(), 1); + $nb_month_old = max($this->view->conf->old_entries, 1); $date_min = time () - (3600 * 24 * 30 * $nb_month_old); $i = 0; $flux_update = 0; + $is_read = $this->view->conf->mark_when['reception'] ? 1 : 0; foreach ($feeds as $feed) { try { $url = $feed->url(); $feed->load(false); $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order - $is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0; - //For this feed, check last n entry GUIDs already in database $existingGuids = array_fill_keys ($entryDAO->listLastGuidsByFeed ($feed->id (), count($entries) + 10), 1); $useDeclaredDate = empty($existingGuids); $feedHistory = $feed->keepHistory(); if ($feedHistory == -2) { //default - $feedHistory = $this->view->conf->keepHistoryDefault(); + $feedHistory = $this->view->conf->keep_history_default; } // On ne vérifie pas strictement que l'article n'est pas déjà en BDD @@ -309,7 +308,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $this->addCategories ($categories); // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = $this->view->conf->oldEntries (); + $nb_month_old = $this->view->conf->old_entries; $date_min = time () - (3600 * 24 * 30 * $nb_month_old); // la variable $error permet de savoir si une erreur est survenue diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 4677787c1..54826636f 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -17,7 +17,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { public function indexAction () { $output = Minz_Request::param ('output'); - $token = $this->view->conf->token(); + $token = $this->view->conf->token; $token_param = Minz_Request::param ('token', ''); $token_is_ok = ($token != '' && $token === $token_param); @@ -91,13 +91,13 @@ class FreshRSS_index_Controller extends Minz_ActionController { ); // On récupère les différents éléments de filtrage - $this->view->state = $state = Minz_Request::param ('state', $this->view->conf->defaultView ()); + $this->view->state = $state = Minz_Request::param ('state', $this->view->conf->default_view); $filter = Minz_Request::param ('search', ''); if (!empty($filter)) { $state = 'all'; //Search always in read and unread articles } - $this->view->order = $order = Minz_Request::param ('order', $this->view->conf->sortOrder ()); - $nb = Minz_Request::param ('nb', $this->view->conf->postsPerPage ()); + $this->view->order = $order = Minz_Request::param ('order', $this->view->conf->sort_order); + $nb = Minz_Request::param ('nb', $this->view->conf->posts_per_page); $first = Minz_Request::param ('next', ''); if ($state === 'not_read') { //Any unread article in this category at all? @@ -128,9 +128,9 @@ class FreshRSS_index_Controller extends Minz_ActionController { $this->view->today = $today; // on calcule la date des articles les plus anciens qu'on affiche - $nb_month_old = $this->view->conf->oldEntries (); + $nb_month_old = $this->view->conf->old_entries; $date_min = $today - (3600 * 24 * 30 * $nb_month_old); //Do not use a fast changing value such as time() to allow SQL caching - $keepHistoryDefault = $this->view->conf->keepHistoryDefault(); + $keepHistoryDefault = $this->view->conf->keep_history_default; try { $entries = $this->entryDAO->listWhere($getType, $getId, $state, $order, $nb + 1, $first, $filter, $date_min, $keepHistoryDefault); @@ -253,7 +253,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { curl_close ($ch); $res = json_decode ($result, true); - if ($res['status'] === 'okay' && $res['email'] === $this->view->conf->mailLogin ()) { + if ($res['status'] === 'okay' && $res['email'] === $this->view->conf->mail_login) { Minz_Session::_param ('mail', $res['email']); invalidateHttpCache(); } else { diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 60610e352..05c8ec8e0 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -2,7 +2,6 @@ class FreshRSS extends Minz_FrontController { public function init () { Minz_Session::init ('FreshRSS'); - Minz_Translate::init (); $this->loadParamsView (); $this->loadStylesAndScripts (); @@ -11,26 +10,26 @@ class FreshRSS extends Minz_FrontController { private function loadParamsView () { try { - $this->conf = Minz_Session::param ('conf', new FreshRSS_Configuration ()); + $this->conf = new FreshRSS_Configuration(); } catch (Minz_Exception $e) { // Permission denied or conf file does not exist // it's critical! - print $e->getMessage(); - exit(); + die($e->getMessage()); } Minz_View::_param ('conf', $this->conf); - Minz_Session::_param ('language', $this->conf->language ()); + Minz_Session::_param ('language', $this->conf->language); + Minz_Translate::init(); $output = Minz_Request::param ('output'); - if(!$output) { - $output = $this->conf->viewMode(); + if (!$output) { + $output = $this->conf->view_mode; Minz_Request::_param ('output', $output); } } private function loadStylesAndScripts () { - $theme = FreshRSS_Themes::get_infos($this->conf->theme()); + $theme = FreshRSS_Themes::get_infos($this->conf->theme); if ($theme) { foreach($theme["files"] as $file) { Minz_View::appendStyle (Minz_Url::display ('/themes/' . $theme['path'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file))); @@ -40,7 +39,7 @@ class FreshRSS extends Minz_FrontController { if (login_is_conf ($this->conf)) { Minz_View::appendScript ('https://login.persona.org/include.js'); } - $includeLazyLoad = $this->conf->lazyload () === 'yes' && ($this->conf->displayPosts () === 'yes' || Minz_Request::param ('output') === 'reader'); + $includeLazyLoad = $this->conf->lazyload && ($this->conf->display_posts || Minz_Request::param ('output') === 'reader'); Minz_View::appendScript (Minz_Url::display ('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')), false, !$includeLazyLoad, !$includeLazyLoad); if ($includeLazyLoad) { Minz_View::appendScript (Minz_Url::display ('/scripts/jquery.lazyload.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.lazyload.min.js'))); diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index 7f4be474d..b0a5d9940 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -1,258 +1,171 @@ 'en', + 'old_entries' => 3, + 'keep_history_default' => 0, + 'mail_login' => '', + 'token' => '', + 'posts_per_page' => 20, + 'view_mode' => 'normal', + 'default_view' => 'not_read', + 'auto_load_more' => true, + 'display_posts' => false, + 'onread_jump_next' => true, + 'lazyload' => true, + 'sort_order' => 'DESC', + 'anon_access' => false, + 'mark_when' => array( + 'article' => true, + 'site' => true, + 'scroll' => false, + 'reception' => false, + ), + 'theme' => 'default', + 'shortcuts' => array( + 'mark_read' => 'r', + 'mark_favorite' => 'f', + 'go_website' => 'space', + 'next_entry' => 'j', + 'prev_entry' => 'k', + 'collapse_entry' => 'c', + 'load_more' => 'm', + ), + 'topline_read' => true, + 'topline_favorite' => true, + 'topline_date' => true, + 'topline_link' => true, + 'bottomline_read' => true, + 'bottomline_favorite' => true, + 'bottomline_sharing' => true, + 'bottomline_tags' => true, + 'bottomline_date' => true, + 'bottomline_link' => true, + 'sharing' => array( + 'shaarli' => '', + 'poche' => '', + 'diaspora' => '', + 'twitter' => true, + 'g+' => true, + 'facebook' => true, + 'email' => true, + 'print' => true, + ), + ); + + private $available_languages = array( 'en' => 'English', 'fr' => 'Français', ); - private $language; - private $posts_per_page; - private $view_mode; - private $default_view; - private $display_posts; - private $onread_jump_next; - private $lazyload; - private $sort_order; - private $old_entries; - private $keep_history_default; - private $shortcuts = array (); - private $mail_login = ''; - private $mark_when = array (); - private $sharing = array (); - private $theme; - private $token; - private $auto_load_more; - private $topline_read; - private $topline_favorite; - private $topline_date; - private $topline_link; - private $bottomline_read; - private $bottomline_favorite; - private $bottomline_sharing; - private $bottomline_tags; - private $bottomline_date; - private $bottomline_link; - public function __construct () { - $confDAO = new FreshRSS_ConfigurationDAO (); - $this->_language ($confDAO->language); - $this->_postsPerPage ($confDAO->posts_per_page); - $this->_viewMode ($confDAO->view_mode); - $this->_defaultView ($confDAO->default_view); - $this->_displayPosts ($confDAO->display_posts); - $this->_onread_jump_next ($confDAO->onread_jump_next); - $this->_lazyload ($confDAO->lazyload); - $this->_sortOrder ($confDAO->sort_order); - $this->_oldEntries ($confDAO->old_entries); - $this->_keepHistoryDefault($confDAO->keep_history_default); - $this->_shortcuts ($confDAO->shortcuts); - $this->_mailLogin ($confDAO->mail_login); - $this->_markWhen ($confDAO->mark_when); - $this->_sharing ($confDAO->sharing); - $this->_theme ($confDAO->theme); - FreshRSS_Themes::setThemeId ($confDAO->theme); - $this->_token ($confDAO->token); - $this->_autoLoadMore ($confDAO->auto_load_more); - $this->_topline_read ($confDAO->topline_read); - $this->_topline_favorite ($confDAO->topline_favorite); - $this->_topline_date ($confDAO->topline_date); - $this->_topline_link ($confDAO->topline_link); - $this->_bottomline_read ($confDAO->bottomline_read); - $this->_bottomline_favorite ($confDAO->bottomline_favorite); - $this->_bottomline_sharing ($confDAO->bottomline_sharing); - $this->_bottomline_tags ($confDAO->bottomline_tags); - $this->_bottomline_date ($confDAO->bottomline_date); - $this->_bottomline_link ($confDAO->bottomline_link); - } + public function __construct ($filename = '') { + if (empty($filename)) { + $filename = DATA_PATH . '/' . Minz_Configuration::currentUser () . '_user.php'; + } + parent::__construct($filename); + $data = parent::loadArray(); - public function availableLanguages () { - return $this->available_languages; - } - public function language () { - return $this->language; - } - public function postsPerPage () { - return $this->posts_per_page; - } - public function viewMode () { - return $this->view_mode; - } - public function defaultView () { - return $this->default_view; - } - public function displayPosts () { - return $this->display_posts; - } - public function onread_jump_next () { - return $this->onread_jump_next; - } - public function lazyload () { - return $this->lazyload; - } - public function sortOrder () { - return $this->sort_order; - } - public function oldEntries () { - return $this->old_entries; - } - public function keepHistoryDefault() { - return $this->keep_history_default; - } - public function shortcuts () { - return $this->shortcuts; - } - public function mailLogin () { - return $this->mail_login; - } - public function markWhen () { - return $this->mark_when; - } - public function markWhenArticle () { - return $this->mark_when['article']; - } - public function markWhenSite () { - return $this->mark_when['site']; + foreach ($data as $key => $value) { + if (isset($this->data[$key])) { + $function = '_' . $key; + $this->$function($value); + } + } } - public function markWhenScroll () { - return $this->mark_when['scroll']; + + public function save() { + invalidateHttpCache(); + return parent::writeArray($this->data); } - public function markUponReception () { - return $this->mark_when['reception']; + + public function __get($name) { + if (array_key_exists($name, $this->data)) { + return $this->data[$name]; + } else { + $trace = debug_backtrace(); + trigger_error('Undefined FreshRSS_Configuration->' . $name . 'in ' . $trace[0]['file'] . ' line ' . $trace[0]['line'], E_USER_NOTICE); //TODO: Use Minz exceptions + return null; + } } - public function sharing ($key = false) { + + public function sharing($key = false) { if ($key === false) { - return $this->sharing; - } elseif (isset ($this->sharing[$key])) { - return $this->sharing[$key]; + return $this->data['sharing']; + } + if (isset($this->data['sharing'][$key])) { + return $this->data['sharing'][$key]; } return false; } - public function theme () { - return $this->theme; - } - public function token () { - return $this->token; - } - public function autoLoadMore () { - return $this->auto_load_more; - } - public function toplineRead () { - return $this->topline_read; - } - public function toplineFavorite () { - return $this->topline_favorite; - } - public function toplineDate () { - return $this->topline_date; - } - public function toplineLink () { - return $this->topline_link; - } - public function bottomlineRead () { - return $this->bottomline_read; - } - public function bottomlineFavorite () { - return $this->bottomline_favorite; - } - public function bottomlineSharing () { - return $this->bottomline_sharing; - } - public function bottomlineTags () { - return $this->bottomline_tags; - } - public function bottomlineDate () { - return $this->bottomline_date; - } - public function bottomlineLink () { - return $this->bottomline_link; + + public function availableLanguages() { + return $this->available_languages; } - public function _language ($value) { - if (!isset ($this->available_languages[$value])) { + public function _language($value) { + if (!isset($this->available_languages[$value])) { $value = 'en'; } - $this->language = $value; + $this->data['language'] = $value; } - public function _postsPerPage ($value) { + public function _posts_per_page ($value) { $value = intval($value); - $this->posts_per_page = $value > 0 ? $value : 10; + $this->data['posts_per_page'] = $value > 0 ? $value : 10; } - public function _viewMode ($value) { - if ($value == 'global' || $value == 'reader') { - $this->view_mode = $value; + public function _view_mode ($value) { + if ($value === 'global' || $value === 'reader') { + $this->data['view_mode'] = $value; } else { - $this->view_mode = 'normal'; + $this->data['view_mode'] = 'normal'; } } - public function _defaultView ($value) { - if ($value == 'not_read') { - $this->default_view = 'not_read'; - } else { - $this->default_view = 'all'; - } + public function _default_view ($value) { + $this->data['default_view'] = $value === 'all' ? 'all' : 'not_read'; } - public function _displayPosts ($value) { - if ($value == 'yes') { - $this->display_posts = 'yes'; - } else { - $this->display_posts = 'no'; - } + public function _display_posts ($value) { + $this->data['display_posts'] = ((bool)$value) && $value !== 'no'; } public function _onread_jump_next ($value) { - if ($value == 'no') { - $this->onread_jump_next = 'no'; - } else { - $this->onread_jump_next = 'yes'; - } + $this->data['onread_jump_next'] = ((bool)$value) && $value !== 'no'; } public function _lazyload ($value) { - if ($value == 'no') { - $this->lazyload = 'no'; - } else { - $this->lazyload = 'yes'; - } + $this->data['lazyload'] = ((bool)$value) && $value !== 'no'; } - public function _sortOrder ($value) { - $this->sort_order = $value === 'ASC' ? 'ASC' : 'DESC'; + public function _sort_order ($value) { + $this->data['sort_order'] = $value === 'ASC' ? 'ASC' : 'DESC'; } - public function _oldEntries($value) { + public function _old_entries($value) { $value = intval($value); - $this->old_entries = $value > 0 ? $value : 3; + $this->data['old_entries'] = $value > 0 ? $value : 3; } - public function _keepHistoryDefault($value) { + public function _keep_history_default($value) { $value = intval($value); - $this->keep_history_default = $value >= -1 ? $value : 0; + $this->data['keep_history_default'] = $value >= -1 ? $value : 0; } public function _shortcuts ($values) { foreach ($values as $key => $value) { - $this->shortcuts[$key] = $value; + if (isset($this->data['shortcuts'][$key])) { + $this->data['shortcuts'][$key] = $value; + } } } - public function _mailLogin ($value) { - if (filter_var ($value, FILTER_VALIDATE_EMAIL)) { + public function _mail_login ($value) { + if (filter_var($value, FILTER_VALIDATE_EMAIL)) { $this->mail_login = $value; - } elseif ($value == false) { - $this->mail_login = false; + } else { + $this->mail_login = ''; } } - public function _markWhen ($values) { - if(!isset($values['article'])) { - $values['article'] = 'yes'; - } - if(!isset($values['site'])) { - $values['site'] = 'yes'; - } - if(!isset($values['scroll'])) { - $values['scroll'] = 'yes'; - } - if(!isset($values['reception'])) { - $values['reception'] = 'no'; + public function _anon_access ($value) { + $this->data['anon_access'] = ((bool)$value) && $value !== 'no'; + } + public function _mark_when ($values) { + foreach ($values as $key => $value) { + if (isset($this->data['mark_when'][$key])) { + $this->data['mark_when'][$key] = ((bool)$value) && $value !== 'no'; + } } - - $this->mark_when['article'] = $values['article']; - $this->mark_when['site'] = $values['site']; - $this->mark_when['scroll'] = $values['scroll']; - $this->mark_when['reception'] = $values['reception']; } public function _sharing ($values) { $are_url = array ('shaarli', 'poche', 'diaspora'); @@ -268,54 +181,50 @@ class FreshRSS_Configuration extends Minz_Model { if (!$is_url) { $value = ''; } - } elseif(!is_bool ($value)) { + } elseif (!is_bool($value)) { $value = true; } - $this->sharing[$key] = $value; + $this->data['sharing'][$key] = $value; } } - public function _theme ($value) { - $this->theme = $value; + public function _theme($value) { + $this->data['theme'] = $value; } - public function _token ($value) { - $this->token = $value; + public function _token($value) { + $this->data['token'] = $value; } - public function _autoLoadMore ($value) { - if ($value == 'yes') { - $this->auto_load_more = 'yes'; - } else { - $this->auto_load_more = 'no'; - } + public function _auto_load_more($value) { + $this->data['auto_load_more'] = ((bool)$value) && $value !== 'no'; } - public function _topline_read ($value) { - $this->topline_read = $value === 'yes'; + public function _topline_read($value) { + $this->data['topline_read'] = ((bool)$value) && $value !== 'no'; } - public function _topline_favorite ($value) { - $this->topline_favorite = $value === 'yes'; + public function _topline_favorite($value) { + $this->data['topline_favorite'] = ((bool)$value) && $value !== 'no'; } - public function _topline_date ($value) { - $this->topline_date = $value === 'yes'; + public function _topline_date($value) { + $this->data['topline_date'] = ((bool)$value) && $value !== 'no'; } - public function _topline_link ($value) { - $this->topline_link = $value === 'yes'; + public function _topline_link($value) { + $this->data['topline_link'] = ((bool)$value) && $value !== 'no'; } - public function _bottomline_read ($value) { - $this->bottomline_read = $value === 'yes'; + public function _bottomline_read($value) { + $this->data['bottomline_read'] = ((bool)$value) && $value !== 'no'; } - public function _bottomline_favorite ($value) { - $this->bottomline_favorite = $value === 'yes'; + public function _bottomline_favorite($value) { + $this->data['bottomline_favorite'] = ((bool)$value) && $value !== 'no'; } - public function _bottomline_sharing ($value) { - $this->bottomline_sharing = $value === 'yes'; + public function _bottomline_sharing($value) { + $this->data['bottomline_sharing'] = ((bool)$value) && $value !== 'no'; } - public function _bottomline_tags ($value) { - $this->bottomline_tags = $value === 'yes'; + public function _bottomline_tags($value) { + $this->data['bottomline_tags'] = ((bool)$value) && $value !== 'no'; } - public function _bottomline_date ($value) { - $this->bottomline_date = $value === 'yes'; + public function _bottomline_date($value) { + $this->data['bottomline_date'] = ((bool)$value) && $value !== 'no'; } - public function _bottomline_link ($value) { - $this->bottomline_link = $value === 'yes'; + public function _bottomline_link($value) { + $this->data['bottomline_link'] = ((bool)$value) && $value !== 'no'; } } diff --git a/app/Models/ConfigurationDAO.php b/app/Models/ConfigurationDAO.php deleted file mode 100644 index 53312f043..000000000 --- a/app/Models/ConfigurationDAO.php +++ /dev/null @@ -1,154 +0,0 @@ - 'r', - 'mark_favorite' => 'f', - 'go_website' => 'space', - 'next_entry' => 'j', - 'prev_entry' => 'k', - 'collapse_entry' => 'c', - 'load_more' => 'm' - ); - public $mail_login = ''; - public $mark_when = array ( - 'article' => 'yes', - 'site' => 'yes', - 'scroll' => 'no', - 'reception' => 'no' - ); - public $sharing = array ( - 'shaarli' => '', - 'poche' => '', - 'diaspora' => '', - 'twitter' => true, - 'g+' => true, - 'facebook' => true, - 'email' => true, - 'print' => true - ); - public $theme = 'default'; - public $token = ''; - public $auto_load_more = 'yes'; - public $topline_read = 'yes'; - public $topline_favorite = 'yes'; - public $topline_date = 'yes'; - public $topline_link = 'yes'; - public $bottomline_read = 'yes'; - public $bottomline_favorite = 'yes'; - public $bottomline_sharing = 'yes'; - public $bottomline_tags = 'yes'; - public $bottomline_date = 'yes'; - public $bottomline_link = 'yes'; - - public function __construct ($nameFile = '') { - if (empty($nameFile)) { - $nameFile = DATA_PATH . '/' . Minz_Configuration::currentUser () . '_user.php'; - } - parent::__construct ($nameFile); - - // TODO : simplifier ce code, une boucle for() devrait suffire ! - if (isset ($this->array['language'])) { - $this->language = $this->array['language']; - } - if (isset ($this->array['posts_per_page'])) { - $this->posts_per_page = intval($this->array['posts_per_page']); - } - if (isset ($this->array['view_mode'])) { - $this->view_mode = $this->array['view_mode']; - } - if (isset ($this->array['default_view'])) { - $this->default_view = $this->array['default_view']; - } - if (isset ($this->array['display_posts'])) { - $this->display_posts = $this->array['display_posts']; - } - if (isset ($this->array['onread_jump_next'])) { - $this->onread_jump_next = $this->array['onread_jump_next']; - } - if (isset ($this->array['lazyload'])) { - $this->lazyload = $this->array['lazyload']; - } - if (isset ($this->array['sort_order'])) { - $this->sort_order = $this->array['sort_order']; - } - if (isset ($this->array['old_entries'])) { - $this->old_entries = intval($this->array['old_entries']); - } - if (isset ($this->array['keep_history_default'])) { - $this->keep_history_default = intval($this->array['keep_history_default']); - } - if (isset ($this->array['shortcuts'])) { - $this->shortcuts = array_merge ( - $this->shortcuts, $this->array['shortcuts'] - ); - } - if (isset ($this->array['mail_login'])) { - $this->mail_login = $this->array['mail_login']; - } - if (isset ($this->array['mark_when'])) { - $this->mark_when = $this->array['mark_when']; - } - if (isset ($this->array['sharing'])) { - $this->sharing = array_merge ( - $this->sharing, $this->array['sharing'] - ); - } - if (isset ($this->array['theme'])) { - $this->theme = $this->array['theme']; - } - if (isset ($this->array['token'])) { - $this->token = $this->array['token']; - } - if (isset ($this->array['auto_load_more'])) { - $this->auto_load_more = $this->array['auto_load_more']; - } - - if (isset ($this->array['topline_read'])) { - $this->topline_read = $this->array['topline_read']; - } - if (isset ($this->array['topline_favorite'])) { - $this->topline_favorite = $this->array['topline_favorite']; - } - if (isset ($this->array['topline_date'])) { - $this->topline_date = $this->array['topline_date']; - } - if (isset ($this->array['topline_link'])) { - $this->topline_link = $this->array['topline_link']; - } - if (isset ($this->array['bottomline_read'])) { - $this->bottomline_read = $this->array['bottomline_read']; - } - if (isset ($this->array['bottomline_favorite'])) { - $this->bottomline_favorite = $this->array['bottomline_favorite']; - } - if (isset ($this->array['bottomline_sharing'])) { - $this->bottomline_sharing = $this->array['bottomline_sharing']; - } - if (isset ($this->array['bottomline_tags'])) { - $this->bottomline_tags = $this->array['bottomline_tags']; - } - if (isset ($this->array['bottomline_date'])) { - $this->bottomline_date = $this->array['bottomline_date']; - } - if (isset ($this->array['bottomline_link'])) { - $this->bottomline_link = $this->array['bottomline_link']; - } - } - - public function update($values) { - $this->array = array_merge($this->array, $values); - invalidateHttpCache(); - return parent::writeFile(); - } -} diff --git a/app/i18n/en.php b/app/i18n/en.php index c7ac16ae0..65afc11e5 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -159,7 +159,7 @@ return array ( 'current_user' => 'Current user', 'default_user' => 'Username of the default user (maximum 16 alphanumeric characters)', 'persona_connection_email' => 'Login mail address (use Mozilla Persona)', - 'allow_anonymous' => 'Allow anonymous reading', + 'allow_anonymous' => 'Allow anonymous reading for the default user (%s)', 'auth_token' => 'Authentication token', 'explain_token' => 'Allows to access RSS output without authentication.
%s?token=%s', 'login_configuration' => 'Login', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index e8da1c603..adc38acbe 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -159,7 +159,7 @@ return array ( 'current_user' => 'Utilisateur actuel', 'default_user' => 'Nom de l’utilisateur par défaut (16 caractères alphanumériques maximum)', 'persona_connection_email' => 'Adresse courriel de connexion (utilise Mozilla Persona)', - 'allow_anonymous' => 'Autoriser la lecture anonyme', + 'allow_anonymous' => 'Autoriser la lecture anonyme pour l’utilisateur par défaut (%s)', 'auth_token' => 'Jeton d’identification', 'explain_token' => 'Permet d’accéder à la sortie RSS sans besoin de s’authentifier.
%s?output=rss&token=%s', 'login_configuration' => 'Identification', diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml index b7c34f04e..ae75c9bdb 100644 --- a/app/layout/layout.phtml +++ b/app/layout/layout.phtml @@ -1,5 +1,5 @@ - + diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 1f2a7b408..37f8a426f 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -19,7 +19,7 @@ $string_mark = Minz_Translate::t ('mark_cat_read'); } $nextGet = $get; - if (($this->conf->onread_jump_next () === 'yes') && (strlen ($get) > 2)) { + if ($this->conf->onread_jump_next && (strlen ($get) > 2)) { $anotherUnreadId = ''; $foundCurrent = false; switch ($get[0]) { diff --git a/app/views/configure/archiving.phtml b/app/views/configure/archiving.phtml index e4aacc7c6..0a68eb76c 100644 --- a/app/views/configure/archiving.phtml +++ b/app/views/configure/archiving.phtml @@ -10,18 +10,18 @@
- +  
- +
+ ?> ()
diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 800181659..11a987610 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -12,7 +12,7 @@
@@ -23,7 +23,7 @@
+
@@ -51,8 +51,8 @@
@@ -61,16 +61,16 @@
@@ -79,9 +79,9 @@
@@ -89,9 +89,9 @@
@@ -99,9 +99,9 @@
@@ -110,19 +110,19 @@
@@ -132,7 +132,7 @@
@@ -162,20 +162,20 @@ - conf->toplineRead () ? ' checked="checked"' : ''; ?> /> - conf->toplineFavorite () ? ' checked="checked"' : ''; ?> /> + conf->topline_read ? ' checked="checked"' : ''; ?> /> + conf->topline_favorite ? ' checked="checked"' : ''; ?> /> - conf->toplineDate () ? ' checked="checked"' : ''; ?> /> - conf->toplineLink () ? ' checked="checked"' : ''; ?> /> + conf->topline_date ? ' checked="checked"' : ''; ?> /> + conf->topline_link ? ' checked="checked"' : ''; ?> /> - conf->bottomlineRead () ? ' checked="checked"' : ''; ?> /> - conf->bottomlineFavorite () ? ' checked="checked"' : ''; ?> /> - conf->bottomlineSharing () ? ' checked="checked"' : ''; ?> /> - conf->bottomlineTags () ? ' checked="checked"' : ''; ?> /> - conf->bottomlineDate () ? ' checked="checked"' : ''; ?> /> - conf->bottomlineLink () ? ' checked="checked"' : ''; ?> /> + conf->bottomline_read ? ' checked="checked"' : ''; ?> /> + conf->bottomline_favorite ? ' checked="checked"' : ''; ?> /> + conf->bottomline_sharing ? ' checked="checked"' : ''; ?> /> + conf->bottomline_tags ? ' checked="checked"' : ''; ?> /> + conf->bottomline_date ? ' checked="checked"' : ''; ?> /> + conf->bottomline_link ? ' checked="checked"' : ''; ?> />
diff --git a/app/views/configure/sharing.phtml b/app/views/configure/sharing.phtml index 825537fc9..c6a96b48a 100644 --- a/app/views/configure/sharing.phtml +++ b/app/views/configure/sharing.phtml @@ -47,7 +47,7 @@ foreach ($services as $service) { ?> diff --git a/app/views/configure/shortcut.phtml b/app/views/configure/shortcut.phtml index e78d91820..2e564a7b6 100644 --- a/app/views/configure/shortcut.phtml +++ b/app/views/configure/shortcut.phtml @@ -9,7 +9,7 @@ - conf->shortcuts (); ?> + conf->shortcuts; ?>
diff --git a/app/views/configure/users.phtml b/app/views/configure/users.phtml index c57671ef3..4fd291ba3 100644 --- a/app/views/configure/users.phtml +++ b/app/views/configure/users.phtml @@ -20,7 +20,7 @@
- conf->mailLogin(); ?> + conf->mail_login; ?>
@@ -29,7 +29,7 @@
- conf->token(); ?> + conf->token; ?>
@@ -51,7 +51,7 @@
diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index d008e2e48..8f508487c 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -1,16 +1,16 @@ conf->markWhen (); + $mark = $this->conf->mark_when; echo 'var ', - 'hide_posts=', ($this->conf->displayPosts () === 'yes' || Minz_Request::param ('output') === 'reader') ? 'false' : 'true', - ',auto_mark_article=', $mark['article'] === 'yes' ? 'true' : 'false', - ',auto_mark_site=', $mark['site'] === 'yes' ? 'true' : 'false', - ',auto_mark_scroll=', $mark['scroll'] === 'yes' ? 'true' : 'false', - ',auto_load_more=', $this->conf->autoLoadMore () === 'yes' ? 'true' : 'false', - ',full_lazyload=', $this->conf->lazyload () === 'yes' && ($this->conf->displayPosts () === 'yes' || Minz_Request::param ('output') === 'reader') ? 'true' : 'false', - ',does_lazyload=', $this->conf->lazyload() === 'yes' ? 'true' : 'false'; + 'hide_posts=', ($this->conf->display_posts || Minz_Request::param('output') === 'reader') ? 'false' : 'true', + ',auto_mark_article=', $mark['article'] ? 'true' : 'false', + ',auto_mark_site=', $mark['site'] ? 'true' : 'false', + ',auto_mark_scroll=', $mark['scroll'] ? 'true' : 'false', + ',auto_load_more=', $this->conf->auto_load_more ? 'true' : 'false', + ',full_lazyload=', $this->conf->lazyload && ($this->conf->display_posts || Minz_Request::param('output') === 'reader') ? 'true' : 'false', + ',does_lazyload=', $this->conf->lazyload ? 'true' : 'false'; - $s = $this->conf->shortcuts (); + $s = $this->conf->shortcuts; echo ',shortcuts={', 'mark_read:"', $s['mark_read'], '",', 'mark_favorite:"', $s['mark_favorite'], '",', diff --git a/app/views/helpers/view/global_view.phtml b/app/views/helpers/view/global_view.phtml index bc6e24e37..58ff13d4e 100644 --- a/app/views/helpers/view/global_view.phtml +++ b/app/views/helpers/view/global_view.phtml @@ -31,6 +31,6 @@
-
conf->displayPosts () === 'no' ? ' class="hide_posts"' : ''; ?>> +
conf->display_posts ? '' : ' class="hide_posts"'; ?>> -
\ No newline at end of file +
diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml index 4307c2113..f59cae2b8 100644 --- a/app/views/helpers/view/normal_view.phtml +++ b/app/views/helpers/view/normal_view.phtml @@ -18,8 +18,8 @@ if (!empty($this->entries)) { $email = $this->conf->sharing ('email'); $print = $this->conf->sharing ('print'); $today = $this->today; - $hidePosts = $this->conf->displayPosts() === 'no'; - $lazyload = $this->conf->lazyload() === 'yes'; + $hidePosts = !$this->conf->display_posts; + $lazyload = $this->conf->lazyload; ?>
@@ -49,13 +49,13 @@ if (!empty($this->entries)) {
@@ -86,13 +86,13 @@ if (!empty($this->entries)) {
    conf->bottomlineRead ()) { + if ($this->conf->bottomline_read) { ?>
  • isRead () ? 'read' : 'unread'); ?>
  • conf->bottomlineFavorite ()) { + if ($this->conf->bottomline_favorite) { ?>
  • isFavorite () ? 'starred' : 'non-starred'); ?>entries)) { } ?>
  • conf->bottomlineSharing () && ( + if ($this->conf->bottomline_sharing && ( $shaarli || $poche || $diaspora || $twitter || $google_plus || $facebook || $email )) { @@ -171,7 +171,7 @@ if (!empty($this->entries)) {
  • conf->bottomlineTags () ? $item->tags() : null; + $tags = $this->conf->bottomline_tags ? $item->tags() : null; if (!empty($tags)) { ?>
  • @@ -190,8 +190,8 @@ if (!empty($this->entries)) {
- conf->bottomlineDate ()) { ?>
  • date (); ?> 
  • - conf->bottomlineLink ()) { ?> + conf->bottomline_date) { ?>
  • date (); ?> 
  • + conf->bottomline_link) { ?>
    diff --git a/app/views/helpers/view/reader_view.phtml b/app/views/helpers/view/reader_view.phtml index 47254f74e..2f64e672a 100644 --- a/app/views/helpers/view/reader_view.phtml +++ b/app/views/helpers/view/reader_view.phtml @@ -2,7 +2,7 @@ $this->partial ('nav_menu'); if (!empty($this->entries)) { - $lazyload = $this->conf->lazyload() === 'yes'; + $lazyload = $this->conf->lazyload; ?>
    diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index 2d134ba4e..4db53e2a5 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -1,7 +1,7 @@ conf->token(); +$token = $this->conf->token; $token_param = Minz_Request::param ('token', ''); $token_is_ok = ($token != '' && $token == $token_param); diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 306328904..3864a9335 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -225,14 +225,14 @@ class Minz_Configuration { } } if (isset ($general['delay_cache'])) { - self::$delay_cache = $general['delay_cache']; + self::$delay_cache = inval($general['delay_cache']); } if (isset ($general['default_user'])) { self::$default_user = $general['default_user']; self::$current_user = self::$default_user; } if (isset ($general['allow_anonymous'])) { - self::$allow_anonymous = (bool)($general['allow_anonymous']); + self::$allow_anonymous = ((bool)($general['allow_anonymous'])) && ($general['allow_anonymous'] !== 'no'); } // Base de données diff --git a/lib/Minz/ModelArray.php b/lib/Minz/ModelArray.php index 89d7f06c1..e3ec77dc9 100644 --- a/lib/Minz/ModelArray.php +++ b/lib/Minz/ModelArray.php @@ -8,11 +8,6 @@ * La classe Model_array représente le modèle interragissant avec les fichiers de type texte gérant des tableaux php */ class Minz_ModelArray { - /** - * $array Le tableau php contenu dans le fichier $filename - */ - protected $array = array (); - /** * $filename est le nom du fichier */ @@ -25,29 +20,32 @@ class Minz_ModelArray { */ public function __construct ($filename) { $this->filename = $filename; + } + protected function loadArray() { if (!file_exists($this->filename)) { throw new Minz_FileNotExistException($this->filename, Minz_Exception::WARNING); } elseif (($handle = $this->getLock()) === false) { throw new Minz_PermissionDeniedException($this->filename); } else { - $this->array = include($this->filename); + $data = include($this->filename); $this->releaseLock($handle); - if ($this->array === false) { + if ($data === false) { throw new Minz_PermissionDeniedException($this->filename); - } elseif (!is_array($this->array)) { - $this->array = array(); + } elseif (!is_array($data)) { + $data = array(); } + return $data; } } /** * Sauve le tableau $array dans le fichier $filename **/ - protected function writeFile() { - if (!file_put_contents($this->filename, "array, true) . ';', LOCK_EX)) { + protected function writeArray($array) { + if (!file_put_contents($this->filename, "filename); } return true; diff --git a/lib/Minz/Session.php b/lib/Minz/Session.php index f527322f5..6e45fd226 100644 --- a/lib/Minz/Session.php +++ b/lib/Minz/Session.php @@ -55,11 +55,6 @@ class Minz_Session { } else { $_SESSION[$p] = $v; self::$session[$p] = $v; - - if($p == 'language') { - // reset pour remettre à jour le fichier de langue à utiliser - Minz_Translate::reset (); - } } } @@ -76,6 +71,7 @@ class Minz_Session { if (!$force) { self::_param ('language', $language); + Minz_Translate::reset (); } } } diff --git a/lib/lib_rss.php b/lib/lib_rss.php index a27ef171a..3f55c7d58 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -63,7 +63,7 @@ function is_logged () { // vérifie que le système d'authentification est configuré function login_is_conf ($conf) { - return $conf->mailLogin () != false; + return $conf->mail_login != ''; } // tiré de Shaarli de Seb Sauvage //Format RFC 4648 base64url -- cgit v1.2.3 From 92efd68a3a13e49fe7bbfb8441611c0dcd639415 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 30 Dec 2013 01:03:32 +0100 Subject: Début de mode multi-utilisateur avec http_auth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Légère optimisation de Minz_View. + Encore plus de tests de bibliothèques dans install.php Contribue à https://github.com/marienfressinaud/FreshRSS/issues/126 et https://github.com/marienfressinaud/FreshRSS/issues/303 --- README.md | 2 +- app/Controllers/configureController.php | 5 +-- app/Controllers/entryController.php | 4 +-- app/Controllers/feedController.php | 27 +++++++------- app/Controllers/indexController.php | 31 ++++++++--------- app/FreshRSS.php | 56 ++++++++++++++++++++++------- app/Models/Configuration.php | 15 ++++---- app/actualize_script.php | 15 +++++--- app/i18n/en.php | 5 +-- app/i18n/fr.php | 5 +-- app/layout/aside_flux.phtml | 6 ++-- app/layout/header.phtml | 21 +++++------ app/layout/nav_menu.phtml | 2 +- app/views/configure/users.phtml | 51 +++++++++++++++------------ app/views/helpers/javascript_vars.phtml | 2 +- app/views/helpers/view/normal_view.phtml | 60 ++++++++++++++++++-------------- app/views/index/index.phtml | 45 ++++++++++++++---------- lib/Minz/Configuration.php | 12 ++++++- lib/Minz/View.php | 29 ++++++--------- lib/lib_rss.php | 16 +++------ p/i/install.php | 24 ++++++++++--- 21 files changed, 246 insertions(+), 187 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/README.md b/README.md index f20f870dd..cfef89781 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Privilégiez pour cela des demandes sur GitHub # Pré-requis * Serveur Apache2 ou Nginx (non testé sur les autres) * PHP 5.2+ (PHP 5.3.3+ recommandé) - * Requis : [LibXML](http://php.net/xml), [PCRE](http://php.net/pcre), [cURL](http://php.net/curl), [PDO_MySQL](http://php.net/pdo-mysql) + * Requis : [PDO_MySQL](http://php.net/pdo-mysql), [cURL](http://php.net/curl), [LibXML](http://php.net/xml), [PCRE](http://php.net/pcre), [ctype](http://php.net/ctype) * Recommandés : [JSON](http://php.net/json), [zlib](http://php.net/zlib), [mbstring](http://php.net/mbstring), [iconv](http://php.net/iconv) * MySQL 5.0.3+ (ou SQLite 3.7.4+ à venir) * Un navigateur Web récent tel Firefox, Chrome, Opera, Safari, Internet Explorer 9+ diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 0c0b4951d..656e2ac89 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -2,7 +2,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { public function firstAction () { - if (login_is_conf ($this->view->conf) && !is_logged ()) { + if (!$this->view->loginOk) { Minz_Error::error ( 403, array ('error' => array (Minz_Translate::t ('access_denied'))) @@ -16,7 +16,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController { public function categorizeAction () { $feedDAO = new FreshRSS_FeedDAO (); $catDAO = new FreshRSS_CategoryDAO (); - $catDAO->checkDefault (); $defaultCategory = $catDAO->getDefault (); $defaultId = $defaultCategory->id (); @@ -167,8 +166,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $this->view->conf->_bottomline_link(Minz_Request::param('bottomline_link', false)); $this->view->conf->save(); - Minz_Session::_param ('mail', $this->view->conf->mail_login); - Minz_Session::_param ('language', $this->view->conf->language); Minz_Translate::reset (); diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index b0fc37cdf..da4ab5ecc 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -2,7 +2,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { public function firstAction () { - if (login_is_conf ($this->view->conf) && !is_logged ()) { + if (!$this->view->loginOk) { Minz_Error::error ( 403, array ('error' => array (Minz_Translate::t ('access_denied'))) @@ -38,7 +38,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { $nextGet = Minz_Request::param ('nextGet', $get); $idMax = Minz_Request::param ('idMax', 0); - $is_read = !!$is_read; + $is_read = (bool)$is_read; $entryDAO = new FreshRSS_EntryDAO (); if ($id == false) { diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 42a0dcb11..2d7c0ab43 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -2,18 +2,17 @@ class FreshRSS_feed_Controller extends Minz_ActionController { public function firstAction () { - $token = $this->view->conf->token; - $token_param = Minz_Request::param ('token', ''); - $token_is_ok = ($token != '' && $token == $token_param); - $action = Minz_Request::actionName (); - - if (login_is_conf ($this->view->conf) && - !is_logged () && - !($token_is_ok && $action == 'actualize')) { - Minz_Error::error ( - 403, - array ('error' => array (Minz_Translate::t ('access_denied'))) - ); + if (!$this->view->loginOk) { + $token = $this->view->conf->token; //TODO: check the token logic again, and if it is still needed + $token_param = Minz_Request::param ('token', ''); + $token_is_ok = ($token != '' && $token == $token_param); + $action = Minz_Request::actionName (); + if (!($token_is_ok && $action === 'actualize')) { + Minz_Error::error ( + 403, + array ('error' => array (Minz_Translate::t ('access_denied'))) + ); + } } $this->catDAO = new FreshRSS_CategoryDAO (); @@ -411,10 +410,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } private function addCategories ($categories) { - $catDAO = new FreshRSS_CategoryDAO (); - foreach ($categories as $cat) { - if (!$catDAO->searchByName ($cat->name ())) { + if (!$this->catDAO->searchByName ($cat->name ())) { $values = array ( 'id' => $cat->id (), 'name' => $cat->name (), diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 54826636f..66809964d 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -16,17 +16,18 @@ class FreshRSS_index_Controller extends Minz_ActionController { public function indexAction () { $output = Minz_Request::param ('output'); - - $token = $this->view->conf->token; - $token_param = Minz_Request::param ('token', ''); - $token_is_ok = ($token != '' && $token === $token_param); - - // check if user is log in - if(login_is_conf ($this->view->conf) && - !is_logged() && - !Minz_Configuration::allowAnonymous() && - !($output === 'rss' && $token_is_ok)) { - return; + $token = ''; + + // check if user is logged in + if (!$this->view->loginOk && !Minz_Configuration::allowAnonymous()) + { + $token = $this->view->conf->token; + $token_param = Minz_Request::param ('token', ''); + $token_is_ok = ($token != '' && $token === $token_param); + if (!($output === 'rss' && $token_is_ok)) { + return; + } + $params['token'] = $token; } // construction of RSS url of this feed @@ -35,11 +36,6 @@ class FreshRSS_index_Controller extends Minz_ActionController { if (isset ($params['search'])) { $params['search'] = urlencode ($params['search']); } - if (login_is_conf($this->view->conf) && - !Minz_Configuration::allowAnonymous() && - $token !== '') { - $params['token'] = $token; - } $this->view->rss_url = array ( 'c' => 'index', 'a' => 'index', @@ -212,7 +208,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { } public function logsAction () { - if (login_is_conf ($this->view->conf) && !is_logged ()) { + if (!$this->view->loginOk) { Minz_Error::error ( 403, array ('error' => array (Minz_Translate::t ('access_denied'))) @@ -255,6 +251,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { $res = json_decode ($result, true); if ($res['status'] === 'okay' && $res['email'] === $this->view->conf->mail_login) { Minz_Session::_param ('mail', $res['email']); + $this->view->loginOk = true; invalidateHttpCache(); } else { $res = array (); diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 05c8ec8e0..10f362717 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -1,26 +1,56 @@ loadParamsView (); - $this->loadStylesAndScripts (); - $this->loadNotifications (); + public function init($currentUser = null) { + Minz_Session::init('FreshRSS'); + $this->accessControl($currentUser); + $this->loadParamsView(); + $this->loadStylesAndScripts(); + $this->loadNotifications(); } - private function loadParamsView () { + private function accessControl($currentUser) { + if ($currentUser === null) { + switch (Minz_Configuration::authType()) { + case 'http_auth': + $currentUser = httpAuthUser(); + $loginOk = $currentUser != ''; + break; + case 'persona': + $currentUser = Minz_Configuration::defaultUser(); + $loginOk = Minz_Session::param('mail') != ''; + break; + case 'none': + $currentUser = Minz_Configuration::defaultUser(); + $loginOk = true; + break; + default: + $loginOk = false; + break; + } + } elseif ((PHP_SAPI === 'cli') && (Minz_Request::actionName() === 'actualize')) { //Command line + Minz_Configuration::_authType('none'); + $loginOk = true; + } + + if (!$loginOk || !isValidUser($currentUser)) { + $currentUser = Minz_Configuration::defaultUser(); + $loginOk = false; + } + Minz_Configuration::_currentUser($currentUser); + Minz_View::_param ('loginOk', $loginOk); + try { - $this->conf = new FreshRSS_Configuration(); + $this->conf = new FreshRSS_Configuration($currentUser); } catch (Minz_Exception $e) { // Permission denied or conf file does not exist - // it's critical! die($e->getMessage()); } - Minz_View::_param ('conf', $this->conf); + } + + private function loadParamsView () { Minz_Session::_param ('language', $this->conf->language); Minz_Translate::init(); - $output = Minz_Request::param ('output'); if (!$output) { $output = $this->conf->view_mode; @@ -31,12 +61,12 @@ class FreshRSS extends Minz_FrontController { private function loadStylesAndScripts () { $theme = FreshRSS_Themes::get_infos($this->conf->theme); if ($theme) { - foreach($theme["files"] as $file) { + foreach($theme['files'] as $file) { Minz_View::appendStyle (Minz_Url::display ('/themes/' . $theme['path'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file))); } } - if (login_is_conf ($this->conf)) { + if (Minz_Configuration::authType() === 'persona') { Minz_View::appendScript ('https://login.persona.org/include.js'); } $includeLazyLoad = $this->conf->lazyload && ($this->conf->display_posts || Minz_Request::param ('output') === 'reader'); diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index b0a5d9940..ec7daaa7d 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -59,10 +59,9 @@ class FreshRSS_Configuration extends Minz_ModelArray { 'fr' => 'Français', ); - public function __construct ($filename = '') { - if (empty($filename)) { - $filename = DATA_PATH . '/' . Minz_Configuration::currentUser () . '_user.php'; - } + public function __construct ($user) { + $filename = DATA_PATH . '/' . $user . '_user.php'; + parent::__construct($filename); $data = parent::loadArray(); @@ -72,6 +71,7 @@ class FreshRSS_Configuration extends Minz_ModelArray { $this->$function($value); } } + $this->data['user'] = $user; } public function save() { @@ -151,10 +151,11 @@ class FreshRSS_Configuration extends Minz_ModelArray { } } public function _mail_login ($value) { - if (filter_var($value, FILTER_VALIDATE_EMAIL)) { - $this->mail_login = $value; + $value = filter_var($value, FILTER_VALIDATE_EMAIL); + if ($value) { + $this->data['mail_login'] = $value; } else { - $this->mail_login = ''; + $this->data['mail_login'] = ''; } } public function _anon_access ($value) { diff --git a/app/actualize_script.php b/app/actualize_script.php index 20438128a..e0c560ff7 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -1,6 +1,8 @@ init (); -Minz_Session::_param('mail', true); // permet de se passer de la phase de connexion -$front_controller->run (); -invalidateHttpCache(); + +$users = listUsers(); +shuffle($users); + +foreach ($users as $user) { + $front_controller->init($user); + $front_controller->run(); + invalidateHttpCache($user); +} diff --git a/app/i18n/en.php b/app/i18n/en.php index 65afc11e5..8b9eee548 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -158,13 +158,14 @@ return array ( 'current_user' => 'Current user', 'default_user' => 'Username of the default user (maximum 16 alphanumeric characters)', - 'persona_connection_email' => 'Login mail address (use Mozilla Persona)', + 'persona_connection_email' => 'Login mail address (for Mozilla Persona)', 'allow_anonymous' => 'Allow anonymous reading for the default user (%s)', 'auth_token' => 'Authentication token', - 'explain_token' => 'Allows to access RSS output without authentication.
    %s?token=%s', + 'explain_token' => 'Allows to access RSS output of the default user without authentication.
    %s?token=%s', 'login_configuration' => 'Login', 'is_admin' => 'is administrator', 'auth_type' => 'Authentication method', + 'auth_none' => 'None (dangerous)', 'users_list' => 'List of users', 'language' => 'Language', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index adc38acbe..cad156d47 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -158,13 +158,14 @@ return array ( 'current_user' => 'Utilisateur actuel', 'default_user' => 'Nom de l’utilisateur par défaut (16 caractères alphanumériques maximum)', - 'persona_connection_email' => 'Adresse courriel de connexion (utilise Mozilla Persona)', + 'persona_connection_email' => 'Adresse courriel de connexion (pour Mozilla Persona)', 'allow_anonymous' => 'Autoriser la lecture anonyme pour l’utilisateur par défaut (%s)', 'auth_token' => 'Jeton d’identification', - 'explain_token' => 'Permet d’accéder à la sortie RSS sans besoin de s’authentifier.
    %s?output=rss&token=%s', + 'explain_token' => 'Permet d’accéder à la sortie RSS de l’utilisateur par défaut sans besoin de s’authentifier.
    %s?output=rss&token=%s', 'login_configuration' => 'Identification', 'is_admin' => 'est administrateur', 'auth_type' => 'Méthode d’authentification', + 'auth_none' => 'Aucune (dangereux)', 'users_list' => 'Liste des utilisateurs', 'language' => 'Langue', diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 9a6b16d58..8730baf0e 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -2,14 +2,14 @@
      - conf) || is_logged ()) { ?> + loginOk) { ?>
    • - conf)) { ?> +
    • @@ -69,7 +69,7 @@
    • - conf) || is_logged ()) { ?> + loginOk) { ?>
    • diff --git a/app/layout/header.phtml b/app/layout/header.phtml index aeb417a6e..0f2c524c4 100644 --- a/app/layout/header.phtml +++ b/app/layout/header.phtml @@ -1,9 +1,9 @@ -conf)) { ?> + @@ -19,9 +19,7 @@
    +
    + +
    + () +
    +
    diff --git a/app/views/configure/feed.phtml b/app/views/configure/feed.phtml index 27b0990ff..a8dd9a8cb 100644 --- a/app/views/configure/feed.phtml +++ b/app/views/configure/feed.phtml @@ -103,6 +103,27 @@ ?>
    +
    + +
    + +
    +
    diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 1b1e4b021..7ca611b04 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -109,7 +109,7 @@ function customSimplePie() { $simplePie = new SimplePie(); $simplePie->set_useragent(Minz_Translate::t('freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION); $simplePie->set_cache_location(CACHE_PATH); - $simplePie->set_cache_duration(1500); + $simplePie->set_cache_duration(800); $simplePie->strip_htmltags(array( 'base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', -- cgit v1.2.3 From 439a0e2991231db51232646736a4bf78cfb2bffd Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 7 Jul 2014 18:25:48 +0200 Subject: SQL: improved performance for adding new articles --- app/Controllers/feedController.php | 28 +++++++++++++++++----------- app/Controllers/importExportController.php | 1 + app/Models/EntryDAO.php | 8 ++++++-- 3 files changed, 24 insertions(+), 13 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 36425ca9b..3326b2059 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -109,18 +109,23 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $nb_month_old = $this->view->conf->old_entries; $date_min = time () - (3600 * 24 * 30 * $nb_month_old); + //MySQL: http://docs.oracle.com/cd/E17952_01/refman-5.5-en/optimizing-innodb-transaction-management.html + //SQLite: http://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite + $preparedStatement = $entryDAO->addEntryPrepare(); $transactionStarted = true; - $feedDAO->beginTransaction (); + $feedDAO->beginTransaction(); // on ajoute les articles en masse sans vérification foreach ($entries as $entry) { - $values = $entry->toArray (); - $values['id_feed'] = $feed->id (); - $values['id'] = min(time(), $entry->date (true)) . uSecString(); + $values = $entry->toArray(); + $values['id_feed'] = $feed->id(); + $values['id'] = min(time(), $entry->date(true)) . uSecString(); $values['is_read'] = $is_read; - $entryDAO->addEntry ($values); + $entryDAO->addEntry($values, $preparedStatement); + } + $feedDAO->updateLastUpdate($feed->id()); + if ($transactionStarted) { + $feedDAO->commit(); } - $feedDAO->updateLastUpdate ($feed->id ()); - $feedDAO->commit (); $transactionStarted = false; // ok, ajout terminé @@ -265,22 +270,23 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feedHistory = $this->view->conf->keep_history_default; } + $preparedStatement = $entryDAO->addEntryPrepare(); $hasTransaction = true; $feedDAO->beginTransaction(); // On ne vérifie pas strictement que l'article n'est pas déjà en BDD // La BDD refusera l'ajout car (id_feed, guid) doit être unique foreach ($entries as $entry) { - $eDate = $entry->date (true); - if ((!isset ($existingGuids[$entry->guid ()])) && + $eDate = $entry->date(true); + if ((!isset($existingGuids[$entry->guid()])) && (($feedHistory != 0) || ($eDate >= $date_min))) { - $values = $entry->toArray (); + $values = $entry->toArray(); //Use declared date at first import, otherwise use discovery date $values['id'] = ($useDeclaredDate || $eDate < $date_min) ? min(time(), $eDate) . uSecString() : uTimeString(); $values['is_read'] = $is_read; - $entryDAO->addEntry ($values); + $entryDAO->addEntry($values, $preparedStatement); } } } diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 6b4c3e81a..ba172cc6d 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -266,6 +266,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { ); $entry->_tags($tags); + //FIME: Use entryDAO->addEntryPrepare(). Do not call entryDAO->listLastGuidsByFeed() for each entry. Consider using a transaction. $id = $this->entryDAO->addEntryObject( $entry, $this->view->conf, $feed->keepHistory() ); diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 1775af63c..6f3f472f6 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -6,14 +6,18 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { return parent::$sharedDbType !== 'sqlite'; } - public function addEntry($valuesTmp) { + public function addEntryPrepare() { $sql = 'INSERT INTO `' . $this->prefix . 'entry`(id, guid, title, author, ' . ($this->isCompressed() ? 'content_bin' : 'content') . ', link, date, is_read, is_favorite, id_feed, tags) ' . 'VALUES(?, ?, ?, ?, ' . ($this->isCompressed() ? 'COMPRESS(?)' : '?') . ', ?, ?, ?, ?, ?, ?)'; - $stm = $this->bd->prepare($sql); + return $this->bd->prepare($sql); + } + + public function addEntry($valuesTmp, $preparedStatement = null) { + $stm = $preparedStatement === null ? addEntryPrepare() : $preparedStatement; $values = array( $valuesTmp['id'], -- cgit v1.2.3 From d284958d52f633738e8cc736f7f4a50e0c984ecf Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 19 Sep 2014 19:44:40 +0200 Subject: Improve redirection when deleting an idle feed --- app/Controllers/feedController.php | 9 ++++++--- app/views/stats/idle.phtml | 6 +++++- lib/Minz/Request.php | 5 +++++ 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 3326b2059..65d4b3a37 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -412,10 +412,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController { Minz_Session::_param ('notification', $notif); - if ($type == 'category') { - Minz_Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true); + $redirect_url = Minz_Request::param('r', false, true); + if ($redirect_url) { + Minz_Request::forward($redirect_url); + } elseif ($type == 'category') { + Minz_Request::forward(array ('c' => 'configure', 'a' => 'categorize'), true); } else { - Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed'), true); + Minz_Request::forward(array ('c' => 'configure', 'a' => 'feed'), true); } } } diff --git a/app/views/stats/idle.phtml b/app/views/stats/idle.phtml index 3ce8d3d3e..6f3d4a117 100644 --- a/app/views/stats/idle.phtml +++ b/app/views/stats/idle.phtml @@ -6,6 +6,10 @@

    'stats', 'a' => 'idle'), + 'php', true + )); $nothing = true; foreach ($this->idleFeeds as $period => $feeds) { if (!empty($feeds)) { @@ -22,7 +26,7 @@
    - +
  • diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index 52f53012f..f7a24c026 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -124,6 +124,11 @@ class Minz_Request { * > sinon, le dispatcher recharge en interne */ public static function forward($url = array(), $redirect = false) { + if (!is_array($url)) { + header('Location: ' . $url); + exit(); + } + $url = Minz_Url::checkUrl($url); if ($redirect) { -- cgit v1.2.3 From 17f686095ddebe1a7c94fe665eddfdfef9696015 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 24 Sep 2014 13:38:07 +0200 Subject: Remove queries at the same time as feeds See https://github.com/marienfressinaud/FreshRSS/issues/625 --- app/Controllers/feedController.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 65d4b3a37..c7cc25fbb 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -383,7 +383,16 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feedDAO = FreshRSS_Factory::createFeedDao(); if ($type == 'category') { + // List feeds to remove then related user queries. + $feeds = $feedDAO->listByCategory($id); + if ($feedDAO->deleteFeedByCategory ($id)) { + // Remove related queries + foreach ($feeds as $feed) { + $this->view->conf->remove_query_by_get('f_' . $feed->id()); + } + $this->view->conf->save(); + $notif = array ( 'type' => 'good', 'content' => Minz_Translate::t ('category_emptied') @@ -397,6 +406,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } else { if ($feedDAO->deleteFeed ($id)) { + // Remove related queries + $this->view->conf->remove_query_by_get('f_' . $id); + $this->view->conf->save(); + $notif = array ( 'type' => 'good', 'content' => Minz_Translate::t ('feed_deleted') -- cgit v1.2.3