diff --git a/data/.htaccess b/data/.htaccess deleted file mode 100644 index 14249c5..0000000 --- a/data/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all \ No newline at end of file diff --git a/index.php b/index.php index 34b90f3..9fef145 100644 --- a/index.php +++ b/index.php @@ -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(); diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index e3abc4d..c335df4 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -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 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 0e277bc..bcda45e 100644 --- a/model.php +++ b/model.php @@ -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')); } diff --git a/schema.php b/schema.php index 5c3409a..03f2768 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_7($pdo) { diff --git a/templates/add.php b/templates/add.php index abd1e4f..7be463c 100644 --- a/templates/add.php +++ b/templates/add.php @@ -13,4 +13,4 @@
- \ No newline at end of file + diff --git a/templates/app_header.php b/templates/app_header.php index 2ccee69..da9a4bc 100644 --- a/templates/app_header.php +++ b/templates/app_header.php @@ -1,4 +1,5 @@ + @@ -19,6 +20,7 @@