Chris@76
|
1 <?php
|
Chris@76
|
2
|
Chris@76
|
3 /**
|
Chris@76
|
4 * Simple Machines Forum (SMF)
|
Chris@76
|
5 *
|
Chris@76
|
6 * @package SMF
|
Chris@76
|
7 * @author Simple Machines http://www.simplemachines.org
|
Chris@76
|
8 * @copyright 2011 Simple Machines
|
Chris@76
|
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
|
Chris@76
|
10 *
|
Chris@76
|
11 * @version 2.0
|
Chris@76
|
12 */
|
Chris@76
|
13
|
Chris@76
|
14 if (!defined('SMF'))
|
Chris@76
|
15 die('Hacking attempt...');
|
Chris@76
|
16
|
Chris@76
|
17 /* This is perhaps the most important and probably most accessed files in all
|
Chris@76
|
18 of SMF. This file controls topic, message, and attachment display. It
|
Chris@76
|
19 does so with the following functions:
|
Chris@76
|
20
|
Chris@76
|
21 void Display()
|
Chris@76
|
22 - loads the posts in a topic up so they can be displayed.
|
Chris@76
|
23 - supports wireless, using wap/wap2/imode and the Wireless templates.
|
Chris@76
|
24 - uses the main sub template of the Display template.
|
Chris@76
|
25 - requires a topic, and can go to the previous or next topic from it.
|
Chris@76
|
26 - jumps to the correct post depending on a number/time/IS_MSG passed.
|
Chris@76
|
27 - depends on the messages_per_page, defaultMaxMessages and enableAllMessages settings.
|
Chris@76
|
28 - is accessed by ?topic=id_topic.START.
|
Chris@76
|
29
|
Chris@76
|
30 array prepareDisplayContext(bool reset = false)
|
Chris@76
|
31 - actually gets and prepares the message context.
|
Chris@76
|
32 - starts over from the beginning if reset is set to true, which is
|
Chris@76
|
33 useful for showing an index before or after the posts.
|
Chris@76
|
34
|
Chris@76
|
35 void Download()
|
Chris@76
|
36 - downloads an attachment or avatar, and increments the downloads.
|
Chris@76
|
37 - requires the view_attachments permission. (not for avatars!)
|
Chris@76
|
38 - disables the session parser, and clears any previous output.
|
Chris@76
|
39 - depends on the attachmentUploadDir setting being correct.
|
Chris@76
|
40 - is accessed via the query string ?action=dlattach.
|
Chris@76
|
41 - views to attachments and avatars do not increase hits and are not
|
Chris@76
|
42 logged in the "Who's Online" log.
|
Chris@76
|
43
|
Chris@76
|
44 array loadAttachmentContext(int id_msg)
|
Chris@76
|
45 - loads an attachment's contextual data including, most importantly,
|
Chris@76
|
46 its size if it is an image.
|
Chris@76
|
47 - expects the $attachments array to have been filled with the proper
|
Chris@76
|
48 attachment data, as Display() does.
|
Chris@76
|
49 - requires the view_attachments permission to calculate image size.
|
Chris@76
|
50 - attempts to keep the "aspect ratio" of the posted image in line,
|
Chris@76
|
51 even if it has to be resized by the max_image_width and
|
Chris@76
|
52 max_image_height settings.
|
Chris@76
|
53
|
Chris@76
|
54 int approved_attach_sort(array a, array b)
|
Chris@76
|
55 - a sort function for putting unapproved attachments first.
|
Chris@76
|
56
|
Chris@76
|
57 void QuickInTopicModeration()
|
Chris@76
|
58 - in-topic quick moderation.
|
Chris@76
|
59
|
Chris@76
|
60 */
|
Chris@76
|
61
|
Chris@76
|
62 // The central part of the board - topic display.
|
Chris@76
|
63 function Display()
|
Chris@76
|
64 {
|
Chris@76
|
65 global $scripturl, $txt, $modSettings, $context, $settings;
|
Chris@76
|
66 global $options, $sourcedir, $user_info, $board_info, $topic, $board;
|
Chris@76
|
67 global $attachments, $messages_request, $topicinfo, $language, $smcFunc;
|
Chris@76
|
68
|
Chris@76
|
69 // What are you gonna display if these are empty?!
|
Chris@76
|
70 if (empty($topic))
|
Chris@76
|
71 fatal_lang_error('no_board', false);
|
Chris@76
|
72
|
Chris@76
|
73 // Load the proper template and/or sub template.
|
Chris@76
|
74 if (WIRELESS)
|
Chris@76
|
75 $context['sub_template'] = WIRELESS_PROTOCOL . '_display';
|
Chris@76
|
76 else
|
Chris@76
|
77 loadTemplate('Display');
|
Chris@76
|
78
|
Chris@76
|
79 // Not only does a prefetch make things slower for the server, but it makes it impossible to know if they read it.
|
Chris@76
|
80 if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
|
Chris@76
|
81 {
|
Chris@76
|
82 ob_end_clean();
|
Chris@76
|
83 header('HTTP/1.1 403 Prefetch Forbidden');
|
Chris@76
|
84 die;
|
Chris@76
|
85 }
|
Chris@76
|
86
|
Chris@76
|
87 // How much are we sticking on each page?
|
Chris@76
|
88 $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) && !WIRELESS ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
|
Chris@76
|
89
|
Chris@76
|
90 // Let's do some work on what to search index.
|
Chris@76
|
91 if (count($_GET) > 2)
|
Chris@76
|
92 foreach ($_GET as $k => $v)
|
Chris@76
|
93 {
|
Chris@76
|
94 if (!in_array($k, array('topic', 'board', 'start', session_name())))
|
Chris@76
|
95 $context['robot_no_index'] = true;
|
Chris@76
|
96 }
|
Chris@76
|
97
|
Chris@76
|
98 if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
|
Chris@76
|
99 $context['robot_no_index'] = true;
|
Chris@76
|
100
|
Chris@76
|
101 // Find the previous or next topic. Make a fuss if there are no more.
|
Chris@76
|
102 if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
|
Chris@76
|
103 {
|
Chris@76
|
104 // No use in calculating the next topic if there's only one.
|
Chris@76
|
105 if ($board_info['num_topics'] > 1)
|
Chris@76
|
106 {
|
Chris@76
|
107 // Just prepare some variables that are used in the query.
|
Chris@76
|
108 $gt_lt = $_REQUEST['prev_next'] == 'prev' ? '>' : '<';
|
Chris@76
|
109 $order = $_REQUEST['prev_next'] == 'prev' ? '' : ' DESC';
|
Chris@76
|
110
|
Chris@76
|
111 $request = $smcFunc['db_query']('', '
|
Chris@76
|
112 SELECT t2.id_topic
|
Chris@76
|
113 FROM {db_prefix}topics AS t
|
Chris@76
|
114 INNER JOIN {db_prefix}topics AS t2 ON (' . (empty($modSettings['enableStickyTopics']) ? '
|
Chris@76
|
115 t2.id_last_msg ' . $gt_lt . ' t.id_last_msg' : '
|
Chris@76
|
116 (t2.id_last_msg ' . $gt_lt . ' t.id_last_msg AND t2.is_sticky ' . $gt_lt . '= t.is_sticky) OR t2.is_sticky ' . $gt_lt . ' t.is_sticky') . ')
|
Chris@76
|
117 WHERE t.id_topic = {int:current_topic}
|
Chris@76
|
118 AND t2.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
|
Chris@76
|
119 AND (t2.approved = {int:is_approved} OR (t2.id_member_started != {int:id_member_started} AND t2.id_member_started = {int:current_member}))') . '
|
Chris@76
|
120 ORDER BY' . (empty($modSettings['enableStickyTopics']) ? '' : ' t2.is_sticky' . $order . ',') . ' t2.id_last_msg' . $order . '
|
Chris@76
|
121 LIMIT 1',
|
Chris@76
|
122 array(
|
Chris@76
|
123 'current_board' => $board,
|
Chris@76
|
124 'current_member' => $user_info['id'],
|
Chris@76
|
125 'current_topic' => $topic,
|
Chris@76
|
126 'is_approved' => 1,
|
Chris@76
|
127 'id_member_started' => 0,
|
Chris@76
|
128 )
|
Chris@76
|
129 );
|
Chris@76
|
130
|
Chris@76
|
131 // No more left.
|
Chris@76
|
132 if ($smcFunc['db_num_rows']($request) == 0)
|
Chris@76
|
133 {
|
Chris@76
|
134 $smcFunc['db_free_result']($request);
|
Chris@76
|
135
|
Chris@76
|
136 // Roll over - if we're going prev, get the last - otherwise the first.
|
Chris@76
|
137 $request = $smcFunc['db_query']('', '
|
Chris@76
|
138 SELECT id_topic
|
Chris@76
|
139 FROM {db_prefix}topics
|
Chris@76
|
140 WHERE id_board = {int:current_board}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
|
Chris@76
|
141 AND (approved = {int:is_approved} OR (id_member_started != {int:id_member_started} AND id_member_started = {int:current_member}))') . '
|
Chris@76
|
142 ORDER BY' . (empty($modSettings['enableStickyTopics']) ? '' : ' is_sticky' . $order . ',') . ' id_last_msg' . $order . '
|
Chris@76
|
143 LIMIT 1',
|
Chris@76
|
144 array(
|
Chris@76
|
145 'current_board' => $board,
|
Chris@76
|
146 'current_member' => $user_info['id'],
|
Chris@76
|
147 'is_approved' => 1,
|
Chris@76
|
148 'id_member_started' => 0,
|
Chris@76
|
149 )
|
Chris@76
|
150 );
|
Chris@76
|
151 }
|
Chris@76
|
152
|
Chris@76
|
153 // Now you can be sure $topic is the id_topic to view.
|
Chris@76
|
154 list ($topic) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
155 $smcFunc['db_free_result']($request);
|
Chris@76
|
156
|
Chris@76
|
157 $context['current_topic'] = $topic;
|
Chris@76
|
158 }
|
Chris@76
|
159
|
Chris@76
|
160 // Go to the newest message on this topic.
|
Chris@76
|
161 $_REQUEST['start'] = 'new';
|
Chris@76
|
162 }
|
Chris@76
|
163
|
Chris@76
|
164 // Add 1 to the number of views of this topic.
|
Chris@76
|
165 if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic)
|
Chris@76
|
166 {
|
Chris@76
|
167 $smcFunc['db_query']('', '
|
Chris@76
|
168 UPDATE {db_prefix}topics
|
Chris@76
|
169 SET num_views = num_views + 1
|
Chris@76
|
170 WHERE id_topic = {int:current_topic}',
|
Chris@76
|
171 array(
|
Chris@76
|
172 'current_topic' => $topic,
|
Chris@76
|
173 )
|
Chris@76
|
174 );
|
Chris@76
|
175
|
Chris@76
|
176 $_SESSION['last_read_topic'] = $topic;
|
Chris@76
|
177 }
|
Chris@76
|
178
|
Chris@76
|
179 // Get all the important topic info.
|
Chris@76
|
180 $request = $smcFunc['db_query']('', '
|
Chris@76
|
181 SELECT
|
Chris@76
|
182 t.num_replies, t.num_views, t.locked, ms.subject, t.is_sticky, t.id_poll,
|
Chris@76
|
183 t.id_member_started, t.id_first_msg, t.id_last_msg, t.approved, t.unapproved_posts,
|
Chris@76
|
184 ' . ($user_info['is_guest'] ? 't.id_last_msg + 1' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from
|
Chris@76
|
185 ' . (!empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $board ? ', id_previous_board, id_previous_topic' : '') . '
|
Chris@76
|
186 FROM {db_prefix}topics AS t
|
Chris@76
|
187 INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)' . ($user_info['is_guest'] ? '' : '
|
Chris@76
|
188 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = {int:current_topic} AND lt.id_member = {int:current_member})
|
Chris@76
|
189 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
|
190 WHERE t.id_topic = {int:current_topic}
|
Chris@76
|
191 LIMIT 1',
|
Chris@76
|
192 array(
|
Chris@76
|
193 'current_member' => $user_info['id'],
|
Chris@76
|
194 'current_topic' => $topic,
|
Chris@76
|
195 'current_board' => $board,
|
Chris@76
|
196 )
|
Chris@76
|
197 );
|
Chris@76
|
198 if ($smcFunc['db_num_rows']($request) == 0)
|
Chris@76
|
199 fatal_lang_error('not_a_topic', false);
|
Chris@76
|
200 $topicinfo = $smcFunc['db_fetch_assoc']($request);
|
Chris@76
|
201 $smcFunc['db_free_result']($request);
|
Chris@76
|
202
|
Chris@76
|
203 $context['real_num_replies'] = $context['num_replies'] = $topicinfo['num_replies'];
|
Chris@76
|
204 $context['topic_first_message'] = $topicinfo['id_first_msg'];
|
Chris@76
|
205 $context['topic_last_message'] = $topicinfo['id_last_msg'];
|
Chris@76
|
206
|
Chris@76
|
207 // Add up unapproved replies to get real number of replies...
|
Chris@76
|
208 if ($modSettings['postmod_active'] && allowedTo('approve_posts'))
|
Chris@76
|
209 $context['real_num_replies'] += $topicinfo['unapproved_posts'] - ($topicinfo['approved'] ? 0 : 1);
|
Chris@76
|
210
|
Chris@76
|
211 // If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
|
Chris@76
|
212 if ($modSettings['postmod_active'] && $topicinfo['unapproved_posts'] && !$user_info['is_guest'] && !allowedTo('approve_posts'))
|
Chris@76
|
213 {
|
Chris@76
|
214 $request = $smcFunc['db_query']('', '
|
Chris@76
|
215 SELECT COUNT(id_member) AS my_unapproved_posts
|
Chris@76
|
216 FROM {db_prefix}messages
|
Chris@76
|
217 WHERE id_topic = {int:current_topic}
|
Chris@76
|
218 AND id_member = {int:current_member}
|
Chris@76
|
219 AND approved = 0',
|
Chris@76
|
220 array(
|
Chris@76
|
221 'current_topic' => $topic,
|
Chris@76
|
222 'current_member' => $user_info['id'],
|
Chris@76
|
223 )
|
Chris@76
|
224 );
|
Chris@76
|
225 list ($myUnapprovedPosts) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
226 $smcFunc['db_free_result']($request);
|
Chris@76
|
227
|
Chris@76
|
228 $context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($topicinfo['approved'] ? 1 : 0);
|
Chris@76
|
229 }
|
Chris@76
|
230 else
|
Chris@76
|
231 $context['total_visible_posts'] = $context['num_replies'] + $topicinfo['unapproved_posts'] + ($topicinfo['approved'] ? 1 : 0);
|
Chris@76
|
232
|
Chris@76
|
233 // When was the last time this topic was replied to? Should we warn them about it?
|
Chris@76
|
234 $request = $smcFunc['db_query']('', '
|
Chris@76
|
235 SELECT poster_time
|
Chris@76
|
236 FROM {db_prefix}messages
|
Chris@76
|
237 WHERE id_msg = {int:id_last_msg}
|
Chris@76
|
238 LIMIT 1',
|
Chris@76
|
239 array(
|
Chris@76
|
240 'id_last_msg' => $topicinfo['id_last_msg'],
|
Chris@76
|
241 )
|
Chris@76
|
242 );
|
Chris@76
|
243
|
Chris@76
|
244 list ($lastPostTime) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
245 $smcFunc['db_free_result']($request);
|
Chris@76
|
246
|
Chris@76
|
247 $context['oldTopicError'] = !empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky);
|
Chris@76
|
248
|
Chris@76
|
249 // The start isn't a number; it's information about what to do, where to go.
|
Chris@76
|
250 if (!is_numeric($_REQUEST['start']))
|
Chris@76
|
251 {
|
Chris@76
|
252 // Redirect to the page and post with new messages, originally by Omar Bazavilvazo.
|
Chris@76
|
253 if ($_REQUEST['start'] == 'new')
|
Chris@76
|
254 {
|
Chris@76
|
255 // Guests automatically go to the last post.
|
Chris@76
|
256 if ($user_info['is_guest'])
|
Chris@76
|
257 {
|
Chris@76
|
258 $context['start_from'] = $context['total_visible_posts'] - 1;
|
Chris@76
|
259 $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
|
Chris@76
|
260 }
|
Chris@76
|
261 else
|
Chris@76
|
262 {
|
Chris@76
|
263 // Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
|
Chris@76
|
264 $request = $smcFunc['db_query']('', '
|
Chris@76
|
265 SELECT IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from
|
Chris@76
|
266 FROM {db_prefix}topics AS t
|
Chris@76
|
267 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = {int:current_topic} AND lt.id_member = {int:current_member})
|
Chris@76
|
268 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
|
269 WHERE t.id_topic = {int:current_topic}
|
Chris@76
|
270 LIMIT 1',
|
Chris@76
|
271 array(
|
Chris@76
|
272 'current_board' => $board,
|
Chris@76
|
273 'current_member' => $user_info['id'],
|
Chris@76
|
274 'current_topic' => $topic,
|
Chris@76
|
275 )
|
Chris@76
|
276 );
|
Chris@76
|
277 list ($new_from) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
278 $smcFunc['db_free_result']($request);
|
Chris@76
|
279
|
Chris@76
|
280 // Fall through to the next if statement.
|
Chris@76
|
281 $_REQUEST['start'] = 'msg' . $new_from;
|
Chris@76
|
282 }
|
Chris@76
|
283 }
|
Chris@76
|
284
|
Chris@76
|
285 // Start from a certain time index, not a message.
|
Chris@76
|
286 if (substr($_REQUEST['start'], 0, 4) == 'from')
|
Chris@76
|
287 {
|
Chris@76
|
288 $timestamp = (int) substr($_REQUEST['start'], 4);
|
Chris@76
|
289 if ($timestamp === 0)
|
Chris@76
|
290 $_REQUEST['start'] = 0;
|
Chris@76
|
291 else
|
Chris@76
|
292 {
|
Chris@76
|
293 // Find the number of messages posted before said time...
|
Chris@76
|
294 $request = $smcFunc['db_query']('', '
|
Chris@76
|
295 SELECT COUNT(*)
|
Chris@76
|
296 FROM {db_prefix}messages
|
Chris@76
|
297 WHERE poster_time < {int:timestamp}
|
Chris@76
|
298 AND id_topic = {int:current_topic}' . ($modSettings['postmod_active'] && $topicinfo['unapproved_posts'] && !allowedTo('approve_posts') ? '
|
Chris@76
|
299 AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')' : ''),
|
Chris@76
|
300 array(
|
Chris@76
|
301 'current_topic' => $topic,
|
Chris@76
|
302 'current_member' => $user_info['id'],
|
Chris@76
|
303 'is_approved' => 1,
|
Chris@76
|
304 'timestamp' => $timestamp,
|
Chris@76
|
305 )
|
Chris@76
|
306 );
|
Chris@76
|
307 list ($context['start_from']) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
308 $smcFunc['db_free_result']($request);
|
Chris@76
|
309
|
Chris@76
|
310 // Handle view_newest_first options, and get the correct start value.
|
Chris@76
|
311 $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : $context['total_visible_posts'] - $context['start_from'] - 1;
|
Chris@76
|
312 }
|
Chris@76
|
313 }
|
Chris@76
|
314
|
Chris@76
|
315 // Link to a message...
|
Chris@76
|
316 elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
|
Chris@76
|
317 {
|
Chris@76
|
318 $virtual_msg = (int) substr($_REQUEST['start'], 3);
|
Chris@76
|
319 if (!$topicinfo['unapproved_posts'] && $virtual_msg >= $topicinfo['id_last_msg'])
|
Chris@76
|
320 $context['start_from'] = $context['total_visible_posts'] - 1;
|
Chris@76
|
321 elseif (!$topicinfo['unapproved_posts'] && $virtual_msg <= $topicinfo['id_first_msg'])
|
Chris@76
|
322 $context['start_from'] = 0;
|
Chris@76
|
323 else
|
Chris@76
|
324 {
|
Chris@76
|
325 // Find the start value for that message......
|
Chris@76
|
326 $request = $smcFunc['db_query']('', '
|
Chris@76
|
327 SELECT COUNT(*)
|
Chris@76
|
328 FROM {db_prefix}messages
|
Chris@76
|
329 WHERE id_msg < {int:virtual_msg}
|
Chris@76
|
330 AND id_topic = {int:current_topic}' . ($modSettings['postmod_active'] && $topicinfo['unapproved_posts'] && !allowedTo('approve_posts') ? '
|
Chris@76
|
331 AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')' : ''),
|
Chris@76
|
332 array(
|
Chris@76
|
333 'current_member' => $user_info['id'],
|
Chris@76
|
334 'current_topic' => $topic,
|
Chris@76
|
335 'virtual_msg' => $virtual_msg,
|
Chris@76
|
336 'is_approved' => 1,
|
Chris@76
|
337 'no_member' => 0,
|
Chris@76
|
338 )
|
Chris@76
|
339 );
|
Chris@76
|
340 list ($context['start_from']) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
341 $smcFunc['db_free_result']($request);
|
Chris@76
|
342 }
|
Chris@76
|
343
|
Chris@76
|
344 // We need to reverse the start as well in this case.
|
Chris@76
|
345 $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : $context['total_visible_posts'] - $context['start_from'] - 1;
|
Chris@76
|
346 }
|
Chris@76
|
347 }
|
Chris@76
|
348
|
Chris@76
|
349 // Create a previous next string if the selected theme has it as a selected option.
|
Chris@76
|
350 $context['previous_next'] = $modSettings['enablePreviousNext'] ? '<a href="' . $scripturl . '?topic=' . $topic . '.0;prev_next=prev#new">' . $txt['previous_next_back'] . '</a> <a href="' . $scripturl . '?topic=' . $topic . '.0;prev_next=next#new">' . $txt['previous_next_forward'] . '</a>' : '';
|
Chris@76
|
351
|
Chris@76
|
352 // Check if spellchecking is both enabled and actually working. (for quick reply.)
|
Chris@76
|
353 $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new');
|
Chris@76
|
354
|
Chris@76
|
355 // Do we need to show the visual verification image?
|
Chris@76
|
356 $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1));
|
Chris@76
|
357 if ($context['require_verification'])
|
Chris@76
|
358 {
|
Chris@76
|
359 require_once($sourcedir . '/Subs-Editor.php');
|
Chris@76
|
360 $verificationOptions = array(
|
Chris@76
|
361 'id' => 'post',
|
Chris@76
|
362 );
|
Chris@76
|
363 $context['require_verification'] = create_control_verification($verificationOptions);
|
Chris@76
|
364 $context['visual_verification_id'] = $verificationOptions['id'];
|
Chris@76
|
365 }
|
Chris@76
|
366
|
Chris@76
|
367 // Are we showing signatures - or disabled fields?
|
Chris@76
|
368 $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
|
Chris@76
|
369 $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
|
Chris@76
|
370
|
Chris@76
|
371 // Censor the title...
|
Chris@76
|
372 censorText($topicinfo['subject']);
|
Chris@76
|
373 $context['page_title'] = $topicinfo['subject'];
|
Chris@76
|
374
|
Chris@76
|
375 // Is this topic sticky, or can it even be?
|
Chris@76
|
376 $topicinfo['is_sticky'] = empty($modSettings['enableStickyTopics']) ? '0' : $topicinfo['is_sticky'];
|
Chris@76
|
377
|
Chris@76
|
378 // Default this topic to not marked for notifications... of course...
|
Chris@76
|
379 $context['is_marked_notify'] = false;
|
Chris@76
|
380
|
Chris@76
|
381 // Did we report a post to a moderator just now?
|
Chris@76
|
382 $context['report_sent'] = isset($_GET['reportsent']);
|
Chris@76
|
383
|
Chris@76
|
384 // Let's get nosey, who is viewing this topic?
|
Chris@76
|
385 if (!empty($settings['display_who_viewing']))
|
Chris@76
|
386 {
|
Chris@76
|
387 // Start out with no one at all viewing it.
|
Chris@76
|
388 $context['view_members'] = array();
|
Chris@76
|
389 $context['view_members_list'] = array();
|
Chris@76
|
390 $context['view_num_hidden'] = 0;
|
Chris@76
|
391
|
Chris@76
|
392 // Search for members who have this topic set in their GET data.
|
Chris@76
|
393 $request = $smcFunc['db_query']('', '
|
Chris@76
|
394 SELECT
|
Chris@76
|
395 lo.id_member, lo.log_time, mem.real_name, mem.member_name, mem.show_online,
|
Chris@76
|
396 mg.online_color, mg.id_group, mg.group_name
|
Chris@76
|
397 FROM {db_prefix}log_online AS lo
|
Chris@76
|
398 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lo.id_member)
|
Chris@76
|
399 LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_id_group} THEN mem.id_post_group ELSE mem.id_group END)
|
Chris@76
|
400 WHERE INSTR(lo.url, {string:in_url_string}) > 0 OR lo.session = {string:session}',
|
Chris@76
|
401 array(
|
Chris@76
|
402 'reg_id_group' => 0,
|
Chris@76
|
403 'in_url_string' => 's:5:"topic";i:' . $topic . ';',
|
Chris@76
|
404 'session' => $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(),
|
Chris@76
|
405 )
|
Chris@76
|
406 );
|
Chris@76
|
407 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
408 {
|
Chris@76
|
409 if (empty($row['id_member']))
|
Chris@76
|
410 continue;
|
Chris@76
|
411
|
Chris@76
|
412 if (!empty($row['online_color']))
|
Chris@76
|
413 $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
|
Chris@76
|
414 else
|
Chris@76
|
415 $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
|
Chris@76
|
416
|
Chris@76
|
417 $is_buddy = in_array($row['id_member'], $user_info['buddies']);
|
Chris@76
|
418 if ($is_buddy)
|
Chris@76
|
419 $link = '<strong>' . $link . '</strong>';
|
Chris@76
|
420
|
Chris@76
|
421 // Add them both to the list and to the more detailed list.
|
Chris@76
|
422 if (!empty($row['show_online']) || allowedTo('moderate_forum'))
|
Chris@76
|
423 $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
|
Chris@76
|
424 $context['view_members'][$row['log_time'] . $row['member_name']] = array(
|
Chris@76
|
425 'id' => $row['id_member'],
|
Chris@76
|
426 'username' => $row['member_name'],
|
Chris@76
|
427 'name' => $row['real_name'],
|
Chris@76
|
428 'group' => $row['id_group'],
|
Chris@76
|
429 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
|
Chris@76
|
430 'link' => $link,
|
Chris@76
|
431 'is_buddy' => $is_buddy,
|
Chris@76
|
432 'hidden' => empty($row['show_online']),
|
Chris@76
|
433 );
|
Chris@76
|
434
|
Chris@76
|
435 if (empty($row['show_online']))
|
Chris@76
|
436 $context['view_num_hidden']++;
|
Chris@76
|
437 }
|
Chris@76
|
438
|
Chris@76
|
439 // The number of guests is equal to the rows minus the ones we actually used ;).
|
Chris@76
|
440 $context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
|
Chris@76
|
441 $smcFunc['db_free_result']($request);
|
Chris@76
|
442
|
Chris@76
|
443 // Sort the list.
|
Chris@76
|
444 krsort($context['view_members']);
|
Chris@76
|
445 krsort($context['view_members_list']);
|
Chris@76
|
446 }
|
Chris@76
|
447
|
Chris@76
|
448 // If all is set, but not allowed... just unset it.
|
Chris@76
|
449 $can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
|
Chris@76
|
450 if (isset($_REQUEST['all']) && !$can_show_all)
|
Chris@76
|
451 unset($_REQUEST['all']);
|
Chris@76
|
452 // Otherwise, it must be allowed... so pretend start was -1.
|
Chris@76
|
453 elseif (isset($_REQUEST['all']))
|
Chris@76
|
454 $_REQUEST['start'] = -1;
|
Chris@76
|
455
|
Chris@76
|
456 // Construct the page index, allowing for the .START method...
|
Chris@76
|
457 $context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
|
Chris@76
|
458 $context['start'] = $_REQUEST['start'];
|
Chris@76
|
459
|
Chris@76
|
460 // This is information about which page is current, and which page we're on - in case you don't like the constructed page index. (again, wireles..)
|
Chris@76
|
461 $context['page_info'] = array(
|
Chris@76
|
462 'current_page' => $_REQUEST['start'] / $context['messages_per_page'] + 1,
|
Chris@76
|
463 'num_pages' => floor(($context['total_visible_posts'] - 1) / $context['messages_per_page']) + 1,
|
Chris@76
|
464 );
|
Chris@76
|
465
|
Chris@76
|
466 // Figure out all the link to the next/prev/first/last/etc. for wireless mainly.
|
Chris@76
|
467 $context['links'] = array(
|
Chris@76
|
468 'first' => $_REQUEST['start'] >= $context['messages_per_page'] ? $scripturl . '?topic=' . $topic . '.0' : '',
|
Chris@76
|
469 'prev' => $_REQUEST['start'] >= $context['messages_per_page'] ? $scripturl . '?topic=' . $topic . '.' . ($_REQUEST['start'] - $context['messages_per_page']) : '',
|
Chris@76
|
470 'next' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic. '.' . ($_REQUEST['start'] + $context['messages_per_page']) : '',
|
Chris@76
|
471 'last' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic. '.' . (floor($context['total_visible_posts'] / $context['messages_per_page']) * $context['messages_per_page']) : '',
|
Chris@76
|
472 'up' => $scripturl . '?board=' . $board . '.0'
|
Chris@76
|
473 );
|
Chris@76
|
474
|
Chris@76
|
475 // If they are viewing all the posts, show all the posts, otherwise limit the number.
|
Chris@76
|
476 if ($can_show_all)
|
Chris@76
|
477 {
|
Chris@76
|
478 if (isset($_REQUEST['all']))
|
Chris@76
|
479 {
|
Chris@76
|
480 // No limit! (actually, there is a limit, but...)
|
Chris@76
|
481 $context['messages_per_page'] = -1;
|
Chris@76
|
482 $context['page_index'] .= empty($modSettings['compactTopicPagesEnable']) ? '<strong>' . $txt['all'] . '</strong> ' : '[<strong>' . $txt['all'] . '</strong>] ';
|
Chris@76
|
483
|
Chris@76
|
484 // Set start back to 0...
|
Chris@76
|
485 $_REQUEST['start'] = 0;
|
Chris@76
|
486 }
|
Chris@76
|
487 // They aren't using it, but the *option* is there, at least.
|
Chris@76
|
488 else
|
Chris@76
|
489 $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
|
Chris@76
|
490 }
|
Chris@76
|
491
|
Chris@76
|
492 // Build the link tree.
|
Chris@76
|
493 $context['linktree'][] = array(
|
Chris@76
|
494 'url' => $scripturl . '?topic=' . $topic . '.0',
|
Chris@76
|
495 'name' => $topicinfo['subject'],
|
Chris@76
|
496 'extra_before' => $settings['linktree_inline'] ? $txt['topic'] . ': ' : ''
|
Chris@76
|
497 );
|
Chris@76
|
498
|
Chris@76
|
499 // Build a list of this board's moderators.
|
Chris@76
|
500 $context['moderators'] = &$board_info['moderators'];
|
Chris@76
|
501 $context['link_moderators'] = array();
|
Chris@76
|
502 if (!empty($board_info['moderators']))
|
Chris@76
|
503 {
|
Chris@76
|
504 // Add a link for each moderator...
|
Chris@76
|
505 foreach ($board_info['moderators'] as $mod)
|
Chris@76
|
506 $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
|
Chris@76
|
507
|
Chris@76
|
508 // And show it after the board's name.
|
Chris@76
|
509 $context['linktree'][count($context['linktree']) - 2]['extra_after'] = ' (' . (count($context['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators']) . ': ' . implode(', ', $context['link_moderators']) . ')';
|
Chris@76
|
510 }
|
Chris@76
|
511
|
Chris@76
|
512 // Information about the current topic...
|
Chris@76
|
513 $context['is_locked'] = $topicinfo['locked'];
|
Chris@76
|
514 $context['is_sticky'] = $topicinfo['is_sticky'];
|
Chris@76
|
515 $context['is_very_hot'] = $topicinfo['num_replies'] >= $modSettings['hotTopicVeryPosts'];
|
Chris@76
|
516 $context['is_hot'] = $topicinfo['num_replies'] >= $modSettings['hotTopicPosts'];
|
Chris@76
|
517 $context['is_approved'] = $topicinfo['approved'];
|
Chris@76
|
518
|
Chris@76
|
519 // We don't want to show the poll icon in the topic class here, so pretend it's not one.
|
Chris@76
|
520 $context['is_poll'] = false;
|
Chris@76
|
521 determineTopicClass($context);
|
Chris@76
|
522
|
Chris@76
|
523 $context['is_poll'] = $topicinfo['id_poll'] > 0 && $modSettings['pollMode'] == '1' && allowedTo('poll_view');
|
Chris@76
|
524
|
Chris@76
|
525 // Did this user start the topic or not?
|
Chris@76
|
526 $context['user']['started'] = $user_info['id'] == $topicinfo['id_member_started'] && !$user_info['is_guest'];
|
Chris@76
|
527 $context['topic_starter_id'] = $topicinfo['id_member_started'];
|
Chris@76
|
528
|
Chris@76
|
529 // Set the topic's information for the template.
|
Chris@76
|
530 $context['subject'] = $topicinfo['subject'];
|
Chris@76
|
531 $context['num_views'] = $topicinfo['num_views'];
|
Chris@76
|
532 $context['mark_unread_time'] = $topicinfo['new_from'];
|
Chris@76
|
533
|
Chris@76
|
534 // Set a canonical URL for this page.
|
Chris@76
|
535 $context['canonical_url'] = $scripturl . '?topic=' . $topic . '.' . $context['start'];
|
Chris@76
|
536
|
Chris@76
|
537 // For quick reply we need a response prefix in the default forum language.
|
Chris@76
|
538 if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
|
Chris@76
|
539 {
|
Chris@76
|
540 if ($language === $user_info['language'])
|
Chris@76
|
541 $context['response_prefix'] = $txt['response_prefix'];
|
Chris@76
|
542 else
|
Chris@76
|
543 {
|
Chris@76
|
544 loadLanguage('index', $language, false);
|
Chris@76
|
545 $context['response_prefix'] = $txt['response_prefix'];
|
Chris@76
|
546 loadLanguage('index');
|
Chris@76
|
547 }
|
Chris@76
|
548 cache_put_data('response_prefix', $context['response_prefix'], 600);
|
Chris@76
|
549 }
|
Chris@76
|
550
|
Chris@76
|
551 // If we want to show event information in the topic, prepare the data.
|
Chris@76
|
552 if (allowedTo('calendar_view') && !empty($modSettings['cal_showInTopic']) && !empty($modSettings['cal_enabled']))
|
Chris@76
|
553 {
|
Chris@76
|
554 // First, try create a better time format, ignoring the "time" elements.
|
Chris@76
|
555 if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
|
Chris@76
|
556 $date_string = $user_info['time_format'];
|
Chris@76
|
557 else
|
Chris@76
|
558 $date_string = $matches[0];
|
Chris@76
|
559
|
Chris@76
|
560 // Any calendar information for this topic?
|
Chris@76
|
561 $request = $smcFunc['db_query']('', '
|
Chris@76
|
562 SELECT cal.id_event, cal.start_date, cal.end_date, cal.title, cal.id_member, mem.real_name
|
Chris@76
|
563 FROM {db_prefix}calendar AS cal
|
Chris@76
|
564 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = cal.id_member)
|
Chris@76
|
565 WHERE cal.id_topic = {int:current_topic}
|
Chris@76
|
566 ORDER BY start_date',
|
Chris@76
|
567 array(
|
Chris@76
|
568 'current_topic' => $topic,
|
Chris@76
|
569 )
|
Chris@76
|
570 );
|
Chris@76
|
571 $context['linked_calendar_events'] = array();
|
Chris@76
|
572 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
573 {
|
Chris@76
|
574 // Prepare the dates for being formatted.
|
Chris@76
|
575 $start_date = sscanf($row['start_date'], '%04d-%02d-%02d');
|
Chris@76
|
576 $start_date = mktime(12, 0, 0, $start_date[1], $start_date[2], $start_date[0]);
|
Chris@76
|
577 $end_date = sscanf($row['end_date'], '%04d-%02d-%02d');
|
Chris@76
|
578 $end_date = mktime(12, 0, 0, $end_date[1], $end_date[2], $end_date[0]);
|
Chris@76
|
579
|
Chris@76
|
580 $context['linked_calendar_events'][] = array(
|
Chris@76
|
581 'id' => $row['id_event'],
|
Chris@76
|
582 'title' => $row['title'],
|
Chris@76
|
583 'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
|
Chris@76
|
584 'modify_href' => $scripturl . '?action=post;msg=' . $topicinfo['id_first_msg'] . ';topic=' . $topic . '.0;calendar;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
|
Chris@76
|
585 'start_date' => timeformat($start_date, $date_string, 'none'),
|
Chris@76
|
586 'start_timestamp' => $start_date,
|
Chris@76
|
587 'end_date' => timeformat($end_date, $date_string, 'none'),
|
Chris@76
|
588 'end_timestamp' => $end_date,
|
Chris@76
|
589 'is_last' => false
|
Chris@76
|
590 );
|
Chris@76
|
591 }
|
Chris@76
|
592 $smcFunc['db_free_result']($request);
|
Chris@76
|
593
|
Chris@76
|
594 if (!empty($context['linked_calendar_events']))
|
Chris@76
|
595 $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
|
Chris@76
|
596 }
|
Chris@76
|
597
|
Chris@76
|
598 // Create the poll info if it exists.
|
Chris@76
|
599 if ($context['is_poll'])
|
Chris@76
|
600 {
|
Chris@76
|
601 // Get the question and if it's locked.
|
Chris@76
|
602 $request = $smcFunc['db_query']('', '
|
Chris@76
|
603 SELECT
|
Chris@76
|
604 p.question, p.voting_locked, p.hide_results, p.expire_time, p.max_votes, p.change_vote,
|
Chris@76
|
605 p.guest_vote, p.id_member, IFNULL(mem.real_name, p.poster_name) AS poster_name, p.num_guest_voters, p.reset_poll
|
Chris@76
|
606 FROM {db_prefix}polls AS p
|
Chris@76
|
607 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = p.id_member)
|
Chris@76
|
608 WHERE p.id_poll = {int:id_poll}
|
Chris@76
|
609 LIMIT 1',
|
Chris@76
|
610 array(
|
Chris@76
|
611 'id_poll' => $topicinfo['id_poll'],
|
Chris@76
|
612 )
|
Chris@76
|
613 );
|
Chris@76
|
614 $pollinfo = $smcFunc['db_fetch_assoc']($request);
|
Chris@76
|
615 $smcFunc['db_free_result']($request);
|
Chris@76
|
616
|
Chris@76
|
617 $request = $smcFunc['db_query']('', '
|
Chris@76
|
618 SELECT COUNT(DISTINCT id_member) AS total
|
Chris@76
|
619 FROM {db_prefix}log_polls
|
Chris@76
|
620 WHERE id_poll = {int:id_poll}
|
Chris@76
|
621 AND id_member != {int:not_guest}',
|
Chris@76
|
622 array(
|
Chris@76
|
623 'id_poll' => $topicinfo['id_poll'],
|
Chris@76
|
624 'not_guest' => 0,
|
Chris@76
|
625 )
|
Chris@76
|
626 );
|
Chris@76
|
627 list ($pollinfo['total']) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
628 $smcFunc['db_free_result']($request);
|
Chris@76
|
629
|
Chris@76
|
630 // Total voters needs to include guest voters
|
Chris@76
|
631 $pollinfo['total'] += $pollinfo['num_guest_voters'];
|
Chris@76
|
632
|
Chris@76
|
633 // Get all the options, and calculate the total votes.
|
Chris@76
|
634 $request = $smcFunc['db_query']('', '
|
Chris@76
|
635 SELECT pc.id_choice, pc.label, pc.votes, IFNULL(lp.id_choice, -1) AS voted_this
|
Chris@76
|
636 FROM {db_prefix}poll_choices AS pc
|
Chris@76
|
637 LEFT JOIN {db_prefix}log_polls AS lp ON (lp.id_choice = pc.id_choice AND lp.id_poll = {int:id_poll} AND lp.id_member = {int:current_member} AND lp.id_member != {int:not_guest})
|
Chris@76
|
638 WHERE pc.id_poll = {int:id_poll}',
|
Chris@76
|
639 array(
|
Chris@76
|
640 'current_member' => $user_info['id'],
|
Chris@76
|
641 'id_poll' => $topicinfo['id_poll'],
|
Chris@76
|
642 'not_guest' => 0,
|
Chris@76
|
643 )
|
Chris@76
|
644 );
|
Chris@76
|
645 $pollOptions = array();
|
Chris@76
|
646 $realtotal = 0;
|
Chris@76
|
647 $pollinfo['has_voted'] = false;
|
Chris@76
|
648 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
649 {
|
Chris@76
|
650 censorText($row['label']);
|
Chris@76
|
651 $pollOptions[$row['id_choice']] = $row;
|
Chris@76
|
652 $realtotal += $row['votes'];
|
Chris@76
|
653 $pollinfo['has_voted'] |= $row['voted_this'] != -1;
|
Chris@76
|
654 }
|
Chris@76
|
655 $smcFunc['db_free_result']($request);
|
Chris@76
|
656
|
Chris@76
|
657 // If this is a guest we need to do our best to work out if they have voted, and what they voted for.
|
Chris@76
|
658 if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
|
Chris@76
|
659 {
|
Chris@76
|
660 if (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $topicinfo['id_poll'] . ',') !== false)
|
Chris@76
|
661 {
|
Chris@76
|
662 // ;id,timestamp,[vote,vote...]; etc
|
Chris@76
|
663 $guestinfo = explode(';', $_COOKIE['guest_poll_vote']);
|
Chris@76
|
664 // Find the poll we're after.
|
Chris@76
|
665 foreach ($guestinfo as $i => $guestvoted)
|
Chris@76
|
666 {
|
Chris@76
|
667 $guestvoted = explode(',', $guestvoted);
|
Chris@76
|
668 if ($guestvoted[0] == $topicinfo['id_poll'])
|
Chris@76
|
669 break;
|
Chris@76
|
670 }
|
Chris@76
|
671 // Has the poll been reset since guest voted?
|
Chris@76
|
672 if ($pollinfo['reset_poll'] > $guestvoted[1])
|
Chris@76
|
673 {
|
Chris@76
|
674 // Remove the poll info from the cookie to allow guest to vote again
|
Chris@76
|
675 unset($guestinfo[$i]);
|
Chris@76
|
676 if (!empty($guestinfo))
|
Chris@76
|
677 $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
|
Chris@76
|
678 else
|
Chris@76
|
679 unset($_COOKIE['guest_poll_vote']);
|
Chris@76
|
680 }
|
Chris@76
|
681 else
|
Chris@76
|
682 {
|
Chris@76
|
683 // What did they vote for?
|
Chris@76
|
684 unset($guestvoted[0], $guestvoted[1]);
|
Chris@76
|
685 foreach ($pollOptions as $choice => $details)
|
Chris@76
|
686 {
|
Chris@76
|
687 $pollOptions[$choice]['voted_this'] = in_array($choice, $guestvoted) ? 1 : -1;
|
Chris@76
|
688 $pollinfo['has_voted'] |= $pollOptions[$choice]['voted_this'] != -1;
|
Chris@76
|
689 }
|
Chris@76
|
690 unset($choice, $details, $guestvoted);
|
Chris@76
|
691 }
|
Chris@76
|
692 unset($guestinfo, $guestvoted, $i);
|
Chris@76
|
693 }
|
Chris@76
|
694 }
|
Chris@76
|
695
|
Chris@76
|
696 // Set up the basic poll information.
|
Chris@76
|
697 $context['poll'] = array(
|
Chris@76
|
698 'id' => $topicinfo['id_poll'],
|
Chris@76
|
699 'image' => 'normal_' . (empty($pollinfo['voting_locked']) ? 'poll' : 'locked_poll'),
|
Chris@76
|
700 'question' => parse_bbc($pollinfo['question']),
|
Chris@76
|
701 'total_votes' => $pollinfo['total'],
|
Chris@76
|
702 'change_vote' => !empty($pollinfo['change_vote']),
|
Chris@76
|
703 'is_locked' => !empty($pollinfo['voting_locked']),
|
Chris@76
|
704 'options' => array(),
|
Chris@76
|
705 'lock' => allowedTo('poll_lock_any') || ($context['user']['started'] && allowedTo('poll_lock_own')),
|
Chris@76
|
706 'edit' => allowedTo('poll_edit_any') || ($context['user']['started'] && allowedTo('poll_edit_own')),
|
Chris@76
|
707 'allowed_warning' => $pollinfo['max_votes'] > 1 ? sprintf($txt['poll_options6'], min(count($pollOptions), $pollinfo['max_votes'])) : '',
|
Chris@76
|
708 'is_expired' => !empty($pollinfo['expire_time']) && $pollinfo['expire_time'] < time(),
|
Chris@76
|
709 'expire_time' => !empty($pollinfo['expire_time']) ? timeformat($pollinfo['expire_time']) : 0,
|
Chris@76
|
710 'has_voted' => !empty($pollinfo['has_voted']),
|
Chris@76
|
711 'starter' => array(
|
Chris@76
|
712 'id' => $pollinfo['id_member'],
|
Chris@76
|
713 'name' => $row['poster_name'],
|
Chris@76
|
714 'href' => $pollinfo['id_member'] == 0 ? '' : $scripturl . '?action=profile;u=' . $pollinfo['id_member'],
|
Chris@76
|
715 'link' => $pollinfo['id_member'] == 0 ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $pollinfo['id_member'] . '">' . $row['poster_name'] . '</a>'
|
Chris@76
|
716 )
|
Chris@76
|
717 );
|
Chris@76
|
718
|
Chris@76
|
719 // Make the lock and edit permissions defined above more directly accessible.
|
Chris@76
|
720 $context['allow_lock_poll'] = $context['poll']['lock'];
|
Chris@76
|
721 $context['allow_edit_poll'] = $context['poll']['edit'];
|
Chris@76
|
722
|
Chris@76
|
723 // You're allowed to vote if:
|
Chris@76
|
724 // 1. the poll did not expire, and
|
Chris@76
|
725 // 2. you're either not a guest OR guest voting is enabled... and
|
Chris@76
|
726 // 3. you're not trying to view the results, and
|
Chris@76
|
727 // 4. the poll is not locked, and
|
Chris@76
|
728 // 5. you have the proper permissions, and
|
Chris@76
|
729 // 6. you haven't already voted before.
|
Chris@76
|
730 $context['allow_vote'] = !$context['poll']['is_expired'] && (!$user_info['is_guest'] || ($pollinfo['guest_vote'] && allowedTo('poll_vote'))) && empty($pollinfo['voting_locked']) && allowedTo('poll_vote') && !$context['poll']['has_voted'];
|
Chris@76
|
731
|
Chris@76
|
732 // You're allowed to view the results if:
|
Chris@76
|
733 // 1. you're just a super-nice-guy, or
|
Chris@76
|
734 // 2. anyone can see them (hide_results == 0), or
|
Chris@76
|
735 // 3. you can see them after you voted (hide_results == 1), or
|
Chris@76
|
736 // 4. you've waited long enough for the poll to expire. (whether hide_results is 1 or 2.)
|
Chris@76
|
737 $context['allow_poll_view'] = allowedTo('moderate_board') || $pollinfo['hide_results'] == 0 || ($pollinfo['hide_results'] == 1 && $context['poll']['has_voted']) || $context['poll']['is_expired'];
|
Chris@76
|
738 $context['poll']['show_results'] = $context['allow_poll_view'] && (isset($_REQUEST['viewresults']) || isset($_REQUEST['viewResults']));
|
Chris@76
|
739 $context['show_view_results_button'] = $context['allow_vote'] && (!$context['allow_poll_view'] || !$context['poll']['show_results'] || !$context['poll']['has_voted']);
|
Chris@76
|
740
|
Chris@76
|
741 // You're allowed to change your vote if:
|
Chris@76
|
742 // 1. the poll did not expire, and
|
Chris@76
|
743 // 2. you're not a guest... and
|
Chris@76
|
744 // 3. the poll is not locked, and
|
Chris@76
|
745 // 4. you have the proper permissions, and
|
Chris@76
|
746 // 5. you have already voted, and
|
Chris@76
|
747 // 6. the poll creator has said you can!
|
Chris@76
|
748 $context['allow_change_vote'] = !$context['poll']['is_expired'] && !$user_info['is_guest'] && empty($pollinfo['voting_locked']) && allowedTo('poll_vote') && $context['poll']['has_voted'] && $context['poll']['change_vote'];
|
Chris@76
|
749
|
Chris@76
|
750 // You're allowed to return to voting options if:
|
Chris@76
|
751 // 1. you are (still) allowed to vote.
|
Chris@76
|
752 // 2. you are currently seeing the results.
|
Chris@76
|
753 $context['allow_return_vote'] = $context['allow_vote'] && $context['poll']['show_results'];
|
Chris@76
|
754
|
Chris@76
|
755 // Calculate the percentages and bar lengths...
|
Chris@76
|
756 $divisor = $realtotal == 0 ? 1 : $realtotal;
|
Chris@76
|
757
|
Chris@76
|
758 // Determine if a decimal point is needed in order for the options to add to 100%.
|
Chris@76
|
759 $precision = $realtotal == 100 ? 0 : 1;
|
Chris@76
|
760
|
Chris@76
|
761 // Now look through each option, and...
|
Chris@76
|
762 foreach ($pollOptions as $i => $option)
|
Chris@76
|
763 {
|
Chris@76
|
764 // First calculate the percentage, and then the width of the bar...
|
Chris@76
|
765 $bar = round(($option['votes'] * 100) / $divisor, $precision);
|
Chris@76
|
766 $barWide = $bar == 0 ? 1 : floor(($bar * 8) / 3);
|
Chris@76
|
767
|
Chris@76
|
768 // Now add it to the poll's contextual theme data.
|
Chris@76
|
769 $context['poll']['options'][$i] = array(
|
Chris@76
|
770 'id' => 'options-' . $i,
|
Chris@76
|
771 'percent' => $bar,
|
Chris@76
|
772 'votes' => $option['votes'],
|
Chris@76
|
773 'voted_this' => $option['voted_this'] != -1,
|
Chris@76
|
774 'bar' => '<span style="white-space: nowrap;"><img src="' . $settings['images_url'] . '/poll_' . ($context['right_to_left'] ? 'right' : 'left') . '.gif" alt="" /><img src="' . $settings['images_url'] . '/poll_middle.gif" width="' . $barWide . '" height="12" alt="-" /><img src="' . $settings['images_url'] . '/poll_' . ($context['right_to_left'] ? 'left' : 'right') . '.gif" alt="" /></span>',
|
Chris@76
|
775 // Note: IE < 8 requires us to set a width on the container, too.
|
Chris@76
|
776 'bar_ndt' => $bar > 0 ? '<div class="bar" style="width: ' . ($bar * 3.5 + 4) . 'px;"><div style="width: ' . $bar * 3.5 . 'px;"></div></div>' : '',
|
Chris@76
|
777 'bar_width' => $barWide,
|
Chris@76
|
778 'option' => parse_bbc($option['label']),
|
Chris@76
|
779 'vote_button' => '<input type="' . ($pollinfo['max_votes'] > 1 ? 'checkbox' : 'radio') . '" name="options[]" id="options-' . $i . '" value="' . $i . '" class="input_' . ($pollinfo['max_votes'] > 1 ? 'check' : 'radio') . '" />'
|
Chris@76
|
780 );
|
Chris@76
|
781 }
|
Chris@76
|
782 }
|
Chris@76
|
783
|
Chris@76
|
784 // Calculate the fastest way to get the messages!
|
Chris@76
|
785 $ascending = empty($options['view_newest_first']);
|
Chris@76
|
786 $start = $_REQUEST['start'];
|
Chris@76
|
787 $limit = $context['messages_per_page'];
|
Chris@76
|
788 $firstIndex = 0;
|
Chris@76
|
789 if ($start >= $context['total_visible_posts'] / 2 && $context['messages_per_page'] != -1)
|
Chris@76
|
790 {
|
Chris@76
|
791 $ascending = !$ascending;
|
Chris@76
|
792 $limit = $context['total_visible_posts'] <= $start + $limit ? $context['total_visible_posts'] - $start : $limit;
|
Chris@76
|
793 $start = $context['total_visible_posts'] <= $start + $limit ? 0 : $context['total_visible_posts'] - $start - $limit;
|
Chris@76
|
794 $firstIndex = $limit - 1;
|
Chris@76
|
795 }
|
Chris@76
|
796
|
Chris@76
|
797 // Get each post and poster in this topic.
|
Chris@76
|
798 $request = $smcFunc['db_query']('display_get_post_poster', '
|
Chris@76
|
799 SELECT id_msg, id_member, approved
|
Chris@76
|
800 FROM {db_prefix}messages
|
Chris@76
|
801 WHERE id_topic = {int:current_topic}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : (!empty($modSettings['db_mysql_group_by_fix']) ? '' : '
|
Chris@76
|
802 GROUP BY id_msg') . '
|
Chris@76
|
803 HAVING (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
|
Chris@76
|
804 ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
|
Chris@76
|
805 LIMIT ' . $start . ', ' . $limit),
|
Chris@76
|
806 array(
|
Chris@76
|
807 'current_member' => $user_info['id'],
|
Chris@76
|
808 'current_topic' => $topic,
|
Chris@76
|
809 'is_approved' => 1,
|
Chris@76
|
810 'blank_id_member' => 0,
|
Chris@76
|
811 )
|
Chris@76
|
812 );
|
Chris@76
|
813
|
Chris@76
|
814 $messages = array();
|
Chris@76
|
815 $all_posters = array();
|
Chris@76
|
816 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
817 {
|
Chris@76
|
818 if (!empty($row['id_member']))
|
Chris@76
|
819 $all_posters[$row['id_msg']] = $row['id_member'];
|
Chris@76
|
820 $messages[] = $row['id_msg'];
|
Chris@76
|
821 }
|
Chris@76
|
822 $smcFunc['db_free_result']($request);
|
Chris@76
|
823 $posters = array_unique($all_posters);
|
Chris@76
|
824
|
Chris@76
|
825 // Guests can't mark topics read or for notifications, just can't sorry.
|
Chris@76
|
826 if (!$user_info['is_guest'])
|
Chris@76
|
827 {
|
Chris@76
|
828 $mark_at_msg = max($messages);
|
Chris@76
|
829 if ($mark_at_msg >= $topicinfo['id_last_msg'])
|
Chris@76
|
830 $mark_at_msg = $modSettings['maxMsgID'];
|
Chris@76
|
831 if ($mark_at_msg >= $topicinfo['new_from'])
|
Chris@76
|
832 {
|
Chris@76
|
833 $smcFunc['db_insert']($topicinfo['new_from'] == 0 ? 'ignore' : 'replace',
|
Chris@76
|
834 '{db_prefix}log_topics',
|
Chris@76
|
835 array(
|
Chris@76
|
836 'id_member' => 'int', 'id_topic' => 'int', 'id_msg' => 'int',
|
Chris@76
|
837 ),
|
Chris@76
|
838 array(
|
Chris@76
|
839 $user_info['id'], $topic, $mark_at_msg,
|
Chris@76
|
840 ),
|
Chris@76
|
841 array('id_member', 'id_topic')
|
Chris@76
|
842 );
|
Chris@76
|
843 }
|
Chris@76
|
844
|
Chris@76
|
845 // Check for notifications on this topic OR board.
|
Chris@76
|
846 $request = $smcFunc['db_query']('', '
|
Chris@76
|
847 SELECT sent, id_topic
|
Chris@76
|
848 FROM {db_prefix}log_notify
|
Chris@76
|
849 WHERE (id_topic = {int:current_topic} OR id_board = {int:current_board})
|
Chris@76
|
850 AND id_member = {int:current_member}
|
Chris@76
|
851 LIMIT 2',
|
Chris@76
|
852 array(
|
Chris@76
|
853 'current_board' => $board,
|
Chris@76
|
854 'current_member' => $user_info['id'],
|
Chris@76
|
855 'current_topic' => $topic,
|
Chris@76
|
856 )
|
Chris@76
|
857 );
|
Chris@76
|
858 $do_once = true;
|
Chris@76
|
859 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
860 {
|
Chris@76
|
861 // Find if this topic is marked for notification...
|
Chris@76
|
862 if (!empty($row['id_topic']))
|
Chris@76
|
863 $context['is_marked_notify'] = true;
|
Chris@76
|
864
|
Chris@76
|
865 // Only do this once, but mark the notifications as "not sent yet" for next time.
|
Chris@76
|
866 if (!empty($row['sent']) && $do_once)
|
Chris@76
|
867 {
|
Chris@76
|
868 $smcFunc['db_query']('', '
|
Chris@76
|
869 UPDATE {db_prefix}log_notify
|
Chris@76
|
870 SET sent = {int:is_not_sent}
|
Chris@76
|
871 WHERE (id_topic = {int:current_topic} OR id_board = {int:current_board})
|
Chris@76
|
872 AND id_member = {int:current_member}',
|
Chris@76
|
873 array(
|
Chris@76
|
874 'current_board' => $board,
|
Chris@76
|
875 'current_member' => $user_info['id'],
|
Chris@76
|
876 'current_topic' => $topic,
|
Chris@76
|
877 'is_not_sent' => 0,
|
Chris@76
|
878 )
|
Chris@76
|
879 );
|
Chris@76
|
880 $do_once = false;
|
Chris@76
|
881 }
|
Chris@76
|
882 }
|
Chris@76
|
883
|
Chris@76
|
884 // Have we recently cached the number of new topics in this board, and it's still a lot?
|
Chris@76
|
885 if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
|
Chris@76
|
886 $_SESSION['topicseen_cache'][$board]--;
|
Chris@76
|
887 // Mark board as seen if this is the only new topic.
|
Chris@76
|
888 elseif (isset($_REQUEST['topicseen']))
|
Chris@76
|
889 {
|
Chris@76
|
890 // Use the mark read tables... and the last visit to figure out if this should be read or not.
|
Chris@76
|
891 $request = $smcFunc['db_query']('', '
|
Chris@76
|
892 SELECT COUNT(*)
|
Chris@76
|
893 FROM {db_prefix}topics AS t
|
Chris@76
|
894 LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = {int:current_board} AND lb.id_member = {int:current_member})
|
Chris@76
|
895 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
|
Chris@76
|
896 WHERE t.id_board = {int:current_board}
|
Chris@76
|
897 AND t.id_last_msg > IFNULL(lb.id_msg, 0)
|
Chris@76
|
898 AND t.id_last_msg > IFNULL(lt.id_msg, 0)' . (empty($_SESSION['id_msg_last_visit']) ? '' : '
|
Chris@76
|
899 AND t.id_last_msg > {int:id_msg_last_visit}'),
|
Chris@76
|
900 array(
|
Chris@76
|
901 'current_board' => $board,
|
Chris@76
|
902 'current_member' => $user_info['id'],
|
Chris@76
|
903 'id_msg_last_visit' => (int) $_SESSION['id_msg_last_visit'],
|
Chris@76
|
904 )
|
Chris@76
|
905 );
|
Chris@76
|
906 list ($numNewTopics) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
907 $smcFunc['db_free_result']($request);
|
Chris@76
|
908
|
Chris@76
|
909 // If there're no real new topics in this board, mark the board as seen.
|
Chris@76
|
910 if (empty($numNewTopics))
|
Chris@76
|
911 $_REQUEST['boardseen'] = true;
|
Chris@76
|
912 else
|
Chris@76
|
913 $_SESSION['topicseen_cache'][$board] = $numNewTopics;
|
Chris@76
|
914 }
|
Chris@76
|
915 // Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
|
Chris@76
|
916 elseif (isset($_SESSION['topicseen_cache'][$board]))
|
Chris@76
|
917 $_SESSION['topicseen_cache'][$board]--;
|
Chris@76
|
918
|
Chris@76
|
919 // Mark board as seen if we came using last post link from BoardIndex. (or other places...)
|
Chris@76
|
920 if (isset($_REQUEST['boardseen']))
|
Chris@76
|
921 {
|
Chris@76
|
922 $smcFunc['db_insert']('replace',
|
Chris@76
|
923 '{db_prefix}log_boards',
|
Chris@76
|
924 array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
|
Chris@76
|
925 array($modSettings['maxMsgID'], $user_info['id'], $board),
|
Chris@76
|
926 array('id_member', 'id_board')
|
Chris@76
|
927 );
|
Chris@76
|
928 }
|
Chris@76
|
929 }
|
Chris@76
|
930
|
Chris@76
|
931 $attachments = array();
|
Chris@76
|
932
|
Chris@76
|
933 // If there _are_ messages here... (probably an error otherwise :!)
|
Chris@76
|
934 if (!empty($messages))
|
Chris@76
|
935 {
|
Chris@76
|
936 // Fetch attachments.
|
Chris@76
|
937 if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments'))
|
Chris@76
|
938 {
|
Chris@76
|
939 $request = $smcFunc['db_query']('', '
|
Chris@76
|
940 SELECT
|
Chris@76
|
941 a.id_attach, a.id_folder, a.id_msg, a.filename, a.file_hash, IFNULL(a.size, 0) AS filesize, a.downloads, a.approved,
|
Chris@76
|
942 a.width, a.height' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ',
|
Chris@76
|
943 IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height') . '
|
Chris@76
|
944 FROM {db_prefix}attachments AS a' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : '
|
Chris@76
|
945 LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . '
|
Chris@76
|
946 WHERE a.id_msg IN ({array_int:message_list})
|
Chris@76
|
947 AND a.attachment_type = {int:attachment_type}',
|
Chris@76
|
948 array(
|
Chris@76
|
949 'message_list' => $messages,
|
Chris@76
|
950 'attachment_type' => 0,
|
Chris@76
|
951 'is_approved' => 1,
|
Chris@76
|
952 )
|
Chris@76
|
953 );
|
Chris@76
|
954 $temp = array();
|
Chris@76
|
955 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
956 {
|
Chris@76
|
957 if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
|
Chris@76
|
958 continue;
|
Chris@76
|
959
|
Chris@76
|
960 $temp[$row['id_attach']] = $row;
|
Chris@76
|
961
|
Chris@76
|
962 if (!isset($attachments[$row['id_msg']]))
|
Chris@76
|
963 $attachments[$row['id_msg']] = array();
|
Chris@76
|
964 }
|
Chris@76
|
965 $smcFunc['db_free_result']($request);
|
Chris@76
|
966
|
Chris@76
|
967 // This is better than sorting it with the query...
|
Chris@76
|
968 ksort($temp);
|
Chris@76
|
969
|
Chris@76
|
970 foreach ($temp as $row)
|
Chris@76
|
971 $attachments[$row['id_msg']][] = $row;
|
Chris@76
|
972 }
|
Chris@76
|
973
|
Chris@76
|
974 // What? It's not like it *couldn't* be only guests in this topic...
|
Chris@76
|
975 if (!empty($posters))
|
Chris@76
|
976 loadMemberData($posters);
|
Chris@76
|
977 $messages_request = $smcFunc['db_query']('', '
|
Chris@76
|
978 SELECT
|
Chris@76
|
979 id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
|
Chris@76
|
980 smileys_enabled, poster_name, poster_email, approved,
|
Chris@76
|
981 id_msg_modified < {int:new_from} AS is_read
|
Chris@76
|
982 FROM {db_prefix}messages
|
Chris@76
|
983 WHERE id_msg IN ({array_int:message_list})
|
Chris@76
|
984 ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
|
Chris@76
|
985 array(
|
Chris@76
|
986 'message_list' => $messages,
|
Chris@76
|
987 'new_from' => $topicinfo['new_from'],
|
Chris@76
|
988 )
|
Chris@76
|
989 );
|
Chris@76
|
990
|
Chris@76
|
991 // Go to the last message if the given time is beyond the time of the last message.
|
Chris@76
|
992 if (isset($context['start_from']) && $context['start_from'] >= $topicinfo['num_replies'])
|
Chris@76
|
993 $context['start_from'] = $topicinfo['num_replies'];
|
Chris@76
|
994
|
Chris@76
|
995 // Since the anchor information is needed on the top of the page we load these variables beforehand.
|
Chris@76
|
996 $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
|
Chris@76
|
997 if (empty($options['view_newest_first']))
|
Chris@76
|
998 $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
|
Chris@76
|
999 else
|
Chris@76
|
1000 $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $topicinfo['num_replies'] - $context['start_from'];
|
Chris@76
|
1001 }
|
Chris@76
|
1002 else
|
Chris@76
|
1003 {
|
Chris@76
|
1004 $messages_request = false;
|
Chris@76
|
1005 $context['first_message'] = 0;
|
Chris@76
|
1006 $context['first_new_message'] = false;
|
Chris@76
|
1007 }
|
Chris@76
|
1008
|
Chris@76
|
1009 $context['jump_to'] = array(
|
Chris@76
|
1010 'label' => addslashes(un_htmlspecialchars($txt['jump_to'])),
|
Chris@76
|
1011 'board_name' => htmlspecialchars(strtr(strip_tags($board_info['name']), array('&' => '&'))),
|
Chris@76
|
1012 'child_level' => $board_info['child_level'],
|
Chris@76
|
1013 );
|
Chris@76
|
1014
|
Chris@76
|
1015 // Set the callback. (do you REALIZE how much memory all the messages would take?!?)
|
Chris@76
|
1016 $context['get_message'] = 'prepareDisplayContext';
|
Chris@76
|
1017
|
Chris@76
|
1018 // Now set all the wonderful, wonderful permissions... like moderation ones...
|
Chris@76
|
1019 $common_permissions = array(
|
Chris@76
|
1020 'can_approve' => 'approve_posts',
|
Chris@76
|
1021 'can_ban' => 'manage_bans',
|
Chris@76
|
1022 'can_sticky' => 'make_sticky',
|
Chris@76
|
1023 'can_merge' => 'merge_any',
|
Chris@76
|
1024 'can_split' => 'split_any',
|
Chris@76
|
1025 'calendar_post' => 'calendar_post',
|
Chris@76
|
1026 'can_mark_notify' => 'mark_any_notify',
|
Chris@76
|
1027 'can_send_topic' => 'send_topic',
|
Chris@76
|
1028 'can_send_pm' => 'pm_send',
|
Chris@76
|
1029 'can_report_moderator' => 'report_any',
|
Chris@76
|
1030 'can_moderate_forum' => 'moderate_forum',
|
Chris@76
|
1031 'can_issue_warning' => 'issue_warning',
|
Chris@76
|
1032 'can_restore_topic' => 'move_any',
|
Chris@76
|
1033 'can_restore_msg' => 'move_any',
|
Chris@76
|
1034 );
|
Chris@76
|
1035 foreach ($common_permissions as $contextual => $perm)
|
Chris@76
|
1036 $context[$contextual] = allowedTo($perm);
|
Chris@76
|
1037
|
Chris@76
|
1038 // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own.
|
Chris@76
|
1039 $anyown_permissions = array(
|
Chris@76
|
1040 'can_move' => 'move',
|
Chris@76
|
1041 'can_lock' => 'lock',
|
Chris@76
|
1042 'can_delete' => 'remove',
|
Chris@76
|
1043 'can_add_poll' => 'poll_add',
|
Chris@76
|
1044 'can_remove_poll' => 'poll_remove',
|
Chris@76
|
1045 'can_reply' => 'post_reply',
|
Chris@76
|
1046 'can_reply_unapproved' => 'post_unapproved_replies',
|
Chris@76
|
1047 );
|
Chris@76
|
1048 foreach ($anyown_permissions as $contextual => $perm)
|
Chris@76
|
1049 $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
|
Chris@76
|
1050
|
Chris@76
|
1051 // Cleanup all the permissions with extra stuff...
|
Chris@76
|
1052 $context['can_mark_notify'] &= !$context['user']['is_guest'];
|
Chris@76
|
1053 $context['can_sticky'] &= !empty($modSettings['enableStickyTopics']);
|
Chris@76
|
1054 $context['calendar_post'] &= !empty($modSettings['cal_enabled']);
|
Chris@76
|
1055 $context['can_add_poll'] &= $modSettings['pollMode'] == '1' && $topicinfo['id_poll'] <= 0;
|
Chris@76
|
1056 $context['can_remove_poll'] &= $modSettings['pollMode'] == '1' && $topicinfo['id_poll'] > 0;
|
Chris@76
|
1057 $context['can_reply'] &= empty($topicinfo['locked']) || allowedTo('moderate_board');
|
Chris@76
|
1058 $context['can_reply_unapproved'] &= $modSettings['postmod_active'] && (empty($topicinfo['locked']) || allowedTo('moderate_board'));
|
Chris@76
|
1059 $context['can_issue_warning'] &= in_array('w', $context['admin_features']) && $modSettings['warning_settings'][0] == 1;
|
Chris@76
|
1060 // Handle approval flags...
|
Chris@76
|
1061 $context['can_reply_approved'] = $context['can_reply'];
|
Chris@76
|
1062 $context['can_reply'] |= $context['can_reply_unapproved'];
|
Chris@76
|
1063 $context['can_quote'] = $context['can_reply'] && (empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])));
|
Chris@76
|
1064 $context['can_mark_unread'] = !$user_info['is_guest'] && $settings['show_mark_read'];
|
Chris@76
|
1065
|
Chris@76
|
1066 $context['can_send_topic'] = (!$modSettings['postmod_active'] || $topicinfo['approved']) && allowedTo('send_topic');
|
Chris@76
|
1067
|
Chris@76
|
1068 // Start this off for quick moderation - it will be or'd for each post.
|
Chris@76
|
1069 $context['can_remove_post'] = allowedTo('delete_any') || (allowedTo('delete_replies') && $context['user']['started']);
|
Chris@76
|
1070
|
Chris@76
|
1071 // Can restore topic? That's if the topic is in the recycle board and has a previous restore state.
|
Chris@76
|
1072 $context['can_restore_topic'] &= !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board && !empty($topicinfo['id_previous_board']);
|
Chris@76
|
1073 $context['can_restore_msg'] &= !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board && !empty($topicinfo['id_previous_topic']);
|
Chris@76
|
1074
|
Chris@76
|
1075 // Wireless shows a "more" if you can do anything special.
|
Chris@76
|
1076 if (WIRELESS && WIRELESS_PROTOCOL != 'wap')
|
Chris@76
|
1077 {
|
Chris@76
|
1078 $context['wireless_more'] = $context['can_sticky'] || $context['can_lock'] || allowedTo('modify_any');
|
Chris@76
|
1079 $context['wireless_moderate'] = isset($_GET['moderate']) ? ';moderate' : '';
|
Chris@76
|
1080 }
|
Chris@76
|
1081
|
Chris@76
|
1082 // Load up the "double post" sequencing magic.
|
Chris@76
|
1083 if (!empty($options['display_quick_reply']))
|
Chris@76
|
1084 {
|
Chris@76
|
1085 checkSubmitOnce('register');
|
Chris@76
|
1086 $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : '';
|
Chris@76
|
1087 $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : '';
|
Chris@76
|
1088 }
|
Chris@76
|
1089 }
|
Chris@76
|
1090
|
Chris@76
|
1091 // Callback for the message display.
|
Chris@76
|
1092 function prepareDisplayContext($reset = false)
|
Chris@76
|
1093 {
|
Chris@76
|
1094 global $settings, $txt, $modSettings, $scripturl, $options, $user_info, $smcFunc;
|
Chris@76
|
1095 global $memberContext, $context, $messages_request, $topic, $attachments, $topicinfo;
|
Chris@76
|
1096
|
Chris@76
|
1097 static $counter = null;
|
Chris@76
|
1098
|
Chris@76
|
1099 // If the query returned false, bail.
|
Chris@76
|
1100 if ($messages_request == false)
|
Chris@76
|
1101 return false;
|
Chris@76
|
1102
|
Chris@76
|
1103 // Remember which message this is. (ie. reply #83)
|
Chris@76
|
1104 if ($counter === null || $reset)
|
Chris@76
|
1105 $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
|
Chris@76
|
1106
|
Chris@76
|
1107 // Start from the beginning...
|
Chris@76
|
1108 if ($reset)
|
Chris@76
|
1109 return @$smcFunc['db_data_seek']($messages_request, 0);
|
Chris@76
|
1110
|
Chris@76
|
1111 // Attempt to get the next message.
|
Chris@76
|
1112 $message = $smcFunc['db_fetch_assoc']($messages_request);
|
Chris@76
|
1113 if (!$message)
|
Chris@76
|
1114 {
|
Chris@76
|
1115 $smcFunc['db_free_result']($messages_request);
|
Chris@76
|
1116 return false;
|
Chris@76
|
1117 }
|
Chris@76
|
1118
|
Chris@76
|
1119 // $context['icon_sources'] says where each icon should come from - here we set up the ones which will always exist!
|
Chris@76
|
1120 if (empty($context['icon_sources']))
|
Chris@76
|
1121 {
|
Chris@76
|
1122 $stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless', 'clip');
|
Chris@76
|
1123 $context['icon_sources'] = array();
|
Chris@76
|
1124 foreach ($stable_icons as $icon)
|
Chris@76
|
1125 $context['icon_sources'][$icon] = 'images_url';
|
Chris@76
|
1126 }
|
Chris@76
|
1127
|
Chris@76
|
1128 // Message Icon Management... check the images exist.
|
Chris@76
|
1129 if (empty($modSettings['messageIconChecks_disable']))
|
Chris@76
|
1130 {
|
Chris@76
|
1131 // If the current icon isn't known, then we need to do something...
|
Chris@76
|
1132 if (!isset($context['icon_sources'][$message['icon']]))
|
Chris@76
|
1133 $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.gif') ? 'images_url' : 'default_images_url';
|
Chris@76
|
1134 }
|
Chris@76
|
1135 elseif (!isset($context['icon_sources'][$message['icon']]))
|
Chris@76
|
1136 $context['icon_sources'][$message['icon']] = 'images_url';
|
Chris@76
|
1137
|
Chris@76
|
1138 // If you're a lazy bum, you probably didn't give a subject...
|
Chris@76
|
1139 $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
|
Chris@76
|
1140
|
Chris@76
|
1141 // Are you allowed to remove at least a single reply?
|
Chris@76
|
1142 $context['can_remove_post'] |= allowedTo('delete_own') && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()) && $message['id_member'] == $user_info['id'];
|
Chris@76
|
1143
|
Chris@76
|
1144 // If it couldn't load, or the user was a guest.... someday may be done with a guest table.
|
Chris@76
|
1145 if (!loadMemberContext($message['id_member'], true))
|
Chris@76
|
1146 {
|
Chris@76
|
1147 // Notice this information isn't used anywhere else....
|
Chris@76
|
1148 $memberContext[$message['id_member']]['name'] = $message['poster_name'];
|
Chris@76
|
1149 $memberContext[$message['id_member']]['id'] = 0;
|
Chris@76
|
1150 $memberContext[$message['id_member']]['group'] = $txt['guest_title'];
|
Chris@76
|
1151 $memberContext[$message['id_member']]['link'] = $message['poster_name'];
|
Chris@76
|
1152 $memberContext[$message['id_member']]['email'] = $message['poster_email'];
|
Chris@76
|
1153 $memberContext[$message['id_member']]['show_email'] = showEmailAddress(true, 0);
|
Chris@76
|
1154 $memberContext[$message['id_member']]['is_guest'] = true;
|
Chris@76
|
1155 }
|
Chris@76
|
1156 else
|
Chris@76
|
1157 {
|
Chris@76
|
1158 $memberContext[$message['id_member']]['can_view_profile'] = allowedTo('profile_view_any') || ($message['id_member'] == $user_info['id'] && allowedTo('profile_view_own'));
|
Chris@76
|
1159 $memberContext[$message['id_member']]['is_topic_starter'] = $message['id_member'] == $context['topic_starter_id'];
|
Chris@76
|
1160 $memberContext[$message['id_member']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member']]['warning_status'] && ($context['user']['can_mod'] || (!$user_info['is_guest'] && !empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member'] == $user_info['id'])));
|
Chris@76
|
1161 }
|
Chris@76
|
1162
|
Chris@76
|
1163 $memberContext[$message['id_member']]['ip'] = $message['poster_ip'];
|
Chris@76
|
1164
|
Chris@76
|
1165 // Do the censor thang.
|
Chris@76
|
1166 censorText($message['body']);
|
Chris@76
|
1167 censorText($message['subject']);
|
Chris@76
|
1168
|
Chris@76
|
1169 // Run BBC interpreter on the message.
|
Chris@76
|
1170 $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
|
Chris@76
|
1171
|
Chris@76
|
1172 // Compose the memory eat- I mean message array.
|
Chris@76
|
1173 $output = array(
|
Chris@76
|
1174 'attachment' => loadAttachmentContext($message['id_msg']),
|
Chris@76
|
1175 'alternate' => $counter % 2,
|
Chris@76
|
1176 'id' => $message['id_msg'],
|
Chris@76
|
1177 'href' => $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'],
|
Chris@76
|
1178 'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',
|
Chris@76
|
1179 'member' => &$memberContext[$message['id_member']],
|
Chris@76
|
1180 'icon' => $message['icon'],
|
Chris@76
|
1181 'icon_url' => $settings[$context['icon_sources'][$message['icon']]] . '/post/' . $message['icon'] . '.gif',
|
Chris@76
|
1182 'subject' => $message['subject'],
|
Chris@76
|
1183 'time' => timeformat($message['poster_time']),
|
Chris@76
|
1184 'timestamp' => forum_time(true, $message['poster_time']),
|
Chris@76
|
1185 'counter' => $counter,
|
Chris@76
|
1186 'modified' => array(
|
Chris@76
|
1187 'time' => timeformat($message['modified_time']),
|
Chris@76
|
1188 'timestamp' => forum_time(true, $message['modified_time']),
|
Chris@76
|
1189 'name' => $message['modified_name']
|
Chris@76
|
1190 ),
|
Chris@76
|
1191 'body' => $message['body'],
|
Chris@76
|
1192 'new' => empty($message['is_read']),
|
Chris@76
|
1193 'approved' => $message['approved'],
|
Chris@76
|
1194 'first_new' => isset($context['start_from']) && $context['start_from'] == $counter,
|
Chris@76
|
1195 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($message['id_member'], $context['user']['ignoreusers']),
|
Chris@76
|
1196 'can_approve' => !$message['approved'] && $context['can_approve'],
|
Chris@76
|
1197 'can_unapprove' => $message['approved'] && $context['can_approve'],
|
Chris@76
|
1198 'can_modify' => (!$context['is_locked'] || allowedTo('moderate_board')) && (allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || !$message['approved'] || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time()))),
|
Chris@76
|
1199 'can_remove' => allowedTo('delete_any') || (allowedTo('delete_replies') && $context['user']['started']) || (allowedTo('delete_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time())),
|
Chris@76
|
1200 'can_see_ip' => allowedTo('moderate_forum') || ($message['id_member'] == $user_info['id'] && !empty($user_info['id'])),
|
Chris@76
|
1201 );
|
Chris@76
|
1202
|
Chris@76
|
1203 // Is this user the message author?
|
Chris@76
|
1204 $output['is_message_author'] = $message['id_member'] == $user_info['id'];
|
Chris@76
|
1205
|
Chris@76
|
1206 if (empty($options['view_newest_first']))
|
Chris@76
|
1207 $counter++;
|
Chris@76
|
1208 else
|
Chris@76
|
1209 $counter--;
|
Chris@76
|
1210
|
Chris@76
|
1211 return $output;
|
Chris@76
|
1212 }
|
Chris@76
|
1213
|
Chris@76
|
1214 // Download an attachment.
|
Chris@76
|
1215 function Download()
|
Chris@76
|
1216 {
|
Chris@76
|
1217 global $txt, $modSettings, $user_info, $scripturl, $context, $sourcedir, $topic, $smcFunc;
|
Chris@76
|
1218
|
Chris@76
|
1219 // Some defaults that we need.
|
Chris@76
|
1220 $context['character_set'] = empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set'];
|
Chris@76
|
1221 $context['utf8'] = $context['character_set'] === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1);
|
Chris@76
|
1222 $context['no_last_modified'] = true;
|
Chris@76
|
1223
|
Chris@76
|
1224 // Make sure some attachment was requested!
|
Chris@76
|
1225 if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id']))
|
Chris@76
|
1226 fatal_lang_error('no_access', false);
|
Chris@76
|
1227
|
Chris@76
|
1228 $_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id'];
|
Chris@76
|
1229
|
Chris@76
|
1230 if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'avatar')
|
Chris@76
|
1231 {
|
Chris@76
|
1232 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1233 SELECT id_folder, filename, file_hash, fileext, id_attach, attachment_type, mime_type, approved, id_member
|
Chris@76
|
1234 FROM {db_prefix}attachments
|
Chris@76
|
1235 WHERE id_attach = {int:id_attach}
|
Chris@76
|
1236 AND id_member > {int:blank_id_member}
|
Chris@76
|
1237 LIMIT 1',
|
Chris@76
|
1238 array(
|
Chris@76
|
1239 'id_attach' => $_REQUEST['attach'],
|
Chris@76
|
1240 'blank_id_member' => 0,
|
Chris@76
|
1241 )
|
Chris@76
|
1242 );
|
Chris@76
|
1243 $_REQUEST['image'] = true;
|
Chris@76
|
1244 }
|
Chris@76
|
1245 // This is just a regular attachment...
|
Chris@76
|
1246 else
|
Chris@76
|
1247 {
|
Chris@76
|
1248 // This checks only the current board for $board/$topic's permissions.
|
Chris@76
|
1249 isAllowedTo('view_attachments');
|
Chris@76
|
1250
|
Chris@76
|
1251 // Make sure this attachment is on this board.
|
Chris@76
|
1252 // NOTE: We must verify that $topic is the attachment's topic, or else the permission check above is broken.
|
Chris@76
|
1253 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1254 SELECT a.id_folder, a.filename, a.file_hash, a.fileext, a.id_attach, a.attachment_type, a.mime_type, a.approved, m.id_member
|
Chris@76
|
1255 FROM {db_prefix}attachments AS a
|
Chris@76
|
1256 INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg AND m.id_topic = {int:current_topic})
|
Chris@76
|
1257 INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
|
Chris@76
|
1258 WHERE a.id_attach = {int:attach}
|
Chris@76
|
1259 LIMIT 1',
|
Chris@76
|
1260 array(
|
Chris@76
|
1261 'attach' => $_REQUEST['attach'],
|
Chris@76
|
1262 'current_topic' => $topic,
|
Chris@76
|
1263 )
|
Chris@76
|
1264 );
|
Chris@76
|
1265 }
|
Chris@76
|
1266 if ($smcFunc['db_num_rows']($request) == 0)
|
Chris@76
|
1267 fatal_lang_error('no_access', false);
|
Chris@76
|
1268 list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
1269 $smcFunc['db_free_result']($request);
|
Chris@76
|
1270
|
Chris@76
|
1271 // If it isn't yet approved, do they have permission to view it?
|
Chris@76
|
1272 if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3))
|
Chris@76
|
1273 isAllowedTo('approve_posts');
|
Chris@76
|
1274
|
Chris@76
|
1275 // Update the download counter (unless it's a thumbnail).
|
Chris@76
|
1276 if ($attachment_type != 3)
|
Chris@76
|
1277 $smcFunc['db_query']('attach_download_increase', '
|
Chris@76
|
1278 UPDATE LOW_PRIORITY {db_prefix}attachments
|
Chris@76
|
1279 SET downloads = downloads + 1
|
Chris@76
|
1280 WHERE id_attach = {int:id_attach}',
|
Chris@76
|
1281 array(
|
Chris@76
|
1282 'id_attach' => $id_attach,
|
Chris@76
|
1283 )
|
Chris@76
|
1284 );
|
Chris@76
|
1285
|
Chris@76
|
1286 $filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash);
|
Chris@76
|
1287
|
Chris@76
|
1288 // This is done to clear any output that was made before now. (would use ob_clean(), but that's PHP 4.2.0+...)
|
Chris@76
|
1289 ob_end_clean();
|
Chris@76
|
1290 if (!empty($modSettings['enableCompressedOutput']) && @version_compare(PHP_VERSION, '4.2.0') >= 0 && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'pdf', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java')))
|
Chris@76
|
1291 @ob_start('ob_gzhandler');
|
Chris@76
|
1292 else
|
Chris@76
|
1293 {
|
Chris@76
|
1294 ob_start();
|
Chris@76
|
1295 header('Content-Encoding: none');
|
Chris@76
|
1296 }
|
Chris@76
|
1297
|
Chris@76
|
1298 // No point in a nicer message, because this is supposed to be an attachment anyway...
|
Chris@76
|
1299 if (!file_exists($filename))
|
Chris@76
|
1300 {
|
Chris@76
|
1301 loadLanguage('Errors');
|
Chris@76
|
1302
|
Chris@76
|
1303 header('HTTP/1.0 404 ' . $txt['attachment_not_found']);
|
Chris@76
|
1304 header('Content-Type: text/plain; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
|
Chris@76
|
1305
|
Chris@76
|
1306 // We need to die like this *before* we send any anti-caching headers as below.
|
Chris@76
|
1307 die('404 - ' . $txt['attachment_not_found']);
|
Chris@76
|
1308 }
|
Chris@76
|
1309
|
Chris@76
|
1310 // If it hasn't been modified since the last time this attachement was retrieved, there's no need to display it again.
|
Chris@76
|
1311 if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']))
|
Chris@76
|
1312 {
|
Chris@76
|
1313 list($modified_since) = explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
Chris@76
|
1314 if (strtotime($modified_since) >= filemtime($filename))
|
Chris@76
|
1315 {
|
Chris@76
|
1316 ob_end_clean();
|
Chris@76
|
1317
|
Chris@76
|
1318 // Answer the question - no, it hasn't been modified ;).
|
Chris@76
|
1319 header('HTTP/1.1 304 Not Modified');
|
Chris@76
|
1320 exit;
|
Chris@76
|
1321 }
|
Chris@76
|
1322 }
|
Chris@76
|
1323
|
Chris@76
|
1324 // Check whether the ETag was sent back, and cache based on that...
|
Chris@76
|
1325 $eTag = '"' . substr($_REQUEST['attach'] . $real_filename . filemtime($filename), 0, 64) . '"';
|
Chris@76
|
1326 if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'], $eTag) !== false)
|
Chris@76
|
1327 {
|
Chris@76
|
1328 ob_end_clean();
|
Chris@76
|
1329
|
Chris@76
|
1330 header('HTTP/1.1 304 Not Modified');
|
Chris@76
|
1331 exit;
|
Chris@76
|
1332 }
|
Chris@76
|
1333
|
Chris@76
|
1334 // Send the attachment headers.
|
Chris@76
|
1335 header('Pragma: ');
|
Chris@76
|
1336 if (!$context['browser']['is_gecko'])
|
Chris@76
|
1337 header('Content-Transfer-Encoding: binary');
|
Chris@76
|
1338 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
|
Chris@76
|
1339 header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT');
|
Chris@76
|
1340 header('Accept-Ranges: bytes');
|
Chris@76
|
1341 header('Connection: close');
|
Chris@76
|
1342 header('ETag: ' . $eTag);
|
Chris@76
|
1343
|
Chris@76
|
1344 // IE 6 just doesn't play nice. As dirty as this seems, it works.
|
Chris@76
|
1345 if ($context['browser']['is_ie6'] && isset($_REQUEST['image']))
|
Chris@76
|
1346 unset($_REQUEST['image']);
|
Chris@76
|
1347
|
Chris@76
|
1348 // Make sure the mime type warrants an inline display.
|
Chris@76
|
1349 elseif (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0)
|
Chris@76
|
1350 unset($_REQUEST['image']);
|
Chris@76
|
1351
|
Chris@76
|
1352 // Does this have a mime type?
|
Chris@76
|
1353 elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
|
Chris@76
|
1354 header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
|
Chris@76
|
1355
|
Chris@76
|
1356 else
|
Chris@76
|
1357 {
|
Chris@76
|
1358 header('Content-Type: ' . ($context['browser']['is_ie'] || $context['browser']['is_opera'] ? 'application/octetstream' : 'application/octet-stream'));
|
Chris@76
|
1359 if (isset($_REQUEST['image']))
|
Chris@76
|
1360 unset($_REQUEST['image']);
|
Chris@76
|
1361 }
|
Chris@76
|
1362
|
Chris@76
|
1363 // Convert the file to UTF-8, cuz most browsers dig that.
|
Chris@76
|
1364 $utf8name = !$context['utf8'] && function_exists('iconv') ? iconv($context['character_set'], 'UTF-8', $real_filename) : (!$context['utf8'] && function_exists('mb_convert_encoding') ? mb_convert_encoding($real_filename, 'UTF-8', $context['character_set']) : $real_filename);
|
Chris@76
|
1365 $fixchar = create_function('$n', '
|
Chris@76
|
1366 if ($n < 32)
|
Chris@76
|
1367 return \'\';
|
Chris@76
|
1368 elseif ($n < 128)
|
Chris@76
|
1369 return chr($n);
|
Chris@76
|
1370 elseif ($n < 2048)
|
Chris@76
|
1371 return chr(192 | $n >> 6) . chr(128 | $n & 63);
|
Chris@76
|
1372 elseif ($n < 65536)
|
Chris@76
|
1373 return chr(224 | $n >> 12) . chr(128 | $n >> 6 & 63) . chr(128 | $n & 63);
|
Chris@76
|
1374 else
|
Chris@76
|
1375 return chr(240 | $n >> 18) . chr(128 | $n >> 12 & 63) . chr(128 | $n >> 6 & 63) . chr(128 | $n & 63);');
|
Chris@76
|
1376
|
Chris@76
|
1377 $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
|
Chris@76
|
1378
|
Chris@76
|
1379 // Different browsers like different standards...
|
Chris@76
|
1380 if ($context['browser']['is_firefox'])
|
Chris@76
|
1381 header('Content-Disposition: ' . $disposition . '; filename*="UTF-8\'\'' . preg_replace('~&#(\d{3,8});~e', '$fixchar(\'$1\')', $utf8name) . '"');
|
Chris@76
|
1382
|
Chris@76
|
1383 elseif ($context['browser']['is_opera'])
|
Chris@76
|
1384 header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace('~&#(\d{3,8});~e', '$fixchar(\'$1\')', $utf8name) . '"');
|
Chris@76
|
1385
|
Chris@76
|
1386 elseif ($context['browser']['is_ie'])
|
Chris@76
|
1387 header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace('~&#(\d{3,8});~e', '$fixchar(\'$1\')', $utf8name)) . '"');
|
Chris@76
|
1388
|
Chris@76
|
1389 else
|
Chris@76
|
1390 header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
|
Chris@76
|
1391
|
Chris@76
|
1392 // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
|
Chris@76
|
1393 if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
|
Chris@76
|
1394 header('Cache-Control: no-cache');
|
Chris@76
|
1395 else
|
Chris@76
|
1396 header('Cache-Control: max-age=' . (525600 * 60) . ', private');
|
Chris@76
|
1397
|
Chris@76
|
1398 if (empty($modSettings['enableCompressedOutput']) || filesize($filename) > 4194304)
|
Chris@76
|
1399 header('Content-Length: ' . filesize($filename));
|
Chris@76
|
1400
|
Chris@76
|
1401 // Try to buy some time...
|
Chris@76
|
1402 @set_time_limit(600);
|
Chris@76
|
1403
|
Chris@76
|
1404 // Recode line endings for text files, if enabled.
|
Chris@76
|
1405 if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml')))
|
Chris@76
|
1406 {
|
Chris@76
|
1407 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
|
Chris@76
|
1408 $callback = create_function('$buffer', 'return preg_replace(\'~[\r]?\n~\', "\r\n", $buffer);');
|
Chris@76
|
1409 elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
|
Chris@76
|
1410 $callback = create_function('$buffer', 'return preg_replace(\'~[\r]?\n~\', "\r", $buffer);');
|
Chris@76
|
1411 else
|
Chris@76
|
1412 $callback = create_function('$buffer', 'return preg_replace(\'~[\r]?\n~\', "\n", $buffer);');
|
Chris@76
|
1413 }
|
Chris@76
|
1414
|
Chris@76
|
1415 // Since we don't do output compression for files this large...
|
Chris@76
|
1416 if (filesize($filename) > 4194304)
|
Chris@76
|
1417 {
|
Chris@76
|
1418 // Forcibly end any output buffering going on.
|
Chris@76
|
1419 if (function_exists('ob_get_level'))
|
Chris@76
|
1420 {
|
Chris@76
|
1421 while (@ob_get_level() > 0)
|
Chris@76
|
1422 @ob_end_clean();
|
Chris@76
|
1423 }
|
Chris@76
|
1424 else
|
Chris@76
|
1425 {
|
Chris@76
|
1426 @ob_end_clean();
|
Chris@76
|
1427 @ob_end_clean();
|
Chris@76
|
1428 @ob_end_clean();
|
Chris@76
|
1429 }
|
Chris@76
|
1430
|
Chris@76
|
1431 $fp = fopen($filename, 'rb');
|
Chris@76
|
1432 while (!feof($fp))
|
Chris@76
|
1433 {
|
Chris@76
|
1434 if (isset($callback))
|
Chris@76
|
1435 echo $callback(fread($fp, 8192));
|
Chris@76
|
1436 else
|
Chris@76
|
1437 echo fread($fp, 8192);
|
Chris@76
|
1438 flush();
|
Chris@76
|
1439 }
|
Chris@76
|
1440 fclose($fp);
|
Chris@76
|
1441 }
|
Chris@76
|
1442 // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if.
|
Chris@76
|
1443 elseif (isset($callback) || @readfile($filename) == null)
|
Chris@76
|
1444 echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
|
Chris@76
|
1445
|
Chris@76
|
1446 obExit(false);
|
Chris@76
|
1447 }
|
Chris@76
|
1448
|
Chris@76
|
1449 function loadAttachmentContext($id_msg)
|
Chris@76
|
1450 {
|
Chris@76
|
1451 global $attachments, $modSettings, $txt, $scripturl, $topic, $sourcedir, $smcFunc;
|
Chris@76
|
1452
|
Chris@76
|
1453 // Set up the attachment info - based on code by Meriadoc.
|
Chris@76
|
1454 $attachmentData = array();
|
Chris@76
|
1455 $have_unapproved = false;
|
Chris@76
|
1456 if (isset($attachments[$id_msg]) && !empty($modSettings['attachmentEnable']))
|
Chris@76
|
1457 {
|
Chris@76
|
1458 foreach ($attachments[$id_msg] as $i => $attachment)
|
Chris@76
|
1459 {
|
Chris@76
|
1460 $attachmentData[$i] = array(
|
Chris@76
|
1461 'id' => $attachment['id_attach'],
|
Chris@76
|
1462 'name' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($attachment['filename'])),
|
Chris@76
|
1463 'downloads' => $attachment['downloads'],
|
Chris@76
|
1464 'size' => round($attachment['filesize'] / 1024, 2) . ' ' . $txt['kilobyte'],
|
Chris@76
|
1465 'byte_size' => $attachment['filesize'],
|
Chris@76
|
1466 'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_attach'],
|
Chris@76
|
1467 'link' => '<a href="' . $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_attach'] . '">' . htmlspecialchars($attachment['filename']) . '</a>',
|
Chris@76
|
1468 'is_image' => !empty($attachment['width']) && !empty($attachment['height']) && !empty($modSettings['attachmentShowImages']),
|
Chris@76
|
1469 'is_approved' => $attachment['approved'],
|
Chris@76
|
1470 );
|
Chris@76
|
1471
|
Chris@76
|
1472 // If something is unapproved we'll note it so we can sort them.
|
Chris@76
|
1473 if (!$attachment['approved'])
|
Chris@76
|
1474 $have_unapproved = true;
|
Chris@76
|
1475
|
Chris@76
|
1476 if (!$attachmentData[$i]['is_image'])
|
Chris@76
|
1477 continue;
|
Chris@76
|
1478
|
Chris@76
|
1479 $attachmentData[$i]['real_width'] = $attachment['width'];
|
Chris@76
|
1480 $attachmentData[$i]['width'] = $attachment['width'];
|
Chris@76
|
1481 $attachmentData[$i]['real_height'] = $attachment['height'];
|
Chris@76
|
1482 $attachmentData[$i]['height'] = $attachment['height'];
|
Chris@76
|
1483
|
Chris@76
|
1484 // Let's see, do we want thumbs?
|
Chris@76
|
1485 if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachment['width'] > $modSettings['attachmentThumbWidth'] || $attachment['height'] > $modSettings['attachmentThumbHeight']) && strlen($attachment['filename']) < 249)
|
Chris@76
|
1486 {
|
Chris@76
|
1487 // A proper thumb doesn't exist yet? Create one!
|
Chris@76
|
1488 if (empty($attachment['id_thumb']) || $attachment['thumb_width'] > $modSettings['attachmentThumbWidth'] || $attachment['thumb_height'] > $modSettings['attachmentThumbHeight'] || ($attachment['thumb_width'] < $modSettings['attachmentThumbWidth'] && $attachment['thumb_height'] < $modSettings['attachmentThumbHeight']))
|
Chris@76
|
1489 {
|
Chris@76
|
1490 $filename = getAttachmentFilename($attachment['filename'], $attachment['id_attach'], $attachment['id_folder']);
|
Chris@76
|
1491
|
Chris@76
|
1492 require_once($sourcedir . '/Subs-Graphics.php');
|
Chris@76
|
1493 if (createThumbnail($filename, $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight']))
|
Chris@76
|
1494 {
|
Chris@76
|
1495 // So what folder are we putting this image in?
|
Chris@76
|
1496 if (!empty($modSettings['currentAttachmentUploadDir']))
|
Chris@76
|
1497 {
|
Chris@76
|
1498 if (!is_array($modSettings['attachmentUploadDir']))
|
Chris@76
|
1499 $modSettings['attachmentUploadDir'] = @unserialize($modSettings['attachmentUploadDir']);
|
Chris@76
|
1500 $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
|
Chris@76
|
1501 $id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
|
Chris@76
|
1502 }
|
Chris@76
|
1503 else
|
Chris@76
|
1504 {
|
Chris@76
|
1505 $path = $modSettings['attachmentUploadDir'];
|
Chris@76
|
1506 $id_folder_thumb = 1;
|
Chris@76
|
1507 }
|
Chris@76
|
1508
|
Chris@76
|
1509 // Calculate the size of the created thumbnail.
|
Chris@76
|
1510 $size = @getimagesize($filename . '_thumb');
|
Chris@76
|
1511 list ($attachment['thumb_width'], $attachment['thumb_height']) = $size;
|
Chris@76
|
1512 $thumb_size = filesize($filename . '_thumb');
|
Chris@76
|
1513
|
Chris@76
|
1514 // These are the only valid image types for SMF.
|
Chris@76
|
1515 $validImageTypes = array(1 => 'gif', 2 => 'jpeg', 3 => 'png', 5 => 'psd', 6 => 'bmp', 7 => 'tiff', 8 => 'tiff', 9 => 'jpeg', 14 => 'iff');
|
Chris@76
|
1516
|
Chris@76
|
1517 // What about the extension?
|
Chris@76
|
1518 $thumb_ext = isset($validImageTypes[$size[2]]) ? $validImageTypes[$size[2]] : '';
|
Chris@76
|
1519
|
Chris@76
|
1520 // Figure out the mime type.
|
Chris@76
|
1521 if (!empty($size['mime']))
|
Chris@76
|
1522 $thumb_mime = $size['mime'];
|
Chris@76
|
1523 else
|
Chris@76
|
1524 $thumb_mime = 'image/' . $thumb_ext;
|
Chris@76
|
1525
|
Chris@76
|
1526 $thumb_filename = $attachment['filename'] . '_thumb';
|
Chris@76
|
1527 $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
|
Chris@76
|
1528
|
Chris@76
|
1529 // Add this beauty to the database.
|
Chris@76
|
1530 $smcFunc['db_insert']('',
|
Chris@76
|
1531 '{db_prefix}attachments',
|
Chris@76
|
1532 array('id_folder' => 'int', 'id_msg' => 'int', 'attachment_type' => 'int', 'filename' => 'string', 'file_hash' => 'string', 'size' => 'int', 'width' => 'int', 'height' => 'int', 'fileext' => 'string', 'mime_type' => 'string'),
|
Chris@76
|
1533 array($id_folder_thumb, $id_msg, 3, $thumb_filename, $thumb_hash, (int) $thumb_size, (int) $attachment['thumb_width'], (int) $attachment['thumb_height'], $thumb_ext, $thumb_mime),
|
Chris@76
|
1534 array('id_attach')
|
Chris@76
|
1535 );
|
Chris@76
|
1536 $old_id_thumb = $attachment['id_thumb'];
|
Chris@76
|
1537 $attachment['id_thumb'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
|
Chris@76
|
1538 if (!empty($attachment['id_thumb']))
|
Chris@76
|
1539 {
|
Chris@76
|
1540 $smcFunc['db_query']('', '
|
Chris@76
|
1541 UPDATE {db_prefix}attachments
|
Chris@76
|
1542 SET id_thumb = {int:id_thumb}
|
Chris@76
|
1543 WHERE id_attach = {int:id_attach}',
|
Chris@76
|
1544 array(
|
Chris@76
|
1545 'id_thumb' => $attachment['id_thumb'],
|
Chris@76
|
1546 'id_attach' => $attachment['id_attach'],
|
Chris@76
|
1547 )
|
Chris@76
|
1548 );
|
Chris@76
|
1549
|
Chris@76
|
1550 $thumb_realname = getAttachmentFilename($thumb_filename, $attachment['id_thumb'], $id_folder_thumb, false, $thumb_hash);
|
Chris@76
|
1551 rename($filename . '_thumb', $thumb_realname);
|
Chris@76
|
1552
|
Chris@76
|
1553 // Do we need to remove an old thumbnail?
|
Chris@76
|
1554 if (!empty($old_id_thumb))
|
Chris@76
|
1555 {
|
Chris@76
|
1556 require_once($sourcedir . '/ManageAttachments.php');
|
Chris@76
|
1557 removeAttachments(array('id_attach' => $old_id_thumb), '', false, false);
|
Chris@76
|
1558 }
|
Chris@76
|
1559 }
|
Chris@76
|
1560 }
|
Chris@76
|
1561 }
|
Chris@76
|
1562
|
Chris@76
|
1563 // Only adjust dimensions on successful thumbnail creation.
|
Chris@76
|
1564 if (!empty($attachment['thumb_width']) && !empty($attachment['thumb_height']))
|
Chris@76
|
1565 {
|
Chris@76
|
1566 $attachmentData[$i]['width'] = $attachment['thumb_width'];
|
Chris@76
|
1567 $attachmentData[$i]['height'] = $attachment['thumb_height'];
|
Chris@76
|
1568 }
|
Chris@76
|
1569 }
|
Chris@76
|
1570
|
Chris@76
|
1571 if (!empty($attachment['id_thumb']))
|
Chris@76
|
1572 $attachmentData[$i]['thumbnail'] = array(
|
Chris@76
|
1573 'id' => $attachment['id_thumb'],
|
Chris@76
|
1574 'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_thumb'] . ';image',
|
Chris@76
|
1575 );
|
Chris@76
|
1576 $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
|
Chris@76
|
1577
|
Chris@76
|
1578 // If thumbnails are disabled, check the maximum size of the image.
|
Chris@76
|
1579 if (!$attachmentData[$i]['thumbnail']['has_thumb'] && ((!empty($modSettings['max_image_width']) && $attachment['width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachment['height'] > $modSettings['max_image_height'])))
|
Chris@76
|
1580 {
|
Chris@76
|
1581 if (!empty($modSettings['max_image_width']) && (empty($modSettings['max_image_height']) || $attachment['height'] * $modSettings['max_image_width'] / $attachment['width'] <= $modSettings['max_image_height']))
|
Chris@76
|
1582 {
|
Chris@76
|
1583 $attachmentData[$i]['width'] = $modSettings['max_image_width'];
|
Chris@76
|
1584 $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
|
Chris@76
|
1585 }
|
Chris@76
|
1586 elseif (!empty($modSettings['max_image_width']))
|
Chris@76
|
1587 {
|
Chris@76
|
1588 $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
|
Chris@76
|
1589 $attachmentData[$i]['height'] = $modSettings['max_image_height'];
|
Chris@76
|
1590 }
|
Chris@76
|
1591 }
|
Chris@76
|
1592 elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
|
Chris@76
|
1593 {
|
Chris@76
|
1594 // If the image is too large to show inline, make it a popup.
|
Chris@76
|
1595 if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
|
Chris@76
|
1596 $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
|
Chris@76
|
1597 else
|
Chris@76
|
1598 $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
|
Chris@76
|
1599 }
|
Chris@76
|
1600
|
Chris@76
|
1601 if (!$attachmentData[$i]['thumbnail']['has_thumb'])
|
Chris@76
|
1602 $attachmentData[$i]['downloads']++;
|
Chris@76
|
1603 }
|
Chris@76
|
1604 }
|
Chris@76
|
1605
|
Chris@76
|
1606 // Do we need to instigate a sort?
|
Chris@76
|
1607 if ($have_unapproved)
|
Chris@76
|
1608 usort($attachmentData, 'approved_attach_sort');
|
Chris@76
|
1609
|
Chris@76
|
1610 return $attachmentData;
|
Chris@76
|
1611 }
|
Chris@76
|
1612
|
Chris@76
|
1613 // A sort function for putting unapproved attachments first.
|
Chris@76
|
1614 function approved_attach_sort($a, $b)
|
Chris@76
|
1615 {
|
Chris@76
|
1616 if ($a['is_approved'] == $b['is_approved'])
|
Chris@76
|
1617 return 0;
|
Chris@76
|
1618
|
Chris@76
|
1619 return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
|
Chris@76
|
1620 }
|
Chris@76
|
1621
|
Chris@76
|
1622 // In-topic quick moderation.
|
Chris@76
|
1623 function QuickInTopicModeration()
|
Chris@76
|
1624 {
|
Chris@76
|
1625 global $sourcedir, $topic, $board, $user_info, $smcFunc, $modSettings, $context;
|
Chris@76
|
1626
|
Chris@76
|
1627 // Check the session = get or post.
|
Chris@76
|
1628 checkSession('request');
|
Chris@76
|
1629
|
Chris@76
|
1630 require_once($sourcedir . '/RemoveTopic.php');
|
Chris@76
|
1631
|
Chris@76
|
1632 if (empty($_REQUEST['msgs']))
|
Chris@76
|
1633 redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
|
Chris@76
|
1634
|
Chris@76
|
1635 $messages = array();
|
Chris@76
|
1636 foreach ($_REQUEST['msgs'] as $dummy)
|
Chris@76
|
1637 $messages[] = (int) $dummy;
|
Chris@76
|
1638
|
Chris@76
|
1639 // We are restoring messages. We handle this in another place.
|
Chris@76
|
1640 if (isset($_REQUEST['restore_selected']))
|
Chris@76
|
1641 redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
|
Chris@76
|
1642
|
Chris@76
|
1643 // Allowed to delete any message?
|
Chris@76
|
1644 if (allowedTo('delete_any'))
|
Chris@76
|
1645 $allowed_all = true;
|
Chris@76
|
1646 // Allowed to delete replies to their messages?
|
Chris@76
|
1647 elseif (allowedTo('delete_replies'))
|
Chris@76
|
1648 {
|
Chris@76
|
1649 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1650 SELECT id_member_started
|
Chris@76
|
1651 FROM {db_prefix}topics
|
Chris@76
|
1652 WHERE id_topic = {int:current_topic}
|
Chris@76
|
1653 LIMIT 1',
|
Chris@76
|
1654 array(
|
Chris@76
|
1655 'current_topic' => $topic,
|
Chris@76
|
1656 )
|
Chris@76
|
1657 );
|
Chris@76
|
1658 list ($starter) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
1659 $smcFunc['db_free_result']($request);
|
Chris@76
|
1660
|
Chris@76
|
1661 $allowed_all = $starter == $user_info['id'];
|
Chris@76
|
1662 }
|
Chris@76
|
1663 else
|
Chris@76
|
1664 $allowed_all = false;
|
Chris@76
|
1665
|
Chris@76
|
1666 // Make sure they're allowed to delete their own messages, if not any.
|
Chris@76
|
1667 if (!$allowed_all)
|
Chris@76
|
1668 isAllowedTo('delete_own');
|
Chris@76
|
1669
|
Chris@76
|
1670 // Allowed to remove which messages?
|
Chris@76
|
1671 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1672 SELECT id_msg, subject, id_member, poster_time
|
Chris@76
|
1673 FROM {db_prefix}messages
|
Chris@76
|
1674 WHERE id_msg IN ({array_int:message_list})
|
Chris@76
|
1675 AND id_topic = {int:current_topic}' . (!$allowed_all ? '
|
Chris@76
|
1676 AND id_member = {int:current_member}' : '') . '
|
Chris@76
|
1677 LIMIT ' . count($messages),
|
Chris@76
|
1678 array(
|
Chris@76
|
1679 'current_member' => $user_info['id'],
|
Chris@76
|
1680 'current_topic' => $topic,
|
Chris@76
|
1681 'message_list' => $messages,
|
Chris@76
|
1682 )
|
Chris@76
|
1683 );
|
Chris@76
|
1684 $messages = array();
|
Chris@76
|
1685 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
1686 {
|
Chris@76
|
1687 if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
|
Chris@76
|
1688 continue;
|
Chris@76
|
1689
|
Chris@76
|
1690 $messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
|
Chris@76
|
1691 }
|
Chris@76
|
1692 $smcFunc['db_free_result']($request);
|
Chris@76
|
1693
|
Chris@76
|
1694 // Get the first message in the topic - because you can't delete that!
|
Chris@76
|
1695 $request = $smcFunc['db_query']('', '
|
Chris@76
|
1696 SELECT id_first_msg, id_last_msg
|
Chris@76
|
1697 FROM {db_prefix}topics
|
Chris@76
|
1698 WHERE id_topic = {int:current_topic}
|
Chris@76
|
1699 LIMIT 1',
|
Chris@76
|
1700 array(
|
Chris@76
|
1701 'current_topic' => $topic,
|
Chris@76
|
1702 )
|
Chris@76
|
1703 );
|
Chris@76
|
1704 list ($first_message, $last_message) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
1705 $smcFunc['db_free_result']($request);
|
Chris@76
|
1706
|
Chris@76
|
1707 // Delete all the messages we know they can delete. ($messages)
|
Chris@76
|
1708 foreach ($messages as $message => $info)
|
Chris@76
|
1709 {
|
Chris@76
|
1710 // Just skip the first message - if it's not the last.
|
Chris@76
|
1711 if ($message == $first_message && $message != $last_message)
|
Chris@76
|
1712 continue;
|
Chris@76
|
1713 // If the first message is going then don't bother going back to the topic as we're effectively deleting it.
|
Chris@76
|
1714 elseif ($message == $first_message)
|
Chris@76
|
1715 $topicGone = true;
|
Chris@76
|
1716
|
Chris@76
|
1717 removeMessage($message);
|
Chris@76
|
1718
|
Chris@76
|
1719 // Log this moderation action ;).
|
Chris@76
|
1720 if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
|
Chris@76
|
1721 logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
|
Chris@76
|
1722 }
|
Chris@76
|
1723
|
Chris@76
|
1724 redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
|
Chris@76
|
1725 }
|
Chris@76
|
1726
|
Chris@76
|
1727 ?> |