//you can use this version under any version of the GPL (GNU Public License) error_reporting(error_reporting()&~E_NOTICE); //this prevents a lot of warnings on a Windows server, but you can comment-out this line for debugging $Amicrotime['total'][0]=getmicrotime(); //time at start of total process $tab=' '; //tab how much? if (!defined($jaap)) $jaap=$false; //($_SERVER['PHP_SELF']=='/jaap/php/amazon/amazonv4.php5' or $_SERVER['PHP_SELF']=='/jaap/php_linux/amazon/amazonv4.php5'); //I use this flag to develop new things for the script on my local PC. $jb=false; //this is a test for someone, please change it to false if it isn't already //Set these to correspond with your site. //This will determine the first results that the user will see. //The user can overrule them using the search form. $Adefault=array( 'language' =>'en', //what language to render the page in 'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us 'page' =>1, //first page to show (we are counting from 1 not 0) 'jaap' =>false, //my own debugflag to test new things 'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending 'show_url' =>false, //debug: show XML request url to be send to Amazon? 'show_xml' =>false, //debug: show incoming XML code from Amazon? ); require_once "data.php5"; //static data about Amazon (servers, search fields) v3- require_once "data_v4.php5"; //static data about Amazon (servers, search fields) v4+ require_once "language.php5"; //translate the output to the prefered language of the user require_once "aws.php5"; //see: http://mierendo.com/software/aws_signed_query/, please note that I'm using an slightly adapted version of the script: I do my own XML-interpreting $Aassociates_id=array( 'de'=>'modellocate-20' , // <-- replace with your amazon.de associate ID, or leave it as it is 'fr'=>'modellocate-20', // <-- replace with your amazon.fr associate ID, or leave it as it is 'jp'=>'modellocate-20' , // <-- replace with your amazon.co.jp associate ID, or leave it as it is 'uk'=>'modellocate-20' , // <-- replace with your amazon.co.uk associate ID, or leave it as it is 'us'=>'modellocate-20' , // <-- replace with your amazon.com associate ID ); $f_user_search=false; //add a user search form and allow user searches? if ($jaap) { print_array($_GET,$tab); } //what are the user's prefered languages? $Ahttp_lang=split(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); if ($jaap) { print_array($Ahttp_lang,$tab); } //try to find the visitor's prefered language, this is still experimental foreach ($Ahttp_lang as $i=>$d) { if ($Axl[$l=substr($d,0,2)]) { $pref_lang=$l; break; } } if (isset($pref_lang)) { $Adefault['language']=$pref_lang; if ($jaap) { echo $tab."prefered available language='$pref_lang'
\n"; } } //for all parameters see if the user has overruled it or use the default foreach ($Adefault as $i=>$d) { $$i=isset($_GET[$i])?$_GET[$i]:$d; if ($jaap) echo $tab."$i = '".$$i."'
\n"; } //this is a test for someone: if ($jb) { $operation ='SellerListingSearch'; $show_array=1; } if (isset($_GET['ASIN'])) { $readid =$_GET['ASIN']; } else { $readid = 'B0012YA85A'; } $parameters=array( 'Operation' =>'SimilarityLookup' , 'Service' =>'AWSECommerceService' , //'IdType' => 'ASIN', 'SearchIndex' =>$_GET['SearchIndex'] , //Books for example. //"$searchparameter"=>$searchparameterdata , //'ItemPage' =>$page , //which page? //'ASIN' =>'1584281782' , 'ItemId' =>$readid , 'ResponseGroup' =>'Medium' , //Small, Medium, Large or SellerListing 'MerchantId' => 'All' ); $A=aws_request($parameters); //do the AWS request via cache and decode the XML //debug: if ($jaap) { echo $tab."
\n"; echo $tab."
\n";
  print_r    ($A);
  echo $tab."
\n"; echo $tab."
\n"; print_array($A); echo $tab."
\n"; } $Amicrotime['XML'][1]=getmicrotime(); //time after XML decoding if ($show_array) { //show the array for debugging? print_array($A,$tab); //show the complete array } //show the stuff $Amicrotime['show'][0]=getmicrotime(); //time before showing stuff //echo $tab."

".xu('searching for')." '$searchparameterdata'

