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  
#1   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Jul 15, 2005
0.00 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
#2   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Jul 15, 2005
0.00 posts per day
Posts: 28
Points: 148
   
<bump> icon_rolleyes.gif



Back to top Reply with quote
#3   
Telli
Site Admin
Telli has been a member for over 20 year's 20 Year Member
Occupation: Self Employed
Age: 45
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.06 posts per day
Posts: 8089
Points: 494,430
   
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
#4   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Jul 15, 2005
0.00 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
#5   
Telli
Site Admin
Telli has been a member for over 20 year's 20 Year Member
Occupation: Self Employed
Age: 45
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.06 posts per day
Posts: 8089
Points: 494,430
   
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
#6   
prekill
CZ Newbie
prekill has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Jul 15, 2005
0.00 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
#7   
Telli
Site Admin
Telli has been a member for over 20 year's 20 Year Member
Occupation: Self Employed
Age: 45
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.06 posts per day
Posts: 8089
Points: 494,430
   
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
#8   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Jul 15, 2005
0.00 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,

                        'L_TOPIC_FOLDER_ALT' => $folder_alt,

                        'U_VIEW_TOPIC' => $view_topic_url)
                );
                if ( array_key_exists($i, $dividers) )
                {
                    $template->assign_block_vars('topicrow.divider', array(
                        'L_DIV_HEADERS' => $dividers[$i])
                    );
                }
        }

        $topics_count -= $total_announcements;

        $template->assign_vars(array(
                'PAGINATION' => generate_pagination("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;topicdays=$topic_days", $topics_count, $board_config['topics_per_page'], $start),
                'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $topics_count / $board_config['topics_per_page'] )),

                'L_GOTO_PAGE' => $lang['Goto_page'])
        );
}
else
{
        //
        // No topics
        //
        $no_topics_msg = ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['No_topics_post_one'];
        $template->assign_vars(array(
                'L_NO_TOPICS' => $no_topics_msg)
        );

        $template->assign_block_vars('switch_no_topics', array() );

}

//
// Parse the page and print
//
$template->pparse('body');

//
// Page footer
//
include("includes/page_tail.php");
?>


viewtopic.php:
<?php
/***************************************************************************
*                               viewtopic.php
*                            -------------------
*   begin                : Saturday, Feb 13, 2001
*   copyright            : (C) 2001 The phpBB Group
*   email                : [ Register or login to view links on this board. ]
*
*   $Id: viewtopic.php,v 1.186.2.45 2005/10/05 17:42:04 grahamje Exp $
*
*
***************************************************************************/

