📄 postwebhandler.java
字号:
/*
* Copyright (C) 2002 by MyVietnam.net
*
* This program 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 any later version.
*
* All copyright notices regarding mvnForum
* must remain intact in the scripts and in the outputted HTML
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in the footer of the pages MUST
* remain visible when the pages are viewed on the internet or intranet.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info@MyVietnam.net
*
* @author: Minh Nguyen minhnn@MyVietnam.net
* @author: Mai Nguyen mai.nh@MyVietnam.net
*/
package net.myvietnam.mvnplugin.mvnforum.user;
import javax.servlet.http.*;
import java.sql.*;
import java.util.Collection;
import java.util.Iterator;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.ParamUtil;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import net.myvietnam.mvncore.filter.HtmlNewLineFilter;
import net.myvietnam.mvnplugin.mvnforum.db.PostBean;
import net.myvietnam.mvnplugin.mvnforum.db.ThreadBean;
import net.myvietnam.mvnplugin.mvnforum.db.MemberBean;
import net.myvietnam.mvnplugin.mvnforum.MVNForumConfig;
import net.myvietnam.mvnplugin.mvnforum.MyUtil;
import net.myvietnam.mvnplugin.mvnforum.auth.*;
class PostWebHandler {
private OnlineUserManager userManager = OnlineUserManager.getInstance();
PostWebHandler() {
}
/**
* This method is for addpost page
*/
public void prepareAdd(HttpServletRequest request)
throws DatabaseException, BadInputException, AuthenticationException, AssertionException {
OnlineUser onlineUser = userManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// we set this action attribute first because the return below can make method return prematurely
request.setAttribute("action", "addnew");
int parentPostID = 0;
try {
// neu co parent thi` khong co forum !!!
parentPostID = ParamUtil.getParameterInt(request, "parent");
} catch (Exception ex) {
// do nothing
// NOTE: we cannot return here since user can have a parameter parent = 0
}
if (parentPostID == 0) {// new thread
int forumID = ParamUtil.getParameterInt(request, "forum");
permission.ensureCanNewThread(forumID);
} else {// reply to a post
// this is a parent post
PostBean postBean = PostWebHelper.getPost(parentPostID);// can throw DatabaseException
// check permission
int forumID = postBean.getForumID();
permission.ensureCanNewPost(forumID);
// now we prepare to list lastest post in the thread
int threadID = postBean.getThreadID();
Collection postBeans = PostWebHelper.getLastBeans_inThread_limit(threadID, MVNForumConfig.ROWS_IN_LAST_REPLIES);
request.setAttribute("ParentPostBean", postBean);
request.setAttribute("PostBeans", postBeans);
}
}
public void processAdd(HttpServletRequest request)
throws AssertionException, DatabaseException, CreateException, BadInputException, ForeignKeyNotFoundException, AuthenticationException {
OnlineUser onlineUser = userManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
/** @todo is guest can post thread or message */
permission.ensureIsAuthenticated();
int memberID = onlineUser.getMemberID();
String memberName = onlineUser.getMemberName();
Timestamp now = DateUtil.getCurrentGMTTimestamp();
int parentPostID = ParamUtil.getParameterInt(request, "ParentPostID");
boolean checkEmpty = false;
if (parentPostID == 0) checkEmpty = true;
String postTopic = ParamUtil.getParameterSafe(request, "PostTopic", checkEmpty);
String postBody = ParamUtil.getParameter(request, "message", true);// use message instead of MessageBody
postBody = DisableHtmlTagFilter.filter(postBody);/** @todo remove this, and use this filter when view */
int forumID = 0;
int threadID= 0;
if (parentPostID == 0) {// new thread
forumID = ParamUtil.getParameterInt(request, "ForumID");
// check permission
permission.ensureCanNewThread(forumID);
String lastPostMemberName = memberName;
int threadType = 0;//xem lai
int threadOption = 0;//xem lai
int threadStatus = 0;//xem lai
int threadHasPoll = 0;//xem lai
String threadIcon = "";//xem lai
int threadDuration = 0;//xem lai
threadID = ThreadWebHelper.createThread(forumID, memberName, lastPostMemberName,
postTopic, postBody, 0/*threadVoteCount*/,
0/*threadVoteTotalStars*/, now/*threadCreationDate*/, now/*threadLastPostDate*/,
threadType, threadOption, threadStatus,
threadHasPoll, 0/*threadViewCount*/, 0/*threadReplyCount*/,
threadIcon, threadDuration);
} else {// reply to a post
PostBean parentPostBean = PostWebHelper.getPost(parentPostID);
forumID = parentPostBean.getForumID();
threadID = parentPostBean.getThreadID();
// check permission
permission.ensureCanNewPost(forumID);
}
Timestamp postLastEditDate = now;
String postCreationIP = request.getRemoteAddr();
String postLastEditIP = "";
int postFormatOption = 0;
int postOption = 0;
int postStatus = 0;
String postIcon = "";
int postAttachCount = 0;
PostWebHelper.createPost(parentPostID, forumID, threadID,
memberID, memberName, ""/*lastEditMemberName*/,
postTopic, postBody, now/*postCreationDate*/,
postLastEditDate, postCreationIP, postLastEditIP,
0/*postEditCount*/, postFormatOption, postOption,
postStatus, postIcon, postAttachCount);
MemberWebHelper.increasePostCount(memberID);
ForumWebHelper.increasePostCount(forumID);
if (parentPostID == 0) {//new thread, so we increase the ForumThreadCount
ForumWebHelper.increaseThreadCount(forumID);
}
if (parentPostID != 0) {//reply to a post in thread, so we increase the ThreadReplyCount
ThreadWebHelper.increaseReplyCount(threadID);
}
ThreadWebHelper.updateLastPostMemberName(threadID, memberName);
ForumWebHelper.updateLastPostMemberName(forumID, memberName);
ForumWebHelper.updateForumLastPostDate(forumID, now);
ThreadWebHelper.updateThreadLastPostDate(threadID, now);
/** @todo Update PostEditLog table here */
request.setAttribute("ForumID", String.valueOf(forumID));
request.setAttribute("ThreadID", String.valueOf(threadID));
/**@todo: review, this variable is still reserved*/
//request.setAttribute("ParentPostID", String.valueOf(parentPostID));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -