]> git.mxchange.org Git - friendica.git/blob - src/Module/OpenSearch.php
Inverted condition
[friendica.git] / src / Module / OpenSearch.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module;
23
24 use DOMDocument;
25 use DOMElement;
26 use Friendica\BaseModule;
27 use Friendica\DI;
28 use Friendica\Util\XML;
29
30 /**
31  * Prints the opensearch description document
32  * @see https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md#opensearch-description-document
33  */
34 class OpenSearch extends BaseModule
35 {
36         /**
37          * @throws \Exception
38          */
39         public static function rawContent(array $parameters = [])
40         {
41                 header('Content-type: application/opensearchdescription+xml');
42
43                 $hostname = DI::baseUrl()->getHostname();
44                 $baseUrl  = DI::baseUrl()->get();
45
46                 /** @var DOMDocument $xml */
47                 $xml = null;
48
49                 XML::fromArray([
50                         'OpenSearchDescription' => [
51                                 '@attributes' => [
52                                         'xmlns' => 'http://a9.com/-/spec/opensearch/1.1',
53                                 ],
54                                 'ShortName'   => "Friendica $hostname",
55                                 'Description' => "Search in Friendica $hostname",
56                                 'Contact'     => 'https://github.com/friendica/friendica/issues',
57                         ],
58                 ], $xml);
59
60                 /** @var DOMElement $parent */
61                 $parent = $xml->getElementsByTagName('OpenSearchDescription')[0];
62
63                 XML::addElement($xml, $parent, 'Image',
64                         "$baseUrl/images/friendica-16.png", [
65                                 'height' => 16,
66                                 'width'  => 16,
67                                 'type'   => 'image/png',
68                         ]);
69
70                 XML::addElement($xml, $parent, 'Image',
71                         "$baseUrl/images/friendica-64.png", [
72                                 'height' => 64,
73                                 'width'  => 64,
74                                 'type'   => 'image/png',
75                         ]);
76
77                 XML::addElement($xml, $parent, 'Url', '', [
78                         'type'     => 'text/html',
79                         'template' => "$baseUrl/search?search={searchTerms}",
80                 ]);
81
82                 XML::addElement($xml, $parent, 'Url', '', [
83                         'type'     => 'application/opensearchdescription+xml',
84                         'rel'      => 'self',
85                         'template' => "$baseUrl/opensearch",
86                 ]);
87
88                 echo $xml->saveXML();
89
90                 exit();
91         }
92 }