|
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 $bbcode_status = ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false; |
|
176 |
|
177 $template->assign_vars(array( |
|
178 'MESSAGE_AUTHOR_FULL' => get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']), |
|
179 'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']), |
|
180 'MESSAGE_AUTHOR' => get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']), |
|
181 'U_MESSAGE_AUTHOR' => get_username_string('profile', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']), |
|
182 |
|
183 'RANK_TITLE' => $user_info['rank_title'], |
|
184 'RANK_IMG' => $user_info['rank_image'], |
|
185 'AUTHOR_AVATAR' => (isset($user_info['avatar'])) ? $user_info['avatar'] : '', |
|
186 'AUTHOR_JOINED' => $user->format_date($user_info['user_regdate']), |
|
187 'AUTHOR_POSTS' => (int) $user_info['user_posts'], |
|
188 'AUTHOR_FROM' => (!empty($user_info['user_from'])) ? $user_info['user_from'] : '', |
|
189 |
|
190 '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'])), |
|
191 'S_ONLINE' => (!$config['load_onlinetrack']) ? false : ((isset($user_info['online']) && $user_info['online']) ? true : false), |
|
192 'DELETE_IMG' => $user->img('icon_post_delete', $user->lang['DELETE_MESSAGE']), |
|
193 'INFO_IMG' => $user->img('icon_post_info', $user->lang['VIEW_PM_INFO']), |
|
194 'PROFILE_IMG' => $user->img('icon_user_profile', $user->lang['READ_PROFILE']), |
|
195 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['SEND_EMAIL']), |
|
196 'QUOTE_IMG' => $user->img('icon_post_quote', $user->lang['POST_QUOTE_PM']), |
|
197 'REPLY_IMG' => $user->img('button_pm_reply', $user->lang['POST_REPLY_PM']), |
|
198 'REPORT_IMG' => $user->img('icon_post_report', 'REPORT_PM'), |
|
199 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['POST_EDIT_PM']), |
|
200 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']), |
|
201 |
|
202 'SENT_DATE' => ($view == 'print') ? $user->format_date($message_row['message_time'], false, true) : $user->format_date($message_row['message_time']), |
|
203 'SUBJECT' => $message_row['message_subject'], |
|
204 'MESSAGE' => $message, |
|
205 'SIGNATURE' => ($message_row['enable_sig']) ? $signature : '', |
|
206 'EDITED_MESSAGE' => $l_edited_by, |
|
207 'MESSAGE_ID' => $message_row['msg_id'], |
|
208 |
|
209 '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) : '', |
|
210 'U_WWW' => (!empty($user_info['user_website'])) ? $user_info['user_website'] : '', |
|
211 'U_ICQ' => ($user_info['user_icq']) ? 'http://www.icq.com/people/' . urlencode($user_info['user_icq']) . '/' : '', |
|
212 '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) : '', |
|
213 'U_YIM' => ($user_info['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user_info['user_yim']) . '&.src=pg' : '', |
|
214 '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) : '', |
|
215 '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) : '', |
|
216 |
|
217 'U_DELETE' => ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '', |
|
218 'U_EMAIL' => $user_info['email'], |
|
219 'U_REPORT' => ($config['allow_pm_report']) ? append_sid("{$phpbb_root_path}report.$phpEx", "pm=" . $message_row['msg_id']) : '', |
|
220 'U_QUOTE' => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=quote&f=$folder_id&p=" . $message_row['msg_id'] : '', |
|
221 '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'] : '', |
|
222 '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'] : '', |
|
223 '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'] : '', |
|
224 'U_PREVIOUS_PM' => "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=previous", |
|
225 'U_NEXT_PM' => "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=next", |
|
226 |
|
227 'U_PM_ACTION' => $url . '&mode=compose&f=' . $folder_id . '&p=' . $message_row['msg_id'], |
|
228 |
|
229 'S_HAS_ATTACHMENTS' => (sizeof($attachments)) ? true : false, |
|
230 'S_DISPLAY_NOTICE' => $display_notice && $message_row['message_attachment'], |
|
231 'S_AUTHOR_DELETED' => ($author_id == ANONYMOUS) ? true : false, |
|
232 'S_SPECIAL_FOLDER' => in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)), |
|
233 'S_PM_RECIPIENTS' => $num_recipients, |
|
234 'S_BBCODE_ALLOWED' => ($bbcode_status) ? 1 : 0, |
|
235 |
|
236 'U_PRINT_PM' => ($config['print_pm'] && $auth->acl_get('u_pm_printpm')) ? "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=print" : '', |
|
237 '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'] : '') |
|
238 ); |
|
239 |
|
240 // Display not already displayed Attachments for this post, we already parsed them. ;) |
|
241 if (isset($attachments) && sizeof($attachments)) |
|
242 { |
|
243 foreach ($attachments as $attachment) |
|
244 { |
|
245 $template->assign_block_vars('attachment', array( |
|
246 'DISPLAY_ATTACHMENT' => $attachment) |
|
247 ); |
|
248 } |
|
249 } |
|
250 |
|
251 if (!isset($_REQUEST['view']) || $_REQUEST['view'] != 'print') |
|
252 { |
|
253 // Message History |
|
254 if (message_history($msg_id, $user->data['user_id'], $message_row, $folder)) |
|
255 { |
|
256 $template->assign_var('S_DISPLAY_HISTORY', true); |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 /** |
|
262 * Get user information (only for message display) |
|
263 */ |
|
264 function get_user_information($user_id, $user_row) |
|
265 { |
|
266 global $db, $auth, $user, $cache; |
|
267 global $phpbb_root_path, $phpEx, $config; |
|
268 |
|
269 if (!$user_id) |
|
270 { |
|
271 return array(); |
|
272 } |
|
273 |
|
274 if (empty($user_row)) |
|
275 { |
|
276 $sql = 'SELECT * |
|
277 FROM ' . USERS_TABLE . ' |
|
278 WHERE user_id = ' . (int) $user_id; |
|
279 $result = $db->sql_query($sql); |
|
280 $user_row = $db->sql_fetchrow($result); |
|
281 $db->sql_freeresult($result); |
|
282 } |
|
283 |
|
284 // Some standard values |
|
285 $user_row['online'] = false; |
|
286 $user_row['rank_title'] = $user_row['rank_image'] = $user_row['rank_image_src'] = $user_row['email'] = ''; |
|
287 |
|
288 // Generate online information for user |
|
289 if ($config['load_onlinetrack']) |
|
290 { |
|
291 $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline |
|
292 FROM ' . SESSIONS_TABLE . " |
|
293 WHERE session_user_id = $user_id |
|
294 GROUP BY session_user_id"; |
|
295 $result = $db->sql_query_limit($sql, 1); |
|
296 $row = $db->sql_fetchrow($result); |
|
297 $db->sql_freeresult($result); |
|
298 |
|
299 $update_time = $config['load_online_time'] * 60; |
|
300 if ($row) |
|
301 { |
|
302 $user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? true : false; |
|
303 } |
|
304 } |
|
305 |
|
306 if (!function_exists('get_user_avatar')) |
|
307 { |
|
308 include($phpbb_root_path . 'includes/functions_display.' . $phpEx); |
|
309 } |
|
310 |
|
311 $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']) : ''; |
|
312 |
|
313 get_user_rank($user_row['user_rank'], $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']); |
|
314 |
|
315 if ((!empty($user_row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email')) |
|
316 { |
|
317 $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']); |
|
318 } |
|
319 |
|
320 return $user_row; |
|
321 } |
|
322 |
|
323 ?> |