Add the possibility to disable/enable a feed

This commit is contained in:
Frederic Guillot 2013-08-04 15:15:12 -04:00
parent 40ab99cd6c
commit e7be31c92c
9 changed files with 172 additions and 65 deletions

View File

@ -375,6 +375,11 @@ nav .active a {
padding-right: 0; padding-right: 0;
} }
.feed-disabled,
.feed-disabled a {
color: #aaa;
}
/* items listing */ /* items listing */
.items article { .items article {

View File

@ -210,7 +210,6 @@
var feed_id = links[i].getAttribute('data-feed-id'); var feed_id = links[i].getAttribute('data-feed-id');
if (feed_id) { if (feed_id) {
feeds.push(parseInt(feed_id)); feeds.push(parseInt(feed_id));
} }
} }

154
index.php
View File

@ -279,62 +279,6 @@ Router\get_action('bookmarks', function() {
}); });
// Confirmation box to remove a feed
Router\get_action('confirm-remove-feed', function() {
$id = Request\int_param('feed_id');
Response\html(Template\layout('confirm_remove_feed', array(
'feed' => Model\get_feed($id),
'menu' => 'feeds',
'title' => t('Confirmation')
)));
});
// Remove a feed
Router\get_action('remove-feed', function() {
$id = Request\int_param('feed_id');
if ($id && Model\remove_feed($id)) {
Session\flash(t('This subscription has been removed successfully.'));
}
else {
Session\flash_error(t('Unable to remove this subscription.'));
}
Response\redirect('?action=feeds');
});
// Refresh one feed and redirect to unread items
Router\get_action('refresh-feed', function() {
$id = Request\int_param('feed_id');
if ($id) Model\update_feed($id);
Model\write_debug();
Response\redirect('?action=unread');
});
// Ajax call to refresh one feed
Router\post_action('refresh-feed', function() {
$id = Request\int_param('feed_id', 0);
if ($id) {
$result = Model\update_feed($id);
Model\write_debug();
}
Response\json(array('feed_id' => $id, 'result' => $result));
});
// Mark all unread items as read // Mark all unread items as read
Router\get_action('mark-as-read', function() { Router\get_action('mark-as-read', function() {
@ -380,6 +324,104 @@ Router\get_action('refresh-all', function() {
}); });
// Confirmation box to disable a feed
Router\get_action('confirm-disable-feed', function() {
$id = Request\int_param('feed_id');
Response\html(Template\layout('confirm_disable_feed', array(
'feed' => Model\get_feed($id),
'menu' => 'feeds',
'title' => t('Confirmation')
)));
});
// Disable a feed
Router\get_action('disable-feed', function() {
$id = Request\int_param('feed_id');
if ($id && Model\disable_feed($id)) {
Session\flash(t('This subscription has been disabled successfully.'));
}
else {
Session\flash_error(t('Unable to disable this subscription.'));
}
Response\redirect('?action=feeds');
});
// Enable a feed
Router\get_action('enable-feed', function() {
$id = Request\int_param('feed_id');
if ($id && Model\enable_feed($id)) {
Session\flash(t('This subscription has been enabled successfully.'));
}
else {
Session\flash_error(t('Unable to enable this subscription.'));
}
Response\redirect('?action=feeds');
});
// Confirmation box to remove a feed
Router\get_action('confirm-remove-feed', function() {
$id = Request\int_param('feed_id');
Response\html(Template\layout('confirm_remove_feed', array(
'feed' => Model\get_feed($id),
'menu' => 'feeds',
'title' => t('Confirmation')
)));
});
// Remove a feed
Router\get_action('remove-feed', function() {
$id = Request\int_param('feed_id');
if ($id && Model\remove_feed($id)) {
Session\flash(t('This subscription has been removed successfully.'));
}
else {
Session\flash_error(t('Unable to remove this subscription.'));
}
Response\redirect('?action=feeds');
});
// Refresh one feed and redirect to unread items
Router\get_action('refresh-feed', function() {
$id = Request\int_param('feed_id');
if ($id) Model\update_feed($id);
Model\write_debug();
Response\redirect('?action=unread');
});
// Ajax call to refresh one feed
Router\post_action('refresh-feed', function() {
$id = Request\int_param('feed_id', 0);
if ($id) {
$result = Model\update_feed($id);
Model\write_debug();
}
Response\json(array('feed_id' => $id, 'result' => $result));
});
// Display all feeds // Display all feeds
Router\get_action('feeds', function() { Router\get_action('feeds', function() {

View File

@ -37,6 +37,18 @@ $server->register('feed.delete', function($feed_id) {
return Model\remove_feed($feed_id); return Model\remove_feed($feed_id);
}); });
// Enable a feed
$server->register('feed.enable', function($feed_id) {
return Model\enable_feed($feed_id);
});
// Disable a feed
$server->register('feed.disable', function($feed_id) {
return Model\disable_feed($feed_id);
});
// Update a feed // Update a feed
$server->register('feed.update', function($feed_id) { $server->register('feed.update', function($feed_id) {

View File

@ -1,6 +1,14 @@
<?php <?php
return array( return array(
'Unable to enable this subscription.' => 'Impossible d\'activer cet abonnement.',
'This subscription has been enabled successfully.' => 'L\'abonnement a été activé avec succès.',
'Unable to disable this subscription.' => 'Impossible de désactiver cet abonnement.',
'This subscription has been disabled successfully.' => 'L\'abonnement a été désactivé avec succès.',
'Do you really want to disable this subscription: "%s"?' => 'Voulez-vous vraiment désactiver cet abonnement : "%s" ?',
'enable' => 'activer',
'disable' => 'désactiver',
'Subscription disabled' => 'Abonnement désactivé',
'Listing' => 'Liste', 'Listing' => 'Liste',
'content downloaded' => 'contenu téléchargé', 'content downloaded' => 'contenu téléchargé',
'in progress...' => 'en cours...', 'in progress...' => 'en cours...',

View File

@ -25,7 +25,7 @@ use PicoFeed\Reader;
use PicoFeed\Export; use PicoFeed\Export;
const DB_VERSION = 12; const DB_VERSION = 13;
const HTTP_USERAGENT = 'Miniflux - http://miniflux.net'; const HTTP_USERAGENT = 'Miniflux - http://miniflux.net';
const LIMIT_ALL = -1; const LIMIT_ALL = -1;
@ -241,6 +241,7 @@ function update_feed($feed_id)
function get_feeds_id($limit = LIMIT_ALL) function get_feeds_id($limit = LIMIT_ALL)
{ {
$table_feeds = \PicoTools\singleton('db')->table('feeds') $table_feeds = \PicoTools\singleton('db')->table('feeds')
->eq('enabled', 1)
->asc('last_checked'); ->asc('last_checked');
if ($limit !== LIMIT_ALL) { if ($limit !== LIMIT_ALL) {
@ -369,8 +370,19 @@ function download_item($item_id)
function remove_feed($feed_id) function remove_feed($feed_id)
{ {
// Items are removed by a sql constraint // Items are removed by a sql constraint
$db = \PicoTools\singleton('db'); return \PicoTools\singleton('db')->table('feeds')->eq('id', $feed_id)->remove();
return $db->table('feeds')->eq('id', $feed_id)->remove(); }
function enable_feed($feed_id)
{
return \PicoTools\singleton('db')->table('feeds')->eq('id', $feed_id)->save((array('enabled' => 1)));
}
function disable_feed($feed_id)
{
return \PicoTools\singleton('db')->table('feeds')->eq('id', $feed_id)->save((array('enabled' => 0)));
} }

View File

@ -3,6 +3,12 @@
namespace Schema; namespace Schema;
function version_13($pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN enabled INTEGER DEFAULT 1');
}
function version_12($pdo) function version_12($pdo)
{ {
$pdo->exec('ALTER TABLE config ADD COLUMN api_token TEXT DEFAULT "'.\Model\generate_api_token().'"'); $pdo->exec('ALTER TABLE config ADD COLUMN api_token TEXT DEFAULT "'.\Model\generate_api_token().'"');

View File

@ -0,0 +1,10 @@
<div class="page-header">
<h2><?= t('Confirmation') ?></h2>
</div>
<p class="alert alert-info"><?= t('Do you really want to disable this subscription: "%s"?', Helper\escape($feed['title'])) ?></p>
<div class="form-actions">
<a href="?action=disable-feed&amp;feed_id=<?= $feed['id'] ?>" class="btn btn-red"><?= t('Yes') ?></a>
<?= t('or') ?> <a href="?action=feeds"><?= t('cancel') ?></a>
</div>

View File

@ -21,16 +21,29 @@
<section class="items"> <section class="items">
<?php foreach ($feeds as $feed): ?> <?php foreach ($feeds as $feed): ?>
<article> <article>
<h2> <h2 class="<?= (! $feed['enabled']) ? 'feed-disabled' : '' ?>">
<span id="loading-feed-<?= $feed['id'] ?>"></span> <?php if (! $feed['enabled']): ?>
<span title="<?= t('Subscription disabled') ?>"></a>
<?php else: ?>
<span id="loading-feed-<?= $feed['id'] ?>"></span>
<?php endif ?>
<a href="<?= $feed['site_url'] ?>" rel="noreferrer" target="_blank"><?= Helper\escape($feed['title']) ?></a> <a href="<?= $feed['site_url'] ?>" rel="noreferrer" target="_blank"><?= Helper\escape($feed['title']) ?></a>
</h2> </h2>
<p> <p>
<a href="<?= $feed['site_url'] ?>" rel="noreferrer" target="_blank"><?= Helper\get_host_from_url($feed['site_url']) ?></a> | <a href="<?= $feed['site_url'] ?>" rel="noreferrer" target="_blank"><?= Helper\get_host_from_url($feed['site_url']) ?></a> |
<span class="hide-mobile"><a href="<?= Helper\escape($feed['feed_url']) ?>" rel="noreferrer" target="_blank"><?= t('feed link') ?></a> |</span>
<span class="hide-mobile"><a href="?action=confirm-remove-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('remove') ?></a> |</span> <span class="hide-mobile"><a href="?action=confirm-remove-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('remove') ?></a> |</span>
<span class="hide-mobile"><a href="?action=feed-items&amp;feed_id=<?= $feed['id'] ?>"><?= t('items') ?></a> |</span>
<a href="?action=refresh-feed&amp;feed_id=<?= $feed['id'] ?>" data-feed-id="<?= $feed['id'] ?>" data-action="refresh-feed"><?= t('refresh') ?></a> <?php if ($feed['enabled']): ?>
<span class="hide-mobile"><a href="?action=confirm-disable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('disable') ?></a> |</span>
<a href="?action=refresh-feed&amp;feed_id=<?= $feed['id'] ?>" data-feed-id="<?= $feed['id'] ?>" data-action="refresh-feed"><?= t('refresh') ?></a> |
<?php else: ?>
<span class="hide-mobile"><a href="?action=enable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('enable') ?></a> |</span>
<?php endif ?>
<span class="hide-mobile"><a href="?action=feed-items&amp;feed_id=<?= $feed['id'] ?>"><?= t('items') ?></a></span>
</p> </p>
</article> </article>
<?php endforeach ?> <?php endforeach ?>