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