' . sprintf($lang['login_require_register'], '', '');
message_die(GENERAL_MESSAGE, $message);
}
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']);
}
else
{
$topic_id = 0;
}
if ( !$topic_id )
{
message_die(GENERAL_MESSAGE, 'No_such_post');
}
$do_gzip_compress = FALSE;
if ( $board_config['gzip_compress'] )
{
$phpver = phpversion();
$useragent = (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) ? $HTTP_SERVER_VARS['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT');
$is_ob_gzhandler_started = false;
if ( @ini_get('zlib.output_compression') && (int)@ini_get('zlib.output_compression') != 0 && strtolower(@ini_get('zlib.output_compression')) != 'off' )
{
$is_ob_gzhandler_started = true;
}
else if ( @ini_get('output_handler') && strtolower(@ini_get('output_handler'))=='ob_gzhandler' )
{
$is_ob_gzhandler_started = true;
}
if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
{
if ( extension_loaded('zlib') && !$is_ob_gzhandler_started )
{
@ob_start('ob_gzhandler');
}
}
else if ( $phpver > '4.0' )
{
if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
{
if ( extension_loaded('zlib') && !$is_ob_gzhandler_started )
{
$do_gzip_compress = TRUE;
@ob_start();
@ob_implicit_flush(0);
@header('Content-Encoding: gzip');
}
}
}
}
$template->set_filenames(array(
'body' => 'viewtopic_print.tpl')
);
$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_poster, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.forum_moderate, f.password, p.post_approve as topic_approve
FROM (" . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p)
WHERE t.topic_id = " . $topic_id . "
AND f.forum_id = t.forum_id
AND p.post_id = t.topic_first_post_id";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Couldn\'t obtain topic information', '', __LINE__, __FILE__, $sql);
}
if ( !($forum_row = $db->sql_fetchrow($result)) )
{
message_die(GENERAL_MESSAGE, 'No_such_post');
}
$forum_id = $forum_row['forum_id'];
$forum_name = $forum_row['forum_name'];
$topic_title = $forum_row['topic_title'];
$topic_time = $forum_row['topic_time'];
if ( $forum_row['forum_moderate'] && !$forum_row['topic_approve'] )
{
$topic_title = $forum_row['topic_title'] = '';
}
$is_auth = array();
$is_auth = $tree['auth'][POST_FORUM_URL . $forum_id];
$forum_view_moderate = ($forum_row['forum_moderate'] && !$is_auth['auth_mod']) ? true : false;
if ( !$is_auth['auth_read'] )
{
if ( !$userdata['session_logged_in'] )
{
$redirect = 't=' . $topic_id;
redirect(append_sid("login.$phpEx?redirect=printview.$phpEx&$redirect", true));
}
$message = sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
message_die(GENERAL_MESSAGE, $message);
}
if ( $forum_row['password'] != '' )
{
if ( !$is_auth['auth_mod'] || $user_level != ADMIN )
{
$redirect = str_replace('&', '&', preg_replace('#.*?([a-z]+?\.' . $phpEx . '.*?)$#i', '\1', htmlspecialchars($_SERVER['REQUEST_URI'])));
$cookie_forum_pass = $unique_cookie_name . '_fpass_' . $forum_id;
if ( $HTTP_POST_VARS['cancel'] )
{
redirect(append_sid("index.$phpEx"));
}
else if ( $HTTP_POST_VARS['submit'] )
{
password_check($forum_id, $HTTP_POST_VARS['password'], $redirect, $forum_row['password']);
}
if ( ($forum_row['password'] != '') && ($HTTP_COOKIE_VARS[$cookie_forum_pass] != md5($forum_row['password'])) )
{
password_box($forum_id, $redirect);
}
}
}
$sql = "SELECT u.username, u.user_id, u.user_level, u.user_jr, u.user_allowhtml, 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
AND pt.post_id = p.post_id
AND u.user_id = p.poster_id
ORDER BY p.post_order, p.post_time";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Couldn\'t obtain post/user information.', '', __LINE__, __FILE__, $sql);
}
if(!$total_posts = $db->sql_numrows($result))
{
message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
}
$postrow = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$orig_word = array();
$replacement_word = array();
$replacement_word = array();
$replacement_word_html = array();
obtain_word_list($orig_word, $replacement_word, $replacement_word_html);
if ( count($orig_word) )
{
$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
}
$forum_moderators = moderarots_list($forum_id, 'mod');
for($i = 0; $i < $total_posts; $i++)
{
$poster_id = $postrow[$i]['user_id'];
$poster = $postrow[$i]['username'];
$post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
$post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : '';
$message = $postrow[$i]['post_text'];
$bbcode_uid = $postrow[$i]['bbcode_uid'];
if ( $postrow[$i]['user_level'] != ANONYMOUS && $postrow[$i]['user_level'] != ADMIN && $postrow[$i]['user_level'] == MOD )
{
$poster_is_mod_here = (@in_array($poster_id, $forum_moderators)) ? true : false;
}
else
{
$poster_is_mod_here = false;
$poster_is_jr_admin = ($postrow[$i]['user_jr']) ? true : false;
}
$show_post_html = ($board_config['allow_html'] && $postrow[$i]['user_allowhtml']) ? true : false;
if ( ($poster_is_mod_here && $board_config['mod_html']) || ($board_config['admin_html'] && $postrow[$i]['user_level'] == ADMIN) || ($board_config['jr_admin_html'] && $poster_is_jr_admin) )
{
$show_post_html = true;
}
if ( !$show_post_html )
{
if ( $postrow[$i]['enable_html'] )
{
$message = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $message);
}
}
$strip_br = ($show_post_html && (strpos($message, '') !== false || strpos($message, ' | ') !== false || strpos($message, '') !== false)) ? true : false;
if ( $postrow[$i]['user_level'] != ADMIN && $postrow[$i]['user_level'] != MOD || $userdata['user_jr'] || $is_auth['auth_mod'] )
{
$message = preg_replace("#\[mod\](.*?)\[/mod\]#si", "
Mod Info:
[\\1]
", $message);
}
elseif ( eregi("[mod]", $message) )
{
$message = preg_replace("#\[mod\](.*?)\[/mod\]#si", "", $message);
}
if( $bbcode_uid != '' )
{
$message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid, $userdata['username']) : preg_replace("/\:[0-9a-z\:]+\]/si", "]", $message);
}
$message = make_clickable($message);
if ( count($orig_word) )
{
$post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
$message = preg_replace($orig_word, $replacement_word_html, $message);
}
if ( $board_config['allow_smilies'] && $userdata['show_smiles'] )
{
if ( $postrow[$i]['enable_smilies'] )
{
$message = smilies_pass($message);
}
}
$message = (eregi("\[hide:", $message) && eregi("\[/hide:", $message)) ? '' : $message;
if ( !$strip_br )
{
$message = str_replace("\n", "\n
\n", $message);
}
if ( !$postrow[$i]['post_approve'] && $forum_view_moderate )
{
$poster_id = $poster = $bbcode_uid = $message = '';
$post_subject = '' . $lang['Post_no_approved'] . '';
}
$template->assign_block_vars('postrow', array(
'POSTER_NAME' => ($postrow[$i]['user_id'] == ANONYMOUS) ? (($postrow[$i]['post_username']) ? $postrow[$i]['post_username'] : $lang['Guest']) : $postrow[$i]['username'],
'POST_DATE' => $post_date,
'POST_SUBJECT' => ($post_subject) ? '' . $lang['Post_subject'] . ': ' . $post_subject : '',
'MESSAGE' => $message)
);
}
$template->assign_vars(array(
'S_CONTENT_DIRECTION' => $lang['DIRECTION'],
'S_CONTENT_ENCODING' => $lang['ENCODING'],
'PAGE_TITLE' => $lang['View_topic'] .' - ' . $topic_title,
'FORUM_NAME' => $forum_name,
'TOPIC_TITLE' => $topic_title,
'SITENAME' => $board_config['sitename'],
'SITE_DESCRIPTION' => $board_config['site_desc'])
);
$template->pparse('body');
$db->sql_close();
if ( $do_gzip_compress )
{
//
// Borrowed from php.net!
//
$gzip_contents = @ob_get_contents();
@ob_end_clean();
$gzip_size = strlen($gzip_contents);
$gzip_crc = @crc32($gzip_contents);
$gzip_contents = @gzcompress($gzip_contents, 9);
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $gzip_contents;
echo pack('V', $gzip_crc);
echo pack('V', $gzip_size);
}
exit;
?>