phpBB
Statistics
| Revision:

root / branches / phpBB-3_0_0 / phpBB / viewtopic.php

History | View | Annotate | Download (67.3 kB)

1 2 thefinn
<?php
2 8146 acydburn
/**
3 5114 acydburn
*
4 5114 acydburn
* @package phpBB3
5 5114 acydburn
* @version $Id$
6 8146 acydburn
* @copyright (c) 2005 phpBB Group
7 8146 acydburn
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 5114 acydburn
*
9 5114 acydburn
*/
10 2 thefinn
11 5114 acydburn
/**
12 5883 acydburn
* @ignore
13 5114 acydburn
*/
14 2305 psotfx
define('IN_PHPBB', true);
15 7954 acydburn
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16 4441 psotfx
$phpEx = substr(strrchr(__FILE__, '.'), 1);
17 6002 acydburn
include($phpbb_root_path . 'common.' . $phpEx);
18 5247 acydburn
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
19 6517 acydburn
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
20 2 thefinn
21 3953 psotfx
// Start session management
22 5247 acydburn
$user->session_begin();
23 3953 psotfx
$auth->acl($user->data);
24 3953 psotfx
25 3538 psotfx
// Initial var setup
26 4578 psotfx
$forum_id        = request_var('f', 0);
27 4578 psotfx
$topic_id        = request_var('t', 0);
28 4578 psotfx
$post_id        = request_var('p', 0);
29 5412 davidmj
$voted_id        = request_var('vote_id', array('' => 0));
30 1215 dougk_ff7
31 9712 Kellanved
$voted_id = (sizeof($voted_id) > 1) ? array_unique($voted_id) : $voted_id;
32 9712 Kellanved
33 9712 Kellanved
34 4578 psotfx
$start                = request_var('start', 0);
35 4578 psotfx
$view                = request_var('view', '');
36 5068 acydburn
37 8751 Kellanved
$default_sort_days        = (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0;
38 8751 Kellanved
$default_sort_key        = (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't';
39 8751 Kellanved
$default_sort_dir        = (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a';
40 5068 acydburn
41 8751 Kellanved
$sort_days        = request_var('st', $default_sort_days);
42 8751 Kellanved
$sort_key        = request_var('sk', $default_sort_key);
43 8751 Kellanved
$sort_dir        = request_var('sd', $default_sort_dir);
44 8751 Kellanved
45 4578 psotfx
$update                = request_var('update', false);
46 4441 psotfx
47 9688 Kellanved
$s_can_vote = false;
48 7920 acydburn
/**
49 7920 acydburn
* @todo normalize?
50 7920 acydburn
*/
51 6002 acydburn
$hilit_words        = request_var('hilit', '', true);
52 3538 psotfx
53 3538 psotfx
// Do we have a topic or post id?
54 4004 psotfx
if (!$topic_id && !$post_id)
55 81 thefinn
{
56 3538 psotfx
        trigger_error('NO_TOPIC');
57 81 thefinn
}
58 2 thefinn
59 2995 psotfx
// Find topic id if user requested a newer or older topic
60 4441 psotfx
if ($view && !$post_id)
61 301 thefinn
{
62 5137 acydburn
        if (!$forum_id)
63 5137 acydburn
        {
64 6002 acydburn
                $sql = 'SELECT forum_id
65 6002 acydburn
                        FROM ' . TOPICS_TABLE . "
66 5137 acydburn
                        WHERE topic_id = $topic_id";
67 5137 acydburn
                $result = $db->sql_query($sql);
68 5824 acydburn
                $forum_id = (int) $db->sql_fetchfield('forum_id');
69 5824 acydburn
                $db->sql_freeresult($result);
70 5824 acydburn
71 5824 acydburn
                if (!$forum_id)
72 5137 acydburn
                {
73 5137 acydburn
                        trigger_error('NO_TOPIC');
74 5137 acydburn
                }
75 5137 acydburn
        }
76 5137 acydburn
77 4441 psotfx
        if ($view == 'unread')
78 301 thefinn
        {
79 5272 acydburn
                // Get topic tracking info
80 5272 acydburn
                $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
81 3953 psotfx
82 5272 acydburn
                $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0;
83 5272 acydburn
84 6513 acydburn
                $sql = 'SELECT post_id, topic_id, forum_id
85 6513 acydburn
                        FROM ' . POSTS_TABLE . "
86 6513 acydburn
                        WHERE topic_id = $topic_id
87 6513 acydburn
                                " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1') . "
88 6513 acydburn
                                AND post_time > $topic_last_read
89 9983 Kellanved
                                AND forum_id = $forum_id
90 6513 acydburn
                        ORDER BY post_time ASC";
91 5137 acydburn
                $result = $db->sql_query_limit($sql, 1);
92 5824 acydburn
                $row = $db->sql_fetchrow($result);
93 5824 acydburn
                $db->sql_freeresult($result);
94 3953 psotfx
95 5824 acydburn
                if (!$row)
96 5137 acydburn
                {
97 6513 acydburn
                        $sql = 'SELECT topic_last_post_id as post_id, topic_id, forum_id
98 6513 acydburn
                                FROM ' . TOPICS_TABLE . '
99 6513 acydburn
                                WHERE topic_id = ' . $topic_id;
100 6513 acydburn
                        $result = $db->sql_query($sql);
101 6513 acydburn
                        $row = $db->sql_fetchrow($result);
102 6513 acydburn
                        $db->sql_freeresult($result);
103 6513 acydburn
                }
104 6513 acydburn
105 6513 acydburn
                if (!$row)
106 6513 acydburn
                {
107 5137 acydburn
                        // Setup user environment so we can process lang string
108 5137 acydburn
                        $user->setup('viewtopic');
109 1093 psotfx
110 6513 acydburn
                        trigger_error('NO_TOPIC');
111 5137 acydburn
                }
112 3953 psotfx
113 5272 acydburn
                $post_id = $row['post_id'];
114 5137 acydburn
                $topic_id = $row['topic_id'];
115 1093 psotfx
        }
116 4441 psotfx
        else if ($view == 'next' || $view == 'previous')
117 1093 psotfx
        {
118 4441 psotfx
                $sql_condition = ($view == 'next') ? '>' : '<';
119 4441 psotfx
                $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
120 302 thefinn
121 8023 davidmj
                $sql = 'SELECT forum_id, topic_last_post_time
122 8023 davidmj
                        FROM ' . TOPICS_TABLE . '
123 8023 davidmj
                        WHERE topic_id = ' . $topic_id;
124 8023 davidmj
                $result = $db->sql_query($sql);
125 8023 davidmj
                $row = $db->sql_fetchrow($result);
126 8023 davidmj
                $db->sql_freeresult($result);
127 8023 davidmj
128 5824 acydburn
                if (!$row)
129 566 psotfx
                {
130 5858 acydburn
                        $user->setup('viewtopic');
131 8228 kellanved
                        // OK, the topic doesn't exist. This error message is not helpful, but technically correct.
132 6002 acydburn
                        trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
133 566 psotfx
                }
134 566 psotfx
                else
135 566 psotfx
                {
136 8228 kellanved
                        $sql = 'SELECT topic_id, forum_id
137 8228 kellanved
                                FROM ' . TOPICS_TABLE . '
138 8228 kellanved
                                WHERE forum_id = ' . $row['forum_id'] . "
139 8228 kellanved
                                        AND topic_moved_id = 0
140 8228 kellanved
                                        AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
141 8228 kellanved
                                        " . (($auth->acl_get('m_approve', $row['forum_id'])) ? '' : 'AND topic_approved = 1') . "
142 8228 kellanved
                                ORDER BY topic_last_post_time $sql_ordering";
143 8228 kellanved
                        $result = $db->sql_query_limit($sql, 1);
144 8228 kellanved
                        $row = $db->sql_fetchrow($result);
145 8228 kellanved
                        $db->sql_freeresult($result);
146 6151 naderman
147 8228 kellanved
                        if (!$row)
148 5137 acydburn
                        {
149 8228 kellanved
                                $user->setup('viewtopic');
150 8228 kellanved
                                trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
151 5137 acydburn
                        }
152 8228 kellanved
                        else
153 5137 acydburn
                        {
154 8228 kellanved
                                $topic_id = $row['topic_id'];
155 8228 kellanved
156 8228 kellanved
                                // Check for global announcement correctness?
157 8228 kellanved
                                if (!$row['forum_id'] && !$forum_id)
158 8228 kellanved
                                {
159 8228 kellanved
                                        trigger_error('NO_TOPIC');
160 8228 kellanved
                                }
161 8228 kellanved
                                else if ($row['forum_id'])
162 8228 kellanved
                                {
163 8228 kellanved
                                        $forum_id = $row['forum_id'];
164 8228 kellanved
                                }
165 5137 acydburn
                        }
166 566 psotfx
                }
167 566 psotfx
        }
168 5137 acydburn
169 5137 acydburn
        // Check for global announcement correctness?
170 5390 subblue
        if ((!isset($row) || !$row['forum_id']) && !$forum_id)
171 5137 acydburn
        {
172 5137 acydburn
                trigger_error('NO_TOPIC');
173 5137 acydburn
        }
174 5390 subblue
        else if (isset($row) && $row['forum_id'])
175 5137 acydburn
        {
176 5137 acydburn
                $forum_id = $row['forum_id'];
177 5137 acydburn
        }
178 301 thefinn
}
179 566 psotfx
180 566 psotfx
// This rather complex gaggle of code handles querying for topics but
181 566 psotfx
// also allows for direct linking to a post (and the calculation of which
182 566 psotfx
// page the post is on and the correct display of viewtopic)
183 5885 davidmj
$sql_array = array(
184 5957 acydburn
        'SELECT'        => 't.*, f.*',
185 5471 acydburn
186 8851 acydburn
        'FROM'                => array(FORUMS_TABLE => 'f'),
187 5885 davidmj
);
188 5885 davidmj
189 10509 toonarmy
// Firebird handles two columns of the same name a little differently, this
190 10509 toonarmy
// addresses that by forcing the forum_id to come from the forums table.
191 10509 toonarmy
if ($db->sql_layer === 'firebird')
192 10509 toonarmy
{
193 10509 toonarmy
        $sql_array['SELECT'] = 'f.forum_id AS forum_id, ' . $sql_array['SELECT'];
194 10509 toonarmy
}
195 10509 toonarmy
196 8971 acydburn
// The FROM-Order is quite important here, else t.* columns can not be correctly bound.
197 8851 acydburn
if ($post_id)
198 8851 acydburn
{
199 11363 git-gate
        $sql_array['SELECT'] .= ', p.post_approved, p.post_time, p.post_id';
200 8851 acydburn
        $sql_array['FROM'][POSTS_TABLE] = 'p';
201 8851 acydburn
}
202 8851 acydburn
203 8851 acydburn
// Topics table need to be the last in the chain
204 8851 acydburn
$sql_array['FROM'][TOPICS_TABLE] = 't';
205 8851 acydburn
206 5117 acydburn
if ($user->data['is_registered'])
207 3007 ludovic_arnaud
{
208 5885 davidmj
        $sql_array['SELECT'] .= ', tw.notify_status';
209 6002 acydburn
        $sql_array['LEFT_JOIN'] = array();
210 6002 acydburn
211 6002 acydburn
        $sql_array['LEFT_JOIN'][] = array(
212 5885 davidmj
                'FROM'        => array(TOPICS_WATCH_TABLE => 'tw'),
213 5885 davidmj
                'ON'        => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id'
214 5885 davidmj
        );
215 5272 acydburn
216 5272 acydburn
        if ($config['allow_bookmarks'])
217 5272 acydburn
        {
218 7497 acydburn
                $sql_array['SELECT'] .= ', bm.topic_id as bookmarked';
219 6002 acydburn
                $sql_array['LEFT_JOIN'][] = array(
220 5885 davidmj
                        'FROM'        => array(BOOKMARKS_TABLE => 'bm'),
221 5885 davidmj
                        'ON'        => 'bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id'
222 5885 davidmj
                );
223 5272 acydburn
        }
224 5272 acydburn
225 5272 acydburn
        if ($config['load_db_lastread'])
226 5272 acydburn
        {
227 5885 davidmj
                $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
228 6151 naderman
229 6002 acydburn
                $sql_array['LEFT_JOIN'][] = array(
230 5885 davidmj
                        'FROM'        => array(TOPICS_TRACK_TABLE => 'tt'),
231 5885 davidmj
                        'ON'        => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
232 5885 davidmj
                );
233 6002 acydburn
234 6002 acydburn
                $sql_array['LEFT_JOIN'][] = array(
235 5885 davidmj
                        'FROM'        => array(FORUMS_TRACK_TABLE => 'ft'),
236 5885 davidmj
                        'ON'        => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
237 5885 davidmj
                );
238 5272 acydburn
        }
239 3007 ludovic_arnaud
}
240 3007 ludovic_arnaud
241 5885 davidmj
if (!$post_id)
242 5885 davidmj
{
243 5885 davidmj
        $sql_array['WHERE'] = "t.topic_id = $topic_id";
244 5885 davidmj
}
245 5885 davidmj
else
246 5885 davidmj
{
247 9983 Kellanved
        $sql_array['WHERE'] = "p.post_id = $post_id AND t.topic_id = p.topic_id";
248 5885 davidmj
}
249 5854 davidmj
250 6135 acydburn
$sql_array['WHERE'] .= ' AND (f.forum_id = t.forum_id';
251 6135 acydburn
252 6135 acydburn
if (!$forum_id)
253 6135 acydburn
{
254 6135 acydburn
        // If it is a global announcement make sure to set the forum id to a postable forum
255 6151 naderman
        $sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . '
256 6135 acydburn
                AND f.forum_type = ' . FORUM_POST . ')';
257 6135 acydburn
}
258 6135 acydburn
else
259 6135 acydburn
{
260 6135 acydburn
        $sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . "
261 6135 acydburn
                AND f.forum_id = $forum_id)";
262 6135 acydburn
}
263 6135 acydburn
264 6135 acydburn
$sql_array['WHERE'] .= ')';
265 5885 davidmj
266 3567 psotfx
// Join to forum table on topic forum_id unless topic forum_id is zero
267 3567 psotfx
// whereupon we join on the forum_id passed as a parameter ... this
268 3567 psotfx
// is done so navigation, forum name, etc. remain consistent with where
269 3567 psotfx
// user clicked to view a global topic
270 5885 davidmj
$sql = $db->sql_build_query('SELECT', $sql_array);
271 2673 psotfx
$result = $db->sql_query($sql);
272 6002 acydburn
$topic_data = $db->sql_fetchrow($result);
273 6002 acydburn
$db->sql_freeresult($result);
274 355 psotfx
275 9983 Kellanved
// link to unapproved post or incorrect link
276 6002 acydburn
if (!$topic_data)
277 81 thefinn
{
278 4679 acydburn
        // If post_id was submitted, we try at least to display the topic as a last resort...
279 9431 acydburn
        if ($post_id && $topic_id)
280 4679 acydburn
        {
281 9431 acydburn
                redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id" . (($forum_id) ? "&amp;f=$forum_id" : '')));
282 4679 acydburn
        }
283 5858 acydburn
284 3538 psotfx
        trigger_error('NO_TOPIC');
285 81 thefinn
}
286 566 psotfx
287 9983 Kellanved
$forum_id = (int) $topic_data['forum_id'];
288 5906 davidmj
// This is for determining where we are (page)
289 5906 davidmj
if ($post_id)
290 5906 davidmj
{
291 9983 Kellanved
        // are we where we are supposed to be?
292 9985 Kellanved
        if (!$topic_data['post_approved'] && !$auth->acl_get('m_approve', $topic_data['forum_id']))
293 9983 Kellanved
        {
294 9983 Kellanved
                // If post_id was submitted, we try at least to display the topic as a last resort...
295 9985 Kellanved
                if ($topic_id)
296 9983 Kellanved
                {
297 9983 Kellanved
                        redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id" . (($forum_id) ? "&amp;f=$forum_id" : '')));
298 9983 Kellanved
                }
299 9983 Kellanved
300 9983 Kellanved
                trigger_error('NO_TOPIC');
301 9983 Kellanved
        }
302 6411 acydburn
        if ($post_id == $topic_data['topic_first_post_id'] || $post_id == $topic_data['topic_last_post_id'])
303 6411 acydburn
        {
304 6411 acydburn
                $check_sort = ($post_id == $topic_data['topic_first_post_id']) ? 'd' : 'a';
305 6002 acydburn
306 6411 acydburn
                if ($sort_dir == $check_sort)
307 6411 acydburn
                {
308 7447 acydburn
                        $topic_data['prev_posts'] = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
309 6411 acydburn
                }
310 6411 acydburn
                else
311 6411 acydburn
                {
312 7447 acydburn
                        $topic_data['prev_posts'] = 0;
313 6411 acydburn
                }
314 6411 acydburn
        }
315 6411 acydburn
        else
316 6411 acydburn
        {
317 11335 git-gate
                $sql = 'SELECT COUNT(p.post_id) AS prev_posts
318 11335 git-gate
                        FROM ' . POSTS_TABLE . " p
319 11335 git-gate
                        WHERE p.topic_id = {$topic_data['topic_id']}
320 11363 git-gate
                                " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '');
321 6411 acydburn
322 11363 git-gate
                if ($sort_dir == 'd')
323 11363 git-gate
                {
324 11363 git-gate
                        $sql .= " AND (p.post_time > {$topic_data['post_time']} OR (p.post_time = {$topic_data['post_time']} AND p.post_id >= {$topic_data['post_id']}))";
325 11363 git-gate
                }
326 11363 git-gate
                else
327 11363 git-gate
                {
328 11363 git-gate
                        $sql .= " AND (p.post_time < {$topic_data['post_time']} OR (p.post_time = {$topic_data['post_time']} AND p.post_id <= {$topic_data['post_id']}))";
329 11363 git-gate
                }
330 11363 git-gate
331 6411 acydburn
                $result = $db->sql_query($sql);
332 6411 acydburn
                $row = $db->sql_fetchrow($result);
333 6411 acydburn
                $db->sql_freeresult($result);
334 6411 acydburn
335 7447 acydburn
                $topic_data['prev_posts'] = $row['prev_posts'] - 1;
336 6411 acydburn
        }
337 5906 davidmj
}
338 5906 davidmj
339 9984 Kellanved
$topic_id = (int) $topic_data['topic_id'];
340 5027 acydburn
//
341 5272 acydburn
$topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
342 4925 acydburn
343 4577 acydburn
// Check sticky/announcement time limit
344 5272 acydburn
if (($topic_data['topic_type'] == POST_STICKY || $topic_data['topic_type'] == POST_ANNOUNCE) && $topic_data['topic_time_limit'] && ($topic_data['topic_time'] + $topic_data['topic_time_limit']) < time())
345 4577 acydburn
{
346 4947 psotfx
        $sql = 'UPDATE ' . TOPICS_TABLE . '
347 4577 acydburn
                SET topic_type = ' . POST_NORMAL . ', topic_time_limit = 0
348 4577 acydburn
                WHERE topic_id = ' . $topic_id;
349 4577 acydburn
        $db->sql_query($sql);
350 5027 acydburn
351 5272 acydburn
        $topic_data['topic_type'] = POST_NORMAL;
352 5272 acydburn
        $topic_data['topic_time_limit'] = 0;
353 4577 acydburn
}
354 4577 acydburn
355 3953 psotfx
// Setup look and feel
356 5272 acydburn
$user->setup('viewtopic', $topic_data['forum_style']);
357 3869 psotfx
358 5272 acydburn
if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id))
359 3969 psotfx
{
360 4204 psotfx
        trigger_error('NO_TOPIC');
361 3969 psotfx
}
362 3969 psotfx
363 377 psotfx
// Start auth check
364 3712 psotfx
if (!$auth->acl_get('f_read', $forum_id))
365 377 psotfx
{
366 3650 psotfx
        if ($user->data['user_id'] != ANONYMOUS)
367 2079 psotfx
        {
368 6002 acydburn
                trigger_error('SORRY_AUTH_READ');
369 2079 psotfx
        }
370 421 thefinn
371 4970 psotfx
        login_box('', $user->lang['LOGIN_VIEWFORUM']);
372 377 psotfx
}
373 377 psotfx
374 4204 psotfx
// Forum is passworded ... check whether access has been granted to this
375 4204 psotfx
// user this session, if not show login box
376 5272 acydburn
if ($topic_data['forum_password'])
377 4167 psotfx
{
378 4204 psotfx
        login_forum_box($topic_data);
379 4167 psotfx
}
380 4167 psotfx
381 4912 acydburn
// Redirect to login or to the correct post upon emailed notification links
382 4912 acydburn
if (isset($_GET['e']))
383 4577 acydburn
{
384 5078 psotfx
        $jump_to = request_var('e', 0);
385 5078 psotfx
386 6015 acydburn
        $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
387 4915 acydburn
388 4912 acydburn
        if ($user->data['user_id'] == ANONYMOUS)
389 4912 acydburn
        {
390 6002 acydburn
                login_box($redirect_url . "&amp;p=$post_id&amp;e=$jump_to", $user->lang['LOGIN_NOTIFY_TOPIC']);
391 4912 acydburn
        }
392 5078 psotfx
393 5078 psotfx
        if ($jump_to > 0)
394 4912 acydburn
        {
395 4912 acydburn
                // We direct the already logged in user to the correct post...
396 6015 acydburn
                redirect($redirect_url . ((!$post_id) ? "&amp;p=$jump_to" : "&amp;p=$post_id") . "#p$jump_to");
397 4912 acydburn
        }
398 4577 acydburn
}
399 4577 acydburn
400 3538 psotfx
// What is start equal to?
401 5272 acydburn
if ($post_id)
402 2079 psotfx
{
403 7447 acydburn
        $start = floor(($topic_data['prev_posts']) / $config['posts_per_page']) * $config['posts_per_page'];
404 2079 psotfx
}
405 2079 psotfx
406 5272 acydburn
// Get topic tracking info
407 5272 acydburn
if (!isset($topic_tracking_info))
408 5272 acydburn
{
409 6256 acydburn
        $topic_tracking_info = array();
410 6256 acydburn
411 5272 acydburn
        // Get topic tracking info
412 5272 acydburn
        if ($config['load_db_lastread'] && $user->data['is_registered'])
413 5272 acydburn
        {
414 5272 acydburn
                $tmp_topic_data = array($topic_id => $topic_data);
415 5272 acydburn
                $topic_tracking_info = get_topic_tracking($forum_id, $topic_id, $tmp_topic_data, array($forum_id => $topic_data['forum_mark_time']));
416 5272 acydburn
                unset($tmp_topic_data);
417 5272 acydburn
        }
418 6256 acydburn
        else if ($config['load_anon_lastread'] || $user->data['is_registered'])
419 5272 acydburn
        {
420 5272 acydburn
                $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
421 5272 acydburn
        }
422 5272 acydburn
}
423 5272 acydburn
424 2673 psotfx
// Post ordering options
425 5705 naderman
$limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
426 3538 psotfx
427 3286 psotfx
$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
428 9523 Kellanved
$sort_by_sql = array('a' => array('u.username_clean', 'p.post_id'), 't' => 'p.post_time', 's' => array('p.post_subject', 'p.post_id'));
429 9523 Kellanved
$join_user_sql = array('a' => true, 't' => false, 's' => false);
430 862 psotfx
431 3961 psotfx
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
432 3538 psotfx
433 8751 Kellanved
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
434 8751 Kellanved
435 3566 psotfx
// Obtain correct post count and ordering SQL if user has
436 3566 psotfx
// requested anything different
437 3561 ludovic_arnaud
if ($sort_days)
438 2673 psotfx
{
439 3561 ludovic_arnaud
        $min_post_time = time() - ($sort_days * 86400);
440 2110 psotfx
441 3561 ludovic_arnaud
        $sql = 'SELECT COUNT(post_id) AS num_posts
442 3561 ludovic_arnaud
                FROM ' . POSTS_TABLE . "
443 3561 ludovic_arnaud
                WHERE topic_id = $topic_id
444 3561 ludovic_arnaud
                        AND post_time >= $min_post_time
445 5025 acydburn
                " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1');
446 3561 ludovic_arnaud
        $result = $db->sql_query($sql);
447 6002 acydburn
        $total_posts = (int) $db->sql_fetchfield('num_posts');
448 6002 acydburn
        $db->sql_freeresult($result);
449 862 psotfx
450 6002 acydburn
        $limit_posts_time = "AND p.post_time >= $min_post_time ";
451 6002 acydburn
452 4031 psotfx
        if (isset($_POST['sort']))
453 4031 psotfx
        {
454 4031 psotfx
                $start = 0;
455 4031 psotfx
        }
456 862 psotfx
}
457 3567 psotfx
else
458 3567 psotfx
{
459 3567 psotfx
        $total_posts = $topic_replies + 1;
460 3567 psotfx
        $limit_posts_time = '';
461 3567 psotfx
}
462 3561 ludovic_arnaud
463 4912 acydburn
// Was a highlight request part of the URI?
464 4912 acydburn
$highlight_match = $highlight = '';
465 4912 acydburn
if ($hilit_words)
466 4522 psotfx
{
467 4912 acydburn
        foreach (explode(' ', trim($hilit_words)) as $word)
468 4912 acydburn
        {
469 4912 acydburn
                if (trim($word))
470 4912 acydburn
                {
471 7559 naderman
                        $word = str_replace('\*', '\w+?', preg_quote($word, '#'));
472 7559 naderman
                        $word = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $word);
473 7559 naderman
                        $highlight_match .= (($highlight_match != '') ? '|' : '') . $word;
474 4912 acydburn
                }
475 4912 acydburn
        }
