[ 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  
  20          $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'info');
  21      }
  22  
  23      /**
  24       * Create the detail info for a single plugin
  25       *
  26       * @param Doku_Event $event
  27       * @param            $param
  28       */
  29      public function info(Doku_Event &$event, $param)
  30      {
  31          global $USERINFO;
  32          global $INPUT;
  33  
  34          if ($event->data != 'plugin_extension') return;
  35          $event->preventDefault();
  36          $event->stopPropagation();
  37  
  38          /** @var admin_plugin_extension $admin */
  39          $admin = plugin_load('admin', 'extension');
  40          if (!$admin->isAccessibleByCurrentUser()) {
  41              http_status(403);
  42              echo 'Forbidden';
  43              exit;
  44          }
  45  
  46          $ext = $INPUT->str('ext');
  47          if (!$ext) {
  48              http_status(400);
  49              echo 'no extension given';
  50              return;
  51          }
  52  
  53          /** @var helper_plugin_extension_extension $extension */
  54          $extension = plugin_load('helper', 'extension_extension');
  55          $extension->setExtension($ext);
  56  
  57          $act = $INPUT->str('act');
  58          switch ($act) {
  59              case 'enable':
  60              case 'disable':
  61                  $extension->$act(); //enables/disables
  62  
  63                  $reverse = ($act == 'disable') ? 'enable' : 'disable';
  64  
  65                  $return = array(
  66                      'state'   => $act.'d', // isn't English wonderful? :-)
  67                      'reverse' => $reverse,
  68                      'label'   => $extension->getLang('btn_'.$reverse)
  69                  );
  70  
  71                  header('Content-Type: application/json');
  72                  json_encode($return);
  73                  break;
  74  
  75              case 'info':
  76              default:
  77                  /** @var helper_plugin_extension_list $list */
  78                  $list = plugin_load('helper', 'extension_list');
  79                  header('Content-Type: text/html; charset=utf-8');
  80                  echo $list->makeInfo($extension);
  81          }
  82      }
  83  }