diff options
| author | 2014-01-29 21:26:19 +0100 | |
|---|---|---|
| committer | 2014-01-29 21:26:19 +0100 | |
| commit | 165eb57459a152b3cc6aa3fd15ca990c3d908829 (patch) | |
| tree | 640ddacbc6eabc985646dd65b0578f369ea92321 /app/models | |
| parent | 75096e6a39fe5d34d3951991f296f616e62a9fd8 (diff) | |
| parent | c053825ff8f9792e692c101585481129b006937b (diff) | |
Sortie de la version 0.70.7.0
Diffstat (limited to 'app/models')
| -rwxr-xr-x | app/models/Category.php | 332 | ||||
| -rw-r--r-- | app/models/Days.php | 7 | ||||
| -rw-r--r-- | app/models/EntriesGetter.php | 156 | ||||
| -rwxr-xr-x | app/models/Entry.php | 590 | ||||
| -rw-r--r-- | app/models/Exception/EntriesGetterException.php | 7 | ||||
| -rw-r--r-- | app/models/Exception/FeedException.php | 19 | ||||
| -rw-r--r-- | app/models/Feed.php | 564 | ||||
| -rw-r--r-- | app/models/Log_Model.php | 47 | ||||
| -rwxr-xr-x | app/models/RSSConfiguration.php | 445 | ||||
| -rw-r--r-- | app/models/RSSPaginator.php | 33 | ||||
| -rw-r--r-- | app/models/RSSThemes.php | 47 |
11 files changed, 0 insertions, 2247 deletions
diff --git a/app/models/Category.php b/app/models/Category.php deleted file mode 100755 index 7659e68f6..000000000 --- a/app/models/Category.php +++ /dev/null @@ -1,332 +0,0 @@ -<?php - -class Category extends Model { - private $id = false; - private $name; - private $color; - private $nbFeed = -1; - private $nbNotRead = -1; - private $feeds = null; - - public function __construct ($name = '', $color = '#0062BE', $feeds = null) { - $this->_name ($name); - $this->_color ($color); - if (isset ($feeds)) { - $this->_feeds ($feeds); - $this->nbFeed = 0; - $this->nbNotRead = 0; - foreach ($feeds as $feed) { - $this->nbFeed++; - $this->nbNotRead += $feed->nbNotRead (); - } - } - } - - public function id () { - if (!$this->id) { - return small_hash ($this->name . time () . Configuration::selApplication ()); - } else { - return $this->id; - } - } - public function name () { - return $this->name; - } - public function color () { - return $this->color; - } - public function nbFeed () { - if ($this->nbFeed < 0) { - $catDAO = new CategoryDAO (); - $this->nbFeed = $catDAO->countFeed ($this->id ()); - } - - return $this->nbFeed; - } - public function nbNotRead () { - if ($this->nbNotRead < 0) { - $catDAO = new CategoryDAO (); - $this->nbNotRead = $catDAO->countNotRead ($this->id ()); - } - - return $this->nbNotRead; - } - public function feeds () { - if (is_null ($this->feeds)) { - $feedDAO = new FeedDAO (); - $this->feeds = $feedDAO->listByCategory ($this->id ()); - $this->nbFeed = 0; - $this->nbNotRead = 0; - foreach ($this->feeds as $feed) { - $this->nbFeed++; - $this->nbNotRead += $feed->nbNotRead (); - } - } - - return $this->feeds; - } - - public function _id ($value) { - $this->id = $value; - } - public function _name ($value) { - $this->name = $value; - } - public function _color ($value) { - if (preg_match ('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { - $this->color = $value; - } else { - $this->color = '#0062BE'; - } - } - public function _feeds ($values) { - if (!is_array ($values)) { - $values = array ($values); - } - - $this->feeds = $values; - } -} - -class CategoryDAO extends Model_pdo { - public function addCategory ($valuesTmp) { - $sql = 'INSERT INTO ' . $this->prefix . 'category (id, name, color) VALUES(?, ?, ?)'; - $stm = $this->bd->prepare ($sql); - - $values = array ( - $valuesTmp['id'], - $valuesTmp['name'], - $valuesTmp['color'], - ); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function updateCategory ($id, $valuesTmp) { - $sql = 'UPDATE ' . $this->prefix . 'category SET name=?, color=? WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ( - $valuesTmp['name'], - $valuesTmp['color'], - $id - ); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function deleteCategory ($id) { - $sql = 'DELETE FROM ' . $this->prefix . 'category WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ($id); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function searchById ($id) { - $sql = 'SELECT * FROM ' . $this->prefix . 'category WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ($id); - - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $cat = HelperCategory::daoToCategory ($res); - - if (isset ($cat[0])) { - return $cat[0]; - } else { - return false; - } - } - public function searchByName ($name) { - $sql = 'SELECT * FROM ' . $this->prefix . 'category WHERE name=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ($name); - - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $cat = HelperCategory::daoToCategory ($res); - - if (isset ($cat[0])) { - return $cat[0]; - } else { - return false; - } - } - - public function listCategories ($prePopulateFeeds = true) { - if ($prePopulateFeeds) { - $sql = 'SELECT c.id AS c_id, c.name AS c_name, c.color AS c_color, ' - . 'COUNT(CASE WHEN e.is_read = 0 THEN 1 END) AS nbNotRead, ' - . 'COUNT(e.id) AS nbEntries, ' - . 'f.* ' - . 'FROM ' . $this->prefix . 'category c ' - . 'LEFT OUTER JOIN ' . $this->prefix . 'feed f ON f.category = c.id ' - . 'LEFT OUTER JOIN ' . $this->prefix . 'entry e ON e.id_feed = f.id ' - . 'GROUP BY f.id ' - . 'ORDER BY c.name, f.name'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - return HelperCategory::daoToCategoryPrepopulated ($stm->fetchAll (PDO::FETCH_ASSOC)); - } else { - $sql = 'SELECT * FROM ' . $this->prefix . 'category ORDER BY name'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - return HelperCategory::daoToCategory ($stm->fetchAll (PDO::FETCH_ASSOC)); - } - } - - public function getDefault () { - $sql = 'SELECT * FROM ' . $this->prefix . 'category WHERE id="000000"'; - $stm = $this->bd->prepare ($sql); - - $stm->execute (); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $cat = HelperCategory::daoToCategory ($res); - - if (isset ($cat[0])) { - return $cat[0]; - } else { - return false; - } - } - public function checkDefault () { - $def_cat = $this->searchById ('000000'); - - if ($def_cat === false) { - $cat = new Category (Translate::t ('default_category')); - $cat->_id ('000000'); - - $values = array ( - 'id' => $cat->id (), - 'name' => $cat->name (), - 'color' => $cat->color () - ); - - $this->addCategory ($values); - } - } - - public function count () { - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'category'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - return $res[0]['count']; - } - - public function countFeed ($id) { - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'feed WHERE category=?'; - $stm = $this->bd->prepare ($sql); - $values = array ($id); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - return $res[0]['count']; - } - - public function countNotRead ($id) { - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE category=? AND e.is_read=0'; - $stm = $this->bd->prepare ($sql); - $values = array ($id); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - return $res[0]['count']; - } -} - -class HelperCategory { - public static function findFeed($categories, $feed_id) { - foreach ($categories as $category) { - foreach ($category->feeds () as $feed) { - if ($feed->id () === $feed_id) { - return $feed; - } - } - } - return null; - } - - public static function daoToCategoryPrepopulated ($listDAO) { - $list = array (); - - if (!is_array ($listDAO)) { - $listDAO = array ($listDAO); - } - - $previousLine = null; - $feedsDao = array(); - foreach ($listDAO as $line) { - if ($previousLine['c_id'] != null && $line['c_id'] !== $previousLine['c_id']) { - // End of the current category, we add it to the $list - $cat = new Category ( - $previousLine['c_name'], - $previousLine['c_color'], - HelperFeed::daoToFeed ($feedsDao) - ); - $cat->_id ($previousLine['c_id']); - $list[] = $cat; - - $feedsDao = array(); //Prepare for next category - } - - $previousLine = $line; - $feedsDao[] = $line; - } - - // add the last category - if ($previousLine != null) { - $cat = new Category ( - $previousLine['c_name'], - $previousLine['c_color'], - HelperFeed::daoToFeed ($feedsDao) - ); - $cat->_id ($previousLine['c_id']); - $list[] = $cat; - } - - return $list; - } - - public static function daoToCategory ($listDAO) { - $list = array (); - - if (!is_array ($listDAO)) { - $listDAO = array ($listDAO); - } - - foreach ($listDAO as $key => $dao) { - $cat = new Category ( - $dao['name'], - $dao['color'] - ); - $cat->_id ($dao['id']); - $list[$key] = $cat; - } - - return $list; - } -} diff --git a/app/models/Days.php b/app/models/Days.php deleted file mode 100644 index a859cbace..000000000 --- a/app/models/Days.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -class Days { - const TODAY = 0; - const YESTERDAY = 1; - const BEFORE_YESTERDAY = 2; -} diff --git a/app/models/EntriesGetter.php b/app/models/EntriesGetter.php deleted file mode 100644 index 803aad732..000000000 --- a/app/models/EntriesGetter.php +++ /dev/null @@ -1,156 +0,0 @@ -<?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; //TODO: Update: Now done in SQL - HelperEntry::$first = $this->first; //TODO: Update: Now done in SQL - HelperEntry::$filter = $this->filter; - - $sqlLimit = (empty ($this->filter['words']) && empty ($this->filter['tags'])) ? $this->nb : ''; //Disable SQL LIMIT optimisation during search //TODO: Do better! - - switch ($this->type['type']) { - case 'all': - list ($this->entries, $this->next) = $entryDAO->listEntries ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'favoris': - list ($this->entries, $this->next) = $entryDAO->listFavorites ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'public': - list ($this->entries, $this->next) = $entryDAO->listPublic ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'c': - list ($this->entries, $this->next) = $entryDAO->listByCategory ( - $this->type['id'], - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'f': - list ($this->entries, $this->next) = $entryDAO->listByFeed ( - $this->type['id'], - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - 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 deleted file mode 100755 index 99edf94b4..000000000 --- a/app/models/Entry.php +++ /dev/null @@ -1,590 +0,0 @@ -<?php - -class Entry extends Model { - - private $id = null; - private $guid; - private $title; - private $author; - private $content; - private $link; - private $date; - private $is_read; - private $is_favorite; - private $feed; - private $tags; - - public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '', - $link = '', $pubdate = 0, $is_read = false, $is_favorite = false) { - $this->_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 (array ()); - } - - public function id () { - if(is_null($this->id)) { - return small_hash ($this->guid . Configuration::selApplication ()); - } else { - 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 isRead () { - return $this->is_read; - } - public function isFavorite () { - return $this->is_favorite; - } - public function feed ($object = false) { - if ($object) { - $feedDAO = new FeedDAO (); - return $feedDAO->searchById ($this->feed); - } else { - return $this->feed; - } - } - public function tags ($inString = false) { - if ($inString) { - if (!empty ($this->tags)) { - return '#' . implode(' #', $this->tags); - } else { - return ''; - } - } 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 (is_int (intval ($value))) { - $this->date = $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 = getdate (); - $today = mktime (0, 0, 0, $date['mon'], $date['mday'], $date['year']); - $yesterday = $today - 86400; - - if ($day == Days::TODAY && - $this->date >= $today && $this->date < $today + 86400) { - return true; - } elseif ($day == Days::YESTERDAY && - $this->date >= $yesterday && $this->date < $yesterday + 86400) { - return true; - } elseif ($day == Days::BEFORE_YESTERDAY && $this->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 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) - ); - } -} - -class EntryDAO extends Model_pdo { - public function addEntry ($valuesTmp) { - $sql = 'INSERT INTO ' . $this->prefix . 'entry(id, guid, title, author, content, link, date, is_read, is_favorite, id_feed, tags) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - $stm = $this->bd->prepare ($sql); - - $values = array ( - $valuesTmp['id'], - $valuesTmp['guid'], - $valuesTmp['title'], - $valuesTmp['author'], - base64_encode (gzdeflate (serialize ($valuesTmp['content']))), - $valuesTmp['link'], - $valuesTmp['date'], - $valuesTmp['is_read'], - $valuesTmp['is_favorite'], - $valuesTmp['id_feed'], - $valuesTmp['tags'], - ); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - if ((int)($info[0] / 1000) !== 23) { //Filter out "SQLSTATE Class code 23: Constraint Violation" because of expected duplicate entries - Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2], Minz_Log::NOTICE); //TODO: Consider adding a Minz_Log::DEBUG level - } - return false; - } - } - - public function updateEntry ($id, $valuesTmp) { - if (isset ($valuesTmp['content'])) { - $valuesTmp['content'] = base64_encode (gzdeflate (serialize ($valuesTmp['content']))); - } - - $set = ''; - foreach ($valuesTmp as $key => $v) { - $set .= $key . '=?, '; - } - $set = substr ($set, 0, -2); - - $sql = 'UPDATE ' . $this->prefix . 'entry SET ' . $set . ' WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - foreach ($valuesTmp as $v) { - $values[] = $v; - } - $values[] = $id; - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function markReadEntries ($read, $dateMax = 0) { - $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id SET is_read = ? WHERE priority > 0'; - - $values = array ($read); - if ($dateMax > 0) { - $sql .= ' AND date < ?'; - $values[] = $dateMax; - } - - $stm = $this->bd->prepare ($sql); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - public function markReadCat ($id, $read, $dateMax = 0) { - $sql = 'UPDATE ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id SET is_read = ? WHERE category = ?'; - - $values = array ($read, $id); - if ($dateMax > 0) { - $sql .= ' AND date < ?'; - $values[] = $dateMax; - } - - $stm = $this->bd->prepare ($sql); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - public function markReadFeed ($id, $read, $dateMax = 0) { - $sql = 'UPDATE ' . $this->prefix . 'entry SET is_read = ? WHERE id_feed = ?'; - - $values = array ($read, $id); - if ($dateMax > 0) { - $sql .= ' AND date < ?'; - $values[] = $dateMax; - } - - $stm = $this->bd->prepare ($sql); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function updateEntries ($valuesTmp) { - if (isset ($valuesTmp['content'])) { - $valuesTmp['content'] = base64_encode (gzdeflate (serialize ($valuesTmp['content']))); - } - - $set = ''; - foreach ($valuesTmp as $key => $v) { - $set .= $key . '=?, '; - } - $set = substr ($set, 0, -2); - - $sql = 'UPDATE ' . $this->prefix . 'entry SET ' . $set; - $stm = $this->bd->prepare ($sql); - - foreach ($valuesTmp as $v) { - $values[] = $v; - } - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function cleanOldEntries ($nb_month) { - $date = 60 * 60 * 24 * 30 * $nb_month; - $sql = 'DELETE e.* FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE e.date <= ? AND e.is_favorite = 0 AND f.keep_history = 0'; - $stm = $this->bd->prepare ($sql); - - $values = array ( - time () - $date - ); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function searchByGuid ($feed_id, $id) { - // un guid est unique pour un flux donné - $sql = 'SELECT * FROM ' . $this->prefix . '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 ' . $this->prefix . 'entry WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ($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; - } - } - - private function listWhere ($where, $state, $order, $limitFromId = '', $limitCount = '', $values = array ()) { - if ($state == 'not_read') { - $where .= ' AND is_read = 0'; - } elseif ($state == 'read') { - $where .= ' AND is_read = 1'; - } - if (!empty($limitFromId)) { //TODO: Consider using LPAD(e.date, 11) //CONCAT is for cases when many entries have the same date - $where .= ' AND CONCAT(e.date, e.id) ' . ($order === 'low_to_high' ? '<=' : '>=') . ' (SELECT CONCAT(s.date, s.id) FROM ' . $this->prefix . 'entry s WHERE s.id = "' . $limitFromId . '")'; - } - - if ($order == 'low_to_high') { - $order = ' DESC'; - } else { - $order = ''; - } - - $sql = 'SELECT e.* FROM ' . $this->prefix . 'entry e' - . ' INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id' . $where - . ' ORDER BY e.date' . $order . ', e.id' . $order; - - if (empty($limitCount)) { - $limitCount = 20000; //TODO: FIXME: Hack temporaire en attendant la recherche côté base-de-données - } - //if (!empty($limitCount)) { - $sql .= ' LIMIT ' . ($limitCount + 2); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ - //} - - $stm = $this->bd->prepare ($sql); - $stm->execute ($values); - - return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); - } - public function listEntries ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere (' WHERE priority > 0', $state, $order, $limitFromId, $limitCount); - } - public function listFavorites ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere (' WHERE is_favorite = 1', $state, $order, $limitFromId, $limitCount); - } - public function listPublic ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere (' WHERE is_public = 1', $state, $order, $limitFromId, $limitCount); - } - public function listByCategory ($cat, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere (' WHERE category = ?', $state, $order, $limitFromId, $limitCount, array ($cat)); - } - public function listByFeed ($feed, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere (' WHERE id_feed = ?', $state, $order, $limitFromId, $limitCount, array ($feed)); - } - - public function listLastIdsByFeed($id, $n) { - $sql = 'SELECT id FROM ' . $this->prefix . 'entry WHERE id_feed=? ORDER BY date DESC LIMIT ' . intval($n); - $stm = $this->bd->prepare ($sql); - $values = array ($id); - $stm->execute ($values); - return $stm->fetchAll (PDO::FETCH_COLUMN, 0); - } - - public function countUnreadRead () { - $sql = 'SELECT is_read, COUNT(*) AS count FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE priority > 0 GROUP BY is_read'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - $readUnread = array('unread' => 0, 'read' => 0); - foreach ($res as $line) { - switch (intval($line['is_read'])) { - case 0: $readUnread['unread'] = intval($line['count']); break; - case 1: $readUnread['read'] = intval($line['count']); break; - } - } - return $readUnread; - } - public function count () { //Deprecated: use countUnreadRead() instead - $unreadRead = $this->countUnreadRead (); //This makes better use of caching - return $unreadRead['unread'] + $unreadRead['read']; - } - public function countNotRead () { //Deprecated: use countUnreadRead() instead - $unreadRead = $this->countUnreadRead (); //This makes better use of caching - return $unreadRead['unread']; - } - - public function countUnreadReadFavorites () { - $sql = 'SELECT is_read, COUNT(*) AS count FROM ' . $this->prefix . 'entry WHERE is_favorite=1 GROUP BY is_read'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $readUnread = array('unread' => 0, 'read' => 0); - foreach ($res as $line) { - switch (intval($line['is_read'])) { - case 0: $readUnread['unread'] = intval($line['count']); break; - case 1: $readUnread['read'] = intval($line['count']); break; - } - } - return $readUnread; - } - - public function optimizeTable() { - $sql = 'OPTIMIZE TABLE ' . $this->prefix . 'entry'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - } -} - -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); - } - - $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; //TODO: Update: Now done in SQL - } - if ($count >= self::$nb) { - $break_after = true; - } - } - } - - unset ($listDAO); - - return array ($list, $next); - } - - 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'] - ); - - $entry->_tags ($dao['tags']); - - if (isset ($dao['id'])) { - $entry->_id ($dao['id']); - } - - return $entry; - } - - private static function tagsMatchEntry ($dao) { - $tags = self::$filter['tags']; - foreach ($tags as $tag) { - if (!in_array ($tag, $dao['tags'])) { - return false; - } - } - - 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) { - return false; - } - } - - return true; - } -} diff --git a/app/models/Exception/EntriesGetterException.php b/app/models/Exception/EntriesGetterException.php deleted file mode 100644 index 3a51bff7c..000000000 --- a/app/models/Exception/EntriesGetterException.php +++ /dev/null @@ -1,7 +0,0 @@ -<?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 deleted file mode 100644 index bff297eb9..000000000 --- a/app/models/Exception/FeedException.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -class FeedException extends Exception { - public function __construct ($message) { - parent::__construct ($message); - } -} - -class BadUrlException extends FeedException { - public function __construct ($url) { - 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 deleted file mode 100644 index 7f53d7be8..000000000 --- a/app/models/Feed.php +++ /dev/null @@ -1,564 +0,0 @@ -<?php - -class Feed extends Model { - private $id = null; - private $url; - private $category = '000000'; - private $nbEntries = -1; - private $nbNotRead = -1; - private $entries = null; - private $name = ''; - private $website = ''; - private $description = ''; - private $lastUpdate = 0; - private $priority = 10; - private $pathEntries = ''; - private $httpAuth = ''; - private $error = false; - private $keep_history = false; - - public function __construct ($url, $validate=true) { - if ($validate) { - $this->_url ($url); - } else { - $this->url = $url; - } - } - - public function id () { - if(is_null($this->id)) { - return small_hash ($this->url . Configuration::selApplication ()); - } else { - return $this->id; - } - } - public function url () { - return $this->url; - } - public function category () { - return $this->category; - } - public function entries () { - if (!is_null ($this->entries)) { - return $this->entries; - } else { - return array (); - } - } - public function name () { - return $this->name; - } - public function website () { - return $this->website; - } - public function description () { - return $this->description; - } - public function lastUpdate () { - return $this->lastUpdate; - } - public function priority () { - return $this->priority; - } - public function pathEntries () { - return $this->pathEntries; - } - public function httpAuth ($raw = true) { - 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' => $user, - 'password' => $pass - ); - } - } - public function inError () { - return $this->error; - } - public function keepHistory () { - return $this->keep_history; - } - public function nbEntries () { - if ($this->nbEntries < 0) { - $feedDAO = new FeedDAO (); - $this->nbEntries = $feedDAO->countEntries ($this->id ()); - } - - return $this->nbEntries; - } - public function nbNotRead () { - if ($this->nbNotRead < 0) { - $feedDAO = new FeedDAO (); - $this->nbNotRead = $feedDAO->countNotRead ($this->id ()); - } - - return $this->nbNotRead; - } - 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; - } - public function _url ($value) { - if (empty ($value)) { - throw new BadUrlException ($value); - } - if (!preg_match ('#^https?://#i', $value)) { - $value = 'http://' . $value; - } - - if (filter_var ($value, FILTER_VALIDATE_URL)) { - $this->url = $value; - } elseif (version_compare(PHP_VERSION, '5.3.3', '<') && (strpos($value, '-') > 0) && ($value === filter_var($value, FILTER_SANITIZE_URL))) { //PHP bug #51192 - $this->url = $value; - } else { - throw new BadUrlException ($value); - } - } - public function _category ($value) { - $this->category = $value; - } - public function _name ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->name = $value; - } - public function _website ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->website = $value; - } - public function _description ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->description = $value; - } - public function _lastUpdate ($value) { - $this->lastUpdate = $value; - } - public function _priority ($value) { - $this->priority = is_numeric ($value) ? intval ($value) : 10; - } - public function _pathEntries ($value) { - $this->pathEntries = $value; - } - public function _httpAuth ($value) { - $this->httpAuth = $value; - } - public function _error ($value) { - if ($value) { - $value = true; - } else { - $value = false; - } - $this->error = $value; - } - public function _keepHistory ($value) { - if ($value) { - $value = true; - } else { - $value = false; - } - $this->keep_history = $value; - } - public function _nbNotRead ($value) { - $this->nbNotRead = is_numeric ($value) ? intval ($value) : -1; - } - public function _nbEntries ($value) { - $this->nbEntries = is_numeric ($value) ? intval ($value) : -1; - } - - public function load () { - if (!is_null ($this->url)) { - if (CACHE_PATH === false) { - throw new FileNotExistException ( - 'CACHE_PATH', - MinzException::ERROR - ); - } else { - $feed = new SimplePie (); - $url = str_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->set_cache_duration(1500); - $feed->strip_htmltags (array ( - 'base', 'blink', 'body', 'doctype', - 'font', 'form', 'frame', 'frameset', 'html', - 'input', 'marquee', 'meta', 'noscript', - 'param', 'script', 'style' - )); - $feed->strip_attributes(array_merge($feed->strip_attributes, array( - 'onload', 'onunload', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', - 'onmouseover', 'onmousemove', 'onmouseout', 'onfocus', 'onblur', - 'onkeypress', 'onkeydown', 'onkeyup', 'onselect', 'onchange'))); - $feed->init (); - - if ($feed->error ()) { - throw new FeedException ($feed->error . ' [' . $url . ']'); - } - - // 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); - } - - if (empty($this->name)) { // May come from OPML - $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); - } - } - } - private function loadEntries ($feed) { - $entries = array (); - - foreach ($feed->get_items () as $item) { - $title = strip_tags($item->get_title ()); - $author = $item->get_author (); - $link = $item->get_permalink (); - $date = strtotime ($item->get_date ()); - - // gestion des tags (catégorie == tag) - $tags_tmp = $item->get_categories (); - $tags = array (); - if (!is_null ($tags_tmp)) { - foreach ($tags_tmp as $tag) { - $tags[] = $tag->get_label (); - } - } - - $content = $item->get_content (); - $elinks = array(); - foreach ($item->get_enclosures() as $enclosure) { - $elink = $enclosure->get_link(); - if (array_key_exists($elink, $elinks)) continue; - $elinks[$elink] = '1'; - $mime = strtolower($enclosure->get_type()); - if (strpos($mime, 'image/') === 0) { - $content .= '<br /><img src="' . $elink . '" alt="" />'; - } - } - - $entry = new Entry ( - $this->id (), - $item->get_id (), - !is_null ($title) ? $title : '', - !is_null ($author) ? $author->name : '', - !is_null ($content) ? $content : '', - !is_null ($link) ? $link : '', - $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; - } - - $this->entries = $entries; - } -} - -class FeedDAO extends Model_pdo { - public function addFeed ($valuesTmp) { - $sql = 'INSERT INTO ' . $this->prefix . 'feed (id, url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history) VALUES(?, ?, ?, ?, ?, ?, ?, 10, ?, 0, 0)'; - $stm = $this->bd->prepare ($sql); - - $values = array ( - $valuesTmp['id'], - $valuesTmp['url'], - $valuesTmp['category'], - $valuesTmp['name'], - $valuesTmp['website'], - $valuesTmp['description'], - $valuesTmp['lastUpdate'], - base64_encode ($valuesTmp['httpAuth']), - ); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function updateFeed ($id, $valuesTmp) { - $set = ''; - foreach ($valuesTmp as $key => $v) { - $set .= $key . '=?, '; - - if ($key == 'httpAuth') { - $valuesTmp[$key] = base64_encode ($v); - } - } - $set = substr ($set, 0, -2); - - $sql = 'UPDATE ' . $this->prefix . 'feed SET ' . $set . ' WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - foreach ($valuesTmp as $v) { - $values[] = $v; - } - $values[] = $id; - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function updateLastUpdate ($id) { - $sql = 'UPDATE ' . $this->prefix . 'feed SET lastUpdate=?, error=0 WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ( - time (), - $id - ); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function isInError ($id) { - $sql = 'UPDATE ' . $this->prefix . '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(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function changeCategory ($idOldCat, $idNewCat) { - $catDAO = new CategoryDAO (); - $newCat = $catDAO->searchById ($idNewCat); - if (!$newCat) { - $newCat = $catDAO->getDefault (); - } - - $sql = 'UPDATE ' . $this->prefix . '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(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function deleteFeed ($id) { - $sql = 'DELETE FROM ' . $this->prefix . 'feed WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ($id); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - public function deleteFeedByCategory ($id) { - $sql = 'DELETE FROM ' . $this->prefix . 'feed WHERE category=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ($id); - - if ($stm && $stm->execute ($values)) { - return true; - } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - return false; - } - } - - public function searchById ($id) { - $sql = 'SELECT * FROM ' . $this->prefix . 'feed WHERE id=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ($id); - - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $feed = HelperFeed::daoToFeed ($res); - - if (isset ($feed[$id])) { - return $feed[$id]; - } else { - return false; - } - } - public function searchByUrl ($url) { - $sql = 'SELECT * FROM ' . $this->prefix . 'feed WHERE url=?'; - $stm = $this->bd->prepare ($sql); - - $values = array ($url); - - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - $feed = current (HelperFeed::daoToFeed ($res)); - - if (isset ($feed)) { - return $feed; - } else { - return false; - } - } - - public function listFeeds () { - $sql = 'SELECT * FROM ' . $this->prefix . 'feed ORDER BY name'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - - return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC)); - } - - public function listFeedsOrderUpdate () { - $sql = 'SELECT * FROM ' . $this->prefix . 'feed ORDER BY lastUpdate'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - - return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC)); - } - - public function listByCategory ($cat) { - $sql = 'SELECT * FROM ' . $this->prefix . 'feed WHERE category=? ORDER BY name'; - $stm = $this->bd->prepare ($sql); - - $values = array ($cat); - - $stm->execute ($values); - - return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC)); - } - - public function count () { //Is this used? - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'feed'; - $stm = $this->bd->prepare ($sql); - $stm->execute (); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - return $res[0]['count']; - } - - public function countEntries ($id) { - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'entry WHERE id_feed=?'; - $stm = $this->bd->prepare ($sql); - $values = array ($id); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - return $res[0]['count']; - } - public function countNotRead ($id) { //Is this used? - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->prefix . 'entry WHERE is_read=0 AND id_feed=?'; - $stm = $this->bd->prepare ($sql); - $values = array ($id); - $stm->execute ($values); - $res = $stm->fetchAll (PDO::FETCH_ASSOC); - - return $res[0]['count']; - } -} - -class HelperFeed { - public static function daoToFeed ($listDAO) { - $list = array (); - - if (!is_array ($listDAO)) { - $listDAO = array ($listDAO); - } - - foreach ($listDAO as $key => $dao) { - if (empty ($dao['url'])) { - continue; - } - if (isset ($dao['id'])) { - $key = $dao['id']; - } - - $list[$key] = new Feed ($dao['url'], false); - $list[$key]->_category ($dao['category']); - $list[$key]->_name ($dao['name']); - $list[$key]->_website ($dao['website']); - $list[$key]->_description ($dao['description']); - $list[$key]->_lastUpdate ($dao['lastUpdate']); - $list[$key]->_priority ($dao['priority']); - $list[$key]->_pathEntries ($dao['pathEntries']); - $list[$key]->_httpAuth (base64_decode ($dao['httpAuth'])); - $list[$key]->_error ($dao['error']); - $list[$key]->_keepHistory ($dao['keep_history']); - if (isset ($dao['nbNotRead'])) { - $list[$key]->_nbNotRead ($dao['nbNotRead']); - } - if (isset ($dao['nbEntries'])) { - $list[$key]->_nbEntries ($dao['nbEntries']); - } - if (isset ($dao['id'])) { - $list[$key]->_id ($dao['id']); - } - } - - return $list; - } -} diff --git a/app/models/Log_Model.php b/app/models/Log_Model.php deleted file mode 100644 index 5c280fa7a..000000000 --- a/app/models/Log_Model.php +++ /dev/null @@ -1,47 +0,0 @@ -<?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 deleted file mode 100755 index e79fd933b..000000000 --- a/app/models/RSSConfiguration.php +++ /dev/null @@ -1,445 +0,0 @@ -<?php - -class RSSConfiguration extends Model { - 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 $shortcuts = array (); - private $mail_login = ''; - private $mark_when = array (); - private $url_shaarli = ''; - private $theme; - private $anon_access; - 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 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->_onread_jump_next ($confDAO->onread_jump_next); - $this->_lazyload ($confDAO->lazyload); - $this->_sortOrder ($confDAO->sort_order); - $this->_oldEntries ($confDAO->old_entries); - $this->_shortcuts ($confDAO->shortcuts); - $this->_mailLogin ($confDAO->mail_login); - $this->_markWhen ($confDAO->mark_when); - $this->_urlShaarli ($confDAO->url_shaarli); - $this->_theme ($confDAO->theme); - $this->_anonAccess ($confDAO->anon_access); - $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 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 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']; - } - public function markWhenScroll () { - return $this->mark_when['scroll']; - } - public function urlShaarli () { - return $this->url_shaarli; - } - public function theme () { - return $this->theme; - } - public function anonAccess () { - return $this->anon_access; - } - 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 _language ($value) { - if (!isset ($this->available_languages[$value])) { - $value = 'en'; - } - $this->language = $value; - } - public function _postsPerPage ($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'; - } else { - $this->default_view = 'all'; - } - } - public function _displayPosts ($value) { - if ($value == 'yes') { - $this->display_posts = 'yes'; - } else { - $this->display_posts = 'no'; - } - } - public function _onread_jump_next ($value) { - if ($value == 'no') { - $this->onread_jump_next = 'no'; - } else { - $this->onread_jump_next = 'yes'; - } - } - 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'; - } else { - $this->sort_order = 'low_to_high'; - } - } - public function _oldEntries ($value) { - if (is_int (intval ($value)) && $value > 0) { - $this->old_entries = $value; - } else { - $this->old_entries = 3; - } - } - public function _shortcuts ($values) { - foreach ($values as $key => $value) { - $this->shortcuts[$key] = $value; - } - } - public function _mailLogin ($value) { - if (filter_var ($value, FILTER_VALIDATE_EMAIL)) { - $this->mail_login = $value; - } elseif ($value == false) { - $this->mail_login = false; - } - } - 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['scroll'] = $values['scroll']; - } - public function _urlShaarli ($value) { - if (filter_var ($value, FILTER_VALIDATE_URL)) { - $this->url_shaarli = $value; - } elseif (version_compare(PHP_VERSION, '5.3.3', '<') && (strpos($value, '-') > 0) && ($value === filter_var($value, FILTER_SANITIZE_URL))) { //PHP bug #51192 - $this->url_shaarli = $value; - } else { - $this->url_shaarli = ''; - } - } - public function _theme ($value) { - $this->theme = $value; - } - public function _anonAccess ($value) { - if ($value == 'yes') { - $this->anon_access = 'yes'; - } else { - $this->anon_access = 'no'; - } - } - public function _token ($value) { - $this->token = $value; - } - public function _autoLoadMore ($value) { - if ($value == 'yes') { - $this->auto_load_more = 'yes'; - } else { - $this->auto_load_more = 'no'; - } - } - public function _topline_read ($value) { - $this->topline_read = $value === 'yes'; - } - public function _topline_favorite ($value) { - $this->topline_favorite = $value === 'yes'; - } - public function _topline_date ($value) { - $this->topline_date = $value === 'yes'; - } - public function _topline_link ($value) { - $this->topline_link = $value === 'yes'; - } - public function _bottomline_read ($value) { - $this->bottomline_read = $value === 'yes'; - } - public function _bottomline_favorite ($value) { - $this->bottomline_favorite = $value === 'yes'; - } - public function _bottomline_sharing ($value) { - $this->bottomline_sharing = $value === 'yes'; - } - public function _bottomline_tags ($value) { - $this->bottomline_tags = $value === 'yes'; - } - public function _bottomline_date ($value) { - $this->bottomline_date = $value === 'yes'; - } - public function _bottomline_link ($value) { - $this->bottomline_link = $value === 'yes'; - } -} - -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 $onread_jump_next = 'yes'; - public $lazyload = 'yes'; - public $sort_order = 'low_to_high'; - public $old_entries = 3; - public $shortcuts = array ( - 'mark_read' => 'r', - 'mark_favorite' => 'f', - 'go_website' => 'space', - 'next_entry' => 'j', - 'prev_entry' => 'k' - ); - public $mail_login = ''; - public $mark_when = array ( - 'article' => 'yes', - 'site' => 'yes', - 'scroll' => 'no' - ); - public $url_shaarli = ''; - public $theme = 'default'; - public $anon_access = 'no'; - public $token = ''; - public $auto_load_more = 'no'; - 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 () { - parent::__construct (PUBLIC_PATH . '/data/Configuration.array.php'); - - // TODO : simplifier ce code, une boucle for() devrait suffir ! - 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']; - } - 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 = $this->array['old_entries']; - } - if (isset ($this->array['shortcuts'])) { - $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['url_shaarli'])) { - $this->url_shaarli = $this->array['url_shaarli']; - } - if (isset ($this->array['theme'])) { - $this->theme = $this->array['theme']; - } - if (isset ($this->array['anon_access'])) { - $this->anon_access = $this->array['anon_access']; - } - 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) { - foreach ($values as $key => $value) { - $this->array[$key] = $value; - } - - $this->writeFile($this->array); - } -} diff --git a/app/models/RSSPaginator.php b/app/models/RSSPaginator.php deleted file mode 100644 index 86b4b5cac..000000000 --- a/app/models/RSSPaginator.php +++ /dev/null @@ -1,33 +0,0 @@ -<?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 next () { - return $this->next; - } - - public function render ($view, $getteur) { - $view = APP_PATH . '/views/helpers/'.$view; - - if (file_exists ($view)) { - include ($view); - } - } -} diff --git a/app/models/RSSThemes.php b/app/models/RSSThemes.php deleted file mode 100644 index 83db85acf..000000000 --- a/app/models/RSSThemes.php +++ /dev/null @@ -1,47 +0,0 @@ -<?php - -class RSSThemes extends Model { - private static $themes_dir = '/themes'; - - private static $list = array(); - - public static function init() { - $basedir = PUBLIC_PATH . self::$themes_dir; - - $themes_list = array_diff( - scandir($basedir), - array('..', '.') - ); - - foreach ($themes_list as $theme_dir) { - $json_filename = $basedir . '/' . $theme_dir . '/metadata.json'; - if(file_exists($json_filename)) { - $content = file_get_contents($json_filename); - $res = json_decode($content, true); - - if($res && - isset($res['name']) && - isset($res['author']) && - isset($res['description']) && - isset($res['version']) && - isset($res['files']) && is_array($res['files'])) { - $theme = $res; - $theme['path'] = $theme_dir; - self::$list[$theme_dir] = $theme; - } - } - } - } - - public static function get() { - return self::$list; - } - - public static function get_infos($theme_id) { - if (isset(self::$list[$theme_id])) { - return self::$list[$theme_id]; - } - - return false; - } -}
\ No newline at end of file |
