<?php
/*
**U2自动链 目标站内容截取函数
**inc/links.inc.php
**By 冬筠 qq426420
*/
!defined("l_ok") && die("Accessed Defined!");
//去除所有js,html,css代码 
function get_enhtml($string){
$pattern=array ("'<script[^>]*?>.*?</script>'si",// 去掉 javascript
"'<style[^>]*?>.*?</style>'si",// 去掉 HTML 标记
"'<[/!]*?[^<>]*?>'si",//去掉 HTML 标记
"'<!--[/!]*?[^<>]*?>'si", // 去掉 注释标记
"'([rn])[s]+'", // 去掉空白字符
"'&(quot|#34);'i",
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(d+);'e");
$replace=array ("", "", "", "", "\1", "", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\1)");
$string=preg_replace($pattern, $replace, $string);
$string=preg_replace("/<(.*?)>/","",$string);
$string=str_replace("\n","",$string);
$string=str_replace("\r","",$string);
$string=str_replace("  ","",$string);
$string=str_replace("		","",$string);
return addslashes(trim($string));
}

function get_title($html)
{
preg_match("@<title>(.*?)<\/title>@si",$html, $regs);
$title = str_replace(" - ",",",$regs[1]);
if ($title) $title=replace_word(textcut($title,80));
if ($title) $title=preg_replace("/<(.*?)>/","",$title);
return addslashes(trim($title));
}

function get_keywords($html)
{
preg_match("@<head[^>]*>(.*?)<\/head>@si",$html, $regs);	
$headdata = $regs[1];
preg_match("/<meta +name *=[\"']?keywords[\"']? *content=[\"']?([^<>\"]+)[\"']?/i", $headdata, $res);
if (isset ($res)) {
$keywords = $res[1];
}
if ($keywords == "") $keywords = "无";
$keywords=replace_word(textcut($keywords,250));
$keywords=str_replace("-",",",$keywords);
$keywords=str_replace("，",",",$keywords);
$keywords=str_replace(" ",",",$keywords);
$keywords=str_replace("|",",",$keywords);
$keywords=str_replace("、",",",$keywords);
$keywords=str_replace(",,",",",$keywords);
$keywords=str_replace("<","",$keywords);
$keywords=str_replace(">","",$keywords);
return addslashes(trim($keywords));
}

function get_description($html)
{
preg_match("@<head[^>]*>(.*?)<\/head>@si",$html, $regs);	
$headdata = $regs[1];
preg_match("/<meta +name *=[\"']?description[\"']? *content=[\"']?([^<>\"]+)[\"']?/i", $headdata, $res);
    		if (isset ($res)) {
    			$description = $res[1];
    		}
if ($description == "") $description = "无";
$description=replace_word(textcut($description,250));
$description=str_replace("-",",",$description);
$description=str_replace("，",",",$description);
$description=str_replace(" ",",",$description);
$description=str_replace("|",",",$description);
$description=str_replace("、",",",$description);
$description=str_replace(",,",",",$description);
$description=str_replace("<","",$description);
$description=str_replace(">","",$description);
return addslashes(trim($description));
}

function get_goolejs($url)
{
global $charset;
$url=str_replace("http://","",$url);
$url="http://www.google.com.hk/search?hl=zh-CN&q=".$url;
$urlhtml=get_url_content($url);
if($urlhtml){
$description = cut($urlhtml,"<div class=\"s\">", "<br>");
if ($description == "") $description = "无";
$description=replace_word(textcut($description,250));
$description=str_replace("-",",",$description);
$description=str_replace("，",",",$description);
$description=str_replace(" ",",",$description);
$description=str_replace("|",",",$description);
$description=str_replace("、",",",$description);
$description=str_replace(",,",",",$description);
$description=str_replace("<","",$description);
$description=str_replace(">","",$description);
return addslashes(trim($description));
} else {
return "无";
}
}


function get_link()
{
	global $murl,$furl;
	if($furl){
	$page = get_url_content($furl);
	if($page){
	if(strpos($page,$murl)>-1)
		return "<font color=green>存在</font>";
	else
		return "<font color=red>不存在</font>";
	}
	else
	{
		return "<font color=red>无法访问</font>";
	}
	}
	else
	{
		return "<font color=red>无最后点击</font>";
	}
}

function baidu()
{
	global $murl,$wurl,$charset;
	$url = "http://www.baidu.com/s?wd=site:$wurl";
	$page = get_url_content($url);
	//$page=get_encoding($page,$charset);
	$PageNum = "0";
	$PageNum = str_replace(",","",cut($page,"找到相关网页约", "篇" ));
	//if ($PageNum == "") $PageNum = str_replace(",","", cut($page,"找到相关网页约", "篇"));
	if ($PageNum == "") $PageNum = "0";
	return "<a href='".$url."' target='_blank'><!--b top-->$PageNum<!--b end--></a>";
}
function baidukz()
{
	global $murl,$wurl,$charset;
$url = "http://www.baidu.com/s?wd=$wurl";
$out=get_url_content($url);
$out1=explode("<font color=\"#008000\"><b>{$wurl}</b>",$out);
$out2=explode("</font>",$out1[1]);
$out=$out2[0];
if(strpos($out,"/")!== false)$out=str_replace("/","",$out);
$out=trim($out);
if(!$out)$out='无';
return "<!--bk top-->".$out."<!--bk end-->";
}

function alexa()
{
global $murl,$wurl;
$url = "http://data.alexa.com/data/?cli=10&dat=snba&ver=7.0&cdt=alx_vw=20&url=$wurl";
$out=get_url_content($url);
$out1=explode("<REACH RANK=\"",$out);
$out2=explode("\"/>",$out1[1]);
$out=$out2[0];
$out=trim($out);
if(!$out)$out='无';
return "<!--a top-->".$out."<!--a end-->";
}

function google()
{
	//在同时间过于频繁地扫描Google搜索结果,GG会屏蔽该IP.因此冰河在此暂时去掉了此功能
	//诸位网友如果想开放此功能可以,可将下面这一行加上注释即可,谢谢! 
//	echo "0";	return "";
	global $murl,$wurl,$charset;
	$url = "http://www.google.com.hk/search?hl=zh-CN&q=site:$wurl";
	$page = get_url_content($url);
	//$page=get_encoding($page,$charset);
	$PageNum = "0";
	$PageNum = str_replace(",","",cut($page,"获得约", "条结果"));
	if ($PageNum == "") $PageNum = "0";
	return "<a href='".$url."' target='_blank'><!--g top-->$PageNum<!--g end--></a>";
}

function pr()
{
global $murl,$wurl;
$website = trim($wurl);
$pr = Gonten_prget($website);
$pr = str_replace( "\n", "", $pr );
return "<!--pr top-->".$pr."<!--pr end-->";
}


//功能与javascript中的escape一样
function escape($str) {
  preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r);
  $ar = $r[0];
  foreach($ar as $k=>$v) {
    if(ord($v[0]) < 128)
      $ar[$k] = rawurlencode($v);
    else
      $ar[$k] = "%u".bin2hex(iconv("GB2312","UCS-2",$v));
  }
  return join("",$ar);
}

