Dotclear

source: plugins/aboutConfig/index.php @ 582:1f624beae675

Revision 582:1f624beae675, 4.8 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Menu d'accès rapide

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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 settings update
15if (!empty($_POST['s']) && is_array($_POST['s']))
16{
17     try
18     {
19          foreach ($_POST['s'] as $ns => $s)
20          {
21               $core->blog->settings->addNamespace($ns);
22               
23               foreach ($s as $k => $v)      {
24                    $core->blog->settings->$ns->put($k,$v);
25               }
26               
27               $core->blog->triggerBlog();
28          }
29         
30          http::redirect($p_url.'&upd=1');
31     }
32     catch (Exception $e)
33     {
34          $core->error->add($e->getMessage());
35     }
36}
37
38# Global settings update
39if (!empty($_POST['gs']) && is_array($_POST['gs']))
40{
41     try
42     {
43          foreach ($_POST['gs'] as $ns => $s)
44          {
45               $core->blog->settings->addNamespace($ns);
46               
47               foreach ($s as $k => $v)      {
48                    $core->blog->settings->$ns->put($k,$v,null,null,true,true);
49               }
50               
51               $core->blog->triggerBlog();
52          }
53         
54          http::redirect($p_url.'&upd=1&part=global');
55     }
56     catch (Exception $e)
57     {
58          $core->error->add($e->getMessage());
59     }
60}
61
62$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
63
64function settingLine($id,$s,$ns,$field_name,$strong_label)
65{
66     if ($s['type'] == 'boolean') {
67          $field = form::combo(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id),
68          array(__('yes') => 1, __('no') => 0),$s['value']);
69     } else {
70          $field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id),40,null,
71          html::escapeHTML($s['value']));
72     }
73     
74     $slabel = $strong_label ? '<strong>%s</strong>' : '%s';
75     
76     return
77     '<tr>'.
78     '<td scope="raw"><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'.
79     '<td>'.$field.'</td>'.
80     '<td>'.$s['type'].'</td>'.
81     '<td>'.html::escapeHTML($s['label']).'</td>'.
82     '</tr>';
83}
84?>
85<html>
86<head>
87  <title>about:config</title>
88  <?php echo dcPage::jsPageTabs($part); ?>
89  <style type="text/css">
90  table.settings { border: 1px solid #999; margin-bottom: 2em; }
91  table.settings th { background: #f5f5f5; color: #444; padding-top: 0.3em; padding-bottom: 0.3em; }
92  ul.submenu {float: right; border: 1px solid #ccc; padding-right: 1em; padding-left: 1.5em; margin-top:0.5em; margin-bottom:0.5em; }
93  </style>
94</head>
95
96<body>
97<?php
98if (!empty($_GET['upd'])) {
99     echo '<p class="message">'.__('Configuration successfully updated').'</p>';
100}
101
102if (!empty($_GET['upda'])) {
103     echo '<p class="message">'.__('Settings definition successfully updated').'</p>';
104}
105?>
106<h2><?php echo html::escapeHTML($core->blog->name); ?> &rsaquo; <span class="page-title">about:config</span></h2>
107
108<div id="local" class="multi-part" title="<?php echo __('blog settings'); ?>">
109<form action="plugin.php" method="post">
110
111<?php 
112
113$table_header = '<table class="settings" id="%s"><caption>%s</caption>'.
114'<thead>'.
115'<tr>'."\n".
116'  <th class="nowrap">Setting ID</th>'."\n".
117'  <th>'.__('Value').'</th>'."\n".
118'  <th>'.__('Type').'</th>'."\n".
119'  <th class="maximalx">'.__('Description').'</th>'."\n".
120'</tr>'."\n".
121'</thead>'."\n".
122'<tbody>';
123$table_footer = '</tbody></table>';
124
125$settings = array();
126
127foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
128     foreach ($namespace->dumpSettings() as $k => $v) {
129          $settings[$ns][$k] = $v;
130     }
131}
132
133ksort($settings);
134
135if (count($settings) > 0) {
136     echo '<ul class="submenu">';
137     foreach ($settings as $ns => $s) {
138          echo '<li><a href="#l_'.$ns.'">'.$ns.'</a></li>';
139     }
140     echo '</ul>';
141}
142
143foreach ($settings as $ns => $s)
144{
145     ksort($s);
146     echo sprintf($table_header,'l_'.$ns,$ns);
147     foreach ($s as $k => $v)
148     {
149          echo settingLine($k,$v,$ns,'s',!$v['global']);
150     }
151     echo $table_footer;
152}
153?>
154
155<p><input type="submit" value="<?php echo __('Save'); ?>" />
156<input type="hidden" name="p" value="aboutConfig" />
157<?php echo $core->formNonce(); ?></p>
158</form>
159</div>
160
161<div id="global" class="multi-part" title="<?php echo __('global settings'); ?>">
162<form action="plugin.php" method="post">
163<?php
164$settings = array();
165
166foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
167     foreach ($namespace->dumpGlobalSettings() as $k => $v) {
168          $settings[$ns][$k] = $v;
169     }
170}
171
172ksort($settings);
173
174if (count($settings) > 0) {
175     echo '<ul class="submenu">';
176     foreach ($settings as $ns => $s) {
177          echo '<li><a href="#g_'.$ns.'">'.$ns.'</a></li>';
178     }
179     echo '</ul>';
180}
181
182foreach ($settings as $ns => $s)
183{
184     ksort($s);
185     echo sprintf($table_header,'g_'.$ns,$ns);
186     foreach ($s as $k => $v)
187     {
188          echo settingLine($k,$v,$ns,'gs',false);
189     }
190     echo $table_footer;
191}
192?>
193
194<p><input type="submit" value="<?php echo __('Save'); ?>" />
195<input type="hidden" name="p" value="aboutConfig" />
196<?php echo $core->formNonce(); ?></p>
197</form>
198</div>
199
200</body>
201</html>
Note: See TracBrowser for help on using the repository browser.

Sites map