From 38965759d6d92d47326e1bd11189a74d330f550b Mon Sep 17 00:00:00 2001 From: Klimplant Date: Sat, 16 Feb 2019 17:00:55 +0100 Subject: [PATCH] Implementing #1 --- functions.php | 12 ++++++++++++ index.php | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index b54d9e7..c063458 100644 --- a/functions.php +++ b/functions.php @@ -41,3 +41,15 @@ function getHostJson($librehostJsonUrl) { $response = json_decode($response, true); return $response; } + +function moveHostToBeginning(&$hosts, $query) { + $query = strtolower($query); + foreach ($hosts as $key => $host) { + if (strtolower($host['name']) === $query) { + $h = $host; + unset($hosts[$key]); + array_unshift($hosts, $h); + break; + } + } +} diff --git a/index.php b/index.php index 781ba4a..4580aea 100644 --- a/index.php +++ b/index.php @@ -53,6 +53,13 @@ if ($recache) { echo "Cache is valid"; } +shuffle($hosts); + +if (isset($_GET['h'])) { + $query = $_GET['h']; + moveHostToBeginning($hosts, $query); +} + ?> @@ -70,7 +77,6 @@ if ($recache) {
-- GitLab