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

📄 forumsetup.jsp

📁 Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统
💻 JSP
字号:

<%
/**
 *	$RCSfile: forumSetup.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:33 $
 */
%>

<%@ page import="java.text.*,
                 java.util.*,
                 com.jivesoftware.util.*,
                 com.jivesoftware.forum.*,
                 com.jivesoftware.forum.util.*"
%>

<%! // global variables
    
    // default number of threads to show
    static final int DEFAULT_THREAD_RANGE = 15;
    // default number of messages to show
    static final int DEFAULT_MESSAGE_RANGE = 15;
    
    // possible values for a thread range
    static final int[] THREAD_RANGES = {15, 30, 50, 100};
    // possible values for message ranges
    static final int[] MESSAGE_RANGES = {5, 15, 30, 50, 100};
    
    // Date constants
    static final long MONTH = JiveGlobals.DAY * 30;
    
    // Timezones
	private static final String[][] timeZones = getTimeZoneList();
    
    // XXX internationalize this!
    static final SimpleDateFormat shortDateFormatter = new SimpleDateFormat("MMM, yyyy");
%>

<%  // Check to see if a Jive authorization token exists
    Authorization authToken = SkinUtils.getUserAuthorization(request, response);
    // If authToken is null, make an anonymous login:
    if (authToken == null) {
        authToken = AuthorizationFactory.getAnonymousAuthorization();
    }
    boolean isGuest = authToken.isAnonymous();
    // Get the forum factory object.
    ForumFactory forumFactory = ForumFactory.getInstance(authToken);
    // Get the user of this page
    User pageUser = null;
    if (!isGuest) {
	    pageUser = forumFactory.getUserManager().getUser(authToken.getUserID());
    }
    long lastVisited = SkinUtils.getLastVisited(request,response);
%>

