function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
{
    global $_CLASS, $_CORE_CONFIG, $site_file_root, $config;
    $_CLASS['core_user']->add_lang('viewtopic');
    $msg_id = (int) $msg_id;
    $folder_id = (int) $folder_id;
    $author_id = (int) $message_row['author_id'];
    // Not able to view message, it was deleted by the sender
    if ($message_row['deleted']) {
        trigger_error('NO_AUTH_READ_REMOVED_MESSAGE');
    }
    // Grab icons
    $icons = array();
    obtain_icons($icons);
    // Instantiate BBCode if need be
    if ($message_row['bbcode_bitfield']) {
        require $site_file_root . 'includes/forums/bbcode.php';
        $bbcode = new bbcode($message_row['bbcode_bitfield']);
    }
    // Assign TO/BCC Addresses to template
    write_pm_addresses(array('to' => $message_row['to_address'], 'bcc' => $message_row['bcc_address']), $author_id);
    $user_info = get_user_informations($author_id, $message_row);
    // Parse the message and subject
    $message = $message_row['message_text'];
    // If the board has HTML off but the message has HTML on then we process it, else leave it alone
    if ($message_row['enable_html'] && (!$config['auth_html_pm'] || !$_CLASS['auth']->acl_get('u_pm_html'))) {
        $message = preg_replace('#(<!\\-\\- h \\-\\-><)([\\/]?.*?)(><!\\-\\- h \\-\\->)#is', "&lt;\\2&gt;", $message);
    }
    // Second parse bbcode here
    if ($message_row['bbcode_bitfield']) {
        $bbcode->bbcode_second_pass($message, $message_row['bbcode_uid'], $message_row['bbcode_bitfield']);
    }
    // Always process smilies after parsing bbcodes
    $message = smiley_text($message);
    // Replace naughty words such as farty pants
    $message_row['message_subject'] = censor_text($message_row['message_subject']);
    $message = str_replace("\n", '<br />', censor_text($message));
    // Editing information
    if ($message_row['message_edit_count'] && $config['display_last_edited']) {
        $l_edit_time_total = $message_row['message_edit_count'] == 1 ? $_CLASS['core_user']->lang['EDITED_TIME_TOTAL'] : $_CLASS['core_user']->lang['EDITED_TIMES_TOTAL'];
        $l_edited_by = '<br /><br />' . sprintf($l_edit_time_total, !$message_row['message_edit_user'] ? $message_row['username'] : $message_row['message_edit_user'], $_CLASS['core_user']->format_date($message_row['message_edit_time']), $message_row['message_edit_count']);
    } else {
        $l_edited_by = '';
    }
    // Pull attachment data
    $display_notice = false;
    $attachments = array();
    if ($message_row['message_attachment'] && $config['allow_pm_attach']) {
        if ($config['auth_download_pm'] && $_CLASS['auth']->acl_get('u_pm_download')) {
            require $site_file_root . 'includes/forums/functions_display.php';
            $sql = 'SELECT * 
				FROM ' . FORUMS_ATTACHMENTS_TABLE . "\n\t\t\t\tWHERE post_msg_id = {$msg_id}\n\t\t\t\t\tAND in_message = 1\n\t\t\t\tORDER BY filetime " . (!$config['display_order'] ? 'DESC' : 'ASC') . ', post_msg_id ASC';
            $result = $_CLASS['core_db']->query($sql);
            while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
                $attachments[] = $row;
            }
            $_CLASS['core_db']->free_result($result);
            // No attachments exist, but message table thinks they do so go ahead and reset attach flags
            if (empty($attachments)) {
                $sql = 'UPDATE ' . FORUMS_PRIVMSGS_TABLE . " \n\t\t\t\t\tSET message_attachment = 0 \n\t\t\t\t\tWHERE msg_id = {$msg_id}";
                $_CLASS['core_db']->query($sql);
            }
        } else {
            $display_notice = true;
        }
    }
    // Assign inline attachments
    if (!empty($attachments)) {
        $unset_attachments = parse_inline_attachments($message, $attachments, $update_count, 0);
        // Needed to let not display the inlined attachments at the end of the message again
        foreach ($unset_attachments as $index) {
            unset($attachments[$index]);
        }
    }
    $user_info['sig'] = '';
    $signature = $message_row['enable_sig'] && $config['allow_sig'] && $_CLASS['auth']->acl_get('u_sig') && $_CLASS['core_user']->optionget('viewsigs') ? $user_info['user_sig'] : '';
    // End signature parsing, only if needed
    if ($signature) {
        if ($user_info['user_sig_bbcode_bitfield']) {
            if (!isset($bbcode) || !$bbcode) {
                require $site_file_root . 'includes/forums/bbcode.php';
                $bbcode = new bbcode($user_info['user_sig_bbcode_bitfield']);
            }
            $bbcode->bbcode_second_pass($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield']);
        }
        $signature = smiley_text($signature);
        $signature = str_replace("\n", '<br />', censor_text($signature));
    }
    $url = 'Control_Panel&amp;i=' . $id;
    $_CLASS['core_template']->assign(array('AUTHOR_NAME' => $user_info['user_colour'] ? '<span style="color:#' . $user_info['user_colour'] . '">' . $user_info['username'] . '</span>' : $user_info['username'], 'AUTHOR_RANK' => $user_info['rank_title'], 'RANK_IMAGE' => $user_info['rank_image'], 'AUTHOR_AVATAR' => isset($user_info['avatar']) ? $user_info['avatar'] : '', 'AUTHOR_JOINED' => $_CLASS['core_user']->format_date($user_info['user_reg_date']), 'AUTHOR_POSTS' => !empty($user_info['user_posts']) ? $user_info['user_posts'] : '', 'AUTHOR_FROM' => !empty($user_info['user_from']) ? $user_info['user_from'] : '', 'ONLINE_IMG' => !$config['load_onlinetrack'] ? '' : (isset($user_info['online']) && $user_info['online'] ? $_CLASS['core_user']->img('btn_online', $_CLASS['core_user']->lang['ONLINE']) : $_CLASS['core_user']->img('btn_offline', $_CLASS['core_user']->lang['OFFLINE'])), 'DELETE_IMG' => $_CLASS['core_user']->img('btn_delete', $_CLASS['core_user']->lang['DELETE_MESSAGE']), 'INFO_IMG' => $_CLASS['core_user']->img('btn_info', $_CLASS['core_user']->lang['VIEW_PM_INFO']), 'REPORT_IMG' => $_CLASS['core_user']->img('btn_report', $_CLASS['core_user']->lang['REPORT_PM']), 'REPORTED_IMG' => $_CLASS['core_user']->img('icon_reported', $_CLASS['core_user']->lang['MESSAGE_REPORTED_MESSAGE']), 'PROFILE_IMG' => $_CLASS['core_user']->img('btn_profile', $_CLASS['core_user']->lang['READ_PROFILE']), 'EMAIL_IMG' => $_CLASS['core_user']->img('btn_email', $_CLASS['core_user']->lang['SEND_EMAIL']), 'QUOTE_IMG' => $_CLASS['core_user']->img('btn_quote', $_CLASS['core_user']->lang['POST_QUOTE_PM']), 'REPLY_IMG' => $_CLASS['core_user']->img('btn_reply_pm', $_CLASS['core_user']->lang['POST_REPLY_PM']), 'EDIT_IMG' => $_CLASS['core_user']->img('btn_edit', $_CLASS['core_user']->lang['POST_EDIT_PM']), 'MINI_POST_IMG' => $_CLASS['core_user']->img('icon_post', $_CLASS['core_user']->lang['PM']), 'SENT_DATE' => $_CLASS['core_user']->format_date($message_row['message_time']), 'SUBJECT' => $message_row['message_subject'], 'MESSAGE' => $message, 'SIGNATURE' => $message_row['enable_sig'] ? $signature : '', 'EDITED_MESSAGE' => $l_edited_by, 'U_MCP_REPORT' => generate_link('Forums&amp;file=mcp&amp;mode=pm_details&amp;p=' . $message_row['msg_id']), 'U_REPORT' => $config['auth_report_pm'] && $_CLASS['auth']->acl_get('u_pm_report') ? generate_link('Forums&amp;file=report&amp;pm=' . $message_row['msg_id']) : '', 'U_INFO' => $_CLASS['auth']->acl_get('m_') && ($message_row['message_reported'] || $message_row['forwarded']) ? generate_link('Forums&amp;file=mcp&amp;mode=pm_details&amp;p=' . $message_row['msg_id']) : '', 'U_DELETE' => $_CLASS['auth']->acl_get('u_pm_delete') ? generate_link("{$url}&amp;mode=compose&amp;action=delete&amp;f={$folder_id}&amp;p=" . $message_row['msg_id']) : '', 'U_AUTHOR_PROFILE' => generate_link('Members_List&amp;mode=viewprofile&amp;u=' . $author_id), 'U_EMAIL' => $user_info['email'], 'U_QUOTE' => $_CLASS['auth']->acl_get('u_sendpm') && $author_id != $_CLASS['core_user']->data['user_id'] ? generate_link("{$url}&amp;mode=compose&amp;action=quote&amp;f={$folder_id}&amp;p=" . $message_row['msg_id']) : '', 'U_EDIT' => ($message_row['message_time'] > time() - $config['pm_edit_time'] || !$config['pm_edit_time']) && $folder_id == PRIVMSGS_OUTBOX && $_CLASS['auth']->acl_get('u_pm_edit') ? generate_link("{$url}&amp;mode=compose&amp;action=edit&amp;f={$folder_id}&amp;p=" . $message_row['msg_id']) : '', 'U_POST_REPLY_PM' => $author_id != $_CLASS['core_user']->data['user_id'] && $_CLASS['auth']->acl_get('u_sendpm') ? generate_link("{$url}&amp;mode=compose&amp;action=reply&amp;f={$folder_id}&amp;p=" . $message_row['msg_id']) : '', 'U_PREVIOUS_PM' => generate_link("{$url}&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] . "&amp;view=previous"), 'U_NEXT_PM' => generate_link("{$url}&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] . "&amp;view=next"), 'S_MESSAGE_REPORTED' => $message_row['message_reported'] && $_CLASS['auth']->acl_get('m_') ? true : false, 'S_HAS_ATTACHMENTS' => sizeof($attachments) ? true : false, 'S_DISPLAY_NOTICE' => $display_notice && $message_row['message_attachment'], 'U_PRINT_PM' => generate_link("{$url}&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] . "&amp;view=print"), 'U_EMAIL_PM' => $_CORE_CONFIG['email']['email_enable'] ? 'Email' : '', 'U_FORWARD_PM' => generate_link("{$url}&amp;mode=compose&amp;action=forward&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'])));
    // Display not already displayed Attachments for this post, we already parsed them. ;)
    if (isset($attachments) && sizeof($attachments)) {
        foreach ($attachments as $attachment) {
            $_CLASS['core_template']->assign_vars_array('attachment', array('DISPLAY_ATTACHMENT' => $attachment));
        }
    }
    if (!isset($_REQUEST['view']) || $_REQUEST['view'] != 'print') {
        // Message History
        if (message_history($msg_id, $_CLASS['core_user']->data['user_id'], $message_row, $folder)) {
            $_CLASS['core_template']->assign('S_DISPLAY_HISTORY', true);
        }
    }
}
예제 #2
0
/**
* View private message
*/
function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
{
    global $user, $template, $auth, $db, $cache;
    global $phpbb_root_path, $phpEx, $config;
    $user->add_lang(array('viewtopic', 'memberlist'));
    $msg_id = (int) $msg_id;
    $folder_id = (int) $folder_id;
    $author_id = (int) $message_row['author_id'];
    // Not able to view message, it was deleted by the sender
    if ($message_row['deleted']) {
        trigger_error('NO_AUTH_READ_REMOVED_MESSAGE');
    }
    // Do not allow hold messages to be seen
    if ($folder_id == PRIVMSGS_HOLD_BOX) {
        trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
    }
    // Grab icons
    $icons = array();
    $cache->obtain_icons($icons);
    $bbcode = false;
    // Instantiate BBCode if need be
    if ($message_row['bbcode_bitfield']) {
        include $phpbb_root_path . 'includes/bbcode.' . $phpEx;
        $bbcode = new bbcode($message_row['bbcode_bitfield']);
    }
    // Assign TO/BCC Addresses to template
    write_pm_addresses(array('to' => $message_row['to_address'], 'bcc' => $message_row['bcc_address']), $author_id);
    $user_info = get_user_informations($author_id, $message_row);
    // Parse the message and subject
    $message = $message_row['message_text'];
    // Second parse bbcode here
    if ($message_row['bbcode_bitfield']) {
        $bbcode->bbcode_second_pass($message, $message_row['bbcode_uid'], $message_row['bbcode_bitfield']);
    }
    // Always process smilies after parsing bbcodes
    $message = smiley_text($message);
    // Replace naughty words such as farty pants
    $message_row['message_subject'] = censor_text($message_row['message_subject']);
    $message = str_replace("\n", '<br />', censor_text($message));
    // Editing information
    if ($message_row['message_edit_count'] && $config['display_last_edited']) {
        $l_edit_time_total = $message_row['message_edit_count'] == 1 ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
        $l_edited_by = '<br /><br />' . sprintf($l_edit_time_total, !$message_row['message_edit_user'] ? $message_row['username'] : $message_row['message_edit_user'], $user->format_date($message_row['message_edit_time']), $message_row['message_edit_count']);
    } else {
        $l_edited_by = '';
    }
    // Pull attachment data
    $display_notice = false;
    $attachments = array();
    if ($message_row['message_attachment'] && $config['allow_pm_attach']) {
        if ($config['auth_download_pm'] && $auth->acl_get('u_pm_download')) {
            include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
            $sql = 'SELECT *
				FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\tWHERE post_msg_id = {$msg_id}\n\t\t\t\t\tAND in_message = 1\n\t\t\t\tORDER BY filetime " . (!$config['display_order'] ? 'DESC' : 'ASC') . ', post_msg_id ASC';
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $attachments[] = $row;
            }
            $db->sql_freeresult($result);
            // No attachments exist, but message table thinks they do so go ahead and reset attach flags
            if (!sizeof($attachments)) {
                $sql = 'UPDATE ' . PRIVMSGS_TABLE . "\n\t\t\t\t\tSET message_attachment = 0\n\t\t\t\t\tWHERE msg_id = {$msg_id}";
                $db->sql_query($sql);
            }
        } else {
            $display_notice = true;
        }
    }
    // Assign inline attachments
    if (isset($attachments) && sizeof($attachments)) {
        $update_count = array();
        $unset_attachments = parse_inline_attachments($message, $attachments, $update_count, 0);
        // Needed to let not display the inlined attachments at the end of the message again
        foreach ($unset_attachments as $index) {
            unset($attachments[$index]);
        }
        // Update the attachment download counts
        if (sizeof($update_count)) {
            $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
				SET download_count = download_count + 1
				WHERE attach_id IN (' . implode(', ', array_unique($update_count)) . ')';
            $db->sql_query($sql);
        }
    }
    $user_info['sig'] = '';
    $signature = $message_row['enable_sig'] && $config['allow_sig'] && $auth->acl_get('u_sig') && $user->optionget('viewsigs') ? $user_info['user_sig'] : '';
    // End signature parsing, only if needed
    if ($signature) {
        if ($user_info['user_sig_bbcode_bitfield']) {
            if ($bbcode === false) {
                include $phpbb_root_path . 'includes/bbcode.' . $phpEx;
                $bbcode = new bbcode($user_info['user_sig_bbcode_bitfield']);
            }
            $bbcode->bbcode_second_pass($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield']);
        }
        $signature = smiley_text($signature);
        $signature = str_replace("\n", '<br />', censor_text($signature));
    }
    $url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm');
    $template->assign_vars(array('AUTHOR_NAME' => $user_info['user_colour'] ? '<span style="color:#' . $user_info['user_colour'] . '">' . $user_info['username'] . '</span>' : $user_info['username'], 'AUTHOR_RANK' => $user_info['rank_title'], 'RANK_IMAGE' => $user_info['rank_image'], 'AUTHOR_AVATAR' => isset($user_info['avatar']) ? $user_info['avatar'] : '', 'AUTHOR_JOINED' => $user->format_date($user_info['user_regdate']), 'AUTHOR_POSTS' => !empty($user_info['user_posts']) ? $user_info['user_posts'] : '', 'AUTHOR_FROM' => !empty($user_info['user_from']) ? $user_info['user_from'] : '', 'ONLINE_IMG' => !$config['load_onlinetrack'] ? '' : (isset($user_info['online']) && $user_info['online'] ? $user->img('btn_online', $user->lang['ONLINE']) : $user->img('btn_offline', $user->lang['OFFLINE'])), 'S_ONLINE' => !$config['load_onlinetrack'] ? false : (isset($user_info['online']) && $user_info['online'] ? true : false), 'DELETE_IMG' => $user->img('btn_delete', $user->lang['DELETE_MESSAGE']), 'INFO_IMG' => $user->img('btn_info', $user->lang['VIEW_PM_INFO']), 'PROFILE_IMG' => $user->img('btn_profile', $user->lang['READ_PROFILE']), 'EMAIL_IMG' => $user->img('btn_email', $user->lang['SEND_EMAIL']), 'QUOTE_IMG' => $user->img('btn_quote', $user->lang['POST_QUOTE_PM']), 'REPLY_IMG' => $user->img('btn_reply_pm', $user->lang['POST_REPLY_PM']), 'EDIT_IMG' => $user->img('btn_edit', $user->lang['POST_EDIT_PM']), 'MINI_POST_IMG' => $user->img('icon_post', $user->lang['PM']), 'SENT_DATE' => $user->format_date($message_row['message_time']), 'SUBJECT' => $message_row['message_subject'], 'MESSAGE' => $message, 'SIGNATURE' => $message_row['enable_sig'] ? $signature : '', 'EDITED_MESSAGE' => $l_edited_by, 'U_INFO' => $auth->acl_get('m_info') && $message_row['forwarded'] ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'mode=pm_details&amp;p=' . $message_row['msg_id'], true, $user->session_id) : '', 'U_DELETE' => $auth->acl_get('u_pm_delete') ? "{$url}&amp;mode=compose&amp;action=delete&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] : '', 'U_AUTHOR_PROFILE' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $author_id), 'U_EMAIL' => $user_info['email'], 'U_QUOTE' => $auth->acl_get('u_sendpm') ? "{$url}&amp;mode=compose&amp;action=quote&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] : '', 'U_EDIT' => ($message_row['message_time'] > time() - $config['pm_edit_time'] || !$config['pm_edit_time']) && $folder_id == PRIVMSGS_OUTBOX && $auth->acl_get('u_pm_edit') ? "{$url}&amp;mode=compose&amp;action=edit&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] : '', 'U_POST_REPLY_PM' => $auth->acl_get('u_sendpm') ? "{$url}&amp;mode=compose&amp;action=reply&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] : '', 'U_PREVIOUS_PM' => "{$url}&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] . "&amp;view=previous", 'U_NEXT_PM' => "{$url}&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] . "&amp;view=next", 'S_HAS_ATTACHMENTS' => sizeof($attachments) ? true : false, 'S_DISPLAY_NOTICE' => $display_notice && $message_row['message_attachment'], 'U_PRINT_PM' => $config['print_pm'] && $auth->acl_get('u_pm_printpm') ? "{$url}&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] . "&amp;view=print" : '', 'U_FORWARD_PM' => $config['forward_pm'] && $auth->acl_get('u_pm_forward') ? "{$url}&amp;mode=compose&amp;action=forward&amp;f={$folder_id}&amp;p=" . $message_row['msg_id'] : ''));
    // Display not already displayed Attachments for this post, we already parsed them. ;)
    if (isset($attachments) && sizeof($attachments)) {
        foreach ($attachments as $attachment) {
            $template->assign_block_vars('attachment', array('DISPLAY_ATTACHMENT' => $attachment));
        }
    }
    if (!isset($_REQUEST['view']) || $_REQUEST['view'] != 'print') {
        // Message History
        if (message_history($msg_id, $user->data['user_id'], $message_row, $folder)) {
            $template->assign_var('S_DISPLAY_HISTORY', true);
        }
    }
}