diff --git a/miniflux/index.php b/miniflux/index.php index 6168bb4..23f2fa3 100644 --- a/miniflux/index.php +++ b/miniflux/index.php @@ -107,12 +107,13 @@ Router\get_action('read', function() { $id = Request\param('id'); $item = Model\get_item($id); + $nav = Model\get_nav_item($item); // must be placed before set_item_read() Model\set_item_read($id); Response\html(Template\layout('read_item', array( 'item' => $item, - 'item_nav' => Model\get_nav_item($item) + 'item_nav' => $nav ))); }); diff --git a/miniflux/model.php b/miniflux/model.php index d14887e..2bcf339 100644 --- a/miniflux/model.php +++ b/miniflux/model.php @@ -241,21 +241,25 @@ function get_item($id) function get_nav_item($item) { - $next_item = \PicoTools\singleton('db') + $unread_items = \PicoTools\singleton('db') ->table('items') ->columns('items.id') ->eq('status', 'unread') - ->lt('updated', $item['updated']) ->desc('updated') - ->findOne(); + ->findAll(); - $previous_item = \PicoTools\singleton('db') - ->table('items') - ->columns('items.id') - ->eq('status', 'unread') - ->gt('updated', $item['updated']) - ->asc('updated') - ->findOne(); + $next_item = null; + $previous_item = null; + + for ($i = 0, $ilen = count($unread_items); $i < $ilen; $i++) { + + if ($unread_items[$i]['id'] == $item['id']) { + + if ($i > 0) $previous_item = $unread_items[$i - 1]; + if ($i < ($ilen - 1)) $next_item = $unread_items[$i + 1]; + break; + } + } return array( 'next' => $next_item,