Home :: Forums :: Register :: Sign In :: Links :: Downloads :: Shop
You are not signed in. Please sign in. If you have not registered, please click here.

News Page Number (want the new codezwiz version please)

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb   More...
#1Fri Feb 08, 2008 8:15 pm   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 3 year's 3 Year Member
Status: Offline
Joined: Jul 15, 2005
0.02 posts per day
Posts: 28
Points: 148
   
Telli, you are the greatest!! Everything in the News module working great with googletap on.

Which file/files do I need to edit to use the pagination script in the Forum module?

Thanks!



Back to top Reply with quote
#2Fri Feb 29, 2008 6:57 pm   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 3 year's 3 Year Member
Status: Offline
Joined: Jul 15, 2005
0.02 posts per day
Posts: 28
Points: 148
   
<bump> icon_rolleyes.gif



Back to top Reply with quote
#3Sun Mar 02, 2008 8:53 pm   
Telli
Site Admin
Telli has been a member for over 5 year's 5 Year Member
usa.gif florida.gif
Occupation: Self Employed
Age: 37
Fav. Sports Team: Detroit Red Wings
Website: www.codezhost.com
Status: Offline
Joined: May 26, 2003
3.98 posts per day
Posts: 7826
Points: 492,165
   
Check the files for the function pagination. Its in many and I don't have a standard version.

Its not a simple project, you must have PHP experience.




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#4Thu Apr 03, 2008 1:12 am   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 3 year's 3 Year Member
Status: Offline
Joined: Jul 15, 2005
0.02 posts per day
Posts: 28
Points: 148
   
Hey,

I have tried to get back to this lately. pagenation do exsists in many pages such as view forum, search, view topic and more but the base function is located in includes/functions.php:

//
// Pagination routine, generates
// page number sequence
//
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
{
   global $lang;

   $total_pages = ceil($num_items/$per_page);

   if ( $total_pages == 1 )
   {
      return '';
   }

   $on_page = floor($start_item / $per_page) + 1;

   $page_string = '';
   if ( $total_pages > 10 )
   {
      $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;

      for($i = 1; $i < $init_page_max + 1; $i++)
      {
         $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
         if ( $i <  $init_page_max )
         {
            $page_string .= ", ";
         }
      }

      if ( $total_pages > 3 )
      {
         if ( $on_page > 1  && $on_page < $total_pages )
         {
            $page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';

            $init_page_min = ( $on_page > 4 ) ? $on_page : 5;
            $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;

            for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++)
            {
               $page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
               if ( $i <  $init_page_max + 1 )
               {
                  $page_string .= ', ';
               }
            }

            $page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
         }
         else
         {
            $page_string .= ' ... ';
         }

         for($i = $total_pages - 2; $i < $total_pages + 1; $i++)
         {
            $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>'  : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
            if( $i <  $total_pages )
            {
               $page_string .= ", ";
            }
         }
      }
   }
   else
   {
      for($i = 1; $i < $total_pages + 1; $i++)
      {
         $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
         if ( $i <  $total_pages )
         {
            $page_string .= ', ';
         }
      }
   }

   if ( $add_prevnext_text )
   {
      if ( $on_page > 1 )
      {
         $page_string = ' <a href="' . append_sid($base_url . "&start=" . ( ( $on_page - 2 ) * $per_page ) ) . '">' . $lang['Previous'] . '</a>&nbsp;&nbsp;' . $page_string;
      }

      if ( $on_page < $total_pages )
      {
         $page_string .= '&nbsp;&nbsp;<a href="' . append_sid($base_url . "&start=" . ( $on_page * $per_page ) ) . '">' . $lang['Next'] . '</a>';
      }

   }

   $page_string = $lang['Goto_page'] . ' ' . $page_string;

   return $page_string;
}


So if you replace this code with your own it should replace all pagenation in phpbb doesnt it?


Back to top Reply with quote
#5Tue Apr 08, 2008 12:31 pm   
Telli
Site Admin
Telli has been a member for over 5 year's 5 Year Member
usa.gif florida.gif
Occupation: Self Employed
Age: 37
Fav. Sports Team: Detroit Red Wings
Website: www.codezhost.com
Status: Offline
Joined: May 26, 2003
3.98 posts per day
Posts: 7826
Points: 492,165
   
Make a backup of that function by renaimg it and then try this in its place:


function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
{
   return pagination($base_url, $num_items, $per_page, $start_item);
}




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#6Tue Apr 15, 2008 7:15 pm   
prekill
CZ Newbie
prekill has been a member for over 3 year's 3 Year Member
Status: Offline
Joined: Jul 15, 2005
0.02 posts per day
Posts: 28
Points: 148
   
Working great! it changed all pagenation in phpbb to the css one...

one problem... again the url is wrong:

here is my GT-Forums.php and my forum .htaccess files:

GT-Forums.php:

<?php

$urlin = array(
"'(?<!/)modules.php\?name=Forums&amp;file=viewtopic&amp;t=([0-9]*)&amp;start=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=(desc|asc)&amp;highlight=([A-Za-z0-9_-]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewtopic&amp;t=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=(desc|asc)&amp;start=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewtopic&amp;t=([0-9]*)&amp;start=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewtopic&amp;t=([0-9]*)&amp;view=(previous|next)'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewtopic&amp;(t|p)=([0-9]*)&amp;highlight=([A-Za-z0-9_-]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewtopic&amp;t=([0-9]*)&amp;(watch|unwatch)=topic&amp;start=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewtopic&amp;(t|p)=([0-9]*)((\")|(&amp;sid=[a-zA-Z0-9]*))'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewtopic&amp;(t|p)=([0-9]*)#([0-9]*)((\")|(&amp;sid=[a-zA-Z0-9]*))'",
"'(?<!/)modules.php\?name=Forums&amp;file=profile&amp;mode=editprofile'",
"'(?<!/)modules.php\?name=Forums&amp;file=profile&amp;mode=viewprofile&amp;u=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=profile&amp;mode=register&amp;agreed=true&amp;coppa=true'",
"'(?<!/)modules.php\?name=Forums&amp;file=profile&amp;mode=register&amp;agreed=true'",
"'(?<!/)modules.php\?name=Forums&amp;file=profile&amp;mode=register'",
"'(?<!/)modules.php\?name=Forums&amp;file=modules&amp;name=Forums&amp;file=posting'",
"'(?<!/)modules.php\?name=Forums&amp;file=faq&amp;mode=bbcode'",
"'(?<!/)modules.php\?name=Forums&amp;file=posting&amp;t=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=posting&amp;mode=vote&amp;t=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=posting&amp;mode=newtopic&amp;f=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=posting&amp;mode=reply&amp;t=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=posting&amp;mode=editpost&amp;p=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=posting&amp;mode=smilies&amp;popup=1'",
"'(?<!/)modules.php\?name=Forums&amp;file=posting&amp;mode=quote&amp;p=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=posting((\")|(&amp;sid=[a-zA-Z0-9]*))'",
"'(?<!/)modules.php\?name=Forums&amp;file=search&amp;search_id=([0-9]*)&amp;start=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=search&amp;search_id=(unanswered|egosearch|newposts)'",
"'(?<!/)modules.php\?name=Forums&amp;file=search&amp;mode=results'",
"'(?<!/)modules.php\?name=Forums&amp;file=index&amp;c=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=index&amp;mark=forums'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewonline'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewforum&amp;f=([0-9]*)&amp;topicdays=([0-9]*)&amp;start=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewforum&amp;f=([0-9]*)&amp;start=([0-9]*)'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewforum&amp;f=([0-9]*)&amp;mark=topics'",
"'(?<!/)modules.php\?name=Forums&amp;file=viewforum&amp;f=([0-9]*)((\")|(&amp;sid=[a-zA-Z0-9]*))'",
"'(?<!/)modules.php\?name=Forums&amp;file=([^index][a-zA-Z0-9_-]*)((\")|(&amp;sid=[a-zA-Z0-9]*))'",
"'(?<!/)modules.php\?name=Forums&amp;file=index((\")|(&amp;sid=[a-zA-Z0-9]*))'",
"'(?<!/)modules.php\?name=Forums(?!&)'",
"'(?<!/)modules.php\?name=Members_List&amp;file=index((\")|(&amp;sid=[a-zA-Z0-9]*))'",
"'(?<!/)modules.php\?name=Private_Messages&amp;file=index&amp;folder=(savebox|inbox|outbox|sentbox)((\")|(&amp;sid=[a-zA-Z0-9]*))'",
"'(?<!/)modules.php\?name=Private_Messages&amp;file=index&amp;mode=post&amp;u=([0-9]*)'",
"'(?<!/)modules.php\?name=Private_Messages&amp;mode=post&amp;u=([0-9]*)'",
"'(?<!/)modules.php\?name=Your_Account&amp;op=([a-z]*)\"'",
);

