📄 topic.php
字号:
<?php/* Copyright (C) 2003-2005 UseBB Team http://www.usebb.net $Header: /cvsroot/usebb/UseBB/topic.php,v 1.66 2005/08/13 11:36:09 pc_freak Exp $ This file is part of UseBB. UseBB 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. UseBB is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with UseBB; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/define('INCLUDED', true);define('ROOT_PATH', './');//// Include usebb engine//require(ROOT_PATH.'sources/common.php');//// If an ID has been passed//if ( ( !empty($_GET['id']) && valid_int($_GET['id']) ) || ( !empty($_GET['post']) && valid_int($_GET['post']) ) ) { // // Look up the topic ID for post ID's // if ( !empty($_GET['post']) && valid_int($_GET['post']) ) { $result = $db->query("SELECT p1.topic_id, COUNT(p2.id) AS post_in_topic FROM ".TABLE_PREFIX."topics t, ".TABLE_PREFIX."posts p1, ".TABLE_PREFIX."posts p2 WHERE p1.id = ".$_GET['post']." AND t.id = p1.topic_id AND p2.topic_id = p1.topic_id AND p2.id <= ".$_GET['post']." GROUP BY p1.topic_id"); $out = $db->fetch_result($result); if ( $out['topic_id'] ) { $requested_topic = $out['topic_id']; $post_in_topic = $out['post_in_topic']; } else { // // Update and get the session information // $session->update(); // // Include the page header // require(ROOT_PATH.'sources/page_head.php'); // // This post does not exist, show an error // header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); $template->set_page_title($lang['Error']); $template->parse('msgbox', 'global', array( 'box_title' => $lang['Error'], 'content' => sprintf($lang['NoSuchPost'], 'ID '.$_GET['post']) )); // // Include the page header // require(ROOT_PATH.'sources/page_foot.php'); exit(); } } elseif ( !empty($_GET['act']) && $_GET['act'] == 'getnewpost' ) { $previous_view = ( array_key_exists($_GET['id'], $_SESSION['viewed_topics']) ) ? $_SESSION['viewed_topics'][$_GET['id']] : $_SESSION['previous_visit']; $result = $db->query("SELECT COUNT(p.id) AS post_in_topic FROM ".TABLE_PREFIX."topics t, ".TABLE_PREFIX."posts p WHERE t.id = ".$_GET['id']." AND t.id = p.topic_id AND p.post_time <= ".$previous_view." GROUP BY p.topic_id"); $out = $db->fetch_result($result); if ( $out['post_in_topic'] ) $post_in_topic = $out['post_in_topic']; $requested_topic = $_GET['id']; } else { $requested_topic = $_GET['id']; } // // Update and get the session information // $session->update('topic:'.$requested_topic); // // Include the page header // require(ROOT_PATH.'sources/page_head.php'); $result = $db->query("SELECT t.id, t.topic_title, t.status_locked, t.status_sticky, t.count_replies, t.forum_id, t.last_post_id, f.id AS forum_id, f.name AS forum_name, f.status AS forum_status, f.auth, f.hide_mods_list FROM ".TABLE_PREFIX."topics t, ".TABLE_PREFIX."forums f WHERE t.id = ".$requested_topic." AND f.id = t.forum_id"); $topicdata = $db->fetch_result($result); if ( !$topicdata['id'] ) { // // This topic does not exist, show an error // header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); $template->set_page_title($lang['Error']); $template->parse('msgbox', 'global', array( 'box_title' => $lang['Error'], 'content' => sprintf($lang['NoSuchTopic'], 'ID '.$requested_topic) )); } else { if ( $functions->auth($topicdata['auth'], 'read', $topicdata['forum_id']) ) { // // The user may view this topic // $topic_title = unhtml($functions->replace_badwords(stripslashes($topicdata['topic_title']))); $template->set_page_title('<a href="'.$functions->make_url('forum.php', array('id' => $topicdata['forum_id'])).'">'.unhtml(stripslashes($topicdata['forum_name'])).'</a>'.$template->get_config('locationbar_item_delimiter').$topic_title); // // Update views count // $result = $db->query("UPDATE ".TABLE_PREFIX."topics SET count_views = count_views+1 WHERE id = ".$requested_topic); // // Eventually (un)subscribe user to topic // if ( $session->sess_info['user_id'] ) { $result = $db->query("SELECT COUNT(*) as subscribed FROM ".TABLE_PREFIX."subscriptions WHERE topic_id = ".$requested_topic." AND user_id = ".$session->sess_info['user_id']); $subscribed = $db->fetch_result($result); $subscribed = ( !$subscribed['subscribed'] ) ? false : true; } if ( !empty($_GET['act']) && in_array($_GET['act'], array('subscribe', 'unsubscribe')) ) { if ( !$session->sess_info['user_id'] ) { $functions->redir_to_login(); } else { if ( !$subscribed && $_GET['act'] == 'subscribe' ) { $result = $db->query("INSERT INTO ".TABLE_PREFIX."subscriptions VALUES(".$requested_topic.", ".$session->sess_info['user_id'].")"); $subscribed = true; $template->parse('msgbox', 'global', array( 'box_title' => $lang['Note'], 'content' => $lang['SubscribedTopic'] )); } elseif ( $subscribed && $_GET['act'] == 'unsubscribe' ) { $result = $db->query("DELETE FROM ".TABLE_PREFIX."subscriptions WHERE topic_id = ".$requested_topic." AND user_id = ".$session->sess_info['user_id']); $subscribed = false; $template->parse('msgbox', 'global', array( 'box_title' => $lang['Note'], 'content' => $lang['UnsubscribedTopic'] )); } } } // // Get all the posts in one query // $forum_moderators = $functions->get_mods_list($topicdata['forum_id']); $new_topic_link = ( $functions->auth($topicdata['auth'], 'post', $topicdata['forum_id']) && ( $topicdata['forum_status'] || $functions->get_user_level() == LEVEL_ADMIN ) ) ? '<a href="'.$functions->make_url('post.php', array('forum' => $topicdata['forum_id'])).'">'.$lang['PostNewTopic'].'</a>' : ''; $reply_link = ( ( !$topicdata['status_locked'] || $functions->auth($topicdata['auth'], 'lock', $topicdata['forum_id']) ) && ( $topicdata['forum_status'] || $functions->get_user_level() == LEVEL_ADMIN ) && $functions->auth($topicdata['auth'], 'reply', $topicdata['forum_id']) ) ? '<a href="'.$functions->make_url('post.php', array('topic' => $requested_topic)).'">'.$lang['PostReply'].'</a>' : ''; // // Get page number // $numpages = ceil(intval($topicdata['count_replies']+1) / $functions->get_config('posts_per_page')); if ( empty($post_in_topic) ) $page = ( !empty($_GET['page']) && valid_int($_GET['page']) && intval($_GET['page']) <= $numpages ) ? intval($_GET['page']) : 1; else $page = ceil(intval($post_in_topic) / $functions->get_config('posts_per_page')); $limit_start = ( $page - 1 ) * $functions->get_config('posts_per_page'); $limit_end = $functions->get_config('posts_per_page'); $page_links = $functions->make_page_links($numpages, $page, $topicdata['count_replies']+1, $functions->get_config('posts_per_page'), 'topic.php', $requested_topic); // // Output the posts // $template->parse('header', 'topic', array( 'topic_name' => '<a href="'.$functions->make_url('topic.php', array('id' => $requested_topic)).'">'.$topic_title.'</a>', 'forum_moderators' => ( !$topicdata['hide_mods_list'] ) ? sprintf($lang['ModeratorList'], $forum_moderators) : '', 'new_topic_link' => $new_topic_link, 'reply_link' => $reply_link, 'page_links' => $page_links )); $avatars_query_part = ( !$functions->get_config('hide_avatars') ) ? ', u.avatar_type, u.avatar_remote' : ''; $userinfo_query_part = ( !$functions->get_config('hide_userinfo') ) ? ', u.posts, u.regdate, u.location' : ''; $signatures_query_part1 = ( !$functions->get_config('hide_signatures') ) ? ', p.enable_sig' : ''; $signatures_query_part2 = ( !$functions->get_config('hide_signatures') ) ? ', u.signature' : ''; $result = $db->query("SELECT p.id, p.poster_id, p.poster_guest, p.poster_ip_addr, p.content, p.post_time, p.enable_bbcode, p.enable_smilies".$signatures_query_part1.", p.enable_html, p.post_edit_time, p.post_edit_by, u.displayed_name AS poster_name, u.level AS poster_level, u.rank".$avatars_query_part.$userinfo_query_part.$signatures_query_part2." FROM ( ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."members u ON p.poster_id = u.id ) WHERE p.topic_id = ".$requested_topic." ORDER BY p.post_time ASC LIMIT ".$limit_start.", ".$limit_end); $i = (( $page - 1 ) * $functions->get_config('posts_per_page') - 1); $new_post_anchor_set = false; while ( $postsdata = $db->fetch_result($result) ) { // // Loop through the posts // // // Used for switching colors in template // $colornum = ( $i % 2 ) ? 1 : 2; // // Post count // $i++; if ( $session->sess_info['user_id'] ) { $previous_view = ( array_key_exists($requested_topic, $_SESSION['viewed_topics']) ) ? $_SESSION['viewed_topics'][$requested_topic] : $_SESSION['previous_visit'];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -