Dotclear

source: admin/plugins.php @ 2163:d41b59b0ae2e

Revision 2163:d41b59b0ae2e, 10.3 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Move maintenance configuration to the new plugins configurator

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
46# -- Check for module configuration --
47$conf_file = false;
48if (!empty($_REQUEST['conf']) && !empty($_REQUEST['module'])) {
49     if (!$core->plugins->moduleExists($_REQUEST['module'])) {
50          $core->error->add(__('Unknow module ID'));
51     }
52     else {
53          $module = $core->plugins->getModules($_REQUEST['module']);
54          $module = adminModulesList::setModuleInfo($_REQUEST['module'], $module);
55
56          if (!file_exists(path::real($module['root'].'/_config.php'))) {
57               $core->error->add(__('This module has no configuration file.'));
58          }
59          else {
60               $conf_file = path::real($module['root'].'/_config.php');
61          }
62     }
63}
64
65# -- Display module configuration page --
66if ($conf_file) {
67     dcPage::open(__('Plugins management'),
68
69          # --BEHAVIOR-- pluginsToolsHeaders
70          $core->callBehavior('pluginsToolsHeaders', $core, $module['id']),
71
72          dcPage::breadcrumb(
73               array(
74                    html::escapeHTML($core->blog->name) => '',
75                    '<a href="'.$list->getPageURL().'">'.__('Plugins management').'</a>' => '',
76                    '<span class="page-title">'.__('Plugin configuration').'</span>' => ''
77               ))
78     );
79
80     if (!empty($_GET['done'])){
81          dcPage::success(__('Plugin successfully configured.'));
82     }
83
84     try {
85          if (!$module['standalone_config']) {
86               echo
87               '<form id="module_config" action="'.$list->getPageURL('conf=1').'" method="post" enctype="multipart/form-data">'.
88               '<h3>'.sprintf(__('Configure plugin "%s"'), html::escapeHTML($module['name'])).'</h3>'.
89               '<p><a class="back" href="'.$list->getPageURL().'#plugins">'.__('Back').'</a></p>';
90          }
91
92          include $conf_file;
93
94          if (!$module['standalone_config']) {
95               echo
96               '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'.
97               form::hidden('module', $module['id']).
98               $core->formNonce().'</p>'.
99               '</form>';
100          }
101     }
102     catch (Exception $e) {
103          echo '<div class="error"><p>'.$e->getMessage().'</p></div>';
104     }
105
106     dcPage::close();
107
108     # Stop reading code here
109     return;
110}
111
112# -- Execute actions --
113if (empty($_POST['conf']) && $core->auth->isSuperAdmin() && $list->isPathWritable()) {
114
115     # Plugin upload
116     if ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) ||
117          (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url'])))
118     {
119          try
120          {
121               if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY, $_POST['your_pwd']))) {
122                    throw new Exception(__('Password verification failed'));
123               }
124               
125               if (!empty($_POST['upload_pkg'])) {
126                    files::uploadStatus($_FILES['pkg_file']);
127                   
128                    $dest = $list->getPath().'/'.$_FILES['pkg_file']['name'];
129                    if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'], $dest)) {
130                         throw new Exception(__('Unable to move uploaded file.'));
131                    }
132               }
133               else {
134                    $url = urldecode($_POST['pkg_url']);
135                    $dest = $list->getPath().'/'.basename($url);
136                    $repository->download($url, $dest);
137               }
138
139               # --BEHAVIOR-- pluginBeforeAdd
140               $core->callBehavior('pluginsBeforeAdd', $plugin_id);
141                             
142               $ret_code = $core->plugins->installPackage($dest, $core->plugins);
143
144               # --BEHAVIOR-- pluginAfterAdd
145               $core->callBehavior('pluginsAfterAdd', $plugin_id);
146               
147               http::redirect('plugins.php?msg='.($ret_code == 2 ? 'update' : 'install').'#plugins');
148          }
149          catch (Exception $e) {
150               $core->error->add($e->getMessage());
151          }
152     }
153     elseif (!empty($_POST['module'])) {
154          try {
155               $list->executeAction('plugins', $core->plugins, $repository);
156          }
157          catch (Exception $e) {
158               $core->error->add($e->getMessage());
159          }
160     }
161}
162
163# -- Plugin install --
164$plugins_install = null;
165if (!$core->error->flag()) {
166     $plugins_install = $core->plugins->installModules();
167}
168
169# -- Page header --
170dcPage::open(__('Plugins management'),
171     dcPage::jsLoad('js/_plugins.js').
172     dcPage::jsPageTabs().
173
174     # --BEHAVIOR-- pluginsToolsHeaders
175     $core->callBehavior('pluginsToolsHeaders', $core, false),
176
177     dcPage::breadcrumb(
178          array(
179               __('System') => '',
180               '<span class="page-title">'.__('Plugins management').'</span>' => ''
181          ))
182);
183
184# -- Succes messages --
185if (!empty($_GET['msg'])) {
186     $list->displayMessage($_GET['msg'],__('Plugins'));
187}
188
189# -- Plugins install messages --
190if (!empty($plugins_install['success'])) {
191     echo 
192     '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
193     foreach ($plugins_install['success'] as $k => $v) {
194          echo 
195          '<li>'.$k.'</li>';
196     }
197     echo 
198     '</ul></div>';
199}
200if (!empty($plugins_install['failure'])) {
201     echo 
202     '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
203     foreach ($plugins_install['failure'] as $k => $v) {
204          echo 
205          '<li>'.$k.' ('.$v.')</li>';
206     }
207     echo 
208     '</ul></div>';
209}
210
211# -- Display modules lists --
212if ($core->auth->isSuperAdmin() && $list->isPathWritable()) {
213
214     # Updated modules from repo
215     $modules = $repository->get(true);
216     if (!empty($modules)) {
217          echo 
218          '<div class="multi-part" id="update" title="'.html::escapeHTML(__('Update plugins')).'">'.
219          '<h3>'.html::escapeHTML(__('Update plugins')).'</h3>'.
220          '<p>'.sprintf(
221               __('There is one plugin to update available from %2$s.', 'There are %s plugins to update available from %s.', count($modules)),
222               count($modules),
223               '<a href="http://dotaddict.org/dc2/plugins">Dotaddict</a>'
224          ).'</p>';
225
226          $list
227               ->newList('plugin-update')
228               ->setModules($modules)
229               ->setPageTab('update')
230               ->displayModulesList(
231                    /*cols */      array('icon', 'name', 'version', 'current_version', 'desc'),
232                    /* actions */  array('update')
233               );
234
235          echo
236          '</div>';
237     }
238}
239
240# List all active plugins
241echo
242'<div class="multi-part" id="plugins" title="'.__('Installed plugins').'">';
243
244$modules = $core->plugins->getModules();
245if (!empty($modules)) {
246
247     echo
248     '<h3>'.__('Activated plugins').'</h3>'.
249     '<p>'.__('Manage installed plugins from this list.').'</p>';
250
251     $list
252          ->newList('plugin-activate')
253          ->setModules($modules)
254          ->setPageTab('plugins')
255          ->displayModulesList(
256               /* cols */          array('expander', 'icon', 'name', 'config', 'version', 'desc', 'distrib'),
257               /* actions */  array('deactivate', 'delete')
258          );
259}
260
261# Deactivated modules
262$modules = $core->plugins->getDisabledModules();
263if (!empty($modules)) {
264
265     echo
266     '<h3>'.__('Deactivated plugins').'</h3>'.
267     '<p>'.__('Deactivated plugins are installed but not usable. You can activate them from here.').'</p>';
268
269     $list
270          ->newList('plugin-deactivate')
271          ->setModules($modules)
272          ->setPageTab('plugins')
273          ->displayModulesList(
274               /* cols */          array('icon', 'name', 'distrib'),
275               /* actions */  array('activate', 'delete')
276          );
277}
278
279echo 
280'</div>';
281
282if ($core->auth->isSuperAdmin() && $list->isPathWritable()) {
283
284     # New modules from repo
285     $search = $list->getSearchQuery();
286     $modules = $search ? $repository->search($search) : $repository->get();
287
288     echo
289     '<div class="multi-part" id="new" title="'.__('Add plugins from Dotaddict').'">'.
290     '<h3>'.__('Add plugins from Dotaddict repository').'</h3>';
291
292     $list
293          ->newList('plugin-new')
294          ->setModules($modules)
295          ->setPageTab('new')
296          ->displaySearchForm()
297          ->displayNavMenu()
298          ->displayModulesList(
299               /* cols */          array('expander', 'name', 'version', 'desc'),
300               /* actions */  array('install'),
301               /* nav limit */     true
302          );
303
304     echo
305     '<p class="info vertical-separator">'.sprintf(
306          __("Visit %s repository, the resources center for Dotclear."),
307          '<a href="http://dotaddict.org/dc2/plugins">Dotaddict</a>'
308          ).
309     '</p>'.
310
311     '</div>';
312
313     # Add a new plugin
314     echo
315     '<div class="multi-part" id="addplugin" title="'.__('Install or upgrade manually').'">';
316
317     echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>';
318     
319     # 'Upload plugin' form
320     echo
321     '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'.
322     '<h4>'.__('Upload a zip file').'</h4>'.
323     '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file:').'</label> '.
324     '<input type="file" id="pkg_file" name="pkg_file" /></p>'.
325     '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
326     form::password(array('your_pwd','your_pwd1'),20,255).'</p>'.
327     '<p><input type="submit" name="upload_pkg" value="'.__('Upload plugin').'" />'.
328     $core->formNonce().
329     '</p>'.
330     '</form>';
331     
332     # 'Fetch plugin' form
333     echo
334     '<form method="post" action="plugins.php" id="fetchpkg" class="fieldset">'.
335     '<h4>'.__('Download a zip file').'</h4>'.
336     '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file URL:').'</label> '.
337     form::field(array('pkg_url','pkg_url'),40,255).'</p>'.
338     '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
339     form::password(array('your_pwd','your_pwd2'),20,255).'</p>'.
340     '<p><input type="submit" name="fetch_pkg" value="'.__('Download plugin').'" />'.
341     $core->formNonce().'</p>'.
342     '</form>';
343
344     echo
345     '</div>';
346}
347
348# --BEHAVIOR-- pluginsToolsTabs
349$core->callBehavior('pluginsToolsTabs', $core);
350
351# -- Notice for super admin --
352if ($core->auth->isSuperAdmin() && !$list->isPathWritable()) {
353     echo 
354     '<p class="warning">'.__('Some functions are disabled, please give write access to your plugins directory to enable them.').'</p>';
355}
356
357dcPage::close();
358?>
Note: See TracBrowser for help on using the repository browser.

Sites map