$urlout = array(
"ftopic-\\1-\\2-days\\3-order\\4-\\5.html",
"ftopic-\\1-days\\2-order\\3-\\4.html",
"ftopic-\\1-\\2.html",
"ftopic-\\1-\\2.html",
"ftopic\\1-\\2-\\3.html",
"ftopic-\\1-\\2-\\3.html",
"ftopic\\1-\\2.html\\3",
"ftopic\\1-\\2.html#\\3\\4",
"forum-editprofile.html",
"forum-userprofile-\\1.html",
"forum-register-coppa.html",
"forum-register-new.html",
"forum-register.html",
"forums-posting.html",
"forum-faq-bbcode.html",
"ftopic-post-\\1.html",
"ftopic-vote-\\1.html",
"ftopic-new-\\1.html",
"ftopic-reply-\\1.html",
"ftopic-edit-\\1.html",
"ftopic-smilies.html",
"ftopic-quote-\\1.html",
"forum-posting.html\\1",
"fsearch-\\1-\\2.html",
"fsearch-\\1.html",
"fsearch-results.html",
"forum-c\\1.html",
"forum-mark.html",
"forum-viewonline.html",
"forum-\\1-days\\2-\\3.html",
"forum-\\1-\\2.html",
"forum-\\1-mark.html",
"forum-\\1.html\\2",
"forums-\\1.html\\2",
"forums.html\\1",
"forums.html",
"members.html\\1",
"messages-\\1.html\\2",
"messages-post-\\1.html",
"messages-post-\\1.html",
"account-\\1.html\"",
);

?>


.htaccess:


#Forums
RewriteRule ^ftopic-([0-9]*)-([0-9]*)-days([0-9]*)-order(desc|asc)-([A-Za-z0-9_-]*).html modules.php?name=Forums&file=viewtopic&t=$1&start=$2&postdays=$3&postorder=$4&highlight=$5
RewriteRule ^ftopic-([0-9]*)-days([0-9]*)-order(desc|asc)-([0-9]*).html modules.php?name=Forums&file=viewtopic&t=$1&postdays=$2&postorder=$3&start=$4
RewriteRule ^ftopic-([0-9]*)-([0-9]*).html modules.php?name=Forums&file=viewtopic&t=$1&start=$2
RewriteRule ^ftopic-([0-9]*)-(previous|next).html modules.php?name=Forums&file=viewtopic&t=$1&view=$2
RewriteRule ^ftopic(t|p)-([0-9]*)-([A-Za-z0-9_-]*).html modules.php?name=Forums&file=viewtopic&$1=$2&highlight=$3
RewriteRule ^ftopic-([0-9]*)-(watch|unwatch)-([0-9]*).html modules.php?name=Forums&file=viewtopic&t=$1&$2=topic&start=$3
RewriteRule ^ftopic(t|p)-([0-9]*).html modules.php?name=Forums&file=viewtopic&$1=$2
RewriteRule ^ftopic(t|p)-([0-9]*).html#([0-9]*) modules.php?name=Forums&file=viewtopic&$1=$2#$3
RewriteRule ^forum-editprofile.html modules.php?name=Forums&file=profile&mode=editprofile
RewriteRule ^forum-userprofile-([0-9]*).html modules.php?name=Forums&file=profile&mode=viewprofile&u=$1
RewriteRule ^forum-register-new.html modules.php?name=Forums&file=profile&mode=register&agreed=true
RewriteRule ^forum-register-coppa.html modules.php?name=Forums&file=profile&mode=register&agreed=true&coppa=true
RewriteRule ^forum-register.html modules.php?name=Forums&file=profile&mode=register
RewriteRule ^forums-posting.html modules.php?name=Forums&file=modules&name=Forums&file=posting
RewriteRule ^forum-faq-bbcode.html modules.php?name=Forums&file=faq&mode=bbcode
RewriteRule ^ftopic-post-([0-9]*).html modules.php?name=Forums&file=posting&t=$1
RewriteRule ^ftopic-vote-([0-9]*).html modules.php?name=Forums&file=posting&mode=vote&t=$1
RewriteRule ^ftopic-new-([0-9]*).html modules.php?name=Forums&file=posting&mode=newtopic&f=$1
RewriteRule ^ftopic-reply-([0-9]*).html modules.php?name=Forums&file=posting&mode=reply&t=$1
RewriteRule ^ftopic-edit-([0-9]*).html modules.php?name=Forums&file=posting&mode=editpost&p=$1
RewriteRule ^ftopic-smilies.html modules.php?name=Forums&file=posting&mode=smilies&popup=1
RewriteRule ^ftopic-quote-([0-9]*).html modules.php?name=Forums&file=posting&mode=quote&p=$1
RewriteRule ^forum-posting.html modules.php?name=Forums&file=posting
RewriteRule ^forums-group([0-9]*).html modules.php?name=Forums&file=groupcp&g=$1
RewriteRule ^fsearch-([0-9]*)-([0-9]*).html modules.php?name=Forums&file=search&search_id=$1&start=$2
RewriteRule ^fsearch-(unanswered|egosearch|newposts).html modules.php?name=Forums&file=search&search_id=$1
RewriteRule ^fsearch-results.html modules.php?name=Forums&file=search&mode=results
RewriteRule ^forums-([^index][a-zA-Z0-9_-]*).html modules.php?name=Forums&file=$1
RewriteRule ^forum-c([0-9]*).html modules.php?name=Forums&file=index&c=$1
RewriteRule ^forum-mark.html modules.php?name=Forums&file=index&mark=forums
RewriteRule ^forums.html modules.php?name=Forums&file=index
RewriteRule ^forum-viewonline.html modules.php?name=Forums&file=viewonline
RewriteRule ^forum-([0-9]*)-days([0-9]*)-([0-9]*).html modules.php?name=Forums&file=viewforum&f=$1&topicdays=$2&start=$3
RewriteRule ^forum-([0-9]*)-([0-9]*).html modules.php?name=Forums&file=viewforum&f=$1&start=$2
RewriteRule ^forum-([0-9]*)-mark.html modules.php?name=Forums&file=viewforum&f=$1&mark=topics
RewriteRule ^forum-([0-9]*).html modules.php?name=Forums&file=viewforum&f=$1
RewriteRule ^forums.html modules.php?name=Forums


