phpBB
Statistics
| Revision:

root / tags / release_2_0_2 / phpBB / viewtopic.php

History | View | Annotate | Download (44.3 kB)

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