Passed
Pull Request — master (#1467)
by Michael
05:54
created

XoopsGuiTransition::getComposerData()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 19
rs 9.9666
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
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.0 or later (https://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
    /*
38
    public function __construct()
39
    {
40
        // Check cookie
41
        $used = isset($_COOKIE['transition_theme']) ? $_COOKIE['transition_theme'] : 0;
42
43
        if(0 == $used){
44
45
            setcookie('transition_theme', 1, time() + (86400*365), '/', null, null, true);
46
47
            header('location: ' . XOOPS_URL . '/admin.php?show=info');
48
            die();
49
        }
50
    }
51
    */
52
    /**
53
     * @return bool
54
     */
55
    public static function validate()
56
    {
57
        return true;
58
    }
59
60
    public function header()
61
    {
62
        parent::header();
63
64
        global $xoopsConfig, $xoopsUser, $xoopsModule, $xoTheme, $xoopsTpl, $xoopsDB;
65
        $tpl =& $this->template;
66
67
        // Determine if information box must be shown
68
        $currentScript = str_replace(XOOPS_ROOT_PATH . '/', '', $_SERVER['SCRIPT_FILENAME']);
69
70
        if('admin.php' == $currentScript){
71
            $show = isset($_GET['show']) ? $_GET['show'] : '';
72
            if('info' == $show){
73
                $tpl->assign('showTransitionInfo', true);
74
            }
75
        }
76
77
        $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

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