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 * @author     Otto Vainio <plugins@valjakko.net>
8 */
9
10//fix for Opera XMLHttpRequests
11if(!count($_POST) && $HTTP_RAW_POST_DATA){
12  parse_str($HTTP_RAW_POST_DATA, $_POST);
13}
14
15if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../../').'/');
16require_once(DOKU_INC.'inc/init.php');
17require_once(DOKU_INC.'inc/common.php');
18require_once(DOKU_INC.'inc/pageutils.php');
19require_once(DOKU_INC.'inc/auth.php');
20if (!defined('DOKU_PLUGIN')) {
21  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
22}
23//close sesseion
24session_write_close();
25
26header('Content-Type: text/html; charset=utf-8');
27
28//call the requested function
29if (!isset($_POST['call'])) { return; }
30$call = 'ajax_'.$_POST['call'];
31if(function_exists($call)){
32  $call();
33}else{
34  $call = $_POST['call'];
35  $evt = new Doku_Event('AJAX_CALL_UNKNOWN', $call);
36  if ($evt->advise_before()) {
37    print "AJAX call '".htmlspecialchars($_POST['call'])."' unknown!\n";
38  }
39  $evt->advise_after();
40  unset($evt);
41}
42
43
44/**
45 * Return subnamespaces for the Mediamanager
46 */
47function ajax_linkpagens(){
48  global $conf;
49  require_once(DOKU_INC.'inc/search.php');
50  require_once('../functions.php');
51
52  // wanted namespace
53  $ns  = cleanID($_POST['ns']);
54  $dir  = utf8_encodeFN(str_replace(':','/',$ns));
55
56  $lvl = count(explode(':',$ns));
57
58  $data = array();
59  search($data,$conf['datadir'],'search_index',array('nofiles' => true),$dir);
60  foreach($data as $item){
61    $item['level'] = $lvl+1;
62    echo linkpage_nstree_li($item);
63    echo linkpage_nstree_item($item);
64    echo '</li>';
65  }
66}
67
68/**
69 * Return subnamespaces for the Mediamanager
70 */
71function ajax_linkpagelist(){
72  global $conf;
73  require_once('../functions.php');
74  linkpage_filelist($_POST['ns']);
75}
76
77//Setup VIM: ex: et ts=2 enc=utf-8 :
78?>
79