<?php 
require_once('fun/funsql.php'); 
require_once('fun/funlogic.php');

$fp=openfile("cache/config.txt");
$fps=explode(",,",$fp);

$keys=@urldecode(funstr($_GET["keys"]));
$p=@floatval(funstr($_GET["p"]));
if($p==''){$p=0;}elseif($p<0){$p=0;}
$times=date("Y-m-d H:i:s");
?>
<!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><?php echo $keys; ?> <?php echo $fps[0]; ?> - 搜索页 </title>

<style>
/*---------- base ---------*/
*{padding:0px;margin:0px;}
html{background:#FFF;}
body{width:98%;margin:0px auto;font:12px Verdana,Arial,Tahoma;}
img{border:none;}
a{color:#3366CC;text-decoration:none;}
a:hover{color:#F33;text-decoration:underline;}
ul{list-style:none;}
input,select,button{font-size:12px;vertical-align:middle;}
.fc_03c{color:#03C;}
.fc_f30{color:#F30;}
/*---------- frame ---------*/
.header{width:100%;margin:0px auto;padding-top:10px;clear:both;overflow:hidden;}
.header .toplogo{width:300px;height:60px;float:left;}
.header .toplogo h1{width:200px;height:56px;}

.header .searchform{float:left;padding-top:12px;}
.header .searchform .s1{float:left;height:29px;line-height:25px;font-size:14px;color:#333333;font-weight:bold;margin-right:6px;}
.header .searchform .s2{float:left;}
.header .searchform .s2 .sf-keyword{padding:3px 5px;height:14px;line-height:17px;overflow:hidden;color:#777;}
.header .searchform .s2 .sf-option{font-size:14px;color:#444;}
.header .searchform .s2 .sf-submit{width:62px;height:23px;font-size:14px;line-height:18px;color:#333;letter-spacing:5px;margin-left:5px;margin-top:-2px;}
.header .searchform .s3{height:29px;float:left;margin-left:20px;line-height:29px;}
.header .searchform .s3 a{margin-right:10px;font-size:14px;}

.msgbar{height:27px;line-height:27px;border-top:1px solid #E4F0DF;border-bottom:1px solid #E4F0DF;font-size:14px;color:#666;}
.msgbar p{padding-left:22px;background:#F3FAF1;border-top:1px solid #FFF;border-bottom:1px solid #FFF;}

.resultlist{padding:2px 20px;}
.resultlist h2{display:none;}
.item h3 .title{font-size:14px;font-weight:normal;line-height:25px;text-decoration:underline;}
.item h3 .title:hover{text-decoration:none;}
.item{margin-top:16px;}
.item .intro{font-size:14px;line-height:19px;padding-left:2px;color:#777;}
.item .info{font-size:12px;line-height:26px;color:#080;}
.item .info small{font-size:12px;}
.item .info span{margin-right:10px;}
.item .info a{color:#444;}
.advancedsearch{width:500px;float:left;padding:30px 40px;}
.advancedsearch input,.advancedsearch select,.advancedsearch button{font-size:14px;margin-left:5px;}
.advancedsearch input{font-size:12px;padding:3px;}
.advancedsearch .f1{width:500px;clear:both;overflow:hidden;}
.advancedsearch .f1 small,.advancedsearch .f2 small{font-size:14px;width:80px;height:40px;float:left;text-align:right;line-height:25px;color:#666;}
.advancedsearch .f1 span,.advancedsearch .f2 span{height:40px;float:left;font-size:14px;}
.advancedsearch .f2{width:200px;float:left;}
.othersearch{height:31px;overflow:hidden;clear:both;line-height:31px;padding-left:16px;margin-top:16px;}
.othersearch h2{float:left;font-size:14px;}
.othersearch ul{float:left;}
.othersearch ul li{float:left;margin-left:10px;font-size:14px;line-height:33px;}
.footer{color:#999;text-align:right;border-top:1px solid #E5EFD6;margin-top:16px;padding:8px 10px;clear:both;overflow:hidden;}
.footer .link{text-align:center;padding:5px 0px;float:left;}
.footer .link a{margin:0px 5px;color:#666666;}
.footer .powered{font-size:10px;line-height:25px;}
.footer .powered strong{color:#690;}
.footer .powered strong span{color:#F93;}
.footer .powered a:hover{text-decoration:none;}
.dede_pages{height:33px;clear:both;overflow:hidden;background:#FAFAFA;margin-top:16px;}
.dede_pages ul{float:left;padding:6px 0px 0px 16px;}
.dede_pages ul li{float:left;font-family:Tahoma;line-height:17px;margin-right:6px;}
.dede_pages ul li a{float:left;padding:2px 4px 2px;color:#666;}
.dede_pages ul li a:hover{color:#690;text-decoration:none;padding:2px 4px 1px;background:#EEE;}
.dede_pages ul li.thisclass a,.pagebox ul li.thisclass a:hover{color:#F63;padding:2px 4px 1px;border-bottom:1px solid #F63;font-weight:bold;}
.dede_pages .pageinfo{float:right;line-height:21px;padding:7px 10px 3px 16px;color:#999;}
.dede_pages .pageinfo strong{color:#666;font-weight:normal;margin:0px 2px;}
</style>
</head>
<body>
<div class="header">
	<div class="toplogo">
		<h1><a href="./"><img src="img/logo.gif" ></a></h1>
	</div>
	<div class="searchform">
      <form action="so.php" name="form" method="get">
		<div class="s1">搜索</div>
		<div class="s2">
           <input name="keys" type="text" style="width:300px; height:20px; font-size:16px" value="<?php echo $keys; ?>" maxlength="100"/>
          <button type="submit" class="search-submit">&nbsp;&nbsp; 搜索&nbsp;&nbsp; </button>        
        </div>
        </form>
	</div>
</div>
<div class="msgbar">
	<p>
		搜索 <strong class="fc_03c"><?php echo $keys; ?></strong> 的结果
	</p>
</div>
<div class="resultlist">
  <?php 
  $list='';
  $num=10;//每页显示条数
  if ($keys==''){
    
    $sonum=rows(query("select id from ".$dbz."news order by id desc limit 0,100"));
	$nums=ceil($sonum/$num);
	$sql=query("select * from ".$dbz."news order by id desc limit ".($p*$num).",$num");
	while($row=fetch($sql)){
	  if($fps[5]==1){$fileurl=$fps[1]."/news/".$row["id"].".htm";}else{$fileurl=$fps[1]."/news.php?id=".$row["id"];}
	  $list.="<div class=\"item\"><h3><a href=\"$fileurl\">".$row["titles"]."</a></h3><p class=\"info\">";
	  $sqls=query("select * from ".$dbz."class where id=".$row["cid"]);
	  if($rows=fetch($sqls)){
	    if($fps[5]==1){$classurl=$fps[1]."/newslist/".$rows["id"].".htm";}else{$classurl=$fps[1]."/class.php?id=".$rows["id"];}
	    $list.="<small>所属分类:</small><span><a href=\"$classurl\">".$rows["names"]."</a></span>";
	  }
	  $list.="<small>作者:</small><span>".$row["users"]."</span>";
	  $list.="<small>来源:</small><span>".$row["sources"]."</span>";
	  $list.="<small>人气:</small><span>".$row["counts"]."</span></p>";
	  $list.="<p><span><a href=\"$fileurl\">$fileurl</a></span></p>";
	}
  }
  else{
    $sql1=query("select * from ".$dbz."so where keywords='".$keys."'");
	if($row1=fetch($sql1)){
	  $sql1=query("update ".$dbz."so set counts=".($row1["counts"]+1)." where id=".$row1["id"]);
	}
	else{
	  $sql1=query("insert into ".$dbz."so(keywords,hots,times)values('$keys','0','$times')");
	}
    
    $sonum=rows(query("select id from ".$dbz."news where titles like '%".$keys."%' or dis like '%".$keys."%' order by id desc limit 0,100"));
	$nums=ceil($sonum/$num);
	$sql=query("select * from ".$dbz."news where titles like '%".$keys."%' or dis like '%".$keys."%' order by id desc limit ".($p*$num).",$num");
	while($row=fetch($sql)){
	  $dis=str_replace($keys,"<font color=red>".$keys."</font>",$row["dis"]);
	  $titles=str_replace($keys,"<font color=red>".$keys."</font>",$row["titles"]);
	  
	  if($fps[5]==1){$fileurl=$fps[1]."/news/".$row["id"].".htm";}else{$fileurl=$fps[1]."/news.php?id=".$row["id"];}
	  $list.="<div class=\"item\"><h3><a href=\"$fileurl\">".$titles."</a></h3><p class=\"intro\">简介:".$dis."...</p><p class=\"info\">";
	  
	  $sqls=query("select * from ".$dbz."class where id=".$row["cid"]);
	  if($rows=fetch($sqls)){
	    if($fps[5]==1){$classurl=$fps[1]."/newslist/".$rows["id"].".htm";}else{$classurl=$fps[1]."/class.php?id=".$rows["id"];}
	    $list.="<small>所属分类:</small><span><a href=\"$classurl\">".$rows["names"]."</a></span>";
	  }
	  $list.="<small>作者:</small><span>".$row["users"]."</span>";
	  $list.="<small>来源:</small><span>".$row["sources"]."</span>";
	  $list.="<small>人气:</small><span>".$row["counts"]."</span></p>";
	  $list.="<p><span><a href=\"$fileurl\">$fileurl</a></span></p>";
	}
  }
  $list.="</div>";
  echo $list;
  ?>
</div>
<div class="dede_pages">
	<ul class="pagelist">
	  <table border='0' cellpadding='0' cellspacing='0'>
<tr align='center' style='font-size:10pt'>
<td><b><?php echo ($p+1); ?>/<?php echo $nums; ?></b> 页: </td>
<?php for($i=0;$i<$nums;$i++){?>
<td><a href="so.php?keys=<?php echo $keys; ?>&p=<?php echo $i; ?>"><?php echo ($i+1); ?></a>&nbsp;</td>
<?php }?>
</tr>
</table>
	</ul>
</div><!-- /pages -->
<div class="otherkey cbox">
相关搜索: <?php 
$sqlx=query("select * from ".$dbz."so where keywords like '%".$keys."%' and keywords<>'".$keys."' order by counts desc limit 0,12");
while($rowx=fetch($sqlx)){
  echo "<a href=\"so.php?keys=".urlencode($rowx["keywords"])." \">".$rowx["keywords"]."</a> ";
}
?>
</div>

<div class="footer">
	<p class="link">
		<?php echo $fps[8]; ?>
    </p>
<p class="powered"><a href="http://www.csc9.cn" title="CSC9社区" target="_blank"></a><?php echo $fps[9]; ?></p><!-- /powered -->	
</div>
<?php mysql_close();?>
</body>
</html>