Passed
Pull Request — master (#1467)
by Michael
05:54
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
        // Determine if information box must be shown
70
        $currentScript = str_replace(XOOPS_ROOT_PATH . '/', '', $_SERVER['SCRIPT_FILENAME']);
71
72
        if('admin.php' == $currentScript){
73
            $show = Request::getString('show', '', 'GET');
74
            if('info' == $show){
75
                $tpl->assign('showTransitionInfo', true);
76
            }
77
        }
78
79
        $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

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