1 | <?php |
---|
2 | /** |
---|
3 | * @brief aboutConfig, a plugin for Dotclear 2 |
---|
4 | * |
---|
5 | * @package Dotclear |
---|
6 | * @subpackage Plugins |
---|
7 | * |
---|
8 | * @copyright Olivier Meunier & Association Dotclear |
---|
9 | * @copyright GPL-2.0-only |
---|
10 | */ |
---|
11 | |
---|
12 | if (!defined('DC_CONTEXT_ADMIN')) {return;} |
---|
13 | |
---|
14 | # Local navigation |
---|
15 | if (!empty($_POST['gs_nav'])) { |
---|
16 | http::redirect($p_url . $_POST['gs_nav']); |
---|
17 | exit; |
---|
18 | } |
---|
19 | if (!empty($_POST['ls_nav'])) { |
---|
20 | http::redirect($p_url . $_POST['ls_nav']); |
---|
21 | exit; |
---|
22 | } |
---|
23 | |
---|
24 | # Local settings update |
---|
25 | if (!empty($_POST['s']) && is_array($_POST['s'])) { |
---|
26 | try |
---|
27 | { |
---|
28 | foreach ($_POST['s'] as $ns => $s) { |
---|
29 | $core->blog->settings->addNamespace($ns); |
---|
30 | foreach ($s as $k => $v) { |
---|
31 | if ($_POST['s_type'][$ns][$k] == 'array') { |
---|
32 | $v = json_decode($v, true); |
---|
33 | } |
---|
34 | $core->blog->settings->$ns->put($k, $v); |
---|
35 | } |
---|
36 | $core->blog->triggerBlog(); |
---|
37 | } |
---|
38 | |
---|
39 | dcPage::addSuccessNotice(__('Configuration successfully updated')); |
---|
40 | http::redirect($p_url); |
---|
41 | } catch (Exception $e) { |
---|
42 | $core->error->add($e->getMessage()); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | # Global settings update |
---|
47 | if (!empty($_POST['gs']) && is_array($_POST['gs'])) { |
---|
48 | try |
---|
49 | { |
---|
50 | foreach ($_POST['gs'] as $ns => $s) { |
---|
51 | $core->blog->settings->addNamespace($ns); |
---|
52 | foreach ($s as $k => $v) { |
---|
53 | if ($_POST['gs_type'][$ns][$k] == 'array') { |
---|
54 | $v = json_decode($v, true); |
---|
55 | } |
---|
56 | $core->blog->settings->$ns->put($k, $v, null, null, true, true); |
---|
57 | } |
---|
58 | $core->blog->triggerBlog(); |
---|
59 | } |
---|
60 | |
---|
61 | dcPage::addSuccessNotice(__('Configuration successfully updated')); |
---|
62 | http::redirect($p_url . '&part=global'); |
---|
63 | } catch (Exception $e) { |
---|
64 | $core->error->add($e->getMessage()); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | $part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; |
---|
69 | |
---|
70 | function settingLine($id, $s, $ns, $field_name, $strong_label) |
---|
71 | { |
---|
72 | if ($s['type'] == 'boolean') { |
---|
73 | $field = form::combo(array($field_name . '[' . $ns . '][' . $id . ']', $field_name . '_' . $ns . '_' . $id), |
---|
74 | array(__('yes') => 1, __('no') => 0), $s['value'] ? 1 : 0); |
---|
75 | } else { |
---|
76 | if ($s['type'] == 'array') { |
---|
77 | $field = form::field(array($field_name . '[' . $ns . '][' . $id . ']', $field_name . '_' . $ns . '_' . $id), 40, null, |
---|
78 | html::escapeHTML(json_encode($s['value']))); |
---|
79 | } else { |
---|
80 | $field = form::field(array($field_name . '[' . $ns . '][' . $id . ']', $field_name . '_' . $ns . '_' . $id), 40, null, |
---|
81 | html::escapeHTML($s['value'])); |
---|
82 | } |
---|
83 | } |
---|
84 | $type = form::hidden(array($field_name . '_type' . '[' . $ns . '][' . $id . ']', $field_name . '_' . $ns . '_' . $id . '_type'), |
---|
85 | html::escapeHTML($s['type'])); |
---|
86 | |
---|
87 | $slabel = $strong_label ? '<strong>%s</strong>' : '%s'; |
---|
88 | |
---|
89 | return |
---|
90 | '<tr class="line">' . |
---|
91 | '<td scope="row"><label for="' . $field_name . '_' . $ns . '_' . $id . '">' . sprintf($slabel, html::escapeHTML($id)) . '</label></td>' . |
---|
92 | '<td>' . $field . '</td>' . |
---|
93 | '<td>' . $s['type'] . $type . '</td>' . |
---|
94 | '<td>' . html::escapeHTML($s['label']) . '</td>' . |
---|
95 | '</tr>'; |
---|
96 | } |
---|
97 | ?> |
---|
98 | <html> |
---|
99 | <head> |
---|
100 | <title>about:config</title> |
---|
101 | <?php echo dcPage::jsPageTabs($part) . dcPage::jsLoad(dcPage::getPF('aboutConfig/js/index.js')); ?> |
---|
102 | </head> |
---|
103 | |
---|
104 | <body> |
---|
105 | <?php |
---|
106 | echo dcPage::breadcrumb( |
---|
107 | array( |
---|
108 | __('System') => '', |
---|
109 | html::escapeHTML($core->blog->name) => '', |
---|
110 | __('about:config') => '' |
---|
111 | )) . |
---|
112 | dcPage::notices(); |
---|
113 | ?> |
---|
114 | |
---|
115 | <div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'), html::escapeHTML($core->blog->name)); ?>"> |
---|
116 | <h3 class="out-of-screen-if-js"><?php echo sprintf(__('Settings for %s'), html::escapeHTML($core->blog->name)); ?></h3> |
---|
117 | |
---|
118 | <?php |
---|
119 | $table_header = '<div class="table-outer"><table class="settings" id="%s"><caption class="as_h3">%s</caption>' . |
---|
120 | '<thead>' . |
---|
121 | '<tr>' . "\n" . |
---|
122 | ' <th class="nowrap">' . __('Setting ID') . '</th>' . "\n" . |
---|
123 | ' <th>' . __('Value') . '</th>' . "\n" . |
---|
124 | ' <th>' . __('Type') . '</th>' . "\n" . |
---|
125 | ' <th>' . __('Description') . '</th>' . "\n" . |
---|
126 | '</tr>' . "\n" . |
---|
127 | '</thead>' . "\n" . |
---|
128 | '<tbody>'; |
---|
129 | $table_footer = '</tbody></table></div>'; |
---|
130 | |
---|
131 | $settings = array(); |
---|
132 | foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { |
---|
133 | foreach ($namespace->dumpSettings() as $k => $v) { |
---|
134 | $settings[$ns][$k] = $v; |
---|
135 | } |
---|
136 | } |
---|
137 | ksort($settings); |
---|
138 | if (count($settings) > 0) { |
---|
139 | $ns_combo = array(); |
---|
140 | foreach ($settings as $ns => $s) { |
---|
141 | $ns_combo[$ns] = '#l_' . $ns; |
---|
142 | } |
---|
143 | echo |
---|
144 | '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post">' . |
---|
145 | '<p class="anchor-nav">' . |
---|
146 | '<label for="ls_nav" class="classic">' . __('Goto:') . '</label> ' . form::combo('ls_nav', $ns_combo) . |
---|
147 | ' <input type="submit" value="' . __('Ok') . '" id="ls_submit" />' . |
---|
148 | '<input type="hidden" name="p" value="aboutConfig" />' . |
---|
149 | $core->formNonce() . '</p></form>'; |
---|
150 | } |
---|
151 | ?> |
---|
152 | |
---|
153 | <form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post"> |
---|
154 | |
---|
155 | <?php |
---|
156 | foreach ($settings as $ns => $s) { |
---|
157 | ksort($s); |
---|
158 | echo sprintf($table_header, 'l_' . $ns, $ns); |
---|
159 | foreach ($s as $k => $v) { |
---|
160 | echo settingLine($k, $v, $ns, 's', !$v['global']); |
---|
161 | } |
---|
162 | echo $table_footer; |
---|
163 | } |
---|
164 | ?> |
---|
165 | |
---|
166 | <p><input type="submit" value="<?php echo __('Save'); ?>" /> |
---|
167 | <input type="hidden" name="p" value="aboutConfig" /> |
---|
168 | <?php echo $core->formNonce(); ?></p> |
---|
169 | </form> |
---|
170 | </div> |
---|
171 | |
---|
172 | <div id="global" class="multi-part" title="<?php echo __('Global settings'); ?>"> |
---|
173 | <h3 class="out-of-screen-if-js"><?php echo __('Global settings'); ?></h3> |
---|
174 | |
---|
175 | <?php |
---|
176 | $settings = array(); |
---|
177 | |
---|
178 | foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { |
---|
179 | foreach ($namespace->dumpGlobalSettings() as $k => $v) { |
---|
180 | $settings[$ns][$k] = $v; |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | ksort($settings); |
---|
185 | |
---|
186 | if (count($settings) > 0) { |
---|
187 | $ns_combo = array(); |
---|
188 | foreach ($settings as $ns => $s) { |
---|
189 | $ns_combo[$ns] = '#g_' . $ns; |
---|
190 | } |
---|
191 | echo |
---|
192 | '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post">' . |
---|
193 | '<p class="anchor-nav">' . |
---|
194 | '<label for="gs_nav" class="classic">' . __('Goto:') . '</label> ' . form::combo('gs_nav', $ns_combo) . ' ' . |
---|
195 | '<input type="submit" value="' . __('Ok') . '" id="gs_submit" />' . |
---|
196 | '<input type="hidden" name="p" value="aboutConfig" />' . |
---|
197 | $core->formNonce() . '</p></form>'; |
---|
198 | } |
---|
199 | ?> |
---|
200 | |
---|
201 | <form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post"> |
---|
202 | |
---|
203 | <?php |
---|
204 | foreach ($settings as $ns => $s) { |
---|
205 | ksort($s); |
---|
206 | echo sprintf($table_header, 'g_' . $ns, $ns); |
---|
207 | foreach ($s as $k => $v) { |
---|
208 | echo settingLine($k, $v, $ns, 'gs', false); |
---|
209 | } |
---|
210 | echo $table_footer; |
---|
211 | } |
---|
212 | ?> |
---|
213 | |
---|
214 | <p><input type="submit" value="<?php echo __('Save'); ?>" /> |
---|
215 | <input type="hidden" name="p" value="aboutConfig" /> |
---|
216 | <?php echo $core->formNonce(); ?></p> |
---|
217 | </form> |
---|
218 | </div> |
---|
219 | |
---|
220 | <?php dcPage::helpBlock('aboutConfig');?> |
---|
221 | |
---|
222 | </body> |
---|
223 | </html> |
---|