fix PHP styling on extension/admin
[dokuwiki.git] / lib / plugins / extension / admin.php
blob7e7eb60d4f98a0532d8136c45c5b65b8d01197fc
1 <?php
2 /**
3 * DokuWiki Plugin extension (Admin Component)
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author Michael Hamann <michael@content-space.de>
7 */
9 /**
10 * Admin part of the extension manager
12 class admin_plugin_extension extends DokuWiki_Admin_Plugin
14 protected $infoFor = null;
15 /** @var helper_plugin_extension_gui */
16 protected $gui;
18 /**
19 * Constructor
21 * loads additional helpers
23 public function __construct()
25 $this->gui = plugin_load('helper', 'extension_gui');
28 /**
29 * @return int sort number in admin menu
31 public function getMenuSort()
33 return 0;
36 /**
37 * @return bool true if only access for superuser, false is for superusers and moderators
39 public function forAdminOnly()
41 return true;
44 /**
45 * Execute the requested action(s) and initialize the plugin repository
47 public function handle()
49 global $INPUT;
50 // initialize the remote repository
51 /* @var helper_plugin_extension_repository $repository */
52 $repository = $this->loadHelper('extension_repository');
54 if (!$repository->hasAccess(!$INPUT->bool('purge'))) {
55 $url = $this->gui->tabURL('', ['purge' => 1], '&');
56 msg($this->getLang('repo_error').
57 ' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1
61 if (!in_array('ssl', stream_get_transports())) {
62 msg($this->getLang('nossl'), -1);
65 /* @var helper_plugin_extension_extension $extension */
66 $extension = $this->loadHelper('extension_extension');
68 try {
69 if ($INPUT->post->has('fn') && checkSecurityToken()) {
70 $actions = $INPUT->post->arr('fn');
71 foreach ($actions as $action => $extensions) {
72 foreach ($extensions as $extname => $label) {
73 switch ($action) {
74 case 'install':
75 case 'reinstall':
76 case 'update':
77 $extension->setExtension($extname);
78 $installed = $extension->installOrUpdate();
79 foreach ($installed as $ext => $info) {
80 msg(sprintf(
81 $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'),
82 $info['base']), 1
85 break;
86 case 'uninstall':
87 $extension->setExtension($extname);
88 $status = $extension->uninstall();
89 if ($status) {
90 msg(sprintf(
91 $this->getLang('msg_delete_success'),
92 hsc($extension->getDisplayName())), 1
94 } else {
95 msg(sprintf(
96 $this->getLang('msg_delete_failed'),
97 hsc($extension->getDisplayName())), -1
100 break;
101 case 'enable':
102 $extension->setExtension($extname);
103 $status = $extension->enable();
104 if ($status !== true) {
105 msg($status, -1);
106 } else {
107 msg(sprintf(
108 $this->getLang('msg_enabled'),
109 hsc($extension->getDisplayName())), 1
112 break;
113 case 'disable':
114 $extension->setExtension($extname);
115 $status = $extension->disable();
116 if ($status !== true) {
117 msg($status, -1);
118 } else {
119 msg(sprintf(
120 $this->getLang('msg_disabled'),
121 hsc($extension->getDisplayName())), 1
124 break;
128 send_redirect($this->gui->tabURL('', [], '&', true));
129 } elseif ($INPUT->post->str('installurl') && checkSecurityToken()) {
130 $installed = $extension->installFromURL(
131 $INPUT->post->str('installurl'),
132 $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
139 send_redirect($this->gui->tabURL('', [], '&', true));
140 } elseif (isset($_FILES['installfile']) && checkSecurityToken()) {
141 $installed = $extension->installFromUpload('installfile', $INPUT->post->bool('overwrite'));
142 foreach ($installed as $ext => $info) {
143 msg(sprintf(
144 $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'),
145 $info['base']), 1
148 send_redirect($this->gui->tabURL('', [], '&', true));
150 } catch (Exception $e) {
151 msg($e->getMessage(), -1);
152 send_redirect($this->gui->tabURL('', [], '&', true));
157 * Render HTML output
159 public function html()
161 echo '<h1>'.$this->getLang('menu').'</h1>'.DOKU_LF;
162 echo '<div id="extension__manager">'.DOKU_LF;
164 $this->gui->tabNavigation();
166 switch ($this->gui->currentTab()) {
167 case 'search':
168 $this->gui->tabSearch();
169 break;
170 case 'templates':
171 $this->gui->tabTemplates();
172 break;
173 case 'install':
174 $this->gui->tabInstall();
175 break;
176 case 'plugins':
177 default:
178 $this->gui->tabPlugins();
181 echo '</div>'.DOKU_LF;
185 // vim:ts=4:sw=4:et: