| Conditions | 31 |
| Paths | > 20000 |
| Total Lines | 157 |
| Code Lines | 102 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 18 | function b_arts_spot_show($options) |
||
| 19 | { |
||
| 20 | $block_outdata = []; |
||
| 21 | //------------------------------------- |
||
| 22 | $myts = \MyTextSanitizer:: getInstance(); |
||
| 23 | $helper = \XoopsModules\Soapbox\Helper::getInstance(); |
||
|
|
|||
| 24 | $module_name = 'soapbox'; |
||
| 25 | $moduleHandler = xoops_getHandler('module'); |
||
| 26 | $soapModule = $moduleHandler->getByDirname($module_name); |
||
| 27 | if (!is_object($soapModule)) { |
||
| 28 | return null; |
||
| 29 | } |
||
| 30 | |||
| 31 | $hModConfig = xoops_getHandler('config'); |
||
| 32 | $module_id = $soapModule->getVar('mid'); |
||
| 33 | $soapConfig = $hModConfig->getConfigsByCat(0, $module_id); |
||
| 34 | //------------------------------------- |
||
| 35 | // To handle options in the template |
||
| 36 | if (isset($options[0]) && 1 === $options[0]) { |
||
| 37 | $block_outdata['showspotlight'] = 1; |
||
| 38 | } else { |
||
| 39 | $block_outdata['showspotlight'] = 0; |
||
| 40 | } |
||
| 41 | //------------------------------------- |
||
| 42 | if (isset($options[1])) { |
||
| 43 | $options[1] = (int)$options[1]; |
||
| 44 | } else { |
||
| 45 | $options[1] = 1; |
||
| 46 | } |
||
| 47 | if (empty($options[1])) { |
||
| 48 | $options[1] = 1; |
||
| 49 | } |
||
| 50 | //------------------------------------- |
||
| 51 | if (isset($options[2]) && 1 === $options[2]) { |
||
| 52 | $block_outdata['showdateask'] = 1; |
||
| 53 | } else { |
||
| 54 | $block_outdata['showdateask'] = 0; |
||
| 55 | } |
||
| 56 | //------------------------------------- |
||
| 57 | if (isset($options[3]) && 1 === $options[3]) { |
||
| 58 | $block_outdata['showbylineask'] = 1; |
||
| 59 | } else { |
||
| 60 | $block_outdata['showbylineask'] = 0; |
||
| 61 | } |
||
| 62 | //------------------------------------- |
||
| 63 | if (isset($options[4]) && 1 === $options[4]) { |
||
| 64 | $block_outdata['showstatsask'] = 1; |
||
| 65 | } else { |
||
| 66 | $block_outdata['showstatsask'] = 0; |
||
| 67 | } |
||
| 68 | //------------------------------------- |
||
| 69 | if (isset($options[5]) && 'ver' === $options[5]) { |
||
| 70 | $block_outdata['verticaltemplate'] = 1; |
||
| 71 | } else { |
||
| 72 | $block_outdata['verticaltemplate'] = 0; |
||
| 73 | } |
||
| 74 | //------------------------------------- |
||
| 75 | if (isset($options[6]) && 1 === $options[6]) { |
||
| 76 | $block_outdata['showpicask'] = 1; |
||
| 77 | } else { |
||
| 78 | $block_outdata['showpicask'] = 0; |
||
| 79 | } |
||
| 80 | //------------------------------------- |
||
| 81 | $sortname = $options[7]; |
||
| 82 | if (!in_array($sortname, ['datesub', 'weight', 'counter', 'rating', 'headline'], true)) { |
||
| 83 | $sortname = 'datesub'; |
||
| 84 | } |
||
| 85 | $sortorder = 'DESC'; |
||
| 86 | if ('weight' === $sortname) { |
||
| 87 | $sortorder = 'ASC'; |
||
| 88 | } |
||
| 89 | //------------------------------------- |
||
| 90 | if (isset($options[8]) && (int)$options[8] > 0) { |
||
| 91 | $options[8] = (int)$options[8]; |
||
| 92 | } else { |
||
| 93 | $options[8] = 65; |
||
| 94 | } |
||
| 95 | //------------------------------------- |
||
| 96 | // Try to see what tabs are visibles (if we are in restricted view of course) |
||
| 97 | $opt_columnIDs = []; |
||
| 98 | if (!empty($options[9])) { |
||
| 99 | $opt_columnIDs = array_slice($options, 9); |
||
| 100 | } |
||
| 101 | if (!empty($opt_columnIDs) && is_array($opt_columnIDs)) { |
||
| 102 | foreach ($opt_columnIDs as $v) { |
||
| 103 | $columnIDs[] = (int)$v; |
||
| 104 | } |
||
| 105 | } else { |
||
| 106 | $columnIDs = null; |
||
| 107 | } |
||
| 108 | // Retrieve the column's name |
||
| 109 | // $resultB = $xoopsDB -> query( "SELECT name, colimage FROM ". $xoopsDB -> prefix( "sbcolumns" ) . " WHERE columnID = " . $options[0] . " " ); |
||
| 110 | // list ( $name, $colimage ) = $xoopsDB -> fetchRow( $resultB ); |
||
| 111 | //------------------------------------- |
||
| 112 | /** @var \XoopsModules\Soapbox\EntrygetHandler $entrydataHandler */ |
||
| 113 | $entrydataHandler = new \XoopsModules\Soapbox\EntrygetHandler(); |
||
| 114 | //------------------------------------- |
||
| 115 | // Retrieve the latest article in the selected column |
||
| 116 | $entryobArray = $entrydataHandler->getArticlesAllPermcheck($options[1], 0, true, true, 0, 0, 1, $sortname, $sortorder, $columnIDs, null, false, false); |
||
| 117 | $totalarts = $entrydataHandler->total_getArticlesAllPermcheck; |
||
| 118 | // If there's no article result (which means there's no article yet... |
||
| 119 | if (empty($entryobArray) || 0 === count($entryobArray)) { |
||
| 120 | $block_outdata['display'] = 0; |
||
| 121 | |||
| 122 | return $block_outdata; |
||
| 123 | } |
||
| 124 | $block_outdata['display'] = 1; |
||
| 125 | //------------------------------------- |
||
| 126 | $block_outdata['moduledir'] = $module_name; |
||
| 127 | $block_outdata['totalarts'] = (int)$totalarts; |
||
| 128 | $block_outdata['modulename'] = $soapModule->getVar('name'); |
||
| 129 | $block_outdata['sbuploaddir'] = $myts->htmlSpecialChars($soapConfig['sbuploaddir']); |
||
| 130 | //------------------------------------- |
||
| 131 | $i = 1; |
||
| 132 | xoops_load('XoopsUserUtility'); |
||
| 133 | foreach ($entryobArray as $key => $_entryob) { |
||
| 134 | // get vars initialize |
||
| 135 | //------------------------------------- |
||
| 136 | $articles = $_entryob->toArray(); |
||
| 137 | //get category object |
||
| 138 | $_categoryob = $_entryob->_sbcolumns; |
||
| 139 | //get vars |
||
| 140 | $category = $_categoryob->toArray(); |
||
| 141 | //spot |
||
| 142 | $_outdata_arr = []; |
||
| 143 | $_outdata_arr = $articles; |
||
| 144 | $_outdata_arr['column'] = $category; |
||
| 145 | |||
| 146 | $_outdata_arr['authorname'] = \XoopsUserUtility::getUnameFromId((int)$category['author']); |
||
| 147 | $_outdata_arr['poster'] = \XoopsUserUtility::getUnameFromId($articles['uid']); |
||
| 148 | $_outdata_arr['date'] = $myts->htmlSpecialChars(formatTimestamp($articles['datesub'], $soapConfig['dateformat'])); |
||
| 149 | $_outdata_arr['rating'] = number_format($articles['rating'], 2, '.', ''); |
||
| 150 | // -- Then the teaser text and as sorted data |
||
| 151 | $_outdata_arr['subhead'] = xoops_substr($articles['headline'], 0, $options[8]); |
||
| 152 | $_outdata_arr['sublead'] = xoops_substr($articles['lead'], 0, 255); |
||
| 153 | $_outdata_arr['subteaser'] = xoops_substr($articles['teaser'], 0, 255); |
||
| 154 | $_outdata_arr ['subbodytext'] = xoops_substr($articles['bodytext'], 0, 255); |
||
| 155 | $_outdata_arr ['bodytext'] = ''; |
||
| 156 | |||
| 157 | if ('datesub' === $sortname) { |
||
| 158 | $_outdata_arr['new'] = $myts->htmlSpecialChars(formatTimestamp($articles['datesub'], $soapConfig['dateformat'])); |
||
| 159 | } elseif ('counter' === $sortname) { |
||
| 160 | $_outdata_arr['new'] = _MB_SOAPBOX_HITS . $articles['counter']; |
||
| 161 | } elseif ('weight' === $sortname) { |
||
| 162 | $_outdata_arr['new'] = _MB_SOAPBOX_WEIGHT . $articles['weight']; |
||
| 163 | } elseif ('rating' === $sortname) { |
||
| 164 | $_outdata_arr['new'] = _MB_SOAPBOX_RATING . number_format($articles['rating'], 2, '.', '') . _MB_SOAPBOX_VOTE . $articles['votes']; |
||
| 165 | } else { |
||
| 166 | $_outdata_arr['new'] = $myts->htmlSpecialChars(formatTimestamp($articles['datesub'], $soapConfig['dateformat'])); |
||
| 167 | } |
||
| 168 | //-------------------- |
||
| 169 | $block_outdata['artdatas'][$i] = $_outdata_arr; |
||
| 170 | unset($_outdata_arr); |
||
| 171 | ++$i; |
||
| 172 | } |
||
| 173 | |||
| 174 | return $block_outdata; |
||
| 175 | } |
||
| 323 |