From b3990c92e7dc4dc051aac0a444e8f6e13777ecc6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Nov 2010 13:56:42 +0300 Subject: [PATCH] add option to sort headlines by feed-specified date (bump schema) --- backend.php | 18 ++++++++++++------ functions.php | 18 +++++++++++++++--- modules/pref-prefs.php | 2 +- sanity_check.php | 2 +- schema/ttrss_schema_mysql.sql | 5 ++++- schema/ttrss_schema_pgsql.sql | 5 ++++- schema/versions/mysql/73.sql | 8 ++++++++ schema/versions/pgsql/73.sql | 8 ++++++++ 8 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 schema/versions/mysql/73.sql create mode 100644 schema/versions/pgsql/73.sql diff --git a/backend.php b/backend.php index 8b1454ad..5cef094d 100644 --- a/backend.php +++ b/backend.php @@ -313,28 +313,34 @@ $override_order = false; + if (get_pref($link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { + $date_sort_field = "updated"; + } else { + $date_sort_field = "date_entered"; + } + switch ($order_by) { case "date": if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $override_order = "date_entered"; + $override_order = "$date_sort_field"; } else { - $override_order = "date_entered DESC"; + $override_order = "$date_sort_field DESC"; } break; case "title": if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $override_order = "title DESC, date_entered"; + $override_order = "title DESC, $date_sort_field"; } else { - $override_order = "title, date_entered DESC"; + $override_order = "title, $date_sort_field DESC"; } break; case "score": if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $override_order = "score, date_entered"; + $override_order = "score, $date_sort_field"; } else { - $override_order = "score DESC, date_entered DESC"; + $override_order = "score DESC, $date_sort_field DESC"; } break; } diff --git a/functions.php b/functions.php index 835398cd..a5d3a7cf 100644 --- a/functions.php +++ b/functions.php @@ -3460,10 +3460,16 @@ $query_strategy_part = "id > 0"; // dumb } + if (get_pref($link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { + $date_sort_field = "updated"; + } else { + $date_sort_field = "date_entered"; + } + if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $order_by = "date_entered"; + $order_by = "$date_sort_field"; } else { - $order_by = "date_entered DESC"; + $order_by = "$date_sort_field DESC"; } if ($view_mode != "noscores") { @@ -3593,9 +3599,15 @@ if (!$limit) $limit = 30; + if (get_pref($link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { + $date_sort_field = "updated"; + } else { + $date_sort_field = "date_entered"; + } + $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $is_cat, $search, $search_mode, - $match_on, "date_entered DESC", 0, $owner_uid); + $match_on, "$date_sort_field DESC", 0, $owner_uid); $result = $qfh_ret[0]; $feed_title = htmlspecialchars($qfh_ret[1]); diff --git a/modules/pref-prefs.php b/modules/pref-prefs.php index 5fcb9311..e291e5c1 100644 --- a/modules/pref-prefs.php +++ b/modules/pref-prefs.php @@ -20,7 +20,7 @@ "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL", - "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE"); + "MARK_UNREAD_ON_UPDATE", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE"); if (FORCE_ARTICLE_PURGE != 0) { array_push($prefs_blacklist, "PURGE_OLD_DAYS"); diff --git a/sanity_check.php b/sanity_check.php index 20ef276c..79291ef3 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -2,7 +2,7 @@ require_once "functions.php"; define('EXPECTED_CONFIG_VERSION', 19); - define('SCHEMA_VERSION', 72); + define('SCHEMA_VERSION', 73); if (!file_exists("config.php")) { print "Fatal Error: You forgot to copy diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 52795703..e3408238 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -245,7 +245,7 @@ create table ttrss_tags (id integer primary key auto_increment, create table ttrss_version (schema_version int not null) TYPE=InnoDB DEFAULT CHARSET=UTF8; -insert into ttrss_version values (72); +insert into ttrss_version values (73); create table ttrss_enclosures (id integer primary key auto_increment, content_url text not null, @@ -406,6 +406,9 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('USER_TIMEZONE', 2, 'UTC', 'User timezone', 1); +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('SORT_HEADLINES_BY_FEED_DATE', 1, 'true', 'Sort headlines by feed date',3, + 'Use feed-specified date to sort headlines instead of local import date.'); + create table ttrss_user_prefs ( owner_uid integer not null, pref_name varchar(250), diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 29c82c0d..fc126500 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -217,7 +217,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid); create table ttrss_version (schema_version int not null); -insert into ttrss_version values (72); +insert into ttrss_version values (73); create table ttrss_enclosures (id serial not null primary key, content_url text not null, @@ -370,6 +370,9 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('USER_TIMEZONE', 2, 'UTC', 'User timezone', 1); +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('SORT_HEADLINES_BY_FEED_DATE', 1, 'true', 'Sort headlines by feed date',3, + 'Use feed-specified date to sort headlines instead of local import date.'); + create table ttrss_user_prefs ( owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE, pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE, diff --git a/schema/versions/mysql/73.sql b/schema/versions/mysql/73.sql new file mode 100644 index 00000000..051578d2 --- /dev/null +++ b/schema/versions/mysql/73.sql @@ -0,0 +1,8 @@ +begin; + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('SORT_HEADLINES_BY_FEED_DATE', 1, 'true', 'Sort headlines by feed date',3, + 'Use feed-specified date to sort headlines instead of local import date.'); + +update ttrss_version set schema_version = 73; + +commit; diff --git a/schema/versions/pgsql/73.sql b/schema/versions/pgsql/73.sql new file mode 100644 index 00000000..051578d2 --- /dev/null +++ b/schema/versions/pgsql/73.sql @@ -0,0 +1,8 @@ +begin; + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('SORT_HEADLINES_BY_FEED_DATE', 1, 'true', 'Sort headlines by feed date',3, + 'Use feed-specified date to sort headlines instead of local import date.'); + +update ttrss_version set schema_version = 73; + +commit; -- 2.39.5