| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
|---|
| 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::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 | |
|---|
| 48 | # Plugin upload |
|---|
| 49 | if ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) || |
|---|
| 50 | (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url']))) |
|---|
| 51 | { |
|---|
| 52 | try |
|---|
| 53 | { |
|---|
| 54 | if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY, $_POST['your_pwd']))) { |
|---|
| 55 | throw new Exception(__('Password verification failed')); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | if (!empty($_POST['upload_pkg'])) { |
|---|
| 59 | files::uploadStatus($_FILES['pkg_file']); |
|---|
| 60 | |
|---|
| 61 | $dest = $list->getPath().'/'.$_FILES['pkg_file']['name']; |
|---|
| 62 | if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'], $dest)) { |
|---|
| 63 | throw new Exception(__('Unable to move uploaded file.')); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | else { |
|---|
| 67 | $url = urldecode($_POST['pkg_url']); |
|---|
| 68 | $dest = $list->getPath().'/'.basename($url); |
|---|
| 69 | $repository->download($url, $dest); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | # --BEHAVIOR-- pluginBeforeAdd |
|---|
| 73 | $core->callBehavior('pluginsBeforeAdd', $plugin_id); |
|---|
| 74 | |
|---|
| 75 | $ret_code = $core->plugins->installPackage($dest, $core->plugins); |
|---|
| 76 | |
|---|
| 77 | # --BEHAVIOR-- pluginAfterAdd |
|---|
| 78 | $core->callBehavior('pluginsAfterAdd', $plugin_id); |
|---|
| 79 | |
|---|
| 80 | http::redirect('plugins.php?msg='.($ret_code == 2 ? 'update' : 'install').'#plugins'); |
|---|
| 81 | } |
|---|
| 82 | catch (Exception $e) { |
|---|
| 83 | $core->error->add($e->getMessage()); |
|---|
| 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 -- |
|---|
| 103 | dcPage::open(__('Plugins management'), |
|---|
| 104 | dcPage::jsLoad('js/_plugins.js'). |
|---|
| 105 | dcPage::jsPageTabs(). |
|---|
| 106 | $core->callBehavior('pluginsToolsHeaders', $core), |
|---|
| 107 | dcPage::breadcrumb( |
|---|
| 108 | array( |
|---|
| 109 | __('System') => '', |
|---|
| 110 | '<span class="page-title">'.__('Plugins management').'</span>' => '' |
|---|
| 111 | )) |
|---|
| 112 | ); |
|---|
| 113 | |
|---|
| 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>'; |
|---|
| 123 | foreach ($plugins_install['success'] as $k => $v) { |
|---|
| 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>'; |
|---|
| 133 | foreach ($plugins_install['failure'] as $k => $v) { |
|---|
| 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 | } |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | # List all active plugins |
|---|
| 170 | echo |
|---|
| 171 | '<div class="multi-part" id="plugins" title="'.__('Installed plugins').'">'; |
|---|
| 172 | |
|---|
| 173 | $modules = $core->plugins->getModules(); |
|---|
| 174 | if (!empty($modules)) { |
|---|
| 175 | |
|---|
| 176 | echo |
|---|
| 177 | '<h3>'.__('Activated plugins').'</h3>'. |
|---|
| 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 | |
|---|
| 193 | echo |
|---|
| 194 | '<h3>'.__('Deactivated plugins').'</h3>'. |
|---|
| 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 | |
|---|
| 241 | echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>'; |
|---|
| 242 | |
|---|
| 243 | # 'Upload plugin' form |
|---|
| 244 | echo |
|---|
| 245 | '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'. |
|---|
| 246 | '<h4>'.__('Upload a zip file').'</h4>'. |
|---|
| 247 | '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file:').'</label> '. |
|---|
| 248 | '<input type="file" id="pkg_file" name="pkg_file" /></p>'. |
|---|
| 249 | '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. |
|---|
| 250 | form::password(array('your_pwd','your_pwd1'),20,255).'</p>'. |
|---|
| 251 | '<p><input type="submit" name="upload_pkg" value="'.__('Upload plugin').'" />'. |
|---|
| 252 | $core->formNonce(). |
|---|
| 253 | '</p>'. |
|---|
| 254 | '</form>'; |
|---|
| 255 | |
|---|
| 256 | # 'Fetch plugin' form |
|---|
| 257 | echo |
|---|
| 258 | '<form method="post" action="plugins.php" id="fetchpkg" class="fieldset">'. |
|---|
| 259 | '<h4>'.__('Download a zip file').'</h4>'. |
|---|
| 260 | '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file URL:').'</label> '. |
|---|
| 261 | form::field(array('pkg_url','pkg_url'),40,255).'</p>'. |
|---|
| 262 | '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. |
|---|
| 263 | form::password(array('your_pwd','your_pwd2'),20,255).'</p>'. |
|---|
| 264 | '<p><input type="submit" name="fetch_pkg" value="'.__('Download plugin').'" />'. |
|---|
| 265 | $core->formNonce().'</p>'. |
|---|
| 266 | '</form>'; |
|---|
| 267 | |
|---|
| 268 | echo |
|---|
| 269 | '</div>'; |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | # --BEHAVIOR-- pluginsToolsTabs |
|---|
| 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 | } |
|---|
| 280 | |
|---|
| 281 | dcPage::close(); |
|---|
| 282 | ?> |
|---|