# HG changeset patch # User Charlie Root # Date 1546687272 18000 # Node ID 3f400072bf14de91479134450bcf0d2beacc9c77 # Parent 0578c6e438d355f7cc77c7dda976fc7771b50701# Parent 2c0c95bd97a6c5051b85c80b3f85620735cd26ad merge, involved ediff3 wrt getAmazonInfo.php diff -r 2c0c95bd97a6 -r 3f400072bf14 xml/getAmazonInfo.php --- a/xml/getAmazonInfo.php Fri Jan 04 18:03:24 2019 -0500 +++ b/xml/getAmazonInfo.php Sat Jan 05 06:21:12 2019 -0500 @@ -1,584 +1,584 @@ -'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 - //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; - } - 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; - }; - - try { - return getAmazonDetRemote($go,$language,$locale,$loc, - $page,$operation,$searchparameter, - $searchparameterdata, - $show_array,$show_url,$show_xml); - } - catch (Exception $e) { - return getAmazonDetLocal($go,$language,$loc, - $page,$operation,$searchparameter, - $searchparameterdata, - $show_array,$show_url,$show_xml); - } -} - -function getAmazonDetRemote($go,$language,$locale,$loc, - $page,$operation,$searchparameter, - $searchparameterdata, - $show_array,$show_url,$show_xml) -{ - global $output, $Aassociates_id, $Aserver; - - //if(go != 1) - //include "aws_signed_request.php"; - //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) , - "$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' - ); - - if (isset($searchindex) && $searchindex!='Books') { - // HST did this - // Used to be in $parameters init above, but - // that caused an error: - // If idType equals ASIN, SearchIndex cannot be present - //'SearchIndex' =>$searchindex , //Books for example. - $parameters['SearchIndex']=$searchindex; - } - $xml=doAmazonRequest($Aserver[$locale]['ext'],$parameters,3,'i'); // may throw exception - set_error_handler(function () { - global $output; - file_put_contents('/var/ywww/debug/phpDebug', - "Caught one?: ".$searchparameterdata, - FILE_APPEND); - file_put_contents('/var/ywww/debug/phpDebug', - print_r($output, TRUE)."\n", - FILE_APPEND); - } ); - $review = $xml->Items->Item->CustomerReviews->IFrameURL; - restore_error_handler(); - //echo $review; - if ($review != "") - { - $review1 = ""; - $review2 = ""; - $review3 = ""; - $text = @file_get_contents($review . "&truncate=300"); - $removeTop1 = preg_replace('~
~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();
- }
-
- if($go == 1) {
- $item = $xml->Items->Item[0];
- if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) {
- $title = $item->ItemAttributes->Title; }
- else { $title = "[no title]"; };
- file_put_contents('/var/ywww/debug/phpDebug',"win: $title\n",
- FILE_APPEND);
- return $output;
- }
- else {
- if ($xml->Items->Item) {
- $title = $xml->Items->Item[0]->ItemAttributes->Title;
- $author = $xml->Items->Item[0]->ItemAttributes->Author;
- $binding = $xml->Items->Item[0]->ItemAttributes->Binding;
- $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber;
- if($dewey == "")
- $dewey = "null";
- $imageURL = $xml->Items->Item[0]->MediumImage->URL;
- $salesRank = $xml->Items->Item[0]->SalesRank;
- $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate;
- if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";}
- if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";}
- if (strlen($pubDate)==0) {
- $pubDate="null";
- }
- else {
- $pubDate="\"$pubDate\"";
- }
- $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher;
- }
- else {
- $title = $salesRank = "";
- $dewey = "null";
- }
-
- $genreID = "";
- $genre = "";
- $genArr = array();
-
- if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) {
- for($i=0;$i
~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();
+ }
+
+ if($go == 1) {
+ $item = $xml->Items->Item[0];
+ if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) {
+ $title = $item->ItemAttributes->Title; }
+ else { $title = "[no title]"; };
+ file_put_contents('/var/ywww/debug/phpDebug',"win: $title\n",
+ FILE_APPEND);
+ return $output;
+ }
+ else {
+ if ($xml->Items->Item) {
+ $title = $xml->Items->Item[0]->ItemAttributes->Title;
+ $author = $xml->Items->Item[0]->ItemAttributes->Author;
+ $binding = $xml->Items->Item[0]->ItemAttributes->Binding;
+ $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber;
+ if($dewey == "")
+ $dewey = "null";
+ $imageURL = $xml->Items->Item[0]->MediumImage->URL;
+ $salesRank = $xml->Items->Item[0]->SalesRank;
+ $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate;
+ if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";}
+ if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";}
+ if (strlen($pubDate)==0) {
+ $pubDate="null";
+ }
+ else {
+ $pubDate="\"$pubDate\"";
+ }
+ $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher;
+ }
+ else {
+ $title = $salesRank = "";
+ $dewey = "null";
+ }
+
+ $genreID = "";
+ $genre = "";
+ $genArr = array();
+
+ if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) {
+ for($i=0;$i