| Conditions | 19 |
| Paths | 264 |
| Total Lines | 94 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 31 | function referDetail() |
||
| 32 | { |
||
| 33 | global $xoopsDB, $xoopsTpl; |
||
| 34 | /** @var Statistics\Helper $helper */ |
||
| 35 | $helper = Statistics\Helper::getInstance(); |
||
| 36 | |||
| 37 | // get any current blacklist |
||
| 38 | $result = $xoopsDB->queryF('SELECT * FROM ' . $xoopsDB->prefix('stats_refer_blacklist')); |
||
| 39 | [$id, $referer] = $xoopsDB->fetchRow($result); |
||
| 40 | $referblacklist = unserialize(stripslashes($referer)); |
||
| 41 | if (!is_array($referblacklist)) { // something went wrong, or there is no data... |
||
| 42 | $referblacklist = []; |
||
| 43 | } |
||
| 44 | |||
| 45 | // figure out if we are saving hits by refer and path or just refer |
||
| 46 | $resultoption = $xoopsDB->queryF('SELECT options FROM ' . $xoopsDB->prefix('newblocks') . " WHERE name='Top Referers' AND dirname='statistics'"); |
||
| 47 | $optionsret = $xoopsDB->fetchRow($resultoption); |
||
| 48 | $options = explode('|', $optionsret[0]); |
||
| 49 | if ('' == $options[1]) { |
||
| 50 | $options[1] = 0; |
||
| 51 | } |
||
| 52 | |||
| 53 | $showselfrefer = $options[2]; |
||
| 54 | |||
| 55 | $result = $xoopsDB->queryF('SELECT refer, date, hits, referpath FROM ' . $xoopsDB->prefix('stats_refer') . ' ORDER BY hits DESC'); |
||
| 56 | $referhits = []; |
||
| 57 | $cnt = 0; |
||
| 58 | while (list($refer, $date, $hits, $referpath) = $xoopsDB->fetchRow($result)) { |
||
| 59 | if ((0 == $showselfrefer && !strcmp($refer, $_SERVER['HTTP_HOST'])) || '' == $refer) { |
||
| 60 | continue; |
||
| 61 | } |
||
| 62 | // see if we have a blacklist |
||
| 63 | $blacklisted = false; |
||
| 64 | |||
| 65 | // check configs if we are ignoring or allowing |
||
| 66 | if ('Allow' !== $helper->getConfig('refererspam')) { |
||
| 67 | if (count($referblacklist) > 0) { |
||
| 68 | $rbldelimited = '/' . implode('|', $referblacklist) . '/'; |
||
| 69 | if (preg_match($rbldelimited, $refer)) { |
||
| 70 | $blacklisted = true; |
||
|
|
|||
| 71 | continue; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | if (false === $blacklisted) { |
||
| 77 | $referpathparts = explode('|', $referpath); |
||
| 78 | if (($howmany = count($referpathparts)) < 3) { |
||
| 79 | switch ($howmany) { |
||
| 80 | case 0: |
||
| 81 | for ($i = 0; $i < 3; ++$i) { |
||
| 82 | $referpathparts[$i] = ''; |
||
| 83 | } |
||
| 84 | break; |
||
| 85 | case 1: |
||
| 86 | for ($i = 1; $i < 3; ++$i) { |
||
| 87 | $referpathparts[$i] = ''; |
||
| 88 | } |
||
| 89 | break; |
||
| 90 | case 2: |
||
| 91 | $referpathparts[2] = ''; |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | $referhits[$cnt]['pathing'] = $options[1]; |
||
| 97 | $referhits[$cnt]['elipses'] = B_STATS_ELIPSES; |
||
| 98 | $referhits[$cnt]['pathstrip'] = B_STATS_DELPATH; |
||
| 99 | $referhits[$cnt]['pathdns'] = B_STATS_PATHDNS; |
||
| 100 | $referhits[$cnt]['path'] = $referpathparts[0]; |
||
| 101 | $referhits[$cnt]['query'] = $referpathparts[1]; |
||
| 102 | $referhits[$cnt]['fragment'] = $referpathparts[2]; |
||
| 103 | $referhits[$cnt]['refer'] = $refer; |
||
| 104 | $referhits[$cnt]['hits'] = ''; |
||
| 105 | preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})/', $date, $regs); |
||
| 106 | $referhits[$cnt]['year'] = $regs[1]; |
||
| 107 | $referhits[$cnt]['month'] = $regs[2]; |
||
| 108 | $referhits[$cnt]['day'] = $regs[3]; |
||
| 109 | $referhits[$cnt]['hour'] = B_STATS_HOUR . ' ' . $regs[4]; |
||
| 110 | if (mb_strlen($hits) < 3) { |
||
| 111 | $hits = sprintf('%03d', $hits); |
||
| 112 | } |
||
| 113 | for ($i = 0, $iMax = mb_strlen($hits); $i < $iMax; ++$i) { |
||
| 114 | //the <img src> tag |
||
| 115 | $imgsrc = mb_substr($hits, $i, 1); |
||
| 116 | $referhits[$cnt]['hits'] .= '<img src="' . XOOPS_URL . '/modules/statistics/assets/images/' . $imgsrc . '.gif" border = "0">'; |
||
| 117 | } |
||
| 118 | |||
| 119 | ++$cnt; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | $xoopsTpl->assign('lang_refer_counterhead', B_STATS_REFERHEAD); |
||
| 124 | $xoopsTpl->assign('lang_refer_referhits', $referhits); |
||
| 125 | } |
||
| 130 |