[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

/includes/mcp/ -> mcp_forum.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 Forum View
  24  */
  25  function mcp_forum_view($id, $mode, $action, $forum_info)
  26  {
  27      global $template, $db, $user, $auth, $cache, $module;
  28      global $phpEx, $phpbb_root_path, $config;
  29      global $request, $phpbb_dispatcher, $phpbb_container;
  30  
  31      $user->add_lang(array('viewtopic', 'viewforum'));
  32  
  33      include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  34  
  35      // merge_topic is the quickmod action, merge_topics is the mcp_forum action, and merge_select is the mcp_topic action
  36      $merge_select = ($action == 'merge_select' || $action == 'merge_topic' || $action == 'merge_topics') ? true : false;
  37  
  38      $forum_id            = $forum_info['forum_id'];
  39      $start                = $request->variable('start', 0);
  40      $topic_id_list        = $request->variable('topic_id_list', array(0));
  41      $post_id_list        = $request->variable('post_id_list', array(0));
  42      $source_topic_ids    = array($request->variable('t', 0));
  43      $to_topic_id        = $request->variable('to_topic_id', 0);
  44  
  45      $url_extra = '';
  46      $url_extra .= ($forum_id) ? "&amp;f=$forum_id" : '';
  47      $url_extra .= ($GLOBALS['topic_id']) ? '&amp;t=' . $GLOBALS['topic_id'] : '';
  48      $url_extra .= ($GLOBALS['post_id']) ? '&amp;p=' . $GLOBALS['post_id'] : '';
  49      $url_extra .= ($GLOBALS['user_id']) ? '&amp;u=' . $GLOBALS['user_id'] : '';
  50  
  51      $url = append_sid("{$phpbb_root_path}mcp.$phpEx?$url_extra");
  52  
  53      // Resync Topics
  54      switch ($action)
  55      {
  56          case 'resync':
  57              $topic_ids = $request->variable('topic_id_list', array(0));
  58              mcp_resync_topics($topic_ids);
  59          break;
  60  
  61          case 'merge_topics':
  62              $source_topic_ids = $topic_id_list;
  63          case 'merge_topic':
  64              if ($to_topic_id)
  65              {
  66                  merge_topics($forum_id, $source_topic_ids, $to_topic_id);
  67              }
  68          break;
  69      }
  70  
  71      /**
  72      * Get some data in order to execute other actions.
  73      *
  74      * @event core.mcp_forum_view_before
  75      * @var    string    action                The action
  76      * @var    array    forum_info            Array with forum infos
  77      * @var    int        start                Start value
  78      * @var    array    topic_id_list        Array of topics ids
  79      * @var    array    post_id_list        Array of posts ids
  80      * @var    array    source_topic_ids    Array of source topics ids
  81      * @var    int        to_topic_id            Array of destination topics ids
  82      * @since 3.1.6-RC1
  83      */
  84      $vars = array(
  85          'action',
  86          'forum_info',
  87          'start',
  88          'topic_id_list',
  89          'post_id_list',
  90          'source_topic_ids',
  91          'to_topic_id',
  92      );
  93      extract($phpbb_dispatcher->trigger_event('core.mcp_forum_view_before', compact($vars)));
  94  
  95      /* @var $pagination \phpbb\pagination */
  96      $pagination = $phpbb_container->get('pagination');
  97  
  98      $selected_ids = '';
  99      if (count($post_id_list) && $action != 'merge_topics')
 100      {
 101          foreach ($post_id_list as $num => $post_id)
 102          {
 103              $selected_ids .= '&amp;post_id_list[' . $num . ']=' . $post_id;
 104          }
 105      }
 106      else if (count($topic_id_list) && $action == 'merge_topics')
 107      {
 108          foreach ($topic_id_list as $num => $topic_id)
 109          {
 110              $selected_ids .= '&amp;topic_id_list[' . $num . ']=' . $topic_id;
 111          }
 112      }
 113  
 114      make_jumpbox($url . "&amp;i=$id&amp;action=$action&amp;mode=$mode" . (($merge_select) ? $selected_ids : ''), $forum_id, false, 'm_', true);
 115  
 116      $topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page'];
 117  
 118      $sort_days = $total = 0;
 119      $sort_key = $sort_dir = '';
 120      $sort_by_sql = $sort_order_sql = array();
 121      phpbb_mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id);
 122  
 123      $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total;
 124      $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 125  
 126      $base_url = $url . "&amp;i=$id&amp;action=$action&amp;mode=$mode&amp;sd=$sort_dir&amp;sk=$sort_key&amp;st=$sort_days" . (($merge_select) ? $selected_ids : '');
 127      $pagination->generate_template_pagination($base_url, 'pagination', 'start', $forum_topics, $topics_per_page, $start);
 128  
 129      $template->assign_vars(array(
 130          'ACTION'                => $action,
 131          'FORUM_NAME'            => $forum_info['forum_name'],
 132          'FORUM_DESCRIPTION'        => generate_text_for_display($forum_info['forum_desc'], $forum_info['forum_desc_uid'], $forum_info['forum_desc_bitfield'], $forum_info['forum_desc_options']),
 133  
 134          'REPORTED_IMG'            => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
 135          'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
 136          'LAST_POST_IMG'            => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
 137          'NEWEST_POST_IMG'        => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
 138  
 139          'S_CAN_REPORT'            => $auth->acl_get('m_report', $forum_id),
 140          'S_CAN_DELETE'            => $auth->acl_get('m_delete', $forum_id),
 141          'S_CAN_RESTORE'            => $auth->acl_get('m_approve', $forum_id),
 142          'S_CAN_MERGE'            => $auth->acl_get('m_merge', $forum_id),
 143          'S_CAN_MOVE'            => $auth->acl_get('m_move', $forum_id),
 144          'S_CAN_FORK'            => $auth->acl_get('m_', $forum_id),
 145          'S_CAN_LOCK'            => $auth->acl_get('m_lock', $forum_id),
 146          'S_CAN_SYNC'            => $auth->acl_get('m_', $forum_id),
 147          'S_CAN_APPROVE'            => $auth->acl_get('m_approve', $forum_id),
 148          'S_MERGE_SELECT'        => ($merge_select) ? true : false,
 149          'S_CAN_MAKE_NORMAL'        => $auth->acl_gets('f_sticky', 'f_announce', 'f_announce_global', $forum_id),
 150          'S_CAN_MAKE_STICKY'        => $auth->acl_get('f_sticky', $forum_id),
 151          'S_CAN_MAKE_ANNOUNCE'    => $auth->acl_get('f_announce', $forum_id),
 152          'S_CAN_MAKE_ANNOUNCE_GLOBAL'    => $auth->acl_get('f_announce_global', $forum_id),
 153  
 154          'U_VIEW_FORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
 155          'U_VIEW_FORUM_LOGS'        => ($auth->acl_gets('a_', 'm_', $forum_id) && $module->loaded('logs')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&amp;mode=forum_logs&amp;f=' . $forum_id) : '',
 156  
 157          'S_MCP_ACTION'            => $url . "&amp;i=$id&amp;forum_action=$action&amp;mode=$mode&amp;start=$start" . (($merge_select) ? $selected_ids : ''),
 158  
 159          'TOTAL_TOPICS'            => $user->lang('VIEW_FORUM_TOPICS', (int) $forum_topics),
 160      ));
 161  
 162      // Grab icons
 163      $icons = $cache->obtain_icons();
 164  
 165      $topic_rows = array();
 166  
 167      if ($config['load_db_lastread'])
 168      {
 169          $sql_read_tracking['LEFT_JOIN'][] = ['FROM' => [TOPICS_TRACK_TABLE => 'tt'], 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']];
 170          $sql_read_tracking['SELECT'] = ', tt.mark_time';
 171      }
 172      else
 173      {
 174          $sql_read_tracking['LEFT_JOIN'] = [];
 175          $sql_read_tracking['SELECT'] = '';
 176      }
 177  
 178      /* @var $phpbb_content_visibility \phpbb\content_visibility */
 179      $phpbb_content_visibility = $phpbb_container->get('content.visibility');
 180  
 181      $sql = 'SELECT t.topic_id
 182          FROM ' . TOPICS_TABLE . ' t
 183          WHERE t.forum_id = ' . $forum_id . '
 184              AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . "
 185              $limit_time_sql
 186          ORDER BY t.topic_type DESC, $sort_order_sql";
 187  
 188      /**
 189      * Modify SQL query before MCP forum view topic list is queried
 190      *
 191      * @event core.mcp_view_forum_modify_sql
 192      * @var    string    sql            SQL query for forum view topic list
 193      * @var    int    forum_id    ID of the forum
 194      * @var    string  limit_time_sql        SQL query part for limit time
 195      * @var    string  sort_order_sql        SQL query part for sort order
 196      * @var    int topics_per_page            Number of topics per page
 197      * @var    int start            Start value
 198      * @since 3.1.2-RC1
 199      */
 200      $vars = array('sql', 'forum_id', 'limit_time_sql', 'sort_order_sql', 'topics_per_page', 'start');
 201      extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_sql', compact($vars)));
 202  
 203      $result = $db->sql_query_limit($sql, $topics_per_page, $start);
 204  
 205      $topic_list = $topic_tracking_info = array();
 206  
 207      while ($row_ary = $db->sql_fetchrow($result))
 208      {
 209          $topic_list[] = $row_ary['topic_id'];
 210      }
 211      $db->sql_freeresult($result);
 212  
 213      $sql_ary = [
 214          'SELECT'    => 't.*' . $sql_read_tracking['SELECT'],
 215          'FROM'        => [TOPICS_TABLE => 't'],
 216          'LEFT_JOIN'    => $sql_read_tracking['LEFT_JOIN'],
 217          'WHERE'        => $db->sql_in_set('t.topic_id', $topic_list, false, true),
 218      ];
 219  
 220      /**
 221      * Event to modify SQL query before MCP forum topic data is queried
 222      *
 223      * @event core.mcp_forum_topic_data_modify_sql
 224      * @var    array    sql_ary        SQL query array to get the MCP forum topic data
 225      * @var    int        forum_id    The forum ID
 226      * @var    array    topic_list    The array of MCP forum topic IDs
 227      *
 228      * @since 3.3.4-RC1
 229      */
 230      $vars = [
 231          'sql_ary',
 232          'forum_id',
 233          'topic_list',
 234      ];
 235      extract($phpbb_dispatcher->trigger_event('core.mcp_forum_topic_data_modify_sql', compact($vars)));
 236  
 237      $sql = $db->sql_build_query('SELECT', $sql_ary);
 238      $result = $db->sql_query($sql);
 239      while ($row_ary = $db->sql_fetchrow($result))
 240      {
 241          $topic_rows[$row_ary['topic_id']] = $row_ary;
 242      }
 243      $db->sql_freeresult($result);
 244  
 245      // If there is more than one page, but we have no topic list, then the start parameter is... erm... out of sync
 246      if (!count($topic_list) && $forum_topics && $start > 0)
 247      {
 248          redirect($url . "&amp;i=$id&amp;action=$action&amp;mode=$mode");
 249      }
 250  
 251      // Get topic tracking info
 252      if (count($topic_list))
 253      {
 254          if ($config['load_db_lastread'])
 255          {
 256              $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $topic_rows, array($forum_id => $forum_info['mark_time']));
 257          }
 258          else
 259          {
 260              $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list);
 261          }
 262      }
 263  
 264      foreach ($topic_list as $topic_id)
 265      {
 266          $row_ary = &$topic_rows[$topic_id];
 267  
 268          $replies = $phpbb_content_visibility->get_count('topic_posts', $row_ary, $forum_id) - 1;
 269  
 270          if ($row_ary['topic_status'] == ITEM_MOVED)
 271          {
 272              $unread_topic = false;
 273          }
 274          else
 275          {
 276              $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row_ary['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
 277          }
 278  
 279          // Get folder img, topic status/type related information
 280          $folder_img = $folder_alt = $topic_type = '';
 281          topic_status($row_ary, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
 282  
 283          $topic_title = censor_text($row_ary['topic_title']);
 284  
 285          $topic_unapproved = (($row_ary['topic_visibility'] == ITEM_UNAPPROVED || $row_ary['topic_visibility'] == ITEM_REAPPROVE)  && $auth->acl_get('m_approve', $row_ary['forum_id'])) ? true : false;
 286          $posts_unapproved = ($row_ary['topic_visibility'] == ITEM_APPROVED && $row_ary['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row_ary['forum_id'])) ? true : false;
 287          $topic_deleted = $row_ary['topic_visibility'] == ITEM_DELETED;
 288          $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&amp;i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&amp;t=' . $row_ary['topic_id'] : '';
 289          $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . '&amp;i=queue&amp;mode=deleted_topics&amp;t=' . $topic_id : $u_mcp_queue;
 290  
 291          $topic_row = array(
 292              'ATTACH_ICON_IMG'        => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row_ary['forum_id']) && $row_ary['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
 293              'TOPIC_IMG_STYLE'        => $folder_img,
 294              'TOPIC_FOLDER_IMG'        => $user->img($folder_img, $folder_alt),
 295              'TOPIC_ICON_IMG'        => (!empty($icons[$row_ary['icon_id']])) ? $icons[$row_ary['icon_id']]['img'] : '',
 296              'TOPIC_ICON_IMG_WIDTH'    => (!empty($icons[$row_ary['icon_id']])) ? $icons[$row_ary['icon_id']]['width'] : '',
 297              'TOPIC_ICON_IMG_HEIGHT'    => (!empty($icons[$row_ary['icon_id']])) ? $icons[$row_ary['icon_id']]['height'] : '',
 298              'UNAPPROVED_IMG'        => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
 299              'DELETED_IMG'            => ($topic_deleted) ? $user->img('icon_topic_deleted', 'TOPIC_DELETED') : '',
 300  
 301              'TOPIC_AUTHOR'                => get_username_string('username', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']),
 302              'TOPIC_AUTHOR_COLOUR'        => get_username_string('colour', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']),
 303              'TOPIC_AUTHOR_FULL'            => get_username_string('full', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']),
 304              'U_TOPIC_AUTHOR'            => get_username_string('profile', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']),
 305  
 306              'LAST_POST_AUTHOR'            => get_username_string('username', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']),
 307              'LAST_POST_AUTHOR_COLOUR'    => get_username_string('colour', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']),
 308              'LAST_POST_AUTHOR_FULL'        => get_username_string('full', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']),
 309              'U_LAST_POST_AUTHOR'        => get_username_string('profile', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']),
 310  
 311              'TOPIC_TYPE'        => $topic_type,
 312              'TOPIC_TITLE'        => $topic_title,
 313              'REPLIES'            => $phpbb_content_visibility->get_count('topic_posts', $row_ary, $row_ary['forum_id']) - 1,
 314              'LAST_POST_TIME'    => $user->format_date($row_ary['topic_last_post_time']),
 315              'FIRST_POST_TIME'    => $user->format_date($row_ary['topic_time']),
 316              'LAST_POST_SUBJECT'    => $row_ary['topic_last_post_subject'],
 317              'LAST_VIEW_TIME'    => $user->format_date($row_ary['topic_last_view_time']),
 318  
 319              'S_TOPIC_REPORTED'        => (!empty($row_ary['topic_reported']) && empty($row_ary['topic_moved_id']) && $auth->acl_get('m_report', $row_ary['forum_id'])) ? true : false,
 320              'S_TOPIC_UNAPPROVED'    => $topic_unapproved,
 321              'S_POSTS_UNAPPROVED'    => $posts_unapproved,
 322              'S_TOPIC_DELETED'        => $topic_deleted,
 323              'S_UNREAD_TOPIC'        => $unread_topic,
 324          );
 325  
 326          if ($row_ary['topic_status'] == ITEM_MOVED)
 327          {
 328              $topic_row = array_merge($topic_row, array(
 329                  'U_VIEW_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row_ary['topic_moved_id']}"),
 330                  'U_DELETE_TOPIC'    => ($auth->acl_get('m_delete', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;f=$forum_id&amp;topic_id_list[]={$row_ary['topic_id']}&amp;mode=forum_view&amp;action=delete_topic") : '',
 331                  'S_MOVED_TOPIC'        => true,
 332                  'TOPIC_ID'            => $row_ary['topic_moved_id'],
 333              ));
 334          }
 335          else
 336          {
 337              if ($action == 'merge_topic' || $action == 'merge_topics')
 338              {
 339                  $u_select_topic = $url . "&amp;i=$id&amp;mode=forum_view&amp;action=$action&amp;to_topic_id=" . $row_ary['topic_id'] . $selected_ids;
 340              }
 341              else
 342              {
 343                  $u_select_topic = $url . "&amp;i=$id&amp;mode=topic_view&amp;action=merge&amp;to_topic_id=" . $row_ary['topic_id'] . $selected_ids;
 344              }
 345              $topic_row = array_merge($topic_row, array(
 346                  'U_VIEW_TOPIC'        => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;f=$forum_id&amp;t={$row_ary['topic_id']}&amp;mode=topic_view"),
 347  
 348                  'S_SELECT_TOPIC'    => ($merge_select && !in_array($row_ary['topic_id'], $source_topic_ids)) ? true : false,
 349                  'U_SELECT_TOPIC'    => $u_select_topic,
 350                  'U_MCP_QUEUE'        => $u_mcp_queue,
 351                  'U_MCP_REPORT'        => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=topic_view&amp;t=' . $row_ary['topic_id'] . '&amp;action=reports') : '',
 352                  'TOPIC_ID'            => $row_ary['topic_id'],
 353                  'S_TOPIC_CHECKED'    => ($topic_id_list && in_array($row_ary['topic_id'], $topic_id_list)) ? true : false,
 354              ));
 355          }
 356  
 357          $row = $row_ary;
 358          /**
 359          * Modify the topic data before it is assigned to the template in MCP
 360          *
 361          * @event core.mcp_view_forum_modify_topicrow
 362          * @var    array    row        Array with topic data
 363          * @var    array    topic_row    Template array with topic data
 364          * @since 3.1.0-a1
 365          */
 366          $vars = array('row', 'topic_row');
 367          extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_topicrow', compact($vars)));
 368          $row_ary = $row;
 369          unset($row);
 370  
 371          $template->assign_block_vars('topicrow', $topic_row);
 372      }
 373      unset($topic_rows);
 374  }
 375  
 376  /**
 377  * Resync topics
 378  */
 379  function mcp_resync_topics($topic_ids)
 380  {
 381      global $db, $user, $phpbb_log, $request;
 382  
 383      if (!count($topic_ids))
 384      {
 385          trigger_error('NO_TOPIC_SELECTED');
 386      }
 387  
 388      if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
 389      {
 390          return;
 391      }
 392  
 393      // Sync everything and perform extra checks separately
 394      sync('topic_reported', 'topic_id', $topic_ids, false, true);
 395      sync('topic_attachment', 'topic_id', $topic_ids, false, true);
 396      sync('topic', 'topic_id', $topic_ids, true, false);
 397  
 398      $sql = 'SELECT topic_id, forum_id, topic_title
 399          FROM ' . TOPICS_TABLE . '
 400          WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
 401      $result = $db->sql_query($sql);
 402  
 403      // Log this action
 404      while ($row = $db->sql_fetchrow($result))
 405      {
 406          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_TOPIC_RESYNC', false, array(
 407              'forum_id' => $row['forum_id'],
 408              'topic_id' => $row['topic_id'],
 409              $row['topic_title']
 410          ));
 411      }
 412      $db->sql_freeresult($result);
 413  
 414      $msg = (count($topic_ids) == 1) ? $user->lang['TOPIC_RESYNC_SUCCESS'] : $user->lang['TOPICS_RESYNC_SUCCESS'];
 415  
 416      $redirect = $request->variable('redirect', $user->data['session_page']);
 417  
 418      meta_refresh(3, $redirect);
 419      trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
 420  
 421      return;
 422  }
 423  
 424  /**
 425  * Merge selected topics into selected topic
 426  */
 427  function merge_topics($forum_id, $topic_ids, $to_topic_id)
 428  {
 429      global $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_log, $request, $phpbb_dispatcher;
 430  
 431      if (!count($topic_ids))
 432      {
 433          $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
 434          return;
 435      }
 436      if (!$to_topic_id)
 437      {
 438          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 439          return;
 440      }
 441  
 442      $sync_topics = array_merge($topic_ids, array($to_topic_id));
 443  
 444      $all_topic_data = phpbb_get_topic_data($sync_topics, 'm_merge');
 445  
 446      if (!count($all_topic_data) || empty($all_topic_data[$to_topic_id]))
 447      {
 448          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 449          return;
 450      }
 451  
 452      $sync_forums = array();
 453      $topic_views = 0;
 454      foreach ($all_topic_data as $data)
 455      {
 456          $sync_forums[$data['forum_id']] = $data['forum_id'];
 457          $topic_views = max($topic_views, $data['topic_views']);
 458      }
 459  
 460      $to_topic_data = $all_topic_data[$to_topic_id];
 461  
 462      $post_id_list    = $request->variable('post_id_list', array(0));
 463      $start            = $request->variable('start', 0);
 464  
 465      if (!count($post_id_list) && count($topic_ids))
 466      {
 467          $sql = 'SELECT post_id
 468              FROM ' . POSTS_TABLE . '
 469              WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
 470          $result = $db->sql_query($sql);
 471  
 472          $post_id_list = array();
 473          while ($row = $db->sql_fetchrow($result))
 474          {
 475              $post_id_list[] = $row['post_id'];
 476          }
 477          $db->sql_freeresult($result);
 478      }
 479  
 480      if (!count($post_id_list))
 481      {
 482          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 483          return;
 484      }
 485  
 486      if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
 487      {
 488          return;
 489      }
 490  
 491      $redirect = $request->variable('redirect', "{$phpbb_root_path}mcp.$phpEx?f=$forum_id&amp;i=main&amp;mode=forum_view");
 492  
 493      $s_hidden_fields = build_hidden_fields(array(
 494          'i'                => 'main',
 495          'f'                => $forum_id,
 496          'post_id_list'    => $post_id_list,
 497          'to_topic_id'    => $to_topic_id,
 498          'mode'            => 'forum_view',
 499          'action'        => 'merge_topics',
 500          'start'            => $start,
 501          'redirect'        => $redirect,
 502          'topic_id_list'    => $topic_ids)
 503      );
 504      $return_link = '';
 505  
 506      if (confirm_box(true))
 507      {
 508          $to_forum_id = $to_topic_data['forum_id'];
 509  
 510          move_posts($post_id_list, $to_topic_id, false);
 511  
 512          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MERGE', false, array(
 513              'forum_id' => $to_forum_id,
 514              'topic_id' => $to_topic_id,
 515              $to_topic_data['topic_title']
 516          ));
 517  
 518          // Update topic views count
 519          $sql = 'UPDATE ' . TOPICS_TABLE . '
 520                  SET topic_views = ' . $topic_views . '
 521                  WHERE topic_id = ' . $to_topic_id;
 522          $db->sql_query($sql);
 523  
 524          // Message and return links
 525          $success_msg = 'POSTS_MERGED_SUCCESS';
 526  
 527          if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
 528          {
 529              include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
 530          }
 531  
 532          // Update the topic watch table.
 533          phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id);
 534  
 535          // Update the bookmarks table.
 536          phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $topic_ids, $to_topic_id);
 537  
 538          // Re-sync the topics and forums because the auto-sync was deactivated in the call of  move_posts()
 539          sync('topic_reported', 'topic_id', $sync_topics);
 540          sync('topic_attachment', 'topic_id', $sync_topics);
 541          sync('topic', 'topic_id', $sync_topics, true);
 542          sync('forum', 'forum_id', $sync_forums, true, true);
 543  
 544          // Link to the new topic
 545          $return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $to_topic_id) . '">', '</a>');
 546          $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?t=$to_topic_id");
 547          $redirect = reapply_sid($redirect);
 548  
 549          /**
 550           * Perform additional actions after merging topics.
 551           *
 552           * @event core.mcp_forum_merge_topics_after
 553           * @var    array    all_topic_data            The data from all topics involved in the merge
 554           * @var    int        to_topic_id                The ID of the topic into which the rest are merged
 555           * @since 3.1.11-RC1
 556           */
 557          $vars = array(
 558              'all_topic_data',
 559              'to_topic_id',
 560          );
 561          extract($phpbb_dispatcher->trigger_event('core.mcp_forum_merge_topics_after', compact($vars)));
 562  
 563          meta_refresh(3, $redirect);
 564          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 565      }
 566      else
 567      {
 568          confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields);
 569      }
 570  }


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1