<?php
 
namespace app\controller;
 
use think\Controller;

 
use think\Db;

 

class Page extends Controller



{



    public function index()



    {



$c=input('get.c');

	$rs3=db('news')->limit(0,9)->order('h desc')->select();

$rs6=db('news')->limit(0,9)->order('Id desc')->select();

$config=db('config')->where('Id',1)->find();

$clist=db('class')->where("zt=1")->order('pid,Id desc')->select();

     $vv=$clist;
	 
	 foreach($vv as $v){
	 if($v['ntitle']==$c){
	 
	 $gg[0]=$c;
	 $gg[1]=$v['seo2'];
	 $gg[2]=$v['seo3'];
	 $gg[3]=$v['ntitle'];
	 }
	 
	 }
	
	if($gg[0]==''){
	 $gg[0]=$c;
	 $gg[1]=$config['seo_2'];
	 $gg[2]=$config['seo_3'];
	 $gg[3]=$v['ntitle'];
	
	}
	
$this->assign('gg',$gg);
 

require_once("./api/php.php");

 


$p=$_GET["p"];


 
if($p=='' || $p<1)$p=1;

 

$index_url="https://zhidao.baidu.com/index/?fr=iknow_common_search&word=".$c."&pn=".$p."0";
 



 //echo $index_url;



$this->assign('p',$p);

 

if (file_exists("cache/list/".$c."-".$z."-".$p.".html")){

 
$fileTime =time()-filemtime("cache/list/".$c."-".$z."-".$p.".html");


 



$ftime=floor($fileTime/60);

 

$cc=0;
 

}else{

 
$cc=1;


 


}

 


//echo $cache_list;

 
//echo $ftime;
 

if ($ftime<$config['cache_list'] && $cc==0){ 
 



$uupp = file_get_contents("cache/list/".$c."-".$z."-".$p.".html");


 

}else{


 

$uupp=curl_https($index_url);




 


 //echo $uupp;

 

if($config['cache_true']){



 
$fp = fopen("cache/list/".$c."-".$z."-".$p.".html",'w+');
 

flock($fp,LOCK_EX);//独占锁定,为防止同一时间多个用户更新这个缓存文件

 
fwrite($fp,$uupp); 

flock($fp,LOCK_UN);//释放锁定

 
fclose($fp);
 

}


 
}


 

preg_match_all("|data-log=\"co\" href=\"\/question/([^\"]*)\.html|",$uupp,$a);
 

$tt[1][0]= nanji_cut("<a class=\"crumbs-name\" href=\"/list?cid=","</a>",$uupp);

 
$tt[1][0]=str_replace($c.'">','',$tt[1][0]);

 
  
preg_match_all("|data-log=\"ti\">([^\"]*)</span>|",$uupp,$t);
 
preg_match_all("|<span class=\"content\">([^\"]*)<\/span>|",$uupp,$cc3);
 
preg_match_all("|<span class=\"n-co5\">([^\"]*)</span>|",$url,$ym);

 
	 $config['s']=$key;

  $str1=file_get_contents('http://image.baidu.com/search/index?tn=baiduimage&ie=utf-8&word='.urlencode($c));



   $str1=nanji_split('<div id="topRS">','<div id="timeliness" class="hotpot-container">',$str1);

 
 //  echo $str1;



    $pat2 = '/(.*?)href="(.*?)">(.*?)<\/a>/i';     



    preg_match_all($pat2, $str1, $m2);  

	 $k2=$m2[3];

	  $this->assign('k2',$k2);
 
 $this->assign('ss',$ss);
 
$this->assign('cbody',$cbody);

 
$this->assign('rs3',$rs3);

$this->assign('rs6',$rs6);

 
$this->assign('ym',$ym);



$this->assign('cc',$cc);

$this->assign('cc3',$cc3);

$this->assign('t',$t);



 $this->assign('a',$a);

 
$this->assign('c',$c);



$this->assign('data',$data); 



$this->assign('config',$config);

$this->assign('clist',$clist);
 

  return view('page');

 
    }



}



