Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.7 KiB

  1. <?php
  2. namespace Friendica\Module;
  3. use DOMDocument;
  4. use DOMElement;
  5. use Friendica\BaseModule;
  6. use Friendica\DI;
  7. use Friendica\Util\XML;
  8. /**
  9. * Prints the opensearch description document
  10. * @see https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md#opensearch-description-document
  11. */
  12. class OpenSearch extends BaseModule
  13. {
  14. /**
  15. * @throws \Exception
  16. */
  17. public static function rawContent(array $parameters = [])
  18. {
  19. header('Content-type: application/opensearchdescription+xml');
  20. $hostname = DI::baseUrl()->getHostname();
  21. $baseUrl = DI::baseUrl()->get();
  22. /** @var DOMDocument $xml */
  23. $xml = null;
  24. XML::fromArray([
  25. 'OpenSearchDescription' => [
  26. '@attributes' => [
  27. 'xmlns' => 'http://a9.com/-/spec/opensearch/1.1',
  28. ],
  29. 'ShortName' => "Friendica $hostname",
  30. 'Description' => "Search in Friendica $hostname",
  31. 'Contact' => 'https://github.com/friendica/friendica/issues',
  32. ],
  33. ], $xml);
  34. /** @var DOMElement $parent */
  35. $parent = $xml->getElementsByTagName('OpenSearchDescription')[0];
  36. XML::addElement($xml, $parent, 'Image',
  37. "$baseUrl/images/friendica-16.png", [
  38. 'height' => 16,
  39. 'width' => 16,
  40. 'type' => 'image/png',
  41. ]);
  42. XML::addElement($xml, $parent, 'Image',
  43. "$baseUrl/images/friendica-64.png", [
  44. 'height' => 64,
  45. 'width' => 64,
  46. 'type' => 'image/png',
  47. ]);
  48. XML::addElement($xml, $parent, 'Url', '', [
  49. 'type' => 'text/html',
  50. 'template' => "$baseUrl/search?search={searchTerms}",
  51. ]);
  52. XML::addElement($xml, $parent, 'Url', '', [
  53. 'type' => 'application/opensearchdescription+xml',
  54. 'rel' => 'self',
  55. 'template' => "$baseUrl/opensearch",
  56. ]);
  57. echo $xml->saveXML();
  58. exit();
  59. }
  60. }