Conditions | 25 |
Paths | 24 |
Total Lines | 149 |
Code Lines | 106 |
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 declare(strict_types=1); |
||
33 | function publisher_items_new_show($options) |
||
34 | { |
||
35 | $helper = Helper::getInstance(); |
||
36 | /** @var ItemHandler $itemHandler */ |
||
37 | $itemHandler = $helper->getHandler('Item'); |
||
38 | |||
39 | $selectedcatids = explode(',', $options[0]); |
||
40 | |||
41 | $block = []; |
||
42 | $allcats = false; |
||
43 | if (in_array(0, $selectedcatids, true)) { |
||
44 | $allcats = true; |
||
45 | } |
||
46 | |||
47 | $sort = $options[1]; |
||
48 | $order = Utility::getOrderBy($sort); |
||
49 | $limit = $options[3]; |
||
50 | $start = 0; |
||
51 | $image = $options[5]; |
||
52 | |||
53 | // creating the ITEM objects that belong to the selected category |
||
54 | if ($allcats) { |
||
55 | $criteria = null; |
||
56 | } else { |
||
57 | $criteria = new \CriteriaCompo(); |
||
58 | $criteria->add(new \Criteria('categoryid', '(' . $options[0] . ')', 'IN')); |
||
59 | } |
||
60 | |||
61 | $publisherIsAdmin = $helper->isUserAdmin(); |
||
62 | if (!$publisherIsAdmin) { |
||
63 | if (null === $criteria) { |
||
64 | $criteria = new \CriteriaCompo(); |
||
65 | } |
||
66 | $criteriaDateSub = new \Criteria('datesub', time(), '<='); |
||
67 | $criteria->add($criteriaDateSub); |
||
68 | } |
||
69 | |||
70 | // $optCatItems = (int)$options[2]; |
||
71 | // $categoryid = -1; |
||
72 | // $categoryItemsObj = $itemHandler->getAllPublished($optCatItems, 0, $categoryid); |
||
73 | |||
74 | $itemsObj = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, 'none'); |
||
75 | |||
76 | $totalitems = count($itemsObj); |
||
77 | if ($totalitems > 0) { |
||
78 | foreach ($itemsObj as $iValue) { |
||
79 | $item = []; |
||
80 | $item['itemurl'] = $iValue->getItemUrl(); |
||
81 | $item['link'] = $iValue->getItemLink(false, $options[4] ?? 65); |
||
82 | $item['id'] = $iValue->itemid(); |
||
83 | $item['poster'] = $iValue->posterName(); // for make poster name linked, use getLinkedPosterName() instead of posterName() |
||
84 | $item['categorylink'] = $iValue->getCategoryLink(); |
||
85 | $item['date'] = $iValue->getDatesub(); |
||
86 | $item['hits'] = $iValue->counter(); |
||
87 | $item['summary'] = $iValue->getBlockSummary(300, true); //show complete summary but truncate to 300 if only body available |
||
88 | $item['rating'] = $iValue->rating(); |
||
89 | $item['votes'] = $iValue->votes(); |
||
90 | $item['lang_fullitem'] = _MB_PUBLISHER_FULLITEM; |
||
91 | $item['lang_poster'] = _MB_PUBLISHER_POSTEDBY; |
||
92 | $item['lang_date'] = _MB_PUBLISHER_ON; |
||
93 | $item['lang_category'] = _MB_PUBLISHER_CATEGORY; |
||
94 | $item['lang_hits'] = _MB_PUBLISHER_TOTALHITS; |
||
95 | $item['cancomment'] = $iValue->cancomment(); |
||
96 | $comments = $iValue->comments(); |
||
97 | if ($comments > 0) { |
||
98 | //shows 1 comment instead of 1 comm. if comments ==1 |
||
99 | //langugage file modified accordingly |
||
100 | if (1 == $comments) { |
||
101 | $item['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' '; |
||
102 | } else { |
||
103 | $item['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' '; |
||
104 | } |
||
105 | } else { |
||
106 | $item['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' '; |
||
107 | } |
||
108 | |||
109 | if ('article' === $image) { |
||
110 | $item['image'] = PUBLISHER_URL . '/assets/images/default_image.jpg'; |
||
111 | $item['image_name'] = ''; |
||
112 | $images = $iValue->getImages(); |
||
113 | |||
114 | if (empty($images['image_path'])) { |
||
115 | $images['image_path'] = PUBLISHER_URL . '/assets/images/default_image.jpg'; |
||
116 | } |
||
117 | if (is_object($images['main'])) { |
||
118 | // check to see if GD function exist |
||
119 | if (function_exists('imagecreatetruecolor')) { |
||
120 | $item['image'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name') . ''; |
||
121 | $item['image_path'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name') . ''; |
||
122 | } else { |
||
123 | $item['image'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name'); |
||
124 | } |
||
125 | $item['image_name'] = $images['main']->getVar('image_nicename'); |
||
126 | } |
||
127 | } elseif ('category' === $image) { |
||
128 | $item['image'] = $iValue->getCategoryImagePath(); |
||
129 | $item['image_name'] = $iValue->getCategoryName(); |
||
130 | } elseif ('avatar' === $image) { |
||
131 | if ('0' == $iValue->uid()) { |
||
132 | $item['image'] = XOOPS_URL . '/uploads/avatars/blank.gif'; |
||
133 | $images = $iValue->getImages(); |
||
134 | if (is_object($images['main'])) { |
||
135 | // check to see if GD function exist |
||
136 | if (function_exists('imagecreatetruecolor')) { |
||
137 | $item['image'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name') . '&w=50'; |
||
138 | } else { |
||
139 | $item['image'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name'); |
||
140 | } |
||
141 | } |
||
142 | // check to see if GD function exist |
||
143 | } elseif (function_exists('imagecreatetruecolor')) { |
||
144 | $item['image'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $iValue->posterAvatar() . '&w=50'; |
||
145 | } else { |
||
146 | $item['image'] = XOOPS_URL . '/uploads/' . $iValue->posterAvatar(); |
||
147 | } |
||
148 | |||
149 | $item['image_name'] = $iValue->posterName(); |
||
150 | } |
||
151 | |||
152 | $item['title'] = $iValue->getTitle(); |
||
153 | $item['alt'] = strip_tags($iValue->getItemLink()); |
||
154 | if ('datesub' === $sort) { |
||
155 | $item['new'] = $iValue->getDatesub(); |
||
156 | } elseif ('counter' === $sort) { |
||
157 | $item['new'] = $iValue->counter(); |
||
158 | } elseif ('weight' === $sort) { |
||
159 | $item['new'] = $iValue->weight(); |
||
160 | } elseif ('rating' === $sort) { |
||
161 | $item['new'] = $iValue->rating(); |
||
162 | } elseif ('votes' === $sort) { |
||
163 | $item['new'] = $iValue->votes(); |
||
164 | } elseif ('comments' === $sort) { |
||
165 | $item['new'] = $iValue->comments(); |
||
166 | } |
||
167 | |||
168 | $block['newitems'][] = $item; |
||
169 | } |
||
170 | } |
||
171 | |||
172 | $block['show_order'] = $options[2]; |
||
173 | $block['show_summary'] = $options[6]; |
||
174 | $block['show_poster'] = $options[7]; |
||
175 | $block['show_date'] = $options[8]; |
||
176 | $block['show_category'] = $options[9]; |
||
177 | $block['show_hits'] = $options[10]; |
||
178 | $block['show_comment'] = $options[11]; |
||
179 | $block['show_rating'] = $options[12]; |
||
180 | |||
181 | return $block; |
||
182 | } |
||
246 |