[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/includes/mcp/ -> mcp_post.php (source)

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


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1