[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/acl/ -> action.php (source)

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