443
by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0 |
1 |
<?php
|
2 |
/**
|
|
3 |
*
|
|
4 |
* @package mcp
|
|
5 |
* @version $Id: mcp_topic.php,v 1.62 2007/10/12 18:13:50 acydburn Exp $
|
|
6 |
* @copyright (c) 2005 phpBB Group
|
|
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
8 |
*
|
|
9 |
*/
|
|
10 |
||
11 |
/**
|
|
12 |
* @ignore
|
|
13 |
*/
|
|
14 |
if (!defined('IN_PHPBB')) |
|
15 |
{
|
|
16 |
exit; |
|
17 |
}
|
|
18 |
||
19 |
/**
|
|
20 |
* View topic in MCP
|
|
21 |
*/
|
|
22 |
function mcp_topic_view($id, $mode, $action) |
|
23 |
{
|
|
24 |
global $phpEx, $phpbb_root_path, $config; |
|
25 |
global $template, $db, $user, $auth, $cache; |
|
26 |
||
27 |
$url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url()); |
|
28 |
||
29 |
$user->add_lang('viewtopic'); |
|
30 |
||
31 |
$topic_id = request_var('t', 0); |
|
32 |
$topic_info = get_topic_data(array($topic_id), false, true); |
|
33 |
||
34 |
if (!sizeof($topic_info)) |
|
35 |
{
|
|
36 |
trigger_error('TOPIC_NOT_EXIST'); |
|
37 |
}
|
|
38 |
||
39 |
$topic_info = $topic_info[$topic_id]; |
|
40 |
||
41 |
// Set up some vars
|
|
42 |
$icon_id = request_var('icon', 0); |
|
43 |
$subject = utf8_normalize_nfc(request_var('subject', '', true)); |
|
44 |
$start = request_var('start', 0); |
|
45 |
$sort_days_old = request_var('st_old', 0); |
|
46 |
$forum_id = request_var('f', 0); |
|
47 |
$to_topic_id = request_var('to_topic_id', 0); |
|
48 |
$to_forum_id = request_var('to_forum_id', 0); |
|
49 |
$post_id_list = request_var('post_id_list', array(0)); |
|
50 |
$sort = isset($_POST['sort']) ? true : false; |
|
51 |
||
52 |
// Split Topic?
|
|
53 |
if ($action == 'split_all' || $action == 'split_beyond') |
|
54 |
{
|
|
55 |
if (!$sort) |
|
56 |
{
|
|
57 |
split_topic($action, $topic_id, $to_forum_id, $subject); |
|
58 |
}
|
|
59 |
$action = 'split'; |
|
60 |
}
|
|
61 |
||
62 |
// Merge Posts?
|
|
63 |
if ($action == 'merge_posts') |
|
64 |
{
|
|
65 |
if (!$sort) |
|
66 |
{
|
|
67 |
merge_posts($topic_id, $to_topic_id); |
|
68 |
}
|
|
69 |
$action = 'merge'; |
|
70 |
}
|
|
71 |
||
72 |
if ($action == 'split' && !$subject) |
|
73 |
{
|
|
74 |
$subject = $topic_info['topic_title']; |
|
75 |
}
|
|
76 |
||
77 |
// Approve posts?
|
|
78 |
if ($action == 'approve' && $auth->acl_get('m_approve', $topic_info['forum_id'])) |
|
79 |
{
|
|
80 |
include($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx); |
|
81 |
include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); |
|
82 |
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); |
|
83 |
||
84 |
if (!sizeof($post_id_list)) |
|
85 |
{
|
|
86 |
trigger_error('NO_POST_SELECTED'); |
|
87 |
}
|
|
88 |
||
89 |
if (!$sort) |
|
90 |
{
|
|
91 |
approve_post($post_id_list, $id, $mode); |
|
92 |
}
|
|
93 |
}
|
|
94 |
||
95 |
// Jumpbox, sort selects and that kind of things
|
|
96 |
make_jumpbox($url . "&i=$id&mode=forum_view", $topic_info['forum_id'], false, 'm_', true); |
|
97 |
$where_sql = ($action == 'reports') ? 'WHERE post_reported = 1 AND ' : 'WHERE'; |
|
98 |
||
99 |
$sort_days = $total = 0; |
|
100 |
$sort_key = $sort_dir = ''; |
|
101 |
$sort_by_sql = $sort_order_sql = array(); |
|
102 |
mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $topic_info['forum_id'], $topic_id, $where_sql); |
|
103 |
||
104 |
$limit_time_sql = ($sort_days) ? 'AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; |
|
105 |
||
106 |
if ($total == -1) |
|
107 |
{
|
|
108 |
$total = $topic_info['topic_replies'] + 1; |
|
109 |
}
|
|
110 |
||
111 |
$posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page']))); |
|
112 |
if ($posts_per_page == 0) |
|
113 |
{
|
|
114 |
$posts_per_page = $total; |
|
115 |
}
|
|
116 |
if (!empty($sort_days_old) && $sort_days_old != $sort_days) |
|
117 |
{
|
|
118 |
$start = 0; |
|
119 |
}
|
|
120 |
||
121 |
$sql = 'SELECT u.username, u.username_clean, u.user_colour, p.* |
|
122 |
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u |
|
123 |
WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . ' |
|
124 |
p.topic_id = ' . $topic_id . ' ' . |
|
125 |
((!$auth->acl_get('m_approve', $topic_info['forum_id'])) ? ' AND p.post_approved = 1 ' : '') . ' |
|
126 |
AND p.poster_id = u.user_id ' . |
|
127 |
$limit_time_sql . ' |
|
128 |
ORDER BY ' . $sort_order_sql; |
|
129 |
$result = $db->sql_query_limit($sql, $posts_per_page, $start); |
|
130 |
||
131 |
$rowset = $post_id_list = array(); |
|
132 |
$bbcode_bitfield = ''; |
|
133 |
while ($row = $db->sql_fetchrow($result)) |
|
134 |
{
|
|
135 |
$rowset[] = $row; |
|
136 |
$post_id_list[] = $row['post_id']; |
|
137 |
$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); |
|
138 |
}
|
|
139 |
$db->sql_freeresult($result); |
|
140 |
||
141 |
if ($bbcode_bitfield !== '') |
|
142 |
{
|
|
143 |
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); |
|
144 |
$bbcode = new bbcode(base64_encode($bbcode_bitfield)); |
|
145 |
}
|
|
146 |
||
147 |
$topic_tracking_info = array(); |
|
148 |
||
149 |
// Get topic tracking info
|
|
150 |
if ($config['load_db_lastread']) |
|
151 |
{
|
|
152 |
$tmp_topic_data = array($topic_id => $topic_info); |
|
153 |
$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'])); |
|
154 |
unset($tmp_topic_data); |
|
155 |
}
|
|
156 |
else
|
|
157 |
{
|
|
158 |
$topic_tracking_info = get_complete_topic_tracking($topic_info['forum_id'], $topic_id); |
|
159 |
}
|
|
160 |
||
161 |
$has_unapproved_posts = false; |
|
162 |
||
163 |
// Grab extensions
|
|
164 |
$extensions = $attachments = array(); |
|
165 |
if ($topic_info['topic_attachment'] && sizeof($post_id_list)) |
|
166 |
{
|
|
167 |
$extensions = $cache->obtain_attach_extensions($topic_info['forum_id']); |
|
168 |
||
169 |
// Get attachments...
|
|
170 |
if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_info['forum_id'])) |
|
171 |
{
|
|
172 |
$sql = 'SELECT * |
|
173 |
FROM ' . ATTACHMENTS_TABLE . ' |
|
174 |
WHERE ' . $db->sql_in_set('post_msg_id', $post_id_list) . ' |
|
175 |
AND in_message = 0
|
|
176 |
ORDER BY filetime DESC, post_msg_id ASC'; |
|
177 |
$result = $db->sql_query($sql); |
|
178 |
||
179 |
while ($row = $db->sql_fetchrow($result)) |
|
180 |
{
|
|
181 |
$attachments[$row['post_msg_id']][] = $row; |
|
182 |
}
|
|
183 |
$db->sql_freeresult($result); |
|
184 |
}
|
|
185 |
}
|
|
186 |
||
187 |
foreach ($rowset as $i => $row) |
|
188 |
{
|
|
189 |
$message = $row['post_text']; |
|
190 |
$post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title']; |
|
191 |
||
192 |
if ($row['bbcode_bitfield']) |
|
193 |
{
|
|
194 |
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']); |
|
195 |
}
|
|
196 |
||
197 |
$message = bbcode_nl2br($message); |
|
198 |
$message = smiley_text($message); |
|
199 |
||
200 |
if (!empty($attachments[$row['post_id']])) |
|
201 |
{
|
|
202 |
$update_count = array(); |
|
203 |
parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count); |
|
204 |
}
|
|
205 |
||
206 |
if (!$row['post_approved']) |
|
207 |
{
|
|
208 |
$has_unapproved_posts = true; |
|
209 |
}
|
|
210 |
||
211 |
$post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false; |
|
212 |
||
213 |
$template->assign_block_vars('postrow', array( |
|
214 |
'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), |
|
215 |
'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), |
|
216 |
'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), |
|
217 |
'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), |
|
218 |
||
219 |
'POST_DATE' => $user->format_date($row['post_time']), |
|
220 |
'POST_SUBJECT' => $post_subject, |
|
221 |
'MESSAGE' => $message, |
|
222 |
'POST_ID' => $row['post_id'], |
|
223 |
'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) . '">', '</a>'), |
|
224 |
||
225 |
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'), |
|
226 |
||
227 |
'S_POST_REPORTED' => ($row['post_reported']) ? true : false, |
|
228 |
'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true, |
|
229 |
'S_CHECKED' => ($post_id_list && in_array(intval($row['post_id']), $post_id_list)) ? true : false, |
|
230 |
'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false, |
|
231 |
||
232 |
'U_POST_DETAILS' => "$url&i=$id&p={$row['post_id']}&mode=post_details" . (($forum_id) ? "&f=$forum_id" : ''), |
|
233 |
'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']) : '', |
|
234 |
'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']) : '') |
|
235 |
);
|
|
236 |
||
237 |
// Display not already displayed Attachments for this post, we already parsed them. ;)
|
|
238 |
if (!empty($attachments[$row['post_id']])) |
|
239 |
{
|
|
240 |
foreach ($attachments[$row['post_id']] as $attachment) |
|
241 |
{
|
|
242 |
$template->assign_block_vars('postrow.attachment', array( |
|
243 |
'DISPLAY_ATTACHMENT' => $attachment) |
|
244 |
);
|
|
245 |
}
|
|
246 |
}
|
|
247 |
||
248 |
unset($rowset[$i]); |
|
249 |
}
|
|
250 |
||
251 |
// Display topic icons for split topic
|
|
252 |
$s_topic_icons = false; |
|
253 |
||
254 |
if ($auth->acl_get('m_split', $topic_info['forum_id'])) |
|
255 |
{
|
|
256 |
include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); |
|
257 |
$s_topic_icons = posting_gen_topic_icons('', $icon_id); |
|
258 |
||
259 |
// Has the user selected a topic for merge?
|
|
260 |
if ($to_topic_id) |
|
261 |
{
|
|
262 |
$to_topic_info = get_topic_data(array($to_topic_id), 'm_merge'); |
|
263 |
||
264 |
if (!sizeof($to_topic_info)) |
|
265 |
{
|
|
266 |
$to_topic_id = 0; |
|
267 |
}
|
|
268 |
else
|
|
269 |
{
|
|
270 |
$to_topic_info = $to_topic_info[$to_topic_id]; |
|
271 |
||
272 |
if (!$to_topic_info['enable_icons'] || $auth->acl_get('!f_icons', $topic_info['forum_id'])) |
|
273 |
{
|
|
274 |
$s_topic_icons = false; |
|
275 |
}
|
|
276 |
}
|
|
277 |
}
|
|
278 |
}
|
|
279 |
||
280 |
$s_hidden_fields = build_hidden_fields(array( |
|
281 |
'st_old' => $sort_days, |
|
282 |
));
|
|
283 |
||
284 |
$template->assign_vars(array( |
|
285 |
'TOPIC_TITLE' => $topic_info['topic_title'], |
|
286 |
'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&t=' . $topic_info['topic_id']), |
|
287 |
||
288 |
'TO_TOPIC_ID' => $to_topic_id, |
|
289 |
'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>') : '', |
|
290 |
||
291 |
'SPLIT_SUBJECT' => $subject, |
|
292 |
'POSTS_PER_PAGE' => $posts_per_page, |
|
293 |
'ACTION' => $action, |
|
294 |
||
295 |
'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED', false, true), |
|
296 |
'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED', false, true), |
|
297 |
||
298 |
'S_MCP_ACTION' => "$url&i=$id&mode=$mode&action=$action&start=$start", |
|
299 |
'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), |
|
300 |
'S_CAN_SPLIT' => ($auth->acl_get('m_split', $topic_info['forum_id'])) ? true : false, |
|
301 |
'S_CAN_MERGE' => ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? true : false, |
|
302 |
'S_CAN_DELETE' => ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? true : false, |
|
303 |
'S_CAN_APPROVE' => ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false, |
|
304 |
'S_CAN_LOCK' => ($auth->acl_get('m_lock', $topic_info['forum_id'])) ? true : false, |
|
305 |
'S_CAN_REPORT' => ($auth->acl_get('m_report', $topic_info['forum_id'])) ? true : false, |
|
306 |
'S_REPORT_VIEW' => ($action == 'reports') ? true : false, |
|
307 |
'S_MERGE_VIEW' => ($action == 'merge') ? true : false, |
|
308 |
'S_SPLIT_VIEW' => ($action == 'split') ? true : false, |
|
309 |
||
310 |
'S_HIDDEN_FIELDS' => $s_hidden_fields, |
|
311 |
||
312 |
'S_SHOW_TOPIC_ICONS' => $s_topic_icons, |
|
313 |
'S_TOPIC_ICON' => $icon_id, |
|
314 |
||
315 |
'U_SELECT_TOPIC' => "$url&i=$id&mode=forum_view&action=merge_select" . (($forum_id) ? "&f=$forum_id" : ''), |
|
316 |
||
317 |
'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>'), |
|
318 |
'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$topic_info['forum_id']}&start=$start") . '">', '</a>'), |
|
319 |
||
320 |
'PAGE_NUMBER' => on_page($total, $posts_per_page, $start), |
|
321 |
'PAGINATION' => (!$posts_per_page) ? '' : generate_pagination(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"), $total, $posts_per_page, $start), |
|
322 |
'TOTAL_POSTS' => ($total == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total), |
|
323 |
));
|
|
324 |
}
|
|
325 |
||
326 |
/**
|
|
327 |
* Split topic
|
|
328 |
*/
|
|
329 |
function split_topic($action, $topic_id, $to_forum_id, $subject) |
|
330 |
{
|
|
331 |
global $db, $template, $user, $phpEx, $phpbb_root_path, $auth; |
|
332 |
||
333 |
$post_id_list = request_var('post_id_list', array(0)); |
|
334 |
$forum_id = request_var('forum_id', 0); |
|
335 |
$start = request_var('start', 0); |
|
336 |
||
337 |
if (!sizeof($post_id_list)) |
|
338 |
{
|
|
339 |
$template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); |
|
340 |
return; |
|
341 |
}
|
|
342 |
||
343 |
if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_split'))) |
|
344 |
{
|
|
345 |
return; |
|
346 |
}
|
|
347 |
||
348 |
$post_id = $post_id_list[0]; |
|
349 |
$post_info = get_post_data(array($post_id)); |
|
350 |
||
351 |
if (!sizeof($post_info)) |
|
352 |
{
|
|
353 |
$template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); |
|
354 |
return; |
|
355 |
}
|
|
356 |
||
357 |
$post_info = $post_info[$post_id]; |
|
358 |
$subject = trim($subject); |
|
359 |
||
360 |
// Make some tests
|
|
361 |
if (!$subject) |
|
362 |
{
|
|
363 |
$template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']); |
|
364 |
return; |
|
365 |
}
|
|
366 |
||
367 |
if ($to_forum_id <= 0) |
|
368 |
{
|
|
369 |
$template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']); |
|
370 |
return; |
|
371 |
}
|
|
372 |
||
373 |
$forum_info = get_forum_data(array($to_forum_id), 'm_split'); |
|
374 |
||
375 |
if (!sizeof($forum_info)) |
|
376 |
{
|
|
377 |
$template->assign_var('MESSAGE', $user->lang['NOT_MODERATOR']); |
|
378 |
return; |
|
379 |
}
|
|
380 |
||
381 |
$forum_info = $forum_info[$to_forum_id]; |
|
382 |
||
383 |
if ($forum_info['forum_type'] != FORUM_POST) |
|
384 |
{
|
|
385 |
$template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']); |
|
386 |
return; |
|
387 |
}
|
|
388 |
||
389 |
$redirect = request_var('redirect', build_url(array('_f_', 'quickmod'))); |
|
390 |
||
391 |
$s_hidden_fields = build_hidden_fields(array( |
|
392 |
'i' => 'main', |
|
393 |
'post_id_list' => $post_id_list, |
|
394 |
'f' => $forum_id, |
|
395 |
'mode' => 'topic_view', |
|
396 |
'start' => $start, |
|
397 |
'action' => $action, |
|
398 |
't' => $topic_id, |
|
399 |
'redirect' => $redirect, |
|
400 |
'subject' => $subject, |
|
401 |
'to_forum_id' => $to_forum_id, |
|
402 |
'icon' => request_var('icon', 0)) |
|
403 |
);
|
|
404 |
$success_msg = $return_link = ''; |
|
405 |
||
406 |
if (confirm_box(true)) |
|
407 |
{
|
|
408 |
if ($action == 'split_beyond') |
|
409 |
{
|
|
410 |
$sort_days = $total = 0; |
|
411 |
$sort_key = $sort_dir = ''; |
|
412 |
$sort_by_sql = $sort_order_sql = array(); |
|
413 |
mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); |
|
414 |
||
415 |
$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; |
|
416 |
||
417 |
if ($sort_order_sql[0] == 'u') |
|
418 |
{
|
|
419 |
$sql = 'SELECT p.post_id, p.forum_id, p.post_approved |
|
420 |
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u |
|
421 |
WHERE p.topic_id = $topic_id |
|
422 |
AND p.poster_id = u.user_id
|
|
423 |
$limit_time_sql |
|
424 |
ORDER BY $sort_order_sql"; |
|
425 |
}
|
|
426 |
else
|
|
427 |
{
|
|
428 |
$sql = 'SELECT p.post_id, p.forum_id, p.post_approved |
|
429 |
FROM ' . POSTS_TABLE . " p |
|
430 |
WHERE p.topic_id = $topic_id |
|
431 |
$limit_time_sql |
|
432 |
ORDER BY $sort_order_sql"; |
|
433 |
}
|
|
434 |
$result = $db->sql_query_limit($sql, 0, $start); |
|
435 |
||
436 |
$store = false; |
|
437 |
$post_id_list = array(); |
|
438 |
while ($row = $db->sql_fetchrow($result)) |
|
439 |
{
|
|
440 |
// If split from selected post (split_beyond), we split the unapproved items too.
|
|
441 |
if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) |
|
442 |
{
|
|
443 |
// continue;
|
|
444 |
}
|
|
445 |
||
446 |
// Start to store post_ids as soon as we see the first post that was selected
|
|
447 |
if ($row['post_id'] == $post_id) |
|
448 |
{
|
|
449 |
$store = true; |
|
450 |
}
|
|
451 |
||
452 |
if ($store) |
|
453 |
{
|
|
454 |
$post_id_list[] = $row['post_id']; |
|
455 |
}
|
|
456 |
}
|
|
457 |
$db->sql_freeresult($result); |
|
458 |
}
|
|
459 |
||
460 |
if (!sizeof($post_id_list)) |
|
461 |
{
|
|
462 |
trigger_error('NO_POST_SELECTED'); |
|
463 |
}
|
|
464 |
||
465 |
$icon_id = request_var('icon', 0); |
|
466 |
||
467 |
$sql_ary = array( |
|
468 |
'forum_id' => $to_forum_id, |
|
469 |
'topic_title' => $subject, |
|
470 |
'icon_id' => $icon_id, |
|
471 |
'topic_approved'=> 1 |
|
472 |
);
|
|
473 |
||
474 |
$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); |
|
475 |
$db->sql_query($sql); |
|
476 |
||
477 |
$to_topic_id = $db->sql_nextid(); |
|
478 |
move_posts($post_id_list, $to_topic_id); |
|
479 |
||
480 |
$topic_info = get_topic_data(array($topic_id)); |
|
481 |
$topic_info = $topic_info[$topic_id]; |
|
482 |
||
483 |
add_log('mod', $to_forum_id, $to_topic_id, 'LOG_SPLIT_DESTINATION', $subject); |
|
484 |
add_log('mod', $forum_id, $topic_id, 'LOG_SPLIT_SOURCE', $topic_info['topic_title']); |
|
485 |
||
486 |
// Change topic title of first post
|
|
487 |
$sql = 'UPDATE ' . POSTS_TABLE . " |
|
488 |
SET post_subject = '" . $db->sql_escape($subject) . "' |
|
489 |
WHERE post_id = {$post_id_list[0]}"; |
|
490 |
$db->sql_query($sql); |
|
491 |
||
492 |
$success_msg = 'TOPIC_SPLIT_SUCCESS'; |
|
493 |
||
494 |
// Link back to both topics
|
|
495 |
$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>'); |
|
496 |
}
|
|
497 |
else
|
|
498 |
{
|
|
499 |
confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields); |
|
500 |
}
|
|
501 |
||
502 |
$redirect = request_var('redirect', "index.$phpEx"); |
|
503 |
$redirect = reapply_sid($redirect); |
|
504 |
||
505 |
if (!$success_msg) |
|
506 |
{
|
|
507 |
return; |
|
508 |
}
|
|
509 |
else
|
|
510 |
{
|
|
511 |
meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id")); |
|
512 |
trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link); |
|
513 |
}
|
|
514 |
}
|
|
515 |
||
516 |
/**
|
|
517 |
* Merge selected posts into selected topic
|
|
518 |
*/
|
|
519 |
function merge_posts($topic_id, $to_topic_id) |
|
520 |
{
|
|
521 |
global $db, $template, $user, $phpEx, $phpbb_root_path, $auth; |
|
522 |
||
523 |
if (!$to_topic_id) |
|
524 |
{
|
|
525 |
$template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']); |
|
526 |
return; |
|
527 |
}
|
|
528 |
||
529 |
$topic_data = get_topic_data(array($to_topic_id), 'm_merge'); |
|
530 |
||
531 |
if (!sizeof($topic_data)) |
|
532 |
{
|
|
533 |
$template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']); |
|
534 |
return; |
|
535 |
}
|
|
536 |
||
537 |
$topic_data = $topic_data[$to_topic_id]; |
|
538 |
||
539 |
$post_id_list = request_var('post_id_list', array(0)); |
|
540 |
$start = request_var('start', 0); |
|
541 |
||
542 |
if (!sizeof($post_id_list)) |
|
543 |
{
|
|
544 |
$template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); |
|
545 |
return; |
|
546 |
}
|
|
547 |
||
548 |
if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge'))) |
|
549 |
{
|
|
550 |
return; |
|
551 |
}
|
|
552 |
||
553 |
$redirect = request_var('redirect', build_url(array('_f_', 'quickmod'))); |
|
554 |
||
555 |
$s_hidden_fields = build_hidden_fields(array( |
|
556 |
'i' => 'main', |
|
557 |
'post_id_list' => $post_id_list, |
|
558 |
'to_topic_id' => $to_topic_id, |
|
559 |
'mode' => 'topic_view', |
|
560 |
'action' => 'merge_posts', |
|
561 |
'start' => $start, |
|
562 |
'redirect' => $redirect, |
|
563 |
't' => $topic_id) |
|
564 |
);
|
|
565 |
$success_msg = $return_link = ''; |
|
566 |
||
567 |
if (confirm_box(true)) |
|
568 |
{
|
|
569 |
$to_forum_id = $topic_data['forum_id']; |
|
570 |
||
571 |
move_posts($post_id_list, $to_topic_id); |
|
572 |
add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']); |
|
573 |
||
574 |
// Message and return links
|
|
575 |
$success_msg = 'POSTS_MERGED_SUCCESS'; |
|
576 |
||
577 |
// Does the original topic still exist? If yes, link back to it
|
|
578 |
$sql = 'SELECT forum_id |
|
579 |
FROM ' . TOPICS_TABLE . ' |
|
580 |
WHERE topic_id = ' . $topic_id; |
|
581 |
$result = $db->sql_query_limit($sql, 1); |
|
582 |
$row = $db->sql_fetchrow($result); |
|
583 |
$db->sql_freeresult($result); |
|
584 |
||
585 |
if ($row) |
|
586 |
{
|
|
587 |
$return_link .= sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $topic_id) . '">', '</a>'); |
|
588 |
}
|
|
589 |
else
|
|
590 |
{
|
|
591 |
// If the topic no longer exist, we will update the topic watch table.
|
|
592 |
// To not let it error out on users watching both topics, we just return on an error...
|
|
593 |
$db->sql_return_on_error(true); |
|
594 |
$db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE topic_id = ' . (int) $topic_id); |
|
595 |
$db->sql_return_on_error(false); |
|
596 |
||
597 |
$db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $topic_id); |
|
598 |
}
|
|
599 |
||
600 |
// Link to the new topic
|
|
601 |
$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>'); |
|
602 |
}
|
|
603 |
else
|
|
604 |
{
|
|
605 |
confirm_box(false, 'MERGE_POSTS', $s_hidden_fields); |
|
606 |
}
|
|
607 |
||
608 |
$redirect = request_var('redirect', "index.$phpEx"); |
|
609 |
$redirect = reapply_sid($redirect); |
|
610 |
||
611 |
if (!$success_msg) |
|
612 |
{
|
|
613 |
return; |
|
614 |
}
|
|
615 |
else
|
|
616 |
{
|
|
617 |
meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id")); |
|
618 |
trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link); |
|
619 |
}
|
|
620 |
}
|
|
621 |
||
622 |
?>
|