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