Chris@76
|
1 <?php
|
Chris@76
|
2
|
Chris@76
|
3 /**
|
Chris@76
|
4 * Simple Machines Forum (SMF)
|
Chris@76
|
5 *
|
Chris@76
|
6 * @package SMF
|
Chris@76
|
7 * @author Simple Machines http://www.simplemachines.org
|
Chris@76
|
8 * @copyright 2011 Simple Machines
|
Chris@76
|
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
|
Chris@76
|
10 *
|
Chris@76
|
11 * @version 2.0
|
Chris@76
|
12 */
|
Chris@76
|
13
|
Chris@76
|
14 if (!defined('SMF'))
|
Chris@76
|
15 die('Hacking attempt...');
|
Chris@76
|
16
|
Chris@76
|
17 /* This file contains the functions required to move topics from one board to
|
Chris@76
|
18 another board.
|
Chris@76
|
19
|
Chris@76
|
20 void MoveTopic()
|
Chris@76
|
21 - is called to allow moderator to give reason for topic move.
|
Chris@76
|
22 - must be called with a topic specified.
|
Chris@76
|
23 - uses the MoveTopic template and main sub template.
|
Chris@76
|
24 - if the member is the topic starter requires the move_own permission,
|
Chris@76
|
25 otherwise the move_any permission.
|
Chris@76
|
26 - is accessed via ?action=movetopic.
|
Chris@76
|
27
|
Chris@76
|
28 void MoveTopic2()
|
Chris@76
|
29 - is called on the submit of MoveTopic.
|
Chris@76
|
30 - requires the use of the Subs-Post.php file.
|
Chris@76
|
31 - logs that topics have been moved in the moderation log.
|
Chris@76
|
32 - if the member is the topic starter requires the move_own permission,
|
Chris@76
|
33 otherwise requires the move_any permission.
|
Chris@76
|
34 - upon successful completion redirects to message index.
|
Chris@76
|
35 - is accessed via ?action=movetopic2.
|
Chris@76
|
36
|
Chris@76
|
37 void moveTopics(array topics, int destination_board)
|
Chris@76
|
38 - performs the changes needed to move topics to new boards.
|
Chris@76
|
39 - topics is an array of the topics to move, and destination_board is
|
Chris@76
|
40 where they should be moved to.
|
Chris@76
|
41 - updates message, topic and calendar statistics.
|
Chris@76
|
42 - does not check permissions. (assumes they have been checked!)
|
Chris@76
|
43 */
|
Chris@76
|
44
|
Chris@76
|
45 // Move a topic. Give the moderator a chance to post a reason.
|
Chris@76
|
46 function MoveTopic()
|
Chris@76
|
47 {
|
Chris@76
|
48 global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $settings, $smcFunc, $modSettings;
|
Chris@76
|
49
|
Chris@76
|
50 if (empty($topic))
|
Chris@76
|
51 fatal_lang_error('no_access', false);
|
Chris@76
|
52
|
Chris@76
|
53 $request = $smcFunc['db_query']('', '
|
Chris@76
|
54 SELECT t.id_member_started, ms.subject, t.approved
|
Chris@76
|
55 FROM {db_prefix}topics AS t
|
Chris@76
|
56 INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
|
Chris@76
|
57 WHERE t.id_topic = {int:current_topic}
|
Chris@76
|
58 LIMIT 1',
|
Chris@76
|
59 array(
|
Chris@76
|
60 'current_topic' => $topic,
|
Chris@76
|
61 )
|
Chris@76
|
62 );
|
Chris@76
|
63 list ($id_member_started, $context['subject'], $context['is_approved']) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
64 $smcFunc['db_free_result']($request);
|
Chris@76
|
65
|
Chris@76
|
66 // Can they see it - if not approved?
|
Chris@76
|
67 if ($modSettings['postmod_active'] && !$context['is_approved'])
|
Chris@76
|
68 isAllowedTo('approve_posts');
|
Chris@76
|
69
|
Chris@76
|
70 // Permission check!
|
Chris@76
|
71 // !!!
|
Chris@76
|
72 if (!allowedTo('move_any'))
|
Chris@76
|
73 {
|
Chris@76
|
74 if ($id_member_started == $user_info['id'])
|
Chris@76
|
75 {
|
Chris@76
|
76 isAllowedTo('move_own');
|
Chris@76
|
77 //$boards = array_merge(boardsAllowedTo('move_own'), boardsAllowedTo('move_any'));
|
Chris@76
|
78 }
|
Chris@76
|
79 else
|
Chris@76
|
80 isAllowedTo('move_any');
|
Chris@76
|
81 }
|
Chris@76
|
82 //else
|
Chris@76
|
83 //$boards = boardsAllowedTo('move_any');
|
Chris@76
|
84
|
Chris@76
|
85 loadTemplate('MoveTopic');
|
Chris@76
|
86
|
Chris@76
|
87 // Get a list of boards this moderator can move to.
|
Chris@76
|
88 $request = $smcFunc['db_query']('order_by_board_order', '
|
Chris@76
|
89 SELECT b.id_board, b.name, b.child_level, c.name AS cat_name, c.id_cat
|
Chris@76
|
90 FROM {db_prefix}boards AS b
|
Chris@76
|
91 LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
|
Chris@76
|
92 WHERE {query_see_board}
|
Chris@76
|
93 AND b.redirect = {string:blank_redirect}
|
Chris@76
|
94 AND b.id_board != {int:current_board}',
|
Chris@76
|
95 array(
|
Chris@76
|
96 'blank_redirect' => '',
|
Chris@76
|
97 'current_board' => $board,
|
Chris@76
|
98 )
|
Chris@76
|
99 );
|
Chris@76
|
100 $context['boards'] = array();
|
Chris@76
|
101 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
102 {
|
Chris@76
|
103 if (!isset($context['categories'][$row['id_cat']]))
|
Chris@76
|
104 $context['categories'][$row['id_cat']] = array (
|
Chris@76
|
105 'name' => strip_tags($row['cat_name']),
|
Chris@76
|
106 'boards' => array(),
|
Chris@76
|
107 );
|
Chris@76
|
108
|
Chris@76
|
109 $context['categories'][$row['id_cat']]['boards'][] = array(
|
Chris@76
|
110 'id' => $row['id_board'],
|
Chris@76
|
111 'name' => strip_tags($row['name']),
|
Chris@76
|
112 'category' => strip_tags($row['cat_name']),
|
Chris@76
|
113 'child_level' => $row['child_level'],
|
Chris@76
|
114 'selected' => !empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] == $row['id_board'] && $row['id_board'] != $board,
|
Chris@76
|
115 );
|
Chris@76
|
116 }
|
Chris@76
|
117 $smcFunc['db_free_result']($request);
|
Chris@76
|
118
|
Chris@76
|
119 if (empty($context['categories']))
|
Chris@76
|
120 fatal_lang_error('moveto_noboards', false);
|
Chris@76
|
121
|
Chris@76
|
122 $context['page_title'] = $txt['move_topic'];
|
Chris@76
|
123
|
Chris@76
|
124 $context['linktree'][] = array(
|
Chris@76
|
125 'url' => $scripturl . '?topic=' . $topic . '.0',
|
Chris@76
|
126 'name' => $context['subject'],
|
Chris@76
|
127 'extra_before' => $settings['linktree_inline'] ? $txt['topic'] . ': ' : '',
|
Chris@76
|
128 );
|
Chris@76
|
129
|
Chris@76
|
130 $context['linktree'][] = array(
|
Chris@76
|
131 'name' => $txt['move_topic'],
|
Chris@76
|
132 );
|
Chris@76
|
133
|
Chris@76
|
134 $context['back_to_topic'] = isset($_REQUEST['goback']);
|
Chris@76
|
135
|
Chris@76
|
136 if ($user_info['language'] != $language)
|
Chris@76
|
137 {
|
Chris@76
|
138 loadLanguage('index', $language);
|
Chris@76
|
139 $temp = $txt['movetopic_default'];
|
Chris@76
|
140 loadLanguage('index');
|
Chris@76
|
141
|
Chris@76
|
142 $txt['movetopic_default'] = $temp;
|
Chris@76
|
143 }
|
Chris@76
|
144
|
Chris@76
|
145 // Register this form and get a sequence number in $context.
|
Chris@76
|
146 checkSubmitOnce('register');
|
Chris@76
|
147 }
|
Chris@76
|
148
|
Chris@76
|
149 // Execute the move.
|
Chris@76
|
150 function MoveTopic2()
|
Chris@76
|
151 {
|
Chris@76
|
152 global $txt, $board, $topic, $scripturl, $sourcedir, $modSettings, $context;
|
Chris@76
|
153 global $board, $language, $user_info, $smcFunc;
|
Chris@76
|
154
|
Chris@76
|
155 if (empty($topic))
|
Chris@76
|
156 fatal_lang_error('no_access', false);
|
Chris@76
|
157
|
Chris@76
|
158 // You can't choose to have a redirection topic and use an empty reason.
|
Chris@76
|
159 if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == ''))
|
Chris@76
|
160 fatal_lang_error('movetopic_no_reason', false);
|
Chris@76
|
161
|
Chris@76
|
162 // Make sure this form hasn't been submitted before.
|
Chris@76
|
163 checkSubmitOnce('check');
|
Chris@76
|
164
|
Chris@76
|
165 $request = $smcFunc['db_query']('', '
|
Chris@76
|
166 SELECT id_member_started, id_first_msg, approved
|
Chris@76
|
167 FROM {db_prefix}topics
|
Chris@76
|
168 WHERE id_topic = {int:current_topic}
|
Chris@76
|
169 LIMIT 1',
|
Chris@76
|
170 array(
|
Chris@76
|
171 'current_topic' => $topic,
|
Chris@76
|
172 )
|
Chris@76
|
173 );
|
Chris@76
|
174 list ($id_member_started, $id_first_msg, $context['is_approved']) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
175 $smcFunc['db_free_result']($request);
|
Chris@76
|
176
|
Chris@76
|
177 // Can they see it?
|
Chris@76
|
178 if (!$context['is_approved'])
|
Chris@76
|
179 isAllowedTo('approve_posts');
|
Chris@76
|
180
|
Chris@76
|
181 // Can they move topics on this board?
|
Chris@76
|
182 if (!allowedTo('move_any'))
|
Chris@76
|
183 {
|
Chris@76
|
184 if ($id_member_started == $user_info['id'])
|
Chris@76
|
185 {
|
Chris@76
|
186 isAllowedTo('move_own');
|
Chris@76
|
187 $boards = array_merge(boardsAllowedTo('move_own'), boardsAllowedTo('move_any'));
|
Chris@76
|
188 }
|
Chris@76
|
189 else
|
Chris@76
|
190 isAllowedTo('move_any');
|
Chris@76
|
191 }
|
Chris@76
|
192 else
|
Chris@76
|
193 $boards = boardsAllowedTo('move_any');
|
Chris@76
|
194
|
Chris@76
|
195 // If this topic isn't approved don't let them move it if they can't approve it!
|
Chris@76
|
196 if ($modSettings['postmod_active'] && !$context['is_approved'] && !allowedTo('approve_posts'))
|
Chris@76
|
197 {
|
Chris@76
|
198 // Only allow them to move it to other boards they can't approve it in.
|
Chris@76
|
199 $can_approve = boardsAllowedTo('approve_posts');
|
Chris@76
|
200 $boards = array_intersect($boards, $can_approve);
|
Chris@76
|
201 }
|
Chris@76
|
202
|
Chris@76
|
203 checkSession();
|
Chris@76
|
204 require_once($sourcedir . '/Subs-Post.php');
|
Chris@76
|
205
|
Chris@76
|
206 // The destination board must be numeric.
|
Chris@76
|
207 $_POST['toboard'] = (int) $_POST['toboard'];
|
Chris@76
|
208
|
Chris@76
|
209 // Make sure they can see the board they are trying to move to (and get whether posts count in the target board).
|
Chris@76
|
210 $request = $smcFunc['db_query']('', '
|
Chris@76
|
211 SELECT b.count_posts, b.name, m.subject
|
Chris@76
|
212 FROM {db_prefix}boards AS b
|
Chris@76
|
213 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
|
Chris@76
|
214 INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
|
Chris@76
|
215 WHERE {query_see_board}
|
Chris@76
|
216 AND b.id_board = {int:to_board}
|
Chris@76
|
217 AND b.redirect = {string:blank_redirect}
|
Chris@76
|
218 LIMIT 1',
|
Chris@76
|
219 array(
|
Chris@76
|
220 'current_topic' => $topic,
|
Chris@76
|
221 'to_board' => $_POST['toboard'],
|
Chris@76
|
222 'blank_redirect' => '',
|
Chris@76
|
223 )
|
Chris@76
|
224 );
|
Chris@76
|
225 if ($smcFunc['db_num_rows']($request) == 0)
|
Chris@76
|
226 fatal_lang_error('no_board');
|
Chris@76
|
227 list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
228 $smcFunc['db_free_result']($request);
|
Chris@76
|
229
|
Chris@76
|
230 // Remember this for later.
|
Chris@76
|
231 $_SESSION['move_to_topic'] = $_POST['toboard'];
|
Chris@76
|
232
|
Chris@76
|
233 // Rename the topic...
|
Chris@76
|
234 if (isset($_POST['reset_subject'], $_POST['custom_subject']) && $_POST['custom_subject'] != '')
|
Chris@76
|
235 {
|
Chris@76
|
236 $_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
|
Chris@76
|
237 // Keep checking the length.
|
Chris@76
|
238 if ($smcFunc['strlen']($_POST['custom_subject']) > 100)
|
Chris@76
|
239 $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
|
Chris@76
|
240
|
Chris@76
|
241 // If it's still valid move onwards and upwards.
|
Chris@76
|
242 if ($_POST['custom_subject'] != '')
|
Chris@76
|
243 {
|
Chris@76
|
244 if (isset($_POST['enforce_subject']))
|
Chris@76
|
245 {
|
Chris@76
|
246 // Get a response prefix, but in the forum's default language.
|
Chris@76
|
247 if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
|
Chris@76
|
248 {
|
Chris@76
|
249 if ($language === $user_info['language'])
|
Chris@76
|
250 $context['response_prefix'] = $txt['response_prefix'];
|
Chris@76
|
251 else
|
Chris@76
|
252 {
|
Chris@76
|
253 loadLanguage('index', $language, false);
|
Chris@76
|
254 $context['response_prefix'] = $txt['response_prefix'];
|
Chris@76
|
255 loadLanguage('index');
|
Chris@76
|
256 }
|
Chris@76
|
257 cache_put_data('response_prefix', $context['response_prefix'], 600);
|
Chris@76
|
258 }
|
Chris@76
|
259
|
Chris@76
|
260 $smcFunc['db_query']('', '
|
Chris@76
|
261 UPDATE {db_prefix}messages
|
Chris@76
|
262 SET subject = {string:subject}
|
Chris@76
|
263 WHERE id_topic = {int:current_topic}',
|
Chris@76
|
264 array(
|
Chris@76
|
265 'current_topic' => $topic,
|
Chris@76
|
266 'subject' => $context['response_prefix'] . $_POST['custom_subject'],
|
Chris@76
|
267 )
|
Chris@76
|
268 );
|
Chris@76
|
269 }
|
Chris@76
|
270
|
Chris@76
|
271 $smcFunc['db_query']('', '
|
Chris@76
|
272 UPDATE {db_prefix}messages
|
Chris@76
|
273 SET subject = {string:custom_subject}
|
Chris@76
|
274 WHERE id_msg = {int:id_first_msg}',
|
Chris@76
|
275 array(
|
Chris@76
|
276 'id_first_msg' => $id_first_msg,
|
Chris@76
|
277 'custom_subject' => $_POST['custom_subject'],
|
Chris@76
|
278 )
|
Chris@76
|
279 );
|
Chris@76
|
280
|
Chris@76
|
281 // Fix the subject cache.
|
Chris@76
|
282 updateStats('subject', $topic, $_POST['custom_subject']);
|
Chris@76
|
283 }
|
Chris@76
|
284 }
|
Chris@76
|
285
|
Chris@76
|
286 // Create a link to this in the old board.
|
Chris@76
|
287 //!!! Does this make sense if the topic was unapproved before? I'd just about say so.
|
Chris@76
|
288 if (isset($_POST['postRedirect']))
|
Chris@76
|
289 {
|
Chris@76
|
290 // Should be in the boardwide language.
|
Chris@76
|
291 if ($user_info['language'] != $language)
|
Chris@76
|
292 loadLanguage('index', $language);
|
Chris@76
|
293
|
Chris@76
|
294 $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
|
Chris@76
|
295 preparsecode($_POST['reason']);
|
Chris@76
|
296
|
Chris@76
|
297 // Add a URL onto the message.
|
Chris@76
|
298 $_POST['reason'] = strtr($_POST['reason'], array(
|
Chris@76
|
299 $txt['movetopic_auto_board'] => '[url=' . $scripturl . '?board=' . $_POST['toboard'] . '.0]' . $board_name . '[/url]',
|
Chris@76
|
300 $txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]'
|
Chris@76
|
301 ));
|
Chris@76
|
302
|
Chris@76
|
303 $msgOptions = array(
|
Chris@76
|
304 'subject' => $txt['moved'] . ': ' . $subject,
|
Chris@76
|
305 'body' => $_POST['reason'],
|
Chris@76
|
306 'icon' => 'moved',
|
Chris@76
|
307 'smileys_enabled' => 1,
|
Chris@76
|
308 );
|
Chris@76
|
309 $topicOptions = array(
|
Chris@76
|
310 'board' => $board,
|
Chris@76
|
311 'lock_mode' => 1,
|
Chris@76
|
312 'mark_as_read' => true,
|
Chris@76
|
313 );
|
Chris@76
|
314 $posterOptions = array(
|
Chris@76
|
315 'id' => $user_info['id'],
|
Chris@76
|
316 'update_post_count' => empty($pcounter),
|
Chris@76
|
317 );
|
Chris@76
|
318 createPost($msgOptions, $topicOptions, $posterOptions);
|
Chris@76
|
319 }
|
Chris@76
|
320
|
Chris@76
|
321 $request = $smcFunc['db_query']('', '
|
Chris@76
|
322 SELECT count_posts
|
Chris@76
|
323 FROM {db_prefix}boards
|
Chris@76
|
324 WHERE id_board = {int:current_board}
|
Chris@76
|
325 LIMIT 1',
|
Chris@76
|
326 array(
|
Chris@76
|
327 'current_board' => $board,
|
Chris@76
|
328 )
|
Chris@76
|
329 );
|
Chris@76
|
330 list ($pcounter_from) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
331 $smcFunc['db_free_result']($request);
|
Chris@76
|
332
|
Chris@76
|
333 if ($pcounter_from != $pcounter)
|
Chris@76
|
334 {
|
Chris@76
|
335 $request = $smcFunc['db_query']('', '
|
Chris@76
|
336 SELECT id_member
|
Chris@76
|
337 FROM {db_prefix}messages
|
Chris@76
|
338 WHERE id_topic = {int:current_topic}
|
Chris@76
|
339 AND approved = {int:is_approved}',
|
Chris@76
|
340 array(
|
Chris@76
|
341 'current_topic' => $topic,
|
Chris@76
|
342 'is_approved' => 1,
|
Chris@76
|
343 )
|
Chris@76
|
344 );
|
Chris@76
|
345 $posters = array();
|
Chris@76
|
346 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
347 {
|
Chris@76
|
348 if (!isset($posters[$row['id_member']]))
|
Chris@76
|
349 $posters[$row['id_member']] = 0;
|
Chris@76
|
350
|
Chris@76
|
351 $posters[$row['id_member']]++;
|
Chris@76
|
352 }
|
Chris@76
|
353 $smcFunc['db_free_result']($request);
|
Chris@76
|
354
|
Chris@76
|
355 foreach ($posters as $id_member => $posts)
|
Chris@76
|
356 {
|
Chris@76
|
357 // The board we're moving from counted posts, but not to.
|
Chris@76
|
358 if (empty($pcounter_from))
|
Chris@76
|
359 updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
|
Chris@76
|
360 // The reverse: from didn't, to did.
|
Chris@76
|
361 else
|
Chris@76
|
362 updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
|
Chris@76
|
363 }
|
Chris@76
|
364 }
|
Chris@76
|
365
|
Chris@76
|
366 // Do the move (includes statistics update needed for the redirect topic).
|
Chris@76
|
367 moveTopics($topic, $_POST['toboard']);
|
Chris@76
|
368
|
Chris@76
|
369 // Log that they moved this topic.
|
Chris@76
|
370 if (!allowedTo('move_own') || $id_member_started != $user_info['id'])
|
Chris@76
|
371 logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
|
Chris@76
|
372 // Notify people that this topic has been moved?
|
Chris@76
|
373 sendNotifications($topic, 'move');
|
Chris@76
|
374
|
Chris@76
|
375 // Why not go back to the original board in case they want to keep moving?
|
Chris@76
|
376 if (!isset($_REQUEST['goback']))
|
Chris@76
|
377 redirectexit('board=' . $board . '.0');
|
Chris@76
|
378 else
|
Chris@76
|
379 redirectexit('topic=' . $topic . '.0');
|
Chris@76
|
380 }
|
Chris@76
|
381
|
Chris@76
|
382 // Moves one or more topics to a specific board. (doesn't check permissions.)
|
Chris@76
|
383 function moveTopics($topics, $toBoard)
|
Chris@76
|
384 {
|
Chris@76
|
385 global $sourcedir, $user_info, $modSettings, $smcFunc;
|
Chris@76
|
386
|
Chris@76
|
387 // Empty array?
|
Chris@76
|
388 if (empty($topics))
|
Chris@76
|
389 return;
|
Chris@76
|
390 // Only a single topic.
|
Chris@76
|
391 elseif (is_numeric($topics))
|
Chris@76
|
392 $topics = array($topics);
|
Chris@76
|
393 $num_topics = count($topics);
|
Chris@76
|
394 $fromBoards = array();
|
Chris@76
|
395
|
Chris@76
|
396 // Destination board empty or equal to 0?
|
Chris@76
|
397 if (empty($toBoard))
|
Chris@76
|
398 return;
|
Chris@76
|
399
|
Chris@76
|
400 // Are we moving to the recycle board?
|
Chris@76
|
401 $isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard;
|
Chris@76
|
402
|
Chris@76
|
403 // Determine the source boards...
|
Chris@76
|
404 $request = $smcFunc['db_query']('', '
|
Chris@76
|
405 SELECT id_board, approved, COUNT(*) AS num_topics, SUM(unapproved_posts) AS unapproved_posts,
|
Chris@76
|
406 SUM(num_replies) AS num_replies
|
Chris@76
|
407 FROM {db_prefix}topics
|
Chris@76
|
408 WHERE id_topic IN ({array_int:topics})
|
Chris@76
|
409 GROUP BY id_board, approved',
|
Chris@76
|
410 array(
|
Chris@76
|
411 'topics' => $topics,
|
Chris@76
|
412 )
|
Chris@76
|
413 );
|
Chris@76
|
414 // Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards.
|
Chris@76
|
415 if ($smcFunc['db_num_rows']($request) == 0)
|
Chris@76
|
416 return;
|
Chris@76
|
417 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
418 {
|
Chris@76
|
419 if (!isset($fromBoards[$row['id_board']]['num_posts']))
|
Chris@76
|
420 {
|
Chris@76
|
421 $fromBoards[$row['id_board']] = array(
|
Chris@76
|
422 'num_posts' => 0,
|
Chris@76
|
423 'num_topics' => 0,
|
Chris@76
|
424 'unapproved_posts' => 0,
|
Chris@76
|
425 'unapproved_topics' => 0,
|
Chris@76
|
426 'id_board' => $row['id_board']
|
Chris@76
|
427 );
|
Chris@76
|
428 }
|
Chris@76
|
429 // Posts = (num_replies + 1) for each approved topic.
|
Chris@76
|
430 $fromBoards[$row['id_board']]['num_posts'] += $row['num_replies'] + ($row['approved'] ? $row['num_topics'] : 0);
|
Chris@76
|
431 $fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
|
Chris@76
|
432
|
Chris@76
|
433 // Add the topics to the right type.
|
Chris@76
|
434 if ($row['approved'])
|
Chris@76
|
435 $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
|
Chris@76
|
436 else
|
Chris@76
|
437 $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
|
Chris@76
|
438 }
|
Chris@76
|
439 $smcFunc['db_free_result']($request);
|
Chris@76
|
440
|
Chris@76
|
441 // Move over the mark_read data. (because it may be read and now not by some!)
|
Chris@76
|
442 $SaveAServer = max(0, $modSettings['maxMsgID'] - 50000);
|
Chris@76
|
443 $request = $smcFunc['db_query']('', '
|
Chris@76
|
444 SELECT lmr.id_member, lmr.id_msg, t.id_topic
|
Chris@76
|
445 FROM {db_prefix}topics AS t
|
Chris@76
|
446 INNER JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board
|
Chris@76
|
447 AND lmr.id_msg > t.id_first_msg AND lmr.id_msg > {int:protect_lmr_msg})
|
Chris@76
|
448 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = lmr.id_member)
|
Chris@76
|
449 WHERE t.id_topic IN ({array_int:topics})
|
Chris@76
|
450 AND lmr.id_msg > IFNULL(lt.id_msg, 0)',
|
Chris@76
|
451 array(
|
Chris@76
|
452 'protect_lmr_msg' => $SaveAServer,
|
Chris@76
|
453 'topics' => $topics,
|
Chris@76
|
454 )
|
Chris@76
|
455 );
|
Chris@76
|
456 $log_topics = array();
|
Chris@76
|
457 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
458 {
|
Chris@76
|
459 $log_topics[] = array($row['id_topic'], $row['id_member'], $row['id_msg']);
|
Chris@76
|
460
|
Chris@76
|
461 // Prevent queries from getting too big. Taking some steam off.
|
Chris@76
|
462 if (count($log_topics) > 500)
|
Chris@76
|
463 {
|
Chris@76
|
464 $smcFunc['db_insert']('replace',
|
Chris@76
|
465 '{db_prefix}log_topics',
|
Chris@76
|
466 array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
|
Chris@76
|
467 $log_topics,
|
Chris@76
|
468 array('id_topic', 'id_member')
|
Chris@76
|
469 );
|
Chris@76
|
470
|
Chris@76
|
471 $log_topics = array();
|
Chris@76
|
472 }
|
Chris@76
|
473 }
|
Chris@76
|
474 $smcFunc['db_free_result']($request);
|
Chris@76
|
475
|
Chris@76
|
476 // Now that we have all the topics that *should* be marked read, and by which members...
|
Chris@76
|
477 if (!empty($log_topics))
|
Chris@76
|
478 {
|
Chris@76
|
479 // Insert that information into the database!
|
Chris@76
|
480 $smcFunc['db_insert']('replace',
|
Chris@76
|
481 '{db_prefix}log_topics',
|
Chris@76
|
482 array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
|
Chris@76
|
483 $log_topics,
|
Chris@76
|
484 array('id_topic', 'id_member')
|
Chris@76
|
485 );
|
Chris@76
|
486 }
|
Chris@76
|
487
|
Chris@76
|
488 // Update the number of posts on each board.
|
Chris@76
|
489 $totalTopics = 0;
|
Chris@76
|
490 $totalPosts = 0;
|
Chris@76
|
491 $totalUnapprovedTopics = 0;
|
Chris@76
|
492 $totalUnapprovedPosts = 0;
|
Chris@76
|
493 foreach ($fromBoards as $stats)
|
Chris@76
|
494 {
|
Chris@76
|
495 $smcFunc['db_query']('', '
|
Chris@76
|
496 UPDATE {db_prefix}boards
|
Chris@76
|
497 SET
|
Chris@76
|
498 num_posts = CASE WHEN {int:num_posts} > num_posts THEN 0 ELSE num_posts - {int:num_posts} END,
|
Chris@76
|
499 num_topics = CASE WHEN {int:num_topics} > num_topics THEN 0 ELSE num_topics - {int:num_topics} END,
|
Chris@76
|
500 unapproved_posts = CASE WHEN {int:unapproved_posts} > unapproved_posts THEN 0 ELSE unapproved_posts - {int:unapproved_posts} END,
|
Chris@76
|
501 unapproved_topics = CASE WHEN {int:unapproved_topics} > unapproved_topics THEN 0 ELSE unapproved_topics - {int:unapproved_topics} END
|
Chris@76
|
502 WHERE id_board = {int:id_board}',
|
Chris@76
|
503 array(
|
Chris@76
|
504 'id_board' => $stats['id_board'],
|
Chris@76
|
505 'num_posts' => $stats['num_posts'],
|
Chris@76
|
506 'num_topics' => $stats['num_topics'],
|
Chris@76
|
507 'unapproved_posts' => $stats['unapproved_posts'],
|
Chris@76
|
508 'unapproved_topics' => $stats['unapproved_topics'],
|
Chris@76
|
509 )
|
Chris@76
|
510 );
|
Chris@76
|
511 $totalTopics += $stats['num_topics'];
|
Chris@76
|
512 $totalPosts += $stats['num_posts'];
|
Chris@76
|
513 $totalUnapprovedTopics += $stats['unapproved_topics'];
|
Chris@76
|
514 $totalUnapprovedPosts += $stats['unapproved_posts'];
|
Chris@76
|
515 }
|
Chris@76
|
516 $smcFunc['db_query']('', '
|
Chris@76
|
517 UPDATE {db_prefix}boards
|
Chris@76
|
518 SET
|
Chris@76
|
519 num_topics = num_topics + {int:total_topics},
|
Chris@76
|
520 num_posts = num_posts + {int:total_posts},' . ($isRecycleDest ? '
|
Chris@76
|
521 unapproved_posts = {int:no_unapproved}, unapproved_topics = {int:no_unapproved}' : '
|
Chris@76
|
522 unapproved_posts = unapproved_posts + {int:total_unapproved_posts},
|
Chris@76
|
523 unapproved_topics = unapproved_topics + {int:total_unapproved_topics}') . '
|
Chris@76
|
524 WHERE id_board = {int:id_board}',
|
Chris@76
|
525 array(
|
Chris@76
|
526 'id_board' => $toBoard,
|
Chris@76
|
527 'total_topics' => $totalTopics,
|
Chris@76
|
528 'total_posts' => $totalPosts,
|
Chris@76
|
529 'total_unapproved_topics' => $totalUnapprovedTopics,
|
Chris@76
|
530 'total_unapproved_posts' => $totalUnapprovedPosts,
|
Chris@76
|
531 'no_unapproved' => 0,
|
Chris@76
|
532 )
|
Chris@76
|
533 );
|
Chris@76
|
534
|
Chris@76
|
535 // Move the topic. Done. :P
|
Chris@76
|
536 $smcFunc['db_query']('', '
|
Chris@76
|
537 UPDATE {db_prefix}topics
|
Chris@76
|
538 SET id_board = {int:id_board}' . ($isRecycleDest ? ',
|
Chris@76
|
539 unapproved_posts = {int:no_unapproved}, approved = {int:is_approved}' : '') . '
|
Chris@76
|
540 WHERE id_topic IN ({array_int:topics})',
|
Chris@76
|
541 array(
|
Chris@76
|
542 'id_board' => $toBoard,
|
Chris@76
|
543 'topics' => $topics,
|
Chris@76
|
544 'is_approved' => 1,
|
Chris@76
|
545 'no_unapproved' => 0,
|
Chris@76
|
546 )
|
Chris@76
|
547 );
|
Chris@76
|
548
|
Chris@76
|
549 // If this was going to the recycle bin, check what messages are being recycled, and remove them from the queue.
|
Chris@76
|
550 if ($isRecycleDest && ($totalUnapprovedTopics || $totalUnapprovedPosts))
|
Chris@76
|
551 {
|
Chris@76
|
552 $request = $smcFunc['db_query']('', '
|
Chris@76
|
553 SELECT id_msg
|
Chris@76
|
554 FROM {db_prefix}messages
|
Chris@76
|
555 WHERE id_topic IN ({array_int:topics})
|
Chris@76
|
556 and approved = {int:not_approved}',
|
Chris@76
|
557 array(
|
Chris@76
|
558 'topics' => $topics,
|
Chris@76
|
559 'not_approved' => 0,
|
Chris@76
|
560 )
|
Chris@76
|
561 );
|
Chris@76
|
562 $approval_msgs = array();
|
Chris@76
|
563 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
564 $approval_msgs[] = $row['id_msg'];
|
Chris@76
|
565 $smcFunc['db_free_result']($request);
|
Chris@76
|
566
|
Chris@76
|
567 // Empty the approval queue for these, as we're going to approve them next.
|
Chris@76
|
568 if (!empty($approval_msgs))
|
Chris@76
|
569 $smcFunc['db_query']('', '
|
Chris@76
|
570 DELETE FROM {db_prefix}approval_queue
|
Chris@76
|
571 WHERE id_msg IN ({array_int:message_list})
|
Chris@76
|
572 AND id_attach = {int:id_attach}',
|
Chris@76
|
573 array(
|
Chris@76
|
574 'message_list' => $approval_msgs,
|
Chris@76
|
575 'id_attach' => 0,
|
Chris@76
|
576 )
|
Chris@76
|
577 );
|
Chris@76
|
578
|
Chris@76
|
579 // Get all the current max and mins.
|
Chris@76
|
580 $request = $smcFunc['db_query']('', '
|
Chris@76
|
581 SELECT id_topic, id_first_msg, id_last_msg
|
Chris@76
|
582 FROM {db_prefix}topics
|
Chris@76
|
583 WHERE id_topic IN ({array_int:topics})',
|
Chris@76
|
584 array(
|
Chris@76
|
585 'topics' => $topics,
|
Chris@76
|
586 )
|
Chris@76
|
587 );
|
Chris@76
|
588 $topicMaxMin = array();
|
Chris@76
|
589 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
590 {
|
Chris@76
|
591 $topicMaxMin[$row['id_topic']] = array(
|
Chris@76
|
592 'min' => $row['id_first_msg'],
|
Chris@76
|
593 'max' => $row['id_last_msg'],
|
Chris@76
|
594 );
|
Chris@76
|
595 }
|
Chris@76
|
596 $smcFunc['db_free_result']($request);
|
Chris@76
|
597
|
Chris@76
|
598 // Check the MAX and MIN are correct.
|
Chris@76
|
599 $request = $smcFunc['db_query']('', '
|
Chris@76
|
600 SELECT id_topic, MIN(id_msg) AS first_msg, MAX(id_msg) AS last_msg
|
Chris@76
|
601 FROM {db_prefix}messages
|
Chris@76
|
602 WHERE id_topic IN ({array_int:topics})
|
Chris@76
|
603 GROUP BY id_topic',
|
Chris@76
|
604 array(
|
Chris@76
|
605 'topics' => $topics,
|
Chris@76
|
606 )
|
Chris@76
|
607 );
|
Chris@76
|
608 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
609 {
|
Chris@76
|
610 // If not, update.
|
Chris@76
|
611 if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max'])
|
Chris@76
|
612 $smcFunc['db_query']('', '
|
Chris@76
|
613 UPDATE {db_prefix}topics
|
Chris@76
|
614 SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg}
|
Chris@76
|
615 WHERE id_topic = {int:selected_topic}',
|
Chris@76
|
616 array(
|
Chris@76
|
617 'first_msg' => $row['first_msg'],
|
Chris@76
|
618 'last_msg' => $row['last_msg'],
|
Chris@76
|
619 'selected_topic' => $row['id_topic'],
|
Chris@76
|
620 )
|
Chris@76
|
621 );
|
Chris@76
|
622 }
|
Chris@76
|
623 $smcFunc['db_free_result']($request);
|
Chris@76
|
624 }
|
Chris@76
|
625
|
Chris@76
|
626 $smcFunc['db_query']('', '
|
Chris@76
|
627 UPDATE {db_prefix}messages
|
Chris@76
|
628 SET id_board = {int:id_board}' . ($isRecycleDest ? ',approved = {int:is_approved}' : '') . '
|
Chris@76
|
629 WHERE id_topic IN ({array_int:topics})',
|
Chris@76
|
630 array(
|
Chris@76
|
631 'id_board' => $toBoard,
|
Chris@76
|
632 'topics' => $topics,
|
Chris@76
|
633 'is_approved' => 1,
|
Chris@76
|
634 )
|
Chris@76
|
635 );
|
Chris@76
|
636 $smcFunc['db_query']('', '
|
Chris@76
|
637 UPDATE {db_prefix}log_reported
|
Chris@76
|
638 SET id_board = {int:id_board}
|
Chris@76
|
639 WHERE id_topic IN ({array_int:topics})',
|
Chris@76
|
640 array(
|
Chris@76
|
641 'id_board' => $toBoard,
|
Chris@76
|
642 'topics' => $topics,
|
Chris@76
|
643 )
|
Chris@76
|
644 );
|
Chris@76
|
645 $smcFunc['db_query']('', '
|
Chris@76
|
646 UPDATE {db_prefix}calendar
|
Chris@76
|
647 SET id_board = {int:id_board}
|
Chris@76
|
648 WHERE id_topic IN ({array_int:topics})',
|
Chris@76
|
649 array(
|
Chris@76
|
650 'id_board' => $toBoard,
|
Chris@76
|
651 'topics' => $topics,
|
Chris@76
|
652 )
|
Chris@76
|
653 );
|
Chris@76
|
654
|
Chris@76
|
655 // Mark target board as seen, if it was already marked as seen before.
|
Chris@76
|
656 $request = $smcFunc['db_query']('', '
|
Chris@76
|
657 SELECT (IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS isSeen
|
Chris@76
|
658 FROM {db_prefix}boards AS b
|
Chris@76
|
659 LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
|
Chris@76
|
660 WHERE b.id_board = {int:id_board}',
|
Chris@76
|
661 array(
|
Chris@76
|
662 'current_member' => $user_info['id'],
|
Chris@76
|
663 'id_board' => $toBoard,
|
Chris@76
|
664 )
|
Chris@76
|
665 );
|
Chris@76
|
666 list ($isSeen) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
667 $smcFunc['db_free_result']($request);
|
Chris@76
|
668
|
Chris@76
|
669 if (!empty($isSeen) && !$user_info['is_guest'])
|
Chris@76
|
670 {
|
Chris@76
|
671 $smcFunc['db_insert']('replace',
|
Chris@76
|
672 '{db_prefix}log_boards',
|
Chris@76
|
673 array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
|
Chris@76
|
674 array($toBoard, $user_info['id'], $modSettings['maxMsgID']),
|
Chris@76
|
675 array('id_board', 'id_member')
|
Chris@76
|
676 );
|
Chris@76
|
677 }
|
Chris@76
|
678
|
Chris@76
|
679 // Update the cache?
|
Chris@76
|
680 if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
|
Chris@76
|
681 foreach ($topics as $topic_id)
|
Chris@76
|
682 cache_put_data('topic_board-' . $topic_id, null, 120);
|
Chris@76
|
683
|
Chris@76
|
684 require_once($sourcedir . '/Subs-Post.php');
|
Chris@76
|
685
|
Chris@76
|
686 $updates = array_keys($fromBoards);
|
Chris@76
|
687 $updates[] = $toBoard;
|
Chris@76
|
688
|
Chris@76
|
689 updateLastMessages(array_unique($updates));
|
Chris@76
|
690
|
Chris@76
|
691 // Update 'em pesky stats.
|
Chris@76
|
692 updateStats('topic');
|
Chris@76
|
693 updateStats('message');
|
Chris@76
|
694 updateSettings(array(
|
Chris@76
|
695 'calendar_updated' => time(),
|
Chris@76
|
696 ));
|
Chris@76
|
697 }
|
Chris@76
|
698
|
Chris@76
|
699 ?> |