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