File: //home/awaldron/public_html/archive/demo/search/index.php
<?php
/////////////////////////////////////////////////
// HEADER ///////////////////////////////////////
// this calls the header file for the page template
//
// replace the contents of this file to match your website...
// or simply replace the include below with the include to your template header
include ("templates/header.php");
/////////////////////////////////////////////////
// setup starting position for search
// we're either 1 less than retrieved page, or 0 as a starting index)
if (!empty($_GET['p']))
{
$page = intval($_GET['p']);
$start = ($page-1) * 10;
}
else
{
$start = 0;
$page = 1;
}
// general includes
include ("class/nusoap.php");
include ("class/search.class.php");
include ("config/config.php");
include ("includes/functions.php");
include ("lang/$sys_lang.php");
// instantiate soap client object
$soap = new soapclientx($apiurl);
// instantiate search object
$search = new searchGoogle($apikey, $search_safe, $search_lang, $start, $search_attempts, &$soap, $GoogleOptions, &$language, $search_site);
// draw important
echo $search->searchform();
// get query and clean input
if (!empty($_GET['q'])) $q = stripslashes($_GET['q']);
if (!empty($q))
{
// successful search
if($search->search($q))
{
$return = $search->return;
// start index
$result_start = $return['startIndex'];
// end index
$result_end = $return['endIndex'];
// total number of results
$result_total = $return['estimatedTotalResultsCount'];
// seconds to complete request
$result_secs = round($return['searchTime'],2);
// we have results
if ($result_end)
{
// process search details
$search_details = sprintf ($language['search_details'], $result_start, $result_end, $result_total, $q, $result_secs);
include ("templates/search-details.php");
$count = $start;
foreach($return['resultElements'] as $value)
{
// increment count
$count++;
// clean url
$value['URL'] = str_replace('http://', '', $value['URL']);
$title = $value['title'];
$url = $value['URL'];
// snip url if it's too long
if (strlen($value['URL']) > $search_url_length_max)
$url_snipped = str_replace('http://', '', substr($value['URL'], 0, $search_url_length_max)) . "...";
else
$url_snipped = $value['URL'];
$snippet = $value['snippet'];
// output result item
include ("templates/search-result.php");
}
// get page number listing html
$pagination = $search->pagination($q, $page, $result_total, $page_separator);
// output pagination html if it exists
if (!empty($pagination))
echo ("<div class='search_pages'>" . $language['search_pages'] . " <b>" . $pagination . "</b></div>");
}
// no results found in the array, let's do a spell check
else
{
// process search details
$search_details = sprintf($language['search_noresults'], $q);
// do spelling search
if ($result = $search->exec_spell($q))
{
if (is_array($search->spell))
$spelling = $search->spell[0];
else
$spelling = $search->spell;
if (!empty($spelling))
{
// create search URL
$search_url = "<a href=\"index.php?q=" . urlencode($search->spell) . "\">" . $spelling . "</a>";
// output spelling search language
$search_details .= " " . sprintf($language['search_spelling'], $search_url);
}
else
{
$search_details .= " " . $language['search_again'];
}
}
// no results found message
include ("templates/search-details.php");
}
}
// search failed
// output errors and spellling suggestion
else
{
if ($showerrors || $showmessages)
{
echo ("<div class='search_title'>" . $language['fail_title'] . "</div>");
if ($showerrors)
echo (outputarray($search->errors));
if ($showmessages)
echo (outputarray($search->messages));
}
}
}
/////////////////////////////////////////////////
// FOOTER ///////////////////////////////////////
// this calls the footer file for the page template
//
// replace the contents of this file to match your website...
// or simply replace the include below with the include to your template footer
include ("templates/footer.php");
/////////////////////////////////////////////////
?>