[ Index ]

PHP Cross Reference of phpBB-3.3.7-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",
 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;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;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      $topic_row = [
 383          'TOPIC_TITLE'        => $topic_info['topic_title'],
 384          'U_VIEW_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", '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", '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", "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       * Event to modify the template data block for topic data output in the MCP
 427       *
 428       * @event core.mcp_topic_review_modify_topic_row
 429       * @var    string    action                    Moderation action type to be performed with the topic
 430       * @var    bool    has_unapproved_posts    Flag indicating if the topic has unapproved posts
 431       * @var    int        icon_id                    Split topic icon ID
 432       * @var    int        id                        ID of the tab we are displaying
 433       * @var    string    mode                    Mode of the MCP page we are displaying
 434       * @var    int        topic_id                The topic ID we are currently reviewing
 435       * @var    int        forum_id                The forum ID we are currently in
 436       * @var    bool    s_topic_icons            Flag indicating if split topic icon to be displayed
 437       * @var    int        start                    Start item of this page
 438       * @var    string    subject                    Subject of the topic to be split
 439       * @var    array    topic_info                Array with topic data
 440       * @var    int        to_forum_id                Forum id the topic is being moved to
 441       * @var    int        to_topic_id                Topic ID the topic is being merged with
 442       * @var    array    topic_row                Topic template data array
 443       * @var    int        total                    Total posts count
 444       * @since 3.3.5-RC1
 445       */
 446      $vars = [
 447          'action',
 448          'has_unapproved_posts',
 449          'icon_id',
 450          'id',
 451          'mode',
 452          'topic_id',
 453          'forum_id',
 454          's_topic_icons',
 455          'start',
 456          'subject',
 457          'topic_info',
 458          'to_forum_id',
 459          'to_topic_id',
 460          'topic_row',
 461          'total',
 462      ];
 463      extract($phpbb_dispatcher->trigger_event('core.mcp_topic_review_modify_topic_row', compact($vars)));
 464  
 465      $template->assign_vars($topic_row);
 466  }
 467  
 468  /**
 469  * Split topic
 470  */
 471  function split_topic($action, $topic_id, $to_forum_id, $subject)
 472  {
 473      global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config, $phpbb_log, $request, $phpbb_dispatcher;
 474  
 475      $post_id_list    = $request->variable('post_id_list', array(0));
 476      $forum_id        = $request->variable('forum_id', 0);
 477      $start            = $request->variable('start', 0);
 478  
 479      if (!count($post_id_list))
 480      {
 481          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 482          return;
 483      }
 484  
 485      if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_split')))
 486      {
 487          return;
 488      }
 489  
 490      $post_id = $post_id_list[0];
 491      $post_info = phpbb_get_post_data(array($post_id));
 492  
 493      if (!count($post_info))
 494      {
 495          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 496          return;
 497      }
 498  
 499      $post_info = $post_info[$post_id];
 500      $subject = trim($subject);
 501  
 502      /**
 503       * Replace Emojis and other 4bit UTF-8 chars not allowed by MySQL to UCR/NCR.
 504       * Using their Numeric Character Reference's Hexadecimal notation.
 505       */
 506      $subject = utf8_encode_ucr($subject);
 507  
 508      // Make some tests
 509      if (!$subject)
 510      {
 511          $template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']);
 512          return;
 513      }
 514  
 515      if ($to_forum_id <= 0)
 516      {
 517          $template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']);
 518          return;
 519      }
 520  
 521      $forum_info = phpbb_get_forum_data(array($to_forum_id), 'f_post');
 522  
 523      if (!count($forum_info))
 524      {
 525          $template->assign_var('MESSAGE', $user->lang['USER_CANNOT_POST']);
 526          return;
 527      }
 528  
 529      $forum_info = $forum_info[$to_forum_id];
 530  
 531      if ($forum_info['forum_type'] != FORUM_POST)
 532      {
 533          $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']);
 534          return;
 535      }
 536  
 537      $redirect = $request->variable('redirect', build_url(array('quickmod')));
 538  
 539      $s_hidden_fields = build_hidden_fields(array(
 540          'i'                => 'main',
 541          'post_id_list'    => $post_id_list,
 542          'f'                => $forum_id,
 543          'mode'            => 'topic_view',
 544          'start'            => $start,
 545          'action'        => $action,
 546          't'                => $topic_id,
 547          'redirect'        => $redirect,
 548          'subject'        => $subject,
 549          'to_forum_id'    => $to_forum_id,
 550          'icon'            => $request->variable('icon', 0))
 551      );
 552  
 553      if (confirm_box(true))
 554      {
 555          if ($action == 'split_beyond')
 556          {
 557              $sort_days = $total = 0;
 558              $sort_key = $sort_dir = '';
 559              $sort_by_sql = $sort_order_sql = array();
 560              phpbb_mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
 561  
 562              $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 563  
 564              if ($sort_order_sql[0] == 'u')
 565              {
 566                  $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
 567                      FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
 568                      WHERE p.topic_id = $topic_id
 569                          AND p.poster_id = u.user_id
 570                          $limit_time_sql
 571                      ORDER BY $sort_order_sql";
 572              }
 573              else
 574              {
 575                  $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
 576                      FROM ' . POSTS_TABLE . " p
 577                      WHERE p.topic_id = $topic_id
 578                          $limit_time_sql
 579                      ORDER BY $sort_order_sql";
 580              }
 581              $result = $db->sql_query_limit($sql, 0, $start);
 582  
 583              $store = false;
 584              $post_id_list = array();
 585              while ($row = $db->sql_fetchrow($result))
 586              {
 587                  // If split from selected post (split_beyond), we split the unapproved items too.
 588                  if (($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE) && !$auth->acl_get('m_approve', $row['forum_id']))
 589                  {
 590  //                    continue;
 591                  }
 592  
 593                  // Start to store post_ids as soon as we see the first post that was selected
 594                  if ($row['post_id'] == $post_id)
 595                  {
 596                      $store = true;
 597                  }
 598  
 599                  if ($store)
 600                  {
 601                      $post_id_list[] = $row['post_id'];
 602                  }
 603              }
 604              $db->sql_freeresult($result);
 605          }
 606  
 607          if (!count($post_id_list))
 608          {
 609              trigger_error('NO_POST_SELECTED');
 610          }
 611  
 612          $icon_id = $request->variable('icon', 0);
 613  
 614          $sql_ary = array(
 615              'forum_id'            => $to_forum_id,
 616              'topic_title'        => $subject,
 617              'icon_id'            => $icon_id,
 618              'topic_visibility'    => 1
 619          );
 620  
 621          $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 622          $db->sql_query($sql);
 623  
 624          $to_topic_id = $db->sql_nextid();
 625          move_posts($post_id_list, $to_topic_id);
 626  
 627          $topic_info = phpbb_get_topic_data(array($topic_id));
 628          $topic_info = $topic_info[$topic_id];
 629  
 630          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SPLIT_DESTINATION', false, array(
 631              'forum_id' => $to_forum_id,
 632              'topic_id' => $to_topic_id,
 633              $subject
 634          ));
 635          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SPLIT_SOURCE', false, array(
 636              'forum_id' => $forum_id,
 637              'topic_id' => $topic_id,
 638              $topic_info['topic_title']
 639          ));
 640  
 641          // Change topic title of first post
 642          $sql = 'UPDATE ' . POSTS_TABLE . "
 643              SET post_subject = '" . $db->sql_escape($subject) . "'
 644              WHERE post_id = {$post_id_list[0]}";
 645          $db->sql_query($sql);
 646  
 647          // Grab data for first post in split topic
 648          $sql_array = array(
 649              'SELECT'  => 'p.post_id, p.forum_id, p.poster_id, p.post_text, f.enable_indexing',
 650              'FROM' => array(
 651                  POSTS_TABLE => 'p',
 652              ),
 653              'LEFT_JOIN' => array(
 654                  array(
 655                      'FROM' => array(FORUMS_TABLE => 'f'),
 656                      'ON' => 'p.forum_id = f.forum_id',
 657                  )
 658              ),
 659              'WHERE' => "post_id = {$post_id_list[0]}",
 660          );
 661          $sql = $db->sql_build_query('SELECT', $sql_array);
 662          $result = $db->sql_query($sql);
 663          $first_post_data = $db->sql_fetchrow($result);
 664          $db->sql_freeresult($result);
 665  
 666          // Index first post as if it were edited
 667          if ($first_post_data['enable_indexing'])
 668          {
 669              // Select the search method and do some additional checks to ensure it can actually be utilised
 670              $search_type = $config['search_type'];
 671  
 672              if (!class_exists($search_type))
 673              {
 674                  trigger_error('NO_SUCH_SEARCH_MODULE');
 675              }
 676  
 677              $error = false;
 678              $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
 679  
 680              if ($error)
 681              {
 682                  trigger_error($error);
 683              }
 684  
 685              $search->index('edit', $first_post_data['post_id'], $first_post_data['post_text'], $subject, $first_post_data['poster_id'], $first_post_data['forum_id']);
 686          }
 687  
 688          // Copy topic subscriptions to new topic
 689          $sql = 'SELECT user_id, notify_status
 690              FROM ' . TOPICS_WATCH_TABLE . '
 691              WHERE topic_id = ' . $topic_id;
 692          $result = $db->sql_query($sql);
 693  
 694          $sql_ary = array();
 695          while ($row = $db->sql_fetchrow($result))
 696          {
 697              $sql_ary[] = array(
 698                  'topic_id'        => (int) $to_topic_id,
 699                  'user_id'        => (int) $row['user_id'],
 700                  'notify_status'    => (int) $row['notify_status'],
 701              );
 702          }
 703          $db->sql_freeresult($result);
 704  
 705          if (count($sql_ary))
 706          {
 707              $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
 708          }
 709  
 710          // Copy bookmarks to new topic
 711          $sql = 'SELECT user_id
 712              FROM ' . BOOKMARKS_TABLE . '
 713              WHERE topic_id = ' . $topic_id;
 714          $result = $db->sql_query($sql);
 715  
 716          $sql_ary = array();
 717          while ($row = $db->sql_fetchrow($result))
 718          {
 719              $sql_ary[] = array(
 720                  'topic_id'        => (int) $to_topic_id,
 721                  'user_id'        => (int) $row['user_id'],
 722              );
 723          }
 724          $db->sql_freeresult($result);
 725  
 726          if (count($sql_ary))
 727          {
 728              $db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary);
 729          }
 730  
 731          $success_msg = 'TOPIC_SPLIT_SUCCESS';
 732  
 733          // Update forum statistics
 734          $config->increment('num_topics', 1, false);
 735  
 736          // Link back to both topics
 737          $return_link = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $post_info['topic_id']) . '">', '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $to_topic_id) . '">', '</a>');
 738          $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?t=$to_topic_id");
 739          $redirect = reapply_sid($redirect);
 740  
 741          /**
 742           * Event to access topic data after split
 743           *
 744           * @event core.mcp_topic_split_topic_after
 745           * @var    string    action            Split action type to be performed with the topic
 746           * @var    int        topic_id        The topic ID we are currently splitting
 747           * @var    int        forum_id        The forum ID we are currently in
 748           * @var    int        start            Start item of this page
 749           * @var    string    subject            Subject of the topic to be split
 750           * @var    array    topic_info        Array with topic data
 751           * @var    int        to_forum_id        Forum id the topic is being moved to
 752           * @var    int        to_topic_id        Topic ID the topic is being split to
 753           * @since 3.3.5-RC1
 754           */
 755          $vars = [
 756              'action',
 757              'topic_id',
 758              'forum_id',
 759              'start',
 760              'subject',
 761              'topic_info',
 762              'to_forum_id',
 763              'to_topic_id',
 764          ];
 765          extract($phpbb_dispatcher->trigger_event('core.mcp_topic_split_topic_after', compact($vars)));
 766  
 767          meta_refresh(3, $redirect);
 768          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 769      }
 770      else
 771      {
 772          confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields);
 773      }
 774  }
 775  
 776  /**
 777  * Merge selected posts into selected topic
 778  */
 779  function merge_posts($topic_id, $to_topic_id)
 780  {
 781      global $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_log, $request, $phpbb_dispatcher;
 782  
 783      if (!$to_topic_id)
 784      {
 785          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 786          return;
 787      }
 788  
 789      $sync_topics = array($topic_id, $to_topic_id);
 790  
 791      $topic_data = phpbb_get_topic_data($sync_topics, 'm_merge');
 792  
 793      if (!count($topic_data) || empty($topic_data[$to_topic_id]))
 794      {
 795          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 796          return;
 797      }
 798  
 799      $sync_forums = array();
 800      foreach ($topic_data as $data)
 801      {
 802          $sync_forums[$data['forum_id']] = $data['forum_id'];
 803      }
 804  
 805      $topic_data = $topic_data[$to_topic_id];
 806  
 807      $post_id_list    = $request->variable('post_id_list', array(0));
 808      $start            = $request->variable('start', 0);
 809  
 810      if (!count($post_id_list))
 811      {
 812          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 813          return;
 814      }
 815  
 816      if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
 817      {
 818          return;
 819      }
 820  
 821      $redirect = $request->variable('redirect', build_url(array('quickmod')));
 822  
 823      $s_hidden_fields = build_hidden_fields(array(
 824          'i'                => 'main',
 825          'post_id_list'    => $post_id_list,
 826          'to_topic_id'    => $to_topic_id,
 827          'mode'            => 'topic_view',
 828          'action'        => 'merge_posts',
 829          'start'            => $start,
 830          'redirect'        => $redirect,
 831          't'                => $topic_id)
 832      );
 833      $return_link = '';
 834  
 835      if (confirm_box(true))
 836      {
 837          $to_forum_id = $topic_data['forum_id'];
 838  
 839          move_posts($post_id_list, $to_topic_id, false);
 840  
 841          $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MERGE', false, array(
 842              'forum_id' => $to_forum_id,
 843              'topic_id' => $to_topic_id,
 844              $topic_data['topic_title']
 845          ));
 846  
 847          // Message and return links
 848          $success_msg = 'POSTS_MERGED_SUCCESS';
 849  
 850          // Does the original topic still exist? If yes, link back to it
 851          $sql = 'SELECT forum_id
 852              FROM ' . POSTS_TABLE . '
 853              WHERE topic_id = ' . $topic_id;
 854          $result = $db->sql_query_limit($sql, 1);
 855          $row = $db->sql_fetchrow($result);
 856          $db->sql_freeresult($result);
 857  
 858          if ($row)
 859          {
 860              $return_link .= sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) . '">', '</a>');
 861          }
 862          else
 863          {
 864              if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
 865              {
 866                  include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
 867              }
 868  
 869              // If the topic no longer exist, we will update the topic watch table.
 870              phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', array($topic_id), $to_topic_id);
 871  
 872              // If the topic no longer exist, we will update the bookmarks table.
 873              phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', array($topic_id), $to_topic_id);
 874          }
 875  
 876          // Re-sync the topics and forums because the auto-sync was deactivated in the call of move_posts()
 877          sync('topic_reported', 'topic_id', $sync_topics);
 878          sync('topic_attachment', 'topic_id', $sync_topics);
 879          sync('topic', 'topic_id', $sync_topics, true);
 880          sync('forum', 'forum_id', $sync_forums, true, true);
 881  
 882          // Link to the new topic
 883          $return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $to_topic_id) . '">', '</a>');
 884          $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?t=$to_topic_id");
 885          $redirect = reapply_sid($redirect);
 886  
 887          /**
 888           * Perform additional actions after merging posts.
 889           *
 890           * @event core.mcp_topics_merge_posts_after
 891           * @var    int        topic_id        The topic ID from which posts are being moved
 892           * @var    int        to_topic_id        The topic ID to which posts are being moved
 893           * @since 3.1.11-RC1
 894           */
 895          $vars = array(
 896              'topic_id',
 897              'to_topic_id',
 898          );
 899          extract($phpbb_dispatcher->trigger_event('core.mcp_topics_merge_posts_after', compact($vars)));
 900  
 901          meta_refresh(3, $redirect);
 902          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 903      }
 904      else
 905      {
 906          confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
 907      }
 908  }


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