\n"; //you can change the h2's to h1's if (isset($A->Error)) { $c=$A->Error->Code; $e=$A->Error->Message; echo $tab."Amazon error: $c: $e
\n"; } else if ($A->Items->Request->IsValid!='True') { $c=$A->Items->Request->Errors->Error->Code; $e=$A->Items->Request->Errors->Error->Message; echo $tab."Amazon error: $c: $e
\n"; } else { print_products($A,$tab); } //print all the products function print_products($A,$tab='') { global $jaap; global $language; global $locale; global $operation; global $page; global $search; global $searchparameter; global $searchparameterdata; switch ($operation) { case 'SellerListingSearch': die("sorry but SellerListingSearch doesn't work yet"); $items =$A['SellerListingSearchResponse']['SellerListings']; $subnode='SellerListing'; break; default: if ($jaap) { echo $tab."in print_products():
\n"; echo $tab."A:
\n"; print_array($A,$tab=''); } $items =$A ->Items; $aitems=(array)$items; //it is very strange that this and the next line works and not the outcommented line before this one $items_sub=$aitems['Item']; if ($jaap) { echo $tab."items:
\n"; echo $tab."
\n";
      print_r($items);
      echo $tab."
\n"; echo $tab."items:
\n"; print_array($items,$tab=''); echo $tab."items->Item:
\n"; echo $tab."
\n";
      print_r($items->Item);
      echo $tab."
\n"; echo $tab."items->Item:
\n"; print_array($items->Item,$tab=''); echo $tab."items_sub:
\n"; echo $tab."
\n";
      print_r($items_sub);
      echo $tab."
\n"; echo $tab."items_sub:
\n"; print_array($items_sub,$tab=''); } break; } $npro=$items->TotalResults; $npag=$items->TotalPages; // head goes here --------------------------- //send html-header so utf8's are correctly shown $EditorialReviews=$items_sub[0]->EditorialReviews ; $EditorialReview=$EditorialReviews->EditorialReview ; echo "\n"; echo ' '; echo " "; include $_SERVER['DOCUMENT_ROOT'].'/php/allhead.php'; echo ''.$items_sub[0]->ItemAttributes->Title.''; echo ''; echo " "; echo " "; include $_SERVER['DOCUMENT_ROOT'].'/php/header.php'; echo $tab."\n"; echo ''; echo $tab." \n"; if (is_array($items_sub) and $items_sub[0]) { foreach ($items_sub as $i=>$E) { if ($bgcolor != "#FFFFFF") { $bgcolor="#FFFFFF"; } else { $bgcolor="#FFFFCC"; } print_product($E,$tab.' ',$bgcolor); } } else { print_product($D,$tab.' '); } echo $tab." \n"; echo $tab."

\n"; //provide links to previous and next page if ($npag>1) { echo $tab.xu('page:')."\n"; echo $tab.make_link_to_page(1,1)."\n"; echo $tab.make_link_to_page(2,2)."\n"; if ($page>=2) { echo $tab.make_link_to_page($page-1,'<')."\n"; } if ($page<$npag) { echo $tab.make_link_to_page($page+1,'>')."\n"; } echo $tab.make_link_to_page($npag,$npag)."\n"; } } //print one Amazon product //version 4 function print_product($E,$tab, $bgcolor) { global $jaap; global $locale; if ($E) { if ($jaap) echo $tab."print_product()
\n"; $url=$E->DetailPageURL; if ($jaap) echo $tab."url=$url
\n"; $E2A=(array)$E; $url=$E2A['DetailPageURL']; if ($jaap) echo $tab."url=$url
\n"; if ($jaap) print_array($E2A); echo $tab. "\n"; echo $tab. " \n"; if ($d=$E->MediumImage) { $iu=$d->URL; $ih=$d->Height; $iw=$d->Width; echo $tab. " \n"; } else { // no medium image? // look for a small one if ($d=$E->SmallImage) { $iu=$d->URL; $ih=$d->Height; $iw=$d->Width; echo $tab. " \n"; } else { if ($d=$E->TinyImage) { $iu=$d->URL; $ih=$d->Height; $iw=$d->Width; echo $tab. " \n"; } } } echo $tab. " \n"; echo $tab. " \n"; if ($d=$E->ItemAttributes->Title) { echo $tab. " $d
\n"; } if (is_array($dd=$E->ItemAttributes->Author)) { echo $tab. " ".xl('by').": "; foreach ($dd as $i=>$d) { if ($i) echo ', '; //echo $tab."$d"; } echo "
\n"; } else if ($d=$dd) { echo $tab. " ".xl('by').": $d
\n"; } $dm=$E->ItemAttributes->Publisher; $dr=$E->ItemAttributes->PublicationDate; if ($dm or $dr) { echo $tab. " "; if ($dm) { echo xl('publisher').": $dm"; } if ($dm and $dr) echo ', '; if ($dr) { echo xl('published').": $dr"; } echo "
\n"; } if ($asin=$E->ASIN) { echo $tab. "ASIN: $asin
\n"; } if ($ean=$E->ItemAttributes->EAN) { echo $tab."EAN: $ean
\n"; } $da=false; //don't show $ds=$E->SalesRank; if ($da or $ds) { echo $tab. " "; if ($ds) echo xl('sales rank').": ".number_format($ds).""; if ($da and $ds) echo ", "; if ($da) echo $tab.xl('customer rating').": ".(($da-1)*25)."%"; echo "
\n"; } $do=$E->OfferSummary->LowestNewPrice ->FormattedPrice; $du=$E->OfferSummary->LowestUsedPrice->FormattedPrice; if ($do or $du) { echo $tab. " ".xl('price').": "; if ($do) echo "$do (".xl('new').")"; if ($do and $du) echo ", "; if ($du) echo "$du (".xl('used').")"; echo "
\n"; } echo $tab. " \n"; if ($EditorialReviews=$E->EditorialReviews and $EditorialReview=$EditorialReviews->EditorialReview and $Content=$EditorialReview->Content) { echo $tab. " \n"; echo $tab. " $Content\n"; echo '

