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