WackoWiki: OpenSearch

https://wackowiki.org/doc     Version: 17.04.2021 09:01
Dev[link4]/NewFeatures[link5]/OpenSearch
OpenSearch in Firefox

1. OpenSearch description format


OpenSearch specification[link1]
MDN: OpenSearch description format[link2]

<?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>

2. Implementation

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

2.1. XML description file

class/feed.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
<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>

2.2. Autodiscovery

theme/_common/_header.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
<link rel="search" type="application/opensearchdescription+xml" href="/xml/opensearch.xml" title="WackoWiki">

2.3. Routing

config/router.conf
`^xml/opensearch\.xml$`		_ok!
`^xml/{}$`			_ok! age=0		// feeds

Uses default cache: $age = 31 (days)

2.4. Resync XML description file

AP -> Maintenance -> Data Synchronization -> Feeds -> Synchronize

2.5. Notes


commit:6e07dab4d91892f7c78de77475bf32b91bbb9951[link3]

3. Questions