Blame Extras/phpBB/3.0.4/includes/ucp/ucp_pm_viewmessage.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package ucp
4c79b5
* @version $Id: ucp_pm_viewmessage.php 9174 2008-12-04 19:58:42Z toonarmy $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* View private message
4c79b5
*/
4c79b5
function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
4c79b5
{
4c79b5
	global $user, $template, $auth, $db, $cache;
4c79b5
	global $phpbb_root_path, $phpEx, $config;
4c79b5
4c79b5
	$user->add_lang(array('viewtopic', 'memberlist'));
4c79b5
4c79b5
	$msg_id		= (int) $msg_id;
4c79b5
	$folder_id	= (int) $folder_id;
4c79b5
	$author_id	= (int) $message_row['author_id'];
4c79b5
4c79b5
	// Not able to view message, it was deleted by the sender
4c79b5
	if ($message_row['pm_deleted'])
4c79b5
	{
4c79b5
		$meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&folder=$folder_id");
4c79b5
		$message = $user->lang['NO_AUTH_READ_REMOVED_MESSAGE'];
4c79b5
4c79b5
		$message .= '

' . sprintf($user->lang['RETURN_FOLDER'], '', '');
4c79b5
		trigger_error($message);
4c79b5
	}
4c79b5
4c79b5
	// Do not allow hold messages to be seen
4c79b5
	if ($folder_id == PRIVMSGS_HOLD_BOX)
4c79b5
	{
4c79b5
		trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
4c79b5
	}
4c79b5
4c79b5
	// Grab icons
4c79b5
	$icons = $cache->obtain_icons();
4c79b5
4c79b5
	$bbcode = false;
4c79b5
4c79b5
	// Instantiate BBCode if need be
4c79b5
	if ($message_row['bbcode_bitfield'])
4c79b5
	{
4c79b5
		include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
4c79b5
		$bbcode = new bbcode($message_row['bbcode_bitfield']);
4c79b5
	}
4c79b5
4c79b5
	// Assign TO/BCC Addresses to template
4c79b5
	write_pm_addresses(array('to' => $message_row['to_address'], 'bcc' => $message_row['bcc_address']), $author_id);
4c79b5
4c79b5
	$user_info = get_user_information($author_id, $message_row);
4c79b5
4c79b5
	// Parse the message and subject
4c79b5
	$message = censor_text($message_row['message_text']);
4c79b5
4c79b5
	// Second parse bbcode here
4c79b5
	if ($message_row['bbcode_bitfield'])
4c79b5
	{
4c79b5
		$bbcode->bbcode_second_pass($message, $message_row['bbcode_uid'], $message_row['bbcode_bitfield']);
4c79b5
	}
4c79b5
4c79b5
	// Always process smilies after parsing bbcodes
4c79b5
	$message = bbcode_nl2br($message);
4c79b5
	$message = smiley_text($message);
4c79b5
4c79b5
	// Replace naughty words such as farty pants
4c79b5
	$message_row['message_subject'] = censor_text($message_row['message_subject']);
4c79b5
4c79b5
	// Editing information
4c79b5
	if ($message_row['message_edit_count'] && $config['display_last_edited'])
4c79b5
	{
4c79b5
		$l_edit_time_total = ($message_row['message_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
4c79b5
		$l_edited_by = '

' . 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'], false, true), $message_row['message_edit_count']);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$l_edited_by = '';
4c79b5
	}
4c79b5
4c79b5
	// Pull attachment data
4c79b5
	$display_notice = false;
4c79b5
	$attachments = array();
4c79b5
4c79b5
	if ($message_row['message_attachment'] && $config['allow_pm_attach'])
