Dotclear

source: plugins/dcAdvancedCleaner/index.php @ 2316

Revision 2316, 8.5 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_CONTEXT_ADMIN')){return;}
14
15if (!$core->auth->isSuperAdmin()){return;}
16
[2199]17# Lists
18function drawDcAdvancedCleanerLists($core,$type)
19{
20     $combo_funcs = array(
21          'settings' => array('dcAdvancedCleaner','getSettings'),
22          'tables' => array('dcAdvancedCleaner','getTables'),
23          'plugins' => array('dcAdvancedCleaner','getPlugins'),
24          'themes' => array('dcAdvancedCleaner','getThemes'),
25          'caches' => array('dcAdvancedCleaner','getCaches'),
26          'versions' => array('dcAdvancedCleaner','getVersions')
27     );
28     $combo_actions = array(
29          'settings' => array(
30               __('delete global settings') => 'delete_global',
31               __('delete blog settings') => 'delete_local',
32               __('delete all settings') =>'delete_all'
33          ),
34          'tables' => array(
35               __('delete') => 'delete',
36               __('empty') => 'empty'
37          ),
38          'plugins' => array(
39               __('delete') => 'delete',
40               __('empty') => 'empty'
41          ),
42          'themes' => array(
43               __('delete') => 'delete',
44               __('empty') => 'empty'
45          ),
46          'caches' => array(
47               __('delete') => 'delete',
48               __('empty') => 'empty'
49          ),
50          'versions' => array(
51               __('delete') => 'delete'
52          )
53     );
54     $combo_help = array(
55          'settings' => __('Namespaces registered in dcSettings'),
56          'tables' => __('All database tables of Dotclear'),
57          'plugins' => __('Folders from plugins directories'),
58          'themes' => __('Folders from blog themes directory'),
59          'caches' => __('Folders from cache directory'),
60          'versions' => __('Versions registered in table "version" of Dotclear')
61     );
62
63     if (!isset($combo_funcs[$type])) return '';
64
65     $rs = call_user_func($combo_funcs[$type],$core);
66
67     echo 
68     '<div class="listDcAdvancedCleaner">'.
69     '<p class="form-note">'.$combo_help[$type].'</p>';
70     
71     if (empty($rs)) {
72          echo 
73          '<p>'.sprintf(__('There is no %s'),__(substr($type,0,-1))).'</p>';
74     } else {
75
76          echo
77          '<p>'.sprintf(__('There are %s %s'),count($rs),__($type)).'</p>'.
78          '<form method="post" action="plugin.php?p=dcAdvancedCleaner&amp;tab=lists&amp;part='.$type.'">'.
79          '<table><thead><tr>'.
80          '<th>'.__('Name').'</th><th>'.__('Objects').'</th>'.
81          '</tr></thead><tbody>';
82
83          foreach($rs as $k => $v)
84          {
85               $offline = in_array($v['key'],dcAdvancedCleaner::$dotclear[$type]);
86
[2316]87               if ($core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide && $offline) continue;
[2199]88
89               echo 
90               '<tr class="line'.
91               ($offline ? ' offline' : '').
92               '">'.
93               '<td class="nowrap"><label class="classic">'.
94               form::checkbox(array('entries['.$k.']'),html::escapeHTML($v['key'])).' '.$v['key'].'</label></td>'.
95               '<td class="nowrap">'.$v['value'].'</td>'.
96               '</tr>';
97          }
98
99          echo
100          '</tbody></table>'.
101          '<p>'.__('Action on selected rows:').'<br />'.
102          form::combo(array('action'),$combo_actions[$type]).
103          '<input type="submit" value="'.__('ok').'" />'.
104          form::hidden(array('p'),'dcAdvancedCleaner').
105          form::hidden(array('tab'),'lists').
106          form::hidden(array('part'),$type).
107          form::hidden(array('type'),$type).
108          $core->formNonce().'</p>'.
109          '</form>';
110     }
111     echo 
112     '<div>';
113}
114
[1413]115# Localized l10n
116__('Settings'); __('settings'); __('setting');
117__('Tables'); __('tables'); __('table');
118__('Plugins'); __('plugins'); __('plugin');
119__('Themes'); __('themes'); __('theme');
120__('Caches'); __('caches'); __('cache');
121__('Versions'); __('versions'); __('version');
122__('delete table');
123__('delete cache files');
124__('delete plugin files');
125__('delete theme files');
126__('delete the version number');
127__('Uninstall extensions');
[1980]128__('delete %s blog settings');
129__('delete %s global settings');
130__('delete all %s settings');
131__('delete %s table');
132__('delete %s version number');
133__('delete %s plugin files');
134__('delete %s theme file');
135__('delete %s cache files');
[1413]136
137# vars
138$msg = isset($_GET['msg']) ? true : false;
[2199]139$tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'dcac';
140$part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'caches';
[1413]141$entries = isset($_POST['entries']) ? $_POST['entries'] : '';
142$action = isset($_POST['action']) ? $_POST['action'] : '';
143$type = isset($_POST['type']) ? $_POST['type'] : '';
[2316]144$s = $core->blog->settings->dcAdvancedCleaner;
[1413]145
146# Combos
[2199]147$combo_title = array(
148     'settings' => __('Settings'),
149     'tables' => __('Tables'),
150     'plugins' => __('Extensions'),
151     'themes' => __('Themes'),
152     'caches' => __('Cache'),
153     'versions' => __('Versions')
[1413]154);
[2199]155     
[1413]156$combo_type = array(
157     'settings' => array('delete_global','delete_local','delete_all'),
158     'tables' => array('empty','delete'),
159     'plugins' => array('empty','delete'),
160     'themes' => array('empty','delete'),
161     'caches' => array('empty','delete'),
162     'versions' => array('delete')
163);
164
165# This plugin settings
[2199]166if ($tab == 'dcac' && $action == 'dcadvancedcleaner_settings')
167{
168     try {
169          $s->put('dcAdvancedCleaner_behavior_active',isset($_POST['dcadvancedcleaner_behavior_active']),'boolean');
170          $s->put('dcAdvancedCleaner_dcproperty_hide',isset($_POST['dcadvancedcleaner_dcproperty_hide']),'boolean');
[1413]171
[2199]172          http::redirect($p_url.'&tab=dcac&part=dcac&part=&msg=done');
173     }
174     catch(Exception $e) {
175          $core->error->add($e->getMessage());
176     }
[1413]177}
178
179# Actions
[2199]180if ($tab == 'lists' && !empty($entries) 
[1413]181 && isset($combo_type[$type]) 
182 && in_array($action,$combo_type[$type])) {
183
184     try {
185          foreach($entries as $v) {
186               dcAdvancedCleaner::execute($core,$type,$action,$v);
187          }
188
[2199]189          http::redirect($p_url.'&tab=lists&part='.$part.'&msg=done');
[1413]190     }
191     catch(Exception $e) {
192          $core->error->add($e->getMessage());
193     }
194}
195
[2199]196echo '
197<html><head>
198<title>'.__('Advanced cleaner').'</title>
199<link rel="stylesheet" type="text/css" href="index.php?pf=dcAdvancedCleaner/style.css" />'.
200dcPage::jsToolBar().
201dcPage::jsPageTabs($tab).'
202</style>';
[1413]203
204# --BEHAVIOR-- dcAdvancedCleanerAdminHeader
205$core->callBehavior('dcAdvancedCleanerAdminHeader',$core,$p_url,$tab);
206
[2199]207echo '
208</head><body>
209<h2 class="bombDcAdvancedCleaner">'.html::escapeHTML($core->blog->name).
210' &rsaquo; '.__('Advanced cleaner').'</h2>
211<p class="static-msg">'.__('Beware: All actions done here are irreversible and are directly applied').'</p>';
[1413]212
[2199]213if (!empty($msg)) { echo '<p class="message">'.__('Action successfully done').'</p>'; }
[1413]214
[2199]215echo '<div class="multi-part" id="lists" title="'.__('Records and folders').'">'.
216'<p>';
217foreach($combo_title as $k => $v)
218{
219     echo '<a class="button" href="'.$p_url.'&amp;tab=lists&part='.$k.'">'.$v.'</a> ';
220}
221echo '</p>';
222     
223# Load "part" page
224if (isset($combo_title[$part]))
225{
226     echo '<fieldset><legend>'.$combo_title[$part].'</legend>';
227     drawDcAdvancedCleanerLists($core,$part);
228     echo '</fieldset>';
229}
[2316]230if ($s->dcAdvancedCleaner_dcproperty_hide)
231{
232     echo '<p>'.__('Default values of Dotclear are hidden. You can change this in settings tab').'</p>';
233}
[2199]234echo '</div>';
[1413]235
236# --BEHAVIOR-- dcAdvancedCleanerAdminTabs
237$core->callBehavior('dcAdvancedCleanerAdminTabs',$core,$p_url);
238
[2199]239echo '
240<div class="multi-part" id="dcac" title="'.__('This plugin settings').'">
241<fieldset><legend>'.__('This plugin settings').'</legend>
242<form method="post" action="'.$p_url.'&amp;tab=dcac&part=">
243<p class="field"><label>'.
244form::checkbox(array('dcadvancedcleaner_behavior_active'),'1',
245$s->dcAdvancedCleaner_behavior_active).
246__('Activate behaviors').'</label></p>
247<p class="form-note">'.__('Enable actions set in _uninstall.php files.').'</p>
248<p class="field"><label>'.
249form::checkbox(array('dcadvancedcleaner_dcproperty_hide'),'1',
250$s->dcAdvancedCleaner_dcproperty_hide).
251__('Hide Dotclear default properties in actions tabs').'
252</label></p>
253<p class="form-note">'.__('Prevent from deleting Dotclear important properties.').'</p>
254<p><input type="submit" name="submit" value="'.__('Save').'" />'.
255form::hidden(array('p'),'dcAdvancedCleaner').
256form::hidden(array('tab'),'dcac').
257form::hidden(array('part'),'').
258form::hidden(array('action'),'dcadvancedcleaner_settings').
259$core->formNonce().'</p>
260</form>
261</fieldset>
262</div>';
[1413]263
[2199]264dcPage::helpBlock('dcAdvancedCleaner');
265echo '
266<hr class="clear"/>
267<p class="right">
268<a class="button" href="'.$p_url.'&amp;part=dcac">'.__('settings').'</a> -
269dcAdvancedCleaner - '.$core->plugins->moduleInfo('dcAdvancedCleaner','version').'&nbsp;
270<img alt="dcMiniUrl" src="index.php?pf=dcAdvancedCleaner/icon.png" />
271</p>
272</body></html>';
[1413]273?>
Note: See TracBrowser for help on using the repository browser.

Sites map