Dotclear

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

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

dcAdvancedCleaner 0.5

  • Switched to DC 2.2
  • Fixed bug in tabs
RevLine 
[1413]1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of dcAdvancedCleaner, a plugin for Dotclear 2.
[1567]4#
[2199]5# Copyright (c) 2009-2010 JC Denis and contributors
[1413]6# jcdenis@gdwd.com
[1567]7#
[1413]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
[1567]27     # Generic module before delete
[1413]28     public static function moduleBeforeDelete($module,$redir)
29     {
30          global $core;
31          $done = false;
32
[2316]33          if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) return;
[1413]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
[2199]41          foreach($m_callbacks as $k => $callback)
42          {
43               if (!isset($callback['func']) || !is_callable($callback['func'])) continue;
[1413]44
[2199]45               call_user_func($callback['func'],$module);
[1413]46               $done = true;
47          }
48
[2199]49          foreach($m_actions as $type => $actions)
50          {
51               foreach($actions as $v)
52               {
[1413]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     {
[2199]65          self::modulesTabs($core,DC_PLUGINS_ROOT,$p_url.'&tab=uninstaller');
[1413]66     }
67
68     public static function pluginsToolsTabs($core)
69     {
70          self::modulesTabs($core,DC_PLUGINS_ROOT,'plugins.php?tab=uninstaller');
71     }
72
[1567]73     # Generic module tabs
[2199]74     public static function modulesTabs($core,$path,$redir,$title='')
[1413]75     {
[2316]76          if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) return;
[1413]77
78          $err = '';
[2199]79          $title = empty($title) ? __('Advanced uninstall') : $title;
[1413]80
81          $uninstaller = new dcUninstaller($core);
82          $uninstaller->loadModules($path);
83          $modules = $uninstaller->getModules();
84          $props = $uninstaller->getAllowedProperties();
85
[2199]86          # Execute
87          if (isset($_POST['action']) && $_POST['action'] == 'uninstall'
88          && (!empty($_POST['extras']) || !empty($_POST['actions']))) {
[1413]89
[2199]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));
[1413]98
[2199]99                                   if (!$extra || !is_callable($extra)) continue;
[1413]100
[2199]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));
[1413]112
[2199]113                                   if (!$action 
114                                    || !isset($action['type']) 
115                                    || !isset($action['action']) 
116                                    || !isset($action['ns'])) continue;
[1413]117
[2199]118                                   $uninstaller->execute($action['type'],$action['action'],$action['ns']);
119                              }
[1413]120                         }
121                    }
[2199]122                    http::redirect($redir.'&msg=1');
[1413]123               }
[2199]124               catch(Exception $e) {
125                    $err = $e->getMessage();
126               }
[1413]127          }
128
129          echo 
[2199]130          '<div class="multi-part" id="uninstaller" title="'.__($title).'">';
[1413]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>'.
[2199]144          '<th>'.__('Id').'</th>'.
[1413]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">'.
[2199]160               '<td class="nowrap">'.$module_id.'</td>'.
[1413]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">'.
[2199]185                         form::checkbox(array('actions['.$module_id.']['.$j.']'),$ret).
[1413]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">'.
[2199]207                    form::checkbox(array('extras['.$module_id.']['.$k.']'),$ret).
[1413]208                    ' '.$callback['desc'].'</label><br />';
209               }
210
211               echo '</td></tr>';
212          }
213          echo 
214          '</table>'.
215          '<p>'.
216          $core->formNonce().
[2199]217          form::hidden(array('redir'),$redir).
[1413]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?>
Note: See TracBrowser for help on using the repository browser.

Sites map