opensearch.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. header("Content-Type: application/xml");
  3. include "data/config.php";
  4. $domain =
  5. htmlspecialchars(
  6. (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on" ? "https" : "http") .
  7. '://' . $_SERVER["HTTP_HOST"]
  8. );
  9. if(
  10. preg_match(
  11. '/\.onion$/',
  12. $domain
  13. )
  14. ){
  15. $onion = true;
  16. }else{
  17. $onion = false;
  18. }
  19. echo
  20. '<?xml version="1.0" encoding="UTF-8"?>' .
  21. '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">' .
  22. '<ShortName>' . htmlspecialchars(config::SERVER_NAME) . ($onion ? " (onion)" : "") . '</ShortName>' .
  23. '<InputEncoding>UTF-8</InputEncoding>' .
  24. '<Image width="16" height="16">' . $domain . '/favicon.ico</Image>' .
  25. '<Url type="text/html" method="GET" template="' . $domain . '/web?s={searchTerms}"/>';
  26. if(
  27. isset($_GET["ac"]) &&
  28. is_string($_GET["ac"]) &&
  29. $_GET["ac"] != "disabled"
  30. ){
  31. echo '<Url rel="suggestions" type="application/x-suggestions+json" template="' . $domain . '/api/v1/ac?s={searchTerms}&amp;scraper=' . htmlspecialchars($_GET["ac"]) . '"/>';
  32. }
  33. echo '</OpenSearchDescription>';