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