| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 216 |
| Code Lines | 134 |
| 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 |
||
| 26 | function publisher_latest_news_show($options) |
||
| 27 | { |
||
| 28 | $xoops = Xoops::getInstance(); |
||
| 29 | $publisher = Publisher::getInstance(); |
||
| 30 | $publisher->loadLanguage('main'); |
||
| 31 | |||
| 32 | $block = array(); |
||
| 33 | |||
| 34 | $start = $options[0]; // You can show articles from specified range |
||
| 35 | $limit = $options[1]; |
||
| 36 | $column_count = $options[2]; |
||
| 37 | $letters = $options[3]; |
||
| 38 | $selected_stories = $options[4]; |
||
| 39 | $sort = $options[9]; |
||
| 40 | $order = PublisherUtils::getOrderBy($sort); |
||
| 41 | $imgwidth = $options[11]; |
||
| 42 | $imgheight = $options[12]; |
||
| 43 | $border = $options[13]; |
||
| 44 | $bordercolor = $options[14]; |
||
| 45 | |||
| 46 | $block['spec']['columnwidth'] = (int)(1 / $column_count * 100); |
||
| 47 | |||
| 48 | $allcats = false; |
||
| 49 | if (!isset($options[29])) { |
||
| 50 | $allcats = true; |
||
| 51 | } elseif (in_array(0, explode(',', $options[29]))) { |
||
| 52 | $allcats = true; |
||
| 53 | } |
||
| 54 | |||
| 55 | // creating the ITEM objects that belong to the selected category |
||
| 56 | if ($allcats) { |
||
| 57 | $criteria = null; |
||
| 58 | } else { |
||
| 59 | $criteria = new CriteriaCompo(); |
||
| 60 | $criteria->add(new Criteria('categoryid', '(' . $options[29] . ')', 'IN')); |
||
| 61 | } |
||
| 62 | |||
| 63 | // Use specific ITEMS |
||
| 64 | if ($selected_stories != 0) { |
||
| 65 | unset($criteria); //removes category option |
||
| 66 | $criteria = new CriteriaCompo(); |
||
| 67 | $criteria->add(new Criteria('itemid', '(' . $selected_stories . ')', 'IN')); |
||
| 68 | } |
||
| 69 | |||
| 70 | $itemsObj = $publisher->getItemHandler()->getItems($limit, $start, array(_PUBLISHER_STATUS_PUBLISHED), -1, $sort, $order, '', true, $criteria, 'itemid'); |
||
| 71 | |||
| 72 | $scount = count($itemsObj); |
||
| 73 | |||
| 74 | if ($scount == 0) { |
||
| 75 | return false; |
||
| 76 | } |
||
| 77 | $k = 0; |
||
| 78 | $columns = array(); |
||
| 79 | |||
| 80 | $thumbService = \Xoops::getInstance()->service('thumbnail'); |
||
| 81 | |||
| 82 | /* @var $itemObj PublisherItem */ |
||
| 83 | foreach ($itemsObj as $itemObj) { |
||
| 84 | $item = array(); |
||
| 85 | $item['itemurl'] = $itemObj->getItemUrl(); |
||
| 86 | $item['title'] = $itemObj->getItemLink(); |
||
| 87 | $item['alt'] = strip_tags($itemObj->getItemLink()); |
||
| 88 | $mainImage = $itemObj->getMainImage(); |
||
| 89 | $item['item_image'] = $thumbService |
||
| 90 | ->getImgUrl($mainImage['image_vpath'], $imgwidth, 0) |
||
| 91 | ->getValue(); |
||
| 92 | |||
| 93 | $item['text'] = $itemObj->getBlockSummary($letters); |
||
| 94 | |||
| 95 | $item = $itemObj->getMainImage($item); //returns an array |
||
| 96 | |||
| 97 | $ls_height = ''; |
||
| 98 | if ($options[12] != 0) { |
||
| 99 | $ls_height = 'height="' . $imgheight . '" '; |
||
| 100 | } |
||
| 101 | |||
| 102 | if ($options[15] === 'LEFT') { |
||
| 103 | $imgposition = "float: left"; |
||
| 104 | $ls_margin = '-right'; |
||
| 105 | } elseif ($options[15] === 'CENTER') { |
||
| 106 | $imgposition = "text-align:center"; |
||
| 107 | $ls_margin = ''; |
||
| 108 | } else { |
||
| 109 | $imgposition = "float: right"; |
||
| 110 | $ls_margin = '-left'; |
||
| 111 | } |
||
| 112 | |||
| 113 | |||
| 114 | //Image |
||
| 115 | if ($options[10] == 1 && $item['image_path'] != '') { |
||
| 116 | $startdiv = '<div style="' . $imgposition . '"><a href="' . $item['itemurl'] . '">'; |
||
| 117 | $style = 'style="margin' . $ls_margin . ': 10px; padding: 2px; border: ' . $border . 'px solid #' . $bordercolor . '"'; |
||
| 118 | $enddiv = 'width="' . $imgwidth . '" ' . $ls_height . '/></a></div>'; |
||
| 119 | $image = $startdiv . '<img ' . $style . ' src="' . $item['item_image'] . '" alt="' . $item['image_name'] . '" ' . $enddiv; |
||
| 120 | |||
| 121 | $item['image'] = $image; |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($publisher->isUserAdmin()) { |
||
| 125 | $item['admin'] = "<a href='" . PUBLISHER_URL . "/submit.php?itemid=" . $itemObj->getVar('itemid'). "'><img src='" . PUBLISHER_URL . "/images/links/edit.gif'" . " title='" . _CO_PUBLISHER_EDIT . "' alt='" . _CO_PUBLISHER_EDIT . "' /></a> "; |
||
| 126 | $item['admin'] .= "<a href='" . PUBLISHER_URL . "/admin/item.php?op=del&itemid=" . $itemObj->getVar('itemid'). "'><img src='" . PUBLISHER_URL . "/images/links/delete.png'" . " title='" . _CO_PUBLISHER_DELETE . "' alt='" . _CO_PUBLISHER_DELETE . "' /></a>"; |
||
| 127 | } else { |
||
| 128 | $item['admin'] = ''; |
||
| 129 | } |
||
| 130 | |||
| 131 | $block['topiclink'] = ''; |
||
| 132 | /* |
||
| 133 | if ($options[16] == 1) { |
||
| 134 | $block['topiclink'] = '| <a href="'.\XoopsBaseConfig::get('url').'/modules/news/topics_directory.php">'._AM_NEWS_TOPICS_DIRECTORY.'</a> '; |
||
| 135 | } |
||
| 136 | */ |
||
| 137 | $block['archivelink'] = ''; |
||
| 138 | if ($options[17] == 1) { |
||
| 139 | $block['archivelink'] = '| <a href="' . PUBLISHER_URL . '/archive.php">' . _MB_PUBLISHER_ARCHIVE . '</a> '; |
||
| 140 | } |
||
| 141 | |||
| 142 | //TODO: Should we not show link to Anonymous? |
||
| 143 | $block['submitlink'] = ''; |
||
| 144 | if ($options[18] == 1 && $xoops->isUser()) { |
||
| 145 | $block['submitlink'] = '| <a href="' . PUBLISHER_URL . '/submit.php">' . _MB_PUBLISHER_SUBMITNEWS . '</a> '; |
||
| 146 | } |
||
| 147 | |||
| 148 | $item['poster'] = ''; |
||
| 149 | if ($options[19] == 1) { |
||
| 150 | $item['poster'] = _MB_PUBLISHER_POSTER . ' ' . $itemObj->posterName(); |
||
| 151 | } |
||
| 152 | |||
| 153 | $item['posttime'] = ''; |
||
| 154 | if ($options[20] == 1) { |
||
| 155 | //todo, check this concatenation |
||
| 156 | $item['posttime'] = strtolower(XoopsLocale::ON) . ' ' . $itemObj->datesub(); |
||
| 157 | } |
||
| 158 | |||
| 159 | $item['topic_title'] = ''; |
||
| 160 | if ($options[21] == 1) { |
||
| 161 | $item['topic_title'] = $itemObj->getCategoryLink() . _MB_PUBLISHER_SP; |
||
| 162 | } |
||
| 163 | |||
| 164 | $item['read'] = ''; |
||
| 165 | if ($options[22] == 1) { |
||
| 166 | //todo, check this concatenation |
||
| 167 | $item['read'] = ' (' . $itemObj->getVar('counter') . ' ' . strtolower(XoopsLocale::READS) . ')'; |
||
| 168 | } |
||
| 169 | |||
| 170 | $item['more'] = ''; |
||
| 171 | if ($itemObj->body() != '' || $itemObj->getVar('comments') > 0) { |
||
| 172 | $item['more'] = '<a class="publisher_spotlight_readmore" href="' . $itemObj->getItemUrl() . '">' . _MB_PUBLISHER_READMORE . '</a>'; |
||
| 173 | } |
||
| 174 | |||
| 175 | $comments = $itemObj->getVar('comments'); |
||
| 176 | if ($options[23] == 1) { |
||
| 177 | if ($comments > 0) { |
||
| 178 | //shows 1 comment instead of 1 comm. if comments ==1 |
||
| 179 | //langugage file modified accordingly |
||
| 180 | if ($comments == 1) { |
||
| 181 | $item['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' '; |
||
| 182 | } else { |
||
| 183 | $item['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' '; |
||
| 184 | } |
||
| 185 | } else { |
||
| 186 | $item['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' '; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | $item['print'] = ''; |
||
| 191 | if ($options[24] == 1) { |
||
| 192 | $item['print'] = '<a href="' . PublisherUtils::seoGenUrl("print", $itemObj->getVar('itemid'), $itemObj->getVar('short_url')) . '" rel="nofollow"><img src="' . PUBLISHER_URL . '/images/links/print.gif" title="' . _CO_PUBLISHER_PRINT . '" alt="' . _CO_PUBLISHER_PRINT . '" /></a> '; |
||
| 193 | } |
||
| 194 | |||
| 195 | $item['pdf'] = ''; |
||
| 196 | if ($options[25] == 1) { |
||
| 197 | $item['pdf'] = "<a href='" . PUBLISHER_URL . "/makepdf.php?itemid=" . $itemObj->getVar('itemid'). "' rel='nofollow'><img src='" . PUBLISHER_URL . "/images/links/pdf.gif' title='" . _CO_PUBLISHER_PDF . "' alt='" . _CO_PUBLISHER_PDF . "' /></a> "; |
||
| 198 | } |
||
| 199 | |||
| 200 | $item['email'] = ''; |
||
| 201 | if ($options[26] == 1 && $xoops->isActiveModule('tellafriend')) { |
||
| 202 | $subject = sprintf(_CO_PUBLISHER_INTITEMFOUND, $xoops->getConfig('sitename')); |
||
| 203 | $subject = $itemObj->_convert_for_japanese($subject); |
||
| 204 | $maillink = PublisherUtils::tellafriend($subject); |
||
| 205 | |||
| 206 | $item['email'] = '<a href="' . $maillink . '"><img src="' . PUBLISHER_URL . '/images/links/friend.gif" title="' . _CO_PUBLISHER_MAIL . '" alt="' . _CO_PUBLISHER_MAIL . '" /></a> '; |
||
| 207 | } |
||
| 208 | |||
| 209 | $block['morelink'] = ''; |
||
| 210 | if ($options[27] == 1) { |
||
| 211 | $block['morelink'] = '<a href="' . PUBLISHER_URL . '/index.php">' . _MB_PUBLISHER_MORE_ITEMS . '</a> '; |
||
| 212 | } |
||
| 213 | |||
| 214 | $block['latestnews_scroll'] = false; |
||
| 215 | if ($options[5] == 1) { |
||
| 216 | $block['latestnews_scroll'] = true; |
||
| 217 | } |
||
| 218 | |||
| 219 | $block['scrollheight'] = $options[6]; |
||
| 220 | $block['scrollspeed'] = $options[7]; |
||
| 221 | $block['scrolldir'] = $options[8]; |
||
| 222 | |||
| 223 | $block['template'] = $options[28]; |
||
| 224 | |||
| 225 | $block['imgwidth'] = $options[11]; |
||
| 226 | $block['imgheight'] = $options[12]; |
||
| 227 | |||
| 228 | $block['letters'] = $letters; |
||
| 229 | |||
| 230 | $columns[$k][] = $item; |
||
| 231 | ++$k; |
||
| 232 | |||
| 233 | if ($k == $column_count) { |
||
| 234 | $k = 0; |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | unset($item); |
||
| 239 | $block['columns'] = $columns; |
||
| 240 | |||
| 241 | return $block; |
||
| 242 | } |
||
| 423 |