| Conditions | 42 |
| Paths | > 20000 |
| Total Lines | 242 |
| Code Lines | 180 |
| 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 |
||
| 436 | public function showPost($isadmin) |
||
| 437 | { |
||
| 438 | global $myts; |
||
| 439 | global $forumUrl, $forumImage; |
||
| 440 | global $viewtopic_users, $viewtopic_posters, $forum_obj, $topic_obj, $online, $user_karma, $viewmode, $order, $start, $total_posts, $topic_status; |
||
| 441 | static $post_NO = 0; |
||
| 442 | static $name_anonymous; |
||
| 443 | |||
| 444 | if (!isset($name_anonymous)) { |
||
| 445 | $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
||
| 446 | } |
||
| 447 | |||
| 448 | // mod_loadFunctions('time', 'newbb'); |
||
| 449 | // mod_loadFunctions('render', 'newbb'); |
||
| 450 | // mod_loadFunctions('text', 'newbb'); // irmtfan add text functions |
||
| 451 | require_once \dirname(__DIR__) . '/include/functions.time.php'; |
||
| 452 | require_once \dirname(__DIR__) . '/include/functions.render.php'; |
||
| 453 | require_once \dirname(__DIR__) . '/include/functions.text.php'; |
||
| 454 | |||
| 455 | $post_id = $this->getVar('post_id'); |
||
| 456 | $topic_id = $this->getVar('topic_id'); |
||
| 457 | $forum_id = $this->getVar('forum_id'); |
||
| 458 | |||
| 459 | $query_vars = ['status', 'order', 'start', 'mode', 'viewmode']; |
||
| 460 | $query_array = []; |
||
| 461 | $query_array['topic_id'] = "topic_id={$topic_id}"; |
||
| 462 | foreach ($query_vars as $var) { |
||
| 463 | if (!empty($_GET[$var])) { |
||
| 464 | $query_array[$var] = "{$var}={$_GET[$var]}"; |
||
| 465 | } |
||
| 466 | } |
||
| 467 | $page_query = \htmlspecialchars(\implode('&', \array_values($query_array)), \ENT_QUOTES | \ENT_HTML5); |
||
| 468 | |||
| 469 | $uid = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
| 470 | |||
| 471 | ++$post_NO; |
||
| 472 | if ('desc' === mb_strtolower($order)) { |
||
| 473 | $post_no = $total_posts - ($start + $post_NO) + 1; |
||
| 474 | } else { |
||
| 475 | $post_no = $start + $post_NO; |
||
| 476 | } |
||
| 477 | |||
| 478 | if ($isadmin || $this->checkIdentity()) { |
||
| 479 | $post_text = $this->getVar('post_text'); |
||
| 480 | $post_attachment = $this->displayAttachment(); |
||
| 481 | } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) { |
||
| 482 | $post_text = "<div class='karma'>" . \sprintf(_MD_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . '</div>'; |
||
| 483 | $post_attachment = ''; |
||
| 484 | } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply') |
||
| 485 | && (!$uid |
||
| 486 | || !\in_array($uid, $viewtopic_posters))) { |
||
| 487 | $post_text = "<div class='karma'>" . _MD_REPLY_REQUIREMENT . "</div>\n"; |
||
| 488 | $post_attachment = ''; |
||
| 489 | } else { |
||
| 490 | $post_text = $this->getVar('post_text'); |
||
| 491 | $post_attachment = $this->displayAttachment(); |
||
| 492 | } |
||
| 493 | // START irmtfan add highlight feature |
||
| 494 | // Hightlighting searched words |
||
| 495 | $post_title = $this->getVar('subject'); |
||
| 496 | if (!empty($_GET['keywords']) && \Xmf\Request::hasVar('keywords', 'GET')) { |
||
| 497 | $keywords = $myts->htmlSpecialChars(\trim(\urldecode($_GET['keywords']))); |
||
| 498 | $post_text = \newbb_highlightText($post_text, $keywords); |
||
| 499 | $post_title = \newbb_highlightText($post_title, $keywords); |
||
| 500 | } |
||
| 501 | // END irmtfan add highlight feature |
||
| 502 | if (isset($viewtopic_users[$this->getVar('uid')])) { |
||
| 503 | $poster = $viewtopic_users[$this->getVar('uid')]; |
||
| 504 | } else { |
||
| 505 | $name = ($post_name = $this->getVar('poster_name')) ? $post_name : $name_anonymous; |
||
| 506 | $poster = [ |
||
| 507 | 'poster_uid' => 0, |
||
| 508 | 'name' => $name, |
||
| 509 | 'link' => $name, |
||
| 510 | ]; |
||
| 511 | } |
||
| 512 | |||
| 513 | $posticon = $this->getVar('icon'); |
||
| 514 | if ($posticon) { |
||
| 515 | $post_image = "<a name='{$post_id}'><img src='" . $GLOBALS['xoops']->url("images/subject/{$posticon}") . "' alt=''></a>"; |
||
| 516 | } else { |
||
| 517 | $post_image = "<a name='{$post_id}'><img src='" . $GLOBALS['xoops']->url('images/icons/posticon.gif') . "' alt=''></a>"; |
||
| 518 | } |
||
| 519 | |||
| 520 | $thread_buttons = []; |
||
| 521 | $mod_buttons = []; |
||
| 522 | |||
| 523 | if (($this->getVar('uid') > 0) |
||
| 524 | && $isadmin |
||
| 525 | && (($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
||
| 526 | && $GLOBALS['xoopsUser']->getVar('uid') !== $this->getVar('uid'))) { |
||
| 527 | $mod_buttons['bann']['image'] = newbb_displayImage('p_bann', _MD_SUSPEND_MANAGEMENT); |
||
| 528 | $mod_buttons['bann']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/moderate.php?forum={$forum_id}&fuid=" . $this->getVar('uid')); |
||
| 529 | $mod_buttons['bann']['name'] = _MD_SUSPEND_MANAGEMENT; |
||
| 530 | $thread_buttons['bann']['image'] = newbb_displayImage('p_bann', _MD_SUSPEND_MANAGEMENT); |
||
| 531 | $thread_buttons['bann']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/moderate.php?forum={$forum_id}&fuid=" . $this->getVar('uid')); |
||
| 532 | $thread_buttons['bann']['name'] = _MD_SUSPEND_MANAGEMENT; |
||
| 533 | } |
||
| 534 | |||
| 535 | if ($GLOBALS['xoopsModuleConfig']['enable_permcheck']) { |
||
| 536 | /** @var Newbb\TopicHandler $topicHandler */ |
||
| 537 | $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||
| 538 | $topic_status = $topic_obj->getVar('topic_status'); |
||
| 539 | if ($topicHandler->getPermission($forum_id, $topic_status, 'edit')) { |
||
| 540 | $edit_ok = ($isadmin || ($this->checkIdentity() && $this->checkTimelimit('edit_timelimit'))); |
||
| 541 | if ($edit_ok) { |
||
| 542 | $thread_buttons['edit']['image'] = newbb_displayImage('p_edit', _EDIT); |
||
| 543 | $thread_buttons['edit']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/edit.php?{$page_query}"); |
||
| 544 | $thread_buttons['edit']['name'] = _EDIT; |
||
| 545 | $mod_buttons['edit']['image'] = newbb_displayImage('p_edit', _EDIT); |
||
| 546 | $mod_buttons['edit']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/edit.php?{$page_query}"); |
||
| 547 | $mod_buttons['edit']['name'] = _EDIT; |
||
| 548 | } |
||
| 549 | } |
||
| 550 | |||
| 551 | if ($topicHandler->getPermission($forum_id, $topic_status, 'delete')) { |
||
| 552 | $delete_ok = ($isadmin || ($this->checkIdentity() && $this->checkTimelimit('delete_timelimit'))); |
||
| 553 | |||
| 554 | if ($delete_ok) { |
||
| 555 | $thread_buttons['delete']['image'] = newbb_displayImage('p_delete', _DELETE); |
||
| 556 | $thread_buttons['delete']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/delete.php?{$page_query}"); |
||
| 557 | $thread_buttons['delete']['name'] = _DELETE; |
||
| 558 | $mod_buttons['delete']['image'] = newbb_displayImage('p_delete', _DELETE); |
||
| 559 | $mod_buttons['delete']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/delete.php?{$page_query}"); |
||
| 560 | $mod_buttons['delete']['name'] = _DELETE; |
||
| 561 | } |
||
| 562 | } |
||
| 563 | if ($topicHandler->getPermission($forum_id, $topic_status, 'reply')) { |
||
| 564 | $thread_buttons['reply']['image'] = newbb_displayImage('p_reply', _MD_REPLY); |
||
| 565 | $thread_buttons['reply']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/reply.php?{$page_query}"); |
||
| 566 | $thread_buttons['reply']['name'] = _MD_REPLY; |
||
| 567 | |||
| 568 | $thread_buttons['quote']['image'] = newbb_displayImage('p_quote', _MD_QUOTE); |
||
| 569 | $thread_buttons['quote']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/reply.php?{$page_query}&quotedac=1"); |
||
| 570 | $thread_buttons['quote']['name'] = _MD_QUOTE; |
||
| 571 | } |
||
| 572 | } else { |
||
| 573 | $mod_buttons['edit']['image'] = newbb_displayImage('p_edit', _EDIT); |
||
| 574 | $mod_buttons['edit']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/edit.php?{$page_query}"); |
||
| 575 | $mod_buttons['edit']['name'] = _EDIT; |
||
| 576 | |||
| 577 | $mod_buttons['delete']['image'] = newbb_displayImage('p_delete', _DELETE); |
||
| 578 | $mod_buttons['delete']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/delete.php?{$page_query}"); |
||
| 579 | $mod_buttons['delete']['name'] = _DELETE; |
||
| 580 | |||
| 581 | $thread_buttons['reply']['image'] = newbb_displayImage('p_reply', _MD_REPLY); |
||
| 582 | $thread_buttons['reply']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/reply.php?{$page_query}"); |
||
| 583 | $thread_buttons['reply']['name'] = _MD_REPLY; |
||
| 584 | } |
||
| 585 | |||
| 586 | if (!$isadmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) { |
||
| 587 | $thread_buttons['report']['image'] = newbb_displayImage('p_report', _MD_REPORT); |
||
| 588 | $thread_buttons['report']['link'] = $GLOBALS['xoops']->url('modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/report.php?{$page_query}"); |
||
| 589 | $thread_buttons['report']['name'] = _MD_REPORT; |
||
| 590 | } |
||
| 591 | |||
| 592 | $thread_action = []; |
||
| 593 | // irmtfan add pdf permission |
||
| 594 | if ($topicHandler->getPermission($forum_id, $topic_status, 'pdf') |
||
| 595 | && \file_exists($GLOBALS['xoops']->path('Frameworks/tcpdf/tcpdf.php'))) { |
||
| 596 | $thread_action['pdf']['image'] = newbb_displayImage('pdf', _MD_PDF); |
||
| 597 | $thread_action['pdf']['link'] = $GLOBALS['xoops']->url('modules/newbb/makepdf.php?type=post&pageid=0'); |
||
| 598 | $thread_action['pdf']['name'] = _MD_PDF; |
||
| 599 | $thread_action['pdf']['target'] = '_blank'; |
||
| 600 | } |
||
| 601 | // irmtfan add print permission |
||
| 602 | if ($topicHandler->getPermission($forum_id, $topic_status, 'print')) { |
||
| 603 | $thread_action['print']['image'] = newbb_displayImage('printer', _MD_PRINT); |
||
| 604 | $thread_action['print']['link'] = $GLOBALS['xoops']->url("modules/newbb/print.php?form=2&forum={$forum_id}&topic_id={$topic_id}"); |
||
| 605 | $thread_action['print']['name'] = _MD_PRINT; |
||
| 606 | $thread_action['print']['target'] = '_blank'; |
||
| 607 | } |
||
| 608 | |||
| 609 | if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) { |
||
| 610 | $full_title = $this->getVar('subject'); |
||
| 611 | $clean_title = \preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject')); |
||
| 612 | $full_link = $GLOBALS['xoops']->url("modules/newbb/viewtopic.php?post_id={$post_id}"); |
||
| 613 | |||
| 614 | $thread_action['social_twitter']['image'] = newbb_displayImage('twitter', \_MD_SHARE_TWITTER); |
||
| 615 | $thread_action['social_twitter']['link'] = "http://twitter.com/share?text={$clean_title}&url={$full_link}"; |
||
| 616 | $thread_action['social_twitter']['name'] = \_MD_SHARE_TWITTER; |
||
| 617 | $thread_action['social_twitter']['target'] = '_blank'; |
||
| 618 | |||
| 619 | $thread_action['social_facebook']['image'] = newbb_displayImage('facebook', \_MD_SHARE_FACEBOOK); |
||
| 620 | $thread_action['social_facebook']['link'] = "http://www.facebook.com/sharer.php?u={$full_link}"; |
||
| 621 | $thread_action['social_facebook']['name'] = \_MD_SHARE_FACEBOOK; |
||
| 622 | $thread_action['social_facebook']['target'] = '_blank'; |
||
| 623 | |||
| 624 | $thread_action['social_gplus']['image'] = newbb_displayImage('googleplus', \_MD_SHARE_GOOGLEPLUS); |
||
| 625 | $thread_action['social_gplus']['link'] = "https://plusone.google.com/_/+1/confirm?hl=en&url={$full_link}"; |
||
| 626 | $thread_action['social_gplus']['name'] = \_MD_SHARE_GOOGLEPLUS; |
||
| 627 | $thread_action['social_gplus']['target'] = '_blank'; |
||
| 628 | |||
| 629 | $thread_action['social_linkedin']['image'] = newbb_displayImage('linkedin', \_MD_SHARE_LINKEDIN); |
||
| 630 | $thread_action['social_linkedin']['link'] = "http://www.linkedin.com/shareArticle?mini=true&title={$full_title}&url={$full_link}"; |
||
| 631 | $thread_action['social_linkedin']['name'] = \_MD_SHARE_LINKEDIN; |
||
| 632 | $thread_action['social_linkedin']['target'] = '_blank'; |
||
| 633 | |||
| 634 | $thread_action['social_delicious']['image'] = newbb_displayImage('delicious', \_MD_SHARE_DELICIOUS); |
||
| 635 | $thread_action['social_delicious']['link'] = "http://del.icio.us/post?title={$full_title}&url={$full_link}"; |
||
| 636 | $thread_action['social_delicious']['name'] = \_MD_SHARE_DELICIOUS; |
||
| 637 | $thread_action['social_delicious']['target'] = '_blank'; |
||
| 638 | |||
| 639 | $thread_action['social_digg']['image'] = newbb_displayImage('digg', \_MD_SHARE_DIGG); |
||
| 640 | $thread_action['social_digg']['link'] = "http://digg.com/submit?phase=2&title={$full_title}&url={$full_link}"; |
||
| 641 | $thread_action['social_digg']['name'] = \_MD_SHARE_DIGG; |
||
| 642 | $thread_action['social_digg']['target'] = '_blank'; |
||
| 643 | |||
| 644 | $thread_action['social_reddit']['image'] = newbb_displayImage('reddit', \_MD_SHARE_REDDIT); |
||
| 645 | $thread_action['social_reddit']['link'] = "http://reddit.com/submit?title={$full_title}&url={$full_link}"; |
||
| 646 | $thread_action['social_reddit']['name'] = \_MD_SHARE_REDDIT; |
||
| 647 | $thread_action['social_reddit']['target'] = '_blank'; |
||
| 648 | |||
| 649 | $thread_action['social_wong']['image'] = newbb_displayImage('wong', \_MD_SHARE_MRWONG); |
||
| 650 | $thread_action['social_wong']['link'] = "http://www.mister-wong.de/index.php?action=addurl&bm_url=$full_link}"; |
||
| 651 | $thread_action['social_wong']['name'] = \_MD_SHARE_MRWONG; |
||
| 652 | $thread_action['social_wong']['target'] = '_blank'; |
||
| 653 | } |
||
| 654 | |||
| 655 | $post = [ |
||
| 656 | 'post_id' => $post_id, |
||
| 657 | 'post_parent_id' => $this->getVar('pid'), |
||
| 658 | 'post_date' => newbb_formatTimestamp($this->getVar('post_time')), |
||
| 659 | 'post_image' => $post_image, |
||
| 660 | 'post_title' => $post_title, // irmtfan $post_title to add highlight keywords |
||
| 661 | 'post_text' => $post_text, |
||
| 662 | 'post_attachment' => $post_attachment, |
||
| 663 | 'post_edit' => $this->displayPostEdit(), |
||
| 664 | 'post_no' => $post_no, |
||
| 665 | 'post_signature' => $this->getVar('attachsig') ? @$poster['signature'] : '', |
||
| 666 | 'poster_ip' => ($isadmin |
||
| 667 | && $GLOBALS['xoopsModuleConfig']['show_ip']) ? \long2ip($this->getVar('poster_ip')) : '', |
||
| 668 | 'thread_action' => $thread_action, |
||
| 669 | 'thread_buttons' => $thread_buttons, |
||
| 670 | 'mod_buttons' => $mod_buttons, |
||
| 671 | 'poster' => $poster, |
||
| 672 | 'post_permalink' => "<a href='" . $GLOBALS['xoops']->url('/modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . "/viewtopic.php?post_id={$post_id}") . "'></a>", |
||
| 673 | ]; |
||
| 674 | |||
| 675 | unset($thread_buttons, $mod_buttons, $eachposter); |
||
| 676 | |||
| 677 | return $post; |
||
| 678 | } |
||
| 680 |