<?
	session_start();
	include_once '../../../include.inc/config.inc.php';
	include_once '../../../include.inc/function.php';
	include_once '../../../include.inc/global.inc.php';
	include_once '../../../include.inc/conn.db.inc.php';
	include_once '../../../parse_site.php';

	function get_content($url)
	{
		if(!strpos($url, '://')) return 'Invalid URI';
		$content = '';
		if(ini_get('allow_url_fopen'))
		{
			$content = file_get_contents($url);
		} 
		elseif(function_exists('curl_init')) 
		{
			$handle = curl_init();
			curl_setopt($handle, CURLOPT_URL, $url);
			curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
			curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 0);
			$content = curl_exec($handle);
			curl_close($handle);
		}
		elseif(function_exists('fsockopen'))
		{
			$urlinfo = parse_url($url);
			$host = $urlinfo['host'];
			$str = explode($host, $url);
			$uri = $str[1];
			unset($urlinfo, $str);
			$content = '';
			$fp = fsockopen($host, 80, $errno, $errstr, 30);
			if(!$fp)
			{
				$content = 'Can Not Open Socket...';
			}
			else
			{
				$out = "GET $uri   HTTP/1.1\r\n";
				$out.= "Host: $host \r\n";
				$out.= "Accept: */*\r\n";
				$out.= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
				$out.= "Connection: Close\r\n\r\n";
				fputs($fp, $out);
				while (!feof($fp))
				{
					$content .= fgets($fp, 4069);
				}
				fclose($fp);
			}
		}
		if(empty($content)) $content = 'phpstat.net';
		return $content;
	}
	function PageRank($domain)
	{
		$result = get_content('http://www.google.com/search?client=navclient-auto&ch=6'. GCH(strord('info:' . $domain)) . '&ie=UTF-8&oe=UTF-8&features=Rank&q=info:' . urlencode($domain));
		if (preg_match('/\d+:\d+:(\d+)/', $result, $matches))
		{
			return intval($matches[1]);
		} 
		else
		{
			return 0;
		}
	}

	function strord($string)
	{
		$strlen = strlen($string);
		for($i = 0; $i < $strlen; $i++) 
		{
			$result[$i] = ord($string{$i});
		}
		return $result;
	}

	function GCH($url, $length=null)
	{
		$length = sizeof($url);
		$a = $b = 0x9E3779B9;
		$c = 0xE6359A60;
		$k = 0;
		$len = $length;
		while($len >= 12)
		{
			$a += ($url[$k + 0] + ($url[$k + 1] << 8) + ($url[$k + 2] << 16) + ($url[$k + 3] << 24));
			$b += ($url[$k + 4] + ($url[$k + 5] << 8) + ($url[$k + 6] << 16) + ($url[$k + 7] << 24));
			$c += ($url[$k + 8] + ($url[$k + 9] << 8) + ($url[$k + 10] << 16) + ($url[$k + 11] << 24));
			$mix = mix($a, $b, $c);
			$a = $mix[0];
			$b = $mix[1];
			$c = $mix[2];
			$k += 12;
			$len -= 12;
		}
		$c += $length;
		switch($len) {
			case 11: $c += ($url[$k + 10] << 24);
			case 10: $c += ($url[$k + 9] << 16);
			case 9 : $c += ($url[$k + 8] << 8);
			case 8 : $b += ($url[$k + 7] << 24);
			case 7 : $b += ($url[$k + 6] << 16);
			case 6 : $b += ($url[$k + 5] << 8);
			case 5 : $b += ($url[$k + 4]);
			case 4 : $a += ($url[$k + 3] << 24);
			case 3 : $a += ($url[$k + 2] << 16);
			case 2 : $a += ($url[$k + 1] << 8);
			case 1 : $a += ($url[$k + 0]);
		}
		$mix = mix($a, $b, $c);
		return $mix[2];
	}

	function mix($a, $b, $c)
	{
		$a -= $b;
		$a -= $c;
		$a ^= (zeroFill($c, 13));
		$b -= $c;
		$b -= $a;
		$b ^= ($a << 8);
		$c -= $a;
		$c -= $b;
		$c ^= (zeroFill($b, 13));
		$a -= $b;
		$a -= $c;
		$a ^= (zeroFill($c, 12));
		$b -= $c;
		$b -= $a;
		$b ^= ($a << 16);
		$c -= $a;
		$c -= $b;
		$c ^= (zeroFill($b, 5));
		$a -= $b;
		$a -= $c;
		$a ^= (zeroFill($c, 3));
		$b -= $c;
		$b -= $a;
		$b ^= ($a << 10);
		$c -= $a;
		$c -= $b;
		$c ^= (zeroFill($b, 15));
		return array($a, $b, $c);
	}

	function zeroFill($a, $b)
	{
		$z = hexdec(80000000);
		if($z & $a) 
		{
			$a = ($a >> 1);
			$a &= (~ $z);
			$a |= 0x40000000;
			$a = ($a >> ($b - 1));
		}
		else
		{
			$a = ($a>>$b);
		}
		return $a;
	}

	

	
	$website = strval($_GET[website]);
	if( strval($_GET[showtype] ) == 'all' ) $website = $website."&showtype=all";
	include_once "../../../count/exclusion/website_".$websiteid.".php";
	$manager = $_SESSION[SESSION_MANAGER];
	$r = @$Conn->Execute("select sitename,site from $TableList[site] where website = '$website'");
	$row = @$r->FetchRow();
	$websitename = $row[sitename];
	$websiteurl = $row[site];	
	$managername = $manager;
	$Timer = date("H");
	$Weekr = date("w");
	if($Weekr == 6 or $Weekr == 0)  $TimerWords = "周末快乐";
	elseif($Timer < 4)  $TimerWords = "已经深夜了，仙人，你不会还没有睡觉吧！";
	elseif($Timer < 6)  $TimerWords = "一日之计在于晨，运动一下真不错";
	elseif($Timer < 8)  $TimerWords = "知识就是力量";
	elseif($Timer < 12) $TimerWords = "已经工作很长时间了，适当放松一下自己";
	elseif($Timer < 13) $TimerWords = "饿了吧，快去吃饭吧";
	elseif($Timer < 14) $TimerWords = "工作积极，午休也要落实好";
	elseif($Timer < 17) $TimerWords = "奋斗在一线的人们，请抓紧时间";	
	elseif($Timer < 18) $TimerWords = "这个时候运动一下，最有效果了";
	elseif($Timer < 20) $TimerWords = "黄昏美意不尽收";
	elseif($Timer < 24) $TimerWords = "要不要喝杯牛奶";
	else                $TimerWords = "";
	
	
	if(true)
	{
		$StartTime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$Res = $Conn->Execute("select count(id) as existsrecord from ". DB_PREFIX.$mainsitecode."_ip_limit where website = '$website' and time < $StartTime limit 1");
		$Row = $Res->FetchRow();
		if($Row[existsrecord] > 0)
		{
			//echo "<SCRIPT LANGUAGE=\"JavaScript\">		
			//location=''		
			//	</SCRIPT>";
			echo "<IFRAME id=\"test\" name=\"test\" frameBorder=0 scrolling=no src=\"../../../get_records.php?website=$website&endtime=$StartTime\" width=\"100%\" height=0></IFRAME>";
			$url = $websiteurl;
			if($url == ""){$url = "www.phpstat.net";}
			$pagerank = PageRank($url);
			$fp = fopen("../../../".COUNT_DIRNAME."/pagerank/website_".$websiteid.".pr","w");
			fwrite($fp , $pagerank);
			fclose($fp);
			
		}
	}


	//GOOGLE PR
	$datetime = date("Ymd");
	if( file_exists("../../../".COUNT_DIRNAME."/pagerank/website_".$websiteid.".pr") )
	{
		$pagerank = (int)read_from_file( "../../../".COUNT_DIRNAME."/pagerank/website_".$websiteid.".pr" );
	}
	else
	{
		$url = $websiteurl;
		if($url == ""){$url = "www.phpstat.net";}
		$pagerank = PageRank($url);
		$fp = fopen("../../../".COUNT_DIRNAME."/pagerank/website_".$websiteid.".pr","w");
		fwrite($fp , $pagerank);
		fclose($fp);
	}
	//$Tpl->assign( 'pagerank', $chjia_sitepr );
	//echo "站点在GOOGLE网站评分满分10分中获得：<font color=red>{$chjia_sitepr}</font>分"

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE> PHPStat Standard 2006</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK 
href="/favicon.ico" rel="shortcut icon">
<LINK href="../imagefiles/style.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.2604" name=GENERATOR></HEAD>
<SCRIPT>
function checkclick(msg){
if(confirm(msg)){
event.returnValue=true;
}else{
event.returnValue=false;
}
}
</SCRIPT>
<script Language=JavaScript>
window.setTimeout('this.location.reload();',3600000);

var OA_TIME = new Date();

function timeview()
{
  timestr=OA_TIME.toLocaleString();
  timestr=timestr.substr(timestr.indexOf(" "));
  time_area.innerHTML = timestr;
  OA_TIME.setSeconds(OA_TIME.getSeconds()+1);
  window.setTimeout( "timeview()", 1000 );
}
</script>
<BODY bottomMargin=0 leftMargin=0  topMargin=0 
rightMargin=0>
<DIV align=left> 
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td height="40" background="../imagefiles/1.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="52%" height="39" valign="top"><strong><img src="../imagefiles/top.jpg" align="absmiddle">
              <?=$PHPStatTopRight?>
              </strong></td>
            <td width="48%"> 
              <div align="right"> <strong><a href=# onClick="javascript:if(confirm('确实要关闭当前窗口吗?'))parent.window.close();"  ><font color="#FFFFFF">关闭窗口</font></a></strong><img src="../imagefiles/loginexit.gif" width="62" height="39" align="absmiddle"><strong><a href="../../../login.php?logout=true"><font color="#FFFFFF">注销登录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></a></strong> 
              </div></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr> 
      <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr class=titlefont_03>
		  <td width=41%>
           <? echo "<B>&nbsp;&nbsp;&nbsp;尊敬的&nbsp;<U>".$managername."</U>&nbsp;欢迎您，&nbsp;$TimerWords";
		   ?></td>
		    
		    <td width=28% align=right><? echo "&nbsp;&nbsp;站点:<a href=$websiteurl target=_blank>".$websitename."</a></B>&nbsp;&nbsp;&nbsp;&nbsp;";
		   ?></td>
		    <td width=7% align=right><div align="left"><IMG SRC=../../../seo/images/pagerank<?=$pagerank?>.gif></div></td>
		    <td width=24% align=right><div id="jnkc"></div><script>setInterval("jnkc.innerHTML=new Date().toLocaleString()+'      星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
</script></td>
          </tr>
        </table></td>
    </tr>
  </table>
</DIV>
</BODY></HTML>
