<?php

require "class.template.php";

$template = new verySimpleTemplate();
$domain = @$_GET['domain'];

if( !strpos( $domain, '.' ) )
{
	$domain .= '.com';
}

switch( @$_GET['action'] )
{
	case 'pagerank':
	echo pageRank( $domain );
	break;

	case 'google':
	echo google( $domain );
	break;

	case 'baidu':
	echo baidu( $domain );
	break;

	case 'msn':
	echo msn( $domain );
	break;

	case 'yahoo':
	echo yahoo( $domain );
	break;

	case 'soso':
	echo soso( $domain );
	break;

	case 'so163':
	echo so163( $domain );
	break;

	case 'sina':
	echo sina( $domain );
	break;

	case 'iask':
	echo iask( $domain );
	break;

	case 'sohu':
	echo sohu( $domain );
	break;

	case 'whois':
	echo whois( $domain );
	break;

	case 'alexa':
	echo alexa( $domain );
	break;

	default:
	break;
}

function getContent( $url, $start, $end )
{
	$content = implode( '', file( $url ) );
    $content = substr( strstr( $content, $start ), strlen($start) );
    $content = substr_replace( $content, '', strpos( $content, $end ) );
	return $content;
}

function pageRank( $domain )
{
	global $template;

	$urlF  = 'http://rankwhere.com/google-page-rank.php?url=' . $domain;
	$urlS  = 'http://rankwhere.com/google-page-rank.php?url=www.' . $domain;
	$rankF = getContent( $urlF, 'has Google PageRank ' , ' out of 10' );
	$rankS = getContent( $urlS, 'has Google PageRank ' , ' out of 10' );
	$rankF  = intval( $rankF );
	$rankS  = intval( $rankS );
	$body  = '<div align=left>www.' . $domain . '在满分10分评价中获得 <b>' . $rankS . '</b> 分&nbsp;&nbsp;|&nbsp;&nbsp;' . $domain . '在满分10分评价中获得 <b>' . $rankF . '</b> 分</div>';;

	$arrayVar = array ( 'CHECK_CAT'  => 'dopagerank',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function google( $domain )
{
	global $template;

	$url       = 'http://www.google.com/search?hl=zh-CN&q=site%3A' . $domain;
	$pageCount = getContent( $url, '</b> 上约有 <b>', '</b> 项符合<b></b>的查询' );
	if( $pageCount == '' )
	{
		$pageCount = getContent( $url, '</b> 上共有 <b>', '</b> 项符合<b></b>的查询' );
	}
	//$pageCount = intval( str_replace( ',', '', $pageCount ) );
	$body      = '<div align=left  bgcolor="#f5f5f5">' . $domain . '在google上的搜索结果：找到相关网页约<b> ' . $pageCount . " </b>篇.&nbsp;&nbsp;<a href='http://www.google.com/search?hl=zh-CN&q=site%3A" . $domain . "' target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  => 'dogoogle',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function baidu( $domain )
{
	global $template;

	$url       = 'http://www.baidu.com/baidu?word=site%3A' . $domain;
	$pageCount = getContent( $url, '相关网页', '篇，用时' );
	$pageCount = str_replace( '约', '', $pageCount );
	//$pageCount = intval( str_replace( ',', '', $pageCount ) );
	$body      = '<div align=left>' . $domain .  '在baidu上的搜索结果：找到相关网页约<b> ' . $pageCount .  "</b> 篇.&nbsp;&nbsp;<a href='http://www.baidu.com/baidu?word=site%3A" . $domain . "' target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  => 'dobaidu',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function msn( $domain )
{
	global $template;

	$url       = 'http://search.msn.com/results.aspx?FORM=PERE&q=site%3A' . $domain;
	$pageCount = getContent( $url, '<h5>Page 1 of ', ' results</h5>' );
	//$pageCount = intval( str_replace( ',', '', $pageCount ) );
	$body      = '<div align=left>' . $domain .  '在msn上的搜索结果：找到相关网页约<b> ' . $pageCount .  "</b> 篇.&nbsp;&nbsp;<a href='http://search.msn.com/results.aspx?FORM=PERE&q=site%3A" . $domain . "' target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  => 'domsn',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function yahoo( $domain )
{
	global $template;

	$url       = 'http://search.cn.yahoo.com/search?ei=UTF-8&p=site%3A' . $domain;
	$pageCount = getContent( $url, "约", '项结果');
	//$pageCount = intval( str_replace( ',', '', $pageCount ) );
	$body      = '<div align=left>' . $domain .  '在yahoo上的搜索结果：找到相关网页约<b> ' . $pageCount .  "</b> 篇.&nbsp;&nbsp;<a href=http://search.cn.yahoo.com/search?ei=UTF-8&p=site%3A" . $domain . " target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  => 'doyahoo',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function soso( $domain )
{
	global $template;

	$url       = 'http://www.soso.com/q?w=site%3A' . $domain;
	$pageCount = getContent( $url, "搜索到约", "项结果" ) ;
	//$pageCount = str_replace( '\r', '', $pageCount );
	//$pageCount = intval( str_replace( ',', '', $pageCount ) );
	$body      = '<div align=left>' . $domain .  '在SOSO上的搜索结果：找到相关网页约<b> ' . $pageCount .  "</b> 篇.&nbsp;&nbsp;<a href=http://www.soso.com/q?w=site%3A" . $domain . " target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  => 'dososo',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function sina( $domain )
{
	global $template;

	$url       = 'http://search.sina.com.cn/cgi-bin/search/search.cgi?_searchkey=site%3A' . $domain;
	$startPos  = $domain . '</font> 网站结果 ';
	$pageCount = getContent( $url, $startPos, ' 个，<font class="t1">' );
	//$pageCount = intval( str_replace( ',', '', $pageCount ) );
	$body      = '<div align=left>' . $domain .  '在sina上的搜索结果：找到相关网页约<b> ' . $pageCount .  "</b> 篇.&nbsp;&nbsp;<a href='http://search.sina.com.cn/cgi-bin/search/search.cgi?_searchkey=site%3A" . $domain . "' target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  =>'dosina',
						'RESULT_BODY'=>$body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function so163( $domain )
{
	global $template;

	$url       = 'http://page.so.163.com/psearch.php?q=site%3A' . $domain;
	$pageCount = getContent( $url, '的结果约', "条" );
	//$pageCount = intval( str_replace( ',', '', $pageCount*10 ) );
	$body      = '<div align=left>' . $domain .  '在163上的搜索结果：找到相关网页约<b> ' . $pageCount .  "</b> 篇.&nbsp;&nbsp;<a href='http://page.so.163.com/psearch.php?q=site%3A" . $domain . "' target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  => 'doso163',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function iask( $domain )
{
	global $template;

	$url       = 'http://www.google.com/search?hl=zh-CN&q=site%3A' . $domain;
	$pageCount = getContent( $url, '</b> 上约有 <b>', '</b> 项符合<b></b>的查询' );
	if( $pageCount == '' )
	{
		$pageCount = getContent( $url, '</b> 上共有 <b>', '</b> 项符合<b></b>的查询' );
	}
	//$pageCount = intval( str_replace( ',', '', $pageCount ) );
	$body      = '<div align=left  bgcolor="#f5f5f5">' . $domain . '在Iask上的搜索结果：找到相关网页约<b> ' . $pageCount . " </b>篇(由于新浪和谷歌合作，数据直接来自谷歌的查询数据).&nbsp;&nbsp;<a href='http://www.iask.com/s?tag=u&k=site%3A" . $domain . "' target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  => 'doiask',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function sohu( $domain )
{
	global $template;

	$url       = 'http://www.sogou.com/web?query=' . $domain;
	$pageCount = getContent( $url, '找到 ', ' 个网页(用时' );
	//$pageCount = intval( str_replace( ',', '', $pageCount ) );
	$body      = '<div align=left>' . $domain .  '在sohu上的搜索结果：找到相关网页约<b> ' . $pageCount .  "</b> 篇.&nbsp;&nbsp;<a href='http://www.sogou.com/web?query=" . $domain . "' target=_blank><font color=red><u>点击察看详细内容</u></font></a></div>";

	$arrayVar = array ( 'CHECK_CAT'  => 'dosohu',
						'RESULT_BODY'=> $body
					  );
	$template->deal( 'template/frameBody.tpl', $arrayVar );

	return $template->template;
}

function whois( $domain )
{
	global $template;
	
	$allowed = '';
	$returnStr = '';
	$i = cWhois( $domain, $domext = '', $Reg = '');
	if( ( $i == 0 ) || ( $i == 1 ) )
	{
		foreach ( $Reg as $line )
		{
			$returnStr .= $line . '<br>';
		}
	}
	else
	{
		$returnStr = 'Could not get the whois info...';
	}

	$arrayVar = array ( 'WHOIS_INFO'  => $returnStr );
	$template->deal( 'template/whoisBody.tpl', $arrayVar );

	return $template->template;
}


?>