[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?php
   2  /**
   3  *
   4  * @package mcp
   5  * @version $Id$
   6  * @copyright (c) 2005 phpBB Group
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  if (!defined('IN_PHPBB'))
  15  {
  16      exit;
  17  }
  18  
  19  /**
  20  * mcp_queue
  21  * Handling the moderation queue
  22  * @package mcp
  23  */
  24  class mcp_queue
  25  {
  26      var $p_master;
  27      var $u_action;
  28  
  29  	function mcp_queue(&$p_master)
  30      {
  31          $this->p_master = &$p_master;
  32      }
  33  
  34  	function main($id, $mode)
  35      {
  36          global $auth, $db, $user, $template, $cache;
  37          global $config, $phpbb_root_path, $phpEx, $action;
  38  
  39          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  40  
  41          $forum_id = request_var('f', 0);
  42          $start = request_var('start', 0);
  43  
  44          $this->page_title = 'MCP_QUEUE';
  45  
  46          switch ($action)
  47          {
  48              case 'approve':
  49              case 'disapprove':
  50                  include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  51  
  52                  $post_id_list = request_var('post_id_list', array(0));
  53  
  54                  if (!sizeof($post_id_list))
  55                  {
  56                      trigger_error('NO_POST_SELECTED');
  57                  }
  58  
  59                  if ($action == 'approve')
  60                  {
  61                      approve_post($post_id_list, 'queue', $mode);
  62                  }
  63                  else
  64                  {
  65                      disapprove_post($post_id_list, 'queue', $mode);
  66                  }
  67  
  68              break;
  69          }
  70  
  71          switch ($mode)
  72          {
  73              case 'approve_details':
  74  
  75                  $this->tpl_name = 'mcp_post';
  76  
  77                  $user->add_lang(array('posting', 'viewtopic'));
  78  
  79                  $post_id = request_var('p', 0);
  80                  $topic_id = request_var('t', 0);
  81  
  82                  if ($topic_id)
  83                  {
  84                      $topic_info = get_topic_data(array($topic_id), 'm_approve');
  85                      if (isset($topic_info[$topic_id]['topic_first_post_id']))
  86                      {
  87                          $post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
  88                      }
  89                      else
  90                      {
  91                          $topic_id = 0;
  92                      }
  93                  }
  94  
  95                  $post_info = get_post_data(array($post_id), 'm_approve', true);
  96  
  97                  if (!sizeof($post_info))
  98                  {
  99                      trigger_error('NO_POST_SELECTED');
 100                  }
 101  
 102                  $post_info = $post_info[$post_id];
 103  
 104                  if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
 105                  {
 106                      $template->assign_vars(array(
 107                          'S_TOPIC_REVIEW'    => true,
 108                          'S_BBCODE_ALLOWED'    => $post_info['enable_bbcode'],
 109                          'TOPIC_TITLE'        => $post_info['topic_title'])
 110                      );
 111                  }
 112  
 113                  $extensions = $attachments = $topic_tracking_info = array();
 114  
 115                  // Get topic tracking info
 116                  if ($config['load_db_lastread'])
 117                  {
 118                      $tmp_topic_data = array($post_info['topic_id'] => $post_info);
 119                      $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']));
 120                      unset($tmp_topic_data);
 121                  }
 122                  else
 123                  {
 124                      $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
 125                  }
 126  
 127                  $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
 128  
 129                  // Process message, leave it uncensored
 130                  $message = $post_info['post_text'];
 131  
 132                  if ($post_info['bbcode_bitfield'])
 133                  {
 134                      include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 135                      $bbcode = new bbcode($post_info['bbcode_bitfield']);
 136                      $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
 137                  }
 138  
 139                  $message = bbcode_nl2br($message);
 140                  $message = smiley_text($message);
 141  
 142                  if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
 143                  {
 144                      $extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
 145  
 146                      $sql = 'SELECT *
 147                          FROM ' . ATTACHMENTS_TABLE . '
 148                          WHERE post_msg_id = ' . $post_id . '
 149                              AND in_message = 0
 150                          ORDER BY filetime DESC, post_msg_id ASC';
 151                      $result = $db->sql_query($sql);
 152  
 153                      while ($row = $db->sql_fetchrow($result))
 154                      {
 155                          $attachments[] = $row;
 156                      }
 157                      $db->sql_freeresult($result);
 158  
 159                      if (sizeof($attachments))
 160                      {
 161                          $update_count = array();
 162                          parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
 163                      }
 164  
 165                      // Display not already displayed Attachments for this post, we already parsed them. ;)
 166                      if (!empty($attachments))
 167                      {
 168                          $template->assign_var('S_HAS_ATTACHMENTS', true);
 169  
 170                          foreach ($attachments as $attachment)
 171                          {
 172                              $template->assign_block_vars('attachment', array(
 173                                  'DISPLAY_ATTACHMENT'    => $attachment)
 174                              );
 175                          }
 176                      }
 177                  }
 178  
 179                  $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;p=' . $post_info['post_id'] . '#p' . $post_info['post_id']);
 180                  $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']);
 181  
 182                  $template->assign_vars(array(
 183                      'S_MCP_QUEUE'            => true,
 184                      'U_APPROVE_ACTION'        => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f=$forum_id"),
 185                      'S_CAN_VIEWIP'            => $auth->acl_get('m_info', $post_info['forum_id']),
 186                      'S_POST_REPORTED'        => $post_info['post_reported'],
 187                      'S_POST_UNAPPROVED'        => !$post_info['post_approved'],
 188                      'S_POST_LOCKED'            => $post_info['post_edit_locked'],
 189                      'S_USER_NOTES'            => true,
 190  
 191                      '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']}") : '',
 192                      '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),
 193                      '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),
 194                      'U_MCP_USER_NOTES'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
 195                      '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']) : '',
 196                      'U_VIEW_POST'            => $post_url,
 197                      'U_VIEW_TOPIC'            => $topic_url,
 198  
 199                      'MINI_POST_IMG'            => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
 200  
 201                      'RETURN_QUEUE'            => sprintf($user->lang['RETURN_QUEUE'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue' . (($topic_id) ? '&amp;mode=unapproved_topics' : '&amp;mode=unapproved_posts')) . "&amp;start=$start\">", '</a>'),
 202                      'RETURN_POST'            => sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'),
 203                      'RETURN_TOPIC_SIMPLE'    => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'),
 204                      'REPORTED_IMG'            => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
 205                      'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
 206                      'EDIT_IMG'                => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
 207  
 208                      'POST_AUTHOR_FULL'        => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 209                      'POST_AUTHOR_COLOUR'    => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 210                      'POST_AUTHOR'            => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 211                      'U_POST_AUTHOR'            => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 212  
 213                      'POST_PREVIEW'            => $message,
 214                      'POST_SUBJECT'            => $post_info['post_subject'],
 215                      'POST_DATE'                => $user->format_date($post_info['post_time']),
 216                      'POST_IP'                => $post_info['poster_ip'],
 217                      'POST_IPADDR'            => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
 218                      'POST_ID'                => $post_info['post_id'],
 219                      'S_FIRST_POST'            => ($post_info['topic_first_post_id'] == $post_id),
 220  
 221                      'U_LOOKUP_IP'            => ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id . '&amp;lookup=' . $post_info['poster_ip']) . '#ip' : '',
 222                  ));
 223  
 224              break;
 225  
 226              case 'unapproved_topics':
 227              case 'unapproved_posts':
 228                  $user->add_lang(array('viewtopic', 'viewforum'));
 229  
 230                  $topic_id = request_var('t', 0);
 231                  $forum_info = array();
 232  
 233                  if ($topic_id)
 234                  {
 235                      $topic_info = get_topic_data(array($topic_id));
 236  
 237                      if (!sizeof($topic_info))
 238                      {
 239                          trigger_error('TOPIC_NOT_EXIST');
 240                      }
 241  
 242                      $topic_info = $topic_info[$topic_id];
 243                      $forum_id = $topic_info['forum_id'];
 244                  }
 245  
 246                  $forum_list_approve = get_forum_list('m_approve', false, true);
 247                  $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
 248  
 249                  // Remove forums we cannot read
 250                  foreach ($forum_list_approve as $k => $forum_data)
 251                  {
 252                      if (!isset($forum_list_read[$forum_data['forum_id']]))
 253                      {
 254                          unset($forum_list_approve[$k]);
 255                      }
 256                  }
 257                  unset($forum_list_read);
 258  
 259                  if (!$forum_id)
 260                  {
 261                      $forum_list = array();
 262                      foreach ($forum_list_approve as $row)
 263                      {
 264                          $forum_list[] = $row['forum_id'];
 265                      }
 266  
 267                      if (!sizeof($forum_list))
 268                      {
 269                          trigger_error('NOT_MODERATOR');
 270                      }
 271  
 272                      $global_id = $forum_list[0];
 273  
 274                      $forum_list = implode(', ', $forum_list);
 275  
 276                      $sql = 'SELECT SUM(forum_topics) as sum_forum_topics
 277                          FROM ' . FORUMS_TABLE . "
 278                          WHERE forum_id IN (0, $forum_list)";
 279                      $result = $db->sql_query($sql);
 280                      $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
 281                      $db->sql_freeresult($result);
 282                  }
 283                  else
 284                  {
 285                      $forum_info = get_forum_data(array($forum_id), 'm_approve');
 286  
 287                      if (!sizeof($forum_info))
 288                      {
 289                          trigger_error('NOT_MODERATOR');
 290                      }
 291  
 292                      $forum_info = $forum_info[$forum_id];
 293                      $forum_list = $forum_id;
 294                      $global_id = $forum_id;
 295                  }
 296  
 297                  $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
 298                  foreach ($forum_list_approve as $row)
 299                  {
 300                      $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp; &nbsp;', $row['padding']) . $row['forum_name'] . '</option>';
 301                  }
 302  
 303                  $sort_days = $total = 0;
 304                  $sort_key = $sort_dir = '';
 305                  $sort_by_sql = $sort_order_sql = array();
 306                  mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
 307  
 308                  $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
 309                  $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 310  
 311                  $forum_names = array();
 312  
 313                  if ($mode == 'unapproved_posts')
 314                  {
 315                      $sql = 'SELECT p.post_id
 316                          FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . "
 317                          WHERE p.forum_id IN (0, $forum_list)
 318                              AND p.post_approved = 0
 319                              " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
 320                              ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
 321                              AND t.topic_id = p.topic_id
 322                              AND t.topic_first_post_id <> p.post_id
 323                              $limit_time_sql
 324                          ORDER BY $sort_order_sql";
 325                      $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 326  
 327                      $i = 0;
 328                      $post_ids = array();
 329                      while ($row = $db->sql_fetchrow($result))
 330                      {
 331                          $post_ids[] = $row['post_id'];
 332                          $row_num[$row['post_id']] = $i++;
 333                      }
 334                      $db->sql_freeresult($result);
 335  
 336                      if (sizeof($post_ids))
 337                      {
 338                          $sql = 'SELECT t.topic_id, t.topic_title, t.forum_id, p.post_id, p.post_subject, p.post_username, p.poster_id, p.post_time, u.username, u.username_clean, u.user_colour
 339                              FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
 340                              WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
 341                                  AND t.topic_id = p.topic_id
 342                                  AND u.user_id = p.poster_id
 343                              ORDER BY ' . $sort_order_sql;
 344                          $result = $db->sql_query($sql);
 345  
 346                          $post_data = $rowset = array();
 347                          while ($row = $db->sql_fetchrow($result))
 348                          {
 349                              if ($row['forum_id'])
 350                              {
 351                                  $forum_names[] = $row['forum_id'];
 352                              }
 353                              $post_data[$row['post_id']] = $row;
 354                          }
 355                          $db->sql_freeresult($result);
 356  
 357                          foreach ($post_ids as $post_id)
 358                          {
 359                              $rowset[] = $post_data[$post_id];
 360                          }
 361                          unset($post_data, $post_ids);
 362                      }
 363                      else
 364                      {
 365                          $rowset = array();
 366                      }
 367                  }
 368                  else
 369                  {
 370                      $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour
 371                          FROM ' . TOPICS_TABLE . " t
 372                          WHERE forum_id IN (0, $forum_list)
 373                              AND topic_approved = 0
 374                              $limit_time_sql
 375                          ORDER BY $sort_order_sql";
 376                      $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 377  
 378                      $rowset = array();
 379                      while ($row = $db->sql_fetchrow($result))
 380                      {
 381                          if ($row['forum_id'])
 382                          {
 383                              $forum_names[] = $row['forum_id'];
 384                          }
 385                          $rowset[] = $row;
 386                      }
 387                      $db->sql_freeresult($result);
 388                  }
 389  
 390                  if (sizeof($forum_names))
 391                  {
 392                      // Select the names for the forum_ids
 393                      $sql = 'SELECT forum_id, forum_name
 394                          FROM ' . FORUMS_TABLE . '
 395                          WHERE ' . $db->sql_in_set('forum_id', $forum_names);
 396                      $result = $db->sql_query($sql, 3600);
 397  
 398                      $forum_names = array();
 399                      while ($row = $db->sql_fetchrow($result))
 400                      {
 401                          $forum_names[$row['forum_id']] = $row['forum_name'];
 402                      }
 403                      $db->sql_freeresult($result);
 404                  }
 405  
 406                  foreach ($rowset as $row)
 407                  {
 408                      $global_topic = ($row['forum_id']) ? false : true;
 409                      if ($global_topic)
 410                      {
 411                          $row['forum_id'] = $global_id;
 412                      }
 413  
 414                      if (empty($row['post_username']))
 415                      {
 416                          $row['post_username'] = $user->lang['GUEST'];
 417                      }
 418  
 419                      $template->assign_block_vars('postrow', array(
 420                          'U_TOPIC'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
 421                          'U_VIEWFORUM'        => (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
 422                          'U_VIEWPOST'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']) . (($mode == 'unapproved_posts') ? '#p' . $row['post_id'] : ''),
 423                          'U_VIEW_DETAILS'    => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;start=$start&amp;mode=approve_details&amp;f={$row['forum_id']}&amp;p={$row['post_id']}" . (($mode == 'unapproved_topics') ? "&amp;t={$row['topic_id']}" : '')),
 424  
 425                          'POST_AUTHOR_FULL'        => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 426                          'POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 427                          'POST_AUTHOR'            => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 428                          'U_POST_AUTHOR'            => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 429  
 430                          'POST_ID'        => $row['post_id'],
 431                          'FORUM_NAME'    => (!$global_topic) ? $forum_names[$row['forum_id']] : $user->lang['GLOBAL_ANNOUNCEMENT'],
 432                          'POST_SUBJECT'    => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
 433                          'TOPIC_TITLE'    => $row['topic_title'],
 434                          'POST_TIME'        => $user->format_date($row['post_time']))
 435                      );
 436                  }
 437                  unset($rowset, $forum_names);
 438  
 439                  // Now display the page
 440                  $template->assign_vars(array(
 441                      'L_DISPLAY_ITEMS'        => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
 442                      'L_EXPLAIN'                => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN'],
 443                      'L_TITLE'                => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS'],
 444                      'L_ONLY_TOPIC'            => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
 445  
 446                      'S_FORUM_OPTIONS'        => $forum_options,
 447                      'S_MCP_ACTION'            => build_url(array('t', 'f', 'sd', 'st', 'sk')),
 448                      'S_TOPICS'                => ($mode == 'unapproved_posts') ? false : true,
 449  
 450                      'PAGINATION'            => generate_pagination($this->u_action . "&amp;f=$forum_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir", $total, $config['topics_per_page'], $start),
 451                      'PAGE_NUMBER'            => on_page($total, $config['topics_per_page'], $start),
 452                      'TOPIC_ID'                => $topic_id,
 453                      'TOTAL'                    => ($total == 1) ? (($mode == 'unapproved_posts') ? $user->lang['VIEW_TOPIC_POST'] : $user->lang['VIEW_FORUM_TOPIC']) : sprintf((($mode == 'unapproved_posts') ? $user->lang['VIEW_TOPIC_POSTS'] : $user->lang['VIEW_FORUM_TOPICS']), $total),
 454                  ));
 455  
 456                  $this->tpl_name = 'mcp_queue';
 457              break;
 458          }
 459      }
 460  }
 461  
 462  /**
 463  * Approve Post/Topic
 464  */
 465  function approve_post($post_id_list, $id, $mode)
 466  {
 467      global $db, $template, $user, $config;
 468      global $phpEx, $phpbb_root_path;
 469  
 470      if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
 471      {
 472          trigger_error('NOT_AUTHORISED');
 473      }
 474  
 475      $redirect = request_var('redirect', build_url(array('quickmod')));
 476      $success_msg = '';
 477  
 478      $s_hidden_fields = build_hidden_fields(array(
 479          'i'                => $id,
 480          'mode'            => $mode,
 481          'post_id_list'    => $post_id_list,
 482          'action'        => 'approve',
 483          'redirect'        => $redirect)
 484      );
 485  
 486      $post_info = get_post_data($post_id_list, 'm_approve');
 487  
 488      if (confirm_box(true))
 489      {
 490          $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
 491  
 492          // If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1
 493          // If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1
 494  
 495          $total_topics = $total_posts = 0;
 496          $topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
 497          $user_posts_sql = $post_approved_list = array();
 498  
 499          foreach ($post_info as $post_id => $post_data)
 500          {
 501              if ($post_data['post_approved'])
 502              {
 503                  $post_approved_list[] = $post_id;
 504                  continue;
 505              }
 506  
 507              $topic_id_list[$post_data['topic_id']] = 1;
 508  
 509              if ($post_data['forum_id'])
 510              {
 511                  $forum_id_list[$post_data['forum_id']] = 1;
 512              }
 513  
 514              // User post update (we do not care about topic or post, since user posts are strictly connected to posts)
 515              // But we care about forums where post counts get not increased. ;)
 516              if ($post_data['post_postcount'])
 517              {
 518                  $user_posts_sql[$post_data['poster_id']] = (empty($user_posts_sql[$post_data['poster_id']])) ? 1 : $user_posts_sql[$post_data['poster_id']] + 1;
 519              }
 520  
 521              // Topic or Post. ;)
 522              if ($post_data['topic_first_post_id'] == $post_id)
 523              {
 524                  if ($post_data['forum_id'])
 525                  {
 526                      $total_topics++;
 527                  }
 528                  $topic_approve_sql[] = $post_data['topic_id'];
 529  
 530                  $approve_log[] = array(
 531                      'type'            => 'topic',
 532                      'post_subject'    => $post_data['post_subject'],
 533                      'forum_id'        => $post_data['forum_id'],
 534                      'topic_id'        => $post_data['topic_id'],
 535                  );
 536              }
 537              else
 538              {
 539                  $approve_log[] = array(
 540                      'type'            => 'post',
 541                      'post_subject'    => $post_data['post_subject'],
 542                      'forum_id'        => $post_data['forum_id'],
 543                      'topic_id'        => $post_data['topic_id'],
 544                  );
 545              }
 546  
 547              if ($post_data['forum_id'])
 548              {
 549                  $total_posts++;
 550  
 551                  // Increment by topic_replies if we approve a topic...
 552                  // This works because we do not adjust the topic_replies when re-approving a topic after an edit.
 553                  if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_replies'])
 554                  {
 555                      $total_posts += $post_data['topic_replies'];
 556                  }
 557              }
 558  
 559              $post_approve_sql[] = $post_id;
 560          }
 561  
 562          $post_id_list = array_values(array_diff($post_id_list, $post_approved_list));
 563          for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++)
 564          {
 565              unset($post_info[$post_approved_list[$i]]);
 566          }
 567  
 568          if (sizeof($topic_approve_sql))
 569          {
 570              $sql = 'UPDATE ' . TOPICS_TABLE . '
 571                  SET topic_approved = 1
 572                  WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
 573              $db->sql_query($sql);
 574          }
 575  
 576          if (sizeof($post_approve_sql))
 577          {
 578              $sql = 'UPDATE ' . POSTS_TABLE . '
 579                  SET post_approved = 1
 580                  WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
 581              $db->sql_query($sql);
 582          }
 583  
 584          unset($topic_approve_sql, $post_approve_sql);
 585  
 586          foreach ($approve_log as $log_data)
 587          {
 588              add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_APPROVED' : 'LOG_POST_APPROVED', $log_data['post_subject']);
 589          }
 590  
 591          if (sizeof($user_posts_sql))
 592          {
 593              // Try to minimize the query count by merging users with the same post count additions
 594              $user_posts_update = array();
 595  
 596              foreach ($user_posts_sql as $user_id => $user_posts)
 597              {
 598                  $user_posts_update[$user_posts][] = $user_id;
 599              }
 600  
 601              foreach ($user_posts_update as $user_posts => $user_id_ary)
 602              {
 603                  $sql = 'UPDATE ' . USERS_TABLE . '
 604                      SET user_posts = user_posts + ' . $user_posts . '
 605                      WHERE ' . $db->sql_in_set('user_id', $user_id_ary);
 606                  $db->sql_query($sql);
 607              }
 608          }
 609  
 610          if ($total_topics)
 611          {
 612              set_config_count('num_topics', $total_topics, true);
 613          }
 614  
 615          if ($total_posts)
 616          {
 617              set_config_count('num_posts', $total_posts, true);
 618          }
 619  
 620          sync('topic', 'topic_id', array_keys($topic_id_list), true);
 621          sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
 622          unset($topic_id_list, $forum_id_list);
 623  
 624          $messenger = new messenger();
 625  
 626          // Notify Poster?
 627          if ($notify_poster)
 628          {
 629              foreach ($post_info as $post_id => $post_data)
 630              {
 631                  if ($post_data['poster_id'] == ANONYMOUS)
 632                  {
 633                      continue;
 634                  }
 635  
 636                  $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved';
 637  
 638                  $messenger->template($email_template, $post_data['user_lang']);
 639  
 640                  $messenger->to($post_data['user_email'], $post_data['username']);
 641                  $messenger->im($post_data['user_jabber'], $post_data['username']);
 642  
 643                  $messenger->assign_vars(array(
 644                      'USERNAME'        => htmlspecialchars_decode($post_data['username']),
 645                      'POST_SUBJECT'    => htmlspecialchars_decode(censor_text($post_data['post_subject'])),
 646                      'TOPIC_TITLE'    => htmlspecialchars_decode(censor_text($post_data['topic_title'])),
 647  
 648                      'U_VIEW_TOPIC'    => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0",
 649                      'U_VIEW_POST'    => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id")
 650                  );
 651  
 652                  $messenger->send($post_data['user_notify_type']);
 653              }
 654          }
 655  
 656          $messenger->save_queue();
 657  
 658          // Send out normal user notifications
 659          $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
 660  
 661          foreach ($post_info as $post_id => $post_data)
 662          {
 663              if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
 664              {
 665                  // Forum Notifications
 666                  user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id);
 667              }
 668              else
 669              {
 670                  // Topic Notifications
 671                  user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id);
 672              }
 673          }
 674  
 675          if (sizeof($post_id_list) == 1)
 676          {
 677              $post_data = $post_info[$post_id_list[0]];
 678              $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&amp;t={$post_data['topic_id']}&amp;p={$post_data['post_id']}") . '#p' . $post_data['post_id'];
 679          }
 680          unset($post_info);
 681  
 682          if ($total_topics)
 683          {
 684              $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS';
 685          }
 686          else
 687          {
 688              $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
 689          }
 690      }
 691      else
 692      {
 693          $show_notify = false;
 694  
 695          if ($config['email_enable'] || $config['jab_enable'])
 696          {
 697              foreach ($post_info as $post_data)
 698              {
 699                  if ($post_data['poster_id'] == ANONYMOUS)
 700                  {
 701                      continue;
 702                  }
 703                  else
 704                  {
 705                      $show_notify = true;
 706                      break;
 707                  }
 708              }
 709          }
 710  
 711          $template->assign_vars(array(
 712              'S_NOTIFY_POSTER'    => $show_notify,
 713              'S_APPROVE'            => true)
 714          );
 715  
 716          confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
 717      }
 718  
 719      $redirect = request_var('redirect', "index.$phpEx");
 720      $redirect = reapply_sid($redirect);
 721  
 722      if (!$success_msg)
 723      {
 724          redirect($redirect);
 725      }
 726      else
 727      {
 728          meta_refresh(3, $redirect);
 729  
 730          // If approving one post, also give links back to post...
 731          $add_message = '';
 732          if (sizeof($post_id_list) == 1 && !empty($post_url))
 733          {
 734              $add_message = '<br /><br />' . sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>');
 735          }
 736  
 737          trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>') . $add_message);
 738      }
 739  }
 740  
 741  /**
 742  * Disapprove Post/Topic
 743  */
 744  function disapprove_post($post_id_list, $id, $mode)
 745  {
 746      global $db, $template, $user, $config;
 747      global $phpEx, $phpbb_root_path;
 748  
 749      if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
 750      {
 751          trigger_error('NOT_AUTHORISED');
 752      }
 753  
 754      $redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&amp;mode=$mode");
 755      $reason = utf8_normalize_nfc(request_var('reason', '', true));
 756      $reason_id = request_var('reason_id', 0);
 757      $success_msg = $additional_msg = '';
 758  
 759      $s_hidden_fields = build_hidden_fields(array(
 760          'i'                => $id,
 761          'mode'            => $mode,
 762          'post_id_list'    => $post_id_list,
 763          'action'        => 'disapprove',
 764          'redirect'        => $redirect)
 765      );
 766  
 767      $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
 768      $disapprove_reason = '';
 769  
 770      if ($reason_id)
 771      {
 772          $sql = 'SELECT reason_title, reason_description
 773              FROM ' . REPORTS_REASONS_TABLE . "
 774              WHERE reason_id = $reason_id";
 775          $result = $db->sql_query($sql);
 776          $row = $db->sql_fetchrow($result);
 777          $db->sql_freeresult($result);
 778  
 779          if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
 780          {
 781              $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
 782              unset($_REQUEST['confirm_key']);
 783              unset($_POST['confirm_key']);
 784              unset($_POST['confirm']);
 785          }
 786          else
 787          {
 788              // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
 789              $disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : '';
 790              $disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
 791  
 792              if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
 793              {
 794                  $disapprove_reason_lang = strtoupper($row['reason_title']);
 795              }
 796  
 797              $email_disapprove_reason = $disapprove_reason;
 798          }
 799      }
 800  
 801      $post_info = get_post_data($post_id_list, 'm_approve');
 802  
 803      if (confirm_box(true))
 804      {
 805          $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
 806          $topic_replies_real = $post_disapprove_list = array();
 807  
 808          // Build a list of posts to be unapproved and get the related topics real replies count
 809          foreach ($post_info as $post_id => $post_data)
 810          {
 811              $post_disapprove_list[$post_id] = $post_data['topic_id'];
 812              if (!isset($topic_replies_real[$post_data['topic_id']]))
 813              {
 814                  $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real'];
 815              }
 816          }
 817  
 818          // Now we build the log array
 819          foreach ($post_disapprove_list as $post_id => $topic_id)
 820          {
 821              // If the count of disapproved posts for the topic is greater
 822              // than topic's real replies count, the whole topic is disapproved/deleted
 823              if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id])
 824              {
 825                  // Don't write the log more than once for every topic
 826                  if (!isset($disapprove_log_topics[$topic_id]))
 827                  {
 828                      // Build disapproved topics log
 829                      $disapprove_log_topics[$topic_id] = array(
 830                          'type'            => 'topic',
 831                          'post_subject'    => $post_info[$post_id]['topic_title'],
 832                          'forum_id'        => $post_info[$post_id]['forum_id'],
 833                          'topic_id'        => 0, // useless to log a topic id, as it will be deleted
 834                      );
 835                  }
 836              }
 837              else
 838              {
 839                  // Build disapproved posts log
 840                  $disapprove_log_posts[] = array(
 841                      'type'            => 'post',
 842                      'post_subject'    => $post_info[$post_id]['post_subject'],
 843                      'forum_id'        => $post_info[$post_id]['forum_id'],
 844                      'topic_id'        => $post_info[$post_id]['topic_id'],
 845                  );
 846  
 847              }
 848          }
 849  
 850          // Get disapproved posts/topics counts separately
 851          $num_disapproved_topics = sizeof($disapprove_log_topics);
 852          $num_disapproved_posts = sizeof($disapprove_log_posts);
 853  
 854          // Build the whole log
 855          $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
 856  
 857          // Unset unneeded arrays
 858          unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
 859  
 860          // Let's do the job - delete disapproved posts
 861          if (sizeof($post_disapprove_list))
 862          {
 863              if (!function_exists('delete_posts'))
 864              {
 865                  include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
 866              }
 867  
 868              // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
 869              // Note: function delete_posts triggers related forums/topics sync,
 870              // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
 871              delete_posts('post_id', array_keys($post_disapprove_list));
 872  
 873              foreach ($disapprove_log as $log_data)
 874              {
 875                  add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason);
 876              }
 877          }
 878  
 879          $messenger = new messenger();
 880  
 881          // Notify Poster?
 882          if ($notify_poster)
 883          {
 884              $lang_reasons = array();
 885  
 886              foreach ($post_info as $post_id => $post_data)
 887              {
 888                  if ($post_data['poster_id'] == ANONYMOUS)
 889                  {
 890                      continue;
 891                  }
 892  
 893                  if (isset($disapprove_reason_lang))
 894                  {
 895                      // Okay we need to get the reason from the posters language
 896                      if (!isset($lang_reasons[$post_data['user_lang']]))
 897                      {
 898                          // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
 899                          $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
 900  
 901                          // Only load up the language pack if the language is different to the current one
 902                          if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
 903                          {
 904                              // Load up the language pack
 905                              $lang = array();
 906                              @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
 907  
 908                              // If we find the reason in this language pack use it
 909                              if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
 910                              {
 911                                  $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
 912                              }
 913  
 914                              unset($lang); // Free memory
 915                          }
 916                      }
 917  
 918                      $email_disapprove_reason = $lang_reasons[$post_data['user_lang']];
 919                      $email_disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
 920                  }
 921  
 922                  $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved';
 923  
 924                  $messenger->template($email_template, $post_data['user_lang']);
 925  
 926                  $messenger->to($post_data['user_email'], $post_data['username']);
 927                  $messenger->im($post_data['user_jabber'], $post_data['username']);
 928  
 929                  $messenger->assign_vars(array(
 930                      'USERNAME'        => htmlspecialchars_decode($post_data['username']),
 931                      'REASON'        => htmlspecialchars_decode($email_disapprove_reason),
 932                      'POST_SUBJECT'    => htmlspecialchars_decode(censor_text($post_data['post_subject'])),
 933                      'TOPIC_TITLE'    => htmlspecialchars_decode(censor_text($post_data['topic_title'])))
 934                  );
 935  
 936                  $messenger->send($post_data['user_notify_type']);
 937              }
 938  
 939              unset($lang_reasons);
 940          }
 941          unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang);
 942  
 943          $messenger->save_queue();
 944  
 945          if ($num_disapproved_topics)
 946          {
 947              $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
 948          }
 949          else
 950          {
 951              $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
 952          }
 953      }
 954      else
 955      {
 956          include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 957  
 958          display_reasons($reason_id);
 959  
 960          $show_notify = false;
 961  
 962          foreach ($post_info as $post_data)
 963          {
 964              if ($post_data['poster_id'] == ANONYMOUS)
 965              {
 966                  continue;
 967              }
 968              else
 969              {
 970                  $show_notify = true;
 971                  break;
 972              }
 973          }
 974  
 975          $template->assign_vars(array(
 976              'S_NOTIFY_POSTER'    => $show_notify,
 977              'S_APPROVE'            => false,
 978              'REASON'            => $reason,
 979              'ADDITIONAL_MSG'    => $additional_msg)
 980          );
 981  
 982          confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
 983      }
 984  
 985      $redirect = request_var('redirect', "index.$phpEx");
 986      $redirect = reapply_sid($redirect);
 987  
 988      if (!$success_msg)
 989      {
 990          redirect($redirect);
 991      }
 992      else
 993      {
 994          meta_refresh(3, $redirect);
 995          trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
 996      }
 997  }
 998  
 999  ?>


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1