1<?php 2/** 3 * AJAX call handler for ACL plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12/** 13 * Register handler 14 */ 15class action_plugin_acl extends DokuWiki_Action_Plugin { 16 17 /** 18 * Registers a callback function for a given event 19 * 20 * @param Doku_Event_Handler $controller DokuWiki's event controller object 21 * @return void 22 */ 23 public function register(Doku_Event_Handler $controller) { 24 25 $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_acl'); 26 27 } 28 29 /** 30 * AJAX call handler for ACL plugin 31 * 32 * @param Doku_Event $event event object by reference 33 * @param mixed $param empty 34 * @return void 35 */ 36 37 public function handle_ajax_call_acl(Doku_Event $event, $param) { 38 if($event->data !== 'plugin_acl') { 39 return; 40 } 41 $event->stopPropagation(); 42 $event->preventDefault(); 43 44 global $ID; 45 global $INPUT; 46 47 /** @var $acl admin_plugin_acl */ 48 $acl = plugin_load('admin', 'acl'); 49 50 if(!$acl->isAccessibleByCurrentUser()) { 51 echo 'for admins only'; 52 return; 53 } 54 if(!checkSecurityToken()) { 55 echo 'CRSF Attack'; 56 return; 57 } 58 59 $ID = getID(); 60 $acl->handle(); 61 62 $ajax = $INPUT->str('ajax'); 63 header('Content-Type: text/html; charset=utf-8'); 64 65 if($ajax == 'info') { 66 $acl->_html_info(); 67 } elseif($ajax == 'tree') { 68 69 $ns = $INPUT->str('ns'); 70 if($ns == '*') { 71 $ns = ''; 72 } 73 $ns = cleanID($ns); 74 $lvl = count(explode(':', $ns)); 75 $ns = utf8_encodeFN(str_replace(':', '/', $ns)); 76 77 $data = $acl->_get_tree($ns, $ns); 78 79 foreach(array_keys($data) as $item) { 80 $data[$item]['level'] = $lvl + 1; 81 } 82 echo html_buildlist( 83 $data, 'acl', array($acl, '_html_list_acl'), 84 array($acl, '_html_li_acl') 85 ); 86 } 87 } 88} 89