Merge branch 'starred' of git://github.com/MonsieurPaulLeBoulanger/miniflux into starred

This commit is contained in:
Frederic Guillot 2013-06-10 22:15:24 -04:00
commit 40b4c00124
12 changed files with 251 additions and 15 deletions

View File

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

View File

@ -103,6 +103,16 @@ 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,11 +128,26 @@ 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'));
Model\set_item_read($id);
Response\Redirect('?action=default');
Response\Redirect('?action='.$_SESSION['MODE']);
});
@ -130,7 +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');
Response\Redirect('?action='.$_SESSION['MODE']);
});
@ -138,7 +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');
Response\Redirect('?action='.$_SESSION['MODE']);
});
@ -158,6 +183,22 @@ 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='.$_SESSION['MODE']);
});
Router\get_action('mark-item-unstarred', function() {
$id = Model\decode_item_id(Request\param('id'));
Model\set_item_unstarred($id);
Response\Redirect('?action='.$_SESSION['MODE']);
});
Router\post_action('change-item-status', function() {
$id = Model\decode_item_id(Request\param('id'));
@ -170,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'
@ -178,6 +219,16 @@ 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'
)));
});
Router\get_action('confirm-remove', function() {
$id = Request\int_param('feed_id');
@ -390,6 +441,7 @@ Router\post_action('config', function() {
Router\notfound(function() {
$_SESSION['MODE']='default';
Model\autoflush();

View File

@ -9,6 +9,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',
@ -89,4 +94,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

@ -254,7 +254,7 @@ function get_unread_items()
{
return \PicoTools\singleton('db')
->table('items')
->columns('items.id', 'items.title', 'items.updated', 'items.url', 'feeds.site_url', 'items.content')
->columns('items.id', 'items.title', 'items.updated', 'items.url', 'feeds.site_url', 'items.content','starred')
->join('feeds', 'id', 'feed_id')
->eq('status', 'unread')
->desc('updated')
@ -266,11 +266,25 @@ function get_read_items()
{
return \PicoTools\singleton('db')
->table('items')
->columns('items.id', 'items.title', 'items.updated', 'items.url', 'feeds.site_url')
->columns('items.id', 'items.title', 'items.updated', 'items.url', 'feeds.site_url','starred')
->join('feeds', 'id', 'feed_id')
->eq('status', 'read')
->desc('updated')
->findAll();
}
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();
}
@ -312,12 +326,41 @@ 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')
->table('items')
->eq('id', $id)
->save(array('status' => 'removed'));
->save(array('status' => 'removed','starred' => 'unstarred'));
}
@ -339,6 +382,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')
@ -397,6 +459,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_7($pdo)
{

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">
@ -19,6 +20,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

@ -1,5 +1,4 @@
<?php if (empty($items)): ?>
<p class="alert alert-info"><?= t('No history') ?></p>
<?php else: ?>
@ -24,8 +23,18 @@
</a>
</h2>
<p>
<?= 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-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a> |
<?php else: ?>
<a href="?action=mark-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a> |
<?php endif ?>
<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 +51,4 @@
<?php endforeach ?>
</section>
<?php endif ?>
<?php endif ?>

View File

@ -3,6 +3,7 @@
<p class="alert alert-info"><?= t('Item not found') ?></p>
<?php else: ?>
<?php $item_id = Model\encode_item_id($item['id']) ?>
<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>
@ -10,7 +11,13 @@
<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']) ?> |
<?php if (isset($item['starred']) && $item['starred']=='starred'): ?>
<a href="?action=mark-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a>
<?php else: ?>
<a href="?action=mark-item-starred&amp;id=<?= $item_id ?>"><?= t('mark as starred') ?></a>
<?php endif ?>
</p>
<?= $item['content'] ?>
@ -48,4 +55,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=read_starred&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-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,44 @@
<?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">
<a href="?action=starred"><?= t('Starred') ?></a>
</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,14 @@
</p>
<p>
<?= Helper\get_host_from_url($item['url']) ?> |
<?php if (isset($item['starred']) && $item['starred']=='starred'): ?>
<a href="?action=mark-item-unstarred&amp;id=<?= $item_id ?>"><?= t('mark as unstarred') ?></a> |
<?php else: ?>
<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> |
<a
href="<?= $item['url'] ?>"
@ -44,4 +52,4 @@
<?php endforeach ?>
</section>
<?php endif ?>
<?php endif ?>