476 4912 acydburn
477 5034 acydburn
        $highlight = urlencode($hilit_words);
478 4522 psotfx
}
479 862 psotfx
480 6165 acydburn
// Make sure $start is set to the last page if it exceeds the amount
481 9022 toonarmy
if ($start < 0 || $start >= $total_posts)
482 6165 acydburn
{
483 6165 acydburn
        $start = ($start < 0) ? 0 : floor(($total_posts - 1) / $config['posts_per_page']) * $config['posts_per_page'];
484 6165 acydburn
}
485 6165 acydburn
486 4912 acydburn
// General Viewtopic URL for return links
487 10597 git-gate
$viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start") . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($highlight_match) ? "&amp;hilit=$highlight" : ''));
488 4912 acydburn
489 4522 psotfx
// Are we watching this topic?
490 8350 acydburn
$s_watching_topic = array(
491 8350 acydburn
        'link'                        => '',
492 8350 acydburn
        'title'                        => '',
493 8350 acydburn
        'is_watching'        => false,
494 8350 acydburn
);
495 7736 acydburn
496 11516 git-gate
if (($config['email_enable'] || $config['jab_enable']) && $config['allow_topic_notify'])
497 4522 psotfx
{
498 11516 git-gate
        $notify_status = (isset($topic_data['notify_status'])) ? $topic_data['notify_status'] : null;
499 11516 git-gate
        watch_topic_forum('topic', $s_watching_topic, $user->data['user_id'], $forum_id, $topic_id, $notify_status, $start, $topic_data['topic_title']);
500 8595 acydburn
501 8595 acydburn
        // Reset forum notification if forum notify is set
502 8595 acydburn
        if ($config['allow_forum_notify'] && $auth->acl_get('f_subscribe', $forum_id))
503 8595 acydburn
        {
504 8595 acydburn
                $s_watching_forum = $s_watching_topic;
505 8595 acydburn
                watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0);
506 8595 acydburn
        }
507 4522 psotfx
}
508 4522 psotfx
509 4912 acydburn
// Bookmarks
510 5117 acydburn
if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('bookmark', 0))
511 4912 acydburn
{
512 8944 acydburn
        if (check_link_hash(request_var('hash', ''), "topic_$topic_id"))
513 4912 acydburn
        {
514 8775 Kellanved
                if (!$topic_data['bookmarked'])
515 8775 Kellanved
                {
516 8775 Kellanved
                        $sql = 'INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
517 8775 Kellanved
                                'user_id'        => $user->data['user_id'],
518 8775 Kellanved
                                'topic_id'        => $topic_id,
519 8775 Kellanved
                        ));
520 8775 Kellanved
                        $db->sql_query($sql);
521 8775 Kellanved
                }
