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 ----------------------------------------- |
---|
12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
13 | |
---|
14 | class adminPageAboutConfig |
---|
15 | { |
---|
16 | public static $p_url = 'plugin.php?p=aboutConfig'; |
---|
17 | |
---|
18 | # Update local settings |
---|
19 | public static function updLocal($form) |
---|
20 | { |
---|
21 | self::updSettings($form); |
---|
22 | } |
---|
23 | |
---|
24 | # Update global settings |
---|
25 | public static function updGlobal($form) |
---|
26 | { |
---|
27 | self::updSettings($form,true); |
---|
28 | } |
---|
29 | |
---|
30 | # Update settings |
---|
31 | protected static function updSettings($form,$global=false) |
---|
32 | { |
---|
33 | global $core,$_ctx; |
---|
34 | |
---|
35 | $part = $global ? 'global' : 'local'; |
---|
36 | $prefix = $part.'_'; |
---|
37 | |
---|
38 | try { |
---|
39 | foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { |
---|
40 | $core->blog->settings->addNamespace($ns); |
---|
41 | $ns_settings = $global ? |
---|
42 | $namespace->dumpGlobalSettings() : $namespace->dumpSettings(); |
---|
43 | |
---|
44 | foreach ($ns_settings as $k => $v) { |
---|
45 | // need to cast type |
---|
46 | $f = (string) $form->{$prefix.$ns.'_'.$k}; |
---|
47 | settype($f,$v['type']); |
---|
48 | |
---|
49 | $core->blog->settings->$ns->put($k,$f,null,null,true,$global); |
---|
50 | $form->{$prefix.$ns.'_'.$k} = $f; |
---|
51 | } |
---|
52 | } |
---|
53 | $core->blog->triggerBlog(); |
---|
54 | |
---|
55 | http::redirect(self::$p_url.'&upd=1&part='.$part); |
---|
56 | } |
---|
57 | catch (Exception $e) { |
---|
58 | $_ctx->addError($e->getMessage()); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | # Set nav and settings forms |
---|
63 | public static function setForms($global=false) |
---|
64 | { |
---|
65 | global $core, $_ctx; |
---|
66 | |
---|
67 | $prefix = $global ? 'global_' : 'local_'; |
---|
68 | $action = $global ? 'updGlobal' : 'updLocal'; |
---|
69 | |
---|
70 | if (!empty($_POST[$prefix.'nav'])) { |
---|
71 | http::redirect(self::$p_url.$_POST[$prefix.'nav']); |
---|
72 | exit; |
---|
73 | } |
---|
74 | |
---|
75 | $nav_form = new dcForm($core,$prefix.'nav_form','plugin.php'); |
---|
76 | $settings_form = new dcForm($core,$prefix.'settings_form','plugin.php'); |
---|
77 | |
---|
78 | $settings = $combo = array(); |
---|
79 | foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { |
---|
80 | $ns_settings = $global ? |
---|
81 | $namespace->dumpGlobalSettings() : $namespace->dumpSettings(); |
---|
82 | |
---|
83 | foreach ($ns_settings as $k => $v) { |
---|
84 | $settings[$ns][$k] = $v; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | ksort($settings); |
---|
89 | foreach ($settings as $ns => $s) { |
---|
90 | $combo['#'.$prefix.$ns] = $ns; |
---|
91 | ksort($s); |
---|
92 | foreach ($s as $k => $v) { |
---|
93 | if ($v['type'] == 'boolean') { |
---|
94 | $settings_form->addField( |
---|
95 | new dcFieldCombo($prefix.$ns.'_'.$k, |
---|
96 | '',array(1 => __('yes'),0 => __('no')))); |
---|
97 | } |
---|
98 | else { |
---|
99 | $settings_form->addField( |
---|
100 | new dcFieldText($prefix.$ns.'_'.$k,'')); |
---|
101 | } |
---|
102 | $settings_form->{$prefix.$ns.'_'.$k} = $v['value']; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | $nav_form |
---|
107 | ->addField( |
---|
108 | new dcFieldCombo($prefix.'nav','',$combo,array( |
---|
109 | "label" => __('Goto:')))) |
---|
110 | ->addField( |
---|
111 | new dcFieldSubmit($prefix.'nav_submit',__('OK'))) |
---|
112 | ->addField( |
---|
113 | new dcFieldHidden ('p','aboutConfig')) |
---|
114 | ; |
---|
115 | |
---|
116 | $settings_form |
---|
117 | ->addField( |
---|
118 | new dcFieldSubmit($prefix.'submit',__('Save'),array( |
---|
119 | 'action' => array('adminPageAboutConfig',$action)))) |
---|
120 | ->addField( |
---|
121 | new dcFieldHidden ('p','aboutConfig')) |
---|
122 | ; |
---|
123 | |
---|
124 | $_ctx->{$prefix.'settings'} = $settings; |
---|
125 | |
---|
126 | $nav_form->setup(); |
---|
127 | $settings_form->setup(); |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | # Local settings forms |
---|
132 | adminPageAboutConfig::setForms(); |
---|
133 | |
---|
134 | # Global settings forms |
---|
135 | adminPageAboutConfig::setForms(true); |
---|
136 | |
---|
137 | # Commons |
---|
138 | if (!empty($_GET['upd'])) { |
---|
139 | $_ctx->setAlert(__('Configuration successfully updated')); |
---|
140 | } |
---|
141 | if (!empty($_GET['upda'])) { |
---|
142 | $_ctx->setAlert(__('Settings definition successfully updated')); |
---|
143 | } |
---|
144 | $_ctx->default_tab = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; |
---|
145 | $_ctx->setBreadCrumb('about:config'); |
---|
146 | $core->tpl->display('@aboutConfig/index.html.twig'); |
---|
147 | ?> |
---|