1
0

opensearch.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. header("Content-Type: application/xml");
  3. include "data/config.php";
  4. $host = strtolower(explode(":", $_SERVER["HTTP_HOST"], 2)[0]);
  5. // detect if 4get should serve the HTTPS endpoint
  6. if(
  7. preg_match(
  8. '/\.(onion|i2p)$/',
  9. strtolower($host),
  10. $match
  11. )
  12. ){
  13. $ssl = false;
  14. $src = $match[1];
  15. }elseif(
  16. is_string(
  17. filter_var(
  18. $host,
  19. FILTER_VALIDATE_IP
  20. )
  21. ) ||
  22. $host == "localhost"
  23. ){
  24. $ssl = false;
  25. $src = "localhost";
  26. }else{
  27. $ssl = true;
  28. }
  29. $domain = ($ssl ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"];
  30. echo
  31. '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">' .
  32. '<ShortName>' . htmlspecialchars(config::SERVER_NAME) . ($ssl === false ? " ({$src})" : "") . '</ShortName>' .
  33. '<Description>' . htmlspecialchars(config::SERVER_SHORT_DESCRIPTION) . '</Description>' .
  34. '<InputEncoding>UTF-8</InputEncoding>' .
  35. '<Image width="32" height="32" type="image/x-icon">' . htmlspecialchars($domain) . '/favicon.ico</Image>' .
  36. '<Url rel="results" type="text/html" method="GET" template="' . htmlspecialchars($domain) . '/web?s={searchTerms}"/>';
  37. if(
  38. isset($_GET["ac"]) &&
  39. is_string($_GET["ac"]) &&
  40. $_GET["ac"] != "disabled"
  41. ){
  42. echo '<Url rel="suggestions" type="application/x-suggestions+json" template="' . $domain . '/api/v1/ac?s={searchTerms}&amp;scraper=' . htmlspecialchars($_GET["ac"]) . '"/>';
  43. }
  44. echo '</OpenSearchDescription>';