From 28f074140370a8c2a11b995271e4c135b2cc1c7f Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 18 Feb 2019 21:34:07 +0100 Subject: extracting of ORDER BY info from $_GET moved from packages/index.php to function in lib/style.php --- lib/style.php | 24 ++++++++++++++++++++++++ packages/index.php | 19 +++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/style.php b/lib/style.php index ff2d364..99d9840 100644 --- a/lib/style.php +++ b/lib/style.php @@ -124,6 +124,30 @@ $pkglist_sorts = array( ) ); +function package_listing_query_order_by() { + global $pkglist_sorts; + if (!array_key_exists('sort', $_GET)) + return; + $criterium = $_GET['sort']; + if ( + array_key_exists($criterium, $pkglist_sorts) && + array_key_exists('mysql', $pkglist_sorts[$criterium]) + ) + return $pkglist_sorts[$criterium]['mysql'] . ','; + + if (substr($criterium, 0, 1) != '-') + return; + $criterium = substr($criterium, 1); + + if ( + array_key_exists($criterium, $pkglist_sorts) && + array_key_exists('mysql', $pkglist_sorts[$criterium]) + ) + return $pkglist_sorts[$criterium]['mysql'] . ' DESC,'; + + return; +} + function query_package_listing($filter_and_order, $float_columns, $count_only) { if ($count_only) $columns = "COUNT(DISTINCT `binary_packages`.`id`)"; diff --git a/packages/index.php b/packages/index.php index 4d854a9..35f0d26 100644 --- a/packages/index.php +++ b/packages/index.php @@ -129,19 +129,11 @@ require_once BASE . "/lib/format.php"; false ); - $q_f = $extra_joins . $filter . $fuzzy_filter . " ORDER BY "; - - if (array_key_exists("sort", $_GET)) { - if (isset($pkglist_sorts[$_GET["sort"]]["mysql"])) - $q_f .= $pkglist_sorts[$_GET["sort"]]["mysql"] . ","; - elseif (isset($pkglist_sorts[substr($_GET["sort"],1)]["mysql"])) - $q_f .= $pkglist_sorts[substr($_GET["sort"],1)]["mysql"] . " DESC,"; - } - - $q_f .= "`binary_packages`.`pkgname`,`repositories`.`stability`,`repositories`.`name`,`architectures`.`name`"; $num_results = query_package_listing( - $q_f, + $extra_joins . $filter . $fuzzy_filter . + " ORDER BY " . package_listing_query_order_by() . + "`binary_packages`.`pkgname`,`repositories`.`stability`,`repositories`.`name`,`architectures`.`name`", array(), true ); @@ -153,7 +145,10 @@ require_once BASE . "/lib/format.php"; $page = 1; $fuzzy_matches = query_package_listing( - $q_f . " LIMIT " . (($page-1)*100) . ", 100", + $extra_joins . $filter . $fuzzy_filter . + " ORDER BY " . package_listing_query_order_by() . + "`binary_packages`.`pkgname`,`repositories`.`stability`,`repositories`.`name`,`architectures`.`name`" . + " LIMIT " . (($page-1)*100) . ", 100", $float_columns, false ); -- cgit v1.2.3-70-g09d2