function unescape($str) {
  $str = rawurldecode($str);
  preg_match_all("/(?:%u.{4})|.+/",$str,$r);
  $ar = $r[0];
  foreach($ar as $k=>$v) {
    if(substr($v,0,2) == "%u" && strlen($v) == 6)
      $ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,-4)));
  }
  return join("",$ar);
}

//下面的函数用于查pr
function HashURL($url)
{$SEED = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer.";
    $Result = 0x01020345;
    for ($i=0; $i<strlen($url); $i++) 
    {
        $Result ^= ord($SEED{$i%87}) ^ ord($url{$i});
        $Result = (($Result >> 23) & 0x1FF) | $Result << 9;
    }
    return sprintf("8%x", $Result);
}
function Gonten_prget($domain)
{	
	$GontenPRURL = "http://www.google.com/search?client=navclient-auto&features=Rank:&q=info:".$domain.'&ch='.HashURL($domain);

	$prstr = file_get_contents($GontenPRURL);

	$pagerank = substr($prstr,9);
	 if ($pagerank){
	 return $pagerank;
	 }
	 else {
	 return "0";
	 }
}

function Get_webdbok($wurl){
global $siteurl,$charset;
$spid=substr(md5($wurl),0,2);
$webdbfc=l_path.'./_Cache/webdb/'.$spid.'/'.$wurl.'.txt';
if(gethchtml($webdbfc,mt_rand(10080,50080))){
$webdbok= readfromfile($webdbfc);
return $webdbok;
}else{
$url="http://".$wurl;
$murl = $siteurl;
$baidu=baidu();
$baidukz=baidukz();
$google=google();
$pr=pr();
$alexa=alexa();
$webdbok= "百度：".$baidu." 快照：".$baidukz." 谷歌：".$google." PR：".$pr." Alexa：".$alexa;
if(!is_dir(l_path.'./_Cache/webdb/'.$spid)) {
		mkpaths('/_Cache/webdb/'.$spid);
}
writetofile($webdbfc,$webdbok);
return $webdbok;
}
}
?>