From c2bf3ead8ae15288eb99c82643fb0cbd595e1454 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 13 Apr 2013 13:02:21 +0200 Subject: Export des flux au format RSS pleinement supporté (voir issue #34) - possibilité de les filtrer comme pour la vue principale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/indexController.php | 14 +++++++++++++ app/controllers/rssController.php | 35 ------------------------------- app/layout/nav_menu.phtml | 19 +++++++++++++++++ app/models/Entry.php | 42 ++++++++++++++++++++++++++++--------- app/views/helpers/rss.phtml | 30 ++++++++++++++++++++++++++ app/views/index/index.phtml | 9 +++++++- app/views/rss/public.phtml | 31 --------------------------- public/theme/global.css | 6 ++++++ public/theme/icons/rss.svg | 32 ++++++++++++++++++++++++++++ public/theme/icons/share.svg | 34 ++++++++++++++++++++++++++++++ 10 files changed, 175 insertions(+), 77 deletions(-) delete mode 100755 app/controllers/rssController.php create mode 100755 app/views/helpers/rss.phtml delete mode 100755 app/views/rss/public.phtml create mode 100644 public/theme/icons/rss.svg create mode 100644 public/theme/icons/share.svg diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 1eba7231f..a11c26044 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -38,6 +38,9 @@ class indexController extends ActionController { } elseif ($this->get['type'] == 'favoris') { $entries = $entryDAO->listFavorites ($this->mode, $search, $order); View::prependTitle ('Vos favoris - '); + } elseif ($this->get['type'] == 'public') { + $entries = $entryDAO->listPublic ($this->mode, $search, $order); + View::prependTitle ('Public - '); } elseif ($this->get != false) { if ($this->get['type'] == 'c') { $cat = $catDAO->searchById ($this->get['filter']); @@ -81,6 +84,10 @@ class indexController extends ActionController { $this->view->cat_aside = $catDAO->listCategories (); $this->view->nb_favorites = $entryDAO->countFavorites (); $this->view->nb_total = $entryDAO->count (); + + if (Request::param ('output', '') == 'rss') { + $this->view->_useLayout (false); + } } } @@ -157,6 +164,13 @@ class indexController extends ActionController { if ($get == 'favoris') { $this->view->get_c = $get; + $this->get = array ( + 'type' => $get, + 'filter' => $get + ); + } elseif ($get == 'public') { + $this->view->get_c = $get; + $this->get = array ( 'type' => $get, 'filter' => $get diff --git a/app/controllers/rssController.php b/app/controllers/rssController.php deleted file mode 100755 index 1f66f4517..000000000 --- a/app/controllers/rssController.php +++ /dev/null @@ -1,35 +0,0 @@ -view->_useLayout (false); - } - - public function publicAction () { - $entryDAO = new EntryDAO (); - $entryDAO->_nbItemsPerPage (-1); - - $items = $entryDAO->listPublic ('low_to_high'); - - try { - $page = Request::param('page', 1); - $nb = Request::param('nb', 15); - $this->view->itemPaginator = new Paginator($items); - $this->view->itemPaginator->_nbItemsPerPage($nb); - $this->view->itemPaginator->_currentPage($page); - } catch(CurrentPagePaginationException $e) { - Error::error( - 404, - array('error' => array('La page que vous cherchez n\'existe pas')) - ); - } - } - - public function getNbNotReadAction() { - } -} diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 90fe4aea1..71a5bd11e 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -62,4 +62,23 @@ + + 'index', + 'a' => 'index', + 'params' => array ( + 'output' => 'rss' + ) + ); + if ($get != '') { + $url['params']['get'] = $get; + } + if ($search != '') { + $url['params']['search'] = $search; + } + ?> + diff --git a/app/models/Entry.php b/app/models/Entry.php index b9b6d30db..230b457bf 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -422,7 +422,7 @@ class EntryDAO extends Model_pdo { $values = array(); if ($search) { $values[] = '%'.$search.'%'; - $where = ' AND title LIKE ?'; + $where .= ' AND title LIKE ?'; } if ($order == 'low_to_high') { @@ -455,8 +455,17 @@ class EntryDAO extends Model_pdo { return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); } - public function listPublic ($order = 'high_to_low') { + public function listPublic ($mode, $search = false, $order = 'high_to_low') { $where = ' WHERE is_public=1'; + if ($mode == 'not_read') { + $where .= ' AND is_read=0'; + } + + $values = array(); + if ($search) { + $values[] = '%'.$search.'%'; + $where .= ' AND title LIKE ?'; + } if ($order == 'low_to_high') { $order = ' DESC'; @@ -464,10 +473,26 @@ class EntryDAO extends Model_pdo { $order = ''; } - $sql = 'SELECT * FROM entry' . $where . ' ORDER BY date' . $order; + $sql = 'SELECT COUNT(*) AS count FROM entry' . $where; + $stm = $this->bd->prepare ($sql); + $stm->execute ($values); + $res = $stm->fetchAll (PDO::FETCH_ASSOC); + $this->nbItems = $res[0]['count']; + if($this->nbItemsPerPage < 0) { + $sql = 'SELECT * FROM entry' . $where + . ' ORDER BY date' . $order; + } else { + $deb = ($this->currentPage () - 1) * $this->nbItemsPerPage; + $fin = $this->nbItemsPerPage; + + $sql = 'SELECT * FROM entry' . $where + . ' ORDER BY date' . $order + . ' LIMIT ' . $deb . ', ' . $fin; + } $stm = $this->bd->prepare ($sql); - $stm->execute (); + + $stm->execute ($values); return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); } @@ -481,7 +506,7 @@ class EntryDAO extends Model_pdo { $values = array ($cat); if ($search) { $values[] = '%'.$search.'%'; - $where = ' AND title LIKE ?'; + $where .= ' AND title LIKE ?'; } if ($order == 'low_to_high') { @@ -515,10 +540,10 @@ class EntryDAO extends Model_pdo { $where .= ' AND is_read=0'; } - $values = array(); + $values = array($feed); if ($search) { $values[] = '%'.$search.'%'; - $where = ' AND title LIKE ?'; + $where .= ' AND title LIKE ?'; } if ($order == 'low_to_high') { @@ -529,7 +554,6 @@ class EntryDAO extends Model_pdo { $sql = 'SELECT COUNT(*) AS count FROM entry' . $where; $stm = $this->bd->prepare ($sql); - $values = array ($feed); $stm->execute ($values); $res = $stm->fetchAll (PDO::FETCH_ASSOC); $this->nbItems = $res[0]['count']; @@ -542,8 +566,6 @@ class EntryDAO extends Model_pdo { $stm = $this->bd->prepare ($sql); - $values = array ($feed); - $stm->execute ($values); return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); diff --git a/app/views/helpers/rss.phtml b/app/views/helpers/rss.phtml new file mode 100755 index 000000000..b75e6d3bc --- /dev/null +++ b/app/views/helpers/rss.phtml @@ -0,0 +1,30 @@ +'; ?> + + + <?php echo View::title(); ?> + + Flux RSS de + + GMT + +entryPaginator->items (); +foreach ($items as $item) { +?> + + <?php echo htmlspecialchars(html_entity_decode($item->title ())); ?> + link (); ?> + author (); ?> + + + + content (); +?>]]> + date (true)); ?> + guid (); ?> + + + + + diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index f9e953858..cd0ff0504 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -1,3 +1,10 @@ +renderHelper ('rss'); + return; +} +?> + partial ('aside_flux'); ?> partial ('nav_menu'); ?> @@ -67,7 +74,7 @@ if (isset ($this->entryPaginator)) {