From 9f13ae6e735625360b762a3f749276d041989573 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 18 May 2019 17:43:58 +0200 Subject: [PATCH] Move mod/opensearch to src/Module/OpenSearch --- mod/opensearch.php | 19 --------- src/App/Router.php | 1 + src/Module/OpenSearch.php | 72 +++++++++++++++++++++++++++++++++++ view/templates/opensearch.tpl | 14 ------- 4 files changed, 73 insertions(+), 33 deletions(-) delete mode 100644 mod/opensearch.php create mode 100644 src/Module/OpenSearch.php delete mode 100644 view/templates/opensearch.tpl diff --git a/mod/opensearch.php b/mod/opensearch.php deleted file mode 100644 index 0744157e5..000000000 --- a/mod/opensearch.php +++ /dev/null @@ -1,19 +0,0 @@ - $a->getHostName(), - ]); - - echo $o; - - exit(); -} diff --git a/src/App/Router.php b/src/App/Router.php index cd59c3dd9..e37565b79 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -172,6 +172,7 @@ class Router }); $this->routeCollector->addRoute(['GET'], '/outbox/{owner}', Module\Outbox::class); $this->routeCollector->addRoute(['GET'], '/owa', Module\Owa::class); + $this->routeCollector->addRoute(['GET'], '/opensearch', Module\OpenSearch::class); $this->routeCollector->addGroup('/photo', function (RouteCollector $collector) { $collector->addRoute(['GET'], '/{name}', Module\Photo::class); $collector->addRoute(['GET'], '/{type}/{name}', Module\Photo::class); diff --git a/src/Module/OpenSearch.php b/src/Module/OpenSearch.php new file mode 100644 index 000000000..ff005bd56 --- /dev/null +++ b/src/Module/OpenSearch.php @@ -0,0 +1,72 @@ +getHostName(); + $baseUrl = self::getApp()->getBaseURL(); + + /** @var DOMDocument $xml */ + $xml = null; + + XML::fromArray([ + 'OpenSearchDescription' => [ + '@attributes' => [ + 'xmlns' => 'http://a9.com/-/spec/opensearch/1.1', + ], + 'ShortName' => "Friendica $hostname", + 'Description' => "Search in Friendica $hostname", + 'Contact' => 'https://github.com/friendica/friendica/issues', + ], + ], $xml); + + /** @var DOMElement $parent */ + $parent = $xml->getElementsByTagName('OpenSearchDescription')[0]; + + XML::addElement($xml, $parent, 'Image', + "$baseUrl/images/friendica-16.png", [ + 'height' => 16, + 'width' => 16, + 'type' => 'image/png', + ]); + + XML::addElement($xml, $parent, 'Image', + "$baseUrl/images/friendica-64.png", [ + 'height' => 64, + 'width' => 64, + 'type' => 'image/png', + ]); + + XML::addElement($xml, $parent, 'Url', '', [ + 'type' => 'text/html', + 'template' => "$baseUrl/search?search={searchTerms}", + ]); + + XML::addElement($xml, $parent, 'Url', '', [ + 'type' => 'application/opensearchdescription+xml', + 'rel' => 'self', + 'template' => "$baseUrl/opensearch", + ]); + + echo $xml->saveXML(); + + exit(); + } +} diff --git a/view/templates/opensearch.tpl b/view/templates/opensearch.tpl deleted file mode 100644 index 6efee25e7..000000000 --- a/view/templates/opensearch.tpl +++ /dev/null @@ -1,14 +0,0 @@ - - - - Friendica@{{$nodename}} - Search in Friendica@{{$nodename}} - http://bugs.friendica.com/ - {{$baseurl}}/images/friendica-16.png - {{$baseurl}}/images/friendica-64.png - - - \ No newline at end of file