⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forum.java

📁 一个用jsp写的完整的论坛源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.bcxy.bbs.forum;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 * <p>Copyright:</p>
 * <p>Company: www.liyunet.com</p>
 * 
 * @author lishujiang
 * @version 1.0
 */

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.bcxy.bbs.util.BBSConst;
import com.bcxy.bbs.util.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.cache.CacheManager;
import com.bcxy.conf.ENV;
import com.bcxy.db.JdbcWrapper;
import com.bcxy.mail.SendMail;
import com.bcxy.util.DateUtil;
import com.bcxy.util.StringUtil;

public class Forum {

	private static Logger log = Logger.getLogger(Forum.class);

	int forumID, forumClass, lockForum, forumSkin, lastBbsNum;

	int lastTopicNum, strAllowForumCode, strAllowHTML, strIMGInPosts;

	int strIcons, strFlash, lastRootID, todayNum;

	int voteID;

	String forumType, readMe, forumMaster;

	String tableBack, tableTitle, tableBody, aTableBody, tableFont,
			tableContent;

	String alertFont, lastPostUser, lastPostTime, forumLogo, indexIMG,
			lastTopic, forumUser;

	Vector forumOLUsers;

	int forumTopicNum;

	int forumOLGuestUsersNum = 0, forumOLMemberUsersNum = 0,
			forumsOLUsersNum = 0;

	int forumMSGsNum = 0;

	ForumTopic forumMSGTopic;

	public Forum() {
	}

	public Forum(HttpServletRequest request, HttpServletResponse response,
			int forumID) throws ForumNotFoundException {
		init(forumID);
		SkinUtil.checkUserStats(request, response, this.forumType);
		this.getOnline();
	}

	public Forum(int forumID) throws ForumNotFoundException {
		init(forumID);
		this.getOnline();
	}

	public void init(int forumID) throws ForumNotFoundException {
		Forum theForum = (Forum) CacheManager.getCache(ENV.FORUM).get(
				String.valueOf(forumID));
		if (theForum != null) {
			this.forumID = theForum.getForumID();
			forumType = theForum.getForumType();
			forumClass = theForum.getForumClass();
			readMe = theForum.getReadMe();
			forumMaster = theForum.getForumMaster();
			lockForum = theForum.getLockForum();
			forumSkin = theForum.getForumSkin();
			tableBack = theForum.getTableBack();
			tableTitle = theForum.getTableTitle();
			tableBody = theForum.getTableBody();
			aTableBody = theForum.getATableBody();
			tableFont = theForum.getTableFont();
			tableContent = theForum.getTableContent();
			alertFont = theForum.getAlertFont();
			lastPostUser = theForum.getLastPostUser();
			lastPostTime = theForum.getLastPostTime();
			lastBbsNum = theForum.getLastBbsNum();
			lastTopicNum = theForum.getLastTopicNum();
			strAllowForumCode = theForum.getStrAllowForumCode() ? 1 : 0;
			strAllowHTML = theForum.getStrAllowHTML() ? 1 : 0;
			strIMGInPosts = theForum.getStrIMGInPosts() ? 1 : 0;
			strIcons = theForum.getStrIcons() ? 1 : 0;
			strFlash = theForum.getStrFlash() ? 1 : 0;
			forumLogo = theForum.getForumLogo();
			indexIMG = theForum.getIndexIMG();
			lastRootID = theForum.getLastRootID();
			lastTopic = theForum.getLastTopic();
			todayNum = theForum.getTodayNum();
			forumUser = theForum.getForumUser();
		} else {
			//
			theForum = new Forum();
			JdbcWrapper jw = new JdbcWrapper();
			try {
				jw.executeQuery("select * from "+BBSConst.TABLE_BOARD+" where boardid=" + forumID);
				jw.next();
				this.forumID = jw.getInt(1);

				forumType = jw.getString(2);
				forumClass = jw.getInt(3);
				readMe = jw.getString(4);
				forumMaster = jw.getString(5);
				lockForum = jw.getInt(6);
				forumSkin = jw.getInt(7);
				tableBack = jw.getString(8);
				tableTitle = jw.getString(9);
				tableBody = jw.getString(10);
				aTableBody = jw.getString(11);
				tableFont = jw.getString(12);
				tableContent = jw.getString(13);
				alertFont = jw.getString(14);
				lastPostUser = jw.getString(15);
				lastPostTime = jw.getString(16);
				lastBbsNum = jw.getInt(17);
				lastTopicNum = jw.getInt(18);
				strAllowForumCode = jw.getInt(19);
				strAllowHTML = jw.getInt(20);
				strIMGInPosts = jw.getInt(21);
				strIcons = jw.getInt(22);
				strFlash = jw.getInt(23);
				forumLogo = jw.getString(24);
				indexIMG = jw.getString(25);
				lastRootID = jw.getInt(26);
				lastTopic = jw.getString(27);
				todayNum = jw.getInt(28);
				forumUser = jw.getString(29);
				//
				CacheManager.getCache(ENV.FORUM).put(
						String.valueOf(this.forumID), this);
			} catch (Exception e) {
				log.error("取得论坛信息出错", e);
				throw new ForumNotFoundException("取得论坛信息出错");
			} finally {
				jw.close();
			}
		}
	}

