[ 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\Form\Form;
  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      protected $tabs = array('plugins', 'templates', 'search', 'install');
  17  
  18      /** @var string the extension that should have an open info window FIXME currently broken */
  19      protected $infoFor = '';
  20  
  21      /**
  22       * Constructor
  23       *
  24       * initializes requested info window
  25       */
  26      public function __construct()
  27      {
  28          global $INPUT;
  29          $this->infoFor = $INPUT->str('info');
  30      }
  31  
  32      /**
  33       * display the plugin tab
  34       */
  35      public function tabPlugins()
  36      {
  37          echo '<div class="panelHeader">';
  38          echo $this->locale_xhtml('intro_plugins');
  39          echo '</div>';
  40  
  41          $pluginlist = plugin_list('', true);
  42          /* @var helper_plugin_extension_extension $extension */
  43          $extension = $this->loadHelper('extension_extension');
  44          /* @var helper_plugin_extension_list $list */
  45          $list = $this->loadHelper('extension_list');
  46  
  47          $form = new Form([
  48                  'action' => $this->tabURL('', [], '&'),
  49                  'id'  => 'extension__list',
  50          ]);
  51          $list->startForm();
  52          foreach ($pluginlist as $name) {
  53              $extension->setExtension($name);
  54              $list->addRow($extension, $extension->getID() == $this->infoFor);
  55          }
  56          $list->endForm();
  57          $form->addHTML($list->render(true));
  58          echo $form->toHTML();
  59      }
  60  
  61      /**
  62       * Display the template tab
  63       */
  64      public function tabTemplates()
  65      {
  66          echo '<div class="panelHeader">';
  67          echo $this->locale_xhtml('intro_templates');
  68          echo '</div>';
  69  
  70          // FIXME do we have a real way?
  71          $tpllist = glob(DOKU_INC.'lib/tpl/*', GLOB_ONLYDIR);
  72          $tpllist = array_map('basename', $tpllist);
  73          sort($tpllist);
  74  
  75          /* @var helper_plugin_extension_extension $extension */
  76          $extension = $this->loadHelper('extension_extension');
  77          /* @var helper_plugin_extension_list $list */
  78          $list = $this->loadHelper('extension_list');
  79  
  80          $form = new Form([
  81                  'action' => $this->tabURL('', [], '&'),
  82                  'id'  => 'extension__list',
  83          ]);
  84          $list->startForm();
  85          foreach ($tpllist as $name) {
  86              $extension->setExtension("template:$name");
  87              $list->addRow($extension, $extension->getID() == $this->infoFor);
  88          }
  89          $list->endForm();
  90          $form->addHTML($list->render(true));
  91          echo $form->toHTML();
  92      }
  93  
  94      /**
  95       * Display the search tab
  96       */
  97      public function tabSearch()
  98      {
  99          global $INPUT;
 100          echo '<div class="panelHeader">';
 101          echo $this->locale_xhtml('intro_search');
 102          echo '</div>';
 103  
 104          $form = new Form([
 105                  'action' => $this->tabURL('', [], '&'),
 106                  'class'  => 'search',
 107          ]);
 108          $form->addTagOpen('div')->addClass('no');
 109          $form->addTextInput('q', $this->getLang('search_for'))
 110              ->addClass('edit')
 111              ->val($INPUT->str('q'));
 112          $form->addButton('submit', $this->getLang('search'))
 113              ->attrs(['type' => 'submit', 'title' => $this->getLang('search')]);
 114          $form->addTagClose('div');
 115          echo $form->toHTML();
 116  
 117          if (!$INPUT->bool('q')) return;
 118  
 119          /* @var helper_plugin_extension_repository $repository FIXME should we use some gloabl instance? */
 120          $repository = $this->loadHelper('extension_repository');
 121          $result     = $repository->search($INPUT->str('q'));
 122  
 123          /* @var helper_plugin_extension_extension $extension */
 124          $extension = $this->loadHelper('extension_extension');
 125          /* @var helper_plugin_extension_list $list */
 126          $list = $this->loadHelper('extension_list');
 127  
 128          $form = new Form([
 129                  'action' => $this->tabURL('', [], '&'),
 130                  'id'  => 'extension__list',
 131          ]);
 132          $list->startForm();
 133          if ($result) {
 134              foreach ($result as $name) {
 135                  $extension->setExtension($name);
 136                  $list->addRow($extension, $extension->getID() == $this->infoFor);
 137              }
 138          } else {
 139              $list->nothingFound();
 140          }
 141          $list->endForm();
 142          $form->addHTML($list->render(true));
 143          echo $form->toHTML();
 144      }
 145  
 146      /**
 147       * Display the template tab
 148       */
 149      public function tabInstall()
 150      {
 151          echo '<div class="panelHeader">';
 152          echo $this->locale_xhtml('intro_install');
 153          echo '</div>';
 154  
 155          $form = new Form([
 156                  'action' => $this->tabURL('', [], '&'),
 157                  'enctype' => 'multipart/form-data',
 158                  'class'  => 'install',
 159          ]);
 160          $form->addTagOpen('div')->addClass('no');
 161          $form->addTextInput('installurl', $this->getLang('install_url'))
 162              ->addClass('block')
 163              ->attrs(['type' => 'url']);
 164          $form->addTag('br');
 165          $form->addTextInput('installfile', $this->getLang('install_upload'))
 166              ->addClass('block')
 167              ->attrs(['type' => 'file']);
 168          $form->addTag('br');
 169          $form->addButton('', $this->getLang('btn_install'))
 170              ->attrs(['type' => 'submit', 'title' => $this->getLang('btn_install')]);
 171          $form->addTagClose('div');
 172          echo $form->toHTML();
 173      }
 174  
 175      /**
 176       * Print the tab navigation
 177       *
 178       * @fixme style active one
 179       */
 180      public function tabNavigation()
 181      {
 182          echo '<ul class="tabs">';
 183          foreach ($this->tabs as $tab) {
 184              $url = $this->tabURL($tab);
 185              if ($this->currentTab() == $tab) {
 186                  $class = ' active';
 187              } else {
 188                  $class = '';
 189              }
 190              echo '<li class="'.$tab.$class.'"><a href="'.$url.'">'.$this->getLang('tab_'.$tab).'</a></li>';
 191          }
 192          echo '</ul>';
 193      }
 194  
 195      /**
 196       * Return the currently selected tab
 197       *
 198       * @return string
 199       */
 200      public function currentTab()
 201      {
 202          global $INPUT;
 203  
 204          $tab = $INPUT->str('tab', 'plugins', true);
 205          if (!in_array($tab, $this->tabs)) $tab = 'plugins';
 206          return $tab;
 207      }
 208  
 209      /**
 210       * Create an URL inside the extension manager
 211       *
 212       * @param string $tab      tab to load, empty for current tab
 213       * @param array  $params   associative array of parameter to set
 214       * @param string $sep      seperator to build the URL
 215       * @param bool   $absolute create absolute URLs?
 216       * @return string
 217       */
 218      public function tabURL($tab = '', $params = [], $sep = '&', $absolute = false)
 219      {
 220          global $ID;
 221          global $INPUT;
 222  
 223          if (!$tab) $tab = $this->currentTab();
 224          $defaults = array(
 225              'do'   => 'admin',
 226              'page' => 'extension',
 227              'tab'  => $tab,
 228          );
 229          if ($tab == 'search') $defaults['q'] = $INPUT->str('q');
 230  
 231          return wl($ID, array_merge($defaults, $params), $absolute, $sep);
 232      }
 233  }