[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

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

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


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6