Conditions | 17 |
Paths | 1280 |
Total Lines | 118 |
Code Lines | 77 |
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 |
||
15 | function b_lxspot_show($options) |
||
16 | { |
||
17 | global $xoopsDB, $xoopsUser; |
||
18 | $myts = MyTextSanitizer:: getInstance(); |
||
19 | xoops_load('XoopsUserUtility'); |
||
20 | |||
21 | $module_name = 'lexikon'; |
||
|
|||
22 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
23 | $moduleHandler = xoops_getHandler('module'); |
||
24 | $lexikon = $moduleHandler->getByDirname('lexikon'); |
||
25 | if (!isset($lxConfig)) { |
||
26 | /** @var \XoopsConfigHandler $configHandler */ |
||
27 | $configHandler = xoops_getHandler('config'); |
||
28 | $lxConfig = $configHandler->getConfigsByCat(0, $lexikon->getVar('mid')); |
||
29 | } |
||
30 | |||
31 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
32 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
33 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
34 | $module_id = $lexikon->getVar('mid'); |
||
35 | |||
36 | $block = []; |
||
37 | |||
38 | // To handle options in the template |
||
39 | if (1 == $options[2]) { |
||
40 | $block['showdateask'] = 1; |
||
41 | } else { |
||
42 | $block['showdateask'] = 0; |
||
43 | } |
||
44 | if (1 == $options[3]) { |
||
45 | $block['showbylineask'] = 1; |
||
46 | } else { |
||
47 | $block['showbylineask'] = 0; |
||
48 | } |
||
49 | if (1 == $options[4]) { |
||
50 | $block['showstatsask'] = 1; |
||
51 | } else { |
||
52 | $block['showstatsask'] = 0; |
||
53 | } |
||
54 | if ('ver' === $options[5]) { |
||
55 | $block['verticaltemplate'] = 1; |
||
56 | } else { |
||
57 | $block['verticaltemplate'] = 0; |
||
58 | } |
||
59 | if (1 == $options[6]) { |
||
60 | $block['showpicask'] = 1; |
||
61 | } else { |
||
62 | $block['showpicask'] = 0; |
||
63 | } |
||
64 | |||
65 | // Retrieve the latest terms in the selected category |
||
66 | $resultA = $xoopsDB->query( |
||
67 | 'SELECT entryID, categoryID, term, definition, uid, datesub, counter, html, smiley, xcodes, breaks, comments |
||
68 | FROM ' . $xoopsDB->prefix('lxentries') . ' |
||
69 | WHERE categoryID = ' . $options[0] . " AND submit = '0' AND offline = 0 AND block= 1 |
||
70 | ORDER BY datesub DESC", //ORDER BY " . $options[7] . " DESC ", |
||
71 | 1, |
||
72 | 0 |
||
73 | ); |
||
74 | |||
75 | [$entryID, $categoryID, $term, $definition, $authorID, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $comments] = $xoopsDB->fetchRow($resultA); |
||
76 | $eID = (int)$entryID; |
||
77 | // If there's no result - which means there's no definition yet... |
||
78 | if (0 == $eID) { |
||
79 | $block['display'] = 0; |
||
80 | } else { |
||
81 | $block['display'] = 1; |
||
82 | } |
||
83 | |||
84 | // Retrieve the category name |
||
85 | $resultB = $xoopsDB->query('SELECT name, logourl FROM ' . $xoopsDB->prefix('lxcategories') . ' WHERE categoryID = ' . $options[0] . ' '); |
||
86 | [$name, $logourl] = $xoopsDB->fetchRow($resultB); |
||
87 | $lexikon = $moduleHandler->getByDirname('lexikon'); |
||
88 | if ($lexikon) { |
||
89 | if ($grouppermHandler->checkRight('lexikon_view', $options[0], $groups, $module_id)) { |
||
90 | // get the items |
||
91 | $block['userID'] = ((int)$authorID); |
||
92 | $block['authorname'] = \XoopsUserUtility::getUnameFromId((int)$authorID); |
||
93 | $block['name'] = xoops_substr($name, 0, (int)$options[9]); |
||
94 | $block['catID'] = (int)$options[0]; |
||
95 | $block['catimage'] = stripslashes($logourl); |
||
96 | $block['termID'] = (int)$entryID; |
||
97 | $block['title'] = htmlspecialchars($term, ENT_QUOTES | ENT_HTML5); |
||
98 | $block['introtext'] = xoops_substr($myts->displayTarea($definition, $html, 1, $xcodes, 1, $breaks), 0, (int)$options[8]); |
||
99 | |||
100 | $block['moduledir'] = $lexikon->dirname(); |
||
101 | $block['date'] = formatTimestamp($datesub, 'd M Y'); |
||
102 | //$block['date'] = formatTimestamp( $datesub, $lxConfig['dateformat'] ); |
||
103 | $block['hits'] = (int)$counter; |
||
104 | if ((0 != $lxConfig['com_rule']) || ((0 != $lxConfig['com_rule']) && is_object($xoopsUser))) { |
||
105 | if (0 != $comments) { |
||
106 | $block['comments'] = "<a href='" . XOOPS_URL . '/modules/' . $lexikon->dirname() . '/entry.php?entryID=' . $block['termID'] . "'>" . _COMMENTS . ' : ' . $comments . '</a>'; |
||
107 | } else { |
||
108 | $block['comments'] = "<a href='" . XOOPS_URL . '/modules/' . $lexikon->dirname() . '/entry.php?entryID=' . $block['termID'] . "'>" . _COMMENTS . '?</a>'; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | // get the other terms |
||
113 | $resultC = $xoopsDB->query('SELECT entryID, term, datesub FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE categoryID = ' . $options[0] . ' AND entryID != ' . $block['termID'] . ' AND submit = 0 AND offline = 0 AND block= 1 ORDER BY ' . $options[7] . ' DESC ', $options[1], 0); |
||
114 | |||
115 | $i = 0; |
||
116 | while (false !== ($myrow = $xoopsDB->fetchArray($resultC))) { |
||
117 | if ($i < $options[1]) { |
||
118 | $morelinks = []; |
||
119 | $morelinks['id'] = $myrow['entryID']; |
||
120 | $morelinks['head'] = xoops_substr(htmlspecialchars($myrow['term'], ENT_QUOTES | ENT_HTML5), 0, (int)$options[9]); |
||
121 | |||
122 | $morelinks['subdate'] = formatTimestamp($datesub, 'd M Y'); |
||
123 | ++$i; |
||
124 | $block['links'][] = $morelinks; |
||
125 | } |
||
126 | } |
||
127 | } else { // if permissions are not granted |
||
128 | $block['display'] = 0; |
||
129 | } |
||
130 | } |
||
131 | //------------ |
||
132 | return $block; |
||
133 | } |
||
189 |