📄 msgdb.java
字号:
k]));
att.setMsgId(id);
att.save();
}
// 加分
ScoreMgr sm = new ScoreMgr();
Vector vatt = sm.getAllScore();
Iterator iratt = vatt.iterator();
while (iratt.hasNext()) {
ScoreUnit su = (ScoreUnit) iratt.next();
IPluginScore ips = su.getScore();
if (ips != null)
ips.onAddAttachment(name, tmpAttachIds.length);
}
}
// 更改用户发贴数 经验值 信用值
UserDb user = new UserDb();
user = user.getUser(name);
user.setAddCount(user.getAddCount() + 1);
user.save();
// 更改用户博客的文章统计信息
if (blog) {
UserConfigDb ucd = new UserConfigDb();
ucd = ucd.getUserConfigDb(name);
ucd.setMsgCount(ucd.getMsgCount() + 1);
ucd.save();
}
// 更改版面最新发贴信息
if (checkStatus==CHECK_STATUS_PASS) {
setBoardNewAddId(id);
// 更改版面统计信息
setBoardStatistic(true);
}
} catch (SQLException e) {
conn.rollback();
Logger.getLogger(MsgDb.class.getName()).error("AddNew:" + e.getMessage());
throw new ResKeyException(new SkinUtil(), SkinUtil.ERR_DB);
} finally {
if (re) {
// 更新缓存
MsgCache mc = new MsgCache();
mc.refreshAdd(boardcode, name, blog, blogUserDir);
}
if (conn != null) {
conn.close();
conn = null;
}
}
return re;
}
/**
* 审核贴子或将其放至回收站
* @param newCheckStatus int
* @return boolean
* @throws ResKeyException
*/
public boolean checkMsg(int newCheckStatus) throws ResKeyException {
checkStatus = newCheckStatus;
String sql = "update sq_message set check_status=? where id=?";
String tsql = "update sq_thread set check_status=? where id=?";
boolean re = false;
Conn conn = new Conn(connname);
try {
conn.beginTrans();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, newCheckStatus);
ps.setLong(2, id);
re = conn.executePreUpdate() == 1 ? true : false;
ps.close();
if (isRootMsg()) {
ps = conn.prepareStatement(tsql);
ps.setInt(1, newCheckStatus);
ps.setLong(2, id);
re = conn.executePreUpdate() == 1 ? true : false;
}
if (re) {
MsgCache mc = new MsgCache();
if (isRootMsg()) {
// 审核的是主题贴
mc.refreshAdd(boardcode, name, blog, blogUserDir);
if (checkStatus == CHECK_STATUS_PASS) {
setBoardNewAddId(id);
// 更改版面统计信息
setBoardStatistic(true);
}
} else {
// 审核的是回复贴
// 如果审核为通过状态
if (checkStatus == CHECK_STATUS_PASS) {
sql =
"Update sq_message set replier=?,redate=?,recount=recount+1 where id=?";
ps = conn.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, "" + System.currentTimeMillis());
ps.setLong(3, rootid);
conn.executePreUpdate();
if (ps != null) {
ps.close();
ps = null;
}
sql = "Update sq_thread set redate=? where id=?";
ps = conn.prepareStatement(sql);
ps.setString(1, "" + System.currentTimeMillis());
ps.setLong(2, rootid);
conn.executePreUpdate();
if (ps != null) {
ps.close();
ps = null;
}
setBoardNewAddId(id);
// 更改版面统计信息
setBoardStatistic(false);
}
mc.refreshReply(boardcode, rootid);
}
}
conn.commit();
} catch (Exception e) {
conn.rollback();
Logger.getLogger(MsgDb.class.getName()).error("checkMsg:" +
e.getMessage());
throw new ResKeyException(SkinUtil.ERR_DB); // "锁定出错!");
} finally {
if (conn != null) {
conn.close();
conn = null;
}
}
return re;
}
/**
* 发贴或回贴后置本版的今日发贴数及总的发贴和回贴数
* @param isAdd boolean true发表发新贴 false表示回贴
*/
public void setBoardStatistic(boolean isAddTopic) {
// 更新版面的当日发贴信息
Leaf lf = new Leaf();
lf = lf.getLeaf(boardcode);
// 从数据库中取出今天日期
java.util.Date d = lf.getTodayDate();
Calendar todaydb = Calendar.getInstance();
todaydb.setTime(d);
Calendar today = Calendar.getInstance();
// 如果today_date字段中为当前日期,则today_count加1
if (DateUtil.isSameDay(todaydb, today)) {
lf.setTodayCount(lf.getTodayCount() + 1);
} else { // 如果字段日期与本日不一致,则说明是本日第一贴
lf.setTodayCount(1);
lf.setTodayDate(new java.sql.Date(today.getTimeInMillis()));
}
if (isAddTopic)
lf.setTopicCount(lf.getTopicCount() + 1);
lf.setPostCount(lf.getPostCount() + 1);
lf.update();
ForumDb forum = new ForumDb();
forum.setStatics(isAddTopic);
}
public boolean isRootMsg() {
return id==rootid;
}
public boolean CheckTopicWE(HttpServletRequest request, FileUpload mfu) throws ErrMsgException {
String errMsg = "";
name = Privilege.getUser(request);
title = mfu.getFieldValue("topic");
if (title == null || title.trim().equals(""))
errMsg += LoadString(request, "err_need_title");
boardcode = mfu.getFieldValue("boardcode");
if (boardcode == null || boardcode.trim().equals(""))
errMsg += LoadString(request, "err_need_board");
content = mfu.getFieldValue("htmlcode");
expression = Integer.parseInt(mfu.getFieldValue("expression"));
ip = mfu.getFieldValue("ip");
String stremail_notify = mfu.getFieldValue("email_notify");
if (stremail_notify == null || stremail_notify.equals(""))
email_notify = 0;
else {
email_notify = Integer.parseInt(stremail_notify);
}
String strIsBlog = StrUtil.getNullStr(mfu.getFieldValue("isBlog"));
if (strIsBlog.equals("1"))
blog = true;
else {
if (boardcode.equals(Leaf.CODE_BLOG))
blog = true;
else
blog = false;
}
if (blog)
blogUserDir = mfu.getFieldValue("blogUserDir");
plugin2Code = StrUtil.getNullStr(mfu.getFieldValue("plugin2Code")).trim();
pluginCode = StrUtil.getNullStr(mfu.getFieldValue("pluginCode")).trim();
if (!errMsg.equals("")) {
throw new ErrMsgException(errMsg);
}
// 过滤title与content
ForumDb fd = new ForumDb();
fd = fd.getForumDb();
fd.FilterMsg(request, title);
fd.FilterMsg(request, content);
isWebedit = this.WEBEDIT_REDMOON;
// 检查发贴是否需审核
TimeConfig tc = new TimeConfig();
if (tc.isPostNeedCheck(request)) {
checkStatus = CHECK_STATUS_NOT;
}
else {
Leaf lf = new Leaf();
lf = lf.getLeaf(boardcode);
checkStatus = lf.getCheckMsg() == lf.CHECK_NOT ? CHECK_STATUS_PASS :
CHECK_STATUS_NOT;
}
String strThreadType = StrUtil.getNullStr(mfu.getFieldValue("threadType"));
if (strThreadType.equals(""))
threadType = ThreadTypeDb.THREAD_TYPE_NONE;
else
threadType = Integer.parseInt(strThreadType);
return true;
}
public boolean setBoardNewAddId(long id) {
Leaf lf = new Leaf();
lf = lf.getLeaf(boardcode);
lf.setAddId(id);
// System.out.println(getClass().getName() + " setBoardNewAddId: id=" + id);
return lf.update();
}
/**
* 使用高级方式发新贴
* @param application ServletContext
* @param request HttpServletRequest
* @param name String
* @param mfu MultiFileUpload
* @return boolean
* @throws ErrMsgException
*/
public boolean AddNewWE(ServletContext application,
HttpServletRequest request,
String name, MultiFileUpload mfu) throws
ErrMsgException {
CheckTopicWE(request, mfu);
String FilePath = StrUtil.getNullString(mfu.getFieldValue("filepath"));
rootpath = request.getContextPath();
// 投票处理
int msgType = 0;
String isvote = mfu.getFieldValue("isvote");
String[] voptions = null;
if (isvote != null && isvote.equals("1")) {
String voteoption = mfu.getFieldValue("vote").trim();
if (!voteoption.equals("")) {
voptions = voteoption.split("\n");
}
if (voptions != null) { // 投票处理
msgType = TYPE_VOTE;
}
// if (voteoption.indexOf("|") != -1)
// throw new ErrMsgException(LoadString(request, "err_vote_option")); // "投票选项中不能包含|");
}
int writeAttachmentResult = mfu.WRITE_ATTACHMENT_SUCCEED;
String sql = "";
int length = 0;
if (title != null)
length = title.length();
if (length < MIN_TOPIC_LEN)
throw new ErrMsgException(LoadString(request, "err_too_short_title") + MIN_TOPIC_LEN); // "您输入的主题内容太短了,最短不能少于" + MIN_TOPIC_LEN);
if (length > MAX_TOPIC_LEN)
throw new ErrMsgException(LoadString(request, "err_too_large_title") + MAX_TOPIC_LEN); // "您输入的主题内容太长了,最长不能超过" + MAX_TOPIC_LEN);
if (content != null)
length = content.length();
if (length < MIN_CONTENT_LEN)
throw new ErrMsgException(LoadString(request, "err_too_short_content") + MIN_CONTENT_LEN);
if (length > MAX_CONTENT_LEN_WE)
throw new ErrMsgException(LoadString(request, "err_too_large_content") + MAX_CONTENT_LEN);
id = SequenceMgr.nextID();
int intIsBlog = blog ? 1 : 0;
int ret = mfu.getRet();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -