"Categories","searchindex"=>SEARCHINDEX); } if( !defined('PERMASEP') ){ define("PERMASEP", '-'); } if( !defined('ROOTPERMA') ){ define("ROOTPERMA", 'products/'); } if( !isset($categoryperma) ){$categoryperma = "%%searchindex%%".PERMASEP."%%node%%/";} if( !isset($productperma) ){$productperma = "%%asin%%";} class AWS{ public $AWSAccessKeyId = ''; public $associateId = ''; public $AWSSecretKey = ''; public $soapClient = ''; public $validate = 'false'; public $SearchIndex = ''; public $Locale = 'US'; public $noPicURL = 'http://g-images.amazon.com/images/G/01/stores/sports-outdoors/sports-no-image.gif'; public $ResponseGroup_Products = "Images,ItemAttributes,OfferFull,EditorialReview,Reviews"; public $ResponseGroup_Item = "Small,Accessories,BrowseNodes,EditorialReview,Images,ItemAttributes,Offers,Reviews,Similarities,SalesRank,Tracks,VariationSummary,Variations"; public $ResponseGroup_Reviews = "ItemAttributes,Reviews"; public $ResponseGroup_Image = "Images,ItemAttributes"; public $cartinfo = array(); public $cartsize = 0; public $cookie = ''; public function __construct($AWSAccessKeyId, $associateId,$AWSSecretKey,$SearchIndex="Electronics",$Locale="US"){ $this->AWSAccessKeyId = $AWSAccessKeyId; $this->associateId = $associateId; $this->AWSSecretKey = $AWSSecretKey; $this->SearchIndex = $SearchIndex; $this->Locale = $Locale; $this->cookie = (empty($_COOKIE[COOKIE_NAME])) ? null : $_COOKIE[COOKIE_NAME]; $this->cookie = (empty($_SESSION[COOKIE_NAME])) ? $this->cookie : $_SESSION[COOKIE_NAME]; if (!is_null($this->cookie)) { $this->cartinfo = unserialize(stripslashes(($this->cookie))); $this->cartsize = $this->cartinfo[0]; } } public function __destruct(){} public function aws_call($action, $body){ # return $this->aws_call2($action, $body); $access_key_id = $this->AWSAccessKeyId; $associate_id = $this->associateId; $secret_access_key = $this->AWSSecretKey; $locale = $this->Locale; $locale_url = "$locale/"; if ($locale != 'US') { $locale_url = "$locale/"; } $wsdlurl = 'http://ecs.amazonaws.com/AWSECommerceService/2009-06-01/' . $locale_url . 'AWSECommerceService.wsdl'; $ckey = $action.md5(serialize($body)); $oCache = new Cache($ckey, (60*60*24)); if (!$oCache->Check()) { $timestamp = gmdate("Y-m-d\TH:i:s\Z"); $signature = $action . $timestamp; $signature = base64_encode(hash_hmac("sha256", $signature, $secret_access_key, True)); $useNusoap = 0; if (!defined('SOAP_1_2')) { $useNusoap = 1; } # $useNusoap = 1; if($useNusoap){ $client = new nusoap_client($wsdlurl, 'wsdl','', '', '', ''); $headers = "".$access_key_id."". "".$timestamp."". "".$signature.""; $result = $client->call($action, array($body), false, false, $headers); $oCache->Set($result); }else{ $client = new SoapClient($wsdlurl); $headers = array(); $headers[] = new SoapHeader('http://security.amazonaws.com/doc/2007-01-01/','AWSAccessKeyId',$access_key_id); $headers[] = new SoapHeader('http://security.amazonaws.com/doc/2007-01-01/','Timestamp',$timestamp); $headers[] = new SoapHeader('http://security.amazonaws.com/doc/2007-01-01/','Signature',$signature); $result = $client->__soapCall($action, array($body), NULL, $headers); $result = $this->object2array($result); $oCache->Set($result); } } $result = $oCache->Get(); return $result; } public function aws_call2($action, $body){ $access_key_id = $this->AWSAccessKeyId; $associate_id = $this->associateId; $secret_access_key = $this->AWSSecretKey; $locale = $this->Locale; $locale_url = "$locale/"; if ($locale != 'US') { $locale_url = "$locale/"; } $wsdlurl = 'http://ecs.amazonaws.com/AWSECommerceService/2009-06-01/' . $locale_url . 'AWSECommerceService.wsdl'; $ckey = $action.md5(serialize($body)); $oCache = new Cache($ckey, (60*60*24)); $timestamp = gmdate("Y-m-d\TH:i:s\Z"); $signature = $action . $timestamp; $signature = base64_encode(hash_hmac("sha256", $signature, $secret_access_key, True)); $useNusoap = 0; if (!defined('SOAP_1_2')) { $useNusoap = 1; } # $useNusoap = 1; if($useNusoap){ $client = new nusoap_client($wsdlurl, 'wsdl','', '', '', ''); $headers = "".$access_key_id."". "".$timestamp."". "".$signature.""; $result = $client->call($action, array($body), false, false, $headers); }else{ $client = new SoapClient($wsdlurl); $headers = array(); $headers[] = new SoapHeader('http://security.amazonaws.com/doc/2007-01-01/','AWSAccessKeyId',$access_key_id); $headers[] = new SoapHeader('http://security.amazonaws.com/doc/2007-01-01/','Timestamp',$timestamp); $headers[] = new SoapHeader('http://security.amazonaws.com/doc/2007-01-01/','Signature',$signature); $result = $client->__soapCall($action, array($body), NULL, $headers); $result = $this->object2array($result); } return $result; } public function signature($string){ $sig = ""; $timestamp = gmdate("Y-m-d\TH:i:s\Z"); $signature = $action . $timestamp; $signature = base64_encode(hash_hmac("sha256", $signature, $secret_access_key, True)); return $sig; } public function object2array($object) { if (!is_object($object) && !is_array($object)) { return $object; } $array = (array)$object; foreach ($array as $key => $value) { $array[$key] = $this->object2array($value); } return $array; } public function array2object($array) { if (!is_array($array)) { return $array; } foreach ($array as $key => $value) { $array[$key] = $this->array2object($value); } return (object)$array; } public function help($type, $about, $responseGroups){ $helpRequest = array( "About" => $about, "HelpType" => $type ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $helpRequest, "Request" => $helpRequest ); return($this->aws_call("Help",$requestOptions)); } public function getSingleProductInfo($asin) { $itemSearchRequest = array( "ItemId" => $asin, // "ResponseGroup" => explode(",",$this->ResponseGroup_Item), "ResponseGroup" => array( "Small", "Accessories", "BrowseNodes", "EditorialReview", "Images", "ItemAttributes", "Offers", "Reviews", "Similarities", "SalesRank", "Tracks", "Variations" ) ); $itemSearchOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $itemSearchRequest, "Request" => $itemSearchRequest ); $result = $this->aws_call("ItemLookup",$itemSearchOptions); // echo "
".print_r($result,true)."
"; return($result['Items']); } public function getItemsFromBrowseNode($browseNode, $itemPage) { $itemSearchRequest = array( "SearchIndex" => $this->SearchIndex, "BrowseNode" => $browseNode, //"ItemPage" => array($itemPage), //"ResponseGroup" => array("Large") //"ResponseGroup" => array("Images","ItemAttributes","OfferFull") ); $itemSearchRequest2 = array( "SearchIndex" => $this->SearchIndex, "ItemPage" => $itemPage, "ResponseGroup" => array("Images","ItemAttributes","OfferFull") ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $itemSearchRequest, "Request" => array($itemSearchRequest, $itemSearchRequest2) ); $result = $this->aws_call("ItemSearch",$requestOptions); //echo "
".print_r($result, true)."
"; return "debug"; return($result['Items'][1]); } public function getBrowseNodeName($browseNodeId) { $browseNodeLookupRequest = array( "BrowseNodeId" => $browseNodeId, "ResponseGroup" => array("BrowseNodeInfo"), ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "XMLEscaping" => "Single", "Shared" => $browseNodeLookupRequest, "Request" => $browseNodeLookupRequest ); $request = $this->aws_call("BrowseNodeLookup",$requestOptions); return(strtolower($request['BrowseNodes']['BrowseNode']['Name'])); } /* ItemSearch has too many parameters, instead write wrapper functions for needed functionality */ public function itemSearch($keywords,$searchindex, $itemPage){ $deliveryMethod = array( ); $itemSearchRequest = array( "Keywords" => $keywords, "ResponseGroup" => array("Images","ItemAttributes","OfferFull"), "SearchIndex" => $searchindex, "ItemPage" => $itemPage ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $itemSearchRequest, "Request" => $itemSearchRequest ); $result = $this->aws_call("ItemSearch",$requestOptions); return $result; } /* depending on type of item lookup, there may be a need for wrappers here */ public function itemLookup($itemId) { $itemLookupRequest = array( "ItemId" => $itemId ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $itemSearchRequest, "Request" => $itemSearchRequest ); return($this->aws_call("ItemLookup",$requestOptions)); } public function getMenuItems($nodeid){ $return = ''; $data = $this->browseNodeLookup($nodeid,'BrowseNodeInfo'); $data = $data['BrowseNodes']['BrowseNode']['Children']['BrowseNode']; foreach($data as $record => $object) { $return[] = $object; } return $return; } public function browseNodeLookup($browseNodeId, $responseGroups) { $browseNodeLookupRequest = array( "BrowseNodeId" => $browseNodeId, "ResponseGroup" => $responseGroups, ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "XMLEscaping" => "Single", "Shared" => $browseNodeLookupRequest, "Request" => $browseNodeLookupRequest ); return($this->aws_call("BrowseNodeLookup",$requestOptions)); } public function getNewReleases($nodeid){ $browseNodeLookupRequest = array( "BrowseNodeId" => $nodeid, "ResponseGroup" => array("NewReleases"), ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "XMLEscaping" => "Single", "Shared" => $browseNodeLookupRequest, "Request" => $browseNodeLookupRequest ); $result = $this->aws_call("BrowseNodeLookup",$requestOptions); //print_r($result); return($result['BrowseNodes']['BrowseNode']['NewReleases']['NewRelease']); } public function getTopSellers($nodeid){ $browseNodeLookupRequest = array( "BrowseNodeId" => $nodeid, "ResponseGroup" => array("NewReleases"), ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "XMLEscaping" => "Single", "Shared" => $browseNodeLookupRequest, "Request" => $browseNodeLookupRequest ); $result = $this->aws_call("BrowseNodeLookup",$requestOptions); # print_r($result); return($result['BrowseNodes']['BrowseNode']['TopItemSet']['TopItem']); } public function cartCreate($itemId){ $CartCreateRequest = array( "Items" => array( "Item"=> array( "ASIN" => $itemId, "Quantity" => 1, "AssociateTag" => $this->associateId ) ) ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $CartCreateRequest, "Request" => $CartCreateRequest ); return($this->aws_call2("CartCreate",$requestOptions)); } public function cartAdd($ItemId){ $cartId = $this->cartinfo[1]; $hmac = $this->cartinfo[2]; $CartAddRequest = array( "CartId" => $cartId, "HMAC" => $hmac, "Items" => array( "Item"=> array( "ASIN" => $ItemId, "Quantity" => 1, "AssociateTag" => $this->associateId ) ) ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $CartAddRequest, "Request" => $CartAddRequest ); return($this->aws_call2("CartAdd",$requestOptions)); } public function cartModify($postarray){ $cartId = $this->cartinfo[1]; $hmac = $this->cartinfo[2]; $CartModifyRequest = array( "CartId" => $cartId, "HMAC" => $hmac, "Items" => array() ); $items = array(); foreach( $postarray as $name=>$change ){ $change=strtolower(trim($change)); $pieces=explode('_', $name); if ($pieces[0] == 'item') { if (is_numeric($change)) { $items[] = array( "CartItemId" => $pieces[3], "Quantity" => $change, ); } } } $CartModifyRequest['Items'] = $items; $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $CartModifyRequest, "Request" => $CartModifyRequest ); return($this->aws_call2("CartModify",$requestOptions)); } public function cartGet($cartId,$hmac){ $cartId = $this->cartinfo[1]; $hmac = $this->cartinfo[2]; $CartGetRequest = array( "CartId" => $cartId, "HMAC" => $hmac, ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $CartGetRequest, "Request" => $CartGetRequest ); return($this->aws_call2("CartGet",$requestOptions)); } public function cartClear($cartId,$hmac){ $cartId = $this->cartinfo[1]; $hmac = $this->cartinfo[2]; $CartClearRequest = array( "CartId" => $cartId, "HMAC" => $hmac, ); $requestOptions = array( "AWSAccessKeyId" => $this->AWSAccessKeyId, "SubscriptionId" => $this->associateId, "Validate" => $this->validate, "Shared" => $CartClearRequest, "Request" => $CartClearRequest ); return($this->aws_call2("CartClear",$requestOptions)); } public function displayPageNumbers($products, $currentPage){ $category_name = $this->SearchIndex; $return = null; $return .= "
"; if($currentPage != 1) { $return .= "|<  "; $return .= ""; } $return .= "« Previous"; if($currentPage != 1) { $return .= ""; } $return .= "
"; $return .= "
"; if($currentPage != $products['TotalPages']) { $return .= ""; } $return .= "Next »"; if($currentPage != $products['TotalPages']) { $return .= ""; $return .= " >|"; } $return .= "
"; $return .= '"; return $return; } public function displayPageNumbers2($products, $currentPage){ $catinfo = $this->browseNodeLookup(ROOTCAT, 'BrowseNodeInfo'); $category_name = $catinfo['BrowseNodes']['BrowseNode']['Name']; // $products = $aws->itemSearch($_GET['search_query'],SEARCHINDEX); if( !isset($products['TotalPages']) ) $products['TotalPages'] = $products['Items']['TotalPages']; $url = "/search.php?search_query=".$_GET['search_query']; if( isset($_GET['category']) ) $url = $url."&category=".$_GET['category']; $return = null; if( $products['TotalPages'] > 1 ){ $limit = 5; if( $products['TotalPages'] < $limit) $limit = $products['TotalPages']; $return .= "
"; if($currentPage != 1) { $return .= "|<  "; $return .= ""; } $return .= "« Previous"; if($currentPage != 1) { $return .= ""; } $return .= "
"; $return .= "
"; if($currentPage != $limit) { $return .= ""; } $return .= "Next »"; if($currentPage != $limit) { $return .= ""; $return .= " >|"; } $return .= "
"; $return .= '"; } return $return; } public function GetCartSize() { return $this->cartsize; } public function KillCookie() { unset($_SESSION[COOKIE_NAME]); setcookie(COOKIE_NAME, '', time()-10000); } public function SetCartCookie($cartarray) { $cart_encoded=serialize($cartarray); $cookie_expiration=time()+60*60*24*COOKIE_EXPIRATION; $_SESSION[COOKIE_NAME]=$cart_encoded; setcookie(COOKIE_NAME, $cart_encoded, $cookie_expiration); $this->cartsize = $cartarray[0]; $this->cartinfo = $cartarray; return true; } } ?>