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