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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
mcp_forum.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 * MCP Forum View
024 */
025 function mcp_forum_view($id, $mode, $action, $forum_info)
026 {
027 global $template, $db, $user, $auth, $cache, $module;
028 global $phpEx, $phpbb_root_path, $config;
029 global $request, $phpbb_dispatcher, $phpbb_container;
030
031 $user->add_lang(array('viewtopic', 'viewforum'));
032
033 include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
034
035 // merge_topic is the quickmod action, merge_topics is the mcp_forum action, and merge_select is the mcp_topic action
036 $merge_select = ($action == 'merge_select' || $action == 'merge_topic' || $action == 'merge_topics') ? true : false;
037
038 $forum_id = $forum_info['forum_id'];
039 $start = $request->variable('start', 0);
040 $topic_id_list = $request->variable('topic_id_list', array(0));
041 $post_id_list = $request->variable('post_id_list', array(0));
042 $source_topic_ids = array($request->variable('t', 0));
043 $to_topic_id = $request->variable('to_topic_id', 0);
044
045 $url_extra = '';
046 $url_extra .= ($forum_id) ? "&f=$forum_id" : '';
047 $url_extra .= ($GLOBALS['topic_id']) ? '&t=' . $GLOBALS['topic_id'] : '';
048 $url_extra .= ($GLOBALS['post_id']) ? '&p=' . $GLOBALS['post_id'] : '';
049 $url_extra .= ($GLOBALS['user_id']) ? '&u=' . $GLOBALS['user_id'] : '';
050
051 $url = append_sid("{$phpbb_root_path}mcp.$phpEx?$url_extra");
052
053 // Resync Topics
054 switch ($action)
055 {
056 case 'resync':
057 $topic_ids = $request->variable('topic_id_list', array(0));
058 mcp_resync_topics($topic_ids);
059 break;
060
061 case 'merge_topics':
062 $source_topic_ids = $topic_id_list;
063 case 'merge_topic':
064 if ($to_topic_id)
065 {
066 merge_topics($forum_id, $source_topic_ids, $to_topic_id);
067 }
068 break;
069 }
070
071 /**
072 * Get some data in order to execute other actions.
073 *
074 * @event core.mcp_forum_view_before
075 * @var string action The action
076 * @var array forum_info Array with forum infos
077 * @var int start Start value
078 * @var array topic_id_list Array of topics ids
079 * @var array post_id_list Array of posts ids
080 * @var array source_topic_ids Array of source topics ids
081 * @var int to_topic_id Array of destination topics ids
082 * @since 3.1.6-RC1
083 */
084 $vars = array(
085 'action',
086 'forum_info',
087 'start',
088 'topic_id_list',
089 'post_id_list',
090 'source_topic_ids',
091 'to_topic_id',
092 );
093 extract($phpbb_dispatcher->trigger_event('core.mcp_forum_view_before', compact($vars)));
094
095 /* @var $pagination \phpbb\pagination */
096 $pagination = $phpbb_container->get('pagination');
097
098 $selected_ids = '';
099 if (count($post_id_list) && $action != 'merge_topics')
100 {
101 foreach ($post_id_list as $num => $post_id)
102 {
103 $selected_ids .= '&post_id_list[' . $num . ']=' . $post_id;
104 }
105 }
106 else if (count($topic_id_list) && $action == 'merge_topics')
107 {
108 foreach ($topic_id_list as $num => $topic_id)
109 {
110 $selected_ids .= '&topic_id_list[' . $num . ']=' . $topic_id;
111 }
112 }
113
114 make_jumpbox($url . "&i=$id&action=$action&mode=$mode" . (($merge_select) ? $selected_ids : ''), $forum_id, false, 'm_', true);
115
116 $topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page'];
117
118 $sort_days = $total = 0;
119 $sort_key = $sort_dir = '';
120 $sort_by_sql = $sort_order_sql = array();
121 phpbb_mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id);
122
123 $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total;
124 $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
125
126 $base_url = $url . "&i=$id&action=$action&mode=$mode&sd=$sort_dir&sk=$sort_key&st=$sort_days" . (($merge_select) ? $selected_ids : '');
127 $pagination->generate_template_pagination($base_url, 'pagination', 'start', $forum_topics, $topics_per_page, $start);
128
129 $template->assign_vars(array(
130 'ACTION' => $action,
131 'FORUM_NAME' => $forum_info['forum_name'],
132 'FORUM_DESCRIPTION' => generate_text_for_display($forum_info['forum_desc'], $forum_info['forum_desc_uid'], $forum_info['forum_desc_bitfield'], $forum_info['forum_desc_options']),
133
134 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
135 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
136 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
137 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
138
139 'S_CAN_REPORT' => $auth->acl_get('m_report', $forum_id),
140 'S_CAN_DELETE' => $auth->acl_get('m_delete', $forum_id),
141 'S_CAN_RESTORE' => $auth->acl_get('m_approve', $forum_id),
142 'S_CAN_MERGE' => $auth->acl_get('m_merge', $forum_id),
143 'S_CAN_MOVE' => $auth->acl_get('m_move', $forum_id),
144 'S_CAN_FORK' => $auth->acl_get('m_', $forum_id),
145 'S_CAN_LOCK' => $auth->acl_get('m_lock', $forum_id),
146 'S_CAN_SYNC' => $auth->acl_get('m_', $forum_id),
147 'S_CAN_APPROVE' => $auth->acl_get('m_approve', $forum_id),
148 'S_MERGE_SELECT' => ($merge_select) ? true : false,
149 'S_CAN_MAKE_NORMAL' => $auth->acl_gets('f_sticky', 'f_announce', 'f_announce_global', $forum_id),
150 'S_CAN_MAKE_STICKY' => $auth->acl_get('f_sticky', $forum_id),
151 'S_CAN_MAKE_ANNOUNCE' => $auth->acl_get('f_announce', $forum_id),
152 'S_CAN_MAKE_ANNOUNCE_GLOBAL' => $auth->acl_get('f_announce_global', $forum_id),
153
154 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
155 'U_VIEW_FORUM_LOGS' => ($auth->acl_gets('a_', 'm_', $forum_id) && $module->loaded('logs')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&mode=forum_logs&f=' . $forum_id) : '',
156
157 'S_MCP_ACTION' => $url . "&i=$id&forum_action=$action&mode=$mode&start=$start" . (($merge_select) ? $selected_ids : ''),
158
159 'TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $forum_topics),
160 ));
161
162 // Grab icons
163 $icons = $cache->obtain_icons();
164
165 $topic_rows = array();
166
167 if ($config['load_db_lastread'])
168 {
169 $sql_read_tracking['LEFT_JOIN'][] = ['FROM' => [TOPICS_TRACK_TABLE => 'tt'], 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']];
170 $sql_read_tracking['SELECT'] = ', tt.mark_time';
171 }
172 else
173 {
174 $sql_read_tracking['LEFT_JOIN'] = [];
175 $sql_read_tracking['SELECT'] = '';
176 }
177
178 /* @var $phpbb_content_visibility \phpbb\content_visibility */
179 $phpbb_content_visibility = $phpbb_container->get('content.visibility');
180
181 $sql = 'SELECT t.topic_id
182 FROM ' . TOPICS_TABLE . ' t
183 WHERE t.forum_id = ' . $forum_id . '
184 AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . "
185 $limit_time_sql
186 ORDER BY t.topic_type DESC, $sort_order_sql";
187
188 /**
189 * Modify SQL query before MCP forum view topic list is queried
190 *
191 * @event core.mcp_view_forum_modify_sql
192 * @var string sql SQL query for forum view topic list
193 * @var int forum_id ID of the forum
194 * @var string limit_time_sql SQL query part for limit time
195 * @var string sort_order_sql SQL query part for sort order
196 * @var int topics_per_page Number of topics per page
197 * @var int start Start value
198 * @since 3.1.2-RC1
199 */
200 $vars = array('sql', 'forum_id', 'limit_time_sql', 'sort_order_sql', 'topics_per_page', 'start');
201 extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_sql', compact($vars)));
202
203 $result = $db->sql_query_limit($sql, $topics_per_page, $start);
204
205 $topic_list = $topic_tracking_info = array();
206
207 while ($row_ary = $db->sql_fetchrow($result))
208 {
209 $topic_list[] = $row_ary['topic_id'];
210 }
211 $db->sql_freeresult($result);
212
213 $sql_ary = [
214 'SELECT' => 't.*' . $sql_read_tracking['SELECT'],
215 'FROM' => [TOPICS_TABLE => 't'],
216 'LEFT_JOIN' => $sql_read_tracking['LEFT_JOIN'],
217 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list, false, true),
218 ];
219
220 /**
221 * Event to modify SQL query before MCP forum topic data is queried
222 *
223 * @event core.mcp_forum_topic_data_modify_sql
224 * @var array sql_ary SQL query array to get the MCP forum topic data
225 * @var int forum_id The forum ID
226 * @var array topic_list The array of MCP forum topic IDs
227 *
228 * @since 3.3.4-RC1
229 */
230 $vars = [
231 'sql_ary',
232 'forum_id',
233 'topic_list',
234 ];
235 extract($phpbb_dispatcher->trigger_event('core.mcp_forum_topic_data_modify_sql', compact($vars)));
236
237 $sql = $db->sql_build_query('SELECT', $sql_ary);
238 $result = $db->sql_query($sql);
239 while ($row_ary = $db->sql_fetchrow($result))
240 {
241 $topic_rows[$row_ary['topic_id']] = $row_ary;
242 }
243 $db->sql_freeresult($result);
244
245 // If there is more than one page, but we have no topic list, then the start parameter is... erm... out of sync
246 if (!count($topic_list) && $forum_topics && $start > 0)
247 {
248 redirect($url . "&i=$id&action=$action&mode=$mode");
249 }
250
251 // Get topic tracking info
252 if (count($topic_list))
253 {
254 if ($config['load_db_lastread'])
255 {
256 $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $topic_rows, array($forum_id => $forum_info['mark_time']));
257 }
258 else
259 {
260 $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list);
261 }
262 }
263
264 foreach ($topic_list as $topic_id)
265 {
266 $row_ary = &$topic_rows[$topic_id];
267
268 $replies = $phpbb_content_visibility->get_count('topic_posts', $row_ary, $forum_id) - 1;
269
270 if ($row_ary['topic_status'] == ITEM_MOVED)
271 {
272 $unread_topic = false;
273 }
274 else
275 {
276 $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row_ary['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
277 }
278
279 // Get folder img, topic status/type related information
280 $folder_img = $folder_alt = $topic_type = '';
281 topic_status($row_ary, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
282
283 $topic_title = censor_text($row_ary['topic_title']);
284
285 $topic_unapproved = (($row_ary['topic_visibility'] == ITEM_UNAPPROVED || $row_ary['topic_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $row_ary['forum_id'])) ? true : false;
286 $posts_unapproved = ($row_ary['topic_visibility'] == ITEM_APPROVED && $row_ary['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row_ary['forum_id'])) ? true : false;
287 $topic_deleted = $row_ary['topic_visibility'] == ITEM_DELETED;
288 $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row_ary['topic_id'] : '';
289 $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? $url . '&i=queue&mode=deleted_topics&t=' . $topic_id : $u_mcp_queue;
290
291 $topic_row = array(
292 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row_ary['forum_id']) && $row_ary['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
293 'TOPIC_IMG_STYLE' => $folder_img,
294 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
295 'TOPIC_ICON_IMG' => (!empty($icons[$row_ary['icon_id']])) ? $icons[$row_ary['icon_id']]['img'] : '',
296 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row_ary['icon_id']])) ? $icons[$row_ary['icon_id']]['width'] : '',
297 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row_ary['icon_id']])) ? $icons[$row_ary['icon_id']]['height'] : '',
298 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
299 'DELETED_IMG' => ($topic_deleted) ? $user->img('icon_topic_deleted', 'TOPIC_DELETED') : '',
300
301 'TOPIC_AUTHOR' => get_username_string('username', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']),
302 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']),
303 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']),
304 'U_TOPIC_AUTHOR' => get_username_string('profile', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']),
305
306 'LAST_POST_AUTHOR' => get_username_string('username', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']),
307 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']),
308 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']),
309 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']),
310
311 'TOPIC_TYPE' => $topic_type,
312 'TOPIC_TITLE' => $topic_title,
313 'REPLIES' => $phpbb_content_visibility->get_count('topic_posts', $row_ary, $row_ary['forum_id']) - 1,
314 'LAST_POST_TIME' => $user->format_date($row_ary['topic_last_post_time']),
315 'FIRST_POST_TIME' => $user->format_date($row_ary['topic_time']),
316 'LAST_POST_SUBJECT' => $row_ary['topic_last_post_subject'],
317 'LAST_VIEW_TIME' => $user->format_date($row_ary['topic_last_view_time']),
318
319 'S_TOPIC_REPORTED' => (!empty($row_ary['topic_reported']) && empty($row_ary['topic_moved_id']) && $auth->acl_get('m_report', $row_ary['forum_id'])) ? true : false,
320 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
321 'S_POSTS_UNAPPROVED' => $posts_unapproved,
322 'S_TOPIC_DELETED' => $topic_deleted,
323 'S_UNREAD_TOPIC' => $unread_topic,
324 );
325
326 if ($row_ary['topic_status'] == ITEM_MOVED)
327 {
328 $topic_row = array_merge($topic_row, array(
329 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row_ary['topic_moved_id']}"),
330 'U_DELETE_TOPIC' => ($auth->acl_get('m_delete', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&f=$forum_id&topic_id_list[]={$row_ary['topic_id']}&mode=forum_view&action=delete_topic") : '',
331 'S_MOVED_TOPIC' => true,
332 'TOPIC_ID' => $row_ary['topic_moved_id'],
333 ));
334 }
335 else
336 {
337 if ($action == 'merge_topic' || $action == 'merge_topics')
338 {
339 $u_select_topic = $url . "&i=$id&mode=forum_view&action=$action&to_topic_id=" . $row_ary['topic_id'] . $selected_ids;
340 }
341 else
342 {
343 $u_select_topic = $url . "&i=$id&mode=topic_view&action=merge&to_topic_id=" . $row_ary['topic_id'] . $selected_ids;
344 }
345 $topic_row = array_merge($topic_row, array(
346 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&f=$forum_id&t={$row_ary['topic_id']}&mode=topic_view"),
347 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&f=$forum_id&t={$row_ary['topic_id']}&mode=topic_view&view=unread#unread"),
348
349 'S_SELECT_TOPIC' => ($merge_select && !in_array($row_ary['topic_id'], $source_topic_ids)) ? true : false,
350 'U_SELECT_TOPIC' => $u_select_topic,
351 'U_MCP_QUEUE' => $u_mcp_queue,
352 'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=topic_view&t=' . $row_ary['topic_id'] . '&action=reports') : '',
353 'TOPIC_ID' => $row_ary['topic_id'],
354 'S_TOPIC_CHECKED' => ($topic_id_list && in_array($row_ary['topic_id'], $topic_id_list)) ? true : false,
355 ));
356 }
357
358 $row = $row_ary;
359 /**
360 * Modify the topic data before it is assigned to the template in MCP
361 *
362 * @event core.mcp_view_forum_modify_topicrow
363 * @var array row Array with topic data
364 * @var array topic_row Template array with topic data
365 * @since 3.1.0-a1
366 */
367 $vars = array('row', 'topic_row');
368 extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_topicrow', compact($vars)));
369 $row_ary = $row;
370 unset($row);
371
372 $template->assign_block_vars('topicrow', $topic_row);
373 }
374 unset($topic_rows);
375 }
376
377 /**
378 * Resync topics
379 */
380 function mcp_resync_topics($topic_ids)
381 {
382 global $db, $user, $phpbb_log, $request;
383
384 if (!count($topic_ids))
385 {
386 trigger_error('NO_TOPIC_SELECTED');
387 }
388
389 if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
390 {
391 return;
392 }
393
394 // Sync everything and perform extra checks separately
395 sync('topic_reported', 'topic_id', $topic_ids, false, true);
396 sync('topic_attachment', 'topic_id', $topic_ids, false, true);
397 sync('topic', 'topic_id', $topic_ids, true, false);
398
399 $sql = 'SELECT topic_id, forum_id, topic_title
400 FROM ' . TOPICS_TABLE . '
401 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
402 $result = $db->sql_query($sql);
403
404 // Log this action
405 while ($row = $db->sql_fetchrow($result))
406 {
407 $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_TOPIC_RESYNC', false, array(
408 'forum_id' => $row['forum_id'],
409 'topic_id' => $row['topic_id'],
410 $row['topic_title']
411 ));
412 }
413 $db->sql_freeresult($result);
414
415 $msg = (count($topic_ids) == 1) ? $user->lang['TOPIC_RESYNC_SUCCESS'] : $user->lang['TOPICS_RESYNC_SUCCESS'];
416
417 $redirect = $request->variable('redirect', $user->data['session_page']);
418
419 meta_refresh(3, $redirect);
420 trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
421
422 return;
423 }
424
425 /**
426 * Merge selected topics into selected topic
427 */
428 function merge_topics($forum_id, $topic_ids, $to_topic_id)
429 {
430 global $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_log, $request, $phpbb_dispatcher;
431
432 if (!count($topic_ids))
433 {
434 $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
435 return;
436 }
437 if (!$to_topic_id)
438 {
439 $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
440 return;
441 }
442
443 $sync_topics = array_merge($topic_ids, array($to_topic_id));
444
445 $all_topic_data = phpbb_get_topic_data($sync_topics, 'm_merge');
446
447 if (!count($all_topic_data) || empty($all_topic_data[$to_topic_id]))
448 {
449 $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
450 return;
451 }
452
453 $sync_forums = array();
454 $topic_views = 0;
455 foreach ($all_topic_data as $data)
456 {
457 $sync_forums[$data['forum_id']] = $data['forum_id'];
458 $topic_views = max($topic_views, $data['topic_views']);
459 }
460
461 $to_topic_data = $all_topic_data[$to_topic_id];
462
463 $post_id_list = $request->variable('post_id_list', array(0));
464 $start = $request->variable('start', 0);
465
466 if (!count($post_id_list) && count($topic_ids))
467 {
468 $sql = 'SELECT post_id
469 FROM ' . POSTS_TABLE . '
470 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
471 $result = $db->sql_query($sql);
472
473 $post_id_list = array();
474 while ($row = $db->sql_fetchrow($result))
475 {
476 $post_id_list[] = $row['post_id'];
477 }
478 $db->sql_freeresult($result);
479 }
480
481 if (!count($post_id_list))
482 {
483 $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
484 return;
485 }
486
487 if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
488 {
489 return;
490 }
491
492 $redirect = $request->variable('redirect', "{$phpbb_root_path}mcp.$phpEx?f=$forum_id&i=main&mode=forum_view");
493
494 $s_hidden_fields = build_hidden_fields(array(
495 'i' => 'main',
496 'f' => $forum_id,
497 'post_id_list' => $post_id_list,
498 'to_topic_id' => $to_topic_id,
499 'mode' => 'forum_view',
500 'action' => 'merge_topics',
501 'start' => $start,
502 'redirect' => $redirect,
503 'topic_id_list' => $topic_ids)
504 );
505 $return_link = '';
506
507 if (confirm_box(true))
508 {
509 $to_forum_id = $to_topic_data['forum_id'];
510
511 move_posts($post_id_list, $to_topic_id, false);
512
513 $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MERGE', false, array(
514 'forum_id' => $to_forum_id,
515 'topic_id' => $to_topic_id,
516 $to_topic_data['topic_title']
517 ));
518
519 // Update topic views count
520 $sql = 'UPDATE ' . TOPICS_TABLE . '
521 SET topic_views = ' . $topic_views . '
522 WHERE topic_id = ' . $to_topic_id;
523 $db->sql_query($sql);
524
525 // Message and return links
526 $success_msg = 'POSTS_MERGED_SUCCESS';
527
528 if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
529 {
530 include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
531 }
532
533 // Update the topic watch table.
534 phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id);
535
536 // Update the bookmarks table.
537 phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $topic_ids, $to_topic_id);
538
539 // Re-sync the topics and forums because the auto-sync was deactivated in the call of move_posts()
540 sync('topic_reported', 'topic_id', $sync_topics);
541 sync('topic_attachment', 'topic_id', $sync_topics);
542 sync('topic', 'topic_id', $sync_topics, true);
543 sync('forum', 'forum_id', $sync_forums, true, true);
544
545 // Link to the new topic
546 $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>');
547 $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?t=$to_topic_id");
548 $redirect = reapply_sid($redirect);
549
550 /**
551 * Perform additional actions after merging topics.
552 *
553 * @event core.mcp_forum_merge_topics_after
554 * @var array all_topic_data The data from all topics involved in the merge
555 * @var int to_topic_id The ID of the topic into which the rest are merged
556 * @since 3.1.11-RC1
557 */
558 $vars = array(
559 'all_topic_data',
560 'to_topic_id',
561 );
562 extract($phpbb_dispatcher->trigger_event('core.mcp_forum_merge_topics_after', compact($vars)));
563
564 meta_refresh(3, $redirect);
565 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
566 }
567 else
568 {
569 confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields);
570 }
571 }
572