]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2/viewforum.php
Baseline
[www.vanrenterghem.biz.git] / phpBB2 / viewforum.php
1 <?php
2 /***************************************************************************
3  *                               viewforum.php
4  *                            -------------------
5  *   begin                : Saturday, Feb 13, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: viewforum.php,v 1.139.2.13 2006/12/16 13:11:25 acydburn Exp $
10  *
11  *
12  ***************************************************************************/
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  ***************************************************************************/
23 define('IN_PHPBB', true);
24 $phpbb_root_path = './';
25 include($phpbb_root_path . 'extension.inc');
26 include($phpbb_root_path . 'common.'.$phpEx);
28 //
29 // Start initial var setup
30 //
31 if ( isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]) )
32 {
33         $forum_id = ( isset($HTTP_GET_VARS[POST_FORUM_URL]) ) ? intval($HTTP_GET_VARS[POST_FORUM_URL]) : intval($HTTP_POST_VARS[POST_FORUM_URL]);
34 }
35 else if ( isset($HTTP_GET_VARS['forum']))
36 {
37         $forum_id = intval($HTTP_GET_VARS['forum']);
38 }
39 else
40 {
41         $forum_id = '';
42 }
44 $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
45 $start = ($start < 0) ? 0 : $start;
47 if ( isset($HTTP_GET_VARS['mark']) || isset($HTTP_POST_VARS['mark']) )
48 {
49         $mark_read = (isset($HTTP_POST_VARS['mark'])) ? $HTTP_POST_VARS['mark'] : $HTTP_GET_VARS['mark'];
50 }
51 else
52 {
53         $mark_read = '';
54 }
55 //
56 // End initial var setup
57 //
59 //
60 // Check if the user has actually sent a forum ID with his/her request
61 // If not give them a nice error page.
62 //
63 if ( !empty($forum_id) )
64 {
65         $sql = "SELECT *
66                 FROM " . FORUMS_TABLE . "
67                 WHERE forum_id = $forum_id";
68         if ( !($result = $db->sql_query($sql)) )
69         {
70                 message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
71         }
72 }
73 else
74 {
75         message_die(GENERAL_MESSAGE, 'Forum_not_exist');
76 }
78 //
79 // If the query doesn't return any rows this isn't a valid forum. Inform
80 // the user.
81 //
82 if ( !($forum_row = $db->sql_fetchrow($result)) )
83 {
84         message_die(GENERAL_MESSAGE, 'Forum_not_exist');
85 }
87 //
88 // Start session management
89 //
90 $userdata = session_pagestart($user_ip, $forum_id);
91 init_userprefs($userdata);
92 //
93 // End session management
94 //
96 //
97 // Start auth check
98 //
99 $is_auth = array();
100 $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_row);
102 if ( !$is_auth['auth_read'] || !$is_auth['auth_view'] )
104         if ( !$userdata['session_logged_in'] )
105         {
106                 $redirect = POST_FORUM_URL . "=$forum_id" . ( ( isset($start) ) ? "&start=$start" : '' );
107                 redirect(append_sid("login.$phpEx?redirect=viewforum.$phpEx&$redirect", true));
108         }
109         //
110         // The user is not authed to read this forum ...
111         //
112         $message = ( !$is_auth['auth_view'] ) ? $lang['Forum_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
114         message_die(GENERAL_MESSAGE, $message);
116 //
117 // End of auth check
118 //
120 //
121 // Handle marking posts
122 //
123 if ( $mark_read == 'topics' )
125         if ( $userdata['session_logged_in'] )
126         {
127                 $sql = "SELECT MAX(post_time) AS last_post 
128                         FROM " . POSTS_TABLE . " 
129                         WHERE forum_id = $forum_id";
130                 if ( !($result = $db->sql_query($sql)) )
131                 {
132                         message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
133                 }
135                 if ( $row = $db->sql_fetchrow($result) )
136                 {
137                         $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
138                         $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
140                         if ( ( count($tracking_forums) + count($tracking_topics) ) >= 150 && empty($tracking_forums[$forum_id]) )
141                         {
142                                 asort($tracking_forums);
143                                 unset($tracking_forums[key($tracking_forums)]);
144                         }
146                         if ( $row['last_post'] > $userdata['user_lastvisit'] )
147                         {
148                                 $tracking_forums[$forum_id] = time();
150                                 setcookie($board_config['cookie_name'] . '_f', serialize($tracking_forums), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
151                         }
152                 }
154                 $template->assign_vars(array(
155                         'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">')
156                 );
157         }
159         $message = $lang['Topics_marked_read'] . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a> ');
160         message_die(GENERAL_MESSAGE, $message);
162 //
163 // End handle marking posts
164 //
166 $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : '';
167 $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : '';
169 //
170 // Do the forum Prune
171 //
172 if ( $is_auth['auth_mod'] && $board_config['prune_enable'] )
174         if ( $forum_row['prune_next'] < time() && $forum_row['prune_enable'] )
175         {
176                 include($phpbb_root_path . 'includes/prune.'.$phpEx);
177                 require($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
178                 auto_prune($forum_id);
179         }
181 //
182 // End of forum prune
183 //
185 //
186 // Obtain list of moderators of each forum
187 // First users, then groups ... broken into two queries
188 //
189 $sql = "SELECT u.user_id, u.username 
190         FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g, " . USERS_TABLE . " u
191         WHERE aa.forum_id = $forum_id 
192                 AND aa.auth_mod = " . TRUE . " 
193                 AND g.group_single_user = 1
194                 AND ug.group_id = aa.group_id 
195                 AND g.group_id = aa.group_id 
196                 AND u.user_id = ug.user_id 
197         GROUP BY u.user_id, u.username  
198         ORDER BY u.user_id";
199 if ( !($result = $db->sql_query($sql)) )
201         message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
204 $moderators = array();
205 while( $row = $db->sql_fetchrow($result) )
207         $moderators[] = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $row['user_id']) . '">' . $row['username'] . '</a>';
210 $sql = "SELECT g.group_id, g.group_name 
211         FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g 
212         WHERE aa.forum_id = $forum_id
213                 AND aa.auth_mod = " . TRUE . " 
214                 AND g.group_single_user = 0
215                 AND g.group_type <> ". GROUP_HIDDEN ."
216                 AND ug.group_id = aa.group_id 
217                 AND g.group_id = aa.group_id 
218         GROUP BY g.group_id, g.group_name  
219         ORDER BY g.group_id";
220 if ( !($result = $db->sql_query($sql)) )
222         message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
225 while( $row = $db->sql_fetchrow($result) )
227         $moderators[] = '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $row['group_id']) . '">' . $row['group_name'] . '</a>';
229         
230 $l_moderators = ( count($moderators) == 1 ) ? $lang['Moderator'] : $lang['Moderators'];
231 $forum_moderators = ( count($moderators) ) ? implode(', ', $moderators) : $lang['None'];
232 unset($moderators);
234 //
235 // Generate a 'Show topics in previous x days' select box. If the topicsdays var is sent
236 // then get it's value, find the number of topics with dates newer than it (to properly
237 // handle pagination) and alter the main query
238 //
239 $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
240 $previous_days_text = array($lang['All_Topics'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
242 if ( !empty($HTTP_POST_VARS['topicdays']) || !empty($HTTP_GET_VARS['topicdays']) )
244         $topic_days = ( !empty($HTTP_POST_VARS['topicdays']) ) ? intval($HTTP_POST_VARS['topicdays']) : intval($HTTP_GET_VARS['topicdays']);
245         $min_topic_time = time() - ($topic_days * 86400);
247         $sql = "SELECT COUNT(t.topic_id) AS forum_topics 
248                 FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p 
249                 WHERE t.forum_id = $forum_id 
250                         AND p.post_id = t.topic_last_post_id
251                         AND p.post_time >= $min_topic_time"; 
253         if ( !($result = $db->sql_query($sql)) )
254         {
255                 message_die(GENERAL_ERROR, 'Could not obtain limited topics count information', '', __LINE__, __FILE__, $sql);
256         }
257         $row = $db->sql_fetchrow($result);
259         $topics_count = ( $row['forum_topics'] ) ? $row['forum_topics'] : 1;
260         $limit_topics_time = "AND p.post_time >= $min_topic_time";
262         if ( !empty($HTTP_POST_VARS['topicdays']) )
263         {
264                 $start = 0;
265         }
267 else
269         $topics_count = ( $forum_row['forum_topics'] ) ? $forum_row['forum_topics'] : 1;
271         $limit_topics_time = '';
272         $topic_days = 0;
275 $select_topic_days = '<select name="topicdays">';
276 for($i = 0; $i < count($previous_days); $i++)
278         $selected = ($topic_days == $previous_days[$i]) ? ' selected="selected"' : '';
279         $select_topic_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
281 $select_topic_days .= '</select>';
284 //
285 // All announcement data, this keeps announcements
286 // on each viewforum page ...
287 //
288 $sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username
289         FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2
290         WHERE t.forum_id = $forum_id 
291                 AND t.topic_poster = u.user_id
292                 AND p.post_id = t.topic_last_post_id
293                 AND p.poster_id = u2.user_id
294                 AND t.topic_type = " . POST_ANNOUNCE . " 
295         ORDER BY t.topic_last_post_id DESC ";
296 if ( !($result = $db->sql_query($sql)) )
298    message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
301 $topic_rowset = array();
302 $total_announcements = 0;
303 while( $row = $db->sql_fetchrow($result) )
305         $topic_rowset[] = $row;
306         $total_announcements++;
309 $db->sql_freeresult($result);
311 //
312 // Grab all the basic data (all topics except announcements)
313 // for this forum
314 //
315 $sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time 
316         FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
317         WHERE t.forum_id = $forum_id
318                 AND t.topic_poster = u.user_id
319                 AND p.post_id = t.topic_first_post_id
320                 AND p2.post_id = t.topic_last_post_id
321                 AND u2.user_id = p2.poster_id 
322                 AND t.topic_type <> " . POST_ANNOUNCE . " 
323                 $limit_topics_time
324         ORDER BY t.topic_type DESC, t.topic_last_post_id DESC 
325         LIMIT $start, ".$board_config['topics_per_page'];
326 if ( !($result = $db->sql_query($sql)) )
328    message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
331 $total_topics = 0;
332 while( $row = $db->sql_fetchrow($result) )
334         $topic_rowset[] = $row;
335         $total_topics++;
338 $db->sql_freeresult($result);
340 //
341 // Total topics ...
342 //
343 $total_topics += $total_announcements;
345 //
346 // Define censored word matches
347 //
348 $orig_word = array();
349 $replacement_word = array();
350 obtain_word_list($orig_word, $replacement_word);
352 //
353 // Post URL generation for templating vars
354 //
355 $template->assign_vars(array(
356         'L_DISPLAY_TOPICS' => $lang['Display_topics'],
358         'U_POST_NEW_TOPIC' => append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id"),
360         'S_SELECT_TOPIC_DAYS' => $select_topic_days,
361         'S_POST_DAYS_ACTION' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $forum_id . "&amp;start=$start"))
362 );
364 //
365 // User authorisation levels output
366 //
367 $s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['Rules_post_can'] : $lang['Rules_post_cannot'] ) . '<br />';
368 $s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot'] ) . '<br />';
369 $s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot'] ) . '<br />';
370 $s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot'] ) . '<br />';
371 $s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot'] ) . '<br />';
373 if ( $is_auth['auth_mod'] )
375         $s_auth_can .= sprintf($lang['Rules_moderate'], "<a href=\"modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;start=" . $start . "&amp;sid=" . $userdata['session_id'] . '">', '</a>');
378 //
379 // Mozilla navigation bar
380 //
381 $nav_links['up'] = array(
382         'url' => append_sid('index.'.$phpEx),
383         'title' => sprintf($lang['Forum_Index'], $board_config['sitename'])
384 );
386 //
387 // Dump out the page header and load viewforum template
388 //
389 define('SHOW_ONLINE', true);
390 $page_title = $lang['View_forum'] . ' - ' . $forum_row['forum_name'];
391 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
393 $template->set_filenames(array(
394         'body' => 'viewforum_body.tpl')
395 );
396 make_jumpbox('viewforum.'.$phpEx);
398 $template->assign_vars(array(
399         'FORUM_ID' => $forum_id,
400         'FORUM_NAME' => $forum_row['forum_name'],
401         'MODERATORS' => $forum_moderators,
402         'POST_IMG' => ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'],
404         'FOLDER_IMG' => $images['folder'],
405         'FOLDER_NEW_IMG' => $images['folder_new'],
406         'FOLDER_HOT_IMG' => $images['folder_hot'],
407         'FOLDER_HOT_NEW_IMG' => $images['folder_hot_new'],
408         'FOLDER_LOCKED_IMG' => $images['folder_locked'],
409         'FOLDER_LOCKED_NEW_IMG' => $images['folder_locked_new'],
410         'FOLDER_STICKY_IMG' => $images['folder_sticky'],
411         'FOLDER_STICKY_NEW_IMG' => $images['folder_sticky_new'],
412         'FOLDER_ANNOUNCE_IMG' => $images['folder_announce'],
413         'FOLDER_ANNOUNCE_NEW_IMG' => $images['folder_announce_new'],
415         'L_TOPICS' => $lang['Topics'],
416         'L_REPLIES' => $lang['Replies'],
417         'L_VIEWS' => $lang['Views'],
418         'L_POSTS' => $lang['Posts'],
419         'L_LASTPOST' => $lang['Last_Post'], 
420         'L_MODERATOR' => $l_moderators, 
421         'L_MARK_TOPICS_READ' => $lang['Mark_all_topics'], 
422         'L_POST_NEW_TOPIC' => ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'], 
423         'L_NO_NEW_POSTS' => $lang['No_new_posts'],
424         'L_NEW_POSTS' => $lang['New_posts'],
425         'L_NO_NEW_POSTS_LOCKED' => $lang['No_new_posts_locked'], 
426         'L_NEW_POSTS_LOCKED' => $lang['New_posts_locked'], 
427         'L_NO_NEW_POSTS_HOT' => $lang['No_new_posts_hot'],
428         'L_NEW_POSTS_HOT' => $lang['New_posts_hot'],
429         'L_ANNOUNCEMENT' => $lang['Post_Announcement'], 
430         'L_STICKY' => $lang['Post_Sticky'], 
431         'L_POSTED' => $lang['Posted'],
432         'L_JOINED' => $lang['Joined'],
433         'L_AUTHOR' => $lang['Author'],
435         'S_AUTH_LIST' => $s_auth_can, 
437         'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL ."=$forum_id"),
439         'U_MARK_READ' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;mark=topics"))
440 );
441 //
442 // End header
443 //
445 //
446 // Okay, lets dump out the page ...
447 //
448 if( $total_topics )
450         for($i = 0; $i < $total_topics; $i++)
451         {
452                 $topic_id = $topic_rowset[$i]['topic_id'];
454                 $topic_title = ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $topic_rowset[$i]['topic_title']) : $topic_rowset[$i]['topic_title'];
456                 $replies = $topic_rowset[$i]['topic_replies'];
458                 $topic_type = $topic_rowset[$i]['topic_type'];
460                 if( $topic_type == POST_ANNOUNCE )
461                 {
462                         $topic_type = $lang['Topic_Announcement'] . ' ';
463                 }
464                 else if( $topic_type == POST_STICKY )
465                 {
466                         $topic_type = $lang['Topic_Sticky'] . ' ';
467                 }
468                 else
469                 {
470                         $topic_type = '';               
471                 }
473                 if( $topic_rowset[$i]['topic_vote'] )
474                 {
475                         $topic_type .= $lang['Topic_Poll'] . ' ';
476                 }
477                 
478                 if( $topic_rowset[$i]['topic_status'] == TOPIC_MOVED )
479                 {
480                         $topic_type = $lang['Topic_Moved'] . ' ';
481                         $topic_id = $topic_rowset[$i]['topic_moved_id'];
483                         $folder_image =  $images['folder'];
484                         $folder_alt = $lang['Topics_Moved'];
485                         $newest_post_img = '';
486                 }
487                 else
488                 {
489                         if( $topic_rowset[$i]['topic_type'] == POST_ANNOUNCE )
490                         {
491                                 $folder = $images['folder_announce'];
492                                 $folder_new = $images['folder_announce_new'];
493                         }
494                         else if( $topic_rowset[$i]['topic_type'] == POST_STICKY )
495                         {
496                                 $folder = $images['folder_sticky'];
497                                 $folder_new = $images['folder_sticky_new'];
498                         }
499                         else if( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED )
500                         {
501                                 $folder = $images['folder_locked'];
502                                 $folder_new = $images['folder_locked_new'];
503                         }
504                         else
505                         {
506                                 if($replies >= $board_config['hot_threshold'])
507                                 {
508                                         $folder = $images['folder_hot'];
509                                         $folder_new = $images['folder_hot_new'];
510                                 }
511                                 else
512                                 {
513                                         $folder = $images['folder'];
514                                         $folder_new = $images['folder_new'];
515                                 }
516                         }
518                         $newest_post_img = '';
519                         if( $userdata['session_logged_in'] )
520                         {
521                                 if( $topic_rowset[$i]['post_time'] > $userdata['user_lastvisit'] ) 
522                                 {
523                                         if( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
524                                         {
525                                                 $unread_topics = true;
527                                                 if( !empty($tracking_topics[$topic_id]) )
528                                                 {
529                                                         if( $tracking_topics[$topic_id] >= $topic_rowset[$i]['post_time'] )
530                                                         {
531                                                                 $unread_topics = false;
532                                                         }
533                                                 }
535                                                 if( !empty($tracking_forums[$forum_id]) )
536                                                 {
537                                                         if( $tracking_forums[$forum_id] >= $topic_rowset[$i]['post_time'] )
538                                                         {
539                                                                 $unread_topics = false;
540                                                         }
541                                                 }
543                                                 if( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
544                                                 {
545                                                         if( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] >= $topic_rowset[$i]['post_time'] )
546                                                         {
547                                                                 $unread_topics = false;
548                                                         }
549                                                 }
551                                                 if( $unread_topics )
552                                                 {
553                                                         $folder_image = $folder_new;
554                                                         $folder_alt = $lang['New_posts'];
556                                                         $newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
557                                                 }
558                                                 else
559                                                 {
560                                                         $folder_image = $folder;
561                                                         $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
563                                                         $newest_post_img = '';
564                                                 }
565                                         }
566                                         else
567                                         {
568                                                 $folder_image = $folder_new;
569                                                 $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['New_posts'];
571                                                 $newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
572                                         }
573                                 }
574                                 else 
575                                 {
576                                         $folder_image = $folder;
577                                         $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
579                                         $newest_post_img = '';
580                                 }
581                         }
582                         else
583                         {
584                                 $folder_image = $folder;
585                                 $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
587                                 $newest_post_img = '';
588                         }
589                 }
591                 if( ( $replies + 1 ) > $board_config['posts_per_page'] )
592                 {
593                         $total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] );
594                         $goto_page = ' [ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['Goto_page'] . '" title="' . $lang['Goto_page'] . '" />' . $lang['Goto_page'] . ': ';
596                         $times = 1;
597                         for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page'])
598                         {
599                                 $goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&amp;start=$j") . '">' . $times . '</a>';
600                                 if( $times == 1 && $total_pages > 4 )
601                                 {
602                                         $goto_page .= ' ... ';
603                                         $times = $total_pages - 3;
604                                         $j += ( $total_pages - 4 ) * $board_config['posts_per_page'];
605                                 }
606                                 else if ( $times < $total_pages )
607                                 {
608                                         $goto_page .= ', ';
609                                 }
610                                 $times++;
611                         }
612                         $goto_page .= ' ] ';
613                 }
614                 else
615                 {
616                         $goto_page = '';
617                 }
618                 
619                 $view_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");
621                 $topic_author = ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $topic_rowset[$i]['user_id']) . '">' : '';
622                 $topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? $topic_rowset[$i]['username'] : ( ( $topic_rowset[$i]['post_username'] != '' ) ? $topic_rowset[$i]['post_username'] : $lang['Guest'] );
624                 $topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';
626                 $first_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['topic_time'], $board_config['board_timezone']);
628                 $last_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['post_time'], $board_config['board_timezone']);
630                 $last_post_author = ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ($topic_rowset[$i]['post_username2'] != '' ) ? $topic_rowset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $topic_rowset[$i]['id2']) . '">' . $topic_rowset[$i]['user2'] . '</a>';
632                 $last_post_url = '<a href="' . append_sid("viewtopic.$phpEx?"  . POST_POST_URL . '=' . $topic_rowset[$i]['topic_last_post_id']) . '#' . $topic_rowset[$i]['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" border="0" /></a>';
634                 $views = $topic_rowset[$i]['topic_views'];
635                 
636                 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
637                 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
639                 $template->assign_block_vars('topicrow', array(
640                         'ROW_COLOR' => $row_color,
641                         'ROW_CLASS' => $row_class,
642                         'FORUM_ID' => $forum_id,
643                         'TOPIC_ID' => $topic_id,
644                         'TOPIC_FOLDER_IMG' => $folder_image, 
645                         'TOPIC_AUTHOR' => $topic_author, 
646                         'GOTO_PAGE' => $goto_page,
647                         'REPLIES' => $replies,
648                         'NEWEST_POST_IMG' => $newest_post_img, 
649                         'TOPIC_TITLE' => $topic_title,
650                         'TOPIC_TYPE' => $topic_type,
651                         'VIEWS' => $views,
652                         'FIRST_POST_TIME' => $first_post_time, 
653                         'LAST_POST_TIME' => $last_post_time, 
654                         'LAST_POST_AUTHOR' => $last_post_author, 
655                         'LAST_POST_IMG' => $last_post_url, 
657                         'L_TOPIC_FOLDER_ALT' => $folder_alt, 
659                         'U_VIEW_TOPIC' => $view_topic_url)
660                 );
661         }
663         $topics_count -= $total_announcements;
665         $template->assign_vars(array(
666                 'PAGINATION' => generate_pagination("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;topicdays=$topic_days", $topics_count, $board_config['topics_per_page'], $start),
667                 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $topics_count / $board_config['topics_per_page'] )), 
669                 'L_GOTO_PAGE' => $lang['Goto_page'])
670         );
672 else
674         //
675         // No topics
676         //
677         $no_topics_msg = ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['No_topics_post_one'];
678         $template->assign_vars(array(
679                 'L_NO_TOPICS' => $no_topics_msg)
680         );
682         $template->assign_block_vars('switch_no_topics', array() );
686 //
687 // Parse the page and print
688 //
689 $template->pparse('body');
691 //
692 // Page footer
693 //
694 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
696 ?>