كود:
<?php
define( "IN_PHPBB", true );
$phpbb_root_path = defined( "PHPBB_ROOT_PATH" ) ? PHPBB_ROOT_PATH : "./";
$phpEx = substr( strrchr( __FILE__, "." ), 1 );
include( $phpbb_root_path."common.".$phpEx );
include( $phpbb_root_path."includes/functions_display.".$phpEx );
include( $phpbb_root_path."includes/bbcode.".$phpEx );
$user->session_begin( );
$auth->acl( $user->data );
$forum_id = request_var( "f", 0 );
$topic_id = request_var( "t", 0 );
$post_id = request_var( "p", 0 );
$voted_id = request_var( "vote_id", array( "" => 0 ) );
$start = request_var( "start", 0 );
$view = request_var( "view", "" );
$sort_days = request_var( "st", !empty( $user->data['user_post_show_days'] ) ? $user->data['user_post_show_days'] : 0 );
$sort_key = request_var( "sk", !empty( $user->data['user_post_sortby_type'] ) ? $user->data['user_post_sortby_type'] : "t" );
$sort_dir = request_var( "sd", !empty( $user->data['user_post_sortby_dir'] ) ? $user->data['user_post_sortby_dir'] : "a" );
$update = request_var( "update", false );
$hilit_words = request_var( "hilit", "", true );
if ( !$topic_id && !$post_id )
{
trigger_error( "NO_TOPIC" );
}
if ( $view && !$post_id )
{
if ( !$forum_id )
{
$sql = "SELECT forum_id\n\t\t\tFROM ".TOPICS_TABLE."\n\t\t\tWHERE topic_id = {$topic_id}";
$result = $db->sql_query( $sql );
$forum_id = ( integer )$db->sql_fetchfield( "forum_id" );
$db->sql_freeresult( $result );
if ( !$forum_id )
{
trigger_error( "NO_TOPIC" );
}
}
if ( $view == "unread" )
{
$topic_tracking_info = get_complete_topic_tracking( $forum_id, $topic_id );
$topic_last_read = isset( $topic_tracking_info[$topic_id] ) ? $topic_tracking_info[$topic_id] : 0;
$sql = "SELECT post_id, topic_id, forum_id\n\t\t\tFROM ".POSTS_TABLE."\n\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t".( $auth->acl_get( "m_approve", $forum_id ) ? "" : "AND post_approved = 1" )."\n\t\t\t\tAND post_time > {$topic_last_read}\n\t\t\tORDER BY post_time ASC";
$result = $db->sql_query_limit( $sql, 1 );
$row = $db->sql_fetchrow( $result );
$db->sql_freeresult( $result );
if ( !$row )
{
$sql = "SELECT topic_last_post_id as post_id, topic_id, forum_id\n\t\t\t\tFROM ".TOPICS_TABLE."\n\t\t\t\tWHERE topic_id = ".$topic_id;
$result = $db->sql_query( $sql );
$row = $db->sql_fetchrow( $result );
$db->sql_freeresult( $result );
}
if ( !$row )
{
$user->setup( "viewtopic" );
trigger_error( "NO_TOPIC" );
}
$post_id = $row['post_id'];
$topic_id = $row['topic_id'];
}
else if ( $view == "next" || $view == "previous" )
{
$sql_condition = $view == "next" ? ">" : "<";
$sql_ordering = $view == "next" ? "ASC" : "DESC";
$sql = "SELECT forum_id, topic_last_post_time\n\t\t\tFROM ".TOPICS_TABLE."\n\t\t\tWHERE topic_id = ".$topic_id;
$result = $db->sql_query( $sql );
$row = $db->sql_fetchrow( $result );
$db->sql_freeresult( $result );
if ( !$row )
{
$user->setup( "viewtopic" );
trigger_error( $view == "next" ? "NO_NEWER_TOPICS" : "NO_OLDER_TOPICS" );
}
$post_edit_list[$user_edit_row['user_id']] = $user_edit_row;
}
$db->sql_freeresult( $result2 );
unset( $post_storage_list );
}
$l_edit_time_total = $row['post_edit_count'] == 1 ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
if ( $row['post_edit_reason'] )
{
if ( !$row['post_edit_user'] || $row['post_edit_user'] == $poster_id )
{
$display_username = get_username_string( "full", $poster_id, $row['username'], $row['user_colour'], $row['post_username'] );
}
else
{
$display_username = get_username_string( "full", $row['post_edit_user'], $post_edit_list[$row['post_edit_user']]['username'], $post_edit_list[$row['post_edit_user']]['user_colour'] );
}
$l_edited_by = sprintf( $l_edit_time_total, $display_username, $user->format_date( $row['post_edit_time'] ), $row['post_edit_count'] );
}
else
{
if ( $row['post_edit_user'] && !isset( $user_cache[$row['post_edit_user']] ) )
{
$user_cache[$row['post_edit_user']] = $post_edit_list[$row['post_edit_user']];
}
if ( !$row['post_edit_user'] || $row['post_edit_user'] == $poster_id )
{
$display_username = get_username_string( "full", $poster_id, $row['username'], $row['user_colour'], $row['post_username'] );
}
else
{
$display_username = get_username_string( "full", $row['post_edit_user'], $user_cache[$row['post_edit_user']]['username'], $user_cache[$row['post_edit_user']]['user_colour'] );
}
$l_edited_by = sprintf( $l_edit_time_total, $display_username, $user->format_date( $row['post_edit_time'] ), $row['post_edit_count'] );
}
}
else
{
$l_edited_by = "";
}
if ( $topic_data['topic_bumped'] && $row['post_id'] == $topic_data['topic_last_post_id'] && isset( $user_cache[$topic_data['topic_bumper']] ) )
{
$l_bumped_by = "<br /><br />".sprintf( $user->lang['BUMPED_BY'], $user_cache[$topic_data['topic_bumper']]['username'], $user->format_date( $topic_data['topic_last_post_time'] ) );
}
else
{
$l_bumped_by = "";
}
$cp_row = array( );
if ( $config['load_cpf_viewtopic'] )
{
$cp_row = isset( $profile_fields_cache[$poster_id] ) ? $cp->generate_profile_fields_template( "show", false, $profile_fields_cache[$poster_id] ) : array( );
}
$post_unread = isset( $topic_tracking_info[$topic_id] ) && $topic_tracking_info[$topic_id] < $row['post_time'] ? true : false;
$s_first_unread = false;
if ( !$first_unread && $post_unread )
{
$s_first_unread = $first_unread = true;
}
$postrow = array(
"POST_AUTHOR_FULL" => get_username_string( "full", $poster_id, $row['username'], $row['user_colour'], $row['post_username'] ),
"POST_AUTHOR_COLOUR" => get_username_string( "colour", $poster_id, $row['username'], $row['user_colour'], $row['post_username'] ),
"POST_AUTHOR" => get_username_string( "username", $poster_id, $row['username'], $row['user_colour'], $row['post_username'] ),
"U_POST_AUTHOR" => get_username_string( "profile", $poster_id, $row['username'], $row['user_colour'], $row['post_username'] ),
"RANK_TITLE" => $user_cache[$poster_id]['rank_title'],
"RANK_IMG" => $user_cache[$poster_id]['rank_image'],
"RANK_IMG_SRC" => $user_cache[$poster_id]['rank_image_src'],
"POSTER_JOINED" => $user_cache[$poster_id]['joined'],
"POSTER_POSTS" => $user_cache[$poster_id]['posts'],
"POSTER_FROM" => $user_cache[$poster_id]['from'],
"POSTER_AVATAR" => $user_cache[$poster_id]['avatar'],
"POSTER_WARNINGS" => $user_cache[$poster_id]['warnings'],
"POSTER_AGE" => $user_cache[$poster_id]['age'],
"POST_DATE" => $user->format_date( $row['post_time'] ),
"POST_SUBJECT" => $row['post_subject'],
"MESSAGE" => $message,
"SIGNATURE" => $row['enable_sig'] ? $user_cache[$poster_id]['sig'] : "",
"EDITED_MESSAGE" => $l_edited_by,
"EDIT_REASON" => $row['post_edit_reason'],
"BUMPED_MESSAGE" => $l_bumped_by,
"MINI_POST_IMG" => $post_unread ? $user->img( "icon_post_target_unread", "NEW_POST" ) : $user->img( "icon_post_target", "POST" ),
"POST_ICON_IMG" => $topic_data['enable_icons'] && !empty( $row['icon_id'] ) ? $icons[$row['icon_id']]['img'] : "",
"POST_ICON_IMG_WIDTH" => $topic_data['enable_icons'] && !empty( $row['icon_id'] ) ? $icons[$row['icon_id']]['width'] : "",
"POST_ICON_IMG_HEIGHT" => $topic_data['enable_icons'] && !empty( $row['icon_id'] ) ? $icons[$row['icon_id']]['height'] : "",
"ICQ_STATUS_IMG" => $user_cache[$poster_id]['icq_status_img'],
"ONLINE_IMG" => $poster_id == ANONYMOUS || !$config['load_onlinetrack'] ? "" : $user_cache[$poster_id]['online'] ? $user->img( "icon_user_online", "ONLINE" ) : $user->img( "icon_user_offline", "OFFLINE" ),
"S_ONLINE" => $poster_id == ANONYMOUS || !$config['load_onlinetrack'] ? false : $user_cache[$poster_id]['online'] ? true : false,
"U_EDIT" => !$user->data['is_registered'] ? "" : $user->data['user_id'] == $poster_id && $auth->acl_get( "f_edit", $forum_id ) && ( time( ) - $config['edit_time'] * 60 < $row['post_time'] || !$config['edit_time'] ) || $auth->acl_get( "m_edit", $forum_id ) ? append_sid( "{$phpbb_root_path}posting.{$phpEx}", "mode=edit&f={$forum_id}&p={$row['post_id']}" ) : "",
"U_QUOTE" => $auth->acl_get( "f_reply", $forum_id ) ? append_sid( "{$phpbb_root_path}posting.{$phpEx}", "mode=quote&f={$forum_id}&p={$row['post_id']}" ) : "",
"U_INFO" => $auth->acl_get( "m_info", $forum_id ) ? append_sid( "{$phpbb_root_path}mcp.{$phpEx}", "i=main&mode=post_details&f={$forum_id}&p=".$row['post_id'], true, $user->session_id ) : "",
"U_DELETE" => !$user->data['is_registered'] ? "" : $user->data['user_id'] == $poster_id && $auth->acl_get( "f_delete", $forum_id ) && $topic_data['topic_last_post_id'] == $row['post_id'] && ( time( ) - $config['edit_time'] * 60 < $row['post_time'] || !$config['edit_time'] ) || $auth->acl_get( "m_delete", $forum_id ) ? append_sid( "{$phpbb_root_path}posting.{$phpEx}", "mode=delete&f={$forum_id}&p={$row['post_id']}" ) : "",
"U_PROFILE" => $user_cache[$poster_id]['profile'],
"U_SEARCH" => $user_cache[$poster_id]['search'],
"U_PM" => $poster_id != ANONYMOUS && $config['allow_privmsg'] && $auth->acl_get( "u_sendpm" ) && ( $user_cache[$poster_id]['allow_pm'] || $auth->acl_gets( "a_", "m_" ) || $auth->acl_getf_global( "m_" ) ) ? append_sid( "{$phpbb_root_path}ucp.{$phpEx}", "i=pm&mode=compose&action=quotepost&p=".$row['post_id'] ) : "",
"U_EMAIL" => $user_cache[$poster_id]['email'],
"U_WWW" => $user_cache[$poster_id]['www'],
"U_ICQ" => $user_cache[$poster_id]['icq'],
"U_AIM" => $user_cache[$poster_id]['aim'],
"U_MSN" => $user_cache[$poster_id]['msn'],
"U_YIM" => $user_cache[$poster_id]['yim'],
"U_JABBER" => $user_cache[$poster_id]['jabber'],
"U_REPORT" => $auth->acl_get( "f_report", $forum_id ) ? append_sid( "{$phpbb_root_path}report.{$phpEx}", "f=".$forum_id."&p=".$row['post_id'] ) : "",
"U_MCP_REPORT" => $auth->acl_get( "m_report", $forum_id ) ? append_sid( "{$phpbb_root_path}mcp.{$phpEx}", "i=reports&mode=report_details&f=".$forum_id."&p=".$row['post_id'], true, $user->session_id ) : "",
"U_MCP_APPROVE" => $auth->acl_get( "m_approve", $forum_id ) ? append_sid( "{$phpbb_root_path}mcp.{$phpEx}", "i=queue&mode=approve_details&f=".$forum_id."&p=".$row['post_id'], true, $user->session_id ) : "",
"U_MINI_POST" => append_sid( "{$phpbb_root_path}viewtopic.{$phpEx}", "p=".$row['post_id'] ).( $topic_data['topic_type'] == POST_GLOBAL ? "&f=".$forum_id : "" )."#p".$row['post_id'],
"U_NEXT_POST_ID" => $i < $i_total && isset( $rowset[$post_list[$i + 1]] ) ? $rowset[$post_list[$i + 1]]['post_id'] : "",
"U_PREV_POST_ID" => $prev_post_id,
"U_NOTES" => $auth->acl_getf_global( "m_" ) ? append_sid( "{$phpbb_root_path}mcp.{$phpEx}", "i=notes&mode=user_notes&u=".$poster_id, true, $user->session_id ) : "",
"U_WARN" => $auth->acl_get( "m_warn" ) && $poster_id != $user->data['user_id'] && $poster_id != ANONYMOUS ? append_sid( "{$phpbb_root_path}mcp.{$phpEx}", "i=warn&mode=warn_post&f=".$forum_id."&p=".$row['post_id'], true, $user->session_id ) : "",
"POST_ID" => $row['post_id'],
"POSTER_ID" => $poster_id,
"S_HAS_ATTACHMENTS" => !empty( $attachments[$row['post_id']] ) ? true : false,
"S_POST_UNAPPROVED" => $row['post_approved'] ? false : true,
"S_POST_REPORTED" => $row['post_reported'] && $auth->acl_get( "m_report", $forum_id ) ? true : false,
"S_DISPLAY_NOTICE" => $display_notice && $row['post_attachment'],
"S_FRIEND" => $row['friend'] ? true : false,
"S_UNREAD_POST" => $post_unread,
"S_FIRST_UNREAD" => $s_first_unread,
"S_CUSTOM_FIELDS" => isset( $cp_row['row'] ) && sizeof( $cp_row['row'] ) ? true : false,
"S_TOPIC_POSTER" => $topic_data['topic_poster'] == $poster_id ? true : false,
"S_IGNORE_POST" => $row['hide_post'] ? true : false,
"L_IGNORE_POST" => $row['hide_post'] ? sprintf( $user->lang['POST_BY_FOE'], get_username_string( "full", $poster_id, $row['username'], $row['user_colour'], $row['post_username'] ), "<a href=\"".$viewtopic_url."&p={$row['post_id']}&view=show#p{$row['post_id']}"."\">", "</a>" ) : ""
);
if ( isset( $cp_row['row'] ) && sizeof( $cp_row['row'] ) )
{
$postrow = array_merge( $postrow, $cp_row['row'] );
}
$template->assign_block_vars( "postrow", $postrow );
if ( !empty( $cp_row['blockrow'] ) )
{
foreach ( $cp_row['blockrow'] as $field_data )
{
$template->assign_block_vars( "postrow.custom_fields", $field_data );
}
}
if ( !empty( $attachments[$row['post_id']] ) )
{
foreach ( $attachments[$row['post_id']] as $attachment )
{
$template->assign_block_vars( "postrow.attachment", array(
"DISPLAY_ATTACHMENT" => $attachment
) );
}
}
$prev_post_id = $row['post_id'];
unset( $rowset->$post_list[$i] );
unset( $attachments->$row['post_id'] );
}
}
unset( $rowset );
unset( $user_cache );
if ( isset( $user->data['session_page'] ) && strpos( $user->data['session_page'], "&t=".$topic_id ) === false )
{
$sql = "UPDATE ".TOPICS_TABLE."\n\t\tSET topic_views = topic_views + 1, topic_last_view_time = ".time( )."\n\t\tWHERE topic_id = {$topic_id}";
$db->sql_query( $sql );
if ( sizeof( $update_count ) )
{
$sql = "UPDATE ".ATTACHMENTS_TABLE."\n\t\t\tSET download_count = download_count + 1\n\t\t\tWHERE ".$db->sql_in_set( "attach_id", array_unique( $update_count ) );
$db->sql_query( $sql );
}
}
if ( isset( $topic_tracking_info[$topic_id] ) && $topic_tracking_info[$topic_id] < $topic_data['topic_last_post_time'] && $topic_tracking_info[$topic_id] < $max_post_time )
{
markread( "topic", $forum_id, $topic_id, $max_post_time );
$all_marked_read = update_forum_tracking_info( $forum_id, $topic_data['forum_last_post_time'], isset( $topic_data['forum_mark_time'] ) ? $topic_data['forum_mark_time'] : false, false );
}
else
{
$all_marked_read = true;
}
if ( $all_marked_read )
{
if ( $post_unread )
{
$template->assign_vars( array( "U_VIEW_UNREAD_POST" => "#unread" ) );
}
else if ( isset( $topic_tracking_info[$topic_id] ) && $topic_tracking_info[$topic_id] < $topic_data['topic_last_post_time'] )
{
$template->assign_vars( array(
"U_VIEW_UNREAD_POST" => append_sid( "{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&t={$topic_id}&view=unread" )."#unread"
) );
}
}
else if ( !$all_marked_read )
{
$last_page = floor( $start / $config['posts_per_page'] ) + 1 == max( ceil( $total_posts / $config['posts_per_page'] ), 1 ) ? true : false;
if ( $last_page && $post_unread )
{
$template->assign_vars( array( "U_VIEW_UNREAD_POST" => "#unread" ) );
}
else if ( !$last_page )
{
$template->assign_vars( array(
"U_VIEW_UNREAD_POST" => append_sid( "{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&t={$topic_id}&view=unread" )."#unread"
) );
}
}
if ( empty( $_REQUEST['f'] ) )
{
$GLOBALS['_REQUEST']['f'] = $forum_id;
}
page_header( $user->lang['VIEW_TOPIC']." - ".$topic_data['topic_title'] );
$template->set_filenames( array(
"body" => $view == "print" ? "viewtopic_print.html" : "viewtopic_body.html"
) );
make_jumpbox( append_sid( "{$phpbb_root_path}viewforum.{$phpEx}" ), $forum_id );
page_footer( );
?>