示例#1
0
     $post_rating = $_GET['post_rating'];
     if (!post_set_user_rating($tid, $pid, $_SESSION['UID'], $post_rating)) {
         header_status(500, 'Internal Server Error');
         exit;
     }
     if (!($message = messages_get($tid, $pid, 1))) {
         header_status(500, 'Internal Server Error');
         exit;
     }
     if (isset($_GET['mobile']) && $_GET['mobile'] == 'Y') {
         if (!($content = light_message_get_vote_form_html($message))) {
             header_status(500, 'Internal Server Error');
             exit;
         }
     } else {
         if (!($content = message_get_vote_form_html($message))) {
             header_status(500, 'Internal Server Error');
             exit;
         }
     }
     break;
 case 'poll_add_question':
     if (!session::logged_in()) {
         break;
     }
     cache_disable();
     if (!isset($_GET['question_number']) || !is_numeric($_GET['question_number'])) {
         header_status(500, 'Internal Server Error');
         exit;
     }
     if (!($content = poll_get_question_html($_GET['question_number']))) {
function message_display($tid, $message, $msg_count, $first_msg, $folder_fid, $in_list = true, $closed = false, $is_poll = false, $show_sigs = true, $is_preview = false, $highlight_array = array())
{
    $perm_is_moderator = session::check_perm(USER_PERM_FOLDER_MODERATE, $folder_fid);
    $post_edit_time = forum_get_setting('post_edit_time', null, 0);
    $post_edit_grace_period = forum_get_setting('post_edit_grace_period', null, 0);
    $webtag = get_webtag();
    forum_check_webtag_available($webtag);
    if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return;
    }
    if (isset($_SESSION['POSTS_PER_PAGE']) && is_numeric($_SESSION['POSTS_PER_PAGE'])) {
        $posts_per_page = max(min($_SESSION['POSTS_PER_PAGE'], 30), 10);
    } else {
        $posts_per_page = 20;
    }
    if (isset($_SESSION['REPLY_QUICK']) && $_SESSION['REPLY_QUICK'] == 'Y') {
        $quick_reply = 'Y';
    } else {
        $quick_reply = 'N';
    }
    if ((!isset($message['CONTENT']) || $message['CONTENT'] == '') && !$is_preview) {
        message_display_deleted($tid, isset($message['PID']) ? $message['PID'] : 0, $message, $in_list, $is_preview, $first_msg, $msg_count, $posts_per_page);
        return;
    }
    $from_user_permissions = perm_get_user_permissions($message['FROM_UID']);
    if ($_SESSION['UID'] != $message['FROM_UID']) {
        if ($from_user_permissions & USER_PERM_WORMED && !$perm_is_moderator) {
            message_display_deleted($tid, $message['PID'], $message, $in_list, $is_preview, $first_msg, $msg_count, $posts_per_page);
            return;
        }
    }
    if (!$is_preview && !isset($message['APPROVED'])) {
        message_display_approval_req($tid, $message['PID'], $in_list, $is_preview, $first_msg, $msg_count, $posts_per_page);
        return;
    }
    if (isset($message['RELATIONSHIP']) && $message['RELATIONSHIP'] & USER_IGNORED_COMPLETELY) {
        message_display_deleted($tid, $message['PID'], $message, $in_list, $is_preview, $first_msg, $msg_count, $posts_per_page);
        return;
    }
    if (isset($message['RECIPIENTS']) && sizeof($message['RECIPIENTS']) == 1) {
        $recipient = array_slice(array_values($message['RECIPIENTS']), 0, 1);
        if (isset($recipient['RELATIONSHIP']) && $recipient['RELATIONSHIP'] & USER_IGNORED_COMPLETELY) {
            message_display_deleted($tid, $message['PID'], $message, $in_list, $is_preview, $first_msg, $msg_count, $posts_per_page);
            return;
        }
    }
    if (!$is_preview && isset($message['MOVED_TID']) && isset($message['MOVED_PID'])) {
        message_display_moved($tid, $message['PID'], $message, $in_list, $is_preview, $first_msg, $msg_count, $posts_per_page);
        return;
    }
    // Add emoticons/WikiLinks and ignore signature ----------------------------
    if (isset($_SESSION['IMAGES_TO_LINKS']) && $_SESSION['IMAGES_TO_LINKS'] == 'Y') {
        $message['CONTENT'] = message_images_to_links($message['CONTENT']);
    }
    if (!$is_poll || isset($message['PID']) && $message['PID'] > 1) {
        $message['CONTENT'] = message_apply_formatting($message['CONTENT'], isset($message['RELATIONSHIP']) && ($message['RELATIONSHIP'] & USER_IGNORED_SIG) > 0 || !$show_sigs);
    }
    // Check for words that should be filtered ---------------------------------
    if (!$is_poll || isset($message['PID']) && $message['PID'] > 1) {
        $message['CONTENT'] = word_filter_add_ob_tags($message['CONTENT'], false);
    }
    if ($in_list && isset($message['PID'])) {
        echo "<a name=\"a{$tid}_{$message['PID']}\"></a>\n";
    }
    // Check for search words to highlight -------------------------------------
    if (is_array($highlight_array) && sizeof($highlight_array) > 0) {
        $highlight_pattern = sprintf('/(%s)/i', implode('|', array_map('preg_quote_callback', $highlight_array)));
        $message_parts = preg_split('/([<|>])/u', $message['CONTENT'], -1, PREG_SPLIT_DELIM_CAPTURE);
        for ($i = 0; $i < sizeof($message_parts); $i++) {
            if (!($i % 4)) {
                $message_parts[$i] = preg_replace_callback($highlight_pattern, 'search_highlight_callback', $message_parts[$i]);
            }
        }
        $message['CONTENT'] = implode("", $message_parts);
    }
    if ($in_list && isset($message['PID'])) {
        echo "<div align=\"center\" class=\"message\" id=\"message_{$tid}_{$message['PID']}\">\n";
    } else {
        echo "<div align=\"center\" class=\"message\">\n";
    }
    echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n";
    echo "  <tr>\n";
    if ($in_list && !$is_preview) {
        message_display_navigation($tid, $message['PID'], $first_msg, $msg_count, $posts_per_page);
    }
    echo "    <td align=\"center\">\n";
    echo "      <table width=\"100%\" class=\"box\" cellpadding=\"0\">\n";
    echo "        <tr>\n";
    echo "          <td align=\"left\">\n";
    echo "            <table class=\"message_posthead\" width=\"100%\">\n";
    echo "              <tr>\n";
    echo "                <td width=\"1%\" align=\"right\" style=\"white-space: nowrap\"><span class=\"posttofromlabel\">&nbsp;", gettext("From"), ":&nbsp;</span></td>\n";
    echo "                <td style=\"white-space: nowrap\" width=\"98%\" align=\"left\"><span class=\"posttofrom\">";
    if (isset($message['FROM_UID'])) {
        echo "<a href=\"user_profile.php?webtag={$webtag}&amp;uid={$message['FROM_UID']}\" target=\"_blank\" class=\"popup 650x500\">";
        echo word_filter_add_ob_tags(format_user_name($message['FROM_LOGON'], $message['FROM_NICKNAME']), true), "</a>&nbsp;</span>";
    } else {
        echo word_filter_add_ob_tags(format_user_name($message['FROM_LOGON'], $message['FROM_NICKNAME']), true), "&nbsp;</span>";
    }
    if (isset($_SESSION['SHOW_AVATARS']) && $_SESSION['SHOW_AVATARS'] == 'Y') {
        if (isset($message['AVATAR_URL']) && filter_var($message['AVATAR_URL'], FILTER_VALIDATE_URL)) {
            echo html_style_image('profile_image profile_image_small', format_user_name($message['FROM_LOGON'], $message['FROM_NICKNAME']), null, array('background-image' => sprintf("url('%s')", $message['AVATAR_URL'])));
        } else {
            if (isset($message['AVATAR_AID']) && is_numeric($message['AVATAR_AID'])) {
                $attachment = attachments_get_by_aid($message['AVATAR_AID']);
                if (($profile_picture_href = attachments_make_link($attachment, false, false, false, false)) !== false) {
                    echo html_style_image('profile_image profile_image_small', format_user_name($message['FROM_LOGON'], $message['FROM_NICKNAME']), null, array('background-image' => sprintf("url('%s&amp;profile_picture')", $profile_picture_href)));
                }
            }
        }
    }
    // If the user posting a poll is ignored, remove ignored status for this message only so the poll can be seen
    if ($is_poll && isset($message['PID']) && $message['PID'] == 1 && (isset($message['RELATIONSHIP']) && $message['RELATIONSHIP'] & USER_IGNORED)) {
        $message['RELATIONSHIP'] -= USER_IGNORED;
    }
    if (isset($message['RELATIONSHIP']) && $message['RELATIONSHIP'] & USER_FRIEND) {
        echo "", html_style_image('friend', gettext("Friend")), "&nbsp;";
    } else {
        if (isset($message['RELATIONSHIP']) && $message['RELATIONSHIP'] & USER_IGNORED) {
            echo "", html_style_image('enemy', gettext("Ignored user")), "&nbsp;";
        }
    }
    if (isset($message['ANON_LOGON']) && $message['ANON_LOGON'] > USER_ANON_DISABLED || !isset($message['USER_ACTIVE']) || is_null($message['USER_ACTIVE'])) {
        echo html_style_image('status_offline', gettext("Inactive / Offline")), "&nbsp;";
    } else {
        echo html_style_image('status_online', gettext("Online")), "&nbsp;";
    }
    if (isset($message['FROM_UID']) && isset($message['THREAD_BY_UID']) && $message['FROM_UID'] == $message['THREAD_BY_UID'] && $first_msg > 1) {
        echo html_style_image('thread_starter', gettext("Thread Starter")), "&nbsp;";
    }
    echo "</td>\n";
    echo "                <td width=\"1%\" align=\"right\" style=\"white-space: nowrap\"><span class=\"postinfo\">";
    if (!$is_preview && $_SESSION['UID'] > 0 && isset($message['RELATIONSHIP']) && $message['RELATIONSHIP'] & USER_IGNORED) {
        echo "<b>", gettext("Ignored message"), "</b>";
    } else {
        if ($in_list) {
            if ($from_user_permissions & USER_PERM_WORMED) {
                echo "<b>", gettext("Wormed user"), "</b> ";
            }
            if (isset($message['RELATIONSHIP']) && $message['RELATIONSHIP'] & USER_IGNORED_SIG) {
                echo "<b>", gettext("Ignored signature"), "</b> ";
            }
            echo format_date_time($message['CREATED']);
        }
    }
    echo "&nbsp;</span></td>\n";
    echo "              </tr>\n";
    echo "              <tr>\n";
    echo "                <td width=\"1%\" align=\"right\" style=\"white-space: nowrap\"><span class=\"posttofromlabel\">&nbsp;", gettext("To"), ":&nbsp;</span></td>\n";
    echo "                <td style=\"white-space: nowrap\" width=\"98%\" align=\"left\">";
    if (isset($message['RECIPIENTS']) && sizeof($message['RECIPIENTS']) > 0) {
        foreach ($message['RECIPIENTS'] as $recipient) {
            if (isset($recipient['RELATIONSHIP']) && $recipient['RELATIONSHIP'] & USER_IGNORED_COMPLETELY) {
                continue;
            }
            echo "<span class=\"posttofrom\"><a href=\"user_profile.php?webtag={$webtag}&amp;uid={$recipient['UID']}\" target=\"_blank\" class=\"popup 650x500\">";
            echo word_filter_add_ob_tags(format_user_name($recipient['LOGON'], $recipient['NICKNAME']), true), "</a>&nbsp;</span>\n";
            if (isset($_SESSION['SHOW_AVATARS']) && $_SESSION['SHOW_AVATARS'] == 'Y') {
                if (isset($recipient['AVATAR_URL']) && filter_var($recipient['AVATAR_URL'], FILTER_VALIDATE_URL)) {
                    echo html_style_image('profile_image profile_image_small', format_user_name($recipient['LOGON'], $recipient['NICKNAME']), null, array('background-image' => sprintf("url('%s')", $recipient['AVATAR_URL'])));
                } else {
                    if (isset($recipient['AVATAR_AID']) && is_numeric($recipient['AVATAR_AID'])) {
                        $attachment = attachments_get_by_aid($recipient['AVATAR_AID']);
                        if (($profile_picture_href = attachments_make_link($attachment, false, false, false, false)) !== false) {
                            echo html_style_image('profile_image profile_image_small', format_user_name($recipient['LOGON'], $recipient['NICKNAME']), null, array('background-image' => sprintf("url('%s&amp;profile_picture')", $profile_picture_href)));
                        }
                    }
                }
            }
            if (isset($recipient['ANON_LOGON']) && $recipient['ANON_LOGON'] > USER_ANON_DISABLED || !isset($recipient['USER_ACTIVE']) || is_null($recipient['USER_ACTIVE'])) {
                echo html_style_image('status_offline', gettext("Inactive / Offline")), "&nbsp;";
            } else {
                echo html_style_image('status_online', gettext("Online")), "&nbsp;";
            }
            if (isset($recipient['UID']) && isset($message['THREAD_BY_UID']) && $recipient['UID'] == $message['THREAD_BY_UID'] && $first_msg > 1) {
                echo html_style_image('thread_starter', gettext("Thread Starter")), "&nbsp;";
            }
            if (isset($recipient['VIEWED']) && $recipient['VIEWED'] > 0) {
                echo html_style_image('post_read', sprintf(gettext("Read: %s"), format_date_time($recipient['VIEWED']))), "&nbsp;&nbsp;";
            } else {
                if ($is_preview == false) {
                    echo html_style_image('post_unread', gettext("Unread Message")), "&nbsp;&nbsp;";
                } else {
                    echo "&nbsp;&nbsp;";
                }
            }
        }
    } else {
        echo gettext('ALL');
    }
    echo "</span></td>\n";
    echo "                <td align=\"right\" style=\"white-space: nowrap\"><span class=\"postinfo\">";
    if (!$is_preview && $_SESSION['UID'] > 0 && isset($message['RELATIONSHIP']) && $message['RELATIONSHIP'] & USER_IGNORED) {
        echo "<a href=\"user_rel.php?webtag={$webtag}&amp;uid={$message['FROM_UID']}&amp;msg={$tid}.{$message['PID']}\" target=\"_self\">", gettext("Stop ignoring this user"), "</a>&nbsp;&nbsp;&nbsp;";
        echo "<a href=\"display.php?webtag={$webtag}&amp;msg={$tid}.{$message['PID']}&amp;return_msg={$tid}.{$first_msg}\" target=\"_self\">", gettext("View Message"), "</a>";
    } else {
        if ($in_list && $msg_count > 0) {
            if ($is_poll) {
                echo "<a href=\"poll_results.php?webtag={$webtag}&amp;tid={$tid}\" target=\"_blank\" class=\"popup 800x600\">", html_style_image('poll', "This is a poll. Click to view results."), "</a> ", gettext("Poll"), " ";
            }
            echo sprintf(gettext("%s of %s"), $message['PID'], $msg_count);
        }
    }
    echo "&nbsp;</span></td>\n";
    echo "              </tr>\n";
    echo "            </table>\n";
    echo "          </td>\n";
    echo "        </tr>\n";
    if ($is_preview || !isset($message['RELATIONSHIP']) || !($message['RELATIONSHIP'] & USER_IGNORED)) {
        echo "        <tr>\n";
        echo "          <td align=\"left\">\n";
        echo "            <table class=\"message_postbody\" width=\"100%\">\n";
        echo "              <tr>\n";
        echo "                <td colspan=\"3\" align=\"right\"><span class=\"postnumber\">";
        if ($in_list && $msg_count > 0) {
            $title = $message['PID'] == 1 ? "" . gettext("Permanent link to this thread") . " ({$tid}.1)" : "" . gettext("Link to this post");
            if ($is_preview) {
                echo "<a href=\"messages.php?webtag={$webtag}&amp;msg={$tid}.{$message['PID']}\" target=\"_blank\" title=\"{$title}\">{$tid}.{$message['PID']}</a>";
            } else {
                echo "<a href=\"index.php?webtag={$webtag}&amp;msg={$tid}.{$message['PID']}\" target=\"", html_get_top_frame_name(), "\" title=\"{$title}\">{$tid}.{$message['PID']}</a>";
            }
            if ($message['REPLY_TO_PID'] > 0) {
                $title = "" . gettext("Link to post") . " #{$message['REPLY_TO_PID']}";
                echo " ", gettext("In reply to"), " ";
                if (intval($message['REPLY_TO_PID']) >= intval($first_msg)) {
                    echo "<a href=\"#a{$tid}_{$message['REPLY_TO_PID']}\" target=\"_self\" title=\"{$title}\">";
                    echo "{$tid}.{$message['REPLY_TO_PID']}</a>";
                } else {
                    if ($is_preview) {
                        echo "<a href=\"messages.php?webtag={$webtag}&amp;msg={$tid}.{$message['REPLY_TO_PID']}\" target=\"_blank\" title=\"{$title}\">";
                        echo "{$tid}.{$message['REPLY_TO_PID']}</a>";
                    } else {
                        echo "<a href=\"messages.php?webtag={$webtag}&amp;msg={$tid}.{$message['REPLY_TO_PID']}\" target=\"_self\" title=\"{$title}\">";
                        echo "{$tid}.{$message['REPLY_TO_PID']}</a>";
                    }
                }
            }
        }
        echo "&nbsp;</span></td>\n";
        echo "              </tr>\n";
        echo "              <tr>\n";
        echo "                <td class=\"postbody overflow_content\" align=\"left\">{$message['CONTENT']}</td>\n";
        echo "              </tr>\n";
        if (!$is_preview && isset($message['EDITED'])) {
            if ($post_edit_grace_period == 0 || $message['EDITED'] - $message['CREATED'] > $post_edit_grace_period * MINUTE_IN_SECONDS) {
                if (($edit_user = user_get_logon($message['EDITED_BY'])) !== false) {
                    echo "              <tr>\n";
                    echo "                <td class=\"postbody\" align=\"left\"><p class=\"edit_text\">", sprintf(gettext("EDITED: %s by %s"), format_date_time($message['EDITED']), $edit_user), "</p></td>\n";
                    echo "              </tr>\n";
                }
            }
        }
        if (!$is_preview && isset($message['APPROVED']) && isset($message['APPROVED_BY'])) {
            if ($message['APPROVED_BY'] != $message['FROM_UID'] && ($approved_user = user_get_logon($message['APPROVED_BY'])) !== false) {
                echo "              <tr>\n";
                echo "                <td class=\"postbody\" align=\"left\"><p class=\"approved_text\">", sprintf(gettext("APPROVED: %s by %s"), format_date_time($message['APPROVED']), $approved_user), "</p></td>\n";
                echo "              </tr>\n";
            }
        }
        if (isset($message['ATTACHMENTS']) && sizeof($message['ATTACHMENTS']) > 0) {
            if (($attachments_array = attachments_get($message['FROM_UID'], $message['ATTACHMENTS'])) !== false) {
                echo "              <tr>\n";
                echo "                <td class=\"postbody\" align=\"left\">\n";
                echo "                  <p><b>", gettext("Attachments"), ":</b><br />\n";
                foreach ($attachments_array as $attachment) {
                    echo attachments_make_link($attachment), $attachment['thumbnail'] == 'N' ? "<br />\n" : "\n";
                }
                echo "                  </p>\n";
                echo "                </td>\n";
                echo "              </tr>\n";
            }
        }
        echo "            </table>\n";
        if (!$is_preview) {
            echo "            <table width=\"100%\" class=\"postresponse\" cellspacing=\"1\" cellpadding=\"0\">\n";
            echo "              <tr>\n";
            echo "                <td align=\"left\" width=\"25%\">";
            echo "                  <div class=\"message_vote_form\" data-msg=\"{$tid}.{$message['PID']}\">\n";
            echo "                    ", message_get_vote_form_html($message), "\n";
            echo "                  </div>\n";
            echo "                </td>\n";
            echo "                <td width=\"50%\" style=\"white-space: nowrap\">";
            if ($msg_count > 0) {
                if (!$closed && session::check_perm(USER_PERM_POST_CREATE, $folder_fid) || $perm_is_moderator) {
                    if ($quick_reply == 'Y') {
                        echo "", html_style_image('quick_reply', "Quick Reply"), "\n";
                        echo "<a href=\"Javascript:void(0)\" data-msg=\"{$tid}.{$message['PID']}\" target=\"_self\" class=\"quick_reply_link\">", gettext("Quick Reply"), "</a>\n";
                    } else {
                        echo "", html_style_image('post', "Reply"), "";
                        echo "&nbsp;<a href=\"post.php?webtag={$webtag}&amp;reply_to={$tid}.{$message['PID']}&amp;return_msg={$tid}.{$first_msg}\" target=\"_parent\" id=\"reply_{$message['PID']}\">", gettext("Reply"), "</a>";
                    }
                    echo "&nbsp;&nbsp;", html_style_image('quote_disabled', gettext("Quote"), "quote_img_{$message['PID']}");
                    echo "&nbsp;<a href=\"post.php?webtag={$webtag}&amp;reply_to={$tid}.{$message['PID']}&amp;quote_list={$message['PID']}&amp;return_msg={$tid}.{$first_msg}\" target=\"_parent\" title=\"", gettext("Quote"), "\" id=\"quote_{$message['PID']}\" data-pid=\"{$message['PID']}\">", gettext("Quote"), "</a>";
                    if (!session::check_perm(USER_PERM_PILLORIED, 0) && ($_SESSION['UID'] != $message['FROM_UID'] && $from_user_permissions & USER_PERM_PILLORIED || $_SESSION['UID'] == $message['FROM_UID']) && session::check_perm(USER_PERM_POST_EDIT, $folder_fid) && ($post_edit_time == 0 || time() - $message['CREATED'] < $post_edit_time * HOUR_IN_SECONDS) && forum_get_setting('allow_post_editing', 'Y') || $perm_is_moderator) {
                        if ($is_poll && $message['PID'] == 1) {
                            if (!poll_is_closed($tid) || $perm_is_moderator) {
                                echo "&nbsp;&nbsp;", html_style_image('edit', "Edit Poll"), "";
                                echo "&nbsp;<a href=\"edit_poll.php?webtag={$webtag}&amp;msg={$tid}.{$message['PID']}&amp;return_msg={$tid}.{$first_msg}\" target=\"_parent\">", gettext("Edit Poll"), "</a>\n";
                            }
                        } else {
                            echo "&nbsp;&nbsp;", html_style_image('edit', "Edit"), "";
                            echo "&nbsp;<a href=\"edit.php?webtag={$webtag}&amp;msg={$tid}.{$message['PID']}&amp;return_msg={$tid}.{$first_msg}\" target=\"_parent\">", gettext("Edit"), "</a>";
                        }
                    }
                }
            } else {
                echo "&nbsp;";
            }
            echo "</td>\n";
            echo "                <td align=\"right\" style=\"white-space: nowrap\">\n";
            echo "                  <span class=\"post_options\" id=\"post_options_{$tid}_{$first_msg}_{$message['PID']}\">\n";
            echo "                    ", gettext("More"), "&nbsp;", html_style_image('post_options', gettext("More"), 'post_options'), "\n";
            echo "                  </span>\n";
            echo "                </td>\n";
            echo "              </tr>";
            echo "            </table>\n";
        } else {
            echo "            <table width=\"100%\" class=\"postresponse\" cellspacing=\"1\" cellpadding=\"0\">\n";
            echo "              <tr>\n";
            echo "                <td>&nbsp;</td>\n";
            echo "              </tr>\n";
            echo "            </table>\n";
        }
    }
    echo "            </td>\n";
    echo "          </tr>\n";
    echo "        </table>\n";
    echo "      </td>\n";
    if ($in_list && !$is_preview) {
        message_display_navigation($tid, $message['PID'], $first_msg, $msg_count, $posts_per_page);
    }
    echo "    </tr>\n";
    echo "  </table>\n";
    if ($in_list && isset($message['PID'])) {
        echo "  <div id=\"quick_reply_{$message['PID']}\"></div>\n";
    }
    echo "</div>\n";
    echo $in_list ? "<br />\n" : '';
}