Dotclear

source: admin/plugins.php @ 456:f55f02550402

Revision 456:f55f02550402, 10.5 KB checked in by Tomtom33 <tbouron@…>, 14 years ago (diff)

Fixed tables in admin pages - step 1, addresses #1068,#1069

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 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>'.__('Plugins management').'</h2>';
176
177if (!empty($_GET['removed'])) {
178     echo
179     '<p class="message">'.__('Plugin has been successfully deleted.').'</p>';
180}
181if (!empty($_GET['added'])) {
182     echo '<p class="message">'.
183     ($_GET['added'] == 2 ? __('Plugin has been successfully upgraded') : __('Plugin has been successfully installed.')).
184     '</p>';
185}
186
187# Plugins install messages
188if (!empty($plugins_install['success']))
189{
190     echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
191     foreach ($plugins_install['success'] as $k => $v) {
192          echo '<li>'.$k.'</li>';
193     }
194     echo '</ul></div>';
195}
196if (!empty($plugins_install['failure']))
197{
198     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
199     foreach ($plugins_install['failure'] as $k => $v) {
200          echo '<li>'.$k.' ('.$v.')</li>';
201     }
202     echo '</ul></div>';
203}
204
205# List all active plugins
206echo '<p>'.__('Plugins add new functionalities to Dotclear. '.
207'Here you can activate or deactivate installed plugins.').'</p>';
208
209echo '<p><strong>'.sprintf(__('You can find additional plugins for your blog on %s.'),
210'<a href="http://plugins.dotaddict.org/dc2/">Dotaddict</a>').'</strong> ';
211
212if ($is_writable) {
213     echo __('To install or upgrade a plugin you generally just need to upload it '.
214     'in "Install or upgrade a plugin" section.');
215} else {
216     echo __('To install or upgrade a plugin you just need to extract it in your plugins directory.');
217}
218echo '</p>';
219
220echo
221'<div class="multi-part" id="plugins" title="'.__('Plugins').'">';
222
223$p_available = $core->plugins->getModules();
224uasort($p_available,create_function('$a,$b','return strcasecmp($a["name"],$b["name"]);'));
225if (!empty($p_available)) 
226{
227     echo
228     '<h3>'.__('Activated plugins').'</h3>'.
229     '<table class="clear plugins">'.
230     '<caption>'.__('Activated plugin list').'</caption>'.
231     '<thead><tr>'.
232     '<th scope="col">'.__('Plugin').'</th>'.
233     '<th scope="col" class="nowrap">'.__('Version').'</th>'.
234     '<th scope="col" class="nowrap">'.__('Details').'</th>'.
235     '<th scope="col" class="nowrap">'.__('Action').'</th>'.
236     '</tr></thead>'.
237     '<tbody>';
238     
239     foreach ($p_available as $k => $v)
240     {
241          $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']);
242          $is_deactivable = $v['root_writable'];
243         
244          echo
245          '<tr class="line wide">'.
246          '<th scope="row" class="minimal nowrap"><strong>'.html::escapeHTML($k).'</strong></th>'.
247          '<td class="minimal">'.html::escapeHTML($v['version']).'</td>'.
248          '<td class="maximal"><strong>'.html::escapeHTML($v['name']).'</strong> '.
249          '<br />'.html::escapeHTML($v['desc']).'</td>'.
250          '<td class="nowrap action">';
251         
252          if ($is_deletable || $is_deactivable)
253          {
254               echo
255               '<form action="plugins.php" method="post">'.
256               '<div>'.
257               $core->formNonce().
258               form::hidden(array('plugin_id'),html::escapeHTML($k)).
259               ($is_deactivable ? '<input type="submit" name="deactivate" value="'.__('Deactivate').'" /> ' : '').
260               ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : '').
261               '</div>'.
262               '</form>';
263          }
264         
265          echo
266          '</td>'.
267          '</tr>';
268     }
269     echo
270     '</tbody>'.
271     '</table>';
272}
273
274$p_disabled = $core->plugins->getDisabledModules();
275uksort($p_disabled,create_function('$a,$b','return strcasecmp($a,$b);'));
276if (!empty($p_disabled))
277{
278     echo
279     '<h3>'.__('Deactivated plugins').'</h3>'.
280     '<table class="clear plugins">'.
281     '<caption>'.__('Deactivated plugin list').'</caption>'.
282     '<thead><tr>'.
283     '<th scope="col">'.__('Plugin').'</th>'.
284     '<th scope="col" class="nowrap">'.__('Action').'</th>'.
285     '</tr></thead>'.
286     '<tbody>';
287     
288     foreach ($p_disabled as $k => $v)
289     {
290          $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']);
291          $is_activable = $v['root_writable'];
292         
293          echo
294          '<tr class="line wide">'.
295          '<th scope="row" class="maximal nowrap"><strong>'.html::escapeHTML($k).'</strong></th>'.
296          '<td class="nowrap action">';
297         
298          if ($is_deletable || $is_activable)
299          {
300               echo
301               '<form action="plugins.php" method="post">'.
302               '<div>'.
303               $core->formNonce().
304               form::hidden(array('plugin_id'),html::escapeHTML($k)).
305               form::hidden(array('deactivated'),1).
306               ($is_activable ? '<input type="submit" name="activate" value="'.__('Activate').'" /> ' : '').
307               ($is_deletable ? '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" /> ' : '').
308               '</div>'.
309               '</form>';
310          }
311         
312          echo
313          '</td>'.
314          '</tr>';
315     }
316     echo
317     '</tbody>'.
318     '</table>';
319}
320
321echo '</div>';
322
323# Add a new plugin
324echo
325'<div class="multi-part" id="addplugin" title="'.__('Install or upgrade a plugin').'">';
326
327if ($is_writable)
328{
329     echo '<p>'.__('You can install plugins by uploading or downloading zip files.').'</p>';
330     
331     # 'Upload plugin' form
332     echo
333     '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data">'.
334     '<fieldset>'.
335     '<legend>'.__('Upload a zip file').'</legend>'.
336     '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file:').' '.
337     '<input type="file" id="pkg_file" name="pkg_file" /></label></p>'.
338     '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '.
339     form::password(array('your_pwd','your_pwd1'),20,255).'</label></p>'.
340     '<input type="submit" name="upload_pkg" value="'.__('Upload plugin').'" />'.
341     $core->formNonce().
342     '</fieldset>'.
343     '</form>';
344     
345     # 'Fetch plugin' form
346     echo
347     '<form method="post" action="plugins.php" id="fetchpkg">'.
348     '<fieldset>'.
349     '<legend>'.__('Download a zip file').'</legend>'.
350     '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Plugin zip file URL:').' '.
351     form::field(array('pkg_url','pkg_url'),40,255).'</label></p>'.
352     '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').' '.
353     form::password(array('your_pwd','your_pwd2'),20,255).'</label></p>'.
354     '<input type="submit" name="fetch_pkg" value="'.__('Download plugin').'" />'.
355     $core->formNonce().
356     '</fieldset>'.
357     '</form>';
358}
359else
360{
361     echo
362     '<p class="static-msg">'.
363     __('To enable this function, please give write access to your plugins directory.').
364     '</p>';
365}
366echo '</div>';
367
368# --BEHAVIOR-- pluginsToolsTabs
369$core->callBehavior('pluginsToolsTabs',$core);
370
371dcPage::close();
372?>
Note: See TracBrowser for help on using the repository browser.

Sites map