📄 msgdb.java~171~
字号:
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();
}
// 更改版面最新发贴信息
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 isAdd boolean true发表发新贴 false表示回贴
*/
public void setBoardStatistic(boolean isAdd) {
// 更新版面的当日发贴信息
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 (isAdd)
lf.setTopicCount(lf.getTopicCount() + 1);
lf.setPostCount(lf.getPostCount() + 1);
lf.update();
ForumDb forum = new ForumDb();
forum.setStatics(isAdd);
}
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;
return true;
}
public boolean setBoardNewAddId(long id) {
Leaf lf = new Leaf();
lf = lf.getLeaf(boardcode);
lf.setAddId(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();
// 投票处理
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 (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 msgType = 0;
String voteresult = "", votestr = "";
int ret = mfu.getRet();
String ubbtype = "";
if (ret == FileUpload.RET_SUCCESS) {
boolean isDdxc = false;
String sisDdxc = StrUtil.getNullString(mfu.getFieldValue("isDdxc"));
// 断点续传
if (sisDdxc.equals("true"))
isDdxc = true;
String filepath = StrUtil.getNullString(mfu.getFieldValue(
"filepath"));
picturename = "";
FileInfo fInfo = mfu.getUpFileInfo();
String virtualpath = "";
if (fInfo!=null) {
// 考虑到webedit控件的断点续传功能,这里上传后的路径还是应该使用附件的路径较好
// 但是附件如果以后用网络硬盘管理以后,可能会带来问题
// 因为表单中filename文件的大小不应被计入用户的磁盘空间,而断点续传后,会被计入么?
// 解决如下:单线程时计算磁盘空间的问题可以通过FileInfo中的size得以解决
// 多线程断点上传时计算空间可以通过控件发送文件大小数组来加以解决
// 另外,在MultiFileUpload中分离时要考到两种情况
// -------------------------------------------------------------
// 考虑到控件上传的附件以后要放在专门的路径中,以便于过滤,保护用户的网络硬盘文件
// 为提高并发性,如果每次存取filename中的文件都要被过滤,则不利于文件的快速存取
// 而断点上传时附件的路径是在控件中就指定了名称的,而且是滞后于其它域的信息保存的
// 无法另外给定其名称,所以一定是存放于附件指定的路径,因而此处放弃对其的处理
// 这里要注意的是需要对用到filename的应用加以处理,使其不能使用WEBEDIT_REDMOON方式发布
// 比如:拍卖。
// -------------------------------------------------------------
// 再三考虑后还是决定高级发贴方式支持filename,否则在博客中使用高级发贴方式时,因为不支持filename而使得一些加挂插件的版块不允许,这样会使得整个应用管理起来比较复杂
extName = fInfo.getExt();
if (!isDdxc) {
picturename = FileUpload.getRandName() + "." + extName;
virtualpath = FilePath;
}
else {
picturename = fInfo.getDiskName();
virtualpath = FilePath;
}
if (extName.equalsIgnoreCase("gif") ||
extName.equalsIgnoreCase("jpg") || extName.equalsIgnoreCase("bmp") || extName.equalsIgnoreCase("png"))
ubbtype = "img";
else if (extName.equalsIgnoreCase("swf"))
ubbtype = "flash";
else
ubbtype = "URL";
if (ubbtype.equals("img"))
content = "<BR><img src='" + rootpath + "/forum/" +
virtualpath + "/" +
picturename + "'><BR>" + content;
else if (ubbtype.equals("flash"))
content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
virtualpath + "/" +
picturename + "[/" +
ubbtype + "]\n" + content;
}
// 2006.1.31 application.getRealPath("/")取得的d:\zjrj在插入mysql后,\不见了,变成了d:zjrj
// 解决方法:改用Global.getRealPath
// String tempAttachFilePath = application.getRealPath("/") + filepath +
// "/";
String tempAttachFilePath = Global.getRealPath() + "forum/" + filepath +
"/";
mfu.setSavePath(tempAttachFilePath); // 取得目录
File f = new File(tempAttachFilePath);
if (!f.isDirectory()) {
f.mkdirs();
}
if (voptions != null) { // 投票处理
msgType = 1;
int len = voptions.length;
for (int k = 0; k < len; k++) {
if (voteresult.equals("")) {
voteresult = "0";
votestr = voptions[k];
} else {
voteresult += "|" + "0";
votestr += "|" + voptions[k];
}
}
}
boolean issuccess = true;
Conn conn = new Conn(connname);
boolean re = false;
try {
conn.beginTrans();
// 插入thread,thread仅用来排序、索引、列表,所以无需缓存
String insertThreadSql = "insert into sq_thread (id,boardcode,msg_level,iselite,lydate,redate,name,blogUserDir,isBlog) values (?,?,?,?,?,?,?,?,?)";
PreparedStatement ps = conn.prepareStatement(insertThreadSql);
ps.setLong(1, id);
ps.setString(2, boardcode);
ps.setInt(3, level);
ps.setInt(4, isElite);
ps.setString(5, "" + System.currentTimeMillis());
ps.setString(6, "" + System.currentTimeMillis());
ps.setString(7, name);
ps.setString(8, blogUserDir);
ps.setInt(9, blog?1:0);
conn.executePreUpdate();
if (ps!=null) {
ps.close();
ps = null;
}
sql = "insert into sq_message (id,rootid,boardcode,name,title,content,length,expression,lydate,ip,filename,extname,MSG_TYPE,voteoption,voteresult,show_ubbcode,show_smile,iswebedit,redate,colorExpire,boldExpire,isBlog,blogUserDir,plugin2Code,email_notify,msg_kind,pluginCode) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
ps = conn.prepareStatement(sql);
ps.setLong(1, id);
ps.setLong(2, id);
ps.setString(3, boardcode);
ps.setString(4, name);
ps.setString(5, title);
ps.setString(6, content);
ps.setInt(7, length);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -