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