"AsinSearch",
"Author" => "AuthorSearch",
"BrowseNode" => "BrowseNodeSearch",
"Keyword" => "KeywordSearch"
);
// --- SearchString array ---
$ArraySearchString = array(
17304 => "Disney World, Florida",
17359 => "Las Vegas",
17413 => "Washington, D.C."
);
// --- Sort type array ---
$ArraySort = array(
"Featured" => "+pmrank",
"Sales" => "+salesrank",
"Reviews" => "+reviewrank"
);
// --- Amazon function ---
function Amazon($SearchType, $SearchString, $Sort, $Mode, $Type, $Page, &$d_ar, &$i_ar) {
global $AssociatesID;
global $DevToken;
// --- Build XML Link ---
$xmlFeed = 'http://xml.amazon.com/onca/xml3?t=' .$AssociatesID;
$xmlFeed .= '&dev-t=' .$DevToken;
$xmlFeed .= '&' .$SearchType;
$xmlFeed .= '=' .$SearchString;
$xmlFeed .= '&mode=' .$Mode;
$xmlFeed .= '&sort=' .$Sort;
$xmlFeed .= '&offer=All&type=' .$Type;
$xmlFeed .= '&page=' .$Page. '&f=xml';
// echo $xmlFeed. '
';
// --- Include the cache package ---
// IMPORTANT - enter the path to Lite.php
require_once("your-path-to/Lite.php");
// --- Set an ID for this cache ---
$id = $xmlFeed;
/**
* Cache options
* "lifeTime" is in seconds, so 1 hour would be 60*60*1
*
* IMPORTANT - enter the path to your cache directory (a new directory with full permissions)
*/
$options = array(
"cacheDir" => "your-path-to-cache-directory/",
"lifeTime" => 60*60*1
);
$objCache = new Cache_Lite($options);
// Check to see if there is a valid cache of xml
if ($xmlCache = $objCache->get($id)) { // there is a cache, so parse cached xml
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parse_into_struct($parser,$xmlCache,&$d_ar,&$i_ar);
xml_parser_free($parser);
}else{
$data = @implode("",file($xmlFeed));
if(!strpos($data, 'xml')){ // there is no XML data in the string (Amazon's Web Services are down)
return false;
} else { // there is XML data, so parse the XML
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parse_into_struct($parser,$data,&$d_ar,&$i_ar);
xml_parser_free($parser);
// --- Cache the XML ---
$objCache->save($data, $id);
}
}
}
?>