Dotclear


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

Switching from inline JS variables to JSON script. A step ahead…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.dc.page.php

    r3913 r3915  
    2424        "static"  => "static-msg"]; 
    2525 
     26    private static function getCore() 
     27    { 
     28        return $GLOBALS['core']; 
     29    } 
     30 
    2631    # Auth check 
    2732    public static function check($permissions) 
    2833    { 
    29         global $core; 
     34        $core = self::getCore(); 
    3035 
    3136        if ($core->blog && $core->auth->check($permissions, $core->blog->id)) { 
     
    4247    public static function checkSuper() 
    4348    { 
    44         global $core; 
     49        $core = self::getCore(); 
    4550 
    4651        if (!$core->auth->isSuperAdmin()) { 
     
    5560    public static function open($title = '', $head = '', $breadcrumb = '', $options = []) 
    5661    { 
    57         global $core; 
     62        $core = self::getCore(); 
     63        $js = []; 
    5864 
    5965        # List of user's blogs 
     
    170176 
    171177        if ($core->auth->user_prefs->interface->darkmode) { 
    172             echo self::jsVars(['dotclear_darkMode' => 1]); 
     178            $js['darkMode'] = 1; 
    173179            echo self::cssLoad('style/default-dark.css'); 
    174180        } else { 
    175             echo self::jsVars(['dotclear_darkMode' => 0]); 
     181            $js['darkMode'] = 0; 
    176182            echo self::cssLoad('style/default.css'); 
    177183        } 
     
    186192                '<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />' . "\n"; 
    187193        } 
    188  
    189194        if ($core->auth->user_prefs->interface->htmlfontsize) { 
    190             echo 
    191             '<script type="text/javascript">' . "\n" . 
    192             self::jsVar('dotclear_htmlFontSize', $core->auth->user_prefs->interface->htmlfontsize) . "\n" . 
    193                 "</script>\n"; 
    194         } 
     195            $js['htmlFontSize'] = $core->auth->user_prefs->interface->htmlfontsize; 
     196        } 
     197        $js['hideMoreInfo'] = (boolean) $core->auth->user_prefs->interface->hidemoreinfo; 
     198        $js['showAjaxLoader'] = (boolean) $core->auth->user_prefs->interface->showajaxloader; 
     199 
     200        $core->auth->user_prefs->addWorkspace('accessibility'); 
     201        $js['noDragDrop'] = (boolean) $core->auth->user_prefs->accessibility->nodragdrop; 
     202 
     203        // Set some JSON data 
     204        echo dcUtils::jsJson('dotclear_init', $js); 
    195205 
    196206        echo 
     
    198208        self::jsToggles() . 
    199209            $head; 
    200  
    201         $core->auth->user_prefs->addWorkspace('accessibility'); 
    202         echo 
    203             '<script type="text/javascript">' . "\n" . 
    204             'dotclear.noDragDrop = '.($core->auth->user_prefs->accessibility->nodragdrop ? 'true' : 'false').';' . "\n" . 
    205             "</script>\n"; 
    206  
    207         if ($core->auth->user_prefs->interface->hidemoreinfo) { 
    208             echo 
    209                 '<script type="text/javascript">' . "\n" . 
    210                 'dotclear.hideMoreInfo = true;' . "\n" . 
    211                 "</script>\n"; 
    212         } 
    213         if ($core->auth->user_prefs->interface->showajaxloader) { 
    214             echo 
    215                 '<script type="text/javascript">' . "\n" . 
    216                 'dotclear.showAjaxLoader = true;' . "\n" . 
    217                 "</script>\n"; 
    218         } 
    219210 
    220211        # --BEHAVIOR-- adminPageHTMLHead 
     
    276267    public static function notices() 
    277268    { 
    278         global $core; 
     269        $core = self::getCore(); 
    279270        static $error_displayed = false; 
    280271 
     
    350341    protected static function getNotification($n) 
    351342    { 
    352         global $core; 
     343        $core = self::getCore(); 
    353344 
    354345        $tag = (isset($n['divtag']) && $n['divtag']) ? 'div' : 'p'; 
     
    363354    public static function close() 
    364355    { 
    365         global $core; 
     356        $core = self::getCore(); 
    366357 
    367358        if (!$GLOBALS['__resources']['ctxhelp']) { 
     
    436427    public static function openPopup($title = '', $head = '', $breadcrumb = '') 
    437428    { 
    438         global $core; 
     429        $core = self::getCore(); 
     430        $js = []; 
    439431 
    440432        # Display 
     
    460452 
    461453        if ($core->auth->user_prefs->interface->darkmode) { 
    462             echo self::jsVars(['dotclear_darkMode' => 1]); 
     454            $js['darkMode'] = 1; 
    463455            echo self::cssLoad('style/default-dark.css'); 
    464456        } else { 
    465             echo self::jsVars(['dotclear_darkMode' => 0]); 
     457            $js['darkMode'] = 0; 
    466458            echo self::cssLoad('style/default.css'); 
    467459        } 
     
    472464        $core->auth->user_prefs->addWorkspace('interface'); 
    473465        if ($core->auth->user_prefs->interface->htmlfontsize) { 
    474             echo 
    475             '<script type="text/javascript">' . "\n" . 
    476             self::jsVar('dotclear_htmlFontSize', $core->auth->user_prefs->interface->htmlfontsize) . "\n" . 
    477                 "</script>\n"; 
    478         } 
     466            $js['htmlFontSize'] = $core->auth->user_prefs->interface->htmlfontsize; 
     467        } 
     468        $js['hideMoreInfo'] = (boolean) $core->auth->user_prefs->interface->hidemoreinfo; 
     469        $js['showAjaxLoader'] = (boolean) $core->auth->user_prefs->interface->showajaxloader; 
     470 
     471        $core->auth->user_prefs->addWorkspace('accessibility'); 
     472        $js['noDragDrop'] = (boolean) $core->auth->user_prefs->accessibility->nodragdrop; 
     473 
     474        // Set JSON data 
     475        echo dcUtils::jsJson('dotclear_init', $js); 
    479476 
    480477        echo 
     
    483480            $head; 
    484481 
    485         $core->auth->user_prefs->addWorkspace('accessibility'); 
    486         echo 
    487             '<script type="text/javascript">' . "\n" . 
    488             'dotclear.noDragDrop = '.($core->auth->user_prefs->accessibility->nodragdrop ? 'true' : 'false').';' . "\n" . 
    489             "</script>\n"; 
    490  
    491         if ($core->auth->user_prefs->interface->hidemoreinfo) { 
    492             echo 
    493                 '<script type="text/javascript">' . "\n" . 
    494                 'dotclear.hideMoreInfo = true;' . "\n" . 
    495                 "</script>\n"; 
    496         } 
    497         if ($core->auth->user_prefs->interface->showajaxloader) { 
    498             echo 
    499                 '<script type="text/javascript">' . "\n" . 
    500                 'dotclear.showAjaxLoader = true;' . "\n" . 
    501                 "</script>\n"; 
    502         } 
    503  
    504482        # --BEHAVIOR-- adminPageHTMLHead 
    505483        $core->callBehavior('adminPageHTMLHead'); 
     
    539517    public static function breadcrumb($elements = null, $options = []) 
    540518    { 
    541         global $core; 
     519        $core = self::getCore(); 
    542520 
    543521        $with_home_link = isset($options['home_link']) ? $options['home_link'] : true; 
     
    566544    public static function message($msg, $timestamp = true, $div = false, $echo = true, $class = 'message') 
    567545    { 
    568         global $core; 
     546        $core = self::getCore(); 
    569547 
    570548        $res = ''; 
     
    639617    public static function helpBlock(...$params) 
    640618    { 
    641         global $core; 
     619        $core = self::getCore(); 
    642620 
    643621        if ($core->auth->user_prefs->interface->hidehelpbutton) { 
     
    648626 
    649627        # --BEHAVIOR-- adminPageHelpBlock 
    650         $GLOBALS['core']->callBehavior('adminPageHelpBlock', $args); 
     628        $core->callBehavior('adminPageHelpBlock', $args); 
    651629 
    652630        if (empty($args)) { 
     
    750728    public static function jsUtil() 
    751729    { 
    752         return self::jsLoad($GLOBALS['core']->blog->getPF('util.js')); 
     730        $core = self::getCore(); 
     731        return self::jsLoad($core->blog->getPF('util.js')); 
    753732    } 
    754733 
    755734    public static function jsToggles() 
    756735    { 
    757         if ($GLOBALS['core']->auth->user_prefs->toggles) { 
    758             $unfolded_sections = explode(',', $GLOBALS['core']->auth->user_prefs->toggles->unfolded_sections); 
     736        $core = self::getCore(); 
     737 
     738        if ($core->auth->user_prefs->toggles) { 
     739            $unfolded_sections = explode(',', $core->auth->user_prefs->toggles->unfolded_sections); 
    759740            foreach ($unfolded_sections as $k => &$v) { 
    760741                if ($v == '') { 
     
    774755    public static function jsCommon() 
    775756    { 
     757        $core = self::getCore(); 
     758 
    776759        $mute_or_no = ''; 
    777         if (empty($GLOBALS['core']->blog) || $GLOBALS['core']->blog->settings->system->jquery_migrate_mute) { 
     760        if (empty($core->blog) || $core->blog->settings->system->jquery_migrate_mute) { 
    778761            $mute_or_no .= 
    779762                '<script type="text/javascript">' . "\n" . 
     
    794777        'jsToolBar = {}, jsToolBar.prototype = { elements : {} };' . "\n" . 
    795778 
    796         self::jsVar('dotclear.nonce', $GLOBALS['core']->getNonce()) . 
     779        self::jsVar('dotclear.nonce', $core->getNonce()) . 
    797780 
    798781        self::jsVar('dotclear.img_plus_src', 'images/expand.png') . 
     
    10291012    public static function jsUpload($params = [], $base_url = null) 
    10301013    { 
     1014        $core = self::getCore(); 
     1015 
    10311016        if (!$base_url) { 
    10321017            $base_url = path::clean(dirname(preg_replace('/(\?.*$)?/', '', $_SERVER['REQUEST_URI']))) . '/'; 
     
    10361021            'sess_id=' . session_id(), 
    10371022            'sess_uid=' . $_SESSION['sess_browser_uid'], 
    1038             'xd_check=' . $GLOBALS['core']->getNonce() 
     1023            'xd_check=' . $core->getNonce() 
    10391024        ]); 
    10401025 
     
    11561141    public static function getPF($file) 
    11571142    { 
    1158         return $GLOBALS['core']->adminurl->get('load.plugin.file', ['pf' => $file]); 
     1143        $core = self::getCore(); 
     1144        return $core->adminurl->get('load.plugin.file', ['pf' => $file]); 
    11591145    } 
    11601146 
    11611147    public static function getVF($file) 
    11621148    { 
    1163         return $GLOBALS['core']->adminurl->get('load.var.file', ['vf' => $file]); 
     1149        $core = self::getCore(); 
     1150        return $core->adminurl->get('load.var.file', ['vf' => $file]); 
    11641151    } 
    11651152 
Note: See TracChangeset for help on using the changeset viewer.

Sites map