[ Index ]

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


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1