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