improved starred/unstarred function, code refactoring using a mode

session var ('default', 'starred', 'history')
This commit is contained in:
MonsieurPaulLeBoulanger 2013-06-10 16:23:48 +02:00
parent e56cfa612a
commit 8951ba8f45
9 changed files with 24 additions and 73 deletions

View File

@ -1 +0,0 @@
Deny from all

View File

@ -104,7 +104,6 @@ Router\get_action('show', function() {
Router\get_action('show_starred_item', function() {
$id = Model\decode_item_id(Request\param('id'));
Response\html(Template\layout('starred_item', array(
@ -148,7 +147,7 @@ Router\get_action('mark-item-read', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_read($id);
Response\Redirect('?action=default');
Response\Redirect('?action='.$_SESSION['MODE']);
});
@ -156,15 +155,7 @@ Router\get_action('mark-item-unread', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_unread($id);
Response\Redirect('?action=history');
});
Router\get_action('mark-read-item-unread', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_unread($id);
Response\Redirect('?action=history');
Response\Redirect('?action='.$_SESSION['MODE']);
});
@ -172,15 +163,7 @@ Router\get_action('mark-item-removed', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_removed($id);
Response\Redirect('?action=history');
});
Router\get_action('mark-starred-item-removed', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_removed($id);
Response\Redirect('?action=starred');
Response\Redirect('?action='.$_SESSION['MODE']);
});
@ -199,43 +182,20 @@ Router\post_action('mark-item-unread', function() {
Response\json(array('Ok'));
});
Router\get_action('mark-read-item-starred', function() {
Router\get_action('mark-item-starred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_starred($id);
Response\Redirect('?action=history');
Response\Redirect('?action='.$_SESSION['MODE']);
});
Router\get_action('mark-read-item-unstarred', function() {
Router\get_action('mark-item-unstarred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_unstarred($id);
Response\Redirect('?action=history');
});
Router\get_action('mark-starred-item-unstarred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_unstarred($id);
Response\Redirect('?action=starred');
});
Router\get_action('mark-unread-item-starred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_starred($id);
Response\Redirect('?action=default');
});
Router\get_action('mark-unread-item-unstarred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_unstarred($id);
Response\Redirect('?action=default');
Response\Redirect('?action='.$_SESSION['MODE']);
});
@ -251,7 +211,7 @@ Router\post_action('change-item-status', function() {
Router\get_action('history', function() {
$_SESSION['MODE']='history';
Response\html(Template\layout('history', array(
'items' => Model\get_read_items(),
'menu' => 'history'
@ -260,7 +220,7 @@ Router\get_action('history', function() {
Router\get_action('starred', function() {
$_SESSION['MODE']='starred';
Response\html(Template\layout('starred', array(
'items' => Model\get_starred_items(),
'menu' => 'starred'
@ -481,6 +441,7 @@ Router\post_action('config', function() {
Router\notfound(function() {
$_SESSION['MODE']='default';
Model\autoflush();

View File

@ -13,4 +13,4 @@
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Add') ?></button>
</div>
</form>
</form>

View File

@ -1,4 +1,5 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

View File

@ -29,15 +29,13 @@
<?php if (isset($item['starred']) && $item['starred']=='starred'): ?>
<a href="?action=mark-unread-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a> |
<a href="?action=mark-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a> |
<?php else: ?>
<a href="?action=mark-unread-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a> |
<a href="?action=mark-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a> |
<?php endif ?>
<a href="?action=mark-read-item-unread&amp;id=<?= $item_id ?>"><?= t('mark as unread') ?></a> |
<a href="?action=mark-item-unread&amp;id=<?= $item_id ?>"><?= t('mark as unread') ?></a> |
<a href="?action=mark-item-removed&amp;id=<?= $item_id ?>"><?= t('remove') ?></a> |
<a
href="<?= $item['url'] ?>"

View File

@ -13,9 +13,9 @@
<?= Helper\get_host_from_url($item['url']) ?> |
<?= dt('%A %e %B %Y %k:%M', $item['updated']) ?> |
<?php if (isset($item['starred']) && $item['starred']=='starred'): ?>
<a href="?action=mark-read-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a>
<a href="?action=mark-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a>
<?php else: ?>
<a href="?action=mark-read-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a>
<a href="?action=mark-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a>
<?php endif ?>
</p>

View File

@ -14,7 +14,7 @@
<article id="item-<?= $item_id ?>" data-item-id="<?= $item_id ?>">
<h2>
<a
href="?action=show_starred_item&amp;id=<?= $item_id ?>"
href="?action=read_starred&amp;id=<?= $item_id ?>"
id="open-<?= $item_id ?>"
>
<?= Helper\escape($item['title']) ?>
@ -23,8 +23,8 @@
<p>
<?= Helper\get_host_from_url($item['url']) ?> |
<?= dt('%A %e %B %Y %k:%M', $item['updated']) ?> |
<a href="?action=mark-starred-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a> |
<a href="?action=mark-starred-item-removed&amp;id=<?= $item_id ?>"><?= t('remove') ?></a> |
<a href="?action=mark-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a> |
<a href="?action=mark-item-removed&amp;id=<?= $item_id ?>"><?= t('remove') ?></a> |
<a
href="<?= $item['url'] ?>"
id="original-<?= $item_id ?>"

View File

@ -27,15 +27,7 @@
</span>
<span class="nav-middle">
<?php if ($item_nav['previous'] && $item_nav['next']): ?>
<a href="?action=default#item-<?= Model\encode_item_id($item_nav['next']['id']) ?>"><?= t('Unread items') ?></a>
<?php elseif ($item_nav['previous'] && ! $item_nav['next']): ?>
<a href="?action=default#item-<?= Model\encode_item_id($item_nav['previous']['id']) ?>"><?= t('Unread items') ?></a>
<?php elseif (! $item_nav['previous'] && $item_nav['next']): ?>
<a href="?action=default#item-<?= Model\encode_item_id($item_nav['next']['id']) ?>"><?= t('Unread items') ?></a>
<?php elseif (! $item_nav['previous'] && ! $item_nav['next']): ?>
<a href="?action=default"><?= t('Unread items') ?></a>
<?php endif ?>
<a href="?action=starred"><?= t('Starred') ?></a>
</span>
<span class="nav-right">

View File

@ -31,9 +31,9 @@
<?php if (isset($item['starred']) && $item['starred']=='starred'): ?>
<a href="?action=mark-unread-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a> |
<a href="?action=mark-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a> |
<?php else: ?>
<a href="?action=mark-unread-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a> |
<a href="?action=mark-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a> |
<?php endif ?>
<a href="?action=mark-item-read&amp;id=<?= $item_id ?>"><?= t('mark as read') ?></a> |