Просмотр файла google/search.php

Размер файла: 3.93Kb
<?
require("config.php");
require("nusoap.php");
require("code.php");

$langCHK = array("", "", "");
$search = $_GET["keywords"];
$lang = $_GET["lang"];
$start = $_GET["start"];

if(!is_numeric($start)) $start = 0;
$start = abs($start);

if($search <> "") {
	switch($lang) {
		case "lang_en":
			$langCHK[2] = " checked";
			break;
		case "lang_en":
			$langCHK[1] = " checked";
			break;
		default:
			$langCHK[0] = " checked";
	}
	
	$BadWords = split("\|", $BadWords);
	foreach($BadWords as $aBadWords) {
		if(stristr($search, $aBadWords)) {
			die("Ryan Bridgers.com");
		}
	}
	
	$soap = new soapclient($googleWSDL, true);
	$soap->decodeUTF8(false);

	$params = array(
		'key' => $googleAPIKey,		// Google license key This is a valid license. But get your own license, by going to www.google.com/api
		'q'   => $search,			// search term
		'start' => $start,			// start from result n
		'maxResults' => 10,			// show a total of n results
		'filter' => true,			// remove similar results
		'restrict' => '',			// restrict by topic
		'safeSearch' =>true,		// remove adult links
		'lr' => $lang,				// restrict by language
		'ie' => 'UTF-8',			// input encoding
		'oe' => 'UTF-8'				// output encoding
	);
	
	$res = $soap->call("doGoogleSearch", $params, "urn:GoogleSearch", "urn:GoogleSearch");

	$totalCount = $res["estimatedTotalResultsCount"];
	$searchTime = $res["searchTime"];
	$startIndex = $res["startIndex"];
	$endIndex = $res["endIndex"];
	
	if($totalCount == 0) {
		$output = "<hr>Sorry, <b>$search is not in our database</b>";
	}
	else {
		$output = "<hr> Number of results: <b>$totalCount</b> Results: <b>$startIndex</b>  -   <b>$endIndex</b>  Page generated in <b>$searchTime</b>  second(s).  <br><br> ";
	}
	
	if(is_array($res["resultElements"])) {
		foreach($res["resultElements"] as $item) {
			$DocSize = $item["cachedSize"];
			$DocSnippet = u2g($item["snippet"]);
			$DocURL = u2g($item["URL"]);
			$DocTitle = u2g($item["title"]);
	
			$DocTitle = ($DocTitle == "") ? "Does not have the title" : $DocTitle;
			
			if($DocSnippet <> "")
				$DocSnippet .= "<br>";
			
				$output .= "<a href=\"$DocURL\">$DocTitle</a><br>";
				$output .= "$DocSnippet<span class=g>$DocURL - $DocSize </span>";
				$output .= " <span snap='$DocURL' class=hand>[ Snapshot looks at in advance ]</span><br><br>";
		}
	}
}
else {
	$langCHK[2] = " checked";
}

$output = preg_replace("/<B>\.\.\.<\/B>/is", "...", $output);
$output .= "<div align=center>";

$theUrl = "<a href=\"" . $_SERVER["PHP_SELF"] . "?keywords=$search&lang=$lang&start=";
if($start > 9)
	$output .= $theUrl . ($start - 10) . "\">Previous page</a> ";
if($endIndex - $startIndex == 9)
	$output .= $theUrl . ($start + 10) . "\">Next page</a> ";

$output .= "<hr><span class=h>$Copyright</span></div>";
?>

<html>
<head>
<title>RyanBridgers.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
* {font-size: 12px;line-height:1.3}
b {color:#0000CC}
hr {color:#0000CC}
.g{color:green}
.h {color: #333}
.h a {color: #333;text-decoration:none}
.h a:visited {color: #666;text-decoration:none}
.h a:hover {color: #f33;text-decoration:underline overline}
.hand {cursor:hand;color:#00f}
.style1 {color: #E0DFE3}
-->
</style>
</head>
<body leftmargin="50" topmargin="0" onload="document.frmSearch.keywords.focus();document.frmSearch.keywords.select()">
<CENTER>
  <form method="GET" action="<?=$_SERVER["PHP_SELF"]?>" name=frmSearch>
    <a href="http://ryanbridgers.com"><img src="img/logo_sm.gif" border="0" alt="Google" align="absmiddle"> </a>
    <input type=text name="keywords" maxLength=256 size=50 value="<?=rawurldecode($search)?>"> <input type="submit" value="Search"> 
<input type=submit value="Search in the results" onClick="document.frmSearch.keywords.value+=' '+KWD">
<br>
</form>
</CENTER>
<p>
  <script src="showcache.js"></script>
  <?=$output?> 
</p>
</body>
</HTML>