feat:explain the users query
This commit is contained in:
@ -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])
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user