4c79b5
	{
4c79b5
		if ($auth->acl_get('u_pm_download'))
4c79b5
		{
4c79b5
			$sql = 'SELECT *
4c79b5
				FROM ' . ATTACHMENTS_TABLE . "
4c79b5
				WHERE post_msg_id = $msg_id
4c79b5
					AND in_message = 1
4c79b5
				ORDER BY filetime DESC, post_msg_id ASC";
4c79b5
			$result = $db->sql_query($sql);
4c79b5
4c79b5
			while ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				$attachments[] = $row;
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			// No attachments exist, but message table thinks they do so go ahead and reset attach flags
4c79b5
			if (!sizeof($attachments))
4c79b5
			{
4c79b5
				$sql = 'UPDATE ' . PRIVMSGS_TABLE . "
4c79b5
					SET message_attachment = 0
4c79b5
					WHERE msg_id = $msg_id";
4c79b5
				$db->sql_query($sql);
4c79b5
			}
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$display_notice = true;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// Assign inline attachments
4c79b5
	if (!empty($attachments))
4c79b5
	{
4c79b5
		$update_count = array();
4c79b5
		parse_attachments(false, $message, $attachments, $update_count);
4c79b5
4c79b5
		// Update the attachment download counts
4c79b5
		if (sizeof($update_count))
4c79b5
		{
4c79b5
			$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
4c79b5
				SET download_count = download_count + 1
4c79b5
				WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
4c79b5
			$db->sql_query($sql);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	$user_info['sig'] = '';
4c79b5
4c79b5
	$signature = ($message_row['enable_sig'] && $config['allow_sig'] && $auth->acl_get('u_sig') && $user->optionget('viewsigs')) ? $user_info['user_sig'] : '';
4c79b5
4c79b5
	// End signature parsing, only if needed
4c79b5
	if ($signature)
4c79b5
	{
4c79b5
		$signature = censor_text($signature);
4c79b5
4c79b5
		if ($user_info['user_sig_bbcode_bitfield'])
4c79b5
		{
4c79b5
			if ($bbcode === false)
4c79b5
			{
4c79b5
				include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
4c79b5
				$bbcode = new bbcode($user_info['user_sig_bbcode_bitfield']);
4c79b5
			}
4c79b5
4c79b5
			$bbcode->bbcode_second_pass($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield']);
4c79b5
		}
4c79b5
4c79b5
		$signature = bbcode_nl2br($signature);
4c79b5
		$signature = smiley_text($signature);
4c79b5
	}
4c79b5
4c79b5
	$url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
4c79b5
4c79b5
	$template->assign_vars(array(
4c79b5
		'MESSAGE_AUTHOR_FULL'		=> get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
4c79b5
		'MESSAGE_AUTHOR_COLOUR'		=> get_username_string('colour', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
4c79b5
		'MESSAGE_AUTHOR'			=> get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
4c79b5
		'U_MESSAGE_AUTHOR'			=> get_username_string('profile', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
4c79b5
4c79b5
		'RANK_TITLE'		=> $user_info['rank_title'],
4c79b5
		'RANK_IMG'			=> $user_info['rank_image'],
4c79b5
		'AUTHOR_AVATAR'		=> (isset($user_info['avatar'])) ? $user_info['avatar'] : '',
4c79b5
		'AUTHOR_JOINED'		=> $user->format_date($user_info['user_regdate']),
4c79b5
		'AUTHOR_POSTS'		=> (!empty($user_info['user_posts'])) ? $user_info['user_posts'] : '',
4c79b5
		'AUTHOR_FROM'		=> (!empty($user_info['user_from'])) ? $user_info['user_from'] : '',
4c79b5
4c79b5
		'ONLINE_IMG'		=> (!$config['load_onlinetrack']) ? '' : ((isset($user_info['online']) && $user_info['online']) ? $user->img('icon_user_online', $user->lang['ONLINE']) : $user->img('icon_user_offline', $user->lang['OFFLINE'])),
4c79b5
		'S_ONLINE'			=> (!$config['load_onlinetrack']) ? false : ((isset($user_info['online']) && $user_info['online']) ? true : false),
4c79b5
		'DELETE_IMG'		=> $user->img('icon_post_delete', $user->lang['DELETE_MESSAGE']),
4c79b5
		'INFO_IMG'			=> $user->img('icon_post_info', $user->lang['VIEW_PM_INFO']),
4c79b5
		'PROFILE_IMG'		=> $user->img('icon_user_profile', $user->lang['READ_PROFILE']),
4c79b5
		'EMAIL_IMG'			=> $user->img('icon_contact_email', $user->lang['SEND_EMAIL']),
4c79b5
		'QUOTE_IMG'			=> $user->img('icon_post_quote', $user->lang['POST_QUOTE_PM']),
4c79b5
		'REPLY_IMG'			=> $user->img('button_pm_reply', $user->lang['POST_REPLY_PM']),
4c79b5
		'EDIT_IMG'			=> $user->img('icon_post_edit', $user->lang['POST_EDIT_PM']),
4c79b5
		'MINI_POST_IMG'		=> $user->img('icon_post_target', $user->lang['PM']),
4c79b5
4c79b5
		'SENT_DATE'			=> $user->format_date($message_row['message_time']),
4c79b5
		'SUBJECT'			=> $message_row['message_subject'],
4c79b5
		'MESSAGE'			=> $message,
4c79b5
		'SIGNATURE'			=> ($message_row['enable_sig']) ? $signature : '',
4c79b5
		'EDITED_MESSAGE'	=> $l_edited_by,
4c79b5
		'MESSAGE_ID'		=> $message_row['msg_id'],
4c79b5
4c79b5
		'U_PM'			=> ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user_info['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $author_id) : '',
4c79b5
		'U_WWW'			=> (!empty($user_info['user_website'])) ? $user_info['user_website'] : '',
4c79b5
		'U_ICQ'			=> ($user_info['user_icq']) ? 'http://www.icq.com/people/webmsg.php?to=' . urlencode($user_info['user_icq']) : '',
4c79b5
		'U_AIM'			=> ($user_info['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=aim&u=' . $author_id) : '',
4c79b5
		'U_YIM'			=> ($user_info['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user_info['user_yim']) . '&.src=pg' : '',
4c79b5
		'U_MSN'			=> ($user_info['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=msnm&u=' . $author_id) : '',
4c79b5
		'U_JABBER'		=> ($user_info['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $author_id) : '',
4c79b5
4c79b5
		'U_DELETE'			=> ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '',
4c79b5
		'U_EMAIL'			=> $user_info['email'],
4c79b5
		'U_QUOTE'			=> ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=quote&f=$folder_id&p=" . $message_row['msg_id'] : '',
4c79b5
		'U_EDIT'			=> (($message_row['message_time'] > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time']) && $folder_id == PRIVMSGS_OUTBOX && $auth->acl_get('u_pm_edit')) ? "$url&mode=compose&action=edit&f=$folder_id&p=" . $message_row['msg_id'] : '',
4c79b5
		'U_POST_REPLY_PM'	=> ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=reply&f=$folder_id&p=" . $message_row['msg_id'] : '',
4c79b5
		'U_PREVIOUS_PM'		=> "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=previous",
4c79b5
		'U_NEXT_PM'			=> "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=next",
4c79b5
4c79b5
		'S_HAS_ATTACHMENTS'	=> (sizeof($attachments)) ? true : false,
4c79b5
		'S_DISPLAY_NOTICE'	=> $display_notice && $message_row['message_attachment'],
4c79b5
		'S_AUTHOR_DELETED'	=> ($author_id == ANONYMOUS) ? true : false,
4c79b5
		'S_SPECIAL_FOLDER'	=> in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)),
4c79b5
4c79b5
		'U_PRINT_PM'		=> ($config['print_pm'] && $auth->acl_get('u_pm_printpm')) ? "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=print" : '',
4c79b5
		'U_FORWARD_PM'		=> ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&mode=compose&action=forward&f=$folder_id&p=" . $message_row['msg_id'] : '')
4c79b5
	);
4c79b5
4c79b5
	// Display not already displayed Attachments for this post, we already parsed them. ;)
4c79b5
	if (isset($attachments) && sizeof($attachments))
4c79b5
	{
4c79b5
		foreach ($attachments as $attachment)
4c79b5
		{
4c79b5
			$template->assign_block_vars('attachment', array(
4c79b5
				'DISPLAY_ATTACHMENT'	=> $attachment)
4c79b5
			);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	if (!isset($_REQUEST['view']) || $_REQUEST['view'] != 'print')
4c79b5
	{
4c79b5
		// Message History
4c79b5
		if (message_history($msg_id, $user->data['user_id'], $message_row, $folder))
4c79b5
		{
4c79b5
			$template->assign_var('S_DISPLAY_HISTORY', true);
4c79b5
		}
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Get user information (only for message display)
4c79b5
*/
4c79b5
function get_user_information($user_id, $user_row)
4c79b5
{
4c79b5
	global $db, $auth, $user, $cache;
4c79b5
	global $phpbb_root_path, $phpEx, $config;
4c79b5
4c79b5
	if (!$user_id)
4c79b5
	{
4c79b5
		return array();
4c79b5
	}
4c79b5
4c79b5
	if (empty($user_row))
4c79b5
	{
4c79b5
		$sql = 'SELECT *
4c79b5
			FROM ' . USERS_TABLE . '
4c79b5
			WHERE user_id = ' . (int) $user_id;
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$user_row = $db->sql_fetchrow($result);
4c79b5
		$db->sql_freeresult($result);
4c79b5
	}
4c79b5
4c79b5
	// Some standard values
4c79b5
	$user_row['online'] = false;
4c79b5
	$user_row['rank_title'] = $user_row['rank_image'] = $user_row['rank_image_src'] = $user_row['email'] = '';
4c79b5
4c79b5
	// Generate online information for user
4c79b5
	if ($config['load_onlinetrack'])
4c79b5
	{
4c79b5
		$sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
4c79b5
			FROM ' . SESSIONS_TABLE . "
4c79b5
			WHERE session_user_id = $user_id
4c79b5
			GROUP BY session_user_id";
4c79b5
		$result = $db->sql_query_limit($sql, 1);
4c79b5
		$row = $db->sql_fetchrow($result);
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$update_time = $config['load_online_time'] * 60;
4c79b5
		if ($row)
4c79b5
		{
4c79b5
			$user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'])) ? true : false;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	if (!function_exists('get_user_avatar'))
4c79b5
	{
4c79b5
		include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
	}
4c79b5
4c79b5
	$user_row['avatar'] = ($user->optionget('viewavatars')) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']) : '';
4c79b5
4c79b5
	get_user_rank($user_row['user_rank'], $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']);
4c79b5
4c79b5
	if (!empty($user_row['user_allow_viewemail']) || $auth->acl_get('a_email'))
4c79b5
	{
4c79b5
		$user_row['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&u=$user_id") : ((($config['board_hide_emails'] && !$auth->acl_get('a_email')) || empty($user_row['user_email'])) ? '' : 'mailto:' . $user_row['user_email']);
4c79b5
	}
4c79b5
4c79b5
	return $user_row;
4c79b5
}
4c79b5
4c79b5
?>