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