search.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. *
  4. * 搜索页
  5. *
  6. * @version $Id: search.php 1 15:38 2010年7月8日Z tianya $
  7. * @package DedeCMS.Site
  8. * @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
  9. * @license http://help.dedecms.com/usersguide/license.html
  10. * @link http://www.dedecms.com
  11. */
  12. require_once(dirname(__FILE__)."/../include/common.inc.php");
  13. require_once(DEDEINC."/arc.searchview.class.php");
  14. $pagesize = (isset($pagesize) && is_numeric($pagesize)) ? $pagesize : 10;
  15. $typeid = (isset($typeid) && is_numeric($typeid)) ? $typeid : 0;
  16. $channeltype = (isset($channeltype) && is_numeric($channeltype)) ? $channeltype : 0;
  17. $kwtype = (isset($kwtype) && is_numeric($kwtype)) ? $kwtype : 0;
  18. $mid = (isset($mid) && is_numeric($mid)) ? $mid : 0;
  19. $mobile = (isset($mobile) && is_numeric($mobile)) ? $mobile : 0;
  20. if ( $mobile==1 )
  21. {
  22. define('DEDEMOB', 'Y');
  23. }
  24. if(!isset($orderby)) $orderby='';
  25. else $orderby = preg_replace("#[^a-z]#i", '', $orderby);
  26. if(!isset($searchtype)) $searchtype = 'titlekeyword';
  27. else $searchtype = preg_replace("#[^a-z]#i", '', $searchtype);
  28. if(!isset($keyword)){
  29. if(!isset($q)) $q = '';
  30. $keyword=$q;
  31. }
  32. $oldkeyword = $keyword = FilterSearch(stripslashes($keyword));
  33. //查找栏目信息
  34. if(empty($typeid))
  35. {
  36. $typenameCacheFile = DEDEDATA.'/cache/typename.inc';
  37. if(!file_exists($typenameCacheFile) || filemtime($typenameCacheFile) < time()-(3600*24) )
  38. {
  39. $fp = fopen(DEDEDATA.'/cache/typename.inc', 'w');
  40. fwrite($fp, "<"."?php\r\n");
  41. $dsql->SetQuery("Select id,typename,channeltype From `#@__arctype`");
  42. $dsql->Execute();
  43. while($row = $dsql->GetArray())
  44. {
  45. fwrite($fp, "\$typeArr[{$row['id']}] = '{$row['typename']}';\r\n");
  46. }
  47. fwrite($fp, '?'.'>');
  48. fclose($fp);
  49. }
  50. //引入栏目缓存并看关键字是否有相关栏目内容
  51. require_once($typenameCacheFile);
  52. if(isset($typeArr) && is_array($typeArr))
  53. {
  54. foreach($typeArr as $id=>$typename)
  55. {
  56. //$keywordn = str_replace($typename, ' ', $keyword);
  57. $keywordn = $keyword;
  58. if($keyword != $keywordn)
  59. {
  60. $keyword = HtmlReplace($keywordn);
  61. $typeid = intval($id);
  62. break;
  63. }
  64. }
  65. }
  66. }
  67. $keyword = addslashes(cn_substr($keyword,30));
  68. $typeid = intval($typeid);
  69. if($cfg_notallowstr !='' && preg_match("#".$cfg_notallowstr."#i", $keyword))
  70. {
  71. ShowMsg("你的搜索关键字中存在非法内容,被系统禁止!","-1");
  72. exit();
  73. }
  74. if(($keyword=='' || strlen($keyword)<2) && empty($typeid))
  75. {
  76. ShowMsg('关键字不能小于2个字节!','-1');
  77. exit();
  78. }
  79. //检查搜索间隔时间
  80. $lockfile = DEDEDATA.'/time.lock.inc';
  81. $lasttime = file_get_contents($lockfile);
  82. if(!empty($lasttime) && ($lasttime + $cfg_search_time) > time())
  83. {
  84. ShowMsg('管理员设定搜索时间间隔为'.$cfg_search_time.'秒,请稍后再试!','-1');
  85. exit();
  86. }
  87. //开始时间
  88. if(empty($starttime)) $starttime = -1;
  89. else
  90. {
  91. $starttime = (is_numeric($starttime) ? $starttime : -1);
  92. if($starttime>0)
  93. {
  94. $dayst = GetMkTime("2008-1-2 0:0:0") - GetMkTime("2008-1-1 0:0:0");
  95. $starttime = time() - ($starttime * $dayst);
  96. }
  97. }
  98. $t1 = ExecTime();
  99. $sp = new SearchView($typeid,$keyword,$orderby,$channeltype,$searchtype,$starttime,$pagesize,$kwtype,$mid);
  100. $keyword = $oldkeyword;
  101. $sp->Display();
  102. PutFile($lockfile, time());
  103. //echo ExecTime() - $t1;