From 3758237bb48eb662f6683f20613eb0b034d9052c Mon Sep 17 00:00:00 2001 From: MonsieurPaulLeBoulanger Date: Tue, 4 Jun 2013 13:38:54 +0200 Subject: [PATCH] added a Star System : starred items will be shown on the Starred Tab Starred item will not be deleted by auto flush --- common.php | 4 +- index.php | 77 +++++++++++++++++++++++++++++++++- locales/fr_FR/translations.php | 7 +++- model.php | 61 +++++++++++++++++++++++++++ schema.php | 5 +++ templates/app_header.php | 1 + templates/history.php | 3 +- templates/read_item.php | 5 ++- templates/starred.php | 42 +++++++++++++++++++ templates/starred_item.php | 52 +++++++++++++++++++++++ templates/unread_items.php | 3 +- 11 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 templates/starred.php create mode 100644 templates/starred_item.php diff --git a/common.php b/common.php index 5fc9893..705e633 100644 --- a/common.php +++ b/common.php @@ -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.'); } -}); \ No newline at end of file +}); diff --git a/index.php b/index.php index 850c8e5..34e3273 100644 --- a/index.php +++ b/index.php @@ -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' ))); -}); \ No newline at end of file +}); diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index e87df66..94a4778 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -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 update your subscriptions?' => 'Il n\'y a rien à lire, voulez-vous mettre à jour vos abonnements ?' -); \ No newline at end of file +); diff --git a/model.php b/model.php index a9ea1b1..f1662a3 100644 --- a/model.php +++ b/model.php @@ -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')); } diff --git a/schema.php b/schema.php index 3ec5beb..c6a30d7 100644 --- a/schema.php +++ b/schema.php @@ -2,6 +2,11 @@ namespace Schema; +function version_7($pdo) +{ + $pdo->exec('ALTER TABLE items ADD COLUMN starred TEXT'); +} + function version_6($pdo) { diff --git a/templates/app_header.php b/templates/app_header.php index 2ccee69..52a95e7 100644 --- a/templates/app_header.php +++ b/templates/app_header.php @@ -19,6 +19,7 @@