522 8775 Kellanved
                else
523 8775 Kellanved
                {
524 8775 Kellanved
                        $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . "
525 8775 Kellanved
                                WHERE user_id = {$user->data['user_id']}
526 8775 Kellanved
                                        AND topic_id = $topic_id";
527 8775 Kellanved
                        $db->sql_query($sql);
528 8775 Kellanved
                }
529 8775 Kellanved
                $message = (($topic_data['bookmarked']) ? $user->lang['BOOKMARK_REMOVED'] : $user->lang['BOOKMARK_ADDED']) . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>');
530 4912 acydburn
        }
531 4912 acydburn
        else
532 4912 acydburn
        {
533 8775 Kellanved
                $message = $user->lang['BOOKMARK_ERR'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>');
534 4912 acydburn
        }
535 4912 acydburn
        meta_refresh(3, $viewtopic_url);
536 5078 psotfx
537 4912 acydburn
        trigger_error($message);
538 4912 acydburn
}
539 4912 acydburn
540 4150 psotfx
// Grab ranks
541 6572 acydburn
$ranks = $cache->obtain_ranks();
542 81 thefinn
543 3357 psotfx
// Grab icons
544 6572 acydburn
$icons = $cache->obtain_icons();
545 2673 psotfx
546 4912 acydburn
// Grab extensions
547 4912 acydburn
$extensions = array();
548 5272 acydburn
if ($topic_data['topic_attachment'])
549 1830 psotfx
{
550 6816 acydburn
        $extensions = $cache->obtain_attach_extensions($forum_id);
551 1830 psotfx
}
552 1830 psotfx
553 3538 psotfx
// Forum rules listing
554 2673 psotfx
$s_forum_rules = '';
555 5765 acydburn
gen_forum_auth_level('topic', $forum_id, $topic_data['forum_status']);
556 1452 bartvb
557 3538 psotfx
// Quick mod tools
558 6149 acydburn
$allow_change_type = ($auth->acl_get('m_', $forum_id) || ($user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'])) ? true : false;
559 5986 naderman
560 2708 psotfx
$topic_mod = '';
561 6317 acydburn
$topic_mod .= ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'] && $topic_data['topic_status'] == ITEM_UNLOCKED)) ? (($topic_data['topic_status'] == ITEM_UNLOCKED) ? '<option value="lock">' . $user->lang['LOCK_TOPIC'] . '</option>' : '<option value="unlock">' . $user->lang['UNLOCK_TOPIC'] . '</option>') : '';
562 3876 ludovic_arnaud
$topic_mod .= ($auth->acl_get('m_delete', $forum_id)) ? '<option value="delete_topic">' . $user->lang['DELETE_TOPIC'] . '</option>' : '';
563 6894 acydburn
$topic_mod .= ($auth->acl_get('m_move', $forum_id) && $topic_data['topic_status'] != ITEM_MOVED) ? '<option value="move">' . $user->lang['MOVE_TOPIC'] . '</option>' : '';
564 3712 psotfx
$topic_mod .= ($auth->acl_get('m_split', $forum_id)) ? '<option value="split">' . $user->lang['SPLIT_TOPIC'] . '</option>' : '';
565 7261 naderman
$topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge">' . $user->lang['MERGE_POSTS'] . '</option>' : '';
566 7261 naderman
$topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge_topic">' . $user->lang['MERGE_TOPIC'] . '</option>' : '';
567 5779 naderman
$topic_mod .= ($auth->acl_get('m_move', $forum_id)) ? '<option value="fork">' . $user->lang['FORK_TOPIC'] . '</option>' : '';
568 6351 acydburn
$topic_mod .= ($allow_change_type && $auth->acl_gets('f_sticky', 'f_announce', $forum_id) && $topic_data['topic_type'] != POST_NORMAL) ? '<option value="make_normal">' . $user->lang['MAKE_NORMAL'] . '</option>' : '';
569 5986 naderman
$topic_mod .= ($allow_change_type && $auth->acl_get('f_sticky', $forum_id) && $topic_data['topic_type'] != POST_STICKY) ? '<option value="make_sticky">' . $user->lang['MAKE_STICKY'] . '</option>' : '';
570 5986 naderman
$topic_mod .= ($allow_change_type && $auth->acl_get('f_announce', $forum_id) && $topic_data['topic_type'] != POST_ANNOUNCE) ? '<option value="make_announce">' . $user->lang['MAKE_ANNOUNCE'] . '</option>' : '';
571 5986 naderman
$topic_mod .= ($allow_change_type && $auth->acl_get('f_announce', $forum_id) && $topic_data['topic_type'] != POST_GLOBAL) ? '<option value="make_global">' . $user->lang['MAKE_GLOBAL'] . '</option>' : '';
572 5460 grahamje
$topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="topic_logs">' . $user->lang['VIEW_TOPIC_LOGS'] . '</option>' : '';
573 1452 bartvb
574 2673 psotfx
// If we've got a hightlight set pass it on to pagination.
575 8751 Kellanved
$pagination = generate_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($highlight_match) ? "&amp;hilit=$highlight" : '')), $total_posts, $config['posts_per_page'], $start);
576 2673 psotfx
577 3359 ludovic_arnaud
// Navigation links
578 3359 ludovic_arnaud
generate_forum_nav($topic_data);
579 3347 psotfx
580 4903 acydburn
// Forum Rules
581 4903 acydburn
generate_forum_rules($topic_data);
582 4903 acydburn
583 3063 psotfx
// Moderators
584 3063 psotfx
$forum_moderators = array();
585 9640 acydburn
if ($config['load_moderators'])
586 9640 acydburn
{
587 9640 acydburn
        get_moderators($forum_moderators, $forum_id);
588 9640 acydburn
}
589 3063 psotfx
590 3347 psotfx
// This is only used for print view so ...
591 5272 acydburn
$server_path = (!$view) ? $phpbb_root_path : generate_board_url() . '/';
592 3071 psotfx
593 3953 psotfx
// Replace naughty words in title
594 5272 acydburn
$topic_data['topic_title'] = censor_text($topic_data['topic_title']);
595 3953 psotfx
596 11191 git-gate
$s_search_hidden_fields = array(
597 11191 git-gate
        't' => $topic_id,
598 11191 git-gate
        'sf' => 'msgonly',
599 11191 git-gate
);
600 11191 git-gate
if ($_SID)
601 11191 git-gate
{
602 11191 git-gate
        $s_search_hidden_fields['sid'] = $_SID;
603 11191 git-gate
}
604 11191 git-gate
605 11619 git-gate
if (!empty($_EXTRA_URL))
606 11619 git-gate
{
607 11619 git-gate
        foreach ($_EXTRA_URL as $url_param)
608 11619 git-gate
        {
609 11619 git-gate
                $url_param = explode('=', $url_param, 2);
610 11682 git-gate
                $s_search_hidden_fields[$url_param[0]] = $url_param[1];
611 11619 git-gate
        }
612 11619 git-gate
}
613 11619 git-gate
614 1851 psotfx
// Send vars to template
615 355 psotfx
$template->assign_vars(array(
616 2972 psotfx
        'FORUM_ID'                 => $forum_id,
617 5272 acydburn
        'FORUM_NAME'         => $topic_data['forum_name'],
618 6188 davidmj
        'FORUM_DESC'        => generate_text_for_display($topic_data['forum_desc'], $topic_data['forum_desc_uid'], $topic_data['forum_desc_bitfield'], $topic_data['forum_desc_options']),
619 4870 acydburn
        'TOPIC_ID'                 => $topic_id,
620 5272 acydburn
        'TOPIC_TITLE'         => $topic_data['topic_title'],
621 7322 acydburn
        'TOPIC_POSTER'        => $topic_data['topic_poster'],
622 7322 acydburn
623 7322 acydburn
        'TOPIC_AUTHOR_FULL'                => get_username_string('full', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
624 7322 acydburn
        'TOPIC_AUTHOR_COLOUR'        => get_username_string('colour', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
625 7322 acydburn
        'TOPIC_AUTHOR'                        => get_username_string('username', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
626 7322 acydburn
627 4167 psotfx
        'PAGINATION'         => $pagination,
628 4167 psotfx
        'PAGE_NUMBER'         => on_page($total_posts, $config['posts_per_page'], $start),
629 4947 psotfx
        'TOTAL_POSTS'        => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts),
630 10597 git-gate
        'U_MCP'                 => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=topic_view&amp;f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start") . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : ''), true, $user->session_id) : '',
631 4892 acydburn
        'MODERATORS'        => (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '',
632 770 psotfx
633 6237 acydburn
        'POST_IMG'                         => ($topic_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'FORUM_LOCKED') : $user->img('button_topic_new', 'POST_NEW_TOPIC'),
634 6237 acydburn
        'QUOTE_IMG'                 => $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'),
635 6237 acydburn
        'REPLY_IMG'                        => ($topic_data['forum_status'] == ITEM_LOCKED || $topic_data['topic_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'TOPIC_LOCKED') : $user->img('button_topic_reply', 'REPLY_TO_TOPIC'),
636 6237 acydburn
        'EDIT_IMG'                         => $user->img('icon_post_edit', 'EDIT_POST'),
637 6237 acydburn
        'DELETE_IMG'                 => $user->img('icon_post_delete', 'DELETE_POST'),
638 6237 acydburn
        'INFO_IMG'                         => $user->img('icon_post_info', 'VIEW_INFO'),
639 6237 acydburn
        'PROFILE_IMG'                => $user->img('icon_user_profile', 'READ_PROFILE'),
640 6237 acydburn
        'SEARCH_IMG'                 => $user->img('icon_user_search', 'SEARCH_USER_POSTS'),
641 6237 acydburn
        'PM_IMG'                         => $user->img('icon_contact_pm', 'SEND_PRIVATE_MESSAGE'),
642 6237 acydburn
        'EMAIL_IMG'                 => $user->img('icon_contact_email', 'SEND_EMAIL'),
643 6237 acydburn
        'WWW_IMG'                         => $user->img('icon_contact_www', 'VISIT_WEBSITE'),
644 6237 acydburn
        'ICQ_IMG'                         => $user->img('icon_contact_icq', 'ICQ'),
645 6237 acydburn
        'AIM_IMG'                         => $user->img('icon_contact_aim', 'AIM'),
646 6237 acydburn
        'MSN_IMG'                         => $user->img('icon_contact_msnm', 'MSNM'),
647 6237 acydburn
        'YIM_IMG'                         => $user->img('icon_contact_yahoo', 'YIM'),
648 6237 acydburn
        'JABBER_IMG'                => $user->img('icon_contact_jabber', 'JABBER') ,
649 6237 acydburn
        'REPORT_IMG'                => $user->img('icon_post_report', 'REPORT_POST'),
650 6237 acydburn
        'REPORTED_IMG'                => $user->img('icon_topic_reported', 'POST_REPORTED'),
651 6237 acydburn
        'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
652 6237 acydburn
        'WARN_IMG'                        => $user->img('icon_user_warn', 'WARN_USER'),
653 3640 ludovic_arnaud
654 9846 rxu
        'S_IS_LOCKED'                        => ($topic_data['topic_status'] == ITEM_UNLOCKED && $topic_data['forum_status'] == ITEM_UNLOCKED) ? false : true,
655 3538 psotfx
        'S_SELECT_SORT_DIR'         => $s_sort_dir,
656 3538 psotfx
        'S_SELECT_SORT_KEY'         => $s_sort_key,
657 3538 psotfx
        'S_SELECT_SORT_DAYS'         => $s_limit_days,
658 6199 grahamje
        'S_SINGLE_MODERATOR'        => (!empty($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id]) > 1) ? false : true,
659 10597 git-gate
        'S_TOPIC_ACTION'                 => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start")),
660 8310 acydburn
        'S_TOPIC_MOD'                         => ($topic_mod != '') ? '<select name="action" id="quick-mod-select">' . $topic_mod . '</select>' : '',
661 10597 git-gate
        'S_MOD_ACTION'                         => append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start") . "&amp;quickmod=1&amp;redirect=" . urlencode(str_replace('&amp;', '&', $viewtopic_url)), true, $user->session_id),
662 3600 ludovic_arnaud
663 8205 acydburn
        'S_VIEWTOPIC'                        => true,
664 7361 naderman
        'S_DISPLAY_SEARCHBOX'        => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
665 11191 git-gate
        'S_SEARCHBOX_ACTION'        => append_sid("{$phpbb_root_path}search.$phpEx"),
666 11254 git-gate
        'S_SEARCH_LOCAL_HIDDEN_FIELDS'        => build_hidden_fields($s_search_hidden_fields),
667 659 psotfx
668 7884 acydburn
        'S_DISPLAY_POST_INFO'        => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
669 7884 acydburn
        'S_DISPLAY_REPLY_INFO'        => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
670 9965 acydburn
        'S_ENABLE_FEEDS_TOPIC'        => ($config['feed_topic'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $topic_data['forum_options'])) ? true : false,
671 7884 acydburn
672 4473 psotfx
        'U_TOPIC'                                => "{$server_path}viewtopic.$phpEx?f=$forum_id&amp;t=$topic_id",
673 3071 psotfx
        'U_FORUM'                                => $server_path,
674 4912 acydburn
        'U_VIEW_TOPIC'                         => $viewtopic_url,
675 6015 acydburn
        'U_VIEW_FORUM'                         => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
676 6015 acydburn
        'U_VIEW_OLDER_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=previous"),
677 6015 acydburn
        'U_VIEW_NEWER_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=next"),
678 4912 acydburn
        'U_PRINT_TOPIC'                        => ($auth->acl_get('f_print', $forum_id)) ? $viewtopic_url . '&amp;view=print' : '',
679 6015 acydburn
        'U_EMAIL_TOPIC'                        => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;t=$topic_id") : '',
680 3747 psotfx
681 4947 psotfx
        'U_WATCH_TOPIC'                 => $s_watching_topic['link'],
682 4947 psotfx
        'L_WATCH_TOPIC'                 => $s_watching_topic['title'],
683 7736 acydburn
        'S_WATCHING_TOPIC'                => $s_watching_topic['is_watching'],
684 4892 acydburn
685 8775 Kellanved
        'U_BOOKMARK_TOPIC'                => ($user->data['is_registered'] && $config['allow_bookmarks']) ? $viewtopic_url . '&amp;bookmark=1&amp;hash=' . generate_link_hash("topic_$topic_id") : '',
686 5272 acydburn
        'L_BOOKMARK_TOPIC'                => ($user->data['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked']) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'],
687 4947 psotfx
688 7884 acydburn
        'U_POST_NEW_TOPIC'                 => ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=post&amp;f=$forum_id") : '',
689 7884 acydburn
        'U_POST_REPLY_TOPIC'         => ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=reply&amp;f=$forum_id&amp;t=$topic_id") : '',
690 8775 Kellanved
        'U_BUMP_TOPIC'                        => (bump_topic_allowed($forum_id, $topic_data['topic_bumped'], $topic_data['topic_last_post_time'], $topic_data['topic_poster'], $topic_data['topic_last_poster_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=bump&amp;f=$forum_id&amp;t=$topic_id&amp;hash=" . generate_link_hash("topic_$topic_id")) : '')
691 579 psotfx
);
692 237 psotfx
693 2853 psotfx
// Does this topic contain a poll?
694 5412 davidmj
if (!empty($topic_data['poll_start']))
695 987 psotfx
{
696 4981 acydburn
        $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid
697 4981 acydburn
                FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p
698 5078 psotfx
                WHERE o.topic_id = $topic_id
699 5272 acydburn
                        AND p.post_id = {$topic_data['topic_first_post_id']}
700 4981 acydburn
                        AND p.topic_id = o.topic_id
701 4981 acydburn
                ORDER BY o.poll_option_id";
702 2673 psotfx
        $result = $db->sql_query($sql);
703 987 psotfx
704 4184 acydburn
        $poll_info = array();
705 2997 psotfx
        while ($row = $db->sql_fetchrow($result))
706 987 psotfx
        {
707 2983 psotfx
                $poll_info[] = $row;
708 2983 psotfx
        }
709 2983 psotfx
        $db->sql_freeresult($result);
710 5078 psotfx
711 4455 psotfx
        $cur_voted_id = array();
712 5117 acydburn
        if ($user->data['is_registered'])
713 3953 psotfx
        {
714 4051 psotfx
                $sql = 'SELECT poll_option_id
715 4057 acydburn
                        FROM ' . POLL_VOTES_TABLE . '
716 4057 acydburn
                        WHERE topic_id = ' . $topic_id . '
717 4057 acydburn
                                AND vote_user_id = ' . $user->data['user_id'];
718 3953 psotfx
                $result = $db->sql_query($sql);
719 987 psotfx
720 4192 ludovic_arnaud
                while ($row = $db->sql_fetchrow($result))
721 3920 psotfx
                {
722 4455 psotfx
                        $cur_voted_id[] = $row['poll_option_id'];
723 3920 psotfx
                }
724 3953 psotfx
                $db->sql_freeresult($result);
725 3920 psotfx
        }
726 3953 psotfx
        else
727 3920 psotfx
        {
728 3953 psotfx
                // Cookie based guest tracking ... I don't like this but hum ho
729 3953 psotfx
                // it's oft requested. This relies on "nice" users who don't feel
730 4749 psotfx
                // the need to delete cookies to mess with results.
731 3953 psotfx
                if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
732 3920 psotfx
                {
733 4455 psotfx
                        $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]);
734 6002 acydburn
                        $cur_voted_id = array_map('intval', $cur_voted_id);
735 3920 psotfx
                }
736 3953 psotfx
        }
737 987 psotfx
738 9470 acydburn
        // Can not vote at all if no vote permission
739 9470 acydburn
        $s_can_vote = ($auth->acl_get('f_vote', $forum_id) &&
740 5412 davidmj
                (($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) &&
741 5272 acydburn
                $topic_data['topic_status'] != ITEM_LOCKED &&
742 9567 toonarmy
                $topic_data['forum_status'] != ITEM_LOCKED &&
743 9567 toonarmy
                (!sizeof($cur_voted_id) ||
744 9567 toonarmy
                ($auth->acl_get('f_votechg', $forum_id) && $topic_data['poll_vote_change']))) ? true : false;
745 5078 psotfx
        $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || $view == 'viewpoll') ? true : false;
746 3953 psotfx
747 4455 psotfx
        if ($update && $s_can_vote)
748 3953 psotfx
        {
749 8350 acydburn
750 9688 Kellanved
                if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id) || !check_form_key('posting'))
751 3920 psotfx
                {
752 10597 git-gate
                        $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start"));
753 3953 psotfx
754 6002 acydburn
                        meta_refresh(5, $redirect_url);
755 8216 kellanved
                        if (!sizeof($voted_id))
756 8216 kellanved
                        {
757 8216 kellanved
                                $message = 'NO_VOTE_OPTION';
758 8216 kellanved
                        }
759 8216 kellanved
                        else if (sizeof($voted_id) > $topic_data['poll_max_options'])
760 8216 kellanved
                        {
761 8216 kellanved
                                $message = 'TOO_MANY_VOTE_OPTIONS';
762 8216 kellanved
                        }
763 9688 Kellanved
                        else if (in_array(VOTE_CONVERTED, $cur_voted_id))
764 8216 kellanved
                        {
765 8216 kellanved
                                $message = 'VOTE_CONVERTED';
766 8216 kellanved
                        }
767 9688 Kellanved
                        else
768 9688 Kellanved
                        {
769 9688 Kellanved
                                $message = 'FORM_INVALID';
770 9688 Kellanved
                        }
771 8350 acydburn
772 6002 acydburn
                        $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
773 3953 psotfx
                        trigger_error($message);
774 3920 psotfx
                }
775 3920 psotfx
776 3920 psotfx
                foreach ($voted_id as $option)
777 3920 psotfx
                {
778 4455 psotfx
                        if (in_array($option, $cur_voted_id))
779 4455 psotfx
                        {
780 4455 psotfx
                                continue;
781 4455 psotfx
                        }
782 4455 psotfx
783 6002 acydburn
                        $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
784 4947 psotfx
                                SET poll_option_total = poll_option_total + 1
785 6002 acydburn
                                WHERE poll_option_id = ' . (int) $option . '
786 6002 acydburn
                                        AND topic_id = ' . (int) $topic_id;
787 3920 psotfx
                        $db->sql_query($sql);
788 3953 psotfx
789 5117 acydburn
                        if ($user->data['is_registered'])
790 3953 psotfx
                        {
791 6002 acydburn
                                $sql_ary = array(
792 6002 acydburn
                                        'topic_id'                        => (int) $topic_id,
793 6002 acydburn
                                        'poll_option_id'        => (int) $option,
794 6002 acydburn
                                        'vote_user_id'                => (int) $user->data['user_id'],
795 6002 acydburn
                                        'vote_user_ip'                => (string) $user->ip,
796 6002 acydburn
                                );
797 6151 naderman
798 6930 acydburn
                                $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
799 3953 psotfx
                                $db->sql_query($sql);
800 3953 psotfx
                        }
801 3920 psotfx
                }
802 3920 psotfx
803 4455 psotfx
                foreach ($cur_voted_id as $option)
804 4455 psotfx
                {
805 4455 psotfx
                        if (!in_array($option, $voted_id))
806 4455 psotfx
                        {
807 6002 acydburn
                                $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
808 4947 psotfx
                                        SET poll_option_total = poll_option_total - 1
809 6002 acydburn
                                        WHERE poll_option_id = ' . (int) $option . '
810 6002 acydburn
                                                AND topic_id = ' . (int) $topic_id;
811 4455 psotfx
                                $db->sql_query($sql);
812 4455 psotfx
813 5117 acydburn
                                if ($user->data['is_registered'])
814 4455 psotfx
                                {
815 6002 acydburn
                                        $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
816 6002 acydburn
                                                WHERE topic_id = ' . (int) $topic_id . '
817 6002 acydburn
                                                        AND poll_option_id = ' . (int) $option . '
818 6002 acydburn
                                                        AND vote_user_id = ' . (int) $user->data['user_id'];
819 4455 psotfx
                                        $db->sql_query($sql);
820 4455 psotfx
                                }
821 4455 psotfx
                        }
822 4455 psotfx
                }
823 4455 psotfx
824 5117 acydburn
                if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
825 3953 psotfx
                {
826 4904 acydburn
                        $user->set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() + 31536000);
827 3953 psotfx
                }
828 3953 psotfx
829 4947 psotfx
                $sql = 'UPDATE ' . TOPICS_TABLE . '
830 4947 psotfx
                        SET poll_last_vote = ' . time() . "
831 3920 psotfx
                        WHERE topic_id = $topic_id";
832 5078 psotfx
                //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
833 3920 psotfx
                $db->sql_query($sql);
834 3953 psotfx
835 10597 git-gate
                $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start"));
836 3953 psotfx
837 6002 acydburn
                meta_refresh(5, $redirect_url);
838 6002 acydburn
                trigger_error($user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>'));
839 3920 psotfx
        }
840 3920 psotfx
841 2983 psotfx
        $poll_total = 0;
842 2983 psotfx
        foreach ($poll_info as $poll_option)
843 2983 psotfx
        {
844 2983 psotfx
                $poll_total += $poll_option['poll_option_total'];
845 2983 psotfx
        }
846 987 psotfx
847 4981 acydburn
        if ($poll_info[0]['bbcode_bitfield'])
848 4981 acydburn
        {
849 4981 acydburn
                $poll_bbcode = new bbcode();
850 5973 acydburn
        }
851 5973 acydburn
        else
852 5973 acydburn
        {
853 5973 acydburn
                $poll_bbcode = false;
854 5973 acydburn
        }
855 4981 acydburn
856 5973 acydburn
        for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++)
857 5973 acydburn
        {
858 6256 acydburn
                $poll_info[$i]['poll_option_text'] = censor_text($poll_info[$i]['poll_option_text']);
859 6256 acydburn
860 5973 acydburn
                if ($poll_bbcode !== false)
861 4981 acydburn
                {
862 4981 acydburn
                        $poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']);
863 4981 acydburn
                }
864 6256 acydburn
865 8050 naderman
                $poll_info[$i]['poll_option_text'] = bbcode_nl2br($poll_info[$i]['poll_option_text']);
866 5973 acydburn
                $poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
867 5973 acydburn
        }
868 4981 acydburn
869 6256 acydburn
        $topic_data['poll_title'] = censor_text($topic_data['poll_title']);
870 6256 acydburn
871 5973 acydburn
        if ($poll_bbcode !== false)
872 5973 acydburn
        {
873 5412 davidmj
                $poll_bbcode->bbcode_second_pass($topic_data['poll_title'], $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']);
874 4981 acydburn
        }
875 8050 naderman
876 8050 naderman
        $topic_data['poll_title'] = bbcode_nl2br($topic_data['poll_title']);
877 5973 acydburn
        $topic_data['poll_title'] = smiley_text($topic_data['poll_title']);
878 5078 psotfx
879 5973 acydburn
        unset($poll_bbcode);
880 5973 acydburn
881 2983 psotfx
        foreach ($poll_info as $poll_option)
882 2983 psotfx
        {
883 3061 psotfx
                $option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0;
884 9010 toonarmy
                $option_pct_txt = sprintf("%.1d%%", round($option_pct * 100));
885 987 psotfx
886 2983 psotfx
                $template->assign_block_vars('poll_option', array(
887 2983 psotfx
                        'POLL_OPTION_ID'                 => $poll_option['poll_option_id'],
888 2983 psotfx
                        'POLL_OPTION_CAPTION'         => $poll_option['poll_option_text'],
889 2983 psotfx
                        'POLL_OPTION_RESULT'         => $poll_option['poll_option_total'],
890 3953 psotfx
                        'POLL_OPTION_PERCENT'         => $option_pct_txt,
891 5073 acydburn
                        'POLL_OPTION_PCT'                => round($option_pct * 100),
892 4947 psotfx
                        'POLL_OPTION_IMG'                 => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)),
893 4455 psotfx
                        'POLL_OPTION_VOTED'                => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)
894 2983 psotfx
                );
895 2983 psotfx
        }
896 987 psotfx
897 6307 grahamje
        $poll_end = $topic_data['poll_length'] + $topic_data['poll_start'];
898 6307 grahamje
899 2983 psotfx
        $template->assign_vars(array(
900 5412 davidmj
                'POLL_QUESTION'                => $topic_data['poll_title'],
901 2983 psotfx
                'TOTAL_VOTES'                 => $poll_total,
902 2983 psotfx
                'POLL_LEFT_CAP_IMG'        => $user->img('poll_left'),
903 2983 psotfx
                'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'),
904 2117 psotfx
905 5412 davidmj
                'L_MAX_VOTES'                => ($topic_data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $topic_data['poll_max_options']),
906 6307 grahamje
                'L_POLL_LENGTH'                => ($topic_data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
907 3920 psotfx
908 4947 psotfx
                'S_HAS_POLL'                => true,
909 4947 psotfx
                'S_CAN_VOTE'                => $s_can_vote,
910 3953 psotfx
                'S_DISPLAY_RESULTS'        => $s_display_results,
911 5412 davidmj
                'S_IS_MULTI_CHOICE'        => ($topic_data['poll_max_options'] > 1) ? true : false,
912 4912 acydburn
                'S_POLL_ACTION'                => $viewtopic_url,
913 987 psotfx
914 4912 acydburn
                'U_VIEW_RESULTS'        => $viewtopic_url . '&amp;view=viewpoll')
915 2983 psotfx
        );
916 3961 psotfx
917 6307 grahamje
        unset($poll_end, $poll_info, $voted_id);
918 987 psotfx
}
919 987 psotfx
920 4471 ludovic_arnaud
// If the user is trying to reach the second half of the topic, fetch it starting from the end
921 5272 acydburn
$store_reverse = false;
922 4675 ludovic_arnaud
$sql_limit = $config['posts_per_page'];
923 9523 Kellanved
$sql_sort_order = $direction = '';
924 4675 ludovic_arnaud
925 4471 ludovic_arnaud
if ($start > $total_posts / 2)
926 4471 ludovic_arnaud
{
927 5272 acydburn
        $store_reverse = true;
928 4471 ludovic_arnaud
929 4471 ludovic_arnaud
        if ($start + $config['posts_per_page'] > $total_posts)
930 4471 ludovic_arnaud
        {
931 4675 ludovic_arnaud
                $sql_limit = min($config['posts_per_page'], max(1, $total_posts - $start));
932 4471 ludovic_arnaud
        }
933 4471 ludovic_arnaud
934 4675 ludovic_arnaud
        // Select the sort order
935 9523 Kellanved
        $direction = (($sort_dir == 'd') ? 'ASC' : 'DESC');
936 4675 ludovic_arnaud
        $sql_start = max(0, $total_posts - $sql_limit - $start);
937 4471 ludovic_arnaud
}
938 4522 psotfx
else
939 4522 psotfx
{
940 4522 psotfx
        // Select the sort order
941 9523 Kellanved
        $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
942 4675 ludovic_arnaud
        $sql_start = $start;
943 4522 psotfx
}
944 10035 acydburn
945 9523 Kellanved
if (is_array($sort_by_sql[$sort_key]))
946 9523 Kellanved
{
947 9523 Kellanved
        $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
948 9523 Kellanved
}
949 9523 Kellanved
else
950 9523 Kellanved
{
951 9523 Kellanved
        $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
952 9523 Kellanved
}
953 4471 ludovic_arnaud
954 4522 psotfx
// Container for user details, only process once
955 4767 acydburn
$post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array();
956 4859 acydburn
$has_attachments = $display_notice = false;
957 6380 naderman
$bbcode_bitfield = '';
958 6209 davidmj
$i = $i_total = 0;
959 4522 psotfx
960 3856 ludovic_arnaud
// Go ahead and pull all data for this topic
961 4675 ludovic_arnaud
$sql = 'SELECT p.post_id
962 9523 Kellanved
        FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . "
963 3856 ludovic_arnaud
        WHERE p.topic_id = $topic_id
964 4675 ludovic_arnaud
                " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . "
965 9523 Kellanved
                " . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . "
966 3856 ludovic_arnaud
                $limit_posts_time
967 4675 ludovic_arnaud
        ORDER BY $sql_sort_order";
968 4675 ludovic_arnaud
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
969 3856 ludovic_arnaud
970 4675 ludovic_arnaud
$i = ($store_reverse) ? $sql_limit - 1 : 0;
971 4675 ludovic_arnaud
while ($row = $db->sql_fetchrow($result))
972 3856 ludovic_arnaud
{
973 9399 toonarmy
        $post_list[$i] = (int) $row['post_id'];
974 6002 acydburn
        ($store_reverse) ? $i-- : $i++;
975 4675 ludovic_arnaud
}
976 5108 acydburn
$db->sql_freeresult($result);
977 4675 ludovic_arnaud
978 5272 acydburn
if (!sizeof($post_list))
979 4675 ludovic_arnaud
{
980 6320 acydburn
        if ($sort_days)
981 6320 acydburn
        {
982 6320 acydburn
                trigger_error('NO_POSTS_TIME_FRAME');
983 6320 acydburn
        }
984 6320 acydburn
        else
985 6320 acydburn
        {
986 6320 acydburn
                trigger_error('NO_TOPIC');
987 6320 acydburn
        }
988 3856 ludovic_arnaud
}
989 3856 ludovic_arnaud
990 5272 acydburn
// Holding maximum post time for marking topic read
991 5272 acydburn
// We need to grab it because we do reverse ordering sometimes
992 5272 acydburn
$max_post_time = 0;
993 5272 acydburn
994 5885 davidmj
$sql = $db->sql_build_query('SELECT', array(
995 6002 acydburn
        'SELECT'        => 'u.*, z.friend, z.foe, p.*',
996 5885 davidmj
997 5885 davidmj
        'FROM'                => array(
998 5885 davidmj
                USERS_TABLE                => 'u',
999 5885 davidmj
                POSTS_TABLE                => 'p',
1000 5885 davidmj
        ),
1001 5885 davidmj
1002 5885 davidmj
        'LEFT_JOIN'        => array(
1003 5885 davidmj
                array(
1004 5885 davidmj
                        'FROM'        => array(ZEBRA_TABLE => 'z'),
1005 5885 davidmj
                        'ON'        => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'
1006 5885 davidmj
                )
1007 5885 davidmj
        ),
1008 5885 davidmj
1009 6271 acydburn
        'WHERE'                => $db->sql_in_set('p.post_id', $post_list) . '
1010 6002 acydburn
                AND u.user_id = p.poster_id'
1011 5885 davidmj
));
1012 5885 davidmj
1013 4675 ludovic_arnaud
$result = $db->sql_query($sql);
1014 4675 ludovic_arnaud
1015 11309 git-gate
$now = phpbb_gmgetdate(time() + $user->timezone + $user->dst);
1016 6151 naderman
1017 3868 ludovic_arnaud
// Posts are stored in the $rowset array while $attach_list, $user_cache
1018 3868 ludovic_arnaud
// and the global bbcode_bitfield are built
1019 4675 ludovic_arnaud
while ($row = $db->sql_fetchrow($result))
1020 3856 ludovic_arnaud
{
1021 5272 acydburn
        // Set max_post_time
1022 5272 acydburn
        if ($row['post_time'] > $max_post_time)
1023 5272 acydburn
        {
1024 5272 acydburn
                $max_post_time = $row['post_time'];
1025 5272 acydburn
        }
1026 5272 acydburn
1027 9399 toonarmy
        $poster_id = (int) $row['poster_id'];
1028 3856 ludovic_arnaud
1029 4139 acydburn
        // Does post have an attachment? If so, add it to the list
1030 4139 acydburn
        if ($row['post_attachment'] && $config['allow_attachments'])
1031 4139 acydburn
        {
1032 9399 toonarmy
                $attach_list[] = (int) $row['post_id'];
1033 4947 psotfx
1034 4269 psotfx
                if ($row['post_approved'])
1035 4139 acydburn
                {
1036 5272 acydburn
                        $has_attachments = true;
1037 4139 acydburn
                }
1038 4139 acydburn
        }
1039 4139 acydburn
1040 4675 ludovic_arnaud
        $rowset[$row['post_id']] = array(
1041 6589 acydburn
                'hide_post'                        => ($row['foe'] && ($view != 'show' || $post_id != $row['post_id'])) ? true : false,
1042 6589 acydburn
1043 4675 ludovic_arnaud
                'post_id'                        => $row['post_id'],
1044 4675 ludovic_arnaud
                'post_time'                        => $row['post_time'],
1045 4675 ludovic_arnaud
                'user_id'                        => $row['user_id'],
1046 6589 acydburn
                'username'                        => $row['username'],
1047 6589 acydburn
                'user_colour'                => $row['user_colour'],
1048 4675 ludovic_arnaud
                'topic_id'                        => $row['topic_id'],
1049 4675 ludovic_arnaud
                'forum_id'                        => $row['forum_id'],
1050 4675 ludovic_arnaud
                'post_subject'                => $row['post_subject'],
1051 4675 ludovic_arnaud
                'post_edit_count'        => $row['post_edit_count'],
1052 4675 ludovic_arnaud
                'post_edit_time'        => $row['post_edit_time'],
1053 4767 acydburn
                'post_edit_reason'        => $row['post_edit_reason'],
1054 4767 acydburn
                'post_edit_user'        => $row['post_edit_user'],
1055 8924 toonarmy
                'post_edit_locked'        => $row['post_edit_locked'],
1056 6143 ludovic_arnaud
1057 6143 ludovic_arnaud
                // Make sure the icon actually exists
1058 6143 ludovic_arnaud
                'icon_id'                        => (isset($icons[$row['icon_id']]['img'], $icons[$row['icon_id']]['height'], $icons[$row['icon_id']]['width'])) ? $row['icon_id'] : 0,
1059 4675 ludovic_arnaud
                'post_attachment'        => $row['post_attachment'],
1060 4675 ludovic_arnaud
                'post_approved'                => $row['post_approved'],
1061 4675 ludovic_arnaud
                'post_reported'                => $row['post_reported'],
1062 6589 acydburn
                'post_username'                => $row['post_username'],
1063 4675 ludovic_arnaud
                'post_text'                        => $row['post_text'],
1064 4675 ludovic_arnaud
                'bbcode_uid'                => $row['bbcode_uid'],
1065 4675 ludovic_arnaud
                'bbcode_bitfield'        => $row['bbcode_bitfield'],
1066 4675 ludovic_arnaud
                'enable_smilies'        => $row['enable_smilies'],
1067 4947 psotfx
                'enable_sig'                => $row['enable_sig'],
1068 4947 psotfx
                'friend'                        => $row['friend'],
1069 6589 acydburn
                'foe'                                => $row['foe'],
1070 4675 ludovic_arnaud
        );
1071 3868 ludovic_arnaud
1072 3953 psotfx
        // Define the global bbcode bitfield, will be used to load bbcodes
1073 6263 davidmj
        $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
1074 3953 psotfx
1075 4499 ludovic_arnaud
        // Is a signature attached? Are we going to display it?
1076 4577 acydburn
        if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
1077 4499 ludovic_arnaud
        {
1078 6263 davidmj
                $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['user_sig_bbcode_bitfield']);
1079 4499 ludovic_arnaud
        }
1080 4499 ludovic_arnaud
1081 3856 ludovic_arnaud
        // Cache various user specific data ... so we don't have to recompute
1082 3856 ludovic_arnaud
        // this each time the same user appears on this page
1083 3856 ludovic_arnaud
        if (!isset($user_cache[$poster_id]))
1084 3856 ludovic_arnaud
        {
1085 3856 ludovic_arnaud
                if ($poster_id == ANONYMOUS)
1086 3538 psotfx
                {
1087 3856 ludovic_arnaud
                        $user_cache[$poster_id] = array(
1088 4892 acydburn
                                'joined'                => '',
1089 4892 acydburn
                                'posts'                        => '',
1090 4892 acydburn
                                'from'                        => '',
1091 4892 acydburn
1092 4892 acydburn
                                'sig'                                        => '',
1093 4892 acydburn
                                'sig_bbcode_uid'                => '',
1094 4892 acydburn
                                'sig_bbcode_bitfield'        => '',
1095 4892 acydburn
1096 5633 acydburn
                                'online'                        => false,
1097 8872 acydburn
                                'avatar'                        => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '',
1098 5633 acydburn
                                'rank_title'                => '',
1099 5633 acydburn
                                'rank_image'                => '',
1100 5633 acydburn
                                'rank_image_src'        => '',
1101 5633 acydburn
                                'sig'                                => '',
1102 5633 acydburn
                                'profile'                        => '',
1103 5633 acydburn
                                'pm'                                => '',
1104 5633 acydburn
                                'email'                                => '',
1105 5633 acydburn
                                'www'                                => '',
1106 5633 acydburn
                                'icq_status_img'        => '',
1107 5633 acydburn
                                'icq'                                => '',
1108 5633 acydburn
                                'aim'                                => '',
1109 5633 acydburn
                                'msn'                                => '',
1110 5633 acydburn
                                'yim'                                => '',
1111 5633 acydburn
                                'jabber'                        => '',
1112 5633 acydburn
                                'search'                        => '',
1113 6151 naderman
                                'age'                                => '',
1114 6151 naderman
1115 6600 acydburn
                                'username'                        => $row['username'],
1116 6600 acydburn
                                'user_colour'                => $row['user_colour'],
1117 6600 acydburn
1118 5633 acydburn
                                'warnings'                        => 0,
1119 6662 acydburn
                                'allow_pm'                        => 0,
1120 3856 ludovic_arnaud
                        );
1121 8872 acydburn
1122 9082 acydburn
                        get_user_rank($row['user_rank'], false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
1123 3856 ludovic_arnaud
                }
1124 3856 ludovic_arnaud
                else
1125 3856 ludovic_arnaud
                {
1126 3953 psotfx
                        $user_sig = '';
1127 4578 psotfx
1128 7256 acydburn
                        // We add the signature to every posters entry because enable_sig is post dependant
1129 7256 acydburn
                        if ($row['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
1130 3538 psotfx
                        {
1131 3953 psotfx
                                $user_sig = $row['user_sig'];
1132 3538 psotfx
                        }
1133 4441 psotfx
1134 4269 psotfx
                        $id_cache[] = $poster_id;
1135 6002 acydburn
1136 3856 ludovic_arnaud
                        $user_cache[$poster_id] = array(
1137 5701 acydburn
                                'joined'                => $user->format_date($row['user_regdate']),
1138 5216 bartvb
                                'posts'                        => $row['user_posts'],
1139 5358 subblue
                                'warnings'                => (isset($row['user_warnings'])) ? $row['user_warnings'] : 0,
1140 4051 psotfx
                                'from'                        => (!empty($row['user_from'])) ? $row['user_from'] : '',
1141 3953 psotfx
1142 4051 psotfx
                                'sig'                                        => $user_sig,
1143 6930 acydburn
                                'sig_bbcode_uid'                => (!empty($row['user_sig_bbcode_uid'])) ? $row['user_sig_bbcode_uid'] : '',
1144 6930 acydburn
                                'sig_bbcode_bitfield'        => (!empty($row['user_sig_bbcode_bitfield'])) ? $row['user_sig_bbcode_bitfield'] : '',
1145 3953 psotfx
1146 4947 psotfx
                                'viewonline'        => $row['user_allow_viewonline'],
1147 6662 acydburn
                                'allow_pm'                => $row['user_allow_pm'],
1148 4269 psotfx
1149 7330 acydburn
                                'avatar'                => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '',
1150 6151 naderman
                                'age'                        => '',
1151 3868 ludovic_arnaud
1152 6190 acydburn
                                'rank_title'                => '',
1153 6190 acydburn
                                'rank_image'                => '',
1154 6190 acydburn
                                'rank_image_src'        => '',
1155 6190 acydburn
1156 6600 acydburn
                                'username'                        => $row['username'],
1157 6600 acydburn
                                'user_colour'                => $row['user_colour'],
1158 6600 acydburn
1159 4920 acydburn
                                'online'                => false,
1160 6015 acydburn
                                'profile'                => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$poster_id"),
1161 4051 psotfx
                                'www'                        => $row['user_website'],
1162 7242 acydburn
                                'aim'                        => ($row['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=aim&amp;u=$poster_id") : '',
1163 7242 acydburn
                                'msn'                        => ($row['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=msnm&amp;u=$poster_id") : '',
1164 8092 acydburn
                                'yim'                        => ($row['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($row['user_yim']) . '&amp;.src=pg' : '',
1165 7242 acydburn
                                'jabber'                => ($row['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=jabber&amp;u=$poster_id") : '',
1166 8835 toonarmy
                                'search'                => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$poster_id&amp;sr=posts") : '',
1167 9790 toonarmy
1168 9790 toonarmy
                                'author_full'                => get_username_string('full', $poster_id, $row['username'], $row['user_colour']),
1169 9790 toonarmy
                                'author_colour'                => get_username_string('colour', $poster_id, $row['username'], $row['user_colour']),
1170 9790 toonarmy
                                'author_username'        => get_username_string('username', $poster_id, $row['username'], $row['user_colour']),
1171 9790 toonarmy
                                'author_profile'        => get_username_string('profile', $poster_id, $row['username'], $row['user_colour']),
1172 3856 ludovic_arnaud
                        );
1173 3538 psotfx
1174 6829 acydburn
                        get_user_rank($row['user_rank'], $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
1175 136 psotfx
1176 10756 git-gate
                        if ((!empty($row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email'))
1177 2714 psotfx
                        {
1178 6015 acydburn
                                $user_cache[$poster_id]['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;u=$poster_id") : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $row['user_email']);
1179 2714 psotfx
                        }
1180 2714 psotfx
                        else
1181 2714 psotfx
                        {
1182 3286 psotfx
                                $user_cache[$poster_id]['email'] = '';
1183 2714 psotfx
                        }
1184 2714 psotfx
1185 2997 psotfx
                        if (!empty($row['user_icq']))
1186 2714 psotfx
                        {
1187 11092 git-gate
                                $user_cache[$poster_id]['icq'] = 'http://www.icq.com/people/' . urlencode($row['user_icq']) . '/';
1188 6002 acydburn
                                $user_cache[$poster_id]['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $row['user_icq'] . '&amp;img=5" width="18" height="18" alt="" />';
1189 2714 psotfx
                        }
1190 2714 psotfx
                        else
1191 2714 psotfx
                        {
1192 3286 psotfx
                                $user_cache[$poster_id]['icq_status_img'] = '';
1193 3286 psotfx
                                $user_cache[$poster_id]['icq'] = '';
1194 2714 psotfx
                        }
1195 6151 naderman
1196 7909 acydburn
                        if ($config['allow_birthdays'] && !empty($row['user_birthday']))
1197 6151 naderman
                        {
1198 6151 naderman
                                list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $row['user_birthday']));
1199 6151 naderman
1200 6151 naderman
                                if ($bday_year)
1201 6151 naderman
                                {
1202 6321 naderman
                                        $diff = $now['mon'] - $bday_month;
1203 6241 naderman
                                        if ($diff == 0)
1204 6241 naderman
                                        {
1205 6321 naderman
                                                $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
1206 6241 naderman
                                        }
1207 6241 naderman
                                        else
1208 6241 naderman
                                        {
1209 6241 naderman
                                                $diff = ($diff < 0) ? 1 : 0;
1210 6241 naderman
                                        }
1211 6256 acydburn
1212 6321 naderman
                                        $user_cache[$poster_id]['age'] = (int) ($now['year'] - $bday_year - $diff);
1213 6151 naderman
                                }
1214 6151 naderman
                        }
1215 1320 psotfx
                }
1216 3856 ludovic_arnaud
        }
1217 3868 ludovic_arnaud
}
1218 3868 ludovic_arnaud
$db->sql_freeresult($result);
1219 1320 psotfx
1220 4984 acydburn
// Load custom profile fields
1221 4984 acydburn
if ($config['load_cpf_viewtopic'])
1222 4892 acydburn
{
1223 9418 acydburn
        if (!class_exists('custom_profile'))
1224 9418 acydburn
        {
1225 9418 acydburn
                include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1226 9418 acydburn
        }
1227 4892 acydburn
        $cp = new custom_profile();
1228 4984 acydburn
1229 4984 acydburn
        // Grab all profile fields from users in id cache for later use - similar to the poster cache
1230 9916 Kellanved
        $profile_fields_tmp = $cp->generate_profile_fields_template('grab', $id_cache);
1231 9965 acydburn
1232 9916 Kellanved
        // filter out fields not to be displayed on viewtopic. Yes, it's a hack, but this shouldn't break any MODs.
1233 9916 Kellanved
        $profile_fields_cache = array();
1234 9916 Kellanved
        foreach ($profile_fields_tmp as $profile_user_id => $profile_fields)
1235 9916 Kellanved
        {
1236 9916 Kellanved
                $profile_fields_cache[$profile_user_id] = array();
1237 9916 Kellanved
                foreach ($profile_fields as $used_ident => $profile_field)
1238 9916 Kellanved
                {
1239 9916 Kellanved
                        if ($profile_field['data']['field_show_on_vt'])
1240 9916 Kellanved
                        {
1241 9916 Kellanved
                                $profile_fields_cache[$profile_user_id][$used_ident] = $profile_field;
1242 9916 Kellanved
                        }
1243 9916 Kellanved
                }
1244 9916 Kellanved
        }
1245 9916 Kellanved
        unset($profile_fields_tmp);
1246 4892 acydburn
}
1247 4892 acydburn
1248 4269 psotfx
// Generate online information for user
1249 4269 psotfx
if ($config['load_onlinetrack'] && sizeof($id_cache))
1250 3868 ludovic_arnaud
{
1251 4973 psotfx
        $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
1252 4947 psotfx
                FROM ' . SESSIONS_TABLE . '
1253 6271 acydburn
                WHERE ' . $db->sql_in_set('session_user_id', $id_cache) . '
1254 4269 psotfx
                GROUP BY session_user_id';
1255 3868 ludovic_arnaud
        $result = $db->sql_query($sql);
1256 3868 ludovic_arnaud
1257 4269 psotfx
        $update_time = $config['load_online_time'] * 60;
1258 3868 ludovic_arnaud
        while ($row = $db->sql_fetchrow($result))
1259 3868 ludovic_arnaud
        {
1260 7755 kellanved
                $user_cache[$row['session_user_id']]['online'] = (time() - $update_time < $row['online_time'] && (($row['viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
1261 3868 ludovic_arnaud
        }
1262 5415 davidmj
        $db->sql_freeresult($result);
1263 4269 psotfx
}
1264 4269 psotfx
unset($id_cache);
1265 3868 ludovic_arnaud
1266 4269 psotfx
// Pull attachment data
1267 4920 acydburn
if (sizeof($attach_list))
1268 4269 psotfx
{
1269 6351 acydburn
        if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
1270 3868 ludovic_arnaud
        {
1271 4947 psotfx
                $sql = 'SELECT *
1272 4637 acydburn
                        FROM ' . ATTACHMENTS_TABLE . '
1273 6271 acydburn
                        WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
1274 4883 acydburn
                                AND in_message = 0
1275 6628 acydburn
                        ORDER BY filetime DESC, post_msg_id ASC';
1276 4269 psotfx
                $result = $db->sql_query($sql);
1277 4269 psotfx
1278 4269 psotfx
                while ($row = $db->sql_fetchrow($result))
1279 3868 ludovic_arnaud
                {
1280 4883 acydburn
                        $attachments[$row['post_msg_id']][] = $row;
1281 4269 psotfx
                }
1282 4269 psotfx
                $db->sql_freeresult($result);
1283 3868 ludovic_arnaud
1284 4473 psotfx
                // No attachments exist, but post table thinks they do so go ahead and reset post_attach flags
1285 4920 acydburn
                if (!sizeof($attachments))
1286 4269 psotfx
                {
1287 4947 psotfx
                        $sql = 'UPDATE ' . POSTS_TABLE . '
1288 4947 psotfx
                                SET post_attachment = 0
1289 6271 acydburn
                                WHERE ' . $db->sql_in_set('post_id', $attach_list);
1290 4269 psotfx
                        $db->sql_query($sql);
1291 4269 psotfx
1292 4269 psotfx
                        // We need to update the topic indicator too if the complete topic is now without an attachment
1293 4920 acydburn
                        if (sizeof($rowset) != $total_posts)
1294 3868 ludovic_arnaud
                        {
1295 4269 psotfx
                                // Not all posts are displayed so we query the db to find if there's any attachment for this topic
1296 4883 acydburn
                                $sql = 'SELECT a.post_msg_id as post_id
1297 4269 psotfx
                                        FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p
1298 4269 psotfx
                                        WHERE p.topic_id = $topic_id
1299 4269 psotfx
                                                AND p.post_approved = 1
1300 4883 acydburn
                                                AND p.topic_id = a.topic_id";
1301 4269 psotfx
                                $result = $db->sql_query_limit($sql, 1);
1302 6002 acydburn
                                $row = $db->sql_fetchrow($result);
1303 6002 acydburn
                                $db->sql_freeresult($result);
1304 4269 psotfx
1305 6002 acydburn
                                if (!$row)
1306 4269 psotfx
                                {
1307 4947 psotfx
                                        $sql = 'UPDATE ' . TOPICS_TABLE . "
1308 4947 psotfx
                                                SET topic_attachment = 0
1309 4269 psotfx
                                                WHERE topic_id = $topic_id";
1310 4269 psotfx
                                        $db->sql_query($sql);
1311 4269 psotfx
                                }
1312 4269 psotfx
                        }
1313 4269 psotfx
                        else
1314 4269 psotfx
                        {
1315 4947 psotfx
                                $sql = 'UPDATE ' . TOPICS_TABLE . "
1316 4947 psotfx
                                        SET topic_attachment = 0
1317 3920 psotfx
                                        WHERE topic_id = $topic_id";
1318 3920 psotfx
                                $db->sql_query($sql);
1319 3868 ludovic_arnaud
                        }
1320 3868 ludovic_arnaud
                }
1321 4762 acydburn
                else if ($has_attachments && !$topic_data['topic_attachment'])
1322 3868 ludovic_arnaud
                {
1323 4269 psotfx
                        // Topic has approved attachments but its flag is wrong
1324 4947 psotfx
                        $sql = 'UPDATE ' . TOPICS_TABLE . "
1325 4947 psotfx
                                SET topic_attachment = 1
1326 3920 psotfx
                                WHERE topic_id = $topic_id";
1327 3920 psotfx
                        $db->sql_query($sql);
1328 4762 acydburn
1329 4762 acydburn
                        $topic_data['topic_attachment'] = 1;
1330 3868 ludovic_arnaud
                }
1331 3868 ludovic_arnaud
        }
1332 4269 psotfx
        else
1333 3868 ludovic_arnaud
        {
1334 4859 acydburn
                $display_notice = true;
1335 3868 ludovic_arnaud
        }
1336 3868 ludovic_arnaud
}
1337 3868 ludovic_arnaud
1338 4167 psotfx
// Instantiate BBCode if need be
1339 6256 acydburn
if ($bbcode_bitfield !== '')
1340 3868 ludovic_arnaud
{
1341 6263 davidmj
        $bbcode = new bbcode(base64_encode($bbcode_bitfield));
1342 3868 ludovic_arnaud
}
1343 3868 ludovic_arnaud
1344 4473 psotfx
$i_total = sizeof($rowset) - 1;
1345 4473 psotfx
$prev_post_id = '';
1346 4167 psotfx
1347 4870 acydburn
$template->assign_vars(array(
1348 4920 acydburn
        'S_NUM_POSTS' => sizeof($post_list))
1349 4870 acydburn
);
1350 4870 acydburn
1351 4167 psotfx
// Output the posts
1352 6479 acydburn
$first_unread = $post_unread = false;
1353 4920 acydburn
for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
1354 3868 ludovic_arnaud
{
1355 7034 acydburn
        // A non-existing rowset only happens if there was no user present for the entered poster_id
1356 7034 acydburn
        // This could be a broken posts table.
1357 7034 acydburn
        if (!isset($rowset[$post_list[$i]]))
1358 7034 acydburn
        {
1359 7034 acydburn
                continue;
1360 7034 acydburn
        }
1361 7034 acydburn
1362 4675 ludovic_arnaud
        $row =& $rowset[$post_list[$i]];
1363 4062 psotfx
        $poster_id = $row['user_id'];
1364 3868 ludovic_arnaud
1365 3868 ludovic_arnaud
        // End signature parsing, only if needed
1366 7256 acydburn
        if ($user_cache[$poster_id]['sig'] && $row['enable_sig'] && empty($user_cache[$poster_id]['sig_parsed']))
1367 3868 ludovic_arnaud
        {
1368 6256 acydburn
                $user_cache[$poster_id]['sig'] = censor_text($user_cache[$poster_id]['sig']);
1369 6256 acydburn
1370 3868 ludovic_arnaud
                if ($user_cache[$poster_id]['sig_bbcode_bitfield'])
1371 3868 ludovic_arnaud
                {
1372 4150 psotfx
                        $bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']);
1373 3868 ludovic_arnaud
                }
1374 3869 psotfx
1375 8050 naderman
                $user_cache[$poster_id]['sig'] = bbcode_nl2br($user_cache[$poster_id]['sig']);
1376 5108 acydburn
                $user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']);
1377 5313 acydburn
                $user_cache[$poster_id]['sig_parsed'] = true;
1378 3868 ludovic_arnaud
        }
1379 3868 ludovic_arnaud
1380 3856 ludovic_arnaud
        // Parse the message and subject
1381 6256 acydburn
        $message = censor_text($row['post_text']);
1382 3347 psotfx
1383 3856 ludovic_arnaud
        // Second parse bbcode here
1384 3856 ludovic_arnaud
        if ($row['bbcode_bitfield'])
1385 3856 ludovic_arnaud
        {
1386 4150 psotfx
                $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
1387 3856 ludovic_arnaud
        }
1388 303 thefinn
1389 8050 naderman
        $message = bbcode_nl2br($message);
1390 5108 acydburn
        $message = smiley_text($message);
1391 987 psotfx
1392 6803 acydburn
        if (!empty($attachments[$row['post_id']]))
1393 4984 acydburn
        {
1394 6803 acydburn
                parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count);
1395 4984 acydburn
        }
1396 4984 acydburn
1397 8045 naderman
        // Replace naughty words such as farty pants
1398 8045 naderman
        $row['post_subject'] = censor_text($row['post_subject']);
1399 8045 naderman
1400 3856 ludovic_arnaud
        // Highlight active words (primarily for search)
1401 3856 ludovic_arnaud
        if ($highlight_match)
1402 3856 ludovic_arnaud
        {
1403 6550 davidmj
                $message = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $message);
1404 8045 naderman
                $row['post_subject'] = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $row['post_subject']);
1405 3856 ludovic_arnaud
        }
1406 3347 psotfx
1407 3856 ludovic_arnaud
        // Editing information
1408 4767 acydburn
        if (($row['post_edit_count'] && $config['display_last_edited']) || $row['post_edit_reason'])
1409 3856 ludovic_arnaud
        {
1410 4767 acydburn
                // Get usernames for all following posts if not already stored
1411 6149 acydburn
                if (!sizeof($post_edit_list) && ($row['post_edit_reason'] || ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))))
1412 4767 acydburn
                {
1413 4767 acydburn
                        // Remove all post_ids already parsed (we do not have to check them)
1414 5068 acydburn
                        $post_storage_list = (!$store_reverse) ? array_slice($post_list, $i) : array_slice(array_reverse($post_list), $i);
1415 4767 acydburn
1416 4947 psotfx
                        $sql = 'SELECT DISTINCT u.user_id, u.username, u.user_colour
1417 4767 acydburn
                                FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
1418 6271 acydburn
                                WHERE ' . $db->sql_in_set('p.post_id', $post_storage_list) . '
1419 4767 acydburn
                                        AND p.post_edit_count <> 0
1420 4767 acydburn
                                        AND p.post_edit_user <> 0
1421 6271 acydburn
                                        AND p.post_edit_user = u.user_id';
1422 4767 acydburn
                        $result2 = $db->sql_query($sql);
1423 4767 acydburn
                        while ($user_edit_row = $db->sql_fetchrow($result2))
1424 4767 acydburn
                        {
1425 4767 acydburn
                                $post_edit_list[$user_edit_row['user_id']] = $user_edit_row;
1426 4767 acydburn
                        }
1427 4767 acydburn
                        $db->sql_freeresult($result2);
1428 4947 psotfx
1429 4767 acydburn
                        unset($post_storage_list);
1430 4767 acydburn
                }
1431 5078 psotfx
1432 4005 acydburn
                $l_edit_time_total = ($row['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
1433 3357 psotfx
1434 5027 acydburn
                if ($row['post_edit_reason'])
1435 5027 acydburn
                {
1436 6600 acydburn
                        // User having edited the post also being the post author?
1437 6600 acydburn
                        if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id)
1438 6600 acydburn
                        {
1439 6600 acydburn
                                $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
1440 6600 acydburn
                        }
1441 6600 acydburn
                        else
1442 6600 acydburn
                        {
1443 6600 acydburn
                                $display_username = get_username_string('full', $row['post_edit_user'], $post_edit_list[$row['post_edit_user']]['username'], $post_edit_list[$row['post_edit_user']]['user_colour']);
1444 6600 acydburn
                        }
1445 6149 acydburn
1446 9138 acydburn
                        $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time'], false, true), $row['post_edit_count']);
1447 5027 acydburn
                }
1448 5027 acydburn
                else
1449 5027 acydburn
                {
1450 6149 acydburn
                        if ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))
1451 6149 acydburn
                        {
1452 6149 acydburn
                                $user_cache[$row['post_edit_user']] = $post_edit_list[$row['post_edit_user']];
1453 6149 acydburn
                        }
1454 6149 acydburn
1455 6600 acydburn
                        // User having edited the post also being the post author?
1456 6600 acydburn
                        if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id)
1457 6600 acydburn
                        {
1458 6600 acydburn
                                $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
1459 6600 acydburn
                        }
1460 6600 acydburn
                        else
1461 6600 acydburn
                        {
1462 6600 acydburn
                                $display_username = get_username_string('full', $row['post_edit_user'], $user_cache[$row['post_edit_user']]['username'], $user_cache[$row['post_edit_user']]['user_colour']);
1463 6600 acydburn
                        }
1464 6600 acydburn
1465 9138 acydburn
                        $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time'], false, true), $row['post_edit_count']);
1466 5027 acydburn
                }
1467 3856 ludovic_arnaud
        }
1468 3856 ludovic_arnaud
        else
1469 3856 ludovic_arnaud
        {
1470 3856 ludovic_arnaud
                $l_edited_by = '';
1471 3856 ludovic_arnaud
        }
1472 2448 psotfx
1473 4634 acydburn
        // Bump information
1474 5534 subblue
        if ($topic_data['topic_bumped'] && $row['post_id'] == $topic_data['topic_last_post_id'] && isset($user_cache[$topic_data['topic_bumper']]) )
1475 4634 acydburn
        {
1476 4947 psotfx
                // It is safe to grab the username from the user cache array, we are at the last
1477 7007 acydburn
                // post and only the topic poster and last poster are allowed to bump.
1478 7007 acydburn
                // Admins and mods are bound to the above rules too...
1479 9563 bantu
                $l_bumped_by = sprintf($user->lang['BUMPED_BY'], $user_cache[$topic_data['topic_bumper']]['username'], $user->format_date($topic_data['topic_last_post_time'], false, true));
1480 4634 acydburn
        }
1481 4634 acydburn
        else
1482 4634 acydburn
        {
1483 4634 acydburn
                $l_bumped_by = '';
1484 4634 acydburn
        }
1485 4634 acydburn
1486 4984 acydburn
        $cp_row = array();
1487 4818 acydburn
1488 4984 acydburn
        //
1489 4984 acydburn
        if ($config['load_cpf_viewtopic'])
1490 4892 acydburn
        {
1491 4892 acydburn
                $cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
1492 4892 acydburn
        }
1493 4892 acydburn
1494 5272 acydburn
        $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
1495 6151 naderman
1496 5272 acydburn
        $s_first_unread = false;
1497 5272 acydburn
        if (!$first_unread && $post_unread)
1498 5272 acydburn
        {
1499 5272 acydburn
                $s_first_unread = $first_unread = true;
1500 5272 acydburn
        }
1501 5272 acydburn
1502 10076 acydburn
        $edit_allowed = ($user->data['is_registered'] && ($auth->acl_get('m_edit', $forum_id) || (
1503 10076 acydburn
                $user->data['user_id'] == $poster_id &&
1504 10076 acydburn
                $auth->acl_get('f_edit', $forum_id) &&
1505 10076 acydburn
                !$row['post_edit_locked'] &&
1506 10076 acydburn
                ($row['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time'])
1507 10076 acydburn
        )));
1508 9798 acydburn
1509 10076 acydburn
        $delete_allowed = ($user->data['is_registered'] && ($auth->acl_get('m_delete', $forum_id) || (
1510 10076 acydburn
                $user->data['user_id'] == $poster_id &&
1511 10076 acydburn
                $auth->acl_get('f_delete', $forum_id) &&
1512 10076 acydburn
                $topic_data['topic_last_post_id'] == $row['post_id'] &&
1513 10080 nickvergessen
                ($row['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time']) &&
1514 10080 nickvergessen
                // we do not want to allow removal of the last post if a moderator locked it!
1515 10076 acydburn
                !$row['post_edit_locked']
1516 10076 acydburn
        )));
1517 10076 acydburn
1518 4984 acydburn
        //
1519 4892 acydburn
        $postrow = array(
1520 9790 toonarmy
                'POST_AUTHOR_FULL'                => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_full'] : get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1521 9790 toonarmy
                'POST_AUTHOR_COLOUR'        => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_colour'] : get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1522 9790 toonarmy
                'POST_AUTHOR'                        => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_username'] : get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1523 9790 toonarmy
                'U_POST_AUTHOR'                        => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_profile'] : get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1524 6589 acydburn
1525 6818 acydburn
                'RANK_TITLE'                => $user_cache[$poster_id]['rank_title'],
1526 6818 acydburn
                'RANK_IMG'                        => $user_cache[$poster_id]['rank_image'],
1527 6818 acydburn
                'RANK_IMG_SRC'                => $user_cache[$poster_id]['rank_image_src'],
1528 5633 acydburn
                'POSTER_JOINED'                => $user_cache[$poster_id]['joined'],
1529 5633 acydburn
                'POSTER_POSTS'                => $user_cache[$poster_id]['posts'],
1530 5633 acydburn
                'POSTER_FROM'                => $user_cache[$poster_id]['from'],
1531 5633 acydburn
                'POSTER_AVATAR'                => $user_cache[$poster_id]['avatar'],
1532 5345 grahamje
                'POSTER_WARNINGS'        => $user_cache[$poster_id]['warnings'],
1533 6151 naderman
                'POSTER_AGE'                => $user_cache[$poster_id]['age'],
1534 3920 psotfx
1535 9435 acydburn
                'POST_DATE'                        => $user->format_date($row['post_time'], false, ($view == 'print') ? true : false),
1536 6002 acydburn
                'POST_SUBJECT'                => $row['post_subject'],
1537 6002 acydburn
                'MESSAGE'                        => $message,
1538 6002 acydburn
                'SIGNATURE'                        => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '',
1539 6002 acydburn
                'EDITED_MESSAGE'        => $l_edited_by,
1540 6002 acydburn
                'EDIT_REASON'                => $row['post_edit_reason'],
1541 6002 acydburn
                'BUMPED_MESSAGE'        => $l_bumped_by,
1542 884 psotfx
1543 10711 git-gate
                'MINI_POST_IMG'                        => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
1544 7007 acydburn
                'POST_ICON_IMG'                        => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['img'] : '',
1545 7007 acydburn
                'POST_ICON_IMG_WIDTH'        => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['width'] : '',
1546 7007 acydburn
                'POST_ICON_IMG_HEIGHT'        => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '',
1547 6002 acydburn
                'ICQ_STATUS_IMG'                => $user_cache[$poster_id]['icq_status_img'],
1548 6237 acydburn
                'ONLINE_IMG'                        => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? '' : (($user_cache[$poster_id]['online']) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
1549 6002 acydburn
                'S_ONLINE'                                => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? false : (($user_cache[$poster_id]['online']) ? true : false),
1550 2708 psotfx
1551 10076 acydburn
                'U_EDIT'                        => ($edit_allowed) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&amp;f=$forum_id&amp;p={$row['post_id']}") : '',
1552 6015 acydburn
                'U_QUOTE'                        => ($auth->acl_get('f_reply', $forum_id)) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=quote&amp;f=$forum_id&amp;p={$row['post_id']}") : '',
1553 6045 naderman
                'U_INFO'                        => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=post_details&amp;f=$forum_id&amp;p=" . $row['post_id'], true, $user->session_id) : '',
1554 10076 acydburn
                'U_DELETE'                        => ($delete_allowed) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=delete&amp;f=$forum_id&amp;p={$row['post_id']}") : '',
1555 2708 psotfx
1556 9780 nickvergessen
                'U_PROFILE'                => $user_cache[$poster_id]['profile'],
1557 6002 acydburn
                'U_SEARCH'                => $user_cache[$poster_id]['search'],
1558 6662 acydburn
                'U_PM'                        => ($poster_id != ANONYMOUS && $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user_cache[$poster_id]['allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;action=quotepost&amp;p=' . $row['post_id']) : '',
1559 6002 acydburn
                'U_EMAIL'                => $user_cache[$poster_id]['email'],
1560 6002 acydburn
                'U_WWW'                        => $user_cache[$poster_id]['www'],
1561 6002 acydburn
                'U_ICQ'                        => $user_cache[$poster_id]['icq'],
1562 6002 acydburn
                'U_AIM'                        => $user_cache[$poster_id]['aim'],
1563 6002 acydburn
                'U_MSN'                        => $user_cache[$poster_id]['msn'],
1564 6002 acydburn
                'U_YIM'                        => $user_cache[$poster_id]['yim'],
1565 6002 acydburn
                'U_JABBER'                => $user_cache[$poster_id]['jabber'],
1566 3357 psotfx
1567 6030 grahamje
                'U_REPORT'                        => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $row['post_id']) : '',
1568 6045 naderman
                'U_MCP_REPORT'                => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
1569 6045 naderman
                'U_MCP_APPROVE'                => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
1570 6135 acydburn
                'U_MINI_POST'                => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . (($topic_data['topic_type'] == POST_GLOBAL) ? '&amp;f=' . $forum_id : '') . '#p' . $row['post_id'],
1571 5861 acydburn
                'U_NEXT_POST_ID'        => ($i < $i_total && isset($rowset[$post_list[$i + 1]])) ? $rowset[$post_list[$i + 1]]['post_id'] : '',
1572 4947 psotfx
                'U_PREV_POST_ID'        => $prev_post_id,
1573 6045 naderman
                'U_NOTES'                        => ($auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $poster_id, true, $user->session_id) : '',
1574 7355 naderman
                'U_WARN'                        => ($auth->acl_get('m_warn') && $poster_id != $user->data['user_id'] && $poster_id != ANONYMOUS) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_post&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
1575 2708 psotfx
1576 4964 acydburn
                'POST_ID'                        => $row['post_id'],
1577 11019 git-gate
                'POST_NUMBER'                => $i + $start + 1,
1578 7322 acydburn
                'POSTER_ID'                        => $poster_id,
1579 4964 acydburn
1580 6002 acydburn
                'S_HAS_ATTACHMENTS'        => (!empty($attachments[$row['post_id']])) ? true : false,
1581 5313 acydburn
                'S_POST_UNAPPROVED'        => ($row['post_approved']) ? false : true,
1582 5649 naderman
                'S_POST_REPORTED'        => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
1583 4947 psotfx
                'S_DISPLAY_NOTICE'        => $display_notice && $row['post_attachment'],
1584 4964 acydburn
                'S_FRIEND'                        => ($row['friend']) ? true : false,
1585 5272 acydburn
                'S_UNREAD_POST'                => $post_unread,
1586 5272 acydburn
                'S_FIRST_UNREAD'        => $s_first_unread,
1587 6589 acydburn
                'S_CUSTOM_FIELDS'        => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
1588 7646 acydburn
                'S_TOPIC_POSTER'        => ($topic_data['topic_poster'] == $poster_id) ? true : false,
1589 6589 acydburn
1590 6589 acydburn
                'S_IGNORE_POST'                => ($row['hide_post']) ? true : false,
1591 6589 acydburn
                'L_IGNORE_POST'                => ($row['hide_post']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), '<a href="' . $viewtopic_url . "&amp;p={$row['post_id']}&amp;view=show#p{$row['post_id']}" . '">', '</a>') : '',
1592 3869 psotfx
        );
1593 6002 acydburn
1594 5137 acydburn
        if (isset($cp_row['row']) && sizeof($cp_row['row']))
1595 4892 acydburn
        {
1596 5137 acydburn
                $postrow = array_merge($postrow, $cp_row['row']);
1597 4984 acydburn
        }
1598 4892 acydburn
1599 4984 acydburn
        // Dump vars into template
1600 4892 acydburn
        $template->assign_block_vars('postrow', $postrow);
1601 4947 psotfx
1602 6002 acydburn
        if (!empty($cp_row['blockrow']))
1603 5137 acydburn
        {
1604 5137 acydburn
                foreach ($cp_row['blockrow'] as $field_data)
1605 5137 acydburn
                {
1606 5137 acydburn
                        $template->assign_block_vars('postrow.custom_fields', $field_data);
1607 5137 acydburn
                }
1608 5137 acydburn
        }
1609 5137 acydburn
1610 4818 acydburn
        // Display not already displayed Attachments for this post, we already parsed them. ;)
1611 6002 acydburn
        if (!empty($attachments[$row['post_id']]))
1612 3856 ludovic_arnaud
        {
1613 4818 acydburn
                foreach ($attachments[$row['post_id']] as $attachment)
1614 4818 acydburn
                {
1615 4818 acydburn
                        $template->assign_block_vars('postrow.attachment', array(
1616 4920 acydburn
                                'DISPLAY_ATTACHMENT'        => $attachment)
1617 4818 acydburn
                        );
1618 4818 acydburn
                }
1619 2714 psotfx
        }
1620 3868 ludovic_arnaud
1621 4473 psotfx
        $prev_post_id = $row['post_id'];
1622 4473 psotfx
1623 5861 acydburn
        unset($rowset[$post_list[$i]]);
1624 3868 ludovic_arnaud
        unset($attachments[$row['post_id']]);
1625 81 thefinn
}
1626 6002 acydburn
unset($rowset, $user_cache);
1627 82 thefinn
1628 8835 toonarmy
// Update topic view and if necessary attachment view counters ... but only for humans and if this is the first 'page view'
1629 9411 acydburn
if (isset($user->data['session_page']) && !$user->data['is_bot'] && (strpos($user->data['session_page'], '&t=' . $topic_id) === false || isset($user->data['session_created'])))
1630 3286 psotfx
{
1631 4167 psotfx
        $sql = 'UPDATE ' . TOPICS_TABLE . '
1632 4167 psotfx
                SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . "
1633 3856 ludovic_arnaud
                WHERE topic_id = $topic_id";
1634 3807 acydburn
        $db->sql_query($sql);
1635 3961 psotfx
1636 3961 psotfx
        // Update the attachment download counts
1637 4167 psotfx
        if (sizeof($update_count))
1638 3961 psotfx
        {
1639 4947 psotfx
                $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
1640 4947 psotfx
                        SET download_count = download_count + 1
1641 6271 acydburn
                        WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
1642 3961 psotfx
                $db->sql_query($sql);
1643 3961 psotfx
        }
1644 3286 psotfx
}
1645 3286 psotfx
1646 10018 rxu
// Get last post time for all global announcements
1647 10018 rxu
// to keep proper forums tracking
1648 10018 rxu
if ($topic_data['topic_type'] == POST_GLOBAL)
1649 10018 rxu
{
1650 10018 rxu
        $sql = 'SELECT topic_last_post_time as forum_last_post_time
1651 10018 rxu
                FROM ' . TOPICS_TABLE . '
1652 10018 rxu
                WHERE forum_id = 0
1653 10018 rxu
                ORDER BY topic_last_post_time DESC';
1654 10018 rxu
        $result = $db->sql_query_limit($sql, 1);
1655 10018 rxu
        $topic_data['forum_last_post_time'] = (int) $db->sql_fetchfield('forum_last_post_time');
1656 10018 rxu
        $db->sql_freeresult($result);
1657 10035 acydburn
1658 10018 rxu
        $sql = 'SELECT mark_time as forum_mark_time
1659 10018 rxu
                FROM ' . FORUMS_TRACK_TABLE . '
1660 10018 rxu
                WHERE forum_id = 0
1661 10018 rxu
                        AND user_id = ' . $user->data['user_id'];
1662 10018 rxu
        $result = $db->sql_query($sql);
1663 10018 rxu
        $topic_data['forum_mark_time'] = (int) $db->sql_fetchfield('forum_mark_time');
1664 10018 rxu
        $db->sql_freeresult($result);
1665 10018 rxu
}
1666 10018 rxu
1667 7257 acydburn
// Only mark topic if it's currently unread. Also make sure we do not set topic tracking back if earlier pages are viewed.
1668 7257 acydburn
if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id] && $max_post_time > $topic_tracking_info[$topic_id])
1669 5272 acydburn
{
1670 9926 rxu
        markread('topic', (($topic_data['topic_type'] == POST_GLOBAL) ? 0 : $forum_id), $topic_id, $max_post_time);
1671 6256 acydburn
1672 6256 acydburn
        // Update forum info
1673 9926 rxu
        $all_marked_read = update_forum_tracking_info((($topic_data['topic_type'] == POST_GLOBAL) ? 0 : $forum_id), $topic_data['forum_last_post_time'], (isset($topic_data['forum_mark_time'])) ? $topic_data['forum_mark_time'] : false, false);
1674 5272 acydburn
}
1675 6320 acydburn
else
1676 6320 acydburn
{
1677 6320 acydburn
        $all_marked_read = true;
1678 6320 acydburn
}
1679 3953 psotfx
1680 6320 acydburn
// If there are absolutely no more unread posts in this forum and unread posts shown, we can savely show the #unread link
1681 7312 acydburn
if ($all_marked_read)
1682 6320 acydburn
{
1683 7312 acydburn
        if ($post_unread)
1684 7312 acydburn
        {
1685 7312 acydburn
                $template->assign_vars(array(
1686 7312 acydburn
                        'U_VIEW_UNREAD_POST'        => '#unread',
1687 7312 acydburn
                ));
1688 7312 acydburn
        }
1689 7312 acydburn
        else if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id])
1690 7312 acydburn
        {
1691 7312 acydburn
                $template->assign_vars(array(
1692 7312 acydburn
                        'U_VIEW_UNREAD_POST'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
1693 7312 acydburn
                ));
1694 7312 acydburn
        }
1695 6320 acydburn
}
1696 6320 acydburn
else if (!$all_marked_read)
1697 6320 acydburn
{
1698 6320 acydburn
        $last_page = ((floor($start / $config['posts_per_page']) + 1) == max(ceil($total_posts / $config['posts_per_page']), 1)) ? true : false;
1699 6320 acydburn
1700 6320 acydburn
        // What can happen is that we are at the last displayed page. If so, we also display the #unread link based in $post_unread
1701 6320 acydburn
        if ($last_page && $post_unread)
1702 6320 acydburn
        {
1703 6320 acydburn
                $template->assign_vars(array(
1704 6320 acydburn
                        'U_VIEW_UNREAD_POST'        => '#unread',
1705 6320 acydburn
                ));
1706 6320 acydburn
        }
1707 6320 acydburn
        else if (!$last_page)
1708 6320 acydburn
        {
1709 6320 acydburn
                $template->assign_vars(array(
1710 6320 acydburn
                        'U_VIEW_UNREAD_POST'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
1711 6320 acydburn
                ));
1712 6320 acydburn
        }
1713 6320 acydburn
}
1714 6320 acydburn
1715 9688 Kellanved
// let's set up quick_reply
1716 10414 rxu
$s_quick_reply = false;
1717 10414 rxu
if ($user->data['is_registered'] && $config['allow_quick_reply'] && ($topic_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) && $auth->acl_get('f_reply', $forum_id))
1718 10414 rxu
{
1719 10414 rxu
        // Quick reply enabled forum
1720 10414 rxu
        $s_quick_reply = (($topic_data['forum_status'] == ITEM_UNLOCKED && $topic_data['topic_status'] == ITEM_UNLOCKED) || $auth->acl_get('m_edit', $forum_id)) ? true : false;
1721 10414 rxu
}
1722 9798 acydburn
1723 9798 acydburn
if ($s_can_vote || $s_quick_reply)
1724 9688 Kellanved
{
1725 9688 Kellanved
        add_form_key('posting');
1726 9798 acydburn
1727 9691 Kellanved
        if ($s_quick_reply)
1728 9688 Kellanved
        {
1729 9798 acydburn
                $s_attach_sig        = $config['allow_sig'] && $user->optionget('attachsig') && $auth->acl_get('f_sigs', $forum_id) && $auth->acl_get('u_sig');
1730 9798 acydburn
                $s_smilies                = $config['allow_smilies'] && $user->optionget('smilies') && $auth->acl_get('f_smilies', $forum_id);
1731 9798 acydburn
                $s_bbcode                = $config['allow_bbcode'] && $user->optionget('bbcode') && $auth->acl_get('f_bbcode', $forum_id);
1732 10408 nickvergessen
                $s_notify                = $config['allow_topic_notify'] && ($user->data['user_notify'] || $s_watching_topic['is_watching']);
1733 9798 acydburn
1734 9688 Kellanved
                $qr_hidden_fields = array(
1735 9798 acydburn
                        'topic_cur_post_id'                => (int) $topic_data['topic_last_post_id'],
1736 9798 acydburn
                        'lastclick'                                => (int) time(),
1737 9798 acydburn
                        'topic_id'                                => (int) $topic_data['topic_id'],
1738 9798 acydburn
                        'forum_id'                                => (int) $forum_id,
1739 9688 Kellanved
                );
1740 9798 acydburn
1741 9798 acydburn
                // Originally we use checkboxes and check with isset(), so we only provide them if they would be checked
1742 9798 acydburn
                (!$s_bbcode)                                        ? $qr_hidden_fields['disable_bbcode'] = 1                : true;
1743 9798 acydburn
                (!$s_smilies)                                        ? $qr_hidden_fields['disable_smilies'] = 1                : true;
1744 9798 acydburn
                (!$config['allow_post_links'])        ? $qr_hidden_fields['disable_magic_url'] = 1        : true;
1745 9798 acydburn
                ($s_attach_sig)                                        ? $qr_hidden_fields['attach_sig'] = 1                        : true;
1746 9798 acydburn
                ($s_notify)                                                ? $qr_hidden_fields['notify'] = 1                                : true;
1747 10179 nickvergessen
                ($topic_data['topic_status'] == ITEM_LOCKED) ? $qr_hidden_fields['lock_topic'] = 1 : true;
1748 9798 acydburn
1749 9688 Kellanved
                $template->assign_vars(array(
1750 9798 acydburn
                        'S_QUICK_REPLY'                        => true,
1751 9688 Kellanved
                        'U_QR_ACTION'                        => append_sid("{$phpbb_root_path}posting.$phpEx", "mode=reply&amp;f=$forum_id&amp;t=$topic_id"),
1752 9688 Kellanved
                        'QR_HIDDEN_FIELDS'                => build_hidden_fields($qr_hidden_fields),
1753 9688 Kellanved
                        'SUBJECT'                                => 'Re: ' . censor_text($topic_data['topic_title']),
1754 9688 Kellanved
                ));
1755 9688 Kellanved
        }
1756 9688 Kellanved
}
1757 9693 Kellanved
// now I have the urge to wash my hands :(
1758 9798 acydburn
1759 9798 acydburn
1760 6364 acydburn
// We overwrite $_REQUEST['f'] if there is no forum specified
1761 6364 acydburn
// to be able to display the correct online list.
1762 6364 acydburn
// One downside is that the user currently viewing this topic/post is not taken into account.
1763 6364 acydburn
if (empty($_REQUEST['f']))
1764 6364 acydburn
{
1765 6364 acydburn
        $_REQUEST['f'] = $forum_id;
1766 6364 acydburn
}
1767 6364 acydburn
1768 10295 bantu
// We need to do the same with the topic_id. See #53025.
1769 10295 bantu
if (empty($_REQUEST['t']) && !empty($topic_id))
1770 10295 bantu
{
1771 10295 bantu
        $_REQUEST['t'] = $topic_id;
1772 10295 bantu
}
1773 10295 bantu
1774 2995 psotfx
// Output the page
1775 9961 Kellanved
page_header($user->lang['VIEW_TOPIC'] . ' - ' . $topic_data['topic_title'], true, $forum_id);
1776 2995 psotfx
1777 2995 psotfx
$template->set_filenames(array(
1778 4473 psotfx
        'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html')
1779 2995 psotfx
);
1780 6015 acydburn
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
1781 2995 psotfx
1782 3969 psotfx
page_footer();
1783 81 thefinn
1784 3286 psotfx
?>