diff options
-rw-r--r-- | misc/tools.php | 23 | ||||
-rw-r--r-- | query.php | 15 | ||||
-rw-r--r-- | scrapers/wallhaven.php | 18 | ||||
-rw-r--r-- | style/style.css | 30 |
4 files changed, 86 insertions, 0 deletions
diff --git a/misc/tools.php b/misc/tools.php index 602722e..0fec976 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,20 @@ $_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 */ + /* HACK: really disgusting code might make it better but for now it works */ + printf("<div id='queryinfo'>"); + $humanreadable = humanquery($_GET["q"], $_GET["NSFW"] ? true : false); + if (!$_GET["q"]) + printf("<p>%s Wallpapers found", $res[1]["total"]); + else { + if (preg_match("/like:/", $_GET["q"])) + printf("<p>%s Wallpapers found \"<a href='/query.php?q=%s'>%s</a>\"</p>", $res[1]["total"], $_GET["q"], $humanreadable); + else + printf("<p>%s Wallpapers found for \"<a href='/query.php?q=%s'>%s</a>\"</p>", $res[1]["total"], $_GET["q"], $humanreadable); + } + printf("</div>"); + /* display wallpapers */ printf("<div id='wallpapers'>\n"); if (!$res[0]) diff --git a/scrapers/wallhaven.php b/scrapers/wallhaven.php index 56b44c7..ea03d25 100644 --- a/scrapers/wallhaven.php +++ b/scrapers/wallhaven.php @@ -56,6 +56,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"]; @@ -95,6 +110,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 1857e0e..a728c18 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; |