aboutsummaryrefslogtreecommitdiffstats
path: root/query.php
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2023-09-22 18:08:37 -0400
committerSquibid <me@zacharyscheiman.com>2023-09-22 18:08:37 -0400
commit472092fe43ad7da9feb4a8c0b4bf216b20c063b9 (patch)
tree6200ad064861b167684483c38e7db9ad05519e7e /query.php
downloadwallheaven-472092fe43ad7da9feb4a8c0b4bf216b20c063b9.tar.gz
wallheaven-472092fe43ad7da9feb4a8c0b4bf216b20c063b9.tar.bz2
wallheaven-472092fe43ad7da9feb4a8c0b4bf216b20c063b9.zip
inital commit
Diffstat (limited to 'query.php')
-rw-r--r--query.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/query.php b/query.php
new file mode 100644
index 0000000..1b7b7c1
--- /dev/null
+++ b/query.php
@@ -0,0 +1,52 @@
+<?php
+ include('scrapers/wallhaven.php');
+ include('style/header.php');
+ $config = require('config.php');
+ $_SERVER['REQUEST_URI'] = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
+
+ /* fix spaces in query */
+ $_GET["q"] = preg_replace("/ /", "+", $_GET["q"]);
+
+ /* parse paramaters */
+ $_GET["SFW"] ? $purity = "1" : $purity = "0";
+ $_GET["Sketchy"] ? $purity .= "1" : $purity .= "0";
+ if ($_GET["NSFW"])
+ /* HACK: to only use the api key when needed we inject it here */
+ $purity .= "1&apikey=".$config["frontends"]["wallhaven"]["apikey"];
+ else
+ $purity .= "0";
+ $_GET["General"] ? $categories = "1" : $categories = "0";
+ $_GET["Anime"] ? $categories .= "1" : $categories .= "0";
+ $_GET["People"] ? $categories .= "1" : $categories .= "0";
+ $_GET["page"] ? $page = $_GET["page"] : $page = 1;
+
+ $res = getwallpapers("https://wallhaven.cc/api/v1/search?q=".$_GET["q"]."&purity=".$purity."&categories=".$categories."&page=".$page);
+ /* display wallpapers */
+ printf("<div id='wallpapers'>\n");
+ if (!$res[0])
+ printf("No Results Found :(");
+ else
+ foreach($res[0] as $walls) {
+ printf("<form action='/view.php' method='POST'>\n");
+ printf("<input type='hidden' name='purity' value='%s'/>\n", $walls["purity"]);
+ printf("<button name=wall value='%s' data-value='%s'><img id='%s' width=307 height=206 src=/proxy.php?i=%s></button>\n", $walls["path"], $walls["purity"], $walls["purity"], $walls["thumbs"]["small"]);
+ printf("</form>\n");
+ }
+ printf("</div>\n");
+
+ /* page numbers */
+ if (!$res || $res[1]["pages"] == 0 || !$res[0][0])
+ return;
+
+ printf("<br>\n<div id='footer'>\n");
+ if ($page > 1)
+ printf("<a href='%s&page=1'><<</a> <a href='%s&page=%d'><</a> ",
+ $_SERVER['REQUEST_URI'], $_SERVER['REQUEST_URI'], $page - 1);
+ for ($i = $page; $i <= ($res[1]["pages"] > $page + 10 ? $page + 10 : $res[1]["pages"]); $i++)
+ printf("<a href='%s&page=%d'>%d</a> ", $_SERVER['REQUEST_URI'], $i, $i);
+ if ($page != $res[1]["pages"])
+ printf("<a href='%s&page=%d'>></a> <a href='%s&page=%d'>>></a> ",
+ $_SERVER['REQUEST_URI'], $page + 1, $_SERVER['REQUEST_URI'],
+ $res[1]["pages"]);
+ printf("</div>\n<br><br>\n");
+?>