Browse Source

优化搜索功能,采用IP限定

tags/6.0.0
tianya 3 years ago
parent
commit
949d452274
2 changed files with 37 additions and 31 deletions
  1. +23
    -21
      src/include/arc.searchview.class.php
  2. +14
    -10
      src/plus/search.php

+ 23
- 21
src/include/arc.searchview.class.php View File

@@ -1,4 +1,4 @@
<?php if(!defined('DEDEINC')) exit("Request Error!");
<?php if(!defined('DEDEINC')) exit("Request Error!");
/**
* 搜索视图类
*
@@ -737,7 +737,7 @@ class SearchView
$row["id"] = $row["id"];
if($row['litpic'] == '-' || $row['litpic'] == '')
{
$row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/defaultpic.gif';
$row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
}
if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
{
@@ -823,11 +823,11 @@ class SearchView
$totalpage = ceil($this->TotalResult / $this->PageSize);
if($totalpage<=1 && $this->TotalResult>0)
{
return "共1页/".$this->TotalResult."条记录";
return "<ul class=\"pagination justify-content-center pt-3\"><li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共1页/".$this->TotalResult."条记录</span></li></ul>";
}
if($this->TotalResult == 0)
{
return "共0页/".$this->TotalResult."条记录";
return "<ul class=\"pagination justify-content-center pt-3\"><li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共0页/".$this->TotalResult."条记录</span></li></ul>";
}
$purl = $this->GetCurUrl();
@@ -838,7 +838,7 @@ class SearchView
{
$totalpage = ceil($this->SearchMaxRc/$this->PageSize);
}
$infos = "<td>共找到<b>".$this->TotalResult."</b>条记录/最大显示<b>{$totalpage}</b>页 </td>\r\n";
$infos = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共找到<b>".$this->TotalResult."</b>条记录/最大显示<b>{$totalpage}</b>页</span></li>\r\n";
$geturl = "keyword=".urlencode($oldkeyword)."&searchtype=".$this->SearchType;
$hidenform = "<input type='hidden' name='keyword' value='".rawurldecode($oldkeyword)."'>\r\n";
$geturl .= "&channeltype=".$this->ChannelType."&orderby=".$this->OrderBy;
@@ -855,21 +855,21 @@ class SearchView
//获得上一页和下一页的链接
if($this->PageNo != 1)
{
$prepage.="<td width='50'><a href='".$purl."PageNo=$prepagenum'>上一页</a></td>\r\n";
$indexpage="<td width='30'><a href='".$purl."PageNo=1'>首页</a></td>\r\n";
$prepage.="<li class='page-item'><a class='page-link' href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
$indexpage="<li class='page-item'><a class='page-link' href='".$purl."PageNo=1'>首页</a></li>\r\n";
}
else
{
$indexpage="<td width='30'>首页</td>\r\n";
$indexpage="<li class='page-item disabled'><a class='page-link'>首页</a></li>\r\n";
}
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<td width='50'><a href='".$purl."PageNo=$nextpagenum'>下一页</a></td>\r\n";
$endpage="<td width='30'><a href='".$purl."PageNo=$totalpage'>末页</a></td>\r\n";
$nextpage.="<li class='page-item'><a class='page-link' href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
$endpage="<li class='page-item'><a class='page-link' href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
}
else
{
$endpage="<td width='30'>末页</td>\r\n";
$endpage="<li class='page-item'><a class='page-link'>末页</a></li>\r\n";
}

//获得数字链接
@@ -896,28 +896,30 @@ class SearchView
{
if($j == $this->PageNo)
{
$listdd.= "<td>$j&nbsp;</td>\r\n";
$listdd.= "<li class='page-item active'><a class='page-link'>$j&nbsp;</a></li>\r\n";
}
else
{
$listdd.="<td><a href='".$purl."PageNo=$j'>[".$j."]</a>&nbsp;</td>\r\n";
$listdd.="<li class='page-item'><a class='page-link' href='".$purl."PageNo=$j'>".$j."</a>&nbsp;</li>\r\n";
}
}
$plist = "<table border='0' cellpadding='0' cellspacing='0'>\r\n";
$plist .= "<tr align='center' style='font-size:10pt'>\r\n";
$plist = "";
// $plist = "<table border='0' cellpadding='0' cellspacing='0'>\r\n";
// $plist .= "<tr align='center' style='font-size:10pt'>\r\n";
$plist .= "<form name='pagelist' action='".$this->GetCurUrl()."'>$hidenform";
$plist .= "<ul class=\"pagination justify-content-center pt-3\">";
$plist .= $infos;
$plist .= $indexpage;
$plist .= $prepage;
$plist .= $listdd;
$plist .= $nextpage;
$plist .= $endpage;
if($totalpage>$total_list)
{
$plist.="<td width='38'><input type='text' name='PageNo' style='width:28px;height:14px' value='".$this->PageNo."' /></td>\r\n";
$plist.="<td width='30'><input type='submit' name='plistgo' value='GO' style='width:30px;height:22px;font-size:9pt' /></td>\r\n";
}
$plist .= "</form>\r\n</tr>\r\n</table>\r\n";
// if($totalpage>$total_list)
// {
// $plist.="<td width='38'><input type='text' name='PageNo' style='width:28px;height:14px' value='".$this->PageNo."' /></td>\r\n";
// $plist.="<td width='30'><input type='submit' name='plistgo' value='GO' style='width:30px;height:22px;font-size:9pt' /></td>\r\n";
// }
$plist .= "</ul></form>\r\n";
return $plist;
}



+ 14
- 10
src/plus/search.php View File

@@ -84,12 +84,20 @@ if(($keyword=='' || strlen($keyword)<2) && empty($typeid))
}
//检查搜索间隔时间
$lockfile = DEDEDATA.'/time.lock.inc';
$lasttime = file_get_contents($lockfile);
if(!empty($lasttime) && ($lasttime + $cfg_search_time) > time())
{
ShowMsg('管理员设定搜索时间间隔为'.$cfg_search_time.'秒,请稍后再试!','-1');
exit();
$ip = GetIP();
$now = time();
$row = $dsql->GetOne("SELECT * FROM `#@__search_limits` WHERE ip='{$ip}'");
if (is_array($row)) {
if (($now - $row['searchtime']) < $cfg_search_time) {
ShowMsg('管理员设定搜索时间间隔为'.$cfg_search_time.'秒,请稍后再试!','-1');
exit;
}
$dsql->ExecuteNoneQuery("UPDATE `#@__search_limits` SET `searchtime`='{$now}' WHERE `ip`='{$ip}';");
} else {
$dsql->ExecuteNoneQuery("INSERT INTO `#@__search_limits` (`ip`, `searchtime`) VALUES ('{$ip}', '{$now}');");
}
//开始时间
@@ -109,8 +117,4 @@ $t1 = ExecTime();
$sp = new SearchView($typeid,$keyword,$orderby,$channeltype,$searchtype,$starttime,$pagesize,$kwtype,$mid);
$keyword = $oldkeyword;
$sp->Display();
PutFile($lockfile, time());
//echo ExecTime() - $t1;

Loading…
Cancel
Save