diff options
| author | 2012-10-22 18:00:13 +0200 | |
|---|---|---|
| committer | 2012-10-22 18:00:13 +0200 | |
| commit | 0426541acbeb44d240e6dbf7a93f3a104bea61b4 (patch) | |
| tree | 209a425c5afee9e627d11023b262326812be1fbc /app | |
| parent | fb57be5a5af3a2fb46b2dbf2b503ffe78eb5cf49 (diff) | |
Grosse màj : ajout de la configuration + ajouts divers fonctionnalités
Diffstat (limited to 'app')
| -rw-r--r-- | app/App_FrontController.php | 1 | ||||
| -rwxr-xr-x | app/controllers/configureController.php | 64 | ||||
| -rwxr-xr-x | app/controllers/feedController.php | 43 | ||||
| -rwxr-xr-x | app/controllers/indexController.php | 6 | ||||
| -rw-r--r-- | app/layout/aside.phtml | 8 | ||||
| -rwxr-xr-x | app/models/Category.php | 113 | ||||
| -rwxr-xr-x | app/models/Entry.php | 16 | ||||
| -rw-r--r-- | app/models/Feed.php | 126 | ||||
| -rwxr-xr-x | app/models/RSSConfiguration.php | 16 | ||||
| -rw-r--r-- | app/views/configure/categorize.phtml | 17 | ||||
| -rw-r--r-- | app/views/configure/display.phtml | 6 | ||||
| -rw-r--r-- | app/views/configure/flux.phtml | 45 | ||||
| -rw-r--r-- | app/views/index/index.phtml | 8 |
13 files changed, 393 insertions, 76 deletions
diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 5a2b27eed..bffe80ea3 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -23,6 +23,7 @@ class App_FrontController extends FrontController { private function loadModels () { include (APP_PATH . '/models/RSSConfiguration.php'); + include (APP_PATH . '/models/Category.php'); include (APP_PATH . '/models/Feed.php'); include (APP_PATH . '/models/Entry.php'); } diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php index 0f5d6b658..5642ef547 100755 --- a/app/controllers/configureController.php +++ b/app/controllers/configureController.php @@ -2,11 +2,66 @@ class configureController extends ActionController { public function categorizeAction () { - + $catDAO = new CategoryDAO (); + + if (Request::isPost ()) { + $cats = Request::param ('categories', array ()); + $ids = Request::param ('ids', array ()); + $newCat = Request::param ('new_category'); + + foreach ($cats as $key => $name) { + if (strlen ($name) > 0) { + $cat = new Category ($name); + $values = array ( + 'name' => $cat->name (), + 'color' => $cat->color () + ); + $catDAO->updateCategory ($ids[$key], $values); + } else { + $catDAO->deleteCategory ($ids[$key]); + } + } + + if ($newCat != false) { + $cat = new Category ($newCat); + $values = array ( + 'id' => $cat->id (), + 'name' => $cat->name (), + 'color' => $cat->color () + ); + $catDAO->addCategory ($values); + } + + $catDAO->save (); + + } + + $this->view->categories = $catDAO->listCategories (); } public function fluxAction () { - + $feedDAO = new FeedDAO (); + $this->view->feeds = $feedDAO->listFeeds (); + + $id = Request::param ('id'); + + $this->view->flux = false; + if ($id != false) { + $this->view->flux = $feedDAO->searchById ($id); + + $catDAO = new CategoryDAO (); + $this->view->categories = $catDAO->listCategories (); + + if (Request::isPost () && $this->view->flux) { + $cat = Request::param ('category'); + $values = array ( + 'category' => $cat + ); + $feedDAO->updateFeed ($id, $values); + + $this->view->flux->_category ($cat); + } + } } public function displayAction () { @@ -14,15 +69,18 @@ class configureController extends ActionController { $nb = Request::param ('posts_per_page', 10); $view = Request::param ('default_view', 'all'); $display = Request::param ('display_posts', 'no'); + $sort = Request::param ('sort_order', 'low_to_high'); $this->view->conf->_postsPerPage (intval ($nb)); $this->view->conf->_defaultView ($view); $this->view->conf->_displayPosts ($display); + $this->view->conf->_sortOrder ($sort); $values = array ( 'posts_per_page' => $this->view->conf->postsPerPage (), 'default_view' => $this->view->conf->defaultView (), - 'display_posts' => $this->view->conf->displayPosts () + 'display_posts' => $this->view->conf->displayPosts (), + 'sort_order' => $this->view->conf->sortOrder () ); $confDAO = new RSSConfigurationDAO (); diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index 3b4a90b64..5bf7d9ec6 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -7,7 +7,8 @@ class feedController extends ActionController { try { $feed = new Feed ($url); - $entries = $feed->loadEntries (); + $feed->load (); + $entries = $feed->entries (false); $feed_entries = array (); if ($entries !== false) { @@ -24,6 +25,7 @@ class feedController extends ActionController { 'date' => $entry->date (true), 'is_read' => $entry->isRead (), 'is_favorite' => $entry->isFavorite (), + 'feed' => $feed->id () ); $entryDAO->addEntry ($values); @@ -35,8 +37,11 @@ class feedController extends ActionController { $values = array ( 'id' => $feed->id (), 'url' => $feed->url (), - 'categories' => $feed->categories (), - 'entries' => $feed_entries + 'category' => $feed->category (), + 'entries' => $feed_entries, + 'name' => $feed->name (), + 'website' => $feed->website (), + 'description' => $feed->description (), ); $feedDAO->addFeed ($values); } catch (Exception $e) { @@ -54,27 +59,31 @@ class feedController extends ActionController { $feeds = $feedDAO->listFeeds (); foreach ($feeds as $feed) { - $entries = $feed->loadEntries (); + $feed->load (); + $entries = $feed->entries (false); $feed_entries = $feed->entries (); if ($entries !== false) { foreach ($entries as $entry) { - $values = array ( - 'id' => $entry->id (), - 'guid' => $entry->guid (), - 'title' => $entry->title (), - 'author' => $entry->author (), - 'content' => $entry->content (), - 'link' => $entry->link (), - 'date' => $entry->date (true), - 'is_read' => $entry->isRead (), - 'is_favorite' => $entry->isFavorite (), - ); - $entryDAO->addEntry ($values); - if (!in_array ($entry->id (), $feed_entries)) { + $values = array ( + 'id' => $entry->id (), + 'guid' => $entry->guid (), + 'title' => $entry->title (), + 'author' => $entry->author (), + 'content' => $entry->content (), + 'link' => $entry->link (), + 'date' => $entry->date (true), + 'is_read' => $entry->isRead (), + 'is_favorite' => $entry->isFavorite (), + 'feed' => $feed->id () + ); + $entryDAO->addEntry ($values); + $feed_entries[] = $entry->id (); } + + // TODO gérer suppression des articles trop vieux (à paramétrer) } } diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 3fda234ca..b9d770e81 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -11,7 +11,11 @@ class indexController extends ActionController { $entries = $entryDAO->listEntries (); } - usort ($entries, 'sortEntriesByDate'); + if ($this->view->conf->sortOrder () == 'high_to_low') { + usort ($entries, 'sortReverseEntriesByDate'); + } else { + usort ($entries, 'sortEntriesByDate'); + } //gestion pagination $page = Request::param ('page', 1); diff --git a/app/layout/aside.phtml b/app/layout/aside.phtml index 6e2e4965d..db4c482c1 100644 --- a/app/layout/aside.phtml +++ b/app/layout/aside.phtml @@ -9,7 +9,7 @@ <a href="<?php echo Url::display (array ()); ?>">Flux RSS</a> </li> <li <?php echo Request::controllerName () == 'configure' ? 'class="active"' : ''; ?>> - <a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'categorize')); ?>">Configurer</a> + <a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'flux')); ?>">Configurer</a> </li> <li> <a href="<?php echo Url::display (array ('c' => 'feed', 'a' => 'actualize')); ?>">Mettre les flux à jour</a> @@ -21,12 +21,12 @@ <div class="aside"> <ul id="menu"> <li><h2>Configuration</h2></li> - <li <?php echo Request::actionName () == 'categorize' ? 'class="active"' : ''; ?>> - <a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'categorize')); ?>">Catégories</a> - </li> <li <?php echo Request::actionName () == 'flux' ? 'class="active"' : ''; ?>> <a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'flux')); ?>">Flux RSS</a> </li> + <li <?php echo Request::actionName () == 'categorize' ? 'class="active"' : ''; ?>> + <a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'categorize')); ?>">Catégories</a> + </li> <li <?php echo Request::actionName () == 'display' ? 'class="active"' : ''; ?>> <a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'display')); ?>">Affichage</a> </li> diff --git a/app/models/Category.php b/app/models/Category.php new file mode 100755 index 000000000..5b5d45b15 --- /dev/null +++ b/app/models/Category.php @@ -0,0 +1,113 @@ +<?php + +class Category extends Model { + private $id; + private $name; + private $color; + + public function __construct ($name = '', $color = '#0062BE') { + $this->_name ($name); + $this->_color ($color); + } + + public function id () { + return small_hash ($this->name . Configuration::selApplication ()); + } + public function name () { + return $this->name; + } + public function color () { + return $this->color; + } + + 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'; + } + } +} + +class CategoryDAO extends Model_array { + public function __construct () { + parent::__construct (PUBLIC_PATH . '/data/db/Categories.array.php'); + } + + public function addCategory ($values) { + $id = $values['id']; + unset ($values['id']); + + if (!isset ($this->array[$id])) { + $this->array[$id] = array (); + + foreach ($values as $key => $value) { + $this->array[$id][$key] = $value; + } + } else { + return false; + } + } + + public function updateCategory ($id, $values) { + foreach ($values as $key => $value) { + $this->array[$id][$key] = $value; + } + } + + public function deleteCategory ($id) { + if (isset ($this->array[$id])) { + unset ($this->array[$id]); + } + } + + public function searchById ($id) { + $list = HelperCategory::daoToCategory ($this->array); + + if (isset ($list[$id])) { + return $list[$id]; + } else { + return false; + } + } + + public function listCategories () { + $list = $this->array; + + if (!is_array ($list)) { + $list = array (); + } + + return HelperCategory::daoToCategory ($list); + } + + public function count () { + return count ($this->array); + } + + public function save () { + $this->writeFile ($this->array); + } +} + +class HelperCategory { + public static function daoToCategory ($listDAO) { + $list = array (); + + if (!is_array ($listDAO)) { + $listDAO = array ($listDAO); + } + + foreach ($listDAO as $key => $dao) { + $list[$key] = new Category ( + $dao['name'], + $dao['color'] + ); + } + + return $list; + } +} diff --git a/app/models/Entry.php b/app/models/Entry.php index 85e04cb4e..67d255c55 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -9,8 +9,9 @@ class Entry extends Model { private $date; private $is_read; private $is_favorite; + private $feed; - public function __construct ($guid = '', $title = '', $author = '', $content = '', + public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '', $link = '', $pubdate = 0, $is_read = false, $is_favorite = false) { $this->_guid ($guid); $this->_title ($title); @@ -20,6 +21,7 @@ class Entry extends Model { $this->_date ($pubdate); $this->_isRead ($is_read); $this->_isFavorite ($is_favorite); + $this->_feed ($feed); } public function id () { @@ -53,6 +55,14 @@ class Entry extends Model { 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 _guid ($value) { $this->guid = $value; @@ -78,6 +88,9 @@ class Entry extends Model { public function _isFavorite ($value) { $this->is_favorite = $value; } + public function _feed ($value) { + $this->feed = $value; + } } class EntryDAO extends Model_array { @@ -162,6 +175,7 @@ class HelperEntry { foreach ($listDAO as $key => $dao) { $list[$key] = new Entry ( + $dao['feed'], $dao['guid'], $dao['title'], $dao['author'], diff --git a/app/models/Feed.php b/app/models/Feed.php index 583a7fef5..57696f64d 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -2,13 +2,15 @@ class Feed extends Model { private $url; - private $categories; - private $entries_list; + private $category = ''; + private $entries_list = array (); + private $entries = null; + private $name = ''; + private $website = ''; + private $description = ''; - public function __construct ($url = null) { + public function __construct ($url) { $this->_url ($url); - $this->_categories (array ()); - $this->_entries (array ()); } public function id () { @@ -17,11 +19,26 @@ class Feed extends Model { public function url () { return $this->url; } - public function categories () { - return $this->categories; + public function category () { + return $this->category; } - public function entries () { - return $this->entries_list; + public function entries ($list = true) { + if ($list) { + return $this->entries_list; + } elseif (!is_null ($this->entries)) { + return $this->entries; + } else { + return false; + } + } + public function name () { + return $this->name; + } + public function website () { + return $this->website; + } + public function description () { + return $this->description; } public function _url ($value) { @@ -31,12 +48,8 @@ class Feed extends Model { throw new Exception (); } } - public function _categories ($value) { - if (!is_array ($value)) { - $value = array ($value); - } - - $this->categories = $value; + public function _category ($value) { + $this->category = $value; } public function _entries ($value) { if (!is_array ($value)) { @@ -45,42 +58,54 @@ class Feed extends Model { $this->entries_list = $value; } + public function _name ($value) { + $this->name = $value; + } + public function _website ($value) { + $this->website = $value; + } + public function _description ($value) { + $this->description = $value; + } - public function loadEntries () { + public function load () { if (!is_null ($this->url)) { $feed = new SimplePie (); $feed->set_feed_url ($this->url); $feed->set_cache_location (CACHE_PATH); $feed->init (); - $entries = array (); - if ($feed->data) { - foreach ($feed->get_items () as $item) { - $title = $item->get_title (); - $author = $item->get_author (); - $content = $item->get_content (); - $link = $item->get_permalink (); - $date = strtotime ($item->get_date ()); - - $entry = new Entry ( - $item->get_id (), - !is_null ($title) ? $title : '', - !is_null ($author) ? $author->name : '', - !is_null ($content) ? $content : '', - !is_null ($link) ? $link : '', - $date ? $date : time () - ); - - $entries[$entry->id ()] = $entry; - } - - return $entries; - } else { - return false; - } - } else { - return false; + $title = $feed->get_title (); + $this->loadEntries ($feed); + $this->_name (!is_null ($title) ? $title : $this->url); + $this->_website ($feed->get_link ()); + $this->_description ($feed->get_description ()); + } + } + private function loadEntries ($feed) { + $entries = array (); + + foreach ($feed->get_items () as $item) { + $title = $item->get_title (); + $author = $item->get_author (); + $content = $item->get_content (); + $link = $item->get_permalink (); + $date = strtotime ($item->get_date ()); + + $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 () + ); + + $entries[$entry->id ()] = $entry; } + + $this->entries = $entries; } } @@ -114,6 +139,16 @@ class FeedDAO extends Model_array { $this->writeFile($this->array); } + public function searchById ($id) { + $list = HelperFeed::daoToFeed ($this->array); + + if (isset ($list[$id])) { + return $list[$id]; + } else { + return false; + } + } + public function listFeeds () { $list = $this->array; @@ -139,8 +174,11 @@ class HelperFeed { foreach ($listDAO as $key => $dao) { $list[$key] = new Feed ($dao['url']); - $list[$key]->_categories ($dao['categories']); + $list[$key]->_category ($dao['category']); $list[$key]->_entries ($dao['entries']); + $list[$key]->_name ($dao['name']); + $list[$key]->_website ($dao['website']); + $list[$key]->_description ($dao['description']); } return $list; diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php index f42f1283c..da5028da3 100755 --- a/app/models/RSSConfiguration.php +++ b/app/models/RSSConfiguration.php @@ -4,12 +4,14 @@ class RSSConfiguration extends Model { private $posts_per_page; private $default_view; private $display_posts; + private $sort_order; public function __construct () { $confDAO = new RSSConfigurationDAO (); $this->_postsPerPage ($confDAO->posts_per_page); $this->_defaultView ($confDAO->default_view); $this->_displayPosts ($confDAO->display_posts); + $this->_sortOrder ($confDAO->sort_order); } public function postsPerPage () { @@ -21,6 +23,9 @@ class RSSConfiguration extends Model { public function displayPosts () { return $this->display_posts; } + public function sortOrder () { + return $this->sort_order; + } public function _postsPerPage ($value) { if (is_int ($value)) { @@ -43,12 +48,20 @@ class RSSConfiguration extends Model { $this->display_posts = 'no'; } } + public function _sortOrder ($value) { + if ($value == 'high_to_low') { + $this->sort_order = 'high_to_low'; + } else { + $this->sort_order = 'low_to_high'; + } + } } class RSSConfigurationDAO extends Model_array { public $posts_per_page = 10; public $default_view = 'all'; public $display_posts = 'no'; + public $sort_order = 'low_to_high'; public function __construct () { parent::__construct (PUBLIC_PATH . '/data/db/Configuration.array.php'); @@ -62,6 +75,9 @@ class RSSConfigurationDAO extends Model_array { if (isset ($this->array['display_posts'])) { $this->display_posts = $this->array['display_posts']; } + if (isset ($this->array['sort_order'])) { + $this->sort_order = $this->array['sort_order']; + } } public function save ($values) { diff --git a/app/views/configure/categorize.phtml b/app/views/configure/categorize.phtml index 126f6b48a..093ec1dcf 100644 --- a/app/views/configure/categorize.phtml +++ b/app/views/configure/categorize.phtml @@ -1,3 +1,14 @@ -<div class="post"> - Fonctionnalité non implémentée (pour le moment) -</div> +<form method="post" action=""> + <h1>Gérer les catégories</h1> + + <?php $i = 0; foreach ($this->categories as $cat) { $i++; ?> + <label for="cat_<?php echo $cat->id (); ?>">Catégorie n°<?php echo $i; ?></label> + <input type="text" id="cat_<?php echo $cat->id (); ?>" name="categories[]" value="<?php echo $cat->name (); ?>" /> + <input type="hidden" name="ids[]" value="<?php echo $cat->id (); ?>" /> + <?php } ?> + + <label for="new_category">Ajouter une catégorie</label> + <input type="text" id="new_category" name="new_category" placeholder="Nouvelle catégorie" /> + + <input type="submit" value="Valider" /> +</form> diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 23c41712b..228957b6a 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -14,6 +14,12 @@ <label for="radio_not_read">Afficher les non lus</label> </div> + <label for="sort_order">Ordre de tri</label> + <select name="sort_order" id="sort_order"> + <option value="low_to_high"<?php echo $this->conf->sortOrder () == 'low_to_high' ? ' selected="selected"' : ''; ?>>Du plus récent au plus ancien</option> + <option value="high_to_low"<?php echo $this->conf->sortOrder () == 'high_to_low' ? ' selected="selected"' : ''; ?>>Du plus ancien au plus récent</option> + </select> + <label>Afficher les articles dépliés par défaut</label> <div class="radio_group"> <input type="radio" name="display_posts" id="radio_yes" value="yes"<?php echo $this->conf->displayPosts () ? ' checked="checked"' : ''; ?> /> diff --git a/app/views/configure/flux.phtml b/app/views/configure/flux.phtml index 126f6b48a..34255bc59 100644 --- a/app/views/configure/flux.phtml +++ b/app/views/configure/flux.phtml @@ -1,3 +1,44 @@ -<div class="post"> - Fonctionnalité non implémentée (pour le moment) +<div class="table"> + <div class="aside"> + <ul> + <li><h2>Vox flux RSS</h2></li> + <?php if (!empty ($this->feeds)) { ?> + <?php foreach ($this->feeds as $feed) { ?> + <li <?php echo ($this->flux && $this->flux->id () == $feed->id ()) ? 'class="active"' : ''; ?>> + <a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'flux', 'params' => array ('id' => $feed->id ()))); ?>"><?php echo $feed->name (); ?></a> + </li> + <?php } ?> + <?php } else { ?> + <li class="disable"><span>Aucun flux</span></li> + <?php } ?> + </ul> + </div> + + <?php if ($this->flux) { ?> + <form method="post" action=""> + <h1><?php echo $this->flux->name (); ?></h1> + <?php echo $this->flux->description (); ?> + + <label>URL du site</label> + <span><a target="_blank" href="<?php echo $this->flux->website (); ?>"><?php echo $this->flux->website (); ?></a></span> + + <label>Nombre d'articles</label> + <span><?php echo count ($this->flux->entries ()); ?></span> + + <?php if (!empty ($this->categories)) { ?> + <label>Ranger dans une catégorie</label> + <div class="radio_group"> + <?php foreach ($this->categories as $cat) { ?> + <input type="radio" name="category" id="cat_<?php echo $cat->id (); ?>" value="<?php echo $cat->id (); ?>"<?php echo $cat->id () == $this->flux->category () ? ' checked="checked"' : ''; ?> /> + <label for="cat_<?php echo $cat->id (); ?>"><?php echo $cat->name (); ?></label> + <br /> + <?php } ?> + </div> + + <input type="submit" value="Valider" /> + <?php } ?> + </form> + <?php } else { ?> + <div class="nothing">Aucun flux sélectionné</div> + <?php } ?> </div> diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index 2dfdb5064..8863d08a2 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -14,7 +14,13 @@ <?php foreach ($items as $item) { ?> <div class="post flux<?php echo !$item->isRead () ? ' not_read' : ''; ?><?php echo $item->isFavorite () ? ' favorite' : ''; ?>"> - <div class="before"><?php echo $item->author (); ?> a écrit le <?php echo $item->date (); ?>,</div> + <?php $author = $item->author (); ?> + <div class="before"> + <?php echo $author != '' ? $author . ' a écrit' : ''; ?> + le <?php echo $item->date (); ?> + <?php $feed = $item->feed (true); ?> + sur <a target="_blank" href="<?php echo $feed->website (); ?>"><?php echo $feed->name (); ?></a>, + </div> <h1><a target="_blank" href="<?php echo $item->link (); ?>"> <?php echo $item->title (); ?></a></h1> <div class="content"><?php echo $item->content (); ?></div> |
