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 | |
---|
13 | if (!defined('DC_ADMIN_CONTEXT')){return;} |
---|
14 | |
---|
15 | class 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 | if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) return; |
---|
34 | |
---|
35 | $uninstaller = new dcUninstaller($core); |
---|
36 | $uninstaller->loadModule($module['root']); |
---|
37 | |
---|
38 | $m_callbacks = $uninstaller->getDirectCallbacks($module['id']); |
---|
39 | $m_actions = $uninstaller->getDirectActions($module['id']); |
---|
40 | |
---|
41 | foreach($m_callbacks as $k => $callback) |
---|
42 | { |
---|
43 | if (!isset($callback['func']) || !is_callable($callback['func'])) continue; |
---|
44 | |
---|
45 | call_user_func($callback['func'],$module); |
---|
46 | $done = true; |
---|
47 | } |
---|
48 | |
---|
49 | foreach($m_actions as $type => $actions) |
---|
50 | { |
---|
51 | foreach($actions as $v) |
---|
52 | { |
---|
53 | $uninstaller->execute($type,$v['action'],$v['ns']); |
---|
54 | $done = true; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | if ($done) { |
---|
59 | http::redirect($redir); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | public static function dcAdvancedCleanerAdminTabs($core,$p_url) |
---|
64 | { |
---|
65 | self::modulesTabs($core,DC_PLUGINS_ROOT,$p_url.'&tab=uninstaller'); |
---|
66 | } |
---|
67 | |
---|
68 | public static function pluginsToolsTabs($core) |
---|
69 | { |
---|
70 | self::modulesTabs($core,DC_PLUGINS_ROOT,'plugins.php?tab=uninstaller'); |
---|
71 | } |
---|
72 | |
---|
73 | # Generic module tabs |
---|
74 | public static function modulesTabs($core,$path,$redir,$title='') |
---|
75 | { |
---|
76 | if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) return; |
---|
77 | |
---|
78 | $err = ''; |
---|
79 | $title = empty($title) ? __('Advanced uninstall') : $title; |
---|
80 | |
---|
81 | $uninstaller = new dcUninstaller($core); |
---|
82 | $uninstaller->loadModules($path); |
---|
83 | $modules = $uninstaller->getModules(); |
---|
84 | $props = $uninstaller->getAllowedProperties(); |
---|
85 | |
---|
86 | # Execute |
---|
87 | if (isset($_POST['action']) && $_POST['action'] == 'uninstall' |
---|
88 | && (!empty($_POST['extras']) || !empty($_POST['actions']))) { |
---|
89 | |
---|
90 | try { |
---|
91 | # Extras |
---|
92 | if (!empty($_POST['extras'])) { |
---|
93 | foreach($_POST['extras'] as $module_id => $extras) |
---|
94 | { |
---|
95 | foreach($extras as $k => $sentence) |
---|
96 | { |
---|
97 | $extra = @unserialize(@base64_decode($sentence)); |
---|
98 | |
---|
99 | if (!$extra || !is_callable($extra)) continue; |
---|
100 | |
---|
101 | call_user_func($extra,$modul_id); |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | # Actions |
---|
106 | if (!empty($_POST['actions'])) { |
---|
107 | foreach($_POST['actions'] as $module_id => $actions) |
---|
108 | { |
---|
109 | foreach($actions as $k => $sentence) |
---|
110 | { |
---|
111 | $action = @unserialize(@base64_decode($sentence)); |
---|
112 | |
---|
113 | if (!$action |
---|
114 | || !isset($action['type']) |
---|
115 | || !isset($action['action']) |
---|
116 | || !isset($action['ns'])) continue; |
---|
117 | |
---|
118 | $uninstaller->execute($action['type'],$action['action'],$action['ns']); |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|
122 | http::redirect($redir.'&msg=1'); |
---|
123 | } |
---|
124 | catch(Exception $e) { |
---|
125 | $err = $e->getMessage(); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | echo |
---|
130 | '<div class="multi-part" id="uninstaller" title="'.__($title).'">'; |
---|
131 | |
---|
132 | if($err) |
---|
133 | echo '<p class="error">'.$err.'</p>'; |
---|
134 | |
---|
135 | if(!count($modules)) { |
---|
136 | echo '<p>'.__('There is no module with uninstall features').'</p></div>'; |
---|
137 | return; |
---|
138 | } |
---|
139 | |
---|
140 | echo |
---|
141 | '<p>'.__('List of modules with advanced uninstall features').'</p>'. |
---|
142 | '<form method="post" action="'.$redir.'">'. |
---|
143 | '<table class="clear"><tr>'. |
---|
144 | '<th>'.__('Id').'</th>'. |
---|
145 | '<th>'.__('Module').'</th>'; |
---|
146 | |
---|
147 | foreach($props as $pro_id => $prop) { |
---|
148 | echo '<th>'.__($pro_id).'</th>'; |
---|
149 | } |
---|
150 | |
---|
151 | echo |
---|
152 | '<th>'.__('extra').'</th>'. |
---|
153 | '</tr>'; |
---|
154 | |
---|
155 | $i = 0; |
---|
156 | foreach($modules as $module_id => $module) { |
---|
157 | |
---|
158 | echo |
---|
159 | '<tr class="line">'. |
---|
160 | '<td class="nowrap">'.$module_id.'</td>'. |
---|
161 | '<td class="maximal nowrap">'.$module['name'].' '.$module['version'].'</td>'; |
---|
162 | |
---|
163 | $actions = $uninstaller->getUserActions($module_id); |
---|
164 | |
---|
165 | foreach($props as $prop_id => $prop) { |
---|
166 | echo '<td class="nowrap">'; |
---|
167 | |
---|
168 | if (!isset($actions[$prop_id])) { |
---|
169 | echo '--</td>'; |
---|
170 | continue; |
---|
171 | } |
---|
172 | |
---|
173 | $j = 0; |
---|
174 | foreach($actions[$prop_id] as $action_id => $action) { |
---|
175 | |
---|
176 | if (!isset($props[$prop_id][$action['action']])) continue; |
---|
177 | |
---|
178 | $ret = base64_encode(serialize(array( |
---|
179 | 'type' => $prop_id, |
---|
180 | 'action'=>$action['action'], |
---|
181 | 'ns'=>$action['ns'] |
---|
182 | ))); |
---|
183 | |
---|
184 | echo '<label class="classic">'. |
---|
185 | form::checkbox(array('actions['.$module_id.']['.$j.']'),$ret). |
---|
186 | ' '.$action['desc'].'</label><br />'; |
---|
187 | |
---|
188 | $j++; |
---|
189 | } |
---|
190 | echo '</td>'; |
---|
191 | } |
---|
192 | |
---|
193 | echo '<td class="nowrap">'; |
---|
194 | |
---|
195 | $callbacks = $uninstaller->getUserCallbacks($module_id); |
---|
196 | |
---|
197 | if (empty($callbacks)) { |
---|
198 | echo '--'; |
---|
199 | } |
---|
200 | |
---|
201 | $k = 0; |
---|
202 | foreach($callbacks as $callback_id => $callback) { |
---|
203 | |
---|
204 | $ret = base64_encode(serialize($callback['func'])); |
---|
205 | |
---|
206 | echo '<label class="classic">'. |
---|
207 | form::checkbox(array('extras['.$module_id.']['.$k.']'),$ret). |
---|
208 | ' '.$callback['desc'].'</label><br />'; |
---|
209 | } |
---|
210 | |
---|
211 | echo '</td></tr>'; |
---|
212 | } |
---|
213 | echo |
---|
214 | '</table>'. |
---|
215 | '<p>'. |
---|
216 | $core->formNonce(). |
---|
217 | form::hidden(array('redir'),$redir). |
---|
218 | form::hidden(array('action'),'uninstall'). |
---|
219 | '<input type="submit" name="submit" value="'.__('Perform selected actions').'" /> '. |
---|
220 | '</p>'. |
---|
221 | '</form>'. |
---|
222 | '</div>'; |
---|
223 | } |
---|
224 | } |
---|
225 | ?> |
---|