the urls I get are:

/viewtopic.php?t=10530&postdays=0&postorder=asc&start=15
/viewforum.php?f=10&topicdays=0&start=54
/search.php?search_id=301315766&start=36

icon_rolleyes.gif

thanks for all the help! you are the greatest.


Back to top Reply with quote
#7Thu May 01, 2008 12:00 am   
Telli
Site Admin
Telli has been a member for over 5 year's 5 Year Member
usa.gif florida.gif
Occupation: Self Employed
Age: 37
Fav. Sports Team: Detroit Red Wings
Website: www.codezhost.com
Status: Offline
Joined: May 26, 2003
3.98 posts per day
Posts: 7826
Points: 492,165
   
Attach one of the pages you edited from the forums module.




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#8Thu May 01, 2008 5:27 am   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 3 year's 3 Year Member
Status: Offline
Joined: Jul 15, 2005
0.02 posts per day
Posts: 28
Points: 148
   
Umm I do not remember if I edit any so I am attaching viewforum.php and viewtopic.php:

viewforum.php:
<?php
/***************************************************************************
*                               viewforum.php
*                            -------------------
*   begin                : Saturday, Feb 13, 2001
*   copyright            : (C) 2001 The phpBB Group
*   email                : [ Register or login to view links on this board. ]
*
*   Id: viewforum.php,v 1.139.2.12 2004/03/13 15:08:23 acydburn Exp
*
*
***************************************************************************/
/***************************************************************************
* phpbb2 forums port version 2.0.5 (c) 2003 - Nuke Cops (http://nukecops.com)
*
* Ported by Nuke Cops to phpbb2 standalone 2.0.5 Test
* and debugging completed by the Elite Nukers and site members.
*
* You run this package at your sole risk. Nuke Cops and affiliates cannot
* be held liable if anything goes wrong. You are advised to test this
* package on a development system. Backup everything before implementing
* in a production environment. If something goes wrong, you can always
* backout and restore your backups.
*
* Installing and running this also means you agree to the terms of the AUP
* found at Nuke Cops.
*
* This is version 2.0.5 of the phpbb2 forum port for PHP-Nuke. Work is based
* on Tom Nitzschner's forum port version 2.0.6. Tom's 2.0.6 port was based
* on the phpbb2 standalone version 2.0.3. Our version 2.0.5 from Nuke Cops is
* now reflecting phpbb2 standalone 2.0.5 that fixes some bugs and the
* invalid_session error message.
***************************************************************************/
/***************************************************************************
*   This file is part of the phpBB2 port to Nuke 6.0 (c) copyright 2002
*   by Tom Nitzschner (tom@toms-home.com)
*   http://bbtonuke.sourceforge.net (or http://www.toms-home.com)
*
*   As always, make a backup before messing with anything. All code
*   release by me is considered sample code only. It may be fully
*   functual, but you use it at your own risk, if you break it,
*   you get to fix it too. No waranty is given or implied.
*
*   Please post all questions/request about this port on http://bbtonuke.sourceforge.net first,
*   then on my site. All original header code and copyright messages will be maintained
*   to give credit where credit is due. If you modify this, the only requirement is
*   that you also maintain all original copyright messages. All my work is released
*   under the GNU GENERAL PUBLIC LICENSE. Please see the README for more information.
*
***************************************************************************/

/***************************************************************************
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
*
***************************************************************************/

if (!eregi("modules.php", $_SERVER['SCRIPT_NAME'])) {
    die ("You can't access this file directly...");
}
if ($popup != "1"){
    $module_name = basename(dirname(__FILE__));
    require("modules/".$module_name."/nukebb.php");
}
else
{
    $phpbb_root_path = 'modules/Forums/';
}
define('IN_PHPBB', true);
//$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include('includes/functions_separate.'.$phpEx);
//
// Start initial var setup
//
if ( isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]) )
{
        $forum_id = ( isset($HTTP_GET_VARS[POST_FORUM_URL]) ) ? intval($HTTP_GET_VARS[POST_FORUM_URL]) : intval($HTTP_POST_VARS[POST_FORUM_URL]);
}
else if ( isset($HTTP_GET_VARS['forum']))
{
        $forum_id = intval($HTTP_GET_VARS['forum']);
}
else
{
        $forum_id = '';
}

