phpBB
Statistics
| Revision:

root / tags / release_2_0_1 / phpBB / viewtopic.php

History | View | Annotate | Download (44.3 kB)

1 2 thefinn
<?php
2 83 thefinn
/***************************************************************************
3 585 psotfx
 *                               viewtopic.php
4 83 thefinn
 *                            -------------------
5 83 thefinn
 *   begin                : Saturday, Feb 13, 2001
6 83 thefinn
 *   copyright            : (C) 2001 The phpBB Group
7 83 thefinn
 *   email                : support@phpbb.com
8 83 thefinn
 *
9 83 thefinn
 *   $Id$
10 83 thefinn
 *
11 83 thefinn
 *
12 83 thefinn
 ***************************************************************************/
13 2 thefinn
14 1008 thefinn
/***************************************************************************
15 1008 thefinn
 *
16 1008 thefinn
 *   This program is free software; you can redistribute it and/or modify
17 1008 thefinn
 *   it under the terms of the GNU General Public License as published by
18 1008 thefinn
 *   the Free Software Foundation; either version 2 of the License, or
19 1008 thefinn
 *   (at your option) any later version.
20 1008 thefinn
 *
21 1008 thefinn
 ***************************************************************************/
22 942 psotfx
23 2305 psotfx
define('IN_PHPBB', true);
24 2411 psotfx
$phpbb_root_path = './';
25 646 psotfx
include($phpbb_root_path . 'extension.inc');
26 646 psotfx
include($phpbb_root_path . 'common.'.$phpEx);
27 646 psotfx
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
28 2 thefinn
29 355 psotfx
//
30 355 psotfx
// Start initial var setup
31 355 psotfx
//
32 2411 psotfx
if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
33 89 psotfx
{
34 1147 psotfx
        $topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
35 89 psotfx
}
36 2411 psotfx
else if ( isset($HTTP_GET_VARS['topic']) )
37 1778 bartvb
{
38 1778 bartvb
        $topic_id = intval($HTTP_GET_VARS['topic']);
39 1778 bartvb
}
40 1778 bartvb
41 2411 psotfx
if ( isset($HTTP_GET_VARS[POST_POST_URL]))
42 370 psotfx
{
43 1147 psotfx
        $post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
44 370 psotfx
}
45 355 psotfx
46 1147 psotfx
$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
47 1215 dougk_ff7
48 2448 psotfx
if ( !isset($topic_id) && !isset($post_id) )
49 81 thefinn
{
50 1291 psotfx
        message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
51 81 thefinn
}
52 2 thefinn
53 541 psotfx
//
54 566 psotfx
// Find topic id if user requested a newer
55 566 psotfx
// or older topic
56 566 psotfx
//
57 2376 psotfx
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
58 301 thefinn
{
59 2376 psotfx
        if ( $HTTP_GET_VARS['view'] == 'newest' )
60 301 thefinn
        {
61 2448 psotfx
                $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
62 2448 psotfx
63 2376 psotfx
                if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) )
64 1093 psotfx
                {
65 2376 psotfx
                        $session_id = $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'];
66 1093 psotfx
67 2376 psotfx
                        if ( $session_id )
68 1093 psotfx
                        {
69 1511 psotfx
                                $sql = "SELECT p.post_id
70 1604 psotfx
                                        FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
71 1604 psotfx
                                        WHERE s.session_id = '$session_id'
72 1604 psotfx
                                                AND u.user_id = s.session_user_id
73 1604 psotfx
                                                AND p.topic_id = $topic_id
74 1604 psotfx
                                                AND p.post_time >= u.user_lastvisit
75 1511 psotfx
                                        ORDER BY p.post_time ASC
76 1511 psotfx
                                        LIMIT 1";
77 2376 psotfx
                                if ( !($result = $db->sql_query($sql)) )
78 1511 psotfx
                                {
79 2376 psotfx
                                        message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
80 1511 psotfx
                                }
81 1093 psotfx
82 2376 psotfx
                                if ( !($row = $db->sql_fetchrow($result)) )
83 1511 psotfx
                                {
84 1605 psotfx
                                        message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
85 1511 psotfx
                                }
86 2448 psotfx
87 2448 psotfx
                                $post_id = $row['post_id'];
88 2448 psotfx
                                header($header_location . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true));
89 2376 psotfx
                                exit;
90 1093 psotfx
                        }
91 1093 psotfx
                }
92 2448 psotfx
93 2448 psotfx
                header($header_location . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
94 2448 psotfx
                exit;
95 1093 psotfx
        }
96 2411 psotfx
        else if ( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
97 1093 psotfx
        {
98 2376 psotfx
                $sql_condition = ( $HTTP_GET_VARS['view'] == 'next' ) ? '>' : '<';
99 2376 psotfx
                $sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';
100 302 thefinn
101 2376 psotfx
                $sql = "SELECT t.topic_id
102 2376 psotfx
                        FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2
103 2376 psotfx
                        WHERE t2.topic_id = $topic_id
104 2376 psotfx
                                AND p2.post_id = t2.topic_last_post_id
105 2376 psotfx
                                AND t.forum_id = t2.forum_id
106 2376 psotfx
                                AND p.post_id = t.topic_last_post_id
107 2376 psotfx
                                AND p.post_time $sql_condition p2.post_time
108 2376 psotfx
                                AND p.topic_id = t.topic_id
109 2376 psotfx
                        ORDER BY p.post_time $sql_ordering
110 2376 psotfx
                        LIMIT 1";
111 2376 psotfx
                if ( !($result = $db->sql_query($sql)) )
112 2376 psotfx
                {
113 2411 psotfx
                        message_die(GENERAL_ERROR, "Could not obtain newer/older topic information", '', __LINE__, __FILE__, $sql);
114 2376 psotfx
                }
115 792 thefinn
116 2579 psotfx
                if ( $row = $db->sql_fetchrow($result) )
117 566 psotfx
                {
118 2579 psotfx
                        $topic_id = $row['topic_id'];
119 566 psotfx
                }
120 566 psotfx
                else
121 566 psotfx
                {
122 2579 psotfx
                        $message = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'No_newer_topics' : 'No_older_topics';
123 2579 psotfx
                        message_die(GENERAL_MESSAGE, $message);
124 566 psotfx
                }
125 566 psotfx
        }
126 301 thefinn
}
127 566 psotfx
128 301 thefinn
//
129 566 psotfx
// This rather complex gaggle of code handles querying for topics but
130 566 psotfx
// also allows for direct linking to a post (and the calculation of which
131 566 psotfx
// page the post is on and the correct display of viewtopic)
132 301 thefinn
//
133 2376 psotfx
$join_sql_table = ( !isset($post_id) ) ? '' : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 ";
134 1511 psotfx
$join_sql = ( !isset($post_id) ) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id";
135 2376 psotfx
$count_sql = ( !isset($post_id) ) ? '' : ", COUNT(p2.post_id) AS prev_posts";
136 87 psotfx
137 2572 psotfx
$order_sql = ( !isset($post_id) ) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC";
138 506 psotfx
139 2572 psotfx
$sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments" . $count_sql . "
140 1511 psotfx
        FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
141 1222 dougk_ff7
        WHERE $join_sql
142 1222 dougk_ff7
                AND f.forum_id = t.forum_id
143 1222 dougk_ff7
                $order_sql";
