admin.php 6.8 KB

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