Completed
Push — master ( 247290...01d05f )
by Michael
08:30
created

XoopsGuiTransition::header()   F

Complexity

Conditions 38
Paths > 20000

Size

Total Lines 289
Code Lines 217

Duplication

Lines 95
Ratio 32.87 %

Importance

Changes 0
Metric Value
cc 38
eloc 217
nc 75600
nop 0
dl 95
loc 289
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
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 XoopsGuiTransition
31
 */
32
class XoopsGuiTransition extends XoopsSystemGui
33
{
34
    /**
35
     *
36
     */
37
    public function __construct()
38
    {
39
        // Check cookie
40
        $used = isset($_COOKIE['transition_theme']) ? $_COOKIE['transition_theme'] : 0;
41
42
        if(0 == $used){
43
44
            setcookie('transition_theme', 1, time() + (86400*365), '/', null, null, true);
45
46
            header('location: ' . XOOPS_URL . '/admin.php?show=info');
47
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method __construct() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
48
        }
49
    }
50
51
    /**
52
     * @return bool
53
     */
54
    public static function validate()
55
    {
56
        return true;
57
    }
58
59
    public function header()
60
    {
61
        parent::header();
62
63
        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...
64
        $tpl =& $this->template;
65
66
        // Determine if information box must be shown
67
        $currentScript = str_replace(XOOPS_ROOT_PATH . '/', '', $_SERVER['SCRIPT_FILENAME']);
68
69
        if('admin.php' == $currentScript){
70
            $show = isset($_GET['show']) ? $_GET['show'] : '';
71
            if('info' == $show){
72
                $tpl->assign('showTransitionInfo', true);
73
            }
74
        }
75
76
        $iconsSet = xoops_getModuleOption('typeicons', 'system');
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated.

This function has been deprecated.

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