Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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