$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;

if ( isset($HTTP_GET_VARS['mark']) || isset($HTTP_POST_VARS['mark']) )
{
        $mark_read = (isset($HTTP_POST_VARS['mark'])) ? $HTTP_POST_VARS['mark'] : $HTTP_GET_VARS['mark'];
}
else
{
        $mark_read = '';
}
//
// End initial var setup
//

//
// Check if the user has actually sent a forum ID with his/her request
// If not give them a nice error page.
//
if ( !empty($forum_id) )
{
        $sql = "SELECT *
                FROM " . FORUMS_TABLE . "
                WHERE forum_id = '$forum_id'";
        if ( !($result = $db->sql_query($sql)) )
        {
                message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
        }
}
else
{
        message_die(GENERAL_MESSAGE, 'Forum_not_exist');
}

//
// If the query doesn't return any rows this isn't a valid forum. Inform
// the user.
//
if ( !($forum_row = $db->sql_fetchrow($result)) )
{
        message_die(GENERAL_MESSAGE, 'Forum_not_exist');
}

//
// Start session management
//
$userdata = session_pagestart($user_ip, $forum_id, $nukeuser);
init_userprefs($userdata);
//
// End session management
//

//
// Start auth check
//
$is_auth = array();
$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_row);

if ( !$is_auth['auth_read'] || !$is_auth['auth_view'] )
{
        if ( !$userdata['session_logged_in'] )
        {
                $redirect = POST_FORUM_URL . "=$forum_id" . ( ( isset($start) ) ? "&start=$start" : '' );
                $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", $_SERVER["SERVER_SOFTWARE"]) ) ? "Refresh: 0; URL=" : "Location: ";
                header($header_location . append_sid("login.$phpEx?redirect=viewforum.$phpEx&$redirect", true));
                exit;
        }
        //
        // The user is not authed to read this forum ...
        //
        $message = ( !$is_auth['auth_view'] ) ? $lang['Forum_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);

        message_die(GENERAL_MESSAGE, $message);
}
//
// End of auth check
//

//
// Handle marking posts
//
if ( $mark_read == 'topics' )
{
        if ( $userdata['session_logged_in'] )
        {
                $sql = "SELECT MAX(post_time) AS last_post
                        FROM " . POSTS_TABLE . "
                        WHERE forum_id = '$forum_id'";
                if ( !($result = $db->sql_query($sql)) )
                {
                        message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
                }

                if ( $row = $db->sql_fetchrow($result) )
                {
                        $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
                        $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();

                        if ( ( count($tracking_forums) + count($tracking_topics) ) >= 150 && empty($tracking_forums[$forum_id]) )
                        {
                                asort($tracking_forums);
                                unset($tracking_forums[key($tracking_forums)]);
                        }

                        if ( $row['last_post'] > $userdata['user_lastvisit'] )
                        {
                                $tracking_forums[$forum_id] = time();

                                setcookie($board_config['cookie_name'] . '_f', serialize($tracking_forums), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
                        }
                }

                $template->assign_vars(array(
                        'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">')
                );
        }

        $message = $lang['Topics_marked_read'] . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a> ');
        message_die(GENERAL_MESSAGE, $message);
}
//
// End handle marking posts
//

$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : '';
$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : '';

//
// Do the forum Prune
//
if ( $is_auth['auth_mod'] && $board_config['prune_enable'] )
{
        if ( $forum_row['prune_next'] < time() && $forum_row['prune_enable'] )

        {

                include("includes/prune.php");

                require("includes/functions_admin.php");
                auto_prune($forum_id);
        }
}
//
// End of forum prune
//

//
// Obtain list of moderators of each forum
// First users, then groups ... broken into two queries
//
$sql = "SELECT u.user_id, u.username
        FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g, " . USERS_TABLE . " u
        WHERE aa.forum_id = '$forum_id'
                AND aa.auth_mod = " . TRUE . "
                AND g.group_single_user = '1'
                AND ug.group_id = aa.group_id
                AND g.group_id = aa.group_id
                AND u.user_id = ug.user_id
        GROUP BY u.user_id, u.username
        ORDER BY u.user_id";
if ( !($result = $db->sql_query($sql)) )
{
        message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
}

$moderators = array();
while( $row = $db->sql_fetchrow($result) )
{
        $moderators[] = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '">' . $row['username'] . '</a>';
}

$sql = "SELECT g.group_id, g.group_name
        FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
        WHERE aa.forum_id = '$forum_id'
                AND aa.auth_mod = " . TRUE . "
                AND g.group_single_user = '0'
                AND g.group_type <> ". GROUP_HIDDEN ."
                AND ug.group_id = aa.group_id
                AND g.group_id = aa.group_id
        GROUP BY g.group_id, g.group_name
        ORDER BY g.group_id";
if ( !($result = $db->sql_query($sql)) )
{
        message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
}

while( $row = $db->sql_fetchrow($result) )
{
        $moderators[] = '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $row['group_id']) . '">' . $row['group_name'] . '</a>';
}

$l_moderators = ( count($moderators) == 1 ) ? $lang['Moderator'] : $lang['Moderators'];
$forum_moderators = ( count($moderators) ) ? implode(', ', $moderators) : $lang['None'];
unset($moderators);

//
// Generate a 'Show topics in previous x days' select box. If the topicsdays var is sent
// then get it's value, find the number of topics with dates newer than it (to properly
// handle pagination) and alter the main query
//
$previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
$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']);

if ( !empty($HTTP_POST_VARS['topicdays']) || !empty($HTTP_GET_VARS['topicdays']) )
{
        $topic_days = ( !empty($HTTP_POST_VARS['topicdays']) ) ? intval($HTTP_POST_VARS['topicdays']) : intval($HTTP_GET_VARS['topicdays']);
        $min_topic_time = time() - ($topic_days * 86400);

        $sql = "SELECT COUNT(t.topic_id) AS forum_topics
                FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
                WHERE t.forum_id = '$forum_id'
                        AND p.post_id = t.topic_last_post_id
                        AND p.post_time >= '$min_topic_time'";

        if ( !($result = $db->sql_query($sql)) )
        {
                message_die(GENERAL_ERROR, 'Could not obtain limited topics count information', '', __LINE__, __FILE__, $sql);
        }
        $row = $db->sql_fetchrow($result);

        $topics_count = ( $row['forum_topics'] ) ? $row['forum_topics'] : 1;
        $limit_topics_time = "AND p.post_time >= $min_topic_time";

        if ( !empty($HTTP_POST_VARS['topicdays']) )
        {
                $start = 0;
        }
}
else
{
        $topics_count = ( $forum_row['forum_topics'] ) ? $forum_row['forum_topics'] : 1;

        $limit_topics_time = '';
        $topic_days = 0;
}

$select_topic_days = '<select name="topicdays">';
for($i = 0; $i < count($previous_days); $i++)
{
        $selected = ($topic_days == $previous_days[$i]) ? ' selected="selected"' : '';
        $select_topic_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
}
$select_topic_days .= '</select>';


//
// All announcement data, this keeps announcements
// on each viewforum page ...
//
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username
        FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2
        WHERE t.forum_id = '$forum_id'
                AND t.topic_poster = u.user_id
                AND p.post_id = t.topic_last_post_id
                AND p.poster_id = u2.user_id
                AND t.topic_type = " . POST_ANNOUNCE . "
        ORDER BY t.topic_priority DESC, t.topic_last_post_id DESC ";
if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}

$topic_rowset = array();
$total_announcements = 0;
while( $row = $db->sql_fetchrow($result) )
{
        $topic_rowset[] = $row;
        $total_announcements++;
}

$db->sql_freeresult($result);

//
// Grab all the basic data (all topics except announcements)
// for this forum
//
$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
        FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
        WHERE t.forum_id = '$forum_id'
                AND t.topic_poster = u.user_id
                AND p.post_id = t.topic_first_post_id
                AND p2.post_id = t.topic_last_post_id
                AND u2.user_id = p2.poster_id
                AND t.topic_type <> " . POST_ANNOUNCE . "
                $limit_topics_time
        ORDER BY t.topic_type DESC, t.topic_priority DESC, t.topic_last_post_id DESC
        LIMIT $start, ".$board_config['topics_per_page'];
if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}

