📄 post.jsp
字号:
<%
/**
* $RCSfile: post.jsp,v $
* $Revision: 1.4 $
* $Date: 2000/12/27 22:39:45 $
*/
%>
<%@ page
import="java.text.*,
java.util.*,
java.net.*,
com.coolservlets.forum.*,
com.coolservlets.forum.util.*"
errorPage="error.jsp"
%>
<%! final static String DEFAULT_REDIRECT_PAGE = "/mainctrl/bbs/viewMessage";
final static String STR_TYPE_NEW = "new";
final static String STR_TYPE_REPLY = "reply";
final static String STR_TYPE_EDIT = "edit";
final static String STR_ACTION_DOPOST = "doPost";
final static int TYPE_NEW = 1;
final static int TYPE_REPLY = 2;
final static int TYPE_EDIT = 4;
final static int ACTION_DOPOST = 1;
SimpleDateFormat dateFormatter = new SimpleDateFormat( "yyyy.MM.dd" );
SimpleDateFormat timeFormatter = new SimpleDateFormat( "h:mm a" );
%>
<% ////////////////////////
// Authorization check
// check for the existence of an authorization token
Authorization authToken = SkinUtils.getUserAuthorization(request,response);
// if the token was null, they're not authorized. Since this skin will
// allow guests to view forums, we'll set a "guest" authentication
// token
if( authToken == null ) {
authToken = AuthorizationFactory.getAnonymousAuthorization();
}
%>
<% // Get parameter values
int forumID = ParamUtils.getIntParameter(request, "forum", -1); // forumID: Forum to post to
int threadID = ParamUtils.getIntParameter(request, "thread", -1); // parentID: Parent message ID
int parentID = ParamUtils.getIntParameter(request, "message", -1); // threadID: Thread to post to
String redirectPage = ParamUtils.getParameter(request, "redirectPage"); // redirectPage: Where to go when this post is successful
String postTypeStr = ParamUtils.getParameter(request, "postType"); // postType: either "new" or "reply" or "edit"
String postActionStr = ParamUtils.getParameter(request, "postAction"); // postAction: either blank or "doPost"
String subject = ParamUtils.getParameter(request, "subject"); // subject: subject of the message
String body = ParamUtils.getParameter(request, "body"); // body: body of the message
int postType = 0;
int postAction = 0;
if (redirectPage == null || redirectPage.length() == 0) {
redirectPage = DEFAULT_REDIRECT_PAGE;
}
// New is default postType
if (postTypeStr == null) {
postType = TYPE_NEW;
postTypeStr = STR_TYPE_NEW;
} else if (STR_TYPE_NEW.equals(postTypeStr)) {
postType = TYPE_NEW;
} else if (STR_TYPE_REPLY.equals(postTypeStr)) {
postType = TYPE_REPLY;
} else if (STR_TYPE_EDIT.equals(postTypeStr)) {
postType = TYPE_EDIT;
}
if (STR_ACTION_DOPOST.equals(postActionStr)) {
postAction = ACTION_DOPOST;
}
%>
<% // Get a ForumFactory object, check if it is null. If it is null, redirect to the error page.
ForumFactory forumFactory = ForumFactory.getInstance(authToken);
// Get a forum object, redirect on error:
Forum forum = forumFactory.getForum(forumID);
// Get a profile manager and create the user object. If the userID of the authorization
// token can't be found, redirect to the error page
ProfileManager manager = forumFactory.getProfileManager();
User thisUser = manager.getUser( authToken.getUserID() );
%>
<% // If this is a reply, setup the parent message and the thread objects
ForumThread thread = null;
ForumMessage parentMessage = null;
if (postType == TYPE_REPLY || postType == TYPE_EDIT) {
thread = forum.getThread( threadID ); // throws ForumThreadNotFoundException
parentMessage = thread.getMessage( parentID ); // throws ForumMessageNotFoundException
}
%>
<% // Create the message only if we're posting or replying to a message:
if (postAction == ACTION_DOPOST) {
ForumMessage newMessage = null;
int messageID = -1;
if (subject == null || body == null) {
throw new Exception( "您输入的帖子主题或内容不完整!" );
//return;
}
try {
if (postType == TYPE_EDIT) {
if (parentMessage.getUser().getID() != authToken.getUserID() ||
(System.currentTimeMillis() > parentMessage.getCreationDate().getTime() + 3 * 3600 * 1000)) {
throw new Exception( "帖子只能在创建后2小时内修改!" );
}
parentMessage.setSubject( subject );
parentMessage.setBody( body );
parentMessage.setProperty( "IP", request.getRemoteAddr() );
messageID = parentID;
} else {
newMessage = forum.createMessage( thisUser );
newMessage.setSubject( subject );
newMessage.setBody( body );
newMessage.setProperty( "IP", request.getRemoteAddr() );
messageID = newMessage.getID();
if (postType == TYPE_REPLY) {
thread.addMessage( parentMessage, newMessage );
}
else if (postType == TYPE_NEW) {
// make new thread with the new message as the root.
thread = forum.createThread(newMessage);
forum.addThread(thread);
threadID = thread.getID();
}
}
}
catch( UnauthorizedException ue) {
// System.err.println( "servletforum/post.jsp: " + ue );
response.sendRedirect( "/mainctrl/bbs/error?message=" + URLEncoder.encode("您没有登录,或者您没有被授权在此发帖子!") );
return;
}
// at this point, the message was created and added successfully,
// so redirect to the redirect page:
response.sendRedirect( redirectPage + "?forum=" + forumID + "&thread=" + threadID + "&parent=" + parentID + "&message=" + messageID);
return;
}
%>
<% /////////////////
// header include
String title = "BBS:贴新帖子";
%>
<%@ include file="/skins/bay/header.jsp" %>
<script language="javascript">
function isEmptyStr(s)
{
var ret = true;
for(i=0;i<s.length;i++)
{
if(s.charAt(i) != " ")
{
ret = false;
break;
}
}
return ret;
}
function checkdata()
{
if ( postForm.subject.value.length < 1 || isEmptyStr(postForm.subject.value) )
{
alert("\你必须输入帖子主题!(不能为空或空格)");
postForm.subject.focus();
return false;
}
if ( postForm.body.value.length < 1 || isEmptyStr(postForm.body.value) )
{
alert("\你必须输入帖子内容!(不能为空或空格)");
postForm.body.focus();
return false;
}
return true;
}
</script>
<table bgcolor="#666666" cellpadding=0 cellspacing=0 border=0 width="100%">
<tr>
<td>
<font class="strongw"><a href="/mainctrl/home/index"><font color="#FFFFFF">首页</font></a>>><a href="/mainctrl/communication/main"><font color="#FFFFFF">通信</font></a>>><a href="/mainctrl/bbs/index" ><font color="#FFFFFF">论坛主页</font></a>>>
<a href="/mainctrl/bbs/viewForum?forum=<%= forumID %>" class="normal"><font color="#FFFFFF"><%= forum.getName() %></font></a>
>>
<% if (postType == TYPE_REPLY) { %>
回帖: <font class="strongw"><%= parentMessage.getSubject() %></font>
<% } else if (postType == TYPE_NEW) { %>
贴新帖子:
<% } %>
</font>
</td>
</tr>
</table>
<p>
<% if (postType == TYPE_REPLY || postType == TYPE_EDIT) { %>
<%-- Message table --%>
<table bgcolor="#666666" cellpadding=1 cellspacing=0 border=0 width="100%">
<tr>
<td>
<table bgcolor="#dddddd" cellpadding=3 cellspacing=0 border=0 width="100%">
<td bgcolor="#dddddd" width="99%">
<font face="Trebuchet MS">
<font class="strong"><%= parentMessage.getSubject() %></font>
</font>
<br>
<font face="verdana" >
<font class="strong">
<% if (!parentMessage.isAnonymous()) {
User parentUser = parentMessage.getUser();
%>
<a href="mailto:<%= parentUser.getEmail() %>" class="normal"><%= parentUser.getName() != null ? parentUser.getName() : parentUser.getUsername() %></a>
<% } else { %>
[匿名]
<% } %>
</font>
</font>
</td>
<td bgcolor="#dddddd" width="1%" nowrap>
<font face="verdana" >
<font class="strong">
<% java.util.Date d = parentMessage.getCreationDate(); %>
<%= dateFormatter.format(d) %> - <%= timeFormatter.format(d) %>
</font>
</font>
</td>
</table>
<table bgcolor="#666666" cellpadding=0 cellspacing=0 border=0 width="100%">
<td><img src="/skins/bay/images/blank.gif" width=1 height=1 border=0></td>
</table>
<table bgcolor="#ffffff" cellpadding=5 cellspacing=0 border=0 width="100%">
<td>
<%= parentMessage.getBody() %>
</td>
</table>
</td>
</tr>
</table>
<%-- Message table --%>
<% } %>
<p>
<form action="/mainctrl/bbs/post" method="post" name="postForm" onsubmit="return checkdata()">
<input type="hidden" name="message" value="<%= parentID %>">
<input type="hidden" name="thread" value="<%= threadID %>">
<input type="hidden" name="forum" value="<%= forumID %>">
<input type="hidden" name="postType" value="<%= postTypeStr %>">
<input type="hidden" name="postAction" value="<%= STR_ACTION_DOPOST %>">
<table cellspacing=1 cellpadding=2 border=0 bgcolor=#fafafa width="600">
<tr>
<td>
<font class="strong">
<% if (postType == TYPE_EDIT) { %>
编辑帖子:
<% } else if (postType == TYPE_REPLY) { %>
回复此帖:
<% } else if (postType == TYPE_NEW) { %>
增加新帖:
<% } %>
</font>
</td>
</tr>
</table>
<table cellspacing=1 cellpadding=2 border=0 width="600" class=title>
<tr bgcolor="#fafafa">
<td><font class="strong"> 主题</font></td>
<% String parentSubject = "";
if (parentMessage != null) {
parentSubject = parentMessage.getSubject();
if (postType == TYPE_REPLY) {
if (parentSubject == null) {
parentSubject = "回复您的帖子";
} else if (!parentSubject.startsWith( "回复:" )) {
parentSubject = "回复:" + parentSubject;
}
}
}
%>
<td bgcolor="#fafafa"> <input type="text" name="subject" value="<%= parentSubject %>" size="72" maxlength="100" class=text></td>
</tr>
<% if (postType == TYPE_REPLY) { %>
<tr>
<td><br></td>
<td>
<br></td>
</tr>
<% } %>
<tr bgcolor="#e0e0e0">
<td valign="top"><font face="verdana" ><font class="strong">
<% if (postType == TYPE_REPLY) { %>
回答
<% } else if (postType == TYPE_NEW) { %>
内容
<% } %>
</font></font></td>
<% String parentBody = "";
if (parentMessage != null && postType == TYPE_EDIT) {
parentBody = parentMessage.getBody();
/***/ // QQQ unfilter waiting for interface change...
parentBody = StringUtils.replace(parentBody, "<BR>", "\n");
parentBody = StringUtils.replace(parentBody, "<font class=strong>", "[b]");
parentBody = StringUtils.replace(parentBody, "</font>", "[/b]");
parentBody = StringUtils.replace(parentBody, "<i>", "[i]");
parentBody = StringUtils.replace(parentBody, "</i>", "[/i]");
/***/
}
%>
<td> <textarea name="body" cols="59" rows="10" wrap="virtual"><%= parentBody %></textarea></td>
</tr>
<tr bgcolor="#fafafa">
<td height=30 align=center colspan=2>
<input type="submit" value="贴帖子" class=text>
</td>
</tr>
</table>
</form>
<%@ include file="/skins/bay/footer.jsp" %>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -