[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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 /** 15 * @ignore 16 */ 17 if (!defined('IN_PHPBB')) 18 { 19 exit; 20 } 21 22 /** 23 * Handling actions in post details screen 24 */ 25 function mcp_post_details($id, $mode, $action) 26 { 27 global $phpEx, $phpbb_root_path, $config, $request; 28 global $template, $db, $user, $auth, $cache, $phpbb_container; 29 global $phpbb_dispatcher; 30 31 $user->add_lang('posting'); 32 33 $post_id = request_var('p', 0); 34 $start = request_var('start', 0); 35 36 // Get post data 37 $post_info = phpbb_get_post_data(array($post_id), false, true); 38 39 add_form_key('mcp_post_details'); 40 41 if (!sizeof($post_info)) 42 { 43 trigger_error('POST_NOT_EXIST'); 44 } 45 46 $post_info = $post_info[$post_id]; 47 $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . phpbb_extra_url()); 48 49 switch ($action) 50 { 51 case 'whois': 52 53 if ($auth->acl_get('m_info', $post_info['forum_id'])) 54 { 55 $ip = request_var('ip', ''); 56 if (!function_exists('user_ipwhois')) 57 { 58 include($phpbb_root_path . 'includes/functions_user.' . $phpEx); 59 } 60 61 $template->assign_vars(array( 62 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&mode=$mode&p=$post_id") . '">', '</a>'), 63 'U_RETURN_POST' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&mode=$mode&p=$post_id"), 64 'L_RETURN_POST' => sprintf($user->lang['RETURN_POST'], '', ''), 65 'WHOIS' => user_ipwhois($ip), 66 )); 67 } 68 69 // We're done with the whois page so return 70 return; 71 72 break; 73 74 case 'chgposter': 75 case 'chgposter_ip': 76 77 if ($action == 'chgposter') 78 { 79 $username = request_var('username', '', true); 80 $sql_where = "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; 81 } 82 else 83 { 84 $new_user_id = request_var('u', 0); 85 $sql_where = 'user_id = ' . $new_user_id; 86 } 87 88 $sql = 'SELECT * 89 FROM ' . USERS_TABLE . ' 90 WHERE ' . $sql_where; 91 $result = $db->sql_query($sql); 92 $row = $db->sql_fetchrow($result); 93 $db->sql_freeresult($result); 94 95 if (!$row) 96 { 97 trigger_error('NO_USER'); 98 } 99 100 if ($auth->acl_get('m_chgposter', $post_info['forum_id'])) 101 { 102 if (check_form_key('mcp_post_details')) 103 { 104 change_poster($post_info, $row); 105 } 106 else 107 { 108 trigger_error('FORM_INVALID'); 109 } 110 } 111 112 break; 113 114 default: 115 116 /** 117 * This event allows you to handle custom post moderation options 118 * 119 * @event core.mcp_post_additional_options 120 * @var string action Post moderation action name 121 * @var array post_info Information on the affected post 122 * @since 3.1.5-RC1 123 */ 124 $vars = array('action', 'post_info'); 125 extract($phpbb_dispatcher->trigger_event('core.mcp_post_additional_options', compact($vars))); 126 127 break; 128 } 129 130 // Set some vars 131 $users_ary = $usernames_ary = array(); 132 $attachments = $extensions = array(); 133 $post_id = $post_info['post_id']; 134 $topic_tracking_info = array(); 135 136 // Get topic tracking info 137 if ($config['load_db_lastread']) 138 { 139 $tmp_topic_data = array($post_info['topic_id'] => $post_info); 140 $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'])); 141 unset($tmp_topic_data); 142 } 143 else 144 { 145 $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']); 146 } 147 148 $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false; 149 150 // Process message, leave it uncensored 151 $parse_flags = ($post_info['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES; 152 $message = generate_text_for_display($post_info['post_text'], $post_info['bbcode_uid'], $post_info['bbcode_bitfield'], $parse_flags, false); 153 154 if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id'])) 155 { 156 $extensions = $cache->obtain_attach_extensions($post_info['forum_id']); 157 158 $sql = 'SELECT * 159 FROM ' . ATTACHMENTS_TABLE . ' 160 WHERE post_msg_id = ' . $post_id . ' 161 AND in_message = 0 162 ORDER BY filetime DESC, post_msg_id ASC'; 163 $result = $db->sql_query($sql); 164 165 while ($row = $db->sql_fetchrow($result)) 166 { 167 $attachments[] = $row; 168 } 169 $db->sql_freeresult($result); 170 171 if (sizeof($attachments)) 172 { 173 $user->add_lang('viewtopic'); 174 $update_count = array(); 175 parse_attachments($post_info['forum_id'], $message, $attachments, $update_count); 176 } 177 178 // Display not already displayed Attachments for this post, we already parsed them. ;) 179 if (!empty($attachments)) 180 { 181 $template->assign_var('S_HAS_ATTACHMENTS', true); 182 183 foreach ($attachments as $attachment) 184 { 185 $template->assign_block_vars('attachment', array( 186 'DISPLAY_ATTACHMENT' => $attachment) 187 ); 188 } 189 } 190 } 191 192 // Deleting information 193 if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user']) 194 { 195 // User having deleted the post also being the post author? 196 if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id']) 197 { 198 $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']); 199 } 200 else 201 { 202 $sql = 'SELECT user_id, username, user_colour 203 FROM ' . USERS_TABLE . ' 204 WHERE user_id = ' . (int) $post_info['post_delete_user']; 205 $result = $db->sql_query($sql); 206 $user_delete_row = $db->sql_fetchrow($result); 207 $db->sql_freeresult($result); 208 $display_username = get_username_string('full', $post_info['post_delete_user'], $user_delete_row['username'], $user_delete_row['user_colour']); 209 } 210 211 $user->add_lang('viewtopic'); 212 $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true)); 213 } 214 else 215 { 216 $l_deleted_by = ''; 217 } 218 219 $mcp_post_template_data = array( 220 'U_MCP_ACTION' => "$url&i=main&quickmod=1&mode=post_details", // Use this for mode paramaters 221 'U_POST_ACTION' => "$url&i=$id&mode=post_details", // Use this for action parameters 222 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f={$post_info['forum_id']}"), 223 224 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 225 'S_CAN_CHGPOSTER' => $auth->acl_get('m_chgposter', $post_info['forum_id']), 226 'S_CAN_LOCK_POST' => $auth->acl_get('m_lock', $post_info['forum_id']), 227 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']), 228 229 'S_POST_REPORTED' => ($post_info['post_reported']) ? true : false, 230 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE) ? true : false, 231 'S_POST_DELETED' => ($post_info['post_visibility'] == ITEM_DELETED) ? true : false, 232 'S_POST_LOCKED' => ($post_info['post_edit_locked']) ? true : false, 233 'S_USER_NOTES' => true, 234 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, 235 'DELETED_MESSAGE' => $l_deleted_by, 236 'DELETE_REASON' => $post_info['post_delete_reason'], 237 238 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '', 239 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp_chgposter&field=username&select_single=true'), 240 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id), 241 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id), 242 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']), 243 'U_MCP_WARN_USER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $post_info['user_id']) : '', 244 'U_VIEW_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']), 245 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']), 246 247 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), 248 249 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_info['forum_id']}&p=$post_id") . "#p$post_id\">", '</a>'), 250 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$post_info['forum_id']}&start={$start}") . '">', '</a>'), 251 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), 252 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']), 253 'DELETED_IMG' => $user->img('icon_topic_deleted', $user->lang['POST_DELETED']), 254 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']), 255 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']), 256 257 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 258 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 259 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 260 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 261 262 'POST_PREVIEW' => $message, 263 'POST_SUBJECT' => $post_info['post_subject'], 264 'POST_DATE' => $user->format_date($post_info['post_time']), 265 'POST_IP' => $post_info['poster_ip'], 266 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '', 267 'POST_ID' => $post_info['post_id'], 268 269 'U_LOOKUP_IP' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? "$url&i=$id&mode=$mode&lookup={$post_info['poster_ip']}#ip" : '', 270 'U_WHOIS' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&mode=$mode&action=whois&p=$post_id&ip={$post_info['poster_ip']}") : '', 271 ); 272 273 $s_additional_opts = false; 274 275 /** 276 * Event to add/modify MCP post template data 277 * 278 * @event core.mcp_post_template_data 279 * @var array post_info Array with the post information 280 * @var array mcp_post_template_data Array with the MCP post template data 281 * @var array attachments Array with the post attachments, if any 282 * @var bool s_additional_opts Must be set to true in extension if additional options are presented in MCP post panel 283 * @since 3.1.5-RC1 284 */ 285 $vars = array( 286 'post_info', 287 'mcp_post_template_data', 288 'attachments', 289 's_additional_opts', 290 ); 291 extract($phpbb_dispatcher->trigger_event('core.mcp_post_template_data', compact($vars))); 292 293 $template->assign_vars($mcp_post_template_data); 294 $template->assign_var('S_MCP_POST_ADDITIONAL_OPTS', $s_additional_opts); 295 296 unset($mcp_post_template_data); 297 298 // Get User Notes 299 $log_data = array(); 300 $log_count = false; 301 view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']); 302 303 if (!empty($log_data)) 304 { 305 $template->assign_var('S_USER_NOTES', true); 306 307 foreach ($log_data as $row) 308 { 309 $template->assign_block_vars('usernotes', array( 310 'REPORT_BY' => $row['username_full'], 311 'REPORT_AT' => $user->format_date($row['time']), 312 'ACTION' => $row['action'], 313 'ID' => $row['id']) 314 ); 315 } 316 } 317 318 // Get Reports 319 if ($auth->acl_get('m_report', $post_info['forum_id'])) 320 { 321 $sql = 'SELECT r.*, re.*, u.user_id, u.username 322 FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u, ' . REPORTS_REASONS_TABLE . " re 323 WHERE r.post_id = $post_id 324 AND r.reason_id = re.reason_id 325 AND u.user_id = r.user_id 326 ORDER BY r.report_time DESC"; 327 $result = $db->sql_query($sql); 328 329 if ($row = $db->sql_fetchrow($result)) 330 { 331 $template->assign_var('S_SHOW_REPORTS', true); 332 333 do 334 { 335 // If the reason is defined within the language file, we will use the localized version, else just use the database entry... 336 if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) 337 { 338 $row['reson_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]; 339 $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]; 340 } 341 342 $template->assign_block_vars('reports', array( 343 'REPORT_ID' => $row['report_id'], 344 'REASON_TITLE' => $row['reason_title'], 345 'REASON_DESC' => $row['reason_description'], 346 'REPORTER' => get_username_string('username', $row['user_id'], $row['username']), 347 'U_REPORTER' => get_username_string('profile', $row['user_id'], $row['username']), 348 'USER_NOTIFY' => ($row['user_notify']) ? true : false, 349 'REPORT_TIME' => $user->format_date($row['report_time']), 350 'REPORT_TEXT' => bbcode_nl2br(trim($row['report_text'])), 351 )); 352 } 353 while ($row = $db->sql_fetchrow($result)); 354 } 355 $db->sql_freeresult($result); 356 } 357 358 // Get IP 359 if ($auth->acl_get('m_info', $post_info['forum_id'])) 360 { 361 /** @var \phpbb\pagination $pagination */ 362 $pagination = $phpbb_container->get('pagination'); 363 364 $rdns_ip_num = $request->variable('rdns', ''); 365 $start_users = $request->variable('start_users', 0); 366 367 if ($rdns_ip_num != 'all') 368 { 369 $template->assign_vars(array( 370 'U_LOOKUP_ALL' => "$url&i=main&mode=post_details&rdns=all") 371 ); 372 } 373 374 $num_users = false; 375 if ($start_users) 376 { 377 $num_users = phpbb_get_num_posters_for_ip($db, $post_info['poster_ip']); 378 $start_users = $pagination->validate_start($start_users, $config['posts_per_page'], $num_users); 379 } 380 381 // Get other users who've posted under this IP 382 $sql = 'SELECT poster_id, COUNT(poster_id) as postings 383 FROM ' . POSTS_TABLE . " 384 WHERE poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "' 385 AND poster_id <> " . (int) $post_info['poster_id'] . " 386 GROUP BY poster_id 387 ORDER BY postings DESC, poster_id ASC"; 388 $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start_users); 389 390 $page_users = 0; 391 while ($row = $db->sql_fetchrow($result)) 392 { 393 $page_users++; 394 $users_ary[$row['poster_id']] = $row; 395 } 396 $db->sql_freeresult($result); 397 398 if ($page_users == $config['posts_per_page'] || $start_users) 399 { 400 if ($num_users === false) 401 { 402 $num_users = phpbb_get_num_posters_for_ip($db, $post_info['poster_ip']); 403 } 404 405 $pagination->generate_template_pagination( 406 $url . '&i=main&mode=post_details', 407 'pagination', 408 'start_users', 409 $num_users, 410 $config['posts_per_page'], 411 $start_users 412 ); 413 } 414 415 if (sizeof($users_ary)) 416 { 417 // Get the usernames 418 $sql = 'SELECT user_id, username 419 FROM ' . USERS_TABLE . ' 420 WHERE ' . $db->sql_in_set('user_id', array_keys($users_ary)); 421 $result = $db->sql_query($sql); 422 423 while ($row = $db->sql_fetchrow($result)) 424 { 425 $users_ary[$row['user_id']]['username'] = $row['username']; 426 $usernames_ary[utf8_clean_string($row['username'])] = $users_ary[$row['user_id']]; 427 } 428 $db->sql_freeresult($result); 429 430 foreach ($users_ary as $user_id => $user_row) 431 { 432 $template->assign_block_vars('userrow', array( 433 'USERNAME' => get_username_string('username', $user_id, $user_row['username']), 434 'NUM_POSTS' => $user_row['postings'], 435 'L_POST_S' => ($user_row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'], 436 437 'U_PROFILE' => get_username_string('profile', $user_id, $user_row['username']), 438 'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user_id . '&sr=topics')) 439 ); 440 } 441 } 442 443 // Get other IP's this user has posted under 444 445 // A compound index on poster_id, poster_ip (posts table) would help speed up this query a lot, 446 // but the extra size is only valuable if there are persons having more than a thousands posts. 447 // This is better left to the really really big forums. 448 $start_ips = $request->variable('start_ips', 0); 449 450 $num_ips = false; 451 if ($start_ips) 452 { 453 $num_ips = phpbb_get_num_ips_for_poster($db, $post_info['poster_id']); 454 $start_ips = $pagination->validate_start($start_ips, $config['posts_per_page'], $num_ips); 455 } 456 457 $sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings 458 FROM ' . POSTS_TABLE . ' 459 WHERE poster_id = ' . $post_info['poster_id'] . " 460 GROUP BY poster_ip 461 ORDER BY postings DESC, poster_ip ASC"; 462 $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start_ips); 463 464 $page_ips = 0; 465 while ($row = $db->sql_fetchrow($result)) 466 { 467 $page_ips++; 468 $hostname = (($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip']) ? @gethostbyaddr($row['poster_ip']) : ''; 469 470 $template->assign_block_vars('iprow', array( 471 'IP' => $row['poster_ip'], 472 'HOSTNAME' => $hostname, 473 'NUM_POSTS' => $row['postings'], 474 'L_POST_S' => ($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'], 475 476 'U_LOOKUP_IP' => ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? '' : "$url&i=$id&mode=post_details&rdns={$row['poster_ip']}#ip", 477 'U_WHOIS' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&mode=$mode&action=whois&p=$post_id&ip={$row['poster_ip']}")) 478 ); 479 } 480 $db->sql_freeresult($result); 481 482 if ($page_ips == $config['posts_per_page'] || $start_ips) 483 { 484 if ($num_ips === false) 485 { 486 $num_ips = phpbb_get_num_ips_for_poster($db, $post_info['poster_id']); 487 } 488 489 $pagination->generate_template_pagination( 490 $url . '&i=main&mode=post_details', 491 'pagination_ips', 492 'start_ips', 493 $num_ips, 494 $config['posts_per_page'], 495 $start_ips 496 ); 497 } 498 499 $user_select = ''; 500 501 if (sizeof($usernames_ary)) 502 { 503 ksort($usernames_ary); 504 505 foreach ($usernames_ary as $row) 506 { 507 $user_select .= '<option value="' . $row['poster_id'] . '">' . $row['username'] . "</option>\n"; 508 } 509 } 510 511 $template->assign_var('S_USER_SELECT', $user_select); 512 } 513 514 } 515 516 /** 517 * Get the number of posters for a given ip 518 * 519 * @param \phpbb\db\driver\driver_interface $db DBAL interface 520 * @param string $poster_ip IP 521 * @return int Number of posters 522 */ 523 function phpbb_get_num_posters_for_ip(\phpbb\db\driver\driver_interface $db, $poster_ip) 524 { 525 $sql = 'SELECT COUNT(DISTINCT poster_id) as num_users 526 FROM ' . POSTS_TABLE . " 527 WHERE poster_ip = '" . $db->sql_escape($poster_ip) . "'"; 528 $result = $db->sql_query($sql); 529 $num_users = (int) $db->sql_fetchfield('num_users'); 530 $db->sql_freeresult($result); 531 532 return $num_users; 533 } 534 535 /** 536 * Get the number of ips for a given poster 537 * 538 * @param \phpbb\db\driver\driver_interface $db 539 * @param int $poster_id Poster user ID 540 * @return int Number of IPs for given poster 541 */ 542 function phpbb_get_num_ips_for_poster(\phpbb\db\driver\driver_interface $db, $poster_id) 543 { 544 $sql = 'SELECT COUNT(DISTINCT poster_ip) as num_ips 545 FROM ' . POSTS_TABLE . ' 546 WHERE poster_id = ' . (int) $poster_id; 547 $result = $db->sql_query($sql); 548 $num_ips = (int) $db->sql_fetchfield('num_ips'); 549 $db->sql_freeresult($result); 550 551 return $num_ips; 552 } 553 554 /** 555 * Change a post's poster 556 */ 557 function change_poster(&$post_info, $userdata) 558 { 559 global $auth, $db, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; 560 561 if (empty($userdata) || $userdata['user_id'] == $post_info['user_id']) 562 { 563 return; 564 } 565 566 $post_id = $post_info['post_id']; 567 568 $sql = 'UPDATE ' . POSTS_TABLE . " 569 SET poster_id = {$userdata['user_id']} 570 WHERE post_id = $post_id"; 571 $db->sql_query($sql); 572 573 // Resync topic/forum if needed 574 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) 575 { 576 sync('topic', 'topic_id', $post_info['topic_id'], false, false); 577 sync('forum', 'forum_id', $post_info['forum_id'], false, false); 578 } 579 580 // Adjust post counts... only if the post is approved (else, it was not added the users post count anyway) 581 if ($post_info['post_postcount'] && $post_info['post_visibility'] == ITEM_APPROVED) 582 { 583 $sql = 'UPDATE ' . USERS_TABLE . ' 584 SET user_posts = user_posts - 1 585 WHERE user_id = ' . $post_info['user_id'] .' 586 AND user_posts > 0'; 587 $db->sql_query($sql); 588 589 $sql = 'UPDATE ' . USERS_TABLE . ' 590 SET user_posts = user_posts + 1 591 WHERE user_id = ' . $userdata['user_id']; 592 $db->sql_query($sql); 593 } 594 595 // Add posted to information for this topic for the new user 596 markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']); 597 598 // Remove the dotted topic option if the old user has no more posts within this topic 599 if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS) 600 { 601 $sql = 'SELECT topic_id 602 FROM ' . POSTS_TABLE . ' 603 WHERE topic_id = ' . $post_info['topic_id'] . ' 604 AND poster_id = ' . $post_info['user_id']; 605 $result = $db->sql_query_limit($sql, 1); 606 $topic_id = (int) $db->sql_fetchfield('topic_id'); 607 $db->sql_freeresult($result); 608 609 if (!$topic_id) 610 { 611 $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . ' 612 WHERE user_id = ' . $post_info['user_id'] . ' 613 AND topic_id = ' . $post_info['topic_id']; 614 $db->sql_query($sql); 615 } 616 } 617 618 // change the poster_id within the attachments table, else the data becomes out of sync and errors displayed because of wrong ownership 619 if ($post_info['post_attachment']) 620 { 621 $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' 622 SET poster_id = ' . $userdata['user_id'] . ' 623 WHERE poster_id = ' . $post_info['user_id'] . ' 624 AND post_msg_id = ' . $post_info['post_id'] . ' 625 AND topic_id = ' . $post_info['topic_id']; 626 $db->sql_query($sql); 627 } 628 629 // refresh search cache of this post 630 $search_type = $config['search_type']; 631 632 if (class_exists($search_type)) 633 { 634 // We do some additional checks in the module to ensure it can actually be utilised 635 $error = false; 636 $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher); 637 638 if (!$error && method_exists($search, 'destroy_cache')) 639 { 640 $search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id'])); 641 } 642 } 643 644 $from_username = $post_info['username']; 645 $to_username = $userdata['username']; 646 647 /** 648 * This event allows you to perform additional tasks after changing a post's poster 649 * 650 * @event core.mcp_change_poster_after 651 * @var array userdata Information on a post's new poster 652 * @var array post_info Information on the affected post 653 * @since 3.1.6-RC1 654 * @changed 3.1.7-RC1 Change location to prevent post_info from being set to the new post information 655 */ 656 $vars = array('userdata', 'post_info'); 657 extract($phpbb_dispatcher->trigger_event('core.mcp_change_poster_after', compact($vars))); 658 659 // Renew post info 660 $post_info = phpbb_get_post_data(array($post_id), false, true); 661 662 if (!sizeof($post_info)) 663 { 664 trigger_error('POST_NOT_EXIST'); 665 } 666 667 $post_info = $post_info[$post_id]; 668 669 // Now add log entry 670 add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $from_username, $to_username); 671 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |