]> git.mxchange.org Git - friendica.git/blob - src/Module/OpenSearch.php
Merge pull request #11411 from annando/creation-date
[friendica.git] / src / Module / OpenSearch.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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\Core\System;
28 use Friendica\DI;
29 use Friendica\Util\XML;
30
31 /**
32  * Prints the opensearch description document
33  * @see https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md#opensearch-description-document
34  */
35 class OpenSearch extends BaseModule
36 {
37         /**
38          * @throws \Exception
39          */
40         protected function rawContent(array $request = [])
41         {
42                 $hostname = DI::baseUrl()->getHostname();
43                 $baseUrl  = DI::baseUrl()->get();
44
45                 /** @var DOMDocument $xml */
46                 $xml = null;
47
48                 XML::fromArray([
49                         'OpenSearchDescription' => [
50                                 '@attributes' => [
51                                         'xmlns' => 'http://a9.com/-/spec/opensearch/1.1',
52                                 ],
53                                 'ShortName'   => "Friendica $hostname",
54                                 'Description' => "Search in Friendica $hostname",
55                                 'Contact'     => 'https://github.com/friendica/friendica/issues',
56                         ],
57                 ], $xml);
58
59                 /** @var DOMElement $parent */
60                 $parent = $xml->getElementsByTagName('OpenSearchDescription')[0];
61
62                 XML::addElement($xml, $parent, 'Image',
63                         "$baseUrl/images/friendica-16.png", [
64                                 'height' => 16,
65                                 'width'  => 16,
66                                 'type'   => 'image/png',
67                         ]);
68
69                 XML::addElement($xml, $parent, 'Image',
70                         "$baseUrl/images/friendica-64.png", [
71                                 'height' => 64,
72                                 'width'  => 64,
73                                 'type'   => 'image/png',
74                         ]);
75
76                 XML::addElement($xml, $parent, 'Url', '', [
77                         'type'     => 'text/html',
78                         'template' => "$baseUrl/search?search={searchTerms}",
79                 ]);
80
81                 XML::addElement($xml, $parent, 'Url', '', [
82                         'type'     => 'application/opensearchdescription+xml',
83                         'rel'      => 'self',
84                         'template' => "$baseUrl/opensearch",
85                 ]);
86
87                 System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');
88         }
89 }