search.jsp

来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· JSP 代码 · 共 699 行 · 第 1/2 页

JSP
699
字号
</tr><tr bgcolor="#ffffff">    <td><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>"         face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"><%= SkinUtils.getLocalizedString("skin.default.search.category_or_forum",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %></font></td>    <td><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>">        <select size="1" name="forums">        <option value="-1"><%= SkinUtils.getLocalizedString("skin.default.search.all_categories",locale) %>    <%  String selected = "";        // Show forums in the root category first:        Iterator iter = null;        for (iter=rootCategory.forums(); iter.hasNext(); ) {            Forum f = (Forum)iter.next();    %>        <option value="<%= f.getID() %>"><%= f.getName() %>    <%  }        // Now, loop through all subcategories, print out forums in each        boolean showHeader = true;        String padding = "&nbsp;&nbsp;";        for (iter=rootCategory.recursiveCategories(); iter.hasNext(); ) {            ForumCategory c = (ForumCategory)iter.next();            selected = "";            if (categoryID == c.getID()) {                selected = " selected";            }            int depth = c.getCategoryDepth();            if (showHeader) {                showHeader = false;    %>        <option value="cid<%= c.getID() %>"<%= selected %>>                <%  for (int i=0; i<depth; i++) { out.print(padding); } %>                [<%= c.getName() %>]    <%      }            for (Iterator forumsIter=c.forums(); forumsIter.hasNext(); )            {                Forum f = (Forum)forumsIter.next();                selected = "";                if (forumID == f.getID()) {                    selected = " selected";                }    %>        <option value="<%= f.getID() %>"<%= selected %>>                <%  for (int i=0; i<depth+2; i++) { out.print(padding); } %>                &#149; <%= f.getName() %>    <%      }            showHeader = true;        }    %>        </select>        </font>   </td></tr><tr bgcolor="#ffffff">    <td><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"><%= SkinUtils.getLocalizedString("skin.default.search.date_range",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %></font></td>    <td><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>">        <select size="1" name="date">        <option value="any"><%= SkinUtils.getLocalizedString("skin.default.search.any_date",locale) %>        <%  Calendar cal = Calendar.getInstance();            // go back to yesterday            cal.add(Calendar.DAY_OF_YEAR, -1);        %>        <option value="yesterday"<%= ("yesterday".equals(relDate))?" selected":"" %>>            &nbsp;&nbsp;&#149;&nbsp;&nbsp; <%= SkinUtils.getLocalizedString("skin.default.search.since_yesterday",locale) %> (<%= shortFormatter.format(cal.getTime()) %>)        <%  cal.add(Calendar.DAY_OF_YEAR, -6); %>        <option value="7daysago"<%= ("7daysago".equals(relDate))?" selected":"" %>>            &nbsp;&nbsp;&#149;&nbsp;&nbsp; <%= SkinUtils.getLocalizedString("skin.default.search.7_days",locale) %> (<%= shortFormatter.format(cal.getTime()) %>)        <%  cal.add(Calendar.DAY_OF_YEAR, -23); %>        <option value="30daysago"<%= ("30daysago".equals(relDate))?" selected":"" %>>            &nbsp;&nbsp;&#149;&nbsp;&nbsp; <%= SkinUtils.getLocalizedString("skin.default.search.30_days",locale) %> (<%= shortFormatter.format(cal.getTime()) %>)        <%  cal.add(Calendar.DAY_OF_YEAR, -60); %>        <option value="90daysago"<%= ("90daysago".equals(relDate))?" selected":"" %>>            &nbsp;&nbsp;&#149;&nbsp;&nbsp; <%= SkinUtils.getLocalizedString("skin.default.search.90_days",locale) %> (<%= shortFormatter.format(cal.getTime()) %>)        <%  cal = Calendar.getInstance();            int year = cal.get(Calendar.YEAR);        %>        <option value="thisyear"<%= ("thisyear".equals(relDate))?" selected":"" %>>            &nbsp;&nbsp;&#149;&nbsp;&nbsp; <%= SkinUtils.getLocalizedString("skin.default.search.this_year",locale) %> (<%= year %>)        <option value="2years"<%= ("2years".equals(relDate))?" selected":"" %>>            &nbsp;&nbsp;&#149;&nbsp;&nbsp; <%= SkinUtils.getLocalizedString("skin.default.search.2_years",locale) %> (<%= (year-1) %>-<%= year %>)        </select>        </font>   </td></tr><tr bgcolor="#ffffff">    <td><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"><%= SkinUtils.getLocalizedString("skin.default.search.username",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %></font></td>    <td><input type="text" name="user" value="<%= (user!=null)?user.getUsername():"" %>"></td></tr><tr bgcolor="#ffffff">    <td><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"><%= SkinUtils.getLocalizedString("skin.default.search.results_page",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %></font></td>    <td><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>">        <select size="1" name="range">    <%  for (int i=0; i<RESULT_COUNTS.length; i++) {            selected = "";            if (RESULT_COUNTS[i] == range) {                selected = " selected";            }    %>        <option value="<%= RESULT_COUNTS[i] %>"<%= selected %>><%= RESULT_COUNTS[i] %>    <%  } %>        </select>        </font>   </td></tr><tr bgcolor="#ffffff">    <td colspan="2" align="center"><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>"><input type="submit" value="<%= SkinUtils.getLocalizedString("skin.default.global.search",locale) %>"></font></td></tr></table></td></tr></table></form><p><%  // Do a search if requested    if (search) {        // The iterator of search results        Iterator results = null;        int numResults = 0;        // If the queryText is not null, set it's value in the query object. If        // it is null, check to see if we're filtering on a user. If so, we need        // to make "results" an iterator of messages posted by that user.        if (queryText != null) {            query.setQueryString(queryText);            results = query.results(start,range);            numResults = query.resultCount();        }        else {            // If we're filtering on a user, make the results iterator a list            // of messages posted by that user            if (user != null) {                results = userManager.userMessages(user, start, range);                numResults = userManager.userMessageCount(user);            }        }        // display results        if (!results.hasNext()) {%>        <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">        <center><i><%= SkinUtils.getLocalizedString("skin.default.search.no_results",locale) %></i></center>        </font>        <p><%      }        else {%>        <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">        <%= SkinUtils.getLocalizedString("skin.default.search.search_results",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %> <b><%= SkinUtils.getLocalizedNumber(numResults,locale) %></b>        <%= SkinUtils.getLocalizedString("skin.default.global.left_bracket",locale) %><%= SkinUtils.getLocalizedString("skin.default.search.results_page",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %> <b><%= SkinUtils.getLocalizedNumber(range,locale) %></b><%= SkinUtils.getLocalizedString("skin.default.global.right_bracket",locale) %>        </font>        <p><%      String[] queryWords = StringUtils.toLowerCaseWordArray(queryText);        String skinElipse = SkinUtils.getLocalizedString("skin.default.global.elipse",locale);        String skinGuest = SkinUtils.getLocalizedString("skin.default.global.guest",locale);        // "count" is the search result number        int count = start + 1;        // "counter" is a way to keep track that we've only displayed "range"        // number of results.        int counter = 0;        // Loop through all the results        while (results.hasNext() && (counter++ < range)) {            // The message that is the search result            ForumMessage message = (ForumMessage)results.next();            // Escape HTML tags in the body and intelligently trim the body		    String body = StringUtils.escapeHTMLTags(message.getUnfilteredBody());		    body = StringUtils.chopAtWord(body.trim(), 200) + " " + skinElipse;		    body = StringUtils.highlightWords(body, queryWords, "<font style='background-color:#ffff00'><b>", "</b></font>");            // The author of this search result            User author = message.getUser();            String authorUsername = "<i>" + skinGuest + "</i>";            if (author != null) {                authorUsername = author.getUsername();            }            // Ids associated with this search result            long mID = message.getID();            long tID = message.getForumThread().getID();            long fID = message.getForumThread().getForum().getID();%>        <table cellpadding="2" cellspacing="0" border="0">        <tr>        <td valign="top">            <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">            <%= count++ %>)            </font>        </td>        <td>            <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">            <a href="thread.jsp?forum=<%= fID %>&thread=<%= tID %>&message=<%= mID %>&q=<%= encodedQueryText %>#<%= mID %>"            ><%= message.getSubject() %></a>            <br>            <font color="#666666" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">            <%               List dateDisplay = new ArrayList(1);               dateDisplay.add(SkinUtils.formatDate(request,pageUser,message.getCreationDate()));               dateDisplay.add(authorUsername);            %>            <%= SkinUtils.getLocalizedString("skin.default.search.posted_on", locale, dateDisplay) %>            </font>            </font>        </td>        </tr>        </table>        <ul>        <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">        <%= body %>        </font>        </ul><%      } // end while loop%><%  // Code for displaying the correct search result page links    // The total search result pages is the number of results divided by the    // number of results per page.    int totalPages = numResults/range;    if (totalPages * range < numResults) {        totalPages += 1;    }    // Logic to correctly display the page pagination links:    int i = start/range;	int lTotal = i-1;	int rTotal = totalPages-i;	int lCount, rCount;	if (i < 5) {        lCount = lTotal;    }	else {        lCount = 5;    }	if (i+5 > totalPages) {		rCount = totalPages-i;		lCount += 5-(totalPages-i) > lTotal-lCount? lTotal-lCount: 5-(totalPages-i);	}	else {		rCount = 5;		if (lCount < 5) {			rCount += 5-lCount > rTotal-rCount? rTotal-rCount: 5-lCount;		}	}    // Construct the search HREF    StringBuffer href = new StringBuffer(100);    href.append("search.jsp?").append(printForumParams(forumIDs));    href.append("&q=").append(java.net.URLEncoder.encode((queryText!=null?queryText:"")));    href.append("&range=").append(range);    href.append("&search=true");    if (relDate != null) {        href.append("&date=").append(relDate);    }    if (user != null) {        href.append("&user=").append(user.getUsername());    }%><table cellpadding="4" cellspacing="2" border="0" align="center"><tr><td colspan="3">    <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">    <b><%= SkinUtils.getLocalizedString("skin.default.search.search_results",locale) %><%= SkinUtils.getLocalizedString("skin.default.global.colon",locale) %></b>    </font>    </td></tr><tr><td>    <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">    <%	// Previous Page link        if ((start-range) >= 0) {    %>    <a href="<%= href.toString() %>&start=<%= (start-range) %>" title="<%= SkinUtils.getLocalizedString("skin.default.search.click_previous",locale) %>"     ><img src="images/prev.gif" width="10" height="10" border="0"></a>    <a href="<%= href.toString() %>&start=<%= (start-range) %>" title="<%= SkinUtils.getLocalizedString("skin.default.search.click_previous",locale) %>"     ><%= SkinUtils.getLocalizedString("skin.default.global.previous_page",locale) %></a>    <%	} %>    &nbsp;    </font>    </td>    <td align="center">    <table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"     cellpadding="0" cellspacing="0" border="0" width="">    <tr><td>    <table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"     cellpadding="4" cellspacing="1" border="0" width="100%">    <tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.bgColor") %>"><%      for (int idx=(i-lCount); idx<=(i+rCount); idx++) {            boolean onCurrent = !((range*(idx-1))!=start);%>        <%  if (onCurrent) { %>        <td align="center" bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>">        <%  } else { %>        <td align="center">        <%  } %>        <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">        <%  if (onCurrent) { %>            <a href="<%= href.toString() %>&start=<%= range*(idx-1) %>"             style="color:#000000;background-color:#cccccc;"             title="<%= SkinUtils.getLocalizedString("skin.default.search.current",locale) %>"             ><%= idx %></a>        <%  } else { %>            <a href="<%= href.toString() %>&start=<%= range*(idx-1) %>"             title="<%= SkinUtils.getLocalizedString("skin.default.search.click_go",locale) %>"             ><%= idx %></a>        <%  } %>        </font>        </td><%	    } // end for %>    </tr>    </table>    </td></tr>    </table>    <td>    <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">    &nbsp;    <%	// Next page link        if( (start+range) < numResults ) {    %>    <a href="<%= href.toString() %>&start=<%= (start+range) %>" title="<%= SkinUtils.getLocalizedString("skin.default.search.click_next",locale) %>"     ><%= SkinUtils.getLocalizedString("skin.default.global.next_page",locale) %></a>    <a href="<%= href.toString() %>&start=<%= (start+range) %>" title="<%= SkinUtils.getLocalizedString("skin.default.search.click_next",locale) %>"     ><img src="images/next.gif" width="10" height="10" title="<%= SkinUtils.getLocalizedString("skin.default.search.click_next",locale) %>" border="0"></a>    <%	} %>    </font>    </td></tr></table><%      } // end else there are results%><%  } // end search block %><script language="JavaScript" type="text/javascript"><!--document.searchForm.q.focus();//--></script><br><%@ include file="footer.jsp" %>

⌨️ 快捷键说明

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