[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  /**
   3   * DokuWiki Plugin extension (Admin Component)
   4   *
   5   * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
   6   * @author  Michael Hamann <michael@content-space.de>
   7   */
   8  
   9  /**
  10   * Admin part of the extension manager
  11   */
  12  class admin_plugin_extension extends DokuWiki_Admin_Plugin
  13  {
  14      protected $infoFor = null;
  15      /** @var  helper_plugin_extension_gui */
  16      protected $gui;
  17  
  18      /**
  19       * Constructor
  20       *
  21       * loads additional helpers
  22       */
  23      public function __construct()
  24      {
  25          $this->gui = plugin_load('helper', 'extension_gui');
  26      }
  27  
  28      /**
  29       * @return int sort number in admin menu
  30       */
  31      public function getMenuSort()
  32      {
  33          return 0;
  34      }
  35  
  36      /**
  37       * @return bool true if only access for superuser, false is for superusers and moderators
  38       */
  39      public function forAdminOnly()
  40      {
  41          return true;
  42      }
  43  
  44      /**
  45       * Execute the requested action(s) and initialize the plugin repository
  46       */
  47      public function handle()
  48      {
  49          global $INPUT;
  50          // initialize the remote repository
  51          /* @var helper_plugin_extension_repository $repository */
  52          $repository = $this->loadHelper('extension_repository');
  53  
  54          if (!$repository->hasAccess(!$INPUT->bool('purge'))) {
  55              $url = $this->gui->tabURL('', ['purge' => 1], '&');
  56              msg($this->getLang('repo_error').
  57                  ' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1
  58              );
  59          }
  60  
  61          if (!in_array('ssl', stream_get_transports())) {
  62              msg($this->getLang('nossl'), -1);
  63          }
  64  
  65          /* @var helper_plugin_extension_extension $extension */
  66          $extension = $this->loadHelper('extension_extension');
  67  
  68          try {
  69              if ($INPUT->post->has('fn') && checkSecurityToken()) {
  70                  $actions = $INPUT->post->arr('fn');
  71                  foreach ($actions as $action => $extensions) {
  72                      foreach ($extensions as $extname => $label) {
  73                          switch ($action) {
  74                              case 'install':
  75                              case 'reinstall':
  76                              case 'update':
  77                                  $extension->setExtension($extname);
  78                                  $installed = $extension->installOrUpdate();
  79                                  foreach ($installed as $ext => $info) {
  80                                      msg(sprintf(
  81                                          $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'),
  82                                          $info['base']), 1
  83                                      );
  84                                  }
  85                                  break;
  86                              case 'uninstall':
  87                                  $extension->setExtension($extname);
  88                                  $status = $extension->uninstall();
  89                                  if ($status) {
  90                                      msg(sprintf(
  91                                          $this->getLang('msg_delete_success'),
  92                                          hsc($extension->getDisplayName())), 1
  93                                      );
  94                                  } else {
  95                                      msg(sprintf(
  96                                          $this->getLang('msg_delete_failed'),
  97                                          hsc($extension->getDisplayName())), -1
  98                                      );
  99                                  }
 100                                  break;
 101                              case 'enable':
 102                                  $extension->setExtension($extname);
 103                                  $status = $extension->enable();
 104                                  if ($status !== true) {
 105                                      msg($status, -1);
 106                                  } else {
 107                                      msg(sprintf(
 108                                          $this->getLang('msg_enabled'),
 109                                          hsc($extension->getDisplayName())), 1
 110                                      );
 111                                  }
 112                                  break;
 113                              case 'disable':
 114                                  $extension->setExtension($extname);
 115                                  $status = $extension->disable();
 116                                  if ($status !== true) {
 117                                      msg($status, -1);
 118                                  } else {
 119                                      msg(sprintf(
 120                                          $this->getLang('msg_disabled'),
 121                                          hsc($extension->getDisplayName())), 1
 122                                      );
 123                                  }
 124                                  break;
 125                          }
 126                      }
 127                  }
 128                  send_redirect($this->gui->tabURL('', [], '&', true));
 129              } elseif ($INPUT->post->str('installurl') && checkSecurityToken()) {
 130                  $installed = $extension->installFromURL($INPUT->post->str('installurl'));
 131                  foreach ($installed as $ext => $info) {
 132                      msg(sprintf(
 133                          $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'),
 134                          $info['base']), 1
 135                      );
 136                  }
 137                  send_redirect($this->gui->tabURL('', [], '&', true));
 138              } elseif (isset($_FILES['installfile']) && checkSecurityToken()) {
 139                  $installed = $extension->installFromUpload('installfile');
 140                  foreach ($installed as $ext => $info) {
 141                      msg(sprintf(
 142                          $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'),
 143                          $info['base']), 1
 144                      );
 145                  }
 146                  send_redirect($this->gui->tabURL('', [], '&', true));
 147              }
 148          } catch (Exception $e) {
 149              msg($e->getMessage(), -1);
 150              send_redirect($this->gui->tabURL('', [], '&', true));
 151          }
 152      }
 153  
 154      /**
 155       * Render HTML output
 156       */
 157      public function html()
 158      {
 159          echo '<h1>'.$this->getLang('menu').'</h1>'.DOKU_LF;
 160          echo '<div id="extension__manager">'.DOKU_LF;
 161  
 162          $this->gui->tabNavigation();
 163  
 164          switch ($this->gui->currentTab()) {
 165              case 'search':
 166                  $this->gui->tabSearch();
 167                  break;
 168              case 'templates':
 169                  $this->gui->tabTemplates();
 170                  break;
 171              case 'install':
 172                  $this->gui->tabInstall();
 173                  break;
 174              case 'plugins':
 175              default:
 176                  $this->gui->tabPlugins();
 177          }
 178  
 179          echo '</div>'.DOKU_LF;
 180      }
 181  }
 182  
 183  // vim:ts=4:sw=4:et: