diff options
author | Andreas Gohr <andi@splitbrain.org> | 2006-11-10 16:14:53 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2006-11-10 16:14:53 +0100 |
commit | da96af357215605d855d6ce8ef8fb50ffb679641 (patch) | |
tree | fb168534bdb989614796cdfdd2fd8febc404a37c /lib/exe/ajax.php | |
parent | 122b469f774df8026a8a6182d2bc026ae1a06e2b (diff) | |
download | rpg-da96af357215605d855d6ce8ef8fb50ffb679641.tar.gz rpg-da96af357215605d855d6ce8ef8fb50ffb679641.tar.bz2 |
OpenSearch support
This adds support for the OpenSearch specification to autodetect
DokuWiki's search engine. The patch was submitted by Mike Frysinger
some time ago.
Some changes were made to the original patch. Only tested in FireFox 2.0
darcs-hash:20061110151453-7ad00-298ad77603854a604a642c0afd3975a997b8dc09.gz
Diffstat (limited to 'lib/exe/ajax.php')
-rw-r--r-- | lib/exe/ajax.php | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 5218803ea..3f64dc7ac 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'); @@ -68,6 +73,48 @@ function ajax_qsearch(){ } /** + * 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 * * Andreas Gohr <andi@splitbrain.org> |