dede地区联动搜索 彻底解决办法

时间:2016-12-12

本例以文章模型为列子
0 添加 联动类型 地区

plus/search.php
<?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;
?>

templets/default/search.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{dede:global.cfg_webname/}_搜索结果</title>
<link href="{dede:global.cfg_templeturl/}/style/search.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>

<div class="header">
    <div class="toplogo">
        <h1><a href="{dede:global.cfg_cmsurl/}/">{dede:global.cfg_webname/}</a></h1>
    </div>
    <div class="searchform">
      <form action="{dede:field name=’phpurl’/}/search.php" name="formsearch">
        <div class="s1">搜索</div>
        <div class="s2">
           <input type="hidden" name="kwtype" value="0" />
           <input name="keyword" type="text" class="search-keyword" id="search-keyword" value="{dede:global.keyword/}" />

<input type=’hidden’ id=’hidden_nativeplace’ name=’nativeplace’ value=’0′ />
<span id=’span_nativeplace’></span>
<span id=’span_nativeplace_son’></span>
<script language="javascript" type="text/javascript" src="{dede:global.cfg_indexurl/}/images/enums.js"></script>
<script language=’javascript’ type=’text/javascript’ src=’{dede:global.cfg_indexurl/}/data/enums/nativeplace.js’></script>
<script language="javascript" type="text/javascript">MakeTopSelect("nativeplace", 0);</script>
<input type=’hidden’ name=’dede_addonfields’ value="nativeplace,stepselect">

           <select name="searchtype" class="search-option" id="search-option">
               <option value="titlekeyword" selected=’1′>智能模糊搜索</option>
               <option value="title">仅搜索标题</option>
           </select>
          <button type="submit" class="search-submit">搜索</button>        
        </div>
        </form>
        <div class="s3">
            <a href="heightsearch.php">高级搜索</a>
            <a href="{dede:global.cfg_cmsurl/}/">返回首页</a>
        </div>
    </div>
</div>

<div class="msgbar">
    <p>
        搜索 <strong class="fc_03c">{dede:global name=’keyword’/}</strong> 的结果
    </p>
</div>

<div class="resultlist">
    
{dede:list perpage=’20′}

    <div class="item">
        <h3><a href="[field:arcurl/]" target="_blank">[field:title/]</a></h3>
        <p class="intro">[field:description/]…</p>
        <p class="info">
            <small> 分类:</small><span> <a href="[field:typeurl/]" target="_blank">[field:typename/]</a></span>
            <small>点击:</small><span> [field:click/]</span>
            <small>日期:</small><span> [field:stime/]</span>
        </p>
        <p><span><a href="[field:arcurl/]" target="_blank">[field:arcurl/]</a></span></p>
    </div>
{/dede:list}

</div>

<div class="dede_pages">
    <ul class="pagelist">
        {dede:pagelist listsize=’5′/}  
    </ul>
</div><!– /pages –>

<div class="othersearch">
    <h2>相关搜索:</h2>
    <ul>
        {dede:likewords num=’8′/}
    </ul>
</div>

<div class="footer">
    <p class="link">
        网站版权信息及免责声明
    </p>
    <!–
        为了支持织梦团队的发展,请您保留织梦内容管理系统的链接信息.
        我们对支持织梦团队发展的朋友表示真心的感谢!织梦因您更精彩!
    –>
    <p class="powered">
        Powered by <a href="http://www.dedecms.com" title="织梦内容管理系统(DedeCms)–国内最专业的PHP网站管理系统,轻松建站的首选利器。" target="_blank"><strong>Dede<span>CMS</span></strong></a> ? 2004-2008 DesDev Inc.
    </p><!– /powered –>
    
</div>

</body>
</html> 

上一条:dede开启二级域名后图片无法显示的解决方法. 下一条:为DedeCms加上腾讯微博一键转播功能

相关文章

最新文章