| Conditions | 40 |
| Paths | > 20000 |
| Total Lines | 248 |
| Code Lines | 163 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 declare(strict_types=1); |
||
| 35 | function publisher_latest_news_show($options) |
||
| 36 | { |
||
| 37 | $block = []; |
||
| 38 | |||
| 39 | $configurator = new Configurator(); |
||
| 40 | $icons = $configurator->icons; |
||
| 41 | |||
| 42 | $helper = Helper::getInstance(); |
||
| 43 | $helper->loadLanguage('main'); |
||
| 44 | /** @var ItemHandler $itemHandler */ |
||
| 45 | $itemHandler = $helper->getHandler('Item'); |
||
| 46 | // xoops_loadLanguage('main', 'publisher'); |
||
| 47 | |||
| 48 | $start = $options[0]; // You can show articles from specified range |
||
| 49 | $limit = $options[1]; |
||
| 50 | $columnCount = $options[2]; |
||
| 51 | $letters = (int)$options[3]; |
||
| 52 | $selectedStories = $options[4]; |
||
| 53 | $sort = $options[9]; |
||
| 54 | $order = Utility::getOrderBy($sort); |
||
| 55 | $imgWidth = $options[11]; |
||
| 56 | $imgHeight = $options[12]; |
||
| 57 | $border = $options[13]; |
||
| 58 | $bordercolor = $options[14]; |
||
| 59 | |||
| 60 | $block['spec']['columnwidth'] = (1 / $columnCount * 100); |
||
| 61 | |||
| 62 | $allcats = false; |
||
| 63 | if (empty($options[31])) { |
||
| 64 | $allcats = true; |
||
| 65 | } elseif (in_array(0, explode(',', $options[31]), true)) { |
||
| 66 | $allcats = true; |
||
| 67 | } |
||
| 68 | |||
| 69 | // creating the ITEM objects that belong to the selected category |
||
| 70 | if ($allcats) { |
||
| 71 | $criteria = null; |
||
| 72 | } else { |
||
| 73 | $criteria = new \CriteriaCompo(); |
||
| 74 | $criteria->add(new \Criteria('categoryid', '(' . $options[31] . ')', 'IN')); |
||
| 75 | } |
||
| 76 | |||
| 77 | // Use specific ITEMS |
||
| 78 | if (0 != $selectedStories) { |
||
| 79 | unset($criteria); //removes category option |
||
| 80 | $criteria = new \CriteriaCompo(); |
||
| 81 | $criteria->add(new \Criteria('itemid', '(' . $selectedStories . ')', 'IN')); |
||
| 82 | } |
||
| 83 | |||
| 84 | $publisherIsAdmin = $helper->isUserAdmin(); |
||
| 85 | if (!$publisherIsAdmin) { |
||
| 86 | if (null === $criteria) { |
||
| 87 | $criteria = new \CriteriaCompo(); |
||
| 88 | } |
||
| 89 | $criteriaDateSub = new \Criteria('datesub', time(), '<='); |
||
| 90 | $criteria->add($criteriaDateSub); |
||
| 91 | } |
||
| 92 | |||
| 93 | $itemsObj = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, 'itemid'); |
||
| 94 | |||
| 95 | $scount = count($itemsObj); |
||
| 96 | |||
| 97 | if (0 == $scount) { |
||
| 98 | return false; |
||
| 99 | } |
||
| 100 | $k = 0; |
||
| 101 | $columns = []; |
||
| 102 | |||
| 103 | foreach ($itemsObj as $itemId => $itemObj) { |
||
| 104 | $item = []; |
||
| 105 | $item['itemurl'] = $itemObj->getItemUrl(); |
||
| 106 | $item['title'] = $itemObj->getItemLink(); |
||
| 107 | $item['alt'] = strip_tags($itemObj->getItemLink()); |
||
| 108 | $mainImage = $itemObj->getMainImage(); |
||
| 109 | if (empty($mainImage['image_path'])) { |
||
| 110 | $mainImage['image_path'] = PUBLISHER_URL . '/assets/images/default_image.jpg'; |
||
| 111 | } |
||
| 112 | // check to see if GD function exist |
||
| 113 | if (!empty($mainImage['image_path']) && !function_exists('imagecreatetruecolor')) { |
||
| 114 | $item['item_image'] = $mainImage['image_path']; |
||
| 115 | } else { |
||
| 116 | $item['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&w=' . $imgWidth; // No $imgHeight for autoheight option |
||
| 117 | $item['image_path'] = $mainImage['image_path']; |
||
| 118 | } |
||
| 119 | $item['text'] = $itemObj->getBlockSummary($letters); |
||
| 120 | $item['display_item_image'] = $options[10]; |
||
| 121 | $item['display_summary'] = $options[16]; |
||
| 122 | $item['display_adminlink'] = $options[29]; |
||
| 123 | $item = $itemObj->getMainImage($item); //returns an array |
||
| 124 | |||
| 125 | $lsHeight = $imgPosition = $lsMargin = ''; |
||
| 126 | if (0 != $options[12]) { |
||
| 127 | $lsHeight = 'height="' . $imgHeight . '" '; |
||
| 128 | } // set height = 0 in block option for auto height |
||
| 129 | |||
| 130 | if ('LEFT' === $options[15]) { |
||
| 131 | $imgPosition = 'float: left'; |
||
| 132 | $lsMargin = '-right'; |
||
| 133 | $block['position'] = $imgPosition; |
||
| 134 | $block['margin'] = $lsMargin; |
||
| 135 | } |
||
| 136 | |||
| 137 | if ('CENTER' === $options[15]) { |
||
| 138 | $imgPosition = 'text-align:center'; |
||
| 139 | $lsMargin = ''; |
||
| 140 | $block['position'] = $imgPosition; |
||
| 141 | $block['margin'] = $lsMargin; |
||
| 142 | } |
||
| 143 | |||
| 144 | if ('RIGHT' === $options[15]) { |
||
| 145 | $imgPosition = 'float: right'; |
||
| 146 | $lsMargin = '-left'; |
||
| 147 | $block['position'] = $imgPosition; |
||
| 148 | $block['margin'] = $lsMargin; |
||
| 149 | } |
||
| 150 | |||
| 151 | //Image |
||
| 152 | if (1 == $options[10] && '' != $item['image_path']) { |
||
| 153 | $startdiv = '<div style="' . $imgPosition . '"><a href="' . $item['itemurl'] . '">'; |
||
| 154 | $style = 'style="margin' . $lsMargin . ': 10px; padding: 2px; border: ' . $border . 'px solid #' . $bordercolor . '"'; |
||
| 155 | $enddiv = 'width="' . $imgWidth . '" ' . $lsHeight . '></a></div>'; |
||
| 156 | $image = $startdiv . '<img ' . $style . ' src="' . $item['item_image'] . '" alt="' . $item['image_name'] . '" ' . $enddiv; |
||
| 157 | |||
| 158 | $item['image'] = $image; |
||
| 159 | } |
||
| 160 | |||
| 161 | if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin(-1)) { |
||
| 162 | $item['admin'] = "<a href='" . PUBLISHER_URL . '/submit.php?itemid=' . $itemObj->itemid() . "'" . $icons['edit'] . '</a> '; |
||
| 163 | $item['admin'] .= "<a href='" . PUBLISHER_URL . '/admin/item.php?op=del&itemid=' . $itemObj->itemid() . "'>" . $icons['delete'] . '</a>'; |
||
| 164 | } else { |
||
| 165 | $item['admin'] = ''; |
||
| 166 | } |
||
| 167 | |||
| 168 | $block['topiclink'] = ''; |
||
| 169 | |||
| 170 | if (1 == $options[16]) { |
||
| 171 | $block['text'] = $itemObj->getBlockSummary($letters); |
||
| 172 | } |
||
| 173 | |||
| 174 | $block['archivelink'] = ''; |
||
| 175 | if (1 == $options[17]) { |
||
| 176 | $block['archivelink'] = '| <a href="' . PUBLISHER_URL . '/archive.php">' . _MB_PUBLISHER_ARCHIVE . '</a> '; |
||
| 177 | } |
||
| 178 | |||
| 179 | //TODO: Should we not show link to Anonymous? |
||
| 180 | $block['submitlink'] = ''; |
||
| 181 | if (1 == $options[18] && $GLOBALS['xoopsUser']) { |
||
| 182 | $block['submitlink'] = '| <a href="' . PUBLISHER_URL . '/submit.php">' . _MB_PUBLISHER_SUBMITNEWS . '</a> '; |
||
| 183 | } |
||
| 184 | |||
| 185 | $item['poster'] = ''; |
||
| 186 | if (1 == $options[19]) { |
||
| 187 | $item['poster'] = $itemObj->posterName(); |
||
| 188 | $block['lang_poster'] = _MB_PUBLISHER_POSTEDBY; |
||
| 189 | } |
||
| 190 | |||
| 191 | $item['posttime'] = ''; |
||
| 192 | if (1 == $options[20]) { |
||
| 193 | $item['posttime'] = $itemObj->getDatesub(); |
||
| 194 | $block['lang_date'] = _MB_PUBLISHER_ON; |
||
| 195 | } |
||
| 196 | |||
| 197 | $item['topic_title'] = ''; |
||
| 198 | if (1 == $options[21]) { |
||
| 199 | $item['topic_title'] = $itemObj->getCategoryLink(); |
||
| 200 | $item['category'] = strip_tags($itemObj->getCategoryLink()); |
||
| 201 | $block['lang_category'] = _MB_PUBLISHER_CATEGORY; |
||
| 202 | } |
||
| 203 | |||
| 204 | $item['read'] = ''; |
||
| 205 | if (1 == $options[22]) { |
||
| 206 | $item['read'] = $itemObj->counter(); |
||
| 207 | $block['lang_reads'] = _MB_PUBLISHER_READS; |
||
| 208 | } |
||
| 209 | $item['cancomment'] = $itemObj->cancomment(); |
||
| 210 | $comments = $itemObj->comments(); |
||
| 211 | if (1 == $options[23]) { |
||
| 212 | if ($comments > 0) { |
||
| 213 | //shows 1 comment instead of 1 comm. if comments ==1 |
||
| 214 | //langugage file modified accordingly |
||
| 215 | if (1 == $comments) { |
||
| 216 | $item['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' '; |
||
| 217 | } else { |
||
| 218 | $item['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' '; |
||
| 219 | } |
||
| 220 | } else { |
||
| 221 | $item['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' '; |
||
| 222 | } |
||
| 223 | } |
||
| 224 | |||
| 225 | $item['print'] = ''; |
||
| 226 | if (1 == $options[24]) { |
||
| 227 | $item['print'] = '<a href="' . Seo::generateUrl('print', $itemObj->itemid(), $itemObj->short_url()) . '" rel="nofollow">' . $icons['print'] . '</a> '; |
||
| 228 | } |
||
| 229 | |||
| 230 | $item['pdf'] = ''; |
||
| 231 | |||
| 232 | if (1 == $options[25]) { |
||
| 233 | $item['pdf'] = "<a href='" . PUBLISHER_URL . '/makepdf.php?itemid=' . $itemObj->itemid() . "' rel='nofollow'>" . $icons['pdf'] . '</a> '; |
||
| 234 | } |
||
| 235 | |||
| 236 | $item['email'] = ''; |
||
| 237 | if (1 == $options[26]) { |
||
| 238 | $maillink = 'mailto:?subject=' . sprintf(_CO_PUBLISHER_INTITEM, $GLOBALS['xoopsConfig']['sitename']) . '&body=' . sprintf(_CO_PUBLISHER_INTITEMFOUND, $GLOBALS['xoopsConfig']['sitename']) . ': ' . $itemObj->getItemUrl(); |
||
| 239 | $item['email'] = '<a href="' . $maillink . '">' . $icons['mail'] . '</a> '; |
||
| 240 | } |
||
| 241 | |||
| 242 | $block['morelink'] = ''; |
||
| 243 | if (1 == $options[27]) { |
||
| 244 | $block['morelink'] = '<a href="' . PUBLISHER_URL . '/index.php">' . _MB_PUBLISHER_MORE_ITEMS . '</a> '; |
||
| 245 | } |
||
| 246 | |||
| 247 | $item['more'] = ''; |
||
| 248 | if ((1 == $options[28] && '' != $itemObj->body()) || $itemObj->comments() > 0) { |
||
| 249 | $item['more'] = '<a href="' . $itemObj->getItemUrl() . '">' . _MB_PUBLISHER_READMORE . '</a>'; |
||
| 250 | } |
||
| 251 | |||
| 252 | $block['latestnews_scroll'] = false; |
||
| 253 | if (1 == $options[5]) { |
||
| 254 | $block['latestnews_scroll'] = true; |
||
| 255 | } |
||
| 256 | |||
| 257 | $block['scrollheight'] = $options[6]; |
||
| 258 | $block['scrollspeed'] = $options[7]; |
||
| 259 | $block['scrolldir'] = $options[8]; |
||
| 260 | |||
| 261 | $block['template'] = $options[30]; |
||
| 262 | |||
| 263 | $block['imgwidth'] = $options[11]; |
||
| 264 | $block['imgheight'] = $options[12]; |
||
| 265 | $block['border'] = $options[13]; |
||
| 266 | $block['bordercolor'] = $options[14]; |
||
| 267 | |||
| 268 | $block['letters'] = $letters; |
||
| 269 | |||
| 270 | $columns[$k][] = $item; |
||
| 271 | ++$k; |
||
| 272 | |||
| 273 | if ($k == $columnCount) { |
||
| 274 | $k = 0; |
||
| 275 | } |
||
| 276 | } |
||
| 277 | |||
| 278 | unset($item); |
||
| 279 | $block['columns'] = $columns; |
||
| 280 | $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/' . PUBLISHER_DIRNAME . '/assets/css/' . PUBLISHER_DIRNAME . '.css'); |
||
| 281 | |||
| 282 | return $block; |
||
| 283 | } |
||
| 488 |