diff options
author | RaindropsSys <raindrops@equestria.dev> | 2023-10-27 22:29:56 +0200 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2023-10-27 22:29:56 +0200 |
commit | 4d4308c46d4f7801c657cc79d2243e1a81831334 (patch) | |
tree | a2e392e0af92b9a3ca3d1b5afb841640276e2294 /app/ui/search.php | |
parent | 9f9d66afebc59c6c265c4424f7b8fb36d8876541 (diff) | |
download | mist-4d4308c46d4f7801c657cc79d2243e1a81831334.tar.gz mist-4d4308c46d4f7801c657cc79d2243e1a81831334.tar.bz2 mist-4d4308c46d4f7801c657cc79d2243e1a81831334.zip |
Updated 32 files, added 279 files, deleted 3 files and renamed 14 files (automated)
Diffstat (limited to 'app/ui/search.php')
-rw-r--r-- | app/ui/search.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/app/ui/search.php b/app/ui/search.php new file mode 100644 index 0000000..7d9fbba --- /dev/null +++ b/app/ui/search.php @@ -0,0 +1,91 @@ +<?php header("X-Frame-Options: SAMEORIGIN"); 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> + <script> + if (typeof window.parent.openModal === "undefined") { + location.href = "/app/#/explore"; + } + </script> + <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/js/shortcuts.js"></script> + <link id="native-css" href="/assets/native.css" rel="stylesheet" disabled> +</head> +<body class="crossplatform"> + <script src="/assets/js/common.js"></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 |