<?php
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
if (!isset($_G['cache']['plugin'])) {
    loadcache('plugin');
}
$args = $_G['cache']['plugin']['csdn123_news']['zhiwu55_uid'];
if (strpos($args, ',') === false) {
    $argsArr = array($args);
} else {
    $argsArr = explode(',', $args);
}
if (!in_array($_G['uid'], $argsArr)) {
	echo 'No_authority';
    exit;
}
require './source/plugin/csdn123_news/function_common.php';
$hzw_appid=wwwzhiwu55com_appid();
if(empty($_G['cache']['plugin']['csdn123_news']['zhiwu55_appsecret']))
{

	$zhiwu55com_authorization_arr=array();
	if (!isset($_G['cache']['zhiwu55com_authorization'])) {
		loadcache('zhiwu55com_authorization');
	}
	if(!empty($_G['cache']['zhiwu55com_authorization']))
	{
		$zhiwu55com_authorization_arr = $_G['cache']['zhiwu55com_authorization'];
	}
	$zhiwu55_appsecret=$zhiwu55com_authorization_arr['hzw_appsecret'];

} else {

	$zhiwu55_appsecret=$_G['cache']['plugin']['csdn123_news']['zhiwu55_appsecret'];

}
if(empty($zhiwu55_appsecret))
{
	$resultArr=array();
	$resultArr['zhiwu55_status']='sign_deny';
	echo $zhiwu55callback.'('.json_encode($resultArr).')';
	exit;
}
if(!empty($_GET['search_query']) && strlen($_GET['search_query'])>1)
{
	$zhiwu55callback=$_GET['zhiwu55callback'];
	$zhiwu55_frequently=getcookie('zhiwu55_frequently');
	if(!empty($zhiwu55_frequently))
	{
		$zhiwu55_frequently_diff=time();
		$zhiwu55_frequently_diff=$zhiwu55_frequently_diff-$zhiwu55_frequently;
		if($zhiwu55_frequently_diff<4)
		{
			$resultArr=array();
			$resultArr['zhiwu55_status']='frequently';
			echo $zhiwu55callback.'('.json_encode($resultArr).')';
			exit;
		}
	}
	dsetcookie('zhiwu55_frequently',time(),3600);
	$keyword=$_GET['search_query'];
	$keyword=trim($keyword);
	$signArr=array();
	$signArr['hzw_appid']=$hzw_appid;
	$signArr['appsecret']=$zhiwu55_appsecret;
	$signArr['keyword']=$keyword;
	$signArr['t']=time();
	$sign=hzw_sign($signArr);
	$dataUrl="http://www.zhiwu55.com/catch_data/catch_keyword_content_list.php?hzw_appid=".$hzw_appid.'&keyword='.urlencode($keyword).'&t='.$signArr['t'].'&sign='.$sign.'&limit=200';
	if(stripos($keyword,'http')===0)
	{
		$htmlcode=dfsockopen($keyword);
		if(empty($htmlcode))
		{
			$htmlcode=ext_dfsockopen_zhiwu55fun($keyword);
		}
		if(empty($htmlcode))
		{
			$resultArr=array();
			$resultArr['zhiwu55_status']='content_empty';
			echo $zhiwu55callback.'('.json_encode($resultArr).')';
			exit;
		}
		$htmlcode=base64_encode($htmlcode);
		$resultStr=dfsockopen($dataUrl,0,array('htmlcode'=>$htmlcode));
		$resultStr=base64_decode($resultStr);
		$resultArr=array();
		$resultArr=dunserialize($resultStr);
		$resultArr['zhiwu55_status']='single_article';
		echo $zhiwu55callback.'('.json_encode($resultArr).')';
		exit;

	} else {

		$resultStr=dfsockopen($dataUrl);

	}
	if(strlen($resultStr)<50)
	{
		$resultArr=array();
		$resultArr['zhiwu55_status']=$resultStr;
		echo $zhiwu55callback.'('.json_encode($resultArr).')';
		exit;
	}
	$resultStr=trim($resultStr);
	$resultStr=base64_decode($resultStr);
	$resultArr['items']=dunserialize($resultStr);
	$resultArr['zhiwu55_status']='ok';
	echo $zhiwu55callback.'('.json_encode($resultArr).')';
	exit;

}
if(!empty($_GET['get_content']) && strlen($_GET['get_content'])>10)
{

	$zhiwu55callback=$_GET['zhiwu55getcontentcallback'];
	$resultArr=array();
	$zhiwu55_frequently=getcookie('zhiwu55_get_content_frequently');
	if(!empty($zhiwu55_frequently))
	{
		$zhiwu55_frequently_diff=time();
		$zhiwu55_frequently_diff=$zhiwu55_frequently_diff-$zhiwu55_frequently;
		if($zhiwu55_frequently_diff<5)
		{
			$resultArr=array();
			$resultArr['zhiwu55_status']='frequently';
			echo $zhiwu55callback.'('.json_encode($resultArr).')';
			exit;
		}
	}
	dsetcookie('zhiwu55_get_content_frequently',time(),3600);
	$signArr=array();
	$signArr['hzw_appid']=$hzw_appid;
	$signArr['appsecret']=$zhiwu55_appsecret;
	$signArr['url']=$_GET['get_content'];
	$signArr['chinese_encoding']=1;
	$signArr['t']=time();
	$sign=hzw_sign($signArr);
	$dataUrl="http://www.zhiwu55.com/catch_data/show_content_202005.php?title=QQ:155120699&hzw_appid=".$hzw_appid.'&url='.urlencode($signArr['url']).'&chinese_encoding=1&sign='.$sign.'&t='.$signArr['t'];
	$dataStr=dfsockopen($dataUrl);
	if(empty($dataStr))
	{
		$resultArr['zhiwu55_status']='empty';
		echo $zhiwu55callback.'('.json_encode($resultArr).')';
		exit;

	} else {

		$dataStr=trim($dataStr);

	}
	if(!empty($dataStr) && strlen($dataStr)<50)
	{

		$resultArr['zhiwu55_status']=$dataStr;
		echo $zhiwu55callback.'('.json_encode($resultArr).')';
		exit;

	}
	$dataArr=array();
	$dataArr=explode('__zhiwu55.net__',$dataStr);
	$resultArr['zhiwu55_status']='ok';
	$resultArr['tags_word']=$dataArr[2];
	if(strpos($dataArr[1],'__zhiwu55.com__')==false)
	{
		$resultArr['content']=$dataArr[1];

	} else {

		$resultArr['content']=substr($dataArr[1],0,strpos($dataArr[1],'__zhiwu55.com__'));

	}
	$resultArr['content']=str_replace('//www.zhiwu55.com/','http://www.zhiwu55.com/',$resultArr['content']);
	echo $zhiwu55callback.'('.json_encode($resultArr).')';

}
if (!empty($_GET["originality"]) && $_GET["originality"]=='yes') {

	$wordRs = DB::fetch_all('SELECT word1,word2 FROM %t',array('zhiwu55cn_weiyanchang'));
	$wordStr = "";
	foreach ($wordRs as $wordValue) {
		$word1 = $wordValue['word1'];
		$word2 = $wordValue['word2'];
		$word2OneStr = mb_substr($word2,1,1,CHARSET);
		$word2hzw = '_hzw_' . $word2OneStr;
		$word2 = mb_ereg_replace($word2OneStr,$word2hzw,$word2);
		$wordStr = $word1 . '=' . $word2 . ',' . $wordStr;
	}
	echo substr($wordStr,0,-1);

}
if (!empty($_GET["zhiwu55_jianTextData"])) {

	$zhiwu55_url = "http://www.zhiwu55.com/catch_data/convert_GBK_BIG_onearticle.php";
	$zhiwu55_data = array();
	$zhiwu55_data['convertType'] = $_GET['convertType'];
	$zhiwu55_data['textdata'] = urlencode($_GET["zhiwu55_jianTextData"]);
	$zhiwu55_data['siteurl'] = urlencode($_G["siteurl"]);
	$zhiwu55_data['charset'] = CHARSET;
	$zhiwu55_data['hzw_appid'] = $hzw_appid;
	$zhiwu55_return = dfsockopen($zhiwu55_url, 0, $zhiwu55_data);
	echo $zhiwu55_return;

}