More like: '.substr($E->ItemAttributes->Title,0,100).''; echo $tab. " \n"; } echo $tab. "\n"; echo '
'; } } //make link to other page (next, previous etc.) function make_link_to_page($page,$s) { global $language; global $locale; global $search; global $searchindex; global $searchparameter; global $searchparameterdata; return "".xu($s).""; } //print an array or object //(for debugging) function print_array($A,$tab='') { if (is_object($A)) { echo $tab."object:
\n"; print_array((array)$A,$tab); } else if (is_array($A)) { echo $tab."\n"; echo $tab." \n"; foreach ($A as $i=>$d) { echo $tab." \n"; echo $tab." \n"; if (is_string($d)) { echo $tab." \n"; } else if (is_array($d)) { echo $tab." \n"; } else if (is_object($d)) { echo $tab." \n"; } else { echo $tab." \n"; } echo $tab." \n"; } echo $tab." \n"; echo $tab."
$i".htmlentities($d)."\n"; print_array($d,$tab.' '); echo $tab." object:\n"; print_array((array)$d,$tab.' '); echo $tab." ".htmlentities($d)."
\n"; } else { echo $tab."warning: not-an-array-or-object given to print_array()
\n"; } } function getmicrotime() { list($us,$s)=explode(' ',microtime()); return (float)$us+(float)$s; } if ($f_user_search ) { //the next section adds a search box for the users echo $tab. "
\n"; echo $tab. "
\n"; //echo $tab." \n"; //echo $tab." \n"; //echo $tab." Search type
\n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. " \n"; echo $tab. "
".xu('language for page:')."\n"; echo $tab. " \n"; echo $tab. "
".xu('which server:')."\n"; echo $tab. " \n"; echo $tab. "
".xu('operation:')."\n"; echo $tab. " \n"; echo $tab. "
".xu('product category:')."\n"; echo $tab. " \n"; echo $tab. "
".xu('search parameter:')."\n"; echo $tab. " \n"; echo $tab. "
".xu('search string:')."
\n"; echo $tab. " \n"; echo $tab. "
\n"; //end of the search box section } //phpinfo(); $Amicrotime['show' ][1]=getmicrotime(); //time after showing $Amicrotime['total'][1]=getmicrotime(); //time at end //The next part is to show if the script isn't overburdoning your server. (The time waiting for Amazon isn't burdoning your server). You can remove the next part if you like: //echo $tab."
\n"; //echo("Time used for time-consuming parts:
\n"); //echo $tab."Time used:
\n"; //foreach ($Amicrotime as $i=>$d) { //if ($d[1]>$d[0]) { // printf($tab."- %.2f s %s
\n",$d[1]-$d[0],$i); //} //} //20091129/wjvg: you may remove these lines or move them to an about section of your site: //echo $tab."
\n"; //echo $tab."This script is GPL'ed and can be downloaded from this page.
\n"; include $_SERVER['DOCUMENT_ROOT'].'/php/connect1.php'; $forcead = TRUE; include $_SERVER['DOCUMENT_ROOT'].'/php/footer.php'; echo ' '; echo " \n"; echo "\n"; //end