[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/extension/helper/ -> gui.php (source)

   1  <?php
   2  /**
   3   * DokuWiki Plugin extension (Helper Component)
   4   *
   5   * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
   6   * @author  Andreas Gohr <andi@splitbrain.org>
   7   */
   8  
   9  use dokuwiki\Extension\PluginController;
  10  
  11  /**
  12   * Class helper_plugin_extension_list takes care of the overall GUI
  13   */
  14  class helper_plugin_extension_gui extends DokuWiki_Plugin
  15  {
  16  
  17      protected $tabs = array('plugins', 'templates', 'search', 'install');
  18  
  19      /** @var string the extension that should have an open info window FIXME currently broken */
  20      protected $infoFor = '';
  21  
  22      /**
  23       * Constructor
  24       *
  25       * initializes requested info window
  26       */
  27      public function __construct()
  28      {
  29          global $INPUT;
  30          $this->infoFor = $INPUT->str('info');
  31      }
  32  
  33      /**
  34       * display the plugin tab
  35       */
  36      public function tabPlugins()
  37      {
  38          echo '<div class="panelHeader">';
  39          echo $this->locale_xhtml('intro_plugins');
  40          echo '</div>';
  41  
  42          $pluginlist = plugin_list('', true);
  43          /* @var helper_plugin_extension_extension $extension */
  44          $extension = $this->loadHelper('extension_extension');
  45          /* @var helper_plugin_extension_list $list */
  46          $list = $this->loadHelper('extension_list');
  47          $list->startForm();
  48          foreach ($pluginlist as $name) {
  49              $extension->setExtension($name);
  50              $list->addRow($extension, $extension->getID() == $this->infoFor);
  51          }
  52          $list->endForm();
  53          $list->render();
  54      }
  55  
  56      /**
  57       * Display the template tab
  58       */
  59      public function tabTemplates()
  60      {
  61          echo '<div class="panelHeader">';
  62          echo $this->locale_xhtml('intro_templates');
  63          echo '</div>';
  64  
  65          // FIXME do we have a real way?
  66          $tpllist = glob(DOKU_INC.'lib/tpl/*', GLOB_ONLYDIR);
  67          $tpllist = array_map('basename', $tpllist);
  68          sort($tpllist);
  69  
  70          /* @var helper_plugin_extension_extension $extension */
  71          $extension = $this->loadHelper('extension_extension');
  72          /* @var helper_plugin_extension_list $list */
  73          $list = $this->loadHelper('extension_list');
  74          $list->startForm();
  75          foreach ($tpllist as $name) {
  76              $extension->setExtension("template:$name");
  77              $list->addRow($extension, $extension->getID() == $this->infoFor);
  78          }
  79          $list->endForm();
  80          $list->render();
  81      }
  82  
  83      /**
  84       * Display the search tab
  85       */
  86      public function tabSearch()
  87      {
  88          global $INPUT;
  89          echo '<div class="panelHeader">';
  90          echo $this->locale_xhtml('intro_search');
  91          echo '</div>';
  92  
  93          $form = new Doku_Form(array('action' => $this->tabURL('', array(), '&'), 'class' => 'search'));
  94          $form->addElement(form_makeTextField('q', $INPUT->str('q'), $this->getLang('search_for')));
  95          $form->addElement(form_makeButton('submit', '', $this->getLang('search')));
  96          $form->printForm();
  97  
  98          if (!$INPUT->bool('q')) return;
  99  
 100          /* @var helper_plugin_extension_repository $repository FIXME should we use some gloabl instance? */
 101          $repository = $this->loadHelper('extension_repository');
 102          $result     = $repository->search($INPUT->str('q'));
 103  
 104          /* @var helper_plugin_extension_extension $extension */
 105          $extension = $this->loadHelper('extension_extension');
 106          /* @var helper_plugin_extension_list $list */
 107          $list = $this->loadHelper('extension_list');
 108          $list->startForm();
 109          if ($result) {
 110              foreach ($result as $name) {
 111                  $extension->setExtension($name);
 112                  $list->addRow($extension, $extension->getID() == $this->infoFor);
 113              }
 114          } else {
 115              $list->nothingFound();
 116          }
 117          $list->endForm();
 118          $list->render();
 119      }
 120  
 121      /**
 122       * Display the template tab
 123       */
 124      public function tabInstall()
 125      {
 126          echo '<div class="panelHeader">';
 127          echo $this->locale_xhtml('intro_install');
 128          echo '</div>';
 129  
 130          $form = new Doku_Form(
 131              array(
 132                  'action' => $this->tabURL('', array(), '&'),
 133                  'enctype' => 'multipart/form-data',
 134                  'class' => 'install'
 135              )
 136          );
 137          $form->addElement(form_makeTextField('installurl', '', $this->getLang('install_url'), '', 'block'));
 138          $form->addElement(form_makeFileField('installfile', $this->getLang('install_upload'), '', 'block'));
 139          $form->addElement(form_makeButton('submit', '', $this->getLang('btn_install')));
 140          $form->printForm();
 141      }
 142  
 143      /**
 144       * Print the tab navigation
 145       *
 146       * @fixme style active one
 147       */
 148      public function tabNavigation()
 149      {
 150          echo '<ul class="tabs">';
 151          foreach ($this->tabs as $tab) {
 152              $url = $this->tabURL($tab);
 153              if ($this->currentTab() == $tab) {
 154                  $class = ' active';
 155              } else {
 156                  $class = '';
 157              }
 158              echo '<li class="'.$tab.$class.'"><a href="'.$url.'">'.$this->getLang('tab_'.$tab).'</a></li>';
 159          }
 160          echo '</ul>';
 161      }
 162  
 163      /**
 164       * Return the currently selected tab
 165       *
 166       * @return string
 167       */
 168      public function currentTab()
 169      {
 170          global $INPUT;
 171  
 172          $tab = $INPUT->str('tab', 'plugins', true);
 173          if (!in_array($tab, $this->tabs)) $tab = 'plugins';
 174          return $tab;
 175      }
 176  
 177      /**
 178       * Create an URL inside the extension manager
 179       *
 180       * @param string $tab      tab to load, empty for current tab
 181       * @param array  $params   associative array of parameter to set
 182       * @param string $sep      seperator to build the URL
 183       * @param bool   $absolute create absolute URLs?
 184       * @return string
 185       */
 186      public function tabURL($tab = '', $params = array(), $sep = '&amp;', $absolute = false)
 187      {
 188          global $ID;
 189          global $INPUT;
 190  
 191          if (!$tab) $tab = $this->currentTab();
 192          $defaults = array(
 193              'do'   => 'admin',
 194              'page' => 'extension',
 195              'tab'  => $tab,
 196          );
 197          if ($tab == 'search') $defaults['q'] = $INPUT->str('q');
 198  
 199          return wl($ID, array_merge($defaults, $params), $absolute, $sep);
 200      }
 201  }