Conditions | 32 |
Paths | > 20000 |
Total Lines | 303 |
Code Lines | 224 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
49 | public function header() |
||
50 | { |
||
51 | parent::header(); |
||
52 | |||
53 | global $xoopsConfig, $xoopsUser, $xoopsModule, $xoTheme, $xoopsTpl, $xoopsDB; |
||
54 | $tpl =& $this->template; |
||
55 | |||
56 | $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js'); |
||
57 | $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/styleswitch.js'); |
||
58 | $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/formenu.js'); |
||
59 | $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/menu.js'); |
||
60 | $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/tooltip.js'); |
||
61 | // $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/tabs.jquery.tools.min.js'); |
||
62 | $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/tabs.js'); |
||
63 | $xoTheme->addScript(XOOPS_ADMINTHEME_URL . '/default/js/tabs.slideshow.js'); |
||
64 | |||
65 | $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/default/css/style.css'); |
||
66 | $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/default/css/dark.css', array('title' => 'dark', 'media' => 'screen')); |
||
67 | $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/default/css/silver.css', array('title' => 'silver', 'media' => 'screen')); |
||
68 | $xoTheme->addStylesheet(XOOPS_ADMINTHEME_URL . '/default/css/orange.css', array('title' => 'orange', 'media' => 'screen')); |
||
69 | |||
70 | $tpl->assign('lang_cp', _CPHOME); |
||
71 | //start system overview |
||
72 | //$tpl->assign('lang_xoops_version', XOOPS_VERSION); |
||
73 | $tpl->assign('lang_php_version', PHP_VERSION); |
||
74 | $tpl->assign('lang_smarty_version', $tpl::SMARTY_VERSION); |
||
75 | $tpl->assign('lang_mysql_version', mysqli_get_server_info($xoopsDB->conn)); |
||
76 | $tpl->assign('lang_server_api', PHP_SAPI); |
||
77 | $tpl->assign('lang_os_name', PHP_OS); |
||
78 | // $tpl->assign('safe_mode', ini_get('safe_mode') ? 'On' : 'Off'); |
||
79 | // $tpl->assign('register_globals', ini_get('register_globals') ? 'On' : 'Off'); |
||
80 | // $tpl->assign('magic_quotes_gpc', ini_get('magic_quotes_gpc') ? 'On' : 'Off'); |
||
81 | $tpl->assign('allow_url_fopen', ini_get('allow_url_fopen') ? 'On' : 'Off'); |
||
82 | $tpl->assign('fsockopen', function_exists('fsockopen') ? 'On' : 'Off'); |
||
83 | // $tpl->assign('allow_call_time_pass_reference', ini_get('allow_call_time_pass_reference') ? 'On' : 'Off'); |
||
84 | $tpl->assign('post_max_size', ini_get('post_max_size')); |
||
85 | $tpl->assign('max_input_time', ini_get('max_input_time')); |
||
86 | $tpl->assign('output_buffering', ini_get('output_buffering')); |
||
87 | $tpl->assign('max_execution_time', ini_get('max_execution_time')); |
||
88 | $tpl->assign('memory_limit', ini_get('memory_limit')); |
||
89 | $tpl->assign('file_uploads', ini_get('file_uploads') ? 'On' : 'Off'); |
||
90 | $tpl->assign('upload_max_filesize', ini_get('upload_max_filesize')); |
||
91 | $tpl->assign('xoops_sitename', $xoopsConfig['sitename']); |
||
92 | |||
93 | // COMPOSER PACKAGES VERSION INFO ******************* |
||
94 | |||
95 | // Function to read and parse composer.lock file |
||
96 | function getComposerData(string $composerLockPath): array |
||
97 | { |
||
98 | $composerLockData = file_get_contents($composerLockPath); |
||
99 | $composerData = json_decode($composerLockData, true); |
||
100 | return $composerData['packages'] ?? []; |
||
101 | } |
||
102 | |||
103 | // Function to extract package name and version (using array_map for optimization) |
||
104 | function extractPackages(array $packages): array |
||
|
|||
105 | { |
||
106 | return array_map( |
||
107 | static fn($package) => [ |
||
108 | 'name' => $package['name'], |
||
109 | 'version' => $package['version'] |
||
110 | ], $packages |
||
111 | ); |
||
112 | } |
||
113 | |||
114 | try { |
||
115 | // Define the path to the composer.lock file |
||
116 | $composerLockPath = XOOPS_ROOT_PATH . '/class/libraries/composer.lock'; |
||
117 | // Get the packages data from composer.lock file |
||
118 | $packages = getComposerData($composerLockPath); |
||
119 | // Extract package name and version |
||
120 | $composerPackages = extractPackages($packages); |
||
121 | // Assign the $composerPackages array to the Smarty template |
||
122 | $tpl->assign('composerPackages', $composerPackages); |
||
123 | } catch (Exception $e) { |
||
124 | // Handle any exception and log the error using XOOPS Logger |
||
125 | global $xoopsLogger; |
||
126 | $xoopsLogger->handleError(E_USER_ERROR, $e->getMessage(), __FILE__, __LINE__); |
||
127 | echo "An error occurred. Please try again later."; |
||
128 | } |
||
129 | |||
130 | // ADD MENU ***************************************** |
||
131 | |||
132 | //Add CONTROL PANEL Menu items |
||
133 | $menu = array(); |
||
134 | $menu[0]['link'] = XOOPS_URL; |
||
135 | $menu[0]['title'] = _YOURHOME; |
||
136 | $menu[0]['absolute'] = 1; |
||
137 | $menu[1]['link'] = XOOPS_URL . '/admin.php?xoopsorgnews=1'; |
||
138 | $menu[1]['title'] = _OXYGEN_NEWS; |
||
139 | $menu[1]['absolute'] = 1; |
||
140 | $menu[1]['icon'] = XOOPS_ADMINTHEME_URL . '/default/images/xoops.png'; |
||
141 | $menu[2]['link'] = XOOPS_URL . '/user.php?op=logout'; |
||
142 | $menu[2]['title'] = _LOGOUT; |
||
143 | $menu[2]['absolute'] = 1; |
||
144 | $menu[2]['icon'] = XOOPS_ADMINTHEME_URL . '/default/images/logout.png'; |
||
145 | $tpl->append('navitems', array('link' => XOOPS_URL . '/admin.php', 'text' => _CPHOME, 'menu' => $menu)); |
||
146 | |||
147 | //add SYSTEM Menu items |
||
148 | include __DIR__ . '/menu.php'; |
||
149 | if (empty($xoopsModule) || 'system' === $xoopsModule->getVar('dirname', 'n')) { |
||
150 | $modpath = XOOPS_URL . '/admin.php'; |
||
151 | $modname = _OXYGEN_SYSOPTIONS; |
||
152 | $modid = 1; |
||
153 | $moddir = 'system'; |
||
154 | |||
155 | $mod_options = $adminmenu; |
||
156 | foreach (array_keys($mod_options) as $item) { |
||
157 | $mod_options[$item]['link'] = empty($mod_options[$item]['absolute']) ? XOOPS_URL . '/modules/' . $moddir . '/' . $mod_options[$item]['link'] : $mod_options[$item]['link']; |
||
158 | $mod_options[$item]['icon'] = empty($mod_options[$item]['icon']) ? '' : XOOPS_ADMINTHEME_URL . '/default/' . $mod_options[$item]['icon']; |
||
159 | unset($mod_options[$item]['icon_small']); |
||
160 | } |
||
161 | } else { |
||
162 | $moddir = $xoopsModule->getVar('dirname', 'n'); |
||
163 | $modpath = XOOPS_URL . '/modules/' . $moddir; |
||
164 | $modname = $xoopsModule->getInfo('name') . ' (' . $xoopsModule->getInfo('version') . ')'; |
||
165 | $modid = $xoopsModule->getVar('mid'); |
||
166 | |||
167 | $mod_options = $xoopsModule->getAdminMenu(); |
||
168 | foreach (array_keys($mod_options) as $item) { |
||
169 | $mod_options[$item]['link'] = empty($mod_options[$item]['absolute']) ? XOOPS_URL . "/modules/{$moddir}/" . $mod_options[$item]['link'] : $mod_options[$item]['link']; |
||
170 | // $mod_options[$item]['icon'] = empty($mod_options[$item]['icon']) ? '' : XOOPS_URL . "/modules/{$moddir}/" . $mod_options[$item]['icon']; |
||
171 | //mb for direct URL access to icons in modules Admin |
||
172 | $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'])); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | $tpl->assign('mod_options', $mod_options); |
||
177 | $tpl->assign('modpath', $modpath); |
||
178 | $tpl->assign('modname', $modname); |
||
179 | $tpl->assign('modid', $modid); |
||
180 | $tpl->assign('moddir', $moddir); |
||
181 | |||
182 | // add MODULES Menu items |
||
183 | /** @var XoopsModuleHandler $module_handler */ |
||
184 | $module_handler = xoops_getHandler('module'); |
||
185 | $criteria = new CriteriaCompo(); |
||
186 | $criteria->add(new Criteria('hasadmin', 1)); |
||
187 | $criteria->add(new Criteria('isactive', 1)); |
||
188 | $criteria->setSort('mid'); |
||
189 | $mods = $module_handler->getObjects($criteria); |
||
190 | |||
191 | $menu = array(); |
||
192 | /** @var XoopsGroupPermHandler $moduleperm_handler */ |
||
193 | $moduleperm_handler = xoops_getHandler('groupperm'); |
||
194 | foreach ($mods as $mod) { |
||
195 | $rtn = array(); |
||
196 | $modOptions = array(); //add for sub menus |
||
197 | $sadmin = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups()); |
||
198 | if ($sadmin) { |
||
199 | $info = $mod->getInfo(); |
||
200 | if (!empty($info['adminindex'])) { |
||
201 | $rtn['link'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info['adminindex']; |
||
202 | } else { |
||
203 | $rtn['link'] = XOOPS_URL . '/modules/system/admin.php?fct=preferences&op=showmod&mod=' . $mod->getVar('mid'); |
||
204 | } |
||
205 | $rtn['title'] = htmlspecialchars($mod->name(), ENT_QUOTES | ENT_HTML5); |
||
206 | $rtn['absolute'] = 1; |
||
207 | $rtn['url'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/'; //add for sub menus |
||
208 | $modOptions = $mod->getAdminMenu(); //add for sub menus |
||
209 | $rtn['options'] = $modOptions; //add for sub menus |
||
210 | |||
211 | if (isset($info['icon']) && $info['icon'] !== '') { |
||
212 | $rtn['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info['icon']; |
||
213 | } |
||
214 | $menu[] = $rtn; |
||
215 | } |
||
216 | } |
||
217 | $tpl->append('navitems', array( |
||
218 | 'link' => XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin', |
||
219 | 'text' => _AM_SYSTEM_MODULES, |
||
220 | 'dir' => $mod->getVar('dirname', 'n'), |
||
221 | 'menu' => $menu)); |
||
222 | |||
223 | // add preferences menu |
||
224 | $menu = array(); |
||
225 | |||
226 | $OPT = array(); |
||
227 | $OPT[] = array( |
||
228 | 'link' => 'admin.php?fct=preferences&op=show&confcat_id=1', |
||
229 | 'title' => _OXYGEN_GENERAL, |
||
230 | 'absolute' => 1, |
||
231 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png'); |
||
232 | $OPT[] = array( |
||
233 | 'link' => 'admin.php?fct=preferences&op=show&confcat_id=2', |
||
234 | 'title' => _OXYGEN_USERSETTINGS, |
||
235 | 'absolute' => 1, |
||
236 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png'); |
||
237 | $OPT[] = array( |
||
238 | 'link' => 'admin.php?fct=preferences&op=show&confcat_id=3', |
||
239 | 'title' => _OXYGEN_METAFOOTER, |
||
240 | 'absolute' => 1, |
||
241 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png'); |
||
242 | $OPT[] = array( |
||
243 | 'link' => 'admin.php?fct=preferences&op=show&confcat_id=4', |
||
244 | 'title' => _OXYGEN_CENSOR, |
||
245 | 'absolute' => 1, |
||
246 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png'); |
||
247 | $OPT[] = array( |
||
248 | 'link' => 'admin.php?fct=preferences&op=show&confcat_id=5', |
||
249 | 'title' => _OXYGEN_SEARCH, |
||
250 | 'absolute' => 1, |
||
251 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png'); |
||
252 | $OPT[] = array( |
||
253 | 'link' => 'admin.php?fct=preferences&op=show&confcat_id=6', |
||
254 | 'title' => _OXYGEN_MAILER, |
||
255 | 'absolute' => 1, |
||
256 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png'); |
||
257 | $OPT[] = array( |
||
258 | 'link' => 'admin.php?fct=preferences&op=show&confcat_id=7', |
||
259 | 'title' => _OXYGEN_AUTHENTICATION, |
||
260 | 'absolute' => 1, |
||
261 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png'); |
||
262 | $OPT[] = array( |
||
263 | 'link' => 'admin.php?fct=preferences&op=showmod&mod=1', |
||
264 | 'title' => _OXYGEN_MODULESETTINGS, |
||
265 | 'absolute' => 1, |
||
266 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/icons/prefs_small.png'); |
||
267 | |||
268 | $menu[] = array( |
||
269 | 'link' => XOOPS_URL . '/modules/system/admin.php?fct=preferences', |
||
270 | 'title' => _OXYGEN_SYSOPTIONS, |
||
271 | 'absolute' => 1, |
||
272 | 'url' => XOOPS_URL . '/modules/system/', |
||
273 | 'options' => $OPT); |
||
274 | |||
275 | foreach ($mods as $mod) { |
||
276 | $rtn = array(); |
||
277 | $sadmin = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups()); |
||
278 | if ($sadmin && ($mod->getVar('hasnotification') || \is_array($mod->getInfo('config')) || \is_array($mod->getInfo('comments')))) { |
||
279 | $rtn['link'] = XOOPS_URL . '/modules/system/admin.php?fct=preferences&op=showmod&mod=' . $mod->getVar('mid'); |
||
280 | $rtn['title'] = htmlspecialchars($mod->name(), ENT_QUOTES | ENT_HTML5); |
||
281 | $rtn['absolute'] = 1; |
||
282 | $rtn['icon'] = XOOPS_ADMINTHEME_URL . '/gui/oxygen/icons/prefs_small.png'; |
||
283 | $menu[] = $rtn; |
||
284 | } |
||
285 | } |
||
286 | $tpl->append('navitems', array( |
||
287 | 'link' => XOOPS_URL . '/modules/system/admin.php?fct=preferences', |
||
288 | 'text' => _OXYGEN_SITEPREF, |
||
289 | 'dir' => $mod->getVar('dirname', 'n'), |
||
290 | 'menu' => $menu)); |
||
291 | |||
292 | //add OPTIONS/Links Menu Items |
||
293 | $menu = array(); |
||
294 | $menu[] = array( |
||
295 | 'link' => 'https://xoops.org', |
||
296 | 'title' => _OXYGEN_XOOPSPROJECT, |
||
297 | 'absolute' => 1); |
||
298 | $menu[] = array( |
||
299 | 'link' => 'https://xoops.org', |
||
300 | 'title' => _OXYGEN_WEBSITE, |
||
301 | 'absolute' => 1, |
||
302 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/images/xoops.png'); |
||
303 | $menu[] = array( |
||
304 | 'link' => 'https://xoops.org/modules/repository/', |
||
305 | 'title' => _OXYGEN_XOOPSMODULES, |
||
306 | 'absolute' => 1, |
||
307 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/images/xoops.png'); |
||
308 | $menu[] = array( |
||
309 | 'link' => 'https://xoops.org/modules/extgallery/', |
||
310 | 'title' => _OXYGEN_XOOPSTHEMES, |
||
311 | 'absolute' => 1, |
||
312 | 'icon' => XOOPS_ADMINTHEME_URL . '/default/images/tweb.png'); |
||
313 | |||
314 | $tpl->append('navitems', array('link' => XOOPS_URL . '/admin.php', 'text' => _OXYGEN_INTERESTSITES, 'menu' => $menu)); |
||
315 | |||
316 | //add OPTIONS/links for local support |
||
317 | if (file_exists($file = XOOPS_ADMINTHEME_PATH . '/default/language/' . $xoopsConfig['language'] . '/localsupport.php')) { |
||
318 | $links = include XOOPS_ADMINTHEME_PATH . '/default/language/' . $xoopsConfig['language'] . '/localsupport.php'; |
||
319 | if (count($links) > 0) { |
||
320 | $tpl->append('navitems', array('link' => XOOPS_URL . '/admin.php', 'text' => _OXYGEN_LOCALSUPPORT, 'menu' => $links)); |
||
321 | } |
||
322 | } |
||
323 | |||
324 | if (is_object($xoopsModule) || !empty($_GET['xoopsorgnews'])) { |
||
325 | if (is_object($xoopsModule) && file_exists($file = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/' . $xoopsModule->getInfo('adminmenu'))) { |
||
326 | include $file; |
||
327 | } |
||
328 | |||
329 | return null; |
||
330 | } |
||
331 | |||
332 | foreach ($mods as $mod) { |
||
333 | $sadmin = $moduleperm_handler->checkRight('module_admin', $mod->getVar('mid'), $xoopsUser->getGroups()); |
||
334 | if ($sadmin) { |
||
335 | $rtn = array(); |
||
336 | $info = $mod->getInfo(); |
||
337 | if (!empty($info ['adminindex'])) { |
||
338 | $rtn ['link'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['adminindex']; |
||
339 | } else { |
||
340 | $rtn ['link'] = XOOPS_URL . '/modules/system/admin.php?fct=preferences&op=showmod&mod=' . $mod->getVar('mid'); |
||
341 | } |
||
342 | $rtn ['title'] = htmlspecialchars($mod->getVar('name'), ENT_QUOTES | ENT_HTML5); |
||
343 | $rtn ['description'] = $mod->getInfo('description'); |
||
344 | $rtn ['absolute'] = 1; |
||
345 | if (isset($info ['icon_big'])) { |
||
346 | $rtn ['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['icon_big']; |
||
347 | } elseif (isset($info ['image'])) { |
||
348 | $rtn ['icon'] = XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . $info ['image']; |
||
349 | } |
||
350 | |||
351 | $tpl->append('modules', $rtn); |
||
352 | } |
||
356 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.