diff --git a/assets/js/app.js b/assets/js/app.js index 7c0e1b2..273f0ff 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -88,7 +88,7 @@ } // Set all items of the current page to the status read and redirect to the main page - function mark_items_as_read() + function mark_items_as_read(redirect) { var articles = document.getElementsByTagName("article"); var idlist = []; @@ -100,7 +100,7 @@ var request = new XMLHttpRequest(); request.onload = function() { - window.location.href = "?action=unread"; + window.location.href = redirect; }; request.open("POST", "?action=mark-items-as-read", true); @@ -499,7 +499,11 @@ break; case 'mark-all-read': e.preventDefault(); - mark_items_as_read(); + mark_items_as_read("?action=unread"); + break; + case 'mark-feed-read': + e.preventDefault(); + mark_items_as_read("?action=feed-items&feed_id=" + e.target.getAttribute("data-feed-id")); break; case 'original-link': var item_id = e.target.getAttribute("data-item-id"); diff --git a/index.php b/index.php index 826c5c2..7b5d9af 100644 --- a/index.php +++ b/index.php @@ -259,14 +259,19 @@ Router\get_action('feed-items', function() { $offset = Request\int_param('offset', 0); $nb_items = Model\count_feed_items($feed_id); $feed = Model\get_feed($feed_id); + $order = Request\param('order', 'updated'); + $direction = Request\param('direction', 'desc'); + $items = Model\get_feed_items($feed_id, $offset, Model\get_config_value('items_per_page'), $order, $direction); Response\html(Template\layout('feed_items', array( + 'order' => $order, + 'direction' => $direction, 'feed' => $feed, - 'items' => Model\get_feed_items($feed_id, $offset, Model\get_config_value('items_per_page')), + 'items' => $items, 'nb_items' => $nb_items, 'offset' => $offset, 'items_per_page' => Model\get_config_value('items_per_page'), - 'menu' => 'feeds', + 'menu' => 'feed-items', 'title' => '('.$nb_items.') '.$feed['title'] ))); }); @@ -297,6 +302,15 @@ Router\get_action('mark-as-read', function() { }); +// Mark all unread items as read for a specific feed +Router\get_action('mark-feed-as-read', function() { + + $feed_id = Request\int_param('feed_id'); + Model\mark_feed_as_read($feed_id); + Response\redirect('?action=unread'); +}); + + // Mark sent items id as read (Ajax request) Router\post_action('mark-items-as-read', function(){ @@ -782,13 +796,17 @@ Router\notfound(function() { Model\autoflush(); + $order = Request\param('order', 'updated'); + $direction = Request\param('direction', 'desc'); $offset = Request\int_param('offset', 0); - $items = Model\get_items('unread', $offset, Model\get_config_value('items_per_page')); + $items = Model\get_items('unread', $offset, Model\get_config_value('items_per_page'), $order, $direction); $nb_items = Model\count_items('unread'); if ($nb_items === 0) Response\redirect('?action=feeds¬hing_to_read=1'); Response\html(Template\layout('unread_items', array( + 'order' => $order, + 'direction' => $direction, 'items' => $items, 'nb_items' => $nb_items, 'nb_unread_items' => $nb_items, diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 4139622..2ded1bc 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,6 +1,11 @@ go back to unread items' => 'Cet abonnement est vide, retourner à la liste des éléments non lus', + 'sort by date (%s)' => 'trier par date (%s)', + 'most recent' => 'plus récents', + 'older' => 'anciens d\'abord', + 'Show only this subscription' => 'Montrer seulement cet abonnement', 'Go to unread' => 'Voir les éléments non lus', 'Go to bookmarks' => 'Voir les favoris', 'Go to history' => 'Voir l\'historique', diff --git a/model.php b/model.php index 776ea7c..d0477a4 100644 --- a/model.php +++ b/model.php @@ -509,7 +509,7 @@ function disable_grabber_feed($feed_id) } -function get_items($status, $offset = null, $limit = null) +function get_items($status, $offset = null, $limit = null, $order_column = 'updated', $order_direction = 'desc') { return \PicoTools\singleton('db') ->table('items') @@ -527,7 +527,7 @@ function get_items($status, $offset = null, $limit = null) ) ->join('feeds', 'id', 'feed_id') ->eq('status', $status) - ->desc('updated') + ->orderBy($order_column, $order_direction) ->offset($offset) ->limit($limit) ->findAll(); @@ -583,12 +583,12 @@ function count_feed_items($feed_id) return \PicoTools\singleton('db') ->table('items') ->eq('feed_id', $feed_id) - ->in('status', array('read', 'unread')) + ->eq('status', 'unread') ->count(); } -function get_feed_items($feed_id, $offset = null, $limit = null) +function get_feed_items($feed_id, $offset = null, $limit = null, $order_column = 'updated', $order_direction = 'desc') { return \PicoTools\singleton('db') ->table('items') @@ -604,9 +604,9 @@ function get_feed_items($feed_id, $offset = null, $limit = null) 'feeds.site_url' ) ->join('feeds', 'id', 'feed_id') - ->in('status', array('read', 'unread')) + ->eq('status', 'unread') ->eq('feed_id', $feed_id) - ->desc('updated') + ->orderBy($order_column, $order_direction) ->offset($offset) ->limit($limit) ->findAll(); @@ -783,6 +783,26 @@ function mark_items_as_read(array $items_id) } +// Mark all items of a feed as read +function mark_feed_as_read($feed_id) +{ + \PicoTools\singleton('db')->startTransaction(); + + $items_id = \PicoTools\singleton('db') + ->table('items') + ->columns('items.id') + ->eq('status', 'unread') + ->eq('feed_id', $feed_id) + ->listing('id', 'id'); + + foreach ($items_id as $id) { + set_item_read($id); + } + + \PicoTools\singleton('db')->closeTransaction(); +} + + function mark_as_removed() { return \PicoTools\singleton('db') diff --git a/templates/bookmarks.php b/templates/bookmarks.php index e98bfa4..4c862c6 100644 --- a/templates/bookmarks.php +++ b/templates/bookmarks.php @@ -24,7 +24,7 @@ = Helper\escape(Helper\summary(strip_tags($item['content']), 50, 300)) ?>
- = Helper\escape($item['feed_title']) ?> | + = Helper\escape($item['feed_title']) ?> | = dt('%e %B %Y %k:%M', $item['updated']) ?> |
- = Helper\escape($item['feed_title']) ?> | + = Helper\escape($item['feed_title']) ?> | diff --git a/templates/unread_items.php b/templates/unread_items.php index 39a4712..7fd6553 100644 --- a/templates/unread_items.php +++ b/templates/unread_items.php @@ -8,9 +8,10 @@
- = Helper\escape($item['feed_title']) ?> | + = Helper\escape($item['feed_title']) ?> |