[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/includes/mcp/ -> mcp_topic.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  * View topic in MCP
  24  */
  25  function mcp_topic_view($id, $mode, $action)
  26  {
  27      global $phpEx, $phpbb_root_path, $config, $request;
  28      global $template, $db, $user, $auth, $phpbb_container, $phpbb_dispatcher;
  29  
  30      $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . phpbb_extra_url());
  31  
  32      /* @var $pagination \phpbb\pagination */
  33      $pagination = $phpbb_container->get('pagination');
  34      $user->add_lang('viewtopic');
  35  
  36      $topic_id = $request->variable('t', 0);
  37      $topic_info = phpbb_get_topic_data(array($topic_id), false, true);
  38  
  39      if (!count($topic_info))
  40      {
  41          trigger_error('TOPIC_NOT_EXIST');
  42      }
  43  
  44      $topic_info = $topic_info[$topic_id];
  45  
  46      // Set up some vars
  47      $icon_id        = $request->variable('icon', 0);
  48      $subject        = $request->variable('subject', '', true);
  49      $start            = $request->variable('start', 0);
  50      $sort_days_old    = $request->variable('st_old', 0);
  51      $forum_id        = $request->variable('f', 0);
  52      $to_topic_id    = $request->variable('to_topic_id', 0);
  53      $to_forum_id    = $request->variable('to_forum_id', 0);
  54      $sort            = isset($_POST['sort']) ? true : false;
  55      $submitted_id_list    = $request->variable('post_ids', array(0));
  56      $checked_ids = $post_id_list = $request->variable('post_id_list', array(0));
  57  
  58      // Resync Topic?
  59      if ($action == 'resync')
  60      {
  61          if (!function_exists('mcp_resync_topics'))
  62          {
  63              include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
  64          }
  65          mcp_resync_topics(array($topic_id));
  66      }
  67  
  68      // Split Topic?
  69      if ($action == 'split_all' || $action == 'split_beyond')
  70      {
  71          if (!$sort)
  72          {
  73              split_topic($action, $topic_id, $to_forum_id, $subject);
  74          }
  75          $action = 'split';
  76      }
  77  
  78      // Merge Posts?
  79      if ($action == 'merge_posts')
  80      {
  81          if (!$sort)
  82          {
  83              merge_posts($topic_id, $to_topic_id);
  84          }
  85          $action = 'merge';
  86      }
  87  
  88      if ($action == 'split' && !$subject)
  89      {
  90          $subject = $topic_info['topic_title'];
  91      }
  92  
  93      // Restore or pprove posts?
  94      if (($action == 'restore' || $action == 'approve') && $auth->acl_get('m_approve', $topic_info['forum_id']))
  95      {
  96          if (!class_exists('mcp_queue'))
  97          {
  98              include($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx);
  99          }
 100  
 101          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 102          include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 103  
 104          if (!count($post_id_list))
 105          {
 106              trigger_error('NO_POST_SELECTED');
 107          }
 108  
 109          if (!$sort)
 110          {
 111              mcp_queue::approve_posts($action, $post_id_list, $id, $mode);
 112          }
 113      }
 114  
 115      // Jumpbox, sort selects and that kind of things
 116      make_jumpbox($url . "&amp;i=$id&amp;mode=forum_view", $topic_info['forum_id'], false, 'm_', true);
 117      $where_sql = ($action == 'reports') ? 'WHERE post_reported = 1 AND ' : 'WHERE';
 118  
 119      $sort_days = $total = 0;
 120      $sort_key = $sort_dir = '';
 121      $sort_by_sql = $sort_order_sql = array();
 122      phpbb_mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $topic_info['forum_id'], $topic_id, $where_sql);
 123  
 124      /* @var $phpbb_content_visibility \phpbb\content_visibility */
 125      $phpbb_content_visibility = $phpbb_container->get('content.visibility');
 126      $limit_time_sql = ($sort_days) ? 'AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
 127  
 128      if ($total == -1)
 129      {
 130          $total = $phpbb_content_visibility->get_count('topic_posts', $topic_info, $topic_info['forum_id']);
 131      }
 132  
 133      $posts_per_page = max(0, $request->variable('posts_per_page', intval($config['posts_per_page'])));
 134      if ($posts_per_page == 0)
 135      {
 136          $posts_per_page = $total;
 137      }
 138  
 139      if ((!empty($sort_days_old) && $sort_days_old != $sort_days) || $total <= $posts_per_page)
 140      {
 141          $start = 0;
 142      }
 143      $start = $pagination->validate_start($start, $posts_per_page, $total);
 144  
 145      $sql_where = (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . '
 146              p.topic_id = ' . $topic_id . '
 147              AND ' .    $phpbb_content_visibility->get_visibility_sql('post', $topic_info['forum_id'], 'p.') . '
 148              AND p.poster_id = u.user_id ' .
 149              $limit_time_sql;
 150  
 151      $sql_ary = array(
 152          'SELECT'    => 'u.username, u.username_clean, u.user_colour, p.*',
 153          'FROM'        => array(
 154              POSTS_TABLE        => 'p',
 155              USERS_TABLE        => 'u'
 156          ),
 157          'LEFT_JOIN'    => array(),
 158          'WHERE'        => $sql_where,
 159          'ORDER_BY'    => $sort_order_sql,
 160      );
 161  
 162      /**
 163      * Event to modify the SQL query before the MCP topic review posts is queried
 164      *
 165      * @event core.mcp_topic_modify_sql_ary
 166      * @var    array    sql_ary        The SQL array to get the data of the MCP topic review posts
 167      * @since 3.2.8-RC1
 168      */
 169      $vars = array('sql_ary');
 170      extract($phpbb_dispatcher->trigger_event('core.mcp_topic_modify_sql_ary', compact($vars)));
 171  
 172      $sql = $db->sql_build_query('SELECT', $sql_ary);
 173      unset($sql_ary);
 174  
 175      $result = $db->sql_query_limit($sql, $posts_per_page, $start);
 176  
 177      $rowset = $post_id_list = array();
 178      while ($row = $db->sql_fetchrow($result))
 179      {
 180          $rowset[] = $row;
 181          $post_id_list[] = $row['post_id'];
 182      }
 183      $db->sql_freeresult($result);
 184  
 185      // Get topic tracking info
 186      if ($config['load_db_lastread'])
 187      {
 188          $tmp_topic_data = array($topic_id => $topic_info);
 189          $topic_tracking_info = get_topic_tracking($topic_info['forum_id'], $topic_id, $tmp_topic_data, array($topic_info['forum_id'] => $topic_info['forum_mark_time']));
 190          unset($tmp_topic_data);
 191      }
 192      else
 193      {
 194          $topic_tracking_info = get_complete_topic_tracking($topic_info['forum_id'], $topic_id);
 195      }
 196  
 197      $has_unapproved_posts = $has_deleted_posts = false;
 198  
 199      // Grab extensions
 200      $attachments = array();
 201      if ($topic_info['topic_attachment'] && count($post_id_list))
 202      {
 203          // Get attachments...
 204          if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_info['forum_id']))
 205          {
 206              $sql = 'SELECT *
 207                  FROM ' . ATTACHMENTS_TABLE . '
 208                  WHERE ' . $db->sql_in_set('post_msg_id', $post_id_list) . '
 209                      AND in_message = 0
 210                  ORDER BY filetime DESC, post_msg_id ASC';
 211              $result = $db->sql_query($sql);
 212  
 213              while ($row = $db->sql_fetchrow($result))
 214              {
 215                  $attachments[$row['post_msg_id']][] = $row;
 216              }
 217              $db->sql_freeresult($result);
 218          }
 219      }
 220  
 221      /**
 222      * Event to modify the post data for the MCP topic review before assigning the posts
 223      *
 224      * @event core.mcp_topic_modify_post_data
 225      * @var    array    attachments        List of attachments post_id => array of attachments
 226      * @var    int        forum_id        The forum ID we are currently in
 227      * @var    int        id                ID of the tab we are displaying
 228      * @var    string    mode            Mode of the MCP page we are displaying
 229      * @var    array    post_id_list    Array with post ids we are going to display
 230      * @var    array    rowset            Array with the posts data
 231      * @var    int        topic_id        The topic ID we are currently reviewing
 232      * @since 3.1.7-RC1
 233      */
 234      $vars = array(
 235          'attachments',
 236          'forum_id',
 237          'id',
 238          'mode',
 239          'post_id_list',
 240          'rowset',
 241          'topic_id',
 242      );
 243      extract($phpbb_dispatcher->trigger_event('core.mcp_topic_modify_post_data', compact($vars)));
 244  
 245      foreach ($rowset as $i => $row)
 246      {
 247          $message = $row['post_text'];
 248          $post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title'];
 249  
 250          $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
 251          $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, false);
 252  
 253          if (!empty($attachments[$row['post_id']]))
 254          {
 255              $update_count = array();
 256              parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count);
 257          }
 258  
 259          if ($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE)
 260          {
 261              $has_unapproved_posts = true;
 262          }
 263  
 264          if ($row['post_visibility'] == ITEM_DELETED)
 265          {
 266              $has_deleted_posts = true;
 267          }
 268  
 269          $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
 270  
 271          $post_row = array(
 272              'POST_AUTHOR_FULL'        => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 273              'POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 274              'POST_AUTHOR'            => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 275              'U_POST_AUTHOR'            => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 276  
 277              'POST_DATE'        => $user->format_date($row['post_time']),
 278              'POST_SUBJECT'    => $post_subject,
 279              'MESSAGE'        => $message,
 280              'POST_ID'        => $row['post_id'],
 281              'RETURN_TOPIC'    => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) . '">', '</a>'),
 282  
 283              'MINI_POST_IMG'            => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
 284  
 285              'S_POST_REPORTED'    => ($row['post_reported'] && $auth->acl_get('m_report', $topic_info['forum_id'])),
 286              'S_POST_UNAPPROVED'    => (($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $topic_info['forum_id'])),
 287              'S_POST_DELETED'    => ($row['post_visibility'] == ITEM_DELETED && $auth->acl_get('m_approve', $topic_info['forum_id'])),
 288              'S_CHECKED'            => (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false,
 289              'S_HAS_ATTACHMENTS'    => (!empty($attachments[$row['post_id']])) ? true : false,
 290  
 291              'U_POST_DETAILS'    => "$url&amp;i=$id&amp;p={$row['post_id']}&amp;mode=post_details" . (($forum_id) ? "&amp;f=$forum_id" : ''),
 292              'U_MCP_APPROVE'        => ($auth->acl_get('m_approve', $topic_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $topic_info['forum_id'] . '&amp;p=' . $row['post_id']) : '',
 293              'U_MCP_REPORT'        => ($auth->acl_get('m_report', $topic_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $topic_info['forum_id'] . '&amp;p=' . $row['post_id']) : '',
 294          );
 295  
 296          /**
 297          * Event to modify the template data block for topic reviews in the MCP
 298          *
 299          * @event core.mcp_topic_review_modify_row
 300          * @var    int        id                    ID of the tab we are displaying
 301          * @var    string    mode                Mode of the MCP page we are displaying
 302          * @var    int        topic_id            The topic ID we are currently reviewing
 303          * @var    int        forum_id            The forum ID we are currently in
 304          * @var    int        start                Start item of this page
 305          * @var    int        current_row_number    Number of the post on this page
 306          * @var    array    post_row            Template block array of the current post
 307          * @var    array    row                    Array with original post and user data
 308          * @var    array    topic_info            Array with topic data
 309          * @var    int        total                Total posts count
 310          * @since 3.1.4-RC1
 311          */
 312          $vars = array(
 313              'id',
 314              'mode',
 315              'topic_id',
 316              'forum_id',
 317              'start',
 318              'current_row_number',
 319              'post_row',
 320              'row',
 321              'topic_info',
 322              'total',
 323          );
 324          extract($phpbb_dispatcher->trigger_event('core.mcp_topic_review_modify_row', compact($vars)));
 325  
 326          $template->assign_block_vars('postrow', $post_row);
 327  
 328          // Display not already displayed Attachments for this post, we already parsed them. ;)
 329          if (!empty($attachments[$row['post_id']]))
 330          {
 331              foreach ($attachments[$row['post_id']] as $attachment)
 332              {
 333                  $template->assign_block_vars('postrow.attachment', array(
 334                      'DISPLAY_ATTACHMENT'    => $attachment)
 335                  );
 336              }
 337          }
 338  
 339          unset($rowset[$i]);
 340      }
 341  
 342      // Display topic icons for split topic
 343      $s_topic_icons = false;
 344  
 345      if ($auth->acl_gets('m_split', 'm_merge', (int) $topic_info['forum_id']))
 346      {
 347          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 348          $s_topic_icons = posting_gen_topic_icons('', $icon_id);
 349  
 350          // Has the user selected a topic for merge?
 351          if ($to_topic_id)
 352          {
 353              $to_topic_info = phpbb_get_topic_data(array($to_topic_id), 'm_merge');
 354  
 355              if (!count($to_topic_info))
 356              {
 357                  $to_topic_id = 0;
 358              }
 359              else
 360              {
 361                  $to_topic_info = $to_topic_info[$to_topic_id];
 362  
 363                  if (!$to_topic_info['enable_icons'] || $auth->acl_get('!f_icons', $topic_info['forum_id']))
 364                  {
 365                      $s_topic_icons = false;
 366                  }
 367              }
 368          }
 369      }
 370  
 371      $s_hidden_fields = build_hidden_fields(array(
 372          'st_old'    => $sort_days,
 373          'post_ids'    => $post_id_list,
 374      ));
 375  
 376      $base_url = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;t={$topic_info['topic_id']}&amp;mode=$mode&amp;action=$action&amp;to_topic_id=$to_topic_id&amp;posts_per_page=$posts_per_page&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir");
 377      if ($posts_per_page)
 378      {
 379          $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $posts_per_page, $start);
 380      }
 381  
 382      $template->assign_vars(array(
 383          'TOPIC_TITLE'        => $topic_info['topic_title'],
 384          'U_VIEW_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&amp;t=' . $topic_info['topic_id']),
 385  
 386          'TO_TOPIC_ID'        => $to_topic_id,
 387          'TO_TOPIC_INFO'        => ($to_topic_id) ? sprintf($user->lang['YOU_SELECTED_TOPIC'], $to_topic_id, '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_topic_info['forum_id'] . '&amp;t=' . $to_topic_id) . '">' . $to_topic_info['topic_title'] . '</a>') : '',
 388  
 389          'SPLIT_SUBJECT'        => $subject,
 390          'POSTS_PER_PAGE'    => $posts_per_page,
 391          'ACTION'            => $action,
 392  
 393          'REPORTED_IMG'        => $user->img('icon_topic_reported', 'POST_REPORTED'),
 394          'UNAPPROVED_IMG'    => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
 395          'DELETED_IMG'        => $user->img('icon_topic_deleted', 'POST_DELETED_RESTORE'),
 396          'INFO_IMG'            => $user->img('icon_post_info', 'VIEW_INFO'),
 397  
 398          'S_MCP_ACTION'        => "$url&amp;i=$id&amp;mode=$mode&amp;action=$action&amp;start=$start",
 399          'S_FORUM_SELECT'    => ($to_forum_id) ? make_forum_select($to_forum_id, false, false, true, true, true) : make_forum_select($topic_info['forum_id'], false, false, true, true, true),
 400          'S_CAN_SPLIT'        => ($auth->acl_get('m_split', $topic_info['forum_id'])) ? true : false,
 401          'S_CAN_MERGE'        => ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? true : false,
 402          'S_CAN_DELETE'        => ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? true : false,
 403          'S_CAN_APPROVE'        => ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false,
 404          'S_CAN_RESTORE'        => ($has_deleted_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false,
 405          'S_CAN_LOCK'        => ($auth->acl_get('m_lock', $topic_info['forum_id'])) ? true : false,
 406          'S_CAN_REPORT'        => ($auth->acl_get('m_report', $topic_info['forum_id'])) ? true : false,
 407          'S_CAN_SYNC'        => $auth->acl_get('m_', $topic_info['forum_id']),
 408          'S_REPORT_VIEW'        => ($action == 'reports') ? true : false,
 409          'S_MERGE_VIEW'        => ($action == 'merge') ? true : false,
 410          'S_SPLIT_VIEW'        => ($action == 'split') ? true : false,
 411  
 412          'S_HIDDEN_FIELDS'    => $s_hidden_fields,
 413  
 414          'S_SHOW_TOPIC_ICONS'    => $s_topic_icons,
 415          'S_TOPIC_ICON'            => $icon_id,
 416  
 417          'U_SELECT_TOPIC'    => "$url&amp;i=$id&amp;mode=forum_view&amp;action=merge_select" . (($forum_id) ? "&amp;f=$forum_id" : ''),
 418  
 419          'RETURN_TOPIC'        => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_info['forum_id']}&amp;t={$topic_info['topic_id']}&amp;start=$start") . '">', '</a>'),
 420          'RETURN_FORUM'        => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$topic_info['forum_id']}&amp;start=$start") . '">', '</a>'),
 421  
 422          'TOTAL_POSTS'        => $user->lang('VIEW_TOPIC_POSTS', (int) $total),
 423      ));
 424  }
 425  
 426  /**
 427  * Split topic
 428  */
 429  function split_topic($action, $topic_id, $to_forum_id, $subject)
 430  {
 431      global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config, $phpbb_log, $request, $phpbb_dispatcher;
 432  
 433      $post_id_list    = $request->variable('post_id_list', array(0));
 434      $forum_id        = $request->variable('forum_id', 0);
 435      $start            = $request->variable('start', 0);
 436  
 437      if (!count($post_id_list))
 438      {
 439          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 440          return;
 441      }
 442  
 443      if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_split')))
 444      {
 445          return;
 446      }
 447  
 448      $post_id = $post_id_list[0];
 449      $post_info = phpbb_get_post_data(array($post_id));
 450  
 451      if (!count($post_info))
 452      {
 453          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 454          return;
 455      }
 456  
 457      $post_info = $post_info[$post_id];
 458      $subject = trim($subject);
 459  
 460      /**
 461       * Replace Emojis and other 4bit UTF-8 chars not allowed by MySQL to UCR/NCR.
 462       * Using their Numeric Character Reference's Hexadecimal notation.
 463       */
 464      $subject = utf8_encode_ucr($subject);
 465  
 466      // Make some tests
 467      if (!$subject)
 468      {
 469          $template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']);
 470          return;
 471      }
 472  
 473      if ($to_forum_id <= 0)
 474      {
 475          $template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']);
 476          return;
 477      }
 478  
 479      $forum_info = phpbb_get_forum_data(array($to_forum_id), 'f_post');
 480  
 481      if (!count($forum_info))
 482      {
 483          $template->assign_var('MESSAGE', $user->lang['USER_CANNOT_POST']);
 484          return;
 485      }
 486  
 487      $forum_info = $forum_info[$to_forum_id];
 488  
 489      if ($forum_info['forum_type'] != FORUM_POST)
 490      {
 491          $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']);
 492          return;
 493      }
 494  
 495      $redirect = $request->variable('redirect', build_url(array('quickmod')));
 496  
 497      $s_hidden_fields = build_hidden_fields(array(
 498          'i'                => 'main',
 499          'post_id_list'    => $post_id_list,
 500          'f'                => $forum_id,
 501          'mode'            => 'topic_view',
 502          'start'            => $start,
 503          'action'        => $action,
 504          't'                => $topic_id,
 505          'redirect'        => $redirect,
 506          'subject'        => $subject,
 507          'to_forum_id'    => $to_forum_id,
 508          'icon'            => $request->variable('icon', 0))
 509      );
 510  
 511      if (confirm_box(true))
 512      {
 513          if ($action == 'split_beyond')
 514          {
 515              $sort_days = $total = 0;
 516              $sort_key = $sort_dir = '';
 517              $sort_by_sql = $sort_order_sql = array();
 518              phpbb_mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
 519  
 520              $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 521  
 522              if ($sort_order_sql[0] == 'u')
 523              {
 524                  $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
 525                      FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
 526                      WHERE p.topic_id = $topic_id
 527                          AND p.poster_id = u.user_id
 528                          $limit_time_sql
 529                      ORDER BY $sort_order_sql";
 530              }
 531              else
 532              {
 533                  $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
 534                      FROM ' . POSTS_TABLE . " p
 535                      WHERE p.topic_id = $topic_id
 536                          $limit_time_sql
 537                      ORDER BY $sort_order_sql";
 538              }
 539              $result = $db->sql_query_limit($sql, 0, $start);
 540  
 541              $store = false;
 542              $post_id_list = array();
 543              while ($row = $db->sql_fetchrow($result))
 544              {
 545                  // If split from selected post (split_beyond), we split the unapproved items too.
 546                  if (($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE) && !$auth->acl_get('m_approve', $row['forum_id']))
 547                  {
 548  //                    continue;
 549                  }
 550  
 551                  // Start to store post_ids as soon as we see the first post that was selected
 552                  if ($row['post_id'] == $post_id)
 553                  {
 554                      $store = true;
 555                  }
 556  
 557                  if ($store)
 558                  {
 559                      $post_id_list[] = $row['post_id'];
 560                  }
 561              }
 562              $db->sql_freeresult($result);
 563          }
 564  
 565          if (!count($post_id_list))
 566          {
 567              trigger_error('NO_POST_SELECTED');
 568          }
 569  
 570          $icon_id = $request->variable('icon', 0);
 571  
 572          $sql_ary = array(
 573              'forum_id'            => $to_forum_id,
 574              'topic_title'        => $subject,
 575              'icon_id'            => $icon_id,
 576              'topic_visibility'    => 1
 577          );
 578  
 579          $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 580          $db->sql_query($sql);
 581  
 582          $to_topic_id = $db->sql_nextid();
 583          move_posts($post_id_list, $to_topic_id);
 584  
 585          $topic_info = phpbb_get_topic_data(array($topic_id));
 586          $topic_info = $topic_info[$topic_id];
 587  
 588          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SPLIT_DESTINATION', false, array(
 589              'forum_id' => $to_forum_id,
 590              'topic_id' => $to_topic_id,
 591              $subject
 592          ));
 593          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SPLIT_SOURCE', false, array(
 594              'forum_id' => $forum_id,
 595              'topic_id' => $topic_id,
 596              $topic_info['topic_title']
 597          ));
 598  
 599          // Change topic title of first post
 600          $sql = 'UPDATE ' . POSTS_TABLE . "
 601              SET post_subject = '" . $db->sql_escape($subject) . "'
 602              WHERE post_id = {$post_id_list[0]}";
 603          $db->sql_query($sql);
 604  
 605          // Grab data for first post in split topic
 606          $sql_array = array(
 607              'SELECT'  => 'p.post_id, p.forum_id, p.poster_id, p.post_text, f.enable_indexing',
 608              'FROM' => array(
 609                  POSTS_TABLE => 'p',
 610              ),
 611              'LEFT_JOIN' => array(
 612                  array(
 613                      'FROM' => array(FORUMS_TABLE => 'f'),
 614                      'ON' => 'p.forum_id = f.forum_id',
 615                  )
 616              ),
 617              'WHERE' => "post_id = {$post_id_list[0]}",
 618          );
 619          $sql = $db->sql_build_query('SELECT', $sql_array);
 620          $result = $db->sql_query($sql);
 621          $first_post_data = $db->sql_fetchrow($result);
 622          $db->sql_freeresult($result);
 623  
 624          // Index first post as if it were edited
 625          if ($first_post_data['enable_indexing'])
 626          {
 627              // Select the search method and do some additional checks to ensure it can actually be utilised
 628              $search_type = $config['search_type'];
 629  
 630              if (!class_exists($search_type))
 631              {
 632                  trigger_error('NO_SUCH_SEARCH_MODULE');
 633              }
 634  
 635              $error = false;
 636              $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
 637  
 638              if ($error)
 639              {
 640                  trigger_error($error);
 641              }
 642  
 643              $search->index('edit', $first_post_data['post_id'], $first_post_data['post_text'], $subject, $first_post_data['poster_id'], $first_post_data['forum_id']);
 644          }
 645  
 646          // Copy topic subscriptions to new topic
 647          $sql = 'SELECT user_id, notify_status
 648              FROM ' . TOPICS_WATCH_TABLE . '
 649              WHERE topic_id = ' . $topic_id;
 650          $result = $db->sql_query($sql);
 651  
 652          $sql_ary = array();
 653          while ($row = $db->sql_fetchrow($result))
 654          {
 655              $sql_ary[] = array(
 656                  'topic_id'        => (int) $to_topic_id,
 657                  'user_id'        => (int) $row['user_id'],
 658                  'notify_status'    => (int) $row['notify_status'],
 659              );
 660          }
 661          $db->sql_freeresult($result);
 662  
 663          if (count($sql_ary))
 664          {
 665              $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
 666          }
 667  
 668          // Copy bookmarks to new topic
 669          $sql = 'SELECT user_id
 670              FROM ' . BOOKMARKS_TABLE . '
 671              WHERE topic_id = ' . $topic_id;
 672          $result = $db->sql_query($sql);
 673  
 674          $sql_ary = array();
 675          while ($row = $db->sql_fetchrow($result))
 676          {
 677              $sql_ary[] = array(
 678                  'topic_id'        => (int) $to_topic_id,
 679                  'user_id'        => (int) $row['user_id'],
 680              );
 681          }
 682          $db->sql_freeresult($result);
 683  
 684          if (count($sql_ary))
 685          {
 686              $db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary);
 687          }
 688  
 689          $success_msg = 'TOPIC_SPLIT_SUCCESS';
 690  
 691          // Update forum statistics
 692          $config->increment('num_topics', 1, false);
 693  
 694          // Link back to both topics
 695          $return_link = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']) . '">', '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
 696          $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&amp;t=$to_topic_id");
 697          $redirect = reapply_sid($redirect);
 698  
 699          meta_refresh(3, $redirect);
 700          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 701      }
 702      else
 703      {
 704          confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields);
 705      }
 706  }
 707  
 708  /**
 709  * Merge selected posts into selected topic
 710  */
 711  function merge_posts($topic_id, $to_topic_id)
 712  {
 713      global $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_log, $request, $phpbb_dispatcher;
 714  
 715      if (!$to_topic_id)
 716      {
 717          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 718          return;
 719      }
 720  
 721      $sync_topics = array($topic_id, $to_topic_id);
 722  
 723      $topic_data = phpbb_get_topic_data($sync_topics, 'm_merge');
 724  
 725      if (!count($topic_data) || empty($topic_data[$to_topic_id]))
 726      {
 727          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 728          return;
 729      }
 730  
 731      $sync_forums = array();
 732      foreach ($topic_data as $data)
 733      {
 734          $sync_forums[$data['forum_id']] = $data['forum_id'];
 735      }
 736  
 737      $topic_data = $topic_data[$to_topic_id];
 738  
 739      $post_id_list    = $request->variable('post_id_list', array(0));
 740      $start            = $request->variable('start', 0);
 741  
 742      if (!count($post_id_list))
 743      {
 744          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 745          return;
 746      }
 747  
 748      if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
 749      {
 750          return;
 751      }
 752  
 753      $redirect = $request->variable('redirect', build_url(array('quickmod')));
 754  
 755      $s_hidden_fields = build_hidden_fields(array(
 756          'i'                => 'main',
 757          'post_id_list'    => $post_id_list,
 758          'to_topic_id'    => $to_topic_id,
 759          'mode'            => 'topic_view',
 760          'action'        => 'merge_posts',
 761          'start'            => $start,
 762          'redirect'        => $redirect,
 763          't'                => $topic_id)
 764      );
 765      $return_link = '';
 766  
 767      if (confirm_box(true))
 768      {
 769          $to_forum_id = $topic_data['forum_id'];
 770  
 771          move_posts($post_id_list, $to_topic_id, false);
 772  
 773          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MERGE', false, array(
 774              'forum_id' => $to_forum_id,
 775              'topic_id' => $to_topic_id,
 776              $topic_data['topic_title']
 777          ));
 778  
 779          // Message and return links
 780          $success_msg = 'POSTS_MERGED_SUCCESS';
 781  
 782          // Does the original topic still exist? If yes, link back to it
 783          $sql = 'SELECT forum_id
 784              FROM ' . POSTS_TABLE . '
 785              WHERE topic_id = ' . $topic_id;
 786          $result = $db->sql_query_limit($sql, 1);
 787          $row = $db->sql_fetchrow($result);
 788          $db->sql_freeresult($result);
 789  
 790          if ($row)
 791          {
 792              $return_link .= sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $topic_id) . '">', '</a>');
 793          }
 794          else
 795          {
 796              if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
 797              {
 798                  include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
 799              }
 800  
 801              // If the topic no longer exist, we will update the topic watch table.
 802              phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', array($topic_id), $to_topic_id);
 803  
 804              // If the topic no longer exist, we will update the bookmarks table.
 805              phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', array($topic_id), $to_topic_id);
 806          }
 807  
 808          // Re-sync the topics and forums because the auto-sync was deactivated in the call of move_posts()
 809          sync('topic_reported', 'topic_id', $sync_topics);
 810          sync('topic_attachment', 'topic_id', $sync_topics);
 811          sync('topic', 'topic_id', $sync_topics, true);
 812          sync('forum', 'forum_id', $sync_forums, true, true);
 813  
 814          // Link to the new topic
 815          $return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
 816          $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&amp;t=$to_topic_id");
 817          $redirect = reapply_sid($redirect);
 818  
 819          /**
 820           * Perform additional actions after merging posts.
 821           *
 822           * @event core.mcp_topics_merge_posts_after
 823           * @var    int        topic_id        The topic ID from which posts are being moved
 824           * @var    int        to_topic_id        The topic ID to which posts are being moved
 825           * @since 3.1.11-RC1
 826           */
 827          $vars = array(
 828              'topic_id',
 829              'to_topic_id',
 830          );
 831          extract($phpbb_dispatcher->trigger_event('core.mcp_topics_merge_posts_after', compact($vars)));
 832  
 833          meta_refresh(3, $redirect);
 834          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 835      }
 836      else
 837      {
 838          confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
 839      }
 840  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1