Conditions | 110 |
Paths | 0 |
Total Lines | 444 |
Code Lines | 207 |
Lines | 0 |
Ratio | 0 % |
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 |
||
463 | function template_single_post($message) |
||
464 | { |
||
465 | global $context, $settings, $options, $txt, $scripturl, $modSettings; |
||
466 | |||
467 | $ignoring = false; |
||
468 | |||
469 | if ($message['can_remove']) |
||
470 | $context['removableMessageIDs'][] = $message['id']; |
||
471 | |||
472 | // Are we ignoring this message? |
||
473 | if (!empty($message['is_ignored'])) |
||
474 | { |
||
475 | $ignoring = true; |
||
476 | $context['ignoredMsgs'][] = $message['id']; |
||
477 | } |
||
478 | |||
479 | // Show the message anchor and a "new" anchor if this message is new. |
||
480 | echo ' |
||
481 | <div class="', $message['css_class'], '" id="msg' . $message['id'] . '"> |
||
482 | ', $message['id'] != $context['first_message'] ? ' |
||
483 | ' . ($message['first_new'] ? '<a id="new"></a>' : '') : '', ' |
||
484 | <div class="post_wrapper">'; |
||
485 | |||
486 | // Show information about the poster of this message. |
||
487 | echo ' |
||
488 | <div class="poster">'; |
||
489 | |||
490 | // Are there any custom fields above the member name? |
||
491 | if (!empty($message['custom_fields']['above_member'])) |
||
492 | { |
||
493 | echo ' |
||
494 | <div class="custom_fields_above_member"> |
||
495 | <ul class="nolist">'; |
||
496 | |||
497 | foreach ($message['custom_fields']['above_member'] as $custom) |
||
498 | echo ' |
||
499 | <li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>'; |
||
500 | |||
501 | echo ' |
||
502 | </ul> |
||
503 | </div>'; |
||
504 | } |
||
505 | |||
506 | echo ' |
||
507 | <h4>'; |
||
508 | |||
509 | // Show online and offline buttons? |
||
510 | if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) |
||
511 | echo ' |
||
512 | ', $context['can_send_pm'] ? '<a href="' . $message['member']['online']['href'] . '" title="' . $message['member']['online']['label'] . '">' : '', '<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>', $context['can_send_pm'] ? '</a>' : ''; |
||
513 | |||
514 | // Custom fields BEFORE the username? |
||
515 | if (!empty($message['custom_fields']['before_member'])) |
||
516 | foreach ($message['custom_fields']['before_member'] as $custom) |
||
517 | echo ' |
||
518 | <span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>'; |
||
519 | |||
520 | // Show a link to the member's profile. |
||
521 | echo ' |
||
522 | ', $message['member']['link']; |
||
523 | |||
524 | // Custom fields AFTER the username? |
||
525 | if (!empty($message['custom_fields']['after_member'])) |
||
526 | foreach ($message['custom_fields']['after_member'] as $custom) |
||
527 | echo ' |
||
528 | <span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>'; |
||
529 | |||
530 | // Begin display of user info |
||
531 | echo ' |
||
532 | </h4> |
||
533 | <ul class="user_info">'; |
||
534 | |||
535 | // Show the member's custom title, if they have one. |
||
536 | if (!empty($message['member']['title'])) |
||
537 | echo ' |
||
538 | <li class="title">', $message['member']['title'], '</li>'; |
||
539 | |||
540 | // Show the member's primary group (like 'Administrator') if they have one. |
||
541 | if (!empty($message['member']['group'])) |
||
542 | echo ' |
||
543 | <li class="membergroup">', $message['member']['group'], '</li>'; |
||
544 | |||
545 | // Show the user's avatar. |
||
546 | if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) |
||
547 | echo ' |
||
548 | <li class="avatar"> |
||
549 | <a href="', $message['member']['href'], '">', $message['member']['avatar']['image'], '</a> |
||
550 | </li>'; |
||
551 | |||
552 | // Are there any custom fields below the avatar? |
||
553 | if (!empty($message['custom_fields']['below_avatar'])) |
||
554 | foreach ($message['custom_fields']['below_avatar'] as $custom) |
||
555 | echo ' |
||
556 | <li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>'; |
||
557 | |||
558 | // Don't show these things for guests. |
||
559 | if (!$message['member']['is_guest']) |
||
560 | { |
||
561 | // Show the post group icons |
||
562 | echo ' |
||
563 | <li class="icons">', $message['member']['group_icons'], '</li>'; |
||
564 | |||
565 | // Show the post group if and only if they have no other group or the option is on, and they are in a post group. |
||
566 | if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group'])) |
||
567 | echo ' |
||
568 | <li class="postgroup">', $message['member']['post_group'], '</li>'; |
||
569 | |||
570 | // Show how many posts they have made. |
||
571 | if (!isset($context['disabled_fields']['posts'])) |
||
572 | echo ' |
||
573 | <li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>'; |
||
574 | |||
575 | // Show their personal text? |
||
576 | if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb'])) |
||
577 | echo ' |
||
578 | <li class="blurb">', $message['member']['blurb'], '</li>'; |
||
579 | |||
580 | // Any custom fields to show as icons? |
||
581 | if (!empty($message['custom_fields']['icons'])) |
||
582 | { |
||
583 | echo ' |
||
584 | <li class="im_icons"> |
||
585 | <ol>'; |
||
586 | |||
587 | foreach ($message['custom_fields']['icons'] as $custom) |
||
588 | echo ' |
||
589 | <li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>'; |
||
590 | |||
591 | echo ' |
||
592 | </ol> |
||
593 | </li>'; |
||
594 | } |
||
595 | |||
596 | // Show the website and email address buttons. |
||
597 | if ($message['member']['show_profile_buttons']) |
||
598 | { |
||
599 | echo ' |
||
600 | <li class="profile"> |
||
601 | <ol class="profile_icons">'; |
||
602 | |||
603 | // Don't show an icon if they haven't specified a website. |
||
604 | if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website'])) |
||
605 | echo ' |
||
606 | <li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="main_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>'; |
||
607 | |||
608 | // Since we know this person isn't a guest, you *can* message them. |
||
609 | if ($context['can_send_pm']) |
||
610 | echo ' |
||
611 | <li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="main_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>'; |
||
612 | |||
613 | // Show the email if necessary |
||
614 | if (!empty($message['member']['email']) && $message['member']['show_email']) |
||
615 | echo ' |
||
616 | <li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="main_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>'; |
||
617 | |||
618 | echo ' |
||
619 | </ol> |
||
620 | </li><!-- .profile -->'; |
||
621 | } |
||
622 | |||
623 | // Any custom fields for standard placement? |
||
624 | if (!empty($message['custom_fields']['standard'])) |
||
625 | foreach ($message['custom_fields']['standard'] as $custom) |
||
626 | echo ' |
||
627 | <li class="custom ', $custom['col_name'], '">', $custom['title'], ': ', $custom['value'], '</li>'; |
||
628 | } |
||
629 | // Otherwise, show the guest's email. |
||
630 | elseif (!empty($message['member']['email']) && $message['member']['show_email']) |
||
631 | echo ' |
||
632 | <li class="email"> |
||
633 | <a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="main_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a> |
||
634 | </li>'; |
||
635 | |||
636 | // Show the IP to this user for this post - because you can moderate? |
||
637 | if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) |
||
638 | echo ' |
||
639 | <li class="poster_ip"> |
||
640 | <a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '" data-hover="', $message['member']['ip'], '" class="show_on_hover"><span>', $txt['show_ip'], '</span></a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a> |
||
641 | </li>'; |
||
642 | |||
643 | // Or, should we show it because this is you? |
||
644 | elseif ($message['can_see_ip']) |
||
645 | echo ' |
||
646 | <li class="poster_ip"> |
||
647 | <a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help show_on_hover" data-hover="', $message['member']['ip'], '"><span>', $txt['show_ip'], '</span></a> |
||
648 | </li>'; |
||
649 | |||
650 | // Okay, are you at least logged in? Then we can show something about why IPs are logged... |
||
651 | elseif (!$context['user']['is_guest']) |
||
652 | echo ' |
||
653 | <li class="poster_ip"> |
||
654 | <a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a> |
||
655 | </li>'; |
||
656 | |||
657 | // Otherwise, you see NOTHING! |
||
658 | else |
||
659 | echo ' |
||
660 | <li class="poster_ip">', $txt['logged'], '</li>'; |
||
661 | |||
662 | // Are we showing the warning status? |
||
663 | // Don't show these things for guests. |
||
664 | if (!$message['member']['is_guest'] && $message['member']['can_see_warning']) |
||
665 | echo ' |
||
666 | <li class="warning"> |
||
667 | ', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="main_icons warning_', $message['member']['warning_status'], '"></span> ', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span> |
||
668 | </li>'; |
||
669 | |||
670 | // Are there any custom fields to show at the bottom of the poster info? |
||
671 | if (!empty($message['custom_fields']['bottom_poster'])) |
||
672 | foreach ($message['custom_fields']['bottom_poster'] as $custom) |
||
673 | echo ' |
||
674 | <li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>'; |
||
675 | |||
676 | // Poster info ends. |
||
677 | echo ' |
||
678 | </ul> |
||
679 | </div><!-- .poster --> |
||
680 | <div class="postarea"> |
||
681 | <div class="keyinfo">'; |
||
682 | |||
683 | // Some people don't want subject... The div is still required or quick edit breaks. |
||
684 | echo ' |
||
685 | <div id="subject_', $message['id'], '" class="subject_title', (empty($modSettings['subject_toggle']) ? ' subject_hidden' : ''), '"> |
||
686 | ', $message['link'], ' |
||
687 | </div>'; |
||
688 | |||
689 | echo ' |
||
690 | ', !empty($message['counter']) ? '<span class="page_number floatright">#' . $message['counter'] . '</span>' : '', ' |
||
691 | <div class="postinfo"> |
||
692 | <span class="messageicon" ', ($message['icon_url'] === $settings['images_url'] . '/post/xx.png' && !$message['can_modify']) ? ' style="position: absolute; z-index: -1;"' : '', '> |
||
693 | <img src="', $message['icon_url'] . '" alt=""', $message['can_modify'] ? ' id="msg_icon_' . $message['id'] . '"' : '', '> |
||
694 | </span> |
||
695 | <a href="', $message['href'], '" rel="nofollow" title="', !empty($message['counter']) ? sprintf($txt['reply_number'], $message['counter'], ' - ') : '', $message['subject'], '" class="smalltext">', $message['time'], '</a> |
||
696 | <span class="spacer"></span>'; |
||
697 | |||
698 | // Show "<< Last Edit: Time by Person >>" if this post was edited. But we need the div even if it wasn't modified! |
||
699 | // Because we insert into it through AJAX and we don't want to stop themers moving it around if they so wish so they can put it where they want it. |
||
700 | echo ' |
||
701 | <span class="smalltext modified floatright', !empty($modSettings['show_modify']) && !empty($message['modified']['name']) ? ' mvisible' : '', '" id="modified_', $message['id'], '">'; |
||
702 | |||
703 | if (!empty($modSettings['show_modify']) && !empty($message['modified']['name'])) |
||
704 | echo |
||
705 | $message['modified']['last_edit_text']; |
||
706 | |||
707 | echo ' |
||
708 | </span> |
||
709 | </div> |
||
710 | <div id="msg_', $message['id'], '_quick_mod"', $ignoring ? ' style="display:none;"' : '', '></div> |
||
711 | </div><!-- .keyinfo -->'; |
||
712 | |||
713 | // Ignoring this user? Hide the post. |
||
714 | if ($ignoring) |
||
715 | echo ' |
||
716 | <div id="msg_', $message['id'], '_ignored_prompt" class="noticebox"> |
||
717 | ', $txt['ignoring_user'], ' |
||
718 | <a href="#" id="msg_', $message['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a> |
||
719 | </div>'; |
||
720 | |||
721 | // Show the post itself, finally! |
||
722 | echo ' |
||
723 | <div class="post">'; |
||
724 | |||
725 | if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id']) |
||
726 | echo ' |
||
727 | <div class="noticebox"> |
||
728 | ', $txt['post_awaiting_approval'], ' |
||
729 | </div>'; |
||
730 | echo ' |
||
731 | <div class="inner" data-msgid="', $message['id'], '" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '> |
||
732 | ', $message['body'], ' |
||
733 | </div> |
||
734 | </div><!-- .post -->'; |
||
735 | |||
736 | // Assuming there are attachments... |
||
737 | if (!empty($message['attachment'])) |
||
738 | { |
||
739 | $last_approved_state = 1; |
||
740 | // Don't output the div unless we actually have something to show... |
||
741 | $div_output = false; |
||
742 | |||
743 | foreach ($message['attachment'] as $attachment) |
||
744 | { |
||
745 | // Do we want this attachment to not be showed here? |
||
746 | if ($attachment['is_approved'] && !empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']])) |
||
747 | continue; |
||
748 | elseif (!$div_output) |
||
749 | { |
||
750 | $div_output = true; |
||
751 | |||
752 | echo ' |
||
753 | <div id="msg_', $message['id'], '_footer" class="attachments"', $ignoring ? ' style="display:none;"' : '', '>'; |
||
754 | } |
||
755 | |||
756 | // Show a special box for unapproved attachments... |
||
757 | if ($attachment['is_approved'] != $last_approved_state) |
||
758 | { |
||
759 | $last_approved_state = 0; |
||
760 | echo ' |
||
761 | <fieldset> |
||
762 | <legend> |
||
763 | ', $txt['attach_awaiting_approve']; |
||
764 | |||
765 | if ($context['can_approve']) |
||
766 | echo ' |
||
767 | [<a href="', $scripturl, '?action=attachapprove;sa=all;mid=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve_all'], '</a>]'; |
||
768 | |||
769 | echo ' |
||
770 | </legend>'; |
||
771 | } |
||
772 | |||
773 | echo ' |
||
774 | <div class="attached">'; |
||
775 | |||
776 | if ($attachment['is_image'] && !empty($modSettings['attachmentShowImages'])) |
||
777 | { |
||
778 | echo ' |
||
779 | <div class="attachments_top">'; |
||
780 | |||
781 | if ($attachment['thumbnail']['has_thumb']) |
||
782 | echo ' |
||
783 | <a href="', $attachment['href'], ';image" id="link_', $attachment['id'], '" onclick="', $attachment['thumbnail']['javascript'], '"><img src="', $attachment['thumbnail']['href'], '" alt="" id="thumb_', $attachment['id'], '" class="atc_img"></a>'; |
||
784 | else |
||
785 | echo ' |
||
786 | <img src="' . $attachment['href'] . ';image" alt="" loading="lazy" class="atc_img">'; |
||
787 | |||
788 | echo ' |
||
789 | </div><!-- .attachments_top -->'; |
||
790 | } |
||
791 | |||
792 | echo ' |
||
793 | <div class="attachments_bot"> |
||
794 | <a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.png" class="centericon" alt="*"> ' . $attachment['name'] . '</a> '; |
||
795 | |||
796 | if (!$attachment['is_approved'] && $context['can_approve']) |
||
797 | echo ' |
||
798 | [<a href="', $scripturl, '?action=attachapprove;sa=approve;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve'], '</a>] [<a href="', $scripturl, '?action=attachapprove;sa=reject;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['delete'], '</a>] '; |
||
799 | echo ' |
||
800 | <br>', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . '<br>' . sprintf($txt['attach_viewed'], $attachment['downloads']) : '<br>' . sprintf($txt['attach_downloaded'], $attachment['downloads'])), ' |
||
801 | </div><!-- .attachments_bot -->'; |
||
802 | |||
803 | echo ' |
||
804 | </div><!-- .attached -->'; |
||
805 | } |
||
806 | |||
807 | // If we had unapproved attachments clean up. |
||
808 | if ($last_approved_state == 0) |
||
809 | echo ' |
||
810 | </fieldset>'; |
||
811 | |||
812 | // Only do this if we output a div above - otherwise it'll break things |
||
813 | if ($div_output) |
||
814 | echo ' |
||
815 | </div><!-- #msg_[id]_footer -->'; |
||
816 | } |
||
817 | |||
818 | echo ' |
||
819 | <div class="under_message">'; |
||
820 | |||
821 | // What about likes? |
||
822 | if (!empty($modSettings['enable_likes'])) |
||
823 | { |
||
824 | echo ' |
||
825 | <ul class="floatleft">'; |
||
826 | |||
827 | if (!empty($message['likes']['can_like'])) |
||
828 | { |
||
829 | echo ' |
||
830 | <li class="smflikebutton" id="msg_', $message['id'], '_likes"', $ignoring ? ' style="display:none;"' : '', '> |
||
831 | <a href="', $scripturl, '?action=likes;ltype=msg;sa=like;like=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '" class="msg_like"><span class="main_icons ', $message['likes']['you'] ? 'unlike' : 'like', '"></span> ', $message['likes']['you'] ? $txt['unlike'] : $txt['like'], '</a> |
||
832 | </li>'; |
||
833 | } |
||
834 | |||
835 | if (!empty($message['likes']['count'])) |
||
836 | { |
||
837 | $context['some_likes'] = true; |
||
838 | $count = $message['likes']['count']; |
||
839 | $base = 'likes_'; |
||
840 | |||
841 | if ($message['likes']['you']) |
||
842 | { |
||
843 | $base = 'you_' . $base; |
||
844 | $count--; |
||
845 | } |
||
846 | |||
847 | $base .= (isset($txt[$base . $count])) ? $count : 'n'; |
||
848 | |||
849 | echo ' |
||
850 | <li class="like_count smalltext"> |
||
851 | ', sprintf($txt[$base], $scripturl . '?action=likes;sa=view;ltype=msg;like=' . $message['id'] . ';' . $context['session_var'] . '=' . $context['session_id'], comma_format($count)), ' |
||
852 | </li>'; |
||
853 | } |
||
854 | |||
855 | echo ' |
||
856 | </ul>'; |
||
857 | } |
||
858 | |||
859 | // Show the quickbuttons, for various operations on posts. |
||
860 | template_quickbuttons($message['quickbuttons'], 'post'); |
||
861 | |||
862 | echo ' |
||
863 | </div><!-- .under_message --> |
||
864 | </div><!-- .postarea --> |
||
865 | <div class="moderatorbar">'; |
||
866 | |||
867 | // Are there any custom profile fields for above the signature? |
||
868 | if (!empty($message['custom_fields']['above_signature'])) |
||
869 | { |
||
870 | echo ' |
||
871 | <div class="custom_fields_above_signature"> |
||
872 | <ul class="nolist">'; |
||
873 | |||
874 | foreach ($message['custom_fields']['above_signature'] as $custom) |
||
875 | echo ' |
||
876 | <li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>'; |
||
877 | |||
878 | echo ' |
||
879 | </ul> |
||
880 | </div>'; |
||
881 | } |
||
882 | |||
883 | // Show the member's signature? |
||
884 | if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) |
||
885 | echo ' |
||
886 | <div class="signature" id="msg_', $message['id'], '_signature"', $ignoring ? ' style="display:none;"' : '', '> |
||
887 | ', $message['member']['signature'], ' |
||
888 | </div>'; |
||
889 | |||
890 | // Are there any custom profile fields for below the signature? |
||
891 | if (!empty($message['custom_fields']['below_signature'])) |
||
892 | { |
||
893 | echo ' |
||
894 | <div class="custom_fields_below_signature"> |
||
895 | <ul class="nolist">'; |
||
896 | |||
897 | foreach ($message['custom_fields']['below_signature'] as $custom) |
||
898 | echo ' |
||
899 | <li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>'; |
||
900 | |||
901 | echo ' |
||
902 | </ul> |
||
903 | </div>'; |
||
904 | } |
||
905 | |||
906 | echo ' |
||
907 | </div><!-- .moderatorbar --> |
||
1060 | ?> |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.