[ Index ]

PHP Cross Reference of phpBB-3.3.0-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 $current_row_number => $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[$current_row_number]);
 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      // Make some tests
 461      if (!$subject)
 462      {
 463          $template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']);
 464          return;
 465      }
 466  
 467      if ($to_forum_id <= 0)
 468      {
 469          $template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']);
 470          return;
 471      }
 472  
 473      $forum_info = phpbb_get_forum_data(array($to_forum_id), 'f_post');
 474  
 475      if (!count($forum_info))
 476      {
 477          $template->assign_var('MESSAGE', $user->lang['USER_CANNOT_POST']);
 478          return;
 479      }
 480  
 481      $forum_info = $forum_info[$to_forum_id];
 482  
 483      if ($forum_info['forum_type'] != FORUM_POST)
 484      {
 485          $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']);
 486          return;
 487      }
 488  
 489      $redirect = $request->variable('redirect', build_url(array('quickmod')));
 490  
 491      $s_hidden_fields = build_hidden_fields(array(
 492          'i'                => 'main',
 493          'post_id_list'    => $post_id_list,
 494          'f'                => $forum_id,
 495          'mode'            => 'topic_view',
 496          'start'            => $start,
 497          'action'        => $action,
 498          't'                => $topic_id,
 499          'redirect'        => $redirect,
 500          'subject'        => $subject,
 501          'to_forum_id'    => $to_forum_id,
 502          'icon'            => $request->variable('icon', 0))
 503      );
 504  
 505      if (confirm_box(true))
 506      {
 507          if ($action == 'split_beyond')
 508          {
 509              $sort_days = $total = 0;
 510              $sort_key = $sort_dir = '';
 511              $sort_by_sql = $sort_order_sql = array();
 512              phpbb_mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
 513  
 514              $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 515  
 516              if ($sort_order_sql[0] == 'u')
 517              {
 518                  $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
 519                      FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
 520                      WHERE p.topic_id = $topic_id
 521                          AND p.poster_id = u.user_id
 522                          $limit_time_sql
 523                      ORDER BY $sort_order_sql";
 524              }
 525              else
 526              {
 527                  $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
 528                      FROM ' . POSTS_TABLE . " p
 529                      WHERE p.topic_id = $topic_id
 530                          $limit_time_sql
 531                      ORDER BY $sort_order_sql";
 532              }
 533              $result = $db->sql_query_limit($sql, 0, $start);
 534  
 535              $store = false;
 536              $post_id_list = array();
 537              while ($row = $db->sql_fetchrow($result))
 538              {
 539                  // If split from selected post (split_beyond), we split the unapproved items too.
 540                  if (($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE) && !$auth->acl_get('m_approve', $row['forum_id']))
 541                  {
 542  //                    continue;
 543                  }
 544  
 545                  // Start to store post_ids as soon as we see the first post that was selected
 546                  if ($row['post_id'] == $post_id)
 547                  {
 548                      $store = true;
 549                  }
 550  
 551                  if ($store)
 552                  {
 553                      $post_id_list[] = $row['post_id'];
 554                  }
 555              }
 556              $db->sql_freeresult($result);
 557          }
 558  
 559          if (!count($post_id_list))
 560          {
 561              trigger_error('NO_POST_SELECTED');
 562          }
 563  
 564          $icon_id = $request->variable('icon', 0);
 565  
 566          $sql_ary = array(
 567              'forum_id'            => $to_forum_id,
 568              'topic_title'        => $subject,
 569              'icon_id'            => $icon_id,
 570              'topic_visibility'    => 1
 571          );
 572  
 573          $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 574          $db->sql_query($sql);
 575  
 576          $to_topic_id = $db->sql_nextid();
 577          move_posts($post_id_list, $to_topic_id);
 578  
 579          $topic_info = phpbb_get_topic_data(array($topic_id));
 580          $topic_info = $topic_info[$topic_id];
 581  
 582          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SPLIT_DESTINATION', false, array(
 583              'forum_id' => $to_forum_id,
 584              'topic_id' => $to_topic_id,
 585              $subject
 586          ));
 587          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SPLIT_SOURCE', false, array(
 588              'forum_id' => $forum_id,
 589              'topic_id' => $topic_id,
 590              $topic_info['topic_title']
 591          ));
 592  
 593          // Change topic title of first post
 594          $sql = 'UPDATE ' . POSTS_TABLE . "
 595              SET post_subject = '" . $db->sql_escape($subject) . "'
 596              WHERE post_id = {$post_id_list[0]}";
 597          $db->sql_query($sql);
 598  
 599          // Grab data for first post in split topic
 600          $sql_array = array(
 601              'SELECT'  => 'p.post_id, p.forum_id, p.poster_id, p.post_text, f.enable_indexing',
 602              'FROM' => array(
 603                  POSTS_TABLE => 'p',
 604              ),
 605              'LEFT_JOIN' => array(
 606                  array(
 607                      'FROM' => array(FORUMS_TABLE => 'f'),
 608                      'ON' => 'p.forum_id = f.forum_id',
 609                  )
 610              ),
 611              'WHERE' => "post_id = {$post_id_list[0]}",
 612          );
 613          $sql = $db->sql_build_query('SELECT', $sql_array);
 614          $result = $db->sql_query($sql);
 615          $first_post_data = $db->sql_fetchrow($result);
 616          $db->sql_freeresult($result);
 617  
 618          // Index first post as if it were edited
 619          if ($first_post_data['enable_indexing'])
 620          {
 621              // Select the search method and do some additional checks to ensure it can actually be utilised
 622              $search_type = $config['search_type'];
 623  
 624              if (!class_exists($search_type))
 625              {
 626                  trigger_error('NO_SUCH_SEARCH_MODULE');
 627              }
 628  
 629              $error = false;
 630              $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
 631  
 632              if ($error)
 633              {
 634                  trigger_error($error);
 635              }
 636  
 637              $search->index('edit', $first_post_data['post_id'], $first_post_data['post_text'], $subject, $first_post_data['poster_id'], $first_post_data['forum_id']);
 638          }
 639  
 640          // Copy topic subscriptions to new topic
 641          $sql = 'SELECT user_id, notify_status
 642              FROM ' . TOPICS_WATCH_TABLE . '
 643              WHERE topic_id = ' . $topic_id;
 644          $result = $db->sql_query($sql);
 645  
 646          $sql_ary = array();
 647          while ($row = $db->sql_fetchrow($result))
 648          {
 649              $sql_ary[] = array(
 650                  'topic_id'        => (int) $to_topic_id,
 651                  'user_id'        => (int) $row['user_id'],
 652                  'notify_status'    => (int) $row['notify_status'],
 653              );
 654          }
 655          $db->sql_freeresult($result);
 656  
 657          if (count($sql_ary))
 658          {
 659              $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
 660          }
 661  
 662          // Copy bookmarks to new topic
 663          $sql = 'SELECT user_id
 664              FROM ' . BOOKMARKS_TABLE . '
 665              WHERE topic_id = ' . $topic_id;
 666          $result = $db->sql_query($sql);
 667  
 668          $sql_ary = array();
 669          while ($row = $db->sql_fetchrow($result))
 670          {
 671              $sql_ary[] = array(
 672                  'topic_id'        => (int) $to_topic_id,
 673                  'user_id'        => (int) $row['user_id'],
 674              );
 675          }
 676          $db->sql_freeresult($result);
 677  
 678          if (count($sql_ary))
 679          {
 680              $db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary);
 681          }
 682  
 683          $success_msg = 'TOPIC_SPLIT_SUCCESS';
 684  
 685          // Update forum statistics
 686          $config->increment('num_topics', 1, false);
 687  
 688          // Link back to both topics
 689          $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>');
 690          $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&amp;t=$to_topic_id");
 691          $redirect = reapply_sid($redirect);
 692  
 693          meta_refresh(3, $redirect);
 694          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 695      }
 696      else
 697      {
 698          confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields);
 699      }
 700  }
 701  
 702  /**
 703  * Merge selected posts into selected topic
 704  */
 705  function merge_posts($topic_id, $to_topic_id)
 706  {
 707      global $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_log, $request, $phpbb_dispatcher;
 708  
 709      if (!$to_topic_id)
 710      {
 711          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 712          return;
 713      }
 714  
 715      $sync_topics = array($topic_id, $to_topic_id);
 716  
 717      $topic_data = phpbb_get_topic_data($sync_topics, 'm_merge');
 718  
 719      if (!count($topic_data) || empty($topic_data[$to_topic_id]))
 720      {
 721          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 722          return;
 723      }
 724  
 725      $sync_forums = array();
 726      foreach ($topic_data as $data)
 727      {
 728          $sync_forums[$data['forum_id']] = $data['forum_id'];
 729      }
 730  
 731      $topic_data = $topic_data[$to_topic_id];
 732  
 733      $post_id_list    = $request->variable('post_id_list', array(0));
 734      $start            = $request->variable('start', 0);
 735  
 736      if (!count($post_id_list))
 737      {
 738          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 739          return;
 740      }
 741  
 742      if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
 743      {
 744          return;
 745      }
 746  
 747      $redirect = $request->variable('redirect', build_url(array('quickmod')));
 748  
 749      $s_hidden_fields = build_hidden_fields(array(
 750          'i'                => 'main',
 751          'post_id_list'    => $post_id_list,
 752          'to_topic_id'    => $to_topic_id,
 753          'mode'            => 'topic_view',
 754          'action'        => 'merge_posts',
 755          'start'            => $start,
 756          'redirect'        => $redirect,
 757          't'                => $topic_id)
 758      );
 759      $return_link = '';
 760  
 761      if (confirm_box(true))
 762      {
 763          $to_forum_id = $topic_data['forum_id'];
 764  
 765          move_posts($post_id_list, $to_topic_id, false);
 766  
 767          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MERGE', false, array(
 768              'forum_id' => $to_forum_id,
 769              'topic_id' => $to_topic_id,
 770              $topic_data['topic_title']
 771          ));
 772  
 773          // Message and return links
 774          $success_msg = 'POSTS_MERGED_SUCCESS';
 775  
 776          // Does the original topic still exist? If yes, link back to it
 777          $sql = 'SELECT forum_id
 778              FROM ' . POSTS_TABLE . '
 779              WHERE topic_id = ' . $topic_id;
 780          $result = $db->sql_query_limit($sql, 1);
 781          $row = $db->sql_fetchrow($result);
 782          $db->sql_freeresult($result);
 783  
 784          if ($row)
 785          {
 786              $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>');
 787          }
 788          else
 789          {
 790              if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
 791              {
 792                  include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
 793              }
 794  
 795              // If the topic no longer exist, we will update the topic watch table.
 796              phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', array($topic_id), $to_topic_id);
 797  
 798              // If the topic no longer exist, we will update the bookmarks table.
 799              phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', array($topic_id), $to_topic_id);
 800          }
 801  
 802          // Re-sync the topics and forums because the auto-sync was deactivated in the call of move_posts()
 803          sync('topic_reported', 'topic_id', $sync_topics);
 804          sync('topic_attachment', 'topic_id', $sync_topics);
 805          sync('topic', 'topic_id', $sync_topics, true);
 806          sync('forum', 'forum_id', $sync_forums, true, true);
 807  
 808          // Link to the new topic
 809          $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>');
 810          $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&amp;t=$to_topic_id");
 811          $redirect = reapply_sid($redirect);
 812  
 813          /**
 814           * Perform additional actions after merging posts.
 815           *
 816           * @event core.mcp_topics_merge_posts_after
 817           * @var    int        topic_id        The topic ID from which posts are being moved
 818           * @var    int        to_topic_id        The topic ID to which posts are being moved
 819           * @since 3.1.11-RC1
 820           */
 821          $vars = array(
 822              'topic_id',
 823              'to_topic_id',
 824          );
 825          extract($phpbb_dispatcher->trigger_event('core.mcp_topics_merge_posts_after', compact($vars)));
 826  
 827          meta_refresh(3, $redirect);
 828          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 829      }
 830      else
 831      {
 832          confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
 833      }
 834  }


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