Conditions | 13 |
Paths | 42 |
Total Lines | 80 |
Code Lines | 53 |
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_refercounter_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[2]; |
||
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 | $result = $xoopsDB->queryF('SELECT refer, date, hits, referpath FROM ' . $xoopsDB->prefix('stats_refer') . ' ORDER BY hits DESC'); |
||
52 | $referhits = []; |
||
53 | $cnt = 0; |
||
54 | while (list($refer, $date, $hits, $referpath) = $xoopsDB->fetchRow($result)) { |
||
55 | if ((0 == $showselfrefer && !strcmp($refer, $_SERVER['HTTP_HOST'])) || '' == $refer) { |
||
56 | continue; |
||
57 | } |
||
58 | // see if we have a blacklist |
||
59 | $blacklisted = false; |
||
60 | if ('Allow' !== $xoopsStatConfig['refererspam']) { // make sure they really want them ignored |
||
61 | if (count($referblacklist) > 0) { |
||
62 | $rbldelimited = '/' . implode('|', $referblacklist) . '/'; |
||
63 | if (preg_match($rbldelimited, $refer)) { |
||
64 | $blacklisted = true; |
||
|
|||
65 | continue; |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | if (false === $blacklisted) { |
||
71 | $referpathparts = explode('|', $referpath); |
||
72 | |||
73 | $referhits[$cnt]['pathing'] = $options[1]; |
||
74 | $referhits[$cnt]['elipses'] = B_STATS_ELIPSES; |
||
75 | $referhits[$cnt]['pathstrip'] = B_STATS_DELPATH; |
||
76 | $referhits[$cnt]['pathdns'] = B_STATS_PATHDNS; |
||
77 | $referhits[$cnt]['path'] = $referpathparts[0]; |
||
78 | $referhits[$cnt]['query'] = $referpathparts[1]; |
||
79 | $referhits[$cnt]['fragment'] = $referpathparts[2]; |
||
80 | $referhits[$cnt]['refer'] = $refer; |
||
81 | $referhits[$cnt]['hits'] = ''; |
||
82 | preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})/', $date, $regs); |
||
83 | $referhits[$cnt]['year'] = $regs[1]; |
||
84 | $referhits[$cnt]['month'] = $regs[2]; |
||
85 | $referhits[$cnt]['day'] = $regs[3]; |
||
86 | $referhits[$cnt]['hour'] = B_STATS_HOUR . ' ' . $regs[4]; |
||
87 | if (mb_strlen($hits) < 3) { |
||
88 | $hits = sprintf('%03d', $hits); |
||
89 | } |
||
90 | for ($i = 0, $iMax = mb_strlen($hits); $i < $iMax; ++$i) { |
||
91 | //the <img src> tag |
||
92 | $imgsrc = mb_substr($hits, $i, 1); |
||
93 | $referhits[$cnt]['hits'] .= '<img src="' . XOOPS_URL . '/modules/statistics/assets/images/' . $imgsrc . '.gif" border = "0">'; |
||
94 | } |
||
95 | |||
96 | ++$cnt; |
||
97 | } |
||
98 | |||
99 | if ($cnt == $showhowmany) { |
||
100 | break; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | $block['counterhead'] = B_STATS_REFERHEAD; |
||
105 | $block['referhits'] = $referhits; |
||
106 | |||
107 | return $block; |
||
108 | } |
||
142 |