[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/includes/mcp/ -> mcp_queue.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  * mcp_queue
  24  * Handling the moderation queue
  25  */
  26  class mcp_queue
  27  {
  28      var $p_master;
  29      var $u_action;
  30  
  31  	public function __construct($p_master)
  32      {
  33          $this->p_master = $p_master;
  34      }
  35  
  36  	public function main($id, $mode)
  37      {
  38          global $auth, $db, $user, $template, $request;
  39          global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container;
  40          global $phpbb_dispatcher;
  41  
  42          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  43  
  44          $forum_id = $request->variable('f', 0);
  45          $start = $request->variable('start', 0);
  46  
  47          $this->page_title = 'MCP_QUEUE';
  48  
  49          switch ($action)
  50          {
  51              case 'approve':
  52              case 'restore':
  53                  include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  54  
  55                  $post_id_list = $request->variable('post_id_list', array(0));
  56                  $topic_id_list = $request->variable('topic_id_list', array(0));
  57  
  58                  if (!empty($post_id_list))
  59                  {
  60                      self::approve_posts($action, $post_id_list, 'queue', $mode);
  61                  }
  62                  else if (!empty($topic_id_list))
  63                  {
  64                      self::approve_topics($action, $topic_id_list, 'queue', $mode);
  65                  }
  66                  else
  67                  {
  68                      trigger_error('NO_POST_SELECTED');
  69                  }
  70              break;
  71  
  72              case 'delete':
  73                  $post_id_list = $request->variable('post_id_list', array(0));
  74                  $topic_id_list = $request->variable('topic_id_list', array(0));
  75                  $delete_reason = $request->variable('delete_reason', '', true);
  76  
  77                  if (!empty($post_id_list))
  78                  {
  79                      if (!function_exists('mcp_delete_post'))
  80                      {
  81                          global $phpbb_root_path, $phpEx;
  82                          include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
  83                      }
  84                      mcp_delete_post($post_id_list, false, $delete_reason, $action);
  85                  }
  86                  else if (!empty($topic_id_list))
  87                  {
  88                      if (!function_exists('mcp_delete_topic'))
  89                      {
  90                          global $phpbb_root_path, $phpEx;
  91                          include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
  92                      }
  93                      mcp_delete_topic($topic_id_list, false, $delete_reason, $action);
  94                  }
  95                  else
  96                  {
  97                      trigger_error('NO_POST_SELECTED');
  98                  }
  99              break;
 100  
 101              case 'disapprove':
 102                  $post_id_list = $request->variable('post_id_list', array(0));
 103                  $topic_id_list = $request->variable('topic_id_list', array(0));
 104  
 105                  if (!empty($topic_id_list) && $mode == 'deleted_topics')
 106                  {
 107                      if (!function_exists('mcp_delete_topic'))
 108                      {
 109                          global $phpbb_root_path, $phpEx;
 110                          include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
 111                      }
 112                      mcp_delete_topic($topic_id_list, false, '', 'disapprove');
 113                      return;
 114                  }
 115  
 116                  if (!class_exists('messenger'))
 117                  {
 118                      include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 119                  }
 120  
 121                  if (!empty($topic_id_list))
 122                  {
 123                      $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : array(ITEM_UNAPPROVED, ITEM_REAPPROVE);
 124                      $sql = 'SELECT post_id
 125                          FROM ' . POSTS_TABLE . '
 126                          WHERE ' . $db->sql_in_set('post_visibility', $post_visibility) . '
 127                              AND ' . $db->sql_in_set('topic_id', $topic_id_list);
 128                      $result = $db->sql_query($sql);
 129  
 130                      $post_id_list = array();
 131                      while ($row = $db->sql_fetchrow($result))
 132                      {
 133                          $post_id_list[] = (int) $row['post_id'];
 134                      }
 135                      $db->sql_freeresult($result);
 136                  }
 137  
 138                  if (!empty($post_id_list))
 139                  {
 140                      self::disapprove_posts($post_id_list, 'queue', $mode);
 141                  }
 142                  else
 143                  {
 144                      trigger_error('NO_POST_SELECTED');
 145                  }
 146              break;
 147          }
 148  
 149          switch ($mode)
 150          {
 151              case 'approve_details':
 152  
 153                  $this->tpl_name = 'mcp_post';
 154  
 155                  $user->add_lang(array('posting', 'viewtopic'));
 156  
 157                  $post_id = $request->variable('p', 0);
 158                  $topic_id = $request->variable('t', 0);
 159  
 160                  /* @var $phpbb_notifications \phpbb\notification\manager */
 161                  $phpbb_notifications = $phpbb_container->get('notification_manager');
 162  
 163                  if ($topic_id)
 164                  {
 165                      $topic_info = phpbb_get_topic_data(array($topic_id), 'm_approve');
 166                      if (isset($topic_info[$topic_id]['topic_first_post_id']))
 167                      {
 168                          $post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
 169  
 170                          $phpbb_notifications->mark_notifications('topic_in_queue', $topic_id, $user->data['user_id']);
 171                      }
 172                      else
 173                      {
 174                          $topic_id = 0;
 175                      }
 176                  }
 177  
 178                  $phpbb_notifications->mark_notifications('post_in_queue', $post_id, $user->data['user_id']);
 179  
 180                  $post_info = phpbb_get_post_data(array($post_id), 'm_approve', true);
 181  
 182                  if (!count($post_info))
 183                  {
 184                      trigger_error('NO_POST_SELECTED');
 185                  }
 186  
 187                  $post_info = $post_info[$post_id];
 188  
 189                  if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
 190                  {
 191                      $template->assign_vars(array(
 192                          'S_TOPIC_REVIEW'    => true,
 193                          'S_BBCODE_ALLOWED'    => $post_info['enable_bbcode'],
 194                          'TOPIC_TITLE'        => $post_info['topic_title'],
 195                      ));
 196                  }
 197  
 198                  $attachments = $topic_tracking_info = array();
 199  
 200                  // Get topic tracking info
 201                  if ($config['load_db_lastread'])
 202                  {
 203                      $tmp_topic_data = array($post_info['topic_id'] => $post_info);
 204                      $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']));
 205                      unset($tmp_topic_data);
 206                  }
 207                  else
 208                  {
 209                      $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
 210                  }
 211  
 212                  $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
 213  
 214                  // Process message, leave it uncensored
 215                  $parse_flags = ($post_info['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
 216                  $message = generate_text_for_display($post_info['post_text'], $post_info['bbcode_uid'], $post_info['bbcode_bitfield'], $parse_flags, false);
 217  
 218                  if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
 219                  {
 220                      $sql = 'SELECT *
 221                          FROM ' . ATTACHMENTS_TABLE . '
 222                          WHERE post_msg_id = ' . $post_id . '
 223                              AND in_message = 0
 224                          ORDER BY filetime DESC, post_msg_id ASC';
 225                      $result = $db->sql_query($sql);
 226  
 227                      while ($row = $db->sql_fetchrow($result))
 228                      {
 229                          $attachments[] = $row;
 230                      }
 231                      $db->sql_freeresult($result);
 232  
 233                      if (count($attachments))
 234                      {
 235                          $update_count = array();
 236                          parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
 237                      }
 238  
 239                      // Display not already displayed Attachments for this post, we already parsed them. ;)
 240                      if (!empty($attachments))
 241                      {
 242                          $template->assign_var('S_HAS_ATTACHMENTS', true);
 243  
 244                          foreach ($attachments as $attachment)
 245                          {
 246                              $template->assign_block_vars('attachment', array(
 247                                  'DISPLAY_ATTACHMENT'    => $attachment,
 248                              ));
 249                          }
 250                      }
 251                  }
 252  
 253                  // Deleting information
 254                  if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user'])
 255                  {
 256                      // User having deleted the post also being the post author?
 257                      if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id'])
 258                      {
 259                          $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']);
 260                      }
 261                      else
 262                      {
 263                          $sql = 'SELECT u.user_id, u.username, u.user_colour
 264                              FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
 265                              WHERE p.post_id =  ' . $post_info['post_id'] . '
 266                                  AND p.post_delete_user = u.user_id';
 267                          $result = $db->sql_query($sql);
 268                          $post_delete_userinfo = $db->sql_fetchrow($result);
 269                          $db->sql_freeresult($result);
 270                          $display_username = get_username_string('full', $post_info['post_delete_user'], $post_delete_userinfo['username'], $post_delete_userinfo['user_colour']);
 271                      }
 272  
 273                      $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true));
 274                  }
 275                  else
 276                  {
 277                      $l_deleted_by = '';
 278                  }
 279  
 280                  $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']);
 281                  $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']);
 282  
 283                  $post_data = array(
 284                      'S_MCP_QUEUE'            => true,
 285                      'U_APPROVE_ACTION'        => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f=$forum_id"),
 286                      'S_CAN_DELETE_POST'        => $auth->acl_get('m_delete', $post_info['forum_id']),
 287                      'S_CAN_VIEWIP'            => $auth->acl_get('m_info', $post_info['forum_id']),
 288                      'S_POST_REPORTED'        => $post_info['post_reported'],
 289                      'S_POST_UNAPPROVED'        => $post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE,
 290                      'S_POST_LOCKED'            => $post_info['post_edit_locked'],
 291                      'S_USER_NOTES'            => true,
 292                      'S_POST_DELETED'        => ($post_info['post_visibility'] == ITEM_DELETED),
 293                      'DELETED_MESSAGE'        => $l_deleted_by,
 294                      'DELETE_REASON'            => $post_info['post_delete_reason'],
 295  
 296                      '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']}") : '',
 297                      '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),
 298                      '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),
 299                      'U_MCP_USER_NOTES'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
 300                      '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']) : '',
 301                      'U_VIEW_POST'            => $post_url,
 302                      'U_VIEW_TOPIC'            => $topic_url,
 303  
 304                      'MINI_POST_IMG'            => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
 305  
 306                      '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>'),
 307                      'RETURN_POST'            => sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'),
 308                      'RETURN_TOPIC_SIMPLE'    => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'),
 309                      'REPORTED_IMG'            => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
 310                      'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
 311                      'EDIT_IMG'                => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
 312  
 313                      'POST_AUTHOR_FULL'        => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 314                      'POST_AUTHOR_COLOUR'    => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 315                      'POST_AUTHOR'            => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 316                      'U_POST_AUTHOR'            => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 317  
 318                      'POST_PREVIEW'            => $message,
 319                      'POST_SUBJECT'            => $post_info['post_subject'],
 320                      'POST_DATE'                => $user->format_date($post_info['post_time']),
 321                      'POST_IP'                => $post_info['poster_ip'],
 322                      'POST_IPADDR'            => ($auth->acl_get('m_info', $post_info['forum_id']) && $request->variable('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
 323                      'POST_ID'                => $post_info['post_id'],
 324                      'S_FIRST_POST'            => ($post_info['topic_first_post_id'] == $post_id),
 325  
 326                      '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' : '',
 327                  );
 328  
 329                  /**
 330                  * Alter post awaiting approval template before it is rendered
 331                  *
 332                  * @event core.mcp_queue_approve_details_template
 333                  * @var    int        post_id        Post ID
 334                  * @var    int        topic_id    Topic ID
 335                  * @var    array    topic_info    Topic data
 336                  * @var    array    post_info    Post data
 337                  * @var array    post_data    Post template data
 338                  * @var    string    message        Post message
 339                  * @var    string    post_url    Post URL
 340                  * @var    string    topic_url    Topic URL
 341                  * @since 3.2.2-RC1
 342                  */
 343                  $vars = array(
 344                      'post_id',
 345                      'topic_id',
 346                      'topic_info',
 347                      'post_info',
 348                      'post_data',
 349                      'message',
 350                      'post_url',
 351                      'topic_url',
 352                  );
 353                  extract($phpbb_dispatcher->trigger_event('core.mcp_queue_approve_details_template', compact($vars)));
 354  
 355                  $template->assign_vars($post_data);
 356  
 357              break;
 358  
 359              case 'unapproved_topics':
 360              case 'unapproved_posts':
 361              case 'deleted_topics':
 362              case 'deleted_posts':
 363                  $m_perm = 'm_approve';
 364                  $is_topics = ($mode == 'unapproved_topics' || $mode == 'deleted_topics') ? true : false;
 365                  $is_restore = ($mode == 'deleted_posts' || $mode == 'deleted_topics') ? true : false;
 366                  $visibility_const = (!$is_restore) ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED;
 367  
 368                  $user->add_lang(array('viewtopic', 'viewforum'));
 369  
 370                  $topic_id = $request->variable('t', 0);
 371                  $forum_info = array();
 372  
 373                  /* @var $pagination \phpbb\pagination */
 374                  $pagination = $phpbb_container->get('pagination');
 375  
 376                  if ($topic_id)
 377                  {
 378                      $topic_info = phpbb_get_topic_data(array($topic_id));
 379  
 380                      if (!count($topic_info))
 381                      {
 382                          trigger_error('TOPIC_NOT_EXIST');
 383                      }
 384  
 385                      $topic_info = $topic_info[$topic_id];
 386                      $forum_id = $topic_info['forum_id'];
 387                  }
 388  
 389                  $forum_list_approve = get_forum_list($m_perm, false, true);
 390                  $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
 391  
 392                  // Remove forums we cannot read
 393                  foreach ($forum_list_approve as $k => $forum_data)
 394                  {
 395                      if (!isset($forum_list_read[$forum_data['forum_id']]))
 396                      {
 397                          unset($forum_list_approve[$k]);
 398                      }
 399                  }
 400                  unset($forum_list_read);
 401  
 402                  if (!$forum_id)
 403                  {
 404                      $forum_list = array();
 405                      foreach ($forum_list_approve as $row)
 406                      {
 407                          $forum_list[] = $row['forum_id'];
 408                      }
 409  
 410                      if (!count($forum_list))
 411                      {
 412                          trigger_error('NOT_MODERATOR');
 413                      }
 414  
 415                      $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics
 416                          FROM ' . FORUMS_TABLE . '
 417                          WHERE ' . $db->sql_in_set('forum_id', $forum_list);
 418                      $result = $db->sql_query($sql);
 419                      $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics');
 420                      $db->sql_freeresult($result);
 421                  }
 422                  else
 423                  {
 424                      $forum_info = phpbb_get_forum_data(array($forum_id), $m_perm);
 425  
 426                      if (!count($forum_info))
 427                      {
 428                          trigger_error('NOT_MODERATOR');
 429                      }
 430  
 431                      $forum_list = $forum_id;
 432                  }
 433  
 434                  $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
 435                  foreach ($forum_list_approve as $row)
 436                  {
 437                      $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp; &nbsp;', $row['padding']) . truncate_string($row['forum_name'], 30, 255, false, $user->lang['ELLIPSIS']) . '</option>';
 438                  }
 439  
 440                  $sort_days = $total = 0;
 441                  $sort_key = $sort_dir = '';
 442                  $sort_by_sql = $sort_order_sql = array();
 443                  phpbb_mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
 444  
 445                  $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 446  
 447                  $forum_names = array();
 448  
 449                  if (!$is_topics)
 450                  {
 451                      $sql = 'SELECT p.post_id
 452                          FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . '
 453                          WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . '
 454                              AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) . '
 455                              ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
 456                              ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
 457                              AND t.topic_id = p.topic_id
 458                              AND (t.topic_visibility <> p.post_visibility
 459                                  OR t.topic_delete_user = 0)
 460                              $limit_time_sql
 461                          ORDER BY $sort_order_sql";
 462  
 463                      /**
 464                      * Alter sql query to get posts in queue to be accepted
 465                      *
 466                      * @event core.mcp_queue_get_posts_query_before
 467                      * @var    string    sql                        Associative array with the query to be executed
 468                      * @var    array    forum_list                List of forums that contain the posts
 469                      * @var    int        visibility_const        Integer with one of the possible ITEM_* constant values
 470                      * @var    int        topic_id                If topic_id not equal to 0, the topic id to filter the posts to display
 471                      * @var    string    limit_time_sql            String with the SQL code to limit the time interval of the post (Note: May be empty string)
 472                      * @var    string    sort_order_sql            String with the ORDER BY SQL code used in this query
 473                      * @since 3.1.0-RC3
 474                      */
 475                      $vars = array(
 476                          'sql',
 477                          'forum_list',
 478                          'visibility_const',
 479                          'topic_id',
 480                          'limit_time_sql',
 481                          'sort_order_sql',
 482                      );
 483                      extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_query_before', compact($vars)));
 484  
 485                      $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 486  
 487                      $i = 0;
 488                      $post_ids = array();
 489                      while ($row = $db->sql_fetchrow($result))
 490                      {
 491                          $post_ids[] = $row['post_id'];
 492                          $row_num[$row['post_id']] = $i++;
 493                      }
 494                      $db->sql_freeresult($result);
 495  
 496                      if (count($post_ids))
 497                      {
 498                          $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, p.post_attachment, u.username, u.username_clean, u.user_colour
 499                              FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
 500                              WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
 501                                  AND t.topic_id = p.topic_id
 502                                  AND u.user_id = p.poster_id
 503                              ORDER BY ' . $sort_order_sql;
 504  
 505                          /**
 506                          * Alter sql query to get information on all posts in queue
 507                          *
 508                          * @event core.mcp_queue_get_posts_for_posts_query_before
 509                          * @var    string    sql                        String with the query to be executed
 510                          * @var    array    forum_list                List of forums that contain the posts
 511                          * @var    int        visibility_const        Integer with one of the possible ITEM_* constant values
 512                          * @var    int        topic_id                topic_id in the page request
 513                          * @var    string    limit_time_sql            String with the SQL code to limit the time interval of the post (Note: May be empty string)
 514                          * @var    string    sort_order_sql            String with the ORDER BY SQL code used in this query
 515                          * @since 3.2.3-RC2
 516                          */
 517                          $vars = array(
 518                              'sql',
 519                              'forum_list',
 520                              'visibility_const',
 521                              'topic_id',
 522                              'limit_time_sql',
 523                              'sort_order_sql',
 524                          );
 525                          extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_for_posts_query_before', compact($vars)));
 526  
 527                          $result = $db->sql_query($sql);
 528  
 529                          $post_data = $rowset = array();
 530                          while ($row = $db->sql_fetchrow($result))
 531                          {
 532                              $forum_names[] = $row['forum_id'];
 533                              $post_data[$row['post_id']] = $row;
 534                          }
 535                          $db->sql_freeresult($result);
 536  
 537                          foreach ($post_ids as $post_id)
 538                          {
 539                              $rowset[] = $post_data[$post_id];
 540                          }
 541                          unset($post_data, $post_ids);
 542                      }
 543                      else
 544                      {
 545                          $rowset = array();
 546                      }
 547                  }
 548                  else
 549                  {
 550                      $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_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour
 551                          FROM ' . TOPICS_TABLE . ' t
 552                          WHERE ' . $db->sql_in_set('forum_id', $forum_list) . '
 553                              AND  ' . $db->sql_in_set('topic_visibility', $visibility_const) . "
 554                              AND topic_delete_user <> 0
 555                              $limit_time_sql
 556                          ORDER BY $sort_order_sql";
 557  
 558                      /**
 559                      * Alter sql query to get information on all topics in the list of forums provided.
 560                      *
 561                      * @event core.mcp_queue_get_posts_for_topics_query_before
 562                      * @var    string    sql                        String with the query to be executed
 563                      * @var    array    forum_list                List of forums that contain the posts
 564                      * @var    int        visibility_const        Integer with one of the possible ITEM_* constant values
 565                      * @var    int        topic_id                topic_id in the page request
 566                      * @var    string    limit_time_sql            String with the SQL code to limit the time interval of the post (Note: May be empty string)
 567                      * @var    string    sort_order_sql            String with the ORDER BY SQL code used in this query
 568                      * @since 3.1.0-RC3
 569                      */
 570                      $vars = array(
 571                          'sql',
 572                          'forum_list',
 573                          'visibility_const',
 574                          'topic_id',
 575                          'limit_time_sql',
 576                          'sort_order_sql',
 577                      );
 578                      extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_for_topics_query_before', compact($vars)));
 579  
 580                      $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 581  
 582                      $rowset = array();
 583                      while ($row = $db->sql_fetchrow($result))
 584                      {
 585                          $forum_names[] = $row['forum_id'];
 586                          $rowset[] = $row;
 587                      }
 588                      $db->sql_freeresult($result);
 589                  }
 590  
 591                  if (count($forum_names))
 592                  {
 593                      // Select the names for the forum_ids
 594                      $sql = 'SELECT forum_id, forum_name
 595                          FROM ' . FORUMS_TABLE . '
 596                          WHERE ' . $db->sql_in_set('forum_id', $forum_names);
 597                      $result = $db->sql_query($sql, 3600);
 598  
 599                      $forum_names = array();
 600                      while ($row = $db->sql_fetchrow($result))
 601                      {
 602                          $forum_names[$row['forum_id']] = $row['forum_name'];
 603                      }
 604                      $db->sql_freeresult($result);
 605                  }
 606  
 607                  foreach ($rowset as $row)
 608                  {
 609                      if (empty($row['post_username']))
 610                      {
 611                          $row['post_username'] = $row['username'] ?: $user->lang['GUEST'];
 612                      }
 613  
 614                      $post_row = array(
 615                          'U_TOPIC'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
 616                          'U_VIEWFORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
 617                          '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'] : ''),
 618                          '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']}" : '')),
 619  
 620                          'POST_AUTHOR_FULL'        => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 621                          'POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 622                          'POST_AUTHOR'            => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 623                          'U_POST_AUTHOR'            => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 624  
 625                          'POST_ID'        => $row['post_id'],
 626                          'TOPIC_ID'        => $row['topic_id'],
 627                          'FORUM_NAME'    => $forum_names[$row['forum_id']],
 628                          'POST_SUBJECT'    => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
 629                          'TOPIC_TITLE'    => $row['topic_title'],
 630                          'POST_TIME'        => $user->format_date($row['post_time']),
 631                          'S_HAS_ATTACHMENTS'    => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment'],
 632                      );
 633  
 634                      /**
 635                      * Alter sql query to get information on all topics in the list of forums provided.
 636                      *
 637                      * @event core.mcp_queue_get_posts_modify_post_row
 638                      * @var    array    post_row    Template variables for current post
 639                      * @var    array    row            Post data
 640                      * @var    array    forum_names    Forum names
 641                      * @since 3.2.3-RC2
 642                      */
 643                      $vars = array(
 644                          'post_row',
 645                          'row',
 646                          'forum_names',
 647                      );
 648                      extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_modify_post_row', compact($vars)));
 649  
 650                      $template->assign_block_vars('postrow', $post_row);
 651                  }
 652                  unset($rowset, $forum_names);
 653  
 654                  $base_url = $this->u_action . "&amp;f=$forum_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir";
 655                  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
 656  
 657                  // Now display the page
 658                  $template->assign_vars(array(
 659                      'L_DISPLAY_ITEMS'        => (!$is_topics) ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
 660                      'L_EXPLAIN'                => $user->lang['MCP_QUEUE_' . strtoupper($mode) . '_EXPLAIN'],
 661                      'L_TITLE'                => $user->lang['MCP_QUEUE_' . strtoupper($mode)],
 662                      'L_ONLY_TOPIC'            => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
 663  
 664                      'S_FORUM_OPTIONS'        => $forum_options,
 665                      'S_MCP_ACTION'            => build_url(array('t', 'f', 'sd', 'st', 'sk')),
 666                      'S_TOPICS'                => $is_topics,
 667                      'S_RESTORE'                => $is_restore,
 668  
 669                      'TOPIC_ID'                => $topic_id,
 670                      'TOTAL'                    => $user->lang(((!$is_topics) ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total),
 671                  ));
 672  
 673                  $this->tpl_name = 'mcp_queue';
 674              break;
 675          }
 676      }
 677  
 678      /**
 679      * Approve/Restore posts
 680      *
 681      * @param $action        string    Action we perform on the posts ('approve' or 'restore')
 682      * @param $post_id_list    array    IDs of the posts to approve/restore
 683      * @param $id            mixed    Category of the current active module
 684      * @param $mode            string    Active module
 685      * @return null
 686      */
 687  	static public function approve_posts($action, $post_id_list, $id, $mode)
 688      {
 689          global $template, $user, $request, $phpbb_container, $phpbb_dispatcher;
 690          global $phpEx, $phpbb_root_path, $phpbb_log;
 691  
 692          if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
 693          {
 694              send_status_line(403, 'Forbidden');
 695              trigger_error('NOT_AUTHORISED');
 696          }
 697  
 698          $redirect = $request->variable('redirect', build_url(array('quickmod')));
 699          $redirect = reapply_sid($redirect);
 700          $post_url = '';
 701          $approve_log = array();
 702          $num_topics = 0;
 703  
 704          $s_hidden_fields = build_hidden_fields(array(
 705              'i'                => $id,
 706              'mode'            => $mode,
 707              'post_id_list'    => $post_id_list,
 708              'action'        => $action,
 709              'redirect'        => $redirect,
 710          ));
 711  
 712          $post_info = phpbb_get_post_data($post_id_list, 'm_approve');
 713  
 714          if (confirm_box(true))
 715          {
 716              $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster']));
 717  
 718              $topic_info = array();
 719  
 720              // Group the posts by topic_id
 721              foreach ($post_info as $post_id => $post_data)
 722              {
 723                  if ($post_data['post_visibility'] == ITEM_APPROVED)
 724                  {
 725                      continue;
 726                  }
 727                  $topic_id = (int) $post_data['topic_id'];
 728  
 729                  $topic_info[$topic_id]['posts'][] = (int) $post_id;
 730                  $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id'];
 731  
 732                  // Refresh the first post, if the time or id is older then the current one
 733                  if ($post_id <= $post_data['topic_first_post_id'] || $post_data['post_time'] <= $post_data['topic_time'])
 734                  {
 735                      $topic_info[$topic_id]['first_post'] = true;
 736                  }
 737  
 738                  // Refresh the last post, if the time or id is newer then the current one
 739                  if ($post_id >= $post_data['topic_last_post_id'] || $post_data['post_time'] >= $post_data['topic_last_post_time'])
 740                  {
 741                      $topic_info[$topic_id]['last_post'] = true;
 742                  }
 743  
 744                  $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'];
 745  
 746                  $approve_log[] = array(
 747                      'forum_id'        => $post_data['forum_id'],
 748                      'topic_id'        => $post_data['topic_id'],
 749                      'post_id'        => $post_id,
 750                      'post_subject'    => $post_data['post_subject'],
 751                  );
 752              }
 753  
 754              /* @var $phpbb_content_visibility \phpbb\content_visibility */
 755              $phpbb_content_visibility = $phpbb_container->get('content.visibility');
 756              foreach ($topic_info as $topic_id => $topic_data)
 757              {
 758                  $phpbb_content_visibility->set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post']));
 759              }
 760  
 761              foreach ($approve_log as $log_data)
 762              {
 763                  $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_POST_' . strtoupper($action) . 'D', false, array(
 764                      'forum_id' => $log_data['forum_id'],
 765                      'topic_id' => $log_data['topic_id'],
 766                      'post_id'  => $log_data['post_id'],
 767                      $log_data['post_subject']
 768                  ));
 769              }
 770  
 771              // Only send out the mails, when the posts are being approved
 772              if ($action == 'approve')
 773              {
 774                  /* @var $phpbb_notifications \phpbb\notification\manager */
 775                  $phpbb_notifications = $phpbb_container->get('notification_manager');
 776  
 777                  // Handle notifications
 778                  foreach ($post_info as $post_id => $post_data)
 779                  {
 780                      // A single topic approval may also happen here, so handle deleting the respective notification.
 781                      if (!$post_data['topic_posts_approved'])
 782                      {
 783                          $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']);
 784  
 785                          if ($post_data['post_visibility'] == ITEM_UNAPPROVED)
 786                          {
 787                              $phpbb_notifications->add_notifications(array('notification.type.topic'), $post_data);
 788                          }
 789                          if ($post_data['post_visibility'] != ITEM_APPROVED)
 790                          {
 791                              $num_topics++;
 792                          }
 793                      }
 794                      else
 795                      {
 796                          // Only add notifications, if we are not reapproving post
 797                          // When the topic was already approved, but was edited and
 798                          // now needs re-approval, we don't want to notify the users
 799                          // again.
 800                          if ($post_data['post_visibility'] == ITEM_UNAPPROVED)
 801                          {
 802                              $phpbb_notifications->add_notifications(array(
 803                                  'notification.type.bookmark',
 804                                  'notification.type.post',
 805                              ), $post_data);
 806                          }
 807                      }
 808                      $phpbb_notifications->add_notifications(array('notification.type.quote'), $post_data);
 809                      $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id);
 810  
 811                      $phpbb_notifications->mark_notifications(array(
 812                          'notification.type.quote',
 813                          'notification.type.bookmark',
 814                          'notification.type.post',
 815                      ), $post_data['post_id'], $user->data['user_id']);
 816  
 817                      // Notify Poster?
 818                      if ($notify_poster)
 819                      {
 820                          if ($post_data['poster_id'] == ANONYMOUS)
 821                          {
 822                              continue;
 823                          }
 824  
 825                          if (!$post_data['topic_posts_approved'])
 826                          {
 827                              $phpbb_notifications->add_notifications('notification.type.approve_topic', $post_data);
 828                          }
 829                          else
 830                          {
 831                              $phpbb_notifications->add_notifications('notification.type.approve_post', $post_data);
 832                          }
 833                      }
 834                  }
 835              }
 836  
 837              if ($num_topics >= 1)
 838              {
 839                  $success_msg = ($num_topics == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS';
 840              }
 841              else
 842              {
 843                  $success_msg = (count($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS';
 844              }
 845  
 846              /**
 847               * Perform additional actions during post(s) approval
 848               *
 849               * @event core.approve_posts_after
 850               * @var    string    action                Variable containing the action we perform on the posts ('approve' or 'restore')
 851               * @var    array    post_info            Array containing info for all posts being approved
 852               * @var    array    topic_info            Array containing info for all parent topics of the posts
 853               * @var    int        num_topics            Variable containing number of topics
 854               * @var bool    notify_poster        Variable telling if the post should be notified or not
 855               * @var    string    success_msg            Variable containing the language key for the success message
 856               * @var string    redirect            Variable containing the redirect url
 857               * @since 3.1.4-RC1
 858               */
 859              $vars = array(
 860                  'action',
 861                  'post_info',
 862                  'topic_info',
 863                  'num_topics',
 864                  'notify_poster',
 865                  'success_msg',
 866                  'redirect',
 867              );
 868              extract($phpbb_dispatcher->trigger_event('core.approve_posts_after', compact($vars)));
 869  
 870              meta_refresh(3, $redirect);
 871              $message = $user->lang[$success_msg];
 872  
 873              if ($request->is_ajax())
 874              {
 875                  $json_response = new \phpbb\json_response;
 876                  $json_response->send(array(
 877                      'MESSAGE_TITLE'        => $user->lang['INFORMATION'],
 878                      'MESSAGE_TEXT'        => $message,
 879                      'REFRESH_DATA'        => null,
 880                      'visible'            => true,
 881                  ));
 882              }
 883              $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
 884  
 885              // If approving one post, also give links back to post...
 886              if (count($post_info) == 1 && $post_url)
 887              {
 888                  $message .= '<br /><br />' . $user->lang('RETURN_POST', '<a href="' . $post_url . '">', '</a>');
 889              }
 890              trigger_error($message);
 891          }
 892          else
 893          {
 894              $show_notify = false;
 895  
 896              if ($action == 'approve')
 897              {
 898                  foreach ($post_info as $post_data)
 899                  {
 900                      if (!$post_data['topic_posts_approved'])
 901                      {
 902                          $num_topics++;
 903                      }
 904  
 905                      if (!$show_notify && $post_data['poster_id'] != ANONYMOUS)
 906                      {
 907                          $show_notify = true;
 908                      }
 909                  }
 910              }
 911  
 912              $template->assign_vars(array(
 913                  'S_NOTIFY_POSTER'            => $show_notify,
 914                  'S_' . strtoupper($action)    => true,
 915              ));
 916  
 917              // Create the confirm box message
 918              $action_msg = strtoupper($action);
 919              $num_posts = count($post_id_list) - $num_topics;
 920              if ($num_topics > 0 && $num_posts <= 0)
 921              {
 922                  $action_msg .= '_TOPIC' . (($num_topics == 1) ? '' : 'S');
 923              }
 924              else
 925              {
 926                  $action_msg .= '_POST' . ((count($post_id_list) == 1) ? '' : 'S');
 927              }
 928              confirm_box(false, $action_msg, $s_hidden_fields, 'mcp_approve.html');
 929          }
 930  
 931          redirect($redirect);
 932      }
 933  
 934      /**
 935      * Approve/Restore topics
 936      *
 937      * @param $action        string    Action we perform on the posts ('approve' or 'restore')
 938      * @param $topic_id_list    array    IDs of the topics to approve/restore
 939      * @param $id            mixed    Category of the current active module
 940      * @param $mode            string    Active module
 941      * @return null
 942      */
 943  	static public function approve_topics($action, $topic_id_list, $id, $mode)
 944      {
 945          global $db, $template, $user, $phpbb_log;
 946          global $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_dispatcher;
 947  
 948          if (!phpbb_check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve')))
 949          {
 950              send_status_line(403, 'Forbidden');
 951              trigger_error('NOT_AUTHORISED');
 952          }
 953  
 954          $redirect = $request->variable('redirect', build_url(array('quickmod')));
 955          $redirect = reapply_sid($redirect);
 956          $success_msg = $topic_url = '';
 957          $approve_log = array();
 958  
 959          $s_hidden_fields = build_hidden_fields(array(
 960              'i'                => $id,
 961              'mode'            => $mode,
 962              'topic_id_list'    => $topic_id_list,
 963              'action'        => $action,
 964              'redirect'        => $redirect,
 965          ));
 966  
 967          $topic_info = phpbb_get_topic_data($topic_id_list, 'm_approve');
 968  
 969          if (confirm_box(true))
 970          {
 971              $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false;
 972  
 973              /* @var $phpbb_content_visibility \phpbb\content_visibility */
 974              $phpbb_content_visibility = $phpbb_container->get('content.visibility');
 975              $first_post_ids = array();
 976  
 977              foreach ($topic_info as $topic_id => $topic_data)
 978              {
 979                  $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '');
 980                  $first_post_ids[$topic_id] = (int) $topic_data['topic_first_post_id'];
 981  
 982                  $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&amp;t={$topic_id}");
 983  
 984                  $approve_log[] = array(
 985                      'forum_id'        => $topic_data['forum_id'],
 986                      'topic_id'        => $topic_data['topic_id'],
 987                      'topic_title'    => $topic_data['topic_title'],
 988                  );
 989              }
 990  
 991              if (count($topic_info) >= 1)
 992              {
 993                  $success_msg = (count($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS';
 994              }
 995  
 996              foreach ($approve_log as $log_data)
 997              {
 998                  $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_TOPIC_' . strtoupper($action) . 'D', false, array(
 999                      'forum_id' => $log_data['forum_id'],
1000                      'topic_id' => $log_data['topic_id'],
1001                      $log_data['topic_title']
1002                  ));
1003              }
1004  
1005              // Only send out the mails, when the posts are being approved
1006              if ($action == 'approve')
1007              {
1008                  // Grab the first post text as it's needed for the quote notification.
1009                  $sql = 'SELECT topic_id, post_text
1010                      FROM ' . POSTS_TABLE . '
1011                      WHERE ' . $db->sql_in_set('post_id', $first_post_ids);
1012                  $result = $db->sql_query($sql);
1013  
1014                  while ($row = $db->sql_fetchrow($result))
1015                  {
1016                      $topic_info[$row['topic_id']]['post_text'] = $row['post_text'];
1017                  }
1018                  $db->sql_freeresult($result);
1019  
1020                  // Handle notifications
1021                  /* @var $phpbb_notifications \phpbb\notification\manager */
1022                  $phpbb_notifications = $phpbb_container->get('notification_manager');
1023  
1024                  foreach ($topic_info as $topic_id => $topic_data)
1025                  {
1026                      $topic_data = array_merge($topic_data, array(
1027                          'post_id'        => $topic_data['topic_first_post_id'],
1028                          'post_subject'    => $topic_data['topic_title'],
1029                          'post_time'        => $topic_data['topic_time'],
1030                          'poster_id'        => $topic_data['topic_poster'],
1031                          'post_username'    => $topic_data['topic_first_poster_name'],
1032                      ));
1033  
1034                      $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $topic_id);
1035  
1036                      // Only add notifications, if we are not reapproving post
1037                      // When the topic was already approved, but was edited and
1038                      // now needs re-approval, we don't want to notify the users
1039                      // again.
1040                      if ($topic_data['topic_visibility'] == ITEM_UNAPPROVED)
1041                      {
1042                          $phpbb_notifications->add_notifications(array(
1043                              'notification.type.quote',
1044                              'notification.type.topic',
1045                          ), $topic_data);
1046                      }
1047  
1048                      $phpbb_notifications->mark_notifications('quote', $topic_data['post_id'], $user->data['user_id']);
1049                      $phpbb_notifications->mark_notifications('topic', $topic_id, $user->data['user_id']);
1050  
1051                      if ($notify_poster)
1052                      {
1053                          $phpbb_notifications->add_notifications('notification.type.approve_topic', $topic_data);
1054                      }
1055                  }
1056              }
1057  
1058              /**
1059               * Perform additional actions during topics(s) approval
1060               *
1061               * @event core.approve_topics_after
1062               * @var    string    action                Variable containing the action we perform on the posts ('approve' or 'restore')
1063               * @var    mixed    topic_info            Array containing info for all topics being approved
1064               * @var    array    first_post_ids        Array containing ids of all first posts
1065               * @var bool    notify_poster        Variable telling if the poster should be notified or not
1066               * @var    string    success_msg            Variable containing the language key for the success message
1067               * @var string    redirect            Variable containing the redirect url
1068               * @since 3.1.4-RC1
1069               */
1070              $vars = array(
1071                  'action',
1072                  'topic_info',
1073                  'first_post_ids',
1074                  'notify_poster',
1075                  'success_msg',
1076                  'redirect',
1077              );
1078              extract($phpbb_dispatcher->trigger_event('core.approve_topics_after', compact($vars)));
1079  
1080              meta_refresh(3, $redirect);
1081              $message = $user->lang[$success_msg];
1082  
1083              if ($request->is_ajax())
1084              {
1085                  $json_response = new \phpbb\json_response;
1086                  $json_response->send(array(
1087                      'MESSAGE_TITLE'        => $user->lang['INFORMATION'],
1088                      'MESSAGE_TEXT'        => $message,
1089                      'REFRESH_DATA'        => null,
1090                      'visible'            => true,
1091                  ));
1092              }
1093              $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
1094  
1095              // If approving one topic, also give links back to topic...
1096              if (count($topic_info) == 1 && $topic_url)
1097              {
1098                  $message .= '<br /><br />' . $user->lang('RETURN_TOPIC', '<a href="' . $topic_url . '">', '</a>');
1099              }
1100              trigger_error($message);
1101          }
1102          else
1103          {
1104              $show_notify = false;
1105  
1106              if ($action == 'approve')
1107              {
1108                  foreach ($topic_info as $topic_data)
1109                  {
1110                      if ($topic_data['topic_poster'] == ANONYMOUS)
1111                      {
1112                          continue;
1113                      }
1114                      else
1115                      {
1116                          $show_notify = true;
1117                          break;
1118                      }
1119                  }
1120              }
1121  
1122              $template->assign_vars(array(
1123                  'S_NOTIFY_POSTER'            => $show_notify,
1124                  'S_' . strtoupper($action)    => true,
1125              ));
1126  
1127              confirm_box(false, strtoupper($action) . '_TOPIC' . ((count($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
1128          }
1129  
1130          redirect($redirect);
1131      }
1132  
1133      /**
1134      * Disapprove Post
1135      *
1136      * @param $post_id_list    array    IDs of the posts to disapprove/delete
1137      * @param $id            mixed    Category of the current active module
1138      * @param $mode            string    Active module
1139      * @return null
1140      */
1141  	static public function disapprove_posts($post_id_list, $id, $mode)
1142      {
1143          global $db, $template, $user, $phpbb_container, $phpbb_dispatcher;
1144          global $phpEx, $phpbb_root_path, $request, $phpbb_log;
1145  
1146          if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
1147          {
1148              send_status_line(403, 'Forbidden');
1149              trigger_error('NOT_AUTHORISED');
1150          }
1151  
1152          $redirect = $request->variable('redirect', build_url(array('t', 'mode', 'quickmod')) . "&amp;mode=$mode");
1153          $redirect = reapply_sid($redirect);
1154          $reason = $request->variable('reason', '', true);
1155          $reason_id = $request->variable('reason_id', 0);
1156          $additional_msg = '';
1157  
1158          $s_hidden_fields = build_hidden_fields(array(
1159              'i'                => $id,
1160              'mode'            => $mode,
1161              'post_id_list'    => $post_id_list,
1162              'action'        => 'disapprove',
1163              'redirect'        => $redirect,
1164          ));
1165  
1166          $notify_poster = $request->is_set('notify_poster');
1167          $disapprove_reason = '';
1168  
1169          if ($reason_id)
1170          {
1171              $sql = 'SELECT reason_title, reason_description
1172                  FROM ' . REPORTS_REASONS_TABLE . "
1173                  WHERE reason_id = $reason_id";
1174              $result = $db->sql_query($sql);
1175              $row = $db->sql_fetchrow($result);
1176              $db->sql_freeresult($result);
1177  
1178              if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
1179              {
1180                  $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
1181  
1182                  $request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
1183                  $request->overwrite('confirm_key', null, \phpbb\request\request_interface::POST);
1184                  $request->overwrite('confirm_key', null, \phpbb\request\request_interface::REQUEST);
1185              }
1186              else
1187              {
1188                  // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
1189                  $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']) : '';
1190                  $disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
1191  
1192                  if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
1193                  {
1194                      $disapprove_reason_lang = strtoupper($row['reason_title']);
1195                  }
1196              }
1197          }
1198  
1199          $post_info = phpbb_get_post_data($post_id_list, 'm_approve');
1200  
1201          $is_disapproving = false;
1202          foreach ($post_info as $post_id => $post_data)
1203          {
1204              if ($post_data['post_visibility'] == ITEM_DELETED)
1205              {
1206                  continue;
1207              }
1208  
1209              $is_disapproving = true;
1210          }
1211  
1212          if (confirm_box(true))
1213          {
1214              $disapprove_log_topics = $disapprove_log_posts = array();
1215              $topic_posts_unapproved = $post_disapprove_list = $topic_information = array();
1216  
1217              // Build a list of posts to be disapproved and get the related topics real replies count
1218              foreach ($post_info as $post_id => $post_data)
1219              {
1220                  if ($mode === 'unapproved_topics' && $post_data['post_visibility'] == ITEM_APPROVED)
1221                  {
1222                      continue;
1223                  }
1224  
1225                  $post_disapprove_list[$post_id] = $post_data['topic_id'];
1226                  if (!isset($topic_posts_unapproved[$post_data['topic_id']]))
1227                  {
1228                      $topic_information[$post_data['topic_id']] = $post_data;
1229                      $topic_posts_unapproved[$post_data['topic_id']] = 0;
1230                  }
1231                  $topic_posts_unapproved[$post_data['topic_id']]++;
1232              }
1233  
1234              // Do not try to disapprove if no posts are selected
1235              if (empty($post_disapprove_list))
1236              {
1237                  trigger_error('NO_POST_SELECTED');
1238              }
1239  
1240              // Now we build the log array
1241              foreach ($post_disapprove_list as $post_id => $topic_id)
1242              {
1243                  // If the count of disapproved posts for the topic is equal
1244                  // to the number of unapproved posts in the topic, and there are no different
1245                  // posts, we disapprove the hole topic
1246                  if ($topic_information[$topic_id]['topic_posts_approved'] == 0 &&
1247                      $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 &&
1248                      $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id])
1249                  {
1250                      // Don't write the log more than once for every topic
1251                      if (!isset($disapprove_log_topics[$topic_id]))
1252                      {
1253                          // Build disapproved topics log
1254                          $disapprove_log_topics[$topic_id] = array(
1255                              'type'            => 'topic',
1256                              'post_subject'    => $post_info[$post_id]['topic_title'],
1257                              'forum_id'        => $post_info[$post_id]['forum_id'],
1258                              'topic_id'        => 0, // useless to log a topic id, as it will be deleted
1259                              'post_username'    => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'],
1260                          );
1261                      }
1262                  }
1263                  else
1264                  {
1265                      // Build disapproved posts log
1266                      $disapprove_log_posts[] = array(
1267                          'type'            => 'post',
1268                          'post_subject'    => $post_info[$post_id]['post_subject'],
1269                          'forum_id'        => $post_info[$post_id]['forum_id'],
1270                          'topic_id'        => $post_info[$post_id]['topic_id'],
1271                          'post_username'    => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'],
1272                      );
1273  
1274                  }
1275              }
1276  
1277              // Get disapproved posts/topics counts separately
1278              $num_disapproved_topics = count($disapprove_log_topics);
1279              $num_disapproved_posts = count($disapprove_log_posts);
1280  
1281              // Build the whole log
1282              $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
1283  
1284              // Unset unneeded arrays
1285              unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
1286  
1287              // Let's do the job - delete disapproved posts
1288              if (count($post_disapprove_list))
1289              {
1290                  if (!function_exists('delete_posts'))
1291                  {
1292                      include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
1293                  }
1294  
1295                  // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
1296                  // Note: function delete_posts triggers related forums/topics sync,
1297                  // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
1298                  delete_posts('post_id', array_keys($post_disapprove_list));
1299  
1300                  foreach ($disapprove_log as $log_data)
1301                  {
1302                      if ($is_disapproving)
1303                      {
1304                          $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED';
1305                          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, $l_log_message, false, array(
1306                              'forum_id' => $log_data['forum_id'],
1307                              'topic_id' => $log_data['topic_id'],
1308                              $log_data['post_subject'],
1309                              $disapprove_reason,
1310                              $log_data['post_username']
1311                          ));
1312                      }
1313                      else
1314                      {
1315                          $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST';
1316                          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, $l_log_message, false, array(
1317                              'forum_id' => $log_data['forum_id'],
1318                              'topic_id' => $log_data['topic_id'],
1319                              $log_data['post_subject'],
1320                              $log_data['post_username']
1321                          ));
1322                      }
1323                  }
1324              }
1325  
1326              /* @var $phpbb_notifications \phpbb\notification\manager */
1327              $phpbb_notifications = $phpbb_container->get('notification_manager');
1328  
1329              $lang_reasons = array();
1330  
1331              foreach ($post_info as $post_id => $post_data)
1332              {
1333                  $disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 &&
1334                      $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 &&
1335                      $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id];
1336  
1337                  $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id);
1338  
1339                  // Do we disapprove the whole topic? Remove potential notifications
1340                  if ($disapprove_all_posts_in_topic)
1341                  {
1342                      $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']);
1343                  }
1344  
1345                  // Notify Poster?
1346                  if ($notify_poster)
1347                  {
1348                      if ($post_data['poster_id'] == ANONYMOUS)
1349                      {
1350                          continue;
1351                      }
1352  
1353                      $post_data['disapprove_reason'] = $disapprove_reason;
1354                      if (isset($disapprove_reason_lang))
1355                      {
1356                          // Okay we need to get the reason from the posters language
1357                          if (!isset($lang_reasons[$post_data['user_lang']]))
1358                          {
1359                              // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
1360                              $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
1361  
1362                              // Only load up the language pack if the language is different to the current one
1363                              if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
1364                              {
1365                                  // Load up the language pack
1366                                  $lang = array();
1367                                  @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
1368  
1369                                  // If we find the reason in this language pack use it
1370                                  if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
1371                                  {
1372                                      $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
1373                                  }
1374  
1375                                  unset($lang); // Free memory
1376                              }
1377                          }
1378  
1379                          $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']];
1380                          $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : '';
1381                      }
1382  
1383                      if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1)
1384                      {
1385                          // If there is only 1 post when disapproving the topic,
1386                          // we send the user a "disapprove topic" notification...
1387                          $phpbb_notifications->add_notifications('notification.type.disapprove_topic', $post_data);
1388                      }
1389                      else
1390                      {
1391                          // ... otherwise there are multiple unapproved posts and
1392                          // all of them are disapproved as posts.
1393                          $phpbb_notifications->add_notifications('notification.type.disapprove_post', $post_data);
1394                      }
1395                  }
1396              }
1397  
1398              if ($num_disapproved_topics)
1399              {
1400                  $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS';
1401              }
1402              else
1403              {
1404                  $success_msg = ($num_disapproved_posts == 1) ? 'POST' : 'POSTS';
1405              }
1406  
1407              if ($is_disapproving)
1408              {
1409                  $success_msg .= '_DISAPPROVED_SUCCESS';
1410              }
1411              else
1412              {
1413                  $success_msg .= '_DELETED_SUCCESS';
1414              }
1415  
1416              // If we came from viewtopic, we try to go back to it.
1417              if (strpos($redirect, $phpbb_root_path . 'viewtopic.' . $phpEx) === 0)
1418              {
1419                  if ($num_disapproved_topics == 0)
1420                  {
1421                      // So we need to remove the post id part from the Url
1422                      $redirect = str_replace("&amp;p={$post_id_list[0]}#p{$post_id_list[0]}", '', $redirect);
1423                  }
1424                  else
1425                  {
1426                      // However this is only possible if the topic still exists,
1427                      // Otherwise we go back to the viewforum page
1428                      $redirect = append_sid($phpbb_root_path . 'viewforum.' . $phpEx, 'f=' . $request->variable('f', 0));
1429                  }
1430              }
1431  
1432              /**
1433               * Perform additional actions during post(s) disapproval
1434               *
1435               * @event core.disapprove_posts_after
1436               * @var    array    post_info                    Array containing info for all posts being disapproved
1437               * @var    array    topic_information            Array containing information for the topics
1438               * @var    array    topic_posts_unapproved        Array containing list of topic ids and the count of disapproved posts in them
1439               * @var    array    post_disapprove_list        Array containing list of posts and their topic id
1440               * @var    int        num_disapproved_topics        Variable containing the number of disapproved topics
1441               * @var    int        num_disapproved_posts        Variable containing the number of disapproved posts
1442               * @var array    lang_reasons                Array containing the language keys for reasons
1443               * @var    string    disapprove_reason            Variable containing the language key for the success message
1444               * @var    string    disapprove_reason_lang        Variable containing the language key for the success message
1445               * @var bool    is_disapproving                Variable telling if anything is going to be disapproved
1446               * @var bool    notify_poster                Variable telling if the post should be notified or not
1447               * @var    string    success_msg                    Variable containing the language key for the success message
1448               * @var string    redirect                    Variable containing the redirect url
1449               * @since 3.1.4-RC1
1450               */
1451              $vars = array(
1452                  'post_info',
1453                  'topic_information',
1454                  'topic_posts_unapproved',
1455                  'post_disapprove_list',
1456                  'num_disapproved_topics',
1457                  'num_disapproved_posts',
1458                  'lang_reasons',
1459                  'disapprove_reason',
1460                  'disapprove_reason_lang',
1461                  'is_disapproving',
1462                  'notify_poster',
1463                  'success_msg',
1464                  'redirect',
1465              );
1466              extract($phpbb_dispatcher->trigger_event('core.disapprove_posts_after', compact($vars)));
1467  
1468              unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang);
1469  
1470              meta_refresh(3, $redirect);
1471              $message = $user->lang[$success_msg];
1472  
1473              if ($request->is_ajax())
1474              {
1475                  $json_response = new \phpbb\json_response;
1476                  $json_response->send(array(
1477                      'MESSAGE_TITLE'        => $user->lang['INFORMATION'],
1478                      'MESSAGE_TEXT'        => $message,
1479                      'REFRESH_DATA'        => null,
1480                      'visible'            => false,
1481                  ));
1482              }
1483              $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
1484              trigger_error($message);
1485          }
1486          else
1487          {
1488              $show_notify = false;
1489  
1490              foreach ($post_info as $post_data)
1491              {
1492                  if ($post_data['poster_id'] == ANONYMOUS)
1493                  {
1494                      continue;
1495                  }
1496                  else
1497                  {
1498                      $show_notify = true;
1499                      break;
1500                  }
1501              }
1502  
1503              $l_confirm_msg = 'DISAPPROVE_POST';
1504              $confirm_template = 'mcp_approve.html';
1505              if ($is_disapproving)
1506              {
1507                  $phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id);
1508              }
1509              else
1510              {
1511                  $user->add_lang('posting');
1512  
1513                  $l_confirm_msg = 'DELETE_POST_PERMANENTLY';
1514                  $confirm_template = 'confirm_delete_body.html';
1515              }
1516              $l_confirm_msg .= ((count($post_id_list) == 1) ? '' : 'S');
1517  
1518              $template->assign_vars(array(
1519                  'S_NOTIFY_POSTER'    => $show_notify,
1520                  'S_APPROVE'            => false,
1521                  'REASON'            => ($is_disapproving) ? $reason : '',
1522                  'ADDITIONAL_MSG'    => $additional_msg,
1523              ));
1524  
1525              confirm_box(false, $l_confirm_msg, $s_hidden_fields, $confirm_template);
1526          }
1527  
1528          redirect($redirect);
1529      }
1530  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1