本例以文章模型为列子
0 添加 联动类型 地区
1 plus/search.PHP
require_once(dirname(__file__)."/../include/common.inc.PHP");
require_once(DEDEINC."/arc.searchvIEw.class.PHP");
$pagesize = (isset($pagesize) && is_numeric($pagesize)) ? $pagesize : 10;
$typeID = (isset($typeID) && is_numeric($typeID)) ? $typeID : 0;
$nativeplace = (isset($nativeplace) && is_numeric($nativeplace)) ? $nativeplace : 0;
$channeltype = (isset($channeltype) && is_numeric($channeltype)) ? $channeltype : 0;
$kwtype = (isset($kwtype) && is_numeric($kwtype)) ? $kwtype : 1;
$mID = (isset($mID) && is_numeric($mID)) ? $mID : 0;
if(!isset($orderby)) $orderby=”;
else $orderby = eregi_replace(‘[^a-z]‘,”,$orderby);
if(!isset($searchtype)) $searchtype = ‘Titlekeyword’;
else $searchtype = eregi_replace(‘[^a-z]‘,$searchtype);
if(!isset($keyword)) $keyword = ”;
$oldkeyword = $keyword;
$keyword = FilterSearch(stripslashes($keyword));
//查找栏目信息
if(empty($typeID))
{
$typenameCachefile = DEDEROOT.’/data/cache/typename.inc’;
if(!file_exists($typenameCachefile) || filemtime($typenameCachefile) < time()-(3600*24) )
{
$fp = fopen(DEDEROOT.’/data/cache/typename.inc’,‘w’);
fwrite($fp,"<"."?PHP\r\n");
$dsql->Setquery("Select ID,typename From `ym_arctype`");
$dsql->Execute();
while($row = $dsql->GetArray())
{
fwrite($fp,"\$typeArr[{$row['ID']}] = ‘{$row['typename']}’;\r\n");
}
fwrite($fp,‘?’.'>’);
fclose($fp);
}
//引入栏目缓存并看关键字是否有相关栏目内容
require_once($typenameCachefile);
if(isset($typeArr) && is_array($typeArr))
{
foreach($typeArr as $ID=>$typename)
{
$keywordn = str_replace($typename,‘ ‘,$keyword);
if($keyword != $keywordn)
{
$keyword = $keywordn;
$typeID = $ID;
break;
}
}
}
}
$keyword = addslashes(cn_substr($keyword,30));
if($cfg_notallowstr !=” && eregi($cfg_notallowstr,$keyword))
{
ShowMsg("你的搜索关键字中存在非法内容,被系统禁止!","-1");
exit();
}
//if(($keyword==” || strlen($keyword)<0) && empty($typeID))
//{
// ShowMsg(‘关键字不能小于2个字节!’,'-1′);
// exit();
//}
//检查搜索间隔时间
$lockfile = DEDEROOT.’/data/time.lock.inc’;
if(!file_exists($lockfile)) {
$fp = fopen($lockfile,’w');
flock($fp,1);
fwrite($fp,time());
fclose($fp);
}
//开始时间
if(empty($starttime)) $starttime = -1;
else
{
$starttime = (is_numeric($starttime) ? $starttime : -1);
if($starttime>0)
{
$dayst = GetMkTime("2008-1-2 0:0:0") – GetMkTime("2008-1-1 0:0:0");
$starttime = time() – ($starttime * $dayst);
}
}
$t1 = ExecTime();
$sp = new SearchVIEw($typeID,$keyword,$orderby,$channeltype,$searchtype,$starttime,$pagesize,$kwtype,$mID,$nativeplace);
$keyword = $oldkeyword;
$sp->display();
//echo ExecTime() – $t1;
?>
2 templets/default/search.htm
评论列表(0条)