xref: /dokuwiki/lib/exe/ajax.php (revision cf157a806193c0cabfbe957c3b9158c5273b7b3b)
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//close sesseion
20session_write_close();
21
22header('Content-Type: text/html; charset=utf-8');
23
24
25//call the requested function
26$call = 'ajax_'.$_POST['call'];
27if(function_exists($call)){
28  $call();
29}else{
30  print "The called function '".htmlspecialchars($call)."' does not exist!";
31}
32
33/**
34 * Searches for matching pagenames
35 *
36 * @author Andreas Gohr <andi@splitbrain.org>
37 */
38function ajax_qsearch(){
39  global $conf;
40  global $lang;
41
42  $query = cleanID($_POST['q']);
43  if(empty($query)) return;
44
45  require_once(DOKU_INC.'inc/html.php');
46  require_once(DOKU_INC.'inc/fulltext.php');
47
48  $data = array();
49  $data = ft_pageLookup($query);
50
51  if(!count($data)) return;
52
53  print '<strong>'.$lang['quickhits'].'</strong>';
54  print '<ul>';
55  foreach($data as $id){
56    print '<li>';
57    print html_wikilink(':'.$id);
58    print '</li>';
59  }
60  print '</ul>';
61}
62
63/**
64 * Refresh a page lock
65 *
66 * Andreas Gohr <andi@splitbrain.org>
67 */
68function ajax_lock(){
69  $id = cleanID($_POST['id']);
70  if(empty($id)) return;
71
72  if(!checklock($id)){
73    lock($id);
74    print 1;
75  }
76}
77
78//Setup VIM: ex: et ts=2 enc=utf-8 :
79?>
80