added a Star System : starred items will be shown on the Starred Tab

Starred item will not be deleted by auto flush
This commit is contained in:
MonsieurPaulLeBoulanger 2013-06-04 13:38:54 +02:00
parent 80f44c5311
commit 3758237bb4
11 changed files with 252 additions and 8 deletions

View File

@ -10,7 +10,7 @@ require 'schema.php';
require 'model.php';
const DB_VERSION = 6;
const DB_VERSION = 7;
const APP_VERSION = 'master';
const APP_USERAGENT = 'Miniflux - http://miniflux.net';
const HTTP_TIMEOUT = 5;
@ -38,4 +38,4 @@ PicoTools\container('db', function() {
die('Unable to migrate database schema.');
}
});
});

View File

@ -103,6 +103,17 @@ 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(
'item' => Model\get_item($id)
)));
});
Router\get_action('read', function() {
$id = Model\decode_item_id(Request\param('id'));
@ -118,6 +129,21 @@ Router\get_action('read', function() {
});
Router\get_action('read_starred', function() {
$id = Model\decode_item_id(Request\param('id'));
$item = Model\get_item($id);
$nav = Model\get_nav_starred_item($item); // must be placed before set_item_read()
Model\set_item_read($id);
Response\html(Template\layout('starred_item', array(
'item' => $item,
'item_nav' => $nav
)));
});
Router\get_action('mark-item-read', function() {
$id = Model\decode_item_id(Request\param('id'));
@ -142,6 +168,14 @@ Router\get_action('mark-item-removed', function() {
});
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');
});
Router\post_action('mark-item-read', function() {
$id = Model\decode_item_id(Request\param('id'));
@ -158,6 +192,37 @@ Router\post_action('mark-item-unread', function() {
});
Router\get_action('mark-item-starred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_starred($id);
Response\Redirect('?action=default');
});
Router\get_action('mark-item-unstarred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_unstarred($id);
Response\Redirect('?action=starred');
});
Router\post_action('mark-item-starred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_starred($id);
Response\json(array('Ok'));
});
Router\post_action('mark-item-unstarred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_unstarred($id);
Response\json(array('Ok'));
});
Router\post_action('change-item-status', function() {
$id = Model\decode_item_id(Request\param('id'));
@ -178,6 +243,16 @@ Router\get_action('history', function() {
});
Router\get_action('starred', function() {
Response\html(Template\layout('starred', array(
'items' => Model\get_starred_items(),
'menu' => 'starred'
)));
});
Router\get_action('confirm-remove', function() {
$id = Request\int_param('feed_id');
@ -404,4 +479,4 @@ Router\notfound(function() {
'items' => $items,
'menu' => 'unread'
)));
});
});

View File

@ -8,6 +8,11 @@ return array(
'French' => 'Français',
'English' => 'Anglais',
'unread' => 'non lus',
'mark as starred' => 'ajouter aux favoris',
'mark as unstarred' => 'supprimer des favoris',
'starred' => 'favoris',
'No starred items' => 'Pas de favoris',
'Starred' => 'Favoris',
'history' => 'historique',
'subscriptions' => 'abonnements',
'Subscriptions' => 'Abonnements',
@ -88,4 +93,4 @@ return array(
'Do you really want to remove this subscription: "%s"?' => 'Voulez-vous vraiment supprimer cet abonnement : "%s" ?',
'Nothing to read, do you want to <a href="?action=refresh-all" data-action="refresh-all">update your subscriptions?</a>' =>
'Il n\'y a rien à lire, voulez-vous <a href="?action=refresh-all" data-action="refresh-all">mettre à jour vos abonnements ?</a>'
);
);

View File

@ -275,6 +275,18 @@ function get_read_items()
}
function get_starred_items()
{
return \PicoTools\singleton('db')
->table('items')
->columns('items.id', 'items.title', 'items.updated', 'items.url', 'feeds.site_url')
->join('feeds', 'id', 'feed_id')
->eq('starred', 'starred')
->desc('updated')
->findAll();
}
function get_item($id)
{
return \PicoTools\singleton('db')
@ -313,6 +325,35 @@ function get_nav_item($item)
}
function get_nav_starred_item($item)
{
$starred_items = \PicoTools\singleton('db')
->table('items')
->columns('items.id')
->eq('starred', 'starred')
->desc('updated')
->findAll();
$next_item = null;
$previous_item = null;
for ($i = 0, $ilen = count($starred_items); $i < $ilen; $i++) {
if ($starred_items[$i]['id'] == $item['id']) {
if ($i > 0) $previous_item = $starred_items[$i - 1];
if ($i < ($ilen - 1)) $next_item = $starred_items[$i + 1];
break;
}
}
return array(
'next' => $next_item,
'previous' => $previous_item
);
}
function set_item_removed($id)
{
\PicoTools\singleton('db')
@ -340,6 +381,25 @@ function set_item_unread($id)
}
function set_item_starred($id)
{
\PicoTools\singleton('db')
->table('items')
->eq('id', $id)
->save(array('starred' => 'starred'));
}
function set_item_unstarred($id)
{
\PicoTools\singleton('db')
->table('items')
->eq('id', $id)
->save(array('starred' => 'unstarred'));
}
function switch_item_status($id)
{
$item = \PicoTools\singleton('db')
@ -398,6 +458,7 @@ function autoflush()
\PicoTools\singleton('db')
->table('items')
->eq('status', 'read')
->eq('starred', 'starred')
->lt('updated', strtotime('-'.$autoflush.'day'))
->save(array('status' => 'removed'));
}

View File

@ -2,6 +2,11 @@
namespace Schema;
function version_7($pdo)
{
$pdo->exec('ALTER TABLE items ADD COLUMN starred TEXT');
}
function version_6($pdo)
{

View File

@ -19,6 +19,7 @@
<a class="logo" href="?">mini<span>flux</span></a>
<ul>
<li <?= isset($menu) && $menu === 'unread' ? 'class="active"' : '' ?>><a href="?action=default"><?= t('unread') ?></a></li>
<li <?= isset($menu) && $menu === 'starred' ? 'class="active"' : '' ?>><a href="?action=starred"><?= t('starred') ?></a></li>
<li <?= isset($menu) && $menu === 'history' ? 'class="active"' : '' ?>><a href="?action=history"><?= t('history') ?></a></li>
<li <?= isset($menu) && $menu === 'feeds' ? 'class="active"' : '' ?>><a href="?action=feeds"><?= t('subscriptions') ?></a></li>
<li <?= isset($menu) && $menu === 'config' ? 'class="active"' : '' ?>><a href="?action=config"><?= t('preferences') ?></a></li>

View File

@ -26,6 +26,7 @@
<p>
<?= Helper\get_host_from_url($item['url']) ?> |
<?= dt('%A %e %B %Y %k:%M', $item['updated']) ?> |
<a href="?action=mark-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></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
@ -42,4 +43,4 @@
<?php endforeach ?>
</section>
<?php endif ?>
<?php endif ?>

View File

@ -10,7 +10,8 @@
<p class="infos">
<?= Helper\get_host_from_url($item['url']) ?> |
<?= dt('%A %e %B %Y %k:%M', $item['updated']) ?>
<?= dt('%A %e %B %Y %k:%M', $item['updated']) ?> |
<a href="?action=mark-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a>
</p>
<?= $item['content'] ?>
@ -48,4 +49,4 @@
<?php endif ?>
</article>
<?php endif ?>
<?php endif ?>

42
templates/starred.php Normal file
View File

@ -0,0 +1,42 @@
<?php if (empty($items)): ?>
<p class="alert alert-info"><?= t('No starred items') ?></p>
<?php else: ?>
<div class="page-header">
<h2><?= t('Starred') ?></h2>
</div>
<section class="items" id="listing">
<?php foreach ($items as $item): ?>
<?php $item_id = Model\encode_item_id($item['id']) ?>
<article id="item-<?= $item_id ?>" data-item-id="<?= $item_id ?>">
<h2>
<a
href="?action=show_starred_item&amp;id=<?= $item_id ?>"
id="open-<?= $item_id ?>"
>
<?= Helper\escape($item['title']) ?>
</a>
</h2>
<p>
<?= Helper\get_host_from_url($item['url']) ?> |
<?= dt('%A %e %B %Y %k:%M', $item['updated']) ?> |
<a href="?action=mark-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="<?= $item['url'] ?>"
id="original-<?= $item_id ?>"
rel="noreferrer"
target="_blank"
data-item-id="<?= $item_id ?>"
>
<?= t('original link') ?>
</a>
</p>
</article>
<?php endforeach ?>
</section>
<?php endif ?>

View File

@ -0,0 +1,52 @@
<?php if (empty($item)): ?>
<p class="alert alert-info"><?= t('Item not found') ?></p>
<?php else: ?>
<article class="item" id="current-item" data-item-id="<?= Model\encode_item_id($item['id']) ?>">
<h1>
<a href="<?= $item['url'] ?>" rel="noreferrer" target="_blank" id="original-item"><?= Helper\escape($item['title']) ?></a>
</h1>
<p class="infos">
<?= Helper\get_host_from_url($item['url']) ?> |
<?= dt('%A %e %B %Y %k:%M', $item['updated']) ?> |
<a href="?action=mark-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a>
</p>
<?= $item['content'] ?>
<?php if (isset($item_nav)): ?>
<nav>
<span class="nav-left">
<?php if ($item_nav['previous']): ?>
<a href="?action=read_starred&amp;id=<?= Model\encode_item_id($item_nav['previous']['id']) ?>" id="previous-item">« <?= t('Previous') ?></a>
<?php else: ?>
« <?= t('Previous') ?>
<?php endif ?>
</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 ?>
</span>
<span class="nav-right">
<?php if ($item_nav['next']): ?>
<a href="?action=read_starred&amp;id=<?= Model\encode_item_id($item_nav['next']['id']) ?>" id="next-item"><?= t('Next') ?> »</a>
<?php else: ?>
<?= t('Next') ?> »
<?php endif ?>
</span>
</nav>
<?php endif ?>
</article>
<?php endif ?>

View File

@ -28,6 +28,7 @@
</p>
<p>
<?= Helper\get_host_from_url($item['url']) ?> |
<a href="?action=mark-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a> |
<a href="?action=mark-item-read&amp;id=<?= $item_id ?>"><?= t('mark as read') ?></a> |
<a
href="<?= $item['url'] ?>"
@ -44,4 +45,4 @@
<?php endforeach ?>
</section>
<?php endif ?>
<?php endif ?>