Conditions | 41 |
Paths | > 20000 |
Total Lines | 241 |
Code Lines | 177 |
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 |
||
477 | public function showPost($isAdmin) |
||
478 | { |
||
479 | global $xoopsModule, $myts; |
||
480 | global $forumUrl, $forumImage, $forumObject, $online, $viewmode; |
||
481 | global $viewtopic_users, $viewtopic_posters, $topicObject, $user_karma; |
||
482 | global $order, $start, $total_posts, $topic_status; |
||
483 | static $post_NO = 0; |
||
484 | static $name_anonymous; |
||
485 | /** @var TopicHandler $topicHandler */ |
||
486 | $topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic'); |
||
487 | if (null === $name_anonymous) { |
||
488 | $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
||
489 | } |
||
490 | |||
491 | require_once \dirname(__DIR__) . '/include/functions.time.php'; |
||
492 | require_once \dirname(__DIR__) . '/include/functions.render.php'; |
||
493 | |||
494 | $post_id = $this->getVar('post_id'); |
||
495 | $topic_id = $this->getVar('topic_id'); |
||
496 | $forum_id = $this->getVar('forum_id'); |
||
497 | |||
498 | $query_vars = ['status', 'order', 'start', 'mode', 'viewmode']; |
||
499 | $query_array = []; |
||
500 | $query_array['topic_id'] = "topic_id={$topic_id}"; |
||
501 | foreach ($query_vars as $var) { |
||
502 | if (Request::getString($var, '', 'GET')) { |
||
503 | $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET'); |
||
504 | } |
||
505 | } |
||
506 | $page_query = \htmlspecialchars(\implode('&', \array_values($query_array)), \ENT_QUOTES | \ENT_HTML5); |
||
507 | |||
508 | $uid = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
509 | |||
510 | ++$post_NO; |
||
511 | if ('desc' === mb_strtolower($order)) { |
||
512 | $post_no = $total_posts - ($start + $post_NO) + 1; |
||
513 | } else { |
||
514 | $post_no = $start + $post_NO; |
||
515 | } |
||
516 | |||
517 | if ($isAdmin || $this->checkIdentity()) { |
||
518 | $post_text = $this->getVar('post_text'); |
||
519 | $post_attachment = $this->displayAttachment(); |
||
520 | } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) { |
||
521 | $post_text = "<div class='karma'>" . \sprintf(\_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . '</div>'; |
||
522 | $post_attachment = ''; |
||
523 | } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply') |
||
524 | && (!$uid || !\in_array($uid, $viewtopic_posters))) { |
||
525 | $post_text = "<div class='karma'>" . \_MD_NEWBB_REPLY_REQUIREMENT . '</div>'; |
||
526 | $post_attachment = ''; |
||
527 | } else { |
||
528 | $post_text = $this->getVar('post_text'); |
||
529 | $post_attachment = $this->displayAttachment(); |
||
530 | } |
||
531 | |||
532 | // Hightlight search words |
||
533 | $post_title = $this->getVar('subject'); |
||
534 | $keywords = Request::getString('keywords', '', 'GET'); |
||
535 | if ($keywords) { |
||
536 | //$keywords = $myts->htmlSpecialChars(trim(urldecode(Request::getString('keywords', '', 'GET')))); |
||
537 | $post_text = Highlighter::apply($keywords, $post_text, '<mark>', '</mark>'); |
||
538 | $post_title = Highlighter::apply($keywords, $post_title, '<mark>', '</mark>'); |
||
539 | } |
||
540 | |||
541 | if (isset($viewtopic_users[$this->getVar('uid')])) { |
||
542 | $poster = $viewtopic_users[$this->getVar('uid')]; |
||
543 | } else { |
||
544 | $name = ($post_name = $this->getVar('poster_name')) ? $post_name : $name_anonymous; |
||
545 | $poster = [ |
||
546 | 'poster_uid' => 0, |
||
547 | 'name' => $name, |
||
548 | 'link' => $name, |
||
549 | ]; |
||
550 | } |
||
551 | |||
552 | $posticon = $this->getVar('icon'); |
||
553 | if ($posticon) { |
||
554 | $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/subject/' . $posticon . '" alt="" ></a>'; |
||
555 | } else { |
||
556 | $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" ></a>'; |
||
557 | } |
||
558 | |||
559 | $thread_buttons = []; |
||
560 | $mod_buttons = []; |
||
561 | |||
562 | if ($isAdmin && ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->getVar('uid') !== $this->getVar('uid')) |
||
563 | && $this->getVar('uid') > 0) { |
||
564 | $mod_buttons['bann']['image'] = \newbbDisplayImage('p_bann', \_MD_NEWBB_SUSPEND_MANAGEMENT); |
||
565 | $mod_buttons['bann']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&uid=' . $this->getVar('uid'); |
||
566 | $mod_buttons['bann']['name'] = \_MD_NEWBB_SUSPEND_MANAGEMENT; |
||
567 | $thread_buttons['bann']['image'] = \newbbDisplayImage('p_bann', \_MD_NEWBB_SUSPEND_MANAGEMENT); |
||
568 | $thread_buttons['bann']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&uid=' . $this->getVar('uid'); |
||
569 | $thread_buttons['bann']['name'] = \_MD_NEWBB_SUSPEND_MANAGEMENT; |
||
570 | } |
||
571 | |||
572 | if ($GLOBALS['xoopsModuleConfig']['enable_permcheck']) { |
||
573 | // /** @var TopicHandler $topicHandler */ |
||
574 | // $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||
575 | $topic_status = $topicObject->getVar('topic_status'); |
||
576 | if ($topicHandler->getPermission($forum_id, $topic_status, 'edit')) { |
||
577 | $edit_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('edit_timelimit'))); |
||
578 | |||
579 | if ($edit_ok) { |
||
580 | $thread_buttons['edit']['image'] = \newbbDisplayImage('p_edit', _EDIT); |
||
581 | $thread_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
||
582 | $thread_buttons['edit']['name'] = _EDIT; |
||
583 | $mod_buttons['edit']['image'] = \newbbDisplayImage('p_edit', _EDIT); |
||
584 | $mod_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
||
585 | $mod_buttons['edit']['name'] = _EDIT; |
||
586 | } |
||
587 | } |
||
588 | |||
589 | if ($topicHandler->getPermission($forum_id, $topic_status, 'delete')) { |
||
590 | $delete_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('delete_timelimit'))); |
||
591 | |||
592 | if ($delete_ok) { |
||
593 | $thread_buttons['delete']['image'] = \newbbDisplayImage('p_delete', _DELETE); |
||
594 | $thread_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
||
595 | $thread_buttons['delete']['name'] = _DELETE; |
||
596 | $mod_buttons['delete']['image'] = \newbbDisplayImage('p_delete', _DELETE); |
||
597 | $mod_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
||
598 | $mod_buttons['delete']['name'] = _DELETE; |
||
599 | } |
||
600 | } |
||
601 | if ($topicHandler->getPermission($forum_id, $topic_status, 'reply')) { |
||
602 | $thread_buttons['reply']['image'] = \newbbDisplayImage('p_reply', \_MD_NEWBB_REPLY); |
||
603 | $thread_buttons['reply']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}"; |
||
604 | $thread_buttons['reply']['name'] = \_MD_NEWBB_REPLY; |
||
605 | |||
606 | $thread_buttons['quote']['image'] = \newbbDisplayImage('p_quote', \_MD_NEWBB_QUOTE); |
||
607 | $thread_buttons['quote']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}&quotedac=1"; |
||
608 | $thread_buttons['quote']['name'] = \_MD_NEWBB_QUOTE; |
||
609 | } |
||
610 | } else { |
||
611 | $mod_buttons['edit']['image'] = \newbbDisplayImage('p_edit', _EDIT); |
||
612 | $mod_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
||
613 | $mod_buttons['edit']['name'] = _EDIT; |
||
614 | |||
615 | $mod_buttons['delete']['image'] = \newbbDisplayImage('p_delete', _DELETE); |
||
616 | $mod_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
||
617 | $mod_buttons['delete']['name'] = _DELETE; |
||
618 | |||
619 | $thread_buttons['reply']['image'] = \newbbDisplayImage('p_reply', \_MD_NEWBB_REPLY); |
||
620 | $thread_buttons['reply']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}"; |
||
621 | $thread_buttons['reply']['name'] = \_MD_NEWBB_REPLY; |
||
622 | } |
||
623 | |||
624 | if (!$isAdmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) { |
||
625 | $thread_buttons['report']['image'] = \newbbDisplayImage('p_report', \_MD_NEWBB_REPORT); |
||
626 | $thread_buttons['report']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/report.php?{$page_query}"; |
||
627 | $thread_buttons['report']['name'] = \_MD_NEWBB_REPORT; |
||
628 | } |
||
629 | |||
630 | $thread_action = []; |
||
631 | // irmtfan add pdf permission |
||
632 | if (\file_exists(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php') |
||
633 | && $topicHandler->getPermission($forum_id, $topic_status, 'pdf')) { |
||
634 | $thread_action['pdf']['image'] = \newbbDisplayImage('pdf', \_MD_NEWBB_PDF); |
||
635 | $thread_action['pdf']['link'] = XOOPS_URL . '/modules/newbb/makepdf.php?type=post&pageid=0'; |
||
636 | $thread_action['pdf']['name'] = \_MD_NEWBB_PDF; |
||
637 | $thread_action['pdf']['target'] = '_blank'; |
||
638 | } |
||
639 | // irmtfan add print permission |
||
640 | if ($topicHandler->getPermission($forum_id, $topic_status, 'print')) { |
||
641 | $thread_action['print']['image'] = \newbbDisplayImage('printer', \_MD_NEWBB_PRINT); |
||
642 | $thread_action['print']['link'] = XOOPS_URL . '/modules/newbb/print.php?form=2&forum=' . $forum_id . '&topic_id=' . $topic_id; |
||
643 | $thread_action['print']['name'] = \_MD_NEWBB_PRINT; |
||
644 | $thread_action['print']['target'] = '_blank'; |
||
645 | } |
||
646 | |||
647 | if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) { |
||
648 | $full_title = $this->getVar('subject'); |
||
649 | $clean_title = \preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject')); |
||
650 | $full_link = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $post_id; |
||
651 | |||
652 | $thread_action['social_twitter']['image'] = \newbbDisplayImage('twitter', \_MD_NEWBB_SHARE_TWITTER); |
||
653 | $thread_action['social_twitter']['link'] = 'http://twitter.com/share?text=' . $clean_title . '&url=' . $full_link; |
||
654 | $thread_action['social_twitter']['name'] = \_MD_NEWBB_SHARE_TWITTER; |
||
655 | $thread_action['social_twitter']['target'] = '_blank'; |
||
656 | |||
657 | $thread_action['social_facebook']['image'] = \newbbDisplayImage('facebook', \_MD_NEWBB_SHARE_FACEBOOK); |
||
658 | $thread_action['social_facebook']['link'] = 'http://www.facebook.com/sharer.php?u=' . $full_link; |
||
659 | $thread_action['social_facebook']['name'] = \_MD_NEWBB_SHARE_FACEBOOK; |
||
660 | $thread_action['social_facebook']['target'] = '_blank'; |
||
661 | |||
662 | $thread_action['social_gplus']['image'] = \newbbDisplayImage('googleplus', \_MD_NEWBB_SHARE_GOOGLEPLUS); |
||
663 | $thread_action['social_gplus']['link'] = 'https://plusone.google.com/_/+1/confirm?hl=en&url=' . $full_link; |
||
664 | $thread_action['social_gplus']['name'] = \_MD_NEWBB_SHARE_GOOGLEPLUS; |
||
665 | $thread_action['social_gplus']['target'] = '_blank'; |
||
666 | |||
667 | $thread_action['social_linkedin']['image'] = \newbbDisplayImage('linkedin', \_MD_NEWBB_SHARE_LINKEDIN); |
||
668 | $thread_action['social_linkedin']['link'] = 'http://www.linkedin.com/shareArticle?mini=true&title=' . $full_title . '&url=' . $full_link; |
||
669 | $thread_action['social_linkedin']['name'] = \_MD_NEWBB_SHARE_LINKEDIN; |
||
670 | $thread_action['social_linkedin']['target'] = '_blank'; |
||
671 | |||
672 | $thread_action['social_delicious']['image'] = \newbbDisplayImage('delicious', \_MD_NEWBB_SHARE_DELICIOUS); |
||
673 | $thread_action['social_delicious']['link'] = 'http://del.icio.us/post?title=' . $full_title . '&url=' . $full_link; |
||
674 | $thread_action['social_delicious']['name'] = \_MD_NEWBB_SHARE_DELICIOUS; |
||
675 | $thread_action['social_delicious']['target'] = '_blank'; |
||
676 | |||
677 | $thread_action['social_digg']['image'] = \newbbDisplayImage('digg', \_MD_NEWBB_SHARE_DIGG); |
||
678 | $thread_action['social_digg']['link'] = 'http://digg.com/submit?phase=2&title=' . $full_title . '&url=' . $full_link; |
||
679 | $thread_action['social_digg']['name'] = \_MD_NEWBB_SHARE_DIGG; |
||
680 | $thread_action['social_digg']['target'] = '_blank'; |
||
681 | |||
682 | $thread_action['social_reddit']['image'] = \newbbDisplayImage('reddit', \_MD_NEWBB_SHARE_REDDIT); |
||
683 | $thread_action['social_reddit']['link'] = 'http://reddit.com/submit?title=' . $full_title . '&url=' . $full_link; |
||
684 | $thread_action['social_reddit']['name'] = \_MD_NEWBB_SHARE_REDDIT; |
||
685 | $thread_action['social_reddit']['target'] = '_blank'; |
||
686 | |||
687 | $thread_action['social_wong']['image'] = \newbbDisplayImage('wong', \_MD_NEWBB_SHARE_MRWONG); |
||
688 | $thread_action['social_wong']['link'] = 'http://www.mister-wong.de/index.php?action=addurl&bm_url=' . $full_link; |
||
689 | $thread_action['social_wong']['name'] = \_MD_NEWBB_SHARE_MRWONG; |
||
690 | $thread_action['social_wong']['target'] = '_blank'; |
||
691 | } |
||
692 | |||
693 | $post = [ |
||
694 | 'post_id' => $post_id, |
||
695 | 'post_parent_id' => $this->getVar('pid'), |
||
696 | 'post_date' => \newbbFormatTimestamp($this->getVar('post_time')), |
||
697 | 'post_image' => $post_image, |
||
698 | 'post_title' => $post_title, |
||
699 | // irmtfan $post_title to add highlight keywords |
||
700 | 'post_text' => $post_text, |
||
701 | 'post_attachment' => $post_attachment, |
||
702 | 'post_edit' => $this->displayPostEdit(), |
||
703 | 'post_no' => $post_no, |
||
704 | 'post_signature' => $this->getVar('attachsig') ? @$poster['signature'] : '', |
||
705 | // 'poster_ip' => ($isAdmin && $GLOBALS['xoopsModuleConfig']['show_ip']) ? long2ip($this->getVar('poster_ip')) : '', |
||
706 | 'poster_ip' => ($isAdmin |
||
707 | && $GLOBALS['xoopsModuleConfig']['show_ip']) ? $this->getVar('poster_ip') : '', |
||
708 | 'thread_action' => $thread_action, |
||
709 | 'thread_buttons' => $thread_buttons, |
||
710 | 'mod_buttons' => $mod_buttons, |
||
711 | 'poster' => $poster, |
||
712 | 'post_permalink' => '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?post_id=' . $post_id . '"></a>', |
||
713 | ]; |
||
714 | |||
715 | unset($thread_buttons, $mod_buttons, $eachposter); |
||
716 | |||
717 | return $post; |
||
718 | } |
||
720 |