Add item navigation

This commit is contained in:
Frederic Guillot 2013-03-26 21:57:12 -04:00
parent 7b155c6ce2
commit e08625ceec
4 changed files with 93 additions and 3 deletions

View File

@ -443,6 +443,44 @@ nav .active a {
color: purple;
}
.item nav span,
.item nav a,
.item nav a:visited {
color: #3366CC;
}
.item nav {
border-top: 1px dotted #ddd;
padding-top: 8px;
margin-top: 50px;
width: 100%;
}
.nav-left {
width: 30%;
display: block;
float: left;
}
.nav-middle {
text-align: center;
float: left;
width: 40%;
}
.nav-right {
text-align: right;
margin-left: 70%;
width: 30%;
display: block;
}
/* other pages */
section li {
margin-left: 20px;
list-style-type: square;
}
/* mobile design */
@media only screen and (max-width: 480px) {

View File

@ -74,14 +74,26 @@ Router\post_action('login', function() {
});
Router\get_action('show', function() {
$id = Request\param('id');
Response\html(Template\layout('read_item', array(
'item' => Model\get_item($id)
)));
});
Router\get_action('read', function() {
$id = Request\param('id');
$item = Model\get_item($id);
Model\set_item_read($id);
Response\html(Template\layout('read_item', array(
'item' => Model\get_item($id)
'item' => $item,
'item_nav' => Model\get_nav_item($item)
)));
});
@ -221,10 +233,17 @@ Router\post_action('add', function() {
});
Router\get_action('optimize-db', function() {
\PicoTools\singleton('db')->getConnection()->exec('VACUUM');
Response\redirect('?action=config');
});
Router\get_action('download-db', function() {
Response\force_download('db.sqlite.gz');
Response\binary(gzencode(file_get_contents('data/db.sqlite')));
Response\binary(gzencode(file_get_contents(get_db_filename())));
});
@ -264,6 +283,7 @@ Router\get_action('config', function() {
Response\html(Template\layout('config', array(
'errors' => array(),
'values' => Model\get_config(),
'db_size' => filesize(get_db_filename()),
'menu' => 'config'
)));
});

View File

@ -15,6 +15,38 @@
</p>
<?= $item['content'] ?>
<?php if (isset($item_nav)): ?>
<nav>
<span class="nav-left">
<?php if ($item_nav['previous']): ?>
<a href="?action=read&amp;id=<?= urlencode($item_nav['previous']['id']) ?>">« Previous</a>
<?php else: ?>
« Previous
<?php endif ?>
</span>
<span class="nav-middle">
<?php if ($item_nav['previous'] && $item_nav['next']): ?>
<a href="?action=default&amp;#item-<?= urlencode($item_nav['next']['id']) ?>">Unread items</a>
<?php elseif ($item_nav['previous'] && ! $item_nav['next']): ?>
<a href="?action=default&amp;#item-<?= urlencode($item_nav['previous']['id']) ?>">Unread items</a>
<?php elseif (! $item_nav['previous'] && $item_nav['next']): ?>
<a href="?action=default&amp;#item-<?= urlencode($item_nav['next']['id']) ?>">Unread items</a>
<?php elseif (! $item_nav['previous'] && ! $item_nav['next']): ?>
<a href="?action=default">Unread items</a>
<?php endif ?>
</span>
<span class="nav-right">
<?php if ($item_nav['next']): ?>
<a href="?action=read&amp;id=<?= urlencode($item_nav['next']['id']) ?>">Next »</a>
<?php else: ?>
Next »
<?php endif ?>
</span>
</nav>
<?php endif ?>
</article>
<?php endif ?>

View File

@ -14,7 +14,7 @@
<section class="items">
<?php foreach ($items as $item): ?>
<article>
<h2><a href="?action=read&amp;id=<?= urlencode($item['id']) ?>"><?= Helper\escape($item['title']) ?></a></h2>
<h2><a href="?action=show&amp;id=<?= urlencode($item['id']) ?>"><?= Helper\escape($item['title']) ?></a></h2>
<p>
<?= Helper\get_host_from_url($item['url']) ?> |
<?= date('l, j F Y H:i', $item['updated']) ?> |