Dotclear


Ignore:
Timestamp:
02/15/18 16:39:52 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Use array form of optionnal parameters for form::combo(), code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/themeEditor/_admin.php

    r3672 r3703  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 
     12if (!defined('DC_CONTEXT_ADMIN')) {return;} 
    1313 
    1414if (!isset($__resources['help']['themeEditor'])) { 
    15      $__resources['help']['themeEditor'] = dirname(__FILE__).'/help.html'; 
     15    $__resources['help']['themeEditor'] = dirname(__FILE__) . '/help.html'; 
    1616} 
    1717 
    18 $core->addBehavior('adminCurrentThemeDetails', array('themeEditorBehaviors','theme_editor_details')); 
     18$core->addBehavior('adminCurrentThemeDetails', array('themeEditorBehaviors', 'theme_editor_details')); 
    1919 
    20 $core->addBehavior('adminBeforeUserOptionsUpdate',array('themeEditorBehaviors','adminBeforeUserUpdate')); 
    21 $core->addBehavior('adminPreferencesForm',array('themeEditorBehaviors','adminPreferencesForm')); 
     20$core->addBehavior('adminBeforeUserOptionsUpdate', array('themeEditorBehaviors', 'adminBeforeUserUpdate')); 
     21$core->addBehavior('adminPreferencesForm', array('themeEditorBehaviors', 'adminPreferencesForm')); 
    2222 
    2323class themeEditorBehaviors 
    2424{ 
    25      public static function theme_editor_details($core,$id) 
    26      { 
    27           if ($id != 'default' && $core->auth->isSuperAdmin()) { 
    28                return '<p><a href="'.$core->adminurl->get('admin.plugin.themeEditor').'" class="button">'.__('Edit theme files').'</a></p>'; 
    29           } 
    30      } 
     25    public static function theme_editor_details($core, $id) 
     26    { 
     27        if ($id != 'default' && $core->auth->isSuperAdmin()) { 
     28            return '<p><a href="' . $core->adminurl->get('admin.plugin.themeEditor') . '" class="button">' . __('Edit theme files') . '</a></p>'; 
     29        } 
     30    } 
    3131 
    32      public static function adminBeforeUserUpdate($cur,$userID) 
    33      { 
    34           global $core; 
     32    public static function adminBeforeUserUpdate($cur, $userID) 
     33    { 
     34        global $core; 
    3535 
    36           // Get and store user's prefs for plugin options 
    37           $core->auth->user_prefs->addWorkspace('interface'); 
    38           try { 
    39                $core->auth->user_prefs->interface->put('colorsyntax',!empty($_POST['colorsyntax']),'boolean'); 
    40                $core->auth->user_prefs->interface->put('colorsyntax_theme', 
    41                     (!empty($_POST['colorsyntax_theme']) ? $_POST['colorsyntax_theme'] : '')); 
    42           } 
    43           catch (Exception $e) 
    44           { 
    45                $core->error->add($e->getMessage()); 
    46           } 
    47      } 
     36        // Get and store user's prefs for plugin options 
     37        $core->auth->user_prefs->addWorkspace('interface'); 
     38        try { 
     39            $core->auth->user_prefs->interface->put('colorsyntax', !empty($_POST['colorsyntax']), 'boolean'); 
     40            $core->auth->user_prefs->interface->put('colorsyntax_theme', 
     41                (!empty($_POST['colorsyntax_theme']) ? $_POST['colorsyntax_theme'] : '')); 
     42        } catch (Exception $e) { 
     43            $core->error->add($e->getMessage()); 
     44        } 
     45    } 
    4846 
    49      public static function adminPreferencesForm($core) 
    50      { 
    51           // Add fieldset for plugin options 
    52           $core->auth->user_prefs->addWorkspace('interface'); 
     47    public static function adminPreferencesForm($core) 
     48    { 
     49        // Add fieldset for plugin options 
     50        $core->auth->user_prefs->addWorkspace('interface'); 
    5351 
    54           $themes_list = dcPage::getCodeMirrorThemes(); 
    55           $themes_combo = array(__('Default') => ''); 
    56           foreach ($themes_list as $theme) { 
    57                $themes_combo[$theme] = $theme; 
    58           } 
     52        $themes_list = dcPage::getCodeMirrorThemes(); 
     53        $themes_combo = array(__('Default') => ''); 
     54        foreach ($themes_list as $theme) { 
     55            $themes_combo[$theme] = $theme; 
     56        } 
    5957 
    60           echo 
    61                '<div class="fieldset two-cols clearfix">'. 
    62                '<h5 id="themeEditor_prefs">'.__('Syntax highlighting').'</h5>'; 
    63           echo 
    64                '<div class="col">'. 
    65                '<p><label for="colorsyntax" class="classic">'. 
    66                form::checkbox('colorsyntax',1,$core->auth->user_prefs->interface->colorsyntax).'</label>'. 
    67                __('Syntax highlighting in theme editor'). 
    68                '</p>'; 
    69           if (count($themes_combo) > 1) { 
    70                echo 
    71                     '<p><label for="colorsyntax_theme" class="classic">'.__('Theme:').'</label> '. 
    72                     form::combo('colorsyntax_theme',$themes_combo,$core->auth->user_prefs->interface->colorsyntax_theme, 
    73                          '','',false,'onchange="selectTheme()"'). 
    74                     '</p>'; 
    75           } else { 
    76                echo form::hidden('colorsyntax_theme',''); 
    77           } 
    78           echo '</div>'; 
    79           echo '<div class="col">'; 
    80           echo dcPage::jsLoadCodeMirror('',false,array('javascript')); 
    81           foreach ($themes_list as $theme) { 
    82                echo dcPage::cssLoad('js/codemirror/theme/'.$theme.'.css'); 
    83           } 
    84           echo ' 
     58        echo 
     59        '<div class="fieldset two-cols clearfix">' . 
     60        '<h5 id="themeEditor_prefs">' . __('Syntax highlighting') . '</h5>'; 
     61        echo 
     62        '<div class="col">' . 
     63        '<p><label for="colorsyntax" class="classic">' . 
     64        form::checkbox('colorsyntax', 1, $core->auth->user_prefs->interface->colorsyntax) . '</label>' . 
     65        __('Syntax highlighting in theme editor') . 
     66            '</p>'; 
     67        if (count($themes_combo) > 1) { 
     68            echo 
     69            '<p><label for="colorsyntax_theme" class="classic">' . __('Theme:') . '</label> ' . 
     70            form::combo('colorsyntax_theme', $themes_combo, 
     71                array( 
     72                    'default'    => $core->auth->user_prefs->interface->colorsyntax_theme, 
     73                    'extra_html' => 'onchange="selectTheme()"')) . 
     74                '</p>'; 
     75        } else { 
     76            echo form::hidden('colorsyntax_theme', ''); 
     77        } 
     78        echo '</div>'; 
     79        echo '<div class="col">'; 
     80        echo dcPage::jsLoadCodeMirror('', false, array('javascript')); 
     81        foreach ($themes_list as $theme) { 
     82            echo dcPage::cssLoad('js/codemirror/theme/' . $theme . '.css'); 
     83        } 
     84        echo ' 
    8585<textarea id="codemirror" name="codemirror"> 
    8686function findSequence(goal) { 
     
    9696  return find(1, "1"); 
    9797}</textarea>'; 
    98           echo 
    99           '<script> 
    100                var input = document.getElementById("colorsyntax_theme"); 
    101                var theme = input.options[input.selectedIndex].textContent; 
    102           var editor = CodeMirror.fromTextArea(document.getElementById("codemirror"), { 
    103                mode: "javascript", 
    104                     tabMode: "indent", 
    105                     lineWrapping: 1, 
    106                     lineNumbers: 1, 
    107                     matchBrackets: 1, 
    108                     autoCloseBrackets: 1, 
    109                     theme: "'.($core->auth->user_prefs->interface->colorsyntax_theme != '' ? $core->auth->user_prefs->interface->colorsyntax_theme : 'default').'" 
    110                }); 
    111                function selectTheme() { 
    112                     var input = document.getElementById("colorsyntax_theme"); 
    113                     var theme = input.options[input.selectedIndex].value; 
    114                     if (theme == "") theme = "default"; 
    115                     editor.setOption("theme", theme); 
    116                     editor.refresh(); 
    117                } 
    118          </script>'; 
    119           echo '</div>'; 
    120           echo '</div>'; 
    121      } 
     98        echo 
     99            '<script> 
     100            var input = document.getElementById("colorsyntax_theme"); 
     101            var theme = input.options[input.selectedIndex].textContent; 
     102            var editor = CodeMirror.fromTextArea(document.getElementById("codemirror"), { 
     103                mode: "javascript", 
     104                tabMode: "indent", 
     105                lineWrapping: 1, 
     106                lineNumbers: 1, 
     107                matchBrackets: 1, 
     108                autoCloseBrackets: 1, 
     109                theme: "' . ($core->auth->user_prefs->interface->colorsyntax_theme != '' ? $core->auth->user_prefs->interface->colorsyntax_theme : 'default') . '" 
     110            }); 
     111            function selectTheme() { 
     112                var input = document.getElementById("colorsyntax_theme"); 
     113                var theme = input.options[input.selectedIndex].value; 
     114                if (theme == "") theme = "default"; 
     115                editor.setOption("theme", theme); 
     116                editor.refresh(); 
     117            } 
     118        </script>'; 
     119        echo '</div>'; 
     120        echo '</div>'; 
     121    } 
    122122} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map