[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1109] | 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
[0] | 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 | |
---|
[1070] | 14 | class adminPageAboutConfig |
---|
[0] | 15 | { |
---|
[1070] | 16 | public static $p_url = 'plugin.php?p=aboutConfig'; |
---|
| 17 | |
---|
| 18 | # Update local settings |
---|
| 19 | public static function updLocal($form) |
---|
[0] | 20 | { |
---|
[1070] | 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 | } |
---|
[0] | 52 | } |
---|
| 53 | $core->blog->triggerBlog(); |
---|
[2322] | 54 | |
---|
[1070] | 55 | http::redirect(self::$p_url.'&upd=1&part='.$part); |
---|
[0] | 56 | } |
---|
[1070] | 57 | catch (Exception $e) { |
---|
| 58 | $_ctx->addError($e->getMessage()); |
---|
| 59 | } |
---|
[0] | 60 | } |
---|
[1070] | 61 | |
---|
| 62 | # Set nav and settings forms |
---|
| 63 | public static function setForms($global=false) |
---|
[0] | 64 | { |
---|
[1070] | 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; |
---|
[1474] | 73 | } |
---|
| 74 | |
---|
[1070] | 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; |
---|
[2322] | 85 | } |
---|
| 86 | } |
---|
[1070] | 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(); |
---|
[0] | 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
[1070] | 131 | # Local settings forms |
---|
| 132 | adminPageAboutConfig::setForms(); |
---|
[2566] | 133 | |
---|
[1070] | 134 | # Global settings forms |
---|
| 135 | adminPageAboutConfig::setForms(true); |
---|
[2566] | 136 | |
---|
[1070] | 137 | # Commons |
---|
| 138 | if (!empty($_GET['upd'])) { |
---|
[1089] | 139 | $_ctx->setAlert(__('Configuration successfully updated')); |
---|
[0] | 140 | } |
---|
[1070] | 141 | if (!empty($_GET['upda'])) { |
---|
[1089] | 142 | $_ctx->setAlert(__('Settings definition successfully updated')); |
---|
[0] | 143 | } |
---|
[1070] | 144 | $_ctx->default_tab = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; |
---|
[1414] | 145 | $_ctx->setBreadCrumb('about:config'); |
---|
[1070] | 146 | $core->tpl->display('@aboutConfig/index.html.twig'); |
---|
| 147 | ?> |
---|