[ Index ]

PHP Cross Reference of phpBB-3.2.8-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          $rdns_ip_num = $request->variable('rdns', '');
 367          $start_users = $request->variable('start_users', 0);
 368  
 369          if ($rdns_ip_num != 'all')
 370          {
 371              $template->assign_vars(array(
 372                  'U_LOOKUP_ALL'    => "$url&amp;i=main&amp;mode=post_details&amp;rdns=all")
 373              );
 374          }
 375  
 376          $num_users = false;
 377          if ($start_users)
 378          {
 379              $num_users = phpbb_get_num_posters_for_ip($db, $post_info['poster_ip']);
 380              $start_users = $pagination->validate_start($start_users, $config['posts_per_page'], $num_users);
 381          }
 382  
 383          // Get other users who've posted under this IP
 384          $sql = 'SELECT poster_id, COUNT(poster_id) as postings
 385              FROM ' . POSTS_TABLE . "
 386              WHERE poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
 387                  AND poster_id <> " . (int) $post_info['poster_id'] . "
 388              GROUP BY poster_id
 389              ORDER BY postings DESC, poster_id ASC";
 390          $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start_users);
 391  
 392          $page_users = 0;
 393          while ($row = $db->sql_fetchrow($result))
 394          {
 395              $page_users++;
 396              $users_ary[$row['poster_id']] = $row;
 397          }
 398          $db->sql_freeresult($result);
 399  
 400          if ($page_users == $config['posts_per_page'] || $start_users)
 401          {
 402              if ($num_users === false)
 403              {
 404                  $num_users = phpbb_get_num_posters_for_ip($db, $post_info['poster_ip']);
 405              }
 406  
 407              $pagination->generate_template_pagination(
 408                  $url . '&amp;i=main&amp;mode=post_details',
 409                  'pagination',
 410                  'start_users',
 411                  $num_users,
 412                  $config['posts_per_page'],
 413                  $start_users
 414              );
 415          }
 416  
 417          if (count($users_ary))
 418          {
 419              // Get the usernames
 420              $sql = 'SELECT user_id, username
 421                  FROM ' . USERS_TABLE . '
 422                  WHERE ' . $db->sql_in_set('user_id', array_keys($users_ary));
 423              $result = $db->sql_query($sql);
 424  
 425              while ($row = $db->sql_fetchrow($result))
 426              {
 427                  $users_ary[$row['user_id']]['username'] = $row['username'];
 428                  $usernames_ary[utf8_clean_string($row['username'])] = $users_ary[$row['user_id']];
 429              }
 430              $db->sql_freeresult($result);
 431  
 432              foreach ($users_ary as $user_id => $user_row)
 433              {
 434                  $template->assign_block_vars('userrow', array(
 435                      'USERNAME'        => get_username_string('username', $user_id, $user_row['username']),
 436                      'NUM_POSTS'        => $user_row['postings'],
 437                      'L_POST_S'        => ($user_row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
 438  
 439                      'U_PROFILE'        => get_username_string('profile', $user_id, $user_row['username']),
 440                      'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user_id . '&amp;sr=topics'))
 441                  );
 442              }
 443          }
 444  
 445          // Get other IP's this user has posted under
 446  
 447          // A compound index on poster_id, poster_ip (posts table) would help speed up this query a lot,
 448          // but the extra size is only valuable if there are persons having more than a thousands posts.
 449          // This is better left to the really really big forums.
 450          $start_ips = $request->variable('start_ips', 0);
 451  
 452          $num_ips = false;
 453          if ($start_ips)
 454          {
 455              $num_ips = phpbb_get_num_ips_for_poster($db, $post_info['poster_id']);
 456              $start_ips = $pagination->validate_start($start_ips, $config['posts_per_page'], $num_ips);
 457          }
 458  
 459          $sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings
 460              FROM ' . POSTS_TABLE . '
 461              WHERE poster_id = ' . $post_info['poster_id'] . "
 462              GROUP BY poster_ip
 463              ORDER BY postings DESC, poster_ip ASC";
 464          $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start_ips);
 465  
 466          $page_ips = 0;
 467          while ($row = $db->sql_fetchrow($result))
 468          {
 469              $page_ips++;
 470              $hostname = (($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip']) ? @gethostbyaddr($row['poster_ip']) : '';
 471  
 472              $template->assign_block_vars('iprow', array(
 473                  'IP'            => $row['poster_ip'],
 474                  'HOSTNAME'        => $hostname,
 475                  'NUM_POSTS'        => $row['postings'],
 476                  'L_POST_S'        => ($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
 477  
 478                  '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",
 479                  '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']}"))
 480              );
 481          }
 482          $db->sql_freeresult($result);
 483  
 484          if ($page_ips == $config['posts_per_page'] || $start_ips)
 485          {
 486              if ($num_ips === false)
 487              {
 488                  $num_ips = phpbb_get_num_ips_for_poster($db, $post_info['poster_id']);
 489              }
 490  
 491              $pagination->generate_template_pagination(
 492                  $url . '&amp;i=main&amp;mode=post_details',
 493                  'pagination_ips',
 494                  'start_ips',
 495                  $num_ips,
 496                  $config['posts_per_page'],
 497                  $start_ips
 498              );
 499          }
 500  
 501          $user_select = '';
 502  
 503          if (count($usernames_ary))
 504          {
 505              ksort($usernames_ary);
 506  
 507              foreach ($usernames_ary as $row)
 508              {
 509                  $user_select .= '<option value="' . $row['poster_id'] . '">' . $row['username'] . "</option>\n";
 510              }
 511          }
 512  
 513          $template->assign_var('S_USER_SELECT', $user_select);
 514      }
 515  
 516  }
 517  
 518  /**
 519   * Get the number of posters for a given ip
 520   *
 521   * @param \phpbb\db\driver\driver_interface $db DBAL interface
 522   * @param string $poster_ip IP
 523   * @return int Number of posters
 524   */
 525  function phpbb_get_num_posters_for_ip(\phpbb\db\driver\driver_interface $db, $poster_ip)
 526  {
 527      $sql = 'SELECT COUNT(DISTINCT poster_id) as num_users
 528          FROM ' . POSTS_TABLE . "
 529          WHERE poster_ip = '" . $db->sql_escape($poster_ip) . "'";
 530      $result = $db->sql_query($sql);
 531      $num_users = (int) $db->sql_fetchfield('num_users');
 532      $db->sql_freeresult($result);
 533  
 534      return $num_users;
 535  }
 536  
 537  /**
 538   * Get the number of ips for a given poster
 539   *
 540   * @param \phpbb\db\driver\driver_interface $db
 541   * @param int $poster_id Poster user ID
 542   * @return int Number of IPs for given poster
 543   */
 544  function phpbb_get_num_ips_for_poster(\phpbb\db\driver\driver_interface $db, $poster_id)
 545  {
 546      $sql = 'SELECT COUNT(DISTINCT poster_ip) as num_ips
 547          FROM ' . POSTS_TABLE . '
 548          WHERE poster_id = ' . (int) $poster_id;
 549      $result = $db->sql_query($sql);
 550      $num_ips = (int) $db->sql_fetchfield('num_ips');
 551      $db->sql_freeresult($result);
 552  
 553      return $num_ips;
 554  }
 555  
 556  /**
 557  * Change a post's poster
 558  */
 559  function change_poster(&$post_info, $userdata)
 560  {
 561      global $auth, $db, $config, $phpbb_root_path, $phpEx, $user, $phpbb_log, $phpbb_dispatcher;
 562  
 563      if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
 564      {
 565          return;
 566      }
 567  
 568      $post_id = $post_info['post_id'];
 569  
 570      $sql = 'UPDATE ' . POSTS_TABLE . "
 571          SET poster_id = {$userdata['user_id']}
 572          WHERE post_id = $post_id";
 573      $db->sql_query($sql);
 574  
 575      // Resync topic/forum if needed
 576      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)
 577      {
 578          sync('topic', 'topic_id', $post_info['topic_id'], false, false);
 579          sync('forum', 'forum_id', $post_info['forum_id'], false, false);
 580      }
 581  
 582      // Adjust post counts... only if the post is approved (else, it was not added the users post count anyway)
 583      if ($post_info['post_postcount'] && $post_info['post_visibility'] == ITEM_APPROVED)
 584      {
 585          $sql = 'UPDATE ' . USERS_TABLE . '
 586              SET user_posts = user_posts - 1
 587              WHERE user_id = ' . $post_info['user_id'] .'
 588              AND user_posts > 0';
 589          $db->sql_query($sql);
 590  
 591          $sql = 'UPDATE ' . USERS_TABLE . '
 592              SET user_posts = user_posts + 1
 593              WHERE user_id = ' . $userdata['user_id'];
 594          $db->sql_query($sql);
 595      }
 596  
 597      // Add posted to information for this topic for the new user
 598      markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
 599  
 600      // Remove the dotted topic option if the old user has no more posts within this topic
 601      if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS)
 602      {
 603          $sql = 'SELECT topic_id
 604              FROM ' . POSTS_TABLE . '
 605              WHERE topic_id = ' . $post_info['topic_id'] . '
 606                  AND poster_id = ' . $post_info['user_id'];
 607          $result = $db->sql_query_limit($sql, 1);
 608          $topic_id = (int) $db->sql_fetchfield('topic_id');
 609          $db->sql_freeresult($result);
 610  
 611          if (!$topic_id)
 612          {
 613              $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
 614                  WHERE user_id = ' . $post_info['user_id'] . '
 615                      AND topic_id = ' . $post_info['topic_id'];
 616              $db->sql_query($sql);
 617          }
 618      }
 619  
 620      // change the poster_id within the attachments table, else the data becomes out of sync and errors displayed because of wrong ownership
 621      if ($post_info['post_attachment'])
 622      {
 623          $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
 624              SET poster_id = ' . $userdata['user_id'] . '
 625              WHERE poster_id = ' . $post_info['user_id'] . '
 626                  AND post_msg_id = ' . $post_info['post_id'] . '
 627                  AND topic_id = ' . $post_info['topic_id'];
 628          $db->sql_query($sql);
 629      }
 630  
 631      // refresh search cache of this post
 632      $search_type = $config['search_type'];
 633  
 634      if (class_exists($search_type))
 635      {
 636          // We do some additional checks in the module to ensure it can actually be utilised
 637          $error = false;
 638          $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
 639  
 640          if (!$error && method_exists($search, 'destroy_cache'))
 641          {
 642              $search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
 643          }
 644      }
 645  
 646      $from_username = $post_info['username'];
 647      $to_username = $userdata['username'];
 648  
 649      /**
 650      * This event allows you to perform additional tasks after changing a post's poster
 651      *
 652      * @event core.mcp_change_poster_after
 653      * @var    array    userdata    Information on a post's new poster
 654      * @var    array    post_info    Information on the affected post
 655      * @since 3.1.6-RC1
 656      * @changed 3.1.7-RC1        Change location to prevent post_info from being set to the new post information
 657      */
 658      $vars = array('userdata', 'post_info');
 659      extract($phpbb_dispatcher->trigger_event('core.mcp_change_poster_after', compact($vars)));
 660  
 661      // Renew post info
 662      $post_info = phpbb_get_post_data(array($post_id), false, true);
 663  
 664      if (!count($post_info))
 665      {
 666          trigger_error('POST_NOT_EXIST');
 667      }
 668  
 669      $post_info = $post_info[$post_id];
 670  
 671      // Now add log entry
 672      $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MCP_CHANGE_POSTER', false, array(
 673          'forum_id' => $post_info['forum_id'],
 674          'topic_id' => $post_info['topic_id'],
 675          'post_id'  => $post_info['post_id'],
 676          $post_info['topic_title'],
 677          $from_username,
 678          $to_username
 679      ));
 680  }


Generated: Sat Oct 26 11:28:42 2019 Cross-referenced by PHPXref 0.7.1