Conditions | 29 |
Paths | 2204 |
Total Lines | 169 |
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 |
||
9 | function b_altsys_admin_menu_show($options) |
||
10 | { |
||
11 | global $xoopsUser; |
||
12 | |||
13 | $mydirname = empty($options[0]) ? 'altsys' : $options[0]; |
||
14 | |||
15 | $this_template = empty($options[1]) ? 'db:' . $mydirname . '_block_admin_menu.tpl' : trim($options[1]); |
||
16 | |||
17 | if (preg_match('/[^0-9a-zA-Z_-]/', $mydirname)) { |
||
18 | die('Invalid mydirname'); |
||
19 | } |
||
20 | |||
21 | if (!is_object(@$xoopsUser)) { |
||
22 | return []; |
||
23 | } |
||
24 | |||
25 | // coretype |
||
26 | |||
27 | $coretype = altsys_get_core_type(); |
||
28 | |||
29 | // mid_selected |
||
30 | |||
31 | if (is_object(@$GLOBALS['xoopsModule'])) { |
||
32 | $mid_selected = $GLOBALS['xoopsModule']->getVar('mid'); |
||
33 | |||
34 | // for system->preferences |
||
35 | |||
36 | if (1 == $mid_selected && 'preferences' == @$_GET['fct'] && 'showmod' == @$_GET['op'] && !empty($_GET['mod'])) { |
||
37 | $mid_selected = \Xmf\Request::getInt('mod', 0, 'GET'); |
||
38 | } |
||
39 | } else { |
||
40 | $mid_selected = 0; |
||
41 | } |
||
42 | |||
43 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
44 | |||
45 | (method_exists('MyTextSanitizer', 'sGetInstance') and $myts = MyTextSanitizer::sGetInstance()) || $myts = MyTextSanitizer::getInstance(); |
||
46 | |||
47 | $module_handler = xoops_getHandler('module'); |
||
48 | |||
49 | $current_module = $module_handler->getByDirname($mydirname); |
||
50 | |||
51 | $configHandler = xoops_getHandler('config'); |
||
52 | |||
53 | $current_configs = $configHandler->getConfigList($current_module->mid()); |
||
54 | |||
55 | $moduleperm_handler = xoops_getHandler('groupperm'); |
||
56 | |||
57 | $admin_mids = $moduleperm_handler->getItemIds('module_admin', $xoopsUser->getGroups()); |
||
58 | |||
59 | $modules = $module_handler->getObjects(new Criteria('mid', '(' . implode(',', $admin_mids) . ')', 'IN'), true); |
||
60 | |||
61 | $block = [ |
||
62 | 'mydirname' => $mydirname, |
||
63 | 'mod_url' => XOOPS_URL . '/modules/' . $mydirname, |
||
64 | 'mod_imageurl' => XOOPS_URL . '/modules/' . $mydirname . '/' . $current_configs['images_dir'], |
||
65 | 'mod_config' => $current_configs, |
||
66 | ]; |
||
67 | |||
68 | foreach ($modules as $mod) { |
||
69 | $mid = (int)$mod->getVar('mid'); |
||
70 | |||
71 | $dirname = $mod->getVar('dirname'); |
||
72 | |||
73 | $modinfo = $mod->getInfo(); |
||
74 | |||
75 | $submenus4assign = []; |
||
76 | |||
77 | $adminmenu = []; |
||
78 | |||
79 | $adminmenu4altsys = []; |
||
80 | |||
81 | unset($adminmenu_use_altsys); |
||
82 | |||
83 | @include XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . @$modinfo['adminmenu']; |
||
|
|||
84 | |||
85 | // from admin_menu.php etc. |
||
86 | |||
87 | $adminmenu = array_merge($adminmenu, $adminmenu4altsys); |
||
88 | |||
89 | foreach ($adminmenu as $sub) { |
||
90 | $link = empty($sub['altsys_link']) ? $sub['link'] : $sub['altsys_link']; |
||
91 | |||
92 | if (isset($sub['show']) && false === $sub['show']) { |
||
93 | continue; |
||
94 | } |
||
95 | |||
96 | $submenus4assign[] = [ |
||
97 | 'title' => htmlspecialchars($sub['title']), |
||
98 | 'url' => XOOPS_URL . '/modules/' . $dirname . '/' . htmlspecialchars($link, ENT_QUOTES), |
||
99 | ]; |
||
100 | } |
||
101 | |||
102 | // for modules overriding Module.class.php (eg. Analyzer for XC) |
||
103 | |||
104 | if (empty($submenus4assign) && defined('XOOPS_CUBE_LEGACY') && !empty($modinfo['cube_style'])) { |
||
105 | $module_handler = xoops_getHandler('module'); |
||
106 | |||
107 | $module = $module_handler->get($mid); |
||
108 | |||
109 | $moduleObj = Legacy_Utils::createModule($module); |
||
110 | |||
111 | $modinfo['adminindex'] = $moduleObj->getAdminIndex(); |
||
112 | |||
113 | $modinfo['adminindex_absolute'] = true; |
||
114 | |||
115 | foreach ($moduleObj->getAdminMenu() as $sub) { |
||
116 | if (false === @$sub['show']) { |
||
117 | continue; |
||
118 | } |
||
119 | |||
120 | $submenus4assign[] = [ |
||
121 | 'title' => htmlspecialchars($sub['title']), |
||
122 | 'url' => 0 === strncmp($sub['link'], 'http', 4) ? htmlspecialchars($sub['link'], ENT_QUOTES) : XOOPS_URL . '/modules/' . $dirname . '/' . htmlspecialchars($sub['link'], ENT_QUOTES), |
||
123 | ]; |
||
124 | } |
||
125 | } elseif (empty($adminmenu4altsys)) { |
||
126 | // add preferences |
||
127 | |||
128 | if ($mod->getVar('hasconfig') && !in_array($mod->getVar('dirname'), ['system', 'legacy'])) { |
||
129 | $submenus4assign[] = [ |
||
130 | 'title' => _PREFERENCES, |
||
131 | 'url' => htmlspecialchars(altsys_get_link2modpreferences($mid, $coretype), ENT_QUOTES), |
||
132 | ]; |
||
133 | } |
||
134 | |||
135 | // add help |
||
136 | |||
137 | if (defined('XOOPS_CUBE_LEGACY') && !empty($modinfo['help'])) { |
||
138 | $submenus4assign[] = [ |
||
139 | 'title' => _HELP, |
||
140 | 'url' => XOOPS_URL . '/modules/legacy/admin/index.php?action=Help&dirname=' . $dirname, |
||
141 | ]; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | $module4assign = [ |
||
146 | 'mid' => $mid, |
||
147 | 'dirname' => $dirname, |
||
148 | 'name' => $mod->getVar('name'), |
||
149 | 'version_in_db' => sprintf('%.2f', $mod->getVar('version') / 100.0), |
||
150 | 'version_in_file' => sprintf('%.2f', $modinfo['version']), |
||
151 | 'description' => htmlspecialchars(@$modinfo['description'], ENT_QUOTES), |
||
152 | 'image' => htmlspecialchars($modinfo['image'], ENT_QUOTES), |
||
153 | 'isactive' => $mod->getVar('isactive'), |
||
154 | 'hasmain' => $mod->getVar('hasmain'), |
||
155 | 'hasadmin' => $mod->getVar('hasadmin'), |
||
156 | 'hasconfig' => $mod->getVar('hasconfig'), |
||
157 | 'weight' => $mod->getVar('weight'), |
||
158 | 'adminindex' => htmlspecialchars(@$modinfo['adminindex'], ENT_QUOTES), |
||
159 | 'adminindex_absolute' => @$modinfo['adminindex_absolute'], |
||
160 | 'submenu' => $submenus4assign, |
||
161 | 'selected' => $mid == $mid_selected, |
||
162 | 'dot_suffix' => $mid == $mid_selected ? 'selected_opened' : 'closed', |
||
163 | ]; |
||
164 | |||
165 | $block['modules'][] = $module4assign; |
||
166 | } |
||
167 | |||
168 | require_once XOOPS_TRUST_PATH . '/libs/altsys/class/D3Tpl.class.php'; |
||
169 | |||
170 | $tpl = new D3Tpl(); |
||
171 | |||
172 | $tpl->assign('block', $block); |
||
173 | |||
174 | $ret['content'] = $tpl->fetch($this_template); |
||
175 | |||
176 | return $ret; |
||
177 | } |
||
178 | |||
202 |
If you suppress an error, we recommend checking for the error condition explicitly: