From e7be31c92cb3ed9eb930318ed47d1cdb0e2d4e97 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 4 Aug 2013 15:15:12 -0400 Subject: [PATCH] Add the possibility to disable/enable a feed --- assets/css/app.css | 5 + assets/js/app.js | 1 - index.php | 154 ++++++++++++++++++----------- jsonrpc.php | 12 +++ locales/fr_FR/translations.php | 8 ++ model.php | 18 +++- schema.php | 6 ++ templates/confirm_disable_feed.php | 10 ++ templates/feeds.php | 23 ++++- 9 files changed, 172 insertions(+), 65 deletions(-) create mode 100644 templates/confirm_disable_feed.php diff --git a/assets/css/app.css b/assets/css/app.css index 484793b..f2782c1 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -375,6 +375,11 @@ nav .active a { padding-right: 0; } +.feed-disabled, +.feed-disabled a { + color: #aaa; +} + /* items listing */ .items article { diff --git a/assets/js/app.js b/assets/js/app.js index 119dc5b..b6f9f6f 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -210,7 +210,6 @@ var feed_id = links[i].getAttribute('data-feed-id'); if (feed_id) { - feeds.push(parseInt(feed_id)); } } diff --git a/index.php b/index.php index 9018d98..732c3b1 100644 --- a/index.php +++ b/index.php @@ -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 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 Router\get_action('feeds', function() { diff --git a/jsonrpc.php b/jsonrpc.php index 642d778..2495e9f 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -37,6 +37,18 @@ $server->register('feed.delete', function($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 $server->register('feed.update', function($feed_id) { diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 82a4bfe..f3ced37 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,6 +1,14 @@ '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', 'content downloaded' => 'contenu téléchargé', 'in progress...' => 'en cours...', diff --git a/model.php b/model.php index 1b8677e..b979a1f 100644 --- a/model.php +++ b/model.php @@ -25,7 +25,7 @@ use PicoFeed\Reader; use PicoFeed\Export; -const DB_VERSION = 12; +const DB_VERSION = 13; const HTTP_USERAGENT = 'Miniflux - http://miniflux.net'; const LIMIT_ALL = -1; @@ -241,6 +241,7 @@ function update_feed($feed_id) function get_feeds_id($limit = LIMIT_ALL) { $table_feeds = \PicoTools\singleton('db')->table('feeds') + ->eq('enabled', 1) ->asc('last_checked'); if ($limit !== LIMIT_ALL) { @@ -369,8 +370,19 @@ function download_item($item_id) function remove_feed($feed_id) { // Items are removed by a sql constraint - $db = \PicoTools\singleton('db'); - return $db->table('feeds')->eq('id', $feed_id)->remove(); + return \PicoTools\singleton('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))); } diff --git a/schema.php b/schema.php index 247c94c..8ddf996 100644 --- a/schema.php +++ b/schema.php @@ -3,6 +3,12 @@ namespace Schema; +function version_13($pdo) +{ + $pdo->exec('ALTER TABLE feeds ADD COLUMN enabled INTEGER DEFAULT 1'); +} + + function version_12($pdo) { $pdo->exec('ALTER TABLE config ADD COLUMN api_token TEXT DEFAULT "'.\Model\generate_api_token().'"'); diff --git a/templates/confirm_disable_feed.php b/templates/confirm_disable_feed.php new file mode 100644 index 0000000..70dcb3d --- /dev/null +++ b/templates/confirm_disable_feed.php @@ -0,0 +1,10 @@ + + +

+ +
+ + +
\ No newline at end of file diff --git a/templates/feeds.php b/templates/feeds.php index 6064343..7a82872 100644 --- a/templates/feeds.php +++ b/templates/feeds.php @@ -21,16 +21,29 @@
-

- +

+ + ∅ + + + + +

| - | + | - | - + + + | + | + + | + + +