Add bottom item naviguation everywhere
This commit is contained in:
parent
f6ea4c419d
commit
5096c3bd6c
53
index.php
53
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);
|
||||
});
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'Listing' => 'Liste',
|
||||
'content downloaded' => 'contenu téléchargé',
|
||||
'in progress...' => 'en cours...',
|
||||
'unable to fetch content' => 'impossible de récupérer l\'article',
|
||||
|
45
model.php
45
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;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
<article id="item-<?= $item['id'] ?>" data-item-id="<?= $item['id'] ?>">
|
||||
<h2>
|
||||
<a
|
||||
href="?action=show&id=<?= $item['id'] ?>"
|
||||
href="?action=show&menu=bookmarks&id=<?= $item['id'] ?>"
|
||||
data-item-id="<?= $item['id'] ?>"
|
||||
id="open-<?= $item['id'] ?>"
|
||||
>
|
||||
@ -25,7 +25,7 @@
|
||||
<?= dt('%e %B %Y %k:%M', $item['updated']) ?> |
|
||||
|
||||
<span class="hide-mobile">
|
||||
<a href="?action=bookmark&value=0&id=<?= $item['id'] ?>&redirect=bookmarks&offset=<?= $offset ?>">
|
||||
<a href="?action=bookmark&value=0&id=<?= $item['id'] ?>&menu=bookmarks&offset=<?= $offset ?>">
|
||||
<?= t('remove bookmark') ?>
|
||||
</a> |
|
||||
</span>
|
||||
|
@ -14,7 +14,7 @@
|
||||
<h2>
|
||||
<?= $item['bookmark'] ? '★ ' : '' ?>
|
||||
<a
|
||||
href="?action=show&id=<?= $item['id'] ?>"
|
||||
href="?action=show&menu=feed-items&id=<?= $item['id'] ?>"
|
||||
data-item-id="<?= $item['id'] ?>"
|
||||
id="open-<?= $item['id'] ?>"
|
||||
>
|
||||
|
@ -15,7 +15,7 @@
|
||||
<h2>
|
||||
<?= $item['bookmark'] ? '★ ' : '' ?>
|
||||
<a
|
||||
href="?action=show&id=<?= $item['id'] ?>"
|
||||
href="?action=show&menu=history&id=<?= $item['id'] ?>"
|
||||
data-item-id="<?= $item['id'] ?>"
|
||||
id="open-<?= $item['id'] ?>"
|
||||
>
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
<?php if (! $item['bookmark']): ?>
|
||||
<span class="hide-mobile">
|
||||
<a id="bookmark-<?= $item['id'] ?>" href="?action=bookmark&value=1&id=<?= $item['id'] ?>&redirect=history&offset=<?= $offset ?>"><?= t('bookmark') ?></a> |
|
||||
<a id="bookmark-<?= $item['id'] ?>" href="?action=bookmark&value=1&id=<?= $item['id'] ?>&menu=history&offset=<?= $offset ?>"><?= t('bookmark') ?></a> |
|
||||
</span>
|
||||
<?php endif ?>
|
||||
|
||||
|
@ -15,9 +15,9 @@
|
||||
<span class="hide-mobile"><?= dt('%e %B %Y - %k:%M', $item['updated']) ?> |</span>
|
||||
|
||||
<?php if ($item['bookmark']): ?>
|
||||
<a href="?action=bookmark&value=0&id=<?= $item['id'] ?>&redirect=<?= $menu ?>"><?= t('remove bookmark') ?></a>
|
||||
<a href="?action=bookmark&value=0&id=<?= $item['id'] ?>&source=show&menu=<?= $menu ?>"><?= t('remove bookmark') ?></a>
|
||||
<?php else: ?>
|
||||
<a href="?action=bookmark&value=1&id=<?= $item['id'] ?>&redirect=<?= $menu ?>"><?= t('bookmark') ?></a>
|
||||
<a href="?action=bookmark&value=1&id=<?= $item['id'] ?>&source=show&menu=<?= $menu ?>"><?= t('bookmark') ?></a>
|
||||
<?php endif ?> |
|
||||
|
||||
<span id="download-item"
|
||||
@ -39,7 +39,7 @@
|
||||
<nav>
|
||||
<span class="nav-left">
|
||||
<?php if ($item_nav['previous']): ?>
|
||||
<a href="?action=read&id=<?= $item_nav['previous']['id'] ?>" id="previous-item">« <?= t('Previous') ?></a>
|
||||
<a href="?action=show&menu=<?= $menu ?>&id=<?= $item_nav['previous']['id'] ?>" id="previous-item" title="<?= t($item_nav['previous']['title']) ?>">« <?= t('Previous') ?></a>
|
||||
<?php else: ?>
|
||||
« <?= t('Previous') ?>
|
||||
<?php endif ?>
|
||||
@ -47,19 +47,19 @@
|
||||
|
||||
<span class="nav-middle">
|
||||
<?php if ($item_nav['previous'] && $item_nav['next']): ?>
|
||||
<a href="?action=default#item-<?= $item_nav['next']['id'] ?>"><?= t('Unread items') ?></a>
|
||||
<a href="?action=<?= $menu ?>&feed_id=<?= $feed['id'] ?>#item-<?= $item_nav['next']['id'] ?>"><?= t('Listing') ?></a>
|
||||
<?php elseif ($item_nav['previous'] && ! $item_nav['next']): ?>
|
||||
<a href="?action=default#item-<?= $item_nav['previous']['id'] ?>"><?= t('Unread items') ?></a>
|
||||
<a href="?action=<?= $menu ?>&feed_id=<?= $feed['id'] ?>#item-<?= $item_nav['previous']['id'] ?>"><?= t('Listing') ?></a>
|
||||
<?php elseif (! $item_nav['previous'] && $item_nav['next']): ?>
|
||||
<a href="?action=default#item-<?= $item_nav['next']['id'] ?>"><?= t('Unread items') ?></a>
|
||||
<a href="?action=<?= $menu ?>&feed_id=<?= $feed['id'] ?>#item-<?= $item_nav['next']['id'] ?>"><?= t('Listing') ?></a>
|
||||
<?php elseif (! $item_nav['previous'] && ! $item_nav['next']): ?>
|
||||
<a href="?action=default"><?= t('Unread items') ?></a>
|
||||
<a href="?action=<?= $menu ?>&feed_id=<?= $feed['id'] ?>"><?= t('Unread items') ?></a>
|
||||
<?php endif ?>
|
||||
</span>
|
||||
|
||||
<span class="nav-right">
|
||||
<?php if ($item_nav['next']): ?>
|
||||
<a href="?action=read&id=<?= $item_nav['next']['id'] ?>" id="next-item"><?= t('Next') ?> »</a>
|
||||
<a href="?action=show&menu=<?= $menu ?>&id=<?= $item_nav['next']['id'] ?>" id="next-item" title="<?= t($item_nav['next']['title']) ?>"><?= t('Next') ?> »</a>
|
||||
<?php else: ?>
|
||||
<?= t('Next') ?> »
|
||||
<?php endif ?>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<h2>
|
||||
<?= $item['bookmark'] ? '★ ' : '' ?>
|
||||
<a
|
||||
href="?action=read&id=<?= $item['id'] ?>"
|
||||
href="?action=show&menu=unread&id=<?= $item['id'] ?>"
|
||||
data-item-id="<?= $item['id'] ?>"
|
||||
id="open-<?= $item['id'] ?>"
|
||||
>
|
||||
@ -37,9 +37,9 @@
|
||||
|
||||
<span class="hide-mobile">
|
||||
<?php if ($item['bookmark']): ?>
|
||||
<a id="bookmark-<?= $item['id'] ?>" href="?action=bookmark&value=0&id=<?= $item['id'] ?>&redirect=unread&offset=<?= $offset ?>"><?= t('remove bookmark') ?></a> |
|
||||
<a id="bookmark-<?= $item['id'] ?>" href="?action=bookmark&value=0&id=<?= $item['id'] ?>&menu=unread&offset=<?= $offset ?>"><?= t('remove bookmark') ?></a> |
|
||||
<?php else: ?>
|
||||
<a id="bookmark-<?= $item['id'] ?>" href="?action=bookmark&value=1&id=<?= $item['id'] ?>&redirect=unread&offset=<?= $offset ?>"><?= t('bookmark') ?></a> |
|
||||
<a id="bookmark-<?= $item['id'] ?>" href="?action=bookmark&value=1&id=<?= $item['id'] ?>&menu=unread&offset=<?= $offset ?>"><?= t('bookmark') ?></a> |
|
||||
<?php endif ?>
|
||||
</span>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user