144 2411 psotfx
if ( !($result = $db->sql_query($sql)) )
145 83 thefinn
{
146 2411 psotfx
        message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
147 81 thefinn
}
148 355 psotfx
149 2572 psotfx
if ( !($forum_topic_data = $db->sql_fetchrow($result)) )
150 81 thefinn
{
151 2079 psotfx
        message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
152 81 thefinn
}
153 566 psotfx
154 2572 psotfx
$forum_id = $forum_topic_data['forum_id'];
155 143 psotfx
156 824 psotfx
//
157 824 psotfx
// Start session management
158 824 psotfx
//
159 1997 psotfx
$userdata = session_pagestart($user_ip, $forum_id);
160 824 psotfx
init_userprefs($userdata);
161 824 psotfx
//
162 824 psotfx
// End session management
163 824 psotfx
//
164 824 psotfx
165 143 psotfx
//
166 377 psotfx
// Start auth check
167 377 psotfx
//
168 1147 psotfx
$is_auth = array();
169 2572 psotfx
$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_topic_data);
170 377 psotfx
171 1619 psotfx
if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
172 377 psotfx
{
173 2079 psotfx
        if ( !$userdata['session_logged_in'] )
174 2079 psotfx
        {
175 2079 psotfx
                $redirect = ( isset($post_id) ) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
176 2411 psotfx
                $redirect .= ( isset($start) ) ? "&start=$start" : '';
177 2444 the_systech
                $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
178 2411 psotfx
                header($header_location . append_sid("login.$phpEx?redirect=viewtopic.$phpEx&$redirect", true));
179 2575 psotfx
                exit;
180 2079 psotfx
        }
181 421 thefinn
182 2079 psotfx
        $message = ( !$is_auth['auth_view'] ) ? $lang['Topic_post_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
183 2079 psotfx
184 1435 psotfx
        message_die(GENERAL_MESSAGE, $message);
185 377 psotfx
}
186 377 psotfx
//
187 377 psotfx
// End auth check
188 421 thefinn
//
189 377 psotfx
190 2572 psotfx
$forum_name = $forum_topic_data['forum_name'];
191 2572 psotfx
$topic_title = $forum_topic_data['topic_title'];
192 2572 psotfx
$topic_id = $forum_topic_data['topic_id'];
193 2572 psotfx
$topic_time = $forum_topic_data['topic_time'];
194 2079 psotfx
195 2079 psotfx
if ( !empty($post_id) )
196 2079 psotfx
{
197 2572 psotfx
        $start = floor(($forum_topic_data['prev_posts'] - 1) / $board_config['posts_per_page']) * $board_config['posts_per_page'];
198 2079 psotfx
}
199 2079 psotfx
200 431 psotfx
//
201 2110 psotfx
// Is user watching this thread?
202 862 psotfx
//
203 2110 psotfx
if( $userdata['session_logged_in'] )
204 862 psotfx
{
205 862 psotfx
        $can_watch_topic = TRUE;
206 862 psotfx
207 1008 thefinn
        $sql = "SELECT notify_status
208 1008 thefinn
                FROM " . TOPICS_WATCH_TABLE . "
209 1008 thefinn
                WHERE topic_id = $topic_id
210 862 psotfx
                        AND user_id = " . $userdata['user_id'];
211 2448 psotfx
        if ( !($result = $db->sql_query($sql)) )
212 862 psotfx
        {
213 2411 psotfx
                message_die(GENERAL_ERROR, "Could not obtain topic watch information", '', __LINE__, __FILE__, $sql);
214 862 psotfx
        }
215 2110 psotfx
216 2411 psotfx
        if ( $row = $db->sql_fetchrow($result) )
217 862 psotfx
        {
218 2411 psotfx
                if ( isset($HTTP_GET_VARS['unwatch']) )
219 862 psotfx
                {
220 2411 psotfx
                        if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
221 862 psotfx
                        {
222 862 psotfx
                                $is_watching_topic = 0;
223 862 psotfx
224 2411 psotfx
                                $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
225 1008 thefinn
                                $sql = "DELETE $sql_priority FROM " . TOPICS_WATCH_TABLE . "
226 1008 thefinn
                                        WHERE topic_id = $topic_id
227 862 psotfx
                                                AND user_id = " . $userdata['user_id'];
228 2411 psotfx
                                if ( !($result = $db->sql_query($sql)) )
229 862 psotfx
                                {
230 2411 psotfx
                                        message_die(GENERAL_ERROR, "Could not delete topic watch information", '', __LINE__, __FILE__, $sql);
231 862 psotfx
                                }
232 862 psotfx
                        }
233 1093 psotfx
234 1093 psotfx
                        $template->assign_vars(array(
235 2411 psotfx
                                'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
236 1093 psotfx
                        );
237 1093 psotfx
238 2110 psotfx
                        $message = $lang['No_longer_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">', '</a>');
239 1093 psotfx
                        message_die(GENERAL_MESSAGE, $message);
240 862 psotfx
                }
241 862 psotfx
                else
242 862 psotfx
                {
243 862 psotfx
                        $is_watching_topic = TRUE;
244 862 psotfx
245 2411 psotfx
                        if ( $row['notify_status'] )
246 862 psotfx
                        {
247 2411 psotfx
                                $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
248 1008 thefinn
                                $sql = "UPDATE $sql_priority " . TOPICS_WATCH_TABLE . "
249 1008 thefinn
                                        SET notify_status = 0
250 1008 thefinn
                                        WHERE topic_id = $topic_id
251 862 psotfx
                                                AND user_id = " . $userdata['user_id'];
252 2411 psotfx
                                if ( !($result = $db->sql_query($sql)) )
253 862 psotfx
                                {
254 2411 psotfx
                                        message_die(GENERAL_ERROR, "Could not update topic watch information", '', __LINE__, __FILE__, $sql);
255 862 psotfx
                                }
256 862 psotfx
                        }
257 862 psotfx
                }
258 862 psotfx
        }
259 862 psotfx
        else
260 862 psotfx
        {
261 2411 psotfx
                if ( isset($HTTP_GET_VARS['watch']) )
262 862 psotfx
                {
263 2411 psotfx
                        if ( $HTTP_GET_VARS['watch'] == 'topic' )
264 862 psotfx
                        {
265 862 psotfx
                                $is_watching_topic = TRUE;
266 862 psotfx
267 2411 psotfx
                                $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
268 1008 thefinn
                                $sql = "INSERT $sql_priority INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
269 862 psotfx
                                        VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
270 2411 psotfx
                                if ( !($result = $db->sql_query($sql)) )
271 862 psotfx
                                {
272 2411 psotfx
                                        message_die(GENERAL_ERROR, "Could not insert topic watch information", '', __LINE__, __FILE__, $sql);
273 862 psotfx
                                }
274 862 psotfx
                        }
275 1093 psotfx
276 1093 psotfx
                        $template->assign_vars(array(
277 2411 psotfx
                                'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
278 1093 psotfx
                        );
279 1093 psotfx
280 2110 psotfx
                        $message = $lang['You_are_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">', '</a>');
281 1093 psotfx
                        message_die(GENERAL_MESSAGE, $message);
282 862 psotfx
                }
283 862 psotfx
                else
284 862 psotfx
                {
285 862 psotfx
                        $is_watching_topic = 0;
286 862 psotfx
                }
287 862 psotfx
        }
288 862 psotfx
}
289 862 psotfx
else
290 862 psotfx
{
291 2411 psotfx
        if ( isset($HTTP_GET_VARS['unwatch']) )
292 866 psotfx
        {
293 2411 psotfx
                if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
294 866 psotfx
                {
295 2444 the_systech
                        $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
296 2411 psotfx
                        header($header_location . append_sid("login.$phpEx?redirect=viewtopic.$phpEx&" . POST_TOPIC_URL . "=$topic_id&unwatch=topic", true));
297 2575 psotfx
                        exit;
298 866 psotfx
                }
299 866 psotfx
        }
300 866 psotfx
        else
301 866 psotfx
        {
302 866 psotfx
                $can_watch_topic = 0;
303 866 psotfx
                $is_watching_topic = 0;
304 866 psotfx
        }
305 862 psotfx
}
306 862 psotfx
307 862 psotfx
//
308 770 psotfx
// Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed
309 770 psotfx
// then get it's value, find the number of topics with dates newer than it (to properly
310 770 psotfx
// handle pagination) and alter the main query
311 770 psotfx
//
312 770 psotfx
$previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
313 1332 psotfx
$previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
314 770 psotfx
315 1511 psotfx
if( !empty($HTTP_POST_VARS['postdays']) || !empty($HTTP_GET_VARS['postdays']) )
316 770 psotfx
{
317 1511 psotfx
        $post_days = ( !empty($HTTP_POST_VARS['postdays']) ) ? $HTTP_POST_VARS['postdays'] : $HTTP_GET_VARS['postdays'];
318 770 psotfx
        $min_post_time = time() - ($post_days * 86400);
319 770 psotfx
320 2564 psotfx
        $sql = "SELECT COUNT(p.post_id) AS num_posts
321 2564 psotfx
                FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
322 2564 psotfx
                WHERE t.topic_id = $topic_id
323 2564 psotfx
                        AND p.topic_id = t.topic_id
324 2564 psotfx
                        AND p.post_time >= $min_post_time";
325 2411 psotfx
        if ( !($result = $db->sql_query($sql)) )
326 770 psotfx
        {
327 2411 psotfx
                message_die(GENERAL_ERROR, "Could not obtain limited topics count information", '', __LINE__, __FILE__, $sql);
328 770 psotfx
        }
329 770 psotfx
330 987 psotfx
        $total_replies = ( $row = $db->sql_fetchrow($result) ) ? $row['num_posts'] : 0;
331 987 psotfx
332 770 psotfx
        $limit_posts_time = "AND p.post_time >= $min_post_time ";
333 770 psotfx
334 2411 psotfx
        if ( !empty($HTTP_POST_VARS['postdays']))
335 770 psotfx
        {
336 770 psotfx
                $start = 0;
337 770 psotfx
        }
338 770 psotfx
}
339 770 psotfx
else
340 770 psotfx
{
341 2572 psotfx
        $total_replies = $forum_topic_data['topic_replies'] + 1;
342 770 psotfx
343 2411 psotfx
        $limit_posts_time = '';
344 770 psotfx
        $post_days = 0;
345 770 psotfx
}
346 770 psotfx
347 2110 psotfx
$select_post_days = '<select name="postdays">';
348 770 psotfx
for($i = 0; $i < count($previous_days); $i++)
349 770 psotfx
{
350 1851 psotfx
        $selected = ($post_days == $previous_days[$i]) ? ' selected="selected"' : '';
351 2110 psotfx
        $select_post_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
352 770 psotfx
}
353 2110 psotfx
$select_post_days .= '</select>';
354 770 psotfx
355 770 psotfx
//
356 770 psotfx
// Decide how to order the post display
357 770 psotfx
//
358 2411 psotfx
if ( !empty($HTTP_POST_VARS['postorder']) || !empty($HTTP_GET_VARS['postorder']) )
359 770 psotfx
{
360 770 psotfx
        $post_order = (!empty($HTTP_POST_VARS['postorder'])) ? $HTTP_POST_VARS['postorder'] : $HTTP_GET_VARS['postorder'];
361 770 psotfx
        $post_time_order = ($post_order == "asc") ? "ASC" : "DESC";
362 770 psotfx
}
363 770 psotfx
else
364 770 psotfx
{
365 2411 psotfx
        $post_order = 'asc';
366 2411 psotfx
        $post_time_order = 'ASC';
367 770 psotfx
}
368 770 psotfx
369 2110 psotfx
$select_post_order = '<select name="postorder">';
370 2411 psotfx
if ( $post_time_order == 'ASC' )
371 770 psotfx
{
372 2110 psotfx
        $select_post_order .= '<option value="asc" selected="selected">' . $lang['Oldest_First'] . '</option><option value="desc">' . $lang['Newest_First'] . '</option>';
373 770 psotfx
}
374 770 psotfx
else
375 770 psotfx
{
376 2110 psotfx
        $select_post_order .= '<option value="asc">' . $lang['Oldest_First'] . '</option><option value="desc" selected="selected">' . $lang['Newest_First'] . '</option>';
377 770 psotfx
}
378 2110 psotfx
$select_post_order .= '</select>';
379 770 psotfx
380 770 psotfx
//
381 355 psotfx
// Go ahead and pull all data for this topic
382 355 psotfx
//
383 1647 psotfx
$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*,  pt.post_text, pt.post_subject, pt.bbcode_uid
384 566 psotfx
        FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
385 281 psotfx
        WHERE p.topic_id = $topic_id
386 792 thefinn
                $limit_posts_time
387 1851 psotfx
                AND pt.post_id = p.post_id
388 1851 psotfx
                AND u.user_id = p.poster_id
389 770 psotfx
        ORDER BY p.post_time $post_time_order
390 237 psotfx
        LIMIT $start, ".$board_config['posts_per_page'];
391 2334 psotfx
if ( !($result = $db->sql_query($sql)) )
392 81 thefinn
{
393 2411 psotfx
        message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
394 81 thefinn
}
395 566 psotfx
396 2334 psotfx
if ( $row = $db->sql_fetchrow($result) )
397 81 thefinn
{
398 2334 psotfx
        $postrow = array();
399 2334 psotfx
        do
400 2334 psotfx
        {
401 2334 psotfx
                $postrow[] = $row;
402 2334 psotfx
        }
403 2334 psotfx
        while ( $row = $db->sql_fetchrow($result) );
404 2334 psotfx
        $db->sql_freeresult($result);
405 2334 psotfx
406 2334 psotfx
        $total_posts = count($postrow);
407 2334 psotfx
}
408 2334 psotfx
else
409 2334 psotfx
{
410 1233 psotfx
        message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
411 81 thefinn
}
412 566 psotfx
413 136 psotfx
$sql = "SELECT *
414 566 psotfx
        FROM " . RANKS_TABLE . "
415 566 psotfx
        ORDER BY rank_special, rank_min";
416 2334 psotfx
if ( !($result = $db->sql_query($sql)) )
417 136 psotfx
{
418 2411 psotfx
        message_die(GENERAL_ERROR, "Could not obtain ranks information.", '', __LINE__, __FILE__, $sql);
419 136 psotfx
}
420 81 thefinn
421 2334 psotfx
$ranksrow = array();
422 2334 psotfx
while ( $row = $db->sql_fetchrow($result) )
423 2334 psotfx
{
424 2334 psotfx
        $ranksrow[] = $row;
425 2334 psotfx
}
426 2334 psotfx
$db->sql_freeresult($result);
427 2334 psotfx
428 237 psotfx
//
429 884 psotfx
// Define censored word matches
430 880 psotfx
//
431 987 psotfx
$orig_word = array();
432 987 psotfx
$replacement_word = array();
433 987 psotfx
obtain_word_list($orig_word, $replacement_word);
434 880 psotfx
435 880 psotfx
//
436 1830 psotfx
// Censor topic title
437 1830 psotfx
//
438 2411 psotfx
if ( count($orig_word) )
439 1830 psotfx
{
440 1830 psotfx
        $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
441 1830 psotfx
}
442 1830 psotfx
443 1830 psotfx
//
444 1830 psotfx
// Was a highlight request part of the URI? Yes, this idea was
445 1830 psotfx
// taken from vB but we did already have a highlighter in place
446 1830 psotfx
// in search itself ... it's just been extended a bit!
447 1830 psotfx
//
448 2411 psotfx
if ( isset($HTTP_GET_VARS['highlight']) )
449 1830 psotfx
{
450 1830 psotfx
        $highlight_match = array();
451 1830 psotfx
452 1830 psotfx
        //
453 1830 psotfx
        // Split words and phrases
454 1830 psotfx
        //
455 2411 psotfx
        $words = explode(' ', trim(urldecode($HTTP_GET_VARS['highlight'])));
456 1830 psotfx
457 1830 psotfx
        for($i = 0; $i < count($words); $i++)
458 1830 psotfx
        {
459 2411 psotfx
                if ( trim($words[$i]) != '' )
460 1830 psotfx
                {
461 2448 psotfx
                        $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $words[$i]) . ')\b#is';
462 1830 psotfx
                }
463 1830 psotfx
        }
464 1830 psotfx
465 1830 psotfx
        $highlight_active = ( count($highlight_match) ) ? true : false;
466 1830 psotfx
}
467 1830 psotfx
else
468 1830 psotfx
{
469 1830 psotfx
        $highlight_active = false;
470 1830 psotfx
}
471 1830 psotfx
472 1830 psotfx
//
473 1452 bartvb
// Post, reply and other URL generation for
474 1452 bartvb
// templating vars
475 1452 bartvb
//
476 1452 bartvb
$new_topic_url = append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id");
477 1452 bartvb
$reply_topic_url = append_sid("posting.$phpEx?mode=reply&amp;" . POST_TOPIC_URL . "=$topic_id");
478 1452 bartvb
$view_forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id");
479 1452 bartvb
$view_prev_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=previous");
480 1452 bartvb
$view_next_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=next");
481 1452 bartvb
482 1452 bartvb
//
483 1452 bartvb
// Mozilla navigation bar
484 1452 bartvb
//
485 1452 bartvb
$nav_links['prev'] = array(
486 1452 bartvb
        'url' => $view_prev_topic_url,
487 1452 bartvb
        'title' => $lang['View_previous_topic']
488 1452 bartvb
);
489 1452 bartvb
$nav_links['next'] = array(
490 1452 bartvb
        'url' => $view_next_topic_url,
491 1452 bartvb
        'title' => $lang['View_next_topic']
492 1452 bartvb
);
493 1452 bartvb
$nav_links['up'] = array(
494 1452 bartvb
        'url' => $view_forum_url,
495 1452 bartvb
        'title' => $forum_name
496 1452 bartvb
);
497 1452 bartvb
498 2572 psotfx
$reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
499 2572 psotfx
$reply_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
500 2572 psotfx
$post_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'];
501 2572 psotfx
$post_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
502 1452 bartvb
503 1452 bartvb
//
504 1851 psotfx
// Set a cookie for this topic
505 355 psotfx
//
506 2411 psotfx
if ( $userdata['session_logged_in'] )
507 1511 psotfx
{
508 2411 psotfx
        $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
509 2411 psotfx
        $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
510 1161 psotfx
511 2411 psotfx
        if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
512 1997 psotfx
        {
513 2411 psotfx
                $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
514 1997 psotfx
        }
515 2411 psotfx
        else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
516 1997 psotfx
        {
517 2411 psotfx
                $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
518 1997 psotfx
        }
519 1997 psotfx
        else
520 1997 psotfx
        {
521 1997 psotfx
                $topic_last_read = $userdata['user_lastvisit'];
522 1997 psotfx
        }
523 1851 psotfx
524 2448 psotfx
        if ( count($tracking_topics) >= 150 && empty($tracking_topics[$topic_id]) )
525 1997 psotfx
        {
526 1997 psotfx
                asort($tracking_topics);
527 1997 psotfx
                unset($tracking_topics[key($tracking_topics)]);
528 1997 psotfx
        }
529 1851 psotfx
530 2411 psotfx
        $tracking_topics[$topic_id] = time();
531 1851 psotfx
532 2448 psotfx
        setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
533 1997 psotfx
}
534 1997 psotfx
535 1511 psotfx
//
536 1511 psotfx
// Load templates
537 1511 psotfx
//
538 355 psotfx
$template->set_filenames(array(
539 2448 psotfx
        'body' => 'viewtopic_body.tpl')
540 355 psotfx
);
541 2448 psotfx
make_jumpbox('viewforum.'.$phpEx, $forum_id);
542 566 psotfx
543 1851 psotfx
//
544 1851 psotfx
// Output page header
545 1851 psotfx
//
546 2411 psotfx
$page_title = $lang['View_topic'] .' - ' . $topic_title;
547 1851 psotfx
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
548 1851 psotfx
549 1851 psotfx
//
550 1851 psotfx
// User authorisation levels output
551 1851 psotfx
//
552 2411 psotfx
$s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['Rules_post_can'] : $lang['Rules_post_cannot'] ) . '<br />';
553 2411 psotfx
$s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot'] ) . '<br />';
554 2411 psotfx
$s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot'] ) . '<br />';
555 2411 psotfx
$s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot'] ) . '<br />';
556 2411 psotfx
$s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot'] ) . '<br />';
557 1851 psotfx
558 2411 psotfx
if ( $is_auth['auth_mod'] )
559 1851 psotfx
{
560 1851 psotfx
        $s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="' . append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
561 1851 psotfx
562 1851 psotfx
        $topic_mod = '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=delete") . '"><img src="' . $images['topic_mod_delete'] . '" alt="' . $lang['Delete_topic'] . '" title="' . $lang['Delete_topic'] . '" border="0" /></a>&nbsp;';
563 1851 psotfx
564 1851 psotfx
        $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=move"). '"><img src="' . $images['topic_mod_move'] . '" alt="' . $lang['Move_topic'] . '" title="' . $lang['Move_topic'] . '" border="0" /></a>&nbsp;';
565 1851 psotfx
566 2572 psotfx
        $topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=lock") . '"><img src="' . $images['topic_mod_lock'] . '" alt="' . $lang['Lock_topic'] . '" title="' . $lang['Lock_topic'] . '" border="0" /></a>&nbsp;' : '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=unlock") . '"><img src="' . $images['topic_mod_unlock'] . '" alt="' . $lang['Unlock_topic'] . '" title="' . $lang['Unlock_topic'] . '" border="0" /></a>&nbsp;';
567 1851 psotfx
568 1851 psotfx
        $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=split") . '"><img src="' . $images['topic_mod_split'] . '" alt="' . $lang['Split_topic'] . '" title="' . $lang['Split_topic'] . '" border="0" /></a>&nbsp;';
569 1851 psotfx
}
570 1851 psotfx
571 1851 psotfx
//
572 1851 psotfx
// Topic watch information
573 1851 psotfx
//
574 2411 psotfx
$s_watching_topic = '';
575 2411 psotfx
if ( $can_watch_topic )
576 1851 psotfx
{
577 2411 psotfx
        if ( $is_watching_topic )
578 1851 psotfx
        {
579 1851 psotfx
                $s_watching_topic = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start") . '">' . $lang['Stop_watching_topic'] . '</a>';
580 1997 psotfx
                $s_watching_topic_img = ( isset($images['Topic_un_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start") . '"><img src="' . $images['Topic_un_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Stop_watching_topic'] . '" border="0"></a>' : '';
581 1851 psotfx
        }
582 1851 psotfx
        else
583 1851 psotfx
        {
584 1851 psotfx
                $s_watching_topic = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start") . '">' . $lang['Start_watching_topic'] . '</a>';
585 1997 psotfx
                $s_watching_topic_img = ( isset($images['Topic_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start") . '"><img src="' . $images['Topic_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Start_watching_topic'] . '" border="0"></a>' : '';
586 1851 psotfx
        }
587 1851 psotfx
}
588 1851 psotfx
589 1851 psotfx
//
590 1851 psotfx
// If we've got a hightlight set pass it on to pagination,
591 1851 psotfx
// I get annoyed when I lose my highlight after the first page.
592 1851 psotfx
//
593 1851 psotfx
$pagination = ( $highlight_active ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=" . $HTTP_GET_VARS['highlight'], $total_replies, $board_config['posts_per_page'], $start) : generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order", $total_replies, $board_config['posts_per_page'], $start);
594 1851 psotfx
595 1851 psotfx
//
596 1851 psotfx
// Send vars to template
597 1851 psotfx
//
598 355 psotfx
$template->assign_vars(array(
599 2411 psotfx
        'FORUM_ID' => $forum_id,
600 2411 psotfx
    'FORUM_NAME' => $forum_name,
601 2411 psotfx
    'TOPIC_ID' => $topic_id,
602 2411 psotfx
    'TOPIC_TITLE' => $topic_title,
603 2411 psotfx
        'PAGINATION' => $pagination,
604 2411 psotfx
        'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['posts_per_page'] ) + 1 ), ceil( $total_replies / $board_config['posts_per_page'] )),
605 770 psotfx
606 2448 psotfx
        'POST_IMG' => $post_img,
607 2448 psotfx
        'REPLY_IMG' => $reply_img,
608 770 psotfx
609 2448 psotfx
        'L_AUTHOR' => $lang['Author'],
610 2448 psotfx
        'L_MESSAGE' => $lang['Message'],
611 2448 psotfx
        'L_POSTED' => $lang['Posted'],
612 2411 psotfx
        'L_POST_SUBJECT' => $lang['Post_subject'],
613 2411 psotfx
        'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],
614 2411 psotfx
        'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],
615 2411 psotfx
        'L_POST_NEW_TOPIC' => $post_alt,
616 2411 psotfx
        'L_POST_REPLY_TOPIC' => $reply_alt,
617 2411 psotfx
        'L_BACK_TO_TOP' => $lang['Back_to_top'],
618 2411 psotfx
        'L_DISPLAY_POSTS' => $lang['Display_posts'],
619 2411 psotfx
        'L_LOCK_TOPIC' => $lang['Lock_topic'],
620 2411 psotfx
        'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
621 2411 psotfx
        'L_MOVE_TOPIC' => $lang['Move_topic'],
622 2411 psotfx
        'L_SPLIT_TOPIC' => $lang['Split_topic'],
623 2411 psotfx
        'L_DELETE_TOPIC' => $lang['Delete_topic'],
624 2411 psotfx
        'L_GOTO_PAGE' => $lang['Goto_page'],
625 1578 bartvb
626 2411 psotfx
        'S_TOPIC_LINK' => POST_TOPIC_URL,
627 2411 psotfx
        'S_SELECT_POST_DAYS' => $select_post_days,
628 2411 psotfx
        'S_SELECT_POST_ORDER' => $select_post_order,
629 2411 psotfx
        'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&amp;start=$start"),
630 2411 psotfx
        'S_AUTH_LIST' => $s_auth_can,
631 2411 psotfx
        'S_TOPIC_ADMIN' => $topic_mod,
632 2411 psotfx
        'S_WATCH_TOPIC' => $s_watching_topic,
633 659 psotfx
634 2411 psotfx
        'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=" . $HTTP_GET_VARS['highlight']),
635 2411 psotfx
        'U_VIEW_FORUM' => $view_forum_url,
636 2411 psotfx
        'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,
637 2411 psotfx
        'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,
638 2411 psotfx
        'U_POST_NEW_TOPIC' => $new_topic_url,
639 2411 psotfx
        'U_POST_REPLY_TOPIC' => $reply_topic_url)
640 579 psotfx
);
641 237 psotfx
642 237 psotfx
//
643 1851 psotfx
// Does this topic contain a poll?
644 1830 psotfx
//
645 2572 psotfx
if ( !empty($forum_topic_data['topic_vote']) )
646 987 psotfx
{
647 1008 thefinn
        $sql = "SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result
648 1008 thefinn
                FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
649 1008 thefinn
                WHERE vd.topic_id = $topic_id
650 1008 thefinn
                        AND vr.vote_id = vd.vote_id
651 987 psotfx
                ORDER BY vr.vote_option_id ASC";
652 2411 psotfx
        if ( !($result = $db->sql_query($sql)) )
653 987 psotfx
        {
654 2411 psotfx
                message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql);
655 987 psotfx
        }
656 987 psotfx
657 2411 psotfx
        if ( $vote_info = $db->sql_fetchrowset($result) )
658 987 psotfx
        {
659 2415 psotfx
                $db->sql_freeresult($result);
660 2415 psotfx
                $vote_options = count($vote_info);
661 2415 psotfx
662 2117 psotfx
                $vote_id = $vote_info[0]['vote_id'];
663 2117 psotfx
                $vote_title = $vote_info[0]['vote_text'];
664 987 psotfx
665 1008 thefinn
                $sql = "SELECT vote_id
666 1008 thefinn
                        FROM " . VOTE_USERS_TABLE . "
667 2117 psotfx
                        WHERE vote_id = $vote_id
668 987 psotfx
                                AND vote_user_id = " . $userdata['user_id'];
669 2411 psotfx
                if ( !($result = $db->sql_query($sql)) )
670 987 psotfx
                {
671 2411 psotfx
                        message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql);
672 987 psotfx
                }
673 987 psotfx
674 2415 psotfx
                $user_voted = ( $row = $db->sql_fetchrow($result) ) ? TRUE : 0;
675 2415 psotfx
                $db->sql_freeresult($result);
676 987 psotfx
677 2411 psotfx
                if ( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
678 987 psotfx
                {
679 2411 psotfx
                        $view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == 'viewresult' ) ? TRUE : 0;
680 987 psotfx
                }
681 987 psotfx
                else
682 987 psotfx
                {
683 987 psotfx
                        $view_result = 0;
684 987 psotfx
                }
685 987 psotfx
686 2117 psotfx
                $poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
687 987 psotfx
688 2572 psotfx
                if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
689 987 psotfx
                {
690 2117 psotfx
                        $template->set_filenames(array(
691 2411 psotfx
                                'pollbox' => 'viewtopic_poll_result.tpl')
692 2117 psotfx
                        );
693 2117 psotfx
694 987 psotfx
                        $vote_results_sum = 0;
695 2117 psotfx
696 987 psotfx
                        for($i = 0; $i < $vote_options; $i++)
697 987 psotfx
                        {
698 987 psotfx
                                $vote_results_sum += $vote_info[$i]['vote_result'];
699 987 psotfx
                        }
700 987 psotfx
701 987 psotfx
                        $vote_graphic = 0;
702 987 psotfx
                        $vote_graphic_max = count($images['voting_graphic']);
703 987 psotfx
704 2117 psotfx
                        for($i = 0; $i < $vote_options; $i++)
705 987 psotfx
                        {
706 2117 psotfx
                                $vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
707 2117 psotfx
                                $vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);
708 987 psotfx
709 2117 psotfx
                                $vote_graphic_img = $images['voting_graphic'][$vote_graphic];
710 2117 psotfx
                                $vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;
711 2117 psotfx
712 2411 psotfx
                                if ( count($orig_word) )
713 2117 psotfx
                                {
714 2117 psotfx
                                        $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
715 2117 psotfx
                                }
716 2117 psotfx
717 987 psotfx
                                $template->assign_block_vars("poll_option", array(
718 2411 psotfx
                                        'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
719 2411 psotfx
                                        'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
720 2411 psotfx
                                        'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
721 987 psotfx
722 2411 psotfx
                                        'POLL_OPTION_IMG' => $vote_graphic_img,
723 2411 psotfx
                                        'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
724 987 psotfx
                                );
725 987 psotfx
                        }
726 987 psotfx
727 987 psotfx
                        $template->assign_vars(array(
728 2411 psotfx
                                'L_TOTAL_VOTES' => $lang['Total_votes'],
729 2411 psotfx
                                'TOTAL_VOTES' => $vote_results_sum)
730 987 psotfx
                        );
731 987 psotfx
732 987 psotfx
                }
733 987 psotfx
                else
734 987 psotfx
                {
735 987 psotfx
                        $template->set_filenames(array(
736 2411 psotfx
                                'pollbox' => 'viewtopic_poll_ballot.tpl')
737 987 psotfx
                        );
738 987 psotfx
739 2117 psotfx
                        for($i = 0; $i < $vote_options; $i++)
740 987 psotfx
                        {
741 2411 psotfx
                                if ( count($orig_word) )
742 2117 psotfx
                                {
743 2117 psotfx
                                        $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
744 2117 psotfx
                                }
745 2117 psotfx
746 987 psotfx
                                $template->assign_block_vars("poll_option", array(
747 2411 psotfx
                                        'POLL_OPTION_ID' => $vote_info[$i]['vote_option_id'],
748 2411 psotfx
                                        'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'])
749 987 psotfx
                                );
750 987 psotfx
                        }
751 987 psotfx
752 987 psotfx
                        $template->assign_vars(array(
753 2411 psotfx
                                'L_SUBMIT_VOTE' => $lang['Submit_vote'],
754 2411 psotfx
                                'L_VIEW_RESULTS' => $lang['View_results'],
755 1008 thefinn
756 2411 psotfx
                                'U_VIEW_RESULTS' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;vote=viewresult"))
757 987 psotfx
                        );
758 987 psotfx
759 987 psotfx
                        $s_hidden_fields = '<input type="hidden" name="topic_id" value="' . $topic_id . '"><input type="hidden" name="mode" value="vote">';
760 987 psotfx
                }
761 987 psotfx
762 2411 psotfx
                if ( count($orig_word) )
763 2117 psotfx
                {
764 2117 psotfx
                        $vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
765 2117 psotfx
                }
766 2117 psotfx
767 987 psotfx
                $template->assign_vars(array(
768 2411 psotfx
                        'POLL_QUESTION' => $vote_title,
769 1008 thefinn
770 2411 psotfx
                        'S_HIDDEN_FIELDS' => ( !empty($s_hidden_fields) ) ? $s_hidden_fields : '',
771 2448 psotfx
                        'S_POLL_ACTION' => append_sid("posting.$phpEx?" . POST_TOPIC_URL . "=$topic_id"))
772 987 psotfx
                );
773 987 psotfx
774 2411 psotfx
                $template->assign_var_from_handle('POLL_DISPLAY', 'pollbox');
775 987 psotfx
        }
776 987 psotfx
}
777 987 psotfx
778 987 psotfx
//
779 355 psotfx
// Update the topic view counter
780 321 thefinn
//
781 566 psotfx
$sql = "UPDATE " . TOPICS_TABLE . "
782 421 thefinn
        SET topic_views = topic_views + 1
783 355 psotfx
        WHERE topic_id = $topic_id";
784 2411 psotfx
if ( !$db->sql_query($sql) )
785 355 psotfx
{
786 2411 psotfx
        message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
787 355 psotfx
}
788 321 thefinn
789 321 thefinn
//
790 237 psotfx
// Okay, let's do the loop, yeah come on baby let's do the loop
791 237 psotfx
// and it goes like this ...
792 237 psotfx
//
793 566 psotfx
for($i = 0; $i < $total_posts; $i++)
794 81 thefinn
{
795 566 psotfx
        $poster_id = $postrow[$i]['user_id'];
796 2415 psotfx
        $poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];
797 462 psotfx
798 1010 bartvb
        $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
799 462 psotfx
800 2411 psotfx
        $poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : '';
801 462 psotfx
802 2411 psotfx
        $poster_from = ( $postrow[$i]['user_from'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Location'] . ': ' . $postrow[$i]['user_from'] : '';
803 462 psotfx
804 2411 psotfx
        $poster_joined = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Joined'] . ': ' . create_date($lang['DATE_FORMAT'], $postrow[$i]['user_regdate'], $board_config['board_timezone']) : '';
805 462 psotfx
806 2411 psotfx
        $poster_avatar = '';
807 2411 psotfx
        if ( $postrow[$i]['user_avatar_type'] && $poster_id != ANONYMOUS && $postrow[$i]['user_allowavatar'] )
808 136 psotfx
        {
809 1173 psotfx
                switch( $postrow[$i]['user_avatar_type'] )
810 1173 psotfx
                {
811 1173 psotfx
                        case USER_AVATAR_UPLOAD:
812 2411 psotfx
                                $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
813 1173 psotfx
                                break;
814 1173 psotfx
                        case USER_AVATAR_REMOTE:
815 1930 psotfx
                                $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
816 1173 psotfx
                                break;
817 1173 psotfx
                        case USER_AVATAR_GALLERY:
818 2411 psotfx
                                $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
819 1173 psotfx
                                break;
820 1173 psotfx
                }
821 566 psotfx
        }
822 566 psotfx
823 566 psotfx
        //
824 1093 psotfx
        // Define the little post icon
825 1093 psotfx
        //
826 2411 psotfx
        if ( $userdata['session_logged_in'] && $postrow[$i]['post_time'] > $userdata['user_lastvisit'] && $postrow[$i]['post_time'] > $topic_last_read )
827 1093 psotfx
        {
828 2448 psotfx
                $mini_post_img = $images['icon_minipost_new'];
829 2448 psotfx
                $mini_post_alt = $lang['New_post'];
830 1093 psotfx
        }
831 1093 psotfx
        else
832 1093 psotfx
        {
833 2448 psotfx
                $mini_post_img = $images['icon_minipost'];
834 2448 psotfx
                $mini_post_alt = $lang['Post'];
835 1093 psotfx
        }
836 1578 bartvb
837 2411 psotfx
        $mini_post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#' . $postrow[$i]['post_id'];
838 1093 psotfx
839 1093 psotfx
        //
840 2448 psotfx
        // Generate ranks, set them to empty string initially.
841 566 psotfx
        //
842 1830 psotfx
        $poster_rank = '';
843 1830 psotfx
        $rank_image = '';
844 2411 psotfx
        if ( $postrow[$i]['user_id'] == ANONYMOUS )
845 566 psotfx
        {
846 566 psotfx
        }
847 2411 psotfx
        else if ( $postrow[$i]['user_rank'] )
848 566 psotfx
        {
849 566 psotfx
                for($j = 0; $j < count($ranksrow); $j++)
850 136 psotfx
                {
851 2411 psotfx
                        if ( $postrow[$i]['user_rank'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special'] )
852 136 psotfx
                        {
853 987 psotfx
                                $poster_rank = $ranksrow[$j]['rank_title'];
854 1830 psotfx
                                $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
855 136 psotfx
                        }
856 136 psotfx
                }
857 431 psotfx
        }
858 792 thefinn
        else
859 431 psotfx
        {
860 566 psotfx
                for($j = 0; $j < count($ranksrow); $j++)
861 136 psotfx
                {
862 2411 psotfx
                        if ( $postrow[$i]['user_posts'] >= $ranksrow[$j]['rank_min'] && !$ranksrow[$j]['rank_special'] )
863 281 psotfx
                        {
864 987 psotfx
                                $poster_rank = $ranksrow[$j]['rank_title'];
865 1830 psotfx
                                $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
866 281 psotfx
                        }
867 136 psotfx
                }
868 136 psotfx
        }
869 136 psotfx
870 566 psotfx
        //
871 463 thefinn
        // Handle anon users posting with usernames
872 566 psotfx
        //
873 2411 psotfx
        if ( $poster_id == ANONYMOUS && $postrow[$i]['post_username'] != '' )
874 463 thefinn
        {
875 987 psotfx
                $poster = $postrow[$i]['post_username'];
876 463 thefinn
                $poster_rank = $lang['Guest'];
877 463 thefinn
        }
878 463 thefinn
879 2448 psotfx
        $temp_url = '';
880 2448 psotfx
881 2411 psotfx
        if ( $poster_id != ANONYMOUS )
882 613 psotfx
        {
883 2448 psotfx
                $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
884 2448 psotfx
                $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
885 2448 psotfx
                $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
886 462 psotfx
887 2448 psotfx
                $temp_url = append_sid("privmsg.$phpEx?mode=post&amp;" . POST_USERS_URL . "=$poster_id");
888 2448 psotfx
                $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
889 2448 psotfx
                $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
890 566 psotfx
891 2411 psotfx
                if ( !empty($postrow[$i]['user_viewemail']) || $is_auth['auth_mod'] )
892 1320 psotfx
                {
893 2411 psotfx
                        $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&amp;" . POST_USERS_URL .'=' . $poster_id) : 'mailto:' . $postrow[$i]['user_email'];
894 1320 psotfx
895 1830 psotfx
                        $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
896 2448 psotfx
                        $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
897 1320 psotfx
                }
898 1320 psotfx
                else
899 1320 psotfx
                {
900 1830 psotfx
                        $email_img = '';
901 2448 psotfx
                        $email = '';
902 1320 psotfx
                }
903 1320 psotfx
904 2448 psotfx
                $www_img = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww"><img src="' . $images['icon_www'] . '" alt="' . $lang['Visit_website'] . '" title="' . $lang['Visit_website'] . '" border="0" /></a>' : '';
905 2448 psotfx
                $www = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
906 462 psotfx
907 2411 psotfx
                if ( !empty($postrow[$i]['user_icq']) )
908 613 psotfx
                {
909 1898 psotfx
                        $icq_status_img = '<a href="http://wwp.icq.com/' . $postrow[$i]['user_icq'] . '#pager"><img src="http://web.icq.com/whitepages/online?icq=' . $postrow[$i]['user_icq'] . '&img=5" width="18" height="18" border="0" /></a>';
910 2448 psotfx
                        $icq_img = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '"><img src="' . $images['icon_icq'] . '" alt="' . $lang['ICQ'] . '" title="' . $lang['ICQ'] . '" border="0" /></a>';
911 2448 psotfx
                        $icq =  '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '">' . $lang['ICQ'] . '</a>';
912 613 psotfx
                }
913 613 psotfx
                else
914 613 psotfx
                {
915 1830 psotfx
                        $icq_status_img = '';
916 2448 psotfx
                        $icq_img = '';
917 2448 psotfx
                        $icq = '';
918 613 psotfx
                }
919 462 psotfx
920 1830 psotfx
                $aim_img = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?"><img src="' . $images['icon_aim'] . '" alt="' . $lang['AIM'] . '" title="' . $lang['AIM'] . '" border="0" /></a>' : '';
921 2448 psotfx
                $aim = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
922 613 psotfx
923 2448 psotfx
                $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
924 2448 psotfx
                $msn_img = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
925 2448 psotfx
                $msn = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
926 613 psotfx
927 1830 psotfx
                $yim_img = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&amp;.src=pg"><img src="' . $images['icon_yim'] . '" alt="' . $lang['YIM'] . '" title="' . $lang['YIM'] . '" border="0" /></a>' : '';
928 2448 psotfx
                $yim = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&amp;.src=pg">' . $lang['YIM'] . '</a>' : '';
929 87 psotfx
        }
930 87 psotfx
        else
931 87 psotfx
        {
932 1830 psotfx
                $profile_img = '';
933 2448 psotfx
                $profile = '';
934 1830 psotfx
                $pm_img = '';
935 2448 psotfx
                $pm = '';
936 1830 psotfx
                $email_img = '';
937 2448 psotfx
                $email = '';
938 1830 psotfx
                $www_img = '';
939 2448 psotfx
                $www = '';
940 1830 psotfx
                $icq_status_img = '';
941 2448 psotfx
                $icq_img = '';
942 2448 psotfx
                $icq = '';
943 1830 psotfx
                $aim_img = '';
944 2448 psotfx
                $aim = '';
945 1830 psotfx
                $msn_img = '';
946 2448 psotfx
                $msn = '';
947 1830 psotfx
                $yim_img = '';
948 2448 psotfx
                $yim = '';
949 87 psotfx
        }
950 303 thefinn
951 2448 psotfx
        $temp_url = append_sid("posting.$phpEx?mode=quote&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
952 2448 psotfx
        $quote_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_quote'] . '" alt="' . $lang['Reply_with_quote'] . '" title="' . $lang['Reply_with_quote'] . '" border="0" /></a>';
953 2448 psotfx
        $quote = '<a href="' . $temp_url . '">' . $lang['Reply_with_quote'] . '</a>';
954 987 psotfx
955 2448 psotfx
        $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($postrow[$i]['username']) . "&amp;showresults=posts");
956 2448 psotfx
        $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . $lang['Search_user_posts'] . '" title="' . $lang['Search_user_posts'] . '" border="0" /></a>';
957 2448 psotfx
        $search = '<a href="' . $temp_url . '">' . $lang['Search_user_posts'] . '</a>';
958 462 psotfx
959 2411 psotfx
        if ( ( $userdata['user_id'] == $poster_id && $is_auth['auth_edit'] ) || $is_auth['auth_mod'] )
960 987 psotfx
        {
961 2448 psotfx
                $temp_url = append_sid("posting.$phpEx?mode=editpost&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
962 2448 psotfx
                $edit_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_edit'] . '" alt="' . $lang['Edit_delete_post'] . '" title="' . $lang['Edit_delete_post'] . '" border="0" /></a>';
963 2448 psotfx
                $edit = '<a href="' . $temp_url . '">' . $lang['Edit_delete_post'] . '</a>';
964 987 psotfx
        }
965 987 psotfx
        else
966 987 psotfx
        {
967 1830 psotfx
                $edit_img = '';
968 2448 psotfx
                $edit = '';
969 987 psotfx
        }
970 303 thefinn
971 2411 psotfx
        if ( $is_auth['auth_mod'] )
972 87 psotfx
        {
973 2448 psotfx
                $temp_url = append_sid("modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;" . POST_TOPIC_URL . "=" . $topic_id);
974 2448 psotfx
                $ip_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_ip'] . '" alt="' . $lang['View_IP'] . '" title="' . $lang['View_IP'] . '" border="0" /></a>';
975 2448 psotfx
                $ip = '<a href="' . $temp_url . '">' . $lang['View_IP'] . '</a>';
976 462 psotfx
977 2448 psotfx
                $temp_url = append_sid("posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
978 2448 psotfx
                $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
979 2448 psotfx
                $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
980 87 psotfx
        }
981 987 psotfx
        else
982 987 psotfx
        {
983 1830 psotfx
                $ip_img = '';
984 2448 psotfx
                $ip = '';
985 1161 psotfx
986 2572 psotfx
                if ( $userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $forum_topic_data['topic_last_post_id'] == $postrow[$i]['post_id'] )
987 1161 psotfx
                {
988 2448 psotfx
                        $temp_url = append_sid("posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
989 2448 psotfx
                        $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
990 2490 psotfx
                        $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
991 1161 psotfx
                }
992 1161 psotfx
                else
993 1161 psotfx
                {
994 1830 psotfx
                        $delpost_img = '';
995 2448 psotfx
                        $delpost = '';
996 1161 psotfx
                }
997 987 psotfx
        }
998 1008 thefinn
999 2411 psotfx
        $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : '';
1000 1083 psotfx
1001 987 psotfx
        $message = $postrow[$i]['post_text'];
1002 566 psotfx
        $bbcode_uid = $postrow[$i]['bbcode_uid'];
1003 462 psotfx
1004 2411 psotfx
        $user_sig = ( $postrow[$i]['enable_sig'] && $postrow[$i]['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow[$i]['user_sig'] : '';
1005 1083 psotfx
        $user_sig_bbcode_uid = $postrow[$i]['user_sig_bbcode_uid'];
1006 134 thefinn
1007 987 psotfx
        //
1008 2448 psotfx
        // Note! The order used for parsing the message _is_ important, moving things around could break any
1009 1511 psotfx
        // output
1010 1511 psotfx
        //
1011 1511 psotfx
1012 1511 psotfx
        //
1013 987 psotfx
        // If the board has HTML off but the post has HTML
1014 987 psotfx
        // on then we process it, else leave it alone
1015 987 psotfx
        //
1016 2411 psotfx
        if ( !$board_config['allow_html'] )
1017 87 psotfx
        {
1018 2411 psotfx
                if ( $user_sig != '' && $userdata['user_allowhtml'] )
1019 673 psotfx
                {
1020 2411 psotfx
                        $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
1021 673 psotfx
                }
1022 987 psotfx
1023 2411 psotfx
                if ( $postrow[$i]['enable_html'] )
1024 987 psotfx
                {
1025 2411 psotfx
                        $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
1026 987 psotfx
                }
1027 87 psotfx
        }
1028 566 psotfx
1029 1511 psotfx
        //
1030 1647 psotfx
        // Parse message and/or sig for BBCode if reqd
1031 1511 psotfx
        //
1032 2411 psotfx
        if ( $board_config['allow_bbcode'] )
1033 87 psotfx
        {
1034 2411 psotfx
                if ( $user_sig != '' && $user_sig_bbcode_uid != '' )
1035 1647 psotfx
                {
1036 2411 psotfx
                        $user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
1037 1647 psotfx
                }
1038 303 thefinn
1039 2411 psotfx
                if ( $bbcode_uid != '' )
1040 1647 psotfx
                {
1041 2411 psotfx
                        $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
1042 1647 psotfx
                }
1043 836 psotfx
        }
1044 303 thefinn
1045 2566 psotfx
        if ( $user_sig != '' )
1046 1649 psotfx
        {
1047 1649 psotfx
                $user_sig = make_clickable($user_sig);
1048 1649 psotfx
        }
1049 1555 natec
        $message = make_clickable($message);
1050 1566 psotfx
1051 1511 psotfx
        //
1052 2066 psotfx
        // Highlight active words (primarily for search)
1053 2066 psotfx
        //
1054 2411 psotfx
        if ( $highlight_active )
1055 2066 psotfx
        {
1056 2448 psotfx
                if ( preg_match('/<.*>/', $message) )
1057 2448 psotfx
                {
1058 2448 psotfx
                        $message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message);
1059 2448 psotfx
1060 2448 psotfx
                        $end_html = 0;
1061 2448 psotfx
                        $start_html = 1;
1062 2448 psotfx
                        $temp_message = '';
1063 2448 psotfx
                        $message = ' ' . $message . ' ';
1064 2448 psotfx
1065 2448 psotfx
                        while( $start_html = strpos($message, '<', $start_html) )
1066 2448 psotfx
                        {
1067 2448 psotfx
                                $grab_length = $start_html - $end_html - 1;
1068 2448 psotfx
                                $temp_message .= substr($message, $end_html + 1, $grab_length);
1069 2448 psotfx
1070 2448 psotfx
                                if ( $end_html = strpos($message, '>', $start_html) )
1071 2448 psotfx
                                {
1072 2448 psotfx
                                        $length = $end_html - $start_html + 1;
1073 2448 psotfx
                                        $hold_string = substr($message, $start_html, $length);
1074 2448 psotfx
1075 2448 psotfx
                                        if ( strrpos(' ' . $hold_string, '<') != 1 )
1076 2448 psotfx
                                        {
1077 2448 psotfx
                                                $end_html = $start_html + 1;
1078 2448 psotfx
                                                $end_counter = 1;
1079 2448 psotfx
1080 2448 psotfx
                                                while ( $end_counter && $end_html < strlen($message) )
1081 2448 psotfx
                                                {
1082 2448 psotfx
                                                        if ( substr($message, $end_html, 1) == '>' )
1083 2448 psotfx
                                                        {
1084 2448 psotfx
                                                                $end_counter--;
1085 2448 psotfx
                                                        }
1086 2448 psotfx
                                                        else if ( substr($message, $end_html, 1) == '<' )
1087 2448 psotfx
                                                        {
1088 2448 psotfx
                                                                $end_counter++;
1089 2448 psotfx
                                                        }
1090 2448 psotfx
1091 2448 psotfx
                                                        $end_html++;
1092 2448 psotfx
                                                }
1093 2448 psotfx
1094 2448 psotfx
                                                $length = $end_html - $start_html + 1;
1095 2448 psotfx
                                                $hold_string = substr($message, $start_html, $length);
1096 2448 psotfx
                                                $hold_string = str_replace('<!-- #sh -->', '', $hold_string);
1097 2448 psotfx
                                                $hold_string = str_replace('<!-- #eh -->', '', $hold_string);
1098 2448 psotfx
                                        }
1099 2448 psotfx
                                        else if ( $hold_string == '<!-- #sh -->' )
1100 2448 psotfx
                                        {
1101 2448 psotfx
                                                $hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string);
1102 2448 psotfx
                                        }
1103 2448 psotfx
                                        else if ( $hold_string == '<!-- #eh -->' )
1104 2448 psotfx
                                        {
1105 2448 psotfx
                                                $hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string);
1106 2448 psotfx
                                        }
1107 2448 psotfx
1108 2448 psotfx
                                        $temp_message .= $hold_string;
1109 2448 psotfx
1110 2448 psotfx
                                        $start_html += $length;
1111 2448 psotfx
                                }
1112 2448 psotfx
                                else
1113 2448 psotfx
                                {
1114 2448 psotfx
                                        $start_html = strlen($message);
1115 2448 psotfx
                                }
1116 2448 psotfx
                        }
1117 2448 psotfx
1118 2448 psotfx
                        $grab_length = strlen($message) - $end_html - 1;
1119 2448 psotfx
                        $temp_message .= substr($message, $end_html + 1, $grab_length);
1120 2448 psotfx
1121 2448 psotfx
                        $message = trim($temp_message);
1122 2448 psotfx
                }
1123 2448 psotfx
                else
1124 2448 psotfx
                {
1125 2448 psotfx
                        $message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message);
1126 2448 psotfx
                }
1127 2066 psotfx
        }
1128 2066 psotfx
1129 2066 psotfx
        //
1130 1511 psotfx
        // Replace naughty words
1131 1511 psotfx
        //
1132 2411 psotfx
        if ( count($orig_word) )
1133 884 psotfx
        {
1134 2411 psotfx
                if ( $user_sig != '' )
1135 1647 psotfx
                {
1136 1647 psotfx
                        $user_sig = preg_replace($orig_word, $replacement_word, $user_sig);
1137 1647 psotfx
                }
1138 1649 psotfx
1139 1649 psotfx
                $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
1140 1649 psotfx
                $message = preg_replace($orig_word, $replacement_word, $message);
1141 884 psotfx
        }
1142 884 psotfx
1143 1511 psotfx
        //
1144 1511 psotfx
        // Parse smilies
1145 1511 psotfx
        //
1146 2411 psotfx
        if ( $board_config['allow_smilies'] )
1147 744 psotfx
        {
1148 2411 psotfx
                if ( $postrow[$i]['user_allowsmile'] && $user_sig != '' )
1149 1647 psotfx
                {
1150 1649 psotfx
                        $user_sig = smilies_pass($user_sig);
1151 1647 psotfx
                }
1152 1647 psotfx
1153 2411 psotfx
                if ( $postrow[$i]['enable_smilies'] )
1154 1647 psotfx
                {
1155 1649 psotfx
                        $message = smilies_pass($message);
1156 1647 psotfx
                }
1157 744 psotfx
        }
1158 744 psotfx
1159 1511 psotfx
        //
1160 1511 psotfx
        // Replace newlines (we use this rather than nl2br because
1161 1511 psotfx
        // till recently it wasn't XHTML compliant)
1162 1511 psotfx
        //
1163 2411 psotfx
        if ( $user_sig != '' )
1164 1647 psotfx
        {
1165 2448 psotfx
                $user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
1166 1647 psotfx
        }
1167 1647 psotfx
1168 1649 psotfx
        $message = str_replace("\n", "\n<br />\n", $message);
1169 1649 psotfx
1170 355 psotfx
        //
1171 673 psotfx
        // Editing information
1172 673 psotfx
        //
1173 2411 psotfx
        if ( $postrow[$i]['post_edit_count'] )
1174 673 psotfx
        {
1175 1247 psotfx
                $l_edit_time_total = ( $postrow[$i]['post_edit_count'] == 1 ) ? $lang['Edited_time_total'] : $lang['Edited_times_total'];
1176 1247 psotfx
1177 2411 psotfx
                $l_edited_by = '<br /><br />' . sprintf($l_edit_time_total, $poster, create_date($board_config['default_dateformat'], $postrow[$i]['post_edit_time'], $board_config['board_timezone']), $postrow[$i]['post_edit_count']);
1178 673 psotfx
        }
1179 1248 psotfx
        else
1180 1248 psotfx
        {
1181 2411 psotfx
                $l_edited_by = '';
1182 1248 psotfx
        }
1183 673 psotfx
1184 673 psotfx
        //
1185 355 psotfx
        // Again this will be handled by the templating
1186 355 psotfx
        // code at some point
1187 355 psotfx
        //
1188 824 psotfx
        $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1189 770 psotfx
        $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1190 303 thefinn
1191 2411 psotfx
        $template->assign_block_vars('postrow', array(
1192 2411 psotfx
                'ROW_COLOR' => '#' . $row_color,
1193 2411 psotfx
                'ROW_CLASS' => $row_class,
1194 2411 psotfx
                'POSTER_NAME' => $poster,
1195 2411 psotfx
                'POSTER_RANK' => $poster_rank,
1196 2411 psotfx
                'RANK_IMAGE' => $rank_image,
1197 2411 psotfx
                'POSTER_JOINED' => $poster_joined,
1198 2411 psotfx
                'POSTER_POSTS' => $poster_posts,
1199 2411 psotfx
                'POSTER_FROM' => $poster_from,
1200 2411 psotfx
                'POSTER_AVATAR' => $poster_avatar,
1201 2411 psotfx
                'POST_DATE' => $post_date,
1202 2411 psotfx
                'POST_SUBJECT' => $post_subject,
1203 2411 psotfx
                'MESSAGE' => $message,
1204 2411 psotfx
                'SIGNATURE' => $user_sig,
1205 2411 psotfx
                'EDITED_MESSAGE' => $l_edited_by,
1206 1247 psotfx
1207 2448 psotfx
                'MINI_POST_IMG' => $mini_post_img,
1208 2448 psotfx
                'PROFILE_IMG' => $profile_img,
1209 2448 psotfx
                'PROFILE' => $profile,
1210 2411 psotfx
                'SEARCH_IMG' => $search_img,
1211 2448 psotfx
                'SEARCH' => $search,
1212 2411 psotfx
                'PM_IMG' => $pm_img,
1213 2448 psotfx
                'PM' => $pm,
1214 2411 psotfx
                'EMAIL_IMG' => $email_img,
1215 2448 psotfx
                'EMAIL' => $email,
1216 2411 psotfx
                'WWW_IMG' => $www_img,
1217 2448 psotfx
                'WWW' => $www,
1218 2411 psotfx
                'ICQ_STATUS_IMG' => $icq_status_img,
1219 2448 psotfx
                'ICQ_IMG' => $icq_img,
1220 2448 psotfx
                'ICQ' => $icq,
1221 2411 psotfx
                'AIM_IMG' => $aim_img,
1222 2448 psotfx
                'AIM' => $aim,
1223 2411 psotfx
                'MSN_IMG' => $msn_img,
1224 2448 psotfx
                'MSN' => $msn,
1225 2411 psotfx
                'YIM_IMG' => $yim_img,
1226 2448 psotfx
                'YIM' => $yim,
1227 2411 psotfx
                'EDIT_IMG' => $edit_img,
1228 2448 psotfx
                'EDIT' => $edit,
1229 2411 psotfx
                'QUOTE_IMG' => $quote_img,
1230 2448 psotfx
                'QUOTE' => $quote,
1231 2411 psotfx
                'IP_IMG' => $ip_img,
1232 2448 psotfx
                'IP' => $ip,
1233 2411 psotfx
                'DELETE_IMG' => $delpost_img,
1234 2448 psotfx
                'DELETE' => $delpost,
1235 462 psotfx
1236 2448 psotfx
                'L_MINI_POST_ALT' => $mini_post_alt,
1237 2448 psotfx
1238 2411 psotfx
                'U_MINI_POST' => $mini_post_url,
1239 2411 psotfx
                'U_POST_ID' => $postrow[$i]['post_id'])
1240 566 psotfx
        );
1241 81 thefinn
}
1242 82 thefinn
1243 2411 psotfx
$template->pparse('body');
1244 105 natec
1245 646 psotfx
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1246 81 thefinn
1247 2448 psotfx
?>