📄 topicdao.java
字号:
UploadVO aAttach = null;
String uploadURL = this.getAbsoluteURL("./upload/", forumURL, rootPath);
m = image_pattern.matcher(result);
while(m.find())
{
url = m.group(1).trim();
title = m.group(2).trim();
if (url.length() <= 2) // It's local image
{
if (attaches == null) continue;
for (int i=attaches.size()-1; i>=0; i--)
{
aAttach = (UploadVO)attaches.get(i);
if (aAttach.localID.equals(url))
{
tagBuf = new StringBuilder();
tagBuf.append("<img src=\"").append(uploadURL)
.append(aAttach.localname)
.append("\" alt=\"").append(aAttach.title)
.append("\" border=\"0\">");
if (sb == null)
sb = new StringBuffer();
m.appendReplacement(sb, tagBuf.toString());
aAttach.state = 'I';
break;
}
}
}
else
{
if (url.indexOf("://") < 0)
url = getAbsoluteURL(url, forumURL, rootPath);
tagBuf = new StringBuilder();
tagBuf.append("<img src=\"").append(url)
.append("\" alt=\"").append(title)
.append("\" border=\"0\">");
if (sb == null)
sb = new StringBuffer();
m.appendReplacement(sb, tagBuf.toString());
request.setAttribute("pic","1");
}
}
if (sb != null)
{
m.appendTail(sb);
result = sb.toString();
}
}
// Filt flash
if (aBoard.isMediaOK=='T')
{
sb = null;
String[] width_height = null;
UploadVO aAttach = null;
int sizeIndex = 0;
String uploadURL = this.getAbsoluteURL("./upload/", forumURL, rootPath);
m = media_pattern.matcher(result);
while(m.find())
{
url = m.group(1).trim();
width_height = m.group(2).trim().split(",");
if (width_height.length > 2) // It's local flash
sizeIndex = 1;
else
sizeIndex = 0;
int width = PageUtils.getIntValue(width_height, sizeIndex, 400);
int height = PageUtils.getIntValue(width_height, sizeIndex+1, 300);
if (url.length() <= 2) // It's local flash
{
if (attaches == null) continue;
for (int i=attaches.size()-1; i>=0; i--)
{
aAttach = (UploadVO)attaches.get(i);
if (aAttach.localID.equals(url))
{
tagBuf = new StringBuilder();
tagBuf.append("<script type=text/javascript>showMedia('")
.append(uploadURL).append(aAttach.localname)
.append("','").append(width).append("','")
.append(height).append("');</script>");
if (sb == null)
sb = new StringBuffer();
m.appendReplacement(sb, tagBuf.toString());
aAttach.state = 'F';
break;
}
}
}
else
{
if (url.indexOf("://") < 0)
url = getAbsoluteURL(url, forumURL, rootPath);
tagBuf = new StringBuilder();
tagBuf.append("<script type=text/javascript>showMedia('")
.append(url).append("','")
.append(width).append("','")
.append(height).append("');</script>");
if (sb == null)
sb = new StringBuffer();
m.appendReplacement(sb, tagBuf.toString());
request.setAttribute("flv","1");
// When update post, local flash would be here
if (attaches != null && url.startsWith(uploadURL))
{
for (int i=attaches.size()-1; i>=0; i--)
{
aAttach = (UploadVO)attaches.get(i);
if (url.indexOf(aAttach.localname) > 0)
{
aAttach.state = 'F';
break;
}
}
}
}
}
if (sb != null)
{
m.appendTail(sb);
result = sb.toString();
}
}
}
// Convert relative links to absolute
sb = null;
m = href_pattern.matcher(result);
while(m.find())
{
url = m.group(1).trim();
if (url.indexOf("://") < 0 && !url.startsWith("mailto:"))
{
url = getAbsoluteURL(url, forumURL, rootPath);
if (sb == null)
sb = new StringBuffer();
m.appendReplacement(sb, url);
}
}
if (sb != null)
{
m.appendTail(sb);
result = sb.toString();
}
return result;
}
private String getAbsoluteURL(String url, String forumURL, String rootPath)
{
String result = url;
if (url.startsWith("./")) // Current path
result = url.substring(2);
else if (url.startsWith("../")) // Root path
result = url.substring(2);
if (result.startsWith("/"))
result = rootPath + result;
else
result = forumURL + result;
return result;
}
private void replaceHTMLStr(StringBuilder sbuf, String from, String to)
{
int p = sbuf.indexOf(from);
while (p >= 0)
{
sbuf.replace(p, p + from.length(), to);
p = sbuf.indexOf(from, p + to.length());
}
}
/**
* Delete forum topics
* @param
* request - HttpServletRequest
* @return none
* @throws SQLException
* @since 1.0
*/
public String deleteTopics(HttpServletRequest request) throws Exception
{
String[] topicIds = request.getParameterValues("topicID");
String reason = PageUtils.getParam(request,"reason");
String sendsms = request.getParameter("sendsms");
PreparedStatement pstmtUpdate = null;
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
pstmtUpdate = conn.prepareStatement(adapter.Topic_Delete);
StringBuilder sbuf = new StringBuilder(adapter.Topic_GetLogInfo);
sbuf.append(" (");
for (int i=0; i<topicIds.length; i++)
{
pstmtUpdate.setString(1, topicIds[i]);
pstmtUpdate.addBatch();
if (i > 0) sbuf.append(",");
sbuf.append("'").append(topicIds[i]).append("'");
}
sbuf.append(")");
ArrayList<HashMap> topics =
this.execSelectSql(sbuf.toString(), null, conn);
pstmtUpdate.executeBatch();
if (topics != null && topics.size() > 0)
{
int count = topics.size();
topicIds = new String[count];
String[] topicTitles = new String[count];
String[] boardIds = new String[count];
String[] boardNames = new String[count];
String[] userIDs = new String[count];
int[] attaches = new int[count];
BoardVO aBoard = null;
HashMap aTopic = null;
boolean hasValidUser = false;
for (int i=0; i<count; i++)
{
aTopic = topics.get(i);
topicIds[i] = (String)aTopic.get("TOPICID");
topicTitles[i] = (String)aTopic.get("TITLE");
userIDs[i] = (String)aTopic.get("USERID");
attaches[i] = Integer.parseInt((String)aTopic.get("ATTACHES"));
if (userIDs[i] != null && userIDs[i].length() > 0)
hasValidUser = true;
if (aBoard == null)
{
boardIds[i] = (String)aTopic.get("BOARDID");
CacheManager cache = CacheManager.getInstance();
aBoard = cache.getBoard(boardIds[i]);
}
boardIds[i] = aBoard.boardID;
boardNames[i] = aBoard.boardName;
}
if (aBoard != null)
{
HashMap<String,BoardVO> boardMap = new HashMap<String,BoardVO>();
boardMap.put(aBoard.boardID, aBoard);
BoardDAO.getInstance().getBoardStatInfo(boardMap, conn);
}
UserInfo userinfo = PageUtils.getSessionUser(request);
int topicCredits = ForumSetting.getInstance().getInt(ForumSetting.CREDITS, "newTopic");
String moduserinfo = request.getParameter("moduserinfo");
if (moduserinfo == null || !moduserinfo.equals("no"))
{
UserDAO.getInstance().decPostsAndCredits(
userIDs, attaches, userinfo, topicCredits, conn);
}
TrashBoxDAO.getInstance().addTrashes(
boardIds, boardNames, topicIds, topicTitles, null,
userIDs, userinfo.userID, conn);
ActionLogDAO.getInstance().addModerateLog(
request, boardIds, boardNames, topicIds, topicTitles,
"0", "删除主题", reason, conn);
if (sendsms != null && sendsms.equals("yes") && hasValidUser)
{
if (reason.length() > 0)
reason = ", 原因是: " + reason;
String[] messages = new String[count];
for (int i=0; i<count; i++)
{
messages[i] = new StringBuilder("您发表的主题\"").append(topicTitles[i])
.append("\"已被删除").append(reason)
.append("。").toString();
}
String subject = "[系统消息]您发表的主题因故被删除";
String fromUser = userinfo.userID;
ShortMsgDAO.getInstance().addShortMsgs(fromUser, userIDs, subject, messages, conn);
}
}
conn.commit();
return "OK";
}
catch(Exception e)
{
conn.rollback();
throw e;
}
finally
{
dbManager.closePStatement(pstmtUpdate);
dbManager.closeConnection(conn);
}
}
/**
* Move forum topics to another board
* @param
* request - HttpServletRequest
* @return none
* @throws SQLException
* @since 1.0
*/
public String moveTopics(HttpServletRequest request) throws Exception
{
String[] topicIds = request.getParameterValues("topicID");
String reason = PageUtils.getParam(request,"reason");
String sendsms = request.getParameter("sendsms");
String moveto = request.getParameter("moveto");
String[] ids = null;
if (moveto != null && moveto.length() > 0)
ids = moveto.split("_");
if (ids == null || ids.length < 2)
return "请选择有效的目标板块";
PreparedStatement pstmtUpdate = null;
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
pstmtUpdate = conn.prepareStatement(adapter.Topic_MoveTo);
StringBuilder sbuf = new StringBuilder(adapter.Topic_GetLogInfo);
sbuf.append(" (");
for (int i=0; i<topicIds.length; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -