<?php



namespace app\controller;

use think\Controller;

use think\Db; 

class Read extends Controller

{

public function post(){
$uid=input('uid');
$qid=input('qid');
$nr=strip_tags(input('nr'));

 if($nr==''){
 $this->error('评论内容不能为空。');
 
 }
$rs=db('comment')->insert(['uid'=>$uid,'qid'=>$qid,'nr'=>$nr,'sj'=>date('Y-m-d H:i:s'),'zt'=>0]);
 
if($rs){

$this->success('评论发表成功，请等待审核。');

}

}

    public function index()
    {

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

$q=input('get.q');
 $qid=input('get.q');
 $pl=db('comment')->where('uid',$q)->limit(0,9)->order('id desc')->select();
 $this->assign('pl',$pl);
//
  $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();


$q=str_replace('.html','',$q);

 $rs=db('news')->where("uid='".$q."'")->find();
  $id=$rs['Id'];
  if($rs){
  db('news')->where("Id=".$id."")->setInc('h');
}


// $q=$rs['uid'];



 $rs9=db('news')->where("Id", ">",$id)->order("Id", "asc")->find();
 $rs91=db('news')->where("Id", "<", $id)->order("Id", "desc")->find();
  
 $this->assign('rs9',$rs9);
 $this->assign('rs91',$rs91);
 $this->assign('rs',$rs);
 
 if($rs['ct']!='1' || $rs['cal']==''){
 
 
 //if(1!=2){
 
$index_url="https://zhidao.baidu.com/mobile/ajax/getqbcontent?qid=461229322239761045&oldqid=461229322239761045";

echo $index_url;
$str=curl_https($index_url);
$str=json_decode($str,true);
print_r($str);
exit;
$title=nanji_cut("<title>","</title>",$str);
echo $title;
echo $str;
exit;
//$index_url="http://wapiknow.baidu.com/question/34686946.html";
 //echo $index_url;
//  echo $str;
//echo 'test';
 

//$str=str_replace('<img class="ikqb_img" src="http://','<img class="ikqb_img" src="/img.php?url=',$str);

 //$ff=nanji_cut("<div class=\"full-content\">","<div class=\"w-detail-display-btn\">",$str);
$ff=nanji_cut("<div class=\"full-content\">",PHP_EOL."</div>".PHP_EOL."</div>".PHP_EOL,$str);
$title=nanji_cut("<title>","</title>",$str);

$title=str_replace(PHP_EOL,'',$title);

 
//preg_match_all("|<div class=\"full-content\">([^\"]*)</div>|", $str,$t);

//echo $ff;
// preg_match_all("|<p class=\"question-list-intro\">([^\"]*)</p>|", $str,$t2);

//preg_match_all("|<p>([^\"]*(?<!微信)(?<!微博)(?<!QQ)(?<!QQ空间)(?<!答案纠错)(?<!举报))</p>|",$str,$nn);

 //preg_match_all('|<img class="ikqb_img" src="([^\"]*)"|',$str,$imgx); 

//echo '$t';

//print_r($t);

//echo '<Br>$t2';

//print_r($t2);

//echo '<br>$nn';

//print_r($nn);

//echo '<Br>$imgx';

//print_r($imgx);

	 
								
								
                     

			 $user=db('news');


$contall=$ff; 
 if($rs){
 $user->where("Id=".$id."")->update(['cal'=>$contall,'ct'=>1]);
 }else{
if($title!='' && $title!='百度安全验证'){
  $add=$user->insert(['title'=>$title,'sj'=>date('Y-m-d H:i:s'),'cid'=>'推荐内容','uid'=>$q,'mid'=>$q,'h'=>0,'cont'=>'']);
  }
//  echo $add;
 }


}else{
 $contall=$rs['cal'];
 $title=$rs['title'];
}
 $contall=str_replace(PHP_EOL."</div>".PHP_EOL."</div>".PHP_EOL,'',$contall);
$this->assign('title',$title);
$this->assign('contall',$contall);
  $this->assign('rs3',$rs3);

    $this->assign('rs6',$rs6);
//print_r($imgx);

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

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

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

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

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

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

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

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

  return view('read');



    }



}



