Passed
Pull Request — master (#1467)
by Michael
09:59
created

XoopsGuiDark::extractPackages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
360
    {
361
        if (!file_exists($composerLockPath)) {
362
            throw new InvalidArgumentException("File not found at: " . $composerLockPath);
363
        }
364
365
        $composerLockData = file_get_contents($composerLockPath);
366
367
        if ($composerLockData === false) {
368
            throw new RuntimeException("Failed to read the file: " . $composerLockPath);
369
        }
370
371
        $composerData = json_decode($composerLockData, true);
372
373
        if (json_last_error() !== JSON_ERROR_NONE) {
374
            throw new JsonException("Failed to decode JSON data: " . json_last_error_msg());
375
        }
376
377
        return $composerData['packages'] ?? [];
378
    }
379
380
381
    // Function to extract package name and version (using array_map for optimization)
382
    private function extractPackages(array $packages): array
0 ignored issues
show
Unused Code introduced by
The method extractPackages() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
383
    {
384
        return array_map(
385
            static fn($package) => [
386
                'name'    => $package['name'],
387
                'version' => $package['version']
388
            ], $packages
389
        );
390
    }
391
}
392