| Conditions | 101 |
| Paths | > 20000 |
| Total Lines | 534 |
| Code Lines | 397 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 declare(strict_types=1); |
||
| 44 | function b_news_top_show($options) |
||
| 45 | { |
||
| 46 | global $xoopsConfig; |
||
| 47 | |||
| 48 | /** @var Helper $helper */ |
||
| 49 | if (!class_exists(Helper::class)) { |
||
| 50 | return false; |
||
| 51 | } |
||
| 52 | |||
| 53 | $helper = Helper::getInstance(); |
||
| 54 | |||
| 55 | $helper->loadLanguage('main'); |
||
| 56 | |||
| 57 | $myts = \MyTextSanitizer::getInstance(); |
||
| 58 | $block = []; |
||
| 59 | $displayname = Utility::getModuleOption('displayname'); |
||
| 60 | $tabskin = Utility::getModuleOption('tabskin'); |
||
| 61 | |||
| 62 | $block['displayview'] = $options[8]; |
||
| 63 | $block['tabskin'] = $tabskin; |
||
| 64 | $block['imagesurl'] = XOOPS_URL . '/modules/news/assets/images/'; |
||
| 65 | |||
| 66 | $restricted = Utility::getModuleOption('restrictindex'); |
||
| 67 | $dateformat = Utility::getModuleOption('dateformat'); |
||
| 68 | $infotips = Utility::getModuleOption('infotips'); |
||
| 69 | $newsrating = Utility::getModuleOption('ratenews'); |
||
| 70 | if ('' == $dateformat) { |
||
| 71 | $dateformat = 's'; |
||
| 72 | } |
||
| 73 | |||
| 74 | $perm_verified = false; |
||
| 75 | $news_visible = true; |
||
| 76 | // Is the spotlight visible ? |
||
| 77 | if (1 == $options[4] && $restricted && 0 == $options[5]) { |
||
| 78 | $perm_verified = true; |
||
| 79 | $permittedtopics = Utility::getMyItemIds(); |
||
| 80 | $permstory = new NewsStory($options[6]); |
||
| 81 | if (!in_array($permstory->topicid(), $permittedtopics, true)) { |
||
| 82 | $usespotlight = false; |
||
| 83 | $news_visible = false; |
||
| 84 | $topicstitles = []; |
||
| 85 | } |
||
| 86 | 0 == $options[4]; |
||
| 87 | } |
||
| 88 | // Try to see what tabs are visibles (if we are in restricted view of course) |
||
| 89 | if (2 == $options[8] && $restricted && 0 != $options[14]) { |
||
| 90 | $topics2 = []; |
||
| 91 | $permittedtopics = Utility::getMyItemIds(); |
||
| 92 | $topics = array_slice($options, 14); |
||
| 93 | foreach ($topics as $onetopic) { |
||
| 94 | if (in_array($onetopic, $permittedtopics, true)) { |
||
| 95 | $topics2[] = $onetopic; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | $before = array_slice($options, 0, 14); |
||
| 99 | $options = array_merge($before, $topics2); |
||
| 100 | } |
||
| 101 | |||
| 102 | if (2 == $options[8]) { // Tabbed view ******************************************************************************************** |
||
| 103 | $defcolors[1] = ['#F90', '#FFFFFF', '#F90', '#C60', '#999']; // Bar Style |
||
| 104 | $defcolors[2] = ['#F90', '#FFFFFF', '#F90', '#AAA', '#666']; // Beveled |
||
| 105 | $defcolors[3] = ['#F90', '#FFFFFF', '', '#789', '#789']; // Classic |
||
| 106 | $defcolors[4] = ['#F90', '#FFFFFF', '', '', '']; // Folders |
||
| 107 | $defcolors[5] = ['#F90', '#FFFFFF', '#CCC', 'inherit', '#999']; // MacOs |
||
| 108 | $defcolors[6] = ['#F90', '#FFFFFF', '#FFF', '#DDD', '#999']; // Plain |
||
| 109 | $defcolors[7] = ['#F90', '#FFFFFF', '', '', '']; // Rounded |
||
| 110 | $defcolors[8] = ['#F90', '#FFFFFF', '#F90', '#930', '#C60']; // ZDnet |
||
| 111 | |||
| 112 | $myurl = $_SERVER['SCRIPT_NAME']; |
||
| 113 | if ('/' === mb_substr($myurl, mb_strlen($myurl) - 1, 1)) { |
||
| 114 | $myurl .= 'index.php'; |
||
| 115 | } |
||
| 116 | $myurl .= '?'; |
||
| 117 | |||
| 118 | foreach ($_GET as $key => $value) { |
||
| 119 | if ('NewsTab' !== $key) { |
||
| 120 | $myurl .= $key . '=' . $value . '&'; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | $block['url'] = $myurl; |
||
| 124 | |||
| 125 | $tabscount = 0; |
||
| 126 | $usespotlight = false; |
||
| 127 | |||
| 128 | if (Request::hasVar('NewsTab', 'GET')) { |
||
| 129 | $_SESSION['NewsTab'] = Request::getInt('NewsTab', 0, 'GET'); |
||
| 130 | $currenttab = Request::getInt('NewsTab', 0, 'GET'); |
||
| 131 | } elseif (Request::hasVar('NewsTab', 'SESSION')) { |
||
| 132 | $currenttab = Request::getInt('NewsTab', 0, 'SESSION'); |
||
| 133 | } else { |
||
| 134 | $currenttab = 0; |
||
| 135 | } |
||
| 136 | |||
| 137 | $tmpstory = new NewsStory(); |
||
| 138 | $topic = new NewsTopic(); |
||
| 139 | $topics = []; |
||
| 140 | $topicstitles = []; |
||
| 141 | if (1 == $options[4]) { // Spotlight enabled |
||
| 142 | $topicstitles[0] = _MB_NEWS_SPOTLIGHT_TITLE; |
||
| 143 | ++$tabscount; |
||
| 144 | $usespotlight = true; |
||
| 145 | } |
||
| 146 | |||
| 147 | if (0 == $options[5] && $restricted) { // Use a specific news and we are in restricted mode |
||
| 148 | if (!$perm_verified) { |
||
| 149 | $permittedtopics = Utility::getMyItemIds(); |
||
| 150 | $permstory = new NewsStory($options[6]); |
||
| 151 | if (!in_array($permstory->topicid(), $permittedtopics, true)) { |
||
| 152 | $usespotlight = false; |
||
| 153 | $topicstitles = []; |
||
| 154 | } |
||
| 155 | //unset($permstory); |
||
| 156 | } elseif (!$news_visible) { |
||
| 157 | $usespotlight = false; |
||
| 158 | $topicstitles = []; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | $block['use_spotlight'] = $usespotlight; |
||
| 163 | |||
| 164 | if (isset($options[14]) && 0 != $options[14]) { // Topic to use |
||
| 165 | $topics = array_slice($options, 14); |
||
| 166 | $tabscount += count($topics); |
||
| 167 | $topicstitles = $topic->getTopicTitleFromId($topics, $topicstitles); |
||
| 168 | } |
||
| 169 | $tabs = []; |
||
| 170 | if ($usespotlight) { |
||
| 171 | $tabs[] = ['id' => 0, 'title' => _MB_NEWS_SPOTLIGHT_TITLE]; |
||
| 172 | } |
||
| 173 | if (count($topics) > 0) { |
||
| 174 | foreach ($topics as $onetopic) { |
||
| 175 | if (isset($topicstitles[$onetopic])) { |
||
| 176 | $tabs[] = [ |
||
| 177 | 'id' => $onetopic, |
||
| 178 | 'title' => $topicstitles[$onetopic]['title'], |
||
| 179 | 'picture' => $topicstitles[$onetopic]['picture'], |
||
| 180 | ]; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | } |
||
| 184 | $block['tabs'] = $tabs; |
||
| 185 | $block['current_is_spotlight'] = false; |
||
| 186 | $block['current_tab'] = $currenttab; |
||
| 187 | $block['use_rating'] = $newsrating; |
||
| 188 | |||
| 189 | if (0 == $currenttab && $usespotlight) { // Spotlight or not ? |
||
| 190 | $block['current_is_spotlight'] = true; |
||
| 191 | if (0 == $options[5] |
||
| 192 | && 0 == $options[6]) { // If the story to use was no selected then we switch to the "recent news" mode. |
||
| 193 | $options[5] = 1; |
||
| 194 | } |
||
| 195 | |||
| 196 | if (0 == $options[5]) { // Use a specific news |
||
| 197 | $tmpstory = $permstory ?? new NewsStory($options[6]); |
||
| 198 | } else { // Use the most recent news |
||
| 199 | $stories = []; |
||
| 200 | $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]); |
||
| 201 | if (count($stories) > 0) { |
||
| 202 | $firststory = $stories[0]; |
||
| 203 | $tmpstory = new NewsStory($firststory->storyid()); |
||
| 204 | } else { |
||
| 205 | $block['use_spotlight'] = false; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | $spotlight = []; |
||
| 209 | $spotlight['title'] = $tmpstory->title(); |
||
| 210 | if ('' !== $options[7]) { |
||
| 211 | $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), $myts->displayTarea($options[7], $tmpstory->nohtml)); |
||
| 212 | } |
||
| 213 | $spotlight['text'] = $tmpstory->hometext(); |
||
| 214 | |||
| 215 | // Added 16 february 2007 ***************************************** |
||
| 216 | $story_user = null; |
||
| 217 | $story_user = new \XoopsUser($tmpstory->uid()); |
||
| 218 | if (is_object($story_user)) { |
||
| 219 | $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar'); |
||
| 220 | } |
||
| 221 | // **************************************************************** |
||
| 222 | $spotlight['id'] = $tmpstory->storyid(); |
||
| 223 | $spotlight['date'] = formatTimestamp($tmpstory->published(), $dateformat); |
||
| 224 | $spotlight['hits'] = $tmpstory->counter(); |
||
| 225 | $spotlight['rating'] = number_format($tmpstory->rating(), 2); |
||
| 226 | $spotlight['votes'] = $tmpstory->votes(); |
||
| 227 | if ('' !== xoops_trim($tmpstory->bodytext())) { |
||
| 228 | $spotlight['read_more'] = true; |
||
| 229 | } else { |
||
| 230 | $spotlight['read_more'] = false; |
||
| 231 | } |
||
| 232 | |||
| 233 | $spotlight['readmore'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), _MB_READMORE); |
||
| 234 | $spotlight['title_with_link'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), $tmpstory->title()); |
||
| 235 | if (1 == $tmpstory->votes()) { |
||
| 236 | $spotlight['number_votes'] = _NW_ONEVOTE; |
||
| 237 | } else { |
||
| 238 | $spotlight['number_votes'] = sprintf(_NW_NUMVOTES, $tmpstory->votes()); |
||
| 239 | } |
||
| 240 | |||
| 241 | $spotlight['votes_with_text'] = sprintf(_NW_NUMVOTES, $tmpstory->votes()); |
||
| 242 | $spotlight['topicid'] = $tmpstory->topicid(); |
||
| 243 | $spotlight['topic_title'] = $tmpstory->topic_title(); |
||
| 244 | // Added, topic's image and description |
||
| 245 | $spotlight['topic_image'] = XOOPS_URL . '/modules/news/assets/images/topics/' . $tmpstory->topic_imgurl(); |
||
| 246 | $spotlight['topic_description'] = $myts->displayTarea($tmpstory->topic_description, 1); |
||
| 247 | |||
| 248 | if (3 != $displayname) { |
||
| 249 | $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $tmpstory->uname()); |
||
| 250 | $spotlight['author_with_link'] = sprintf("%s <a href='%s'>%s</a>", _POSTEDBY, XOOPS_URL . '/userinfo.php?uid=' . $tmpstory->uid(), $tmpstory->uname()); |
||
| 251 | } else { |
||
| 252 | $spotlight['author'] = ''; |
||
| 253 | $spotlight['author_with_link'] = ''; |
||
| 254 | } |
||
| 255 | $spotlight['author_id'] = $tmpstory->uid(); |
||
| 256 | |||
| 257 | // Create the summary table under the spotlight text |
||
| 258 | if (isset($options[14]) && 0 == $options[14]) { // Use all topics |
||
| 259 | $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]); |
||
| 260 | } else { // Use some topics |
||
| 261 | $topics = array_slice($options, 14); |
||
| 262 | $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]); |
||
| 263 | } |
||
| 264 | if (count($stories) > 0) { |
||
| 265 | foreach ($stories as $key => $story) { |
||
| 266 | $news = []; |
||
| 267 | $title = $story->title(); |
||
| 268 | if (mb_strlen($title) > $options[2]) { |
||
| 269 | $title = xoops_substr($title, 0, $options[2] + 3); |
||
| 270 | } |
||
| 271 | $news['title'] = $title; |
||
| 272 | $news['id'] = $story->storyid(); |
||
| 273 | $news['date'] = formatTimestamp($story->published(), $dateformat); |
||
| 274 | $news['hits'] = $story->counter(); |
||
| 275 | $news['rating'] = number_format($story->rating(), 2); |
||
| 276 | $news['votes'] = $story->votes(); |
||
| 277 | $news['topicid'] = $story->topicid(); |
||
| 278 | $news['topic_title'] = $story->topic_title(); |
||
| 279 | $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
| 280 | $news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
||
| 281 | $news['pictureinfo'] = $story->pictureinfo(); |
||
| 282 | if (3 != $displayname) { |
||
| 283 | $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
| 284 | } else { |
||
| 285 | $news['author'] = ''; |
||
| 286 | } |
||
| 287 | if ($options[3] > 0) { |
||
| 288 | $html = 1 == $story->nohtml() ? 0 : 1; |
||
| 289 | $news['teaser'] = Utility::truncateTagSafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3); |
||
| 290 | } else { |
||
| 291 | $news['teaser'] = ''; |
||
| 292 | } |
||
| 293 | if ($infotips > 0) { |
||
| 294 | $news['infotips'] = ' title="' . Utility::makeInfotips($story->hometext()) . '"'; |
||
| 295 | } else { |
||
| 296 | $news['infotips'] = ''; |
||
| 297 | } |
||
| 298 | |||
| 299 | $news['title_with_link'] = sprintf("<a href='%s'%s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title); |
||
| 300 | $spotlight['news'][] = $news; |
||
| 301 | } |
||
| 302 | } |
||
| 303 | |||
| 304 | $block['spotlight'] = $spotlight; |
||
| 305 | } elseif ($tabscount > 0) { |
||
| 306 | $topics = array_slice($options, 14); |
||
| 307 | $thetopic = $currenttab; |
||
| 308 | $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $thetopic, 1, true, $options[0]); |
||
| 309 | |||
| 310 | $topic->getTopic($thetopic); |
||
| 311 | // Added, topic's image and description |
||
| 312 | $block['topic_image'] = XOOPS_URL . '/modules/news/assets/images/topics/' . $topic->topic_imgurl(); |
||
| 313 | $block['topic_description'] = $topic->topic_description(); |
||
| 314 | |||
| 315 | $smallheader = []; |
||
| 316 | $stats = $topic->getTopicMiniStats($thetopic); |
||
| 317 | $smallheader[] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/index.php?storytopic=' . $thetopic, _MB_READMORE); |
||
| 318 | $smallheader[] = sprintf('%u %s', $stats['count'], _NW_ARTICLES); |
||
| 319 | $smallheader[] = sprintf('%u %s', $stats['reads'], _READS); |
||
| 320 | if (count($stories) > 0) { |
||
| 321 | foreach ($stories as $key => $story) { |
||
| 322 | $news = []; |
||
| 323 | $title = $story->title(); |
||
| 324 | if (mb_strlen($title) > $options[2]) { |
||
| 325 | $title = Utility::truncateTagSafe($title, $options[2] + 3); |
||
| 326 | } |
||
| 327 | if ('' !== $options[7]) { |
||
| 328 | $news['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $myts->displayTarea($options[7], $story->nohtml)); |
||
| 329 | } |
||
| 330 | if ($options[3] > 0) { |
||
| 331 | $html = 1 == $story->nohtml() ? 0 : 1; |
||
| 332 | $news['text'] = Utility::truncateTagSafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3); |
||
| 333 | } else { |
||
| 334 | $news['text'] = ''; |
||
| 335 | } |
||
| 336 | |||
| 337 | if (1 == $story->votes()) { |
||
| 338 | $news['number_votes'] = _NW_ONEVOTE; |
||
| 339 | } else { |
||
| 340 | $news['number_votes'] = sprintf(_NW_NUMVOTES, $story->votes()); |
||
| 341 | } |
||
| 342 | if ($infotips > 0) { |
||
| 343 | $news['infotips'] = ' title="' . Utility::makeInfotips($story->hometext()) . '"'; |
||
| 344 | } else { |
||
| 345 | $news['infotips'] = ''; |
||
| 346 | } |
||
| 347 | $news['title'] = sprintf("<a href='%s' %s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title); |
||
| 348 | $news['id'] = $story->storyid(); |
||
| 349 | $news['date'] = formatTimestamp($story->published(), $dateformat); |
||
| 350 | $news['hits'] = $story->counter(); |
||
| 351 | $news['rating'] = number_format($story->rating(), 2); |
||
| 352 | $news['votes'] = $story->votes(); |
||
| 353 | $news['topicid'] = $story->topicid(); |
||
| 354 | $news['topic_title'] = $story->topic_title(); |
||
| 355 | $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
| 356 | $news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
||
| 357 | $news['pictureinfo'] = $story->pictureinfo(); |
||
| 358 | |||
| 359 | if (3 != $displayname) { |
||
| 360 | $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
| 361 | } else { |
||
| 362 | $news['author'] = ''; |
||
| 363 | } |
||
| 364 | $news['title_with_link'] = sprintf("<a href='%s'%s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title); |
||
| 365 | $block['news'][] = $news; |
||
| 366 | } |
||
| 367 | $block['smallheader'] = $smallheader; |
||
| 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 | if (isset($options[14]) && 0 == (int)$options[14]) { |
||
| 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 (!$stories) { |
||
| 404 | return ''; |
||
| 405 | } |
||
| 406 | $topic = new NewsTopic(); |
||
| 407 | |||
| 408 | foreach ($stories as $key => $story) { |
||
| 409 | $news = []; |
||
| 410 | $title = $story->title(); |
||
| 411 | if (mb_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 ((0 == $options[5]) && (1 == $options[4]) |
||
| 417 | && (($options[6] > 0 && $options[6] == $story->storyid()) |
||
| 418 | || (0 == $options[6] && 0 == $key))) { |
||
| 419 | $spotlight = []; |
||
| 420 | $visible = true; |
||
| 421 | if ($restricted) { |
||
| 422 | $permittedtopics = Utility::getMyItemIds(); |
||
| 423 | if (!in_array($story->topicid(), $permittedtopics, true)) { |
||
| 424 | $visible = false; |
||
| 425 | } |
||
| 426 | } |
||
| 427 | |||
| 428 | if ($visible) { |
||
| 429 | $spotlight['title'] = $title; |
||
| 430 | if ('' !== $options[7]) { |
||
| 431 | $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $myts->displayTarea($options[7], $story->nohtml)); |
||
| 432 | } |
||
| 433 | // Added 16 february 2007 ***************************************** |
||
| 434 | $story_user = null; |
||
| 435 | $story_user = new \XoopsUser($story->uid()); |
||
| 436 | if (is_object($story_user)) { |
||
| 437 | $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar'); |
||
| 438 | } |
||
| 439 | // **************************************************************** |
||
| 440 | $spotlight['text'] = $story->hometext(); |
||
| 441 | $spotlight['id'] = $story->storyid(); |
||
| 442 | $spotlight['date'] = formatTimestamp($story->published(), $dateformat); |
||
| 443 | $spotlight['hits'] = $story->counter(); |
||
| 444 | $spotlight['rating'] = $story->rating(); |
||
| 445 | $spotlight['votes'] = $story->votes(); |
||
| 446 | $spotlight['topicid'] = $story->topicid(); |
||
| 447 | $spotlight['topic_title'] = $story->topic_title(); |
||
| 448 | $spotlight['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
| 449 | // Added, topic's image and description |
||
| 450 | $spotlight['topic_image'] = XOOPS_URL . '/modules/news/assets/images/topics/' . $story->topic_imgurl(); |
||
| 451 | $spotlight['topic_description'] = $myts->displayTarea($story->topic_description, 1); |
||
| 452 | if ('' !== xoops_trim($story->bodytext())) { |
||
| 453 | $spotlight['read_more'] = true; |
||
| 454 | } else { |
||
| 455 | $spotlight['read_more'] = false; |
||
| 456 | } |
||
| 457 | |||
| 458 | if (3 != $displayname) { |
||
| 459 | $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
| 460 | } else { |
||
| 461 | $spotlight['author'] = ''; |
||
| 462 | } |
||
| 463 | } |
||
| 464 | $block['spotlight'] = $spotlight; |
||
| 465 | } else { |
||
| 466 | $news['title'] = $title; |
||
| 467 | $news['id'] = $story->storyid(); |
||
| 468 | $news['date'] = formatTimestamp($story->published(), $dateformat); |
||
| 469 | $news['hits'] = $story->counter(); |
||
| 470 | $news['rating'] = $story->rating(); |
||
| 471 | $news['votes'] = $story->votes(); |
||
| 472 | $news['topicid'] = $story->topicid(); |
||
| 473 | $news['topic_title'] = $story->topic_title(); |
||
| 474 | $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
| 475 | $news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
||
| 476 | $news['pictureinfo'] = $story->pictureinfo(); |
||
| 477 | |||
| 478 | if (3 != $displayname) { |
||
| 479 | $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
| 480 | } else { |
||
| 481 | $news['author'] = ''; |
||
| 482 | } |
||
| 483 | if ($options[3] > 0) { |
||
| 484 | $html = 1 == $story->nohtml() ? 0 : 1; |
||
| 485 | $news['teaser'] = Utility::truncateTagSafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3); |
||
| 486 | $news['infotips'] = ''; |
||
| 487 | } else { |
||
| 488 | $news['teaser'] = ''; |
||
| 489 | if ($infotips > 0) { |
||
| 490 | $news['infotips'] = ' title="' . Utility::makeInfotips($story->hometext()) . '"'; |
||
| 491 | } else { |
||
| 492 | $news['infotips'] = ''; |
||
| 493 | } |
||
| 494 | } |
||
| 495 | $block['stories'][] = $news; |
||
| 496 | } |
||
| 497 | } |
||
| 498 | |||
| 499 | // If spotlight article was not in the fetched stories |
||
| 500 | if (!isset($spotlight) && $options[4]) { |
||
| 501 | $block['use_spotlight'] = true; |
||
| 502 | $visible = true; |
||
| 503 | if (0 == $options[5] && $restricted) { // Use a specific news and we are in restricted mode |
||
| 504 | $permittedtopics = Utility::getMyItemIds(); |
||
| 505 | $permstory = new NewsStory($options[6]); |
||
| 506 | if (!in_array($permstory->topicid(), $permittedtopics, true)) { |
||
| 507 | $visible = false; |
||
| 508 | } |
||
| 509 | unset($permstory); |
||
| 510 | } |
||
| 511 | |||
| 512 | if (0 == $options[5]) { // Use a specific news |
||
| 513 | if ($visible) { |
||
| 514 | $spotlightArticle = new NewsStory($options[6]); |
||
| 515 | } else { |
||
| 516 | $block['use_spotlight'] = false; |
||
| 517 | } |
||
| 518 | } else { // Use the most recent news |
||
| 519 | $stories = []; |
||
| 520 | $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]); |
||
| 521 | if (count($stories) > 0) { |
||
| 522 | $firststory = $stories[0]; |
||
| 523 | $spotlightArticle = new NewsStory($firststory->storyid()); |
||
| 524 | } else { |
||
| 525 | $block['use_spotlight'] = false; |
||
| 526 | } |
||
| 527 | } |
||
| 528 | if ($block['use_spotlight']) { |
||
| 529 | $spotlight = []; |
||
| 530 | $spotlight['title'] = xoops_substr($spotlightArticle->title(), 0, $options[2] - 1); |
||
| 531 | if ('' !== $options[7]) { |
||
| 532 | $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $spotlightArticle->storyid(), $myts->displayTarea($options[7], $spotlightArticle->nohtml)); |
||
| 533 | } |
||
| 534 | // Added 16 february 2007 ***************************************** |
||
| 535 | $story_user = null; |
||
| 536 | $story_user = new \XoopsUser($spotlightArticle->uid()); |
||
| 537 | if (is_object($story_user)) { |
||
| 538 | $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar'); |
||
| 539 | } |
||
| 540 | // **************************************************************** |
||
| 541 | $spotlight['topicid'] = $spotlightArticle->topicid(); |
||
| 542 | $spotlight['topic_title'] = $spotlightArticle->topic_title(); |
||
| 543 | $spotlight['topic_color'] = '#' . $myts->displayTarea($spotlightArticle->topic_color); |
||
| 544 | $spotlight['text'] = $spotlightArticle->hometext(); |
||
| 545 | $spotlight['id'] = $spotlightArticle->storyid(); |
||
| 546 | $spotlight['date'] = formatTimestamp($spotlightArticle->published(), $dateformat); |
||
| 547 | $spotlight['hits'] = $spotlightArticle->counter(); |
||
| 548 | $spotlight['rating'] = $spotlightArticle->rating(); |
||
| 549 | $spotlight['votes'] = $spotlightArticle->votes(); |
||
| 550 | // Added, topic's image and description |
||
| 551 | $spotlight['topic_image'] = XOOPS_URL . '/modules/news/assets/images/topics/' . $spotlightArticle->topic_imgurl(); |
||
| 552 | $spotlight['topic_description'] = $myts->displayTarea($spotlightArticle->topic_description, 1); |
||
| 553 | if (3 != $displayname) { |
||
| 554 | $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $spotlightArticle->uname()); |
||
| 555 | } else { |
||
| 556 | $spotlight['author'] = ''; |
||
| 557 | } |
||
| 558 | if ('' !== xoops_trim($spotlightArticle->bodytext())) { |
||
| 559 | $spotlight['read_more'] = true; |
||
| 560 | } else { |
||
| 561 | $spotlight['read_more'] = false; |
||
| 562 | } |
||
| 563 | $block['spotlight'] = $spotlight; |
||
| 564 | } |
||
| 565 | } |
||
| 566 | } |
||
| 567 | if (isset($permstory)) { |
||
| 568 | unset($permstory); |
||
| 569 | } |
||
| 570 | $block['lang_read_more'] = htmlspecialchars(_MB_READMORE, ENT_QUOTES | ENT_HTML5); // Read More... |
||
| 571 | $block['lang_orderby'] = htmlspecialchars(_MB_NEWS_ORDER, ENT_QUOTES | ENT_HTML5); // "Order By" |
||
| 572 | $block['lang_orderby_date'] = htmlspecialchars(_MB_NEWS_DATE, ENT_QUOTES | ENT_HTML5); // Published date |
||
| 573 | $block['lang_orderby_hits'] = htmlspecialchars(_MB_NEWS_HITS, ENT_QUOTES | ENT_HTML5); // Number of Hits |
||
| 574 | $block['lang_orderby_rating'] = htmlspecialchars(_MB_NEWS_RATE, ENT_QUOTES | ENT_HTML5); // Rating |
||
| 575 | $block['sort'] = $options[0]; // "published" or "counter" or "rating" |
||
| 576 | |||
| 577 | return $block; |
||
| 578 | } |
||
| 708 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: