Mercurial > hg > ywww
annotate xml/getAmazonInfo.php @ 39:2c0c95bd97a6
pass char for log lines in to doAmazonRequest,
move static arrays to aws_s_r
| author | Charlie Root |
|---|---|
| date | Fri, 04 Jan 2019 18:03:24 -0500 |
| parents | 86f79bc1d142 |
| children | 3f400072bf14 |
| rev | line source |
|---|---|
| 4 | 1 <?php |
| 2 | |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
3 include_once "doAmazonRequest.inc"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
4 |
| 4 | 5 function getAmazonDet($isbn,$go,$localeIn) |
| 6 { | |
| 32 | 7 $Adefault=array( |
| 8 'language' =>'en', //what language to render the page in | |
| 9 'locale' =>$localeIn, //which server's products? available: ca,de,fr,jp,uk,us | |
| 10 //'mode' =>'books', //what product category? | |
| 11 'page' =>1, //first page to show (we are counting from 1 not 0) | |
| 12 //'search' =>'Machiavelli', //what to search for? | |
| 13 'operation' =>'ItemLookup', //what to do? //ItemSearch | |
| 33 | 14 'searchindex' =>'Books', //what product category for search? |
| 32 | 15 'searchparameter' =>'ItemId', //what kind of search? |
| 16 'searchparameterdata'=>$isbn, //what to search for? | |
| 17 //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true' | |
| 18 'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending | |
| 19 'show_url' =>false, //debug: show XML request url to be send to Amazon? | |
| 20 'show_xml' =>false, //debug: show incoming XML code from Amazon? | |
| 21 ); | |
| 22 //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 | |
| 23 //for all parameters see if the user has overruled it or use the default | |
| 24 foreach ($Adefault as $i=>$d) { | |
| 25 $$i=isset($_GET[$i])?$_GET[$i]:$d; | |
| 26 } | |
| 27 switch($locale){ | |
| 28 case "us": | |
| 29 $loc = 0; | |
| 30 break; | |
| 31 case "uk": | |
| 32 $loc = 1; | |
| 33 break; | |
| 34 case "ca": | |
| 35 $loc = 2; | |
| 36 break; | |
| 37 case "de": | |
| 38 $loc = 3; | |
| 39 break; | |
| 40 case "fr": | |
| 41 $loc = 4; | |
| 42 break; | |
| 43 }; | |
| 44 | |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
45 try { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
46 return getAmazonDetRemote($go,$language,$locale,$loc, |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
47 $page,$operation,$searchparameter, |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
48 $searchparameterdata, |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
49 $show_array,$show_url,$show_xml); |
| 32 | 50 } |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
51 catch (Exception $e) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
52 return getAmazonDetLocal($go,$language,$loc, |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
53 $page,$operation,$searchparameter, |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
54 $searchparameterdata, |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
55 $show_array,$show_url,$show_xml); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
56 } |
| 32 | 57 } |
| 58 | |
| 59 function getAmazonDetRemote($go,$language,$locale,$loc, | |
| 60 $page,$operation,$searchparameter, | |
| 61 $searchparameterdata, | |
| 62 $show_array,$show_url,$show_xml) | |
| 63 { | |
| 39 | 64 global $output, $Aassociates_id, $Aserver; |
| 4 | 65 |
| 32 | 66 //if(go != 1) |
| 67 //include "aws_signed_request.php"; | |
| 68 //this is the data that is used to form the request for AWS | |
| 69 //this is the part that is search specific | |
| 4 | 70 $parameters=array( |
| 32 | 71 'Operation' =>$operation , |
| 72 //'Keywords' =>urlencode($search) , | |
| 73 "$searchparameter"=>$searchparameterdata , | |
| 74 'ItemPage' =>$page , //which page? | |
| 75 'AssociateTag' =>$Aassociates_id[$locale], | |
| 76 'ResponseGroup' =>'ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes' , //Small, Medium, Large or SellerListing,'BrowseNodes',// , | |
| 77 'ReviewSort' =>'-HelpfulVotes' | |
| 78 ); | |
| 4 | 79 |
| 33 | 80 if (isset($searchindex) && $searchindex!='Books') { |
| 81 // HST did this | |
| 82 // Used to be in $parameters init above, but | |
| 83 // that caused an error: | |
| 84 // If idType equals ASIN, SearchIndex cannot be present | |
| 85 //'SearchIndex' =>$searchindex , //Books for example. | |
| 86 $parameters['SearchIndex']=$searchindex; | |
| 87 } | |
| 39 | 88 $xml=doAmazonRequest($Aserver[$locale]['ext'],$parameters,3,'i'); // may throw exception |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
89 set_error_handler(function () { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
90 global $output; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
91 file_put_contents('/var/ywww/debug/phpDebug', |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
92 "Caught one?: ".$searchparameterdata, |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
93 FILE_APPEND); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
94 file_put_contents('/var/ywww/debug/phpDebug', |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
95 print_r($output, TRUE)."\n", |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
96 FILE_APPEND); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
97 } ); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
98 $review = $xml->Items->Item->CustomerReviews->IFrameURL; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
99 restore_error_handler(); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
100 //echo $review; |
| 32 | 101 if ($review != "") |
| 102 { | |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
103 $review1 = ""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
104 $review2 = ""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
105 $review3 = ""; |
| 32 | 106 $text = @file_get_contents($review . "&truncate=300"); |
| 107 $removeTop1 = preg_replace('~<div class="crIFrameHeaderLeftColumn">(.*?)<div class="crIFrameHeaderHistogram">~si', '', $text); | |
| 108 $removeTop2 = preg_replace('~<div class="crIFrameHeaderHistogram">(.*?)<div class="crIframeReviewList">~si', '', $text); | |
| 109 if (preg_match('~<body[^>]*>(.*?)</body>~si', $removeTop2, $body)){ $getBody = trim($body[1]); } else { $getBody = $removeTop2;} | |
| 110 $removeDiv = preg_replace('~<div[^>]*>(.*?)</div>~si', '', $getBody); | |
| 111 $removeCloseDivs = preg_replace('/<\/div>/','', $removeDiv); | |
| 112 $setBoundary = str_replace('<!-- BOUNDARY -->','BOTTOM-TOP', $removeCloseDivs); | |
| 113 //replace <!-- BOUNDARY --> with BOTTOM-TOP | |
| 114 $remove1 = '~<table cellpadding="0"(.*?)%">~s'; | |
| 115 $setBoundary = preg_replace($remove1,'', $setBoundary); | |
| 116 $remove2 = '~</td><td bg(.*?)</table>~s'; | |
| 117 $setBoundary = preg_replace($remove2,'', $setBoundary); | |
| 118 $remove3 = '~<a name=(.*?)</a>~s'; | |
| 119 $setBoundary = preg_replace($remove3,'', $setBoundary); | |
| 120 $setBoundary2 = str_replace('<br />','', $setBoundary); | |
| 121 //remove all extra crap; | |
| 122 $setBoundary3 = str_replace('</td>','BOTTOM', $setBoundary2); | |
| 123 //replace </td> with BOTTOM | |
| 124 | |
| 125 if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews)) | |
| 126 { | |
| 127 $reviewContents = $reviews[1]; | |
| 128 //print_r($reviewContents); | |
| 129 $review1 = trim($reviewContents[0]); | |
| 130 $review1 = str_replace("\n", "", $review1); | |
| 131 $review1 = str_replace("\r", "", $review1); | |
| 132 if (isset($reviewContents[1])) { | |
| 133 $review2 = trim($reviewContents[1]); | |
| 134 $review2 = str_replace("\n", "", $review2); | |
| 135 $review2 = str_replace("\r", "", $review2); | |
|
7
1dfe64e365a0
a bit more debugging/bomb-proofing
Robert Boland <robert@markup.co.uk>
parents:
5
diff
changeset
|
136 } |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
7
diff
changeset
|
137 else { |
| 32 | 138 $review2 = ""; |
| 139 } | |
| 140 if (isset($reviewContents[2])) { | |
| 141 $review3 = trim($reviewContents[2]); | |
| 142 $review3 = str_replace("\n", "", $review3); | |
| 143 $review3 = str_replace("\r", "", $review3); | |
| 144 } | |
| 145 else { | |
| 146 $review3 = ""; | |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
7
diff
changeset
|
147 } |
| 5 | 148 } |
| 32 | 149 else |
| 150 { | |
| 151 $review1 = ""; | |
| 152 $review2 = ""; | |
| 153 $review3 = ""; | |
| 154 //echo "EPIC FAIL"; | |
| 155 } | |
| 156 | |
| 157 unset($xml->Items->Item->CustomerReviews); | |
| 158 $xdoc = new DomDocument; | |
| 159 $xdoc->loadXML($xml->asXML()); | |
| 160 | |
| 161 $cReviews = $xdoc ->createElement('CustomerReviews'); | |
| 162 $cReviewHolder = $xdoc ->createElement('Review'); | |
| 163 $cReview = $xdoc ->createElement('Content'); | |
| 164 $cReviewHolder2 = $xdoc ->createElement('Review'); | |
| 165 $cReview2 = $xdoc ->createElement('Content'); | |
| 166 $cReviewHolder3 = $xdoc ->createElement('Review'); | |
| 167 $cReview3 = $xdoc ->createElement('Content'); | |
| 168 | |
| 169 $txtNode = $xdoc ->createTextNode ($review1); | |
| 170 $cReview -> appendChild($txtNode); | |
| 171 | |
| 172 $txtNode2 = $xdoc ->createTextNode ($review2); | |
| 173 $cReview2 -> appendChild($txtNode2); | |
| 174 | |
| 175 $txtNode3 = $xdoc ->createTextNode ($review3); | |
| 176 $cReview3 -> appendChild($txtNode3); | |
| 177 | |
| 178 $cReviewHolder -> appendChild($cReview); | |
| 179 $cReviewHolder2 -> appendChild($cReview2); | |
| 180 $cReviewHolder3 -> appendChild($cReview3); | |
| 181 | |
| 182 $cReviews -> appendChild($cReviewHolder); | |
| 183 $cReviews -> appendChild($cReviewHolder2); | |
| 184 $cReviews -> appendChild($cReviewHolder3); | |
| 185 | |
| 186 $xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews); | |
| 187 $newXML = simplexml_import_dom($xdoc); | |
| 188 $output = $newXML->asXml(); | |
| 189 } | |
| 190 | |
| 191 if($go == 1) { | |
| 192 $item = $xml->Items->Item[0]; | |
| 193 if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) { | |
| 194 $title = $item->ItemAttributes->Title; } | |
| 195 else { $title = "[no title]"; }; | |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
196 file_put_contents('/var/ywww/debug/phpDebug',"win: $title\n", |
| 32 | 197 FILE_APPEND); |
| 198 return $output; | |
| 199 } | |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
200 else { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
201 if ($xml->Items->Item) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
202 $title = $xml->Items->Item[0]->ItemAttributes->Title; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
203 $author = $xml->Items->Item[0]->ItemAttributes->Author; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
204 $binding = $xml->Items->Item[0]->ItemAttributes->Binding; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
205 $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
206 if($dewey == "") |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
207 $dewey = "null"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
208 $imageURL = $xml->Items->Item[0]->MediumImage->URL; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
209 $salesRank = $xml->Items->Item[0]->SalesRank; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
210 $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
211 if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";} |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
212 if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";} |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
213 if (strlen($pubDate)==0) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
214 $pubDate="null"; |
| 32 | 215 } |
| 216 else { | |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
217 $pubDate="\"$pubDate\""; |
| 32 | 218 } |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
219 $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
220 } |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
221 else { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
222 $title = $salesRank = ""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
223 $dewey = "null"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
224 } |
| 32 | 225 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
226 $genreID = ""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
227 $genre = ""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
228 $genArr = array(); |
| 32 | 229 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
230 if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
231 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
232 //sexy recursive function |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
233 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); |
| 32 | 234 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
235 if($genre != "") |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
236 $genArr[strval($genreID)] = strval($genre); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
237 //$genArr[$i] = array(strval($genreID) => strval($genre)); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
238 |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
239 //echo $genre; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
240 //echo $genreID; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
241 |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
242 $genre = ""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
243 $genreID = ""; |
| 32 | 244 } |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
245 } |
| 32 | 246 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
247 $g1 = "null"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
248 $g2 = "null"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
249 $g3 = "null"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
250 $loop = 1; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
251 |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
252 foreach ($genArr as $key => $value) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
253 //echo "$key => $value"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
254 if ($key>2047) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
255 //HST added |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
256 break; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
257 } |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
258 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
259 //echo $queryG; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
260 include "../../private/db.php"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
261 $resG = mysqli_query($link, $queryG); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
262 mysqli_close($link); |
| 32 | 263 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
264 switch ($loop) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
265 case 1: |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
266 $g1 = $key; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
267 break; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
268 case 2: |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
269 $g2 = $key; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
270 break; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
271 case 3: |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
272 $g3 = $key; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
273 break; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
274 } |
| 32 | 275 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
276 $loop++; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
277 } |
| 32 | 278 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
279 if($salesRank == "") |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
280 $salesRank = "null"; |
| 32 | 281 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
282 if($title != "") |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
283 { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
284 include "../../private/db.php"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
285 if ($publisher->count()==0) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
286 $publisher="null"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
287 } |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
288 else { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
289 $publisher=mysqli_real_escape_string($link,$publisher); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
290 if (strlen($publisher)>30) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
291 $publisher=rtrim(substr($publisher,0,30),"\\"); |
| 32 | 292 } |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
293 $publisher="\"".$publisher."\""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
294 } |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
295 if ($author->count()==0) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
296 $author="unknown"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
297 } |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
298 else { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
299 $author=mysqli_real_escape_string($link,$author); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
300 if (strlen($author)>30) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
301 $author=rtrim(substr($author,0,30),"\\"); |
| 32 | 302 } |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
303 } |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
304 $author="\"".$author."\""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
305 $title=mysqli_real_escape_string($link,$title); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
306 if (strlen($title)>100) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
307 $title=rtrim(substr($title,0,100),"\\"); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
308 } |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
309 $title="\"".$title."\""; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
310 $review1 = mysqli_real_escape_string($link,$review1); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
311 if (strlen($review1)>500) { $review1=rtrim(substr($review1,0,500),"\\");} |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
312 $review2 = mysqli_real_escape_string($link,$review2); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
313 if (strlen($review2)>500) { $review2=rtrim(substr($review2,0,500),"\\");} |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
314 $review3 = mysqli_real_escape_string($link,$review3); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
315 if (strlen($review3)>500) { $review3=rtrim(substr($review3,0,500),"\\");} |
| 4 | 316 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
317 $queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",$title, $author,\"$binding\",\"$imageURL\", $dewey, $salesRank,$pubDate,$publisher,$g1,$g2,$g3,$loc)"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
318 //echo $queryInsert; |
|
25
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
319 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
320 $res = mysqli_query($link, $queryInsert); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
321 if (!$res) { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
322 $err=mysqli_error( $link ); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
323 mysqli_close($link); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
324 file_put_contents('/var/ywww/debug/phpDebug', |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
325 "anb failed: $queryInsert\n$err\n", |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
326 FILE_APPEND); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
327 exit($err); |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
328 } |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
329 $queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")"; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
330 if($review1 != "") { |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
331 $res = mysqli_query($link, $queryInsertReviews); |
| 32 | 332 if (!$res) { |
| 333 $err=mysqli_error( $link ); | |
| 334 mysqli_close($link); | |
| 335 file_put_contents('/var/ywww/debug/phpDebug', | |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
336 "anr failed: $queryInsertReviews\n", |
| 32 | 337 FILE_APPEND); |
| 338 exit($err); | |
| 339 } | |
| 4 | 340 } |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
341 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
342 } |
| 32 | 343 |
|
35
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
344 echo $output; |
|
86f79bc1d142
refactor to split out shareable fn to actually do an Amazon API request
Charlie Root
parents:
33
diff
changeset
|
345 } |
| 32 | 346 } |
| 347 | |
| 348 function getAmazonDetLocal($go,$language,$loc, | |
| 349 $page,$operation,$searchparameter, | |
| 350 $searchparameterdata, | |
| 351 $show_array,$show_url,$show_xml) | |
| 352 { | |
| 353 global $output; | |
| 354 //look up info from db | |
| 355 include "../../private/db.php"; | |
| 356 $query = "CALL b_getBookInfo('$searchparameterdata', $loc)"; | |
| 357 //echo $query; | |
| 358 $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); | |
| 4 | 359 |
| 32 | 360 $output = ""; |
| 361 $output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | |
| 362 $output .= "<Details>"; | |
| 363 if ( mysqli_num_rows( $res ) > 0 ) | |
| 364 { | |
| 365 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); | |
| 366 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | |
| 367 $output .= "<ASIN>" . $searchparameterdata . "</ASIN>"; | |
| 368 $output .= "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>"; | |
| 369 $output .= "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>"; | |
| 370 $output .= "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>"; | |
| 371 $output .= "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>"; | |
| 372 $output .= "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>"; | |
| 373 $output .= "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>"; | |
| 374 $output .= "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>"; | |
| 375 $output .= "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>"; | |
| 376 $output .= "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>"; | |
| 377 $output .= "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>"; | |
| 378 $output .= "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>"; | |
| 379 $output .= "<ProductGroup>Book</ProductGroup>"; | |
| 380 $output .= "<Error>AccountLimitExceeded</Error>"; | |
| 4 | 381 |
| 32 | 382 } |
| 383 else { | |
| 384 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | |
| 385 } | |
| 386 $output .= "</Details>"; | |
| 387 echo $output; | |
| 4 | 388 } |
| 389 | |
| 390 function findGenre($browseNode, &$ID, &$gen) | |
| 391 { | |
| 392 if($browseNode->Name == "Subjects") | |
| 393 { | |
| 394 return true; | |
| 395 } | |
| 396 else | |
| 397 { | |
| 398 if($browseNode->Ancestors->BrowseNode) | |
| 399 { | |
| 400 if(findGenre($browseNode->Ancestors->BrowseNode, $ID, $gen) == true) | |
| 401 { | |
| 402 $gen = $browseNode->Name; | |
| 403 $ID = $browseNode->BrowseNodeId; | |
| 404 } | |
| 405 } | |
| 406 return false; | |
| 407 } | |
| 408 } | |
| 409 | |
| 410 if(!isset($ret)) | |
| 411 { | |
| 39 | 412 include "aws_signed_request.php"; |
| 413 getAmazonDet('default',0,'us'); //will get overwritten from URI params | |
| 414 // by the foreach ($Adefault as ... loop above | |
| 4 | 415 } |
| 416 /*Caught oneSimpleXMLElement Object | |
| 417 ( | |
| 418 [OperationRequest] => SimpleXMLElement Object | |
| 419 ( | |
| 420 [RequestId] => d2eaacba-2411-44e7-b268-f23a20167330 | |
| 421 [Arguments] => SimpleXMLElement Object | |
| 422 ( | |
| 423 [Argument] => Array | |
| 424 ( | |
| 425 [0] => SimpleXMLElement Object | |
| 426 ( | |
| 427 [@attributes] => Array | |
| 428 ( | |
| 429 [Name] => AWSAccessKeyId | |
|
17
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
11
diff
changeset
|
430 [Value] => AKIAIHTNWC7L6LOUY4LQ |
| 4 | 431 ) |
| 432 | |
| 433 ) | |
| 434 | |
| 435 [1] => SimpleXMLElement Object | |
| 436 ( | |
| 437 [@attributes] => Array | |
| 438 ( | |
| 439 [Name] => AssociateTag | |
| 440 [Value] => bookwhack-21 | |
| 441 ) | |
| 442 | |
| 443 ) | |
| 444 | |
| 445 [2] => SimpleXMLElement Object | |
| 446 ( | |
| 447 [@attributes] => Array | |
| 448 ( | |
| 449 [Name] => ItemId | |
| 450 [Value] => B004Q3Q3Y4 | |
| 451 ) | |
| 452 | |
| 453 ) | |
| 454 | |
| 455 [3] => SimpleXMLElement Object | |
| 456 ( | |
| 457 [@attributes] => Array | |
| 458 ( | |
| 459 [Name] => ItemPage | |
| 460 [Value] => 1 | |
| 461 ) | |
| 462 | |
| 463 ) | |
| 464 | |
| 465 [4] => SimpleXMLElement Object | |
| 466 ( | |
| 467 [@attributes] => Array | |
| 468 ( | |
| 469 [Name] => Operation | |
| 470 [Value] => ItemLookup | |
| 471 ) | |
| 472 | |
| 473 ) | |
| 474 | |
| 475 [5] => SimpleXMLElement Object | |
| 476 ( | |
| 477 [@attributes] => Array | |
| 478 ( | |
| 479 [Name] => ResponseGroup | |
| 480 [Value] => ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes | |
| 481 ) | |
| 482 | |
| 483 ) | |
| 484 | |
| 485 [6] => SimpleXMLElement Object | |
| 486 ( | |
| 487 [@attributes] => Array | |
| 488 ( | |
| 489 [Name] => ReviewSort | |
| 490 [Value] => -HelpfulVotes | |
| 491 ) | |
| 492 | |
| 493 ) | |
| 494 | |
| 495 [7] => SimpleXMLElement Object | |
| 496 ( | |
| 497 [@attributes] => Array | |
| 498 ( | |
| 499 [Name] => Service | |
| 500 [Value] => AWSECommerceService | |
| 501 ) | |
| 502 | |
| 503 ) | |
| 504 | |
| 505 [8] => SimpleXMLElement Object | |
| 506 ( | |
| 507 [@attributes] => Array | |
| 508 ( | |
| 509 [Name] => Timestamp | |
| 510 [Value] => 2016-12-15T23:12:34Z | |
| 511 ) | |
| 512 | |
| 513 ) | |
| 514 | |
| 515 [9] => SimpleXMLElement Object | |
| 516 ( | |
| 517 [@attributes] => Array | |
| 518 ( | |
| 519 [Name] => Version | |
| 520 [Value] => 2011-08-01 | |
| 521 ) | |
| 522 | |
| 523 ) | |
| 524 | |
| 525 [10] => SimpleXMLElement Object | |
| 526 ( | |
| 527 [@attributes] => Array | |
| 528 ( | |
| 529 [Name] => Signature | |
| 530 [Value] => SUXfFZHQ74Joc+WDLx87uzemTdtHijNohykqafJXYKQ= | |
| 531 ) | |
| 532 | |
| 533 ) | |
| 534 | |
| 535 ) | |
| 536 | |
| 537 ) | |
| 538 | |
| 539 [RequestProcessingTime] => 0.3518217620000000 | |
| 540 ) | |
| 541 | |
| 542 [Items] => SimpleXMLElement Object | |
| 543 ( | |
| 544 [Request] => SimpleXMLElement Object | |
| 545 ( | |
| 546 [IsValid] => True | |
| 547 [ItemLookupRequest] => SimpleXMLElement Object | |
| 548 ( | |
| 549 [IdType] => ASIN | |
| 550 [ItemId] => B004Q3Q3Y4 | |
| 551 [ResponseGroup] => Array | |
| 552 ( | |
| 553 [0] => ItemAttributes | |
| 554 [1] => Reviews | |
| 555 [2] => EditorialReview | |
| 556 [3] => OfferSummary | |
| 557 [4] => Offers | |
| 558 [5] => Images | |
| 559 [6] => AlternateVersions | |
| 560 [7] => SalesRank | |
| 561 [8] => BrowseNodes | |
| 562 ) | |
| 563 | |
| 564 [VariationPage] => All | |
| 565 ) | |
| 566 | |
| 567 [Errors] => SimpleXMLElement Object | |
| 568 ( | |
| 569 [Error] => SimpleXMLElement Object | |
| 570 ( | |
| 571 [Code] => AWS.InvalidParameterValue | |
| 572 [Message] => B004Q3Q3Y4 is not a valid value for ItemId. Please change this value and retry your request. | |
| 573 ) | |
| 574 | |
| 575 ) | |
| 576 | |
| 577 ) | |
| 578 | |
| 579 ) | |
| 580 | |
| 581 ) | |
| 582 */ | |
|
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
583 /*$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><ItemLookupErrorResponse xmlns=\"http://ecs.amazonaws.com/doc/2009-03-31/\"><Error><Code>AccountLimitExceeded</Code><Message>Account limit of 2056 requests per hour exceeded.</Message></Error><RequestID>290ed059-730c-4789-93b4-6d21e11053d3</RequestID></ItemLookupErrorResponse>");*/ |
| 4 | 584 ?> |
