diff --git a/index.php b/index.php index c58811b..c8fb3d0 100644 --- a/index.php +++ b/index.php @@ -87,38 +87,37 @@ Router\get_action('show-help', function() { }); -// Show item without bottom nav +// Show item Router\get_action('show', function() { $id = Request\param('id'); + $menu = Request\param('menu'); $item = Model\get_item($id); $feed = Model\get_feed($item['feed_id']); Model\set_item_read($id); - Response\html(Template\layout('show_item', array( - 'item' => $item, - 'feed' => $feed, - 'menu' => 'show' - ))); -}); - - -// Show item with bottom nav -Router\get_action('read', function() { - - $id = Request\param('id'); - $item = Model\get_item($id); - $feed = Model\get_feed($item['feed_id']); - $nav = Model\get_nav_item($item); // must be placed before set_item_read() - - Model\set_item_read($id); + switch ($menu) { + case 'unread': + $nav = Model\get_nav_item($item); + break; + case 'history': + $nav = Model\get_nav_item($item, array('read')); + break; + case 'feed-items': + $nav = Model\get_nav_item($item, array('unread', 'read')); + break; + case 'bookmarks': + $nav = Model\get_nav_item($item, array('unread', 'read'), array(1)); + break; + } Response\html(Template\layout('show_item', array( 'item' => $item, 'feed' => $feed, - 'item_nav' => $nav, - 'menu' => 'read' + 'item_nav' => isset($nav) ? $nav : null, + 'menu' => $menu, + 'title' => $item['title'] ))); }); @@ -212,21 +211,17 @@ Router\post_action('change-item-status', function() { Router\get_action('bookmark', function() { $id = Request\param('id'); - $redirect = Request\param('redirect', 'unread'); + $menu = Request\param('menu', 'unread'); + $source = Request\param('source', 'unread'); $offset = Request\int_param('offset', 0); Model\set_bookmark_value($id, Request\int_param('value')); - if ($redirect === 'show') { - - Response\Redirect('?action=show&id='.$id); - } - else if ($redirect === 'read') { - - Response\Redirect('?action=read&id='.$id); + if ($source === 'show') { + Response\Redirect('?action=show&menu='.$menu.'&id='.$id); } - Response\Redirect('?action='.$redirect.'&offset='.$offset); + Response\Redirect('?action='.$menu.'&offset='.$offset); }); diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index f65475e..82a4bfe 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,6 +1,7 @@ 'Liste', 'content downloaded' => 'contenu téléchargé', 'in progress...' => 'en cours...', 'unable to fetch content' => 'impossible de récupérer l\'article', diff --git a/model.php b/model.php index 55e6cf1..4001f4f 100644 --- a/model.php +++ b/model.php @@ -470,24 +470,53 @@ function get_item($id) } -function get_nav_item($item) +function get_nav_item($item, $status = array('unread'), $bookmark = array(1, 0)) { - $unread_items = \PicoTools\singleton('db') + $items = \PicoTools\singleton('db') ->table('items') - ->columns('items.id') - ->eq('status', 'unread') + ->columns('id', 'status', 'title') + ->in('bookmark', $bookmark) + ->neq('status', 'removed') ->desc('updated') ->findAll(); $next_item = null; $previous_item = null; - for ($i = 0, $ilen = count($unread_items); $i < $ilen; $i++) { + for ($i = 0, $ilen = count($items); $i < $ilen; $i++) { - if ($unread_items[$i]['id'] == $item['id']) { + if ($items[$i]['id'] == $item['id']) { + + if ($i > 0) { + + $j = $i - 1; + + while ($j >= 0) { + + if (in_array($items[$j]['status'], $status)) { + $previous_item = $items[$j]; + break; + } + + $j--; + } + } + + if ($i < ($ilen - 1)) { + + $j = $i + 1; + + while ($j < $ilen) { + + if (in_array($items[$j]['status'], $status)) { + $next_item = $items[$j]; + break; + } + + $j++; + } + } - if ($i > 0) $previous_item = $unread_items[$i - 1]; - if ($i < ($ilen - 1)) $next_item = $unread_items[$i + 1]; break; } } diff --git a/templates/bookmarks.php b/templates/bookmarks.php index 9c44543..393ed9e 100644 --- a/templates/bookmarks.php +++ b/templates/bookmarks.php @@ -13,7 +13,7 @@

@@ -25,7 +25,7 @@ | - + | diff --git a/templates/feed_items.php b/templates/feed_items.php index 64c39c3..d050e2c 100644 --- a/templates/feed_items.php +++ b/templates/feed_items.php @@ -14,7 +14,7 @@

diff --git a/templates/history.php b/templates/history.php index b204a34..448f817 100644 --- a/templates/history.php +++ b/templates/history.php @@ -15,7 +15,7 @@

@@ -29,7 +29,7 @@ - | + | diff --git a/templates/show_item.php b/templates/show_item.php index 1e8b389..916ef17 100644 --- a/templates/show_item.php +++ b/templates/show_item.php @@ -15,9 +15,9 @@ | - + - + | - « + « « @@ -47,19 +47,19 @@ - + - + - + - + - » + » » diff --git a/templates/unread_items.php b/templates/unread_items.php index 7d9f0ca..1858b74 100644 --- a/templates/unread_items.php +++ b/templates/unread_items.php @@ -21,7 +21,7 @@

@@ -37,9 +37,9 @@ - | + | - | + |