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