Dotclear


Ignore:
Timestamp:
08/09/13 08:01:31 (11 years ago)
Author:
Dsls
Branch:
twig
Parents:
1158:9d7267aec27b (diff), 1314:99a1319b79fc (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.
Message:

Merge with default

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/aboutConfig/index.php

    r1312 r1315  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_CONTEXT_ADMIN')) { return; } 
    1313 
    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'])) 
     14class adminPageAboutConfig 
    2615{ 
    27      try 
     16     public static $p_url = 'plugin.php?p=aboutConfig'; 
     17      
     18     # Update local settings 
     19     public static function updLocal($form) 
    2820     { 
    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(); 
    3254                
    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; 
    3873          } 
    3974           
    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(); 
    45128     } 
    46129} 
    47130 
    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 
     132adminPageAboutConfig::setForms(); 
     133 
     134# Global settings forms 
     135adminPageAboutConfig::setForms(true); 
     136 
     137# Commons 
     138if (!empty($_GET['upd'])) { 
     139     $_ctx->setAlert(__('Configuration successfully updated')); 
    70140} 
    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>'. 
    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>'; 
     141if (!empty($_GET['upda'])) { 
     142     $_ctx->setAlert(__('Settings definition successfully updated')); 
    93143} 
     144$_ctx->default_tab = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 
     145$_ctx->fillPageTitle('about:config'); 
     146$core->tpl->display('@aboutConfig/index.html.twig'); 
    94147?> 
    95 <html> 
    96 <head> 
    97   <title>about:config</title> 
    98   <?php echo dcPage::jsPageTabs($part); ?> 
    99   <style type="text/css"> 
    100   table.settings { border: 1px solid #999; margin-bottom: 2em; } 
    101   table.settings th { background: #f5f5f5; color: #444; padding-top: 0.3em; padding-bottom: 0.3em; } 
    102   </style> 
    103      <script type="text/javascript"> 
    104      //<![CDATA[ 
    105      $(function() { 
    106           $("#gs_submit").hide(); 
    107           $("#ls_submit").hide(); 
    108           $("#gs_nav").change(function() { 
    109                window.location = $("#gs_nav option:selected").val(); 
    110           }) 
    111           $("#ls_nav").change(function() { 
    112                window.location = $("#ls_nav option:selected").val(); 
    113           }) 
    114      }); 
    115      //]]> 
    116      </script> 
    117 </head> 
    118  
    119 <body> 
    120 <?php 
    121 if (!empty($_GET['upd'])) { 
    122      dcPage::message(__('Configuration successfully updated')); 
    123 } 
    124  
    125 if (!empty($_GET['upda'])) { 
    126      dcPage::message(__('Settings definition successfully updated')); 
    127 } 
    128 ?> 
    129 <h2><?php echo __('System'); ?> &rsaquo; <span class="page-title">about:config</span></h2> 
    130  
    131 <div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?>"> 
    132  
    133  
    134 <?php 
    135 $table_header = '<table class="settings" id="%s"><caption>%s</caption>'. 
    136 '<thead>'. 
    137 '<tr>'."\n". 
    138 '  <th class="nowrap">Setting ID</th>'."\n". 
    139 '  <th>'.__('Value').'</th>'."\n". 
    140 '  <th>'.__('Type').'</th>'."\n". 
    141 '  <th class="maximalx">'.__('Description').'</th>'."\n". 
    142 '</tr>'."\n". 
    143 '</thead>'."\n". 
    144 '<tbody>'; 
    145 $table_footer = '</tbody></table>'; 
    146  
    147 $settings = array(); 
    148 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 
    149      foreach ($namespace->dumpSettings() as $k => $v) { 
    150           $settings[$ns][$k] = $v; 
    151      } 
    152 } 
    153 ksort($settings); 
    154 if (count($settings) > 0) { 
    155      $ns_combo = array(); 
    156      foreach ($settings as $ns => $s) { 
    157           $ns_combo[$ns] = '#l_'.$ns; 
    158      } 
    159      echo  
    160           '<form action="plugin.php" method="post">'. 
    161           '<p class="anchor-nav">'. 
    162           '<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo). 
    163           ' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'. 
    164           '<input type="hidden" name="p" value="aboutConfig" />'. 
    165           $core->formNonce().'</p></form>'; 
    166 } 
    167 ?> 
    168  
    169 <form action="plugin.php" method="post"> 
    170  
    171 <?php 
    172 foreach ($settings as $ns => $s) 
    173 { 
    174      ksort($s); 
    175      echo sprintf($table_header,'l_'.$ns,$ns); 
    176      foreach ($s as $k => $v) 
    177      { 
    178           echo settingLine($k,$v,$ns,'s',!$v['global']); 
    179      } 
    180      echo $table_footer; 
    181 } 
    182 ?> 
    183  
    184 <p><input type="submit" value="<?php echo __('Save'); ?>" /> 
    185 <input type="hidden" name="p" value="aboutConfig" /> 
    186 <?php echo $core->formNonce(); ?></p> 
    187 </form> 
    188 </div> 
    189  
    190 <div id="global" class="multi-part" title="<?php echo __('global settings'); ?>"> 
    191  
    192 <?php 
    193 $settings = array(); 
    194  
    195 foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 
    196      foreach ($namespace->dumpGlobalSettings() as $k => $v) { 
    197           $settings[$ns][$k] = $v; 
    198      } 
    199 } 
    200  
    201 ksort($settings); 
    202  
    203 if (count($settings) > 0) { 
    204      $ns_combo = array(); 
    205      foreach ($settings as $ns => $s) { 
    206           $ns_combo[$ns] = '#g_'.$ns; 
    207      } 
    208      echo  
    209           '<form action="plugin.php" method="post">'. 
    210           '<p class="anchor-nav">'. 
    211           '<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo). 
    212           ' <input type="submit" value="'.__('Ok').'" id="gs_submit" />'. 
    213           '<input type="hidden" name="p" value="aboutConfig" />'. 
    214           $core->formNonce().'</p></form>'; 
    215 } 
    216 ?> 
    217  
    218 <form action="plugin.php" method="post"> 
    219  
    220 <?php 
    221 foreach ($settings as $ns => $s) 
    222 { 
    223      ksort($s); 
    224      echo sprintf($table_header,'g_'.$ns,$ns); 
    225      foreach ($s as $k => $v) 
    226      { 
    227           echo settingLine($k,$v,$ns,'gs',false); 
    228      } 
    229      echo $table_footer; 
    230 } 
    231 ?> 
    232  
    233 <p><input type="submit" value="<?php echo __('Save'); ?>" /> 
    234 <input type="hidden" name="p" value="aboutConfig" /> 
    235 <?php echo $core->formNonce(); ?></p> 
    236 </form> 
    237 </div> 
    238  
    239 </body> 
    240 </html> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map