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