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

📄 searchthreadaction.java

📁 论坛软件系统亦称电子公告板(BBS)系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package cn.jsprun.struts.foreg.actions;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import cn.jsprun.domain.Members;
import cn.jsprun.domain.Searchindex;
import cn.jsprun.domain.Threadtypes;
import cn.jsprun.foreg.service.SearchService;
import cn.jsprun.service.system.DataBaseService;
import cn.jsprun.utils.BeanFactory;
import cn.jsprun.utils.Common;
import cn.jsprun.utils.DataParse;

public class SearchThreadAction extends DispatchAction {
	private SearchService searchServer = (SearchService) BeanFactory.getBean("searchserver");
	private DataBaseService dataBaseService = (DataBaseService) BeanFactory.getBean("dataBaseService");
	@SuppressWarnings("unused")
	private static int convertInt(String s) {
		int count = 0;
		try {
			count = Integer.valueOf(s);
		} catch (Exception e) {
		}
		return count;
	}

	@SuppressWarnings("unchecked")
	public ActionForward toSearch(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		Map<String,String> usergroups = (Map<String,String>)request.getAttribute("usergroups");
		if(usergroups==null || convertInt(usergroups.get("allowsearch"))<=0){
			String grouptitle = usergroups==null?"游客":usergroups.get("grouptitle");
			request.setAttribute("resultInfo", "您无权进行当前操作,这可能因以下原因之一造成<br>您所在的用户组("+grouptitle+")无法进行此操作。<br>您已经登录,但您的帐号或其所在的用户组无权访问当前页面");
			return mapping.findForward("showMessage");
		}
		HttpSession session=request.getSession();
		short groupid = (Short)session.getAttribute("jsprun_groupid");
		Members member = (Members)session.getAttribute("user");
		request.setAttribute("forumselect", Common.forumselect(false, false,groupid,member!=null?member.getExtgroupids():"",null,false));
		Map<String,String> settings = (Map<String,String>)request.getAttribute("settings");
		String hottaglist = "";
		if(settings.get("tagstatus").equals("1")){
			List<Map<String,String>> taglist = dataBaseService.executeQuery("SELECT tagname FROM jrun_tags WHERE closed=0 ORDER BY total DESC LIMIT 5");
			for(Map<String,String> tags:taglist){
				String tag = "<a href=\"tag.jsp?name="+Common.encode(tags.get("tagname"))+"\" target=\"_blank\">"+tags.get("tagname")+"</a>";
				hottaglist = hottaglist+"&nbsp;"+tag;
			}
			taglist = null;
		}
		request.setAttribute("hottaglist", hottaglist);
		return mapping.findForward("tosearch");
	}
	@SuppressWarnings("unchecked")
	public ActionForward toSearchByType(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		Map<String,String>usergroups = (Map<String,String>)request.getAttribute("usergroups");
		if(usergroups==null || usergroups.get("allowsearch").equals("0")){
			String grouptitle = usergroups==null?"游客":usergroups.get("grouptitle");
			request.setAttribute("show_message", "您所在的用户组("+grouptitle+")无法进行此操作。");
			return mapping.findForward("nopermission");
		}
		HttpSession session=request.getSession();
		short groupid = (Short)session.getAttribute("jsprun_groupid");
		Members member = (Members)session.getAttribute("user");
		request.setAttribute("forumselect", Common.forumselect(false, false,groupid,member!=null?member.getExtgroupids():"",null,false));
		String typehql = "from Threadtypes as t where t.special='1' order by displayorder";
		List<Threadtypes> typelist = searchServer.findThreadtypeByHql(typehql);
		request.setAttribute("threadtype", typelist);
		request.setAttribute("typeid", request.getParameter("typeid"));
		return mapping.findForward("tosearchbytype");
	}
	@SuppressWarnings("unchecked")
	public ActionForward search(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		Map<String,String> settings = (Map<String,String>)request.getAttribute("settings");
		Map<String,String> forumStr = (Map<String,String>)request.getAttribute("forums");
		Map<String,String> usergroups = (Map<String,String>)request.getAttribute("usergroups");
		if(usergroups==null || usergroups.get("allowsearch").equals("0")){
			String grouptitle = usergroups==null?"游客":usergroups.get("grouptitle");
			request.setAttribute("show_message", "您所在的用户组("+grouptitle+")无法进行此操作。");
			return mapping.findForward("nopermission");
		}
		DataParse dataParse = (DataParse) BeanFactory.getBean("dataParse");
		Map<String,Map<String,String>> forumMap=dataParse.characterParse(forumStr.get("forums"),false);
		request.setAttribute("threadsticky", settings.get("threadsticky").split(","));
		String srchtxt = request.getParameter("srchtxt");
		String srchuname = request.getParameter("srchuname");
		HttpSession session = request.getSession();
		int uid = (Integer)session.getAttribute("jsprun_uid");
		short groupid = (Short)session.getAttribute("jsprun_groupid");
		Members member = (Members)session.getAttribute("user");
		int cachelife_text = 3600;
		int timestamp = (Integer)(request.getAttribute("timestamp"));
		String searchid = request.getParameter("searchid");
		String searchsubmit = request.getParameter("searchsubmit");
		String orderby = request.getParameter("orderby");
		String ascdesc = request.getParameter("ascdesc");
		orderby = Common.isinarray(orderby, new String[]{"dateline","replies","views"})?orderby:"lastpost";
		ascdesc = !Common.isEmpty(ascdesc)&&ascdesc.equals("asc")?"asc":"desc";
		if (searchid != null && !searchid.equals("")) {
			List<Map<String,String>> searchindex = dataBaseService.executeQuery("select tids from jrun_searchindex as i where i.searchid="+searchid);
			if(searchindex!=null && searchindex.size()>0){
			String tids = searchindex.get(0).get("tids");
			if (tids.equals("0")) {
				request.setAttribute("threadlist", null);
			} else {
				int size = Common.toDigit(dataBaseService.executeQuery("select count(*) as count from jrun_threads as t where t.tid in ("+tids+") and t.displayorder>='0'").get(0).get("count"));
				int tpp = member != null && member.getTpp() > 0 ? member.getTpp(): Integer.valueOf(settings.get("topicperpage"));
				int page =Common.toDigit(request.getParameter("page"),2147483647l,1l).intValue();
				Map<String,Integer> multiInfo=Common.getMultiInfo(size, tpp, page);
				page=multiInfo.get("curpage");
				int start_limit=multiInfo.get("start_limit");
				String url = "search.jsp?action=search&searchid=" + searchid + "&orderby=" + orderby + "&ascdesc=" + ascdesc;
				Map<String,Object> multi=Common.multi(size, tpp, page, url,0, 10, true, false, null, false);
				request.setAttribute("multi", multi);
				String hql = "SELECT t.*,f.name FROM jrun_threads as t LEFT JOIN jrun_forums as f on t.fid=f.fid where t.tid IN ( "+tids+" ) AND t.displayorder>='0' order by " + orderby + " " + ascdesc+" limit "+start_limit+","+tpp;
				List<Map<String,String>> threadlist = dataBaseService.executeQuery(hql);
				List<Map<String,String>> disgetThread=new ArrayList<Map<String,String>>();
				if (threadlist != null) {
					int ppp = member != null&& member.getPpp() > 0 ? member.getPpp() : Integer.valueOf(settings.get("postperpage"));
					for (Map<String,String> t : threadlist) {
						disgetThread.add(Common.procThread(t, ppp));
					}
					request.setAttribute("threadlist", disgetThread);
				} else {
					request.setAttribute("threadlist", null);
				}
			}
			}else{
				request.setAttribute("threadlist", null);
			}
			if(Common.isshowsuccess(session, "search_redirect")){
				return mapping.findForward("searchresult");
			}else if(request.getParameter("path")==null && request.getParameter("page")==null){
				request.setAttribute("successInfo", "搜索完成,现在将转入结果页面。");
				request.setAttribute("requestPath", "search.jsp?action=search&searchid=" + searchid+ "&orderby=" + orderby + "&ascdesc=" + ascdesc+"&path=1");
				return mapping.findForward("showMessage");
			}else{
				return mapping.findForward("searchresult");
			}
		} else {
			String messages = null;
			Map creditspolicys=dataParse.characterParse(settings.get("creditspolicy"),false);
			Map<Integer, Integer> postcredits=(Map<Integer,Integer>)creditspolicys.get("search");
			Map extcredits = dataParse.characterParse(settings.get("extcredits"), true);
			Set<Integer> keys = postcredits.keySet();
			for (Integer key : keys) {
				Map extcreditmap = (Map)extcredits.get(key);
				if(extcreditmap!=null){
					int extcredit = member==null?0:(Integer)Common.getValues(member, "extcredits"+key);
					int getattacreditvalue = Integer.valueOf(postcredits.get(key)+"");
					String lowerlimit = extcreditmap.get("lowerlimit")==null?"0":String.valueOf(extcreditmap.get("lowerlimit"));
					if(getattacreditvalue!=0&&extcredit-getattacreditvalue<=Integer.valueOf(lowerlimit)){
						messages =  "对不起,您的操作将会导致您的 <b>"+extcreditmap.get("title")+"</b> 低于系统规定的下限值 "+lowerlimit+(extcreditmap.get("unit")!=null?"":extcreditmap.get("unit"))+",请返回修正后重新提交。";
						break;
					}
				}
			}
			if(uid!=0 && messages==null){
				Common.updatepostcredits("-", uid, postcredits);
				Common.updatepostcredits(uid, settings.get("creditsformula"));
				Common.updateMember(session, uid);
			}else{
				request.setAttribute("errorInfo", messages);
				return mapping.findForward("showMessage");
			}
			String searchctrl = settings.get("searchctrl");
			String maxspm = settings.get("maxspm");
			String maxsearchresult = settings.get("maxsearchresults");
			String special[] = request.getParameterValues("special[]");
			String srchfrom = request.getParameter("srchfrom");
			String srchfid[] = request.getParameterValues("srchfid");
			String srchtype = request.getParameter("srchtype");
			 String srchfilter = request.getParameter("srchfilter");
			String before = request.getParameter("before");
			srchtype = srchtype==null?"":srchtype;
			srchfilter = srchfilter==null?"":srchfilter;
			before = before == null?"0":before;
			if(usergroups.get("allowsearch").equals("2")&& srchtype.equals("fulltext")) {
				String message=Common.periodscheck(settings.get("searchbanperiods"), Byte.valueOf(usergroups.get("disableperiodctrl")),Float.valueOf(settings.get("timeoffset")));
				if(message!=null)
				{
					request.setAttribute("show_message", message);
					return mapping.findForward("nopermission");
				}
			} else if(!srchtype.equals("title")||!srchtype.equals("blog")) {
				srchtype = "title";
			}
			
			if(searchsubmit==null){
				if ((srchtxt == null || srchtxt.equals(""))&& (srchuname == null || srchuname.equals(""))) {
					request.setAttribute("errorInfo", "您没有指定要搜索的关键字或用户名,请返回重新填写。");
					return mapping.findForward("showMessage");
				}
			}
			srchtxt = srchtxt == null ? "" : srchtxt.replace("'", "''");
			srchuname = srchuname == null ? "" : srchuname.replace("'", "''");
			String space = "";
			if (special != null) {
				for (int i = 0; i < special.length; i++) {
					space += special[i] + ",";
				}
			}
			if (!space.equals("")) {
				space = space.substring(0, space.length() - 1);
			}
			StringBuffer forums =new StringBuffer();
			if (srchfid == null || srchfid[0].trim().equals("all")) {
				Set<String> fids = forumMap.keySet();
				String extgroupids = member!=null?member.getExtgroupids():"";
				for(String fid:fids){
					Map<String,String> forum = forumMap.get(fid);
					if ((forum.get("viewperm").equals(""))||Common.forumperm(forum.get("viewperm"), groupid, extgroupids)) {
						forums.append(fid + ",");
					}
				}
			} else {
				for (int i = 0; i < srchfid.length; i++) {
					forums.append(srchfid[i] + ",");
				}
			}
			if (forums.length()>0) {
				forums.deleteCharAt(forums.length()-1);
			}
			if(forums.toString().equals("all")){
				forums.delete(0, forums.length());
			}
			String srchuid = request.getParameter("srchuid");
			if(srchuid==null){
				srchuid = "0";
			}
			String searchstring = srchtype + "|" + srchtxt + "|"+srchuid+"|" + srchuname+ "|" + forums + "|" + srchfrom + "|" + before + "|"+ srchfilter + "|" + special;
			String searchindexhql = "select s.searchid from jrun_searchindex as s where s.searchstring = '"+ searchstring + "' and s.expiration >" + timestamp;
			List<Map<String,String>> searchindex = dataBaseService.executeQuery(searchindexhql);
			if (searchindex != null && searchindex.size()>0) {
				try {
					response.sendRedirect("search.jsp?action=search&searchid="+searchindex.get(0).get("searchid")+"&orderby="+orderby+"&ascdesc="+ascdesc);
				} catch (IOException e) {
				}
				return null;
			} else {
				String ip = request.getRemoteAddr();
				if (!searchctrl.equals("0")) {
					int times = timestamp - convertInt(searchctrl);
					String ctrlhql = "select searchid from jrun_searchindex as s where s.useip='"+ ip + "' and uid=" + uid + " and s.dateline >="+ times+" limit 1";
					List<Map<String,String>> index = dataBaseService.executeQuery(ctrlhql);

⌨️ 快捷键说明

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