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

📄 forum.java

📁 BBS论坛系统由JAVA和JSP实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package net.acai.forum;
/**
 * Title:        清清网络
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:      www.SuperSpace.com
 * @author:       SuperSpace
 * @version 1.0
 */
import net.acai.database.*;
import java.sql.*;
import net.acai.filter.*;
import net.acai.util.*;
import net.acai.forum.*;
import net.acai.util.Format;
import java.util.Vector;
import javax.servlet.http.*;
//import net.acai.forum.util.*;
import java.util.regex.*;

public class Forum{

	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{
		try{
			DBConnect dbc=new DBConnect("select * from bbs.board where boardid=?");
			dbc.setInt(1,forumID);
			ResultSet rs=dbc.executeQuery();
			rs.next();
			this.forumID=rs.getInt(1);
			forumType=rs.getString(2);
			forumClass=rs.getInt(3);
			readMe=rs.getString(4);
			forumMaster=rs.getString(5);
			lockForum=rs.getInt(6);
			forumSkin=rs.getInt(7);
			tableBack=rs.getString(8);
			tableTitle=rs.getString(9);
			tableBody=rs.getString(10);
			aTableBody=rs.getString(11);
			tableFont=rs.getString(12);
			tableContent=rs.getString(13);
			alertFont=rs.getString(14);
			lastPostUser=rs.getString(15);
			lastPostTime=rs.getString(16);
			lastBbsNum=rs.getInt(17);
			lastTopicNum=rs.getInt(18);
			strAllowForumCode=rs.getInt(19);
			strAllowHTML=rs.getInt(20);
			strIMGInPosts=rs.getInt(21);
			strIcons=rs.getInt(22);
			strFlash=rs.getInt(23);
			forumLogo=rs.getString(24);
			indexIMG=rs.getString(25);
			lastRootID=rs.getInt(26);
			lastTopic=rs.getString(27);
			todayNum=rs.getInt(28);
			forumUser=rs.getString(29);
			dbc.clearParameters();
			dbc.close();
		}
		catch(Exception e){
			e.printStackTrace();
			throw new ForumNotFoundException();
		}
	}

	public Vector getOnline() throws ForumNotFoundException{
		try{
			DBConnect dbc=new DBConnect();
			dbc.prepareStatement("select * from bbs.online order by id");
			ResultSet rs=dbc.executeQuery();
			forumsOLUsersNum=rs.getRow();
			forumOLUsers=new Vector();
			dbc.prepareStatement("select * from bbs.online where stats like ? order by id");
			String tempForumType="%"+forumType+"%";
			dbc.setBytes(1,(new String(tempForumType.getBytes("ISO-8859-1"),"GBK")).getBytes());
			rs=dbc.executeQuery();

			while(rs.next()){//&&this.forumType.equals(rs.getString(4).trim())){

				OLUser tempOLUser=new OLUser();
				tempOLUser.setUserID(rs.getInt(1));
				if("guest".equals(rs.getString(2)))
					forumOLGuestUsersNum++;
				else
					forumOLMemberUsersNum++;
				tempOLUser.setUserName(rs.getString(2));
				tempOLUser.setUserClass(rs.getString(3));
				tempOLUser.setStats(rs.getString(4));
				tempOLUser.setUserIP(rs.getString(5));
				tempOLUser.setStartTime(rs.getString(6));
				tempOLUser.setLastTimeBK(rs.getString(7));
				tempOLUser.setLastTime(rs.getString(8));
				tempOLUser.setBrowser(rs.getString(9));
				tempOLUser.setActForIP(rs.getString(10));
				tempOLUser.setComeFrom(rs.getString(11));
				tempOLUser.setActCome(rs.getString(12));
				forumOLUsers.add(tempOLUser);

			}

			dbc.close();
			return forumOLUsers;
		}
		catch(Exception e){
			e.printStackTrace();
			throw new ForumNotFoundException();
		}
	}

	public Vector getForumTopics  (int forumID,int start ,int Page) throws ForumTopicNotFoundException{
		try
		{
			//DBConnect dbc=new DBConnect(2,0);
			DBConnect dbc=new DBConnect();
			ResultSet rs=dbc.executeQuery("select count(announceid) from bbs.bbs1 where boardID="+forumID+" and parentID=0  and  locktopic!=2");
			rs.next();
			forumTopicNum=rs.getInt(1);

			String sql="select count(Announceid) from bbs.bbs1 where istop=1 and layer=1 and boardid="+forumID;
			rs=dbc.executeQuery(sql);
			rs.next();
			int topNum=rs.getInt(1);
			rs.close();
			int maxAnnouncePerPage=Integer.parseInt(ForumPropertiesManager.getString("MaxAnnouncePerPage"));

			/*if(Page>1)
				sql="select * from bbs1 where boardID="+forumID+" and parentID=0\n and times < (select all (times) from bbs1 where boardID="+forumID+" and istop=0 and parentID=0 order by times desc limit 0,"+((Page-1)*maxAnnouncePerPage-topNum)+")  and\n  locktopic!=2 ORDER BY istop desc,times desc,announceid desc limit\n 0,"+maxAnnouncePerPage;
			else*/
				sql="select * from bbs.bbs1 where boardID="+forumID+" and parentID=0  and  locktopic!=2\n ORDER BY istop desc,times desc,announceid desc\n";

			dbc.prepareStatement(sql);
			rs=dbc.executeQuery();
			int num1 = ((Page-1)*maxAnnouncePerPage) ;
			int num2 = (((Page-1)*maxAnnouncePerPage)+maxAnnouncePerPage) ;
			int i = 0 ;
			int n = 0 ;
			Vector forumTopics=new Vector();
			while(rs.next()){
			
					i++;
					if(i<num1)continue;

					n++;
					if(n>num2)break;

					ForumTopic theTopic=new ForumTopic(rs.getInt(12));
					theTopic.setAnnounceID(rs.getInt(1));
					theTopic.setParentID(rs.getInt(2));
					theTopic.setChildNum(rs.getInt(3));
					theTopic.setForumID(rs.getInt(4));
					theTopic.setUserName(rs.getString(5));
					theTopic.setUserEmail(rs.getString(6));
					theTopic.setTopic(rs.getString(7));
					theTopic.setBody(rs.getString(8));
					theTopic.setDateAndTime(rs.getString(9));
					theTopic.setHits(rs.getInt(10));
					theTopic.setLength(rs.getInt(11));
					theTopic.setRootID(rs.getInt(12));
					theTopic.setLayer(rs.getInt(13));
					theTopic.setOrders(rs.getInt(14));
					theTopic.setIsBest(rs.getInt(15));
					theTopic.setUserIP(rs.getString(16));
					theTopic.setExpression(rs.getString(17));
					theTopic.setTimes(rs.getInt(18));
					theTopic.setLockTopic(rs.getInt(19));
					theTopic.setSignFlag(rs.getInt(20));
					theTopic.setEmailFlag(rs.getInt(21));
					theTopic.setIsTop(rs.getInt(22));
					theTopic.setIsVote(rs.getInt(23));
					forumTopics.add(theTopic);

				}

			dbc.close();
			return forumTopics;
		}
		catch ( ForumTopicNotFoundException  oe )
		{
			oe.printStackTrace();
			return null;
		}
		catch ( SQLException s3 )
		{
			s3.printStackTrace();
			return null;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new ForumTopicNotFoundException();
		}
	}
	public Vector getForumBestTopics  (int forumID,int start ,int perPage) throws ForumTopicNotFoundException{
		try{
			//DBConnect dbc=new DBConnect(2,0);
			DBConnect dbc=new DBConnect();
			dbc.prepareStatement("select * from bbs.bbs1 where boardID=? and isBest=1 and locktopic!=2  ORDER BY bbs1.times desc,bbs1.announceid desc");
			dbc.setInt(1,forumID);
			ResultSet rs=dbc.executeQuery();
			if(rs.last())
			forumTopicNum=rs.getRow();
			rs.absolute(start);
			int i=0;
			Vector forumTopics=new Vector();
			do
				{

					ForumTopic theTopic=new ForumTopic(rs.getInt(12));
					theTopic.setAnnounceID(rs.getInt(1));
					theTopic.setParentID(rs.getInt(2));
					theTopic.setChildNum(rs.getInt(3));
					theTopic.setForumID(rs.getInt(4));
					theTopic.setUserName(rs.getString(5));
					theTopic.setUserEmail(rs.getString(6));
					theTopic.setTopic(rs.getString(7));
					theTopic.setBody(rs.getString(8));
					theTopic.setDateAndTime(rs.getString(9));
					theTopic.setHits(rs.getInt(10));
					theTopic.setLength(rs.getInt(11));
					theTopic.setRootID(rs.getInt(12));
					theTopic.setLayer(rs.getInt(13));
					theTopic.setOrders(rs.getInt(14));
					theTopic.setIsBest(rs.getInt(15));
					theTopic.setUserIP(rs.getString(16));
					theTopic.setExpression(rs.getString(17));
					theTopic.setTimes(rs.getInt(18));
					theTopic.setLockTopic(rs.getInt(19));
					theTopic.setSignFlag(rs.getInt(20));
					theTopic.setEmailFlag(rs.getInt(21));
					theTopic.setIsTop(rs.getInt(22));
					theTopic.setIsVote(rs.getInt(23));
					forumTopics.add(theTopic);
					i++;
					if(i==perPage)
					break;
				}
			while(rs.next());
			dbc.close();
			return forumTopics;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new ForumTopicNotFoundException();
		}
	}

