Dotclear

source: admin/plugins.php @ 2158:13b49921f64a

Revision 2158:13b49921f64a, 8.4 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Déplacement du bouton reset, meilleure vue des messages et résumés de résultats.

Line 
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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('admin');
16
17# --------------------------------------------------
18# @todo Add settings to Dotclear update features
19if ($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}
24if ($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 --
46if ($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;
98if (!$core->error->flag()) {
99     $plugins_install = $core->plugins->installModules();
100}
101
102# -- Page header --
103dcPage::open(__('Plugins management'),
104     dcPage::jsLoad('js/_plugins.js').
105     dcPage::jsPageTabs().
106
107     # --BEHAVIOR-- pluginsToolsHeaders
108     $core->callBehavior('pluginsToolsHeaders', $core),
109
110     dcPage::breadcrumb(
111          array(
112               __('System') => '',
113               '<span class="page-title">'.__('Plugins management').'</span>' => ''
114          ))
115);
116
117# -- Succes messages --
118if (!empty($_GET['msg'])) {
119     $list->displayMessage($_GET['msg'],__('Plugins'));
120}
121
122# -- Plugins install messages --
123if (!empty($plugins_install['success'])) {
124     echo 
125     '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
126     foreach ($plugins_install['success'] as $k => $v) {
127          echo 
128          '<li>'.$k.'</li>';
129     }
130     echo 
131     '</ul></div>';
132}
133if (!empty($plugins_install['failure'])) {
134     echo 
135     '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
136     foreach ($plugins_install['failure'] as $k => $v) {
137          echo 
138          '<li>'.$k.' ('.$v.')</li>';
139     }
140     echo 
141     '</ul></div>';
142}
143
144# -- Display modules lists --
145if ($core->auth->isSuperAdmin() && $list->isPathWritable()) {
146
147     # Updated modules from repo
148     $modules = $repository->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 %2$s.', 'There are %s plugins to update available from %s.', count($modules)),
155               count($modules),
156               '<a href="http://dotaddict.org/dc2/plugins">Dotaddict</a>'
157          ).'</p>';
158
159          $list
160               ->newList('plugin-update')
161               ->setModules($modules)
162               ->setPageTab('update')
163               ->displayModulesList(
164                    /*cols */      array('icon', 'name', 'version', 'current_version', 'desc'),
165                    /* actions */  array('update')
166               );
167
168          echo
169          '</div>';
170     }
171}
172
173# List all active plugins
174echo
175'<div class="multi-part" id="plugins" title="'.__('Installed plugins').'">';
176
177$modules = $core->plugins->getModules();
178if (!empty($modules)) {
179
180     echo
181     '<h3>'.__('Activated plugins').'</h3>'.
182     '<p>'.__('Manage installed plugins from this list.').'</p>';
183
184     $list
185          ->newList('plugin-activate')
186          ->setModules($modules)
187          ->setPageTab('plugins')
188          ->displayModulesList(
189               /* cols */          array('expander', 'icon', 'name', 'config', 'version', 'desc', 'distrib'),
190               /* actions */  array('deactivate', 'delete')
191          );
192}
193
194# Deactivated modules
195$modules = $core->plugins->getDisabledModules();
196if (!empty($modules)) {
197
198     echo
199     '<h3>'.__('Deactivated plugins').'</h3>'.
200     '<p>'.__('Deactivated plugins are installed but not usable. You can activate them from here.').'</p>';
201
202     $list
203          ->newList('plugin-deactivate')
204          ->setModules($modules)
205          ->setPageTab('plugins')
206          ->displayModulesList(
207               /* cols */          array('icon', 'name', 'distrib'),
208               /* actions */  array('activate', 'delete')
209          );
210}
211
212echo 
213'</div>';
214
215if ($core->auth->isSuperAdmin() && $list->isPathWritable()) {
216
217     # New modules from repo
218     $search = $list->getSearchQuery();
219     $modules = $search ? $repository->search($search) : $repository->get();
220
221     echo
222     '<div class="multi-part" id="new" title="'.__('Add plugins from Dotaddict').'">'.
223     '<h3>'.__('Add plugins from Dotaddict repository').'</h3>';
224
225     $list
226          ->newList('plugin-new')
227          ->setModules($modules)
228          ->setPageTab('new')
229          ->displaySearchForm()
230          ->displayNavMenu()
231          ->displayModulesList(
232               /* cols */          array('expander', 'name', 'version', 'desc'),
233               /* actions */  array('install'),
234               /* nav limit */     true
235          );
236
237     echo
238     '<p class="info vertical-separator">'.sprintf(
239          __("Visit %s repository, the resources center for Dotclear."),
240          '<a href="http://dotaddict.org/dc2/plugins">Dotaddict</a>'
241          ).
242     '</p>'.
243
244     '</div>';
245
246     # Add a new plugin
247     echo
248     '<div class="multi-part" id="addplugin" title="'.__('Install or upgrade manually').'">';
249
250     echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>';
251     
252     # 'Upload plugin' form
253     echo
254     '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'.
255     '<h4>'.__('Upload a zip file').'</h4>'.
256     '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file:').'</label> '.
257     '<input type="file" id="pkg_file" name="pkg_file" /></p>'.
258     '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
259     form::password(array('your_pwd','your_pwd1'),20,255).'</p>'.
260     '<p><input type="submit" name="upload_pkg" value="'.__('Upload plugin').'" />'.
261     $core->formNonce().
262     '</p>'.
263     '</form>';
264     
265     # 'Fetch plugin' form
266     echo
267     '<form method="post" action="plugins.php" id="fetchpkg" class="fieldset">'.
268     '<h4>'.__('Download a zip file').'</h4>'.
269     '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file URL:').'</label> '.
270     form::field(array('pkg_url','pkg_url'),40,255).'</p>'.
271     '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
272     form::password(array('your_pwd','your_pwd2'),20,255).'</p>'.
273     '<p><input type="submit" name="fetch_pkg" value="'.__('Download plugin').'" />'.
274     $core->formNonce().'</p>'.
275     '</form>';
276
277     echo
278     '</div>';
279}
280
281# --BEHAVIOR-- pluginsToolsTabs
282$core->callBehavior('pluginsToolsTabs', $core);
283
284# -- Notice for super admin --
285if ($core->auth->isSuperAdmin() && !$list->isPathWritable()) {
286     echo 
287     '<p class="warning">'.__('Some functions are disabled, please give write access to your plugins directory to enable them.').'</p>';
288}
289
290dcPage::close();
291?>
Note: See TracBrowser for help on using the repository browser.

Sites map