Completed
Pull Request — master (#133)
by Goffy
16:45
created

XoopsGuiDefault::header()   F

Complexity

Conditions 34
Paths 7560

Size

Total Lines 266
Code Lines 207

Duplication

Lines 77
Ratio 28.95 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 34
eloc 207
nc 7560
nop 0
dl 77
loc 266
rs 2
c 1
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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 32 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
xoops_load('gui', 'system');
13
14
/*
15
 * Xoops Cpanel default GUI class
16
 *
17
 * @copyright   (c) 2000-2016 XOOPS Project (www.xoops.org)
18
 * @license     GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
19
 * @package     system
20
 * @usbpackage  GUI
21
 * @since       2.4
22
 * @author      Mamba       <[email protected]>
23
 * @author      Mojtabajml  <[email protected]>
24
 * @author      Voltan      <[email protected]>
25
 * @author      BitC3R0     <[email protected]>
26
 * @author      trabis      <[email protected]>
27
 */
28
29
/**
30
 * Class XoopsGuiDefault
31
 */
32
class XoopsGuiDefault extends XoopsSystemGui
33
{
34
    /**
35
     *
36
     */
37
    public function __construct()
38
    {
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public static function validate()
45
    {
46
        return true;
47
    }
48
49
    public function header()
50
    {
51
        parent::header();
52
53
        global $xoopsConfig, $xoopsUser, $xoopsModule, $xoTheme, $xoopsTpl, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
54
        $tpl =& $this->template;
55
56
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
57
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/styleswitch.js');
58
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/formenu.js');
59
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/menu.js');
60
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/tooltip.js');
61
//        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/tabs.jquery.tools.min.js');
62
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/tabs.js');
63
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/tabs.slideshow.js');
64
65
        $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/default/css/style.css');
66
        $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/default/css/dark.css', array('title' => 'dark', 'media' => 'screen'));
67
        $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/default/css/silver.css', array('title' => 'silver', 'media' => 'screen'));
68
        $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/default/css/orange.css', array('title' => 'orange', 'media' => 'screen'));
69
70
        $tpl->assign('lang_cp', _CPHOME);
71
        //start system overview
72
        //$tpl->assign('lang_xoops_version', XOOPS_VERSION);
73
        $tpl->assign('lang_php_vesion', PHP_VERSION);
74
        $tpl->assign('lang_mysql_version', mysqli_get_server_info($xoopsDB->conn));
75
        $tpl->assign('lang_server_api', PHP_SAPI);
76
        $tpl->assign('lang_os_name', PHP_OS);
77
//        $tpl->assign('safe_mode', ini_get('safe_mode') ? 'On' : 'Off');
78
//        $tpl->assign('register_globals', ini_get('register_globals') ? 'On' : 'Off');
79
//        $tpl->assign('magic_quotes_gpc', ini_get('magic_quotes_gpc') ? 'On' : 'Off');
80
        $tpl->assign('allow_url_fopen', ini_get('allow_url_fopen') ? 'On' : 'Off');
81
        $tpl->assign('fsockopen', function_exists('fsockopen') ? 'On' : 'Off');
82
//        $tpl->assign('allow_call_time_pass_reference', ini_get('allow_call_time_pass_reference') ? 'On' : 'Off');
83
        $tpl->assign('post_max_size', ini_get('post_max_size'));
84
        $tpl->assign('max_input_time', ini_get('max_input_time'));
85
        $tpl->assign('output_buffering', ini_get('output_buffering'));
86
        $tpl->assign('max_execution_time', ini_get('max_execution_time'));
87
        $tpl->assign('memory_limit', ini_get('memory_limit'));
88
        $tpl->assign('file_uploads', ini_get('file_uploads') ? 'On' : 'Off');
89
        $tpl->assign('upload_max_filesize', ini_get('upload_max_filesize'));
90
        $tpl->assign('xoops_sitename', $xoopsConfig['sitename']);
91
92
        // ADD MENU *****************************************
93
94
        //Add  CONTROL PANEL  Menu  items
95
        $menu                = array();
96
        $menu[0]['link']     = XOOPS_URL;
97
        $menu[0]['title']    = _YOURHOME;
98
        $menu[0]['absolute'] = 1;
99
        $menu[1]['link']     = XOOPS_URL . '/admin.php?xoopsorgnews=1';
100
        $menu[1]['title']    = _OXYGEN_NEWS;
101
        $menu[1]['absolute'] = 1;
102
        $menu[1]['icon']     = XOOPS_ADMINTHEME_URL . '/default/images/xoops.png';
103
        $menu[2]['link']     = XOOPS_URL . '/user.php?op=logout';
104
        $menu[2]['title']    = _LOGOUT;
105
        $menu[2]['absolute'] = 1;
106
        $menu[2]['icon']     = XOOPS_ADMINTHEME_URL . '/default/images/logout.png';
107
        $tpl->append('navitems', array('link' => XOOPS_URL . '/admin.php', 'text' => _CPHOME, 'menu' => $menu));
108
109
        //add SYSTEM  Menu items
110
        include __DIR__ . '/menu.php';
111 View Code Duplication
        if (empty($xoopsModule) || 'system' === $xoopsModule->getVar('dirname', 'n')) {
112
            $modpath = XOOPS_URL . '/admin.php';
113
            $modname = _OXYGEN_SYSOPTIONS;
114
            $modid   = 1;
115
            $moddir  = 'system';
116
117
            $mod_options = $adminmenu;
0 ignored issues
show
Bug introduced by
The variable $adminmenu does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
118
            foreach (array_keys($mod_options) as $item) {
119
                $mod_options[$item]['link'] = empty($mod_options[$item]['absolute']) ? XOOPS_URL . '/modules/' . $moddir . '/' . $mod_options[$item]['link'] : $mod_options[$item]['link'];
120
                $mod_options[$item]['icon'] = empty($mod_options[$item]['icon']) ? '' : XOOPS_ADMINTHEME_URL . '/default/' . $mod_options[$item]['icon'];
121
                unset($mod_options[$item]['icon_small']);
122
            }
123
        } else {
124
            $moddir  = $xoopsModule->getVar('dirname', 'n');
125
            $modpath = XOOPS_URL . '/modules/' . $moddir;
126
            $modname = $xoopsModule->getVar('name');
127
            $modid   = $xoopsModule->getVar('mid');
128
129
            $mod_options = $xoopsModule->getAdminMenu();
130
            foreach (array_keys($mod_options) as $item) {
131
                $mod_options[$item]['link'] = empty($mod_options[$item]['absolute']) ? XOOPS_URL . "/modules/{$moddir}/" . $mod_options[$item]['link'] : $mod_options[$item]['link'];
132
                //                $mod_options[$item]['icon'] = empty($mod_options[$item]['icon']) ? '' : XOOPS_URL . "/modules/{$moddir}/" . $mod_options[$item]['icon'];
133
                //mb for direct URL access to icons in modules Admin
134
                $mod_options[$item]['icon'] = empty($mod_options[$item]['icon']) ? '' : (filter_var($mod_options[$item]['icon'], FILTER_VALIDATE_URL) ? $mod_options[$item]['icon'] : (XOOPS_URL . "/modules/{$moddir}/" . $mod_options[$item]['icon']));
135
            }
136
        }
137
138
        $tpl->assign('mod_options', $mod_options);
139
        $tpl->assign('modpath', $modpath);
140
        $tpl->assign('modname', $modname);
141
        $tpl->assign('modid', $modid);
142
        $tpl->assign('moddir', $moddir);
143
144
        // add MODULES  Menu items
145
        $module_handler = xoops_getHandler('module');
146
        $criteria       = new CriteriaCompo();
147
        $criteria->add(new Criteria('hasadmin', 1));
148
        $criteria->add(new Criteria('isactive', 1));
149
        $criteria->setSort('mid');
150
        $mods = $module_handler->getObjects($criteria);
151
152
        $menu               = array();
153
        $moduleperm_handler = xoops_getHandler('groupperm');
154 View Code Duplication
        foreach ($mods as $mod) {
155
            $rtn        = array();
156
            $modOptions = array();                                                         //add for sub menus
157
            $sadmin     = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups());
158
            if ($sadmin) {
159
                $info = $mod->getInfo();
160
                if (!empty($info['adminindex'])) {
161
                    $rtn['link'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info['adminindex'];
162
                } else {
163
                    $rtn['link'] = XOOPS_URL . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $mod->getVar('mid');
164
                }
165
                $rtn['title']    = htmlspecialchars($mod->name(), ENT_QUOTES);
166
                $rtn['absolute'] = 1;
167
                $rtn['url']      = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/'; //add for sub menus
168
                $modOptions      = $mod->getAdminMenu();                                        //add for sub menus
169
                $rtn['options']  = $modOptions;                                             //add for sub menus
170
171
                if (isset($info['icon']) && $info['icon'] !== '') {
172
                    $rtn['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info['icon'];
173
                }
174
                $menu[] = $rtn;
175
            }
176
        }
177
        $tpl->append('navitems', array(
178
            'link' => XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin',
179
            'text' => _AM_SYSTEM_MODULES,
180
            'dir'  => $mod->getVar('dirname', 'n'),
0 ignored issues
show
Bug introduced by
The variable $mod seems to be defined by a foreach iteration on line 154. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
181
            'menu' => $menu));
182
183
        // add preferences menu
184
        $menu = array();
185
186
        $OPT   = array();
187
        $OPT[] = array(
188
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=1',
189
            'title'    => _OXYGEN_GENERAL,
190
            'absolute' => 1,
191
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png');
192
        $OPT[] = array(
193
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=2',
194
            'title'    => _OXYGEN_USERSETTINGS,
195
            'absolute' => 1,
196
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png');
197
        $OPT[] = array(
198
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=3',
199
            'title'    => _OXYGEN_METAFOOTER,
200
            'absolute' => 1,
201
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png');
202
        $OPT[] = array(
203
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=4',
204
            'title'    => _OXYGEN_CENSOR,
205
            'absolute' => 1,
206
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png');
207
        $OPT[] = array(
208
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=5',
209
            'title'    => _OXYGEN_SEARCH,
210
            'absolute' => 1,
211
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png');
212
        $OPT[] = array(
213
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=6',
214
            'title'    => _OXYGEN_MAILER,
215
            'absolute' => 1,
216
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png');
217
        $OPT[] = array(
218
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=7',
219
            'title'    => _OXYGEN_AUTHENTICATION,
220
            'absolute' => 1,
221
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png');
222
        $OPT[] = array(
223
            'link'     => 'admin.php?fct=preferences&amp;op=showmod&amp;mod=1',
224
            'title'    => _OXYGEN_MODULESETTINGS,
225
            'absolute' => 1,
226
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png');
227
228
        $menu[] = array(
229
            'link'     => XOOPS_URL . '/modules/system/admin.php?fct=preferences',
230
            'title'    => _OXYGEN_SYSOPTIONS,
231
            'absolute' => 1,
232
            'url'      => XOOPS_URL . '/modules/system/',
233
            'options'  => $OPT);
234
235
        foreach ($mods as $mod) {
236
            $rtn    = array();
237
            $sadmin = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups());
238
            if ($sadmin && ($mod->getVar('hasnotification') || is_array($mod->getInfo('config')) || is_array($mod->getInfo('comments')))) {
239
                $rtn['link']     = XOOPS_URL . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $mod->getVar('mid');
240
                $rtn['title']    = htmlspecialchars($mod->name(), ENT_QUOTES);
241
                $rtn['absolute'] = 1;
242
                $rtn['icon']     = XOOPS_ADMINTHEME_URL . '/gui/oxygen/icons/prefs_small.png';
243
                $menu[]          = $rtn;
244
            }
245
        }
246
        $tpl->append('navitems', array(
247
            'link' => XOOPS_URL . '/modules/system/admin.php?fct=preferences',
248
            'text' => _OXYGEN_SITEPREF,
249
            'dir'  => $mod->getVar('dirname', 'n'),
250
            'menu' => $menu));
251
252
        //add OPTIONS/Links Menu Items
253
        $menu   = array();
254
        $menu[] = array(
255
            'link'     => 'http://xoops.org',
256
            'title'    => _OXYGEN_XOOPSPROJECT,
257
            'absolute' => 1);
258
        $menu[] = array(
259
            'link'     => 'http://xoops.org',
260
            'title'    => _OXYGEN_WEBSITE,
261
            'absolute' => 1,
262
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/images/xoops.png');
263
        $menu[] = array(
264
            'link'     => 'http://www.xoops.org/modules/repository/',
265
            'title'    => _OXYGEN_XOOPSMODULES,
266
            'absolute' => 1,
267
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/images/xoops.png');
268
        $menu[] = array(
269
            'link'     => 'http://www.xoops.org/modules/extgallery/',
270
            'title'    => _OXYGEN_XOOPSTHEMES,
271
            'absolute' => 1,
272
            'icon'     => XOOPS_ADMINTHEME_URL . '/default/images/tweb.png');
273
274
        $tpl->append('navitems', array('link' => XOOPS_URL . '/admin.php', 'text' => _OXYGEN_INTERESTSITES, 'menu' => $menu));
275
276
        //add OPTIONS/links for local support
277 View Code Duplication
        if (file_exists($file = XOOPS_ADMINTHEME_PATH . '/default/language/' . $xoopsConfig['language'] . '/localsupport.php')) {
278
            $links = include XOOPS_ADMINTHEME_PATH . '/default/language/' . $xoopsConfig['language'] . '/localsupport.php';
279
            if (count($links) > 0) {
280
                $tpl->append('navitems', array('link' => XOOPS_URL . '/admin.php', 'text' => _OXYGEN_LOCALSUPPORT, 'menu' => $links));
281
            }
282
        }
283
284
        if (is_object($xoopsModule) || !empty($_GET['xoopsorgnews'])) {
285
            if (is_object($xoopsModule) && file_exists($file = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/' . $xoopsModule->getInfo('adminmenu'))) {
286
                include $file;
287
            }
288
289
            return null;
290
        }
291
292 View Code Duplication
        foreach ($mods as $mod) {
293
            $sadmin = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups());
294
            if ($sadmin) {
295
                $rtn  = array();
296
                $info = $mod->getInfo();
297
                if (!empty($info ['adminindex'])) {
298
                    $rtn ['link'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['adminindex'];
299
                } else {
300
                    $rtn ['link'] = XOOPS_URL . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $mod->getVar('mid');
301
                }
302
                $rtn ['title']       = htmlspecialchars($mod->getVar('name'), ENT_QUOTES);
303
                $rtn ['description'] = $mod->getInfo('description');
304
                $rtn ['absolute']    = 1;
305
                if (isset($info ['icon_big'])) {
306
                    $rtn ['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['icon_big'];
307
                } elseif (isset($info ['image'])) {
308
                    $rtn ['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['image'];
309
                }
310
311
                $tpl->append('modules', $rtn);
312
            }
313
        }
314
    }
315
}
316