You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

241 lines
7.1 KiB

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