diff options
author | Minteck <contact@minteck.org> | 2022-11-20 22:42:48 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-11-20 22:42:48 +0100 |
commit | 086a11930704b68cf351c6027900a523f5fe7bd5 (patch) | |
tree | f410cde759dafd643f0079d470b3dbfa4a03b67f /search | |
parent | 6a7415b0db02872f49a3cbe03fa1d5e69ca2c03c (diff) | |
download | horses-086a11930704b68cf351c6027900a523f5fe7bd5.tar.gz horses-086a11930704b68cf351c6027900a523f5fe7bd5.tar.bz2 horses-086a11930704b68cf351c6027900a523f5fe7bd5.zip |
First commit, probably
Diffstat (limited to 'search')
-rw-r--r-- | search/index.php | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/search/index.php b/search/index.php new file mode 100644 index 0000000..f4199a0 --- /dev/null +++ b/search/index.php @@ -0,0 +1,119 @@ +<?php + +if (isset($_GET['q'])) { + if (trim($_GET['q']) === "") { + header("Location: /search"); + die(); + } else { + $query = preg_replace("/ +/m", " ", preg_replace("/[^0-9_\-.?=+()a-zA-Z\$€*\[\]&@ ;,]/m", " ", trim($_GET['q']))); + $title = $query . " | Search"; + } +} else { + $query = null; + $title = "Search"; +} + +require $_SERVER['DOCUMENT_ROOT'] . "/includes/main.php"; require $_SERVER['DOCUMENT_ROOT'] . "/includes/header.php"; ?> + +<div class="container"> + <br> + <form action="" style="margin-bottom: 20px;"> + <div style="display: grid; grid-template-columns: 1fr 32px; grid-gap: 10px;"> + <input type="text" name="q" autocomplete="off" value="<?= $query ?>" style="outline: none;color: white;background: transparent;border: none;border-bottom: 1px solid rgba(255, 255, 255, .25); width: 100%;" placeholder="Search across our websites..."> + <button type="submit" id="search-submit" style="border: 1px solid rgba(255, 255, 255, .25); background: transparent; border-radius: 100%; width: 32px; height: 32px; vertical-align: middle; padding: 4px;"> + <img src="/assets/icons/search.svg" alt="Search" style="display: inline-block; width: 24px; height: 24px; vertical-align: middle; position: relative; pointer-events: none; top: -2px;"> + </button> + </div> + </form> + + <?php if (isset($query)): ?> + <?php + + $searchSource = "local"; + + $out = []; + chdir($_SERVER['DOCUMENT_ROOT'] . "/includes/search/search"); + + $start = microtime(true); + exec("node search.js \"" . $searchSource . "\" \"" . $query . "\"", $out); + $end = microtime(true); + + $total = $end - $start; + + $data = json_decode(implode("\n", $out), true); + + ?> + + <?php if (is_array($data)): ?> + <?php if (count($data["results"]) > 0): ?> + <p class="muted"><?= count($data["results"]) ?> results (<?= round($total, 2) ?> seconds)</p> + <div style="display: grid; grid-template-columns: 1.5fr 1fr; grid-gap: 20px;"> + <div id="results"> + <?php foreach ($data["results"] as $result): $id = md5($result["url"]); ?> + <a class="result-anchor" id="result-<?= $id ?>-anchor" href="<?= strip_tags($result["url"]) ?>"><div class="result" id="result-<?= $id ?>" style="border: 1px solid transparent; background: rgba(0, 0, 0, .1); margin-bottom: 10px; border-radius: 10px; padding: 10px 15px;"> + <div class="result-title" style="font-weight: bold; margin-bottom: 2px;" id="result-<?= $id ?>-title"><?= strip_tags($result["title"]) ?></div> + <div class="result-details" id="result-<?= $id ?>-details" style="font-size: smaller; margin-bottom: 2px;"> + <img src="<?= $result["icon"] ?>" style="width: 16px; height: 16px; vertical-align: middle; margin-right: 2px;"> + <span style="vertical-align: middle;"><?= strip_tags($result["link"]) ?></span> + </div> + <div class="result-snippet text-muted" id="result-<?= $id ?>-snippet"><?= preg_replace("/\[(.*)]/m", "<b>$1</b>", strip_tags($result["snippet"])) ?></div> + <?php if ($result["official"] === 2): ?> + <div class="official official-web text-info" style="margin-top: 2px; font-size: smaller; opacity: .75;">This result is for an official website.</div> + <?php elseif ($result["official"] === 1 && $searchSource !== "local"): ?> + <div class="official official-eqd text-warning" style="margin-top: 2px; font-size: smaller; opacity: .75;">This result is for an Equestria.dev official resource.</div> + <?php endif; ?> + </div></a> + <?php endforeach; ?> + </div> + </div> + <hr> + <pre><?php var_dump($data); ?></pre> + <?php else: ?> + <p class="muted"> + Sorry, no results corresponding to your query has been found. Please try another query. + </p> + <?php endif; ?> + <?php else: ?> + <p class="muted"> + Sorry, something went wrong while trying to process your query, Izzy probably put too much glitter! Please try again later.<br>Response ID: <?= strtoupper(substr(sha1(implode("\n", $out)), 0, 8)) . "/" . strtoupper(substr(md5(implode("\n", $out)), 0, 8)) ?> + </p> + <?php endif; ?> + + <?php else: ?> + <p>Search</p> + <?php endif; ?> +</div> + +<style> + #search-submit:hover { + background-color: rgba(255, 255, 255, .1) !important; + } + + #search-submit:active, #search-submit:focus { + background-color: rgba(255, 255, 255, .25) !important; + border: 1px solid rgba(255, 255, 255, .5) !important; + } + + a.result-anchor { + text-decoration: none; + color: white; + } + + .result { + pointer-events: none; + } + + a.result-anchor:hover .result { + border: 1px solid rgba(255, 255, 255, .05) !important; + background-color: rgba(0, 0, 0, .05) !important; + } + + a.result-anchor:active .result, a.result-anchor:focus .result { + border: 1px solid rgba(255, 255, 255, .1) !important; + background-color: rgba(0, 0, 0, .1) !important; + } +</style> + +<!-- /[^0-9_\-.?=+()a-zA-Z$€*\[\]&@ ;,]/gm --> + +<?php require $_SERVER['DOCUMENT_ROOT'] . "/includes/footer.php"; ?>
\ No newline at end of file |