📄 post_topic.php
字号:
<?php/* Copyright (C) 2003-2005 UseBB Team http://www.usebb.net $Header: /cvsroot/usebb/UseBB/sources/post_topic.php,v 1.44 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*///// Die when called directly in browser//if ( !defined('INCLUDED') ) exit();//// Update and get the session information//$session->update('posttopic:'.$_GET['forum']);//// Include the page header//require(ROOT_PATH.'sources/page_head.php');$result = $db->query("SELECT id, name, status, auth, increase_post_count FROM ".TABLE_PREFIX."forums WHERE id = ".$_GET['forum']);$forumdata = $db->fetch_result($result);if ( !$forumdata['id'] ) { // // This forum 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['NoSuchForum'], 'ID '.$_GET['forum']) )); } else { if ( !$forumdata['status'] && $functions->get_user_level() != LEVEL_ADMIN ) { $template->set_page_title($lang['ForumIsLocked']); $template->parse('msgbox', 'global', array( 'box_title' => $lang['ForumIsLocked'], 'content' => $lang['ForumIsLockedExplain'] )); } elseif ( $functions->auth($forumdata['auth'], 'post', $_GET['forum']) ) { $_POST['user'] = ( !empty($_POST['user']) ) ? preg_replace('#\s+#', '_', $_POST['user']) : ''; if ( ( $session->sess_info['user_id'] || ( !empty($_POST['user']) && preg_match(USER_PREG, $_POST['user']) && strlen($_POST['user']) <= $functions->get_config('username_max_length') ) ) && !empty($_POST['subject']) && !empty($_POST['content']) && empty($_POST['preview']) && ( time() > $_SESSION['latest_post'] + $functions->get_config('flood_interval') || $functions->get_user_level() > LEVEL_MEMBER ) ) { // // Save the guest's username in the session // if ( !$session->sess_info['user_id'] ) $_SESSION['user'] = $_POST['user']; $poster_id = ( $session->sess_info['user_id'] ) ? $session->sess_info['user_id'] : 0; $poster_guest = ( !$session->sess_info['user_id'] ) ? $_POST['user'] : ''; $_POST['enable_bbcode'] = ( !empty($_POST['enable_bbcode']) ) ? 1 : 0; $_POST['enable_smilies'] = ( !empty($_POST['enable_smilies']) ) ? 1 : 0; $_POST['enable_sig'] = ( $session->sess_info['user_id'] && !empty($session->sess_info['user_info']['signature']) && !empty($_POST['enable_sig']) ) ? 1 : 0; $_POST['enable_html'] = ( $functions->auth($forumdata['auth'], 'html', $_GET['forum']) && !empty($_POST['enable_html']) ) ? 1 : 0; $result = $db->query("INSERT INTO ".TABLE_PREFIX."posts VALUES(NULL, 0, ".$poster_id.", '".$poster_guest."', '".$session->sess_info['ip_addr']."', '".$_POST['content']."', ".time().", 0, 0, ".$_POST['enable_bbcode'].", ".$_POST['enable_smilies'].", ".$_POST['enable_sig'].", ".$_POST['enable_html'].")"); $inserted_post_id = $db->last_id(); $status_locked = ( $functions->auth($forumdata['auth'], 'lock', $_GET['forum']) && !empty($_POST['lock_topic']) ) ? 1 : 0; $status_sticky = ( $functions->auth($forumdata['auth'], 'sticky', $_GET['forum']) && !empty($_POST['sticky_topic']) ) ? 1 : 0; $result = $db->query("INSERT INTO ".TABLE_PREFIX."topics VALUES(NULL, ".$_GET['forum'].", '".$_POST['subject']."', ".$inserted_post_id.", ".$inserted_post_id.", 0, 0, ".$status_locked.", ".$status_sticky.")"); $inserted_topic_id = $db->last_id(); $result = $db->query("UPDATE ".TABLE_PREFIX."posts SET topic_id = ".$inserted_topic_id." WHERE id = ".$inserted_post_id); $result = $db->query("UPDATE ".TABLE_PREFIX."forums SET topics = topics+1, posts = posts+1, last_topic_id = ".$inserted_topic_id." WHERE id = ".$_GET['forum']); if ( $session->sess_info['user_id'] && $forumdata['increase_post_count'] ) { $result = $db->query("UPDATE ".TABLE_PREFIX."members SET posts = posts+1 WHERE id = ".$session->sess_info['user_id']); } $result = $db->query("UPDATE ".TABLE_PREFIX."stats SET content = content+1 WHERE name = 'topics'"); $result = $db->query("UPDATE ".TABLE_PREFIX."stats SET content = content+1 WHERE name = 'posts'"); // // Subscribe user to topic // if ( $session->sess_info['user_id'] && !empty($_POST['subscribe_topic']) ) { $result = $db->query("INSERT INTO ".TABLE_PREFIX."subscriptions VALUES(".$inserted_topic_id.", ".$session->sess_info['user_id'].")"); } // // This topic should be viewed // $_SESSION['viewed_topics'][$inserted_topic_id] = time(); $_SESSION['latest_post'] = time(); if ( $functions->get_config('return_to_topic_after_posting') ) $functions->redirect('topic.php', array('id' => $inserted_topic_id)); else $functions->redirect('forum.php', array('id' => $_GET['forum'])); } else { $template->set_page_title('<a href="'.$functions->make_url('forum.php', array('id' => $_GET['forum'])).'">'.unhtml(stripslashes($forumdata['name'])).'</a>'.$template->get_config('locationbar_item_delimiter').$lang['PostNewTopic']); if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) { $enable_bbcode_checked = ( !empty($_POST['enable_bbcode']) ) ? ' checked="checked"' : ''; $enable_smilies_checked = ( !empty($_POST['enable_smilies']) ) ? ' checked="checked"' : ''; $enable_sig_checked = ( !empty($_POST['enable_sig']) ) ? ' checked="checked"' : ''; $enable_html_checked = ( !empty($_POST['enable_html']) ) ? ' checked="checked"' : ''; $lock_topic_checked = ( !empty($_POST['lock_topic']) ) ? ' checked="checked"' : ''; $sticky_topic_checked = ( !empty($_POST['sticky_topic']) ) ? ' checked="checked"' : ''; $subscribe_topic_checked = ( !empty($_POST['subscribe_topic']) ) ? ' checked="checked"' : ''; $errors = array(); if ( !$session->sess_info['user_id'] && ( empty($_POST['user']) || !preg_match(USER_PREG, $_POST['user']) ) ) $errors[] = $lang['Username']; if ( empty($_POST['subject']) ) $errors[] = $lang['Subject']; if ( empty($_POST['content']) ) $errors[] = $lang['Content']; if ( count($errors) ) { $template->parse('msgbox', 'global', array( 'box_title' => $lang['Error'], 'content' => sprintf($lang['MissingFields'], join(', ', $errors)) )); } elseif ( !empty($_POST['preview']) ) { $template->parse('preview', 'various', array( 'post_content' => $functions->markup(stripslashes($_POST['content']), $enable_bbcode_checked, $enable_smilies_checked, $enable_html_checked) )); } elseif ( time() <= $_SESSION['latest_post'] + $functions->get_config('flood_interval') ) { $template->parse('msgbox', 'global', array( 'box_title' => $lang['Note'], 'content' => sprintf($lang['FloodIntervalWarning'], $functions->get_config('flood_interval')) )); } } else { // // Get session saved guest's username if there is one // $_POST['user'] = ( !$session->sess_info['user_id'] && !empty($_SESSION['user']) ) ? $_SESSION['user'] : ''; $enable_bbcode_checked = ' checked="checked"'; $enable_smilies_checked = ' checked="checked"'; $enable_sig_checked = ' checked="checked"'; $enable_html_checked = ''; $lock_topic_checked = ''; $sticky_topic_checked = ''; $subscribe_topic_checked = ( $session->sess_info['user_id'] && $session->sess_info['user_info']['auto_subscribe_topic'] ) ? ' checked="checked"' : ''; if ( $session->sess_info['user_id'] ) $template->set_js_onload("set_focus('subject')"); else $template->set_js_onload("set_focus('user')"); } $_POST['user'] = ( !empty($_POST['user']) && preg_match(USER_PREG, $_POST['user']) ) ? $_POST['user'] : ''; $_POST['subject'] = ( !empty($_POST['subject']) ) ? unhtml(stripslashes($_POST['subject'])) : ''; $_POST['content'] = ( !empty($_POST['content']) ) ? unhtml(stripslashes($_POST['content'])) : ''; $options_input = array(); $options_input[] = '<input type="checkbox" name="enable_bbcode" id="enable_bbcode" value="1"'.$enable_bbcode_checked.' /><label for="enable_bbcode"> '.$lang['EnableBBCode'].'</label>'; $options_input[] = '<input type="checkbox" name="enable_smilies" id="enable_smilies" value="1"'.$enable_smilies_checked.' /><label for="enable_smilies"> '.$lang['EnableSmilies'].'</label>'; if ( $session->sess_info['user_id'] && !empty($session->sess_info['user_info']['signature']) ) $options_input[] = '<input type="checkbox" name="enable_sig" id="enable_sig" value="1"'.$enable_sig_checked.' /><label for="enable_sig"> '.$lang['EnableSig'].'</label>'; if ( $functions->auth($forumdata['auth'], 'html', $_GET['forum']) ) $options_input[] = '<input type="checkbox" name="enable_html" id="enable_html" value="1"'.$enable_html_checked.' /><label for="enable_html"> '.$lang['EnableHTML'].'</label>'; if ( $functions->auth($forumdata['auth'], 'lock', $_GET['forum']) ) $options_input[] = '<input type="checkbox" name="lock_topic" id="lock_topic" value="1"'.$lock_topic_checked.' /><label for="lock_topic"> '.$lang['LockTopicAfterPost'].'</label>'; if ( $functions->auth($forumdata['auth'], 'sticky', $_GET['forum']) ) $options_input[] = '<input type="checkbox" name="sticky_topic" id="sticky_topic" value="1"'.$sticky_topic_checked.' /><label for="sticky_topic"> '.$lang['MakeTopicSticky'].'</label>'; if ( $session->sess_info['user_id'] ) $options_input[] = '<input type="checkbox" name="subscribe_topic" id="subscribe_topic" value="1"'.$subscribe_topic_checked.' /><label for="subscribe_topic"> '.$lang['SubscribeToThisTopic'].'</label>'; $options_input = join('<br />', $options_input); $template->parse('post_form', 'various', array( 'form_begin' => '<form action="'.$functions->make_url('post.php', array('forum' => $_GET['forum'])).'" method="post">', 'post_title' => $lang['PostNewTopic'], 'username_input' => ( $session->sess_info['user_id'] ) ? '<a href="'.$functions->make_url('profile.php', array('id' => $session->sess_info['user_info']['id'])).'">'.unhtml(stripslashes($session->sess_info['user_info']['displayed_name'])).'</a>' : '<input type="text" size="25" maxlength="'.$functions->get_config('username_max_length').'" name="user" id="user" value="'.unhtml(stripslashes($_POST['user'])).'" tabindex="1" />', 'subject_input' => '<input type="text" name="subject" id="subject" size="50" value="'.$_POST['subject'].'" tabindex="2" />', 'content_input' => '<textarea rows="'.$template->get_config('textarea_rows').'" cols="'.$template->get_config('textarea_cols').'" name="content" id="tags-txtarea" tabindex="3">'.$_POST['content'].'</textarea>', 'bbcode_controls' => $functions->get_bbcode_controls(), 'smiley_controls' => $functions->get_smiley_controls(), 'options_input' => $options_input, 'submit_button' => '<input type="submit" name="submit" value="'.$lang['OK'].'" tabindex="4" />', 'preview_button' => '<input type="submit" name="preview" value="'.$lang['Preview'].'" />', 'reset_button' => '<input type="reset" value="'.$lang['Reset'].'" />', 'form_end' => '</form>' )); } } else { // // The user is not granted to post new topics in this forum // $functions->redir_to_login(); } }//// Include the page footer//require(ROOT_PATH.'sources/page_foot.php');?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -