📄 msgdb.java
字号:
String strIsBlog = StrUtil.getNullStr(TheBean.getFieldValue("isBlog"));
if (strIsBlog.equals("1"))
blog = true;
else {
if (boardcode.equals(Leaf.CODE_BLOG))
blog = true;
else
blog = false;
}
if (blog)
blogUserDir = TheBean.getFieldValue("blogUserDir");
plugin2Code = StrUtil.getNullStr(TheBean.getFieldValue("plugin2Code")).trim();
pluginCode = StrUtil.getNullStr(TheBean.getFieldValue("pluginCode")).trim();
if (!errMsg.equals("")) {
throw new ErrMsgException(errMsg);
}
// 检查发贴是否需审核
TimeConfig tc = new TimeConfig();
if (tc.isPostNeedCheck(req)) {
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(TheBean.getFieldValue("threadType"));
if (strThreadType.equals("") || !StrUtil.isNumeric(strThreadType))
threadType = ThreadTypeDb.THREAD_TYPE_NONE;
else
threadType = Integer.parseInt(strThreadType);
return true;
}
/**
* 发新贴,适用于普通和ubb方式
* @param application ServletContext
* @param request HttpServletRequest
* @param name String
* @param TheBean FileUpload
* @return boolean
* @throws ErrMsgException
* @throws ResKeyException
*/
public boolean AddNew(ServletContext application,
HttpServletRequest request,
String name, FileUpload TheBean) throws
ErrMsgException, ResKeyException {
this.name = name;
try {
CheckTopic(request, TheBean);
} catch (ErrMsgException e) {
throw e;
}
rootpath = request.getContextPath();
// 投票处理
String isvote = TheBean.getFieldValue("isvote");
String[] voptions = null;
int msgType = 0;
if (isvote != null && isvote.equals("1")) {
String voteoption = TheBean.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")); // "投票选项中不能包含|");
}
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)
throw new ErrMsgException(LoadString(request, "err_too_large_content") + MAX_CONTENT_LEN);
id = SequenceMgr.nextID();
int intIsBlog = blog ? 1 : 0;
FileInfo fi = null;
Vector v = TheBean.getFiles();
int size = v.size();
String[] fileNameAry = null;
if (size > 0) {
fi = (FileInfo) v.get(0); // 取得第一个附件
// 为每个附件生成文件名
fileNameAry = new String[size];
for (int i=0; i<size; i++) {
fileNameAry[i] = FileUpload.getRandName() + "." + ((FileInfo)v.get(i)).getExt();
}
}
String virtualpath = "";
picturename = "";
if (ret == FileUpload.RET_SUCCESS && fi!=null) {
extName = fi.getExt();
Calendar cal = Calendar.getInstance();
String year = "" + (cal.get(cal.YEAR));
String month = "" + (cal.get(cal.MONTH) + 1);
String filepath = Global.getRealPath() + "forum/upfile/" +
year + "/" + month +
"/";
File f = new File(filepath);
if (!f.isDirectory()) {
f.mkdirs();
}
virtualpath = "upfile/" + year +
"/" +
month;
TheBean.setSavePath(filepath); // 设置保存的目录
picturename = fileNameAry[0];
picturename = virtualpath + "/" + picturename;
Iterator ir = v.iterator();
int k = 0;
while (ir.hasNext()) {
fi = (FileInfo)ir.next();
extName = fi.getExt();
String ubbtype = "";
if (extName.equalsIgnoreCase("gif") ||
extName.equalsIgnoreCase("jpg") ||
extName.equalsIgnoreCase("png") || extName.equalsIgnoreCase("bmp"))
ubbtype = "img";
else if (extName.equalsIgnoreCase("swf"))
ubbtype = "flash";
else
ubbtype = "URL";
if (isWebedit == WEBEDIT_UBB) {
if (ubbtype.equals("img"))
content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
virtualpath + "/" +
fileNameAry[k] + "[/" + ubbtype + "]\n" +
content;
else if (ubbtype.equals("flash"))
content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
virtualpath + "/" +
fileNameAry[k] + "[/" +
ubbtype + "]\n" + content;
} else {
if (ubbtype.equals("img"))
// content = "<BR><img src='" + rootpath + "/forum/" +
// virtualpath + "/" +
// picturename + "'><BR>" + content;
content = "<BR><a onfocus=this.blur() href=\"" + rootpath + "/forum/" + virtualpath + "/" + fileNameAry[k] + "\" target=_blank><IMG SRC=\"" + rootpath + "/forum/" + virtualpath + "/" + fileNameAry[k] + "\" border=0 alt=" + SkinUtil.LoadString(request, "res.cn.js.fan.util.StrUtil", "click_open_win") + " onmousewheel='return zoomimg(this)' onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></a><BR>" + content;
else if (ubbtype.equals("flash"))
content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
virtualpath + "/" +
fileNameAry[k] + "[/" +
ubbtype + "]\n" + content;
}
k++;
}
}
boolean re = false;
Conn conn = new Conn(connname);
try {
conn.beginTrans();
// 插入thread,thread仅用来排序、索引、列表,所以无需进行对象的缓存,只有列表的缓存
String insertThreadSql = "insert into sq_thread (id,boardcode,msg_level,iselite,lydate,redate,name,blogUserDir,isBlog,check_status,thread_type) 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);
ps.setInt(10, checkStatus);
ps.setInt(11, threadType);
conn.executePreUpdate();
if (ps!=null) {
ps.close();
ps = null;
}
// 需使用preparestatement,比如在oracel中sql字符串的长度是有限制的 20060909
sql = "insert into sq_message (id,rootid,boardcode,name,title,content,length,expression,lydate,ip,filename,extname,MSG_TYPE,show_ubbcode,show_smile,iswebedit,redate,colorExpire,boldExpire,isBlog,blogUserDir,plugin2Code,email_notify,thread_type,pluginCode,check_status,replyid) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,-1)";
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);
ps.setInt(8, expression);
ps.setString(9, "" + System.currentTimeMillis());
ps.setString(10, ip);
ps.setString(11, picturename);
ps.setString(12, extName);
ps.setInt(13, msgType);
ps.setInt(14, show_ubbcode);
ps.setInt(15, show_smile);
ps.setInt(16, isWebedit);
ps.setString(17, "" + System.currentTimeMillis());
ps.setString(18, "" + System.currentTimeMillis());
ps.setString(19, "" + System.currentTimeMillis());
ps.setInt(20, intIsBlog);
ps.setString(21, blogUserDir);
ps.setString(22, plugin2Code);
ps.setInt(23, email_notify);
ps.setInt(24, threadType);
ps.setString(25, pluginCode);
ps.setInt(26, checkStatus);
conn.executePreUpdate();
if (ps!=null) {
ps.close();
ps = null;
}
// 保存上传的图片
if (ret == FileUpload.RET_SUCCESS && fi != null) {
// fi.write(TheBean.getSavePath(), picturename);
Iterator ir = v.iterator();
// 将附件保存至数据库
int orders = 1;
int i = 0;
while (ir.hasNext()) {
fi = (FileInfo) ir.next();
fi.write(TheBean.getSavePath(), fileNameAry[i]);
String fpath = TheBean.getSavePath() + fi.getDiskName();
long attachId = SequenceMgr.nextID(SequenceMgr.SQ_MESSAGE_ATTACH);
sql =
"insert into sq_message_attach (id,fullpath,msgId,name,diskname,visualpath,orders,UPLOAD_DATE,FILE_SIZE,USER_NAME) values (" +
attachId + "," +
StrUtil.sqlstr(fpath) + "," + id + "," +
StrUtil.sqlstr(fi.getName()) + "," +
StrUtil.sqlstr(fi.getDiskName()) + "," +
StrUtil.sqlstr(virtualpath) + "," + orders +
"," + StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + fi.getSize() + "," + StrUtil.sqlstr(name) + ")";
conn.executeUpdate(sql);
orders++;
i++;
}
if (i>0) {
// 加分
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, i);
}
}
UserPrivDb upd = new UserPrivDb();
upd = upd.getUserPrivDb(name);
upd.addAttachTodayUploadCount(i);
}
conn.commit();
if (voptions != null) {
MsgPollDb mpd = new MsgPollDb();
String epdate = StrUtil.getNullString(TheBean.getFieldValue("expire_date"));
java.util.Date expireDate = DateUtil.parse(epdate, "yyyy-MM-dd");
String strMaxChoices = StrUtil.getNullString(TheBean.getFieldValue("max_choice"));
int maxChoices = StrUtil.toInt(strMaxChoices, 1);
// 创建投票项
mpd.create(new JdbcTemplate(), new Object[] {new Long(id), expireDate, new Integer(maxChoices)});
int vlen = voptions.length;
// 创建投票选项
MsgPollOptionDb mpod = new MsgPollOptionDb();
for (int i=0; i<vlen; i++) {
mpod.create(new JdbcTemplate(), new Object[] {new Long(id), new Integer(i), voptions[i]});
}
}
re = true;
// 将msgId与上传的临时图片文件相关联
String[] tmpAttachIds = TheBean.getFieldValues("tmpAttachId");
if (tmpAttachIds != null) {
int len = tmpAttachIds.length;
for (int k = 0; k < len; k++) {
Attachment att = new Attachment(Long.parseLong(tmpAttachIds[
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -