From 9e437c1a939eacb82b0952f507347bd1fc817a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Wed, 18 Sep 2013 21:02:46 -0400 Subject: [PATCH] Add a preference parameter to save default items sorting order --- README.markdown | 4 +++- index.php | 14 +++++++++++--- locales/fr_FR/translations.php | 7 +++++-- model.php | 18 ++++++++++++++---- schema.php | 6 ++++++ templates/config.php | 3 +++ templates/feed_items.php | 2 +- templates/unread_items.php | 2 +- 8 files changed, 44 insertions(+), 12 deletions(-) diff --git a/README.markdown b/README.markdown index 767dafc..0ee82ae 100644 --- a/README.markdown +++ b/README.markdown @@ -41,11 +41,12 @@ Original author: [Frédéric Guillot](http://fredericguillot.com/) ### Contributors -People who sent one or many pull-requests: +People who sent a pull-request, report a bug, make a new theme or share super a cool idea: - André Kelpe: https://github.com/fs111 - Ayodio: https://github.com/ayodio - Bjauy: https://github.com/bjauy +- Bohwaz: https://github.com/bohwaz - Chase Arnold: https://github.com/chase4926 - Chris Lemonier: https://github.com/chrislemonier - Derjus: https://github.com/derjus @@ -53,6 +54,7 @@ People who sent one or many pull-requests: - Félix: https://github.com/dysosmus - Horsely: https://github.com/horsley - Ing. Jan Kaláb: https://github.com/Pitel +- Itoine: https://github.com/itoine - James Scott-Brown: https://github.com/jamesscottbrown - Luca Marra: https://github.com/facciocose - Maxime: https://github.com/EpocDotFr diff --git a/index.php b/index.php index 7b5d9af..6693434 100644 --- a/index.php +++ b/index.php @@ -242,7 +242,13 @@ Router\get_action('history', function() { $nb_items = Model\count_items('read'); Response\html(Template\layout('history', array( - 'items' => Model\get_items('read', $offset, Model\get_config_value('items_per_page')), + 'items' => Model\get_items( + 'read', + $offset, + Model\get_config_value('items_per_page'), + 'updated', + Model\get_config_value('items_sorting_direction') + ), 'nb_items' => $nb_items, 'offset' => $offset, 'items_per_page' => Model\get_config_value('items_per_page'), @@ -260,7 +266,7 @@ Router\get_action('feed-items', function() { $nb_items = Model\count_feed_items($feed_id); $feed = Model\get_feed($feed_id); $order = Request\param('order', 'updated'); - $direction = Request\param('direction', 'desc'); + $direction = Request\param('direction', Model\get_config_value('items_sorting_direction')); $items = Model\get_feed_items($feed_id, $offset, Model\get_config_value('items_per_page'), $order, $direction); Response\html(Template\layout('feed_items', array( @@ -642,6 +648,7 @@ Router\get_action('config', function() { 'autoflush_options' => Model\get_autoflush_options(), 'paging_options' => Model\get_paging_options(), 'theme_options' => Model\get_themes(), + 'sorting_options' => Model\get_sorting_directions(), 'menu' => 'config', 'title' => t('Preferences') ))); @@ -674,6 +681,7 @@ Router\post_action('config', function() { 'autoflush_options' => Model\get_autoflush_options(), 'paging_options' => Model\get_paging_options(), 'theme_options' => Model\get_themes(), + 'sorting_options' => Model\get_sorting_directions(), 'menu' => 'config', 'title' => t('Preferences') ))); @@ -797,7 +805,7 @@ Router\notfound(function() { Model\autoflush(); $order = Request\param('order', 'updated'); - $direction = Request\param('direction', 'desc'); + $direction = Request\param('direction', Model\get_config_value('items_sorting_direction')); $offset = Request\int_param('offset', 0); $items = Model\get_items('unread', $offset, Model\get_config_value('items_per_page'), $order, $direction); $nb_items = Model\count_items('unread'); diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index ab2b013..08f43b5 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,10 +1,13 @@ 'Plus anciens en premier', + 'Most recent first' => 'Plus récents en premier', + 'Default sorting order for items' => 'Ordre des éléments par défaut', 'This subscription is empty, 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', + 'most recent first' => 'plus récents d\'abord', + 'older first' => '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', diff --git a/model.php b/model.php index 2892dd2..37a92ec 100644 --- a/model.php +++ b/model.php @@ -24,12 +24,21 @@ use PicoFeed\Reader; use PicoFeed\Export; -const DB_VERSION = 16; +const DB_VERSION = 17; const HTTP_USERAGENT = 'Miniflux - http://miniflux.net'; const HTTP_FAKE_USERAGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36'; const LIMIT_ALL = -1; +function get_sorting_directions() +{ + return array( + 'asc' => t('Older items first'), + 'desc' => t('Most recent first'), + ); +} + + function get_languages() { return array( @@ -571,7 +580,7 @@ function get_bookmarks($offset = null, $limit = null) ->join('feeds', 'id', 'feed_id') ->in('status', array('read', 'unread')) ->eq('bookmark', 1) - ->desc('updated') + ->orderBy('updated', get_config_value('items_sorting_direction')) ->offset($offset) ->limit($limit) ->findAll(); @@ -628,7 +637,7 @@ function get_nav_item($item, $status = array('unread'), $bookmark = array(1, 0), ->table('items') ->columns('id', 'status', 'title', 'bookmark') ->neq('status', 'removed') - ->desc('updated'); + ->orderBy('updated', get_config_value('items_sorting_direction')); if ($feed_id) $query->eq('feed_id', $feed_id); @@ -937,7 +946,8 @@ function get_config() 'api_token', 'feed_token', 'auth_google_token', - 'auth_mozilla_token' + 'auth_mozilla_token', + 'items_sorting_direction' ) ->findOne(); } diff --git a/schema.php b/schema.php index c1fcaf5..58ab98e 100644 --- a/schema.php +++ b/schema.php @@ -3,6 +3,12 @@ namespace Schema; +function version_17($pdo) +{ + $pdo->exec('ALTER TABLE config ADD COLUMN items_sorting_direction TEXT DEFAULT "desc"'); +} + + function version_16($pdo) { $pdo->exec('ALTER TABLE config ADD COLUMN auth_google_token TEXT DEFAULT ""'); diff --git a/templates/config.php b/templates/config.php index 0e71a05..9a8d19a 100644 --- a/templates/config.php +++ b/templates/config.php @@ -22,6 +22,9 @@
+ +
+
diff --git a/templates/feed_items.php b/templates/feed_items.php index e9eb31b..2a57108 100644 --- a/templates/feed_items.php +++ b/templates/feed_items.php @@ -10,7 +10,7 @@

()