EXCMS 搜索文件
来自站长百科
导航:返回上一页
EXCMS的模块搜索文件为:search.php,用于站内搜索包括按关键字搜索和高级搜索。
代码[ ]
001 <?
002
003 /**
004 * Project: EXCMS: the PHP content management system.
005 * File: search.php
006 *
007 * A product of SINOICAN Inc.
008 *
009 * EXCMS is a ten million data-level,high speed,human-based content management system.
010 *
011 * EX is Excellence & Express & Exceed & Expert.
012 *
013 * For questions, help, comments, discussion, please join the
014 * EXCMS mailing list. Send a blank e-mail to
015 * excms@sinoican.com
016 * or join the EXCMS forum
017 * www.excms.cn/forum
018 *
019 * @link http://www.excms.cn/
020 * @copyright Copyright (c) 2007-2009 SINOICAN Inc.
021 * @license http://www.excms.cn/licenses/LICENSE-1.0
022 * @category EXCMS
023 * @author zhangxuelin@sinoican.com
024 * @version $Rev: 146 $
025 */
026
027 /* $Id: search.php 146 2009-11-10 07:58:36Z zhangxuelin $ */
028
029 /**
030 * 站内搜索
031 */
032
033 session_start();
034
035 //加载系统配置文件,移动本程序时,请修改配置文件路径
036 require_once ('configuration/inc/common.inc.php');
037
038 //获取关键字
039 $_PAGE['search']['keywords'] = trim(str_replace('\\','',trim($_GET[$EXCMS['search']['querystring_keywords']])));
040 $_PAGE['search']['category'] = $_GET[$EXCMS['search']['querystring_category']];
041 $_PAGE['search']['advanced'] = $_GET[$EXCMS['search']['querystring_advanced']];
042
043 $allkeywords = $_GET[$EXCMS['search']['querystring_allkeywords']];
044 $completekeywords = $_GET[$EXCMS['search']['querystring_completekeywords']];
045 $arbitrarykeywords = $_GET[$EXCMS['search']['querystring_anykeywords']];
046 $notin = $_GET[$EXCMS['search']['querystring_notin']];
047
048 //加载搜索类,创建搜索对象
049 excms_import('EXCMS.search.Search');
050 $_PAGE['search']['class'] = new Search();
051
052 //设置搜索分类
053 $_PAGE['search']['class']->setCategory($_PAGE['search']['category']);
054
055 //获取搜索分类
056 $_PAGE['search']['category'] = $_PAGE['search']['class']->getCategory();
057
058 //检查搜索关键字是否为空
059 if($_PAGE['search']['keywords'] != '' || $allkeywords!='' || $completekeywords!='' || $arbitrarykeywords!='' || $notin!=''){
060 //获取参数
061 $pagesize = $_GET[$EXCMS['search']['querystring_pagesize']];
062 $pageon = excms_func_page_decode($_GET[$EXCMS['search']['querystring_pageon']]);
063 $_PAGE['search']['date'] = $_GET[$EXCMS['search']['querystring_date']];
064 $_PAGE['search']['keywordslocation'] = $_GET[$EXCMS['search']['querystring_keywordslocation']];
065 $orderby = $_GET[$EXCMS['search']['querystring_orderby']];
066 //设置是否是高级搜索
067 $_PAGE['search']['class']->setAdvanced($_PAGE['search']['advanced']);
068 //设置搜索关键字
069 $_PAGE['search']['class']->setKeywords($_PAGE['search']['keywords']);
070
071 /**
072 * 高级搜索相关参数
073 */
074 //包含以下全部的关键词
075 $_PAGE['search']['class']->setAllKeywords($allkeywords);
076 //包含以下的完整关键词
077 $_PAGE['search']['class']->setCompleteKeywords($completekeywords);
078 //包含以下任意一个关键词
079 $_PAGE['search']['class']->setArbitraryKeywords($arbitrarykeywords);
080 //不包括以下关键词
081 $_PAGE['search']['class']->setNotIn($notin);
082 //限定要搜索的网页的时间是
083 $_PAGE['search']['class']->setDate($_PAGE['search']['date']);
084 //查询关键词位于
085 $_PAGE['search']['class']->setKeywordsLocation($_PAGE['search']['keywordslocation']);
086 //设置排序
087 $_PAGE['search']['class']->setOrderby($orderby);
088 //选择搜索结果显示的条数
089 $_PAGE['search']['class']->setPagesize($pagesize);
090 //设置当前页
091 $_PAGE['search']['class']->setPageon($pageon);
092
093 if($_PAGE['search']['advanced']){
094 //获取关键字
095 $_PAGE['search']['keywords'] = $_PAGE['search']['class']->getWords();
096 }
097
098 //按搜索分类设定模板
099 $tpl = $_PAGE['search']['category']['template'];
100 $tpl = $tpl ? $tpl : 'search.html';
101 }else{
102 //空搜索模板
103 $tpl = $_PAGE['search']['advanced'] ? 'search_advanced.html' : 'search_blank.html';
104 }
105
106 //输出模板
107 excms_func_templateDisplay($tpl);
108
109 ?>
代码修改[ ]
如果站点不需要高级搜索,可以去除高级搜索的相关参数,以及部分代码,更改后的结果如下
01 <?
02
03 /**
04 * Project: EXCMS: the PHP content management system.
05 * File: search.php
06 *
07 * A product of SINOICAN Inc.
08 *
09 * EXCMS is a ten million data-level,high speed,human-based content management system.
10 *
11 * EX is Excellence & Express & Exceed & Expert.
12 *
13 * For questions, help, comments, discussion, please join the
14 * EXCMS mailing list. Send a blank e-mail to
15 * excms@sinoican.com
16 * or join the EXCMS forum
17 * www.excms.cn/forum
18 *
19 * @link http://www.excms.cn/
20 * @copyright Copyright (c) 2007-2009 SINOICAN Inc.
21 * @license http://www.excms.cn/licenses/LICENSE-1.0
22 * @category EXCMS
23 * @author zhangxuelin@sinoican.com
24 * @version $Rev: 146 $
25 */
26
27 /* $Id: search.php 146 2009-11-10 07:58:36Z zhangxuelin $ */
28
29 /**
30 * 站内搜索
31 */
32
33 session_start();
34
35 //加载系统配置文件,移动本程序时,请修改配置文件路径
36 require_once ('configuration/inc/common.inc.php');
37
38 //获取关键字
39 $_PAGE['search']['keywords'] = trim(str_replace('\\','',trim($_GET[$EXCMS['search']['querystring_keywords']])));
40 $_PAGE['search']['category'] = $_GET[$EXCMS['search']['querystring_category']];
41
42 //加载搜索类,创建搜索对象
43 excms_import('EXCMS.search.Search');
44 $_PAGE['search']['class'] = new Search();
45
46 //设置搜索分类
47 $_PAGE['search']['class']->setCategory($_PAGE['search']['category']);
48
49 //获取搜索分类
50 $_PAGE['search']['category'] = $_PAGE['search']['class']->getCategory();
51
52 //检查搜索关键字是否为空
53 if($_PAGE['search']['keywords'] != ''){
54 //获取参数
55 $pagesize = $_GET[$EXCMS['search']['querystring_pagesize']];
56 $pageon = excms_func_page_decode($_GET[$EXCMS['search']['querystring_pageon']]);
57
58 //设置搜索关键字
59 $_PAGE['search']['class']->setKeywords($_PAGE['search']['keywords']);
60 //选择搜索结果显示的条数
61 $_PAGE['search']['class']->setPagesize($pagesize);
62 //设置当前页
63 $_PAGE['search']['class']->setPageon($pageon);
64 //按搜索分类设定模板
65 $tpl = $_PAGE['search']['category']['template'];
66 $tpl = $tpl ? $tpl : 'search.html';
67 }else{
68 //空搜索模板
69 $tpl = 'search_blank.html';
70 }
71
72 //输出模板
73 excms_func_templateDisplay($tpl);
74
75 ?>
页面参数$_PAGE可以自由修改,根据模板的需要来增加和修改页面参数。模板中可自由调用页面的参数,例如:{$_PAGE.title}显示页面标题。