action.php 2.1 KB

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