xref: /dokuwiki/lib/exe/ajax.php (revision 95657bc6773c23c04843d51d5224df0bbd5191f0)
1<?php
2/**
3 * DokuWiki AJAX call handler
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9//fix for Opera XMLHttpRequests
10if(!count($_POST) && $HTTP_RAW_POST_DATA){
11  parse_str($HTTP_RAW_POST_DATA, $_POST);
12}
13
14if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
15require_once(DOKU_INC.'inc/init.php');
16require_once(DOKU_INC.'inc/common.php');
17require_once(DOKU_INC.'inc/pageutils.php');
18require_once(DOKU_INC.'inc/auth.php');
19
20header('Content-Type: text/html; charset=utf-8');
21
22
23//call the requested function
24$call = 'ajax_'.$_POST['call'];
25if(function_exists($call)){
26  $call();
27}else{
28  print "The called function '".htmlspecialchars($call)."' does not exist!";
29}
30
31/**
32 * Searches for matching pagenames
33 *
34 * @author Andreas Gohr <andi@splitbrain.org>
35 */
36function ajax_qsearch(){
37  global $conf;
38  global $lang;
39
40  $query = cleanID($_POST['q']);
41  if(empty($query)) return;
42
43  $nsdir = str_replace(':','/',getNS($query));
44  require_once(DOKU_INC.'inc/search.php');
45  require_once(DOKU_INC.'inc/html.php');
46
47  $data = array();
48  search($data,$conf['datadir'],'search_qsearch',array(query => $query),$nsdir);
49
50  if(!count($data)) return;
51
52  print '<b>'.$lang['quickhits'].'</b>';
53  print html_buildlist($data,'qsearch','html_list_index');
54}
55
56//Setup VIM: ex: et ts=2 enc=utf-8 :
57?>
58