Conditions | 22 |
Paths | 274 |
Total Lines | 96 |
Code Lines | 51 |
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 |
||
33 | function b_waiting_waiting_show($options) |
||
34 | { |
||
35 | $userLang = $GLOBALS['xoopsConfig']['language']; |
||
36 | |||
37 | $sql_cache_min = empty($options[1]) ? 0 : (int)$options[1]; |
||
38 | $sql_cache_file = XOOPS_CACHE_PATH . '/waiting_touch'; |
||
39 | |||
40 | // SQL cache check (you have to use this cache with block's cache by system) |
||
41 | if (file_exists($sql_cache_file)) { |
||
42 | $sql_cache_mtime = filemtime($sql_cache_file); |
||
43 | if (time() < $sql_cache_mtime + $sql_cache_min * 60) { |
||
44 | return []; |
||
45 | } else { |
||
46 | unlink($sql_cache_file); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | require_once dirname(__DIR__) . '/include/functions.php'; |
||
51 | |||
52 | /** @var \XoopsModules\Waiting\Helper $helper */ |
||
53 | $helper = \XoopsModules\Waiting\Helper::getInstance(); |
||
54 | // read language files for plugins |
||
55 | $helper->loadLanguage('plugins'); |
||
56 | |||
57 | $plugins_path = XOOPS_ROOT_PATH . '/modules/waiting/plugins'; |
||
|
|||
58 | /** @var \XoopsMySQLDatabase $xoopsDB */ |
||
59 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
60 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
61 | $moduleHandler = xoops_getHandler('module'); |
||
62 | $block = []; |
||
63 | |||
64 | // get module's list installed |
||
65 | $mod_lists = $moduleHandler->getList(new \Criteria(''), true); |
||
66 | foreach ($mod_lists as $dirname => $name) { |
||
67 | $plugin_info = waiting_get_plugin_info($dirname, $userLang); |
||
68 | if (empty($plugin_info) || empty($plugin_info['plugin_path'])) { |
||
69 | continue; |
||
70 | } |
||
71 | |||
72 | if (!empty($plugin_info['langfile_path'])) { |
||
73 | require_once $plugin_info['langfile_path']; |
||
74 | } |
||
75 | require_once $plugin_info['plugin_path']; |
||
76 | |||
77 | // call the plugin |
||
78 | if (function_exists(@$plugin_info['func'])) { |
||
79 | // get the list of waitings |
||
80 | $_tmp = call_user_func($plugin_info['func'], $dirname); |
||
81 | if (\Xmf\Request::hasVar('lang_linkname', 'tmp')) { |
||
82 | if (@$_tmp['pendingnum'] > 0 || $options[0] > 0) { |
||
83 | $block['modules'][$dirname]['pending'][] = $_tmp; |
||
84 | } |
||
85 | unset($_tmp); |
||
86 | } else { |
||
87 | // Judging the plugin returns multiple items |
||
88 | // if lang_linkname does not exist |
||
89 | foreach ($_tmp as $_one) { |
||
90 | if (@$_one['pendingnum'] > 0 || $options[0] > 0) { |
||
91 | $block['modules'][$dirname]['pending'][] = $_one; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
97 | // for older compatibilities |
||
98 | // Hacked by GIJOE |
||
99 | $i = 0; |
||
100 | while (1) { |
||
101 | $function_name = "b_waiting_{$dirname}_$i"; |
||
102 | if (function_exists($function_name)) { |
||
103 | $_tmp = call_user_func($function_name); |
||
104 | ++$i; |
||
105 | if ($_tmp['pendingnum'] > 0 || $options[0] > 0) { |
||
106 | $block['modules'][$dirname]['pending'][] = $_tmp; |
||
107 | } |
||
108 | unset($_tmp); |
||
109 | } else { |
||
110 | break; |
||
111 | } |
||
112 | } |
||
113 | // End of Hack |
||
114 | |||
115 | // if(count($block["modules"][$dirname]) > 0){ |
||
116 | if (!empty($block['modules'][$dirname])) { |
||
117 | $block['modules'][$dirname]['name'] = $name; |
||
118 | } |
||
119 | } |
||
120 | //print_r($block); |
||
121 | |||
122 | // SQL cache touch (you have to use this cache with block's cache by system) |
||
123 | if (empty($block) && $sql_cache_min > 0) { |
||
124 | $fp = fopen($sql_cache_file, 'wb'); |
||
125 | fclose($fp); |
||
126 | } |
||
127 | |||
128 | return $block; |
||
129 | } |
||
155 |