| Conditions | 13 |
| Paths | 42 |
| Total Lines | 69 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 28 | function b_referaccum_show($options) |
||
| 29 | { |
||
| 30 | global $xoopsDB, $configHandler, $xoopsStatConfig; |
||
| 31 | |||
| 32 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 33 | $moduleHandler = xoops_getHandler('module'); |
||
| 34 | $xoopsStatModule = $moduleHandler->getByDirname('statistics'); |
||
| 35 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 36 | $configHandler = xoops_getHandler('config'); |
||
| 37 | $xoopsStatConfig = $configHandler->getConfigsByCat(0, $xoopsStatModule->getVar('mid')); |
||
| 38 | |||
| 39 | $showhowmany = $options[0]; |
||
| 40 | $showselfrefer = $options[1]; |
||
| 41 | |||
| 42 | // get any current blacklist |
||
| 43 | $result = $xoopsDB->queryF('SELECT * FROM ' . $xoopsDB->prefix('stats_refer_blacklist')); |
||
| 44 | [$id, $referer] = $xoopsDB->fetchRow($result); |
||
| 45 | $referblacklist = unserialize(stripslashes($referer)); |
||
| 46 | if (!is_array($referblacklist)) { // something went wrong, or there is no data... |
||
| 47 | $referblacklist = []; |
||
| 48 | } |
||
| 49 | |||
| 50 | $block = []; |
||
| 51 | // this sql is getting the total hits for a refer by summing the hits and grouping by refer. We order |
||
| 52 | // by the total hits in DESC fashion. Highest is first. total is an alias for SUM(hits) |
||
| 53 | $result = $xoopsDB->queryF('SELECT refer, SUM(hits) AS total FROM ' . $xoopsDB->prefix('stats_refer') . ' GROUP BY refer ORDER BY total DESC'); |
||
| 54 | $referhits = []; |
||
| 55 | $cnt = 0; |
||
| 56 | while (list($refer, $total) = $xoopsDB->fetchRow($result)) { |
||
| 57 | if ((0 == $showselfrefer && !strcmp($refer, $_SERVER['HTTP_HOST'])) || '' == $refer) { |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | // see if we have a blacklist |
||
| 61 | $blacklisted = false; |
||
| 62 | |||
| 63 | if ('Allow' != $xoopsStatConfig['refererspam']) { // make sure they really want them ignored |
||
| 64 | if (count($referblacklist) > 0) { |
||
| 65 | $rbldelimited = '/' . implode('|', $referblacklist) . '/'; |
||
| 66 | if (preg_match($rbldelimited, $refer)) { |
||
| 67 | $blacklisted = true; |
||
|
|
|||
| 68 | continue; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | if (false === $blacklisted) { |
||
| 74 | $referhits[$cnt]['refer'] = $refer; |
||
| 75 | $referhits[$cnt]['hits'] = ''; |
||
| 76 | if (mb_strlen($total) < 3) { |
||
| 77 | $hits = sprintf('%03d', $total); |
||
| 78 | } |
||
| 79 | for ($i = 0, $iMax = mb_strlen($total); $i < $iMax; ++$i) { |
||
| 80 | //the <img src> tag |
||
| 81 | $imgsrc = mb_substr($total, $i, 1); |
||
| 82 | $referhits[$cnt]['hits'] .= '<img src="' . XOOPS_URL . '/modules/statistics/assets/images/' . $imgsrc . '.gif" border = "0">'; |
||
| 83 | } |
||
| 84 | |||
| 85 | ++$cnt; |
||
| 86 | } |
||
| 87 | |||
| 88 | if ($cnt == $showhowmany) { |
||
| 89 | break; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | $block['counterhead'] = B_STATS_REFERACCUM; |
||
| 94 | $block['referhits'] = $referhits; |
||
| 95 | |||
| 96 | return $block; |
||
| 97 | } |
||
| 116 |