Changeset 2267:e59137433afb for admin/plugins.php
- Timestamp:
- 10/04/13 21:37:08 (12 years ago)
- Branch:
- default
- Parents:
- 2266:4194798ba665 (diff), 2261:e7aa9cffbc30 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/plugins.php
r2256 r2267 13 13 require dirname(__FILE__).'/../inc/admin/prepend.php'; 14 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 dcPage::addSuccessNotice(__('Plugin has been successfully deleted.')); 65 http::redirect('plugins.php'); 66 } 67 catch (Exception $e) 68 { 69 $core->error->add($e->getMessage()); 70 } 71 } 72 # Deactivate plugin 73 elseif ($plugin_id && !empty($_POST['deactivate'])) 74 { 75 try 76 { 77 if (!$core->plugins->moduleExists($plugin_id)) { 78 throw new Exception(__('No such plugin.')); 79 } 80 81 $plugin = $core->plugins->getModules($plugin_id); 82 $plugin['id'] = $plugin_id; 83 84 if (!$plugin['root_writable']) { 85 throw new Exception(__('You don\'t have permissions to deactivate this plugin.')); 86 } 87 88 # --BEHAVIOR-- pluginBeforeDeactivate 89 $core->callBehavior('pluginsBeforeDeactivate', $plugin); 90 91 $core->plugins->deactivateModule($plugin_id); 92 93 # --BEHAVIOR-- pluginAfterDeactivate 94 $core->callBehavior('pluginsAfterDeactivate', $plugin); 95 96 http::redirect('plugins.php'); 97 } 98 catch (Exception $e) 99 { 100 $core->error->add($e->getMessage()); 101 } 102 } 103 # Activate plugin 104 elseif ($plugin_id && !empty($_POST['activate'])) 105 { 106 try 107 { 108 $p = $core->plugins->getDisabledModules(); 109 if (!isset($p[$plugin_id])) { 110 throw new Exception(__('No such plugin.')); 111 } 112 113 # --BEHAVIOR-- pluginBeforeActivate 114 $core->callBehavior('pluginsBeforeActivate', $plugin_id); 115 116 $core->plugins->activateModule($plugin_id); 117 118 # --BEHAVIOR-- pluginAfterActivate 119 $core->callBehavior('pluginsAfterActivate', $plugin_id); 120 121 http::redirect('plugins.php'); 122 } 123 catch (Exception $e) 124 { 125 $core->error->add($e->getMessage()); 126 } 127 } 128 # Plugin upload 129 elseif ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) || 130 (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url']))) 131 { 132 try 133 { 134 if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) { 135 throw new Exception(__('Password verification failed')); 136 } 137 138 if (!empty($_POST['upload_pkg'])) 139 { 140 files::uploadStatus($_FILES['pkg_file']); 141 142 $dest = $p_path.'/'.$_FILES['pkg_file']['name']; 143 if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) { 144 throw new Exception(__('Unable to move uploaded file.')); 145 } 146 } 147 else 148 { 149 $url = urldecode($_POST['pkg_url']); 150 $dest = $p_path.'/'.basename($url); 151 152 try 153 { 154 $client = netHttp::initClient($url,$path); 155 $client->setUserAgent('Dotclear - http://www.dotclear.org/'); 156 $client->useGzip(false); 157 $client->setPersistReferers(false); 158 $client->setOutput($dest); 159 $client->get($path); 160 } 161 catch( Exception $e) 162 { 163 throw new Exception(__('An error occurred while downloading the file.')); 164 } 165 166 unset($client); 167 } 168 169 # --BEHAVIOR-- pluginBeforeAdd 170 $core->callBehavior('pluginsBeforeAdd', $plugin_id); 171 172 $ret_code = $core->plugins->installPackage($dest,$core->plugins); 173 174 # --BEHAVIOR-- pluginAfterAdd 175 $core->callBehavior('pluginsAfterAdd', $plugin_id); 176 if ($ret_code == 2) { 177 dcPage::addSuccessNotice(__('Plugin has been successfully upgraded')); 178 } else { 179 dcPage::addSuccessNotice(__('Plugin has been successfully installed.')); 180 } 181 http::redirect('plugins.php'); 182 } 183 catch (Exception $e) 184 { 185 $core->error->add($e->getMessage()); 186 $default_tab = 'addplugin'; 187 } 188 } 189 } 190 191 # Plugin install 192 $plugins_install = $core->plugins->installModules(); 193 194 /* DISPLAY Main page 195 -------------------------------------------------------- */ 15 dcPage::check('admin'); 16 17 # -- "First time" settings setup -- 18 if ($core->blog->settings->system->plugins_allow_multi_install === null) { 19 $core->blog->settings->system->put( 20 'plugins_allow_multi_install', false, 'boolean', 'Allow multi-installation for plugins', true, true 21 ); 22 } 23 if ($core->blog->settings->system->store_plugin_url === null) { 24 $core->blog->settings->system->put( 25 'store_plugin_url', 'http://update.dotaddict.org/dc2/plugins.xml', 'string', 'Plugins XML feed location', true, true 26 ); 27 } 28 29 # -- Page helper -- 30 $list = new adminModulesList( 31 $core->plugins, 32 DC_PLUGINS_ROOT, 33 $core->blog->settings->system->store_plugin_url 34 ); 35 36 $list::$allow_multi_install = $core->blog->settings->system->plugins_allow_multi_install; 37 $list::$distributed_modules = array( 38 'aboutConfig', 39 'akismet', 40 'antispam', 41 'attachments', 42 'blogroll', 43 'blowupConfig', 44 'daInstaller', 45 'fairTrackbacks', 46 'importExport', 47 'maintenance', 48 'pages', 49 'pings', 50 'simpleMenu', 51 'tags', 52 'themeEditor', 53 'userPref', 54 'widgets' 55 ); 56 57 # -- Display module configuration page -- 58 if ($list->setConfiguration()) { 59 60 # Get content before page headers 61 include $list->includeConfiguration(); 62 63 # Gather content 64 $list->getConfiguration(); 65 66 # Display page 67 dcPage::open(__('Plugins management'), 68 69 # --BEHAVIOR-- pluginsToolsHeaders 70 $core->callBehavior('pluginsToolsHeaders', $core, true), 71 72 dcPage::breadcrumb( 73 array( 74 html::escapeHTML($core->blog->name) => '', 75 __('Plugins management') => $list->getURL('',false), 76 '<span class="page-title">'.__('Plugin configuration').'</span>' => '' 77 )) 78 ); 79 80 # Display previously gathered content 81 $list->displayConfiguration(); 82 83 dcPage::close(); 84 85 # Stop reading code here 86 return; 87 } 88 89 # -- Execute actions -- 90 try { 91 $list->doActions('plugins'); 92 } 93 catch (Exception $e) { 94 $core->error->add($e->getMessage()); 95 } 96 97 # -- Plugin install -- 98 $plugins_install = null; 99 if (!$core->error->flag()) { 100 $plugins_install = $core->plugins->installModules(); 101 } 102 103 # -- Page header -- 196 104 dcPage::open(__('Plugins management'), 197 105 dcPage::jsLoad('js/_plugins.js'). 198 dcPage::jsPageTabs($default_tab), 106 dcPage::jsPageTabs(). 107 108 # --BEHAVIOR-- pluginsToolsHeaders 109 $core->callBehavior('pluginsToolsHeaders', $core, false), 110 199 111 dcPage::breadcrumb( 200 112 array( … … 204 116 ); 205 117 206 if (!empty($_GET['removed'])) { 207 dcPage::success(__('Plugin has been successfully deleted.')); 208 } 209 if (!empty($_GET['added'])) { 210 dcPage::success(($_GET['added'] == 2 ? __('Plugin has been successfully upgraded') : __('Plugin has been successfully installed.'))); 211 } 212 213 # Plugins install messages 214 if (!empty($plugins_install['success'])) 215 { 216 echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>'; 118 # -- Plugins install messages -- 119 if (!empty($plugins_install['success'])) { 120 echo 121 '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>'; 122 217 123 foreach ($plugins_install['success'] as $k => $v) { 218 echo '<li>'.$k.'</li>'; 219 } 220 echo '</ul></div>'; 221 } 222 if (!empty($plugins_install['failure'])) 223 { 224 echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; 124 echo 125 '<li>'.$k.'</li>'; 126 } 127 128 echo 129 '</ul></div>'; 130 } 131 if (!empty($plugins_install['failure'])) { 132 echo 133 '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; 134 225 135 foreach ($plugins_install['failure'] as $k => $v) { 226 echo '<li>'.$k.' ('.$v.')</li>'; 227 } 228 echo '</ul></div>'; 229 } 230 231 # List all active plugins 232 echo '<p>'.__('Plugins add new functionalities to Dotclear. '. 233 'Here you can activate or deactivate installed plugins.').'</p>'; 234 235 echo (!$core->plugins->moduleExists('daInstaller') ? 236 sprintf('<p><strong>'.__('You can find additional plugins for your blog on %s.').'</strong></p>', 237 '<a href="http://plugins.dotaddict.org/dc2/">Dotaddict</a>') : 238 sprintf('<p><strong>'.__('You can find additional plugins for your blog on %s or using the %s.').'</strong></p>', 239 '<a href="http://plugins.dotaddict.org/dc2/">Dotaddict</a>', 240 '<a href="plugin.php?p=daInstaller">'.__('DotAddict.org Installer').'</a>')); 241 242 if ($is_writable) { 243 echo '<p>'.__('To install or upgrade a plugin you generally just need to upload it '. 244 'in "Install or upgrade a plugin" section.'); 245 } else { 246 echo '<p>'.__('To install or upgrade a plugin you just need to extract it in your plugins directory.'); 247 } 248 echo '</p>'; 136 echo 137 '<li>'.$k.' ('.$v.')</li>'; 138 } 139 140 echo 141 '</ul></div>'; 142 } 143 144 # -- Display modules lists -- 145 if ($core->auth->isSuperAdmin() && $list->isWritablePath()) { 146 147 # Updated modules from repo 148 $modules = $list->store->get(true); 149 if (!empty($modules)) { 150 echo 151 '<div class="multi-part" id="update" title="'.html::escapeHTML(__('Update plugins')).'">'. 152 '<h3>'.html::escapeHTML(__('Update plugins')).'</h3>'. 153 '<p>'.sprintf( 154 __('There is one plugin to update available from repository.', 'There are %s plugins to update available from repository.', count($modules)), 155 count($modules) 156 ).'</p>'; 157 158 $list 159 ->setList('plugin-update') 160 ->setTab('update') 161 ->setModules($modules) 162 ->displayModules( 163 /*cols */ array('icon', 'name', 'version', 'current_version', 'desc'), 164 /* actions */ array('update') 165 ); 166 167 echo 168 '<p class="info vertical-separator">'.sprintf( 169 __("Visit %s repository, the resources center for Dotclear."), 170 '<a href="http://dotaddict.org/dc2/plugins">Dotaddict</a>' 171 ). 172 '</p>'. 173 174 '</div>'; 175 } 176 } 249 177 250 178 echo 251 '<div class="multi-part" id="plugins" title="'.__('Plugins').'">'; 252 253 $p_available = $core->plugins->getModules(); 254 uasort($p_available,create_function('$a,$b','return strcasecmp($a["name"],$b["name"]);')); 255 if (!empty($p_available)) 256 { 179 '<div class="multi-part" id="plugins" title="'.__('Installed plugins').'">'; 180 181 # Activated modules 182 $modules = $list->modules->getModules(); 183 if (!empty($modules)) { 184 185 echo 186 '<h3>'.($core->auth->isSuperAdmin() ?__('Activated plugins') : __('Installed plugins')).'</h3>'. 187 '<p>'.__('You can configure and manage installed plugins from this list.').'</p>'; 188 189 $list 190 ->setList('plugin-activate') 191 ->setTab('plugins') 192 ->setModules($modules) 193 ->displayModules( 194 /* cols */ array('expander', 'icon', 'name', 'config', 'version', 'desc', 'distrib'), 195 /* actions */ array('deactivate', 'delete', 'behavior') 196 ); 197 } 198 199 # Deactivated modules 200 if ($core->auth->isSuperAdmin()) { 201 $modules = $list->modules->getDisabledModules(); 202 if (!empty($modules)) { 203 echo 204 '<h3>'.__('Deactivated plugins').'</h3>'. 205 '<p>'.__('Deactivated plugins are installed but not usable. You can activate them from here.').'</p>'; 206 207 $list 208 ->setList('plugin-deactivate') 209 ->setTab('plugins') 210 ->setModules($modules) 211 ->displayModules( 212 /* cols */ array('icon', 'name', 'distrib'), 213 /* actions */ array('activate', 'delete') 214 ); 215 } 216 } 217 218 echo 219 '</div>'; 220 221 if ($core->auth->isSuperAdmin() && $list->isWritablePath()) { 222 223 # New modules from repo 224 $search = $list->getSearch(); 225 $modules = $search ? $list->store->search($search) : $list->store->get(); 226 227 if (!empty($search) || !empty($modules)) { 228 echo 229 '<div class="multi-part" id="new" title="'.__('Add plugins').'">'. 230 '<h3>'.__('Add plugins from repository').'</h3>'. 231 '<p>'.__('Search and install plugins directly from repository.').'</p>'; 232 233 $list 234 ->setList('plugin-new') 235 ->setTab('new') 236 ->setModules($modules) 237 ->displaySearch() 238 ->displayIndex() 239 ->displayModules( 240 /* cols */ array('expander', 'name', 'score', 'version', 'desc'), 241 /* actions */ array('install'), 242 /* nav limit */ true 243 ); 244 245 echo 246 '<p class="info vertical-separator">'.sprintf( 247 __("Visit %s repository, the resources center for Dotclear."), 248 '<a href="http://dotaddict.org/dc2/plugins">Dotaddict</a>' 249 ). 250 '</p>'. 251 252 '</div>'; 253 } 254 255 # Add a new plugin 257 256 echo 258 '<h3>'.__('Activated plugins').'</h3>'. 259 '<div class="table-outer clear">'. 260 '<table class="plugins"><tr>'. 261 '<th>'.__('Plugin').'</th>'. 262 '<th class="nowrap">'.__('Version').'</th>'. 263 '<th class="nowrap">'.__('Details').'</th>'. 264 '<th class="nowrap">'.__('Action').'</th>'. 265 '</tr>'; 266 267 $distrib_plugins = array('aboutConfig','akismet','antispam','attachments','blogroll','blowupConfig','daInstaller', 268 'fairTrackbacks','importExport','maintenance','pages','pings','simpleMenu','tags','themeEditor','userPref','widgets'); 269 $distrib_img = '<img src="images/dotclear_pw.png"'. 270 ' alt="'.__('Plugin from official distribution').'" title="'.__('Plugin from official distribution').'" />'; 271 272 foreach ($p_available as $k => $v) 273 { 274 $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']); 275 $is_deactivable = $v['root_writable']; 276 $is_distrib = in_array($k, $distrib_plugins); 277 278 echo 279 '<tr class="line wide">'. 280 '<td class="minimal nowrap"><strong>'.html::escapeHTML($k).'</strong></td>'. 281 '<td class="minimal">'.html::escapeHTML($v['version']).'</td>'. 282 '<td class="maximal'.($is_distrib ? ' distrib' : '').'"><strong>'.html::escapeHTML(__($v['name'])).'</strong> '. 283 '<br />'.html::escapeHTML(__($v['desc'])).($is_distrib ? ' '.$distrib_img : '').'</td>'. 284 '<td class="nowrap action">'; 285 286 if ($is_deletable || $is_deactivable) 287 { 288 echo 289 '<form action="plugins.php" method="post">'. 290 '<div>'. 291 $core->formNonce(). 292 form::hidden(array('plugin_id'),html::escapeHTML($k)). 293 ($is_deactivable ? '<input type="submit" name="deactivate" value="'.__('Deactivate').'" /> ' : ''). 294 ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : ''). 295 '</div>'. 296 '</form>'; 297 } 298 299 echo 300 '</td>'. 301 '</tr>'; 302 } 257 '<div class="multi-part" id="addplugin" title="'.__('Install or upgrade manually').'">'. 258 '<h3>'.__('Add plugins from a package').'</h3>'. 259 '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>'; 260 261 $list->displayManualForm(); 262 303 263 echo 304 '</table></div>'; 305 } 306 307 $p_disabled = $core->plugins->getDisabledModules(); 308 uksort($p_disabled,create_function('$a,$b','return strcasecmp($a,$b);')); 309 if (!empty($p_disabled)) 310 { 311 echo 312 '<h3>'.__('Deactivated plugins').'</h3>'. 313 '<div class="clear table-outer">'. 314 '<table class="plugins"><tr>'. 315 '<th>'.__('Plugin').'</th>'. 316 '<th class="nowrap">'.__('Action').'</th>'. 317 '</tr>'; 318 319 foreach ($p_disabled as $k => $v) 320 { 321 $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']); 322 $is_activable = $v['root_writable']; 323 324 echo 325 '<tr class="line wide">'. 326 '<td class="maximal nowrap"><strong>'.html::escapeHTML($k).'</strong></td>'. 327 '<td class="nowrap action">'; 328 329 if ($is_deletable || $is_activable) 330 { 331 echo 332 '<form action="plugins.php" method="post">'. 333 '<div>'. 334 $core->formNonce(). 335 form::hidden(array('plugin_id'),html::escapeHTML($k)). 336 form::hidden(array('deactivated'),1). 337 ($is_activable ? '<input type="submit" name="activate" value="'.__('Activate').'" /> ' : ''). 338 ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : ''). 339 '</div>'. 340 '</form>'; 341 } 342 343 echo 344 '</td>'. 345 '</tr>'; 346 } 347 echo 348 '</table></div>'; 349 } 350 351 echo '</div>'; 352 353 # Add a new plugin 354 echo 355 '<div class="multi-part" id="addplugin" title="'.__('Install or upgrade a plugin').'">'; 356 357 if ($is_writable) 358 { 359 echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>'; 360 361 # 'Upload plugin' form 362 echo 363 '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'. 364 '<h3>'.__('Upload a zip file').'</h3>'. 365 '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file:').'</label> '. 366 '<input type="file" id="pkg_file" name="pkg_file" /></p>'. 367 '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. 368 form::password(array('your_pwd','your_pwd1'),20,255).'</p>'. 369 '<p><input type="submit" name="upload_pkg" value="'.__('Upload plugin').'" />'. 370 $core->formNonce(). 371 '</p>'. 372 '</form>'; 373 374 # 'Fetch plugin' form 375 echo 376 '<form method="post" action="plugins.php" id="fetchpkg" class="fieldset">'. 377 '<h3>'.__('Download a zip file').'</h3>'. 378 '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file URL:').'</label> '. 379 form::field(array('pkg_url','pkg_url'),40,255).'</p>'. 380 '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. 381 form::password(array('your_pwd','your_pwd2'),20,255).'</p>'. 382 '<p><input type="submit" name="fetch_pkg" value="'.__('Download plugin').'" />'. 383 $core->formNonce().'</p>'. 384 '</form>'; 385 } 386 else 387 { 388 echo 389 '<p class="static-msg">'. 390 __('To enable this function, please give write access to your plugins directory.'). 391 '</p>'; 392 } 393 echo '</div>'; 264 '</div>'; 265 } 394 266 395 267 # --BEHAVIOR-- pluginsToolsTabs 396 $core->callBehavior('pluginsToolsTabs',$core); 268 $core->callBehavior('pluginsToolsTabs', $core); 269 270 # -- Notice for super admin -- 271 if ($core->auth->isSuperAdmin() && !$list->isWritablePath()) { 272 echo 273 '<p class="warning">'.__('Some functions are disabled, please give write access to your plugins directory to enable them.').'</p>'; 274 } 397 275 398 276 dcPage::close(); 399 ?>
Note: See TracChangeset
for help on using the changeset viewer.