Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

mcp_topic.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 22.66 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  /**
 015  * @ignore
 016  */
 017  if (!defined('IN_PHPBB'))
 018  {
 019      exit;
 020  }
 021   
 022  /**
 023  * View topic in MCP
 024  */
 025  function mcp_topic_view($id, $mode, $action)
 026  {
 027      global $phpEx, $phpbb_root_path, $config;
 028      global $template, $db, $user, $auth, $cache, $phpbb_container;
 029   
 030      $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . phpbb_extra_url());
 031   
 032      $user->add_lang('viewtopic');
 033      $pagination = $phpbb_container->get('pagination');
 034   
 035      $topic_id = request_var('t', 0);
 036      $topic_info = phpbb_get_topic_data(array($topic_id), false, true);
 037   
 038      if (!sizeof($topic_info))
 039      {
 040          trigger_error('TOPIC_NOT_EXIST');
 041      }
 042   
 043      $topic_info = $topic_info[$topic_id];
 044   
 045      // Set up some vars
 046      $icon_id        = request_var('icon', 0);
 047      $subject        = utf8_normalize_nfc(request_var('subject', '', true));
 048      $start            = request_var('start', 0);
 049      $sort_days_old    = request_var('st_old', 0);
 050      $forum_id        = request_var('f', 0);
 051      $to_topic_id    = request_var('to_topic_id', 0);
 052      $to_forum_id    = request_var('to_forum_id', 0);
 053      $sort            = isset($_POST['sort']) ? true : false;
 054      $submitted_id_list    = request_var('post_ids', array(0));
 055      $checked_ids = $post_id_list = request_var('post_id_list', array(0));
 056   
 057      // Resync Topic?
 058      if ($action == 'resync')
 059      {
 060          if (!function_exists('mcp_resync_topics'))
 061          {
 062              include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
 063          }
 064          mcp_resync_topics(array($topic_id));
 065      }
 066   
 067      // Split Topic?
 068      if ($action == 'split_all' || $action == 'split_beyond')
 069      {
 070          if (!$sort)
 071          {
 072              split_topic($action, $topic_id, $to_forum_id, $subject);
 073          }
 074          $action = 'split';
 075      }
 076   
 077      // Merge Posts?
 078      if ($action == 'merge_posts')
 079      {
 080          if (!$sort)
 081          {
 082              merge_posts($topic_id, $to_topic_id);
 083          }
 084          $action = 'merge';
 085      }
 086   
 087      if ($action == 'split' && !$subject)
 088      {
 089          $subject = $topic_info['topic_title'];
 090      }
 091   
 092      // Restore or pprove posts?
 093      if (($action == 'restore' || $action == 'approve') && $auth->acl_get('m_approve', $topic_info['forum_id']))
 094      {
 095          include($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx);
 096          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 097          include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 098   
 099          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      $bbcode_bitfield = '';
 151      while ($row = $db->sql_fetchrow($result))
 152      {
 153          $rowset[] = $row;
 154          $post_id_list[] = $row['post_id'];
 155          $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
 156      }
 157      $db->sql_freeresult($result);
 158   
 159      if ($bbcode_bitfield !== '')
 160      {
 161          include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 162          $bbcode = new bbcode(base64_encode($bbcode_bitfield));
 163      }
 164   
 165      $topic_tracking_info = array();
 166   
 167      // Get topic tracking info
 168      if ($config['load_db_lastread'])
 169      {
 170          $tmp_topic_data = array($topic_id => $topic_info);
 171          $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']));
 172          unset($tmp_topic_data);
 173      }
 174      else
 175      {
 176          $topic_tracking_info = get_complete_topic_tracking($topic_info['forum_id'], $topic_id);
 177      }
 178   
 179      $has_unapproved_posts = $has_deleted_posts = false;
 180   
 181      // Grab extensions
 182      $extensions = $attachments = array();
 183      if ($topic_info['topic_attachment'] && sizeof($post_id_list))
 184      {
 185          $extensions = $cache->obtain_attach_extensions($topic_info['forum_id']);
 186   
 187          // Get attachments...
 188          if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_info['forum_id']))
 189          {
 190              $sql = 'SELECT *
 191                  FROM ' . ATTACHMENTS_TABLE . '
 192                  WHERE ' . $db->sql_in_set('post_msg_id', $post_id_list) . '
 193                      AND in_message = 0
 194                  ORDER BY filetime DESC, post_msg_id ASC';
 195              $result = $db->sql_query($sql);
 196   
 197              while ($row = $db->sql_fetchrow($result))
 198              {
 199                  $attachments[$row['post_msg_id']][] = $row;
 200              }
 201              $db->sql_freeresult($result);
 202          }
 203      }
 204   
 205      foreach ($rowset as $i => $row)
 206      {
 207          $message = $row['post_text'];
 208          $post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title'];
 209   
 210          $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
 211          $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, false);
 212   
 213          if (!empty($attachments[$row['post_id']]))
 214          {
 215              $update_count = array();
 216              parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count);
 217          }
 218   
 219          if ($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE)
 220          {
 221              $has_unapproved_posts = true;
 222          }
 223   
 224          if ($row['post_visibility'] == ITEM_DELETED)
 225          {
 226              $has_deleted_posts = true;
 227          }
 228   
 229          $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
 230   
 231          $template->assign_block_vars('postrow', array(
 232              'POST_AUTHOR_FULL'        => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 233              'POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 234              'POST_AUTHOR'            => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 235              'U_POST_AUTHOR'            => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 236   
 237              'POST_DATE'        => $user->format_date($row['post_time']),
 238              'POST_SUBJECT'    => $post_subject,
 239              'MESSAGE'        => $message,
 240              'POST_ID'        => $row['post_id'],
 241              'RETURN_TOPIC'    => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) . '">', '</a>'),
 242   
 243              'MINI_POST_IMG'            => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
 244   
 245              'S_POST_REPORTED'    => ($row['post_reported'] && $auth->acl_get('m_report', $topic_info['forum_id'])),
 246              'S_POST_UNAPPROVED'    => (($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $topic_info['forum_id'])),
 247              'S_POST_DELETED'    => ($row['post_visibility'] == ITEM_DELETED && $auth->acl_get('m_approve', $topic_info['forum_id'])),
 248              'S_CHECKED'            => (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false,
 249              'S_HAS_ATTACHMENTS'    => (!empty($attachments[$row['post_id']])) ? true : false,
 250   
 251              'U_POST_DETAILS'    => "$url&amp;i=$id&amp;p={$row['post_id']}&amp;mode=post_details" . (($forum_id) ? "&amp;f=$forum_id" : ''),
 252              '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']) : '',
 253              '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']) : '')
 254          );
 255   
 256          // Display not already displayed Attachments for this post, we already parsed them. ;)
 257          if (!empty($attachments[$row['post_id']]))
 258          {
 259              foreach ($attachments[$row['post_id']] as $attachment)
 260              {
 261                  $template->assign_block_vars('postrow.attachment', array(
 262                      'DISPLAY_ATTACHMENT'    => $attachment)
 263                  );
 264              }
 265          }
 266   
 267          unset($rowset[$i]);
 268      }
 269   
 270      // Display topic icons for split topic
 271      $s_topic_icons = false;
 272   
 273      if ($auth->acl_gets('m_split', 'm_merge', (int) $topic_info['forum_id']))
 274      {
 275          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 276          $s_topic_icons = posting_gen_topic_icons('', $icon_id);
 277   
 278          // Has the user selected a topic for merge?
 279          if ($to_topic_id)
 280          {
 281              $to_topic_info = phpbb_get_topic_data(array($to_topic_id), 'm_merge');
 282   
 283              if (!sizeof($to_topic_info))
 284              {
 285                  $to_topic_id = 0;
 286              }
 287              else
 288              {
 289                  $to_topic_info = $to_topic_info[$to_topic_id];
 290   
 291                  if (!$to_topic_info['enable_icons'] || $auth->acl_get('!f_icons', $topic_info['forum_id']))
 292                  {
 293                      $s_topic_icons = false;
 294                  }
 295              }
 296          }
 297      }
 298   
 299      $s_hidden_fields = build_hidden_fields(array(
 300          'st_old'    => $sort_days,
 301          'post_ids'    => $post_id_list,
 302      ));
 303   
 304      $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");
 305      if ($posts_per_page)
 306      {
 307          $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $posts_per_page, $start);
 308      }
 309   
 310      $template->assign_vars(array(
 311          'TOPIC_TITLE'        => $topic_info['topic_title'],
 312          'U_VIEW_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&amp;t=' . $topic_info['topic_id']),
 313   
 314          'TO_TOPIC_ID'        => $to_topic_id,
 315          '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>') : '',
 316   
 317          'SPLIT_SUBJECT'        => $subject,
 318          'POSTS_PER_PAGE'    => $posts_per_page,
 319          'ACTION'            => $action,
 320   
 321          'REPORTED_IMG'        => $user->img('icon_topic_reported', 'POST_REPORTED'),
 322          'UNAPPROVED_IMG'    => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
 323          'DELETED_IMG'        => $user->img('icon_topic_deleted', 'POST_DELETED_RESTORE'),
 324          'INFO_IMG'            => $user->img('icon_post_info', 'VIEW_INFO'),
 325   
 326          'S_MCP_ACTION'        => "$url&amp;i=$id&amp;mode=$mode&amp;action=$action&amp;start=$start",
 327          '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),
 328          'S_CAN_SPLIT'        => ($auth->acl_get('m_split', $topic_info['forum_id'])) ? true : false,
 329          'S_CAN_MERGE'        => ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? true : false,
 330          'S_CAN_DELETE'        => ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? true : false,
 331          'S_CAN_APPROVE'        => ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false,
 332          'S_CAN_RESTORE'        => ($has_deleted_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false,
 333          'S_CAN_LOCK'        => ($auth->acl_get('m_lock', $topic_info['forum_id'])) ? true : false,
 334          'S_CAN_REPORT'        => ($auth->acl_get('m_report', $topic_info['forum_id'])) ? true : false,
 335          'S_CAN_SYNC'        => $auth->acl_get('m_', $topic_info['forum_id']),
 336          'S_REPORT_VIEW'        => ($action == 'reports') ? true : false,
 337          'S_MERGE_VIEW'        => ($action == 'merge') ? true : false,
 338          'S_SPLIT_VIEW'        => ($action == 'split') ? true : false,
 339   
 340          'S_HIDDEN_FIELDS'    => $s_hidden_fields,
 341   
 342          'S_SHOW_TOPIC_ICONS'    => $s_topic_icons,
 343          'S_TOPIC_ICON'            => $icon_id,
 344   
 345          'U_SELECT_TOPIC'    => "$url&amp;i=$id&amp;mode=forum_view&amp;action=merge_select" . (($forum_id) ? "&amp;f=$forum_id" : ''),
 346   
 347          '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>'),
 348          '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>'),
 349   
 350          'TOTAL_POSTS'        => $user->lang('VIEW_TOPIC_POSTS', (int) $total),
 351      ));
 352  }
 353   
 354  /**
 355  * Split topic
 356  */
 357  function split_topic($action, $topic_id, $to_forum_id, $subject)
 358  {
 359      global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config;
 360   
 361      $post_id_list    = request_var('post_id_list', array(0));
 362      $forum_id        = request_var('forum_id', 0);
 363      $start            = request_var('start', 0);
 364   
 365      if (!sizeof($post_id_list))
 366      {
 367          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 368          return;
 369      }
 370   
 371      if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_split')))
 372      {
 373          return;
 374      }
 375   
 376      $post_id = $post_id_list[0];
 377      $post_info = phpbb_get_post_data(array($post_id));
 378   
 379      if (!sizeof($post_info))
 380      {
 381          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 382          return;
 383      }
 384   
 385      $post_info = $post_info[$post_id];
 386      $subject = trim($subject);
 387   
 388      // Make some tests
 389      if (!$subject)
 390      {
 391          $template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']);
 392          return;
 393      }
 394   
 395      if ($to_forum_id <= 0)
 396      {
 397          $template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']);
 398          return;
 399      }
 400   
 401      $forum_info = phpbb_get_forum_data(array($to_forum_id), 'f_post');
 402   
 403      if (!sizeof($forum_info))
 404      {
 405          $template->assign_var('MESSAGE', $user->lang['USER_CANNOT_POST']);
 406          return;
 407      }
 408   
 409      $forum_info = $forum_info[$to_forum_id];
 410   
 411      if ($forum_info['forum_type'] != FORUM_POST)
 412      {
 413          $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']);
 414          return;
 415      }
 416   
 417      $redirect = request_var('redirect', build_url(array('quickmod')));
 418   
 419      $s_hidden_fields = build_hidden_fields(array(
 420          'i'                => 'main',
 421          'post_id_list'    => $post_id_list,
 422          'f'                => $forum_id,
 423          'mode'            => 'topic_view',
 424          'start'            => $start,
 425          'action'        => $action,
 426          't'                => $topic_id,
 427          'redirect'        => $redirect,
 428          'subject'        => $subject,
 429          'to_forum_id'    => $to_forum_id,
 430          'icon'            => request_var('icon', 0))
 431      );
 432      $success_msg = $return_link = '';
 433   
 434      if (confirm_box(true))
 435      {
 436          if ($action == 'split_beyond')
 437          {
 438              $sort_days = $total = 0;
 439              $sort_key = $sort_dir = '';
 440              $sort_by_sql = $sort_order_sql = array();
 441              phpbb_mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
 442   
 443              $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 444   
 445              if ($sort_order_sql[0] == 'u')
 446              {
 447                  $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
 448                      FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
 449                      WHERE p.topic_id = $topic_id
 450                          AND p.poster_id = u.user_id
 451                          $limit_time_sql
 452                      ORDER BY $sort_order_sql";
 453              }
 454              else
 455              {
 456                  $sql = 'SELECT p.post_id, p.forum_id, p.post_visibility
 457                      FROM ' . POSTS_TABLE . " p
 458                      WHERE p.topic_id = $topic_id
 459                          $limit_time_sql
 460                      ORDER BY $sort_order_sql";
 461              }
 462              $result = $db->sql_query_limit($sql, 0, $start);
 463   
 464              $store = false;
 465              $post_id_list = array();
 466              while ($row = $db->sql_fetchrow($result))
 467              {
 468                  // If split from selected post (split_beyond), we split the unapproved items too.
 469                  if (($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE) && !$auth->acl_get('m_approve', $row['forum_id']))
 470                  {
 471  //                    continue;
 472                  }
 473   
 474                  // Start to store post_ids as soon as we see the first post that was selected
 475                  if ($row['post_id'] == $post_id)
 476                  {
 477                      $store = true;
 478                  }
 479   
 480                  if ($store)
 481                  {
 482                      $post_id_list[] = $row['post_id'];
 483                  }
 484              }
 485              $db->sql_freeresult($result);
 486          }
 487   
 488          if (!sizeof($post_id_list))
 489          {
 490              trigger_error('NO_POST_SELECTED');
 491          }
 492   
 493          $icon_id = request_var('icon', 0);
 494   
 495          $sql_ary = array(
 496              'forum_id'            => $to_forum_id,
 497              'topic_title'        => $subject,
 498              'icon_id'            => $icon_id,
 499              'topic_visibility'    => 1
 500          );
 501   
 502          $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 503          $db->sql_query($sql);
 504   
 505          $to_topic_id = $db->sql_nextid();
 506          move_posts($post_id_list, $to_topic_id);
 507   
 508          $topic_info = phpbb_get_topic_data(array($topic_id));
 509          $topic_info = $topic_info[$topic_id];
 510   
 511          add_log('mod', $to_forum_id, $to_topic_id, 'LOG_SPLIT_DESTINATION', $subject);
 512          add_log('mod', $forum_id, $topic_id, 'LOG_SPLIT_SOURCE', $topic_info['topic_title']);
 513   
 514          // Change topic title of first post
 515          $sql = 'UPDATE ' . POSTS_TABLE . "
 516              SET post_subject = '" . $db->sql_escape($subject) . "'
 517              WHERE post_id = {$post_id_list[0]}";
 518          $db->sql_query($sql);
 519   
 520          // Copy topic subscriptions to new topic
 521          $sql = 'SELECT user_id, notify_status
 522              FROM ' . TOPICS_WATCH_TABLE . '
 523              WHERE topic_id = ' . $topic_id;
 524          $result = $db->sql_query($sql);
 525   
 526          $sql_ary = array();
 527          while ($row = $db->sql_fetchrow($result))
 528          {
 529              $sql_ary[] = array(
 530                  'topic_id'        => (int) $to_topic_id,
 531                  'user_id'        => (int) $row['user_id'],
 532                  'notify_status'    => (int) $row['notify_status'],
 533              );
 534          }
 535          $db->sql_freeresult($result);
 536   
 537          if (sizeof($sql_ary))
 538          {
 539              $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
 540          }
 541   
 542          // Copy bookmarks to new topic
 543          $sql = 'SELECT user_id
 544              FROM ' . BOOKMARKS_TABLE . '
 545              WHERE topic_id = ' . $topic_id;
 546          $result = $db->sql_query($sql);
 547   
 548          $sql_ary = array();
 549          while ($row = $db->sql_fetchrow($result))
 550          {
 551              $sql_ary[] = array(
 552                  'topic_id'        => (int) $to_topic_id,
 553                  'user_id'        => (int) $row['user_id'],
 554              );
 555          }
 556          $db->sql_freeresult($result);
 557   
 558          if (sizeof($sql_ary))
 559          {
 560              $db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary);
 561          }
 562   
 563          $success_msg = 'TOPIC_SPLIT_SUCCESS';
 564   
 565          // Update forum statistics
 566          set_config_count('num_topics', 1, true);
 567   
 568          // Link back to both topics
 569          $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>');
 570          $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&amp;t=$to_topic_id");
 571          $redirect = reapply_sid($redirect);
 572   
 573          meta_refresh(3, $redirect);
 574          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 575      }
 576      else
 577      {
 578          confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields);
 579      }
 580  }
 581   
 582  /**
 583  * Merge selected posts into selected topic
 584  */
 585  function merge_posts($topic_id, $to_topic_id)
 586  {
 587      global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
 588   
 589      if (!$to_topic_id)
 590      {
 591          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 592          return;
 593      }
 594   
 595      $sync_topics = array($topic_id, $to_topic_id);
 596   
 597      $topic_data = phpbb_get_topic_data($sync_topics, 'm_merge');
 598   
 599      if (!sizeof($topic_data) || empty($topic_data[$to_topic_id]))
 600      {
 601          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 602          return;
 603      }
 604   
 605      $sync_forums = array();
 606      foreach ($topic_data as $data)
 607      {
 608          $sync_forums[$data['forum_id']] = $data['forum_id'];
 609      }
 610   
 611      $topic_data = $topic_data[$to_topic_id];
 612   
 613      $post_id_list    = request_var('post_id_list', array(0));
 614      $start            = request_var('start', 0);
 615   
 616      if (!sizeof($post_id_list))
 617      {
 618          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 619          return;
 620      }
 621   
 622      if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
 623      {
 624          return;
 625      }
 626   
 627      $redirect = request_var('redirect', build_url(array('quickmod')));
 628   
 629      $s_hidden_fields = build_hidden_fields(array(
 630          'i'                => 'main',
 631          'post_id_list'    => $post_id_list,
 632          'to_topic_id'    => $to_topic_id,
 633          'mode'            => 'topic_view',
 634          'action'        => 'merge_posts',
 635          'start'            => $start,
 636          'redirect'        => $redirect,
 637          't'                => $topic_id)
 638      );
 639      $success_msg = $return_link = '';
 640   
 641      if (confirm_box(true))
 642      {
 643          $to_forum_id = $topic_data['forum_id'];
 644   
 645          move_posts($post_id_list, $to_topic_id, false);
 646          add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
 647   
 648          // Message and return links
 649          $success_msg = 'POSTS_MERGED_SUCCESS';
 650   
 651          // Does the original topic still exist? If yes, link back to it
 652          $sql = 'SELECT forum_id
 653              FROM ' . POSTS_TABLE . '
 654              WHERE topic_id = ' . $topic_id;
 655          $result = $db->sql_query_limit($sql, 1);
 656          $row = $db->sql_fetchrow($result);
 657          $db->sql_freeresult($result);
 658   
 659          if ($row)
 660          {
 661              $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>');
 662          }
 663          else
 664          {
 665              if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
 666              {
 667                  include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
 668              }
 669   
 670              // If the topic no longer exist, we will update the topic watch table.
 671              phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', array($topic_id), $to_topic_id);
 672   
 673              // If the topic no longer exist, we will update the bookmarks table.
 674              phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', array($topic_id), $to_topic_id);
 675          }
 676   
 677          // Re-sync the topics and forums because the auto-sync was deactivated in the call of move_posts()
 678          sync('topic_reported', 'topic_id', $sync_topics);
 679          sync('topic_attachment', 'topic_id', $sync_topics);
 680          sync('topic', 'topic_id', $sync_topics, true);
 681          sync('forum', 'forum_id', $sync_forums, true, true);
 682   
 683          // Link to the new topic
 684          $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>');
 685          $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&amp;t=$to_topic_id");
 686          $redirect = reapply_sid($redirect);
 687   
 688          meta_refresh(3, $redirect);
 689          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 690      }
 691      else
 692      {
 693          confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
 694      }
 695  }
 696