Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

mcp_queue.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 51.49 KiB


0001  <?php
0002  /**
0003  *
0004  * This file is part of the phpBB Forum Software package.
0005  *
0006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
0007  * @license GNU General Public License, version 2 (GPL-2.0)
0008  *
0009  * For full copyright and license information, please see
0010  * the docs/CREDITS.txt file.
0011  *
0012  */
0013   
0014  /**
0015  * @ignore
0016  */
0017  if (!defined('IN_PHPBB'))
0018  {
0019      exit;
0020  }
0021   
0022  /**
0023  * mcp_queue
0024  * Handling the moderation queue
0025  */
0026  class mcp_queue
0027  {
0028      var $p_master;
0029      var $u_action;
0030   
0031      public function mcp_queue(&$p_master)
0032      {
0033          $this->p_master = &$p_master;
0034      }
0035   
0036      public function main($id, $mode)
0037      {
0038          global $auth, $db, $user, $template, $request;
0039          global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container;
0040          global $phpbb_dispatcher;
0041   
0042          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
0043   
0044          $forum_id = $request->variable('f', 0);
0045          $start = $request->variable('start', 0);
0046   
0047          $this->page_title = 'MCP_QUEUE';
0048   
0049          switch ($action)
0050          {
0051              case 'approve':
0052              case 'restore':
0053                  include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
0054   
0055                  $post_id_list = $request->variable('post_id_list', array(0));
0056                  $topic_id_list = $request->variable('topic_id_list', array(0));
0057   
0058                  if (!empty($post_id_list))
0059                  {
0060                      self::approve_posts($action, $post_id_list, 'queue', $mode);
0061                  }
0062                  else if (!empty($topic_id_list))
0063                  {
0064                      self::approve_topics($action, $topic_id_list, 'queue', $mode);
0065                  }
0066                  else
0067                  {
0068                      trigger_error('NO_POST_SELECTED');
0069                  }
0070              break;
0071   
0072              case 'delete':
0073                  $post_id_list = $request->variable('post_id_list', array(0));
0074                  $topic_id_list = $request->variable('topic_id_list', array(0));
0075                  $delete_reason = $request->variable('delete_reason', '', true);
0076   
0077                  if (!empty($post_id_list))
0078                  {
0079                      if (!function_exists('mcp_delete_post'))
0080                      {
0081                          global $phpbb_root_path, $phpEx;
0082                          include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
0083                      }
0084                      mcp_delete_post($post_id_list, false, $delete_reason, $action);
0085                  }
0086                  else if (!empty($topic_id_list))
0087                  {
0088                      if (!function_exists('mcp_delete_topic'))
0089                      {
0090                          global $phpbb_root_path, $phpEx;
0091                          include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
0092                      }
0093                      mcp_delete_topic($topic_id_list, false, $delete_reason, $action);
0094                  }
0095                  else
0096                  {
0097                      trigger_error('NO_POST_SELECTED');
0098                  }
0099              break;
0100   
0101              case 'disapprove':
0102                  $post_id_list = $request->variable('post_id_list', array(0));
0103                  $topic_id_list = $request->variable('topic_id_list', array(0));
0104   
0105                  if (!empty($topic_id_list) && $mode == 'deleted_topics')
0106                  {
0107                      if (!function_exists('mcp_delete_topic'))
0108                      {
0109                          global $phpbb_root_path, $phpEx;
0110                          include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
0111                      }
0112                      mcp_delete_topic($topic_id_list, false, '', 'disapprove');
0113                      return;
0114                  }
0115   
0116                  if (!class_exists('messenger'))
0117                  {
0118                      include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
0119                  }
0120   
0121                  if (!empty($topic_id_list))
0122                  {
0123                      $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : array(ITEM_UNAPPROVED, ITEM_REAPPROVE);
0124                      $sql = 'SELECT post_id
0125                          FROM ' . POSTS_TABLE . '
0126                          WHERE ' . $db->sql_in_set('post_visibility', $post_visibility) . '
0127                              AND ' . $db->sql_in_set('topic_id', $topic_id_list);
0128                      $result = $db->sql_query($sql);
0129   
0130                      $post_id_list = array();
0131                      while ($row = $db->sql_fetchrow($result))
0132                      {
0133                          $post_id_list[] = (int) $row['post_id'];
0134                      }
0135                      $db->sql_freeresult($result);
0136                  }
0137   
0138                  if (!empty($post_id_list))
0139                  {
0140                      self::disapprove_posts($post_id_list, 'queue', $mode);
0141                  }
0142                  else
0143                  {
0144                      trigger_error('NO_POST_SELECTED');
0145                  }
0146              break;
0147          }
0148   
0149          switch ($mode)
0150          {
0151              case 'approve_details':
0152   
0153                  $this->tpl_name = 'mcp_post';
0154   
0155                  $user->add_lang(array('posting', 'viewtopic'));
0156   
0157                  $post_id = $request->variable('p', 0);
0158                  $topic_id = $request->variable('t', 0);
0159   
0160                  /* @var $phpbb_notifications \phpbb\notification\manager */
0161                  $phpbb_notifications = $phpbb_container->get('notification_manager');
0162   
0163                  if ($topic_id)
0164                  {
0165                      $topic_info = phpbb_get_topic_data(array($topic_id), 'm_approve');
0166                      if (isset($topic_info[$topic_id]['topic_first_post_id']))
0167                      {
0168                          $post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
0169   
0170                          $phpbb_notifications->mark_notifications('topic_in_queue', $topic_id, $user->data['user_id']);
0171                      }
0172                      else
0173                      {
0174                          $topic_id = 0;
0175                      }
0176                  }
0177   
0178                  $phpbb_notifications->mark_notifications('post_in_queue', $post_id, $user->data['user_id']);
0179   
0180                  $post_info = phpbb_get_post_data(array($post_id), 'm_approve', true);
0181   
0182                  if (!sizeof($post_info))
0183                  {
0184                      trigger_error('NO_POST_SELECTED');
0185                  }
0186   
0187                  $post_info = $post_info[$post_id];
0188   
0189                  if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
0190                  {
0191                      $template->assign_vars(array(
0192                          'S_TOPIC_REVIEW'    => true,
0193                          'S_BBCODE_ALLOWED'    => $post_info['enable_bbcode'],
0194                          'TOPIC_TITLE'        => $post_info['topic_title'],
0195                      ));
0196                  }
0197   
0198                  $attachments = $topic_tracking_info = array();
0199   
0200                  // Get topic tracking info
0201                  if ($config['load_db_lastread'])
0202                  {
0203                      $tmp_topic_data = array($post_info['topic_id'] => $post_info);
0204                      $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']));
0205                      unset($tmp_topic_data);
0206                  }
0207                  else
0208                  {
0209                      $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
0210                  }
0211   
0212                  $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
0213   
0214                  // Process message, leave it uncensored
0215                  $parse_flags = ($post_info['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
0216                  $message = generate_text_for_display($post_info['post_text'], $post_info['bbcode_uid'], $post_info['bbcode_bitfield'], $parse_flags, false);
0217   
0218                  if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
0219                  {
0220                      $sql = 'SELECT *
0221                          FROM ' . ATTACHMENTS_TABLE . '
0222                          WHERE post_msg_id = ' . $post_id . '
0223                              AND in_message = 0
0224                          ORDER BY filetime DESC, post_msg_id ASC';
0225                      $result = $db->sql_query($sql);
0226   
0227                      while ($row = $db->sql_fetchrow($result))
0228                      {
0229                          $attachments[] = $row;
0230                      }
0231                      $db->sql_freeresult($result);
0232   
0233                      if (sizeof($attachments))
0234                      {
0235                          $update_count = array();
0236                          parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
0237                      }
0238   
0239                      // Display not already displayed Attachments for this post, we already parsed them. ;)
0240                      if (!empty($attachments))
0241                      {
0242                          $template->assign_var('S_HAS_ATTACHMENTS', true);
0243   
0244                          foreach ($attachments as $attachment)
0245                          {
0246                              $template->assign_block_vars('attachment', array(
0247                                  'DISPLAY_ATTACHMENT'    => $attachment,
0248                              ));
0249                          }
0250                      }
0251                  }
0252   
0253                  // Deleting information
0254                  if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user'])
0255                  {
0256                      // User having deleted the post also being the post author?
0257                      if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id'])
0258                      {
0259                          $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']);
0260                      }
0261                      else
0262                      {
0263                          $sql = 'SELECT u.user_id, u.username, u.user_colour
0264                              FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
0265                              WHERE p.post_id =  ' . $post_info['post_id'] . '
0266                                  AND p.post_delete_user = u.user_id';
0267                          $result = $db->sql_query($sql);
0268                          $post_delete_userinfo = $db->sql_fetchrow($result);
0269                          $db->sql_freeresult($result);
0270                          $display_username = get_username_string('full', $post_info['post_delete_user'], $post_delete_userinfo['username'], $post_delete_userinfo['user_colour']);
0271                      }
0272   
0273                      $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true));
0274                  }
0275                  else
0276                  {
0277                      $l_deleted_by = '';
0278                  }
0279   
0280                  $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']);
0281                  $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']);
0282   
0283                  $template->assign_vars(array(
0284                      'S_MCP_QUEUE'            => true,
0285                      'U_APPROVE_ACTION'        => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f=$forum_id"),
0286                      'S_CAN_DELETE_POST'        => $auth->acl_get('m_delete', $post_info['forum_id']),
0287                      'S_CAN_VIEWIP'            => $auth->acl_get('m_info', $post_info['forum_id']),
0288                      'S_POST_REPORTED'        => $post_info['post_reported'],
0289                      'S_POST_UNAPPROVED'        => $post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE,
0290                      'S_POST_LOCKED'            => $post_info['post_edit_locked'],
0291                      'S_USER_NOTES'            => true,
0292                      'S_POST_DELETED'        => ($post_info['post_visibility'] == ITEM_DELETED),
0293                      'DELETED_MESSAGE'        => $l_deleted_by,
0294                      'DELETE_REASON'            => $post_info['post_delete_reason'],
0295   
0296                      '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']}") : '',
0297                      '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),
0298                      '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),
0299                      'U_MCP_USER_NOTES'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
0300                      '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']) : '',
0301                      'U_VIEW_POST'            => $post_url,
0302                      'U_VIEW_TOPIC'            => $topic_url,
0303   
0304                      'MINI_POST_IMG'            => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
0305   
0306                      '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>'),
0307                      'RETURN_POST'            => sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'),
0308                      'RETURN_TOPIC_SIMPLE'    => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'),
0309                      'REPORTED_IMG'            => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
0310                      'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
0311                      'EDIT_IMG'                => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
0312   
0313                      'POST_AUTHOR_FULL'        => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
0314                      'POST_AUTHOR_COLOUR'    => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
0315                      'POST_AUTHOR'            => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
0316                      'U_POST_AUTHOR'            => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
0317   
0318                      'POST_PREVIEW'            => $message,
0319                      'POST_SUBJECT'            => $post_info['post_subject'],
0320                      'POST_DATE'                => $user->format_date($post_info['post_time']),
0321                      'POST_IP'                => $post_info['poster_ip'],
0322                      'POST_IPADDR'            => ($auth->acl_get('m_info', $post_info['forum_id']) && $request->variable('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
0323                      'POST_ID'                => $post_info['post_id'],
0324                      'S_FIRST_POST'            => ($post_info['topic_first_post_id'] == $post_id),
0325   
0326                      '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' : '',
0327                  ));
0328   
0329              break;
0330   
0331              case 'unapproved_topics':
0332              case 'unapproved_posts':
0333              case 'deleted_topics':
0334              case 'deleted_posts':
0335                  $m_perm = 'm_approve';
0336                  $is_topics = ($mode == 'unapproved_topics' || $mode == 'deleted_topics') ? true : false;
0337                  $is_restore = ($mode == 'deleted_posts' || $mode == 'deleted_topics') ? true : false;
0338                  $visibility_const = (!$is_restore) ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED;
0339   
0340                  $user->add_lang(array('viewtopic', 'viewforum'));
0341   
0342                  $topic_id = $request->variable('t', 0);
0343                  $forum_info = array();
0344   
0345                  /* @var $pagination \phpbb\pagination */
0346                  $pagination = $phpbb_container->get('pagination');
0347   
0348                  if ($topic_id)
0349                  {
0350                      $topic_info = phpbb_get_topic_data(array($topic_id));
0351   
0352                      if (!sizeof($topic_info))
0353                      {
0354                          trigger_error('TOPIC_NOT_EXIST');
0355                      }
0356   
0357                      $topic_info = $topic_info[$topic_id];
0358                      $forum_id = $topic_info['forum_id'];
0359                  }
0360   
0361                  $forum_list_approve = get_forum_list($m_perm, false, true);
0362                  $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
0363   
0364                  // Remove forums we cannot read
0365                  foreach ($forum_list_approve as $k => $forum_data)
0366                  {
0367                      if (!isset($forum_list_read[$forum_data['forum_id']]))
0368                      {
0369                          unset($forum_list_approve[$k]);
0370                      }
0371                  }
0372                  unset($forum_list_read);
0373   
0374                  if (!$forum_id)
0375                  {
0376                      $forum_list = array();
0377                      foreach ($forum_list_approve as $row)
0378                      {
0379                          $forum_list[] = $row['forum_id'];
0380                      }
0381   
0382                      if (!sizeof($forum_list))
0383                      {
0384                          trigger_error('NOT_MODERATOR');
0385                      }
0386   
0387                      $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics
0388                          FROM ' . FORUMS_TABLE . '
0389                          WHERE ' . $db->sql_in_set('forum_id', $forum_list);
0390                      $result = $db->sql_query($sql);
0391                      $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics');
0392                      $db->sql_freeresult($result);
0393                  }
0394                  else
0395                  {
0396                      $forum_info = phpbb_get_forum_data(array($forum_id), $m_perm);
0397   
0398                      if (!sizeof($forum_info))
0399                      {
0400                          trigger_error('NOT_MODERATOR');
0401                      }
0402   
0403                      $forum_list = $forum_id;
0404                  }
0405   
0406                  $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
0407                  foreach ($forum_list_approve as $row)
0408                  {
0409                      $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>';
0410                  }
0411   
0412                  $sort_days = $total = 0;
0413                  $sort_key = $sort_dir = '';
0414                  $sort_by_sql = $sort_order_sql = array();
0415                  phpbb_mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
0416   
0417                  $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
0418   
0419                  $forum_names = array();
0420   
0421                  if (!$is_topics)
0422                  {
0423                      $sql = 'SELECT p.post_id
0424                          FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . '
0425                          WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . '
0426                              AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) . '
0427                              ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
0428                              ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
0429                              AND t.topic_id = p.topic_id
0430                              AND (t.topic_visibility <> p.post_visibility
0431                                  OR t.topic_delete_user = 0)
0432                              $limit_time_sql
0433                          ORDER BY $sort_order_sql";
0434   
0435                      /**
0436                      * Alter sql query to get posts in queue to be accepted
0437                      *
0438                      * @event core.mcp_queue_get_posts_query_before
0439                      * @var    string    sql                        Associative array with the query to be executed
0440                      * @var    array    forum_list                List of forums that contain the posts
0441                      * @var    int        visibility_const        Integer with one of the possible ITEM_* constant values
0442                      * @var    int        topic_id                If topic_id not equal to 0, the topic id to filter the posts to display
0443                      * @var    string    limit_time_sql            String with the SQL code to limit the time interval of the post (Note: May be empty string)
0444                      * @var    string    sort_order_sql            String with the ORDER BY SQL code used in this query
0445                      * @since 3.1.0-RC3
0446                      */
0447                      $vars = array(
0448                          'sql',
0449                          'forum_list',
0450                          'visibility_const',
0451                          'topic_id',
0452                          'limit_time_sql',
0453                          'sort_order_sql',
0454                      );
0455                      extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_query_before', compact($vars)));
0456   
0457                      $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
0458   
0459                      $i = 0;
0460                      $post_ids = array();
0461                      while ($row = $db->sql_fetchrow($result))
0462                      {
0463                          $post_ids[] = $row['post_id'];
0464                          $row_num[$row['post_id']] = $i++;
0465                      }
0466                      $db->sql_freeresult($result);
0467   
0468                      if (sizeof($post_ids))
0469                      {
0470                          $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
0471                              FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
0472                              WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
0473                                  AND t.topic_id = p.topic_id
0474                                  AND u.user_id = p.poster_id
0475                              ORDER BY ' . $sort_order_sql;
0476                          $result = $db->sql_query($sql);
0477   
0478                          $post_data = $rowset = array();
0479                          while ($row = $db->sql_fetchrow($result))
0480                          {
0481                              $forum_names[] = $row['forum_id'];
0482                              $post_data[$row['post_id']] = $row;
0483                          }
0484                          $db->sql_freeresult($result);
0485   
0486                          foreach ($post_ids as $post_id)
0487                          {
0488                              $rowset[] = $post_data[$post_id];
0489                          }
0490                          unset($post_data, $post_ids);
0491                      }
0492                      else
0493                      {
0494                          $rowset = array();
0495                      }
0496                  }
0497                  else
0498                  {
0499                      $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
0500                          FROM ' . TOPICS_TABLE . ' t
0501                          WHERE ' . $db->sql_in_set('forum_id', $forum_list) . '
0502                              AND  ' . $db->sql_in_set('topic_visibility', $visibility_const) . "
0503                              AND topic_delete_user <> 0
0504                              $limit_time_sql
0505                          ORDER BY $sort_order_sql";
0506   
0507                      /**
0508                      * Alter sql query to get information on all topics in the list of forums provided.
0509                      *
0510                      * @event core.mcp_queue_get_posts_for_topics_query_before
0511                      * @var    string    sql                        String with the query to be executed
0512                      * @var    array    forum_list                List of forums that contain the posts
0513                      * @var    int        visibility_const        Integer with one of the possible ITEM_* constant values
0514                      * @var    int        topic_id                topic_id in the page request
0515                      * @var    string    limit_time_sql            String with the SQL code to limit the time interval of the post (Note: May be empty string)
0516                      * @var    string    sort_order_sql            String with the ORDER BY SQL code used in this query
0517                      * @since 3.1.0-RC3
0518                      */
0519                      $vars = array(
0520                          'sql',
0521                          'forum_list',
0522                          'visibility_const',
0523                          'topic_id',
0524                          'limit_time_sql',
0525                          'sort_order_sql',
0526                      );
0527                      extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_for_topics_query_before', compact($vars)));
0528   
0529                      $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
0530   
0531                      $rowset = array();
0532                      while ($row = $db->sql_fetchrow($result))
0533                      {
0534                          $forum_names[] = $row['forum_id'];
0535                          $rowset[] = $row;
0536                      }
0537                      $db->sql_freeresult($result);
0538                  }
0539   
0540                  if (sizeof($forum_names))
0541                  {
0542                      // Select the names for the forum_ids
0543                      $sql = 'SELECT forum_id, forum_name
0544                          FROM ' . FORUMS_TABLE . '
0545                          WHERE ' . $db->sql_in_set('forum_id', $forum_names);
0546                      $result = $db->sql_query($sql, 3600);
0547   
0548                      $forum_names = array();
0549                      while ($row = $db->sql_fetchrow($result))
0550                      {
0551                          $forum_names[$row['forum_id']] = $row['forum_name'];
0552                      }
0553                      $db->sql_freeresult($result);
0554                  }
0555   
0556                  foreach ($rowset as $row)
0557                  {
0558                      if (empty($row['post_username']))
0559                      {
0560                          $row['post_username'] = $row['username'] ?: $user->lang['GUEST'];
0561                      }
0562   
0563                      $template->assign_block_vars('postrow', array(
0564                          'U_TOPIC'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
0565                          'U_VIEWFORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
0566                          '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'] : ''),
0567                          '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']}" : '')),
0568   
0569                          'POST_AUTHOR_FULL'        => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
0570                          'POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
0571                          'POST_AUTHOR'            => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
0572                          'U_POST_AUTHOR'            => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
0573   
0574                          'POST_ID'        => $row['post_id'],
0575                          'TOPIC_ID'        => $row['topic_id'],
0576                          'FORUM_NAME'    => $forum_names[$row['forum_id']],
0577                          'POST_SUBJECT'    => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
0578                          'TOPIC_TITLE'    => $row['topic_title'],
0579                          'POST_TIME'        => $user->format_date($row['post_time']),
0580                          'S_HAS_ATTACHMENTS'    => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment'],
0581                      ));
0582                  }
0583                  unset($rowset, $forum_names);
0584   
0585                  $base_url = $this->u_action . "&amp;f=$forum_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir";
0586                  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
0587   
0588                  // Now display the page
0589                  $template->assign_vars(array(
0590                      'L_DISPLAY_ITEMS'        => (!$is_topics) ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
0591                      'L_EXPLAIN'                => $user->lang['MCP_QUEUE_' . strtoupper($mode) . '_EXPLAIN'],
0592                      'L_TITLE'                => $user->lang['MCP_QUEUE_' . strtoupper($mode)],
0593                      'L_ONLY_TOPIC'            => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
0594   
0595                      'S_FORUM_OPTIONS'        => $forum_options,
0596                      'S_MCP_ACTION'            => build_url(array('t', 'f', 'sd', 'st', 'sk')),
0597                      'S_TOPICS'                => $is_topics,
0598                      'S_RESTORE'                => $is_restore,
0599   
0600                      'TOPIC_ID'                => $topic_id,
0601                      'TOTAL'                    => $user->lang(((!$is_topics) ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total),
0602                  ));
0603   
0604                  $this->tpl_name = 'mcp_queue';
0605              break;
0606          }
0607      }
0608   
0609      /**
0610      * Approve/Restore posts
0611      *
0612      * @param $action        string    Action we perform on the posts ('approve' or 'restore')
0613      * @param $post_id_list    array    IDs of the posts to approve/restore
0614      * @param $id            mixed    Category of the current active module
0615      * @param $mode            string    Active module
0616      * @return null
0617      */
0618      static public function approve_posts($action, $post_id_list, $id, $mode)
0619      {
0620          global $template, $user, $request, $phpbb_container, $phpbb_dispatcher;
0621          global $phpEx, $phpbb_root_path, $phpbb_log;
0622   
0623          if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
0624          {
0625              send_status_line(403, 'Forbidden');
0626              trigger_error('NOT_AUTHORISED');
0627          }
0628   
0629          $redirect = $request->variable('redirect', build_url(array('quickmod')));
0630          $redirect = reapply_sid($redirect);
0631          $post_url = '';
0632          $approve_log = array();
0633          $num_topics = 0;
0634   
0635          $s_hidden_fields = build_hidden_fields(array(
0636              'i'                => $id,
0637              'mode'            => $mode,
0638              'post_id_list'    => $post_id_list,
0639              'action'        => $action,
0640              'redirect'        => $redirect,
0641          ));
0642   
0643          $post_info = phpbb_get_post_data($post_id_list, 'm_approve');
0644   
0645          if (confirm_box(true))
0646          {
0647              $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster']));
0648   
0649              $topic_info = array();
0650   
0651              // Group the posts by topic_id
0652              foreach ($post_info as $post_id => $post_data)
0653              {
0654                  if ($post_data['post_visibility'] == ITEM_APPROVED)
0655                  {
0656                      continue;
0657                  }
0658                  $topic_id = (int) $post_data['topic_id'];
0659   
0660                  $topic_info[$topic_id]['posts'][] = (int) $post_id;
0661                  $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id'];
0662   
0663                  // Refresh the first post, if the time or id is older then the current one
0664                  if ($post_id <= $post_data['topic_first_post_id'] || $post_data['post_time'] <= $post_data['topic_time'])
0665                  {
0666                      $topic_info[$topic_id]['first_post'] = true;
0667                  }
0668   
0669                  // Refresh the last post, if the time or id is newer then the current one
0670                  if ($post_id >= $post_data['topic_last_post_id'] || $post_data['post_time'] >= $post_data['topic_last_post_time'])
0671                  {
0672                      $topic_info[$topic_id]['last_post'] = true;
0673                  }
0674   
0675                  $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'];
0676   
0677                  $approve_log[] = array(
0678                      'forum_id'        => $post_data['forum_id'],
0679                      'topic_id'        => $post_data['topic_id'],
0680                      'post_id'        => $post_id,
0681                      'post_subject'    => $post_data['post_subject'],
0682                  );
0683              }
0684   
0685              /* @var $phpbb_content_visibility \phpbb\content_visibility */
0686              $phpbb_content_visibility = $phpbb_container->get('content.visibility');
0687              foreach ($topic_info as $topic_id => $topic_data)
0688              {
0689                  $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']));
0690              }
0691   
0692              foreach ($approve_log as $log_data)
0693              {
0694                  $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_POST_' . strtoupper($action) . 'D', false, array(
0695                      'forum_id' => $log_data['forum_id'],
0696                      'topic_id' => $log_data['topic_id'],
0697                      'post_id'  => $log_data['post_id'],
0698                      $log_data['post_subject']
0699                  ));
0700              }
0701   
0702              // Only send out the mails, when the posts are being approved
0703              if ($action == 'approve')
0704              {
0705                  /* @var $phpbb_notifications \phpbb\notification\manager */
0706                  $phpbb_notifications = $phpbb_container->get('notification_manager');
0707   
0708                  // Handle notifications
0709                  foreach ($post_info as $post_id => $post_data)
0710                  {
0711                      // A single topic approval may also happen here, so handle deleting the respective notification.
0712                      if (!$post_data['topic_posts_approved'])
0713                      {
0714                          $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']);
0715   
0716                          if ($post_data['post_visibility'] == ITEM_UNAPPROVED)
0717                          {
0718                              $phpbb_notifications->add_notifications(array('notification.type.topic'), $post_data);
0719                          }
0720                          if ($post_data['post_visibility'] != ITEM_APPROVED)
0721                          {
0722                              $num_topics++;
0723                          }
0724                      }
0725                      else
0726                      {
0727                          // Only add notifications, if we are not reapproving post
0728                          // When the topic was already approved, but was edited and
0729                          // now needs re-approval, we don't want to notify the users
0730                          // again.
0731                          if ($post_data['post_visibility'] == ITEM_UNAPPROVED)
0732                          {
0733                              $phpbb_notifications->add_notifications(array(
0734                                  'notification.type.bookmark',
0735                                  'notification.type.post',
0736                              ), $post_data);
0737                          }
0738                      }
0739                      $phpbb_notifications->add_notifications(array('notification.type.quote'), $post_data);
0740                      $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id);
0741   
0742                      $phpbb_notifications->mark_notifications(array(
0743                          'notification.type.quote',
0744                          'notification.type.bookmark',
0745                          'notification.type.post',
0746                      ), $post_data['post_id'], $user->data['user_id']);
0747   
0748                      // Notify Poster?
0749                      if ($notify_poster)
0750                      {
0751                          if ($post_data['poster_id'] == ANONYMOUS)
0752                          {
0753                              continue;
0754                          }
0755   
0756                          if (!$post_data['topic_posts_approved'])
0757                          {
0758                              $phpbb_notifications->add_notifications('notification.type.approve_topic', $post_data);
0759                          }
0760                          else
0761                          {
0762                              $phpbb_notifications->add_notifications('notification.type.approve_post', $post_data);
0763                          }
0764                      }
0765                  }
0766              }
0767   
0768              if ($num_topics >= 1)
0769              {
0770                  $success_msg = ($num_topics == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS';
0771              }
0772              else
0773              {
0774                  $success_msg = (sizeof($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS';
0775              }
0776   
0777              /**
0778               * Perform additional actions during post(s) approval
0779               *
0780               * @event core.approve_posts_after
0781               * @var    string    action                Variable containing the action we perform on the posts ('approve' or 'restore')
0782               * @var    array    post_info            Array containing info for all posts being approved
0783               * @var    array    topic_info            Array containing info for all parent topics of the posts
0784               * @var    int        num_topics            Variable containing number of topics
0785               * @var bool    notify_poster        Variable telling if the post should be notified or not
0786               * @var    string    success_msg            Variable containing the language key for the success message
0787               * @var string    redirect            Variable containing the redirect url
0788               * @since 3.1.4-RC1
0789               */
0790              $vars = array(
0791                  'action',
0792                  'post_info',
0793                  'topic_info',
0794                  'num_topics',
0795                  'notify_poster',
0796                  'success_msg',
0797                  'redirect',
0798              );
0799              extract($phpbb_dispatcher->trigger_event('core.approve_posts_after', compact($vars)));
0800   
0801              meta_refresh(3, $redirect);
0802              $message = $user->lang[$success_msg];
0803   
0804              if ($request->is_ajax())
0805              {
0806                  $json_response = new \phpbb\json_response;
0807                  $json_response->send(array(
0808                      'MESSAGE_TITLE'        => $user->lang['INFORMATION'],
0809                      'MESSAGE_TEXT'        => $message,
0810                      'REFRESH_DATA'        => null,
0811                      'visible'            => true,
0812                  ));
0813              }
0814              $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
0815   
0816              // If approving one post, also give links back to post...
0817              if (sizeof($post_info) == 1 && $post_url)
0818              {
0819                  $message .= '<br /><br />' . $user->lang('RETURN_POST', '<a href="' . $post_url . '">', '</a>');
0820              }
0821              trigger_error($message);
0822          }
0823          else
0824          {
0825              $show_notify = false;
0826   
0827              if ($action == 'approve')
0828              {
0829                  foreach ($post_info as $post_data)
0830                  {
0831                      if (!$post_data['topic_posts_approved'])
0832                      {
0833                          $num_topics++;
0834                      }
0835   
0836                      if (!$show_notify && $post_data['poster_id'] != ANONYMOUS)
0837                      {
0838                          $show_notify = true;
0839                      }
0840                  }
0841              }
0842   
0843              $template->assign_vars(array(
0844                  'S_NOTIFY_POSTER'            => $show_notify,
0845                  'S_' . strtoupper($action)    => true,
0846              ));
0847   
0848              // Create the confirm box message
0849              $action_msg = strtoupper($action);
0850              $num_posts = sizeof($post_id_list) - $num_topics;
0851              if ($num_topics > 0 && $num_posts <= 0)
0852              {
0853                  $action_msg .= '_TOPIC' . (($num_topics == 1) ? '' : 'S');
0854              }
0855              else
0856              {
0857                  $action_msg .= '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S');
0858              }
0859              confirm_box(false, $action_msg, $s_hidden_fields, 'mcp_approve.html');
0860          }
0861   
0862          redirect($redirect);
0863      }
0864   
0865      /**
0866      * Approve/Restore topics
0867      *
0868      * @param $action        string    Action we perform on the posts ('approve' or 'restore')
0869      * @param $topic_id_list    array    IDs of the topics to approve/restore
0870      * @param $id            mixed    Category of the current active module
0871      * @param $mode            string    Active module
0872      * @return null
0873      */
0874      static public function approve_topics($action, $topic_id_list, $id, $mode)
0875      {
0876          global $db, $template, $user, $phpbb_log;
0877          global $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_dispatcher;
0878   
0879          if (!phpbb_check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve')))
0880          {
0881              send_status_line(403, 'Forbidden');
0882              trigger_error('NOT_AUTHORISED');
0883          }
0884   
0885          $redirect = $request->variable('redirect', build_url(array('quickmod')));
0886          $redirect = reapply_sid($redirect);
0887          $success_msg = $topic_url = '';
0888          $approve_log = array();
0889   
0890          $s_hidden_fields = build_hidden_fields(array(
0891              'i'                => $id,
0892              'mode'            => $mode,
0893              'topic_id_list'    => $topic_id_list,
0894              'action'        => $action,
0895              'redirect'        => $redirect,
0896          ));
0897   
0898          $topic_info = phpbb_get_topic_data($topic_id_list, 'm_approve');
0899   
0900          if (confirm_box(true))
0901          {
0902              $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false;
0903   
0904              /* @var $phpbb_content_visibility \phpbb\content_visibility */
0905              $phpbb_content_visibility = $phpbb_container->get('content.visibility');
0906              $first_post_ids = array();
0907   
0908              foreach ($topic_info as $topic_id => $topic_data)
0909              {
0910                  $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '');
0911                  $first_post_ids[$topic_id] = (int) $topic_data['topic_first_post_id'];
0912   
0913                  $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&amp;t={$topic_id}");
0914   
0915                  $approve_log[] = array(
0916                      'forum_id'        => $topic_data['forum_id'],
0917                      'topic_id'        => $topic_data['topic_id'],
0918                      'topic_title'    => $topic_data['topic_title'],
0919                  );
0920              }
0921   
0922              if (sizeof($topic_info) >= 1)
0923              {
0924                  $success_msg = (sizeof($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS';
0925              }
0926   
0927              foreach ($approve_log as $log_data)
0928              {
0929                  $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_TOPIC_' . strtoupper($action) . 'D', false, array(
0930                      'forum_id' => $log_data['forum_id'],
0931                      'topic_id' => $log_data['topic_id'],
0932                      $log_data['topic_title']
0933                  ));
0934              }
0935   
0936              // Only send out the mails, when the posts are being approved
0937              if ($action == 'approve')
0938              {
0939                  // Grab the first post text as it's needed for the quote notification.
0940                  $sql = 'SELECT topic_id, post_text
0941                      FROM ' . POSTS_TABLE . '
0942                      WHERE ' . $db->sql_in_set('post_id', $first_post_ids);
0943                  $result = $db->sql_query($sql);
0944   
0945                  while ($row = $db->sql_fetchrow($result))
0946                  {
0947                      $topic_info[$row['topic_id']]['post_text'] = $row['post_text'];
0948                  }
0949                  $db->sql_freeresult($result);
0950   
0951                  // Handle notifications
0952                  /* @var $phpbb_notifications \phpbb\notification\manager */
0953                  $phpbb_notifications = $phpbb_container->get('notification_manager');
0954   
0955                  foreach ($topic_info as $topic_id => $topic_data)
0956                  {
0957                      $topic_data = array_merge($topic_data, array(
0958                          'post_id'        => $topic_data['topic_first_post_id'],
0959                          'post_subject'    => $topic_data['topic_title'],
0960                          'post_time'        => $topic_data['topic_time'],
0961                          'poster_id'        => $topic_data['topic_poster'],
0962                          'post_username'    => $topic_data['topic_first_poster_name'],
0963                      ));
0964   
0965                      $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $topic_id);
0966   
0967                      // Only add notifications, if we are not reapproving post
0968                      // When the topic was already approved, but was edited and
0969                      // now needs re-approval, we don't want to notify the users
0970                      // again.
0971                      if ($topic_data['topic_visibility'] == ITEM_UNAPPROVED)
0972                      {
0973                          $phpbb_notifications->add_notifications(array(
0974                              'notification.type.quote',
0975                              'notification.type.topic',
0976                          ), $topic_data);
0977                      }
0978   
0979                      $phpbb_notifications->mark_notifications('quote', $topic_data['post_id'], $user->data['user_id']);
0980                      $phpbb_notifications->mark_notifications('topic', $topic_id, $user->data['user_id']);
0981   
0982                      if ($notify_poster)
0983                      {
0984                          $phpbb_notifications->add_notifications('notification.type.approve_topic', $topic_data);
0985                      }
0986                  }
0987              }
0988   
0989              /**
0990               * Perform additional actions during topics(s) approval
0991               *
0992               * @event core.approve_topics_after
0993               * @var    string    action                Variable containing the action we perform on the posts ('approve' or 'restore')
0994               * @var    mixed    topic_info            Array containing info for all topics being approved
0995               * @var    array    first_post_ids        Array containing ids of all first posts
0996               * @var bool    notify_poster        Variable telling if the poster should be notified or not
0997               * @var    string    success_msg            Variable containing the language key for the success message
0998               * @var string    redirect            Variable containing the redirect url
0999               * @since 3.1.4-RC1
1000               */
1001              $vars = array(
1002                  'action',
1003                  'topic_info',
1004                  'first_post_ids',
1005                  'notify_poster',
1006                  'success_msg',
1007                  'redirect',
1008              );
1009              extract($phpbb_dispatcher->trigger_event('core.approve_topics_after', compact($vars)));
1010   
1011              meta_refresh(3, $redirect);
1012              $message = $user->lang[$success_msg];
1013   
1014              if ($request->is_ajax())
1015              {
1016                  $json_response = new \phpbb\json_response;
1017                  $json_response->send(array(
1018                      'MESSAGE_TITLE'        => $user->lang['INFORMATION'],
1019                      'MESSAGE_TEXT'        => $message,
1020                      'REFRESH_DATA'        => null,
1021                      'visible'            => true,
1022                  ));
1023              }
1024              $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
1025   
1026              // If approving one topic, also give links back to topic...
1027              if (sizeof($topic_info) == 1 && $topic_url)
1028              {
1029                  $message .= '<br /><br />' . $user->lang('RETURN_TOPIC', '<a href="' . $topic_url . '">', '</a>');
1030              }
1031              trigger_error($message);
1032          }
1033          else
1034          {
1035              $show_notify = false;
1036   
1037              if ($action == 'approve')
1038              {
1039                  foreach ($topic_info as $topic_data)
1040                  {
1041                      if ($topic_data['topic_poster'] == ANONYMOUS)
1042                      {
1043                          continue;
1044                      }
1045                      else
1046                      {
1047                          $show_notify = true;
1048                          break;
1049                      }
1050                  }
1051              }
1052   
1053              $template->assign_vars(array(
1054                  'S_NOTIFY_POSTER'            => $show_notify,
1055                  'S_' . strtoupper($action)    => true,
1056              ));
1057   
1058              confirm_box(false, strtoupper($action) . '_TOPIC' . ((sizeof($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
1059          }
1060   
1061          redirect($redirect);
1062      }
1063   
1064      /**
1065      * Disapprove Post
1066      *
1067      * @param $post_id_list    array    IDs of the posts to disapprove/delete
1068      * @param $id            mixed    Category of the current active module
1069      * @param $mode            string    Active module
1070      * @return null
1071      */
1072      static public function disapprove_posts($post_id_list, $id, $mode)
1073      {
1074          global $db, $template, $user, $phpbb_container, $phpbb_dispatcher;
1075          global $phpEx, $phpbb_root_path, $request, $phpbb_log;
1076   
1077          if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
1078          {
1079              send_status_line(403, 'Forbidden');
1080              trigger_error('NOT_AUTHORISED');
1081          }
1082   
1083          $redirect = $request->variable('redirect', build_url(array('t', 'mode', 'quickmod')) . "&amp;mode=$mode");
1084          $redirect = reapply_sid($redirect);
1085          $reason = $request->variable('reason', '', true);
1086          $reason_id = $request->variable('reason_id', 0);
1087          $additional_msg = '';
1088   
1089          $s_hidden_fields = build_hidden_fields(array(
1090              'i'                => $id,
1091              'mode'            => $mode,
1092              'post_id_list'    => $post_id_list,
1093              'action'        => 'disapprove',
1094              'redirect'        => $redirect,
1095          ));
1096   
1097          $notify_poster = $request->is_set('notify_poster');
1098          $disapprove_reason = '';
1099   
1100          if ($reason_id)
1101          {
1102              $sql = 'SELECT reason_title, reason_description
1103                  FROM ' . REPORTS_REASONS_TABLE . "
1104                  WHERE reason_id = $reason_id";
1105              $result = $db->sql_query($sql);
1106              $row = $db->sql_fetchrow($result);
1107              $db->sql_freeresult($result);
1108   
1109              if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
1110              {
1111                  $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
1112   
1113                  $request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
1114                  $request->overwrite('confirm_key', null, \phpbb\request\request_interface::POST);
1115                  $request->overwrite('confirm_key', null, \phpbb\request\request_interface::REQUEST);
1116              }
1117              else
1118              {
1119                  // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
1120                  $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']) : '';
1121                  $disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
1122   
1123                  if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
1124                  {
1125                      $disapprove_reason_lang = strtoupper($row['reason_title']);
1126                  }
1127              }
1128          }
1129   
1130          $post_info = phpbb_get_post_data($post_id_list, 'm_approve');
1131   
1132          $is_disapproving = false;
1133          foreach ($post_info as $post_id => $post_data)
1134          {
1135              if ($post_data['post_visibility'] == ITEM_DELETED)
1136              {
1137                  continue;
1138              }
1139   
1140              $is_disapproving = true;
1141          }
1142   
1143          if (confirm_box(true))
1144          {
1145              $disapprove_log_topics = $disapprove_log_posts = array();
1146              $topic_posts_unapproved = $post_disapprove_list = $topic_information = array();
1147   
1148              // Build a list of posts to be disapproved and get the related topics real replies count
1149              foreach ($post_info as $post_id => $post_data)
1150              {
1151                  if ($mode === 'unapproved_topics' && $post_data['post_visibility'] == ITEM_APPROVED)
1152                  {
1153                      continue;
1154                  }
1155   
1156                  $post_disapprove_list[$post_id] = $post_data['topic_id'];
1157                  if (!isset($topic_posts_unapproved[$post_data['topic_id']]))
1158                  {
1159                      $topic_information[$post_data['topic_id']] = $post_data;
1160                      $topic_posts_unapproved[$post_data['topic_id']] = 0;
1161                  }
1162                  $topic_posts_unapproved[$post_data['topic_id']]++;
1163              }
1164   
1165              // Do not try to disapprove if no posts are selected
1166              if (empty($post_disapprove_list))
1167              {
1168                  trigger_error('NO_POST_SELECTED');
1169              }
1170   
1171              // Now we build the log array
1172              foreach ($post_disapprove_list as $post_id => $topic_id)
1173              {
1174                  // If the count of disapproved posts for the topic is equal
1175                  // to the number of unapproved posts in the topic, and there are no different
1176                  // posts, we disapprove the hole topic
1177                  if ($topic_information[$topic_id]['topic_posts_approved'] == 0 &&
1178                      $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 &&
1179                      $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id])
1180                  {
1181                      // Don't write the log more than once for every topic
1182                      if (!isset($disapprove_log_topics[$topic_id]))
1183                      {
1184                          // Build disapproved topics log
1185                          $disapprove_log_topics[$topic_id] = array(
1186                              'type'            => 'topic',
1187                              'post_subject'    => $post_info[$post_id]['topic_title'],
1188                              'forum_id'        => $post_info[$post_id]['forum_id'],
1189                              'topic_id'        => 0, // useless to log a topic id, as it will be deleted
1190                              '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'],
1191                          );
1192                      }
1193                  }
1194                  else
1195                  {
1196                      // Build disapproved posts log
1197                      $disapprove_log_posts[] = array(
1198                          'type'            => 'post',
1199                          'post_subject'    => $post_info[$post_id]['post_subject'],
1200                          'forum_id'        => $post_info[$post_id]['forum_id'],
1201                          'topic_id'        => $post_info[$post_id]['topic_id'],
1202                          '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'],
1203                      );
1204   
1205                  }
1206              }
1207   
1208              // Get disapproved posts/topics counts separately
1209              $num_disapproved_topics = sizeof($disapprove_log_topics);
1210              $num_disapproved_posts = sizeof($disapprove_log_posts);
1211   
1212              // Build the whole log
1213              $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
1214   
1215              // Unset unneeded arrays
1216              unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
1217   
1218              // Let's do the job - delete disapproved posts
1219              if (sizeof($post_disapprove_list))
1220              {
1221                  if (!function_exists('delete_posts'))
1222                  {
1223                      include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
1224                  }
1225   
1226                  // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
1227                  // Note: function delete_posts triggers related forums/topics sync,
1228                  // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
1229                  delete_posts('post_id', array_keys($post_disapprove_list));
1230   
1231                  foreach ($disapprove_log as $log_data)
1232                  {
1233                      if ($is_disapproving)
1234                      {
1235                          $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED';
1236                          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, $l_log_message, false, array(
1237                              'forum_id' => $log_data['forum_id'],
1238                              'topic_id' => $log_data['topic_id'],
1239                              $log_data['post_subject'],
1240                              $disapprove_reason,
1241                              $log_data['post_username']
1242                          ));
1243                      }
1244                      else
1245                      {
1246                          $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST';
1247                          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, $l_log_message, false, array(
1248                              'forum_id' => $log_data['forum_id'],
1249                              'topic_id' => $log_data['topic_id'],
1250                              $log_data['post_subject'],
1251                              $log_data['post_username']
1252                          ));
1253                      }
1254                  }
1255              }
1256   
1257              /* @var $phpbb_notifications \phpbb\notification\manager */
1258              $phpbb_notifications = $phpbb_container->get('notification_manager');
1259   
1260              $lang_reasons = array();
1261   
1262              foreach ($post_info as $post_id => $post_data)
1263              {
1264                  $disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 &&
1265                      $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 &&
1266                      $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id];
1267   
1268                  $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id);
1269   
1270                  // Do we disapprove the whole topic? Remove potential notifications
1271                  if ($disapprove_all_posts_in_topic)
1272                  {
1273                      $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']);
1274                  }
1275   
1276                  // Notify Poster?
1277                  if ($notify_poster)
1278                  {
1279                      if ($post_data['poster_id'] == ANONYMOUS)
1280                      {
1281                          continue;
1282                      }
1283   
1284                      $post_data['disapprove_reason'] = $disapprove_reason;
1285                      if (isset($disapprove_reason_lang))
1286                      {
1287                          // Okay we need to get the reason from the posters language
1288                          if (!isset($lang_reasons[$post_data['user_lang']]))
1289                          {
1290                              // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
1291                              $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
1292   
1293                              // Only load up the language pack if the language is different to the current one
1294                              if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
1295                              {
1296                                  // Load up the language pack
1297                                  $lang = array();
1298                                  @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
1299   
1300                                  // If we find the reason in this language pack use it
1301                                  if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
1302                                  {
1303                                      $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
1304                                  }
1305   
1306                                  unset($lang); // Free memory
1307                              }
1308                          }
1309   
1310                          $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']];
1311                          $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : '';
1312                      }
1313   
1314                      if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1)
1315                      {
1316                          // If there is only 1 post when disapproving the topic,
1317                          // we send the user a "disapprove topic" notification...
1318                          $phpbb_notifications->add_notifications('notification.type.disapprove_topic', $post_data);
1319                      }
1320                      else
1321                      {
1322                          // ... otherwise there are multiple unapproved posts and
1323                          // all of them are disapproved as posts.
1324                          $phpbb_notifications->add_notifications('notification.type.disapprove_post', $post_data);
1325                      }
1326                  }
1327              }
1328   
1329              if ($num_disapproved_topics)
1330              {
1331                  $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS';
1332              }
1333              else
1334              {
1335                  $success_msg = ($num_disapproved_posts == 1) ? 'POST' : 'POSTS';
1336              }
1337   
1338              if ($is_disapproving)
1339              {
1340                  $success_msg .= '_DISAPPROVED_SUCCESS';
1341              }
1342              else
1343              {
1344                  $success_msg .= '_DELETED_SUCCESS';
1345              }
1346   
1347              // If we came from viewtopic, we try to go back to it.
1348              if (strpos($redirect, $phpbb_root_path . 'viewtopic.' . $phpEx) === 0)
1349              {
1350                  if ($num_disapproved_topics == 0)
1351                  {
1352                      // So we need to remove the post id part from the Url
1353                      $redirect = str_replace("&amp;p={$post_id_list[0]}#p{$post_id_list[0]}", '', $redirect);
1354                  }
1355                  else
1356                  {
1357                      // However this is only possible if the topic still exists,
1358                      // Otherwise we go back to the viewforum page
1359                      $redirect = append_sid($phpbb_root_path . 'viewforum.' . $phpEx, 'f=' . $request->variable('f', 0));
1360                  }
1361              }
1362   
1363              /**
1364               * Perform additional actions during post(s) disapproval
1365               *
1366               * @event core.disapprove_posts_after
1367               * @var    array    post_info                    Array containing info for all posts being disapproved
1368               * @var    array    topic_information            Array containing information for the topics
1369               * @var    array    topic_posts_unapproved        Array containing list of topic ids and the count of disapproved posts in them
1370               * @var    array    post_disapprove_list        Array containing list of posts and their topic id
1371               * @var    int        num_disapproved_topics        Variable containing the number of disapproved topics
1372               * @var    int        num_disapproved_posts        Variable containing the number of disapproved posts
1373               * @var array    lang_reasons                Array containing the language keys for reasons
1374               * @var    string    disapprove_reason            Variable containing the language key for the success message
1375               * @var    string    disapprove_reason_lang        Variable containing the language key for the success message
1376               * @var bool    is_disapproving                Variable telling if anything is going to be disapproved
1377               * @var bool    notify_poster                Variable telling if the post should be notified or not
1378               * @var    string    success_msg                    Variable containing the language key for the success message
1379               * @var string    redirect                    Variable containing the redirect url
1380               * @since 3.1.4-RC1
1381               */
1382              $vars = array(
1383                  'post_info',
1384                  'topic_information',
1385                  'topic_posts_unapproved',
1386                  'post_disapprove_list',
1387                  'num_disapproved_topics',
1388                  'num_disapproved_posts',
1389                  'lang_reasons',
1390                  'disapprove_reason',
1391                  'disapprove_reason_lang',
1392                  'is_disapproving',
1393                  'notify_poster',
1394                  'success_msg',
1395                  'redirect',
1396              );
1397              extract($phpbb_dispatcher->trigger_event('core.disapprove_posts_after', compact($vars)));
1398   
1399              unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang);
1400   
1401              meta_refresh(3, $redirect);
1402              $message = $user->lang[$success_msg];
1403   
1404              if ($request->is_ajax())
1405              {
1406                  $json_response = new \phpbb\json_response;
1407                  $json_response->send(array(
1408                      'MESSAGE_TITLE'        => $user->lang['INFORMATION'],
1409                      'MESSAGE_TEXT'        => $message,
1410                      'REFRESH_DATA'        => null,
1411                      'visible'            => false,
1412                  ));
1413              }
1414              $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
1415              trigger_error($message);
1416          }
1417          else
1418          {
1419              $show_notify = false;
1420   
1421              foreach ($post_info as $post_data)
1422              {
1423                  if ($post_data['poster_id'] == ANONYMOUS)
1424                  {
1425                      continue;
1426                  }
1427                  else
1428                  {
1429                      $show_notify = true;
1430                      break;
1431                  }
1432              }
1433   
1434              $l_confirm_msg = 'DISAPPROVE_POST';
1435              $confirm_template = 'mcp_approve.html';
1436              if ($is_disapproving)
1437              {
1438                  $phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id);
1439              }
1440              else
1441              {
1442                  $user->add_lang('posting');
1443   
1444                  $l_confirm_msg = 'DELETE_POST_PERMANENTLY';
1445                  $confirm_template = 'confirm_delete_body.html';
1446              }
1447              $l_confirm_msg .= ((sizeof($post_id_list) == 1) ? '' : 'S');
1448   
1449              $template->assign_vars(array(
1450                  'S_NOTIFY_POSTER'    => $show_notify,
1451                  'S_APPROVE'            => false,
1452                  'REASON'            => ($is_disapproving) ? $reason : '',
1453                  'ADDITIONAL_MSG'    => $additional_msg,
1454              ));
1455   
1456              confirm_box(false, $l_confirm_msg, $s_hidden_fields, $confirm_template);
1457          }
1458   
1459          redirect($redirect);
1460      }
1461  }
1462