XoopsGuiDark::header()   F
last analyzed

Complexity

Conditions 37
Paths > 20000

Size

Total Lines 294
Code Lines 219

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 37
eloc 219
c 0
b 0
f 0
nc 45360
nop 0
dl 0
loc 294
rs 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
use Xmf\Request;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
13
14
xoops_load('gui', 'system');
15
16
/*
17
 * Xoops Cpanel default GUI class
18
 *
19
 * @copyright   (c) 2000-2025 XOOPS Project (https://xoops.org)
20
 * @license     GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
21
 * @package     system
22
 * @usbpackage  GUI
23
 * @since       2.4
24
 * @author      Mamba       <[email protected]>
25
 * @author      Mojtabajml  <[email protected]>
26
 * @author      Voltan      <[email protected]>
27
 * @author      BitC3R0     <[email protected]>
28
 * @author      trabis      <[email protected]>
29
 */
30
31
/**
32
 * Class XoopsGuiDark
33
 */
34
class XoopsGuiDark extends XoopsSystemGui
35
{
36
    /**
37
     *
38
     */
39
    /*
40
    public function __construct()
41
    {
42
        // Check cookie
43
        $used = isset($_COOKIE['transition_theme']) ? $_COOKIE['transition_theme'] : 0;
44
45
        if(0 == $used){
46
47
            setcookie('transition_theme', 1, time() + (86400*365), '/', null, null, true);
48
49
            header('location: ' . XOOPS_URL . '/admin.php?show=info');
50
            die();
51
        }
52
    }
53
    */
54
    /**
55
     * @return bool
56
     */
57
    public static function validate()
58
    {
59
        return true;
60
    }
61
62
    public function header()
63
    {
64
        parent::header();
65
66
        global $xoopsConfig, $xoopsUser, $xoopsModule, $xoTheme, $xoopsTpl, $xoopsDB;
67
        $tpl =& $this->template;
68
69
        include_once dirname(__DIR__) . '/ComposerInfo.php';
70
71
        // Determine if information box must be shown
72
        $currentScript = str_replace(XOOPS_ROOT_PATH . '/', '', (string) $_SERVER['SCRIPT_FILENAME']);
73
74
        if('admin.php' == $currentScript){
75
            $show = Request::getString('show', '', 'GET');
76
            if('info' == $show){
77
                $tpl->assign('showTransitionInfo', true);
78
            }
79
        }
80
81
        $iconsSet = xoops_getModuleOption('typeicons', 'system');
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

81
        $iconsSet = /** @scrutinizer ignore-deprecated */ xoops_getModuleOption('typeicons', 'system');
Loading history...
82
83
        if ($iconsSet == '') {
84
            $icons = 'transition';
85
        }
86
87
        $tpl->assign('theme_icons', XOOPS_URL . '/modules/system/images/icons/' . $iconsSet);
88
89
        // language
90
        $tpl->assign('xoops_language', $xoopsConfig['language']);
91
92
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
93
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/dark/js/close_errors.js');
94
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/dark/js/formenu.js');
95
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/dark/js/menu.js');
96
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/dark/js/tooltip.js');
97
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/dark/js/tabs.js');
98
        $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/dark/js/tabs.slideshow.js');
99
100
        $xoTheme->addStylesheet('https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:300,300i,400,400i,700,700i');
101
//        $xoTheme->addStylesheet('https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
102
        $xoTheme->addStylesheet('media/font-awesome6/css/solid.min.css');
103
        $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/dark/css/style.css');
104
        $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/dark/css/dark.css', ['title' => 'dark', 'media' => 'screen']);
105
        //$xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/dark/css/silver.css', array('title' => 'silver', 'media' => 'screen'));
106
        //$xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/dark/css/orange.css', array('title' => 'orange', 'media' => 'screen'));
107
108
109
        $tpl->assign('lang_cp', _CPHOME);
110
        //start system overview
111
        //$tpl->assign('lang_xoops_version', XOOPS_VERSION);
112
        $tpl->assign('lang_php_version', PHP_VERSION);
113
        $tpl->assign('lang_smarty_version', $tpl::SMARTY_VERSION);
114
        $tpl->assign('lang_mysql_version', mysqli_get_server_info($xoopsDB->conn));
115
        $tpl->assign('lang_server_api', PHP_SAPI);
116
        $tpl->assign('lang_os_name', PHP_OS);
117
//        $tpl->assign('safe_mode', ini_get('safe_mode') ? 'On' : 'Off');
118
//        $tpl->assign('register_globals', ini_get('register_globals') ? 'On' : 'Off');
119
//        $tpl->assign('magic_quotes_gpc', ini_get('magic_quotes_gpc') ? 'On' : 'Off');
120
        $tpl->assign('allow_url_fopen', ini_get('allow_url_fopen') ? 'On' : 'Off');
121
        $tpl->assign('fsockopen', function_exists('fsockopen') ? 'On' : 'Off');
122
//        $tpl->assign('allow_call_time_pass_reference', ini_get('allow_call_time_pass_reference') ? 'On' : 'Off');
123
        $tpl->assign('post_max_size', ini_get('post_max_size'));
124
        $tpl->assign('max_input_time', ini_get('max_input_time'));
125
        $tpl->assign('output_buffering', ini_get('output_buffering'));
126
        $tpl->assign('max_execution_time', ini_get('max_execution_time'));
127
        $tpl->assign('memory_limit', ini_get('memory_limit'));
128
        $tpl->assign('file_uploads', ini_get('file_uploads') ? 'On' : 'Off');
129
        $tpl->assign('upload_max_filesize', ini_get('upload_max_filesize'));
130
        $tpl->assign('xoops_sitename', $xoopsConfig['sitename']);
131
132
        // COMPOSER PACKAGES VERSION INFO *******************
133
134
        ComposerInfo::getComposerInfo($tpl);
135
136
        // ADD MENU *****************************************
137
        $menu                = [];
138
        $menu[0]['link']     = XOOPS_URL;
139
        $menu[0]['title']    = "<span class='fa-solid fa-home'></span> " . _YOURHOME;
140
        $menu[0]['absolute'] = 1;
141
        $menu[1]['link']     = XOOPS_URL . '/admin.php?xoopsorgnews=1';
142
        $menu[1]['title']    = "<span class='fa-solid fa-newspaper'></span> " . _OXYGEN_NEWS;
143
        $menu[1]['absolute'] = 1;
144
        $menu[1]['icon']     = XOOPS_ADMINTHEME_URL . '/dark/images/xoops.png';
145
        $menu[2]['link']     = XOOPS_URL . '/user.php?op=logout';
146
        $menu[2]['title']    = "<span class='fa-solid fa-right-from-bracket'></span> " . _LOGOUT;
147
        $menu[2]['absolute'] = 1;
148
        $menu[2]['icon']     = XOOPS_ADMINTHEME_URL . '/dark/images/logout.png';
149
        $tpl->append('navitems', ['link' => XOOPS_URL . '/admin.php', 'text' => '<span class="fa-solid fa-gear"></span> ' . _CPHOME, 'menu' => $menu]);
150
151
        //add SYSTEM  Menu items
152
        include __DIR__ . '/menu.php';
153
        if (empty($xoopsModule) || 'system' === $xoopsModule->getVar('dirname', 'n')) {
154
            $modpath = XOOPS_URL . '/admin.php';
155
            $modname = _OXYGEN_SYSOPTIONS;
156
            $modid   = 1;
157
            $moddir  = 'system';
158
159
            $mod_options = $adminmenu;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $adminmenu seems to be never defined.
Loading history...
160
            foreach (array_keys($mod_options) as $item) {
161
                $mod_options[$item]['link'] = empty($mod_options[$item]['absolute']) ? XOOPS_URL . '/modules/' . $moddir . '/' . $mod_options[$item]['link'] : $mod_options[$item]['link'];
162
                $mod_options[$item]['icon'] = empty($mod_options[$item]['icon']) ? '' : XOOPS_URL . '/modules/system/images/' . $mod_options[$item]['icon'];
163
                unset($mod_options[$item]['icon_small']);
164
            }
165
        } else {
166
            $moddir  = $xoopsModule->getVar('dirname', 'n');
167
            $modpath = XOOPS_URL . '/modules/' . $moddir;
168
            $modname = $xoopsModule->getInfo('name') . '  (' . $xoopsModule->getInfo('version') . ')';
169
            $modid   = $xoopsModule->getVar('mid');
170
171
            $mod_options = $xoopsModule->getAdminMenu();
172
            foreach (array_keys($mod_options) as $item) {
173
                $mod_options[$item]['link'] = empty($mod_options[$item]['absolute']) ? XOOPS_URL . "/modules/{$moddir}/" . $mod_options[$item]['link'] : $mod_options[$item]['link'];
174
                //                $mod_options[$item]['icon'] = empty($mod_options[$item]['icon']) ? '' : XOOPS_URL . "/modules/{$moddir}/" . $mod_options[$item]['icon'];
175
                //mb for direct URL access to icons in modules Admin
176
                $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']));
177
            }
178
        }
179
180
        $tpl->assign('mod_options', $mod_options);
181
        $tpl->assign('modpath', $modpath);
182
        $tpl->assign('modname', $modname);
183
        $tpl->assign('modid', $modid);
184
        $tpl->assign('moddir', $moddir);
185
186
        // add MODULES  Menu items
187
        /** @var XoopsModuleHandler $module_handler */
188
        $module_handler = xoops_getHandler('module');
189
        $criteria       = new CriteriaCompo();
190
        $criteria->add(new Criteria('hasadmin', 1));
191
        $criteria->add(new Criteria('isactive', 1));
192
        $criteria->setSort('mid');
193
        $mods = $module_handler->getObjects($criteria);
194
195
        $menu               = [];
196
        /** @var XoopsGroupPermHandler $moduleperm_handler */
197
        $moduleperm_handler = xoops_getHandler('groupperm');
198
        foreach ($mods as $mod) {
199
            $rtn        = [];
200
            $modOptions = [];                                                         //add for sub menus
201
            $sadmin     = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups());
202
            if ($sadmin) {
203
                $info = $mod->getInfo();
204
                if (!empty($info['adminindex'])) {
205
                    $rtn['link'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info['adminindex'];
206
                } else {
207
                    $rtn['link'] = XOOPS_URL . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $mod->getVar('mid');
208
                }
209
                $rtn['title']    = htmlspecialchars((string) $mod->name(), ENT_QUOTES | ENT_HTML5);
210
                $rtn['absolute'] = 1;
211
                $rtn['url']      = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/'; //add for sub menus
212
                $modOptions      = $mod->getAdminMenu();                                        //add for sub menus
213
                $rtn['options']  = $modOptions;                                             //add for sub menus
214
215
                if (isset($info['icon']) && $info['icon'] !== '') {
216
                    $rtn['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info['icon'];
217
                }
218
                $menu[] = $rtn;
219
            }
220
        }
221
        $tpl->append('navitems', [
222
            'link' => XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin',
223
            'text' => '<span class="fa-solid fa-puzzle-piece"></span> ' . _AM_SYSTEM_MODULES,
224
            'dir'  => $mod->getVar('dirname', 'n'),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $mod seems to be defined by a foreach iteration on line 198. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
225
            'menu' => $menu]);
226
227
        // add preferences menu
228
        $menu = [];
229
230
        $OPT   = [];
231
        $OPT[] = [
232
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=1',
233
            'title'    => _OXYGEN_GENERAL,
234
            'absolute' => 1,
235
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/icons/prefs_small.png'];
236
        $OPT[] = [
237
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=2',
238
            'title'    => _OXYGEN_USERSETTINGS,
239
            'absolute' => 1,
240
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/icons/prefs_small.png'];
241
        $OPT[] = [
242
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=3',
243
            'title'    => _OXYGEN_METAFOOTER,
244
            'absolute' => 1,
245
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/icons/prefs_small.png'];
246
        $OPT[] = [
247
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=4',
248
            'title'    => _OXYGEN_CENSOR,
249
            'absolute' => 1,
250
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/icons/prefs_small.png'];
251
        $OPT[] = [
252
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=5',
253
            'title'    => _OXYGEN_SEARCH,
254
            'absolute' => 1,
255
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/icons/prefs_small.png'];
256
        $OPT[] = [
257
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=6',
258
            'title'    => _OXYGEN_MAILER,
259
            'absolute' => 1,
260
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/icons/prefs_small.png'];
261
        $OPT[] = [
262
            'link'     => 'admin.php?fct=preferences&amp;op=show&amp;confcat_id=7',
263
            'title'    => _OXYGEN_AUTHENTICATION,
264
            'absolute' => 1,
265
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/icons/prefs_small.png'];
266
        $OPT[] = [
267
            'link'     => 'admin.php?fct=preferences&amp;op=showmod&amp;mod=1',
268
            'title'    => _OXYGEN_MODULESETTINGS,
269
            'absolute' => 1,
270
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/icons/prefs_small.png'];
271
272
        $menu[] = [
273
            'link'     => XOOPS_URL . '/modules/system/admin.php?fct=preferences',
274
            'title'    => _OXYGEN_SYSOPTIONS,
275
            'absolute' => 1,
276
            'url'      => XOOPS_URL . '/modules/system/',
277
            'options'  => $OPT];
278
279
        foreach ($mods as $mod) {
280
            $rtn    = [];
281
            $sadmin = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups());
282
            if ($sadmin && ($mod->getVar('hasnotification') || \is_array($mod->getInfo('config')) || \is_array($mod->getInfo('comments')))) {
283
                $rtn['link']     = XOOPS_URL . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $mod->getVar('mid');
284
                $rtn['title']    = htmlspecialchars((string) $mod->name(), ENT_QUOTES | ENT_HTML5);
285
                $rtn['absolute'] = 1;
286
                $rtn['icon']     = XOOPS_ADMINTHEME_URL . '/gui/oxygen/icons/prefs_small.png';
287
                $menu[]          = $rtn;
288
            }
289
        }
290
        $tpl->append('navitems', [
291
            'link' => XOOPS_URL . '/modules/system/admin.php?fct=preferences',
292
            'text' => '<span class="fa-solid fa-wrench"></span> ' . _OXYGEN_SITEPREF,
293
            'dir'  => $mod->getVar('dirname', 'n'),
294
            'menu' => $menu]);
295
296
        //add OPTIONS/Links Menu Items
297
        $menu   = [];
298
        $menu[] = [
299
            'link'     => 'https://xoops.org',
300
            'title'    => _OXYGEN_XOOPSPROJECT,
301
            'absolute' => 1];
302
        $menu[] = [
303
            'link'     => 'https://xoops.org',
304
            'title'    => _OXYGEN_WEBSITE,
305
            'absolute' => 1,
306
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/images/xoops.png'];
307
        $menu[] = [
308
            'link'     => 'https://xoops.org/modules/repository/',
309
            'title'    => _OXYGEN_XOOPSMODULES,
310
            'absolute' => 1,
311
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/images/xoops.png'];
312
        $menu[] = [
313
            'link'     => 'https://xoops.org/modules/extgallery/',
314
            'title'    => _OXYGEN_XOOPSTHEMES,
315
            'absolute' => 1,
316
            'icon'     => XOOPS_ADMINTHEME_URL . '/dark/images/tweb.png'];
317
318
        $tpl->append('navitems', ['link' => XOOPS_URL . '/admin.php', 'text' => '<span class="fa-solid fa-link"></span> ' . _OXYGEN_INTERESTSITES, 'menu' => $menu]);
319
320
        //add OPTIONS/links for local support
321
        if (file_exists($file = XOOPS_ADMINTHEME_PATH . '/dark/language/' . $xoopsConfig['language'] . '/localsupport.php')) {
322
            $links = include XOOPS_ADMINTHEME_PATH . '/dark/language/' . $xoopsConfig['language'] . '/localsupport.php';
323
            if (count($links) > 0) {
324
                $tpl->append('navitems', ['link' => XOOPS_URL . '/admin.php', 'text' => '<span class="fa-solid fa-link"></span> ' . _OXYGEN_LOCALSUPPORT, 'menu' => $links]);
325
            }
326
        }
327
328
        if (is_object($xoopsModule) || !empty($_GET['xoopsorgnews'])) {
329
            if (is_object($xoopsModule) && file_exists($file = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/' . $xoopsModule->getInfo('adminmenu'))) {
330
                include $file;
331
            }
332
333
            return null;
334
        }
335
336
        foreach ($mods as $mod) {
337
            $sadmin = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups());
338
            if ($sadmin) {
339
                $rtn  = [];
340
                $info = $mod->getInfo();
341
                if (!empty($info ['adminindex'])) {
342
                    $rtn ['link'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['adminindex'];
343
                } else {
344
                    $rtn ['link'] = XOOPS_URL . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $mod->getVar('mid');
345
                }
346
                $rtn ['title']       = htmlspecialchars((string) $mod->getVar('name'), ENT_QUOTES | ENT_HTML5);
347
                $rtn ['description'] = $mod->getInfo('description');
348
                $rtn ['absolute']    = 1;
349
                if (isset($info ['icon_big'])) {
350
                    $rtn ['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['icon_big'];
351
                } elseif (isset($info ['image'])) {
352
                    $rtn ['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['image'];
353
                }
354
355
                $tpl->append('modules', $rtn);
356
            }
357
        }
358
    }
359
}
360