diff options
| author | 2012-10-23 18:29:43 +0200 | |
|---|---|---|
| committer | 2012-10-23 18:29:43 +0200 | |
| commit | fca236dc6d6ff6e09182c560f3566904cbc7a70a (patch) | |
| tree | 850bfab52359702dad2a9eccd03f01b5c68c9bcb /app | |
| parent | 9a95cb844e80512205c519da69ec373e046b7f52 (diff) | |
affichage par catégories + meilleur exportation opml
Diffstat (limited to 'app')
| -rw-r--r-- | app/App_FrontController.php | 23 | ||||
| -rwxr-xr-x | app/controllers/configureController.php | 13 | ||||
| -rwxr-xr-x | app/controllers/indexController.php | 23 | ||||
| -rw-r--r-- | app/layout/aside.phtml | 8 | ||||
| -rwxr-xr-x | app/models/Entry.php | 56 | ||||
| -rw-r--r-- | app/models/Feed.php | 12 | ||||
| -rw-r--r-- | app/views/configure/importExport.phtml | 4 | ||||
| -rw-r--r-- | app/views/index/index.phtml | 4 | ||||
| -rw-r--r-- | app/views/javascript/main.phtml | 17 |
9 files changed, 108 insertions, 52 deletions
diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 5a1009436..d61927c9e 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -10,14 +10,9 @@ class App_FrontController extends FrontController { $this->loadLibs (); $this->loadModels (); - Session::init (); - - View::prependStyle (Url::display ('/theme/base.css')); - View::appendScript (Url::display ('/scripts/jquery.js')); - View::appendScript (Url::display ('/scripts/smoothscroll.js')); - View::appendScript (Url::display ('/scripts/shortcut.js')); - View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main'))); - View::_param ('conf', Session::param ('conf', new RSSConfiguration ())); + Session::init (); // lancement de la session doit se faire après chargement des modèles sinon bug (pourquoi ?) + $this->loadStylesAndScripts (); + $this->loadParamsView (); } private function loadLibs () { @@ -31,4 +26,16 @@ class App_FrontController extends FrontController { include (APP_PATH . '/models/Feed.php'); include (APP_PATH . '/models/Entry.php'); } + + private function loadStylesAndScripts () { + View::prependStyle (Url::display ('/theme/base.css')); + View::appendScript (Url::display ('/scripts/jquery.js')); + View::appendScript (Url::display ('/scripts/smoothscroll.js')); + View::appendScript (Url::display ('/scripts/shortcut.js')); + View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main'))); + } + + private function loadParamsView () { + View::_param ('conf', Session::param ('conf', new RSSConfiguration ())); + } } diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php index c501e5242..e61eb3872 100755 --- a/app/controllers/configureController.php +++ b/app/controllers/configureController.php @@ -99,12 +99,21 @@ class configureController extends ActionController { header('Content-type: text/xml'); $feedDAO = new FeedDAO (); - $this->view->feeds = $feedDAO->listFeeds (); - } elseif (Request::isPost ()) { + $catDAO = new CategoryDAO (); + + $list = array (); + foreach ($catDAO->listCategories () as $key => $cat) { + $list[$key]['name'] = $cat->name (); + $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ()); + } + + $this->view->categories = $list; + } elseif ($this->view->req == 'import' && Request::isPost ()) { if ($_FILES['file']['error'] == 0) { $content = file_get_contents ($_FILES['file']['tmp_name']); $feeds = opml_import ($content); + Request::_param ('q'); Request::_param ('feeds', $feeds); Request::forward (array ('c' => 'feed', 'a' => 'massiveInsert')); } diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index b9d770e81..b8908dee3 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -3,25 +3,38 @@ class indexController extends ActionController { public function indexAction () { $entryDAO = new EntryDAO (); + $catDAO = new CategoryDAO (); $mode = Session::param ('mode', $this->view->conf->defaultView ()); - if ($mode == 'not_read') { - $entries = $entryDAO->listNotReadEntries (); - } elseif ($mode == 'all') { - $entries = $entryDAO->listEntries (); + $get = Request::param ('get'); + + // Récupère les flux par catégorie, favoris ou tous + if ($get == 'favoris') { + $entries = $entryDAO->listFavorites ($mode); + } elseif ($get != false) { + $entries = $entryDAO->listByCategory ($get, $mode); } + // Cas où on ne choisie ni catégorie ni les favoris + // ou si la catégorie ne correspond à aucune + if (!isset ($entries)) { + $entries = $entryDAO->listEntries ($mode); + } + + // Tri par date if ($this->view->conf->sortOrder () == 'high_to_low') { usort ($entries, 'sortReverseEntriesByDate'); } else { usort ($entries, 'sortEntriesByDate'); } - //gestion pagination + // Gestion pagination $page = Request::param ('page', 1); $this->view->entryPaginator = new Paginator ($entries); $this->view->entryPaginator->_nbItemsPerPage ($this->view->conf->postsPerPage ()); $this->view->entryPaginator->_currentPage ($page); + + $this->view->cat_aside = $catDAO->listCategories (); } public function changeModeAction () { diff --git a/app/layout/aside.phtml b/app/layout/aside.phtml index b154c5ea3..265a0902b 100644 --- a/app/layout/aside.phtml +++ b/app/layout/aside.phtml @@ -7,6 +7,14 @@ <ul id="menu"> <li <?php echo Request::controllerName () == 'index' ? 'class="active"' : ''; ?>> <a href="<?php echo Url::display (array ()); ?>">Flux RSS</a> + <?php if (isset ($this->cat_aside)) { ?> + <ul id="flux_menu"> + <li><a href="<?php echo Url::display (array ('params' => array ('get' => 'favoris'))); ?>">Favoris</a></li> + <?php foreach ($this->cat_aside as $cat) { ?> + <li><a href="<?php echo Url::display (array ('params' => array ('get' => $cat->id ()))); ?>"><?php echo $cat->name (); ?></a></li> + <?php } ?> + </ul> + <?php } ?> </li> <li <?php echo Request::controllerName () == 'configure' ? 'class="active"' : ''; ?>> <a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'flux')); ?>">Configurer</a> diff --git a/app/models/Entry.php b/app/models/Entry.php index 67d255c55..dbbdc1362 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -133,31 +133,44 @@ class EntryDAO extends Model_array { } } - public function listEntries () { + public function listEntries ($mode) { $list = $this->array; if (!is_array ($list)) { $list = array (); } - return HelperEntry::daoToEntry ($list); + return HelperEntry::daoToEntry ($list, $mode); } - public function listNotReadEntries () { + public function listFavorites ($mode) { $list = $this->array; - $list_not_read = array (); if (!is_array ($list)) { $list = array (); } - foreach ($list as $key => $entry) { - if (!$entry['is_read']) { - $list_not_read[$key] = $entry; + return HelperEntry::daoToEntry ($list, $mode, true); + } + + public function listByCategory ($cat, $mode) { + $feedDAO = new FeedDAO (); + $feeds = $feedDAO->listByCategory ($cat); + + $list = array (); + foreach ($feeds as $feed) { + foreach ($feed->entries () as $id) { + if (isset ($this->array[$id])) { + $list[$id] = $this->array[$id]; + } } } - return HelperEntry::daoToEntry ($list_not_read); + return HelperEntry::daoToEntry ($list, $mode); + } + + public function listNotReadEntries () { + } public function count () { @@ -166,7 +179,7 @@ class EntryDAO extends Model_array { } class HelperEntry { - public static function daoToEntry ($listDAO) { + public static function daoToEntry ($listDAO, $mode = 'all', $favorite = false) { $list = array (); if (!is_array ($listDAO)) { @@ -174,17 +187,20 @@ class HelperEntry { } foreach ($listDAO as $key => $dao) { - $list[$key] = new Entry ( - $dao['feed'], - $dao['guid'], - $dao['title'], - $dao['author'], - $dao['content'], - $dao['link'], - $dao['date'], - $dao['is_read'], - $dao['is_favorite'] - ); + if (($mode != 'not_read' || !$dao['is_read']) + && ($favorite == false || $dao['is_favorite'])) { + $list[$key] = new Entry ( + $dao['feed'], + $dao['guid'], + $dao['title'], + $dao['author'], + $dao['content'], + $dao['link'], + $dao['date'], + $dao['is_read'], + $dao['is_favorite'] + ); + } } return $list; diff --git a/app/models/Feed.php b/app/models/Feed.php index 57696f64d..90656de15 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -159,6 +159,18 @@ class FeedDAO extends Model_array { return HelperFeed::daoToFeed ($list); } + public function listByCategory ($cat) { + $list = array (); + + foreach ($this->array as $key => $feed) { + if ($feed['category'] == $cat) { + $list[$key] = $feed; + } + } + + return HelperFeed::daoToFeed ($list); + } + public function count () { return count ($this->array); } diff --git a/app/views/configure/importExport.phtml b/app/views/configure/importExport.phtml index 634800157..7f2fbd7c5 100644 --- a/app/views/configure/importExport.phtml +++ b/app/views/configure/importExport.phtml @@ -7,12 +7,12 @@ <dateCreated><?php echo date('D, d M Y H:i:s'); ?></dateCreated> </head> <body> -<?php echo opml_export ($this->feeds); ?> +<?php echo opml_export ($this->categories); ?> </body> </opml> <?php } else { ?> -<form method="post" action="" enctype="multipart/form-data"> +<form method="post" action="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'import'))); ?>" enctype="multipart/form-data"> <h1>Exporter au format OPML</h1> <a class="button" href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'export'))); ?>">Exporter</a> diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index af01f3fd2..c3f4242c4 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -16,10 +16,10 @@ <div class="post flux<?php echo !$item->isRead () ? ' not_read' : ''; ?><?php echo $item->isFavorite () ? ' favorite' : ''; ?>"> <?php $author = $item->author (); ?> <div class="before"> + <?php $feed = $item->feed (true); ?> <?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>, + sur <a target="_blank" href="<?php echo $feed->website (); ?>"><?php echo $feed->name (); ?> <img src="http://www.google.com/s2/favicons?domain=<?php echo get_domain ($feed->website ()); ?>" alt="" /></a>, </div> <h1><a target="_blank" href="<?php echo $item->link (); ?>"> <?php echo $item->title (); ?></a></h1> diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml index 87b53ca9a..f5682d1f0 100644 --- a/app/views/javascript/main.phtml +++ b/app/views/javascript/main.phtml @@ -68,18 +68,9 @@ $(document).ready (function () { } }); }); - shortcut.add("space", function () { - // On plie / déplie l'article - active = $(".post.flux.active"); - active.children (".content").slideToggle (200, function () { - $.smoothScroll({ - offset: active.position ().top + 25 - }); - }); - }); // Touches de navigation - shortcut.add("up", function () { + /*shortcut.add("up", function () { old_active = $(".post.flux.active"); last_active = $(".post.flux:last"); new_active = old_active.prev (); @@ -89,15 +80,15 @@ $(document).ready (function () { } else { slide (last_active, old_active); } - }); - shortcut.add("down", function () { + });*/ + shortcut.add("space", function () { old_active = $(".post.flux.active"); first_active = $(".post.flux:first"); new_active = old_active.next (); if (new_active[0] instanceof HTMLDivElement) { slide (new_active, old_active); - } else { + } else if (new_active[0] === undefined) { slide (first_active, old_active); } }); |
