diff --git a/inc/template.php b/inc/template.php index 3593cc60204a712cc9fd2e2b4e530d352d1673a5..cf3bf8da01418fe53facb8e4bf43609e082e5759 100644 --- a/inc/template.php +++ b/inc/template.php @@ -179,6 +179,8 @@ function tpl_metaheaders($alt=true){ // the usual stuff $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() ); + $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml', + 'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] ); $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE ); $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'), 'title'=>$lang['btn_index'] ); diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 5218803ea0dbbafa8d5349f8da5e34df8b23d774..3f64dc7ac5cdee2ab4eec4715eb2571029499725 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -23,8 +23,12 @@ header('Content-Type: text/html; charset=utf-8'); //call the requested function -if (!isset($_POST['call'])) { return; } -$call = 'ajax_'.$_POST['call']; +if(isset($_POST['call'])) + $call = 'ajax_'.$_POST['call']; +else if(isset($_GET['call'])) + $call = 'ajax_'.$_GET['call']; +else + return; if(function_exists($call)){ $call(); }else{ @@ -47,6 +51,7 @@ function ajax_qsearch(){ global $lang; $query = cleanID($_POST['q']); + if(empty($query)) $query = cleanID($_GET['q']); if(empty($query)) return; require_once(DOKU_INC.'inc/html.php'); @@ -67,6 +72,48 @@ function ajax_qsearch(){ print '</ul>'; } +/** + * Support OpenSearch suggestions + * + * @link http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.0 + * @author Mike Frysinger <vapier@gentoo.org> + */ +function ajax_suggestions() { + global $conf; + global $lang; + + $query = cleanID($_POST['q']); + if(empty($query)) $query = cleanID($_GET['q']); + if(empty($query)) return; + + require_once(DOKU_INC.'inc/html.php'); + require_once(DOKU_INC.'inc/fulltext.php'); + require_once(DOKU_INC.'inc/JSON.php'); + + $data = array(); + $data = ft_pageLookup($query); + if(!count($data)) return; + + // limit results to 15 hits + $data = array_slice($data, 0, 15); + $data = array_map('trim',$data); + $data = array_map('noNS',$data); + $data = array_unique($data); + sort($data); + + /* now construct a json */ + $suggestions = array( + $query, // the original query + $data, // some suggestions + array(), // no description + array() // no urls + ); + $json = new JSON(); + + header('Content-Type: application/x-suggestions+json'); + print $json->encode($suggestions); +} + /** * Refresh a page lock and save draft * diff --git a/lib/exe/opensearch.php b/lib/exe/opensearch.php new file mode 100644 index 0000000000000000000000000000000000000000..e23d16d201d13cb1d3f8461aa79be4d8d2c4ea0c --- /dev/null +++ b/lib/exe/opensearch.php @@ -0,0 +1,38 @@ +<?php +/** + * DokuWiki OpenSearch creator + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @link http://www.opensearch.org/ + * @author Mike Frysinger <vapier@gentoo.org> + * @author Andreas Gohr <andi@splitbrain.org> + */ + +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); +if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching) +if(!defined('NL')) define('NL',"\n"); +require_once(DOKU_INC.'inc/init.php'); + +// try to be clever about the favicon location +if(file_exists(DOKU_INC.'favicon.ico')){ + $ico = DOKU_URL.'favicon.ico'; +}elseif(DOKU_TPL.'images/favicon.ico'){ + $ico = DOKU_URL.'lib/tpl/'.$conf['template'].'/images/favicon.ico'; +}elseif(DOKU_TPL.'favicon.ico'){ + $ico = DOKU_URL.'lib/tpl/'.$conf['template'].'/favicon.ico'; +}else{ + $ico = DOKU_URL.'lib/tpl/default/images/favicon.ico'; +} + +// output +header('Content-Type: application/opensearchdescription+xml; charset=utf-8'); +echo '<?xml version="1.0"?>'.NL; +echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">'.NL; +echo ' <ShortName>'.htmlspecialchars($conf['title']).'</ShortName>'.NL; +echo ' <Image type="image/x-icon">'.$ico.'</Image>'.NL; +echo ' <Url type="text/html" template="'.DOKU_URL.DOKU_SCRIPT.'?do=search&id={searchTerms}" />'.NL; +echo ' <Url type="application/x-suggestions+json" template="'. + DOKU_URL.'lib/exe/ajax.php?call=suggestions&q={searchTerms}" />'.NL; +echo '</OpenSearchDescription>'.NL; + +//Setup VIM: ex: et ts=4 enc=utf-8 :