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

@@ -11,12 +11,13 @@ define('E_AOWOW', E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED | E
define('JSON_AOWOW_POWER', JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
define('FILTER_FLAG_STRIP_AOWOW', FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
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_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');
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');
// shared setup strings
define('ERR_CREATE_FILE', 'could not create file at destination %s');

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));
{
header(MIME_TYPE_JSON);
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']);
}