Changeset 1490:60501ef579eb for plugins
- Timestamp:
- 08/19/13 08:04:33 (12 years ago)
- Branch:
- twig
- Parents:
- 1489:f2398e7f3395 (diff), 1466:e67efe636ce1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/aboutConfig/index.php
r1358 r1490 4 4 # This file is part of Dotclear 2. 5 5 # 6 # Copyright (c) 2003-201 3Olivier Meunier & Association Dotclear6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 7 7 # Licensed under the GPL version 2.0 license. 8 8 # See LICENSE file or … … 12 12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 13 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'])) 14 class adminPageAboutConfig 26 15 { 27 try 16 public static $p_url = 'plugin.php?p=aboutConfig'; 17 18 # Update local settings 19 public static function updLocal($form) 28 20 { 29 foreach ($_POST['s'] as $ns => $s) 30 { 31 $core->blog->settings->addNamespace($ns); 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(); 32 54 33 foreach ($s as $k => $v) { 34 $core->blog->settings->$ns->put($k,$v); 35 } 36 37 $core->blog->triggerBlog(); 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; 38 73 } 39 74 40 http::redirect($p_url.'&upd=1'); 41 } 42 catch (Exception $e) 43 { 44 $core->error->add($e->getMessage()); 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(); 45 128 } 46 129 } 47 130 48 # Global settings update 49 if (!empty($_POST['gs']) && is_array($_POST['gs'])) 50 { 51 try 52 { 53 foreach ($_POST['gs'] as $ns => $s) 54 { 55 $core->blog->settings->addNamespace($ns); 56 57 foreach ($s as $k => $v) { 58 $core->blog->settings->$ns->put($k,$v,null,null,true,true); 59 } 60 61 $core->blog->triggerBlog(); 62 } 63 64 http::redirect($p_url.'&upd=1&part=global'); 65 } 66 catch (Exception $e) 67 { 68 $core->error->add($e->getMessage()); 69 } 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')); 70 140 } 71 72 $part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 73 74 function settingLine($id,$s,$ns,$field_name,$strong_label) 75 { 76 if ($s['type'] == 'boolean') { 77 $field = form::combo(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id), 78 array(__('yes') => 1, __('no') => 0),$s['value'] ? 1 : 0); 79 } else { 80 $field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id),40,null, 81 html::escapeHTML($s['value'])); 82 } 83 84 $slabel = $strong_label ? '<strong>%s</strong>' : '%s'; 85 86 return 87 '<tr class="line">'. 88 '<td scope="raw"><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'. 89 '<td>'.$field.'</td>'. 90 '<td>'.$s['type'].'</td>'. 91 '<td>'.html::escapeHTML($s['label']).'</td>'. 92 '</tr>'; 141 if (!empty($_GET['upda'])) { 142 $_ctx->setAlert(__('Settings definition successfully updated')); 93 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'); 94 147 ?> 95 <html>96 <head>97 <title>about:config</title>98 <?php echo dcPage::jsPageTabs($part); ?>99 <script type="text/javascript">100 //<![CDATA[101 $(function() {102 $("#gs_submit").hide();103 $("#ls_submit").hide();104 $("#gs_nav").change(function() {105 window.location = $("#gs_nav option:selected").val();106 })107 $("#ls_nav").change(function() {108 window.location = $("#ls_nav option:selected").val();109 })110 });111 //]]>112 </script>113 </head>114 115 <body>116 <?php117 echo dcPage::breadcrumb(118 array(119 __('System') => '',120 html::escapeHTML($core->blog->name) => '',121 '<span class="page-title">'.__('about:config').'</span>' => ''122 ));123 if (!empty($_GET['upd'])) {124 dcPage::message(__('Configuration successfully updated'));125 }126 127 if (!empty($_GET['upda'])) {128 dcPage::message(__('Settings definition successfully updated'));129 }130 ?>131 132 <div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?>">133 134 135 <?php136 $table_header = '<table class="settings" id="%s"><caption class="as_h3">%s</caption>'.137 '<thead>'.138 '<tr>'."\n".139 ' <th class="nowrap">Setting ID</th>'."\n".140 ' <th>'.__('Value').'</th>'."\n".141 ' <th>'.__('Type').'</th>'."\n".142 ' <th class="maximalx">'.__('Description').'</th>'."\n".143 '</tr>'."\n".144 '</thead>'."\n".145 '<tbody>';146 $table_footer = '</tbody></table>';147 148 $settings = array();149 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {150 foreach ($namespace->dumpSettings() as $k => $v) {151 $settings[$ns][$k] = $v;152 }153 }154 ksort($settings);155 if (count($settings) > 0) {156 $ns_combo = array();157 foreach ($settings as $ns => $s) {158 $ns_combo[$ns] = '#l_'.$ns;159 }160 echo161 '<form action="plugin.php" method="post">'.162 '<p class="anchor-nav">'.163 '<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo).164 ' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'.165 '<input type="hidden" name="p" value="aboutConfig" />'.166 $core->formNonce().'</p></form>';167 }168 ?>169 170 <form action="plugin.php" method="post">171 172 <?php173 foreach ($settings as $ns => $s)174 {175 ksort($s);176 echo sprintf($table_header,'l_'.$ns,$ns);177 foreach ($s as $k => $v)178 {179 echo settingLine($k,$v,$ns,'s',!$v['global']);180 }181 echo $table_footer;182 }183 ?>184 185 <p><input type="submit" value="<?php echo __('Save'); ?>" />186 <input type="hidden" name="p" value="aboutConfig" />187 <?php echo $core->formNonce(); ?></p>188 </form>189 </div>190 191 <div id="global" class="multi-part" title="<?php echo __('global settings'); ?>">192 193 <?php194 $settings = array();195 196 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {197 foreach ($namespace->dumpGlobalSettings() as $k => $v) {198 $settings[$ns][$k] = $v;199 }200 }201 202 ksort($settings);203 204 if (count($settings) > 0) {205 $ns_combo = array();206 foreach ($settings as $ns => $s) {207 $ns_combo[$ns] = '#g_'.$ns;208 }209 echo210 '<form action="plugin.php" method="post">'.211 '<p class="anchor-nav">'.212 '<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo).213 ' <input type="submit" value="'.__('Ok').'" id="gs_submit" />'.214 '<input type="hidden" name="p" value="aboutConfig" />'.215 $core->formNonce().'</p></form>';216 }217 ?>218 219 <form action="plugin.php" method="post">220 221 <?php222 foreach ($settings as $ns => $s)223 {224 ksort($s);225 echo sprintf($table_header,'g_'.$ns,$ns);226 foreach ($s as $k => $v)227 {228 echo settingLine($k,$v,$ns,'gs',false);229 }230 echo $table_footer;231 }232 ?>233 234 <p><input type="submit" value="<?php echo __('Save'); ?>" />235 <input type="hidden" name="p" value="aboutConfig" />236 <?php echo $core->formNonce(); ?></p>237 </form>238 </div>239 240 </body>241 </html>
Note: See TracChangeset
for help on using the changeset viewer.