Mercurial > hg > vamp-website
comparison forum/Sources/MessageIndex.php @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Simple Machines Forum (SMF) | |
5 * | |
6 * @package SMF | |
7 * @author Simple Machines http://www.simplemachines.org | |
8 * @copyright 2011 Simple Machines | |
9 * @license http://www.simplemachines.org/about/smf/license.php BSD | |
10 * | |
11 * @version 2.0.2 | |
12 */ | |
13 | |
14 if (!defined('SMF')) | |
15 die('Hacking attempt...'); | |
16 | |
17 /* This file is what shows the listing of topics in a board. It's just one | |
18 function, but don't under estimate it ;). | |
19 | |
20 void MessageIndex() | |
21 // !!! | |
22 | |
23 void QuickModeration() | |
24 // !!! | |
25 | |
26 */ | |
27 | |
28 // Show the list of topics in this board, along with any child boards. | |
29 function MessageIndex() | |
30 { | |
31 global $txt, $scripturl, $board, $modSettings, $context; | |
32 global $options, $settings, $board_info, $user_info, $smcFunc, $sourcedir; | |
33 | |
34 // If this is a redirection board head off. | |
35 if ($board_info['redirect']) | |
36 { | |
37 $smcFunc['db_query']('', ' | |
38 UPDATE {db_prefix}boards | |
39 SET num_posts = num_posts + 1 | |
40 WHERE id_board = {int:current_board}', | |
41 array( | |
42 'current_board' => $board, | |
43 ) | |
44 ); | |
45 | |
46 redirectexit($board_info['redirect']); | |
47 } | |
48 | |
49 if (WIRELESS) | |
50 $context['sub_template'] = WIRELESS_PROTOCOL . '_messageindex'; | |
51 else | |
52 loadTemplate('MessageIndex'); | |
53 | |
54 $context['name'] = $board_info['name']; | |
55 $context['description'] = $board_info['description']; | |
56 // How many topics do we have in total? | |
57 $board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics']; | |
58 | |
59 // View all the topics, or just a few? | |
60 $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) && !WIRELESS ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; | |
61 $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) && !WIRELESS ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; | |
62 $maxindex = isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) ? $board_info['total_topics'] : $context['topics_per_page']; | |
63 | |
64 // Right, let's only index normal stuff! | |
65 if (count($_GET) > 1) | |
66 { | |
67 $session_name = session_name(); | |
68 foreach ($_GET as $k => $v) | |
69 { | |
70 if (!in_array($k, array('board', 'start', $session_name))) | |
71 $context['robot_no_index'] = true; | |
72 } | |
73 } | |
74 if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) | |
75 $context['robot_no_index'] = true; | |
76 | |
77 // If we can view unapproved messages and there are some build up a list. | |
78 if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts'])) | |
79 { | |
80 $untopics = $board_info['unapproved_topics'] ? '<a href="' . $scripturl . '?action=moderate;area=postmod;sa=topics;brd=' . $board . '">' . $board_info['unapproved_topics'] . '</a>' : 0; | |
81 $unposts = $board_info['unapproved_posts'] ? '<a href="' . $scripturl . '?action=moderate;area=postmod;sa=posts;brd=' . $board . '">' . ($board_info['unapproved_posts'] - $board_info['unapproved_topics']) . '</a>' : 0; | |
82 $context['unapproved_posts_message'] = sprintf($txt['there_are_unapproved_topics'], $untopics, $unposts, $scripturl . '?action=moderate;area=postmod;sa=' . ($board_info['unapproved_topics'] ? 'topics' : 'posts') . ';brd=' . $board); | |
83 } | |
84 | |
85 // We only know these. | |
86 if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) | |
87 $_REQUEST['sort'] = 'last_post'; | |
88 | |
89 // Make sure the starting place makes sense and construct the page index. | |
90 if (isset($_REQUEST['sort'])) | |
91 $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true); | |
92 else | |
93 $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true); | |
94 $context['start'] = &$_REQUEST['start']; | |
95 | |
96 // Set a canonical URL for this page. | |
97 $context['canonical_url'] = $scripturl . '?board=' . $board . '.' . $context['start']; | |
98 | |
99 $context['links'] = array( | |
100 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?board=' . $board . '.0' : '', | |
101 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] - $context['topics_per_page']) : '', | |
102 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $board_info['total_topics'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] + $context['topics_per_page']) : '', | |
103 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $board_info['total_topics'] ? $scripturl . '?board=' . $board . '.' . (floor(($board_info['total_topics'] - 1) / $context['topics_per_page']) * $context['topics_per_page']) : '', | |
104 'up' => $board_info['parent'] == 0 ? $scripturl . '?' : $scripturl . '?board=' . $board_info['parent'] . '.0' | |
105 ); | |
106 | |
107 $context['page_info'] = array( | |
108 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, | |
109 'num_pages' => floor(($board_info['total_topics'] - 1) / $context['topics_per_page']) + 1 | |
110 ); | |
111 | |
112 if (isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) && $maxindex > $modSettings['enableAllMessages']) | |
113 { | |
114 $maxindex = $modSettings['enableAllMessages']; | |
115 $_REQUEST['start'] = 0; | |
116 } | |
117 | |
118 // Build a list of the board's moderators. | |
119 $context['moderators'] = &$board_info['moderators']; | |
120 $context['link_moderators'] = array(); | |
121 if (!empty($board_info['moderators'])) | |
122 { | |
123 foreach ($board_info['moderators'] as $mod) | |
124 $context['link_moderators'][] ='<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; | |
125 | |
126 $context['linktree'][count($context['linktree']) - 1]['extra_after'] = ' (' . (count($context['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators']) . ': ' . implode(', ', $context['link_moderators']) . ')'; | |
127 } | |
128 | |
129 // Mark current and parent boards as seen. | |
130 if (!$user_info['is_guest']) | |
131 { | |
132 // We can't know they read it if we allow prefetches. | |
133 if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') | |
134 { | |
135 ob_end_clean(); | |
136 header('HTTP/1.1 403 Prefetch Forbidden'); | |
137 die; | |
138 } | |
139 | |
140 $smcFunc['db_insert']('replace', | |
141 '{db_prefix}log_boards', | |
142 array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'), | |
143 array($modSettings['maxMsgID'], $user_info['id'], $board), | |
144 array('id_member', 'id_board') | |
145 ); | |
146 | |
147 if (!empty($board_info['parent_boards'])) | |
148 { | |
149 $smcFunc['db_query']('', ' | |
150 UPDATE {db_prefix}log_boards | |
151 SET id_msg = {int:id_msg} | |
152 WHERE id_member = {int:current_member} | |
153 AND id_board IN ({array_int:board_list})', | |
154 array( | |
155 'current_member' => $user_info['id'], | |
156 'board_list' => array_keys($board_info['parent_boards']), | |
157 'id_msg' => $modSettings['maxMsgID'], | |
158 ) | |
159 ); | |
160 | |
161 // We've seen all these boards now! | |
162 foreach ($board_info['parent_boards'] as $k => $dummy) | |
163 if (isset($_SESSION['topicseen_cache'][$k])) | |
164 unset($_SESSION['topicseen_cache'][$k]); | |
165 } | |
166 | |
167 if (isset($_SESSION['topicseen_cache'][$board])) | |
168 unset($_SESSION['topicseen_cache'][$board]); | |
169 | |
170 $request = $smcFunc['db_query']('', ' | |
171 SELECT sent | |
172 FROM {db_prefix}log_notify | |
173 WHERE id_board = {int:current_board} | |
174 AND id_member = {int:current_member} | |
175 LIMIT 1', | |
176 array( | |
177 'current_board' => $board, | |
178 'current_member' => $user_info['id'], | |
179 ) | |
180 ); | |
181 $context['is_marked_notify'] = $smcFunc['db_num_rows']($request) != 0; | |
182 if ($context['is_marked_notify']) | |
183 { | |
184 list ($sent) = $smcFunc['db_fetch_row']($request); | |
185 if (!empty($sent)) | |
186 { | |
187 $smcFunc['db_query']('', ' | |
188 UPDATE {db_prefix}log_notify | |
189 SET sent = {int:is_sent} | |
190 WHERE id_board = {int:current_board} | |
191 AND id_member = {int:current_member}', | |
192 array( | |
193 'current_board' => $board, | |
194 'current_member' => $user_info['id'], | |
195 'is_sent' => 0, | |
196 ) | |
197 ); | |
198 } | |
199 } | |
200 $smcFunc['db_free_result']($request); | |
201 } | |
202 else | |
203 $context['is_marked_notify'] = false; | |
204 | |
205 // 'Print' the header and board info. | |
206 $context['page_title'] = strip_tags($board_info['name']); | |
207 | |
208 // Set the variables up for the template. | |
209 $context['can_mark_notify'] = allowedTo('mark_notify') && !$user_info['is_guest']; | |
210 $context['can_post_new'] = allowedTo('post_new') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_topics')); | |
211 $context['can_post_poll'] = $modSettings['pollMode'] == '1' && allowedTo('poll_post') && $context['can_post_new']; | |
212 $context['can_moderate_forum'] = allowedTo('moderate_forum'); | |
213 $context['can_approve_posts'] = allowedTo('approve_posts'); | |
214 | |
215 require_once($sourcedir . '/Subs-BoardIndex.php'); | |
216 $boardIndexOptions = array( | |
217 'include_categories' => false, | |
218 'base_level' => $board_info['child_level'] + 1, | |
219 'parent_id' => $board_info['id'], | |
220 'set_latest_post' => false, | |
221 'countChildPosts' => !empty($modSettings['countChildPosts']), | |
222 ); | |
223 $context['boards'] = getBoardIndex($boardIndexOptions); | |
224 | |
225 // Nosey, nosey - who's viewing this topic? | |
226 if (!empty($settings['display_who_viewing'])) | |
227 { | |
228 $context['view_members'] = array(); | |
229 $context['view_members_list'] = array(); | |
230 $context['view_num_hidden'] = 0; | |
231 | |
232 $request = $smcFunc['db_query']('', ' | |
233 SELECT | |
234 lo.id_member, lo.log_time, mem.real_name, mem.member_name, mem.show_online, | |
235 mg.online_color, mg.id_group, mg.group_name | |
236 FROM {db_prefix}log_online AS lo | |
237 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lo.id_member) | |
238 LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_member_group} THEN mem.id_post_group ELSE mem.id_group END) | |
239 WHERE INSTR(lo.url, {string:in_url_string}) > 0 OR lo.session = {string:session}', | |
240 array( | |
241 'reg_member_group' => 0, | |
242 'in_url_string' => 's:5:"board";i:' . $board . ';', | |
243 'session' => $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(), | |
244 ) | |
245 ); | |
246 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
247 { | |
248 if (empty($row['id_member'])) | |
249 continue; | |
250 | |
251 if (!empty($row['online_color'])) | |
252 $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; | |
253 else | |
254 $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; | |
255 | |
256 $is_buddy = in_array($row['id_member'], $user_info['buddies']); | |
257 if ($is_buddy) | |
258 $link = '<strong>' . $link . '</strong>'; | |
259 | |
260 if (!empty($row['show_online']) || allowedTo('moderate_forum')) | |
261 $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; | |
262 $context['view_members'][$row['log_time'] . $row['member_name']] = array( | |
263 'id' => $row['id_member'], | |
264 'username' => $row['member_name'], | |
265 'name' => $row['real_name'], | |
266 'group' => $row['id_group'], | |
267 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], | |
268 'link' => $link, | |
269 'is_buddy' => $is_buddy, | |
270 'hidden' => empty($row['show_online']), | |
271 ); | |
272 | |
273 if (empty($row['show_online'])) | |
274 $context['view_num_hidden']++; | |
275 } | |
276 $context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']); | |
277 $smcFunc['db_free_result']($request); | |
278 | |
279 // Put them in "last clicked" order. | |
280 krsort($context['view_members_list']); | |
281 krsort($context['view_members']); | |
282 } | |
283 | |
284 // Default sort methods. | |
285 $sort_methods = array( | |
286 'subject' => 'mf.subject', | |
287 'starter' => 'IFNULL(memf.real_name, mf.poster_name)', | |
288 'last_poster' => 'IFNULL(meml.real_name, ml.poster_name)', | |
289 'replies' => 't.num_replies', | |
290 'views' => 't.num_views', | |
291 'first_post' => 't.id_topic', | |
292 'last_post' => 't.id_last_msg' | |
293 ); | |
294 | |
295 // They didn't pick one, default to by last post descending. | |
296 if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) | |
297 { | |
298 $context['sort_by'] = 'last_post'; | |
299 $_REQUEST['sort'] = 'id_last_msg'; | |
300 $ascending = isset($_REQUEST['asc']); | |
301 } | |
302 // Otherwise default to ascending. | |
303 else | |
304 { | |
305 $context['sort_by'] = $_REQUEST['sort']; | |
306 $_REQUEST['sort'] = $sort_methods[$_REQUEST['sort']]; | |
307 $ascending = !isset($_REQUEST['desc']); | |
308 } | |
309 | |
310 $context['sort_direction'] = $ascending ? 'up' : 'down'; | |
311 | |
312 // Calculate the fastest way to get the topics. | |
313 $start = (int) $_REQUEST['start']; | |
314 if ($start > ($board_info['total_topics'] - 1) / 2) | |
315 { | |
316 $ascending = !$ascending; | |
317 $fake_ascending = true; | |
318 $maxindex = $board_info['total_topics'] < $start + $maxindex + 1 ? $board_info['total_topics'] - $start : $maxindex; | |
319 $start = $board_info['total_topics'] < $start + $maxindex + 1 ? 0 : $board_info['total_topics'] - $start - $maxindex; | |
320 } | |
321 else | |
322 $fake_ascending = false; | |
323 | |
324 // Setup the default topic icons... | |
325 $stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless', 'clip'); | |
326 $context['icon_sources'] = array(); | |
327 foreach ($stable_icons as $icon) | |
328 $context['icon_sources'][$icon] = 'images_url'; | |
329 | |
330 $topic_ids = array(); | |
331 $context['topics'] = array(); | |
332 | |
333 // Sequential pages are often not optimized, so we add an additional query. | |
334 $pre_query = $start > 0; | |
335 if ($pre_query && $maxindex > 0) | |
336 { | |
337 $request = $smcFunc['db_query']('', ' | |
338 SELECT t.id_topic | |
339 FROM {db_prefix}topics AS t' . ($context['sort_by'] === 'last_poster' ? ' | |
340 INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)' : (in_array($context['sort_by'], array('starter', 'subject')) ? ' | |
341 INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)' : '')) . ($context['sort_by'] === 'starter' ? ' | |
342 LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' : '') . ($context['sort_by'] === 'last_poster' ? ' | |
343 LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' : '') . ' | |
344 WHERE t.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : ' | |
345 AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . ' | |
346 ORDER BY ' . (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . ' | |
347 LIMIT {int:start}, {int:maxindex}', | |
348 array( | |
349 'current_board' => $board, | |
350 'current_member' => $user_info['id'], | |
351 'is_approved' => 1, | |
352 'id_member_guest' => 0, | |
353 'start' => $start, | |
354 'maxindex' => $maxindex, | |
355 ) | |
356 ); | |
357 $topic_ids = array(); | |
358 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
359 $topic_ids[] = $row['id_topic']; | |
360 } | |
361 | |
362 // Grab the appropriate topic information... | |
363 if (!$pre_query || !empty($topic_ids)) | |
364 { | |
365 // For search engine effectiveness we'll link guests differently. | |
366 $context['pageindex_multiplier'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) && !WIRELESS ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; | |
367 | |
368 $result = $smcFunc['db_query']('substring', ' | |
369 SELECT | |
370 t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board, | |
371 ' . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from, | |
372 t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, | |
373 ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon, | |
374 ml.poster_name AS last_member_name, ml.id_member AS last_id_member, | |
375 IFNULL(meml.real_name, ml.poster_name) AS last_display_name, t.id_first_msg, | |
376 mf.poster_time AS first_poster_time, mf.subject AS first_subject, mf.icon AS first_icon, | |
377 mf.poster_name AS first_member_name, mf.id_member AS first_id_member, | |
378 IFNULL(memf.real_name, mf.poster_name) AS first_display_name, SUBSTRING(ml.body, 1, 385) AS last_body, | |
379 SUBSTRING(mf.body, 1, 385) AS first_body, ml.smileys_enabled AS last_smileys, mf.smileys_enabled AS first_smileys | |
380 FROM {db_prefix}topics AS t | |
381 INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) | |
382 INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) | |
383 LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member) | |
384 LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' . ($user_info['is_guest'] ? '' : ' | |
385 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) | |
386 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})'). ' | |
387 WHERE ' . ($pre_query ? 't.id_topic IN ({array_int:topic_list})' : 't.id_board = {int:current_board}') . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : ' | |
388 AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . ' | |
389 ORDER BY ' . ($pre_query ? 'FIND_IN_SET(t.id_topic, {string:find_set_topics})' : (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC')) . ' | |
390 LIMIT ' . ($pre_query ? '' : '{int:start}, ') . '{int:maxindex}', | |
391 array( | |
392 'current_board' => $board, | |
393 'current_member' => $user_info['id'], | |
394 'topic_list' => $topic_ids, | |
395 'is_approved' => 1, | |
396 'find_set_topics' => implode(',', $topic_ids), | |
397 'start' => $start, | |
398 'maxindex' => $maxindex, | |
399 ) | |
400 ); | |
401 | |
402 // Begin 'printing' the message index for current board. | |
403 while ($row = $smcFunc['db_fetch_assoc']($result)) | |
404 { | |
405 if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') | |
406 continue; | |
407 | |
408 if (!$pre_query) | |
409 $topic_ids[] = $row['id_topic']; | |
410 | |
411 if (!empty($settings['message_index_preview'])) | |
412 { | |
413 // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise. | |
414 $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br />' => ' '))); | |
415 if ($smcFunc['strlen']($row['first_body']) > 128) | |
416 $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; | |
417 $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br />' => ' '))); | |
418 if ($smcFunc['strlen']($row['last_body']) > 128) | |
419 $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; | |
420 | |
421 // Censor the subject and message preview. | |
422 censorText($row['first_subject']); | |
423 censorText($row['first_body']); | |
424 | |
425 // Don't censor them twice! | |
426 if ($row['id_first_msg'] == $row['id_last_msg']) | |
427 { | |
428 $row['last_subject'] = $row['first_subject']; | |
429 $row['last_body'] = $row['first_body']; | |
430 } | |
431 else | |
432 { | |
433 censorText($row['last_subject']); | |
434 censorText($row['last_body']); | |
435 } | |
436 } | |
437 else | |
438 { | |
439 $row['first_body'] = ''; | |
440 $row['last_body'] = ''; | |
441 censorText($row['first_subject']); | |
442 | |
443 if ($row['id_first_msg'] == $row['id_last_msg']) | |
444 $row['last_subject'] = $row['first_subject']; | |
445 else | |
446 censorText($row['last_subject']); | |
447 } | |
448 | |
449 // Decide how many pages the topic should have. | |
450 if ($row['num_replies'] + 1 > $context['messages_per_page']) | |
451 { | |
452 $pages = '« '; | |
453 | |
454 // We can't pass start by reference. | |
455 $start = -1; | |
456 $pages .= constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true); | |
457 | |
458 // If we can use all, show all. | |
459 if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) | |
460 $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; | |
461 $pages .= ' »'; | |
462 } | |
463 else | |
464 $pages = ''; | |
465 | |
466 // We need to check the topic icons exist... | |
467 if (empty($modSettings['messageIconChecks_disable'])) | |
468 { | |
469 if (!isset($context['icon_sources'][$row['first_icon']])) | |
470 $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.gif') ? 'images_url' : 'default_images_url'; | |
471 if (!isset($context['icon_sources'][$row['last_icon']])) | |
472 $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.gif') ? 'images_url' : 'default_images_url'; | |
473 } | |
474 else | |
475 { | |
476 if (!isset($context['icon_sources'][$row['first_icon']])) | |
477 $context['icon_sources'][$row['first_icon']] = 'images_url'; | |
478 if (!isset($context['icon_sources'][$row['last_icon']])) | |
479 $context['icon_sources'][$row['last_icon']] = 'images_url'; | |
480 } | |
481 | |
482 // 'Print' the topic info. | |
483 $context['topics'][$row['id_topic']] = array( | |
484 'id' => $row['id_topic'], | |
485 'first_post' => array( | |
486 'id' => $row['id_first_msg'], | |
487 'member' => array( | |
488 'username' => $row['first_member_name'], | |
489 'name' => $row['first_display_name'], | |
490 'id' => $row['first_id_member'], | |
491 'href' => !empty($row['first_id_member']) ? $scripturl . '?action=profile;u=' . $row['first_id_member'] : '', | |
492 'link' => !empty($row['first_id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['first_id_member'] . '" title="' . $txt['profile_of'] . ' ' . $row['first_display_name'] . '">' . $row['first_display_name'] . '</a>' : $row['first_display_name'] | |
493 ), | |
494 'time' => timeformat($row['first_poster_time']), | |
495 'timestamp' => forum_time(true, $row['first_poster_time']), | |
496 'subject' => $row['first_subject'], | |
497 'preview' => $row['first_body'], | |
498 'icon' => $row['first_icon'], | |
499 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.gif', | |
500 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', | |
501 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['first_subject'] . '</a>' | |
502 ), | |
503 'last_post' => array( | |
504 'id' => $row['id_last_msg'], | |
505 'member' => array( | |
506 'username' => $row['last_member_name'], | |
507 'name' => $row['last_display_name'], | |
508 'id' => $row['last_id_member'], | |
509 'href' => !empty($row['last_id_member']) ? $scripturl . '?action=profile;u=' . $row['last_id_member'] : '', | |
510 'link' => !empty($row['last_id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['last_id_member'] . '">' . $row['last_display_name'] . '</a>' : $row['last_display_name'] | |
511 ), | |
512 'time' => timeformat($row['last_poster_time']), | |
513 'timestamp' => forum_time(true, $row['last_poster_time']), | |
514 'subject' => $row['last_subject'], | |
515 'preview' => $row['last_body'], | |
516 'icon' => $row['last_icon'], | |
517 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.gif', | |
518 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($user_info['is_guest'] ? ('.' . (!empty($options['view_newest_first']) ? 0 : ((int) (($row['num_replies']) / $context['pageindex_multiplier'])) * $context['pageindex_multiplier']) . '#msg' . $row['id_last_msg']) : (($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new')), | |
519 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($user_info['is_guest'] ? ('.' . (!empty($options['view_newest_first']) ? 0 : ((int) (($row['num_replies']) / $context['pageindex_multiplier'])) * $context['pageindex_multiplier']) . '#msg' . $row['id_last_msg']) : (($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new')) . '" ' . ($row['num_replies'] == 0 ? '' : 'rel="nofollow"') . '>' . $row['last_subject'] . '</a>' | |
520 ), | |
521 'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['is_sticky']), | |
522 'is_locked' => !empty($row['locked']), | |
523 'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0, | |
524 'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'], | |
525 'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'], | |
526 'is_posted_in' => false, | |
527 'icon' => $row['first_icon'], | |
528 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.gif', | |
529 'subject' => $row['first_subject'], | |
530 'new' => $row['new_from'] <= $row['id_msg_modified'], | |
531 'new_from' => $row['new_from'], | |
532 'newtime' => $row['new_from'], | |
533 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new', | |
534 'pages' => $pages, | |
535 'replies' => comma_format($row['num_replies']), | |
536 'views' => comma_format($row['num_views']), | |
537 'approved' => $row['approved'], | |
538 'unapproved_posts' => $row['unapproved_posts'], | |
539 ); | |
540 | |
541 determineTopicClass($context['topics'][$row['id_topic']]); | |
542 } | |
543 $smcFunc['db_free_result']($result); | |
544 | |
545 // Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...) | |
546 if ($fake_ascending) | |
547 $context['topics'] = array_reverse($context['topics'], true); | |
548 | |
549 if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'] && !empty($topic_ids)) | |
550 { | |
551 $result = $smcFunc['db_query']('', ' | |
552 SELECT id_topic | |
553 FROM {db_prefix}messages | |
554 WHERE id_topic IN ({array_int:topic_list}) | |
555 AND id_member = {int:current_member} | |
556 GROUP BY id_topic | |
557 LIMIT ' . count($topic_ids), | |
558 array( | |
559 'current_member' => $user_info['id'], | |
560 'topic_list' => $topic_ids, | |
561 ) | |
562 ); | |
563 while ($row = $smcFunc['db_fetch_assoc']($result)) | |
564 { | |
565 $context['topics'][$row['id_topic']]['is_posted_in'] = true; | |
566 $context['topics'][$row['id_topic']]['class'] = 'my_' . $context['topics'][$row['id_topic']]['class']; | |
567 } | |
568 $smcFunc['db_free_result']($result); | |
569 } | |
570 } | |
571 | |
572 $context['jump_to'] = array( | |
573 'label' => addslashes(un_htmlspecialchars($txt['jump_to'])), | |
574 'board_name' => htmlspecialchars(strtr(strip_tags($board_info['name']), array('&' => '&'))), | |
575 'child_level' => $board_info['child_level'], | |
576 ); | |
577 | |
578 // Is Quick Moderation active/needed? | |
579 if (!empty($options['display_quick_mod']) && !empty($context['topics'])) | |
580 { | |
581 $context['can_lock'] = allowedTo('lock_any'); | |
582 $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']); | |
583 $context['can_move'] = allowedTo('move_any'); | |
584 $context['can_remove'] = allowedTo('remove_any'); | |
585 $context['can_merge'] = allowedTo('merge_any'); | |
586 // Ignore approving own topics as it's unlikely to come up... | |
587 $context['can_approve'] = $modSettings['postmod_active'] && allowedTo('approve_posts') && !empty($board_info['unapproved_topics']); | |
588 // Can we restore topics? | |
589 $context['can_restore'] = allowedTo('move_any') && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board; | |
590 | |
591 // Set permissions for all the topics. | |
592 foreach ($context['topics'] as $t => $topic) | |
593 { | |
594 $started = $topic['first_post']['member']['id'] == $user_info['id']; | |
595 $context['topics'][$t]['quick_mod'] = array( | |
596 'lock' => allowedTo('lock_any') || ($started && allowedTo('lock_own')), | |
597 'sticky' => allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']), | |
598 'move' => allowedTo('move_any') || ($started && allowedTo('move_own')), | |
599 'modify' => allowedTo('modify_any') || ($started && allowedTo('modify_own')), | |
600 'remove' => allowedTo('remove_any') || ($started && allowedTo('remove_own')), | |
601 'approve' => $context['can_approve'] && $topic['unapproved_posts'] | |
602 ); | |
603 $context['can_lock'] |= ($started && allowedTo('lock_own')); | |
604 $context['can_move'] |= ($started && allowedTo('move_own')); | |
605 $context['can_remove'] |= ($started && allowedTo('remove_own')); | |
606 } | |
607 | |
608 // Find the boards/cateogories they can move their topic to. | |
609 if ($options['display_quick_mod'] == 1 && $context['can_move'] && !empty($context['topics'])) | |
610 { | |
611 require_once($sourcedir . '/Subs-MessageIndex.php'); | |
612 $boardListOptions = array( | |
613 'excluded_boards' => array($board), | |
614 'not_redirection' => true, | |
615 'use_permissions' => true, | |
616 'selected_board' => empty($_SESSION['move_to_topic']) ? null : $_SESSION['move_to_topic'], | |
617 ); | |
618 $context['move_to_boards'] = getBoardList($boardListOptions); | |
619 | |
620 // Make the boards safe for display. | |
621 foreach ($context['move_to_boards'] as $id_cat => $cat) | |
622 { | |
623 $context['move_to_boards'][$id_cat]['name'] = strip_tags($cat['name']); | |
624 foreach ($cat['boards'] as $id_board => $board) | |
625 $context['move_to_boards'][$id_cat]['boards'][$id_board]['name'] = strip_tags($board['name']); | |
626 } | |
627 | |
628 // With no other boards to see, it's useless to move. | |
629 if (empty($context['move_to_boards'])) | |
630 $context['can_move'] = false; | |
631 } | |
632 // Can we use quick moderation checkboxes? | |
633 if ($options['display_quick_mod'] == 1) | |
634 $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore']; | |
635 // Or the icons? | |
636 else | |
637 $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; | |
638 } | |
639 | |
640 // If there are children, but no topics and no ability to post topics... | |
641 $context['no_topic_listing'] = !empty($context['boards']) && empty($context['topics']) && !$context['can_post_new']; | |
642 } | |
643 | |
644 // Allows for moderation from the message index. | |
645 function QuickModeration() | |
646 { | |
647 global $sourcedir, $board, $user_info, $modSettings, $sourcedir, $smcFunc, $context; | |
648 | |
649 // Check the session = get or post. | |
650 checkSession('request'); | |
651 | |
652 // Lets go straight to the restore area. | |
653 if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) | |
654 redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']); | |
655 | |
656 if (isset($_SESSION['topicseen_cache'])) | |
657 $_SESSION['topicseen_cache'] = array(); | |
658 | |
659 // This is going to be needed to send off the notifications and for updateLastMessages(). | |
660 require_once($sourcedir . '/Subs-Post.php'); | |
661 | |
662 // Remember the last board they moved things to. | |
663 if (isset($_REQUEST['move_to'])) | |
664 $_SESSION['move_to_topic'] = $_REQUEST['move_to']; | |
665 | |
666 // Only a few possible actions. | |
667 $possibleActions = array(); | |
668 | |
669 if (!empty($board)) | |
670 { | |
671 $boards_can = array( | |
672 'make_sticky' => allowedTo('make_sticky') ? array($board) : array(), | |
673 'move_any' => allowedTo('move_any') ? array($board) : array(), | |
674 'move_own' => allowedTo('move_own') ? array($board) : array(), | |
675 'remove_any' => allowedTo('remove_any') ? array($board) : array(), | |
676 'remove_own' => allowedTo('remove_own') ? array($board) : array(), | |
677 'lock_any' => allowedTo('lock_any') ? array($board) : array(), | |
678 'lock_own' => allowedTo('lock_own') ? array($board) : array(), | |
679 'merge_any' => allowedTo('merge_any') ? array($board) : array(), | |
680 'approve_posts' => allowedTo('approve_posts') ? array($board) : array(), | |
681 ); | |
682 | |
683 $redirect_url = 'board=' . $board . '.' . $_REQUEST['start']; | |
684 } | |
685 else | |
686 { | |
687 // !!! Ugly. There's no getting around this, is there? | |
688 // !!! Maybe just do this on the actions people want to use? | |
689 $boards_can = array( | |
690 'make_sticky' => boardsAllowedTo('make_sticky'), | |
691 'move_any' => boardsAllowedTo('move_any'), | |
692 'move_own' => boardsAllowedTo('move_own'), | |
693 'remove_any' => boardsAllowedTo('remove_any'), | |
694 'remove_own' => boardsAllowedTo('remove_own'), | |
695 'lock_any' => boardsAllowedTo('lock_any'), | |
696 'lock_own' => boardsAllowedTo('lock_own'), | |
697 'merge_any' => boardsAllowedTo('merge_any'), | |
698 'approve_posts' => boardsAllowedTo('approve_posts'), | |
699 ); | |
700 | |
701 $redirect_url = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : (isset($_SESSION['old_url']) ? $_SESSION['old_url'] : ''); | |
702 } | |
703 | |
704 if (!$user_info['is_guest']) | |
705 $possibleActions[] = 'markread'; | |
706 if (!empty($boards_can['make_sticky']) && !empty($modSettings['enableStickyTopics'])) | |
707 $possibleActions[] = 'sticky'; | |
708 if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) | |
709 $possibleActions[] = 'move'; | |
710 if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) | |
711 $possibleActions[] = 'remove'; | |
712 if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) | |
713 $possibleActions[] = 'lock'; | |
714 if (!empty($boards_can['merge_any'])) | |
715 $possibleActions[] = 'merge'; | |
716 if (!empty($boards_can['approve_posts'])) | |
717 $possibleActions[] = 'approve'; | |
718 | |
719 // Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction']. | |
720 // (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.) | |
721 if (!empty($_REQUEST['topics'])) | |
722 { | |
723 // If the action isn't valid, just quit now. | |
724 if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) | |
725 redirectexit($redirect_url); | |
726 | |
727 // Merge requires all topics as one parameter and can be done at once. | |
728 if ($_REQUEST['qaction'] == 'merge') | |
729 { | |
730 // Merge requires at least two topics. | |
731 if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) | |
732 redirectexit($redirect_url); | |
733 | |
734 require_once($sourcedir . '/SplitTopics.php'); | |
735 return MergeExecute($_REQUEST['topics']); | |
736 } | |
737 | |
738 // Just convert to the other method, to make it easier. | |
739 foreach ($_REQUEST['topics'] as $topic) | |
740 $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction']; | |
741 } | |
742 | |
743 // Weird... how'd you get here? | |
744 if (empty($_REQUEST['actions'])) | |
745 redirectexit($redirect_url); | |
746 | |
747 // Validate each action. | |
748 $temp = array(); | |
749 foreach ($_REQUEST['actions'] as $topic => $action) | |
750 { | |
751 if (in_array($action, $possibleActions)) | |
752 $temp[(int) $topic] = $action; | |
753 } | |
754 $_REQUEST['actions'] = $temp; | |
755 | |
756 if (!empty($_REQUEST['actions'])) | |
757 { | |
758 // Find all topics... | |
759 $request = $smcFunc['db_query']('', ' | |
760 SELECT id_topic, id_member_started, id_board, locked, approved, unapproved_posts | |
761 FROM {db_prefix}topics | |
762 WHERE id_topic IN ({array_int:action_topic_ids}) | |
763 LIMIT ' . count($_REQUEST['actions']), | |
764 array( | |
765 'action_topic_ids' => array_keys($_REQUEST['actions']), | |
766 ) | |
767 ); | |
768 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
769 { | |
770 if (!empty($board)) | |
771 { | |
772 if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) | |
773 unset($_REQUEST['actions'][$row['id_topic']]); | |
774 } | |
775 else | |
776 { | |
777 // Don't allow them to act on unapproved posts they can't see... | |
778 if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) | |
779 unset($_REQUEST['actions'][$row['id_topic']]); | |
780 // Goodness, this is fun. We need to validate the action. | |
781 elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) | |
782 unset($_REQUEST['actions'][$row['id_topic']]); | |
783 elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) | |
784 unset($_REQUEST['actions'][$row['id_topic']]); | |
785 elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) | |
786 unset($_REQUEST['actions'][$row['id_topic']]); | |
787 elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $locked == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) | |
788 unset($_REQUEST['actions'][$row['id_topic']]); | |
789 // If the topic is approved then you need permission to approve the posts within. | |
790 elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) | |
791 unset($_REQUEST['actions'][$row['id_topic']]); | |
792 } | |
793 } | |
794 $smcFunc['db_free_result']($request); | |
795 } | |
796 | |
797 $stickyCache = array(); | |
798 $moveCache = array(0 => array(), 1 => array()); | |
799 $removeCache = array(); | |
800 $lockCache = array(); | |
801 $markCache = array(); | |
802 $approveCache = array(); | |
803 | |
804 // Separate the actions. | |
805 foreach ($_REQUEST['actions'] as $topic => $action) | |
806 { | |
807 $topic = (int) $topic; | |
808 | |
809 if ($action == 'markread') | |
810 $markCache[] = $topic; | |
811 elseif ($action == 'sticky') | |
812 $stickyCache[] = $topic; | |
813 elseif ($action == 'move') | |
814 { | |
815 // $moveCache[0] is the topic, $moveCache[1] is the board to move to. | |
816 $moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']); | |
817 | |
818 if (empty($moveCache[1][$topic])) | |
819 continue; | |
820 | |
821 $moveCache[0][] = $topic; | |
822 } | |
823 elseif ($action == 'remove') | |
824 $removeCache[] = $topic; | |
825 elseif ($action == 'lock') | |
826 $lockCache[] = $topic; | |
827 elseif ($action == 'approve') | |
828 $approveCache[] = $topic; | |
829 } | |
830 | |
831 if (empty($board)) | |
832 $affectedBoards = array(); | |
833 else | |
834 $affectedBoards = array($board => array(0, 0)); | |
835 | |
836 // Do all the stickies... | |
837 if (!empty($stickyCache)) | |
838 { | |
839 $smcFunc['db_query']('', ' | |
840 UPDATE {db_prefix}topics | |
841 SET is_sticky = CASE WHEN is_sticky = {int:is_sticky} THEN 0 ELSE 1 END | |
842 WHERE id_topic IN ({array_int:sticky_topic_ids})', | |
843 array( | |
844 'sticky_topic_ids' => $stickyCache, | |
845 'is_sticky' => 1, | |
846 ) | |
847 ); | |
848 | |
849 // Get the board IDs and Sticky status | |
850 $request = $smcFunc['db_query']('', ' | |
851 SELECT id_topic, id_board, is_sticky | |
852 FROM {db_prefix}topics | |
853 WHERE id_topic IN ({array_int:sticky_topic_ids}) | |
854 LIMIT ' . count($stickyCache), | |
855 array( | |
856 'sticky_topic_ids' => $stickyCache, | |
857 ) | |
858 ); | |
859 $stickyCacheBoards = array(); | |
860 $stickyCacheStatus = array(); | |
861 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
862 { | |
863 $stickyCacheBoards[$row['id_topic']] = $row['id_board']; | |
864 $stickyCacheStatus[$row['id_topic']] = empty($row['is_sticky']); | |
865 } | |
866 $smcFunc['db_free_result']($request); | |
867 } | |
868 | |
869 // Move sucka! (this is, by the by, probably the most complicated part....) | |
870 if (!empty($moveCache[0])) | |
871 { | |
872 // I know - I just KNOW you're trying to beat the system. Too bad for you... we CHECK :P. | |
873 $request = $smcFunc['db_query']('', ' | |
874 SELECT t.id_topic, t.id_board, b.count_posts | |
875 FROM {db_prefix}topics AS t | |
876 LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board) | |
877 WHERE t.id_topic IN ({array_int:move_topic_ids})' . (!empty($board) && !allowedTo('move_any') ? ' | |
878 AND t.id_member_started = {int:current_member}' : '') . ' | |
879 LIMIT ' . count($moveCache[0]), | |
880 array( | |
881 'current_member' => $user_info['id'], | |
882 'move_topic_ids' => $moveCache[0], | |
883 ) | |
884 ); | |
885 $moveTos = array(); | |
886 $moveCache2 = array(); | |
887 $countPosts = array(); | |
888 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
889 { | |
890 $to = $moveCache[1][$row['id_topic']]; | |
891 | |
892 if (empty($to)) | |
893 continue; | |
894 | |
895 // Does this topic's board count the posts or not? | |
896 $countPosts[$row['id_topic']] = empty($row['count_posts']); | |
897 | |
898 if (!isset($moveTos[$to])) | |
899 $moveTos[$to] = array(); | |
900 | |
901 $moveTos[$to][] = $row['id_topic']; | |
902 | |
903 // For reporting... | |
904 $moveCache2[] = array($row['id_topic'], $row['id_board'], $to); | |
905 } | |
906 $smcFunc['db_free_result']($request); | |
907 | |
908 $moveCache = $moveCache2; | |
909 | |
910 require_once($sourcedir . '/MoveTopic.php'); | |
911 | |
912 // Do the actual moves... | |
913 foreach ($moveTos as $to => $topics) | |
914 moveTopics($topics, $to); | |
915 | |
916 // Does the post counts need to be updated? | |
917 if (!empty($moveTos)) | |
918 { | |
919 $topicRecounts = array(); | |
920 $request = $smcFunc['db_query']('', ' | |
921 SELECT id_board, count_posts | |
922 FROM {db_prefix}boards | |
923 WHERE id_board IN ({array_int:move_boards})', | |
924 array( | |
925 'move_boards' => array_keys($moveTos), | |
926 ) | |
927 ); | |
928 | |
929 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
930 { | |
931 $cp = empty($row['count_posts']); | |
932 | |
933 // Go through all the topics that are being moved to this board. | |
934 foreach ($moveTos[$row['id_board']] as $topic) | |
935 { | |
936 // If both boards have the same value for post counting then no adjustment needs to be made. | |
937 if ($countPosts[$topic] != $cp) | |
938 { | |
939 // If the board being moved to does count the posts then the other one doesn't so add to their post count. | |
940 $topicRecounts[$topic] = $cp ? '+' : '-'; | |
941 } | |
942 } | |
943 } | |
944 | |
945 $smcFunc['db_free_result']($request); | |
946 | |
947 if (!empty($topicRecounts)) | |
948 { | |
949 $members = array(); | |
950 | |
951 // Get all the members who have posted in the moved topics. | |
952 $request = $smcFunc['db_query']('', ' | |
953 SELECT id_member, id_topic | |
954 FROM {db_prefix}messages | |
955 WHERE id_topic IN ({array_int:moved_topic_ids})', | |
956 array( | |
957 'moved_topic_ids' => array_keys($topicRecounts), | |
958 ) | |
959 ); | |
960 | |
961 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
962 { | |
963 if (!isset($members[$row['id_member']])) | |
964 $members[$row['id_member']] = 0; | |
965 | |
966 if ($topicRecounts[$row['id_topic']] === '+') | |
967 $members[$row['id_member']] += 1; | |
968 else | |
969 $members[$row['id_member']] -= 1; | |
970 } | |
971 | |
972 $smcFunc['db_free_result']($request); | |
973 | |
974 // And now update them member's post counts | |
975 foreach ($members as $id_member => $post_adj) | |
976 updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj)); | |
977 | |
978 } | |
979 } | |
980 } | |
981 | |
982 // Now delete the topics... | |
983 if (!empty($removeCache)) | |
984 { | |
985 // They can only delete their own topics. (we wouldn't be here if they couldn't do that..) | |
986 $result = $smcFunc['db_query']('', ' | |
987 SELECT id_topic, id_board | |
988 FROM {db_prefix}topics | |
989 WHERE id_topic IN ({array_int:removed_topic_ids})' . (!empty($board) && !allowedTo('remove_any') ? ' | |
990 AND id_member_started = {int:current_member}' : '') . ' | |
991 LIMIT ' . count($removeCache), | |
992 array( | |
993 'current_member' => $user_info['id'], | |
994 'removed_topic_ids' => $removeCache, | |
995 ) | |
996 ); | |
997 | |
998 $removeCache = array(); | |
999 $removeCacheBoards = array(); | |
1000 while ($row = $smcFunc['db_fetch_assoc']($result)) | |
1001 { | |
1002 $removeCache[] = $row['id_topic']; | |
1003 $removeCacheBoards[$row['id_topic']] = $row['id_board']; | |
1004 } | |
1005 $smcFunc['db_free_result']($result); | |
1006 | |
1007 // Maybe *none* were their own topics. | |
1008 if (!empty($removeCache)) | |
1009 { | |
1010 // Gotta send the notifications *first*! | |
1011 foreach ($removeCache as $topic) | |
1012 { | |
1013 // Only log the topic ID if it's not in the recycle board. | |
1014 logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $removeCacheBoards[$topic] ? 'topic' : 'old_topic_id') => $topic, 'board' => $removeCacheBoards[$topic])); | |
1015 sendNotifications($topic, 'remove'); | |
1016 } | |
1017 | |
1018 require_once($sourcedir . '/RemoveTopic.php'); | |
1019 removeTopics($removeCache); | |
1020 } | |
1021 } | |
1022 | |
1023 // Approve the topics... | |
1024 if (!empty($approveCache)) | |
1025 { | |
1026 // We need unapproved topic ids and their authors! | |
1027 $request = $smcFunc['db_query']('', ' | |
1028 SELECT id_topic, id_member_started | |
1029 FROM {db_prefix}topics | |
1030 WHERE id_topic IN ({array_int:approve_topic_ids}) | |
1031 AND approved = {int:not_approved} | |
1032 LIMIT ' . count($approveCache), | |
1033 array( | |
1034 'approve_topic_ids' => $approveCache, | |
1035 'not_approved' => 0, | |
1036 ) | |
1037 ); | |
1038 $approveCache = array(); | |
1039 $approveCacheMembers = array(); | |
1040 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
1041 { | |
1042 $approveCache[] = $row['id_topic']; | |
1043 $approveCacheMembers[$row['id_topic']] = $row['id_member_started']; | |
1044 } | |
1045 $smcFunc['db_free_result']($request); | |
1046 | |
1047 // Any topics to approve? | |
1048 if (!empty($approveCache)) | |
1049 { | |
1050 // Handle the approval part... | |
1051 approveTopics($approveCache); | |
1052 | |
1053 // Time for some logging! | |
1054 foreach ($approveCache as $topic) | |
1055 logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic])); | |
1056 } | |
1057 } | |
1058 | |
1059 // And (almost) lastly, lock the topics... | |
1060 if (!empty($lockCache)) | |
1061 { | |
1062 $lockStatus = array(); | |
1063 | |
1064 // Gotta make sure they CAN lock/unlock these topics... | |
1065 if (!empty($board) && !allowedTo('lock_any')) | |
1066 { | |
1067 // Make sure they started the topic AND it isn't already locked by someone with higher priv's. | |
1068 $result = $smcFunc['db_query']('', ' | |
1069 SELECT id_topic, locked, id_board | |
1070 FROM {db_prefix}topics | |
1071 WHERE id_topic IN ({array_int:locked_topic_ids}) | |
1072 AND id_member_started = {int:current_member} | |
1073 AND locked IN (2, 0) | |
1074 LIMIT ' . count($lockCache), | |
1075 array( | |
1076 'current_member' => $user_info['id'], | |
1077 'locked_topic_ids' => $lockCache, | |
1078 ) | |
1079 ); | |
1080 $lockCache = array(); | |
1081 $lockCacheBoards = array(); | |
1082 while ($row = $smcFunc['db_fetch_assoc']($result)) | |
1083 { | |
1084 $lockCache[] = $row['id_topic']; | |
1085 $lockCacheBoards[$row['id_topic']] = $row['id_board']; | |
1086 $lockStatus[$row['id_topic']] = empty($row['locked']); | |
1087 } | |
1088 $smcFunc['db_free_result']($result); | |
1089 } | |
1090 else | |
1091 { | |
1092 $result = $smcFunc['db_query']('', ' | |
1093 SELECT id_topic, locked, id_board | |
1094 FROM {db_prefix}topics | |
1095 WHERE id_topic IN ({array_int:locked_topic_ids}) | |
1096 LIMIT ' . count($lockCache), | |
1097 array( | |
1098 'locked_topic_ids' => $lockCache, | |
1099 ) | |
1100 ); | |
1101 $lockCacheBoards = array(); | |
1102 while ($row = $smcFunc['db_fetch_assoc']($result)) | |
1103 { | |
1104 $lockStatus[$row['id_topic']] = empty($row['locked']); | |
1105 $lockCacheBoards[$row['id_topic']] = $row['id_board']; | |
1106 } | |
1107 $smcFunc['db_free_result']($result); | |
1108 } | |
1109 | |
1110 // It could just be that *none* were their own topics... | |
1111 if (!empty($lockCache)) | |
1112 { | |
1113 // Alternate the locked value. | |
1114 $smcFunc['db_query']('', ' | |
1115 UPDATE {db_prefix}topics | |
1116 SET locked = CASE WHEN locked = {int:is_locked} THEN ' . (allowedTo('lock_any') ? '1' : '2') . ' ELSE 0 END | |
1117 WHERE id_topic IN ({array_int:locked_topic_ids})', | |
1118 array( | |
1119 'locked_topic_ids' => $lockCache, | |
1120 'is_locked' => 0, | |
1121 ) | |
1122 ); | |
1123 } | |
1124 } | |
1125 | |
1126 if (!empty($markCache)) | |
1127 { | |
1128 $markArray = array(); | |
1129 foreach ($markCache as $topic) | |
1130 $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic); | |
1131 | |
1132 $smcFunc['db_insert']('replace', | |
1133 '{db_prefix}log_topics', | |
1134 array('id_msg' => 'int', 'id_member' => 'int', 'id_topic' => 'int'), | |
1135 $markArray, | |
1136 array('id_member', 'id_topic') | |
1137 ); | |
1138 } | |
1139 | |
1140 foreach ($moveCache as $topic) | |
1141 { | |
1142 // Didn't actually move anything! | |
1143 if (!isset($topic[0])) | |
1144 break; | |
1145 | |
1146 logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2])); | |
1147 sendNotifications($topic[0], 'move'); | |
1148 } | |
1149 foreach ($lockCache as $topic) | |
1150 { | |
1151 logAction($lockStatus[$topic] ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $lockCacheBoards[$topic])); | |
1152 sendNotifications($topic, $lockStatus[$topic] ? 'lock' : 'unlock'); | |
1153 } | |
1154 foreach ($stickyCache as $topic) | |
1155 { | |
1156 logAction($stickyCacheStatus[$topic] ? 'unsticky' : 'sticky', array('topic' => $topic, 'board' => $stickyCacheBoards[$topic])); | |
1157 sendNotifications($topic, 'sticky'); | |
1158 } | |
1159 | |
1160 updateStats('topic'); | |
1161 updateStats('message'); | |
1162 updateSettings(array( | |
1163 'calendar_updated' => time(), | |
1164 )); | |
1165 | |
1166 if (!empty($affectedBoards)) | |
1167 updateLastMessages(array_keys($affectedBoards)); | |
1168 | |
1169 redirectexit($redirect_url); | |
1170 } | |
1171 | |
1172 ?> |