From 77de8b3efc90934ba2119dafe310249036c36d76 Mon Sep 17 00:00:00 2001 From: mkuba50 Date: Sat, 10 Feb 2018 01:10:57 +0100 Subject: [PATCH] Added search of builds in local database --- listid.php | 30 ++++++++++++++++++++++++++++-- shared/main.php | 4 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/listid.php b/listid.php index 2381e8a..7e1aead 100644 --- a/listid.php +++ b/listid.php @@ -1,6 +1,6 @@ 'NO_FILEINFO_DIR'); @@ -100,6 +100,32 @@ function uupListIds() { if(!$success) consoleLogger('Failed to update database cache.'); } + if($search) { + $searchSafe = preg_quote($search, '/'); + if(preg_match('/^".*"$/', $searchSafe)) { + $searchSafe = preg_replace('/^"|"$/', '', $searchSafe); + } else { + $searchSafe = str_replace(' ', '.*', $searchSafe); + } + + foreach($builds as $key => $val) { + $buildString[$key] = $val['title'].' '.$val['build'].' '.$val['arch']; + } + + $remove = preg_grep('/.*'.$searchSafe.'.*/i', $buildString, PREG_GREP_INVERT); + $removeKeys = array_keys($remove); + + foreach($removeKeys as $value) { + unset($builds[$value]); + } + + if(empty($builds)) { + return array('error' => 'SEARCH_NO_RESULTS'); + } + + unset($remove, $removeKeys, $buildString); + } + return array( 'apiVersion' => uupApiVersion(), 'builds' => $builds, diff --git a/shared/main.php b/shared/main.php index 7fe6de7..1e986a0 100644 --- a/shared/main.php +++ b/shared/main.php @@ -1,6 +1,6 @@