Search/Opensearch

* return results with correct mime type.
This commit is contained in:
Sarjuuk
2023-10-08 01:14:01 +02:00
parent 0e0116b274
commit 79383fc83a
2 changed files with 16 additions and 12 deletions

View File

@@ -14,6 +14,7 @@ define('FILTER_FLAG_STRIP_AOWOW', FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH
define('MIME_TYPE_TEXT', 'Content-Type: text/plain; charset=utf-8');
define('MIME_TYPE_XML', 'Content-Type: text/xml; charset=utf-8');
define('MIME_TYPE_JSON', 'Content-Type: application/x-javascript; charset=utf-8');
define('MIME_TYPE_OPENSEARCH', 'Content-Type: application/x-suggestions+json; charset=utf-8');
define('MIME_TYPE_RSS', 'Content-Type: application/rss+xml; charset=utf-8');
define('MIME_TYPE_JPEG', 'Content-Type: image/jpeg');
define('MIME_TYPE_PNG', 'Content-Type: image/png');

View File

@@ -223,12 +223,15 @@ class SearchPage extends GenericPage
parent::display(); // errors are handled in the search-template itself
}
else if ($this->searchMask & SEARCH_TYPE_OPEN)
$result = [$this->search, []];
{
header(MIME_TYPE_OPENSEARCH);
exit(Util::toJSON([$this->search, []]));
}
else if ($this->searchMask & SEARCH_TYPE_JSON)
$result = [$this->search, [], []];
{
header(MIME_TYPE_JSON);
exit(Util::toJSON($result));
exit(Util::toJSON([$this->search, [], []]));
}
}
public function display(string $override = '') : void
@@ -236,7 +239,7 @@ class SearchPage extends GenericPage
if ($override || ($this->searchMask & SEARCH_TYPE_REGULAR))
parent::display($override);
else if ($this->searchMask & SEARCH_TYPE_OPEN)
$this->displayExtra([$this, 'generateOpenSearch']);
$this->displayExtra([$this, 'generateOpenSearch'], MIME_TYPE_OPENSEARCH);
else if ($this->searchMask & SEARCH_TYPE_JSON)
$this->displayExtra([$this, 'generateJsonSearch']);
}