summaryrefslogtreecommitdiff
path: root/app/search.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/search.php')
-rw-r--r--app/search.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/app/search.php b/app/search.php
new file mode 100644
index 0000000..2f5f164
--- /dev/null
+++ b/app/search.php
@@ -0,0 +1,91 @@
+<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php";
+
+if (!isset($_GET["q"]) || trim($_GET["q"]) === "" || trim(preg_replace("/ +/m", " ", preg_replace("/[^a-z\d ]/m", " ", strtolower($_GET["q"])))) === "") {
+ header("Location: explore.php");
+ die();
+}
+
+?>
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport"
+ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
+ <title>search</title>
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
+ <link href="/assets/dark.css" rel="stylesheet">
+ <link href="/assets/styles.css" rel="stylesheet">
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
+ <script src="/assets/localforage.min.js"></script>
+ <script src="/assets/fuse.min.js"></script>
+ <script src="/assets/shortcuts.js"></script>
+ <link id="native-css" href="/assets/native.css" rel="stylesheet" disabled>
+</head>
+<body class="crossplatform">
+ <script>
+ if (navigator.userAgent.includes("MistNative/darwin") || navigator.userAgent.includes("MistNative/win32")) {
+ document.getElementById("native-css").disabled = false;
+ document.body.classList.remove("crossplatform");
+ }
+ </script>
+ <div class="container">
+ <br>
+ <h2 style="margin-top: 10px; margin-bottom: 20px; margin-left: 10px;">Search results for "<?= strip_tags($_GET["q"]) ?>"</h2>
+ <?php
+
+ global $albums; global $songs;
+
+ function getMatches($item) {
+ $n = 0;
+ $query = preg_replace("/ +/m", " ", preg_replace("/[^a-z\d ]/m", " ", strtolower($_GET["q"])));
+
+ if (isset($item["title"]) && str_contains(preg_replace("/ +/m", " ", preg_replace("/[^a-z\d ]/m", " ", strtolower($item["title"]))), $query)) $n++;
+ if (isset($item["artist"]) && str_contains(preg_replace("/ +/m", " ", preg_replace("/[^a-z\d ]/m", " ", strtolower($item["artist"]))), $query)) $n++;
+ if (isset($item["album"]) && str_contains(preg_replace("/ +/m", " ", preg_replace("/[^a-z\d ]/m", " ", strtolower($item["album"]))), $query)) $n++;
+
+ return $n;
+ }
+
+ $albums = array_filter($albums, function ($i) {
+ return getMatches($i) > 0;
+ });
+
+ uasort($albums, function ($a, $b) {
+ return strcmp($a["title"], $b["title"]);
+ });
+
+ uasort($albums, function ($a, $b) {
+ return strcmp($a["artist"], $b["artist"]);
+ });
+
+ uasort($albums, function ($a, $b) {
+ return getMatches($b) - getMatches($a);
+ });
+
+ $songs = array_filter($songs, function ($i) {
+ return getMatches($i) > 0;
+ });
+
+ uasort($songs, function ($a, $b) {
+ return getMatches($b) - getMatches($a);
+ });
+
+ ?>
+
+ <div id="album-grid" style="display: grid; grid-template-columns: repeat(5, 1fr);">
+ <?php foreach ($albums as $id => $album): ?>
+ <a id="album-<?= $id ?>" data-item-track="<?= $album["title"] ?>" data-item-artist="<?= $album["artist"] ?>" href="listing.php?a=<?= $id ?>" style="padding: 10px; color: inherit; text-decoration: inherit;" class="album">
+ <img class="album-list-art" alt="" src="/assets/content/<?= $id ?>.jpg" style="width: 100%; aspect-ratio: 1; border-radius: 5px; margin-bottom: 5px;">
+ <div class="album-list-item" style="max-width: calc(80vw / 5); white-space: nowrap; overflow: hidden !important; text-overflow: ellipsis;"><?= $album["title"] ?></div>
+ <div class="album-list-item" style="max-width: calc(80vw / 5); opacity: .5; white-space: nowrap; overflow: hidden !important; text-overflow: ellipsis;"><?= $album["artist"] ?></div>
+ </a>
+ <?php endforeach; ?>
+ </div>
+ <?php global $songs; displayList($songs); ?>
+ </div>
+
+ <br><br>
+</body>
+</html> \ No newline at end of file