3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module;
26 use Friendica\BaseModule;
27 use Friendica\Core\System;
29 use Friendica\Util\XML;
32 * Prints the opensearch description document
33 * @see https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md#opensearch-description-document
35 class OpenSearch extends BaseModule
40 protected function rawContent(array $request = [])
42 $hostname = DI::baseUrl()->getHost();
43 $baseUrl = (string)DI::baseUrl();
45 /** @var DOMDocument $xml */
47 'OpenSearchDescription' => [
49 'xmlns' => 'http://a9.com/-/spec/opensearch/1.1',
51 'ShortName' => "Friendica $hostname",
52 'Description' => "Search in Friendica $hostname",
53 'Contact' => 'https://github.com/friendica/friendica/issues',
54 'InputEncoding' => 'UTF-8',
55 'OutputEncoding' => 'UTF-8',
56 'Developer' => 'Friendica Developer Team',
60 /** @var DOMElement $parent */
61 $parent = $xml->getElementsByTagName('OpenSearchDescription')[0];
63 XML::addElement($xml, $parent, 'Image',
64 "$baseUrl/images/friendica-16.png", [
67 'type' => 'image/png',
70 XML::addElement($xml, $parent, 'Image',
71 "$baseUrl/images/friendica-64.png", [
74 'type' => 'image/png',
77 XML::addElement($xml, $parent, 'Url', '', [
78 'type' => 'text/html',
79 'template' => "$baseUrl/search?search={searchTerms}",
82 XML::addElement($xml, $parent, 'Url', '', [
83 'type' => 'application/opensearchdescription+xml',
85 'template' => "$baseUrl/opensearch",
88 System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');