diff options
| author | 2013-04-13 13:02:21 +0200 | |
|---|---|---|
| committer | 2013-04-13 13:02:21 +0200 | |
| commit | c2bf3ead8ae15288eb99c82643fb0cbd595e1454 (patch) | |
| tree | 2a4da7c310f3506aa478eade79d8a807d809f2bd /app | |
| parent | 1cc118acdc52895ca500c93b36bbb5cf3a149bc7 (diff) | |
Export des flux au format RSS pleinement supporté (voir issue #34) - possibilité de les filtrer comme pour la vue principale
Diffstat (limited to 'app')
| -rwxr-xr-x | app/controllers/indexController.php | 14 | ||||
| -rwxr-xr-x | app/controllers/rssController.php | 35 | ||||
| -rw-r--r-- | app/layout/nav_menu.phtml | 19 | ||||
| -rwxr-xr-x | app/models/Entry.php | 42 | ||||
| -rwxr-xr-x | app/views/helpers/rss.phtml (renamed from app/views/rss/public.phtml) | 9 | ||||
| -rw-r--r-- | app/views/index/index.phtml | 9 |
6 files changed, 77 insertions, 51 deletions
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); + } } } @@ -161,6 +168,13 @@ class indexController extends ActionController { 'type' => $get, 'filter' => $get ); + } elseif ($get == 'public') { + $this->view->get_c = $get; + + $this->get = array ( + 'type' => $get, + 'filter' => $get + ); } elseif ($get == false) { $this->get = array ( 'type' => 'all', 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 @@ -<?php - -class rssController extends ActionController { - public function firstAction() { - header('Content-Type: text/xml'); - header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - - $this->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 @@ </li> </ul> </div> + + <?php + $get = Request::param ('get', ''); + $search = Request::param ('search', ''); + $url = array ( + 'c' => 'index', + 'a' => 'index', + 'params' => array ( + 'output' => 'rss' + ) + ); + if ($get != '') { + $url['params']['get'] = $get; + } + if ($search != '') { + $url['params']['search'] = $search; + } + ?> + <a class="btn" href="<?php echo Url::display ($url); ?>"><i class="icon i_rss"></i></a> </div> 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/rss/public.phtml b/app/views/helpers/rss.phtml index 04a035699..b75e6d3bc 100755 --- a/app/views/rss/public.phtml +++ b/app/views/helpers/rss.phtml @@ -3,13 +3,12 @@ <channel> <title><?php echo View::title(); ?></title> <link><?php echo Url::display(); ?></link> - <description>Flux public de <?php echo View::title(); ?></description> - <language>fr</language> + <description>Flux RSS de <?php echo View::title(); ?></description> <pubDate><?php echo date('D, d M Y H:i:s O'); ?></pubDate> <lastBuildDate><?php echo gmdate('D, d M Y H:i:s'); ?> GMT</lastBuildDate> - <atom:link href="<?php echo Url::display(array('a' => 'rss')); ?>" rel="self" type="application/rss+xml" /> + <atom:link href="<?php echo _url ('index', 'index', 'output', 'rss'); ?>" rel="self" type="application/rss+xml" /> <?php -$items = $this->itemPaginator->items (); +$items = $this->entryPaginator->items (); foreach ($items as $item) { ?> <item> @@ -20,7 +19,7 @@ foreach ($items as $item) { <dc:creator><?php echo $author; ?></dc:creator> <?php } ?> <description><![CDATA[<?php - echo html_entity_decode($item->notes (false, false)); + echo $item->content (); ?>]]></description> <pubDate><?php echo date('D, d M Y H:i:s O', $item->date (true)); ?></pubDate> <guid><?php echo $item->guid (); ?></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 @@ +<?php +if (Request::param ('output', '') == 'rss') { + $this->renderHelper ('rss'); + return; +} +?> + <?php $this->partial ('aside_flux'); ?> <?php $this->partial ('nav_menu'); ?> @@ -67,7 +74,7 @@ if (isset ($this->entryPaginator)) { <li class="item"> <div class="dropdown"> <div id="dropdown-share-<?php echo $item->id ();?>" class="dropdown-target"></div> - <a class="dropdown-toggle" href="#dropdown-share-<?php echo $item->id ();?>">Partager</a> + <i class="icon i_share"></i> <a class="dropdown-toggle" href="#dropdown-share-<?php echo $item->id ();?>">Partager</a> <ul class="dropdown-menu"> <li class="dropdown-close"><a href="#close"><i class="icon i_close"></i></a></li> |
