From 896fa7c96856142f844d958b049d5432f511641c Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 4 Aug 2021 16:56:12 +0200 Subject: v2.0 --- _site/search/index.php | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 _site/search/index.php (limited to '_site/search/index.php') diff --git a/_site/search/index.php b/_site/search/index.php new file mode 100644 index 0000000..09ad5c0 --- /dev/null +++ b/_site/search/index.php @@ -0,0 +1,99 @@ +") === false && strpos($_GET['q'], ">") === false) { + $q = $_GET['q']; +} else { + header("Location: /"); + die(); +} + +$_TITLE = "Search Results"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/dom/header.php"; + +$orig = getArticlesList(); +$list = []; + +$words = explode(' ', $q); +$index = 0; + +foreach ($words as $word) { + if (!ctype_alnum($word)) { + header("Location: /"); + die(); + } +} + +foreach ($orig as $article) { + if (!$article["admin"]) { + $item = $article; + $add = false; + $matches = 0; + + foreach ($words as $word) { + if (substr_count(strtolower($article["title"]), strtolower($word)) > 0) $add = true; + if (substr_count(strtolower($article["title"]), strtolower($word)) > 0) $matches += substr_count(strtolower($article["title"]), strtolower($word)); + foreach ($article["author"] as $author) { + if (substr_count(strtolower($author), strtolower($word)) > 0) $add = true; + if (substr_count(strtolower($author), strtolower($word)) > 0) $matches += substr_count(strtolower($author), strtolower($word)); + } + if (substr_count(strtolower($article["category"]), strtolower($word)) > 0) $add = true; + if (substr_count(strtolower($article["category"]), strtolower($word)) > 0) $matches += substr_count(strtolower($article["category"]), strtolower($word)); + if (substr_count(strtolower($article["content"]["clean"]), strtolower($word)) > 0) $add = true; + if (substr_count(strtolower($article["content"]["clean"]), strtolower($word)) > 0) $matches += substr_count(strtolower($article["content"]["clean"]), strtolower($word)); + if (substr_count(strtolower($article["date"]), strtolower($word)) > 0) $add = true; + if (substr_count(strtolower($article["date"]), strtolower($word)) > 0) $matches += substr_count(strtolower($article["date"]), strtolower($word)); + } + + if ($add) { + $list[$index]["matches"] = $matches; + $list[$index]["content"] = '
+
+

' . $item["category"] . '

+

' . $item["title"] . '

+

' . $item["content"]["mini"] . '

+ Read more +
+ +
'; + $index++; + } + } +} + +usort($list, function($a, $b) { + return strtoupper($a['matches']) <=> strtoupper($b['matches']); +}); +$list = array_reverse($list); + +?> + +
+

Results for « »

+

result 1 ? "s" : "" ?> found

+
+
+ +
+ +
+
+ + \ No newline at end of file -- cgit