$total_topics = 0;
while( $row = $db->sql_fetchrow($result) )
{
        $topic_rowset[] = $row;
        $total_topics++;
}

$db->sql_freeresult($result);

//
// Total topics ...
//
$total_topics += $total_announcements;
$dividers = get_dividers($topic_rowset);

//
// Define censored word matches
//
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);

//
// Post URL generation for templating vars
//
$template->assign_vars(array(
        'L_DISPLAY_TOPICS' => $lang['Display_topics'],

        'U_POST_NEW_TOPIC' => append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id"),

        'S_SELECT_TOPIC_DAYS' => $select_topic_days,
        'S_POST_DAYS_ACTION' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $forum_id . "&amp;start=$start"))
);

//
// User authorisation levels output
//
$s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['Rules_post_can'] : $lang['Rules_post_cannot'] ) . '<br />';
$s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot'] ) . '<br />';
$s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot'] ) . '<br />';
$s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot'] ) . '<br />';
$s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot'] ) . '<br />';

if ( $is_auth['auth_mod'] )
{
        $s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="' . append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
}

//
// Mozilla navigation bar
//
$nav_links['up'] = array(
        'url' => append_sid('index.'.$phpEx),
        'title' => sprintf($lang['Forum_Index'], $board_config['sitename'])
);

