From 8762d68466b825382f4708a0eebbd3074e32c5c5 Mon Sep 17 00:00:00 2001 From: cynic Date: Wed, 13 Sep 2023 22:24:02 -0500 Subject: add structure for `Oracles' (special answers depending on queries + a few implementations (#10) incl. a calculator, a hash encoder + rot13 and b64!, and a "what time is it" with timezone selection frontend injected in $payload["left"] in web.php you can see this live [on my instance](https://4get.silly.computer/web?s=7%2B8(9%5E2)&scraper=brave&nsfw=yes) (there are some issues that aren't related to this PR. favicons, etc. I'll fix them later.) Reviewed-on: https://git.lolcat.ca/lolcat/4get/pulls/10 Co-authored-by: cynic Co-committed-by: cynic --- web.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'web.php') diff --git a/web.php b/web.php index 48539b9..e34672d 100644 --- a/web.php +++ b/web.php @@ -475,6 +475,35 @@ if($c !== 0){ $payload["left"] .= ''; } +/* + Prepend Oracle output, if applicable +*/ +include_once("oracles/encoder.php"); +include_once("oracles/calc.php"); +include_once("oracles/time.php"); +include_once("oracles/numerics.php"); +$oracles = [new calculator(), new encoder(), new time(), new numerics()]; +$fortune = ""; +foreach ($oracles as $oracle) { + if ($oracle->check_query($_GET["s"])) { + $resp = $oracle->generate_response($_GET["s"]); + if ($resp != "") { + $fortune .= "
"; + foreach ($resp as $title => $r) { + if ($title) { + $fortune .= "

".htmlspecialchars($title)."

".htmlspecialchars($r)."
"; + } + else { + $fortune .= "".$r."
"; + } + } + $fortune .= "Answer provided by oracle: ".$oracle->info["name"]."
"; + } + break; + } +} +$payload["left"] = $fortune . $payload["left"]; + /* Load next page */ -- cgit v1.2.3