Merge branch 'dev'

This commit is contained in:
2023-12-27 14:50:22 -05:00
4 changed files with 86 additions and 0 deletions

View File

@ -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;
}
?>

View File

@ -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])

View File

@ -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;
}

View File

@ -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;