| [0] | 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| [1179] | 6 | # Copyright (c) 2003-2013 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 | |
|---|
| [938] | 87 | # --BEHAVIOR-- pluginBeforeDeactivate |
|---|
| 88 | $core->callBehavior('pluginsBeforeDeactivate', $plugin); |
|---|
| 89 | |
|---|
| [0] | 90 | $core->plugins->deactivateModule($plugin_id); |
|---|
| [938] | 91 | |
|---|
| 92 | # --BEHAVIOR-- pluginAfterDeactivate |
|---|
| 93 | $core->callBehavior('pluginsAfterDeactivate', $plugin); |
|---|
| 94 | |
|---|
| [0] | 95 | http::redirect('plugins.php'); |
|---|
| 96 | } |
|---|
| 97 | catch (Exception $e) |
|---|
| 98 | { |
|---|
| 99 | $core->error->add($e->getMessage()); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | # Activate plugin |
|---|
| 103 | elseif ($plugin_id && !empty($_POST['activate'])) |
|---|
| 104 | { |
|---|
| 105 | try |
|---|
| 106 | { |
|---|
| 107 | $p = $core->plugins->getDisabledModules(); |
|---|
| 108 | if (!isset($p[$plugin_id])) { |
|---|
| 109 | throw new Exception(__('No such plugin.')); |
|---|
| 110 | } |
|---|
| [938] | 111 | |
|---|
| 112 | # --BEHAVIOR-- pluginBeforeActivate |
|---|
| [961] | 113 | $core->callBehavior('pluginsBeforeActivate', $plugin_id); |
|---|
| [938] | 114 | |
|---|
| [0] | 115 | $core->plugins->activateModule($plugin_id); |
|---|
| [938] | 116 | |
|---|
| 117 | # --BEHAVIOR-- pluginAfterActivate |
|---|
| [961] | 118 | $core->callBehavior('pluginsAfterActivate', $plugin_id); |
|---|
| [938] | 119 | |
|---|
| [0] | 120 | http::redirect('plugins.php'); |
|---|
| 121 | } |
|---|
| 122 | catch (Exception $e) |
|---|
| 123 | { |
|---|
| 124 | $core->error->add($e->getMessage()); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | # Plugin upload |
|---|
| 128 | elseif ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) || |
|---|
| 129 | (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url']))) |
|---|
| 130 | { |
|---|
| 131 | try |
|---|
| 132 | { |
|---|
| 133 | if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) { |
|---|
| 134 | throw new Exception(__('Password verification failed')); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | if (!empty($_POST['upload_pkg'])) |
|---|
| 138 | { |
|---|
| 139 | files::uploadStatus($_FILES['pkg_file']); |
|---|
| 140 | |
|---|
| 141 | $dest = $p_path.'/'.$_FILES['pkg_file']['name']; |
|---|
| 142 | if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) { |
|---|
| 143 | throw new Exception(__('Unable to move uploaded file.')); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | else |
|---|
| 147 | { |
|---|
| 148 | $url = urldecode($_POST['pkg_url']); |
|---|
| 149 | $dest = $p_path.'/'.basename($url); |
|---|
| 150 | |
|---|
| 151 | try |
|---|
| 152 | { |
|---|
| 153 | $client = netHttp::initClient($url,$path); |
|---|
| 154 | $client->setUserAgent('Dotclear - http://www.dotclear.org/'); |
|---|
| 155 | $client->useGzip(false); |
|---|
| 156 | $client->setPersistReferers(false); |
|---|
| 157 | $client->setOutput($dest); |
|---|
| 158 | $client->get($path); |
|---|
| 159 | } |
|---|
| 160 | catch( Exception $e) |
|---|
| 161 | { |
|---|
| 162 | throw new Exception(__('An error occurred while downloading the file.')); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | unset($client); |
|---|
| 166 | } |
|---|
| [938] | 167 | |
|---|
| 168 | # --BEHAVIOR-- pluginBeforeAdd |
|---|
| [1182] | 169 | $core->callBehavior('pluginsBeforeAdd', $plugin_id); |
|---|
| [938] | 170 | |
|---|
| 171 | $ret_code = $core->plugins->installPackage($dest,$core->plugins); |
|---|
| 172 | |
|---|
| 173 | # --BEHAVIOR-- pluginAfterAdd |
|---|
| [1182] | 174 | $core->callBehavior('pluginsAfterAdd', $plugin_id); |
|---|
| [0] | 175 | |
|---|
| 176 | http::redirect('plugins.php?added='.$ret_code); |
|---|
| 177 | } |
|---|
| 178 | catch (Exception $e) |
|---|
| 179 | { |
|---|
| 180 | $core->error->add($e->getMessage()); |
|---|
| 181 | $default_tab = 'addplugin'; |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | # Plugin install |
|---|
| 187 | $plugins_install = $core->plugins->installModules(); |
|---|
| 188 | |
|---|
| 189 | /* DISPLAY Main page |
|---|
| 190 | -------------------------------------------------------- */ |
|---|
| 191 | dcPage::open(__('Plugins management'), |
|---|
| 192 | dcPage::jsLoad('js/_plugins.js'). |
|---|
| 193 | dcPage::jsPageTabs($default_tab) |
|---|
| 194 | ); |
|---|
| 195 | |
|---|
| 196 | echo |
|---|
| [500] | 197 | '<h2 class="page-title">'.__('Plugins management').'</h2>'; |
|---|
| [0] | 198 | |
|---|
| 199 | if (!empty($_GET['removed'])) { |
|---|
| [907] | 200 | dcPage::message(__('Plugin has been successfully deleted.')); |
|---|
| [0] | 201 | } |
|---|
| 202 | if (!empty($_GET['added'])) { |
|---|
| [907] | 203 | dcPage::message(($_GET['added'] == 2 ? __('Plugin has been successfully upgraded') : __('Plugin has been successfully installed.'))); |
|---|
| [0] | 204 | } |
|---|
| 205 | |
|---|
| 206 | # Plugins install messages |
|---|
| 207 | if (!empty($plugins_install['success'])) |
|---|
| 208 | { |
|---|
| 209 | echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>'; |
|---|
| 210 | foreach ($plugins_install['success'] as $k => $v) { |
|---|
| 211 | echo '<li>'.$k.'</li>'; |
|---|
| 212 | } |
|---|
| 213 | echo '</ul></div>'; |
|---|
| 214 | } |
|---|
| 215 | if (!empty($plugins_install['failure'])) |
|---|
| 216 | { |
|---|
| 217 | echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; |
|---|
| 218 | foreach ($plugins_install['failure'] as $k => $v) { |
|---|
| 219 | echo '<li>'.$k.' ('.$v.')</li>'; |
|---|
| 220 | } |
|---|
| 221 | echo '</ul></div>'; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | # List all active plugins |
|---|
| 225 | echo '<p>'.__('Plugins add new functionalities to Dotclear. '. |
|---|
| 226 | 'Here you can activate or deactivate installed plugins.').'</p>'; |
|---|
| 227 | |
|---|
| [1180] | 228 | echo (!$core->plugins->moduleExists('daInstaller') ? |
|---|
| 229 | sprintf('<p><strong>'.__('You can find additional plugins for your blog on %s.').'</strong></p>', |
|---|
| 230 | '<a href="http://plugins.dotaddict.org/dc2/">Dotaddict</a>') : |
|---|
| 231 | sprintf('<p><strong>'.__('You can find additional plugins for your blog on %s or using the %s.').'</strong></p>', |
|---|
| 232 | '<a href="http://plugins.dotaddict.org/dc2/">Dotaddict</a>', |
|---|
| 233 | '<a href="plugin.php?p=daInstaller">'.__('DotAddict.org Installer').'</a>')); |
|---|
| [0] | 234 | |
|---|
| 235 | if ($is_writable) { |
|---|
| 236 | echo __('To install or upgrade a plugin you generally just need to upload it '. |
|---|
| 237 | 'in "Install or upgrade a plugin" section.'); |
|---|
| 238 | } else { |
|---|
| 239 | echo __('To install or upgrade a plugin you just need to extract it in your plugins directory.'); |
|---|
| 240 | } |
|---|
| 241 | echo '</p>'; |
|---|
| 242 | |
|---|
| 243 | echo |
|---|
| 244 | '<div class="multi-part" id="plugins" title="'.__('Plugins').'">'; |
|---|
| 245 | |
|---|
| 246 | $p_available = $core->plugins->getModules(); |
|---|
| 247 | uasort($p_available,create_function('$a,$b','return strcasecmp($a["name"],$b["name"]);')); |
|---|
| 248 | if (!empty($p_available)) |
|---|
| 249 | { |
|---|
| 250 | echo |
|---|
| 251 | '<h3>'.__('Activated plugins').'</h3>'. |
|---|
| 252 | '<table class="clear plugins"><tr>'. |
|---|
| 253 | '<th>'.__('Plugin').'</th>'. |
|---|
| 254 | '<th class="nowrap">'.__('Version').'</th>'. |
|---|
| 255 | '<th class="nowrap">'.__('Details').'</th>'. |
|---|
| 256 | '<th class="nowrap">'.__('Action').'</th>'. |
|---|
| 257 | '</tr>'; |
|---|
| 258 | |
|---|
| [1055] | 259 | $distrib_plugins = array('aboutConfig','akismet','antispam','attachments','blogroll','blowupConfig','daInstaller', |
|---|
| 260 | 'fairTrackbacks','importExport','maintenance','pages','pings','simpleMenu','tags','themeEditor','userPref','widgets'); |
|---|
| [926] | 261 | $distrib_img = '<img src="images/dotclear_pw.png"'. |
|---|
| 262 | ' alt="'.__('Plugin from official distribution').'" title="'.__('Plugin from official distribution').'" />'; |
|---|
| 263 | |
|---|
| [0] | 264 | foreach ($p_available as $k => $v) |
|---|
| 265 | { |
|---|
| 266 | $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']); |
|---|
| 267 | $is_deactivable = $v['root_writable']; |
|---|
| [926] | 268 | $is_distrib = in_array($k, $distrib_plugins); |
|---|
| [0] | 269 | |
|---|
| 270 | echo |
|---|
| 271 | '<tr class="line wide">'. |
|---|
| 272 | '<td class="minimal nowrap"><strong>'.html::escapeHTML($k).'</strong></td>'. |
|---|
| 273 | '<td class="minimal">'.html::escapeHTML($v['version']).'</td>'. |
|---|
| [960] | 274 | '<td class="maximal'.($is_distrib ? ' distrib' : '').'"><strong>'.html::escapeHTML(__($v['name'])).'</strong> '. |
|---|
| 275 | '<br />'.html::escapeHTML(__($v['desc'])).($is_distrib ? ' '.$distrib_img : '').'</td>'. |
|---|
| [0] | 276 | '<td class="nowrap action">'; |
|---|
| 277 | |
|---|
| 278 | if ($is_deletable || $is_deactivable) |
|---|
| 279 | { |
|---|
| 280 | echo |
|---|
| 281 | '<form action="plugins.php" method="post">'. |
|---|
| 282 | '<div>'. |
|---|
| 283 | $core->formNonce(). |
|---|
| 284 | form::hidden(array('plugin_id'),html::escapeHTML($k)). |
|---|
| [3] | 285 | ($is_deactivable ? '<input type="submit" name="deactivate" value="'.__('Deactivate').'" /> ' : ''). |
|---|
| [0] | 286 | ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : ''). |
|---|
| 287 | '</div>'. |
|---|
| 288 | '</form>'; |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | echo |
|---|
| 292 | '</td>'. |
|---|
| 293 | '</tr>'; |
|---|
| 294 | } |
|---|
| 295 | echo |
|---|
| 296 | '</table>'; |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | $p_disabled = $core->plugins->getDisabledModules(); |
|---|
| 300 | uksort($p_disabled,create_function('$a,$b','return strcasecmp($a,$b);')); |
|---|
| 301 | if (!empty($p_disabled)) |
|---|
| 302 | { |
|---|
| 303 | echo |
|---|
| 304 | '<h3>'.__('Deactivated plugins').'</h3>'. |
|---|
| 305 | '<table class="clear plugins"><tr>'. |
|---|
| 306 | '<th>'.__('Plugin').'</th>'. |
|---|
| 307 | '<th class="nowrap">'.__('Action').'</th>'. |
|---|
| 308 | '</tr>'; |
|---|
| 309 | |
|---|
| 310 | foreach ($p_disabled as $k => $v) |
|---|
| 311 | { |
|---|
| 312 | $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']); |
|---|
| 313 | $is_activable = $v['root_writable']; |
|---|
| 314 | |
|---|
| 315 | echo |
|---|
| 316 | '<tr class="line wide">'. |
|---|
| 317 | '<td class="maximal nowrap"><strong>'.html::escapeHTML($k).'</strong></td>'. |
|---|
| 318 | '<td class="nowrap action">'; |
|---|
| 319 | |
|---|
| 320 | if ($is_deletable || $is_activable) |
|---|
| 321 | { |
|---|
| 322 | echo |
|---|
| 323 | '<form action="plugins.php" method="post">'. |
|---|
| 324 | '<div>'. |
|---|
| 325 | $core->formNonce(). |
|---|
| 326 | form::hidden(array('plugin_id'),html::escapeHTML($k)). |
|---|
| 327 | form::hidden(array('deactivated'),1). |
|---|
| [211] | 328 | ($is_activable ? '<input type="submit" name="activate" value="'.__('Activate').'" /> ' : ''). |
|---|
| [0] | 329 | ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : ''). |
|---|
| 330 | '</div>'. |
|---|
| 331 | '</form>'; |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | echo |
|---|
| 335 | '</td>'. |
|---|
| 336 | '</tr>'; |
|---|
| 337 | } |
|---|
| 338 | echo |
|---|
| 339 | '</table>'; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | echo '</div>'; |
|---|
| 343 | |
|---|
| 344 | # Add a new plugin |
|---|
| 345 | echo |
|---|
| 346 | '<div class="multi-part" id="addplugin" title="'.__('Install or upgrade a plugin').'">'; |
|---|
| 347 | |
|---|
| 348 | if ($is_writable) |
|---|
| 349 | { |
|---|
| 350 | echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>'; |
|---|
| 351 | |
|---|
| 352 | # 'Upload plugin' form |
|---|
| 353 | echo |
|---|
| 354 | '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data">'. |
|---|
| 355 | '<fieldset>'. |
|---|
| 356 | '<legend>'.__('Upload a zip file').'</legend>'. |
|---|
| [68] | 357 | '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file:').' '. |
|---|
| [125] | 358 | '<input type="file" id="pkg_file" name="pkg_file" /></label></p>'. |
|---|
| [68] | 359 | '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '. |
|---|
| 360 | form::password(array('your_pwd','your_pwd1'),20,255).'</label></p>'. |
|---|
| [0] | 361 | '<input type="submit" name="upload_pkg" value="'.__('Upload plugin').'" />'. |
|---|
| 362 | $core->formNonce(). |
|---|
| 363 | '</fieldset>'. |
|---|
| 364 | '</form>'; |
|---|
| 365 | |
|---|
| 366 | # 'Fetch plugin' form |
|---|
| 367 | echo |
|---|
| 368 | '<form method="post" action="plugins.php" id="fetchpkg">'. |
|---|
| 369 | '<fieldset>'. |
|---|
| 370 | '<legend>'.__('Download a zip file').'</legend>'. |
|---|
| [68] | 371 | '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file URL:').' '. |
|---|
| [125] | 372 | form::field(array('pkg_url','pkg_url'),40,255).'</label></p>'. |
|---|
| [68] | 373 | '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '. |
|---|
| 374 | form::password(array('your_pwd','your_pwd2'),20,255).'</label></p>'. |
|---|
| [0] | 375 | '<input type="submit" name="fetch_pkg" value="'.__('Download plugin').'" />'. |
|---|
| 376 | $core->formNonce(). |
|---|
| 377 | '</fieldset>'. |
|---|
| 378 | '</form>'; |
|---|
| 379 | } |
|---|
| 380 | else |
|---|
| 381 | { |
|---|
| 382 | echo |
|---|
| 383 | '<p class="static-msg">'. |
|---|
| 384 | __('To enable this function, please give write access to your plugins directory.'). |
|---|
| 385 | '</p>'; |
|---|
| 386 | } |
|---|
| 387 | echo '</div>'; |
|---|
| 388 | |
|---|
| [1238] | 389 | if ($core->plugins->moduleExists('daInstaller')) { |
|---|
| 390 | echo '<p><a href="plugin.php?p=daInstaller" class="multi-part">'.__('DotAddict.org Installer').'</a></p>'; |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | |
|---|
| [0] | 394 | # --BEHAVIOR-- pluginsToolsTabs |
|---|
| 395 | $core->callBehavior('pluginsToolsTabs',$core); |
|---|
| 396 | |
|---|
| 397 | dcPage::close(); |
|---|
| 398 | ?> |
|---|