Conditions | 195 |
Total Lines | 726 |
Code Lines | 431 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | function MessageIndex() |
||
24 | { |
||
25 | global $txt, $scripturl, $board, $modSettings, $context; |
||
26 | global $options, $settings, $board_info, $user_info, $smcFunc, $sourcedir; |
||
27 | |||
28 | require_once($sourcedir . '/Subs-Boards.php'); |
||
29 | |||
30 | // If this is a redirection board head off. |
||
31 | if ($board_info['redirect']) |
||
32 | { |
||
33 | $smcFunc['db_query']('', ' |
||
34 | UPDATE {db_prefix}boards |
||
35 | SET num_posts = num_posts + 1 |
||
36 | WHERE id_board = {int:current_board}', |
||
37 | array( |
||
38 | 'current_board' => $board, |
||
39 | ) |
||
40 | ); |
||
41 | |||
42 | redirectexit($board_info['redirect']); |
||
43 | } |
||
44 | |||
45 | loadTemplate('MessageIndex'); |
||
46 | |||
47 | if (!$user_info['is_guest']) |
||
48 | { |
||
49 | // We can't know they read it if we allow prefetches. |
||
50 | // But we'll actually mark it read later after we've done everything else. |
||
51 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
||
52 | { |
||
53 | ob_end_clean(); |
||
54 | send_http_status(403, 'Prefetch Forbidden'); |
||
55 | die; |
||
|
|||
56 | } |
||
57 | } |
||
58 | |||
59 | $boards_parsed_data = getBoardsParsedDescription($board_info['cat']['id']); |
||
60 | |||
61 | if (!isset($boards_parsed_data[$board_info['id']])) |
||
62 | $boards_parsed_data = setBoardParsedDescription($board_info['cat']['id'], array( |
||
63 | $board_info['id'] => $board_info['description'] |
||
64 | )); |
||
65 | |||
66 | $context['name'] = $board_info['name']; |
||
67 | $context['description'] = $boards_parsed_data[$board_info['id']]; |
||
68 | |||
69 | if (!empty($board_info['description'])) |
||
70 | $context['meta_description'] = strip_tags($board_info['description']); |
||
71 | |||
72 | // How many topics do we have in total? |
||
73 | $board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics']; |
||
74 | |||
75 | // View all the topics, or just a few? |
||
76 | $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
||
77 | $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
||
78 | $context['maxindex'] = isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) ? $board_info['total_topics'] : $context['topics_per_page']; |
||
79 | |||
80 | // Right, let's only index normal stuff! |
||
81 | if (count($_GET) > 1) |
||
82 | { |
||
83 | $session_name = session_name(); |
||
84 | foreach ($_GET as $k => $v) |
||
85 | { |
||
86 | if (!in_array($k, array('board', 'start', $session_name))) |
||
87 | $context['robot_no_index'] = true; |
||
88 | } |
||
89 | } |
||
90 | if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
||
91 | $context['robot_no_index'] = true; |
||
92 | |||
93 | // If we can view unapproved messages and there are some build up a list. |
||
94 | if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts'])) |
||
95 | { |
||
96 | $untopics = $board_info['unapproved_topics'] ? '<a href="' . $scripturl . '?action=moderate;area=postmod;sa=topics;brd=' . $board . '">' . $board_info['unapproved_topics'] . '</a>' : 0; |
||
97 | $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; |
||
98 | $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); |
||
99 | } |
||
100 | |||
101 | // Default sort methods. |
||
102 | $sort_methods = array( |
||
103 | 'subject' => 'mf.subject', |
||
104 | 'starter' => 'COALESCE(memf.real_name, mf.poster_name)', |
||
105 | 'last_poster' => 'COALESCE(meml.real_name, ml.poster_name)', |
||
106 | 'replies' => 't.num_replies', |
||
107 | 'views' => 't.num_views', |
||
108 | 'first_post' => 't.id_topic', |
||
109 | 'last_post' => 't.id_last_msg' |
||
110 | ); |
||
111 | |||
112 | // Default sort methods tables. |
||
113 | $sort_methods_table = array( |
||
114 | 'subject' => 'JOIN {db_prefix}messages mf ON (mf.id_msg = t.id_first_msg)', |
||
115 | 'starter' => 'JOIN {db_prefix}messages mf ON (mf.id_msg = t.id_first_msg) |
||
116 | LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)', |
||
117 | 'last_poster' => 'JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) |
||
118 | LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)', |
||
119 | 'replies' => '', |
||
120 | 'views' => '', |
||
121 | 'first_post' => '', |
||
122 | 'last_post' => '' |
||
123 | ); |
||
124 | |||
125 | // Bring in any changes we want to make before the query. |
||
126 | call_integration_hook('integrate_pre_messageindex', array(&$sort_methods, &$sort_methods_table)); |
||
127 | |||
128 | // We only know these. |
||
129 | if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array_keys($sort_methods))) |
||
130 | $_REQUEST['sort'] = 'last_post'; |
||
131 | |||
132 | // Make sure the starting place makes sense and construct the page index. |
||
133 | if (isset($_REQUEST['sort'])) |
||
134 | $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
||
135 | else |
||
136 | $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
||
137 | $context['start'] = &$_REQUEST['start']; |
||
138 | |||
139 | // Set a canonical URL for this page. |
||
140 | $context['canonical_url'] = $scripturl . '?board=' . $board . '.' . $context['start']; |
||
141 | |||
142 | $can_show_all = !empty($modSettings['enableAllMessages']) && $context['maxindex'] > $modSettings['enableAllMessages']; |
||
143 | |||
144 | if (!($can_show_all && isset($_REQUEST['all']))) |
||
145 | { |
||
146 | $context['links'] = array( |
||
147 | 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?board=' . $board . '.0' : '', |
||
148 | 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] - $context['topics_per_page']) : '', |
||
149 | 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $board_info['total_topics'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] + $context['topics_per_page']) : '', |
||
150 | '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']) : '', |
||
151 | 'up' => $board_info['parent'] == 0 ? $scripturl . '?' : $scripturl . '?board=' . $board_info['parent'] . '.0' |
||
152 | ); |
||
153 | } |
||
154 | |||
155 | $context['page_info'] = array( |
||
156 | 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, |
||
157 | 'num_pages' => floor(($board_info['total_topics'] - 1) / $context['topics_per_page']) + 1 |
||
158 | ); |
||
159 | |||
160 | if (isset($_REQUEST['all']) && $can_show_all) |
||
161 | { |
||
162 | $context['maxindex'] = $modSettings['enableAllMessages']; |
||
163 | $_REQUEST['start'] = 0; |
||
164 | } |
||
165 | |||
166 | // Build a list of the board's moderators. |
||
167 | $context['moderators'] = &$board_info['moderators']; |
||
168 | $context['moderator_groups'] = &$board_info['moderator_groups']; |
||
169 | $context['link_moderators'] = array(); |
||
170 | if (!empty($board_info['moderators'])) |
||
171 | { |
||
172 | foreach ($board_info['moderators'] as $mod) |
||
173 | $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
||
174 | } |
||
175 | if (!empty($board_info['moderator_groups'])) |
||
176 | { |
||
177 | // By default just tack the moderator groups onto the end of the members |
||
178 | foreach ($board_info['moderator_groups'] as $mod_group) |
||
179 | $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
||
180 | } |
||
181 | |||
182 | // Now we tack the info onto the end of the linktree |
||
183 | if (!empty($context['link_moderators'])) |
||
184 | { |
||
185 | $context['linktree'][count($context['linktree']) - 1]['extra_after'] = '<span class="board_moderators">(' . (count($context['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators']) . ': ' . implode(', ', $context['link_moderators']) . ')</span>'; |
||
186 | } |
||
187 | |||
188 | // 'Print' the header and board info. |
||
189 | $context['page_title'] = strip_tags($board_info['name']); |
||
190 | |||
191 | // Set the variables up for the template. |
||
192 | $context['can_mark_notify'] = !$user_info['is_guest']; |
||
193 | $context['can_post_new'] = allowedTo('post_new') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_topics')); |
||
194 | $context['can_post_poll'] = $modSettings['pollMode'] == '1' && allowedTo('poll_post') && $context['can_post_new']; |
||
195 | $context['can_moderate_forum'] = allowedTo('moderate_forum'); |
||
196 | $context['can_approve_posts'] = allowedTo('approve_posts'); |
||
197 | |||
198 | require_once($sourcedir . '/Subs-BoardIndex.php'); |
||
199 | $boardIndexOptions = array( |
||
200 | 'include_categories' => false, |
||
201 | 'base_level' => $board_info['child_level'] + 1, |
||
202 | 'parent_id' => $board_info['id'], |
||
203 | 'set_latest_post' => false, |
||
204 | 'countChildPosts' => !empty($modSettings['countChildPosts']), |
||
205 | ); |
||
206 | $context['boards'] = getBoardIndex($boardIndexOptions); |
||
207 | |||
208 | // Nosey, nosey - who's viewing this topic? |
||
209 | if (!empty($settings['display_who_viewing'])) |
||
210 | { |
||
211 | $context['view_members'] = array(); |
||
212 | $context['view_members_list'] = array(); |
||
213 | $context['view_num_hidden'] = 0; |
||
214 | |||
215 | $request = $smcFunc['db_query']('', ' |
||
216 | SELECT |
||
217 | lo.id_member, lo.log_time, mem.real_name, mem.member_name, mem.show_online, |
||
218 | mg.online_color, mg.id_group, mg.group_name |
||
219 | FROM {db_prefix}log_online AS lo |
||
220 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lo.id_member) |
||
221 | 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) |
||
222 | WHERE INSTR(lo.url, {string:in_url_string}) > 0 OR lo.session = {string:session}', |
||
223 | array( |
||
224 | 'reg_member_group' => 0, |
||
225 | 'in_url_string' => '"board":' . $board, |
||
226 | 'session' => $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(), |
||
227 | ) |
||
228 | ); |
||
229 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
230 | { |
||
231 | if (empty($row['id_member'])) |
||
232 | continue; |
||
233 | |||
234 | if (!empty($row['online_color'])) |
||
235 | $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
||
236 | else |
||
237 | $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
||
238 | |||
239 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
||
240 | if ($is_buddy) |
||
241 | $link = '<strong>' . $link . '</strong>'; |
||
242 | |||
243 | if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
||
244 | $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
||
245 | // @todo why are we filling this array of data that are just counted (twice) and discarded? ??? |
||
246 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
||
247 | 'id' => $row['id_member'], |
||
248 | 'username' => $row['member_name'], |
||
249 | 'name' => $row['real_name'], |
||
250 | 'group' => $row['id_group'], |
||
251 | 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], |
||
252 | 'link' => $link, |
||
253 | 'is_buddy' => $is_buddy, |
||
254 | 'hidden' => empty($row['show_online']), |
||
255 | ); |
||
256 | |||
257 | if (empty($row['show_online'])) |
||
258 | $context['view_num_hidden']++; |
||
259 | } |
||
260 | $context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']); |
||
261 | $smcFunc['db_free_result']($request); |
||
262 | |||
263 | // Put them in "last clicked" order. |
||
264 | krsort($context['view_members_list']); |
||
265 | krsort($context['view_members']); |
||
266 | } |
||
267 | |||
268 | // They didn't pick one, default to by last post descending. |
||
269 | if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) |
||
270 | { |
||
271 | $context['sort_by'] = 'last_post'; |
||
272 | $_REQUEST['sort'] = 'id_last_msg'; |
||
273 | $ascending = isset($_REQUEST['asc']); |
||
274 | } |
||
275 | // Otherwise default to ascending. |
||
276 | else |
||
277 | { |
||
278 | $context['sort_by'] = $_REQUEST['sort']; |
||
279 | $_REQUEST['sort'] = $sort_methods[$_REQUEST['sort']]; |
||
280 | $ascending = !isset($_REQUEST['desc']); |
||
281 | } |
||
282 | |||
283 | $context['sort_direction'] = $ascending ? 'up' : 'down'; |
||
284 | $txt['starter'] = $txt['started_by']; |
||
285 | |||
286 | foreach ($sort_methods as $key => $val) |
||
287 | $context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>'; |
||
288 | |||
289 | // Calculate the fastest way to get the topics. |
||
290 | $start = (int) $_REQUEST['start']; |
||
291 | if ($start > ($board_info['total_topics'] - 1) / 2) |
||
292 | { |
||
293 | $ascending = !$ascending; |
||
294 | $fake_ascending = true; |
||
295 | $context['maxindex'] = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? $board_info['total_topics'] - $start : $context['maxindex']; |
||
296 | $start = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? 0 : $board_info['total_topics'] - $start - $context['maxindex']; |
||
297 | } |
||
298 | else |
||
299 | $fake_ascending = false; |
||
300 | |||
301 | // Setup the default topic icons... |
||
302 | $context['icon_sources'] = array(); |
||
303 | foreach ($context['stable_icons'] as $icon) |
||
304 | $context['icon_sources'][$icon] = 'images_url'; |
||
305 | |||
306 | $topic_ids = array(); |
||
307 | $context['topics'] = array(); |
||
308 | |||
309 | // Grab the appropriate topic information... |
||
310 | // For search engine effectiveness we'll link guests differently. |
||
311 | $context['pageindex_multiplier'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
||
312 | |||
313 | $message_index_parameters = array( |
||
314 | 'current_board' => $board, |
||
315 | 'current_member' => $user_info['id'], |
||
316 | 'topic_list' => $topic_ids, |
||
317 | 'is_approved' => 1, |
||
318 | 'find_set_topics' => implode(',', $topic_ids), |
||
319 | 'start' => $start, |
||
320 | 'maxindex' => $context['maxindex'], |
||
321 | ); |
||
322 | |||
323 | $message_index_selects = array(); |
||
324 | $message_index_tables = array(); |
||
325 | $message_index_wheres = array(); |
||
326 | $message_index_topic_wheres = array(); |
||
327 | |||
328 | call_integration_hook('integrate_message_index', array(&$message_index_selects, &$message_index_tables, &$message_index_parameters, &$message_index_wheres, &$topic_ids, &$message_index_topic_wheres)); |
||
329 | |||
330 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) |
||
331 | $enableParticipation = true; |
||
332 | else |
||
333 | $enableParticipation = false; |
||
334 | |||
335 | $sort_table = ' |
||
336 | SELECT t.id_topic, t.id_first_msg, t.id_last_msg' . (!empty($message_index_selects) ? (', ' . implode(', ', $message_index_selects)) : '') . ' |
||
337 | FROM {db_prefix}topics t |
||
338 | ' . (empty($sort_methods_table[$context['sort_by']]) ? '' : $sort_methods_table[$context['sort_by']]) . ' |
||
339 | ' . (!empty($message_index_tables) ? implode("\n\t\t\t\t", $message_index_tables) : '') . ' |
||
340 | WHERE t.id_board = {int:current_board} ' |
||
341 | . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : ' |
||
342 | AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . (!empty($message_index_topic_wheres) ? ' |
||
343 | AND ' . implode("\n\t\t\t\tAND ", $message_index_topic_wheres) : ''). ' |
||
344 | ORDER BY is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . ' |
||
345 | LIMIT {int:maxindex} |
||
346 | OFFSET {int:start} '; |
||
347 | |||
348 | $result = $smcFunc['db_query']('substring', ' |
||
349 | SELECT |
||
350 | t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board, |
||
351 | ' . ($user_info['is_guest'] ? '0' : 'COALESCE(lt.id_msg, COALESCE(lmr.id_msg, -1)) + 1') . ' AS new_from, |
||
352 | ' . ($enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in, |
||
353 | ' : '') . ' |
||
354 | t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, t.id_redirect_topic, |
||
355 | ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon, |
||
356 | ml.poster_name AS last_member_name, ml.id_member AS last_id_member,' . (!empty($settings['avatars_on_indexes']) ? ' meml.avatar, meml.email_address, memf.avatar AS first_member_avatar, memf.email_address AS first_member_mail, COALESCE(af.id_attach, 0) AS first_member_id_attach, af.filename AS first_member_filename, af.attachment_type AS first_member_attach_type, COALESCE(al.id_attach, 0) AS last_member_id_attach, al.filename AS last_member_filename, al.attachment_type AS last_member_attach_type,' : '') . ' |
||
357 | COALESCE(meml.real_name, ml.poster_name) AS last_display_name, t.id_first_msg, |
||
358 | mf.poster_time AS first_poster_time, mf.subject AS first_subject, mf.icon AS first_icon, |
||
359 | mf.poster_name AS first_member_name, mf.id_member AS first_id_member, |
||
360 | COALESCE(memf.real_name, mf.poster_name) AS first_display_name, ' . (!empty($modSettings['preview_characters']) ? ' |
||
361 | SUBSTRING(ml.body, 1, ' . ($modSettings['preview_characters'] + 256) . ') AS last_body, |
||
362 | SUBSTRING(mf.body, 1, ' . ($modSettings['preview_characters'] + 256) . ') AS first_body,' : '') . 'ml.smileys_enabled AS last_smileys, mf.smileys_enabled AS first_smileys |
||
363 | ' . (!empty($message_index_selects) ? (', ' . implode(', ', $message_index_selects)) : '') . ' |
||
364 | FROM (' . $sort_table . ') as st |
||
365 | JOIN {db_prefix}topics AS t ON (st.id_topic = t.id_topic) |
||
366 | JOIN {db_prefix}messages AS ml ON (ml.id_msg = st.id_last_msg) |
||
367 | JOIN {db_prefix}messages AS mf ON (mf.id_msg = st.id_first_msg) |
||
368 | LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member) |
||
369 | LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' . (!empty($settings['avatars_on_indexes']) ? ' |
||
370 | LEFT JOIN {db_prefix}attachments AS af ON (af.id_member = memf.id_member) |
||
371 | LEFT JOIN {db_prefix}attachments AS al ON (al.id_member = meml.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : ' |
||
372 | LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) |
||
373 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})') . ' |
||
374 | ' . (!empty($message_index_tables) ? implode("\n\t\t\t\t", $message_index_tables) : '') . ' |
||
375 | ' . (!empty($message_index_wheres) ? ' WHERE ' . implode("\n\t\t\t\tAND ", $message_index_wheres) : '') . ' |
||
376 | ORDER BY is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC'), |
||
377 | $message_index_parameters |
||
378 | ); |
||
379 | |||
380 | // Begin 'printing' the message index for current board. |
||
381 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
||
382 | { |
||
383 | if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
||
384 | continue; |
||
385 | |||
386 | $topic_ids[] = $row['id_topic']; |
||
387 | |||
388 | // Reference the main color class. |
||
389 | $colorClass = 'windowbg'; |
||
390 | |||
391 | // Does the theme support message previews? |
||
392 | if (!empty($modSettings['preview_characters'])) |
||
393 | { |
||
394 | // Limit them to $modSettings['preview_characters'] characters |
||
395 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
||
396 | if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) |
||
397 | $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...'; |
||
398 | |||
399 | // Censor the subject and message preview. |
||
400 | censorText($row['first_subject']); |
||
401 | censorText($row['first_body']); |
||
402 | |||
403 | // Don't censor them twice! |
||
404 | if ($row['id_first_msg'] == $row['id_last_msg']) |
||
405 | { |
||
406 | $row['last_subject'] = $row['first_subject']; |
||
407 | $row['last_body'] = $row['first_body']; |
||
408 | } |
||
409 | else |
||
410 | { |
||
411 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
||
412 | if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) |
||
413 | $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...'; |
||
414 | |||
415 | censorText($row['last_subject']); |
||
416 | censorText($row['last_body']); |
||
417 | } |
||
418 | } |
||
419 | else |
||
420 | { |
||
421 | $row['first_body'] = ''; |
||
422 | $row['last_body'] = ''; |
||
423 | censorText($row['first_subject']); |
||
424 | |||
425 | if ($row['id_first_msg'] == $row['id_last_msg']) |
||
426 | $row['last_subject'] = $row['first_subject']; |
||
427 | else |
||
428 | censorText($row['last_subject']); |
||
429 | } |
||
430 | |||
431 | // Decide how many pages the topic should have. |
||
432 | if ($row['num_replies'] + 1 > $context['messages_per_page']) |
||
433 | { |
||
434 | // We can't pass start by reference. |
||
435 | $start = -1; |
||
436 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false); |
||
437 | |||
438 | // If we can use all, show all. |
||
439 | if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) |
||
440 | $pages .= sprintf(strtr($settings['page_index']['page'], array('{URL}' => $scripturl . '?topic=' . $row['id_topic'] . '.0;all')), '', $txt['all']); |
||
441 | } |
||
442 | else |
||
443 | $pages = ''; |
||
444 | |||
445 | // We need to check the topic icons exist... |
||
446 | if (!empty($modSettings['messageIconChecks_enable'])) |
||
447 | { |
||
448 | if (!isset($context['icon_sources'][$row['first_icon']])) |
||
449 | $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
||
450 | if (!isset($context['icon_sources'][$row['last_icon']])) |
||
451 | $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
||
452 | } |
||
453 | else |
||
454 | { |
||
455 | if (!isset($context['icon_sources'][$row['first_icon']])) |
||
456 | $context['icon_sources'][$row['first_icon']] = 'images_url'; |
||
457 | if (!isset($context['icon_sources'][$row['last_icon']])) |
||
458 | $context['icon_sources'][$row['last_icon']] = 'images_url'; |
||
459 | } |
||
460 | |||
461 | if (!empty($board_info['recycle'])) |
||
462 | $row['first_icon'] = 'recycled'; |
||
463 | |||
464 | // Is this topic pending approval, or does it have any posts pending approval? |
||
465 | if ($context['can_approve_posts'] && $row['unapproved_posts']) |
||
466 | $colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost'); |
||
467 | |||
468 | // Sticky topics should get a different color, too. |
||
469 | if ($row['is_sticky']) |
||
470 | $colorClass .= ' sticky'; |
||
471 | |||
472 | // Locked topics get special treatment as well. |
||
473 | if ($row['locked']) |
||
474 | $colorClass .= ' locked'; |
||
475 | |||
476 | // 'Print' the topic info. |
||
477 | $context['topics'][$row['id_topic']] = array_merge($row, array( |
||
478 | 'id' => $row['id_topic'], |
||
479 | 'first_post' => array( |
||
480 | 'id' => $row['id_first_msg'], |
||
481 | 'member' => array( |
||
482 | 'username' => $row['first_member_name'], |
||
483 | 'name' => $row['first_display_name'], |
||
484 | 'id' => $row['first_id_member'], |
||
485 | 'href' => !empty($row['first_id_member']) ? $scripturl . '?action=profile;u=' . $row['first_id_member'] : '', |
||
486 | 'link' => !empty($row['first_id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['first_id_member'] . '" title="' . sprintf($txt['view_profile_of_username'], $row['first_display_name']) . '" class="preview">' . $row['first_display_name'] . '</a>' : $row['first_display_name'] |
||
487 | ), |
||
488 | 'time' => timeformat($row['first_poster_time']), |
||
489 | 'timestamp' => $row['first_poster_time'], |
||
490 | 'subject' => $row['first_subject'], |
||
491 | 'preview' => $row['first_body'], |
||
492 | 'icon' => $row['first_icon'], |
||
493 | 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', |
||
494 | 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', |
||
495 | 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['first_subject'] . '</a>', |
||
496 | ), |
||
497 | 'last_post' => array( |
||
498 | 'id' => $row['id_last_msg'], |
||
499 | 'member' => array( |
||
500 | 'username' => $row['last_member_name'], |
||
501 | 'name' => $row['last_display_name'], |
||
502 | 'id' => $row['last_id_member'], |
||
503 | 'href' => !empty($row['last_id_member']) ? $scripturl . '?action=profile;u=' . $row['last_id_member'] : '', |
||
504 | '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'] |
||
505 | ), |
||
506 | 'time' => timeformat($row['last_poster_time']), |
||
507 | 'timestamp' => $row['last_poster_time'], |
||
508 | 'subject' => $row['last_subject'], |
||
509 | 'preview' => $row['last_body'], |
||
510 | 'icon' => $row['last_icon'], |
||
511 | 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.png', |
||
512 | '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')), |
||
513 | '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>' |
||
514 | ), |
||
515 | 'is_sticky' => !empty($row['is_sticky']), |
||
516 | 'is_locked' => !empty($row['locked']), |
||
517 | 'is_redirect' => !empty($row['id_redirect_topic']), |
||
518 | 'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0, |
||
519 | 'is_posted_in' => ($enableParticipation ? $row['is_posted_in'] : false), |
||
520 | 'is_watched' => false, |
||
521 | 'icon' => $row['first_icon'], |
||
522 | 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', |
||
523 | 'subject' => $row['first_subject'], |
||
524 | 'new' => $row['new_from'] <= $row['id_msg_modified'], |
||
525 | 'new_from' => $row['new_from'], |
||
526 | 'newtime' => $row['new_from'], |
||
527 | 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new', |
||
528 | 'pages' => $pages, |
||
529 | 'replies' => comma_format($row['num_replies']), |
||
530 | 'views' => comma_format($row['num_views']), |
||
531 | 'approved' => $row['approved'], |
||
532 | 'unapproved_posts' => $row['unapproved_posts'], |
||
533 | 'css_class' => $colorClass, |
||
534 | )); |
||
535 | if (!empty($settings['avatars_on_indexes'])) |
||
536 | { |
||
537 | // Last post member avatar |
||
538 | $context['topics'][$row['id_topic']]['last_post']['member']['avatar'] = set_avatar_data(array( |
||
539 | 'avatar' => $row['avatar'], |
||
540 | 'email' => $row['email_address'], |
||
541 | 'filename' => !empty($row['last_member_filename']) ? $row['last_member_filename'] : '', |
||
542 | )); |
||
543 | |||
544 | // First post member avatar |
||
545 | $context['topics'][$row['id_topic']]['first_post']['member']['avatar'] = set_avatar_data(array( |
||
546 | 'avatar' => $row['first_member_avatar'], |
||
547 | 'email' => $row['first_member_mail'], |
||
548 | 'filename' => !empty($row['first_member_filename']) ? $row['first_member_filename'] : '', |
||
549 | )); |
||
550 | } |
||
551 | } |
||
552 | $smcFunc['db_free_result']($result); |
||
553 | |||
554 | // Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...) |
||
555 | if ($fake_ascending) |
||
556 | $context['topics'] = array_reverse($context['topics'], true); |
||
557 | |||
558 | $context['jump_to'] = array( |
||
559 | 'label' => addslashes(un_htmlspecialchars($txt['jump_to'])), |
||
560 | 'board_name' => strtr($smcFunc['htmlspecialchars'](strip_tags($board_info['name'])), array('&' => '&')), |
||
561 | 'child_level' => $board_info['child_level'], |
||
562 | ); |
||
563 | |||
564 | // Is Quick Moderation active/needed? |
||
565 | if (!empty($options['display_quick_mod']) && !empty($context['topics'])) |
||
566 | { |
||
567 | $context['can_markread'] = $context['user']['is_logged']; |
||
568 | $context['can_lock'] = allowedTo('lock_any'); |
||
569 | $context['can_sticky'] = allowedTo('make_sticky'); |
||
570 | $context['can_move'] = allowedTo('move_any'); |
||
571 | $context['can_remove'] = allowedTo('remove_any'); |
||
572 | $context['can_merge'] = allowedTo('merge_any'); |
||
573 | // Ignore approving own topics as it's unlikely to come up... |
||
574 | $context['can_approve'] = $modSettings['postmod_active'] && allowedTo('approve_posts') && !empty($board_info['unapproved_topics']); |
||
575 | // Can we restore topics? |
||
576 | $context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']); |
||
577 | |||
578 | if ($user_info['is_admin'] || $modSettings['topic_move_any']) |
||
579 | $context['can_move_any'] = true; |
||
580 | else |
||
581 | { |
||
582 | // We'll use this in a minute |
||
583 | $boards_allowed = boardsAllowedTo('post_new'); |
||
584 | |||
585 | // How many boards can you do this on besides this one? |
||
586 | $context['can_move_any'] = count($boards_allowed) > 1; |
||
587 | } |
||
588 | |||
589 | // Set permissions for all the topics. |
||
590 | foreach ($context['topics'] as $t => $topic) |
||
591 | { |
||
592 | $started = $topic['first_post']['member']['id'] == $user_info['id']; |
||
593 | $context['topics'][$t]['quick_mod'] = array( |
||
594 | 'lock' => allowedTo('lock_any') || ($started && allowedTo('lock_own')), |
||
595 | 'sticky' => allowedTo('make_sticky'), |
||
596 | 'move' => (allowedTo('move_any') || ($started && allowedTo('move_own')) && $context['can_move_any']), |
||
597 | 'modify' => allowedTo('modify_any') || ($started && allowedTo('modify_own')), |
||
598 | 'remove' => allowedTo('remove_any') || ($started && allowedTo('remove_own')), |
||
599 | 'approve' => $context['can_approve'] && $topic['unapproved_posts'] |
||
600 | ); |
||
601 | $context['can_lock'] |= ($started && allowedTo('lock_own')); |
||
602 | $context['can_move'] |= ($started && allowedTo('move_own') && $context['can_move_any']); |
||
603 | $context['can_remove'] |= ($started && allowedTo('remove_own')); |
||
604 | } |
||
605 | |||
606 | // Can we use quick moderation checkboxes? |
||
607 | if ($options['display_quick_mod'] == 1) |
||
608 | $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']; |
||
609 | // Or the icons? |
||
610 | else |
||
611 | $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; |
||
612 | } |
||
613 | |||
614 | if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) |
||
615 | { |
||
616 | $context['qmod_actions'] = array('approve', 'remove', 'lock', 'sticky', 'move', 'merge', 'restore', 'markread'); |
||
617 | call_integration_hook('integrate_quick_mod_actions'); |
||
618 | } |
||
619 | |||
620 | // Mark current and parent boards as seen. |
||
621 | if (!$user_info['is_guest']) |
||
622 | { |
||
623 | $smcFunc['db_insert']('replace', |
||
624 | '{db_prefix}log_boards', |
||
625 | array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'), |
||
626 | array($modSettings['maxMsgID'], $user_info['id'], $board), |
||
627 | array('id_member', 'id_board') |
||
628 | ); |
||
629 | |||
630 | if (!empty($board_info['parent_boards'])) |
||
631 | { |
||
632 | $smcFunc['db_query']('', ' |
||
633 | UPDATE {db_prefix}log_boards |
||
634 | SET id_msg = {int:id_msg} |
||
635 | WHERE id_member = {int:current_member} |
||
636 | AND id_board IN ({array_int:board_list})', |
||
637 | array( |
||
638 | 'current_member' => $user_info['id'], |
||
639 | 'board_list' => array_keys($board_info['parent_boards']), |
||
640 | 'id_msg' => $modSettings['maxMsgID'], |
||
641 | ) |
||
642 | ); |
||
643 | |||
644 | // We've seen all these boards now! |
||
645 | foreach ($board_info['parent_boards'] as $k => $dummy) |
||
646 | if (isset($_SESSION['topicseen_cache'][$k])) |
||
647 | unset($_SESSION['topicseen_cache'][$k]); |
||
648 | } |
||
649 | |||
650 | if (isset($_SESSION['topicseen_cache'][$board])) |
||
651 | unset($_SESSION['topicseen_cache'][$board]); |
||
652 | |||
653 | $request = $smcFunc['db_query']('', ' |
||
654 | SELECT id_topic, id_board, sent |
||
655 | FROM {db_prefix}log_notify |
||
656 | WHERE id_member = {int:current_member} |
||
657 | AND (' . (!empty($context['topics']) ? 'id_topic IN ({array_int:topics}) OR ' : '') . 'id_board = {int:current_board})', |
||
658 | array( |
||
659 | 'current_board' => $board, |
||
660 | 'topics' => !empty($context['topics']) ? array_keys($context['topics']) : array(), |
||
661 | 'current_member' => $user_info['id'], |
||
662 | ) |
||
663 | ); |
||
664 | $context['is_marked_notify'] = false; // this is for the *board* only |
||
665 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
666 | { |
||
667 | if (!empty($row['id_board'])) |
||
668 | { |
||
669 | $context['is_marked_notify'] = true; |
||
670 | $board_sent = $row['sent']; |
||
671 | } |
||
672 | if (!empty($row['id_topic'])) |
||
673 | $context['topics'][$row['id_topic']]['is_watched'] = true; |
||
674 | } |
||
675 | $smcFunc['db_free_result']($request); |
||
676 | |||
677 | if ($context['is_marked_notify'] && !empty($board_sent)) |
||
678 | { |
||
679 | $smcFunc['db_query']('', ' |
||
680 | UPDATE {db_prefix}log_notify |
||
681 | SET sent = {int:is_sent} |
||
682 | WHERE id_member = {int:current_member} |
||
683 | AND id_board = {int:current_board}', |
||
684 | array( |
||
685 | 'current_board' => $board, |
||
686 | 'current_member' => $user_info['id'], |
||
687 | 'is_sent' => 0, |
||
688 | ) |
||
689 | ); |
||
690 | } |
||
691 | |||
692 | require_once($sourcedir . '/Subs-Notify.php'); |
||
693 | $pref = getNotifyPrefs($user_info['id'], array('board_notify', 'board_notify_' . $board), true); |
||
694 | $pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array(); |
||
695 | $pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0); |
||
696 | $context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1)); |
||
697 | } |
||
698 | else |
||
699 | { |
||
700 | $context['is_marked_notify'] = false; |
||
701 | $context['board_notification_mode'] = 1; |
||
702 | } |
||
703 | |||
704 | // If there are children, but no topics and no ability to post topics... |
||
705 | $context['no_topic_listing'] = !empty($context['boards']) && empty($context['topics']) && !$context['can_post_new']; |
||
706 | |||
707 | // Show a message in case a recently posted message became unapproved. |
||
708 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']); |
||
709 | unset($_SESSION['becomesUnapproved']); |
||
710 | |||
711 | // Build the message index button array. |
||
712 | $context['normal_buttons'] = array(); |
||
713 | |||
714 | if ($context['can_post_new']) |
||
715 | $context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true); |
||
716 | |||
717 | if ($context['can_post_poll']) |
||
718 | $context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'); |
||
719 | |||
720 | if ($context['user']['is_logged']) |
||
721 | $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
||
722 | |||
723 | if ($context['can_mark_notify']) |
||
724 | $context['normal_buttons']['notify'] = array( |
||
725 | 'lang' => true, |
||
726 | 'text' => 'notify_board_' . $context['board_notification_mode'], |
||
727 | 'sub_buttons' => array( |
||
728 | array( |
||
729 | 'text' => 'notify_board_1', |
||
730 | 'url' => $scripturl . '?action=notifyboard;board=' . $board . ';mode=1;' . $context['session_var'] . '=' . $context['session_id'], |
||
731 | ), |
||
732 | array( |
||
733 | 'text' => 'notify_board_2', |
||
734 | 'url' => $scripturl . '?action=notifyboard;board=' . $board . ';mode=2;' . $context['session_var'] . '=' . $context['session_id'], |
||
735 | ), |
||
736 | array( |
||
737 | 'text' => 'notify_board_3', |
||
738 | 'url' => $scripturl . '?action=notifyboard;board=' . $board . ';mode=3;' . $context['session_var'] . '=' . $context['session_id'], |
||
739 | ), |
||
740 | ), |
||
741 | ); |
||
742 | |||
743 | // Javascript for inline editing. |
||
744 | loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic'); |
||
745 | |||
746 | // Allow adding new buttons easily. |
||
747 | // Note: $context['normal_buttons'] is added for backward compatibility with 2.0, but is deprecated and should not be used |
||
748 | call_integration_hook('integrate_messageindex_buttons', array(&$context['normal_buttons'])); |
||
749 | } |
||
1339 | ?> |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.