	public Vector getOnline() throws ForumNotFoundException {
		JdbcWrapper jw = new JdbcWrapper();
		forumOLUsers = new Vector();
		try {
			forumsOLUsersNum = jw.doIntSearch("select count(*) from "+BBSConst.TABLE_ONLINE+" where stats like '%"
					+ forumType + "%'");
			forumOLGuestUsersNum = jw.doIntSearch("select count(*) from "+BBSConst.TABLE_ONLINE+" where stats like '%"
					+ forumType + "%' and username='guest'");
			forumOLMemberUsersNum = forumsOLUsersNum - forumOLGuestUsersNum;
		} catch (Exception e) {
			log.error("取得在线用户信息出错", e);
			throw new ForumNotFoundException("取得在线用户信息出错");
		}
		return forumOLUsers;
	}

	public Vector getForumTopics(int forumID, int Page, int perPage)
			throws ForumTopicNotFoundException {
		JdbcWrapper rs = new JdbcWrapper(); // 每次取出20条数据,和用JDBC性能相差不大
		Vector forumTopics = new Vector();
		try {
			forumTopicNum = rs
					.doIntSearch("select count(announceid) from " + BBSConst.TABLE_BBS1 + " where boardID="
							+ forumID + " and parentID=0  and  locktopic!=2");
			int maxAnnouncePerPage = StringUtil.parseInt(ForumPropertiesManager
					.getString("MaxAnnouncePerPage"));
			// 数据量比较大,利用MYSQL特性实现分页提高性能
			String sql = "select announceid,rootid,child,hits from " + BBSConst.TABLE_BBS1 + " where (boardID="
					+ forumID
					+ " or istop=2) and parentID=0  and  locktopic!=2 ORDER BY istop desc,times desc,announceid desc limit "
					+ ((Page - 1) * maxAnnouncePerPage) + ","
					+ maxAnnouncePerPage;
			rs.executeQuery(sql);
			while (rs.next()) {
				int announceID = rs.getInt(1);
				int forumRootID = rs.getInt(2);
				ForumTopic theTopic = (ForumTopic) CacheManager.getCache(
						ENV.FORUM_TOPIC).get(String.valueOf(announceID));
				if (theTopic == null) {
					theTopic = new ForumTopic(forumRootID, announceID);
					CacheManager.getCache(ENV.FORUM_TOPIC).put(
							String.valueOf(announceID), theTopic);
				}else{
					theTopic.setChildNum(rs.getInt(3));
					theTopic.setHits(rs.getInt(4));
				}
				forumTopics.add(theTopic);
			}
		} catch (Exception e) {
			log.error("取得论坛主题列表出错", e);
			throw new ForumTopicNotFoundException(e.getMessage());
		} finally {
			rs.close();
		}
		return forumTopics;
	}

	/**
	 * 取得所有帖子主题信息
	 * @param Page
	 * @param perPage
	 * @param type 1:普通帖子;2:固顶帖子;3:精华帖子;
	 * @return
	 * @throws ForumTopicNotFoundException
	 */
	public static Vector getAllTopics(int Page, int perPage, int type)
			throws ForumTopicNotFoundException {
		JdbcWrapper rs = new JdbcWrapper(); // 每次取出20条数据,和用JDBC性能相差不大
		Vector forumTopics = new Vector();
		try {
			// 数据量比较大,利用MYSQL特性实现分页提高性能
			String sql = "select announceid,rootid from " + BBSConst.TABLE_BBS1 + " where ";
			switch(type)
			{
				case 1:
					sql += " 1=1 ";
					break;
				case 2:
					sql += " istop=1 or istop=2 ";
					break;
				case 3:
					sql += " isbest=1 ";
					break;
				default:
					sql += " 1=1 ";	
			}
			sql += " and parentID=0  and  locktopic!=2 ORDER BY times desc,announceid desc limit "
				+ ((Page - 1) * perPage) + ","
				+ perPage;

			rs.executeQuery(sql);
			while (rs.next()) {
				int announceID = rs.getInt(1);
				int forumRootID = rs.getInt(2);
				ForumTopic theTopic = (ForumTopic) CacheManager.getCache(
						ENV.FORUM_TOPIC).get(String.valueOf(announceID));
				if (theTopic == null) {
					theTopic = new ForumTopic(forumRootID, announceID);
					CacheManager.getCache(ENV.FORUM_TOPIC).put(
							String.valueOf(announceID), theTopic);
				}
				forumTopics.add(theTopic);
			}
		} catch (Exception e) {
			log.error("取得论坛主题列表", e);
			throw new ForumTopicNotFoundException(e.getMessage());
		} finally {
			rs.close();
		}
		return forumTopics;
	}

