Dotclear

source: plugins/dcAdvancedCleaner/inc/lib.dc.advanced.cleaner.behaviors.php @ 2199

Revision 2199, 5.7 KB checked in by JcDenis, 13 years ago (diff)

dcAdvancedCleaner 0.4:

  • Fixed list of tables (closes #440)
  • Fixed direct uninstaller
  • Added readable errors return
  • Added DC 2.2 compatibility (new settings)
  • Changed admin design
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of dcAdvancedCleaner, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009-2010 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13if (!defined('DC_ADMIN_CONTEXT')){return;}
14
15class behaviorsDcAdvancedCleaner
16{
17     public static function pluginsBeforeDelete($plugin)
18     {
19          self::moduleBeforeDelete($plugin,'plugins.php?removed=1');
20     }
21
22     public static function themeBeforeDelete($theme)
23     {
24          self::moduleBeforeDelete($theme,'blog_theme.php?del=1');
25     }
26
27     # Generic module before delete
28     public static function moduleBeforeDelete($module,$redir)
29     {
30          global $core;
31          $done = false;
32
33          $s = dcAdvancedCleanerSettings($core);
34          if (!$s->dcAdvancedCleaner_behavior_active) return;
35
36          $uninstaller = new dcUninstaller($core);
37          $uninstaller->loadModule($module['root']);
38
39          $m_callbacks = $uninstaller->getDirectCallbacks($module['id']);
40          $m_actions = $uninstaller->getDirectActions($module['id']);
41
42          foreach($m_callbacks as $k => $callback)
43          {
44               if (!isset($callback['func']) || !is_callable($callback['func'])) continue;
45
46               call_user_func($callback['func'],$module);
47               $done = true;
48          }
49
50          foreach($m_actions as $type => $actions)
51          {
52               foreach($actions as $v)
53               {
54                    $uninstaller->execute($type,$v['action'],$v['ns']);
55                    $done = true;
56               }
57          }
58
59          if ($done) {
60               http::redirect($redir);
61          }
62     }
63
64     public static function dcAdvancedCleanerAdminTabs($core,$p_url)
65     {
66          self::modulesTabs($core,DC_PLUGINS_ROOT,$p_url.'&tab=uninstaller');
67     }
68
69     public static function pluginsToolsTabs($core)
70     {
71          self::modulesTabs($core,DC_PLUGINS_ROOT,'plugins.php?tab=uninstaller');
72     }
73
74     # Generic module tabs
75     public static function modulesTabs($core,$path,$redir,$title='')
76     {
77          $s = dcAdvancedCleanerSettings($core);
78          if (!$s->dcadvancedcleaner_behavior_active) return;
79
80          $err = '';
81          $title = empty($title) ? __('Advanced uninstall') : $title;
82
83          $uninstaller = new dcUninstaller($core);
84          $uninstaller->loadModules($path);
85          $modules = $uninstaller->getModules();
86          $props = $uninstaller->getAllowedProperties();
87
88          # Execute
89          if (isset($_POST['action']) && $_POST['action'] == 'uninstall'
90          && (!empty($_POST['extras']) || !empty($_POST['actions']))) {
91
92               try {
93                    # Extras
94                    if (!empty($_POST['extras'])) {
95                         foreach($_POST['extras'] as $module_id => $extras)
96                         {
97                              foreach($extras as $k => $sentence)
98                              {
99                                   $extra = @unserialize(@base64_decode($sentence));
100
101                                   if (!$extra || !is_callable($extra)) continue;
102
103                                   call_user_func($extra,$modul_id);
104                              }
105                         }
106                    }
107                    # Actions
108                    if (!empty($_POST['actions'])) {
109                         foreach($_POST['actions'] as $module_id => $actions)
110                         {
111                              foreach($actions as $k => $sentence)
112                              {
113                                   $action = @unserialize(@base64_decode($sentence));
114
115                                   if (!$action 
116                                    || !isset($action['type']) 
117                                    || !isset($action['action']) 
118                                    || !isset($action['ns'])) continue;
119
120                                   $uninstaller->execute($action['type'],$action['action'],$action['ns']);
121                              }
122                         }
123                    }
124                    http::redirect($redir.'&msg=1');
125               }
126               catch(Exception $e) {
127                    $err = $e->getMessage();
128               }
129          }
130
131          echo 
132          '<div class="multi-part" id="uninstaller" title="'.__($title).'">';
133
134          if($err)
135               echo '<p class="error">'.$err.'</p>';
136
137          if(!count($modules)) {
138               echo '<p>'.__('There is no module with uninstall features').'</p></div>';
139               return;
140          }
141
142          echo
143          '<p>'.__('List of modules with advanced uninstall features').'</p>'.
144          '<form method="post" action="'.$redir.'">'.
145          '<table class="clear"><tr>'.
146          '<th>'.__('Id').'</th>'.
147          '<th>'.__('Module').'</th>';
148         
149          foreach($props as $pro_id => $prop) {
150               echo '<th>'.__($pro_id).'</th>';
151          }
152
153          echo 
154          '<th>'.__('extra').'</th>'.
155          '</tr>';
156
157          $i = 0;
158          foreach($modules as $module_id => $module) {
159
160               echo
161               '<tr class="line">'.
162               '<td class="nowrap">'.$module_id.'</td>'.
163               '<td class="maximal nowrap">'.$module['name'].' '.$module['version'].'</td>';
164
165               $actions = $uninstaller->getUserActions($module_id);
166
167               foreach($props as $prop_id => $prop) {
168                    echo '<td class="nowrap">';
169
170                    if (!isset($actions[$prop_id])) {
171                         echo '--</td>';
172                         continue;
173                    }
174
175                    $j = 0;
176                    foreach($actions[$prop_id] as $action_id => $action) {
177
178                         if (!isset($props[$prop_id][$action['action']])) continue;
179
180                         $ret = base64_encode(serialize(array(
181                              'type' => $prop_id,
182                              'action'=>$action['action'],
183                              'ns'=>$action['ns']
184                         )));
185
186                         echo '<label class="classic">'.
187                         form::checkbox(array('actions['.$module_id.']['.$j.']'),$ret).
188                         ' '.$action['desc'].'</label><br />';
189
190                         $j++;
191                    }
192                    echo '</td>';
193               }
194
195               echo '<td class="nowrap">';
196
197               $callbacks = $uninstaller->getUserCallbacks($module_id);
198
199               if (empty($callbacks)) {
200                    echo '--';
201               }
202
203               $k = 0;
204               foreach($callbacks as $callback_id => $callback) {
205
206                    $ret = base64_encode(serialize($callback['func']));
207
208                    echo '<label class="classic">'.
209                    form::checkbox(array('extras['.$module_id.']['.$k.']'),$ret).
210                    ' '.$callback['desc'].'</label><br />';
211               }
212
213               echo '</td></tr>';
214          }
215          echo 
216          '</table>'.
217          '<p>'.
218          $core->formNonce().
219          form::hidden(array('redir'),$redir).
220          form::hidden(array('action'),'uninstall').
221          '<input type="submit" name="submit" value="'.__('Perform selected actions').'" /> '.
222          '</p>'.
223          '</form>'.
224          '</div>';
225     }
226}
227?>
Note: See TracBrowser for help on using the repository browser.

Sites map