View source for OpenSearch

file:wackowiki_opensearch_de.png?right&caption
{{toc numerate=1}}

===OpenSearch description format===

((https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md OpenSearch specification))
((https://developer.mozilla.org/en-US/docs/Web/OpenSearch MDN: OpenSearch description format))

%%(hl xml)
<?xml version="1.0"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
	<ShortName>WackoWiki</ShortName>
	<Description>WackoWiki</Description>
	<Image height="16" width="16" type="image/x-icon">https://example.com/theme/default/icon/favicon.ico</Image>
	<Url type="text/html" method="get" template="https://example.com/Search?phrase={searchTerms}" />
	<moz:SearchForm>https://example.com/Search</moz:SearchForm>
</OpenSearchDescription>
%%

===Implementation===
OpenSearch (##type="text/html"##) + Autodiscovery

====XML description file====
class/feed.php
%%(php)
<?php

// OpenSearch XML description file
function open_search()
{
	$this->engine->canonical = true;

	$xml  = '<?xml version="1.0"?>' . "\n";
	$xml .= '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">' . "\n";
	$xml .= '<ShortName>' . $this->engine->db->site_name . '</ShortName>' . "\n";
	$xml .= '<Description>' . $this->engine->db->site_name . '</Description>' . "\n";
	$xml .= '<InputEncoding>UTF-8</InputEncoding>' . "\n";
	$xml .= '<Image height="16" width="16" type="image/x-icon">' .
		($this->engine->db->site_favicon
			? $this->engine->db->base_url . Ut::join_path(IMAGE_DIR, $this->engine->db->site_favicon)
			: $this->engine->db->base_url . Ut::join_path(THEME_DIR, $this->engine->db->theme) . '/' . 'icon/favicon.ico')
		. '</Image>' . "\n";
	$xml .= '<Url type="text/html" method="get" template="' . $this->engine->href('', $this->engine->db->search_page) . '?phrase={searchTerms}" />' . "\n";
	$xml .= '</OpenSearchDescription>' . "\n";

	$file_name = Ut::join_path(XML_DIR, 'opensearch.xml');
	file_put_contents($file_name, $xml);
	@chmod('opensearch.xml', CHMOD_FILE);
	$this->engine->canonical = false;
}
%%
**xml/opensearch.xml**
%%(hl xml)
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
	<ShortName>WackoWiki</ShortName>
	<Description>WackoWiki</Description>
	<InputEncoding>UTF-8</InputEncoding>
	<Image height="16" width="16" type="image/x-icon">https://example.com/theme/default/icon/favicon.ico</Image>
	<Url type="text/html" method="get" template="https://example.com/Search?phrase={searchTerms}"/>
</OpenSearchDescription>
%%
====Autodiscovery====
theme/_common/_header.php
%%(php)
<?php

$tpl->os_href = $this->db->base_path . XML_DIR . '/';
%%
theme/_common/_header.tpl
%%
[= os _ =
	<link rel="search" type="application/opensearchdescription+xml" title="[ ' db: site_name | e ' ]" href="[ ' href ' ]opensearch.xml">
=]
%%
HTML head
%%(hl html)
<link rel="search" type="application/opensearchdescription+xml" href="/xml/opensearch.xml" title="WackoWiki">
%%
====Routing====
config/router.conf
%%
`^xml/opensearch\.xml$`		_ok!
`^xml/{}$`			_ok! age=0		// feeds
%%
Uses default cache: ##$age = 31## (days)

====Resync XML description file====
AP -> Maintenance -> Data Synchronization -> Feeds -> Synchronize

====Notes====
  * The ##xmlns## attribute is important — without it you could get the error message "Firefox could not download the search plugin".
    * Some providers just use ##<OpenSearchDescription>## without ##xmlns="~http://a9.com/-/spec/opensearch/1.1/"## and it may work, but it won't work with the current solution (tested)
  * Adds only ##type="text/html"##. It has been implemented along with the feed functions (feed class & xml folder), its static and is written only once.

commit:6e07dab4d91892f7c78de77475bf32b91bbb9951

===Questions===
  * Do we want a option to disable OpenSearch?
  * Do we need the AJAX auto-suggest feature as option (##type="application/x-suggestions+json"##)
  * What is ##<moz:SearchForm>https://example.com/Search</moz:SearchForm>## good for?