XoopsSystemGui::validate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
eloc 0
nc 1
nop 0
1
<?php
2
/**
3
 * Xoops Cpanel GUI abstract class
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             system
15
 * @subpackage          class
16
 * @author              Taiwen Jiang <[email protected]>
17
 */
18
class XoopsSystemGui
19
{
20
    /**
21
     * Reference to template object
22
     */
23
    public $template;
24
25
    /**
26
     * Holding navigation
27
     */
28
    public $navigation;
29
30
    /**
31
     * Holding gui folder name
32
     */
33
    public $foldername;
34
35
    /**
36
     * Reference for Theme
37
     */
38
    public $xoTheme;
39
40
    public function header()
41
    {
42
        global $xoops, $xoopsConfig, $xoopsModule, $xoopsUser, $xoopsOption, $xoTheme, $xoopsTpl;
43
        ob_start();
44
45
        xoops_loadLanguage('admin', 'system');
46
        xoops_loadLanguage('cpanel', 'system');
47
        xoops_loadLanguage('modinfo', 'system');
48
49
        $xoopsLogger = XoopsLogger::getInstance();
50
        $xoopsLogger->stopTime('Module init');
51
        $xoopsLogger->startTime('XOOPS output init');
52
53
        if (!headers_sent()) {
54
            header('Content-Type:text/html; charset=' . _CHARSET);
55
            header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
56
            header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
57
            header('Cache-Control: no-store, no-cache, must-revalidate');
58
            header('Cache-Control: post-check=0, pre-check=0', false);
59
            header('Pragma: no-cache');
60
        }
61
62
        require_once XOOPS_ROOT_PATH . '/class/template.php';
63
        require_once XOOPS_ROOT_PATH . '/class/theme.php';
64
65
        if (isset($GLOBALS['xoopsOption']['template_main'])) {
66
            if (false === strpos($GLOBALS['xoopsOption']['template_main'], ':')) {
67
                $GLOBALS['xoopsOption']['template_main'] = 'db:' . $GLOBALS['xoopsOption']['template_main'];
68
            }
69
        }
70
71
        $adminThemeFactory = new xos_opal_AdminThemeFactory();
72
        $this->xoTheme     =& $adminThemeFactory->createInstance(array(
73
                                                                     'folderName'      => $this->foldername,
74
                                                                     'themesPath'      => 'modules/system/themes',
75
                                                                     'contentTemplate' => isset($GLOBALS['xoopsOption']['template_main'])? $GLOBALS['xoopsOption']['template_main'] :''));
76
        $this->xoTheme->loadLocalization('admin');
77
        $this->template =& $this->xoTheme->template;
78
79
        $GLOBALS['xoTheme']  =& $this->xoTheme;
80
        $GLOBALS['adminTpl'] =& $this->xoTheme->template;
81
82
        $xoopsLogger->stopTime('XOOPS output init');
83
        $xoopsLogger->startTime('Module display');
84
85
        $xoopsPreload = XoopsPreload::getInstance();
86
        $xoopsPreload->triggerEvent('system.class.gui.header');
87
88
        if (isset($xoopsModule) && $xoopsModule->getVar('dirname') === 'system') {
89
            $xoopsModule->loadAdminMenu();
90
91
            foreach (array_keys($xoopsModule->adminmenu) as $item) {
92
                $sys_menu[$item]['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/' . $xoopsModule->adminmenu[$item]['link'];
93
                $GLOBALS['xoopsTpl']->appendByRef('sys_menu', $sys_menu);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $sys_menu seems to be defined later in this foreach loop on line 92. Are you sure it is defined here?
Loading history...
94
                unset($sys_menu);
95
            }
96
        }
97
        // Module adminmenu
98
        if (isset($xoopsModule) && $xoopsModule->getVar('dirname') !== 'system') {
99
            if ($xoopsModule->getInfo('system_menu')) {
100
                $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/system/css/menu.css');
101
102
                $xoopsModule->loadAdminMenu();
103
                // Get menu tab handler
104
                /** @var SystemMenuHandler $menu_handler */
105
                $menu_handler = xoops_getModuleHandler('menu', 'system');
106
                // Define top navigation
107
                $menu_handler->addMenuTop(XOOPS_URL . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $xoopsModule->getVar('mid', 'e'), _AM_SYSTEM_PREF);
108
                $menu_handler->addMenuTop(XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin&amp;op=update&amp;module=' . $xoopsModule->getVar('dirname', 'e'), _AM_SYSTEM_UPDATE);
109
                $blocksTest = $xoopsModule->getInfo('blocks');
110
                if (!empty($blocksTest)) {
111
                    $menu_handler->addMenuTop(XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&amp;op=list&amp;filter=1&amp;selgen=' . $xoopsModule->getVar('mid', 'e') . '&amp;selmod=-2&amp;selgrp=-1&amp;selvis=-1', _AM_SYSTEM_BLOCKS);
112
                }
113
                $menu_handler->addMenuTop(XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=listtpl&amp;tplset=default&amp;moddir=' . $xoopsModule->getVar('dirname', 'e'), _AM_SYSTEM_TPLSETS);
114
                if ($xoopsModule->getInfo('hasComments') == 1){
115
                    $menu_handler->addMenuTop(XOOPS_URL . '/modules/system/admin.php?module=' . $xoopsModule->getVar('mid', 'e') . '&amp;status=0&amp;limit=10&amp;fct=comments', _AM_SYSTEM_COMMENTS);
116
                }
117
                $menu_handler->addMenuTop(XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin&amp;op=uninstall&amp;module=' . $xoopsModule->getVar('dirname', 'e'), _AM_SYSTEM_UNINSTALL);
118
                if ($xoopsModule->getInfo('hasMain') == 1){
119
                    $menu_handler->addMenuTop(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'e') . '/', _AM_SYSTEM_GOTOMODULE);
120
                }
121
                // Define main tab navigation
122
                $i       = 0;
123
                $current = $i;
124
                foreach ($xoopsModule->adminmenu as $menu) {
125
                    if (stripos($_SERVER['REQUEST_URI'], $menu['link']) !== false) {
126
                        $current = $i;
127
                    }
128
                    $menu_handler->addMenuTabs($menu['link'], $menu['title']);
129
                    ++$i;
130
                }
131
                if ($xoopsModule->getInfo('help')) {
132
                    if (stripos($_SERVER['REQUEST_URI'], 'admin/' . $xoopsModule->getInfo('help')) !== false) {
133
                        $current = $i;
134
                    }
135
                    $menu_handler->addMenuTabs('../system/help.php?mid=' . $xoopsModule->getVar('mid', 's') . '&amp;' . $xoopsModule->getInfo('help'), _AM_SYSTEM_HELP);
136
                }
137
138
                // Display navigation tabs
139
                $GLOBALS['xoopsTpl']->assign('xo_system_menu', $menu_handler->render($current, false));
140
            }
141
        }
142
    }
143
144
    public function footer()
145
    {
146
        global $xoopsConfig, $xoopsOption, $xoopsTpl, $xoTheme;
147
148
        $xoopsLogger = XoopsLogger::getInstance();
149
        $xoopsLogger->stopTime('Module display');
150
151
        if (!headers_sent()) {
152
            header('Content-Type:text/html; charset=' . _CHARSET);
153
            header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
154
            header('Cache-Control: private, no-cache');
155
            header('Pragma: no-cache');
156
        }
157
158
        //@internal: using global $xoTheme dereferences the variable in old versions, this does not
159
        if (!isset($xoTheme)) {
160
            $xoTheme = $GLOBALS['xoTheme'];
161
        }
162
163
        if (isset($GLOBALS['xoopsOption']['template_main']) && $GLOBALS['xoopsOption']['template_main'] != $xoTheme->contentTemplate) {
164
            trigger_error("xoopsOption['template_main'] should be defined before call xoops_cp_header function", E_USER_WARNING);
165
            if (false === strpos($GLOBALS['xoopsOption']['template_main'], ':')) {
166
                $xoTheme->contentTemplate = 'db:' . $GLOBALS['xoopsOption']['template_main'];
167
            } else {
168
                $xoTheme->contentTemplate = $GLOBALS['xoopsOption']['template_main'];
169
            }
170
        }
171
172
        $xoTheme->render();
173
        $xoopsLogger->stopTime();
174
        ob_end_flush();
175
    }
176
177
    public static function validate()
178
    {
179
    }
180
181
    public static function flush()
182
    {
183
    }
184
185
    public function getInstance()
186
    {
187
        static $instance;
188
        if (!isset($instance)) {
189
            $class    = __CLASS__;
190
            $instance = new $class();
191
        }
192
193
        return $instance;
194
    }
195
}
196