-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.php
More file actions
75 lines (69 loc) · 2.66 KB
/
action.php
File metadata and controls
75 lines (69 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
/**
* Action part of the tag plugin, handles tag display and index updates
*/
class action_plugin_explorertree extends DokuWiki_Action_Plugin {
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, '_ajax_call');
}
/**
* Register the events
*
* @param $event DOKU event on ajax call
* @param $param parameters, ignored
*/
function _ajax_call(&$event, $param) {
if ($event->data !== 'plugin_explorertree') {
return;
}
//no other ajax call handlers needed
$event->stopPropagation();
$event->preventDefault();
//e.g. access additional request variables
global $INPUT; //available since release 2012-10-13 "Adora Belle"
if (!checkSecurityToken()){
$data = array('error'=>true,'msg'=>'invalid security token!');
}else{
switch($INPUT->str('operation')){
case 'explorertree_branch':
if (!($helper = plugin_load('helper', 'explorertree'))){
$data = array('error'=>true,'msg'=>"Can't load tree helper.");
break;
}
if (!($route = $helper->loadRoute($INPUT->str('route'),$INPUT->arr('loader')))){
$data = array('error'=>true,'msg'=>"Can't load route '".$INPUT->str('route')."'!");
}
$data = array('html' => $helper->htmlExplorer($INPUT->str('route'),ltrim(':'.$INPUT->str('itemid')),':') );
if (!$data['html']) {$data['error'] = true; $data['msg'] = "Can't load tree html.";}
break;
case 'callback':
if (!($helper = plugin_load('helper', 'explorertree'))){
$data = array('error'=>true,'msg'=>"Can't load tree helper.");
break;
}
$route = $helper->loadRoute($INPUT->str('route'),$INPUT->arr('loader'));
if (!$route || !is_callable(@$route['callbacks'][$INPUT->str(event)])) {
$data = array('error'=>true,'msg'=>"Can't load callback '".$INPUT->str('event')."'for '".$INPUT->str('route')."'!");
}
$data = @call_user_func_array($route['callbacks'][$INPUT->str(event)],array($INPUT->str('itemid')));
if (!is_array($data)) $data = array('error'=>true,'msg'=>"Callback for '".$INPUT->str('event')."' does not exists!");
break;
default:
$data = array('error'=>true,'msg'=>'Unknown operation: '.$INPUT->str('operation'));
break;
}
//data
//json library of DokuWiki
}
if (is_array($data)) $data['token'] = getSecurityToken();
require_once DOKU_INC . 'inc/JSON.php';
$json = new JSON();
//set content type
header('Content-Type: application/json');
echo $json->encode($data);
// $this->get_helper()->check_meta_changes();
}
}