diff options
Diffstat (limited to 'app/models')
| -rwxr-xr-x | app/models/Category.php | 2 | ||||
| -rw-r--r-- | app/models/EntriesGetter.php | 144 | ||||
| -rwxr-xr-x | app/models/Entry.php | 333 | ||||
| -rw-r--r-- | app/models/Exception/EntriesGetterException.php | 7 | ||||
| -rw-r--r-- | app/models/Exception/FeedException.php | 6 | ||||
| -rw-r--r-- | app/models/Feed.php | 75 | ||||
| -rwxr-xr-x | app/models/RSSConfiguration.php | 26 | ||||
| -rw-r--r-- | app/models/RSSPaginator.php | 29 |
8 files changed, 381 insertions, 241 deletions
diff --git a/app/models/Category.php b/app/models/Category.php index 7ce572e71..273559b1e 100755 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -176,7 +176,7 @@ class CategoryDAO extends Model_pdo { $def_cat = $this->searchById ('000000'); if (!$def_cat) { - $cat = new Category ('Sans catégorie'); + $cat = new Category (Translate::t ('default_category')); $cat->_id ('000000'); $values = array ( diff --git a/app/models/EntriesGetter.php b/app/models/EntriesGetter.php new file mode 100644 index 000000000..ca92804a7 --- /dev/null +++ b/app/models/EntriesGetter.php @@ -0,0 +1,144 @@ +<?php + +class EntriesGetter { + private $type = array ( + 'type' => 'all', + 'id' => 'all' + ); + private $state = 'all'; + private $filter = array ( + 'words' => array (), + 'tags' => array (), + ); + private $order = 'high_to_low'; + private $entries = array (); + + private $nb = 1; + private $first = ''; + private $next = ''; + + public function __construct ($type, $state, $filter, $order, $nb, $first = '') { + $this->_type ($type); + $this->_state ($state); + $this->_filter ($filter); + $this->_order ($order); + $this->nb = $nb; + $this->first = $first; + } + + public function type () { + return $this->type; + } + public function state () { + return $this->state; + } + public function filter () { + return $this->filter; + } + public function order () { + return $this->order; + } + public function entries () { + return $this->entries; + } + + public function _type ($value) { + if (!is_array ($value) || + !isset ($value['type']) || + !isset ($value['id'])) { + throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); + } + + $type = $value['type']; + $id = $value['id']; + + if ($type != 'all' && $type != 'favoris' && $type != 'public' && $type != 'c' && $type != 'f') { + throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); + } + + if (($type == 'all' || $type == 'favoris' || $type == 'public') && + ($type != $id)) { + throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); + } + + $this->type = $value; + } + public function _state ($value) { + if ($value != 'all' && $value != 'not_read' && $value != 'read') { + throw new EntriesGetterException ('Bad state line ' . __LINE__ . ' in file ' . __FILE__); + } + + $this->state = $value; + } + public function _filter ($value) { + $value = trim ($value); + $terms = explode (' ', $value); + + foreach ($terms as $word) { + if (!empty ($word) && $word[0] == '#' && isset ($word[1])) { + $tag = substr ($word, 1); + $this->filter['tags'][$tag] = $tag; + } elseif (!empty ($word)) { + $this->filter['words'][$word] = $word; + } + } + } + public function _order ($value) { + if ($value != 'high_to_low' && $value != 'low_to_high') { + throw new EntriesGetterException ('Bad order line ' . __LINE__ . ' in file ' . __FILE__); + } + + $this->order = $value; + } + + public function execute () { + $entryDAO = new EntryDAO (); + + HelperEntry::$nb = $this->nb; + HelperEntry::$first = $this->first; + HelperEntry::$filter = $this->filter; + + switch ($this->type['type']) { + case 'all': + list ($this->entries, $this->next) = $entryDAO->listEntries ( + $this->state, + $this->order + ); + break; + case 'favoris': + list ($this->entries, $this->next) = $entryDAO->listFavorites ( + $this->state, + $this->order + ); + break; + case 'public': + list ($this->entries, $this->next) = $entryDAO->listPublic ( + $this->state, + $this->order + ); + break; + case 'c': + list ($this->entries, $this->next) = $entryDAO->listByCategory ( + $this->type['id'], + $this->state, + $this->order + ); + break; + case 'f': + list ($this->entries, $this->next) = $entryDAO->listByFeed ( + $this->type['id'], + $this->state, + $this->order + ); + break; + default: + throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); + } + } + + public function getPaginator () { + $paginator = new RSSPaginator ($this->entries, $this->next); + + return $paginator; + } +} diff --git a/app/models/Entry.php b/app/models/Entry.php index 230b457bf..f49e74239 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -216,7 +216,7 @@ class Entry extends Model { class EntryDAO extends Model_pdo { public function addEntry ($valuesTmp) { - $sql = 'INSERT INTO entry(id, guid, title, author, content, link, date, is_read, is_favorite, is_public, id_feed, lastUpdate) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + $sql = 'INSERT INTO entry(id, guid, title, author, content, link, date, is_read, is_favorite, is_public, id_feed, lastUpdate, tags) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; $stm = $this->bd->prepare ($sql); $values = array ( @@ -232,6 +232,7 @@ class EntryDAO extends Model_pdo { $valuesTmp['is_public'], $valuesTmp['id_feed'], $valuesTmp['lastUpdate'], + $valuesTmp['tags'], ); if ($stm && $stm->execute ($values)) { @@ -367,7 +368,7 @@ class EntryDAO extends Model_pdo { $stm->execute ($values); $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $entry = HelperEntry::daoToEntry ($res); + list ($entry, $next) = HelperEntry::daoToEntry ($res); if (isset ($entry[0])) { return $entry[0]; @@ -376,16 +377,11 @@ class EntryDAO extends Model_pdo { } } - public function listEntries ($mode, $search = false, $order = 'high_to_low') { - $where = ' WHERE priority > 0'; - if ($mode == 'not_read') { - $where .= ' AND is_read=0'; - } - - $values = array(); - if ($search) { - $values[] = '%'.$search.'%'; - $where .= ' AND title LIKE ?'; + public function listWhere ($where, $state, $order, $values = array ()) { + if ($state == 'not_read') { + $where .= ' AND is_read = 0'; + } elseif ($state == 'read') { + $where .= ' AND is_read = 1'; } if ($order == 'low_to_high') { @@ -394,181 +390,28 @@ class EntryDAO extends Model_pdo { $order = ''; } - $sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where; - $stm = $this->bd->prepare ($sql); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $this->nbItems = $res[0]['count']; - - $deb = ($this->currentPage () - 1) * $this->nbItemsPerPage; - $fin = $this->nbItemsPerPage; - $sql = 'SELECT e.* FROM entry e' . ' INNER JOIN feed f ON e.id_feed = f.id' . $where - . ' ORDER BY date' . $order - . ' LIMIT ' . $deb . ', ' . $fin; + . ' ORDER BY date' . $order; $stm = $this->bd->prepare ($sql); $stm->execute ($values); return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); } - - public function listFavorites ($mode, $search = false, $order = 'high_to_low') { - $where = ' WHERE is_favorite=1'; - if ($mode == 'not_read') { - $where .= ' AND is_read=0'; - } - - $values = array(); - if ($search) { - $values[] = '%'.$search.'%'; - $where .= ' AND title LIKE ?'; - } - - if ($order == 'low_to_high') { - $order = ' DESC'; - } else { - $order = ''; - } - - $sql = 'SELECT COUNT(*) AS count FROM entry' . $where; - $stm = $this->bd->prepare ($sql); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $this->nbItems = $res[0]['count']; - - if($this->nbItemsPerPage < 0) { - $sql = 'SELECT * FROM entry' . $where - . ' ORDER BY date' . $order; - } else { - $deb = ($this->currentPage () - 1) * $this->nbItemsPerPage; - $fin = $this->nbItemsPerPage; - - $sql = 'SELECT * FROM entry' . $where - . ' ORDER BY date' . $order - . ' LIMIT ' . $deb . ', ' . $fin; - } - $stm = $this->bd->prepare ($sql); - - $stm->execute ($values); - - return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); + public function listEntries ($state, $order = 'high_to_low') { + return $this->listWhere (' WHERE priority > 0', $state, $order); } - - public function listPublic ($mode, $search = false, $order = 'high_to_low') { - $where = ' WHERE is_public=1'; - if ($mode == 'not_read') { - $where .= ' AND is_read=0'; - } - - $values = array(); - if ($search) { - $values[] = '%'.$search.'%'; - $where .= ' AND title LIKE ?'; - } - - if ($order == 'low_to_high') { - $order = ' DESC'; - } else { - $order = ''; - } - - $sql = 'SELECT COUNT(*) AS count FROM entry' . $where; - $stm = $this->bd->prepare ($sql); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $this->nbItems = $res[0]['count']; - - if($this->nbItemsPerPage < 0) { - $sql = 'SELECT * FROM entry' . $where - . ' ORDER BY date' . $order; - } else { - $deb = ($this->currentPage () - 1) * $this->nbItemsPerPage; - $fin = $this->nbItemsPerPage; - - $sql = 'SELECT * FROM entry' . $where - . ' ORDER BY date' . $order - . ' LIMIT ' . $deb . ', ' . $fin; - } - $stm = $this->bd->prepare ($sql); - - $stm->execute ($values); - - return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); + public function listFavorites ($state, $order = 'high_to_low') { + return $this->listWhere (' WHERE is_favorite = 1', $state, $order); } - - public function listByCategory ($cat, $mode, $search = false, $order = 'high_to_low') { - $where = ' WHERE category=?'; - if ($mode == 'not_read') { - $where .= ' AND is_read=0'; - } - - $values = array ($cat); - if ($search) { - $values[] = '%'.$search.'%'; - $where .= ' AND title LIKE ?'; - } - - if ($order == 'low_to_high') { - $order = ' DESC'; - } else { - $order = ''; - } - - $sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where; - $stm = $this->bd->prepare ($sql); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $this->nbItems = $res[0]['count']; - - $deb = ($this->currentPage () - 1) * $this->nbItemsPerPage; - $fin = $this->nbItemsPerPage; - $sql = 'SELECT e.* FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where - . ' ORDER BY date' . $order - . ' LIMIT ' . $deb . ', ' . $fin; - - $stm = $this->bd->prepare ($sql); - - $stm->execute ($values); - - return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); + public function listPublic ($state, $order = 'high_to_low') { + return $this->listWhere (' WHERE is_public = 1', $state, $order); } - - public function listByFeed ($feed, $mode, $search = false, $order = 'high_to_low') { - $where = ' WHERE id_feed=?'; - if ($mode == 'not_read') { - $where .= ' AND is_read=0'; - } - - $values = array($feed); - if ($search) { - $values[] = '%'.$search.'%'; - $where .= ' AND title LIKE ?'; - } - - if ($order == 'low_to_high') { - $order = ' DESC'; - } else { - $order = ''; - } - - $sql = 'SELECT COUNT(*) AS count FROM entry' . $where; - $stm = $this->bd->prepare ($sql); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $this->nbItems = $res[0]['count']; - - $deb = ($this->currentPage () - 1) * $this->nbItemsPerPage; - $fin = $this->nbItemsPerPage; - $sql = 'SELECT * FROM entry e' . $where - . ' ORDER BY date' . $order - . ' LIMIT ' . $deb . ', ' . $fin; - - $stm = $this->bd->prepare ($sql); - - $stm->execute ($values); - - return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); + public function listByCategory ($cat, $state, $order = 'high_to_low') { + return $this->listWhere (' WHERE category = ?', $state, $order, array ($cat)); + } + public function listByFeed ($feed, $state, $order = 'high_to_low') { + return $this->listWhere (' WHERE id_feed = ?', $state, $order, array ($feed)); } public function count () { @@ -579,7 +422,6 @@ class EntryDAO extends Model_pdo { return $res[0]['count']; } - public function countNotRead () { $sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE is_read=0 AND priority > 0'; $stm = $this->bd->prepare ($sql); @@ -615,7 +457,6 @@ class EntryDAO extends Model_pdo { return $res[0]['count']; } - public function countFavorites () { $sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_favorite=1'; $stm = $this->bd->prepare ($sql); @@ -624,73 +465,103 @@ class EntryDAO extends Model_pdo { return $res[0]['count']; } +} - // gestion de la pagination directement via le DAO - private $nbItemsPerPage = 1; - private $currentPage = 1; - private $nbItems = 0; - public function _nbItemsPerPage ($value) { - $this->nbItemsPerPage = $value; - } - public function _currentPage ($value) { - $this->currentPage = $value; - } - public function currentPage () { - if ($this->currentPage < 1) { - return 1; +class HelperEntry { + public static $nb = 1; + public static $first = ''; + + public static $filter = array ( + 'words' => array (), + 'tags' => array (), + ); + + public static function daoToEntry ($listDAO) { + $list = array (); + + if (!is_array ($listDAO)) { + $listDAO = array ($listDAO); } - $maxPage = ceil ($this->nbItems / $this->nbItemsPerPage); - if ($this->currentPage > $maxPage) { - return $maxPage; + $count = 0; + $first_is_found = false; + $break_after = false; + $next = ''; + foreach ($listDAO as $key => $dao) { + $dao['content'] = unserialize (gzinflate (base64_decode ($dao['content']))); + $dao['tags'] = preg_split('/[\s#]/', $dao['tags']); + + if (self::tagsMatchEntry ($dao) && + self::searchMatchEntry ($dao)) { + if ($break_after) { + $next = $dao['id']; + break; + } + if ($first_is_found || $dao['id'] == self::$first || self::$first == '') { + $list[$key] = self::createEntry ($dao); + + $count++; + $first_is_found = true; + } + if ($count >= self::$nb) { + $break_after = true; + } + } } - return $this->currentPage; + unset ($listDAO); + return array ($list, $next); } - public function getPaginator ($entries) { - $paginator = new Paginator ($entries); - $paginator->_nbItems ($this->nbItems); - $paginator->_nbItemsPerPage ($this->nbItemsPerPage); - $paginator->_currentPage ($this->currentPage ()); + private static function createEntry ($dao) { + $entry = new Entry ( + $dao['id_feed'], + $dao['guid'], + $dao['title'], + $dao['author'], + $dao['content'], + $dao['link'], + $dao['date'], + $dao['is_read'], + $dao['is_favorite'], + $dao['is_public'] + ); - return $paginator; - } -} + $entry->_notes ($dao['annotation']); + $entry->_lastUpdate ($dao['lastUpdate']); + $entry->_tags ($dao['tags']); -class HelperEntry { - public static function daoToEntry ($listDAO, $mode = 'all', $favorite = false) { - $list = array (); + if (isset ($dao['id'])) { + $entry->_id ($dao['id']); + } - if (!is_array ($listDAO)) { - $listDAO = array ($listDAO); + return $entry; + } + + private static function tagsMatchEntry ($dao) { + $tags = self::$filter['tags']; + foreach ($tags as $tag) { + if (!in_array ($tag, $dao['tags'])) { + return false; + } } - foreach ($listDAO as $key => $dao) { - $list[$key] = new Entry ( - $dao['id_feed'], - $dao['guid'], - $dao['title'], - $dao['author'], - unserialize (gzinflate (base64_decode ($dao['content']))), - $dao['link'], - $dao['date'], - $dao['is_read'], - $dao['is_favorite'], - $dao['is_public'] - ); - - $tags = preg_split('/[\s#]/', $dao['tags']); - $list[$key]->_notes ($dao['annotation']); - $list[$key]->_lastUpdate ($dao['lastUpdate']); - $list[$key]->_tags ($tags); - - if (isset ($dao['id'])) { - $list[$key]->_id ($dao['id']); + return true; + } + private static function searchMatchEntry ($dao) { + $words = self::$filter['words']; + + foreach ($words as $word) { + $word = strtolower ($word); + if (strpos (strtolower ($dao['title']), $word) === false && + strpos (strtolower ($dao['content']), $word) === false && + strpos (strtolower ($dao['link']), $word) === false && + strpos (strtolower ($dao['annotation']), $word) === false) { + return false; } } - return $list; + return true; } } diff --git a/app/models/Exception/EntriesGetterException.php b/app/models/Exception/EntriesGetterException.php new file mode 100644 index 000000000..3a51bff7c --- /dev/null +++ b/app/models/Exception/EntriesGetterException.php @@ -0,0 +1,7 @@ +<?php + +class EntriesGetterException extends Exception { + public function __construct ($message) { + parent::__construct ($message); + } +} diff --git a/app/models/Exception/FeedException.php b/app/models/Exception/FeedException.php index 3fe0f4ea0..bc61e1736 100644 --- a/app/models/Exception/FeedException.php +++ b/app/models/Exception/FeedException.php @@ -5,3 +5,9 @@ class FeedException extends Exception { parent::__construct ($message); } } + +class BadUrlException extends FeedException { + public function __construct ($url) { + parent::__construct ('`' . $url . '` is not a valid URL'); + } +} diff --git a/app/models/Feed.php b/app/models/Feed.php index 222e22256..51c409b69 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -59,9 +59,13 @@ class Feed extends Model { if ($raw) { return $this->httpAuth; } else { + $pos_colon = strpos ($this->httpAuth, ':'); + $user = substr ($this->httpAuth, 0, $pos_colon); + $pass = substr ($this->httpAuth, $pos_colon + 1); + return array ( - 'username' => '', - 'password' => '' + 'username' => $user, + 'password' => $pass ); } } @@ -73,6 +77,16 @@ class Feed extends Model { $feedDAO = new FeedDAO (); return $feedDAO->countNotRead ($this->id ()); } + public function favicon () { + $file = '/data/favicons/' . $this->id () . '.ico'; + + $favicon_url = Url::display ($file); + if (!file_exists (PUBLIC_PATH . $file)) { + $favicon_url = dowload_favicon ($this->website (), $this->id ()); + } + + return $favicon_url; + } public function _id ($value) { $this->id = $value; @@ -85,7 +99,7 @@ class Feed extends Model { if (!is_null ($value) && filter_var ($value, FILTER_VALIDATE_URL)) { $this->url = $value; } else { - throw new Exception (); + throw new BadUrlException ($value); } } public function _category ($value) { @@ -134,22 +148,40 @@ class Feed extends Model { ); } else { $feed = new SimplePie (); - $feed->set_feed_url (preg_replace ('/&/', '&', $this->url)); + $url = preg_replace ('/&/', '&', $this->url); + if ($this->httpAuth != '') { + $url = preg_replace ('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $url); + } + + $feed->set_feed_url ($url); $feed->set_cache_location (CACHE_PATH); + $feed->strip_htmltags (array ( + 'base', 'blink', 'body', 'doctype', + 'font', 'form', 'frame', 'frameset', 'html', + 'input', 'marquee', 'meta', 'noscript', + 'param', 'script', 'style' + )); $feed->init (); - if ($feed->error()) { + if ($feed->error ()) { throw new FeedException ($feed->error); } + // 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 ($this->httpAuth != '') { + // on enlève les id si authentification HTTP + $subscribe_url = preg_replace ('#((.+)://)((.+)@)(.+)#', '${1}${5}', $subscribe_url); + } $this->_url ($subscribe_url); } $title = $feed->get_title (); $this->_name (!is_null ($title) ? $title : $this->url); $this->_website ($feed->get_link ()); $this->_description ($feed->get_description ()); + + // et on charge les articles du flux $this->loadEntries ($feed); } } @@ -205,7 +237,7 @@ class Feed extends Model { class FeedDAO extends Model_pdo { public function addFeed ($valuesTmp) { - $sql = 'INSERT INTO feed (id, url, category, name, website, description, lastUpdate, priority, error) VALUES(?, ?, ?, ?, ?, ?, ?, 10, 0)'; + $sql = 'INSERT INTO feed (id, url, category, name, website, description, lastUpdate, priority, httpAuth, error) VALUES(?, ?, ?, ?, ?, ?, ?, 10, ?, 0)'; $stm = $this->bd->prepare ($sql); $values = array ( @@ -216,6 +248,7 @@ class FeedDAO extends Model_pdo { $valuesTmp['website'], $valuesTmp['description'], $valuesTmp['lastUpdate'], + base64_encode ($valuesTmp['httpAuth']), ); if ($stm && $stm->execute ($values)) { @@ -231,6 +264,10 @@ class FeedDAO extends Model_pdo { $set = ''; foreach ($valuesTmp as $key => $v) { $set .= $key . '=?, '; + + if ($key == 'httpAuth') { + $valuesTmp[$key] = base64_encode ($v); + } } $set = substr ($set, 0, -2); @@ -269,6 +306,30 @@ class FeedDAO extends Model_pdo { } } + public function changeCategory ($idOldCat, $idNewCat) { + $catDAO = new CategoryDAO (); + $newCat = $catDAO->searchById ($idNewCat); + if (!$newCat) { + $newCat = $catDAO->getDefault (); + } + + $sql = 'UPDATE feed SET category=? WHERE category=?'; + $stm = $this->bd->prepare ($sql); + + $values = array ( + $newCat->id (), + $idOldCat + ); + + if ($stm && $stm->execute ($values)) { + return true; + } else { + $info = $stm->errorInfo(); + Log::record ('SQL error : ' . $info[2], Log::ERROR); + return false; + } + } + public function deleteFeed ($id) { $sql = 'DELETE FROM feed WHERE id=?'; $stm = $this->bd->prepare ($sql); @@ -408,7 +469,7 @@ class HelperFeed { $list[$key]->_lastUpdate ($dao['lastUpdate']); $list[$key]->_priority ($dao['priority']); $list[$key]->_pathEntries ($dao['pathEntries']); - $list[$key]->_httpAuth ($dao['httpAuth']); + $list[$key]->_httpAuth (base64_decode ($dao['httpAuth'])); if (isset ($dao['id'])) { $list[$key]->_id ($dao['id']); diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php index ca56ec3a8..00fe3fe52 100755 --- a/app/models/RSSConfiguration.php +++ b/app/models/RSSConfiguration.php @@ -1,6 +1,11 @@ <?php class RSSConfiguration extends Model { + private $available_languages = array ( + 'en' => 'English', + 'fr' => 'Français', + ); + private $language; private $posts_per_page; private $default_view; private $display_posts; @@ -13,6 +18,7 @@ class RSSConfiguration extends Model { public function __construct () { $confDAO = new RSSConfigurationDAO (); + $this->_language ($confDAO->language); $this->_postsPerPage ($confDAO->posts_per_page); $this->_defaultView ($confDAO->default_view); $this->_displayPosts ($confDAO->display_posts); @@ -24,6 +30,12 @@ class RSSConfiguration extends Model { $this->_urlShaarli ($confDAO->url_shaarli); } + public function availableLanguages () { + return $this->available_languages; + } + public function language () { + return $this->language; + } public function postsPerPage () { return $this->posts_per_page; } @@ -60,7 +72,13 @@ class RSSConfiguration extends Model { public function urlShaarli () { return $this->url_shaarli; } - + + public function _language ($value) { + if (!isset ($this->available_languages[$value])) { + $value = 'en'; + } + $this->language = $value; + } public function _postsPerPage ($value) { if (is_int (intval ($value))) { $this->posts_per_page = $value; @@ -122,6 +140,7 @@ class RSSConfiguration extends Model { } class RSSConfigurationDAO extends Model_array { + public $language = 'en'; public $posts_per_page = 20; public $default_view = 'not_read'; public $display_posts = 'no'; @@ -146,7 +165,10 @@ class RSSConfigurationDAO extends Model_array { public function __construct () { parent::__construct (PUBLIC_PATH . '/data/Configuration.array.php'); - + + if (isset ($this->array['language'])) { + $this->language = $this->array['language']; + } if (isset ($this->array['posts_per_page'])) { $this->posts_per_page = $this->array['posts_per_page']; } diff --git a/app/models/RSSPaginator.php b/app/models/RSSPaginator.php new file mode 100644 index 000000000..7010291bc --- /dev/null +++ b/app/models/RSSPaginator.php @@ -0,0 +1,29 @@ +<?php + +// Un système de pagination beaucoup plus simple que Paginator +// mais mieux adapté à nos besoins +class RSSPaginator { + private $items = array (); + private $next = ''; + + public function __construct ($items, $next) { + $this->items = $items; + $this->next = $next; + } + + public function isEmpty () { + return empty ($this->items); + } + + public function items () { + return $this->items; + } + + public function render ($view, $getteur) { + $view = APP_PATH . '/views/helpers/'.$view; + + if (file_exists ($view)) { + include ($view); + } + } +} |