/***************************************************************************
*
*   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 (!(isset($popup)) OR ($popup != "1"))
    {
        $module_name = basename(dirname(__FILE__));
        require("modules/".$module_name."/nukebb.php");
    }
    else
    {
        $phpbb_root_path = 'modules/Forums/';
    }

define('IN_PHPBB', true);
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include_once("includes/bbcode.php");

//
// Start initial var setup
//
$adblocktext = <<<EOM
<tr><td  align="center" bgcolor="#d1d7dc" colspan="2">
<iframe src="googlephpbb.html" width="478" height="75" frameborder="0"></iframe><br><br>
</td></tr>
<tr><td class="spaceRow" height="1" colspan="2"><img
src="modules/Forums/templates/subSilver/images/spacer.gif"
alt="" width="1" height="1" /></td>
</tr>
EOM;
$topic_id = $post_id = 0;
if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
{
        $topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
}
else if ( isset($HTTP_GET_VARS['topic']) )
{
        $topic_id = intval($HTTP_GET_VARS['topic']);
}

if ( isset($HTTP_GET_VARS[POST_POST_URL]))
{
        $post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
}

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

if (!$topic_id && !$post_id)
{
        message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}

//
// Find topic id if user requested a newer
// or older topic
//
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{
        if ( $HTTP_GET_VARS['view'] == 'newest' )
        {
                $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', $_SERVER['SERVER_SOFTWARE']) ) ? 'Refresh: 0; URL=' : 'Location: ';

                if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
                {
                        $session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid'];
                        if (!preg_match('/^[A-Za-z0-9]*$/', $session_id))
                        {
                        $session_id = '';
                        }
                        if ( $session_id )
                        {
                                $sql = "SELECT p.post_id
                                        FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
                                        WHERE s.session_id = '$session_id'
                                                AND u.user_id = s.session_user_id
                                                AND p.topic_id = '$topic_id'
                                                AND p.post_time >= u.user_lastvisit
                                        ORDER BY p.post_time ASC
                                        LIMIT 1";
                                if ( !($result = $db->sql_query($sql)) )
                                {
                                        message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
                                }

                                if ( !($row = $db->sql_fetchrow($result)) )
                                {
                                        message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
                                }

                                $post_id = $row['post_id'];
                                header($header_location . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true));
                                exit;
                        }
                }

                header($header_location . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
                exit;
        }
        else if ( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
        {
                $sql_condition = ( $HTTP_GET_VARS['view'] == 'next' ) ? '>' : '<';
                $sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';

                $sql = "SELECT t.topic_id
         FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2
         WHERE
            t2.topic_id = '$topic_id'
            AND t.forum_id = t2.forum_id
            AND t.topic_moved_id = 0
            AND t.topic_last_post_id $sql_condition t2.topic_last_post_id
         ORDER BY t.topic_last_post_id $sql_ordering
                        LIMIT 1";
                if ( !($result = $db->sql_query($sql)) )
                {
                        message_die(GENERAL_ERROR, "Could not obtain newer/older topic information", '', __LINE__, __FILE__, $sql);
                }

                if ( $row = $db->sql_fetchrow($result) )
                {
                        $topic_id = intval($row['topic_id']);
                }
                else
                {
                        $message = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'No_newer_topics' : 'No_older_topics';
                        message_die(GENERAL_MESSAGE, $message);
                }
        }
}

//
// This rather complex gaggle of code handles querying for topics but
// also allows for direct linking to a post (and the calculation of which
// page the post is on and the correct display of viewtopic)
//
$join_sql_table = (!$post_id) ? '' : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 ";
$join_sql = (!$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'";
$count_sql = (!$post_id) ? '' : ", COUNT(p2.post_id) AS prev_posts";

$order_sql = (!$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";

$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 . "
        FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
        WHERE $join_sql
                AND f.forum_id = t.forum_id
                $order_sql";
if ( !($result = $db->sql_query($sql)) )
{
        message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
}

if ( !($forum_topic_data = $db->sql_fetchrow($result)) )
{
        message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}

$forum_id = intval($forum_topic_data['forum_id']);

//
// 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_topic_data);

if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
{
        if ( !$userdata['session_logged_in'] )
        {
      $redirect = ($post_id) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
      $redirect .= ($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=viewtopic.$phpEx&$redirect", true));
                exit;
        }

        $message = ( !$is_auth['auth_view'] ) ? $lang['Topic_post_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);

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

$forum_name = $forum_topic_data['forum_name'];
$topic_title = $forum_topic_data['topic_title'];
$topic_id = intval($forum_topic_data['topic_id']);
$topic_time = $forum_topic_data['topic_time'];

if ($post_id)
{
        $start = floor(($forum_topic_data['prev_posts'] - 1) / intval($board_config['posts_per_page'])) * intval($board_config['posts_per_page']);
}

//
// Is user watching this thread?
//
if( $userdata['session_logged_in'] )
{
        $can_watch_topic = TRUE;

        $sql = "SELECT notify_status
                FROM " . TOPICS_WATCH_TABLE . "
                WHERE topic_id = '$topic_id'
                        AND user_id = " . $userdata['user_id'];
        if ( !($result = $db->sql_query($sql)) )
        {
                message_die(GENERAL_ERROR, "Could not obtain topic watch information", '', __LINE__, __FILE__, $sql);
        }

        if ( $row = $db->sql_fetchrow($result) )
        {
                if ( isset($HTTP_GET_VARS['unwatch']) )
                {
                        if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
                        {
                                $is_watching_topic = 0;

                                $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
                                $sql = "DELETE $sql_priority FROM " . TOPICS_WATCH_TABLE . "
                                        WHERE topic_id = '$topic_id'
                                                AND user_id = " . $userdata['user_id'];
                                if ( !($result = $db->sql_query($sql)) )
                                {
                                        message_die(GENERAL_ERROR, "Could not delete topic watch information", '', __LINE__, __FILE__, $sql);
                                }
                        }

                        $template->assign_vars(array(
                                'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
                        );

                        $message = $lang['No_longer_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&start=$start") . '">', '</a>');
                        message_die(GENERAL_MESSAGE, $message);
                }
                else
                {
                        $is_watching_topic = TRUE;

                        if ( $row['notify_status'] )
                        {
                                $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
                                $sql = "UPDATE $sql_priority " . TOPICS_WATCH_TABLE . "
                                        SET notify_status = '0'
                                        WHERE topic_id = '$topic_id'
                                                AND user_id = " . $userdata['user_id'];
                                if ( !($result = $db->sql_query($sql)) )
                                {
                                        message_die(GENERAL_ERROR, "Could not update topic watch information", '', __LINE__, __FILE__, $sql);
                                }
                        }
                }
        }
        else
        {
                if ( isset($HTTP_GET_VARS['watch']) )
                {
                        if ( $HTTP_GET_VARS['watch'] == 'topic' )
                        {
                                $is_watching_topic = TRUE;

                                $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
                                $sql = "INSERT $sql_priority INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
                                        VALUES (" . $userdata['user_id'] . ", '$topic_id', '0')";
                                if ( !($result = $db->sql_query($sql)) )
                                {
                                        message_die(GENERAL_ERROR, "Could not insert topic watch information", '', __LINE__, __FILE__, $sql);
                                }
                        }

                        $template->assign_vars(array(
                                'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
                        );

                        $message = $lang['You_are_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&start=$start") . '">', '</a>');
                        message_die(GENERAL_MESSAGE, $message);
                }
                else
                {
                        $is_watching_topic = 0;
                }
        }
}
else
{
        if ( isset($HTTP_GET_VARS['unwatch']) )
        {
                if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
                {
                        $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", $_SERVER["SERVER_SOFTWARE"]) ) ? "Refresh: 0; URL=" : "Location: ";
                        header($header_location . append_sid("login.$phpEx?redirect=viewtopic.$phpEx&" . POST_TOPIC_URL . "=$topic_id&unwatch=topic", true));
                        exit;
                }
        }
        else
        {
                $can_watch_topic = 0;
                $is_watching_topic = 0;
        }
}

//
// Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed
// 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_Posts'], $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['postdays']) || !empty($HTTP_GET_VARS['postdays']) )
{
        $post_days = ( !empty($HTTP_POST_VARS['postdays']) ) ? intval($HTTP_POST_VARS['postdays']) : intval($HTTP_GET_VARS['postdays']);
        $min_post_time = time() - (intval($post_days) * 86400);

        $sql = "SELECT COUNT(p.post_id) AS num_posts
                FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
                WHERE t.topic_id = '$topic_id'
                        AND p.topic_id = t.topic_id
                        AND p.post_time >= '$min_post_time'";
        if ( !($result = $db->sql_query($sql)) )
        {
                message_die(GENERAL_ERROR, "Could not obtain limited topics count information", '', __LINE__, __FILE__, $sql);
        }

        $total_replies = ( $row = $db->sql_fetchrow($result) ) ? intval($row['num_posts']) : 0;

        $limit_posts_time = "AND p.post_time >= $min_post_time ";

        if ( !empty($HTTP_POST_VARS['postdays']))
        {
                $start = 0;
        }
}
else
{
        $total_replies = intval($forum_topic_data['topic_replies']) + 1;

        $limit_posts_time = '';
        $post_days = 0;
}

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

//
// Decide how to order the post display
//
if ( !empty($HTTP_POST_VARS['postorder']) || !empty($HTTP_GET_VARS['postorder']) )
{
   $post_order = (!empty($HTTP_POST_VARS['postorder'])) ? htmlspecialchars($HTTP_POST_VARS['postorder']) : htmlspecialchars($HTTP_GET_VARS['postorder']);
        $post_time_order = ($post_order == "asc") ? "ASC" : "DESC";
}
else
{
        $post_order = 'asc';
        $post_time_order = 'ASC';
}

$select_post_order = '<select name="postorder">';
if ( $post_time_order == 'ASC' )
{
        $select_post_order .= '<option value="asc" selected="selected">' . $lang['Oldest_First'] . '</option><option value="desc">' . $lang['Newest_First'] . '</option>';
}
else
{
        $select_post_order .= '<option value="asc">' . $lang['Oldest_First'] . '</option><option value="desc" selected="selected">' . $lang['Newest_First'] . '</option>';
}
$select_post_order .= '</select>';

//
// Go ahead and pull all data for this topic
//
$sql = "SELECT u.username, u.user_id, u.user_level, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim,  u.user_skype, 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
        FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
        WHERE p.topic_id = '$topic_id'
                $limit_posts_time
                AND pt.post_id = p.post_id
                AND u.user_id = p.poster_id
        ORDER BY p.post_time $post_time_order
        LIMIT $start, ".$board_config['posts_per_page'];
if ( !($result = $db->sql_query($sql)) )
{
        message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
}

$postrow = array();
if ($row = $db->sql_fetchrow($result))
{
        do
        {
                $postrow[] = $row;
        }
        while ($row = $db->sql_fetchrow($result));
        $db->sql_freeresult($result);

        $total_posts = count($postrow);
}
else
{
   include("includes/functions_admin.php");
   sync('topic', $topic_id);

   message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
}

$resync = FALSE;
if ($forum_topic_data['topic_replies'] + 1 < $start + count($postrow))
{
   $resync = TRUE;
}
elseif ($start + $board_config['posts_per_page'] > $forum_topic_data['topic_replies'])
{
   $row_id = intval($forum_topic_data['topic_replies']) % intval($board_config['posts_per_page']);
   if ($postrow[$row_id]['post_id'] != $forum_topic_data['topic_last_post_id'] || $start + count($postrow) < $forum_topic_data['topic_replies'])
   {
      $resync = TRUE;
   }
}
elseif (count($postrow) < $board_config['posts_per_page'])
{
   $resync = TRUE;
}

if ($resync)
{
   include("includes/functions_admin.php");
   sync('topic', $topic_id);

   $result = $db->sql_query('SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id);
   $row = $db->sql_fetchrow($result);
   $total_replies = $row['total'];
}

$sql = "SELECT *
        FROM " . RANKS_TABLE . "
        ORDER BY rank_special, rank_min";
if ( !($result = $db->sql_query($sql)) )
{
        message_die(GENERAL_ERROR, "Could not obtain ranks information.", '', __LINE__, __FILE__, $sql);
}

$ranksrow = array();
while ( $row = $db->sql_fetchrow($result) )
{
        $ranksrow[] = $row;
}
$db->sql_freeresult($result);

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

//
// Censor topic title
//
if ( count($orig_word) )
{
        $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
}

//
// Was a highlight request part of the URI?
//
$highlight_match = $highlight = '';
if (isset($HTTP_GET_VARS['highlight']))
{
        // Split words and phrases
        $words = explode(' ', trim(htmlspecialchars($HTTP_GET_VARS['highlight'])));

        for($i = 0; $i < sizeof($words); $i++)
        {
                if (trim($words[$i]) != '')
                {
                        $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', preg_quote($words[$i], '#'));
                }
        }
        unset($words);

   $highlight = urlencode($HTTP_GET_VARS['highlight']);
        $highlight_match = phpbb_rtrim($highlight_match, "\\");
}

//
// Post, reply and other URL generation for
// templating vars
//
$new_topic_url = append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id");
$reply_topic_url = append_sid("posting.$phpEx?mode=reply&amp;" . POST_TOPIC_URL . "=$topic_id");
$view_forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id");
$view_prev_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=previous");
$view_next_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=next");

//
// Mozilla navigation bar
//
$nav_links['prev'] = array(
        'url' => $view_prev_topic_url,
        'title' => $lang['View_previous_topic']
);
$nav_links['next'] = array(
        'url' => $view_next_topic_url,
        'title' => $lang['View_next_topic']
);
$nav_links['up'] = array(
        'url' => $view_forum_url,
        'title' => $forum_name
);

$reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
$reply_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
$post_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'];
$post_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];

//
// Set a cookie for this topic
//
if ( $userdata['session_logged_in'] )
{
        $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
        $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();

        if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
        {
                $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
        }
        else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
        {
                $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
        }
        else
        {
                $topic_last_read = $userdata['user_lastvisit'];
        }

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

        $tracking_topics[$topic_id] = time();

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

//
// Load templates
//
$template->set_filenames(array(
        'body' => 'viewtopic_body.tpl')
);
make_jumpbox('viewforum.'.$phpEx, $forum_id);

//
// Output page header
//
$page_title = $lang['View_topic'] .' - ' . $topic_title;
include("includes/page_header.php");

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

$topic_mod = '';

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

        $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&mode=delete") . '"><img src="' . $images['topic_mod_delete'] . '" alt="' . $lang['Delete_topic'] . '" title="' . $lang['Delete_topic'] . '" border="0" /></a>&nbsp;';

        $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&mode=move"). '"><img src="' . $images['topic_mod_move'] . '" alt="' . $lang['Move_topic'] . '" title="' . $lang['Move_topic'] . '" border="0" /></a>&nbsp;';

        $topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&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&mode=unlock") . '"><img src="' . $images['topic_mod_unlock'] . '" alt="' . $lang['Unlock_topic'] . '" title="' . $lang['Unlock_topic'] . '" border="0" /></a>&nbsp;';

        $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&mode=split") . '"><img src="' . $images['topic_mod_split'] . '" alt="' . $lang['Split_topic'] . '" title="' . $lang['Split_topic'] . '" border="0" /></a>&nbsp;';
}

//
// Topic watch information
//
$s_watching_topic = '';
if ( $can_watch_topic )
{
        if ( $is_watching_topic )
        {
                $s_watching_topic = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&unwatch=topic&start=$start") . '">' . $lang['Stop_watching_topic'] . '</a>';
                $s_watching_topic_img = ( isset($images['Topic_un_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&unwatch=topic&start=$start") . '"><img src="' . $images['Topic_un_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Stop_watching_topic'] . '" border="0"></a>' : '';
        }
        else
        {
                $s_watching_topic = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&watch=topic&start=$start") . '">' . $lang['Start_watching_topic'] . '</a>';
                $s_watching_topic_img = ( isset($images['Topic_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&watch=topic&start=$start") . '"><img src="' . $images['Topic_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Start_watching_topic'] . '" border="0"></a>' : '';
        }
}

//
// If we've got a hightlight set pass it on to pagination,
// I get annoyed when I lose my highlight after the first page.
//
$pagination = ( $highlight != '' ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=$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);

//
// Send vars to template
//
$template->assign_vars(array(
        'FORUM_ID' => $forum_id,
    'FORUM_NAME' => $forum_name,
    'TOPIC_ID' => $topic_id,
    'TOPIC_TITLE' => $topic_title,
        'PAGINATION' => $pagination,
        'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / intval($board_config['posts_per_page']) ) + 1 ), ceil( $total_replies / intval($board_config['posts_per_page']) )),

        'POST_IMG' => $post_img,
        'REPLY_IMG' => $reply_img,

        'L_AUTHOR' => $lang['Author'],
        'L_MESSAGE' => $lang['Message'],
        'L_POSTED' => $lang['Posted'],
        'L_POST_SUBJECT' => $lang['Post_subject'],
        'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],
        'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],
        'L_POST_NEW_TOPIC' => $post_alt,
        'L_POST_REPLY_TOPIC' => $reply_alt,
        'L_BACK_TO_TOP' => $lang['Back_to_top'],
        'L_DISPLAY_POSTS' => $lang['Display_posts'],
        'L_LOCK_TOPIC' => $lang['Lock_topic'],
        'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
        'L_MOVE_TOPIC' => $lang['Move_topic'],
        'L_SPLIT_TOPIC' => $lang['Split_topic'],
        'L_DELETE_TOPIC' => $lang['Delete_topic'],
        'L_GOTO_PAGE' => $lang['Goto_page'],

        'S_TOPIC_LINK' => POST_TOPIC_URL,
        'S_SELECT_POST_DAYS' => $select_post_days,
        'S_SELECT_POST_ORDER' => $select_post_order,
        'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&amp;start=$start"),
        'S_AUTH_LIST' => $s_auth_can,
        'S_TOPIC_ADMIN' => $topic_mod,
        'S_WATCH_TOPIC' => $s_watching_topic,
        'S_WATCH_TOPIC_IMG' => $s_watching_topic_img,

        '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=$highlight"),
        'U_VIEW_FORUM' => $view_forum_url,
        'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,
        'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,
        'U_POST_NEW_TOPIC' => $new_topic_url,
        'U_POST_REPLY_TOPIC' => $reply_topic_url)
);

//
// Does this topic contain a poll?
//
if ( !empty($forum_topic_data['topic_vote']) )
{
        $s_hidden_fields = '';

        $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
                FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
                WHERE vd.topic_id = '$topic_id'
                        AND vr.vote_id = vd.vote_id
                ORDER BY vr.vote_option_id ASC";
        if ( !($result = $db->sql_query($sql)) )
        {
                message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql);
        }

        if ( $vote_info = $db->sql_fetchrowset($result) )
        {
                $db->sql_freeresult($result);
                $vote_options = count($vote_info);

                $vote_id = $vote_info[0]['vote_id'];
                $vote_title = $vote_info[0]['vote_text'];

                $sql = "SELECT vote_id
                        FROM " . VOTE_USERS_TABLE . "
                        WHERE vote_id = '$vote_id'
                                AND vote_user_id = " . intval($userdata['user_id']);
                if ( !($result = $db->sql_query($sql)) )
                {
                        message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql);
                }

                $user_voted = ( $row = $db->sql_fetchrow($result) ) ? TRUE : 0;
                $db->sql_freeresult($result);

                if ( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
                {
                        $view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == 'viewresult' ) ? TRUE : 0;
                }
                else
                {
                        $view_result = 0;
                }

                $poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;

                if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
                {
                        $template->set_filenames(array(
                                'pollbox' => 'viewtopic_poll_result.tpl')
                        );

                        $vote_results_sum = 0;

                        for($i = 0; $i < $vote_options; $i++)
                        {
                                $vote_results_sum += $vote_info[$i]['vote_result'];
                        }

                        $vote_graphic = 0;
                        $vote_graphic_max = count($images['voting_graphic']);

                        for($i = 0; $i < $vote_options; $i++)
                        {
                                $vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
                                $vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);

                                $vote_graphic_img = $images['voting_graphic'][$vote_graphic];
                                $vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;

                                if ( count($orig_word) )
                                {
                                        $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
                                }

                                $template->assign_block_vars("poll_option", array(
                                        'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
                                        'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
                                        'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),

                                        'POLL_OPTION_IMG' => $vote_graphic_img,
                                        'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
                                );
                        }

                        $template->assign_vars(array(
                                'L_TOTAL_VOTES' => $lang['Total_votes'],
                                'TOTAL_VOTES' => $vote_results_sum)
                        );

                }
                else
                {
                        $template->set_filenames(array(
                                'pollbox' => 'viewtopic_poll_ballot.tpl')
                        );

                        for($i = 0; $i < $vote_options; $i++)
                        {
                                if ( count($orig_word) )
                                {
                                        $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
                                }

                                $template->assign_block_vars("poll_option", array(
                                        'POLL_OPTION_ID' => $vote_info[$i]['vote_option_id'],
                                        'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'])
                                );
                        }

                        $template->assign_vars(array(
                                'L_SUBMIT_VOTE' => $lang['Submit_vote'],
                                'L_VIEW_RESULTS' => $lang['View_results'],

                                'U_VIEW_RESULTS' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;vote=viewresult"))
                        );

                        $s_hidden_fields = '<input type="hidden" name="topic_id" value="' . $topic_id . '" /><input type="hidden" name="mode" value="vote" />';
                }

                if ( count($orig_word) )
                {
                        $vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
                }

                $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';

                $template->assign_vars(array(
                        'POLL_QUESTION' => $vote_title,

                        'S_HIDDEN_FIELDS' => $s_hidden_fields,
                        'S_POLL_ACTION' => append_sid("posting.$phpEx?mode=vote&amp;" . POST_TOPIC_URL . "=$topic_id"))
                );

                $template->assign_var_from_handle('POLL_DISPLAY', 'pollbox');
        }
}

//
// Update the topic view counter
//
$sql = "UPDATE " . TOPICS_TABLE . "
        SET topic_views = topic_views + 1
        WHERE topic_id = '$topic_id'";
if ( !$db->sql_query($sql) )
{
        message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
}

//
// Okay, let's do the loop, yeah come on baby let's do the loop
// and it goes like this ...
//
for($i = 0; $i < $total_posts; $i++)
{
if ($i=="0") {
$adblock = $adblocktext;
} else {
$adblock = "";
}
        $poster_id = $postrow[$i]['user_id'];
        $poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];

        $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);

        $poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : '';

        $poster_from = ( $postrow[$i]['user_from'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Location'] . ': ' . $postrow[$i]['user_from'] : '';
        $poster_from = ereg_replace(".gif", "", $poster_from);
        $poster_joined = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Joined'] . ': ' . $postrow[$i]['user_regdate'] : '';

   $poster_avatar = '';
   if ( $postrow[$i]['user_avatar_type'] && $poster_id != ANONYMOUS && $postrow[$i]['user_allowavatar'] )
   {
      switch( $postrow[$i]['user_avatar_type'] )
      {
         case USER_AVATAR_UPLOAD:
            $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
            break;
         case USER_AVATAR_REMOTE:
            $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
            break;
         case USER_AVATAR_GALLERY:
            $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
            break;
      }
   }
        $images['default_avatar'] = "modules/Forums/images/avatars/gallery/blank.gif";
        $images['guest_avatar'] = "modules/Forums/images/avatars/gallery/blank.gif";
        //
        // Default Avatar MOD - Begin
        //
        if ( empty($poster_avatar) && $poster_id != ANONYMOUS)
        {
                $poster_avatar = '<img src="'.  $images['default_avatar'] .'" alt="" border="0" />';
        }
        if ( $poster_id == ANONYMOUS )
        {
                $poster_avatar = '<img src="'.  $images['guest_avatar'] .'" alt="" border="0" />';
        }
        //
        // Default Avatar MOD - End
        //
        //
        // Define the little post icon
        //
        if ( $userdata['session_logged_in'] && $postrow[$i]['post_time'] > $userdata['user_lastvisit'] && $postrow[$i]['post_time'] > $topic_last_read )
        {
                $mini_post_img = $images['icon_minipost_new'];
                $mini_post_alt = $lang['New_post'];
        }
        else
        {
                $mini_post_img = $images['icon_minipost'];
                $mini_post_alt = $lang['Post'];
        }

        $mini_post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#' . $postrow[$i]['post_id'];

        //
        // Generate ranks, set them to empty string initially.
        //
        $poster_rank = '';
        $rank_image = '';
        if ( $postrow[$i]['user_id'] == ANONYMOUS )
        {
        }
        else if ( $postrow[$i]['user_rank'] )
        {
                for($j = 0; $j < count($ranksrow); $j++)
                {
                        if ( $postrow[$i]['user_rank'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special'] )
                        {
                                $poster_rank = $ranksrow[$j]['rank_title'];
                                $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
                        }
                }
        }
        else
        {
                for($j = 0; $j < count($ranksrow); $j++)
                {
                        if ( $postrow[$i]['user_posts'] >= $ranksrow[$j]['rank_min'] && !$ranksrow[$j]['rank_special'] )
                        {
                                $poster_rank = $ranksrow[$j]['rank_title'];
                                $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
                        }
                }
        }

        //
        // Handle anon users posting with usernames
        //
        if ( $poster_id == ANONYMOUS && $postrow[$i]['post_username'] != '' )
        {
                $poster = $postrow[$i]['post_username'];
                $poster_rank = $lang['Guest'];
        }

        $temp_url = '';

        if ( $poster_id != ANONYMOUS )
        {
                $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
                $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
                $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';

                $temp_url = append_sid("privmsg.$phpEx?mode=post&amp;" . POST_USERS_URL . "=$poster_id");
                if (is_active("Private_Messages")) {
                $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
                $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
                }

                if ( !empty($postrow[$i]['user_viewemail']) || $is_auth['auth_mod'] )
                {
                        $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&amp;" . POST_USERS_URL .'=' . $poster_id) : 'mailto:' . $postrow[$i]['user_email'];

                        $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
                        $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
                }
                else
                {
                        $email_img = '';
                        $email = '';
                }
                if (( $postrow[$i]['user_website'] == "http:///") || ( $postrow[$i]['user_website'] == "http://")){
                    $postrow[$i]['user_website'] =  "";
                }
                if (($postrow[$i]['user_website'] != "" ) && (substr($postrow[$i]['user_website'],0, 7) != "http://")) {
                    $postrow[$i]['user_website'] = "http://".$postrow[$i]['user_website'];
                }

                $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>' : '';
                $www = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';

                if ( !empty($postrow[$i]['user_icq']) )
                {
                        $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>';
                        $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>';
                        $icq =  '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '">' . $lang['ICQ'] . '</a>';
                }
                else
                {
                        $icq_status_img = '';
                        $icq_img = '';
                        $icq = '';
                }

                $aim_img = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&message=Hello+Are+you+there?"><img src="' . $images['icon_aim'] . '" alt="' . $lang['AIM'] . '" title="' . $lang['AIM'] . '" border="0" /></a>' : '';
                $aim = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';

                $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
                $msn_img = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
                $msn = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';

                $yim_img = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&.src=pg"><img src="' . $images['icon_yim'] . '" alt="' . $lang['YIM'] . '" title="' . $lang['YIM'] . '" border="0" /></a>' : '';
                $yim = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&.src=pg">' . $lang['YIM'] . '</a>' : '';
                $skype_img = ( $postrow[$i]['user_skype'] ) ? '<a href="skype:' . $postrow[$i]['user_skype'] . '"><img src="' . $images['icon_skype'] . '" alt="' . $lang['SKYPE'] . '" title="' . $lang['SKYPE'] . '" border="0" /></a>' : '';
                $skype_status = ( $postrow[$i]['user_skype'] ) ? '<img src="http://mystatus.skype.com/smallicon/' . $postrow[$i]['user_skype'] . '" border="0" />' : '';   
               $skype = ( $postrow[$i]['user_skype'] ) ? '<a href="skype:' . $postrow[$i]['user_skype'] . '">' . $lang['SKYPE'] . '</a>' : '';
        }
        else
        {
                $profile_img = '';
                $profile = '';
                $pm_img = '';
                $pm = '';
                $email_img = '';
                $email = '';
                $www_img = '';
                $www = '';
                $icq_status_img = '';
                $icq_img = '';
                $icq = '';
                $aim_img = '';
                $aim = '';
                $msn_img = '';
                $msn = '';
                $yim_img = '';
                $yim = '';
                $skype_img = '';
                $skype_status = '';
              $skype = '';
        }

        $temp_url = append_sid("posting.$phpEx?mode=quote&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
        $quote_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_quote'] . '" alt="' . $lang['Reply_with_quote'] . '" title="' . $lang['Reply_with_quote'] . '" border="0" /></a>';
        $quote = '<a href="' . $temp_url . '">' . $lang['Reply_with_quote'] . '</a>';

        $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($postrow[$i]['username']) . "&amp;showresults=posts");
   $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . sprintf($lang['Search_user_posts'], $postrow[$i]['username']) . '" title="' . sprintf($lang['Search_user_posts'], $postrow[$i]['username']) . '" border="0" /></a>';
   $search = '<a href="' . $temp_url . '">' . sprintf($lang['Search_user_posts'], $postrow[$i]['username']) . '</a>';

        if ( ( $userdata['user_id'] == $poster_id && $is_auth['auth_edit'] ) || $is_auth['auth_mod'] )
        {
                $temp_url = append_sid("posting.$phpEx?mode=editpost&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
                $edit_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_edit'] . '" alt="' . $lang['Edit_delete_post'] . '" title="' . $lang['Edit_delete_post'] . '" border="0" /></a>';
                $edit = '<a href="' . $temp_url . '">' . $lang['Edit_delete_post'] . '</a>';
        }
        else
        {
                $edit_img = '';
                $edit = '';
        }

        if ( $is_auth['auth_mod'] )
        {
// -> Ban mod by Vladson
      if ($postrow[$i]['user_level'] <> ADMIN && $postrow[$i]['user_level'] <> MOD)
      {
         $temp_url = append_sid("ban.$phpEx?" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;sid=" . $userdata['session_id']);
         $ban_img = '<a href="' . $temp_url . '"><img src="' . $images['user_ban'] . '" alt="' . $lang['user_ban'] . '" title="' . $lang['user_ban'] . '" border="0" /></a>';
         $ban = '<a href="' . $temp_url . '">' . $lang['user_ban'] . '</a>';
      }
      else
      {
         $temp_url = '';
         $ban_img = '';
         $ban = '';
      }
// <- Ban mod by Vladson
                $temp_url = append_sid("modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;" . POST_TOPIC_URL . "=" . $topic_id);
                $ip_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_ip'] . '" alt="' . $lang['View_IP'] . '" title="' . $lang['View_IP'] . '" border="0" /></a>';
                $ip = '<a href="' . $temp_url . '">' . $lang['View_IP'] . '</a>';

                $temp_url = append_sid("posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
                $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
                $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
        }
        else
        {
                $ip_img = '';
                $ip = '';

                if ( $userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $forum_topic_data['topic_last_post_id'] == $postrow[$i]['post_id'] )
                {
                        $temp_url = append_sid("posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
                        $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
                        $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
                }
                else
                {
                        $delpost_img = '';
                        $delpost = '';
                }
        }

        $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : '';

        $message = $postrow[$i]['post_text'];
        $bbcode_uid = $postrow[$i]['bbcode_uid'];

        $user_sig = ( $postrow[$i]['enable_sig'] && $postrow[$i]['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow[$i]['user_sig'] : '';
        $user_sig_bbcode_uid = $postrow[$i]['user_sig_bbcode_uid'];

        //
        // Note! The order used for parsing the message _is_ important, moving things around could break any
        // output
        //

        //
        // If the board has HTML off but the post has HTML
        // on then we process it, else leave it alone
        //
   if ( !$board_config['allow_html'] || !$userdata['user_allowhtml'])
        {
                if ( $user_sig != '' )
                {
                        $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
                }

                if ( $postrow[$i]['enable_html'] )
                {
                        $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
                }
        }

        //
        // Parse message and/or sig for BBCode if reqd
        //
   if ($user_sig != '' && $user_sig_bbcode_uid != '')
   {
      $user_sig = ($board_config['allow_bbcode']) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace("/\:$user_sig_bbcode_uid/si", '', $user_sig);
   }

   if ($bbcode_uid != '')
   {
      $message = ($board_config['allow_bbcode']) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace("/\:$bbcode_uid/si", '', $message);
   }

        if ( $user_sig != '' )
        {
                $user_sig = make_clickable($user_sig);
        }
        $message = make_clickable($message);

        //
        // Parse smilies
        //
        if ( $board_config['allow_smilies'] )
        {
                if ( $postrow[$i]['user_allowsmile'] && $user_sig != '' )
                {
                        $user_sig = smilies_pass($user_sig);
                }

                if ( $postrow[$i]['enable_smilies'] )
                {
                        $message = smilies_pass($message);
                }
        }

        //
        // Highlight active words (primarily for search)
        //
        if ($highlight_match)
        {
                // This was shamelessly 'borrowed' from volker at multiartstudio dot de
                // via php.net's annotated manual
      $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace('#\b(" . str_replace('\\', '\\\\', addslashes($highlight_match)) . ")\b#i', '<span style=\"color:#" . $theme['fontcolor3'] . "\"><b>\\\\1</b></span>', '\\0')", '>' . $message . '<'), 1, -1));
        }

        //
        // Replace naughty words
        //
        if (count($orig_word))
        {
                $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);

                if ($user_sig != '')
                {
         $user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1));
                }

      $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1));
        }

        //
        // Replace newlines (we use this rather than nl2br because
        // till recently it wasn't XHTML compliant)
        //
        if ( $user_sig != '' )
        {
                $user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
        }

        $message = str_replace("\n", "\n<br />\n", $message);

        //
        // Editing information
        //
        if ( $postrow[$i]['post_edit_count'] )
        {
                $l_edit_time_total = ( $postrow[$i]['post_edit_count'] == 1 ) ? $lang['Edited_time_total'] : $lang['Edited_times_total'];

                $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']);
        }
        else
        {
                $l_edited_by = '';
        }

        //
        // Again this will be handled by the templating
        // code at some point
        //
        $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
        $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];

        $template->assign_block_vars('postrow', array(
                'ROW_COLOR' => '#' . $row_color,
                'ROW_CLASS' => $row_class,
                'AD_BLOCK' => $adblock,
                'POSTER_NAME' => $poster,
                'POSTER_COLOR' => get_user_color($poster_id),
                'POSTER_RANK' => $poster_rank,
                'RANK_IMAGE' => $rank_image,
                'POSTER_JOINED' => $poster_joined,
                'POSTER_POSTS' => $poster_posts,
                'POSTER_FROM' => $poster_from,
                'POSTER_AVATAR' => $poster_avatar,
                'POST_DATE' => $post_date,
                'POST_SUBJECT' => $post_subject,
                'MESSAGE' => $message,
                'SIGNATURE' => $user_sig,
                'EDITED_MESSAGE' => $l_edited_by,

                'MINI_POST_IMG' => $mini_post_img,
                'PROFILE_IMG' => $profile_img,
                'PROFILE' => $profile,
                'SEARCH_IMG' => $search_img,
                'SEARCH' => $search,
                'PM_IMG' => $pm_img,
                'PM' => $pm,
                'EMAIL_IMG' => $email_img,
                'EMAIL' => $email,
                'WWW_IMG' => $www_img,
                'WWW' => $www,
                'ICQ_STATUS_IMG' => $icq_status_img,
                'ICQ_IMG' => $icq_img,
                'ICQ' => $icq,
                'AIM_IMG' => $aim_img,
                'AIM' => $aim,
                'MSN_IMG' => $msn_img,
                'MSN' => $msn,
                'YIM_IMG' => $yim_img,
                'YIM' => $yim,
               'SKYPE_IMG' => $skype_img,
                'SKYPE_STATUS' => $skype_status,
              'SKYPE' => $skype,
                'EDIT_IMG' => $edit_img,
                'EDIT' => $edit,
                'QUOTE_IMG' => $quote_img,
                'QUOTE' => $quote,
                'IP_IMG' => $ip_img,
                'IP' => $ip,
                'DELETE_IMG' => $delpost_img,
                'DELETE' => $delpost,
              'BAN_IMG' => ( $is_auth['auth_mod'] ) ? $ban_img : '',
              'BAN' => ( $is_auth['auth_mod'] ) ? $ban : '',

                'L_MINI_POST_ALT' => $mini_post_alt,

                'U_MINI_POST' => $mini_post_url,
                'U_POST_ID' => $postrow[$i]['post_id'])
        );
}

include($phpbb_root_path . 'quick_reply.'.$phpEx);

$template->pparse('body');

include("includes/page_tail.php");

?>


icon_rolleyes.gif


Back to top Reply with quote
#9   
Telli
Site Admin
Telli has been a member for over 20 year's 20 Year Member
Occupation: Self Employed
Age: 45
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.06 posts per day
Posts: 8089
Points: 494,430
   
Try replacing the generate_pagination function with this instead and let me know:


function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE) {
      return pagination(append_sid($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
#10   re: News Page Number (want the new codezwiz version please)
prekill
CZ Newbie
prekill has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Jul 15, 2005
0.00 posts per day
Posts: 28
Points: 148
   
Well... working 100% now! Thank you very very much!

I am trying to apply this in my_egallery module too but with no successes.

I have tried to edit the following function:

function navigationCat($gid, $offset, $orderby) {
   global
      $font,
                $galleryvar,
      $baseurl,
      $prefix
   ;
   $limit = $galleryvar['maxNumberMedia'];
   $orderby = convertorderbyout($orderby);
   $numresults = mysql_query("select * from $prefix"._gallery_pictures." where gid=$gid");
   $numrows=mysql_num_rows($numresults);
   $nav = '';
   $pages=intval($numrows/$limit);

   if ($numrows>0 & $pages>=1) {
      if ($offset!=0) {
   $prevoffset=$offset-$limit;
              $nav = "<a class=\"".$font['normal']."\" href=\"$baseurl&do=showgall&gid=$gid&offset=$prevoffset&orderby=$orderby\"><img src=\"modules/My_eGallery/images/navright.gif\" border=\"0\"></a>&nbsp;.&nbsp;";
      }

      if ($numrows%$limit) {
              $pages++;
      }
      
      for ($i=1;$i<=$pages; $i++) {
              $newoffset=$limit*($i-1);
              if ($newoffset==$offset) {
                 $nav .= "<font class=\"".$font['normal']."\" color=\"blue\"><b>";
                 if ($i==1)
                    if ($pages==1)
                       $nav .= "<img src=\"modules/My_eGallery/images/navright.gif\" border=\"0\"> . ".$i." . <img src=\"modules/My_eGallery/images/navleft.gif\" border=\"0\">";
                    else
                       $nav .= "<img src=\"modules/My_eGallery/images/navright.gif\" border=\"0\"> . ".$i."&nbsp;.&nbsp;";
                 elseif  ($i==$pages)
                    $nav .= $i."&nbsp;.&nbsp;<img src=\"modules/My_eGallery/images/navleft.gif\" border=\"0\">";
                 else
                    $nav .= $i."&nbsp;.&nbsp;";
                 $nav .= "</b></font>";
              }
              else {
                 $nav .= "<a class=\"".$font['normal']."\" href=\"$baseurl&do=showgall&gid=$gid&offset=$newoffset&orderby=$orderby\">$i</a>&nbsp;.&nbsp;";
              }
      }
      if (!(($offset/$limit)==($pages-1)) && $pages!=1) {
              $newoffset=$offset+$limit;
                 $nav .= "<a class=\"".$font['normal']."\" href=\"$baseurl&do=showgall&gid=$gid&offset=$newoffset&orderby=$orderby\"><img src=\"modules/My_eGallery/images/navleft.gif\" border=\"0\"></a>";
      }
   }
   return $nav;
}


This is what I came up with:

function navigationCat($gid, $offset, $orderby) {
   global $font, $galleryvar, $baseurl, $prefix;

   $limit = $galleryvar['maxNumberMedia'];
   $orderby = convertorderbyout($orderby);
   $numresults = mysql_query("select * from $prefix"._gallery_pictures." where gid=$gid");
   $numrows=mysql_num_rows($numresults);
   $pages=intval($numrows/$limit);
    $start = ($offset > 0) ? '&amp;offset=' . $offset : '';
    $add_url = ($gid > 0) ? '&amp;do=showgall&amp;gid=' . $gid : '';

$nav = pagination('modules.php?name=My_eGallery' . $add_url, $pages, $limit, $start);
return $nav;
}


There is no error given but also the pagnation will not appear. As I played with the vaules in pagination it did appear but was all wrong numbers.

any idea on this one?


Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum