Mercurial > hg > ywww
annotate php/read/getBookDetails.php @ 29:f024f2f08994
a few more undef var fixes
| author | Robert Boland <robert@markup.co.uk> |
|---|---|
| date | Fri, 04 Jan 2019 08:49:25 -0500 |
| parents | b058736bc9ad |
| children | 5cae8d572998 |
| rev | line source |
|---|---|
| 2 | 1 <?php |
| 2 | |
| 3 function findGenre($browseNode, &$ID, &$gen) | |
| 4 { | |
| 5 if($browseNode->Name == "Subjects") | |
| 6 { | |
| 7 return true; | |
| 8 } | |
| 9 else | |
| 10 { | |
| 11 if($browseNode->Ancestors->BrowseNode) | |
| 12 { | |
| 13 if(findGenre($browseNode->Ancestors->BrowseNode, $ID, $gen) == true) | |
| 14 { | |
| 15 $gen = $browseNode->Name; | |
| 16 $ID = $browseNode->BrowseNodeId; | |
| 17 | |
| 18 //if($browseNode->Name == "Literature & Fiction") //to return one level up the tree as well | |
| 19 // return true; | |
| 20 } | |
| 21 } | |
| 22 return false; | |
| 23 } | |
| 24 } | |
| 25 | |
| 3 | 26 global $out,$isbn; |
| 2 | 27 if(isset($_GET['isbn'])){ |
| 28 $isbn = $_GET['isbn']; | |
| 29 if(isset($_GET['locale'])){ | |
| 30 $locale=$_GET['locale']; | |
| 31 | |
| 32 switch ($locale) { | |
| 33 case "uk": | |
| 34 $loc = 1; | |
| 35 break; | |
| 36 case "us": | |
| 37 $loc = 0; | |
| 38 break; | |
| 39 case "ca": | |
| 40 $loc = 2; | |
| 41 break; | |
| 42 case "de": | |
| 43 $loc = 3; | |
| 44 break; | |
| 45 case "fr": | |
| 46 $loc = 4; | |
| 47 break; | |
| 48 case "": | |
| 49 $loc = 0; | |
| 50 break; | |
| 51 } | |
| 52 } | |
| 53 else{ | |
| 54 $loc=0; | |
| 55 } | |
| 56 $output = ""; | |
| 57 | |
| 58 $output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | |
| 59 $output .= "<BookDetails>"; | |
| 60 | |
| 61 $proceed = true; | |
| 62 include "../../../private/db.php"; | |
| 63 | |
| 64 $query = "CALL b_getBookInfo('$isbn', $loc)"; | |
| 65 //select Timestamp,Title,Author,Binding,DeweyDecimal,ImageURL,SalesRank,PublicationDate,Publisher,Genre1,Genre2,Genre3 from books where ISBN = '$isbn'"; | |
| 66 //echo $query; | |
| 67 $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); | |
| 68 | |
| 69 if ( mysqli_num_rows( $res ) > 0 ) | |
| 70 { | |
| 71 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); | |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
72 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
| 2 | 73 $timestamp=$rows['Timestamp']; |
| 74 //echo $timestamp; | |
| 75 date_default_timezone_set('UTC'); | |
| 76 $dbStamp = strtotime($timestamp); | |
| 77 //echo $dbStamp; | |
| 78 $unixTime = time(); | |
| 79 //echo $unixTime; | |
| 80 $timeDiff = $unixTime - $dbStamp; | |
| 81 //echo $timeDiff; | |
| 82 | |
| 83 if($timeDiff < 2592000) //if it has been updated in the last 30 days | |
| 84 { | |
| 85 $proceed = false; | |
| 86 $output .= "<ISBN>" . $isbn . "</ISBN>"; | |
| 87 $output .= "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>"; | |
| 88 $output .= "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>"; | |
| 89 $output .= "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>"; | |
| 90 $output .= "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>"; | |
| 91 $output .= "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>"; | |
| 92 $output .= "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>"; | |
| 93 $output .= "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>"; | |
| 94 $output .= "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>"; | |
| 95 $output .= "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>"; | |
| 96 $output .= "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>"; | |
| 97 $output .= "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>"; | |
| 98 $output .= "<ProductGroup>Book</ProductGroup>"; | |
| 99 } | |
| 100 } | |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
101 else { |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
102 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
103 } |
| 2 | 104 include "../../../private/db.php"; |
| 105 | |
| 106 if($proceed == true) | |
| 107 { | |
| 108 include "aws_signed_request.php"; | |
| 109 //book does not exist already so look up all the info from browse nodes.... | |
| 110 | |
| 111 $Adefault=array( | |
| 112 'language' =>'en', //what language to render the page in | |
| 113 'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us | |
| 114 'page' =>1, //first page to show (we are counting from 1 not 0) | |
| 115 'operation' =>'ItemLookup', //what to do? //ItemSearch | |
| 116 'searchparameter' =>'ItemId', //what kind of search? | |
| 117 'searchindex' => 'Books', | |
| 118 'searchparameterdata'=>$isbn, //what to search for? | |
| 119 'search' =>$isbn, | |
| 120 //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true' | |
| 121 'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending | |
| 122 'show_url' =>false, //debug: show XML request url to be send to Amazon? | |
| 123 'show_xml' =>false, //debug: show incoming XML code from Amazon? | |
| 124 ); | |
| 125 //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 | |
| 126 | |
| 127 $Aassociates_id=array( | |
| 128 'uk' => 'bookwhack-21', | |
| 129 'us' => 'your02b-20', | |
| 130 'ca' => 'book009-20', | |
| 131 'de' => 'book04c-21', | |
| 132 'fr' => 'book07f-21', | |
| 133 ); | |
| 134 | |
| 135 $Aserver=array( | |
| 136 'ca' => array( | |
| 137 'ext' => 'ca' , //Canadian normal server | |
| 138 'nor' => 'http://www.amazon.ca' , //Canadian normal server | |
| 139 'xml' => 'http://xml.amazon.com' , //Canadian xml server | |
| 140 ), | |
| 141 'de' => array( | |
| 142 'ext' => 'de' , //German normal server | |
| 143 'nor' => 'http://www.amazon.de' , //German normal server | |
| 144 'xml' => 'http://xml-eu.amazon.com', //German xml server | |
| 145 ), | |
| 146 'fr' => array( | |
| 147 'ext' => 'fr' , //French normal server | |
| 148 'nor' => 'http://www.amazon.fr' , //French normal server | |
| 149 'xml' => 'http://xml-eu.amazon.com', //French xml server | |
| 150 ), | |
| 151 'jp' => array( | |
| 152 'ext' => 'jp' , //Japanese normal server, not co.jp! | |
| 153 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server | |
| 154 'xml' => 'http://xml.amazon.com' , //Japanese xml server | |
| 155 ), | |
| 156 'uk' => array( | |
| 157 'ext' => 'co.uk' , //UK normal server | |
| 158 'nor' => 'http://www.amazon.co.uk' , //UK normal server | |
| 159 'xml' => 'http://xml-eu.amazon.com', //UK xml server | |
| 160 ), | |
| 161 'us' => array( | |
| 162 'ext' => 'com' , //USA normal server | |
| 163 'nor' => 'http://www.amazon.com' , //USA normal server | |
| 164 'xml' => 'http://xml.amazon.com' , //USA xml server | |
| 165 ), | |
| 166 ); | |
|
17
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
10
diff
changeset
|
167 $public_key ="AKIAIHTNWC7L6LOUY4LQ"; |
|
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
10
diff
changeset
|
168 $private_key="zWQlIzndJDtXNfxEXH7K7YR7hzv3u77lOcqfqPde"; |
| 2 | 169 |
| 170 //for all parameters see if the user has overruled it or use the default | |
| 171 foreach ($Adefault as $i=>$d) { | |
| 172 $$i=isset($_GET[$i])?$_GET[$i]:$d; | |
| 173 } | |
| 174 | |
| 175 $parameters=array( | |
| 176 'Operation' =>$operation , | |
| 177 'Keywords' =>urlencode($search) , | |
| 178 "$searchparameter"=>$searchparameterdata , | |
| 179 'ItemPage' =>$page , //which page? | |
| 180 'AssociateTag' =>$Aassociates_id[$locale], | |
| 181 'ResponseGroup' =>'ItemAttributes,Images,SalesRank,BrowseNodes' | |
| 182 ); | |
| 183 | |
| 3 | 184 if ($searchindex!='Books') { |
| 185 // HST did this | |
| 186 // Used to be in $parameters init above, but | |
| 187 // that caused an error: | |
| 188 // If idType equals ASIN, SearchIndex cannot be present | |
| 189 //'SearchIndex' =>$searchindex , //Books for example. | |
| 190 $parameters['SearchIndex']=$searchindex; | |
| 191 } | |
| 192 | |
| 193 | |
| 2 | 194 $ext=$Aserver[$locale]['ext']; |
| 195 $file_data=$ext; | |
| 196 ksort($parameters); | |
| 197 foreach ($parameters as $i=>$d) { | |
| 198 $file_data.='&'.$i.'='.$d; | |
| 199 } | |
| 200 | |
| 201 $url=aws_signed_request($ext,$parameters,$public_key,$private_key); | |
| 202 //echo $url; | |
| 203 | |
| 204 $crl = curl_init(); | |
| 205 $timeout = 5; | |
| 206 curl_setopt ($crl, CURLOPT_URL,$url); | |
| 207 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
| 208 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
| 209 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
|
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
210 $gotit=0; |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
211 $requestIP = $_SERVER['REMOTE_ADDR']; |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
212 $semaphore = new SyncSemaphore("Amazon"); |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
213 $gotit = $semaphore->lock(1000); |
|
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
214 if (!$gotit) { |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
215 file_put_contents('/var/ywww/debug/phpDebug', |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
216 "Got it: ".(int)$gotit." $requestIP 2\n",FILE_APPEND); |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
217 $gotit=$semaphore->lock(1000); |
|
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
218 file_put_contents('/var/ywww/debug/phpDebug', |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
219 "Got it: ".(int)$gotit." $requestIP 2a\n",FILE_APPEND); |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
220 } |
| 2 | 221 $out = curl_exec($crl); |
| 222 curl_close($crl); | |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
223 usleep(500000); |
|
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
224 if ($gotit) { |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
225 $semaphore->unlock(); |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
226 } |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
227 else { |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
228 file_put_contents('/var/ywww/debug/phpDebug', |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
229 "W/o lock for $requestIP 2b\n",FILE_APPEND); |
|
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
230 } |
| 2 | 231 //echo $out; |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
232 $mm=array(); |
| 28 | 233 if (preg_match("/<Error>/",$out,$mm)) { |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
234 $xml = new SimpleXMLElement($out); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
235 $resName=$xml->getName(); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
236 $code=$xml->Error->Code; |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
237 if (!$code) { |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
238 $code=$xml->Items->Request->Errors->Error->Code; |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
239 } |
|
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
18
diff
changeset
|
240 $requestIP = $_SERVER['REMOTE_ADDR']; |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
241 file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: ".$mm[0].", $resName, $code, $requestIP\n",FILE_APPEND); |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
242 if ($code=='RequestThrottled') { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
243 usleep(200000); // Try to reduce throttling until we get a |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
244 // principled solution in place |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
245 } |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
246 else { |
| 18 | 247 file_put_contents('/var/ywww/debug/phpDebug',"parms $url\nbd: ". |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
248 print_r($parameters,TRUE)."\n",FILE_APPEND); |
|
10
5aa24c984a3b
if no code show entire response
Henry S. Thompson <ht@markup.co.uk>
parents:
9
diff
changeset
|
249 if ($code=="") { |
|
5aa24c984a3b
if no code show entire response
Henry S. Thompson <ht@markup.co.uk>
parents:
9
diff
changeset
|
250 file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$out\n",FILE_APPEND); |
|
5aa24c984a3b
if no code show entire response
Henry S. Thompson <ht@markup.co.uk>
parents:
9
diff
changeset
|
251 } |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
252 } |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
253 } |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
254 else { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
255 $xml = new SimpleXMLElement($out); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
256 //use this xml to pull out the necessary information and save it |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
257 set_error_handler(function () { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
258 global $out,$isbn; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
259 file_put_contents('/var/ywww/debug/phpDebug', |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
260 "Caught one bd: ".$isbn, |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
261 FILE_APPEND); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
262 file_put_contents('/var/ywww/debug/phpDebug', |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
263 print_r($out, TRUE)."\n", |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
264 FILE_APPEND); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
265 } ); |
| 2 | 266 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
267 $title=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
268 $author=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
269 $binding=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
270 $dewey=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
271 $imageURL=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
272 $salesRank=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
273 $pubDate=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
274 $publisher=""; |
| 2 | 275 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
276 $title = $xml->Items->Item->ItemAttributes->Title; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
277 $author = $xml->Items->Item->ItemAttributes->Author; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
278 $binding = $xml->Items->Item->ItemAttributes->Binding; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
279 $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
280 if($dewey == "") |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
281 $dewey = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
282 $imageURL = $xml->Items->Item->MediumImage->URL; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
283 $salesRank = $xml->Items->Item->SalesRank; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
284 $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
285 $publisher = $xml->Items->Item->ItemAttributes->Publisher; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
286 restore_error_handler(); |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
287 if ($publisher and strlen($publisher)>30) { |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
288 $publisher=substr($publisher,0,30); |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
289 } |
|
25
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
290 if ($author and strlen($author)>30) { |
|
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
291 $author=substr($author,0,30); |
|
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
292 } |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
293 if ($title and strlen($title)>100) { |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
294 $title=substr($title,0,100); |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
295 } |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
296 $publisher=mysqli_real_escape_string($link,$publisher); |
|
25
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
297 $author=mysqli_real_escape_string($link,$author); |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
298 $title=mysqli_real_escape_string($link,$title); |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
299 if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";} |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
300 if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";} |
|
25
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
301 if (strlen($pubDate)==0) { |
|
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
302 $pubDate="null"; |
|
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
303 } |
|
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
304 else { |
|
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
305 $pubDate="\"$pubDate\""; |
|
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
306 } |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
307 /*echo $title; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
308 echo $author; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
309 echo $binding; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
310 echo $dewey; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
311 echo $imageURL; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
312 echo $salesRank; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
313 echo $pubDate; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
314 echo $publisher;*/ |
| 2 | 315 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
316 $genreID = ""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
317 $genre = ""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
318 $genArr = array(); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
319 $g1 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
320 $g2 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
321 $g3 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
322 if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){ |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
323 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
324 //sexy recursive function |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
325 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); |
| 2 | 326 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
327 if($genre != "") |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
328 $genArr[strval($genreID)] = strval($genre); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
329 //$genArr[$i] = array(strval($genreID) => strval($genre)); |
| 2 | 330 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
331 //echo $genre; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
332 //echo $genreID; |
| 2 | 333 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
334 $genre = ""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
335 $genreID = ""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
336 } |
| 2 | 337 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
338 $g1 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
339 $g2 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
340 $g3 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
341 $loop = 1; |
| 2 | 342 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
343 foreach ($genArr as $key => $value) { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
344 //echo "$key => $value"; |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
345 if ($key>2047) { |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
346 //HST added |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
347 break; |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
348 } |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
349 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
350 //echo $queryG; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
351 $resG = mysqli_query($link, $queryG); |
| 2 | 352 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
353 switch ($loop) { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
354 case 1: |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
355 $g1 = $key; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
356 break; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
357 case 2: |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
358 $g2 = $key; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
359 break; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
360 case 3: |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
361 $g3 = $key; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
362 break; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
363 } |
| 2 | 364 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
365 $loop++; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
366 } |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
367 } |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
368 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
369 if($salesRank == "") |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
370 $salesRank = "null"; |
| 2 | 371 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
372 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
373 include "../../../private/db.php"; |
| 2 | 374 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
375 $title = strtr($title, '"', "'"); |
|
25
828895488948
more db column protection
Robert Boland <robert@markup.co.uk>
parents:
23
diff
changeset
|
376 $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,$pubDate,\"$publisher\",$g1,$g2,$g3,$loc)"; |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
377 //echo $queryInsert; |
| 2 | 378 |
|
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
379 $res = mysqli_query($link, $queryInsert); |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
380 if (!$res) { |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
381 $err=mysqli_error( $link ); |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
382 mysqli_close($link); |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
383 file_put_contents('/var/ywww/debug/phpDebug', |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
384 "anb failed: $err, $pubDate, $g2, $publisher, $title\n", |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
385 FILE_APPEND); |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
386 exit($err); |
|
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
387 } |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
388 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
| 2 | 389 |
| 390 | |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
391 $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
392 $output .= "<Title>" . htmlspecialchars($title) . "</Title>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
393 $output .= "<Author>" . htmlspecialchars($author) . "</Author>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
394 $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
395 $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
396 $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
397 $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
398 $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
399 $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
400 $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
401 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
402 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
403 $output .= "<ProductGroup>Book</ProductGroup>"; |
|
6
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
3
diff
changeset
|
404 } |
| 2 | 405 } |
| 406 | |
| 407 $output .= "</BookDetails>"; | |
| 408 | |
| 409 echo $output; | |
| 410 } | |
| 411 ?> |
