# HG changeset patch
# User robert
# Date 1482930293 0
# Node ID a6b55ae706174f41980134bd6f4c2ac09b0b4da8
# Parent a5e5475bf357f6089f3e2b5337e1e0633217b755
original
diff -r a5e5475bf357 -r a6b55ae70617 xml/getAmazonInfo.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/xml/getAmazonInfo.php Wed Dec 28 13:04:53 2016 +0000
@@ -0,0 +1,553 @@
+'en', //what language to render the page in
+ 'locale' =>$localeIn, //which server's products? available: ca,de,fr,jp,uk,us
+//'mode' =>'books', //what product category?
+ 'page' =>1, //first page to show (we are counting from 1 not 0)
+//'search' =>'Machiavelli', //what to search for?
+ 'operation' =>'ItemLookup', //what to do? //ItemSearch
+ // 'searchindex' =>'Books', //what product category for search?
+ 'searchparameter' =>'ItemId', //what kind of search?
+ 'searchparameterdata'=>$isbn, //what to search for?
+ //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
+ '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?
+);
+//change the debug options to true if you want to activate them or call the script with '?show_array=true' to see what actual information you're getting from Amazon and how little my standard script is actually showing of it
+
+$Aassociates_id=array(
+ 'uk' => 'bookwhack-21',
+ 'us' => 'your02b-20',
+ 'ca' => 'book009-20',
+ 'de' => 'book04c-21',
+ 'fr' => 'book07f-21',
+);
+
+$Aserver=array(
+ 'ca' => array(
+ 'ext' => 'ca' , //Canadian normal server
+ 'nor' => 'http://www.amazon.ca' , //Canadian normal server
+ 'xml' => 'http://xml.amazon.com' , //Canadian xml server
+ ),
+ 'de' => array(
+ 'ext' => 'de' , //German normal server
+ 'nor' => 'http://www.amazon.de' , //German normal server
+ 'xml' => 'http://xml-eu.amazon.com', //German xml server
+ ),
+ 'fr' => array(
+ 'ext' => 'fr' , //French normal server
+ 'nor' => 'http://www.amazon.fr' , //French normal server
+ 'xml' => 'http://xml-eu.amazon.com', //French xml server
+ ),
+ 'jp' => array(
+ 'ext' => 'jp' , //Japanese normal server, not co.jp!
+ 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server
+ 'xml' => 'http://xml.amazon.com' , //Japanese xml server
+ ),
+ 'uk' => array(
+ 'ext' => 'co.uk' , //UK normal server
+ 'nor' => 'http://www.amazon.co.uk' , //UK normal server
+ 'xml' => 'http://xml-eu.amazon.com', //UK xml server
+ ),
+ 'us' => array(
+ 'ext' => 'com' , //USA normal server
+ 'nor' => 'http://www.amazon.com' , //USA normal server
+ 'xml' => 'http://xml.amazon.com' , //USA xml server
+ ),
+);
+
+//if(go != 1)
+ //include "aws_signed_request.php";
+
+$public_key ="AKIAJBXEHTNCU6LLFNIA";
+$private_key="Dgyv7aR6uGe3OtY95Dj6hHpDS/UEtyboMWpJchYA";
+
+//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;
+}
+//this is the data that is used to form the request for AWS
+//this is the part that is search specific
+ $parameters=array(
+ 'Operation' =>$operation ,
+ //'Keywords' =>urlencode($search) ,
+ //'SearchIndex' =>$searchindex , //Books for example.
+ "$searchparameter"=>$searchparameterdata ,
+ 'ItemPage' =>$page , //which page?
+ 'AssociateTag' =>$Aassociates_id[$locale],
+ 'ResponseGroup' =>'ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes' , //Small, Medium, Large or SellerListing,'BrowseNodes',// ,
+ 'ReviewSort' =>'-HelpfulVotes'
+ );
+
+$ext=$Aserver[$locale]['ext'];
+$file_data=$ext;
+ksort($parameters);
+foreach ($parameters as $i=>$d) {
+ $file_data.='&'.$i.'='.$d;
+}
+
+$url=aws_signed_request($ext,$parameters,$public_key,$private_key);
+//echo $url;
+ file_put_contents('/var/ywww/debug/phpDebug',"parms: ".
+ print_r($parameters,TRUE)."\n",FILE_APPEND);
+ $crl = curl_init();
+ $timeout = 5;
+ curl_setopt ($crl, CURLOPT_URL,$url);
+ curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
+ curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
+ $output = curl_exec($crl);
+ curl_close($crl);
+
+ /*$xml = new SimpleXMLElement("AccountLimitExceeded
~s';
+ $setBoundary = preg_replace($remove2,'', $setBoundary);
+ $remove3 = '~~s';
+ $setBoundary = preg_replace($remove3,'', $setBoundary);
+ $setBoundary2 = str_replace(' ','', $setBoundary); + //remove all extra crap; + $setBoundary3 = str_replace(' | ','BOTTOM', $setBoundary2);
+ //replace with BOTTOM
+
+ if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews))
+ {
+ $reviewContents = $reviews[1];
+ //print_r($reviewContents);
+ $review1 = trim($reviewContents[0]);
+ $review1 = str_replace("\n", "", $review1);
+ $review1 = str_replace("\r", "", $review1);
+ if (isset($reviewContents[1])) {
+ $review2 = trim($reviewContents[1]);
+ $review2 = str_replace("\n", "", $review2);
+ $review2 = str_replace("\r", "", $review2);
+ }
+ else {
+ $review2 = "";
+ }
+ if (isset($reviewContents[2])) {
+ $review3 = trim($reviewContents[2]);
+ $review3 = str_replace("\n", "", $review3);
+ $review3 = str_replace("\r", "", $review3);
+ }
+ else {
+ $review3 = "";
+ }
+ }
+ else
+ {
+ $review1 = "";
+ $review2 = "";
+ $review3 = "";
+ //echo "EPIC FAIL";
+ }
+
+ unset($xml->Items->Item->CustomerReviews);
+ $xdoc = new DomDocument;
+ $xdoc->loadXML($xml->asXML());
+
+ $cReviews = $xdoc ->createElement('CustomerReviews');
+ $cReviewHolder = $xdoc ->createElement('Review');
+ $cReview = $xdoc ->createElement('Content');
+ $cReviewHolder2 = $xdoc ->createElement('Review');
+ $cReview2 = $xdoc ->createElement('Content');
+ $cReviewHolder3 = $xdoc ->createElement('Review');
+ $cReview3 = $xdoc ->createElement('Content');
+
+ $txtNode = $xdoc ->createTextNode ($review1);
+ $cReview -> appendChild($txtNode);
+
+ $txtNode2 = $xdoc ->createTextNode ($review2);
+ $cReview2 -> appendChild($txtNode2);
+
+ $txtNode3 = $xdoc ->createTextNode ($review3);
+ $cReview3 -> appendChild($txtNode3);
+
+ $cReviewHolder -> appendChild($cReview);
+ $cReviewHolder2 -> appendChild($cReview2);
+ $cReviewHolder3 -> appendChild($cReview3);
+
+ $cReviews -> appendChild($cReviewHolder);
+ $cReviews -> appendChild($cReviewHolder2);
+ $cReviews -> appendChild($cReviewHolder3);
+
+ $xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews);
+ $newXML = simplexml_import_dom($xdoc);
+ $output = $newXML->asXml();
+ }
+
+ switch($locale){
+ case "us":
+ $loc = 0;
+ break;
+ case "uk":
+ $loc = 1;
+ break;
+ case "ca":
+ $loc = 2;
+ break;
+ case "de":
+ $loc = 3;
+ break;
+ case "fr":
+ $loc = 4;
+ break;
+ };
+
+ $errorCode = $xml->Error->Code;
+ //echo $errorCode;
+
+ if($errorCode != "AccountLimitExceeded")
+ {
+ if($go == 1)
+ return $output;
+ else
+ {
+ $title = $xml->Items->Item->ItemAttributes->Title;
+ $author = $xml->Items->Item->ItemAttributes->Author;
+ $binding = $xml->Items->Item->ItemAttributes->Binding;
+ $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;
+ if($dewey == "")
+ $dewey = "null";
+ $imageURL = $xml->Items->Item->MediumImage->URL;
+ $salesRank = $xml->Items->Item->SalesRank;
+ $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate;
+ $publisher = $xml->Items->Item->ItemAttributes->Publisher;
+
+ $genreID = "";
+ $genre = "";
+ $genArr = array();
+
+ for($i=0;$i