[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | |
---|
| 13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
| 14 | |
---|
| 15 | dcPage::checkSuper(); |
---|
| 16 | |
---|
| 17 | $default_tab = !empty($_REQUEST['tab']) ? html::escapeHTML($_REQUEST['tab']) : 'plugins'; |
---|
| 18 | |
---|
| 19 | $p_paths = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT); |
---|
| 20 | $p_path = array_pop($p_paths); |
---|
| 21 | unset($p_paths); |
---|
| 22 | |
---|
| 23 | $is_writable = false; |
---|
| 24 | if (is_dir($p_path) && is_writeable($p_path)) { |
---|
| 25 | $is_writable = true; |
---|
| 26 | $p_path_pat = preg_quote($p_path,'!'); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | $plugin_id = !empty($_POST['plugin_id']) ? $_POST['plugin_id'] : null; |
---|
| 30 | |
---|
| 31 | if ($is_writable) |
---|
| 32 | { |
---|
| 33 | # Delete plugin |
---|
| 34 | if ($plugin_id && !empty($_POST['delete'])) |
---|
| 35 | { |
---|
| 36 | try |
---|
| 37 | { |
---|
| 38 | if (empty($_POST['deactivated'])) |
---|
| 39 | { |
---|
| 40 | if (!$core->plugins->moduleExists($plugin_id)) { |
---|
| 41 | throw new Exception(__('No such plugin.')); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | $plugin = $core->plugins->getModules($plugin_id); |
---|
| 45 | $plugin['id'] = $plugin_id; |
---|
| 46 | |
---|
| 47 | if (!preg_match('!^'.$p_path_pat.'!', $plugin['root'])) { |
---|
| 48 | throw new Exception(__('You don\'t have permissions to delete this plugin.')); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | # --BEHAVIOR-- pluginBeforeDelete |
---|
| 52 | $core->callBehavior('pluginsBeforeDelete', $plugin); |
---|
| 53 | |
---|
| 54 | $core->plugins->deleteModule($plugin_id); |
---|
| 55 | |
---|
| 56 | # --BEHAVIOR-- pluginAfterDelete |
---|
| 57 | $core->callBehavior('pluginsAfterDelete', $plugin); |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
| 61 | $core->plugins->deleteModule($plugin_id,true); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | http::redirect('plugins.php?removed=1'); |
---|
| 65 | } |
---|
| 66 | catch (Exception $e) |
---|
| 67 | { |
---|
| 68 | $core->error->add($e->getMessage()); |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | # Deactivate plugin |
---|
| 72 | elseif ($plugin_id && !empty($_POST['deactivate'])) |
---|
| 73 | { |
---|
| 74 | try |
---|
| 75 | { |
---|
| 76 | if (!$core->plugins->moduleExists($plugin_id)) { |
---|
| 77 | throw new Exception(__('No such plugin.')); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | $plugin = $core->plugins->getModules($plugin_id); |
---|
| 81 | $plugin['id'] = $plugin_id; |
---|
| 82 | |
---|
| 83 | if (!$plugin['root_writable']) { |
---|
| 84 | throw new Exception(__('You don\'t have permissions to deactivate this plugin.')); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | $core->plugins->deactivateModule($plugin_id); |
---|
| 88 | http::redirect('plugins.php'); |
---|
| 89 | } |
---|
| 90 | catch (Exception $e) |
---|
| 91 | { |
---|
| 92 | $core->error->add($e->getMessage()); |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | # Activate plugin |
---|
| 96 | elseif ($plugin_id && !empty($_POST['activate'])) |
---|
| 97 | { |
---|
| 98 | try |
---|
| 99 | { |
---|
| 100 | $p = $core->plugins->getDisabledModules(); |
---|
| 101 | if (!isset($p[$plugin_id])) { |
---|
| 102 | throw new Exception(__('No such plugin.')); |
---|
| 103 | } |
---|
| 104 | $core->plugins->activateModule($plugin_id); |
---|
| 105 | http::redirect('plugins.php'); |
---|
| 106 | } |
---|
| 107 | catch (Exception $e) |
---|
| 108 | { |
---|
| 109 | $core->error->add($e->getMessage()); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | # Plugin upload |
---|
| 113 | elseif ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) || |
---|
| 114 | (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url']))) |
---|
| 115 | { |
---|
| 116 | try |
---|
| 117 | { |
---|
| 118 | if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) { |
---|
| 119 | throw new Exception(__('Password verification failed')); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | if (!empty($_POST['upload_pkg'])) |
---|
| 123 | { |
---|
| 124 | files::uploadStatus($_FILES['pkg_file']); |
---|
| 125 | |
---|
| 126 | $dest = $p_path.'/'.$_FILES['pkg_file']['name']; |
---|
| 127 | if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) { |
---|
| 128 | throw new Exception(__('Unable to move uploaded file.')); |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | else |
---|
| 132 | { |
---|
| 133 | $url = urldecode($_POST['pkg_url']); |
---|
| 134 | $dest = $p_path.'/'.basename($url); |
---|
| 135 | |
---|
| 136 | try |
---|
| 137 | { |
---|
| 138 | $client = netHttp::initClient($url,$path); |
---|
| 139 | $client->setUserAgent('Dotclear - http://www.dotclear.org/'); |
---|
| 140 | $client->useGzip(false); |
---|
| 141 | $client->setPersistReferers(false); |
---|
| 142 | $client->setOutput($dest); |
---|
| 143 | $client->get($path); |
---|
| 144 | } |
---|
| 145 | catch( Exception $e) |
---|
| 146 | { |
---|
| 147 | throw new Exception(__('An error occurred while downloading the file.')); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | unset($client); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | $ret_code = $core->plugins->installPackage($dest,$core->plugins); |
---|
| 154 | http::redirect('plugins.php?added='.$ret_code); |
---|
| 155 | } |
---|
| 156 | catch (Exception $e) |
---|
| 157 | { |
---|
| 158 | $core->error->add($e->getMessage()); |
---|
| 159 | $default_tab = 'addplugin'; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | # Plugin install |
---|
| 165 | $plugins_install = $core->plugins->installModules(); |
---|
| 166 | |
---|
| 167 | /* DISPLAY Main page |
---|
| 168 | -------------------------------------------------------- */ |
---|
| 169 | dcPage::open(__('Plugins management'), |
---|
| 170 | dcPage::jsLoad('js/_plugins.js'). |
---|
| 171 | dcPage::jsPageTabs($default_tab) |
---|
| 172 | ); |
---|
| 173 | |
---|
| 174 | echo |
---|
[500] | 175 | '<h2 class="page-title">'.__('Plugins management').'</h2>'; |
---|
[0] | 176 | |
---|
| 177 | if (!empty($_GET['removed'])) { |
---|
| 178 | echo |
---|
| 179 | '<p class="message">'.__('Plugin has been successfully deleted.').'</p>'; |
---|
| 180 | } |
---|
| 181 | if (!empty($_GET['added'])) { |
---|
| 182 | echo '<p class="message">'. |
---|
| 183 | ($_GET['added'] == 2 ? __('Plugin has been successfully upgraded') : __('Plugin has been successfully installed.')). |
---|
| 184 | '</p>'; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | # Plugins install messages |
---|
| 188 | if (!empty($plugins_install['success'])) |
---|
| 189 | { |
---|
| 190 | echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>'; |
---|
| 191 | foreach ($plugins_install['success'] as $k => $v) { |
---|
| 192 | echo '<li>'.$k.'</li>'; |
---|
| 193 | } |
---|
| 194 | echo '</ul></div>'; |
---|
| 195 | } |
---|
| 196 | if (!empty($plugins_install['failure'])) |
---|
| 197 | { |
---|
| 198 | echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; |
---|
| 199 | foreach ($plugins_install['failure'] as $k => $v) { |
---|
| 200 | echo '<li>'.$k.' ('.$v.')</li>'; |
---|
| 201 | } |
---|
| 202 | echo '</ul></div>'; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | # List all active plugins |
---|
| 206 | echo '<p>'.__('Plugins add new functionalities to Dotclear. '. |
---|
| 207 | 'Here you can activate or deactivate installed plugins.').'</p>'; |
---|
| 208 | |
---|
| 209 | echo '<p><strong>'.sprintf(__('You can find additional plugins for your blog on %s.'), |
---|
| 210 | '<a href="http://plugins.dotaddict.org/dc2/">Dotaddict</a>').'</strong> '; |
---|
| 211 | |
---|
| 212 | if ($is_writable) { |
---|
| 213 | echo __('To install or upgrade a plugin you generally just need to upload it '. |
---|
| 214 | 'in "Install or upgrade a plugin" section.'); |
---|
| 215 | } else { |
---|
| 216 | echo __('To install or upgrade a plugin you just need to extract it in your plugins directory.'); |
---|
| 217 | } |
---|
| 218 | echo '</p>'; |
---|
| 219 | |
---|
| 220 | echo |
---|
| 221 | '<div class="multi-part" id="plugins" title="'.__('Plugins').'">'; |
---|
| 222 | |
---|
| 223 | $p_available = $core->plugins->getModules(); |
---|
| 224 | uasort($p_available,create_function('$a,$b','return strcasecmp($a["name"],$b["name"]);')); |
---|
| 225 | if (!empty($p_available)) |
---|
| 226 | { |
---|
| 227 | echo |
---|
| 228 | '<h3>'.__('Activated plugins').'</h3>'. |
---|
| 229 | '<table class="clear plugins"><tr>'. |
---|
| 230 | '<th>'.__('Plugin').'</th>'. |
---|
| 231 | '<th class="nowrap">'.__('Version').'</th>'. |
---|
| 232 | '<th class="nowrap">'.__('Details').'</th>'. |
---|
| 233 | '<th class="nowrap">'.__('Action').'</th>'. |
---|
| 234 | '</tr>'; |
---|
| 235 | |
---|
| 236 | foreach ($p_available as $k => $v) |
---|
| 237 | { |
---|
| 238 | $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']); |
---|
| 239 | $is_deactivable = $v['root_writable']; |
---|
| 240 | |
---|
| 241 | echo |
---|
| 242 | '<tr class="line wide">'. |
---|
| 243 | '<td class="minimal nowrap"><strong>'.html::escapeHTML($k).'</strong></td>'. |
---|
| 244 | '<td class="minimal">'.html::escapeHTML($v['version']).'</td>'. |
---|
| 245 | '<td class="maximal"><strong>'.html::escapeHTML($v['name']).'</strong> '. |
---|
| 246 | '<br />'.html::escapeHTML($v['desc']).'</td>'. |
---|
| 247 | '<td class="nowrap action">'; |
---|
| 248 | |
---|
| 249 | if ($is_deletable || $is_deactivable) |
---|
| 250 | { |
---|
| 251 | echo |
---|
| 252 | '<form action="plugins.php" method="post">'. |
---|
| 253 | '<div>'. |
---|
| 254 | $core->formNonce(). |
---|
| 255 | form::hidden(array('plugin_id'),html::escapeHTML($k)). |
---|
[3] | 256 | ($is_deactivable ? '<input type="submit" name="deactivate" value="'.__('Deactivate').'" /> ' : ''). |
---|
[0] | 257 | ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : ''). |
---|
| 258 | '</div>'. |
---|
| 259 | '</form>'; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | echo |
---|
| 263 | '</td>'. |
---|
| 264 | '</tr>'; |
---|
| 265 | } |
---|
| 266 | echo |
---|
| 267 | '</table>'; |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | $p_disabled = $core->plugins->getDisabledModules(); |
---|
| 271 | uksort($p_disabled,create_function('$a,$b','return strcasecmp($a,$b);')); |
---|
| 272 | if (!empty($p_disabled)) |
---|
| 273 | { |
---|
| 274 | echo |
---|
| 275 | '<h3>'.__('Deactivated plugins').'</h3>'. |
---|
| 276 | '<table class="clear plugins"><tr>'. |
---|
| 277 | '<th>'.__('Plugin').'</th>'. |
---|
| 278 | '<th class="nowrap">'.__('Action').'</th>'. |
---|
| 279 | '</tr>'; |
---|
| 280 | |
---|
| 281 | foreach ($p_disabled as $k => $v) |
---|
| 282 | { |
---|
| 283 | $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']); |
---|
| 284 | $is_activable = $v['root_writable']; |
---|
| 285 | |
---|
| 286 | echo |
---|
| 287 | '<tr class="line wide">'. |
---|
| 288 | '<td class="maximal nowrap"><strong>'.html::escapeHTML($k).'</strong></td>'. |
---|
| 289 | '<td class="nowrap action">'; |
---|
| 290 | |
---|
| 291 | if ($is_deletable || $is_activable) |
---|
| 292 | { |
---|
| 293 | echo |
---|
| 294 | '<form action="plugins.php" method="post">'. |
---|
| 295 | '<div>'. |
---|
| 296 | $core->formNonce(). |
---|
| 297 | form::hidden(array('plugin_id'),html::escapeHTML($k)). |
---|
| 298 | form::hidden(array('deactivated'),1). |
---|
[211] | 299 | ($is_activable ? '<input type="submit" name="activate" value="'.__('Activate').'" /> ' : ''). |
---|
[0] | 300 | ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : ''). |
---|
| 301 | '</div>'. |
---|
| 302 | '</form>'; |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | echo |
---|
| 306 | '</td>'. |
---|
| 307 | '</tr>'; |
---|
| 308 | } |
---|
| 309 | echo |
---|
| 310 | '</table>'; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | echo '</div>'; |
---|
| 314 | |
---|
| 315 | # Add a new plugin |
---|
| 316 | echo |
---|
| 317 | '<div class="multi-part" id="addplugin" title="'.__('Install or upgrade a plugin').'">'; |
---|
| 318 | |
---|
| 319 | if ($is_writable) |
---|
| 320 | { |
---|
| 321 | echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>'; |
---|
| 322 | |
---|
| 323 | # 'Upload plugin' form |
---|
| 324 | echo |
---|
| 325 | '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data">'. |
---|
| 326 | '<fieldset>'. |
---|
| 327 | '<legend>'.__('Upload a zip file').'</legend>'. |
---|
[68] | 328 | '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file:').' '. |
---|
[125] | 329 | '<input type="file" id="pkg_file" name="pkg_file" /></label></p>'. |
---|
[68] | 330 | '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '. |
---|
| 331 | form::password(array('your_pwd','your_pwd1'),20,255).'</label></p>'. |
---|
[0] | 332 | '<input type="submit" name="upload_pkg" value="'.__('Upload plugin').'" />'. |
---|
| 333 | $core->formNonce(). |
---|
| 334 | '</fieldset>'. |
---|
| 335 | '</form>'; |
---|
| 336 | |
---|
| 337 | # 'Fetch plugin' form |
---|
| 338 | echo |
---|
| 339 | '<form method="post" action="plugins.php" id="fetchpkg">'. |
---|
| 340 | '<fieldset>'. |
---|
| 341 | '<legend>'.__('Download a zip file').'</legend>'. |
---|
[68] | 342 | '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file URL:').' '. |
---|
[125] | 343 | form::field(array('pkg_url','pkg_url'),40,255).'</label></p>'. |
---|
[68] | 344 | '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '. |
---|
| 345 | form::password(array('your_pwd','your_pwd2'),20,255).'</label></p>'. |
---|
[0] | 346 | '<input type="submit" name="fetch_pkg" value="'.__('Download plugin').'" />'. |
---|
| 347 | $core->formNonce(). |
---|
| 348 | '</fieldset>'. |
---|
| 349 | '</form>'; |
---|
| 350 | } |
---|
| 351 | else |
---|
| 352 | { |
---|
| 353 | echo |
---|
| 354 | '<p class="static-msg">'. |
---|
| 355 | __('To enable this function, please give write access to your plugins directory.'). |
---|
| 356 | '</p>'; |
---|
| 357 | } |
---|
| 358 | echo '</div>'; |
---|
| 359 | |
---|
| 360 | # --BEHAVIOR-- pluginsToolsTabs |
---|
| 361 | $core->callBehavior('pluginsToolsTabs',$core); |
---|
| 362 | |
---|
| 363 | dcPage::close(); |
---|
| 364 | ?> |
---|