Completed
Pull Request — master (#563)
by Richard
08:33
created

XoopsGuiDefault::header()   F

Complexity

Conditions 21
Paths 1168

Size

Total Lines 156
Code Lines 103

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 21
eloc 103
nc 1168
nop 0
dl 0
loc 156
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
13
/*
14
 * Xoops Cpanel default GUI class
15
 *
16
 * @copyright   XOOPS project http://xoops.org
17
 * @license     GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
18
 * @package     system
19
 * @usbpackage  GUI
20
 * @since       2.4
21
 * @author      Mamba       <[email protected]>
22
 * @author      Mojtabajml  <[email protected]>
23
 * @author      Voltan      <[email protected]>
24
 * @author      BitC3R0     <[email protected]>
25
 * @author      trabis      <[email protected]>
26
 * @version     1.2
27
 * @version     $Id$
28
 */
29
30
class XoopsGuiDefault
31
{
32
33
    function header()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
    {
35
        $xoops = Xoops::getInstance();
36
        $xoops->loadLocale('system');
37
38
        $xoops->theme()->setNamedAsset('jqueryuicss', 'media/jquery/ui/themes/smoothness/jquery-ui.css');
39
        $xoops->theme()->setNamedAsset('bootstrap', 'media/bootstrap/js/bootstrap.min.js');
40
        $xoops->theme()->addBaseScriptAssets(array('@jquery', '@bootstrap'));
41
42
        $xoops->theme()->addBaseStylesheetAssets(array(
43
            'xoops.css',
44
            'media/bootstrap/css/bootstrap.css',
45
            //'themes/default/media/bootstrap/css/xoops.bootstrap.css',
46
            //'themes/default/css/style.css',
47
        ));
48
49
        $xoops->theme()->addBaseStylesheetAssets('@jqueryuicss');
0 ignored issues
show
Bug introduced by
'@jqueryuicss' of type string is incompatible with the type array expected by parameter $assets of Xoops\Core\Theme\XoopsTh...dBaseStylesheetAssets(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
        $xoops->theme()->addBaseStylesheetAssets(/** @scrutinizer ignore-type */ '@jqueryuicss');
Loading history...
50
        $xoops->theme()->addStylesheet('media/xoops/css/moduladmin.css');
51
        $xoops->theme()->addStylesheet(\XoopsBaseConfig::get('adminthemes-url') . '/default/css/style.css');
52
53
        // $xoops->theme()->addBaseScriptAssets('@jquery');
54
        // bootstrap has to come before jquery.ui or dialog close buttons are blank
55
        //$xoops->theme()->addBaseScriptAssets('@bootstrap');
56
        $xoops->theme()->addBaseScriptAssets('@jqueryui');
0 ignored issues
show
Bug introduced by
'@jqueryui' of type string is incompatible with the type array expected by parameter $assets of Xoops\Core\Theme\XoopsTheme::addBaseScriptAssets(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $xoops->theme()->addBaseScriptAssets(/** @scrutinizer ignore-type */ '@jqueryui');
Loading history...
57
        $xoops->theme()->addBaseScriptAssets('@jgrowl');
58
        // ddsmoothmenu
59
        $xoops->theme()->addScript(\XoopsBaseConfig::get('adminthemes-url') . '/default/js/ddsmoothmenu.js');
60
        $xoops->theme()->addScript(\XoopsBaseConfig::get('adminthemes-url') . '/default/js/tooltip.js');
61
62
        $quick = array();
63
        $quick[] = array('title' => SystemLocale::CONTROL_PANEL, 'link' => \XoopsBaseConfig::get('url') . '/admin.php');
64
        $quick[] = array('title' => XoopsLocale::HOME_PAGE, 'link' => \XoopsBaseConfig::get('url'));
65
        $quick[] = array('title' => DefaultThemeLocale::XOOPS_NEWS, 'link' => \XoopsBaseConfig::get('url') . '/admin.php?xoopsorgnews=1');
0 ignored issues
show
Bug introduced by
The constant DefaultThemeLocale::XOOPS_NEWS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
66
        $quick[] = array('title' => 'separator');
67
        $quick[] = array('title' => XoopsLocale::A_LOGOUT, 'link' => \XoopsBaseConfig::get('url') . '/user.php?op=logout');
68
        $xoops->tpl()->assign('quick_menu', $quick);
69
70
        XoopsLoad::load('module', 'system');
71
        XoopsLoad::load('extension', 'system');
72
        $system_module = new SystemModule();
73
        $system_extension = new SystemExtension();
74
75
        $adminmenu = null;
76
        include __DIR__ . '/menu.php';
77
        if (!$xoops->isModule() || 'system' === $xoops->module->getVar('dirname', 'n')) {
0 ignored issues
show
Bug introduced by
The method getVar() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
        if (!$xoops->isModule() || 'system' === $xoops->module->/** @scrutinizer ignore-call */ getVar('dirname', 'n')) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
            $modpath = \XoopsBaseConfig::get('url') . '/admin.php';
79
            $modname = DefaultThemeLocale::SYSTEM_OPTIONS;
0 ignored issues
show
Bug introduced by
The constant DefaultThemeLocale::SYSTEM_OPTIONS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
80
            $modid = 1;
81
            $moddir = 'system';
82
83
            $mod_options = $adminmenu;
84
            foreach (array_keys($mod_options) as $item) {
0 ignored issues
show
Bug introduced by
$mod_options of type null is incompatible with the type array expected by parameter $input of array_keys(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

84
            foreach (array_keys(/** @scrutinizer ignore-type */ $mod_options) as $item) {
Loading history...
85
                $mod_options[$item]['link'] = empty($mod_options[$item]['absolute'])
86
                    ? \XoopsBaseConfig::get('url') . '/modules/' . $moddir . '/' . $mod_options[$item]['link']
87
                    : $mod_options[$item]['link'];
88
                $mod_options[$item]['icon'] = empty($mod_options[$item]['icon']) ? ''
89
                    : \XoopsBaseConfig::get('adminthemes-url') . '/default/' . $mod_options[$item]['icon'];
90
                unset($mod_options[$item]['icon_small']);
91
            }
92
93
        } else {
94
            $moddir = $xoops->module->getVar('dirname', 'n');
95
            $modpath = \XoopsBaseConfig::get('url') . '/modules/' . $moddir;
96
            $modname = $xoops->module->getVar('name');
97
            $modid = $xoops->module->getVar('mid');
98
99
            $mod_options = $xoops->module->getAdminMenu();
100
            foreach (array_keys($mod_options) as $item) {
0 ignored issues
show
Bug introduced by
$mod_options of type string is incompatible with the type array expected by parameter $input of array_keys(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

100
            foreach (array_keys(/** @scrutinizer ignore-type */ $mod_options) as $item) {
Loading history...
101
                $mod_options[$item]['link'] = empty($mod_options[$item]['absolute'])
102
                    ? \XoopsBaseConfig::get('url') . "/modules/{$moddir}/" . $mod_options[$item]['link']
103
                    : $mod_options[$item]['link'];
104
                if ( XoopsLoad::fileExists($xoops->path('media/xoops/images/icons/32/' . $mod_options[$item]['icon']) ) ) {
105
                    $mod_options[$item]['icon'] = $xoops->url('media/xoops/images/icons/32/' . $mod_options[$item]['icon']);
106
107
                } elseif ( XoopsLoad::fileExists($xoops->path('modules/' . $xoops->module->dirname() . '/assets/icons/32/' . $mod_options[$item]['icon'])) ) {
108
                    $mod_options[$item]['icon'] = $xoops->url('modules/' . $xoops->module->dirname() . '/assets/icons/32/' . $mod_options[$item]['icon']);
109
                } else {
110
                    $mod_options[$item]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/icons/32/" . $mod_options[$item]['icon']);
111
                }
112
            }
113
            $xoops->tpl()->assign('modhasconfig', $xoops->module->getVar('hasconfig'));
114
        }
115
        $xoops->tpl()->assign('mod_options', $mod_options);
116
        $xoops->tpl()->assign('modpath', $modpath);
117
        $xoops->tpl()->assign('modname', $modname);
118
        $xoops->tpl()->assign('modid', $modid);
119
        $xoops->tpl()->assign('moddir', $moddir);
120
121
        // Modules list
122
        $module_list = $system_module->getModuleList();
123
        $xoops->tpl()->assign('module_menu', $module_list);
124
        unset($module_list);
125
126
        // Extensions list
127
        $extension_list = $system_extension->getExtensionList();
128
        $xoops->tpl()->assign('extension_menu', $extension_list);
129
        unset($extension_list);
130
131
        $extension_mod = $system_extension->getExtension( $moddir );
132
        $xoops->tpl()->assign('extension_mod', $extension_mod);
133
134
        // add preferences menu
135
        $menu = array();
136
137
        $OPT = array();
138
139
        $menu[] = array(
140
            'link' => \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=preferences', 'title' => XoopsLocale::PREFERENCES,
141
            'absolute' => 1, 'url' => \XoopsBaseConfig::get('url') . '/modules/system/', 'options' => $OPT
142
        );
143
        $menu[] = array('title' => 'separator');
144
145
        // Module adminmenu
146
        if ($xoops->isModule() && $xoops->module->getVar('dirname') !== 'system') {
147
148
            if ($xoops->module->getInfo('system_menu')) {
149
                //$xoops->theme()->addStylesheet('modules/system/css/menu.css');
150
151
                $xoops->module->loadAdminMenu();
152
                // Get menu tab handler
153
                /* @var $menu_handler SystemMenuHandler */
154
                $menu_handler = $xoops->getModuleHandler('menu', 'system');
155
                // Define top navigation
156
                if ($xoops->module->getVar('hasconfig')) {
157
                    $menu_handler->addMenuTop(\XoopsBaseConfig::get('url') . "/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=" . $xoops->module->getVar('mid', 'e'), XoopsLocale::PREFERENCES);
0 ignored issues
show
Bug introduced by
Are you sure $xoops->module->getVar('mid', 'e') of type null|mixed|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

157
                    $menu_handler->addMenuTop(\XoopsBaseConfig::get('url') . "/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=" . /** @scrutinizer ignore-type */ $xoops->module->getVar('mid', 'e'), XoopsLocale::PREFERENCES);
Loading history...
158
                }
159
                if ($xoops->module->getInfo('extension')) {
160
                    $menu_handler->addMenuTop(\XoopsBaseConfig::get('url') . "/modules/system/admin.php?fct=extensions&amp;op=update&amp;module=" . $xoops->module->getVar('dirname', 'e'), XoopsLocale::A_UPDATE);
0 ignored issues
show
Bug introduced by
Are you sure $xoops->module->getVar('dirname', 'e') of type null|mixed|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

160
                    $menu_handler->addMenuTop(\XoopsBaseConfig::get('url') . "/modules/system/admin.php?fct=extensions&amp;op=update&amp;module=" . /** @scrutinizer ignore-type */ $xoops->module->getVar('dirname', 'e'), XoopsLocale::A_UPDATE);
Loading history...
161
                } else {
162
                    $menu_handler->addMenuTop(\XoopsBaseConfig::get('url') . "/modules/system/admin.php?fct=modulesadmin&amp;op=update&amp;module=" . $xoops->module->getVar('dirname', 'e'), XoopsLocale::A_UPDATE);
163
                }
164
                if ($xoops->module->getInfo('blocks')) {
165
                    $menu_handler->addMenuTop(\XoopsBaseConfig::get('url') . "/modules/system/admin.php?fct=blocksadmin&amp;op=list&amp;filter=1&amp;selgen=" . $xoops->module->getVar('mid', 'e') . "&amp;selmod=-2&amp;selgrp=-1&amp;selvis=-1", XoopsLocale::BLOCKS);
166
                }
167
                if ($xoops->module->getInfo('hasMain')) {
168
                    $menu_handler->addMenuTop(\XoopsBaseConfig::get('url') . "/modules/" . $xoops->module->getVar('dirname', 'e') . "/", SystemLocale::GO_TO_MODULE);
169
                }
170
                // Define main tab navigation
171
                $i = 0;
172
                $current = $i;
173
                foreach ($xoops->module->adminmenu as $menu) {
174
                    if (stripos($_SERVER['REQUEST_URI'], $menu['link']) !== false) {
175
                        $current = $i;
176
                    }
177
                    $menu_handler->addMenuTabs( $xoops->url('modules/' . $xoops->module->getVar('dirname') . '/' . $menu['link']), $menu['title']);
178
                    ++$i;
179
                }
180
                if ($xoops->module->getInfo('help')) {
181
                    if (stripos($_SERVER['REQUEST_URI'], 'admin/' . $xoops->module->getInfo('help')) !== false) {
0 ignored issues
show
Bug introduced by
Are you sure $xoops->module->getInfo('help') of type string|string[] can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

181
                    if (stripos($_SERVER['REQUEST_URI'], 'admin/' . /** @scrutinizer ignore-type */ $xoops->module->getInfo('help')) !== false) {
Loading history...
182
                        $current = $i;
183
                    }
184
                    $menu_handler->addMenuTabs('../../system/help.php?mid=' . $xoops->module->getVar('mid', 's') . '&amp;' . $xoops->module->getInfo('help'), XoopsLocale::HELP);
185
                }
186
187
                // Display navigation tabs
188
                $xoops->tpl()->assign('xo_system_menu', $menu_handler->render($current, false));
189
            }
190
        }
191
192
    }
193
}
194