From 4ee4f16ffe06e247d2cb79a2054ab5d5315d82b2 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 15 Dec 2013 11:24:14 +0100 Subject: Problème de casse renommage répertoire MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Entry.php | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 app/Models/Entry.php (limited to 'app/Models/Entry.php') diff --git a/app/Models/Entry.php b/app/Models/Entry.php new file mode 100644 index 000000000..ba0fb48f4 --- /dev/null +++ b/app/Models/Entry.php @@ -0,0 +1,193 @@ +_guid ($guid); + $this->_title ($title); + $this->_author ($author); + $this->_content ($content); + $this->_link ($link); + $this->_date ($pubdate); + $this->_isRead ($is_read); + $this->_isFavorite ($is_favorite); + $this->_feed ($feed); + $this->_tags (preg_split('/[\s#]/', $tags)); + } + + public function id () { + return $this->id; + } + public function guid () { + return $this->guid; + } + public function title () { + return $this->title; + } + public function author () { + if (is_null ($this->author)) { + return ''; + } else { + return $this->author; + } + } + public function content () { + return $this->content; + } + public function link () { + return $this->link; + } + public function date ($raw = false) { + if ($raw) { + return $this->date; + } else { + return timestamptodate ($this->date); + } + } + public function dateAdded ($raw = false) { + $date = intval(substr($this->id, 0, -6)); + if ($raw) { + return $date; + } else { + return timestamptodate ($date); + } + } + public function isRead () { + return $this->is_read; + } + public function isFavorite () { + return $this->is_favorite; + } + public function feed ($object = false) { + if ($object) { + $feedDAO = new FreshRSS_FeedDAO (); + return $feedDAO->searchById ($this->feed); + } else { + return $this->feed; + } + } + public function tags ($inString = false) { + if ($inString) { + return empty ($this->tags) ? '' : '#' . implode(' #', $this->tags); + } else { + return $this->tags; + } + } + + public function _id ($value) { + $this->id = $value; + } + public function _guid ($value) { + $this->guid = $value; + } + public function _title ($value) { + $this->title = $value; + } + public function _author ($value) { + $this->author = $value; + } + public function _content ($value) { + $this->content = $value; + } + public function _link ($value) { + $this->link = $value; + } + public function _date ($value) { + if (ctype_digit ($value)) { + $this->date = intval ($value); + } else { + $this->date = time (); + } + } + public function _isRead ($value) { + $this->is_read = $value; + } + public function _isFavorite ($value) { + $this->is_favorite = $value; + } + public function _feed ($value) { + $this->feed = $value; + } + public function _tags ($value) { + if (!is_array ($value)) { + $value = array ($value); + } + + foreach ($value as $key => $t) { + if (!$t) { + unset ($value[$key]); + } + } + + $this->tags = $value; + } + + public function isDay ($day) { + $date = $this->dateAdded(true); + $today = @strtotime('today'); + $yesterday = $today - 86400; + + if ($day === FreshRSS_Days::TODAY && + $date >= $today && $date < $today + 86400) { + return true; + } elseif ($day === FreshRSS_Days::YESTERDAY && + $date >= $yesterday && $date < $yesterday + 86400) { + return true; + } elseif ($day === FreshRSS_Days::BEFORE_YESTERDAY && $date < $yesterday) { + return true; + } else { + return false; + } + } + + public function loadCompleteContent($pathEntries) { + // Gestion du contenu + // On cherche à récupérer les articles en entier... même si le flux ne le propose pas + if ($pathEntries) { + $entryDAO = new FreshRSS_EntryDAO(); + $entry = $entryDAO->searchByGuid($this->feed, $this->guid); + + if($entry) { + // l'article existe déjà en BDD, en se contente de recharger ce contenu + $this->content = $entry->content(); + } else { + try { + // l'article n'est pas en BDD, on va le chercher sur le site + $this->content = get_content_by_parsing( + $this->link(), $pathEntries + ); + } catch (Exception $e) { + // rien à faire, on garde l'ancien contenu (requête a échoué) + } + } + } + } + + public function toArray () { + return array ( + 'id' => $this->id (), + 'guid' => $this->guid (), + 'title' => $this->title (), + 'author' => $this->author (), + 'content' => $this->content (), + 'link' => $this->link (), + 'date' => $this->date (true), + 'is_read' => $this->isRead (), + 'is_favorite' => $this->isFavorite (), + 'id_feed' => $this->feed (), + 'tags' => $this->tags (true), + ); + } +} -- cgit v1.2.3 From 847de9b3292ad854b281d7e12cc36ac93e745139 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 16 Dec 2013 00:54:13 +0100 Subject: PHP : performances fonction isDay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amélioration des performances de Entry->isDay() --- app/Controllers/indexController.php | 1 + app/Models/Entry.php | 27 +++++++++++++-------------- app/layout/nav_menu.phtml | 2 +- app/views/helpers/view/normal_view.phtml | 7 ++++--- 4 files changed, 19 insertions(+), 18 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index cc474302e..22c5683ea 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -125,6 +125,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { } $today = @strtotime('today'); + $this->view->today = $today; // on calcule la date des articles les plus anciens qu'on affiche $nb_month_old = $this->view->conf->oldEntries (); diff --git a/app/Models/Entry.php b/app/Models/Entry.php index ba0fb48f4..983f94727 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -134,21 +134,20 @@ class FreshRSS_Entry extends Minz_Model { $this->tags = $value; } - public function isDay ($day) { + public function isDay ($day, $today) { $date = $this->dateAdded(true); - $today = @strtotime('today'); - $yesterday = $today - 86400; - - if ($day === FreshRSS_Days::TODAY && - $date >= $today && $date < $today + 86400) { - return true; - } elseif ($day === FreshRSS_Days::YESTERDAY && - $date >= $yesterday && $date < $yesterday + 86400) { - return true; - } elseif ($day === FreshRSS_Days::BEFORE_YESTERDAY && $date < $yesterday) { - return true; - } else { - return false; + switch ($day) { + case FreshRSS_Days::TODAY: + $tomorrow = $today + 86400; + return $date >= $today && $date < $tomorrow; + case FreshRSS_Days::YESTERDAY: + $yesterday = $today - 86400; + return $date >= $yesterday && $date < $today; + case FreshRSS_Days::BEFORE_YESTERDAY: + $yesterday = $today - 86400; + return $date < $yesterday; + default: + return false; } } diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 92a987aed..045f391f9 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -72,7 +72,7 @@
  • today; $one_week = $today - 604800; ?>
  • diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml index 094017957..d5328651d 100644 --- a/app/views/helpers/view/normal_view.phtml +++ b/app/views/helpers/view/normal_view.phtml @@ -21,24 +21,25 @@ if (!empty($this->entries)) { $facebook = $this->conf->sharing ('facebook'); $email = $this->conf->sharing ('email'); $print = $this->conf->sharing ('print'); + $today = $this->today; ?> entries as $item) { ?> - isDay (FreshRSS_Days::TODAY)) { ?> + isDay (FreshRSS_Days::TODAY, $today)) { ?>
    - currentName; ?>
    - isDay (FreshRSS_Days::YESTERDAY)) { ?> + isDay (FreshRSS_Days::YESTERDAY, $today)) { ?>
    - currentName; ?>
    - isDay (FreshRSS_Days::BEFORE_YESTERDAY)) { ?> + isDay (FreshRSS_Days::BEFORE_YESTERDAY, $today)) { ?>
    currentName; ?> -- cgit v1.2.3 From 7b7acf5c8738e949109672748dbd9f39a6e5a2c4 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 23 Dec 2013 13:35:54 +0100 Subject: Synchronisation quelques lignes blanches --- README.md | 4 ++-- app/Models/CategoryDAO.php | 1 + app/Models/Configuration.php | 1 + app/Models/ConfigurationDAO.php | 1 + app/Models/Entry.php | 1 + app/Models/EntryDAO.php | 1 + app/Models/Feed.php | 1 + app/Models/FeedDAO.php | 1 + app/Models/LogDAO.php | 1 + public/install.php | 1 + 10 files changed, 11 insertions(+), 2 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/README.md b/README.md index a45c8e67c..87ed9de99 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ Il se veut léger et facile à prendre en main tout en étant un outil puissant * Site officiel : http://marienfressinaud.github.io/FreshRSS/ * Démo : http://marienfressinaud.fr/projets/freshrss/ * Développeur : Marien Fressinaud -* Version actuelle : 0.7-dev -* Date de publication 2013-12-xx +* Version actuelle : 0.7-beta +* Date de publication 2014-01-xx * License [GNU AGPL 3](http://www.gnu.org/licenses/agpl-3.0.html) ![Logo de FreshRSS](http://marienfressinaud.fr/data/images/freshrss/freshrss_title.png) diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 3a810e9f0..6b07ab063 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -1,4 +1,5 @@ prefix . 'category` (name, color) VALUES(?, ?)'; diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index 7ef76b522..d5f69601f 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -1,4 +1,5 @@ 'English', diff --git a/app/Models/ConfigurationDAO.php b/app/Models/ConfigurationDAO.php index 57fc98047..0eebf2d90 100644 --- a/app/Models/ConfigurationDAO.php +++ b/app/Models/ConfigurationDAO.php @@ -1,4 +1,5 @@ prefix . 'entry`(id, guid, title, author, content_bin, link, date, is_read, is_favorite, id_feed, tags) ' diff --git a/app/Models/Feed.php b/app/Models/Feed.php index e63ac8c7a..70efb0fa3 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -1,4 +1,5 @@ prefix . 'feed` (url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history) VALUES(?, ?, ?, ?, ?, ?, 10, ?, 0, 0)'; diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php index bf043fd6d..06855ec66 100644 --- a/app/Models/LogDAO.php +++ b/app/Models/LogDAO.php @@ -1,4 +1,5 @@ Date: Thu, 26 Dec 2013 02:50:58 +0100 Subject: Problème ctype_digit qui ne marche pas sur des variables qui sont déjà des entiers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Configuration.php | 16 +++++----------- app/Models/Entry.php | 7 ++----- app/Models/Feed.php | 7 ++++--- 3 files changed, 11 insertions(+), 19 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index 47509636f..cb2f90655 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -220,19 +220,13 @@ class FreshRSS_Configuration extends Minz_Model { public function _sortOrder ($value) { $this->sort_order = $value === 'ASC' ? 'ASC' : 'DESC'; } - public function _oldEntries ($value) { - if (ctype_digit ($value) && $value > 0) { - $this->old_entries = intval($value); - } else { - $this->old_entries = 3; - } + public function _oldEntries($value) { + $value = intval($value); + $this->old_entries = $value > 0 ? $value : 3; } public function _keepHistoryDefault($value) { - if (ctype_digit($value) && $value >= -1) { - $this->keep_history_default = intval($value); - } else { - $this->keep_history_default = 0; - } + $value = intval($value); + $this->keep_history_default = $value >= -1 ? $value : 0; } public function _shortcuts ($values) { foreach ($values as $key => $value) { diff --git a/app/Models/Entry.php b/app/Models/Entry.php index ed31ef2b1..ab9605eb1 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -106,11 +106,8 @@ class FreshRSS_Entry extends Minz_Model { $this->link = $value; } public function _date ($value) { - if (ctype_digit ($value)) { - $this->date = intval ($value); - } else { - $this->date = time (); - } + $value = intval($value); + $this->date = $value > 1 ? $value : time(); } public function _isRead ($value) { $this->is_read = $value; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index dcf97d4ec..3008e33d7 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -154,7 +154,8 @@ class FreshRSS_Feed extends Minz_Model { $this->lastUpdate = $value; } public function _priority ($value) { - $this->priority = ctype_digit ($value) ? intval ($value) : 10; + $value = intval($value); + $this->priority = $value >= 0 ? $value : 10; } public function _pathEntries ($value) { $this->pathEntries = $value; @@ -172,10 +173,10 @@ class FreshRSS_Feed extends Minz_Model { $this->keep_history = $value; } public function _nbNotRead ($value) { - $this->nbNotRead = ctype_digit ($value) ? intval ($value) : -1; + $this->nbNotRead = intval($value); } public function _nbEntries ($value) { - $this->nbEntries = ctype_digit ($value) ? intval ($value) : -1; + $this->nbEntries = intval($value); } public function load () { -- cgit v1.2.3 From 4d6ab45b03031e1c13ac2d3589364a43a0fe5578 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 30 Dec 2013 12:43:39 +0100 Subject: Micro-optimisation : évite is_null et quelques if/else MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contribue à https://github.com/marienfressinaud/FreshRSS/issues/303 --- app/Models/Category.php | 2 +- app/Models/Entry.php | 6 +----- app/Models/Feed.php | 32 +++++++++++--------------------- lib/Minz/Dispatcher.php | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/app/Models/Category.php b/app/Models/Category.php index e70d1303f..8e1e44ef8 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -48,7 +48,7 @@ class FreshRSS_Category extends Minz_Model { return $this->nbNotRead; } public function feeds () { - if (is_null ($this->feeds)) { + if ($this->feeds === null) { $feedDAO = new FreshRSS_FeedDAO (); $this->feeds = $feedDAO->listByCategory ($this->id ()); $this->nbFeed = 0; diff --git a/app/Models/Entry.php b/app/Models/Entry.php index ab9605eb1..83f68ce78 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -38,11 +38,7 @@ class FreshRSS_Entry extends Minz_Model { return $this->title; } public function author () { - if (is_null ($this->author)) { - return ''; - } else { - return $this->author; - } + return $this->author === null ? '' : $this->author; } public function content () { return $this->content; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 32f8546dd..f38828a42 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -44,11 +44,7 @@ class FreshRSS_Feed extends Minz_Model { return $this->category; } public function entries () { - if (!is_null ($this->entries)) { - return $this->entries; - } else { - return array (); - } + return $this->entries === null ? array() : $this->entries; } public function name () { return $this->name; @@ -140,10 +136,7 @@ class FreshRSS_Feed extends Minz_Model { $this->category = $value >= 0 ? $value : 0; } public function _name ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->name = $value; + $this->name = $value === null ? '' : $value; } public function _website ($value, $validate=true) { if ($validate) { @@ -155,10 +148,7 @@ class FreshRSS_Feed extends Minz_Model { $this->website = $value; } public function _description ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->description = $value; + $this->description = $value === null ? '' : $value; } public function _lastUpdate ($value) { $this->lastUpdate = $value; @@ -190,7 +180,7 @@ class FreshRSS_Feed extends Minz_Model { } public function load ($loadDetails = false) { - if (!is_null ($this->url)) { + if ($this->url !== null) { if (CACHE_PATH === false) { throw new Minz_FileNotExistException ( 'CACHE_PATH', @@ -253,7 +243,7 @@ class FreshRSS_Feed extends Minz_Model { // si on a utilisé l'auto-discover, notre url va avoir changé $subscribe_url = $feed->subscribe_url (); - if (!is_null ($subscribe_url) && $subscribe_url != $this->url) { + if ($subscribe_url !== null && $subscribe_url !== $this->url) { if ($this->httpAuth != '') { // on enlève les id si authentification HTTP $subscribe_url = preg_replace ('#((.+)://)((.+)@)(.+)#', '${1}${5}', $subscribe_url); @@ -263,7 +253,7 @@ class FreshRSS_Feed extends Minz_Model { if ($loadDetails) { $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8'); - $this->_name (!is_null ($title) ? $title : $this->url); + $this->_name ($title === null ? $this->url : $title); $this->_website(html_only_entity_decode($feed->get_link())); $this->_description(html_only_entity_decode($feed->get_description())); @@ -286,7 +276,7 @@ class FreshRSS_Feed extends Minz_Model { // gestion des tags (catégorie == tag) $tags_tmp = $item->get_categories (); $tags = array (); - if (!is_null ($tags_tmp)) { + if ($tags_tmp !== null) { foreach ($tags_tmp as $tag) { $tags[] = html_only_entity_decode ($tag->get_label ()); } @@ -308,10 +298,10 @@ class FreshRSS_Feed extends Minz_Model { $entry = new FreshRSS_Entry ( $this->id (), $item->get_id (), - !is_null ($title) ? $title : '', - !is_null ($author) ? html_only_entity_decode ($author->name) : '', - !is_null ($content) ? $content : '', - !is_null ($link) ? $link : '', + $title === null ? '' : $title, + $author === null ? '' : html_only_entity_decode ($author->name), + $content === null ? '' : $content, + $link === null ? '' : $link, $date ? $date : time () ); $entry->_tags ($tags); diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php index 2898b5f00..c2c5e7f65 100644 --- a/lib/Minz/Dispatcher.php +++ b/lib/Minz/Dispatcher.php @@ -22,7 +22,7 @@ class Minz_Dispatcher { * Récupère l'instance du Dispatcher */ public static function getInstance ($router) { - if (is_null (self::$instance)) { + if (self::$instance === null) { self::$instance = new Minz_Dispatcher ($router); } return self::$instance; -- cgit v1.2.3 From 6f117abfb6010150f95d2d0830a9715cd6f270fc Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 18 Jan 2014 22:54:53 +0100 Subject: Bugs chargement des articles complets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrige https://github.com/marienfressinaud/FreshRSS/issues/365 Ajoute le nettoyage correct du HTML par SimplePie, ainsi que le décodage des caractères HTML dans l'URL, et enfin un message dans le syslog pour chaque article téléchargé --- app/Models/Entry.php | 2 +- lib/lib_rss.php | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 83f68ce78..a6c67221b 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -159,7 +159,7 @@ class FreshRSS_Entry extends Minz_Model { try { // l'article n'est pas en BDD, on va le chercher sur le site $this->content = get_content_by_parsing( - $this->link(), $pathEntries + htmlspecialchars_decode($this->link(), ENT_QUOTES), $pathEntries ); } catch (Exception $e) { // rien à faire, on garde l'ancien contenu (requête a échoué) diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 4f98ed14a..33d7ebc32 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -110,6 +110,7 @@ function sanitizeHTML($data) { static $simplePie = null; if ($simplePie == null) { $simplePie = new SimplePie(); + $simplePie->init(); } return html_only_entity_decode($simplePie->sanitize->sanitize($data, SIMPLEPIE_CONSTRUCT_MAYBE_HTML)); } @@ -118,22 +119,13 @@ function sanitizeHTML($data) { function get_content_by_parsing ($url, $path) { require_once (LIB_PATH . '/lib_phpQuery.php'); + syslog(LOG_INFO, 'FreshRSS GET ' . $url); $html = file_get_contents ($url); if ($html) { $doc = phpQuery::newDocument ($html); $content = $doc->find ($path); - $content->find ('*')->removeAttr ('style') - ->removeAttr ('id') - ->removeAttr ('class') - ->removeAttr ('onload') - ->removeAttr ('target'); - $content->removeAttr ('style') - ->removeAttr ('id') - ->removeAttr ('class') - ->removeAttr ('onload') - ->removeAttr ('target'); - return $content->__toString (); + return sanitizeHTML($content->__toString()); } else { throw new Exception (); } -- cgit v1.2.3