From dfa65e9374a52441d9c7f2d9187dc831b705858e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 13 Aug 2020 11:52:32 +0300 Subject: [PATCH] move order_by to SQL override logic into a separate function --- classes/api.php | 16 +--------------- classes/feeds.php | 36 +++++++++++++++++++++--------------- classes/handler/public.php | 26 +++++++++----------------- 3 files changed, 31 insertions(+), 47 deletions(-) diff --git a/classes/api.php b/classes/api.php index 7c8c4c9f1..7b0c58a98 100755 --- a/classes/api.php +++ b/classes/api.php @@ -214,21 +214,7 @@ class API extends Handler { $_SESSION['hasSandbox'] = $has_sandbox; - $skip_first_id_check = false; - - $override_order = false; - switch (clean($_REQUEST["order_by"])) { - case "title": - $override_order = "ttrss_entries.title, date_entered, updated"; - break; - case "date_reverse": - $override_order = "updated"; - $skip_first_id_check = true; - break; - case "feed_dates": - $override_order = "updated DESC"; - break; - } + list($override_order, $skip_first_id_check) = Feeds::order_to_override_query(clean($_REQUEST["order_by"])); /* do not rely on params below */ diff --git a/classes/feeds.php b/classes/feeds.php index 5601a500d..86dd750ec 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -529,21 +529,7 @@ class Feeds extends Handler_Protected { $reply['headlines'] = []; - $override_order = false; - $skip_first_id_check = false; - - switch ($order_by) { - case "title": - $override_order = "ttrss_entries.title, date_entered, updated"; - break; - case "date_reverse": - $override_order = "updated"; - $skip_first_id_check = true; - break; - case "feed_dates": - $override_order = "updated DESC"; - break; - } + list($override_order, $skip_first_id_check) = Feeds::order_to_override_query($order_by); $ret = $this->format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $offset, @@ -2348,5 +2334,25 @@ class Feeds extends Handler_Protected { return array($search_query_part, $search_words); } + + static function order_to_override_query($order) { + $query = ""; + $skip_first_id = false; + + switch ($order) { + case "title": + $query = "ttrss_entries.title, date_entered, updated"; + break; + case "date_reverse": + $query = "updated"; + $skip_first_id = true; + break; + case "feed_dates": + $query = "updated DESC"; + break; + } + + return [$query, $skip_first_id]; + } } diff --git a/classes/handler/public.php b/classes/handler/public.php index c378de9bf..378e4b6c6 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -12,24 +12,16 @@ class Handler_Public extends Handler { if (!$limit) $limit = 60; - $date_sort_field = "date_entered DESC, updated DESC"; + list($override_order, $skip_first_id_check) = Feeds::order_to_override_query($order); - if ($feed == -2 && !$is_cat) { - $date_sort_field = "last_published DESC"; - } else if ($feed == -1 && !$is_cat) { - $date_sort_field = "last_marked DESC"; - } + if (!$override_order) { + $override_order = "date_entered DESC, updated DESC"; - switch ($order) { - case "title": - $date_sort_field = "ttrss_entries.title, date_entered, updated"; - break; - case "date_reverse": - $date_sort_field = "updated"; - break; - case "feed_dates": - $date_sort_field = "updated DESC"; - break; + if ($feed == -2 && !$is_cat) { + $override_order = "last_published DESC"; + } else if ($feed == -1 && !$is_cat) { + $override_order = "last_marked DESC"; + } } $params = array( @@ -39,7 +31,7 @@ class Handler_Public extends Handler { "view_mode" => $view_mode, "cat_view" => $is_cat, "search" => $search, - "override_order" => $date_sort_field, + "override_order" => $override_order, "include_children" => true, "ignore_vfeed_group" => true, "offset" => $offset,