mirror of
https://github.com/friendica/friendica
synced 2025-04-25 07:50:10 +00:00
Issue 14524: Fix Open Search
This commit is contained in:
parent
e0290d22ec
commit
b276b89777
2 changed files with 176 additions and 139 deletions
|
@ -9,10 +9,14 @@ namespace Friendica\Module;
|
|||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Util\BasePath;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\XML;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Prints the opensearch description document
|
||||
|
@ -20,22 +24,37 @@ use Friendica\Util\XML;
|
|||
*/
|
||||
class OpenSearch extends BaseModule
|
||||
{
|
||||
/** @var IManageConfigValues */
|
||||
private $config;
|
||||
|
||||
/** @var App\baseUrl */
|
||||
protected $baseUrl;
|
||||
|
||||
/** @var string */
|
||||
private $basePath;
|
||||
|
||||
public function __construct(BasePath $basePath, IManageConfigValues $config, L10n $l10n, App\baseUrl $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->config = $config;
|
||||
$this->basePath = $basePath->getPath();
|
||||
$this->baseUrl = $baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
$hostname = DI::baseUrl()->getHost();
|
||||
$baseUrl = (string)DI::baseUrl();
|
||||
|
||||
/** @var DOMDocument $xml */
|
||||
XML::fromArray([
|
||||
'OpenSearchDescription' => [
|
||||
'@attributes' => [
|
||||
'xmlns' => 'http://a9.com/-/spec/opensearch/1.1',
|
||||
'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/',
|
||||
],
|
||||
'ShortName' => "Friendica $hostname",
|
||||
'Description' => "Search in Friendica $hostname",
|
||||
'ShortName' => $this->baseUrl->getHost(),
|
||||
'Description' => $this->l10n->t('Search in Friendica %s', $this->baseUrl->getHost()),
|
||||
'Contact' => 'https://github.com/friendica/friendica/issues',
|
||||
'InputEncoding' => 'UTF-8',
|
||||
'OutputEncoding' => 'UTF-8',
|
||||
|
@ -46,29 +65,41 @@ class OpenSearch extends BaseModule
|
|||
/** @var DOMElement $parent */
|
||||
$parent = $xml->getElementsByTagName('OpenSearchDescription')[0];
|
||||
|
||||
XML::addElement($xml, $parent, 'Image',
|
||||
"$baseUrl/images/friendica-16.png", [
|
||||
if (file_exists($this->basePath . '/favicon.ico')) {
|
||||
$shortcut_icon = '/favicon.ico';
|
||||
} else {
|
||||
$shortcut_icon = $this->config->get('system', 'shortcut_icon');
|
||||
}
|
||||
|
||||
if (!empty($shortcut_icon)) {
|
||||
$imagedata = getimagesize($this->baseUrl . $shortcut_icon);
|
||||
}
|
||||
|
||||
if (!empty($imagedata)) {
|
||||
XML::addElement($xml, $parent, 'Image', $this->baseUrl . $shortcut_icon, [
|
||||
'width' => $imagedata[0],
|
||||
'height' => $imagedata[1],
|
||||
'type' => $imagedata['mime'],
|
||||
]);
|
||||
} else {
|
||||
XML::addElement($xml, $parent, 'Image',
|
||||
$this->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}",
|
||||
'method' => 'get',
|
||||
'template' => $this->baseUrl . '/search?q={searchTerms}',
|
||||
]);
|
||||
|
||||
XML::addElement($xml, $parent, 'Url', '', [
|
||||
'type' => 'application/opensearchdescription+xml',
|
||||
'rel' => 'self',
|
||||
'template' => "$baseUrl/opensearch",
|
||||
'template' => $this->baseUrl . '/opensearch',
|
||||
]);
|
||||
|
||||
$this->httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue