<% /* * $RCSfile: global.jsp,v $ * $Revision: 1.4 $ * $Date: 2001/05/16 16:21:36 $ */ %> <%@ page import="java.text.*, com.coolservlets.util.*" %> <%@ include file="loginMethods.jsp" %> <%@ include file="searchMethods.jsp" %> <%! // Global variables // one month in seconds: private static final int ONE_MONTH = 60*60*24*30; // Threads per page private static final int DEFAULT_THREAD_RANGE = 15; private static final int[] threadRanges = { 15, 30, 50, 100 }; // Messages per page private static final int DEFAULT_MESSAGE_RANGE = 15; private static final int[] messageRanges = { 5, 15, 30, 50, 100 }; // Default locale private static final Locale defaultLocale = SkinUtils.DEFAULT_LOCALE; // Timezones private static final String[][] timeZones = getTimeZoneList(); // Default timezone code private static final String defaultTimeZoneCode = SkinUtils.DEFAULT_TIMEZONECODE; // Default timezone private static final TimeZone defaultTimeZone = TimeZone.getTimeZone(defaultTimeZoneCode); // Date Formatter private static final DateFormat defaultDateFormatter = SkinUtils.DEFAULT_DATEFORMAT; static { defaultDateFormatter.setTimeZone(defaultTimeZone); } // A date format for displaying "dates since" like "user a member since:" private static final DateFormat dateSinceFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM,defaultLocale); // The following variables indicate what type of popular item list to display // (for instance, whether or not to show a list of the popular threads, // popular messages, or nothing). private static final int NONE = 0; private static final int POPULAR_FORUMS = 1; private static final int POPULAR_TOPICS = 2; // Global methods private static Iterator getRecentWatches(ForumFactory forumFactory, User user) throws UnauthorizedException { return forumFactory.getWatchManager().getWatchedForumThreads( user, WatchManager.NORMAL_WATCH); } private static ForumMessage getLastPost(ForumFactory forumFactory) { ForumMessage lastPost = null; // make a result filter, ordered by creation date (decending) // and with 1 result ResultFilter filter = new ResultFilter(); filter.setSortField(JiveGlobals.CREATION_DATE); filter.setSortOrder(ResultFilter.DESCENDING); filter.setStartIndex(0); filter.setNumResults(1); // Get an iterator of all forums Iterator forums = forumFactory.forums(); while (forums.hasNext()) { Forum forum = (Forum)forums.next(); // Get the last post in this forum Iterator messages = forum.messages(filter); if (messages.hasNext()) { ForumMessage message = (ForumMessage)messages.next(); if (message != null) { if (lastPost == null) { lastPost = message; } else if (message.getCreationDate().getTime() > lastPost.getCreationDate().getTime()) { lastPost = message; } } } } return lastPost; } // Returns the number of threads per forum listing to display for the user private static int getThreadRange(HttpServletRequest request, HttpServletResponse response, User user) { int threadRange = ParamUtils.getIntParameter(request,"range",-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 getMessageRange(HttpServletRequest request, HttpServletResponse response, User user) { int messageRange = ParamUtils.getIntParameter(request,"range",-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; } } // private static String getSkinURLRoot(HttpServletRequest request) { String uri = request.getRequestURI(); int pos = -1; // chop off the jsp page part of the URI if ((pos=uri.lastIndexOf("/")) > -1) { uri = uri.substring(0,pos) + "/"; } return uri; } // private static int getNewMessageCount(Forum forum) { long yesterday = CacheTimer.currentTime - (1000*60*60*24); ResultFilter filter = new ResultFilter(); filter.setModifiedDateRangeMin(new Date(yesterday)); int newMessageCount = forum.getThreadCount(filter); return newMessageCount; } private static final String fontFace = "\"arial,helvetica,sans-serif\""; private static final String fontSize = "\"-1\""; // Prints out a group of links to paginate through thread listings, ie: // "X page(s) [ 1 2 3 4 5 | > ]" private static String printForumPaginator(long forumID, int topicCount, int numPages, int start, int range) { StringBuffer buf = new StringBuffer(); // Initial font tag buf.append(""); // "X page(s)": buf.append(numPages).append(" page").append((numPages!=1)?"s":""); // "[" buf.append(" [ "); // Print out a left arrow if necessary if (start > 0) { buf.append(""); buf.append(" | "); } // Calculate the starting point & end points (the range of pages to display) int currentPage = (start/range)+1; int lo = currentPage - 3; if (lo <= 0) { lo = 1; } int hi = currentPage + 5; // print out a link to the first page if we're beyond that page if (currentPage > 2) { buf.append("first | "); } // Print the page numbers before the current page while (lo < currentPage) { buf.append(""); buf.append(lo); buf.append(" "); lo++; } // Print the current page buf.append(""); buf.append(currentPage); buf.append(""); currentPage++; // Print page numbers after the current page while ((currentPage <= hi) && (currentPage<=numPages)) { buf.append(" "); buf.append(currentPage); buf.append(""); currentPage++; } // Show a next arrow if necesary if (topicCount > (start+range)) { int numRemaining = (int)(topicCount-(start+range)); buf.append(" | "); buf.append(""); } // "]" buf.append(" ] "); 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; }