	public static Vector getFollowTopics (int forumID,int rootID){
			Vector followTopics=new Vector();
			try{
				String sql="select announceID,layer,bbs.bbs1.boardID,rootID,topic,body,userName,child,hits from bbs.bbs1,bbs.board where bbs.bbs1.boardid="+forumID+" and bbs.bbs1.rootid="+rootID+" and bbs.bbs1.announceid<>"+rootID+" and bbs.bbs1.boardid=bbs.board.boardid and  bbs.bbs1.locktopic!=2 order by bbs.bbs1.rootid desc,bbs.bbs1.orders";
				//DBConnect dbc=new DBConnect(2,0);
				DBConnect dbc=new DBConnect();
				ResultSet rs=dbc.executeQuery(sql);

				while(rs.next()){
					ForumTopic theMSG=new ForumTopic();
					theMSG.setAnnounceID(rs.getInt("announceID"));
					theMSG.setLayer(rs.getInt("layer"));
					theMSG.setForumID(rs.getInt("boardID"));
					theMSG.setRootID(rs.getInt("rootID"));
					theMSG.setAnnounceID(rs.getInt("announceID"));

					/*
					if(rs.getString("topic")==null||rs.getString("topic").trim().equals("")){
						String m=rs.getString("body");
						if(rs.getString("body").length()>22)
							theMSG.setTopic(m.substring(0,22).replaceAll("\\n|\\r"," ").replaceAll(">", "&gt;").replaceAll("<", "&lt;"));
						else{

							theMSG.setTopic(m.replaceAll("\\r|\\n"," ").replaceAll(">", "&gt;").replaceAll("<", "&lt;"));
						}
					}
					else*/
					theMSG.setTopic(rs.getString("topic"));
					theMSG.setBody(rs.getString("body"));
					theMSG.setUserName(rs.getString("userName"));
					theMSG.setChildNum(rs.getInt("child"));
					theMSG.setHits(rs.getInt("hits"));

					followTopics.add(theMSG);
				}
				dbc.close();

			}
			catch(Exception e){
				e.printStackTrace();
			}

			return followTopics;

	}
	public ForumMSG getForumMSGTopic(){
		return this.forumMSGTopic;
	}
	public Vector getForumMSGs  (int forumID,int rootID,int announceID,int start ,int perPage) throws ForumMSGNotFoundException{
		try{
			DBConnect dbc=new DBConnect();
			ResultSet rs=dbc.executeQuery("select topic,istop,isbest,username,hits,times from bbs.bbs1 where announceID="+rootID);
			rs.next();
			forumMSGTopic=new ForumTopic();
			forumMSGTopic.setTopic(rs.getString(1));
			forumMSGTopic.setIsTop(rs.getInt(2));
			forumMSGTopic.setIsBest(rs.getInt(3));
			forumMSGTopic.setUserName(rs.getString(4));
			forumMSGTopic.setHits(rs.getInt(5));
			forumMSGTopic.setTimes(rs.getInt(6));
			forumMSGTopic.setAnnounceID(rootID);
			rs.close();


			String sql="Select B.AnnounceID,B.boardID,B.UserName,B.Topic,B.dateandtime,B.body,"+
				"B.Expression,B.ip,B.rootid,B.signflag,B.isbest,B.isvote,"+
				"U.username,U.useremail,U.homepage,U.oicq,U.sign,U.userclass,"+
				"U.title,U.width,U.height,U.article,U.face,U.addDate,"+
				"U.userWealth,U.userEP,U.userCP,B.hits,B.isTop,B.lockTopic"+
				" from bbs.bbs1 B inner join bbs.myuser U on U.username=B.username "+
				"where B.boardid="+forumID+" and B.rootid="+rootID+" and B.lockTopic!=2 order by announceid";

			rs=dbc.executeQuery(sql);

			//if(rs.last())				forumMSGsNum=rs.getRow();
			forumMSGsNum = 0 ;
			while(rs.next())
			{
				forumMSGsNum  ++ ;

⌨️ 快捷键说明

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