PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/wwwroot/phpbb/includes/ucp/ucp_pm_viewmessage.php

https://github.com/spring/spring-website
PHP | 414 lines | 298 code | 61 blank | 55 comment | 74 complexity | 0e27c52f7ad744380fe84d6adc57d098 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, LGPL-3.0, BSD-3-Clause
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. if (!defined('IN_PHPBB'))
  17. {
  18. exit;
  19. }
  20. /**
  21. * View private message
  22. */
  23. function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
  24. {
  25. global $user, $template, $auth, $db, $cache, $phpbb_container;
  26. global $phpbb_root_path, $request, $phpEx, $config, $phpbb_dispatcher;
  27. $user->add_lang(array('viewtopic', 'memberlist'));
  28. $msg_id = (int) $msg_id;
  29. $folder_id = (int) $folder_id;
  30. $author_id = (int) $message_row['author_id'];
  31. $view = request_var('view', '');
  32. // Not able to view message, it was deleted by the sender
  33. if ($message_row['pm_deleted'])
  34. {
  35. $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;folder=$folder_id");
  36. $message = $user->lang['NO_AUTH_READ_REMOVED_MESSAGE'];
  37. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
  38. trigger_error($message);
  39. }
  40. // Do not allow hold messages to be seen
  41. if ($folder_id == PRIVMSGS_HOLD_BOX)
  42. {
  43. trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
  44. }
  45. // Grab icons
  46. $icons = $cache->obtain_icons();
  47. // Load the custom profile fields
  48. if ($config['load_cpf_pm'])
  49. {
  50. $cp = $phpbb_container->get('profilefields.manager');
  51. $profile_fields = $cp->grab_profile_fields_data($author_id);
  52. }
  53. // Assign TO/BCC Addresses to template
  54. write_pm_addresses(array('to' => $message_row['to_address'], 'bcc' => $message_row['bcc_address']), $author_id);
  55. $user_info = get_user_information($author_id, $message_row);
  56. // Parse the message and subject
  57. $parse_flags = ($message_row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
  58. $message = generate_text_for_display($message_row['message_text'], $message_row['bbcode_uid'], $message_row['bbcode_bitfield'], $parse_flags, true);
  59. // Replace naughty words such as farty pants
  60. $message_row['message_subject'] = censor_text($message_row['message_subject']);
  61. // Editing information
  62. if ($message_row['message_edit_count'] && $config['display_last_edited'])
  63. {
  64. if (!$message_row['message_edit_user'])
  65. {
  66. $display_username = get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour']);
  67. }
  68. else
  69. {
  70. $edit_user_info = get_user_information($message_row['message_edit_user'], false);
  71. $display_username = get_username_string('full', $message_row['message_edit_user'], $edit_user_info['username'], $edit_user_info['user_colour']);
  72. }
  73. $l_edited_by = '<br /><br />' . $user->lang('EDITED_TIMES_TOTAL', (int) $message_row['message_edit_count'], $display_username, $user->format_date($message_row['message_edit_time'], false, true));
  74. }
  75. else
  76. {
  77. $l_edited_by = '';
  78. }
  79. // Pull attachment data
  80. $display_notice = false;
  81. $attachments = array();
  82. if ($message_row['message_attachment'] && $config['allow_pm_attach'])
  83. {
  84. if ($auth->acl_get('u_pm_download'))
  85. {
  86. $sql = 'SELECT *
  87. FROM ' . ATTACHMENTS_TABLE . "
  88. WHERE post_msg_id = $msg_id
  89. AND in_message = 1
  90. ORDER BY filetime DESC, post_msg_id ASC";
  91. $result = $db->sql_query($sql);
  92. while ($row = $db->sql_fetchrow($result))
  93. {
  94. $attachments[] = $row;
  95. }
  96. $db->sql_freeresult($result);
  97. // No attachments exist, but message table thinks they do so go ahead and reset attach flags
  98. if (!sizeof($attachments))
  99. {
  100. $sql = 'UPDATE ' . PRIVMSGS_TABLE . "
  101. SET message_attachment = 0
  102. WHERE msg_id = $msg_id";
  103. $db->sql_query($sql);
  104. }
  105. }
  106. else
  107. {
  108. $display_notice = true;
  109. }
  110. }
  111. // Assign inline attachments
  112. if (!empty($attachments))
  113. {
  114. $update_count = array();
  115. parse_attachments(false, $message, $attachments, $update_count);
  116. // Update the attachment download counts
  117. if (sizeof($update_count))
  118. {
  119. $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
  120. SET download_count = download_count + 1
  121. WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
  122. $db->sql_query($sql);
  123. }
  124. }
  125. $user_info['sig'] = '';
  126. $signature = ($message_row['enable_sig'] && $config['allow_sig'] && $auth->acl_get('u_sig') && $user->optionget('viewsigs')) ? $user_info['user_sig'] : '';
  127. // End signature parsing, only if needed
  128. if ($signature)
  129. {
  130. $parse_flags = ($user_info['user_sig_bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
  131. $signature = generate_text_for_display($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield'], $parse_flags, true);
  132. }
  133. $url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
  134. // Number of "to" recipients
  135. $num_recipients = (int) preg_match_all('/:?(u|g)_([0-9]+):?/', $message_row['to_address'], $match);
  136. $bbcode_status = ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false;
  137. // Get the profile fields template data
  138. $cp_row = array();
  139. if ($config['load_cpf_pm'] && isset($profile_fields[$author_id]))
  140. {
  141. // Filter the fields we don't want to show
  142. foreach ($profile_fields[$author_id] as $used_ident => $profile_field)
  143. {
  144. if (!$profile_field['data']['field_show_on_pm'])
  145. {
  146. unset($profile_fields[$author_id][$used_ident]);
  147. }
  148. }
  149. if (isset($profile_fields[$author_id]))
  150. {
  151. $cp_row = $cp->generate_profile_fields_template_data($profile_fields[$author_id]);
  152. }
  153. }
  154. $u_pm = $u_jabber = '';
  155. if ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user_info['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')))
  156. {
  157. $u_pm = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;u=' . $author_id);
  158. }
  159. if ($config['jab_enable'] && $user_info['user_jabber'] && $auth->acl_get('u_sendim'))
  160. {
  161. $u_jabber = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=jabber&amp;u=' . $author_id);
  162. }
  163. $msg_data = array(
  164. 'MESSAGE_AUTHOR_FULL' => get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
  165. 'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
  166. 'MESSAGE_AUTHOR' => get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
  167. 'U_MESSAGE_AUTHOR' => get_username_string('profile', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
  168. 'RANK_TITLE' => $user_info['rank_title'],
  169. 'RANK_IMG' => $user_info['rank_image'],
  170. 'AUTHOR_AVATAR' => (isset($user_info['avatar'])) ? $user_info['avatar'] : '',
  171. 'AUTHOR_JOINED' => $user->format_date($user_info['user_regdate']),
  172. 'AUTHOR_POSTS' => (int) $user_info['user_posts'],
  173. 'U_AUTHOR_POSTS' => ($config['load_search'] && $auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$author_id&amp;sr=posts") : '',
  174. 'CONTACT_USER' => $user->lang('CONTACT_USER', get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username'])),
  175. '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'])),
  176. 'S_ONLINE' => (!$config['load_onlinetrack']) ? false : ((isset($user_info['online']) && $user_info['online']) ? true : false),
  177. 'DELETE_IMG' => $user->img('icon_post_delete', $user->lang['DELETE_MESSAGE']),
  178. 'INFO_IMG' => $user->img('icon_post_info', $user->lang['VIEW_PM_INFO']),
  179. 'PROFILE_IMG' => $user->img('icon_user_profile', $user->lang['READ_PROFILE']),
  180. 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['SEND_EMAIL']),
  181. 'QUOTE_IMG' => $user->img('icon_post_quote', $user->lang['POST_QUOTE_PM']),
  182. 'REPLY_IMG' => $user->img('button_pm_reply', $user->lang['POST_REPLY_PM']),
  183. 'REPORT_IMG' => $user->img('icon_post_report', 'REPORT_PM'),
  184. 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['POST_EDIT_PM']),
  185. 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']),
  186. 'SENT_DATE' => ($view == 'print') ? $user->format_date($message_row['message_time'], false, true) : $user->format_date($message_row['message_time']),
  187. 'SUBJECT' => $message_row['message_subject'],
  188. 'MESSAGE' => $message,
  189. 'SIGNATURE' => ($message_row['enable_sig']) ? $signature : '',
  190. 'EDITED_MESSAGE' => $l_edited_by,
  191. 'MESSAGE_ID' => $message_row['msg_id'],
  192. 'U_PM' => $u_pm,
  193. 'U_JABBER' => $u_jabber,
  194. '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'] : '',
  195. 'U_EMAIL' => $user_info['email'],
  196. 'U_REPORT' => ($config['allow_pm_report']) ? append_sid("{$phpbb_root_path}report.$phpEx", "pm=" . $message_row['msg_id']) : '',
  197. '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'] : '',
  198. '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'] : '',
  199. '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'] : '',
  200. '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'] : '',
  201. 'U_PREVIOUS_PM' => "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=previous",
  202. 'U_NEXT_PM' => "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=next",
  203. 'U_PM_ACTION' => $url . '&amp;mode=compose&amp;f=' . $folder_id . '&amp;p=' . $message_row['msg_id'],
  204. 'S_HAS_ATTACHMENTS' => (sizeof($attachments)) ? true : false,
  205. 'S_DISPLAY_NOTICE' => $display_notice && $message_row['message_attachment'],
  206. 'S_AUTHOR_DELETED' => ($author_id == ANONYMOUS) ? true : false,
  207. 'S_SPECIAL_FOLDER' => in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)),
  208. 'S_PM_RECIPIENTS' => $num_recipients,
  209. 'S_BBCODE_ALLOWED' => ($bbcode_status) ? 1 : 0,
  210. 'S_CUSTOM_FIELDS' => (!empty($cp_row['row'])) ? true : false,
  211. '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" : '',
  212. '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'] : '',
  213. );
  214. /**
  215. * Modify pm and sender data before it is assigned to the template
  216. *
  217. * @event core.ucp_pm_view_messsage
  218. * @var mixed id Active module category (can be int or string)
  219. * @var string mode Active module
  220. * @var int folder_id ID of the folder the message is in
  221. * @var int msg_id ID of the private message
  222. * @var array folder Array with data of user's message folders
  223. * @var array message_row Array with message data
  224. * @var array cp_row Array with senders custom profile field data
  225. * @var array msg_data Template array with message data
  226. * @since 3.1.0-a1
  227. */
  228. $vars = array(
  229. 'id',
  230. 'mode',
  231. 'folder_id',
  232. 'msg_id',
  233. 'folder',
  234. 'message_row',
  235. 'cp_row',
  236. 'msg_data',
  237. );
  238. extract($phpbb_dispatcher->trigger_event('core.ucp_pm_view_messsage', compact($vars)));
  239. $template->assign_vars($msg_data);
  240. $contact_fields = array(
  241. array(
  242. 'ID' => 'pm',
  243. 'NAME' => $user->lang['SEND_PRIVATE_MESSAGE'],
  244. 'U_CONTACT' => $u_pm,
  245. ),
  246. array(
  247. 'ID' => 'email',
  248. 'NAME' => $user->lang['SEND_EMAIL'],
  249. 'U_CONTACT' => $user_info['email'],
  250. ),
  251. array(
  252. 'ID' => 'jabber',
  253. 'NAME' => $user->lang['JABBER'],
  254. 'U_CONTACT' => $u_jabber,
  255. ),
  256. );
  257. foreach ($contact_fields as $field)
  258. {
  259. if ($field['U_CONTACT'])
  260. {
  261. $template->assign_block_vars('contact', $field);
  262. }
  263. }
  264. // Display the custom profile fields
  265. if (!empty($cp_row['row']))
  266. {
  267. $template->assign_vars($cp_row['row']);
  268. foreach ($cp_row['blockrow'] as $cp_block_row)
  269. {
  270. $template->assign_block_vars('custom_fields', $cp_block_row);
  271. if ($cp_block_row['S_PROFILE_CONTACT'])
  272. {
  273. $template->assign_block_vars('contact', array(
  274. 'ID' => $cp_block_row['PROFILE_FIELD_IDENT'],
  275. 'NAME' => $cp_block_row['PROFILE_FIELD_NAME'],
  276. 'U_CONTACT' => $cp_block_row['PROFILE_FIELD_CONTACT'],
  277. ));
  278. }
  279. }
  280. }
  281. // Display not already displayed Attachments for this post, we already parsed them. ;)
  282. if (isset($attachments) && sizeof($attachments))
  283. {
  284. foreach ($attachments as $attachment)
  285. {
  286. $template->assign_block_vars('attachment', array(
  287. 'DISPLAY_ATTACHMENT' => $attachment)
  288. );
  289. }
  290. }
  291. if (!isset($_REQUEST['view']) || $request->variable('view', '') != 'print')
  292. {
  293. // Message History
  294. if (message_history($msg_id, $user->data['user_id'], $message_row, $folder))
  295. {
  296. $template->assign_var('S_DISPLAY_HISTORY', true);
  297. }
  298. }
  299. }
  300. /**
  301. * Get user information (only for message display)
  302. */
  303. function get_user_information($user_id, $user_row)
  304. {
  305. global $db, $auth, $user, $cache;
  306. global $phpbb_root_path, $phpEx, $config;
  307. if (!$user_id)
  308. {
  309. return array();
  310. }
  311. if (empty($user_row))
  312. {
  313. $sql = 'SELECT *
  314. FROM ' . USERS_TABLE . '
  315. WHERE user_id = ' . (int) $user_id;
  316. $result = $db->sql_query($sql);
  317. $user_row = $db->sql_fetchrow($result);
  318. $db->sql_freeresult($result);
  319. }
  320. // Some standard values
  321. $user_row['online'] = false;
  322. $user_row['rank_title'] = $user_row['rank_image'] = $user_row['rank_image_src'] = $user_row['email'] = '';
  323. // Generate online information for user
  324. if ($config['load_onlinetrack'])
  325. {
  326. $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
  327. FROM ' . SESSIONS_TABLE . "
  328. WHERE session_user_id = $user_id
  329. GROUP BY session_user_id";
  330. $result = $db->sql_query_limit($sql, 1);
  331. $row = $db->sql_fetchrow($result);
  332. $db->sql_freeresult($result);
  333. $update_time = $config['load_online_time'] * 60;
  334. if ($row)
  335. {
  336. $user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? true : false;
  337. }
  338. }
  339. $user_row['avatar'] = ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($user_row) : '';
  340. if (!function_exists('phpbb_get_user_rank'))
  341. {
  342. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  343. }
  344. $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']);
  345. $user_row['rank_title'] = $user_rank_data['title'];
  346. $user_row['rank_image'] = $user_rank_data['img'];
  347. $user_row['rank_image_src'] = $user_rank_data['img_src'];
  348. if ((!empty($user_row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email'))
  349. {
  350. $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']);
  351. }
  352. return $user_row;
  353. }