gui.php 7.2 KB

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