PageRenderTime 61ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/mcp/mcp_post.php

https://github.com/Global-Conflict-Dev/Project-Phoenix
PHP | 501 lines | 371 code | 87 blank | 43 comment | 68 complexity | 7b3a2ceb8594ad63f475e88bd4694feb MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package mcp
  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. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * Handling actions in post details screen
  19. */
  20. function mcp_post_details($id, $mode, $action)
  21. {
  22. global $phpEx, $phpbb_root_path, $config;
  23. global $template, $db, $user, $auth, $cache;
  24. $user->add_lang('posting');
  25. $post_id = request_var('p', 0);
  26. $start = request_var('start', 0);
  27. // Get post data
  28. $post_info = get_post_data(array($post_id), false, true);
  29. add_form_key('mcp_post_details');
  30. if (!sizeof($post_info))
  31. {
  32. trigger_error('POST_NOT_EXIST');
  33. }
  34. $post_info = $post_info[$post_id];
  35. $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
  36. switch ($action)
  37. {
  38. case 'whois':
  39. if ($auth->acl_get('m_info', $post_info['forum_id']))
  40. {
  41. $ip = request_var('ip', '');
  42. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  43. $template->assign_vars(array(
  44. 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;p=$post_id") . '">', '</a>'),
  45. 'U_RETURN_POST' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;p=$post_id"),
  46. 'L_RETURN_POST' => sprintf($user->lang['RETURN_POST'], '', ''),
  47. 'WHOIS' => user_ipwhois($ip),
  48. ));
  49. }
  50. // We're done with the whois page so return
  51. return;
  52. break;
  53. case 'chgposter':
  54. case 'chgposter_ip':
  55. if ($action == 'chgposter')
  56. {
  57. $username = request_var('username', '', true);
  58. $sql_where = "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
  59. }
  60. else
  61. {
  62. $new_user_id = request_var('u', 0);
  63. $sql_where = 'user_id = ' . $new_user_id;
  64. }
  65. $sql = 'SELECT *
  66. FROM ' . USERS_TABLE . '
  67. WHERE ' . $sql_where;
  68. $result = $db->sql_query($sql);
  69. $row = $db->sql_fetchrow($result);
  70. $db->sql_freeresult($result);
  71. if (!$row)
  72. {
  73. trigger_error('NO_USER');
  74. }
  75. if ($auth->acl_get('m_chgposter', $post_info['forum_id']))
  76. {
  77. if (check_form_key('mcp_post_details'))
  78. {
  79. change_poster($post_info, $row);
  80. }
  81. else
  82. {
  83. trigger_error('FORM_INVALID');
  84. }
  85. }
  86. break;
  87. }
  88. // Set some vars
  89. $users_ary = $usernames_ary = array();
  90. $attachments = $extensions = array();
  91. $post_id = $post_info['post_id'];
  92. $topic_tracking_info = array();
  93. // Get topic tracking info
  94. if ($config['load_db_lastread'])
  95. {
  96. $tmp_topic_data = array($post_info['topic_id'] => $post_info);
  97. $topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
  98. unset($tmp_topic_data);
  99. }
  100. else
  101. {
  102. $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
  103. }
  104. $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
  105. // Process message, leave it uncensored
  106. $message = $post_info['post_text'];
  107. if ($post_info['bbcode_bitfield'])
  108. {
  109. include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  110. $bbcode = new bbcode($post_info['bbcode_bitfield']);
  111. $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
  112. }
  113. $message = bbcode_nl2br($message);
  114. $message = smiley_text($message);
  115. if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
  116. {
  117. $extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
  118. $sql = 'SELECT *
  119. FROM ' . ATTACHMENTS_TABLE . '
  120. WHERE post_msg_id = ' . $post_id . '
  121. AND in_message = 0
  122. ORDER BY filetime DESC, post_msg_id ASC';
  123. $result = $db->sql_query($sql);
  124. while ($row = $db->sql_fetchrow($result))
  125. {
  126. $attachments[] = $row;
  127. }
  128. $db->sql_freeresult($result);
  129. if (sizeof($attachments))
  130. {
  131. $update_count = array();
  132. parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
  133. }
  134. // Display not already displayed Attachments for this post, we already parsed them. ;)
  135. if (!empty($attachments))
  136. {
  137. $template->assign_var('S_HAS_ATTACHMENTS', true);
  138. foreach ($attachments as $attachment)
  139. {
  140. $template->assign_block_vars('attachment', array(
  141. 'DISPLAY_ATTACHMENT' => $attachment)
  142. );
  143. }
  144. }
  145. }
  146. $template->assign_vars(array(
  147. 'U_MCP_ACTION' => "$url&amp;i=main&amp;quickmod=1&amp;mode=post_details", // Use this for mode paramaters
  148. 'U_POST_ACTION' => "$url&amp;i=$id&amp;mode=post_details", // Use this for action parameters
  149. 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f={$post_info['forum_id']}"),
  150. 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
  151. 'S_CAN_CHGPOSTER' => $auth->acl_get('m_chgposter', $post_info['forum_id']),
  152. 'S_CAN_LOCK_POST' => $auth->acl_get('m_lock', $post_info['forum_id']),
  153. 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']),
  154. 'S_POST_REPORTED' => ($post_info['post_reported']) ? true : false,
  155. 'S_POST_UNAPPROVED' => (!$post_info['post_approved']) ? true : false,
  156. 'S_POST_LOCKED' => ($post_info['post_edit_locked']) ? true : false,
  157. 'S_USER_NOTES' => true,
  158. 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false,
  159. 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&amp;f={$post_info['forum_id']}&amp;p={$post_info['post_id']}") : '',
  160. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp_chgposter&amp;field=username&amp;select_single=true'),
  161. 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id),
  162. 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id),
  163. 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
  164. 'U_MCP_WARN_USER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $post_info['user_id']) : '',
  165. 'U_VIEW_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;p=' . $post_info['post_id'] . '#p' . $post_info['post_id']),
  166. 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']),
  167. 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
  168. 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_info['forum_id']}&amp;p=$post_id") . "#p$post_id\">", '</a>'),
  169. 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$post_info['forum_id']}&amp;start={$start}") . '">', '</a>'),
  170. 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
  171. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
  172. 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
  173. 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
  174. 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
  175. 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
  176. 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
  177. 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
  178. 'POST_PREVIEW' => $message,
  179. 'POST_SUBJECT' => $post_info['post_subject'],
  180. 'POST_DATE' => $user->format_date($post_info['post_time']),
  181. 'POST_IP' => $post_info['poster_ip'],
  182. 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
  183. 'POST_ID' => $post_info['post_id'],
  184. 'U_LOOKUP_IP' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? "$url&amp;i=$id&amp;mode=$mode&amp;lookup={$post_info['poster_ip']}#ip" : '',
  185. 'U_WHOIS' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;action=whois&amp;p=$post_id&amp;ip={$post_info['poster_ip']}") : '',
  186. ));
  187. // Get User Notes
  188. $log_data = array();
  189. $log_count = false;
  190. view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
  191. if (!empty($log_data))
  192. {
  193. $template->assign_var('S_USER_NOTES', true);
  194. foreach ($log_data as $row)
  195. {
  196. $template->assign_block_vars('usernotes', array(
  197. 'REPORT_BY' => $row['username_full'],
  198. 'REPORT_AT' => $user->format_date($row['time']),
  199. 'ACTION' => $row['action'],
  200. 'ID' => $row['id'])
  201. );
  202. }
  203. }
  204. // Get Reports
  205. if ($auth->acl_get('m_report', $post_info['forum_id']))
  206. {
  207. $sql = 'SELECT r.*, re.*, u.user_id, u.username
  208. FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u, ' . REPORTS_REASONS_TABLE . " re
  209. WHERE r.post_id = $post_id
  210. AND r.reason_id = re.reason_id
  211. AND u.user_id = r.user_id
  212. ORDER BY r.report_time DESC";
  213. $result = $db->sql_query($sql);
  214. if ($row = $db->sql_fetchrow($result))
  215. {
  216. $template->assign_var('S_SHOW_REPORTS', true);
  217. do
  218. {
  219. // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
  220. if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
  221. {
  222. $row['reson_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
  223. $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
  224. }
  225. $template->assign_block_vars('reports', array(
  226. 'REPORT_ID' => $row['report_id'],
  227. 'REASON_TITLE' => $row['reason_title'],
  228. 'REASON_DESC' => $row['reason_description'],
  229. 'REPORTER' => ($row['user_id'] != ANONYMOUS) ? $row['username'] : $user->lang['GUEST'],
  230. 'U_REPORTER' => ($row['user_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']) : '',
  231. 'USER_NOTIFY' => ($row['user_notify']) ? true : false,
  232. 'REPORT_TIME' => $user->format_date($row['report_time']),
  233. 'REPORT_TEXT' => bbcode_nl2br(trim($row['report_text'])),
  234. ));
  235. }
  236. while ($row = $db->sql_fetchrow($result));
  237. }
  238. $db->sql_freeresult($result);
  239. }
  240. // Get IP
  241. if ($auth->acl_get('m_info', $post_info['forum_id']))
  242. {
  243. $rdns_ip_num = request_var('rdns', '');
  244. if ($rdns_ip_num != 'all')
  245. {
  246. $template->assign_vars(array(
  247. 'U_LOOKUP_ALL' => "$url&amp;i=main&amp;mode=post_details&amp;rdns=all")
  248. );
  249. }
  250. // Get other users who've posted under this IP
  251. $sql = 'SELECT poster_id, COUNT(poster_id) as postings
  252. FROM ' . POSTS_TABLE . "
  253. WHERE poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
  254. GROUP BY poster_id
  255. ORDER BY postings DESC";
  256. $result = $db->sql_query($sql);
  257. while ($row = $db->sql_fetchrow($result))
  258. {
  259. // Fill the user select list with users who have posted under this IP
  260. if ($row['poster_id'] != $post_info['poster_id'])
  261. {
  262. $users_ary[$row['poster_id']] = $row;
  263. }
  264. }
  265. $db->sql_freeresult($result);
  266. if (sizeof($users_ary))
  267. {
  268. // Get the usernames
  269. $sql = 'SELECT user_id, username
  270. FROM ' . USERS_TABLE . '
  271. WHERE ' . $db->sql_in_set('user_id', array_keys($users_ary));
  272. $result = $db->sql_query($sql);
  273. while ($row = $db->sql_fetchrow($result))
  274. {
  275. $users_ary[$row['user_id']]['username'] = $row['username'];
  276. $usernames_ary[utf8_clean_string($row['username'])] = $users_ary[$row['user_id']];
  277. }
  278. $db->sql_freeresult($result);
  279. foreach ($users_ary as $user_id => $user_row)
  280. {
  281. $template->assign_block_vars('userrow', array(
  282. 'USERNAME' => ($user_id == ANONYMOUS) ? $user->lang['GUEST'] : $user_row['username'],
  283. 'NUM_POSTS' => $user_row['postings'],
  284. 'L_POST_S' => ($user_row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
  285. 'U_PROFILE' => ($user_id == ANONYMOUS) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id),
  286. 'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user_id . '&amp;sr=topics'))
  287. );
  288. }
  289. }
  290. // Get other IP's this user has posted under
  291. // A compound index on poster_id, poster_ip (posts table) would help speed up this query a lot,
  292. // but the extra size is only valuable if there are persons having more than a thousands posts.
  293. // This is better left to the really really big forums.
  294. $sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings
  295. FROM ' . POSTS_TABLE . '
  296. WHERE poster_id = ' . $post_info['poster_id'] . "
  297. GROUP BY poster_ip
  298. ORDER BY postings DESC";
  299. $result = $db->sql_query($sql);
  300. while ($row = $db->sql_fetchrow($result))
  301. {
  302. $hostname = (($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip']) ? @gethostbyaddr($row['poster_ip']) : '';
  303. $template->assign_block_vars('iprow', array(
  304. 'IP' => $row['poster_ip'],
  305. 'HOSTNAME' => $hostname,
  306. 'NUM_POSTS' => $row['postings'],
  307. 'L_POST_S' => ($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
  308. 'U_LOOKUP_IP' => ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? '' : "$url&amp;i=$id&amp;mode=post_details&amp;rdns={$row['poster_ip']}#ip",
  309. 'U_WHOIS' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;action=whois&amp;p=$post_id&amp;ip={$row['poster_ip']}"))
  310. );
  311. }
  312. $db->sql_freeresult($result);
  313. $user_select = '';
  314. if (sizeof($usernames_ary))
  315. {
  316. ksort($usernames_ary);
  317. foreach ($usernames_ary as $row)
  318. {
  319. $user_select .= '<option value="' . $row['poster_id'] . '">' . $row['username'] . "</option>\n";
  320. }
  321. }
  322. $template->assign_var('S_USER_SELECT', $user_select);
  323. }
  324. }
  325. /**
  326. * Change a post's poster
  327. */
  328. function change_poster(&$post_info, $userdata)
  329. {
  330. global $auth, $db, $config, $phpbb_root_path, $phpEx;
  331. if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
  332. {
  333. return;
  334. }
  335. $post_id = $post_info['post_id'];
  336. $sql = 'UPDATE ' . POSTS_TABLE . "
  337. SET poster_id = {$userdata['user_id']}
  338. WHERE post_id = $post_id";
  339. $db->sql_query($sql);
  340. // Resync topic/forum if needed
  341. if ($post_info['topic_last_post_id'] == $post_id || $post_info['forum_last_post_id'] == $post_id || $post_info['topic_first_post_id'] == $post_id)
  342. {
  343. sync('topic', 'topic_id', $post_info['topic_id'], false, false);
  344. sync('forum', 'forum_id', $post_info['forum_id'], false, false);
  345. }
  346. // Adjust post counts... only if the post is approved (else, it was not added the users post count anyway)
  347. if ($post_info['post_postcount'] && $post_info['post_approved'])
  348. {
  349. $sql = 'UPDATE ' . USERS_TABLE . '
  350. SET user_posts = user_posts - 1
  351. WHERE user_id = ' . $post_info['user_id'] .'
  352. AND user_posts > 0';
  353. $db->sql_query($sql);
  354. $sql = 'UPDATE ' . USERS_TABLE . '
  355. SET user_posts = user_posts + 1
  356. WHERE user_id = ' . $userdata['user_id'];
  357. $db->sql_query($sql);
  358. }
  359. // Add posted to information for this topic for the new user
  360. markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
  361. // Remove the dotted topic option if the old user has no more posts within this topic
  362. if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS)
  363. {
  364. $sql = 'SELECT topic_id
  365. FROM ' . POSTS_TABLE . '
  366. WHERE topic_id = ' . $post_info['topic_id'] . '
  367. AND poster_id = ' . $post_info['user_id'];
  368. $result = $db->sql_query_limit($sql, 1);
  369. $topic_id = (int) $db->sql_fetchfield('topic_id');
  370. $db->sql_freeresult($result);
  371. if (!$topic_id)
  372. {
  373. $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
  374. WHERE user_id = ' . $post_info['user_id'] . '
  375. AND topic_id = ' . $post_info['topic_id'];
  376. $db->sql_query($sql);
  377. }
  378. }
  379. // change the poster_id within the attachments table, else the data becomes out of sync and errors displayed because of wrong ownership
  380. if ($post_info['post_attachment'])
  381. {
  382. $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
  383. SET poster_id = ' . $userdata['user_id'] . '
  384. WHERE poster_id = ' . $post_info['user_id'] . '
  385. AND post_msg_id = ' . $post_info['post_id'] . '
  386. AND topic_id = ' . $post_info['topic_id'];
  387. $db->sql_query($sql);
  388. }
  389. // refresh search cache of this post
  390. $search_type = basename($config['search_type']);
  391. if (file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
  392. {
  393. require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
  394. // We do some additional checks in the module to ensure it can actually be utilised
  395. $error = false;
  396. $search = new $search_type($error);
  397. if (!$error && method_exists($search, 'destroy_cache'))
  398. {
  399. $search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
  400. }
  401. }
  402. $from_username = $post_info['username'];
  403. $to_username = $userdata['username'];
  404. // Renew post info
  405. $post_info = get_post_data(array($post_id), false, true);
  406. if (!sizeof($post_info))
  407. {
  408. trigger_error('POST_NOT_EXIST');
  409. }
  410. $post_info = $post_info[$post_id];
  411. // Now add log entry
  412. add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $from_username, $to_username);
  413. }
  414. ?>