Compare commits
10 Commits
20a1eb4174
...
1.0
Author | SHA1 | Date | |
---|---|---|---|
ede8620428 | |||
c33a109f48 | |||
0109509996 | |||
3274ca1700 | |||
ef04bbb568 | |||
0796c59f92 | |||
64b3371ac2 | |||
b374423342 | |||
39dd311cee | |||
404bd217ac |
@ -99,7 +99,7 @@ class proxy {
|
|||||||
$curl,
|
$curl,
|
||||||
CURLOPT_HTTPHEADER,
|
CURLOPT_HTTPHEADER,
|
||||||
[
|
[
|
||||||
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0",
|
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/120.0",
|
||||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
||||||
"Accept-Language: en-US,en;q=0.5",
|
"Accept-Language: en-US,en;q=0.5",
|
||||||
"Accept-Encoding: gzip, deflate",
|
"Accept-Encoding: gzip, deflate",
|
||||||
@ -119,7 +119,7 @@ class proxy {
|
|||||||
$curl,
|
$curl,
|
||||||
CURLOPT_HTTPHEADER,
|
CURLOPT_HTTPHEADER,
|
||||||
[
|
[
|
||||||
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0",
|
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/120.0",
|
||||||
"Accept: image/avif,image/webp,*/*",
|
"Accept: image/avif,image/webp,*/*",
|
||||||
"Accept-Language: en-US,en;q=0.5",
|
"Accept-Language: en-US,en;q=0.5",
|
||||||
"Accept-Encoding: gzip, deflate",
|
"Accept-Encoding: gzip, deflate",
|
||||||
@ -242,7 +242,7 @@ class proxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt( $curl, CURLOPT_HTTPHEADER, [
|
curl_setopt( $curl, CURLOPT_HTTPHEADER, [
|
||||||
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0",
|
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/120.0",
|
||||||
"Accept: image/avif,image/webp,*/*",
|
"Accept: image/avif,image/webp,*/*",
|
||||||
"Accept-Language: en-US,en;q=0.5",
|
"Accept-Language: en-US,en;q=0.5",
|
||||||
"Accept-Encoding: gzip, deflate, br",
|
"Accept-Encoding: gzip, deflate, br",
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
include_once('scrapers/wallhaven.php');
|
||||||
|
$config = require(__DIR__.'/../config.php');
|
||||||
|
|
||||||
function timesince($time) {
|
function timesince($time) {
|
||||||
$time = time() - $time;
|
$time = time() - $time;
|
||||||
$timeunits = [
|
$timeunits = [
|
||||||
@ -18,7 +21,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function humanfilesize($size, $unit="") {
|
function humanfilesize($size, $unit = "") {
|
||||||
if ((!$unit && $size >= 1 << 30) || $unit == "GB")
|
if ((!$unit && $size >= 1 << 30) || $unit == "GB")
|
||||||
return number_format($size / (1 << 30),2)."GB";
|
return number_format($size / (1 << 30),2)."GB";
|
||||||
if ((!$unit && $size >= 1 << 20) || $unit == "MB")
|
if ((!$unit && $size >= 1 << 20) || $unit == "MB")
|
||||||
@ -37,4 +40,24 @@
|
|||||||
return strtoupper($str);
|
return strtoupper($str);
|
||||||
return $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;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
17
query.php
17
query.php
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
include('scrapers/wallhaven.php');
|
include('scrapers/wallhaven.php');
|
||||||
include('style/header.php');
|
include('style/header.php');
|
||||||
|
include('misc/tools.php');
|
||||||
$config = require('config.php');
|
$config = require('config.php');
|
||||||
$_SERVER['REQUEST_URI'] = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
|
$_SERVER['REQUEST_URI'] = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
|
||||||
|
|
||||||
@ -21,6 +22,20 @@
|
|||||||
$_GET["page"] ? $page = $_GET["page"] : $page = 1;
|
$_GET["page"] ? $page = $_GET["page"] : $page = 1;
|
||||||
|
|
||||||
$res = getwallpapers("https://wallhaven.cc/api/v1/search?q=".$_GET["q"]."&purity=".$purity."&categories=".$categories."&page=".$page);
|
$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 */
|
/* display wallpapers */
|
||||||
printf("<div id='wallpapers'>\n");
|
printf("<div id='wallpapers'>\n");
|
||||||
if (!$res[0])
|
if (!$res[0])
|
||||||
@ -40,7 +55,7 @@
|
|||||||
if ($page > 1)
|
if ($page > 1)
|
||||||
printf("<a href='%s&page=1'><<</a> <a href='%s&page=%d'><</a> ",
|
printf("<a href='%s&page=1'><<</a> <a href='%s&page=%d'><</a> ",
|
||||||
$_SERVER['REQUEST_URI'], $_SERVER['REQUEST_URI'], $page - 1);
|
$_SERVER['REQUEST_URI'], $_SERVER['REQUEST_URI'], $page - 1);
|
||||||
for ($i = $page; $i <= ($res[1]["pages"] > $page + 10 ? $page + 10 : $res[1]["pages"]); $i++)
|
for ($i = $page; $i <= ($res[1]["pages"] > $page + 9 ? $page + 9 : $res[1]["pages"]); $i++)
|
||||||
printf("<a href='%s&page=%d'>%d</a> ", $_SERVER['REQUEST_URI'], $i, $i);
|
printf("<a href='%s&page=%d'>%d</a> ", $_SERVER['REQUEST_URI'], $i, $i);
|
||||||
if ($page != $res[1]["pages"])
|
if ($page != $res[1]["pages"])
|
||||||
printf("<a href='%s&page=%s'>></a> <a href='%s&page=%s'>>></a> ",
|
printf("<a href='%s&page=%s'>></a> <a href='%s&page=%s'>>></a> ",
|
||||||
|
@ -15,10 +15,13 @@
|
|||||||
if ($data)
|
if ($data)
|
||||||
$url = sprintf("%s?%s", $url, http_build_query($data));
|
$url = sprintf("%s?%s", $url, http_build_query($data));
|
||||||
}
|
}
|
||||||
|
curl_setopt($curl, CURLOPT_HEADER, "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/120.0");
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
|
||||||
$result = curl_exec($curl);
|
$result = curl_exec($curl);
|
||||||
|
if ($result == null)
|
||||||
|
printf("<p id='error'>Request to wallhaven.cc denied :(</p>\n");
|
||||||
|
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
@ -53,6 +56,21 @@
|
|||||||
return array($walls, $meta);
|
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) {
|
function getwallpaper($link) {
|
||||||
$decoded = json_decode(callapi("GET", $link), true);
|
$decoded = json_decode(callapi("GET", $link), true);
|
||||||
$wall = $decoded["data"];
|
$wall = $decoded["data"];
|
||||||
@ -92,6 +110,9 @@
|
|||||||
$wall["tags"][$key]["purity"] = $decoded["data"]["tags"][$key]["purity"];
|
$wall["tags"][$key]["purity"] = $decoded["data"]["tags"][$key]["purity"];
|
||||||
$wall["tags"][$key]["created_at"] = $decoded["data"]["tags"][$key]["created_at"];
|
$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;
|
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 {
|
#wallpapers {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
@ -194,9 +224,18 @@ h1, #header {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* wallpaper preview borders */
|
/* wallpaper preview borders */
|
||||||
#sfw { border: 3px solid var(--sfw-color-1); }
|
#sfw {
|
||||||
#sketchy { border: 3px solid var(--sketchy-color-1); }
|
border: 3px solid var(--sfw-color-1);
|
||||||
#nsfw { border: 3px solid var(--nsfw-color-1); }
|
background-color: var(--sfw-color-2);
|
||||||
|
}
|
||||||
|
#sketchy {
|
||||||
|
border: 3px solid var(--sketchy-color-1);
|
||||||
|
background-color: var(--sketchy-color-2);
|
||||||
|
}
|
||||||
|
#nsfw {
|
||||||
|
border: 3px solid var(--nsfw-color-1);
|
||||||
|
background-color: var(--nsfw-color-2);
|
||||||
|
}
|
||||||
|
|
||||||
/* search category buttons */
|
/* search category buttons */
|
||||||
input[type=checkbox] { display: none; }
|
input[type=checkbox] { display: none; }
|
||||||
|
Reference in New Issue
Block a user