summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Burton <phil@d3r.com>2015-12-10 16:14:17 +0000
committerPhil Burton <phil@d3r.com>2015-12-10 16:14:17 +0000
commit2ddc79fe381529f81886c385622d5bff3e586236 (patch)
treecaada216e2adc1144847c45ef2e3026b1103b83d
parentebc68bf73205c0f821e6a0c70218112b4a2b288a (diff)
Move the check to a regex. Prevents a few loopsHEADmaster
-rw-r--r--search.php21
1 files changed, 7 insertions, 14 deletions
diff --git a/search.php b/search.php
index aa19f90..795d404 100644
--- a/search.php
+++ b/search.php
@@ -1,6 +1,6 @@
<?php
-define("VERSION", "2.0.2");
+define("VERSION", "2.1.0");
/**
* Load and parse the config file, setting any defaults here if non-required
@@ -234,19 +234,12 @@ try {
// Really slow search
$results = [];
- foreach ($content as $upload) {
- $match = false;
- foreach ($arguments["search"] as $arg) {
- if (!is_null($arg) && stripos($upload, $arg) === false) {
- $match = false;
- break;
- }
- $match = true;
- }
- if ($match) {
- $results[] = $config["url"] . "/" . rawurlencode($upload);
- }
+ $regex = "";
+ foreach ($arguments["search"] as $arg) {
+ $regex .= "(?=.*" . $arg . ")";
}
+ $content = preg_grep("/" . $regex . "/i", $content);
+ $results = $content;
if (empty($results)) {
output("No results found");
@@ -265,7 +258,7 @@ try {
$i++;
continue;
}
- $out[] = $i + 1 . ": " . $result;
+ $out[] = $i + 1 . ": " . $config["url"] . "/" . rawurlencode($result);
$i++;
}