You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

90 lines
2.2 KiB

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