base.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. abstract class oracle {
  3. // some info to spit out alongside the result, so the user knows
  4. // what exactly is giving out the answer. prevents confusion
  5. // about what oracle is answering them for ambiguous queries.
  6. public $info = [
  7. "name" => "some oracle"
  8. ];
  9. // this function should take in a query string search from $_GET,
  10. // and return a bool determining whether or not it is a question
  11. // intended for the oracle.
  12. public function check_query($q) {
  13. return false;
  14. }
  15. // produce the correct answer for the query using the oracle.
  16. // note: if it becomes apparent /during generation/ that the
  17. // query is not in fact for the oracle, returning an empty
  18. // string will kill the oracle pane.
  19. // answer format: ["ans1 title" => "ans1", ...]
  20. public function generate_response($q) {
  21. return "";
  22. }
  23. }
  24. // backwards compatibility
  25. if (!function_exists('str_starts_with')) {
  26. function str_starts_with($haystack, $needle) {
  27. return strncmp($haystack, $needle, strlen($needle)) === 0;;
  28. }
  29. }
  30. if (!function_exists('str_contains')) {
  31. function str_contains($haystack, $needle) {
  32. return strpos((string)$haystack, (string)$needle) !== false;
  33. }
  34. }
  35. ?>