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