Changeset 2593:6741802596a0 for plugins/aboutConfig
- Timestamp:
- 11/27/13 16:32:38 (12 years ago)
- Branch:
- twig
- Children:
- 2612:1537212bd291, 2613:014098e27ea0
- Parents:
- 2468:d7fda5a0bd39 (diff), 2589:3d427735ca70 (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. - Location:
- plugins/aboutConfig
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/aboutConfig/_admin.php
r2566 r2593 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 $_menu[' System']->addItem('about:config','plugin.php?p=aboutConfig','index.php?pf=aboutConfig/icon.png',14 $_menu['Plugins']->addItem('about:config','plugin.php?p=aboutConfig','index.php?pf=aboutConfig/icon.png', 15 15 preg_match('/plugin.php\?p=aboutConfig(&.*)?$/',$_SERVER['REQUEST_URI']), 16 16 $core->auth->isSuperAdmin()); 17 18 $core->tpl->getLoader()->addPath(dirname(__FILE__).'/admtpl/','aboutConfig'); 19 ?> -
plugins/aboutConfig/index.php
r2566 r2593 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); 32 33 foreach ($s as $k => $v) { 34 $core->blog->settings->$ns->put($k,$v); 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 } 35 52 } 36 37 53 $core->blog->triggerBlog(); 54 55 http::redirect(self::$p_url.'&upd=1&part='.$part); 38 56 } 39 40 dcPage::addSuccessNotice(__('Configuration successfully updated'));41 http::redirect($p_url);57 catch (Exception $e) { 58 $_ctx->addError($e->getMessage()); 59 } 42 60 } 43 catch (Exception $e) 61 62 # Set nav and settings forms 63 public static function setForms($global=false) 44 64 { 45 $core->error->add($e->getMessage()); 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(); 46 128 } 47 129 } 48 130 49 # Global settings update 50 if (!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); 131 # Local settings forms 132 adminPageAboutConfig::setForms(); 57 133 58 foreach ($s as $k => $v) { 59 $core->blog->settings->$ns->put($k,$v,null,null,true,true); 60 } 134 # Global settings forms 135 adminPageAboutConfig::setForms(true); 61 136 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 } 137 # Commons 138 if (!empty($_GET['upd'])) { 139 $_ctx->setAlert(__('Configuration successfully updated')); 72 140 } 73 74 $part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 75 76 function 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>'; 141 if (!empty($_GET['upda'])) { 142 $_ctx->setAlert(__('Settings definition successfully updated')); 95 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'); 96 147 ?> 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 <?php119 echo 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 <?php132 $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();145 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {146 foreach ($namespace->dumpSettings() as $k => $v) {147 $settings[$ns][$k] = $v;148 }149 }150 ksort($settings);151 if (count($settings) > 0) {152 $ns_combo = array();153 foreach ($settings as $ns => $s) {154 $ns_combo[$ns] = '#l_'.$ns;155 }156 echo157 '<form action="plugin.php" 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="plugin.php" method="post">167 168 <?php169 foreach ($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 <?php191 $settings = array();192 193 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {194 foreach ($namespace->dumpGlobalSettings() as $k => $v) {195 $settings[$ns][$k] = $v;196 }197 }198 199 ksort($settings);200 201 if (count($settings) > 0) {202 $ns_combo = array();203 foreach ($settings as $ns => $s) {204 $ns_combo[$ns] = '#g_'.$ns;205 }206 echo207 '<form action="plugin.php" 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="plugin.php" method="post">217 218 <?php219 foreach ($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 TracChangeset
for help on using the changeset viewer.