<%! // global methods
    
    // Returns the number of messages posted in the given forum in the last
    // 24 hours.
	private static int getNewMessageCount(Forum forum) {
        long recent = CacheTimer.currentTime;
        recent = (recent/36000000)*36000000;
		ResultFilter filter = new ResultFilter();
		filter.setCreationDateRangeMin(new Date(recent));
		int newMessageCount = forum.getThreadCount(filter);
		return newMessageCount;
	}
    
    // Returns the number of messages posted in the given thread in the last
    // 24 hours.
	private static int getNewMessageCount(ForumThread thread) {
        long recent = CacheTimer.currentTime;
        recent = (recent/36000000)*36000000;
		ResultFilter filter = new ResultFilter();
		filter.setCreationDateRangeMin(new Date(recent));
		int newMessageCount = thread.getMessageCount(filter);
		return newMessageCount;
	}
    
    // Returns the most recent message posted in this forum
	private static ForumMessage getMostRecentMessage(ForumThread thread) {
		ResultFilter filter = new ResultFilter();
        filter.setSortOrder(ResultFilter.DESCENDING);
        Iterator messages = thread.messages(filter);
        ForumMessage recentMessage = null;
        if (messages.hasNext()) {
            recentMessage = (ForumMessage)messages.next();
        }
        return recentMessage;
	}
    
	// Returns the number of threads per forum listing to display for the user
	private static int myEnv.du.getThreadRange(HttpServletRequest request,
			HttpServletResponse response, User user)
	{
		int threadRange = ParamUtils.getIntParameter(request,"thRange",-1);
		if (threadRange > -1) {
			return threadRange;
		} else {
			threadRange = DEFAULT_THREAD_RANGE;
			if (user != null) {
				try {
					threadRange = Integer.parseInt(user.getProperty("jive.threadRange"));
				} catch (Exception e) {}
			}
			else {
				try {
					threadRange = Integer.parseInt(SkinUtils.retrieve(request,response,"jive.threadRange").trim());
				} catch (Exception e) {}
			}
			return threadRange;
		}
	}
    
	// Returns the number of messages to display.
	private static int myEnv.du.getMessageRange(HttpServletRequest request,
			HttpServletResponse response, User user)
	{
		int messageRange = ParamUtils.getIntParameter(request,"msRange",-1);
		if (messageRange > -1) {
			return messageRange;
		} else {
			messageRange = DEFAULT_MESSAGE_RANGE;
			if (user != null) {
				try { 
					messageRange = Integer.parseInt(user.getProperty("jive.messageRange"));
				} catch (Exception e) {}
			}
			else {
				try {
					messageRange = Integer.parseInt(SkinUtils.retrieve(request,response,"jive.messageRange").trim());
				} catch (Exception e) {}
			}
			return messageRange;
		}
	}
    
	// Prints out a group of links to paginate through thread listings, ie:
	// "X page(s) [ 1 2 3 4 5 | > ]"
	private static String myEnv.du.getForumPaginator(long forumID, int topicCount,
			int numPages, int start, int range)
	{
		StringBuffer buf = new StringBuffer();
		
		// "X page(s) in this forum":
		buf.append("<b>").append(numPages).append("</b> page").append((numPages!=1)?"s":"");
        buf.append(" in this forum");
		
		// "["
		buf.append(" [ ");
		
		// Print out a left arrow if necessary
		if (start > 0) {
			buf.append("<a href=\"forum.jsp?forum=");
			buf.append(forumID);
			buf.append("&start=");
			buf.append((start-range));
			buf.append("&thRange=");
			buf.append(range);
			buf.append("\" class=\"forum\" title=\"Previous page\">&laquo;</a>");
			buf.append(" | ");
		}
		
		// Calculate the starting point & end points (the range of pages to display)
		int currentPage = (start/range)+1;
		int lo = currentPage - 5;
		if (lo <= 0) {
			lo = 1;
		}
		int hi = currentPage + 5;
		
		// print out a link to the first page if we're beyond that page
		if (lo > 2) {
			buf.append("<a href=\"forum.jsp?forum=");
			buf.append(forumID);
			buf.append("\" class=\"forum\" title=\"Go to the first topic page\">1</a> ... ");
		}
		
		// Print the page numbers before the current page
		while (lo < currentPage) {
			buf.append("<a href=\"forum.jsp?forum=");
			buf.append(forumID);
			buf.append("&start=");
			buf.append(((lo-1)*range));
			buf.append("&thRange=");
			buf.append(range);
			buf.append("\" class=\"forum\"><b>");
			buf.append(lo);
			buf.append("</b></a>&nbsp;");
			lo++;
		}
		
		// Print the current page
		buf.append("<b><span style=\"background-color:#ffffff;color:#000000;\">");
		buf.append(currentPage);
		buf.append("</span></b>");
		
		currentPage++;
		
		// Print page numbers after the current page
		while ((currentPage <= hi) && (currentPage<=numPages)) {
			buf.append("&nbsp;<a href=\"forum.jsp?forum=");
			buf.append(forumID);
			buf.append("&start=");
			buf.append(((currentPage-1)*range));
			buf.append("&thRange=");
			buf.append(range);
			buf.append("\" class=\"forum\"><b>");
			buf.append(currentPage);
			buf.append("</b></a>");
			currentPage++;
		}
		
		// Show a next arrow if necesary
		if (topicCount > (start+range)) {
			int numRemaining = (int)(topicCount-(start+range));
			buf.append(" | ");
			buf.append("<a href=\"forum.jsp?forum=");
			buf.append(forumID);
			buf.append("&start=");
			buf.append((start+range));
			buf.append("&thRange=");
			buf.append(range);
			buf.append("\" class=\"forum\" title=\"Next page\">&raquo;</a>");
		}
		
		// "]"
		buf.append(" ]");
		return buf.toString();
	}
    
    private static int boxSequence = 0;
    
    private static String printBox(String label, String href, String borderColor,
            String backgroundColor, String borderColorHover,
            String backgroundColorHover, String width)
    {
        if (boxSequence == 100) {
            boxSequence = 0;
        }
        
        StringBuffer buf = new StringBuffer(500);
        boxSequence++;
        buf.append("<table id=\"tb").append(boxSequence).append("\" ");
        buf.append("bgcolor=\"").append(borderColor).append("\" ");
        buf.append("cellpadding=\"1\" cellspacing=\"0\" border=\"0\" ");
        if (width != null && !width.equals("")) {
            buf.append("width=\"").append(width).append("\">");
        } else {
            buf.append(">");
        }
        
        buf.append("<tr><td><table bgcolor=\"").append(backgroundColor).append("\" ");
        buf.append("cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
        buf.append("<tr><td nowrap align=\"center\"");
        buf.append("onmouseover=\"this.style.cursor='hand';");
        buf.append("this.style.backgroundColor='").append(backgroundColorHover).append("';");
        buf.append("document.all.tb").append(boxSequence).append(".style.backgroundColor='").append(borderColorHover).append("';\"");
        buf.append("onmouseout=\"this.style.backgroundColor='").append(backgroundColor).append("';");
        buf.append("document.all.tb").append(boxSequence).append(".style.backgroundColor='").append(borderColor).append("';\"");
        //buf.append("onclick=\"location.href='").append(href).append("'\";");
        buf.append("onclick=\"document.anchors('foo").append(boxSequence).append("').click();\"");
        buf.append("><font size=\"-2\">");
        buf.append("<a id=\"foo").append(boxSequence).append("\" href=\"").append(href).append("\" ");
        buf.append("style=\"text-decoration:none;\"><b>").append(label).append("</b></a>");
        buf.append("</font></td></tr></table></td></tr></table>");
        
        return buf.toString();
    }
    
	//
	private static String[][] getTimeZoneList() {
		String[][] zones = new String[30][2];
		for (int i=0; i<12; i++) {
			zones[i][0] = "GMT+" + ((i<10)?"0":"") + i;
			zones[i][1] = "GMT +" + i + " hour" + ((i!=1)?"s":"");
		}
		zones[12][0] = "GMT-12";
		zones[12][1] = "GMT -12 hours";
		
		zones[13][0] = "GMT-11";
		zones[13][1] = "GMT -11 hours";
		
		zones[14][0] = "GMT-10";
		zones[14][1] = "GMT -10 hours";
		
		zones[15][0] = "Pacific/Honolulu";
		zones[15][1] = "GMT -10 hours (HST)";
		
		zones[16][0] = "GMT-09";
		zones[16][1] = "GMT -9 hours";
		
		zones[17][0] = "America/Anchorage";
		zones[17][1] = "GMT -9 hours (AKT)";
		
		zones[18][0] = "GMT-08";
		zones[18][1] = "GMT -8 hours";
		
		zones[19][0] = "America/Los_Angeles";
		zones[19][1] = "GMT -8 hours (PST)";
		
		zones[20][0] = "GMT-07";
		zones[20][1] = "GMT -7 hours";
		
		zones[21][0] = "America/Denver";
		zones[21][1] = "GMT -7 hours (MST)";
		
		zones[22][0] = "GMT-06";
		zones[22][1] = "GMT -6 hours";
		
		zones[23][0] = "America/Chicago";
		zones[23][1] = "GMT -6 hours (CST)";
		
		zones[24][0] = "GMT-05";
		zones[24][1] = "GMT -5 hours";
		
		zones[25][0] = "America/New_York";
		zones[25][1] = "GMT -5 hours (EST)";
		
		zones[26][0] = "GMT-04";
		zones[26][1] = "GMT -4 hours";
		
		zones[27][0] = "GMT-03";
		zones[27][1] = "GMT -3 hours";
		
		zones[28][0] = "GMT-02";
		zones[28][1] = "GMT -2 hours";
		
		zones[29][0] = "GMT-01";
		zones[29][1] = "GMT -1 hour";
		
		return zones;
	}
%>

⌨️ 快捷键说明

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