aboutsummaryrefslogtreecommitdiff
path: root/_site/search
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-08-04 16:56:12 +0200
committerMinteck <nekostarfan@gmail.com>2021-08-04 16:56:12 +0200
commit896fa7c96856142f844d958b049d5432f511641c (patch)
treed8bbbe327939ade9bd13276c6b4c6105adf95323 /_site/search
parent7df2fb3f5ee0ac5bd89e127c86ad0c2d6de126d1 (diff)
downloadunchainedtech-896fa7c96856142f844d958b049d5432f511641c.tar.gz
unchainedtech-896fa7c96856142f844d958b049d5432f511641c.tar.bz2
unchainedtech-896fa7c96856142f844d958b049d5432f511641c.zip
v2.0
Diffstat (limited to '_site/search')
-rw-r--r--_site/search/index.php99
1 files changed, 99 insertions, 0 deletions
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 @@
+<?php
+
+if (isset($_GET['q']) && strpos($_GET['q'], "/") === false && strpos($_GET['q'], "&") === false && strpos($_GET['q'], ">") === 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"] = '<div class="card' . ($item["admin"] ? " card-admin" : "") . '">
+ <div class="card-body">
+ <p><span class="badge badge-secondary">' . $item["category"] . '</span></p>
+ <h2>' . $item["title"] . '</h2>
+ <p>' . $item["content"]["mini"] . '</p>
+ <a class="btn btn-primary" href="' . ($item["admin"] ? "/admin" : "") . '/article/' . $item["id"] . '">Read more</a>
+ </div>
+ <div class="card-footer">
+ <small class="text-muted">';
+
+ if ($item["admin"]) {
+ $list[$index]["content"] .= "<b>Unreleased</b>";
+ } else {
+ $dt = DateTime::createFromFormat('Ymd', $item["date"]);
+ $list[$index]["content"] .= $dt->format("M jS, Y");
+ }
+
+ $list[$index]["content"] .= ' · by ' . implode(" and ", $item["author"]) . '</small>
+ </div>
+ </div>';
+ $index++;
+ }
+ }
+}
+
+usort($list, function($a, $b) {
+ return strtoupper($a['matches']) <=> strtoupper($b['matches']);
+});
+$list = array_reverse($list);
+
+?>
+
+<div class="container" style="margin-top:30px;text-align: center;">
+ <h2>Results for « <?= $q ?> »</h2>
+ <p><?= count($list) ?> result<?= count($list) > 1 ? "s" : "" ?> found</p>
+</div>
+<div class="container">
+ <style>
+ @media (max-width: 800px) {
+ #results {
+ grid-template-columns: 1fr;
+ }
+ }
+ </style>
+ <div id="results" style="display: grid;grid-template-columns: 1fr 1fr 1fr;grid-gap: 20px;">
+ <?php foreach ($list as $item) {
+ echo($item["content"]);
+ } ?>
+ </div>
+</div>
+
+<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/dom/footer.php"; ?> \ No newline at end of file