[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  /** DokuWiki Plugin extension (Action Component)
   3   *
   4   * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
   5   * @author  Andreas Gohr <andi@splitbrain.org>
   6   */
   7  
   8  class action_plugin_extension extends DokuWiki_Action_Plugin
   9  {
  10  
  11      /**
  12       * Registers a callback function for a given event
  13       *
  14       * @param Doku_Event_Handler $controller DokuWiki's event controller object
  15       * @return void
  16       */
  17      public function register(Doku_Event_Handler $controller)
  18      {
  19          $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'info');
  20      }
  21  
  22      /**
  23       * Create the detail info for a single plugin
  24       *
  25       * @param Doku_Event $event
  26       * @param            $param
  27       */
  28      public function info(Doku_Event $event, $param)
  29      {
  30          global $USERINFO;
  31          global $INPUT;
  32  
  33          if ($event->data != 'plugin_extension') return;
  34          $event->preventDefault();
  35          $event->stopPropagation();
  36  
  37          /** @var admin_plugin_extension $admin */
  38          $admin = plugin_load('admin', 'extension');
  39          if (!$admin->isAccessibleByCurrentUser()) {
  40              http_status(403);
  41              echo 'Forbidden';
  42              exit;
  43          }
  44  
  45          $ext = $INPUT->str('ext');
  46          if (!$ext) {
  47              http_status(400);
  48              echo 'no extension given';
  49              return;
  50          }
  51  
  52          /** @var helper_plugin_extension_extension $extension */
  53          $extension = plugin_load('helper', 'extension_extension');
  54          $extension->setExtension($ext);
  55  
  56          $act = $INPUT->str('act');
  57          switch ($act) {
  58              case 'enable':
  59              case 'disable':
  60                  $extension->$act(); //enables/disables
  61  
  62                  $reverse = ($act == 'disable') ? 'enable' : 'disable';
  63  
  64                  $return = array(
  65                      'state'   => $act.'d', // isn't English wonderful? :-)
  66                      'reverse' => $reverse,
  67                      'label'   => $extension->getLang('btn_'.$reverse)
  68                  );
  69  
  70                  header('Content-Type: application/json');
  71                  echo json_encode($return);
  72                  break;
  73  
  74              case 'info':
  75              default:
  76                  /** @var helper_plugin_extension_list $list */
  77                  $list = plugin_load('helper', 'extension_list');
  78                  header('Content-Type: text/html; charset=utf-8');
  79                  echo $list->makeInfo($extension);
  80          }
  81      }
  82  }