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

📄 pmsaction.java

📁 论坛软件系统亦称电子公告板(BBS)系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
				}
			}

		} else {
			request.setAttribute("errorInfo", ss);
		}
		return mapping.findForward("showMessage");
	}

	@SuppressWarnings("unchecked")
	public ActionForward searchPms(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		setExtcredits(request);
		String srchtxt = request.getParameter("srchtxt");  
		String srchuname = request.getParameter("srchuname");  
		HttpSession session = request.getSession();
		int uid = (Integer) session.getAttribute("jsprun_uid");
		int cachelife_text = 3600;
		int timestamp = (Integer)(request.getAttribute("timestamp"));
		String searchid = request.getParameter("searchid");
		String orderby = request.getParameter("orderby");
		String ascdesc = request.getParameter("ascdesc");
		orderby = orderby.equals("msgfrom") ? "msgfrom" : "dateline";
		ascdesc = ascdesc.equals("asc") ? "asc" : "desc";
		if (searchid != null && !searchid.equals("")) {
			String srchfolder = request.getParameter("srchfolder");  
			Pmsearchindex searchindex = pmsServer.findPmsearchindexById(convertInt(searchid));
			String pmids = searchindex.getPmids();
			if (pmids.equals("0")) {
				request.setAttribute("pmslist", null);
			} else {
				Members member=(Members)session.getAttribute("user");
				Map<String,String> settings=(Map<String,String>)request.getAttribute("settings");
				int pmnum=Integer.valueOf(dataBaseService.executeQuery("select count(*) count from jrun_pms as p where p.pmid in ( " + pmids + " )").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(pmnum, tpp, page);
				page=multiInfo.get("curpage");
				int start_limit=multiInfo.get("start_limit");
				Map<String,Object> multi=Common.multi(pmnum, tpp, page, "pm.jsp?action=search&searchid=" + searchid + "&orderby=" + orderby + "&ascdesc=" + ascdesc + "&srchfolder=" + srchfolder, 0, 10, true, false, null, false);
				request.setAttribute("multi", multi);
				request.setAttribute("searchid", searchid);
				String hql = "select p.*,m.username from jrun_pms as p left join jrun_members as m on p.msgtoid=m.uid  where p.pmid in ( " + pmids + " ) order by " + orderby + " " + ascdesc+" limit "+start_limit+","+tpp;
				List<Map<String,String>>pmslist = dataBaseService.executeQuery(hql);
				if (pmslist != null && pmslist.size()>0) {
					request.setAttribute("pmslist", pmslist);
				} else {
					request.setAttribute("pmslist", null);
				}
			}
			return mapping.findForward("todisplay");
		} else {
			String srchtype = request.getParameter("srchtype");  
			Map<String,String> settings = (Map<String,String>)request.getAttribute("settings");
			Map<String,String> usergroups=(Map<String,String>)request.getAttribute("usergroups");
			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";
			}
			srchtxt = srchtxt == null ? "" : srchtxt.replace("'", "''");
			srchuname = srchuname == null ? "" : srchuname.replace("'", "''");
			if (srchtxt.equals("")&&srchuname.equals("")) {
				request.setAttribute("errorInfo", "您没有指定要搜索的关键字或用户名,请返回重新填写。");
				return mapping.findForward("showMessage");
			}
			String searchctrl = settings.get("searchctrl");  
			String maxspm = settings.get("maxspm");  
			String maxsearchresult = settings.get("maxsearchresults");  
			String srchfolder = request.getParameter("srchfolder");  
			String srchread = request.getParameter("srchread");  
			String srchunread = request.getParameter("srchunread");  
			String srchfrom = request.getParameter("srchfrom");  
			String before = request.getParameter("before");  
			srchread = srchread == null ? "0" : "1";
			srchunread = srchunread == null ? "0" : "1";
			String searchstring = uid + "|" + srchfolder + "|" + srchtype + "|"+ srchtxt + "|" + srchuname + "|" + srchread + "|"+ srchunread + "|" + srchfrom + "|" + before;
			String pmsindexhql = "from Pmsearchindex as p where p.searchstring = '"+ searchstring + "' and p.expiration >" + timestamp;
			Pmsearchindex pmssearchindex = pmsServer.findPmssearchindexByHql(pmsindexhql);
			if (pmssearchindex != null) {
				try {
					response.sendRedirect("pm.jsp?action=search&searchid="+ pmssearchindex.getSearchid() + "&orderby=" + orderby + "&ascdesc="+ ascdesc+"&srchfolder=" + srchfolder);
				} catch (IOException e) {
				}
				return null;
			} else {
				if (!searchctrl.equals("0")) {
					int times = timestamp - convertInt(searchctrl);
					String ctrlhql = "select searchid from jrun_pmsearchindex as p where p.uid=" + uid + " and p.dateline >=" + times+" limit 1";
					List<Map<String,String>> index = dataBaseService.executeQuery(ctrlhql);
					if (index != null && index.size()>0) {
						String message = "对不起,您在 " + searchctrl+ " 秒内只能进行一次搜索,请返回。";
						request.setAttribute("errorInfo", message);
						return mapping.findForward("showMessage");
					}
					index = null;
				}
				if (!maxspm.equals("0")) {
					int times = timestamp - 60;
					String maxhql = "select count(*) from Pmsearchindex as p where p.uid="+ uid + " and p.dateline>=" + times;
					int count = pmsServer.findPmsCountByHql(maxhql);
					if (count >= convertInt(maxspm)) {
						String message = "对不起,管理员设置了每分钟系统最多响应搜索请求 " + maxspm + " 次,请返回并稍后再试。";
						request.setAttribute("errorInfo", message);
						return mapping.findForward("showMessage");
					}
				}
				String pmshql = "select pmid from jrun_pms as p where p.delstatus <>2 and ";
				if (!srchtxt.equals("")) { 
					srchtxt = srchtxt.replaceAll("\\*", "%");
					srchtxt = srchtxt.toLowerCase();
					if (Common.matches(srchtxt,"[and|\\+|&|\\s+]") && !Common.matches(srchtxt,"[or|\\|]")) {
						srchtxt = srchtxt.replaceAll("( and |&| )", "+");
						String[] keyword = srchtxt.split("\\+");
						if (srchtype.equals("title")) {
							for (int i = 0; i < keyword.length; i++) {
								pmshql += "p.subject like '%" + keyword[i].trim()
										+ "%' and ";
							}
						} else {
							for (int i = 0; i < keyword.length; i++) {
								pmshql += "p.message like '%" + keyword[i].trim()
										+ "'% and ";
							}
						}
					} else {
						srchtxt = srchtxt.replaceAll("( or |\\|)", "+");
						String[] keyword = srchtxt.split("\\+");
						if (srchtype.equals("title")) {
							pmshql = pmshql + "(";
							for (int i = 0; i < keyword.length; i++) {
								pmshql += "p.subject like '%" + keyword[i].trim()
										+ "%' or ";
							}
						} else {
							pmshql = pmshql + "(";
							for (int i = 0; i < keyword.length; i++) {
								pmshql += "p.message like '%" + keyword[i].trim()
										+ "%' or ";
							}
						}
					}
				}
				int lastor = pmshql.lastIndexOf("or");
				if (lastor > 0) {
					pmshql = pmshql.substring(0, lastor);
					pmshql = pmshql + ") and ";
				}
				if (!srchuname.equals("")) {  
					String uids = "-1";
					srchuname = srchuname.replaceAll("\\*", "%");
					String memhql = "select uid from jrun_members as m where m.username like '"+ srchuname.trim() + "' limit 50";
					List<Map<String,String>> memberlist = dataBaseService.executeQuery(memhql);
					if (memberlist != null && memberlist.size() > 0) {
						for (Map<String,String> member : memberlist) {
							uids += ","+member.get("uid");
						}
					}
						if (srchfolder.equals("inbox")) {
							pmshql += "p.msgtoid = " + uid
									+ " AND  p.msgtoid in ( " + uids+ " ) and folder='inbox' and ";
						} else if (srchfolder.equals("outbox")) {
							pmshql += "p.msgfromid=" + uid
									+ " AND p.msgtoid in ( " +uids+ " ) and folder='outbox' and ";
						} else {
							pmshql += "p.msgfromid=" + uid
									+ " AND folder='inbox' and p.msgfromid in ( " +uids+ " ) and ";
						}
				} else {
					if (srchfolder.equals("inbox")) {
						pmshql += "p.msgtoid = " + uid
								+ " AND folder='inbox' and ";
					} else if (srchfolder.equals("outbox")) {
						pmshql += "p.msgfromid=" + uid
								+ " AND folder='outbox' and ";
					} else {
						pmshql += "p.msgfromid=" + uid
								+ " AND folder='inbox' and ";
					}
				}
				if (srchread.equals("0") || srchunread.equals("0")) {  
					if (srchread.equals("1")) {
						pmshql += "p.new=0 and ";
					}
					if (srchunread.equals("1")) {
						pmshql += "p.new >0 and ";
					}
				}
				if (!srchfrom.equals("0")) {
					int datetime = timestamp- Integer.valueOf(srchfrom);
					if (before.equals("0")) {
						pmshql += "p.dateline >= " + datetime + " and ";
					} else {
						pmshql += "p.dateline <" + datetime + " and ";
					}
				}
				int lastand = pmshql.lastIndexOf("and");
				if (lastand > 0) {
					pmshql = pmshql.substring(0, lastand);
				}
				pmshql += "order by " + orderby + " " + ascdesc+" limit 0,"+maxsearchresult;
				List<Map<String,String>> pmslist = dataBaseService.executeQuery(pmshql);
				String pmsids = "0";
				int pmscount = 0;
				if (pmslist != null && pmslist.size() > 0) {
					pmscount = pmslist.size();
					for (Map<String,String> pms : pmslist) {
						pmsids += ","+pms.get("pmid");
					}
				}
				Pmsearchindex pmsserch = new Pmsearchindex();
				pmsserch.setDateline(timestamp);
				int exprtation = timestamp + cachelife_text;
				pmsserch.setExpiration(exprtation);
				pmsserch.setKeywords(srchtxt + "+" + srchuname);
				pmsserch.setPmids(pmsids);
				pmsserch.setPms(Short.valueOf(pmscount + ""));
				pmsserch.setUid(uid);
				pmsserch.setSearchstring(searchstring);
				int searchids = pmsServer.insertPmsearchindex(pmsserch);
				try {
					response.sendRedirect("pm.jsp?action=search&searchid="+ searchids + "&orderby=" + orderby + "&ascdesc="+ ascdesc+"&srchfolder=" + srchfolder);
				} catch (IOException e) {
				}
				return null;
			}
		}
	}

	public ActionForward archive(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
		int uid = (Integer) session.getAttribute("jsprun_uid");
		Jspruncode jspcode = (Jspruncode)BeanFactory.getBean("jspruncode");
		int timestamp = (Integer)(request.getAttribute("timestamp"));
		int timeoffset=(int)((Float)session.getAttribute("timeoffset")*3600);
		String pmid = request.getParameter("pmid");
		if (pmid != null) {
			List<Map<String,String>> pmslist = dataBaseService.executeQuery("select p.*,m.username from jrun_pms as p left join jrun_members as m on p.msgtoid=m.uid where p.pmid="+pmid);
			Map<String,String> pms = pmslist.get(0);
			String message = pms.get("message");
			message = jspcode.parsecode(message,false);
			message = relacesmile(message);
			pms.put("message",message);
			pmslist.clear();
			pmslist.add(pms);
			request.setAttribute("pmslist", pmslist);
		} else {
			String folder = request.getParameter("folder");
			String amount = request.getParameter("amount");
			String delete = request.getParameter("delete");
			String days = request.getParameter("days");
			String newerolder = request.getParameter("newerolder");
			String pmshql = "select p.*,m.username from jrun_pms as p left join jrun_members as m on p.msgtoid=m.uid where p.delstatus<>2 and ";
			if ("inbox".equals(folder)) {
				pmshql += "p.msgtoid = " + uid + " AND folder='inbox' and ";
			} else if ("outbox".equals(folder)) {
				pmshql += "p.msgfromid=" + uid + " AND folder='outbox' and ";
			}
			if (days!=null&&!days.equals("0")) {
				int datetime = timestamp - Integer.valueOf(days);
				if (newerolder.equals("0")) {
					pmshql += "p.dateline >= " + datetime + " and ";
				} else {
					pmshql += "p.dateline <" + datetime + " and ";
				}
			}
			int lastand = pmshql.lastIndexOf("and");
			if (lastand > 0) {
				pmshql = pmshql.substring(0, lastand);

⌨️ 快捷键说明

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