includes/ucp/ucp_pm_viewmessage.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/ucp/ucp_pm_viewmessage.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,323 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package ucp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* View private message
    1.24 +*/
    1.25 +function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
    1.26 +{
    1.27 +	global $user, $template, $auth, $db, $cache;
    1.28 +	global $phpbb_root_path, $phpEx, $config;
    1.29 +
    1.30 +	$user->add_lang(array('viewtopic', 'memberlist'));
    1.31 +
    1.32 +	$msg_id		= (int) $msg_id;
    1.33 +	$folder_id	= (int) $folder_id;
    1.34 +	$author_id	= (int) $message_row['author_id'];
    1.35 +	$view		= request_var('view', '');
    1.36 +
    1.37 +	// Not able to view message, it was deleted by the sender
    1.38 +	if ($message_row['pm_deleted'])
    1.39 +	{
    1.40 +		$meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;folder=$folder_id");
    1.41 +		$message = $user->lang['NO_AUTH_READ_REMOVED_MESSAGE'];
    1.42 +
    1.43 +		$message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
    1.44 +		trigger_error($message);
    1.45 +	}
    1.46 +
    1.47 +	// Do not allow hold messages to be seen
    1.48 +	if ($folder_id == PRIVMSGS_HOLD_BOX)
    1.49 +	{
    1.50 +		trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
    1.51 +	}
    1.52 +
    1.53 +	// Grab icons
    1.54 +	$icons = $cache->obtain_icons();
    1.55 +
    1.56 +	$bbcode = false;
    1.57 +
    1.58 +	// Instantiate BBCode if need be
    1.59 +	if ($message_row['bbcode_bitfield'])
    1.60 +	{
    1.61 +		include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
    1.62 +		$bbcode = new bbcode($message_row['bbcode_bitfield']);
    1.63 +	}
    1.64 +
    1.65 +	// Assign TO/BCC Addresses to template
    1.66 +	write_pm_addresses(array('to' => $message_row['to_address'], 'bcc' => $message_row['bcc_address']), $author_id);
    1.67 +
    1.68 +	$user_info = get_user_information($author_id, $message_row);
    1.69 +
    1.70 +	// Parse the message and subject
    1.71 +	$message = censor_text($message_row['message_text']);
    1.72 +
    1.73 +	// Second parse bbcode here
    1.74 +	if ($message_row['bbcode_bitfield'])
    1.75 +	{
    1.76 +		$bbcode->bbcode_second_pass($message, $message_row['bbcode_uid'], $message_row['bbcode_bitfield']);
    1.77 +	}
    1.78 +
    1.79 +	// Always process smilies after parsing bbcodes
    1.80 +	$message = bbcode_nl2br($message);
    1.81 +	$message = smiley_text($message);
    1.82 +
    1.83 +	// Replace naughty words such as farty pants
    1.84 +	$message_row['message_subject'] = censor_text($message_row['message_subject']);
    1.85 +
    1.86 +	// Editing information
    1.87 +	if ($message_row['message_edit_count'] && $config['display_last_edited'])
    1.88 +	{
    1.89 +		$l_edit_time_total = ($message_row['message_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
    1.90 +		$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'], false, true), $message_row['message_edit_count']);
    1.91 +	}
    1.92 +	else
    1.93 +	{
    1.94 +		$l_edited_by = '';
    1.95 +	}
    1.96 +
    1.97 +	// Pull attachment data
    1.98 +	$display_notice = false;
    1.99 +	$attachments = array();
   1.100 +
   1.101 +	if ($message_row['message_attachment'] && $config['allow_pm_attach'])
   1.102 +	{
   1.103 +		if ($auth->acl_get('u_pm_download'))
   1.104 +		{
   1.105 +			$sql = 'SELECT *
   1.106 +				FROM ' . ATTACHMENTS_TABLE . "
   1.107 +				WHERE post_msg_id = $msg_id
   1.108 +					AND in_message = 1
   1.109 +				ORDER BY filetime DESC, post_msg_id ASC";
   1.110 +			$result = $db->sql_query($sql);
   1.111 +
   1.112 +			while ($row = $db->sql_fetchrow($result))
   1.113 +			{
   1.114 +				$attachments[] = $row;
   1.115 +			}
   1.116 +			$db->sql_freeresult($result);
   1.117 +
   1.118 +			// No attachments exist, but message table thinks they do so go ahead and reset attach flags
   1.119 +			if (!sizeof($attachments))
   1.120 +			{
   1.121 +				$sql = 'UPDATE ' . PRIVMSGS_TABLE . "
   1.122 +					SET message_attachment = 0
   1.123 +					WHERE msg_id = $msg_id";
   1.124 +				$db->sql_query($sql);
   1.125 +			}
   1.126 +		}
   1.127 +		else
   1.128 +		{
   1.129 +			$display_notice = true;
   1.130 +		}
   1.131 +	}
   1.132 +
   1.133 +	// Assign inline attachments
   1.134 +	if (!empty($attachments))
   1.135 +	{
   1.136 +		$update_count = array();
   1.137 +		parse_attachments(false, $message, $attachments, $update_count);
   1.138 +
   1.139 +		// Update the attachment download counts
   1.140 +		if (sizeof($update_count))
   1.141 +		{
   1.142 +			$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
   1.143 +				SET download_count = download_count + 1
   1.144 +				WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
   1.145 +			$db->sql_query($sql);
   1.146 +		}
   1.147 +	}
   1.148 +
   1.149 +	$user_info['sig'] = '';
   1.150 +
   1.151 +	$signature = ($message_row['enable_sig'] && $config['allow_sig'] && $auth->acl_get('u_sig') && $user->optionget('viewsigs')) ? $user_info['user_sig'] : '';
   1.152 +
   1.153 +	// End signature parsing, only if needed
   1.154 +	if ($signature)
   1.155 +	{
   1.156 +		$signature = censor_text($signature);
   1.157 +
   1.158 +		if ($user_info['user_sig_bbcode_bitfield'])
   1.159 +		{
   1.160 +			if ($bbcode === false)
   1.161 +			{
   1.162 +				include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
   1.163 +				$bbcode = new bbcode($user_info['user_sig_bbcode_bitfield']);
   1.164 +			}
   1.165 +
   1.166 +			$bbcode->bbcode_second_pass($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield']);
   1.167 +		}
   1.168 +
   1.169 +		$signature = bbcode_nl2br($signature);
   1.170 +		$signature = smiley_text($signature);
   1.171 +	}
   1.172 +
   1.173 +	$url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
   1.174 +
   1.175 +	// Number of "to" recipients
   1.176 +	$num_recipients = (int) preg_match_all('/:?(u|g)_([0-9]+):?/', $message_row['to_address'], $match);
   1.177 +
   1.178 +	$bbcode_status	= ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false;
   1.179 +
   1.180 +	$template->assign_vars(array(
   1.181 +		'MESSAGE_AUTHOR_FULL'		=> get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
   1.182 +		'MESSAGE_AUTHOR_COLOUR'		=> get_username_string('colour', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
   1.183 +		'MESSAGE_AUTHOR'			=> get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
   1.184 +		'U_MESSAGE_AUTHOR'			=> get_username_string('profile', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
   1.185 +
   1.186 +		'RANK_TITLE'		=> $user_info['rank_title'],
   1.187 +		'RANK_IMG'			=> $user_info['rank_image'],
   1.188 +		'AUTHOR_AVATAR'		=> (isset($user_info['avatar'])) ? $user_info['avatar'] : '',
   1.189 +		'AUTHOR_JOINED'		=> $user->format_date($user_info['user_regdate']),
   1.190 +		'AUTHOR_POSTS'		=> (int) $user_info['user_posts'],
   1.191 +		'AUTHOR_FROM'		=> (!empty($user_info['user_from'])) ? $user_info['user_from'] : '',
   1.192 +
   1.193 +		'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'])),
   1.194 +		'S_ONLINE'			=> (!$config['load_onlinetrack']) ? false : ((isset($user_info['online']) && $user_info['online']) ? true : false),
   1.195 +		'DELETE_IMG'		=> $user->img('icon_post_delete', $user->lang['DELETE_MESSAGE']),
   1.196 +		'INFO_IMG'			=> $user->img('icon_post_info', $user->lang['VIEW_PM_INFO']),
   1.197 +		'PROFILE_IMG'		=> $user->img('icon_user_profile', $user->lang['READ_PROFILE']),
   1.198 +		'EMAIL_IMG'			=> $user->img('icon_contact_email', $user->lang['SEND_EMAIL']),
   1.199 +		'QUOTE_IMG'			=> $user->img('icon_post_quote', $user->lang['POST_QUOTE_PM']),
   1.200 +		'REPLY_IMG'			=> $user->img('button_pm_reply', $user->lang['POST_REPLY_PM']),
   1.201 +		'REPORT_IMG'		=> $user->img('icon_post_report', 'REPORT_PM'),
   1.202 +		'EDIT_IMG'			=> $user->img('icon_post_edit', $user->lang['POST_EDIT_PM']),
   1.203 +		'MINI_POST_IMG'		=> $user->img('icon_post_target', $user->lang['PM']),
   1.204 +
   1.205 +		'SENT_DATE'			=> ($view == 'print') ? $user->format_date($message_row['message_time'], false, true) : $user->format_date($message_row['message_time']),
   1.206 +		'SUBJECT'			=> $message_row['message_subject'],
   1.207 +		'MESSAGE'			=> $message,
   1.208 +		'SIGNATURE'			=> ($message_row['enable_sig']) ? $signature : '',
   1.209 +		'EDITED_MESSAGE'	=> $l_edited_by,
   1.210 +		'MESSAGE_ID'		=> $message_row['msg_id'],
   1.211 +
   1.212 +		'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&amp;mode=compose&amp;u=' . $author_id) : '',
   1.213 +		'U_WWW'			=> (!empty($user_info['user_website'])) ? $user_info['user_website'] : '',
   1.214 +		'U_ICQ'			=> ($user_info['user_icq']) ? 'http://www.icq.com/people/' . urlencode($user_info['user_icq']) . '/' : '',
   1.215 +		'U_AIM'			=> ($user_info['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=aim&amp;u=' . $author_id) : '',
   1.216 +		'U_YIM'			=> ($user_info['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user_info['user_yim']) . '&amp;.src=pg' : '',
   1.217 +		'U_MSN'			=> ($user_info['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=msnm&amp;u=' . $author_id) : '',
   1.218 +		'U_JABBER'		=> ($user_info['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=jabber&amp;u=' . $author_id) : '',
   1.219 +
   1.220 +		'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'] : '',
   1.221 +		'U_EMAIL'			=> $user_info['email'],
   1.222 +		'U_REPORT'			=> ($config['allow_pm_report']) ? append_sid("{$phpbb_root_path}report.$phpEx", "pm=" . $message_row['msg_id']) : '',
   1.223 +		'U_QUOTE'			=> ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=quote&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
   1.224 +		'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&amp;mode=compose&amp;action=edit&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
   1.225 +		'U_POST_REPLY_PM'	=> ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=reply&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
   1.226 +		'U_POST_REPLY_ALL'	=> ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=reply&amp;f=$folder_id&amp;reply_to_all=1&amp;p=" . $message_row['msg_id'] : '',
   1.227 +		'U_PREVIOUS_PM'		=> "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=previous",
   1.228 +		'U_NEXT_PM'			=> "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=next",
   1.229 +
   1.230 +		'U_PM_ACTION'		=> $url . '&amp;mode=compose&amp;f=' . $folder_id . '&amp;p=' . $message_row['msg_id'],
   1.231 +
   1.232 +		'S_HAS_ATTACHMENTS'	=> (sizeof($attachments)) ? true : false,
   1.233 +		'S_DISPLAY_NOTICE'	=> $display_notice && $message_row['message_attachment'],
   1.234 +		'S_AUTHOR_DELETED'	=> ($author_id == ANONYMOUS) ? true : false,
   1.235 +		'S_SPECIAL_FOLDER'	=> in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)),
   1.236 +		'S_PM_RECIPIENTS'	=> $num_recipients,
   1.237 +		'S_BBCODE_ALLOWED'	=> ($bbcode_status) ? 1 : 0,
   1.238 +
   1.239 +		'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" : '',
   1.240 +		'U_FORWARD_PM'		=> ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&amp;mode=compose&amp;action=forward&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '')
   1.241 +	);
   1.242 +
   1.243 +	// Display not already displayed Attachments for this post, we already parsed them. ;)
   1.244 +	if (isset($attachments) && sizeof($attachments))
   1.245 +	{
   1.246 +		foreach ($attachments as $attachment)
   1.247 +		{
   1.248 +			$template->assign_block_vars('attachment', array(
   1.249 +				'DISPLAY_ATTACHMENT'	=> $attachment)
   1.250 +			);
   1.251 +		}
   1.252 +	}
   1.253 +
   1.254 +	if (!isset($_REQUEST['view']) || $_REQUEST['view'] != 'print')
   1.255 +	{
   1.256 +		// Message History
   1.257 +		if (message_history($msg_id, $user->data['user_id'], $message_row, $folder))
   1.258 +		{
   1.259 +			$template->assign_var('S_DISPLAY_HISTORY', true);
   1.260 +		}
   1.261 +	}
   1.262 +}
   1.263 +
   1.264 +/**
   1.265 +* Get user information (only for message display)
   1.266 +*/
   1.267 +function get_user_information($user_id, $user_row)
   1.268 +{
   1.269 +	global $db, $auth, $user, $cache;
   1.270 +	global $phpbb_root_path, $phpEx, $config;
   1.271 +
   1.272 +	if (!$user_id)
   1.273 +	{
   1.274 +		return array();
   1.275 +	}
   1.276 +
   1.277 +	if (empty($user_row))
   1.278 +	{
   1.279 +		$sql = 'SELECT *
   1.280 +			FROM ' . USERS_TABLE . '
   1.281 +			WHERE user_id = ' . (int) $user_id;
   1.282 +		$result = $db->sql_query($sql);
   1.283 +		$user_row = $db->sql_fetchrow($result);
   1.284 +		$db->sql_freeresult($result);
   1.285 +	}
   1.286 +
   1.287 +	// Some standard values
   1.288 +	$user_row['online'] = false;
   1.289 +	$user_row['rank_title'] = $user_row['rank_image'] = $user_row['rank_image_src'] = $user_row['email'] = '';
   1.290 +
   1.291 +	// Generate online information for user
   1.292 +	if ($config['load_onlinetrack'])
   1.293 +	{
   1.294 +		$sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
   1.295 +			FROM ' . SESSIONS_TABLE . "
   1.296 +			WHERE session_user_id = $user_id
   1.297 +			GROUP BY session_user_id";
   1.298 +		$result = $db->sql_query_limit($sql, 1);
   1.299 +		$row = $db->sql_fetchrow($result);
   1.300 +		$db->sql_freeresult($result);
   1.301 +
   1.302 +		$update_time = $config['load_online_time'] * 60;
   1.303 +		if ($row)
   1.304 +		{
   1.305 +			$user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? true : false;
   1.306 +		}
   1.307 +	}
   1.308 +
   1.309 +	if (!function_exists('get_user_avatar'))
   1.310 +	{
   1.311 +		include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
   1.312 +	}
   1.313 +
   1.314 +	$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']) : '';
   1.315 +
   1.316 +	get_user_rank($user_row['user_rank'], $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']);
   1.317 +
   1.318 +	if ((!empty($user_row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email'))
   1.319 +	{
   1.320 +		$user_row['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;u=$user_id") : ((($config['board_hide_emails'] && !$auth->acl_get('a_email')) || empty($user_row['user_email'])) ? '' : 'mailto:' . $user_row['user_email']);
   1.321 +	}
   1.322 +
   1.323 +	return $user_row;
   1.324 +}
   1.325 +
   1.326 +?>
   1.327 \ No newline at end of file