Dotclear

source: plugins/aboutConfig/index.php @ 2824:c7051e56fd3c

Revision 2824:c7051e56fd3c, 6.0 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Using dcAdminURL, work in progress on plugins…

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

Sites map