Conditions | 102 |
Paths | > 20000 |
Total Lines | 533 |
Code Lines | 398 |
Lines | 127 |
Ratio | 23.83 % |
Changes | 2 | ||
Bugs | 0 | 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 |
||
45 | function b_news_top_show($options) |
||
46 | { |
||
47 | global $xoopsConfig; |
||
48 | include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php'; |
||
49 | $myts = MyTextSanitizer::getInstance(); |
||
50 | $block = array(); |
||
51 | $displayname = news_getmoduleoption('displayname'); |
||
52 | $tabskin = news_getmoduleoption('tabskin'); |
||
53 | |||
54 | View Code Duplication | if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) { |
|
55 | include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php'; |
||
56 | } else { |
||
57 | include_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php'; |
||
58 | } |
||
59 | |||
60 | $block['displayview'] = $options[8]; |
||
61 | $block['tabskin'] = $tabskin; |
||
62 | $block['imagesurl'] = XOOPS_URL . '/modules/news/assets/images/'; |
||
63 | |||
64 | $restricted = news_getmoduleoption('restrictindex'); |
||
65 | $dateformat = news_getmoduleoption('dateformat'); |
||
66 | $infotips = news_getmoduleoption('infotips'); |
||
67 | $newsrating = news_getmoduleoption('ratenews'); |
||
68 | if ($dateformat == '') { |
||
69 | $dateformat = 's'; |
||
70 | } |
||
71 | |||
72 | $perm_verified = false; |
||
73 | $news_visible = true; |
||
74 | // Is the spotlight visible ? |
||
75 | if ($options[4] == 1 && $restricted && $options[5] == 0) { |
||
76 | $perm_verified = true; |
||
77 | $permittedtopics = news_MygetItemIds(); |
||
78 | $permstory = new NewsStory($options[6]); |
||
79 | if (!in_array($permstory->topicid(), $permittedtopics)) { |
||
80 | $usespotlight = false; |
||
81 | $news_visible = false; |
||
82 | $topicstitles = array(); |
||
83 | } |
||
84 | $options[4] == 0; |
||
85 | } |
||
86 | // Try to see what tabs are visibles (if we are in restricted view of course) |
||
87 | if ($options[8] == 2 && $restricted && $options[14] != 0) { |
||
88 | $topics2 = array(); |
||
89 | $permittedtopics = news_MygetItemIds(); |
||
90 | $topics = array_slice($options, 14); |
||
91 | foreach ($topics as $onetopic) { |
||
92 | if (in_array($onetopic, $permittedtopics)) { |
||
93 | $topics2[] = $onetopic; |
||
94 | } |
||
95 | } |
||
96 | $before = array_slice($options, 0, 14); |
||
97 | $options = array_merge($before, $topics2); |
||
98 | } |
||
99 | |||
100 | if ($options[8] == 2) { // Tabbed view ******************************************************************************************** |
||
101 | $defcolors[1] = array('#F90', '#FFFFFF', '#F90', '#C60', '#999'); // Bar Style |
||
102 | $defcolors[2] = array('#F90', '#FFFFFF', '#F90', '#AAA', '#666'); // Beveled |
||
103 | $defcolors[3] = array('#F90', '#FFFFFF', '', '#789', '#789'); // Classic |
||
104 | $defcolors[4] = array('#F90', '#FFFFFF', '', '', ''); // Folders |
||
105 | $defcolors[5] = array('#F90', '#FFFFFF', '#CCC', 'inherit', '#999'); // MacOs |
||
106 | $defcolors[6] = array('#F90', '#FFFFFF', '#FFF', '#DDD', '#999'); // Plain |
||
107 | $defcolors[7] = array('#F90', '#FFFFFF', '', '', ''); // Rounded |
||
108 | $defcolors[8] = array('#F90', '#FFFFFF', '#F90', '#930', '#C60'); // ZDnet |
||
109 | |||
110 | $myurl = $_SERVER['PHP_SELF']; |
||
111 | if (substr($myurl, strlen($myurl) - 1, 1) === '/') { |
||
112 | $myurl .= 'index.php'; |
||
113 | } |
||
114 | $myurl .= '?'; |
||
115 | |||
116 | foreach ($_GET as $key => $value) { |
||
117 | if ($key !== 'NewsTab') { |
||
118 | $myurl .= $key . '=' . $value . '&'; |
||
119 | } |
||
120 | } |
||
121 | $block['url'] = $myurl; |
||
122 | |||
123 | $tabscount = 0; |
||
124 | $usespotlight = false; |
||
125 | |||
126 | if (isset($_GET['NewsTab'])) { |
||
127 | $_SESSION['NewsTab'] = (int)$_GET['NewsTab']; |
||
128 | $currenttab = (int)$_GET['NewsTab']; |
||
129 | } elseif (isset($_SESSION['NewsTab'])) { |
||
130 | $currenttab = (int)$_SESSION['NewsTab']; |
||
131 | } else { |
||
132 | $currenttab = 0; |
||
133 | } |
||
134 | |||
135 | $tmpstory = new NewsStory(); |
||
136 | $topic = new NewsTopic(); |
||
137 | $topicstitles = array(); |
||
138 | if ($options[4] == 1) { // Spotlight enabled |
||
139 | $topicstitles[0] = _MB_NEWS_SPOTLIGHT_TITLE; |
||
140 | ++$tabscount; |
||
141 | $usespotlight = true; |
||
142 | } |
||
143 | |||
144 | if ($options[5] == 0 && $restricted) { // Use a specific news and we are in restricted mode |
||
145 | if (!$perm_verified) { |
||
146 | $permittedtopics = news_MygetItemIds(); |
||
147 | $permstory = new NewsStory($options[6]); |
||
148 | if (!in_array($permstory->topicid(), $permittedtopics)) { |
||
149 | $usespotlight = false; |
||
150 | $topicstitles = array(); |
||
151 | } |
||
152 | //unset($permstory); |
||
153 | } else { |
||
154 | if (!$news_visible) { |
||
155 | $usespotlight = false; |
||
156 | $topicstitles = array(); |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | $block['use_spotlight'] = $usespotlight; |
||
162 | |||
163 | if (isset($options[14]) && $options[14] != 0) { // Topic to use |
||
164 | $topics = array_slice($options, 14); |
||
165 | $tabscount += count($topics); |
||
166 | $topicstitles = $topic->getTopicTitleFromId($topics, $topicstitles); |
||
167 | } |
||
168 | $tabs = array(); |
||
169 | if ($usespotlight) { |
||
170 | $tabs[] = array('id' => 0, 'title' => _MB_NEWS_SPOTLIGHT_TITLE); |
||
171 | } |
||
172 | if (count($topics) > 0) { |
||
173 | foreach ($topics as $onetopic) { |
||
174 | if (isset($topicstitles[$onetopic])) { |
||
175 | $tabs[] = array('id' => $onetopic, 'title' => $topicstitles[$onetopic]['title'], 'picture' => $topicstitles[$onetopic]['picture']); |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | $block['tabs'] = $tabs; |
||
180 | $block['current_is_spotlight'] = false; |
||
181 | $block['current_tab'] = $currenttab; |
||
182 | $block['use_rating'] = $newsrating; |
||
183 | |||
184 | if ($currenttab == 0 && $usespotlight) { // Spotlight or not ? |
||
185 | $block['current_is_spotlight'] = true; |
||
186 | if ($options[5] == 0 && $options[6] == 0) { // If the story to use was no selected then we switch to the "recent news" mode. |
||
187 | $options[5] = 1; |
||
188 | } |
||
189 | |||
190 | if ($options[5] == 0) { // Use a specific news |
||
191 | if (!isset($permstory)) { |
||
192 | $tmpstory->NewsStory($options[6]); |
||
193 | } else { |
||
194 | $tmpstory = $permstory; |
||
195 | } |
||
196 | View Code Duplication | } else { // Use the most recent news |
|
197 | $stories = array(); |
||
198 | $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]); |
||
199 | if (count($stories) > 0) { |
||
200 | $firststory = $stories[0]; |
||
201 | $tmpstory->NewsStory($firststory->storyid()); |
||
202 | } else { |
||
203 | $block['use_spotlight'] = false; |
||
204 | } |
||
205 | } |
||
206 | $spotlight = array(); |
||
207 | $spotlight['title'] = $tmpstory->title(); |
||
208 | View Code Duplication | if ($options[7] !== '') { |
|
209 | $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), $myts->displayTarea($options[7], $tmpstory->nohtml)); |
||
210 | } |
||
211 | $spotlight['text'] = $tmpstory->hometext(); |
||
212 | |||
213 | // Added 16 february 2007 ***************************************** |
||
214 | $story_user = null; |
||
215 | $story_user = new XoopsUser($tmpstory->uid()); |
||
216 | View Code Duplication | if (is_object($story_user)) { |
|
217 | $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar'); |
||
218 | } |
||
219 | // **************************************************************** |
||
220 | $spotlight['id'] = $tmpstory->storyid(); |
||
221 | $spotlight['date'] = formatTimestamp($tmpstory->published(), $dateformat); |
||
222 | $spotlight['hits'] = $tmpstory->counter(); |
||
223 | $spotlight['rating'] = number_format($tmpstory->rating(), 2); |
||
224 | $spotlight['votes'] = $tmpstory->votes(); |
||
225 | View Code Duplication | if (strlen(xoops_trim($tmpstory->bodytext())) > 0) { |
|
226 | $spotlight['read_more'] = true; |
||
227 | } else { |
||
228 | $spotlight['read_more'] = false; |
||
229 | } |
||
230 | |||
231 | $spotlight['readmore'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), _MB_READMORE); |
||
232 | $spotlight['title_with_link'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), $tmpstory->title()); |
||
233 | View Code Duplication | if ($tmpstory->votes() == 1) { |
|
234 | $spotlight['number_votes'] = _NW_ONEVOTE; |
||
235 | } else { |
||
236 | $spotlight['number_votes'] = sprintf(_NW_NUMVOTES, $tmpstory->votes()); |
||
237 | } |
||
238 | |||
239 | $spotlight['votes_with_text'] = sprintf(_NW_NUMVOTES, $tmpstory->votes()); |
||
240 | $spotlight['topicid'] = $tmpstory->topicid(); |
||
241 | $spotlight['topic_title'] = $tmpstory->topic_title(); |
||
242 | // Added, topic's image and description |
||
243 | $spotlight['topic_image'] = XOOPS_URL . '/modules/news/assets/images/topics/' . $tmpstory->topic_imgurl(); |
||
244 | $spotlight['topic_description'] = $myts->displayTarea($tmpstory->topic_description, 1); |
||
245 | |||
246 | if ($displayname != 3) { |
||
247 | $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $tmpstory->uname()); |
||
248 | $spotlight['author_with_link'] = sprintf("%s <a href='%s'>%s</a>", _POSTEDBY, XOOPS_URL . '/userinfo.php?uid=' . $tmpstory->uid(), $tmpstory->uname()); |
||
249 | } else { |
||
250 | $spotlight['author'] = ''; |
||
251 | $spotlight['author_with_link'] = ''; |
||
252 | } |
||
253 | $spotlight['author_id'] = $tmpstory->uid(); |
||
254 | |||
255 | // Create the summary table under the spotlight text |
||
256 | View Code Duplication | if (isset($options[14]) && $options[14] == 0) { // Use all topics |
|
257 | $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]); |
||
258 | } else { // Use some topics |
||
259 | $topics = array_slice($options, 14); |
||
260 | $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]); |
||
261 | } |
||
262 | if (count($stories) > 0) { |
||
263 | foreach ($stories as $key => $story) { |
||
264 | $news = array(); |
||
265 | $title = $story->title(); |
||
266 | View Code Duplication | if (strlen($title) > $options[2]) { |
|
267 | $title = xoops_substr($title, 0, $options[2] + 3); |
||
268 | } |
||
269 | $news['title'] = $title; |
||
270 | $news['id'] = $story->storyid(); |
||
271 | $news['date'] = formatTimestamp($story->published(), $dateformat); |
||
272 | $news['hits'] = $story->counter(); |
||
273 | $news['rating'] = number_format($story->rating(), 2); |
||
274 | $news['votes'] = $story->votes(); |
||
275 | $news['topicid'] = $story->topicid(); |
||
276 | $news['topic_title'] = $story->topic_title(); |
||
277 | $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
278 | $news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
||
279 | $news['pictureinfo'] = $story->pictureinfo(); |
||
280 | View Code Duplication | if ($displayname != 3) { |
|
281 | $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
282 | } else { |
||
283 | $news['author'] = ''; |
||
284 | } |
||
285 | View Code Duplication | if ($options[3] > 0) { |
|
286 | $html = $story->nohtml() == 1 ? 0 : 1; |
||
287 | $news['teaser'] = news_truncate_tagsafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3); |
||
288 | } else { |
||
289 | $news['teaser'] = ''; |
||
290 | } |
||
291 | if ($infotips > 0) { |
||
292 | $news['infotips'] = ' title="' . news_make_infotips($story->hometext()) . '"'; |
||
293 | } else { |
||
294 | $news['infotips'] = ''; |
||
295 | } |
||
296 | |||
297 | $news['title_with_link'] = sprintf("<a href='%s'%s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title); |
||
298 | $spotlight['news'][] = $news; |
||
299 | } |
||
300 | } |
||
301 | |||
302 | $block['spotlight'] = $spotlight; |
||
303 | } else { |
||
304 | if ($tabscount > 0) { |
||
305 | $topics = array_slice($options, 14); |
||
306 | $thetopic = $currenttab; |
||
307 | $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $thetopic, 1, true, $options[0]); |
||
308 | |||
309 | $topic->getTopic($thetopic); |
||
310 | // Added, topic's image and description |
||
311 | $block['topic_image'] = XOOPS_URL . '/modules/news/assets/images/topics/' . $topic->topic_imgurl(); |
||
312 | $block['topic_description'] = $topic->topic_description(); |
||
313 | |||
314 | $smallheader = array(); |
||
315 | $stats = $topic->getTopicMiniStats($thetopic); |
||
316 | $smallheader[] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/index.php?storytopic=' . $thetopic, _MB_READMORE); |
||
317 | $smallheader[] = sprintf('%u %s', $stats['count'], _NW_ARTICLES); |
||
318 | $smallheader[] = sprintf('%u %s', $stats['reads'], _READS); |
||
319 | if (count($stories) > 0) { |
||
320 | foreach ($stories as $key => $story) { |
||
321 | $news = array(); |
||
322 | $title = $story->title(); |
||
323 | if (strlen($title) > $options[2]) { |
||
324 | $title = news_truncate_tagsafe($title, $options[2] + 3); |
||
325 | } |
||
326 | View Code Duplication | if ($options[7] !== '') { |
|
327 | $news['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $myts->displayTarea($options[7], $story->nohtml)); |
||
328 | } |
||
329 | View Code Duplication | if ($options[3] > 0) { |
|
330 | $html = $story->nohtml() == 1 ? 0 : 1; |
||
331 | $news['text'] = news_truncate_tagsafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3); |
||
332 | } else { |
||
333 | $news['text'] = ''; |
||
334 | } |
||
335 | |||
336 | View Code Duplication | if ($story->votes() == 1) { |
|
337 | $news['number_votes'] = _NW_ONEVOTE; |
||
338 | } else { |
||
339 | $news['number_votes'] = sprintf(_NW_NUMVOTES, $story->votes()); |
||
340 | } |
||
341 | if ($infotips > 0) { |
||
342 | $news['infotips'] = ' title="' . news_make_infotips($story->hometext()) . '"'; |
||
343 | } else { |
||
344 | $news['infotips'] = ''; |
||
345 | } |
||
346 | $news['title'] = sprintf("<a href='%s' %s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title); |
||
347 | $news['id'] = $story->storyid(); |
||
348 | $news['date'] = formatTimestamp($story->published(), $dateformat); |
||
349 | $news['hits'] = $story->counter(); |
||
350 | $news['rating'] = number_format($story->rating(), 2); |
||
351 | $news['votes'] = $story->votes(); |
||
352 | $news['topicid'] = $story->topicid(); |
||
353 | $news['topic_title'] = $story->topic_title(); |
||
354 | $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
355 | $news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
||
356 | $news['pictureinfo'] = $story->pictureinfo(); |
||
357 | |||
358 | View Code Duplication | if ($displayname != 3) { |
|
359 | $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
360 | } else { |
||
361 | $news['author'] = ''; |
||
362 | } |
||
363 | $news['title_with_link'] = sprintf("<a href='%s'%s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title); |
||
364 | $block['news'][] = $news; |
||
365 | } |
||
366 | $block['smallheader'] = $smallheader; |
||
367 | } |
||
368 | } |
||
369 | } |
||
370 | $block['lang_on'] = _ON; // on |
||
371 | $block['lang_reads'] = _READS; // reads |
||
372 | // Default values |
||
373 | $block['color1'] = $defcolors[$tabskin][0]; |
||
374 | $block['color2'] = $defcolors[$tabskin][1]; |
||
375 | $block['color3'] = $defcolors[$tabskin][2]; |
||
376 | $block['color4'] = $defcolors[$tabskin][3]; |
||
377 | $block['color5'] = $defcolors[$tabskin][4]; |
||
378 | |||
379 | if (xoops_trim($options[9]) !== '') { |
||
380 | $block['color1'] = $options[9]; |
||
381 | } |
||
382 | if (xoops_trim($options[10]) !== '') { |
||
383 | $block['color2'] = $options[10]; |
||
384 | } |
||
385 | if (xoops_trim($options[11]) !== '') { |
||
386 | $block['color3'] = $options[11]; |
||
387 | } |
||
388 | if (xoops_trim($options[12]) !== '') { |
||
389 | $block['color4'] = $options[12]; |
||
390 | } |
||
391 | if (xoops_trim($options[13]) !== '') { |
||
392 | $block['color5'] = $options[13]; |
||
393 | } |
||
394 | } else { // ************************ Classical view ************************************************************************************************************** |
||
395 | $tmpstory = new NewsStory; |
||
396 | View Code Duplication | if (isset($options[14]) && $options[14] == 0) { |
|
397 | $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]); |
||
398 | } else { |
||
399 | $topics = array_slice($options, 14); |
||
400 | $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]); |
||
401 | } |
||
402 | |||
403 | if (!count($stories)) { |
||
404 | return ''; |
||
405 | } |
||
406 | $topic = new NewsTopic(); |
||
407 | |||
408 | foreach ($stories as $key => $story) { |
||
409 | $news = array(); |
||
410 | $title = $story->title(); |
||
411 | View Code Duplication | if (strlen($title) > $options[2]) { |
|
412 | $title = xoops_substr($title, 0, $options[2] + 3); |
||
413 | } |
||
414 | |||
415 | //if spotlight is enabled and this is either the first article or the selected one |
||
416 | if (($options[5] == 0) && ($options[4] == 1) && (($options[6] > 0 && $options[6] == $story->storyid()) || ($options[6] == 0 && $key == 0))) { |
||
417 | $spotlight = array(); |
||
418 | $visible = true; |
||
419 | if ($restricted) { |
||
420 | $permittedtopics = news_MygetItemIds(); |
||
421 | if (!in_array($story->topicid(), $permittedtopics)) { |
||
422 | $visible = false; |
||
423 | } |
||
424 | } |
||
425 | |||
426 | if ($visible) { |
||
427 | $spotlight['title'] = $title; |
||
428 | View Code Duplication | if ($options[7] !== '') { |
|
429 | $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $myts->displayTarea($options[7], $story->nohtml)); |
||
430 | } |
||
431 | // Added 16 february 2007 ***************************************** |
||
432 | $story_user = null; |
||
433 | $story_user = new XoopsUser($story->uid()); |
||
434 | View Code Duplication | if (is_object($story_user)) { |
|
435 | $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar'); |
||
436 | } |
||
437 | // **************************************************************** |
||
438 | $spotlight['text'] = $story->hometext(); |
||
439 | $spotlight['id'] = $story->storyid(); |
||
440 | $spotlight['date'] = formatTimestamp($story->published(), $dateformat); |
||
441 | $spotlight['hits'] = $story->counter(); |
||
442 | $spotlight['rating'] = $story->rating(); |
||
443 | $spotlight['votes'] = $story->votes(); |
||
444 | $spotlight['topicid'] = $story->topicid(); |
||
445 | $spotlight['topic_title'] = $story->topic_title(); |
||
446 | $spotlight['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
447 | // Added, topic's image and description |
||
448 | $spotlight['topic_image'] = XOOPS_URL . '/modules/news/assets/images/topics/' . $story->topic_imgurl(); |
||
449 | $spotlight['topic_description'] = $myts->displayTarea($story->topic_description, 1); |
||
450 | View Code Duplication | if (strlen(xoops_trim($story->bodytext())) > 0) { |
|
451 | $spotlight['read_more'] = true; |
||
452 | } else { |
||
453 | $spotlight['read_more'] = false; |
||
454 | } |
||
455 | |||
456 | View Code Duplication | if ($displayname != 3) { |
|
457 | $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
458 | } else { |
||
459 | $spotlight['author'] = ''; |
||
460 | } |
||
461 | } |
||
462 | $block['spotlight'] = $spotlight; |
||
463 | } else { |
||
464 | $news['title'] = $title; |
||
465 | $news['id'] = $story->storyid(); |
||
466 | $news['date'] = formatTimestamp($story->published(), $dateformat); |
||
467 | $news['hits'] = $story->counter(); |
||
468 | $news['rating'] = $story->rating(); |
||
469 | $news['votes'] = $story->votes(); |
||
470 | $news['topicid'] = $story->topicid(); |
||
471 | $news['topic_title'] = $story->topic_title(); |
||
472 | $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
473 | $news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
||
474 | $news['pictureinfo'] = $story->pictureinfo(); |
||
475 | |||
476 | View Code Duplication | if ($displayname != 3) { |
|
477 | $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
478 | } else { |
||
479 | $news['author'] = ''; |
||
480 | } |
||
481 | if ($options[3] > 0) { |
||
482 | $html = $story->nohtml() == 1 ? 0 : 1; |
||
483 | $news['teaser'] = news_truncate_tagsafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3); |
||
484 | $news['infotips'] = ''; |
||
485 | } else { |
||
486 | $news['teaser'] = ''; |
||
487 | if ($infotips > 0) { |
||
488 | $news['infotips'] = ' title="' . news_make_infotips($story->hometext()) . '"'; |
||
489 | } else { |
||
490 | $news['infotips'] = ''; |
||
491 | } |
||
492 | } |
||
493 | $block['stories'][] = $news; |
||
494 | } |
||
495 | } |
||
496 | |||
497 | // If spotlight article was not in the fetched stories |
||
498 | if (!isset($spotlight) && $options[4]) { |
||
499 | $block['use_spotlight'] = true; |
||
500 | $visible = true; |
||
501 | if ($options[5] == 0 && $restricted) { // Use a specific news and we are in restricted mode |
||
502 | $permittedtopics = news_MygetItemIds(); |
||
503 | $permstory = new NewsStory($options[6]); |
||
504 | if (!in_array($permstory->topicid(), $permittedtopics)) { |
||
505 | $visible = false; |
||
506 | } |
||
507 | unset($permstory); |
||
508 | } |
||
509 | |||
510 | if ($options[5] == 0) { // Use a specific news |
||
511 | if ($visible) { |
||
512 | $spotlightArticle = new NewsStory($options[6]); |
||
513 | } else { |
||
514 | $block['use_spotlight'] = false; |
||
515 | } |
||
516 | View Code Duplication | } else { // Use the most recent news |
|
517 | $stories = array(); |
||
518 | $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]); |
||
519 | if (count($stories) > 0) { |
||
520 | $firststory = $stories[0]; |
||
521 | $spotlightArticle = new NewsStory($firststory->storyid()); |
||
522 | } else { |
||
523 | $block['use_spotlight'] = false; |
||
524 | } |
||
525 | } |
||
526 | if ($block['use_spotlight'] == true) { |
||
527 | $spotlight = array(); |
||
528 | $spotlight['title'] = xoops_substr($spotlightArticle->title(), 0, $options[2] - 1); |
||
529 | View Code Duplication | if ($options[7] !== '') { |
|
530 | $spotlight['image'] = |
||
531 | sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $spotlightArticle->storyid(), $myts->displayTarea($options[7], $spotlightArticle->nohtml)); |
||
532 | } |
||
533 | // Added 16 february 2007 ***************************************** |
||
534 | $story_user = null; |
||
535 | $story_user = new XoopsUser($spotlightArticle->uid()); |
||
536 | View Code Duplication | if (is_object($story_user)) { |
|
537 | $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar'); |
||
538 | } |
||
539 | // **************************************************************** |
||
540 | $spotlight['topicid'] = $spotlightArticle->topicid(); |
||
541 | $spotlight['topic_title'] = $spotlightArticle->topic_title(); |
||
542 | $spotlight['topic_color'] = '#' . $myts->displayTarea($spotlightArticle->topic_color); |
||
543 | $spotlight['text'] = $spotlightArticle->hometext(); |
||
544 | $spotlight['id'] = $spotlightArticle->storyid(); |
||
545 | $spotlight['date'] = formatTimestamp($spotlightArticle->published(), $dateformat); |
||
546 | $spotlight['hits'] = $spotlightArticle->counter(); |
||
547 | $spotlight['rating'] = $spotlightArticle->rating(); |
||
548 | $spotlight['votes'] = $spotlightArticle->votes(); |
||
549 | // Added, topic's image and description |
||
550 | $spotlight['topic_image'] = XOOPS_URL . '/modules/news/assets/images/topics/' . $spotlightArticle->topic_imgurl(); |
||
551 | $spotlight['topic_description'] = $myts->displayTarea($spotlightArticle->topic_description, 1); |
||
552 | View Code Duplication | if ($displayname != 3) { |
|
553 | $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $spotlightArticle->uname()); |
||
554 | } else { |
||
555 | $spotlight['author'] = ''; |
||
556 | } |
||
557 | View Code Duplication | if (strlen(xoops_trim($spotlightArticle->bodytext())) > 0) { |
|
558 | $spotlight['read_more'] = true; |
||
559 | } else { |
||
560 | $spotlight['read_more'] = false; |
||
561 | } |
||
562 | $block['spotlight'] = $spotlight; |
||
563 | } |
||
564 | } |
||
565 | } |
||
566 | if (isset($permstory)) { |
||
567 | unset($permstory); |
||
568 | } |
||
569 | $block['lang_read_more'] = $myts->htmlSpecialChars(_MB_READMORE); // Read More... |
||
570 | $block['lang_orderby'] = $myts->htmlSpecialChars(_MB_NEWS_ORDER); // "Order By" |
||
571 | $block['lang_orderby_date'] = $myts->htmlSpecialChars(_MB_NEWS_DATE); // Published date |
||
572 | $block['lang_orderby_hits'] = $myts->htmlSpecialChars(_MB_NEWS_HITS); // Number of Hits |
||
573 | $block['lang_orderby_rating'] = $myts->htmlSpecialChars(_MB_NEWS_RATE); // Rating |
||
574 | $block['sort'] = $options[0]; // "published" or "counter" or "rating" |
||
575 | |||
576 | return $block; |
||
577 | } |
||
578 | |||
711 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.