?<%@page import="com.hanweb.common.util.file.LocalFileUtil"%> <%@page import="com.hanweb.common.util.NumberUtil"%> <%@page import="com.hanweb.common.util.StringUtil"%> <%@page import="com.hanweb.common.util.mvc.Script"%> <%@page contentType="text/html;charset=UTF-8" %> <%@page import="java.io.File"%> <%@page import="com.hanweb.jcms.build.service.makepage.ModalFile"%> <%@page import="com.hanweb.jcms.service.website.Jcms_WebinfomationBLF"%> <%@page import="com.hanweb.jcms.build.service.makeunit.ExtraModuleUnit"%> <%@page import="com.hanweb.jcms.plugins.sitesearch.service.Jcms_Sitesearch_ModalBLF"%> <%@page import="com.hanweb.jcms.util.AccessUtil"%> <%@page import="com.hanweb.jcms.util.HTMLFilter"%> <%@ page import="com.hanweb.jcms.entity.Jcms_ModalobjectunitEntity" %> <%@ include file="config.jsp" %> <%! public boolean canAccess(String strPara){ boolean bl = true; strPara = strPara.toLowerCase(); if (strPara.indexOf("%")>=0 || strPara.indexOf("|")>=0 || strPara.indexOf("+")>=0 || strPara.indexOf("&")>=0 || strPara.indexOf("alert")>=0 || strPara.indexOf("script")>=0 || strPara.indexOf("\"")>=0 || strPara.indexOf("\'")>=0 || strPara.indexOf("<")>=0 || strPara.indexOf("set")>=0 || strPara.indexOf("exec")>=0 || strPara.indexOf("delete")>=0 || strPara.indexOf("update")>=0 || strPara.indexOf("declare")>=0 || strPara.indexOf("cast")>=0){ bl = false; } return bl; } public boolean isTimeIndex(String keyWord, String keyValue){ boolean bl = false; if(("".equals(keyValue) || keyValue.length()==0) && ("0".equals(keyWord) || "1".equals(keyWord) || "0".equals(keyWord) || "7".equals(keyWord) || "30".equals(keyWord) || "90".equals(keyWord) || "365".equals(keyWord))){ bl = true; } return bl; } %> <% request.setCharacterEncoding("UTF-8"); Script script = Script.getInstanceOnly(); if(!AccessUtil.checkAccess(request)){ //阻止跨站点请求伪造 out.print(script.addScript("location.href='../../';").getScript()); return; } LocalFileUtil fileUtil = LocalFileUtil.getInstance(); //得到栏目IDs,可认是当前栏目ID也可以是ID的集合 String strColumnId = StringUtil.getSafeString(request.getParameter("columnid")); int strWebId = NumberUtil.getInt(request.getParameter("webid"), 0); String strClassWord = StringUtil.getSafeString(request.getParameter("classword")); //查询的字段类型 String strKeyWord = StringUtil.getSafeString(request.getParameter("keyword")); //查询的关键字值 String strKeyValue = StringUtil.getSafeString(request.getParameter("keyvalue")); //子栏目下信息类别id号 String loadsubid = StringUtil.getSafeString(request.getParameter("loadsubid")); //模块单元id编号 String modalUnitId = StringUtil.getSafeString(request.getParameter("modalunitid")); //当前页码 int nCurrentPage = NumberUtil.getInt(request.getParameter("currpage"), 1); if( nCurrentPage < 1 ){ nCurrentPage = 1; } //得到网站域名 String strDomain = Jcms_WebinfomationBLF.modifyAndGetWebDomain("1", NumberUtil.getInt(strWebID)); //路径 String strSysPath = application.getRealPath(""); String strPath = strSysPath+"/jcms_files/jcms1/web"+strWebID +"/site/"; String strModulePath = fileUtil.getAbsolutePath("jcms_files/jcms1/web"+strWebID +"/site/module/sitesearch/"); String webtype = xmlFile.getContent("webtype", strModulePath+"config/config.xml"); String strUrl = "/"; if( webtype.trim().equals("2")){ strUrl = "/module/"; } else{ strUrl = request.getContextPath() + "/jcms_files/jcms1/web"+strWebID+"/site/module/"; } Jcms_Sitesearch_ModalBLF search = Jcms_Sitesearch_ModalBLF.getInstance().init(strAppID, NumberUtil.getInt(strWebID)); String strUnitPath = ""; if(modalUnitId == null || modalUnitId.equals("")){ strUnitPath = strModulePath + "config/unit.xml"; }else if(NumberUtil.getInt(modalUnitId) > 0){ strUnitPath = strModulePath + "config/unit_" + modalUnitId + ".xml"; }else{ out.println("模块单元id不正确"); return; } Jcms_ModalobjectunitEntity unitEntity = search.getUnitInfo(strUnitPath); /*得到模板实例的ID*/ ExtraModuleUnit unit = ExtraModuleUnit.getInstance().init("1", NumberUtil.getInt(strWebID)); int nModalObjectID = NumberUtil.getInt(xmlFile.getContent( "sub_moduleid", strUnitPath )); String strModalHtml = ""; String strImgPath = ""; String defaultModalHtml = ""; ModalFile mfile = ModalFile.getInstance().init("1"); if(nModalObjectID > 0){ mfile.setWebID( NumberUtil.getInt(strWebID)); mfile.setSysPath(); java.util.Hashtable htReturn = mfile.getModalHTML(nModalObjectID); if( htReturn != null && htReturn.size()>0 ){ strModalHtml = htReturn.get("modalHTML").toString(); //板板文件 strImgPath = htReturn.get("imagePath").toString(); //图片路径 //copy模板图片 mfile.copyImageFile(strImgPath, strModulePath + "images/", strModalHtml); } }else{ nModalObjectID = unit.getModalObjectID("jcms_all_modal", "i_modalobjectid"); if(nModalObjectID > 0){ mfile.setWebID( NumberUtil.getInt(strWebID)); mfile.setSysPath(); java.util.Hashtable htReturn = mfile.getModalHTML(nModalObjectID); if( htReturn != null && htReturn.size()>0 ){ strModalHtml = htReturn.get("modalHTML").toString(); //板板文件 strImgPath = htReturn.get("imagePath").toString(); //图片路径 //copy模板图片 mfile.copyImageFile(strImgPath, strModulePath + "images/", strModalHtml); } }else{ out.println("请先设制模板"); return; } /* //默认模板读取 defaultModalHtml = strModulePath + "html/sitesearch.html"; strImgPath = strModulePath + "html/"; String strCssPath = strModulePath + "html/"; // 读取模板实例源文件 String strHTML = fileUtil.readFileToString(defaultModalHtml, "UTF-8"); strModalHtml = StringUtil.getString(strHTML); //copy模板图片 mfile.copyImageFile(strImgPath, strModulePath + "images/", strModalHtml); mfile.copyImageFile(strCssPath, strModulePath + "css/", strModalHtml); */ } long time = System.currentTimeMillis(); //得到每页显示的记录数 int nRow = unitEntity.getI_row(); int nCol = unitEntity.getI_col(); int nPageCount = nRow * nCol; //每页显示记录数 /* if((strKeyValue==null||"".equals(strKeyValue)) && !isTimeIndex(strKeyWord, strKeyValue)){ out.println(script.addScript("alert('请输入关键字!');history.go(-1);").getScript()); return; } */ //得到总记录数 int nTotalCount = 0; if("0".equals(strColumnId)){ if(isTimeIndex(strKeyWord, strKeyValue)){ nTotalCount = search.getSiteTotalCountByTime(strColumnId, strClassWord, strKeyWord, loadsubid, strWebId); }else{ nTotalCount = search.getSiteTotalCount(strColumnId,strClassWord, strKeyWord, strKeyValue, loadsubid ,strWebId); } }else{ if(isTimeIndex(strKeyWord, strKeyValue)){ nTotalCount = search.getSiteTotalCountByTime(strColumnId, strClassWord, strKeyWord, loadsubid); }else{ nTotalCount = search.getSiteTotalCount(strColumnId,strClassWord, strKeyWord, strKeyValue, loadsubid); } } //得到总页数 int nTotalPage = nTotalCount / nPageCount; if( nTotalCount % nPageCount != 0 ){ nTotalPage += 1; } if( nCurrentPage > nTotalPage ){ nCurrentPage = nTotalPage; } int nMin = (nCurrentPage-1) * nPageCount; int nMax = nCurrentPage * nPageCount; unit.setUnitInfo( unitEntity ); unit.setModalUnitID( ""+nModalObjectID ); unit.setAbsolutePath( strPath ); unit.setPath( "http://"+strDomain+"/" ); //判断是否要高亮显示 String c_view = search.get_c_view(); boolean viewFlag = false; if( c_view.trim().equals("1") && strKeyValue.trim().length() > 0 ){ viewFlag = true; } String strContent = ""; if(nTotalCount > 0){ if("0".equals(strColumnId)){ if(isTimeIndex(strKeyWord, strKeyValue)){ strContent = unit.getSiteSubjectLinkByTime(strColumnId, strClassWord, strKeyWord,strKeyValue, nMin, nMax, viewFlag, loadsubid, unitEntity, strWebId+""); }else{ strContent = unit.getSiteSubjectLink(strColumnId, strClassWord, strKeyWord, strKeyValue, nMin, nMax, viewFlag, loadsubid, unitEntity, strWebId+""); } }else{ if(isTimeIndex(strKeyWord, strKeyValue)){ strContent = unit.getSiteSubjectLinkByTime(strColumnId, strClassWord, strKeyWord, strKeyValue, nMin, nMax, viewFlag, loadsubid, unitEntity); }else{ strContent = unit.getSiteSubjectLink(strColumnId, strClassWord, strKeyWord, strKeyValue, nMin, nMax, viewFlag, loadsubid, unitEntity); } } } //模块的访问路径 String strModule = strUrl+ "sitesearch/index.jsp?classword=" + strClassWord + "&keyword=" + strKeyWord + "&columnid=" + strColumnId+"&webid="+strWebId+"&modalunitid="+modalUnitId;; //得到检索的表单 String strSearchForm = search.getSearchModuleForm(strModule, strKeyValue); // request,总记录,每页记录数,当前页码.表格样式,页码的hidden值 //页码的hidden值 String strHidden = "\n" + " \n" + "" + ""; String urlPage = "./index.jsp?keyword=" + strKeyWord + "&columnid=" + strColumnId + "&keyvalue=" + strKeyValue+"&webid="+strWebId+"&modalunitid="+modalUnitId; String strPages = search.getPaginationView(urlPage, nTotalCount, nPageCount, nCurrentPage, strHidden); if("".equals(strContent)) { strContent = "
没有发现任何记录
"; } time = System.currentTimeMillis() - time; String cssstyle = ""; int endRecord = nPageCount * nCurrentPage; if(endRecord > nTotalCount){ endRecord = nTotalCount; } int indexStartNum = nPageCount * (nCurrentPage - 1) + 1; if(indexStartNum < 0){ indexStartNum = 0; } StringBuffer searchTip = new StringBuffer(cssstyle) .append("") .append("") .append("") .append("") .append("") .append("
搜索: ").append(strKeyValue).append("共有 ").append(nTotalCount) .append(" 条结果,这是 ").append(indexStartNum).append(" - ").append(endRecord) .append(" 条。
"); strContent = strContent + "
" + searchTip.toString() + "
" + strPages; //内外网路径判断 String strConfPath = strModulePath + "config/config.xml"; String strWebType = xmlFile.getContent("webtype", strConfPath); //获取内外网的标识 strWebType = strWebType == null ? "1" : strWebType; String strAppPath = xmlFile.getContent("web_in_servername", strConfPath); strAppPath = strAppPath == null ? "jcms" : strAppPath; String strReplace = "/"+strAppPath+"/jcms_files/jcms1"+ "/web"+strWebID+"/site/"; if(strWebType.trim().equals("2")) { //外网 strContent = StringUtil.replace(strContent, strReplace , "/"); } if( strModalHtml.trim().length()> 0 ){ strModalHtml = unit.replaceUnitTag("站内检索表单",strModalHtml,strSearchForm); strModalHtml = unit.replaceUnitTag("站内检索",strModalHtml,strContent); out.println(strModalHtml); }else{ strContent = StringUtil.replace(strContent,"\"","\\\""); strContent = StringUtil.removeEnter(strContent); String strAlter = " var content=\""+strContent+"\";"; strAlter += " document.write(content);"; out.println(script.addScript(strAlter).getScript()); } %>