Dotclear

source: admin/plugins.php @ 907:da55072f8b87

Revision 907:da55072f8b87, 10.2 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Add timestamp on information message, fixes #1189

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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::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);
21unset($p_paths);
22
23$is_writable = false;
24if (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
31if ($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               $core->plugins->deactivateModule($plugin_id);
88               http::redirect('plugins.php');
89          }
90          catch (Exception $e)
91          {
92               $core->error->add($e->getMessage());
93          }
94     }
95     # Activate plugin
96     elseif ($plugin_id && !empty($_POST['activate']))
97     {
98          try
99          {
100               $p = $core->plugins->getDisabledModules();
101               if (!isset($p[$plugin_id])) {
102                    throw new Exception(__('No such plugin.'));
103               }
104               $core->plugins->activateModule($plugin_id);
105               http::redirect('plugins.php');
106          }
107          catch (Exception $e)
108          {
109               $core->error->add($e->getMessage());
110          }
111     }
112     # Plugin upload
113     elseif ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) ||
114          (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url'])))
115     {
116          try
117          {
118               if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) {
119                    throw new Exception(__('Password verification failed'));
120               }
121               
122               if (!empty($_POST['upload_pkg']))
123               {
124                    files::uploadStatus($_FILES['pkg_file']);
125                   
126                    $dest = $p_path.'/'.$_FILES['pkg_file']['name'];
127                    if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) {
128                         throw new Exception(__('Unable to move uploaded file.'));
129                    }
130               }
131               else
132               {
133                    $url = urldecode($_POST['pkg_url']);
134                    $dest = $p_path.'/'.basename($url);
135                   
136                    try
137                    {
138                         $client = netHttp::initClient($url,$path);
139                         $client->setUserAgent('Dotclear - http://www.dotclear.org/');
140                         $client->useGzip(false);
141                         $client->setPersistReferers(false);
142                         $client->setOutput($dest);
143                         $client->get($path);
144                    }
145                    catch( Exception $e)
146                    {
147                         throw new Exception(__('An error occurred while downloading the file.'));
148                    }
149                   
150                    unset($client);
151               }
152               
153               $ret_code = $core->plugins->installPackage($dest,$core->plugins);
154               http::redirect('plugins.php?added='.$ret_code);
155          }
156          catch (Exception $e)
157          {
158               $core->error->add($e->getMessage());
159               $default_tab = 'addplugin';
160          }
161     }
162}
163
164# Plugin install
165$plugins_install = $core->plugins->installModules();
166
167/* DISPLAY Main page
168-------------------------------------------------------- */
169dcPage::open(__('Plugins management'),
170     dcPage::jsLoad('js/_plugins.js').
171     dcPage::jsPageTabs($default_tab)
172);
173
174echo
175'<h2 class="page-title">'.__('Plugins management').'</h2>';
176
177if (!empty($_GET['removed'])) {
178     dcPage::message(__('Plugin has been successfully deleted.'));
179}
180if (!empty($_GET['added'])) {
181     dcPage::message(($_GET['added'] == 2 ? __('Plugin has been successfully upgraded') : __('Plugin has been successfully installed.')));
182}
183
184# Plugins install messages
185if (!empty($plugins_install['success']))
186{
187     echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
188     foreach ($plugins_install['success'] as $k => $v) {
189          echo '<li>'.$k.'</li>';
190     }
191     echo '</ul></div>';
192}
193if (!empty($plugins_install['failure']))
194{
195     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
196     foreach ($plugins_install['failure'] as $k => $v) {
197          echo '<li>'.$k.' ('.$v.')</li>';
198     }
199     echo '</ul></div>';
200}
201
202# List all active plugins
203echo '<p>'.__('Plugins add new functionalities to Dotclear. '.
204'Here you can activate or deactivate installed plugins.').'</p>';
205
206echo '<p><strong>'.sprintf(__('You can find additional plugins for your blog on %s.'),
207'<a href="http://plugins.dotaddict.org/dc2/">Dotaddict</a>').'</strong> ';
208
209if ($is_writable) {
210     echo __('To install or upgrade a plugin you generally just need to upload it '.
211     'in "Install or upgrade a plugin" section.');
212} else {
213     echo __('To install or upgrade a plugin you just need to extract it in your plugins directory.');
214}
215echo '</p>';
216
217echo
218'<div class="multi-part" id="plugins" title="'.__('Plugins').'">';
219
220$p_available = $core->plugins->getModules();
221uasort($p_available,create_function('$a,$b','return strcasecmp($a["name"],$b["name"]);'));
222if (!empty($p_available)) 
223{
224     echo
225     '<h3>'.__('Activated plugins').'</h3>'.
226     '<table class="clear plugins"><tr>'.
227     '<th>'.__('Plugin').'</th>'.
228     '<th class="nowrap">'.__('Version').'</th>'.
229     '<th class="nowrap">'.__('Details').'</th>'.
230     '<th class="nowrap">'.__('Action').'</th>'.
231     '</tr>';
232     
233     foreach ($p_available as $k => $v)
234     {
235          $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']);
236          $is_deactivable = $v['root_writable'];
237         
238          echo
239          '<tr class="line wide">'.
240          '<td class="minimal nowrap"><strong>'.html::escapeHTML($k).'</strong></td>'.
241          '<td class="minimal">'.html::escapeHTML($v['version']).'</td>'.
242          '<td class="maximal"><strong>'.html::escapeHTML($v['name']).'</strong> '.
243          '<br />'.html::escapeHTML($v['desc']).'</td>'.
244          '<td class="nowrap action">';
245         
246          if ($is_deletable || $is_deactivable)
247          {
248               echo
249               '<form action="plugins.php" method="post">'.
250               '<div>'.
251               $core->formNonce().
252               form::hidden(array('plugin_id'),html::escapeHTML($k)).
253               ($is_deactivable ? '<input type="submit" name="deactivate" value="'.__('Deactivate').'" /> ' : '').
254               ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : '').
255               '</div>'.
256               '</form>';
257          }
258         
259          echo
260          '</td>'.
261          '</tr>';
262     }
263     echo
264     '</table>';
265}
266
267$p_disabled = $core->plugins->getDisabledModules();
268uksort($p_disabled,create_function('$a,$b','return strcasecmp($a,$b);'));
269if (!empty($p_disabled))
270{
271     echo
272     '<h3>'.__('Deactivated plugins').'</h3>'.
273     '<table class="clear plugins"><tr>'.
274     '<th>'.__('Plugin').'</th>'.
275     '<th class="nowrap">'.__('Action').'</th>'.
276     '</tr>';
277     
278     foreach ($p_disabled as $k => $v)
279     {
280          $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']);
281          $is_activable = $v['root_writable'];
282         
283          echo
284          '<tr class="line wide">'.
285          '<td class="maximal nowrap"><strong>'.html::escapeHTML($k).'</strong></td>'.
286          '<td class="nowrap action">';
287         
288          if ($is_deletable || $is_activable)
289          {
290               echo
291               '<form action="plugins.php" method="post">'.
292               '<div>'.
293               $core->formNonce().
294               form::hidden(array('plugin_id'),html::escapeHTML($k)).
295               form::hidden(array('deactivated'),1).
296               ($is_activable ? '<input type="submit" name="activate" value="'.__('Activate').'" /> ' : '').
297               ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : '').
298               '</div>'.
299               '</form>';
300          }
301         
302          echo
303          '</td>'.
304          '</tr>';
305     }
306     echo
307     '</table>';
308}
309
310echo '</div>';
311
312# Add a new plugin
313echo
314'<div class="multi-part" id="addplugin" title="'.__('Install or upgrade a plugin').'">';
315
316if ($is_writable)
317{
318     echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>';
319     
320     # 'Upload plugin' form
321     echo
322     '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data">'.
323     '<fieldset>'.
324     '<legend>'.__('Upload a zip file').'</legend>'.
325     '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file:').' '.
326     '<input type="file" id="pkg_file" name="pkg_file" /></label></p>'.
327     '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '.
328     form::password(array('your_pwd','your_pwd1'),20,255).'</label></p>'.
329     '<input type="submit" name="upload_pkg" value="'.__('Upload plugin').'" />'.
330     $core->formNonce().
331     '</fieldset>'.
332     '</form>';
333     
334     # 'Fetch plugin' form
335     echo
336     '<form method="post" action="plugins.php" id="fetchpkg">'.
337     '<fieldset>'.
338     '<legend>'.__('Download a zip file').'</legend>'.
339     '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file URL:').' '.
340     form::field(array('pkg_url','pkg_url'),40,255).'</label></p>'.
341     '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '.
342     form::password(array('your_pwd','your_pwd2'),20,255).'</label></p>'.
343     '<input type="submit" name="fetch_pkg" value="'.__('Download plugin').'" />'.
344     $core->formNonce().
345     '</fieldset>'.
346     '</form>';
347}
348else
349{
350     echo
351     '<p class="static-msg">'.
352     __('To enable this function, please give write access to your plugins directory.').
353     '</p>';
354}
355echo '</div>';
356
357# --BEHAVIOR-- pluginsToolsTabs
358$core->callBehavior('pluginsToolsTabs',$core);
359
360dcPage::close();
361?>
Note: See TracBrowser for help on using the repository browser.

Sites map