1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # |
---|
4 | # This file is part of clean:config. |
---|
5 | # Copyright 2007 Moe (http://gniark.net/) |
---|
6 | # |
---|
7 | # clean:config is free software; you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation; either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # clean:config is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | # |
---|
20 | # Icon (icon.png) and images are from Silk Icons : http://www.famfamfam.com/lab/icons/silk/ |
---|
21 | # |
---|
22 | # ***** END LICENSE BLOCK ***** |
---|
23 | |
---|
24 | class cleanconfig |
---|
25 | { |
---|
26 | |
---|
27 | public static function delete($setting,$limit) |
---|
28 | { |
---|
29 | global $core; |
---|
30 | |
---|
31 | if ($limit == 'blog') |
---|
32 | { |
---|
33 | $core->blog->settings->drop($setting); |
---|
34 | } |
---|
35 | elseif ($limit == 'global') |
---|
36 | { |
---|
37 | # inspirated from drop() function in /dotclear/inc/core/class.dc.settings.php |
---|
38 | $strReq = 'DELETE FROM '.$core->prefix.'setting'.' '; |
---|
39 | $strReq .= 'WHERE blog_id IS NULL '; |
---|
40 | $strReq .= "AND setting_id = '".$core->con->escape($setting)."' "; |
---|
41 | |
---|
42 | $core->con->execute($strReq); |
---|
43 | } |
---|
44 | else |
---|
45 | { |
---|
46 | throw new Exception('no limit'); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | public static function settings($limit) |
---|
51 | { |
---|
52 | global $core; |
---|
53 | |
---|
54 | $str = '<p>'.__('Use carefully. Only settings related to plugins can be deleted.').'</p>'."\n"; |
---|
55 | $str .= '<form method="post" action="'.http::getSelfURI().'">'."\n"; |
---|
56 | $table = new table('class="clear" summary="'.__('Settings').'"'); |
---|
57 | $table->part('head'); |
---|
58 | $table->row(); |
---|
59 | $table->header(__('Setting'),'colspan="2"'); |
---|
60 | $table->header(__('Value'),'class="nowrap"'); |
---|
61 | $table->header(__('Type'),'class="nowrap"'); |
---|
62 | $table->header(__('Description'),'class="maximal"'); |
---|
63 | |
---|
64 | $table->part('body'); |
---|
65 | |
---|
66 | $settings = array(); |
---|
67 | |
---|
68 | # limit to blog |
---|
69 | if ($limit == 'blog') |
---|
70 | { |
---|
71 | $dump = $core->blog->settings->dumpSettings(); |
---|
72 | } |
---|
73 | # global |
---|
74 | else |
---|
75 | { |
---|
76 | $dump = $core->blog->settings->dumpGlobalSettings(); |
---|
77 | } |
---|
78 | |
---|
79 | foreach ($dump as $k => $v) { |
---|
80 | $settings[$v['ns']][$k] = $v; |
---|
81 | } |
---|
82 | |
---|
83 | ksort($settings); |
---|
84 | |
---|
85 | # number of settings |
---|
86 | $i = 0; |
---|
87 | foreach ($settings as $k => $v) |
---|
88 | { |
---|
89 | # echo namespace |
---|
90 | $echo_ns = false; |
---|
91 | # only settings related to plugins |
---|
92 | if (($k != 'system') AND ($k != 'widgets')) |
---|
93 | { |
---|
94 | ksort($v); |
---|
95 | foreach ($v as $k => $v) |
---|
96 | { |
---|
97 | # hide deleted settings |
---|
98 | if (!((!empty($_POST['settings'])) AND (in_array($k,$_POST['settings'])))) |
---|
99 | { |
---|
100 | # hide global settings on blog settings |
---|
101 | if ((($limit == 'global') AND ($v['global'])) OR (($limit == 'blog') AND (!$v['global']))) |
---|
102 | { |
---|
103 | $table->row(); |
---|
104 | # echo namespace |
---|
105 | if (!$echo_ns) |
---|
106 | { |
---|
107 | $table->row(); |
---|
108 | $table->cell(__('namespace:').' <strong>'.$v['ns'].'</strong>','class="ns-name" colspan="5"'); |
---|
109 | $echo_ns = true; |
---|
110 | } |
---|
111 | $table->row('class="line"'); |
---|
112 | $table->cell(form::checkbox(array('settings[]',html::escapeHTML($k)),html::escapeHTML($k),false,$v['ns'])); |
---|
113 | $table->cell('<label for="'.html::escapeHTML($k).'">'.$k.'</label>'); |
---|
114 | # boolean |
---|
115 | if (($v['type']) == 'boolean') |
---|
116 | { |
---|
117 | $value = ($v['value']) ? 'true' : 'false'; |
---|
118 | } |
---|
119 | #other types |
---|
120 | else |
---|
121 | { |
---|
122 | $value = form::field(html::escapeHTML($k.'_field'),40, |
---|
123 | null,html::escapeHTML($v['value']),null,null,null,'readonly="readonly"'); |
---|
124 | } |
---|
125 | $table->cell($value); |
---|
126 | $table->cell($v['type']); |
---|
127 | $table->cell($v['label'],'class="maximal"'); |
---|
128 | $i++; |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | # nothing to display |
---|
135 | if ($i == 0) |
---|
136 | { |
---|
137 | return('<p><strong>'.__('No setting.').'</strong></p>'); |
---|
138 | } |
---|
139 | |
---|
140 | $str.= $table->get(); |
---|
141 | |
---|
142 | if ($i > 0) |
---|
143 | { |
---|
144 | $str .= ('<p class="checkboxes-helpers"></p>'. |
---|
145 | '<p>'.form::hidden(array('limit',$limit),$limit). |
---|
146 | '<input type="submit" name="delete" value="'.__('Remove selected settings').'" /></p>'."\n". |
---|
147 | '<p>'.$core->formNonce().'</p>'); |
---|
148 | } |
---|
149 | $str .= '</form>'."\n"; |
---|
150 | |
---|
151 | return($str); |
---|
152 | } |
---|
153 | |
---|
154 | public static function versions() |
---|
155 | { |
---|
156 | global $core; |
---|
157 | |
---|
158 | $table = new table('class="clear" summary="'.__('Settings').'"'); |
---|
159 | |
---|
160 | $query = 'SELECT module, version FROM '.DC_DBPREFIX.'version WHERE (module != \'core\');'; |
---|
161 | $rs = $core->con->select($query); |
---|
162 | |
---|
163 | # nothing to display |
---|
164 | if ($rs->isEmpty()) |
---|
165 | { |
---|
166 | return('<p class="message">'.sprintf(__('%s is empty'),DC_DBPREFIX.'version').'</p>'); |
---|
167 | } |
---|
168 | |
---|
169 | $str = '<form method="post" action="'.http::getSelfURI().'">'."\n"; |
---|
170 | $table = new table('class="clear" summary="'.__('Versions').'"'); |
---|
171 | $table->part('head'); |
---|
172 | $table->row(); |
---|
173 | $table->header(__('Module'),'colspan="2"'); |
---|
174 | $table->header(__('Version'),'class="nowrap"'); |
---|
175 | |
---|
176 | $table->part('body'); |
---|
177 | |
---|
178 | while ($rs->fetch()) |
---|
179 | { |
---|
180 | $module = $rs->module; |
---|
181 | $table->row('class="line"'); |
---|
182 | $table->cell(form::checkbox(array('versions[]',html::escapeHTML($module)),html::escapeHTML($module))); |
---|
183 | $table->cell('<label for="'.html::escapeHTML(html::escapeHTML($module)).'">'.$module.'</label>'); |
---|
184 | $table->cell($rs->version); |
---|
185 | } |
---|
186 | |
---|
187 | $str .= $table->get(); |
---|
188 | $str .= ('<p class="checkboxes-helpers"></p>'. |
---|
189 | '<input type="submit" name="delete_versions" value="'.__('Remove selected versions').'" /></p>'."\n". |
---|
190 | '<p>'.$core->formNonce().'</p>'); |
---|
191 | $str .= '</form>'."\n"; |
---|
192 | |
---|
193 | return($str); |
---|
194 | } |
---|
195 | |
---|
196 | public static function delete_version($module) |
---|
197 | { |
---|
198 | global $core; |
---|
199 | |
---|
200 | # inspirated from drop() function in /dotclear/inc/core/class.dc.settings.php |
---|
201 | $strReq = 'DELETE FROM '.$core->prefix.'version '; |
---|
202 | $strReq .= 'WHERE module = \''.$core->con->escape($module).'\';'; |
---|
203 | |
---|
204 | $core->con->execute($strReq); |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | ?> |
---|