| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | *
|
|---|
| 4 | * @package ucp
|
|---|
| 5 | * @version $Id$
|
|---|
| 6 | * @copyright (c) 2005 phpBB Group
|
|---|
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * @ignore
|
|---|
| 13 | */
|
|---|
| 14 | if (!defined('IN_PHPBB'))
|
|---|
| 15 | {
|
|---|
| 16 | exit;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * View private message
|
|---|
| 21 | */
|
|---|
| 22 | function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
|
|---|
| 23 | {
|
|---|
| 24 | global $user, $template, $auth, $db, $cache;
|
|---|
| 25 | global $phpbb_root_path, $phpEx, $config;
|
|---|
| 26 |
|
|---|
| 27 | $user->add_lang(array('viewtopic', 'memberlist'));
|
|---|
| 28 |
|
|---|
| 29 | $msg_id = (int) $msg_id;
|
|---|
| 30 | $folder_id = (int) $folder_id;
|
|---|
| 31 | $author_id = (int) $message_row['author_id'];
|
|---|
| 32 | $view = request_var('view', '');
|
|---|
| 33 |
|
|---|
| 34 | // Not able to view message, it was deleted by the sender
|
|---|
| 35 | if ($message_row['pm_deleted'])
|
|---|
| 36 | {
|
|---|
| 37 | $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&folder=$folder_id");
|
|---|
| 38 | $message = $user->lang['NO_AUTH_READ_REMOVED_MESSAGE'];
|
|---|
| 39 |
|
|---|
| 40 | $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
|
|---|
| 41 | trigger_error($message);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | // Do not allow hold messages to be seen
|
|---|
| 45 | if ($folder_id == PRIVMSGS_HOLD_BOX)
|
|---|
| 46 | {
|
|---|
| 47 | trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | // Grab icons
|
|---|
| 51 | $icons = $cache->obtain_icons();
|
|---|
| 52 |
|
|---|
| 53 | $bbcode = false;
|
|---|
| 54 |
|
|---|
| 55 | // Instantiate BBCode if need be
|
|---|
| 56 | if ($message_row['bbcode_bitfield'])
|
|---|
| 57 | {
|
|---|
| 58 | include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
|
|---|
| 59 | $bbcode = new bbcode($message_row['bbcode_bitfield']);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | // Assign TO/BCC Addresses to template
|
|---|
| 63 | write_pm_addresses(array('to' => $message_row['to_address'], 'bcc' => $message_row['bcc_address']), $author_id);
|
|---|
| 64 |
|
|---|
| 65 | $user_info = get_user_information($author_id, $message_row);
|
|---|
| 66 |
|
|---|
| 67 | // Parse the message and subject
|
|---|
| 68 | $message = censor_text($message_row['message_text']);
|
|---|
| 69 |
|
|---|
| 70 | // Second parse bbcode here
|
|---|
| 71 | if ($message_row['bbcode_bitfield'])
|
|---|
| 72 | {
|
|---|
| 73 | $bbcode->bbcode_second_pass($message, $message_row['bbcode_uid'], $message_row['bbcode_bitfield']);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | // Always process smilies after parsing bbcodes
|
|---|
| 77 | $message = bbcode_nl2br($message);
|
|---|
| 78 | $message = smiley_text($message);
|
|---|
| 79 |
|
|---|
| 80 | // Replace naughty words such as farty pants
|
|---|
| 81 | $message_row['message_subject'] = censor_text($message_row['message_subject']);
|
|---|
| 82 |
|
|---|
| 83 | // Editing information
|
|---|
| 84 | if ($message_row['message_edit_count'] && $config['display_last_edited'])
|
|---|
| 85 | {
|
|---|
| 86 | $l_edit_time_total = ($message_row['message_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
|
|---|
| 87 | $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']);
|
|---|
| 88 | }
|
|---|
| 89 | else
|
|---|
| 90 | {
|
|---|
| 91 | $l_edited_by = '';
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | // Pull attachment data
|
|---|
| 95 | $display_notice = false;
|
|---|
| 96 | $attachments = array();
|
|---|
| 97 |
|
|---|
| 98 | if ($message_row['message_attachment'] && $config['allow_pm_attach'])
|
|---|
| 99 | {
|
|---|
| 100 | if ($auth->acl_get('u_pm_download'))
|
|---|
| 101 | {
|
|---|
| 102 | $sql = 'SELECT *
|
|---|
| 103 | FROM ' . ATTACHMENTS_TABLE . "
|
|---|
| 104 | WHERE post_msg_id = $msg_id
|
|---|
| 105 | AND in_message = 1
|
|---|
| 106 | ORDER BY filetime DESC, post_msg_id ASC";
|
|---|
| 107 | $result = $db->sql_query($sql);
|
|---|
| 108 |
|
|---|
| 109 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 110 | {
|
|---|
| 111 | $attachments[] = $row;
|
|---|
| 112 | }
|
|---|
| 113 | $db->sql_freeresult($result);
|
|---|
| 114 |
|
|---|
| 115 | // No attachments exist, but message table thinks they do so go ahead and reset attach flags
|
|---|
| 116 | if (!sizeof($attachments))
|
|---|
| 117 | {
|
|---|
| 118 | $sql = 'UPDATE ' . PRIVMSGS_TABLE . "
|
|---|
| 119 | SET message_attachment = 0
|
|---|
| 120 | WHERE msg_id = $msg_id";
|
|---|
| 121 | $db->sql_query($sql);
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | else
|
|---|
| 125 | {
|
|---|
| 126 | $display_notice = true;
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | // Assign inline attachments
|
|---|
| 131 | if (!empty($attachments))
|
|---|
| 132 | {
|
|---|
| 133 | $update_count = array();
|
|---|
| 134 | parse_attachments(false, $message, $attachments, $update_count);
|
|---|
| 135 |
|
|---|
| 136 | // Update the attachment download counts
|
|---|
| 137 | if (sizeof($update_count))
|
|---|
| 138 | {
|
|---|
| 139 | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
|
|---|
| 140 | SET download_count = download_count + 1
|
|---|
| 141 | WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
|
|---|
| 142 | $db->sql_query($sql);
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | $user_info['sig'] = '';
|
|---|
| 147 |
|
|---|
| 148 | $signature = ($message_row['enable_sig'] && $config['allow_sig'] && $auth->acl_get('u_sig') && $user->optionget('viewsigs')) ? $user_info['user_sig'] : '';
|
|---|
| 149 |
|
|---|
| 150 | // End signature parsing, only if needed
|
|---|
| 151 | if ($signature)
|
|---|
| 152 | {
|
|---|
| 153 | $signature = censor_text($signature);
|
|---|
| 154 |
|
|---|
| 155 | if ($user_info['user_sig_bbcode_bitfield'])
|
|---|
| 156 | {
|
|---|
| 157 | if ($bbcode === false)
|
|---|
| 158 | {
|
|---|
| 159 | include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
|
|---|
| 160 | $bbcode = new bbcode($user_info['user_sig_bbcode_bitfield']);
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | $bbcode->bbcode_second_pass($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield']);
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | $signature = bbcode_nl2br($signature);
|
|---|
| 167 | $signature = smiley_text($signature);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | $url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
|
|---|
| 171 |
|
|---|
| 172 | // Number of "to" recipients
|
|---|
| 173 | $num_recipients = (int) preg_match_all('/:?(u|g)_([0-9]+):?/', $message_row['to_address'], $match);
|
|---|
| 174 |
|
|---|
| 175 | $template->assign_vars(array(
|
|---|
| 176 | 'MESSAGE_AUTHOR_FULL' => get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
|
|---|
| 177 | 'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
|
|---|
| 178 | 'MESSAGE_AUTHOR' => get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
|
|---|
| 179 | 'U_MESSAGE_AUTHOR' => get_username_string('profile', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
|
|---|
| 180 |
|
|---|
| 181 | 'RANK_TITLE' => $user_info['rank_title'],
|
|---|
| 182 | 'RANK_IMG' => $user_info['rank_image'],
|
|---|
| 183 | 'AUTHOR_AVATAR' => (isset($user_info['avatar'])) ? $user_info['avatar'] : '',
|
|---|
| 184 | 'AUTHOR_JOINED' => $user->format_date($user_info['user_regdate']),
|
|---|
| 185 | 'AUTHOR_POSTS' => (int) $user_info['user_posts'],
|
|---|
| 186 | 'AUTHOR_FROM' => (!empty($user_info['user_from'])) ? $user_info['user_from'] : '',
|
|---|
| 187 |
|
|---|
| 188 | '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'])),
|
|---|
| 189 | 'S_ONLINE' => (!$config['load_onlinetrack']) ? false : ((isset($user_info['online']) && $user_info['online']) ? true : false),
|
|---|
| 190 | 'DELETE_IMG' => $user->img('icon_post_delete', $user->lang['DELETE_MESSAGE']),
|
|---|
| 191 | 'INFO_IMG' => $user->img('icon_post_info', $user->lang['VIEW_PM_INFO']),
|
|---|
| 192 | 'PROFILE_IMG' => $user->img('icon_user_profile', $user->lang['READ_PROFILE']),
|
|---|
| 193 | 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['SEND_EMAIL']),
|
|---|
| 194 | 'QUOTE_IMG' => $user->img('icon_post_quote', $user->lang['POST_QUOTE_PM']),
|
|---|
| 195 | 'REPLY_IMG' => $user->img('button_pm_reply', $user->lang['POST_REPLY_PM']),
|
|---|
| 196 | 'REPORT_IMG' => $user->img('icon_post_report', 'REPORT_PM'),
|
|---|
| 197 | 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['POST_EDIT_PM']),
|
|---|
| 198 | 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']),
|
|---|
| 199 |
|
|---|
| 200 | 'SENT_DATE' => ($view == 'print') ? $user->format_date($message_row['message_time'], false, true) : $user->format_date($message_row['message_time']),
|
|---|
| 201 | 'SUBJECT' => $message_row['message_subject'],
|
|---|
| 202 | 'MESSAGE' => $message,
|
|---|
| 203 | 'SIGNATURE' => ($message_row['enable_sig']) ? $signature : '',
|
|---|
| 204 | 'EDITED_MESSAGE' => $l_edited_by,
|
|---|
| 205 | 'MESSAGE_ID' => $message_row['msg_id'],
|
|---|
| 206 |
|
|---|
| 207 | '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) : '',
|
|---|
| 208 | 'U_WWW' => (!empty($user_info['user_website'])) ? $user_info['user_website'] : '',
|
|---|
| 209 | 'U_ICQ' => ($user_info['user_icq']) ? 'http://www.icq.com/people/webmsg.php?to=' . urlencode($user_info['user_icq']) : '',
|
|---|
| 210 | '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) : '',
|
|---|
| 211 | 'U_YIM' => ($user_info['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user_info['user_yim']) . '&.src=pg' : '',
|
|---|
| 212 | '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) : '',
|
|---|
| 213 | '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) : '',
|
|---|
| 214 |
|
|---|
| 215 | 'U_DELETE' => ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '',
|
|---|
| 216 | 'U_EMAIL' => $user_info['email'],
|
|---|
| 217 | 'U_REPORT' => ($config['allow_pm_report']) ? append_sid("{$phpbb_root_path}report.$phpEx", "pm=" . $message_row['msg_id']) : '',
|
|---|
| 218 | 'U_QUOTE' => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=quote&f=$folder_id&p=" . $message_row['msg_id'] : '',
|
|---|
| 219 | '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'] : '',
|
|---|
| 220 | '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'] : '',
|
|---|
| 221 | 'U_POST_REPLY_ALL' => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=reply&f=$folder_id&reply_to_all=1&p=" . $message_row['msg_id'] : '',
|
|---|
| 222 | 'U_PREVIOUS_PM' => "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=previous",
|
|---|
| 223 | 'U_NEXT_PM' => "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=next",
|
|---|
| 224 |
|
|---|
| 225 | 'U_PM_ACTION' => $url . '&mode=compose&f=' . $folder_id . '&p=' . $message_row['msg_id'],
|
|---|
| 226 |
|
|---|
| 227 | 'S_HAS_ATTACHMENTS' => (sizeof($attachments)) ? true : false,
|
|---|
| 228 | 'S_DISPLAY_NOTICE' => $display_notice && $message_row['message_attachment'],
|
|---|
| 229 | 'S_AUTHOR_DELETED' => ($author_id == ANONYMOUS) ? true : false,
|
|---|
| 230 | 'S_SPECIAL_FOLDER' => in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)),
|
|---|
| 231 | 'S_PM_RECIPIENTS' => $num_recipients,
|
|---|
| 232 |
|
|---|
| 233 | 'U_PRINT_PM' => ($config['print_pm'] && $auth->acl_get('u_pm_printpm')) ? "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=print" : '',
|
|---|
| 234 | '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'] : '')
|
|---|
| 235 | );
|
|---|
| 236 |
|
|---|
| 237 | // Display not already displayed Attachments for this post, we already parsed them. ;)
|
|---|
| 238 | if (isset($attachments) && sizeof($attachments))
|
|---|
| 239 | {
|
|---|
| 240 | foreach ($attachments as $attachment)
|
|---|
| 241 | {
|
|---|
| 242 | $template->assign_block_vars('attachment', array(
|
|---|
| 243 | 'DISPLAY_ATTACHMENT' => $attachment)
|
|---|
| 244 | );
|
|---|
| 245 | }
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | if (!isset($_REQUEST['view']) || $_REQUEST['view'] != 'print')
|
|---|
| 249 | {
|
|---|
| 250 | // Message History
|
|---|
| 251 | if (message_history($msg_id, $user->data['user_id'], $message_row, $folder))
|
|---|
| 252 | {
|
|---|
| 253 | $template->assign_var('S_DISPLAY_HISTORY', true);
|
|---|
| 254 | }
|
|---|
| 255 | }
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | /**
|
|---|
| 259 | * Get user information (only for message display)
|
|---|
| 260 | */
|
|---|
| 261 | function get_user_information($user_id, $user_row)
|
|---|
| 262 | {
|
|---|
| 263 | global $db, $auth, $user, $cache;
|
|---|
| 264 | global $phpbb_root_path, $phpEx, $config;
|
|---|
| 265 |
|
|---|
| 266 | if (!$user_id)
|
|---|
| 267 | {
|
|---|
| 268 | return array();
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | if (empty($user_row))
|
|---|
| 272 | {
|
|---|
| 273 | $sql = 'SELECT *
|
|---|
| 274 | FROM ' . USERS_TABLE . '
|
|---|
| 275 | WHERE user_id = ' . (int) $user_id;
|
|---|
| 276 | $result = $db->sql_query($sql);
|
|---|
| 277 | $user_row = $db->sql_fetchrow($result);
|
|---|
| 278 | $db->sql_freeresult($result);
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | // Some standard values
|
|---|
| 282 | $user_row['online'] = false;
|
|---|
| 283 | $user_row['rank_title'] = $user_row['rank_image'] = $user_row['rank_image_src'] = $user_row['email'] = '';
|
|---|
| 284 |
|
|---|
| 285 | // Generate online information for user
|
|---|
| 286 | if ($config['load_onlinetrack'])
|
|---|
| 287 | {
|
|---|
| 288 | $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
|
|---|
| 289 | FROM ' . SESSIONS_TABLE . "
|
|---|
| 290 | WHERE session_user_id = $user_id
|
|---|
| 291 | GROUP BY session_user_id";
|
|---|
| 292 | $result = $db->sql_query_limit($sql, 1);
|
|---|
| 293 | $row = $db->sql_fetchrow($result);
|
|---|
| 294 | $db->sql_freeresult($result);
|
|---|
| 295 |
|
|---|
| 296 | $update_time = $config['load_online_time'] * 60;
|
|---|
| 297 | if ($row)
|
|---|
| 298 | {
|
|---|
| 299 | $user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? true : false;
|
|---|
| 300 | }
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | if (!function_exists('get_user_avatar'))
|
|---|
| 304 | {
|
|---|
| 305 | include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | $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']) : '';
|
|---|
| 309 |
|
|---|
| 310 | get_user_rank($user_row['user_rank'], $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']);
|
|---|
| 311 |
|
|---|
| 312 | if (!empty($user_row['user_allow_viewemail']) || $auth->acl_get('a_email'))
|
|---|
| 313 | {
|
|---|
| 314 | $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']);
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | return $user_row;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | ?>
|
|---|