//
// Dump out the page header and load viewforum template
//
define('SHOW_ONLINE', true);
$page_title = $lang['View_forum'] . ' - ' . $forum_row['forum_name'];
include("includes/page_header.php");

$template->set_filenames(array(
        'body' => 'viewforum_body.tpl')
);
make_jumpbox('viewforum.'.$phpEx);

$template->assign_vars(array(
        'FORUM_ID' => $forum_id,
        'FORUM_NAME' => $forum_row['forum_name'],
        'MODERATORS' => $forum_moderators,
        'POST_IMG' => ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'],

        'FOLDER_IMG' => $images['folder'],
        'FOLDER_NEW_IMG' => $images['folder_new'],
        'FOLDER_HOT_IMG' => $images['folder_hot'],
        'FOLDER_HOT_NEW_IMG' => $images['folder_hot_new'],
        'FOLDER_LOCKED_IMG' => $images['folder_locked'],
        'FOLDER_LOCKED_NEW_IMG' => $images['folder_locked_new'],
        'FOLDER_STICKY_IMG' => $images['folder_sticky'],
        'FOLDER_STICKY_NEW_IMG' => $images['folder_sticky_new'],
        'FOLDER_ANNOUNCE_IMG' => $images['folder_announce'],
        'FOLDER_ANNOUNCE_NEW_IMG' => $images['folder_announce_new'],

        'L_TOPICS' => $lang['Topics'],
        'L_REPLIES' => $lang['Replies'],
        'L_VIEWS' => $lang['Views'],
        'L_POSTS' => $lang['Posts'],
        'L_LASTPOST' => $lang['Last_Post'],
        'L_MODERATOR' => $l_moderators,
        'L_MARK_TOPICS_READ' => $lang['Mark_all_topics'],
        'L_POST_NEW_TOPIC' => ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'],
        'L_NO_NEW_POSTS' => $lang['No_new_posts'],
        'L_NEW_POSTS' => $lang['New_posts'],
        'L_NO_NEW_POSTS_LOCKED' => $lang['No_new_posts_locked'],
        'L_NEW_POSTS_LOCKED' => $lang['New_posts_locked'],
        'L_NO_NEW_POSTS_HOT' => $lang['No_new_posts_hot'],
        'L_NEW_POSTS_HOT' => $lang['New_posts_hot'],
        'L_ANNOUNCEMENT' => $lang['Post_Announcement'],
        'L_STICKY' => $lang['Post_Sticky'],
        'L_POSTED' => $lang['Posted'],
        'L_JOINED' => $lang['Joined'],
        'L_AUTHOR' => $lang['Author'],

        'S_AUTH_LIST' => $s_auth_can,

        'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL ."=$forum_id"),

        'U_MARK_READ' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;mark=topics"))
);
//
// End header
//

//
// Okay, lets dump out the page ...
//
if( $total_topics )
{
        for($i = 0; $i < $total_topics; $i++)
        {
                $topic_id = $topic_rowset[$i]['topic_id'];

                $topic_title = ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $topic_rowset[$i]['topic_title']) : $topic_rowset[$i]['topic_title'];

                $replies = $topic_rowset[$i]['topic_replies'];

                $topic_type = $topic_rowset[$i]['topic_type'];

                if( $topic_type == POST_ANNOUNCE )
                {
                        $topic_type = $lang['Topic_Announcement'] . ' ';
                }
                else if( $topic_type == POST_STICKY )
                {
                        $topic_type = $lang['Topic_Sticky'] . ' ';
                }
                else
                {
                        $topic_type = '';
                }

                if( $topic_rowset[$i]['topic_vote'] )
                {
                        $topic_type .= $lang['Topic_Poll'] . ' ';
                }

                if( $topic_rowset[$i]['topic_status'] == TOPIC_MOVED )
                {
                        $topic_type = $lang['Topic_Moved'] . ' ';
                        $topic_id = $topic_rowset[$i]['topic_moved_id'];

                        $folder_image =  $images['folder'];
                        $folder_alt = $lang['Topics_Moved'];
                        $newest_post_img = '';
                }
                else
                {
                        if( $topic_rowset[$i]['topic_type'] == POST_ANNOUNCE )
                        {
                                $folder = $images['folder_announce'];
                                $folder_new = $images['folder_announce_new'];
                        }
                        else if( $topic_rowset[$i]['topic_type'] == POST_STICKY )
                        {
                                $folder = $images['folder_sticky'];
                                $folder_new = $images['folder_sticky_new'];
                        }
                        else if( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED )
                        {
                                $folder = $images['folder_locked'];
                                $folder_new = $images['folder_locked_new'];
                        }
                        else
                        {
                                if($replies >= $board_config['hot_threshold'])
                                {
                                        $folder = $images['folder_hot'];
                                        $folder_new = $images['folder_hot_new'];
                                }
                                else
                                {
                                        $folder = $images['folder'];
                                        $folder_new = $images['folder_new'];
                                }
                        }

                        $newest_post_img = '';
                        if( $userdata['session_logged_in'] )
                        {
                                if( $topic_rowset[$i]['post_time'] > $userdata['user_lastvisit'] )
                                {
                                        if( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
                                        {
                                                $unread_topics = true;

                                                if( !empty($tracking_topics[$topic_id]) )
                                                {
                                                        if( $tracking_topics[$topic_id] >= $topic_rowset[$i]['post_time'] )
                                                        {
                                                                $unread_topics = false;
                                                        }
                                                }

                                                if( !empty($tracking_forums[$forum_id]) )
                                                {
                                                        if( $tracking_forums[$forum_id] >= $topic_rowset[$i]['post_time'] )
                                                        {
                                                                $unread_topics = false;
                                                        }
                                                }

                                                if( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
                                                {
                                                        if( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] >= $topic_rowset[$i]['post_time'] )
                                                        {
                                                                $unread_topics = false;
                                                        }
                                                }

                                                if( $unread_topics )
                                                {
                                                        $folder_image = $folder_new;
                                                        $folder_alt = $lang['New_posts'];

                                                        $newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
                                                }
                                                else
                                                {
                                                        $folder_image = $folder;
                                                        $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];

                                                        $newest_post_img = '';
                                                }
                                        }
                                        else
                                        {
                                                $folder_image = $folder_new;
                                                $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['New_posts'];

                                                $newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
                                        }
                                }
                                else
                                {
                                        $folder_image = $folder;
                                        $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];

                                        $newest_post_img = '';
                                }
                        }
                        else
                        {
                                $folder_image = $folder;
                                $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];

                                $newest_post_img = '';
                        }
                }

                if( ( $replies + 1 ) > $board_config['posts_per_page'] )
                {
                        $total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] );
                        $goto_page = ' [ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['Goto_page'] . '" title="' . $lang['Goto_page'] . '" />' . $lang['Goto_page'] . ': ';

                        $times = 1;
                        for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page'])
                        {
                                $goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&start=$j") . '">' . $times . '</a>';
                                if( $times == 1 && $total_pages > 4 )
                                {
                                        $goto_page .= ' ... ';
                                        $times = $total_pages - 3;
                                        $j += ( $total_pages - 4 ) * $board_config['posts_per_page'];
                                }
                                else if ( $times < $total_pages )
                                {
                                        $goto_page .= ', ';
                                }
                                $times++;
                        }
                        $goto_page .= ' ] ';
                }
                else
                {
                        $goto_page = '';
                }

                $view_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");

                $topic_author = ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $topic_rowset[$i]['user_id']) . '">' : '';
                $topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? $topic_rowset[$i]['username'] : ( ( $topic_rowset[$i]['post_username'] != '' ) ? $topic_rowset[$i]['post_username'] : $lang['Guest'] );

                $topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';

                $first_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['topic_time'], $board_config['board_timezone']);

                $last_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['post_time'], $board_config['board_timezone']);

                $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&" . POST_USERS_URL . '='  . $topic_rowset[$i]['id2']) . '">' . $topic_rowset[$i]['user2'] . '</a>';

                $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>';

                $views = $topic_rowset[$i]['topic_views'];

                $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
                $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];

      $sql = "SELECT post_text FROM " . POSTS_TEXT_TABLE . " WHERE post_id=" . $topic_rowset[$i]['topic_first_post_id'];
       
      $result = $db->sql_query($sql);
           $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
         
      $first_post = $row['post_text'];
            $char_limit = '150';
      if (strlen($first_post) > $char_limit)
      {
      $first_post=substr($first_post, 0, $char_limit) . "....";
      }
         
      $first_post = preg_replace("/\[.+\]/iU",'',$first_post);
      $first_post = str_replace(array('"', '\''), array('&quote;', '\''), $first_post);

                $template->assign_block_vars('topicrow', array(
                        'ROW_COLOR' => $row_color,
                        'ROW_CLASS' => $row_class,
                        'FORUM_ID' => $forum_id,
                        'TOPIC_ID' => $topic_id,
                        'TOPIC_FOLDER_IMG' => $folder_image,
                        'TOPIC_AUTHOR' => $topic_author,
                        'GOTO_PAGE' => $goto_page,
                        'REPLIES' => $replies,
                        'NEWEST_POST_IMG' => $newest_post_img,
                        'TOPIC_TITLE' => $topic_title,
                        'TOPIC_TYPE' => $topic_type,
                        'VIEWS' => $views,
                        'FIRST_POST_TIME' => $first_post_time,
                        'LAST_POST_TIME' => $last_post_time,
                        'FIRST_POST_RESULT' => $first_post,
                        'LAST_POST_AUTHOR' => $last_post_author,
                        'LAST_POST_IMG' => $last_post_url,

            &n