Dotclear

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

Revision 1567, 5.2 KB checked in by JcDenis, 14 years ago (diff)

dcAdvancedCleaner 0.2:

  • Fixed delete_all settings
  • Fixed typo
  • Added license
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of dcAdvancedCleaner, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009 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          if (!$core->blog->settings->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 $callback) {
42
43               $f = unserialize(base64_decode($callback['func']));
44               if (!is_callable($f)) continue;
45
46               call_user_func($f,$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.'&amp;t=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='Uninstall extensions')
76     {
77          if (!$core->blog->settings->dcadvancedcleaner_behavior_active) return;
78
79          $err = '';
80
81          $uninstaller = new dcUninstaller($core);
82          $uninstaller->loadModules($path);
83          $modules = $uninstaller->getModules();
84          $props = $uninstaller->getAllowedProperties();
85
86          # Execute actions
87          if (isset($_POST['action']) && $_POST['action'] == 'uninstall' && !empty($_POST['id'])) {
88
89               foreach($_POST['id'] as $k => $id) {
90
91                    # Settings
92                    if (!isset($_POST['actions'][$k])) continue;
93
94                    try {
95                         foreach($_POST['actions'][$k] as $ks => $sentence) {
96
97                              $s = unserialize(base64_decode($sentence));
98
99                              if (!isset($s['type']) 
100                               || !isset($s['action']) 
101                               || !isset($s['ns'])) continue;
102
103                              $uninstaller->execute($s['type'],$s['action'],$s['ns']);
104
105                              http::redirect($_POST['redir'].'&removed=1');
106                         }
107                    }
108                    catch(Exception $e) {
109                         $err = $e->getMessage();
110                    }
111               }
112          }
113
114          echo 
115          '<div class="multi-part" id="uninstaller" title="'.
116               __($title).'">';
117
118          if($err)
119               echo '<p class="error">'.$err.'</p>';
120
121          if(!count($modules)) {
122               echo '<p>'.__('There is no module with uninstall features').'</p></div>';
123               return;
124          }
125
126          echo
127          '<p>'.__('List of modules with advanced uninstall features').'</p>'.
128          '<form method="post" action="'.$redir.'">'.
129          '<table class="clear"><tr>'.
130          '<th>&nbsp;</th>'.
131          '<th>'.__('Module').'</th>';
132         
133          foreach($props as $pro_id => $prop) {
134               echo '<th>'.__($pro_id).'</th>';
135          }
136
137          echo 
138          '<th>'.__('extra').'</th>'.
139          '</tr>';
140
141          $i = 0;
142          foreach($modules as $module_id => $module) {
143
144               echo
145               '<tr class="line">'.
146               '<td class="nowrap"><label class="classic">'.
147               form::checkbox(array('id['.$i.']'),$module_id).' '.$module_id.
148               '</label></td>'.
149               '<td class="maximal nowrap">'.$module['name'].' '.$module['version'].'</td>';
150
151               $actions = $uninstaller->getUserActions($module_id);
152
153               foreach($props as $prop_id => $prop) {
154                    echo '<td class="nowrap">';
155
156                    if (!isset($actions[$prop_id])) {
157                         echo '--</td>';
158                         continue;
159                    }
160
161                    $j = 0;
162                    foreach($actions[$prop_id] as $action_id => $action) {
163
164                         if (!isset($props[$prop_id][$action['action']])) continue;
165
166                         $ret = base64_encode(serialize(array(
167                              'type' => $prop_id,
168                              'action'=>$action['action'],
169                              'ns'=>$action['ns']
170                         )));
171
172                         echo '<label class="classic">'.
173                         form::checkbox(array('actions['.$i.']['.$j.']'),$ret).
174                         ' '.$action['desc'].'</label><br />';
175
176                         $j++;
177                    }
178                    echo '</td>';
179               }
180
181               echo '<td class="nowrap">';
182
183               $callbacks = $uninstaller->getUserCallbacks($module_id);
184
185               if (empty($callbacks)) {
186                    echo '--';
187               }
188
189               $k = 0;
190               foreach($callbacks as $callback_id => $callback) {
191
192                    $ret = base64_encode(serialize($callback['func']));
193
194                    echo '<label class="classic">'.
195                    form::checkbox(array('extras['.$i.']['.$k.']'),$ret).
196                    ' '.$callback['desc'].'</label><br />';
197               }
198
199               echo '</td></tr>';
200               $i++;
201          }
202          echo 
203          '</table>'.
204          '<p>'.
205          $core->formNonce().
206          form::hidden(array('action'),'uninstall').
207          '<input type="submit" name="submit" value="'.__('Perform selected actions').'" /> '.
208          '</p>'.
209          '</form>'.
210          '</div>';
211     }
212}
213?>
Note: See TracBrowser for help on using the repository browser.

Sites map