diff options
author | Squibid <me@zacharyscheiman.com> | 2023-12-26 22:58:20 -0500 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2023-12-26 22:59:01 -0500 |
commit | 39dd311cee2255c6cc41d656007f395784e44d31 (patch) | |
tree | 8af4613eec2f7fcf8b0f67bf5c6791657a9ac6a4 | |
parent | 404bd217ac5fdad3e4e3c49657cbafacfa2742db (diff) | |
download | wallheaven-39dd311cee2255c6cc41d656007f395784e44d31.tar.gz wallheaven-39dd311cee2255c6cc41d656007f395784e44d31.tar.bz2 wallheaven-39dd311cee2255c6cc41d656007f395784e44d31.zip |
feat:explain the users querydev
Diffstat (limited to '')
-rw-r--r-- | misc/tools.php | 23 | ||||
-rw-r--r-- | query.php | 4 | ||||
-rw-r--r-- | scrapers/wallhaven.php | 18 | ||||
-rw-r--r-- | style/style.css | 30 |
4 files changed, 75 insertions, 0 deletions
diff --git a/misc/tools.php b/misc/tools.php index 9917be7..0dbb7b8 100644 --- a/misc/tools.php +++ b/misc/tools.php @@ -1,4 +1,7 @@ <?php + include_once('scrapers/wallhaven.php'); + $config = require(__DIR__.'/../config.php'); + function timesince($time) { $time = time() - $time; $timeunits = [ @@ -37,4 +40,24 @@ return strtoupper($str); return $str; } + + function humanquery($q, $nsfw = false) { + global $config; + if ($nsfw) + $apikey = $config["frontends"]["wallhaven"]["apikey"]; + else + $apikey = ""; + + if (preg_match("/id:[0-9+]/", $q)) { + $info = gettaginfo("https://wallhaven.cc/api/v1/tag/".preg_replace("/id:/", "", $q)); + $q = preg_replace("/id:[0-9]+/", $info["name"], $q); + } + if (preg_match("/like:([A-Za-z0-9]+)/", $q, $matches)) { + $id = preg_replace("/like:/", "", $matches[0]); + $wall = getwallpaper("https://wallhaven.cc/api/v1/w/$id?apikey=$apikey"); + $q = $q."<span id='triangle'></span><img src='/proxy.php?i=".$wall["thumbs"]["orig"]."'>"; + } + + return $q; + } ?> @@ -1,6 +1,7 @@ <?php include('scrapers/wallhaven.php'); include('style/header.php'); + include('misc/tools.php'); $config = require('config.php'); $_SERVER['REQUEST_URI'] = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; @@ -21,6 +22,9 @@ $_GET["page"] ? $page = $_GET["page"] : $page = 1; $res = getwallpapers("https://wallhaven.cc/api/v1/search?q=".$_GET["q"]."&purity=".$purity."&categories=".$categories."&page=".$page); + /* explain query */ + printf("<div id='queryinfo'><p>%s Wallpapers found for \"<a href='/query.php?q=%s'>%s</a>\"</p></div>", $res[1]["total"], $_GET["q"], humanquery($_GET["q"], $_GET["NSFW"] ? true : false)); + /* display wallpapers */ printf("<div id='wallpapers'>\n"); if (!$res[0]) diff --git a/scrapers/wallhaven.php b/scrapers/wallhaven.php index 5dbdd68..29df5d3 100644 --- a/scrapers/wallhaven.php +++ b/scrapers/wallhaven.php @@ -53,6 +53,21 @@ return array($walls, $meta); } + function gettaginfo($link) { + $decoded = json_decode(callapi("GET", $link), true); + $tag = []; + + foreach($decoded["data"] as $key => $value) { + $tag["id"] = $decoded["data"]["id"]; + $tag["name"] = $decoded["data"]["name"]; + $tag["alias"] = $decoded["data"]["alias"]; + $tag["category_id"] = $decoded["data"]["category_id"]; + $tag["purity"] = $decoded["data"]["purity"]; + $tag["created_at"] = $decoded["data"]["created_at"]; + } + return $tag; + } + function getwallpaper($link) { $decoded = json_decode(callapi("GET", $link), true); $wall = $decoded["data"]; @@ -92,6 +107,9 @@ $wall["tags"][$key]["purity"] = $decoded["data"]["tags"][$key]["purity"]; $wall["tags"][$key]["created_at"] = $decoded["data"]["tags"][$key]["created_at"]; } + $wall["thumbs"]["large"] = $decoded["data"]["thumbs"]["large"]; + $wall["thumbs"]["orig"] = $decoded["data"]["thumbs"]["original"]; + $wall["thumbs"]["small"] = $decoded["data"]["thumbs"]["small"]; } return $wall; } diff --git a/style/style.css b/style/style.css index a90ad2a..b039b56 100644 --- a/style/style.css +++ b/style/style.css @@ -85,6 +85,36 @@ h1, #header { } } +#queryinfo { + font-size: 25px; + width: 85%; + margin: 0 auto; + color: #fff; +} +#queryinfo p { margin: 0 auto; } +#queryinfo a { color: var(--user-color-1); } +#queryinfo img, #queryinfo span { display: none; } +#queryinfo a:hover img { + display: unset !important; + position: absolute; + border: 0.2em solid #fff; + margin-top: 1.2em; + margin-left: -12em; +} +#queryinfo a:hover span { + display: unset !important; + position: absolute; + margin-top: 1em; + margin-left: -5em; + + width: 0; + height: 0; + border-left: 5px solid transparent; + border-right: 5px solid transparent; + border-bottom: 5px solid #fff; + transform: scale(2); +} + #wallpapers { text-align: center; color: #fff; |