	public Vector getForumBestTopics(int forumID, int Page, int perPage)
			throws ForumTopicNotFoundException {
		JdbcWrapper rs = new JdbcWrapper();
		Vector forumTopics = new Vector();
		try {
			// 数据量比较少,利用方法实现分页提高可移植性
			String sql = "select announceid,rootid from " + BBSConst.TABLE_BBS1 + " where boardID="
					+ forumID
					+ " and isBest=1 and locktopic!=2  ORDER BY " + BBSConst.TABLE_BBS1 + ".times desc," + BBSConst.TABLE_BBS1 + ".announceid desc";
			rs.executeQuery(sql, perPage, Page);
			forumTopicNum = rs.getAllRows();
			while (rs.next()) {
				int announceID = rs.getInt(1);
				int forumRootID = rs.getInt(2);
				ForumTopic theTopic = (ForumTopic) CacheManager.getCache(
						ENV.FORUM_TOPIC).get(String.valueOf(announceID));
				if (theTopic == null) {
					theTopic = new ForumTopic(forumRootID, announceID);
					CacheManager.getCache(ENV.FORUM_TOPIC).put(
							String.valueOf(announceID), theTopic);
				}
				forumTopics.add(theTopic);
			}
		} catch (Exception e) {
			log.error("取得精华主题列表出错", e);
			throw new ForumTopicNotFoundException(e.getMessage());
		} finally {
			rs.close();
		}
		return forumTopics;
	}

	public static Vector getFollowTopics(int forumID, int rootID) {
		JdbcWrapper rs = new JdbcWrapper();
		Vector followTopics = new Vector();
		try {
			String sql = "select announceID from " + BBSConst.TABLE_BBS1 + "," + BBSConst.TABLE_BOARD + " where " + BBSConst.TABLE_BBS1 + ".boardid="
					+ forumID
					+ " and " + BBSConst.TABLE_BBS1 + ".rootid="
					+ rootID
					+ " and " + BBSConst.TABLE_BBS1 + ".announceid<>"
					+ rootID
					+ " and " + BBSConst.TABLE_BBS1 + ".boardid=" + BBSConst.TABLE_BOARD + ".boardid and  " + BBSConst.TABLE_BBS1 + ".locktopic!=2 order by " + BBSConst.TABLE_BBS1 + ".rootid desc," + BBSConst.TABLE_BBS1 + ".orders";
			rs.executeQuery(sql);

			while (rs.next()) {
				int announceID = rs.getInt(1);
				ForumTopic theMSG = (ForumTopic) CacheManager.getCache(
						ENV.FORUM_TOPIC).get(String.valueOf(announceID));
				if (theMSG == null) {
					theMSG = new ForumTopic(rootID, announceID);
					CacheManager.getCache(ENV.FORUM_TOPIC).put(
							String.valueOf(announceID), theMSG);
				}
				followTopics.add(theMSG);
			}
		} catch (Exception e) {
			log.error("取得主题回复帖子出错", e);
		} finally {
			rs.close();
		}
		return followTopics;
	}

	public ForumMSG getForumMSGTopic() {
		return this.forumMSGTopic;
	}

	public Vector getForumMSGs(int forumID, int rootID, int announceID,
			int start, int perPage) throws ForumMSGNotFoundException {
		JdbcWrapper rs = new JdbcWrapper();
		Vector forumMSGs = new Vector();
		String sql = null;
		try {
			// 回复帖子数量
			sql = " select count(*) from " + BBSConst.TABLE_BBS1 + " B where B.rootid=" + rootID
					+ " and B.lockTopic!=2 order by announceid ";
			forumMSGsNum = rs.doIntSearch(sql);

			sql = " Select B.AnnounceID,B.UserName " + " from " + BBSConst.TABLE_BBS1 + " B "
					//+ " where (B.boardid=" + forumID + " or B.istop=2) and B.rootid=" + rootID
					+ " where B.rootid=" + rootID
					+ " and B.lockTopic!=2 order by announceid limit "
					+ (start - 1) + "," + (perPage);
			//
			rs.executeQuery(sql);
			while (rs.next()) {
				//
				int aid = rs.getInt(1);
				ForumMSG theMSG = (ForumMSG) CacheManager.getCache(
						ENV.FORUM_NEWS).get(String.valueOf(aid));
				if (theMSG == null) {
					theMSG = new ForumMSG(aid);
					CacheManager.getCache(ENV.FORUM_NEWS).put(
							String.valueOf(aid), theMSG);
				}
				//
				String un = rs.getString(2);
				User msgUser = (User) CacheManager.getCache(ENV.FORUM_USER)
						.get(un);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -