package com.redmoon.forum;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import cn.js.fan.cache.jcs.*;
import cn.js.fan.db.*;
import cn.js.fan.mail.*;
import cn.js.fan.security.*;
import cn.js.fan.util.*;
import cn.js.fan.web.*;
import com.cloudwebsoft.framework.db.*;
import com.redmoon.blog.*;
import com.redmoon.forum.message.*;
import com.redmoon.forum.person.*;
import com.redmoon.forum.plugin.*;
import com.redmoon.forum.plugin.base.*;
import com.redmoon.kit.util.*;
import org.apache.log4j.*;
import com.cloudwebsoft.framework.util.LogUtil;
import com.redmoon.forum.security.TimeConfig;
public class MsgDb implements java.io.Serializable {
public static int LEVEL_TOP_BOARD = 100;
public static int LEVEL_TOP_FORUM = 200;
public static int LEVEL_NONE = 0;
public static int WEBEDIT_UBB = 0;
public static int WEBEDIT_REDMOON = 1;
public static int WEBEDIT_NORMAL = 2;
public static int MIN_CONTENT_LEN = 10;
public static int MAX_CONTENT_LEN = 3000;
public static int MAX_CONTENT_LEN_WE = 20000;
public static int MAX_TOPIC_LEN = 100;
public static int MIN_TOPIC_LEN = 1;
public static final int TYPE_MSG = 0;
public static final int TYPE_VOTE = 1;
public static final int CHECK_STATUS_NOT = 0; // 未审核
public static final int CHECK_STATUS_PASS = 1; // 审核通过
public static final int CHECK_STATUS_DUSTBIN = 10; // 删除
static {
initParam();
}
String connname = Global.defaultDB;
// 序列化时,类的所有数据成员应可序列化除了声明为transient或static的成员。
// 将变量声明为transient告诉JVM我们会负责将变元序列化。
// 将数据成员声明为transient后,序列化过程就无法将其加进对象字节流中,
// transient Logger Logger = Logger.getLogger(MsgDb.class.getName());
int ret = 1;
String boardcode, name, pwd,
title = "", content = "", picturename, ip;
int show_smile = 1, show_ubbcode = 1, email_notify = 0;
long rootid = -1;
long id;
int layer;
java.util.Date addDate;
int orders;
int expression = 1;
String fileName = "";
String rootpath;
long replyid = -1;
int isWebedit = WEBEDIT_NORMAL;
private String plugin2Code;
public MsgDb() {
init();
}
public MsgDb(long id) {
init();
loadFromDb(id);
}
public static void initParam() {
com.redmoon.forum.Config cfg = new com.redmoon.forum.Config();
MIN_TOPIC_LEN = cfg.getIntProperty("forum.msgTitleLengthMin");
MAX_TOPIC_LEN = cfg.getIntProperty("forum.msgTitleLengthMax");
MIN_CONTENT_LEN = cfg.getIntProperty("forum.msgLengthMin");
MAX_CONTENT_LEN = cfg.getIntProperty("forum.msgLengthMax");
MAX_CONTENT_LEN_WE = MAX_CONTENT_LEN;
}
public void init() {
}
protected void finalize() throws Throwable {
super.finalize();
}
public String getFileName() {
return fileName;
}
private int recount;
public String getboardcode() {
return boardcode;
}
/**
* 取得当前处理的boardcode,用于oscache刷新缓存,oscache已放弃,主要是其原理适合于页面的缓存,但对于对象的缓存不是很方便
* @return String
*/
public String getCurBoardCode() {
return boardcode;
}
/**@task:需优化
* 取得year年month月中每天的日志数
* @param year int
* @param month int First month begin with 1
* @return int[] First day begin with 1
*/
public int[] getBlogMsgDayCount(long blogId, int year, int month) {
// System.out.println("month=" + month);
// 取得year-month这个月的天数
int dayCount = DateUtil.getDayCount(year, month - 1);
// System.out.println("day=" + dayCount);
int[] ary = new int[dayCount + 1];
for (int i = 1; i <= dayCount; i++) {
ary[i] = 0;
}
Calendar calStart = Calendar.getInstance();
calStart.set(year, month - 1, 1);
String start = "" + calStart.getTimeInMillis();
Calendar calEnd = Calendar.getInstance();
calEnd.set(year, month - 1, dayCount, 24, 60);
String end = "" + calEnd.getTimeInMillis();
String sql = "select lydate from sq_thread where blog_id=? and isBlog=1 and lydate>? and lydate<? order by lydate asc";
Conn conn = new Conn(connname);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, blogId);
pstmt.setString(2, start);
pstmt.setString(3, end);
rs = conn.executePreQuery();
Calendar cal = Calendar.getInstance();
while (rs.next()) {
java.util.Date d = DateUtil.parse(rs.getString(1));
cal.setTime(d);
ary[cal.get(cal.DAY_OF_MONTH)]++;
}
} catch (SQLException e) {
Logger.getLogger(MsgDb.class.getName()).error("getBlogMsgDayCount:" +
e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e) {}
pstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return ary;
}
/**
* 取得y年m月d日的用户日志
* @param userName String
* @param y int
* @param m int
* @param d int
* @return Vector
*/
public Vector getBlogDayList(long blogId, int y, int m, int d) {
String sql = "select id from sq_thread where blog_id=? and isBlog=1 and lydate>? and lydate<? order by lydate asc";
Calendar calStart = Calendar.getInstance();
calStart.set(y, m - 1, d, 0, 0, 0);
String start = "" + calStart.getTimeInMillis();
Calendar calEnd = Calendar.getInstance();
calEnd.set(y, m - 1, d, 23, 59, 59);
String end = "" + calEnd.getTimeInMillis();
PreparedStatement pstmt = null;
ResultSet rs = null;
Vector v = new Vector();
Conn conn = new Conn(connname);
try {
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, blogId);
pstmt.setString(2, start);
pstmt.setString(3, end);
// url,title,image,userName,sort,kind
rs = conn.executePreQuery();
Calendar cal = Calendar.getInstance();
while (rs.next()) {
MsgDb md = getMsgDb(rs.getLong(1));
v.addElement(md);
}
} catch (SQLException e) {
Logger.getLogger(MsgDb.class.getName()).error("getBlogDayList:" +
e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {}
rs = null;
}
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e) {}
pstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
return v;
}
public static String LoadString(HttpServletRequest request, String key) {
return SkinUtil.LoadString(request, "res.forum.MsgDb", key);
}
public