// include libraries here...
header('Content-type: text/html; charset=utf-8');
if ( !isset($q) ) { $q = ''; }
if ( get_magic_quotes_gpc() )
{
$q = stripslashes($q);
}
$q = str_replace('"', ' ', $q);
$q = trim($q);
$q = ucfirst($q);
$key = 'YOUR_GOOGLE_API_KEY';
$soapclient = new soapclient('http://api.google.com/search/beta2');
$g_db = openDatabase();
?>
if ($q != '')
{
$sCache = getQueryFromCache($q);
if ($sCache == '')
{
$person = $q;
$foundHusband = false;
$arrFamily = array('father', 'mother', 'uncle', 'aunt', 'brother', 'sister', 'husband', 'wife', 'son', 'daughter');
foreach ($arrFamily as $familyRelation)
{
if ( ! ($foundHusband && $familyRelation == wife) )
{
$s = getFamilyResults($soapclient, $key, $familyRelation, $q, 'was');
if ($s == '') { $s = getFamilyResults($soapclient, $key, $familyRelation, $q, 'is'); }
if ($s == '') { $s = getFamilyResults($soapclient, $key, $familyRelation, $q, 'had'); }
if ($s == '') { $s = getFamilyResults($soapclient, $key, $familyRelation, $q, 'has'); }
if ($s != '' && $familyRelation == 'husband')
{
$foundHusband = true;
}
if ($s == '' && $familyRelation == 'husband')
{
}
else
{
if ($s == '')
{
$s = "
• nothing was found";
$s = str_replace("s's", "s'", $s);
}
$s = '
' . $s . '
';
echo $s;
$sCache .= $s;
}
}
}
addQueryToCache($q, $sCache);
}
else
{
echo $sCache;
}
}
?>
closeDatabase($g_db);
function getFamilyResults(&$soapclient, $key, $familyRelation, $person, $state, $cutTrash = true)
{
$s = '';
$start = 0;
$maxGoodOnes = 2;
if ($familyRelation == 'uncle' || $familyRelation == 'aunt' || $familyRelation == 'brother' || $familyRelation == 'sister')
{
$maxGoodOnes = 1;
}
$q = "\"$person's $familyRelation $state\"";
$q = str_replace("s's", "s'", $q);
$start1 = "$person's " . ucfirst($familyRelation) . " $state";
$start2 = "$person's " . strtolower($familyRelation) . " $state";;
$parameters = array(
"key" => $key,
"q" => $q,
"start" => $start,
"maxResults" => 10,
"filter" => true,
"restrict" => "",
"safeSearch" => false,
"lr" => "",
"ie" => "",
"oe" => ""
);
$result = $soapclient->call('doGoogleSearch', $parameters, 'urn:GoogleSearch');
$searchtime = $result['searchTime'];
$begin = $start + 1;
$end = $start + $parameters["maxResults"];
$total = $result["estimatedTotalResultsCount"];
$searchComments = $result["searchComments"];
$searchTips = $result["searchTips"];
if ($total > 0)
{
$oldSnippet = '';
$result = $result["resultElements"];
$n = 0;
for ($i = 0; $i < $parameters['maxResults'] && $goodOnes < $maxGoodOnes; $i++)
{
$element = $result[$i];
$snippet = $element['snippet'];
$snippet = prepareContent($snippet);
$newSnippet = getTextBetween($snippet . '.', $start1, '.');
if ($newSnippet == '') { $newSnippet = getTextBetween($snippet . '.', $start2, '.'); }
if ($newSnippet == '') { $newSnippet = getTextBetween( strtolower($snippet . '.'), strtolower($start1), '.'); }
if ($newSnippet == '') { $newSnippet = getTextBetween( strtolower($snippet . '.'), strtolower($start2), '.'); }
$newSnippet = trim($newSnippet);
if ($cutTrash)
{
if ( !(strpos($newSnippet, '?') === false) ) { $newSnippet = ''; }
if ( !(strpos($newSnippet, '(') === false) ) { $newSnippet = ''; }
if ( !(strpos($newSnippet, 'http://') === false) ) { $newSnippet = ''; }
if ( !(strpos($newSnippet, 'www') === false) ) { $newSnippet = ''; }
}
if ($newSnippet != '' && $newSnippet != $oldSnippet)
{
$goodOnes++;
$s .= '• ' . $newSnippet . '