diff options
Diffstat (limited to 'app/models')
| -rwxr-xr-x | app/models/Category.php | 6 | ||||
| -rwxr-xr-x | app/models/Entry.php | 52 | ||||
| -rw-r--r-- | app/models/Exception/FeedException.php | 6 | ||||
| -rw-r--r-- | app/models/Feed.php | 47 | ||||
| -rw-r--r-- | app/models/Log.php | 47 | ||||
| -rwxr-xr-x | app/models/RSSConfiguration.php | 54 |
6 files changed, 189 insertions, 23 deletions
diff --git a/app/models/Category.php b/app/models/Category.php index 273559b1e..0c991588d 100755 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -35,10 +35,10 @@ class Category extends Model { public function feeds () { if (is_null ($this->feeds)) { $feedDAO = new FeedDAO (); - return $feedDAO->listByCategory ($this->id ()); - } else { - return $this->feeds; + $this->feeds = $feedDAO->listByCategory ($this->id ()); } + + return $this->feeds; } public function _id ($value) { diff --git a/app/models/Entry.php b/app/models/Entry.php index f49e74239..6af3178ee 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -194,6 +194,29 @@ class Entry extends Model { } } + 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 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 (), @@ -239,7 +262,7 @@ class EntryDAO extends Model_pdo { return true; } else { $info = $stm->errorInfo(); - Log::record ('SQL error : ' . $info[2], Log::ERROR); + Log::record ('SQL error : ' . $info[2], Log::NOTICE); return false; } } @@ -360,6 +383,27 @@ class EntryDAO extends Model_pdo { } } + public function searchByGuid ($feed_id, $id) { + // un guid est unique pour un flux donné + $sql = 'SELECT * FROM entry WHERE id_feed=? AND guid=?'; + $stm = $this->bd->prepare ($sql); + + $values = array ( + $feed_id, + $id + ); + + $stm->execute ($values); + $res = $stm->fetchAll (PDO::FETCH_ASSOC); + list ($entry, $next) = HelperEntry::daoToEntry ($res); + + if (isset ($entry[0])) { + return $entry[0]; + } else { + return false; + } + } + public function searchById ($id) { $sql = 'SELECT * FROM entry WHERE id=?'; $stm = $this->bd->prepare ($sql); @@ -465,6 +509,12 @@ class EntryDAO extends Model_pdo { return $res[0]['count']; } + + public function optimizeTable() { + $sql = 'OPTIMIZE TABLE entry'; + $stm = $this->bd->prepare ($sql); + $stm->execute (); + } } class HelperEntry { diff --git a/app/models/Exception/FeedException.php b/app/models/Exception/FeedException.php index bc61e1736..bff297eb9 100644 --- a/app/models/Exception/FeedException.php +++ b/app/models/Exception/FeedException.php @@ -11,3 +11,9 @@ class BadUrlException extends FeedException { parent::__construct ('`' . $url . '` is not a valid URL'); } } + +class OpmlException extends FeedException { + public function __construct ($name_file) { + parent::__construct ('OPML file is invalid'); + } +} diff --git a/app/models/Feed.php b/app/models/Feed.php index 51c409b69..4c6a3d229 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -12,6 +12,7 @@ class Feed extends Model { private $priority = 10; private $pathEntries = ''; private $httpAuth = ''; + private $error = false; public function __construct ($url) { $this->_url ($url); @@ -69,6 +70,9 @@ class Feed extends Model { ); } } + public function inError () { + return $this->error; + } public function nbEntries () { $feedDAO = new FeedDAO (); return $feedDAO->countEntries ($this->id ()); @@ -138,6 +142,14 @@ class Feed extends Model { public function _httpAuth ($value) { $this->httpAuth = $value; } + public function _error ($value) { + if ($value) { + $value = true; + } else { + $value = false; + } + $this->error = $value; + } public function load () { if (!is_null ($this->url)) { @@ -204,18 +216,7 @@ class Feed extends Model { } } - // Gestion du contenu - // On cherche à récupérer les articles en entier... même si le flux ne le propose pas - $path = $this->pathEntries (); - if ($path) { - try { - $content = get_content_by_parsing ($item->get_permalink (), $path); - } catch (Exception $e) { - $content = $item->get_content (); - } - } else { - $content = $item->get_content (); - } + $content = $item->get_content (); $entry = new Entry ( $this->id (), @@ -227,6 +228,8 @@ class Feed extends Model { $date ? $date : time () ); $entry->_tags ($tags); + // permet de récupérer le contenu des flux tronqués + $entry->loadCompleteContent($this->pathEntries()); $entries[$entry->id ()] = $entry; } @@ -289,7 +292,7 @@ class FeedDAO extends Model_pdo { } public function updateLastUpdate ($id) { - $sql = 'UPDATE feed SET lastUpdate=? WHERE id=?'; + $sql = 'UPDATE feed SET lastUpdate=?, error=0 WHERE id=?'; $stm = $this->bd->prepare ($sql); $values = array ( @@ -306,6 +309,23 @@ class FeedDAO extends Model_pdo { } } + public function isInError ($id) { + $sql = 'UPDATE feed SET error=1 WHERE id=?'; + $stm = $this->bd->prepare ($sql); + + $values = array ( + $id + ); + + if ($stm && $stm->execute ($values)) { + return true; + } else { + $info = $stm->errorInfo(); + Log::record ('SQL error : ' . $info[2], Log::ERROR); + return false; + } + } + public function changeCategory ($idOldCat, $idNewCat) { $catDAO = new CategoryDAO (); $newCat = $catDAO->searchById ($idNewCat); @@ -470,6 +490,7 @@ class HelperFeed { $list[$key]->_priority ($dao['priority']); $list[$key]->_pathEntries ($dao['pathEntries']); $list[$key]->_httpAuth (base64_decode ($dao['httpAuth'])); + $list[$key]->_error ($dao['error']); if (isset ($dao['id'])) { $list[$key]->_id ($dao['id']); diff --git a/app/models/Log.php b/app/models/Log.php new file mode 100644 index 000000000..5c280fa7a --- /dev/null +++ b/app/models/Log.php @@ -0,0 +1,47 @@ +<?php + +class Log_Model extends Model { + private $date; + private $level; + private $information; + + public function date () { + return $this->date; + } + public function level () { + return $this->level; + } + public function info () { + return $this->information; + } + public function _date ($date) { + $this->date = $date; + } + public function _level ($level) { + $this->level = $level; + } + public function _info ($information) { + $this->information = $information; + } +} + +class LogDAO extends Model_txt { + public function __construct () { + parent::__construct (LOG_PATH . '/application.log', 'r+'); + } + + public function lister () { + $logs = array (); + + $i = 0; + while (($line = $this->readLine ()) !== false) { + $logs[$i] = new Log_Model (); + $logs[$i]->_date (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\1", $line)); + $logs[$i]->_level (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\2", $line)); + $logs[$i]->_info (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\3", $line)); + $i++; + } + + return $logs; + } +}
\ No newline at end of file diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php index 00fe3fe52..dde120e4a 100755 --- a/app/models/RSSConfiguration.php +++ b/app/models/RSSConfiguration.php @@ -7,8 +7,10 @@ class RSSConfiguration extends Model { ); private $language; private $posts_per_page; + private $view_mode; private $default_view; private $display_posts; + private $lazyload; private $sort_order; private $old_entries; private $shortcuts = array (); @@ -20,8 +22,10 @@ class RSSConfiguration extends Model { $confDAO = new RSSConfigurationDAO (); $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->_lazyload ($confDAO->lazyload); $this->_sortOrder ($confDAO->sort_order); $this->_oldEntries ($confDAO->old_entries); $this->_shortcuts ($confDAO->shortcuts); @@ -39,12 +43,18 @@ class RSSConfiguration extends Model { 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 lazyload () { + return $this->lazyload; + } public function sortOrder () { return $this->sort_order; } @@ -66,8 +76,8 @@ class RSSConfiguration extends Model { public function markWhenSite () { return $this->mark_when['site']; } - public function markWhenPage () { - return $this->mark_when['page']; + public function markWhenScroll () { + return $this->mark_when['scroll']; } public function urlShaarli () { return $this->url_shaarli; @@ -80,12 +90,19 @@ class RSSConfiguration extends Model { $this->language = $value; } public function _postsPerPage ($value) { - if (is_int (intval ($value))) { + if (is_int (intval ($value)) && $value > 0) { $this->posts_per_page = $value; } else { $this->posts_per_page = 10; } } + public function _viewMode ($value) { + if ($value == 'global' || $value == 'reader') { + $this->view_mode = $value; + } else { + $this->view_mode = 'normal'; + } + } public function _defaultView ($value) { if ($value == 'not_read') { $this->default_view = 'not_read'; @@ -100,6 +117,13 @@ class RSSConfiguration extends Model { $this->display_posts = 'no'; } } + public function _lazyload ($value) { + if ($value == 'no') { + $this->lazyload = 'no'; + } else { + $this->lazyload = 'yes'; + } + } public function _sortOrder ($value) { if ($value == 'high_to_low') { $this->sort_order = 'high_to_low'; @@ -108,7 +132,7 @@ class RSSConfiguration extends Model { } } public function _oldEntries ($value) { - if (is_int (intval ($value))) { + if (is_int (intval ($value)) && $value > 0) { $this->old_entries = $value; } else { $this->old_entries = 3; @@ -127,9 +151,19 @@ class RSSConfiguration extends Model { } } 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'; + } + $this->mark_when['article'] = $values['article']; $this->mark_when['site'] = $values['site']; - $this->mark_when['page'] = $values['page']; + $this->mark_when['scroll'] = $values['scroll']; } public function _urlShaarli ($value) { $this->url_shaarli = ''; @@ -142,8 +176,10 @@ class RSSConfiguration extends Model { class RSSConfigurationDAO extends Model_array { public $language = 'en'; public $posts_per_page = 20; + public $view_mode = 'normal'; public $default_view = 'not_read'; public $display_posts = 'no'; + public $lazyload = 'yes'; public $sort_order = 'low_to_high'; public $old_entries = 3; public $shortcuts = array ( @@ -159,7 +195,7 @@ class RSSConfigurationDAO extends Model_array { public $mark_when = array ( 'article' => 'yes', 'site' => 'yes', - 'page' => 'no' + 'scroll' => 'no' ); public $url_shaarli = ''; @@ -172,12 +208,18 @@ class RSSConfigurationDAO extends Model_array { if (isset ($this->array['posts_per_page'])) { $this->posts_per_page = $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['lazyload'])) { + $this->lazyload = $this->array['lazyload']; + } if (isset ($this->array['sort_order'])) { $this->sort_order = $this->array['sort_order']; } |
