Dotclear


Ignore:
Timestamp:
02/18/18 18:16:29 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

use strict and no more linter warnings/errors as far as possible, switch from inline js to separate loaded file

Location:
plugins/aboutConfig
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/aboutConfig/index.php

    r3421 r3709  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 
     12if (!defined('DC_CONTEXT_ADMIN')) {return;} 
    1313 
    1414# Local navigation 
    1515if (!empty($_POST['gs_nav'])) { 
    16      http::redirect($p_url.$_POST['gs_nav']); 
    17      exit; 
     16    http::redirect($p_url . $_POST['gs_nav']); 
     17    exit; 
    1818} 
    1919if (!empty($_POST['ls_nav'])) { 
    20      http::redirect($p_url.$_POST['ls_nav']); 
    21      exit; 
     20    http::redirect($p_url . $_POST['ls_nav']); 
     21    exit; 
    2222} 
    2323 
    2424# Local settings update 
    25 if (!empty($_POST['s']) && is_array($_POST['s'])) 
     25if (!empty($_POST['s']) && is_array($_POST['s'])) { 
     26    try 
     27    { 
     28        foreach ($_POST['s'] as $ns => $s) { 
     29            $core->blog->settings->addNamespace($ns); 
     30            foreach ($s as $k => $v) { 
     31                if ($_POST['s_type'][$ns][$k] == 'array') { 
     32                    $v = json_decode($v, true); 
     33                } 
     34                $core->blog->settings->$ns->put($k, $v); 
     35            } 
     36            $core->blog->triggerBlog(); 
     37        } 
     38 
     39        dcPage::addSuccessNotice(__('Configuration successfully updated')); 
     40        http::redirect($p_url); 
     41    } catch (Exception $e) { 
     42        $core->error->add($e->getMessage()); 
     43    } 
     44} 
     45 
     46# Global settings update 
     47if (!empty($_POST['gs']) && is_array($_POST['gs'])) { 
     48    try 
     49    { 
     50        foreach ($_POST['gs'] as $ns => $s) { 
     51            $core->blog->settings->addNamespace($ns); 
     52            foreach ($s as $k => $v) { 
     53                if ($_POST['gs_type'][$ns][$k] == 'array') { 
     54                    $v = json_decode($v, true); 
     55                } 
     56                $core->blog->settings->$ns->put($k, $v, null, null, true, true); 
     57            } 
     58            $core->blog->triggerBlog(); 
     59        } 
     60 
     61        dcPage::addSuccessNotice(__('Configuration successfully updated')); 
     62        http::redirect($p_url . '&part=global'); 
     63    } catch (Exception $e) { 
     64        $core->error->add($e->getMessage()); 
     65    } 
     66} 
     67 
     68$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 
     69 
     70function settingLine($id, $s, $ns, $field_name, $strong_label) 
    2671{ 
    27      try 
    28      { 
    29           foreach ($_POST['s'] as $ns => $s) { 
    30                $core->blog->settings->addNamespace($ns); 
    31                foreach ($s as $k => $v) { 
    32                     if ($_POST['s_type'][$ns][$k] == 'array') { 
    33                          $v = json_decode($v,true); 
    34                     } 
    35                     $core->blog->settings->$ns->put($k,$v); 
    36                } 
    37                $core->blog->triggerBlog(); 
    38           } 
    39  
    40           dcPage::addSuccessNotice(__('Configuration successfully updated')); 
    41           http::redirect($p_url); 
    42      } 
    43      catch (Exception $e) 
    44      { 
    45           $core->error->add($e->getMessage()); 
    46      } 
    47 } 
    48  
    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                $core->blog->settings->addNamespace($ns); 
    56                foreach ($s as $k => $v) { 
    57                     if ($_POST['gs_type'][$ns][$k] == 'array') { 
    58                          $v = json_decode($v,true); 
    59                     } 
    60                     $core->blog->settings->$ns->put($k,$v,null,null,true,true); 
    61                } 
    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      } 
    72 } 
    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           if ($s['type'] == 'array') { 
    83                $field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$ns.'_'.$id),40,null, 
    84                html::escapeHTML(json_encode($s['value']))); 
    85           } else { 
    86                $field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$ns.'_'.$id),40,null, 
    87                html::escapeHTML($s['value'])); 
    88           } 
    89      } 
    90      $type = form::hidden(array($field_name.'_type'.'['.$ns.']['.$id.']',$field_name.'_'.$ns.'_'.$id.'_type'), 
    91           html::escapeHTML($s['type'])); 
    92  
    93      $slabel = $strong_label ? '<strong>%s</strong>' : '%s'; 
    94  
    95      return 
    96      '<tr class="line">'. 
    97      '<td scope="row"><label for="'.$field_name.'_'.$ns.'_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'. 
    98      '<td>'.$field.'</td>'. 
    99      '<td>'.$s['type'].$type.'</td>'. 
    100      '<td>'.html::escapeHTML($s['label']).'</td>'. 
    101      '</tr>'; 
     72    if ($s['type'] == 'boolean') { 
     73        $field = form::combo(array($field_name . '[' . $ns . '][' . $id . ']', $field_name . '_' . $ns . '_' . $id), 
     74            array(__('yes') => 1, __('no') => 0), $s['value'] ? 1 : 0); 
     75    } else { 
     76        if ($s['type'] == 'array') { 
     77            $field = form::field(array($field_name . '[' . $ns . '][' . $id . ']', $field_name . '_' . $ns . '_' . $id), 40, null, 
     78                html::escapeHTML(json_encode($s['value']))); 
     79        } else { 
     80            $field = form::field(array($field_name . '[' . $ns . '][' . $id . ']', $field_name . '_' . $ns . '_' . $id), 40, null, 
     81                html::escapeHTML($s['value'])); 
     82        } 
     83    } 
     84    $type = form::hidden(array($field_name . '_type' . '[' . $ns . '][' . $id . ']', $field_name . '_' . $ns . '_' . $id . '_type'), 
     85        html::escapeHTML($s['type'])); 
     86 
     87    $slabel = $strong_label ? '<strong>%s</strong>' : '%s'; 
     88 
     89    return 
     90    '<tr class="line">' . 
     91    '<td scope="row"><label for="' . $field_name . '_' . $ns . '_' . $id . '">' . sprintf($slabel, html::escapeHTML($id)) . '</label></td>' . 
     92    '<td>' . $field . '</td>' . 
     93    '<td>' . $s['type'] . $type . '</td>' . 
     94    '<td>' . html::escapeHTML($s['label']) . '</td>' . 
     95        '</tr>'; 
    10296} 
    10397?> 
     
    10599<head> 
    106100  <title>about:config</title> 
    107   <?php echo dcPage::jsPageTabs($part); ?> 
    108   <script type="text/javascript"> 
    109      $(function() { 
    110           $("#gs_submit").hide(); 
    111           $("#ls_submit").hide(); 
    112           $("#gs_nav").change(function() { 
    113                window.location = $("#gs_nav option:selected").val(); 
    114           }) 
    115           $("#ls_nav").change(function() { 
    116                window.location = $("#ls_nav option:selected").val(); 
    117           }) 
    118      }); 
    119      </script> 
     101  <?php echo dcPage::jsPageTabs($part) . dcPage::jsLoad(dcPage::getPF('aboutConfig/js/index.js')); ?> 
    120102</head> 
    121103 
     
    123105<?php 
    124106echo dcPage::breadcrumb( 
    125      array( 
    126           __('System') => '', 
    127           html::escapeHTML($core->blog->name) => '', 
    128           __('about:config') => '' 
    129      )). 
    130      dcPage::notices(); 
    131 ?> 
    132  
    133 <div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?>"> 
    134 <h3 class="out-of-screen-if-js"><?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?></h3> 
    135  
    136 <?php 
    137 $table_header = '<div class="table-outer"><table class="settings" id="%s"><caption class="as_h3">%s</caption>'. 
    138 '<thead>'. 
    139 '<tr>'."\n". 
    140 '  <th class="nowrap">'.__('Setting ID').'</th>'."\n". 
    141 '  <th>'.__('Value').'</th>'."\n". 
    142 '  <th>'.__('Type').'</th>'."\n". 
    143 '  <th class="maximalx">'.__('Description').'</th>'."\n". 
    144 '</tr>'."\n". 
    145 '</thead>'."\n". 
    146 '<tbody>'; 
     107    array( 
     108        __('System')                        => '', 
     109        html::escapeHTML($core->blog->name) => '', 
     110        __('about:config')                  => '' 
     111    )) . 
     112dcPage::notices(); 
     113?> 
     114 
     115<div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'), html::escapeHTML($core->blog->name)); ?>"> 
     116<h3 class="out-of-screen-if-js"><?php echo sprintf(__('Settings for %s'), html::escapeHTML($core->blog->name)); ?></h3> 
     117 
     118<?php 
     119$table_header = '<div class="table-outer"><table class="settings" id="%s"><caption class="as_h3">%s</caption>' . 
     120'<thead>' . 
     121'<tr>' . "\n" . 
     122'  <th class="nowrap">' . __('Setting ID') . '</th>' . "\n" . 
     123'  <th>' . __('Value') . '</th>' . "\n" . 
     124'  <th>' . __('Type') . '</th>' . "\n" . 
     125'  <th class="maximalx">' . __('Description') . '</th>' . "\n" . 
     126    '</tr>' . "\n" . 
     127    '</thead>' . "\n" . 
     128    '<tbody>'; 
    147129$table_footer = '</tbody></table></div>'; 
    148130 
    149131$settings = array(); 
    150132foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 
    151      foreach ($namespace->dumpSettings() as $k => $v) { 
    152           $settings[$ns][$k] = $v; 
    153      } 
     133    foreach ($namespace->dumpSettings() as $k => $v) { 
     134        $settings[$ns][$k] = $v; 
     135    } 
    154136} 
    155137ksort($settings); 
    156138if (count($settings) > 0) { 
    157      $ns_combo = array(); 
    158      foreach ($settings as $ns => $s) { 
    159           $ns_combo[$ns] = '#l_'.$ns; 
    160      } 
    161      echo 
    162           '<form action="'.$core->adminurl->get('admin.plugin').'" method="post">'. 
    163           '<p class="anchor-nav">'. 
    164           '<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo). 
    165           ' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'. 
    166           '<input type="hidden" name="p" value="aboutConfig" />'. 
    167           $core->formNonce().'</p></form>'; 
     139    $ns_combo = array(); 
     140    foreach ($settings as $ns => $s) { 
     141        $ns_combo[$ns] = '#l_' . $ns; 
     142    } 
     143    echo 
     144    '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post">' . 
     145    '<p class="anchor-nav">' . 
     146    '<label for="ls_nav" class="classic">' . __('Goto:') . '</label> ' . form::combo('ls_nav', $ns_combo) . 
     147    ' <input type="submit" value="' . __('Ok') . '" id="ls_submit" />' . 
     148    '<input type="hidden" name="p" value="aboutConfig" />' . 
     149    $core->formNonce() . '</p></form>'; 
    168150} 
    169151?> 
     
    172154 
    173155<?php 
    174 foreach ($settings as $ns => $s) 
    175 { 
    176      ksort($s); 
    177      echo sprintf($table_header,'l_'.$ns,$ns); 
    178      foreach ($s as $k => $v) 
    179      { 
    180           echo settingLine($k,$v,$ns,'s',!$v['global']); 
    181      } 
    182      echo $table_footer; 
     156foreach ($settings as $ns => $s) { 
     157    ksort($s); 
     158    echo sprintf($table_header, 'l_' . $ns, $ns); 
     159    foreach ($s as $k => $v) { 
     160        echo settingLine($k, $v, $ns, 's', !$v['global']); 
     161    } 
     162    echo $table_footer; 
    183163} 
    184164?> 
     
    197177 
    198178foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) { 
    199      foreach ($namespace->dumpGlobalSettings() as $k => $v) { 
    200           $settings[$ns][$k] = $v; 
    201      } 
     179    foreach ($namespace->dumpGlobalSettings() as $k => $v) { 
     180        $settings[$ns][$k] = $v; 
     181    } 
    202182} 
    203183 
     
    205185 
    206186if (count($settings) > 0) { 
    207      $ns_combo = array(); 
    208      foreach ($settings as $ns => $s) { 
    209           $ns_combo[$ns] = '#g_'.$ns; 
    210      } 
    211      echo 
    212           '<form action="'.$core->adminurl->get('admin.plugin').'" method="post">'. 
    213           '<p class="anchor-nav">'. 
    214           '<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo).' '. 
    215           '<input type="submit" value="'.__('Ok').'" id="gs_submit" />'. 
    216           '<input type="hidden" name="p" value="aboutConfig" />'. 
    217           $core->formNonce().'</p></form>'; 
     187    $ns_combo = array(); 
     188    foreach ($settings as $ns => $s) { 
     189        $ns_combo[$ns] = '#g_' . $ns; 
     190    } 
     191    echo 
     192    '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post">' . 
     193    '<p class="anchor-nav">' . 
     194    '<label for="gs_nav" class="classic">' . __('Goto:') . '</label> ' . form::combo('gs_nav', $ns_combo) . ' ' . 
     195    '<input type="submit" value="' . __('Ok') . '" id="gs_submit" />' . 
     196    '<input type="hidden" name="p" value="aboutConfig" />' . 
     197    $core->formNonce() . '</p></form>'; 
    218198} 
    219199?> 
     
    222202 
    223203<?php 
    224 foreach ($settings as $ns => $s) 
    225 { 
    226      ksort($s); 
    227      echo sprintf($table_header,'g_'.$ns,$ns); 
    228      foreach ($s as $k => $v) 
    229      { 
    230           echo settingLine($k,$v,$ns,'gs',false); 
    231      } 
    232      echo $table_footer; 
     204foreach ($settings as $ns => $s) { 
     205    ksort($s); 
     206    echo sprintf($table_header, 'g_' . $ns, $ns); 
     207    foreach ($s as $k => $v) { 
     208        echo settingLine($k, $v, $ns, 'gs', false); 
     209    } 
     210    echo $table_footer; 
    233211} 
    234212?> 
     
    240218</div> 
    241219 
    242 <?php dcPage::helpBlock('aboutConfig'); ?> 
     220<?php dcPage::helpBlock('aboutConfig');?> 
    243221 
    244222</body> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map