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