Mercurial > hg > ywww
comparison xml/getAmazonInfo.php @ 31:4124f103b46b
fix old :-( preg bug,
finally (?) get length and escaping right
author | Robert Boland <robert@markup.co.uk> |
---|---|
date | Fri, 04 Jan 2019 08:52:01 -0500 |
parents | 828895488948 |
children | 8130865e9e82 |
comparison
equal
deleted
inserted
replaced
30:b1bbf44c701b | 31:4124f103b46b |
---|---|
135 $review1 = ""; | 135 $review1 = ""; |
136 $review2 = ""; | 136 $review2 = ""; |
137 $review3 = ""; | 137 $review3 = ""; |
138 // HST added this | 138 // HST added this |
139 $mm=array(); | 139 $mm=array(); |
140 if (preg_match("<Error>",$output,$mm)) { | 140 if (preg_match("/<Error>/",$output,$mm)) { |
141 $xml = new SimpleXMLElement($output); | 141 $xml = new SimpleXMLElement($output); |
142 $resName=$xml->getName(); | 142 $resName=$xml->getName(); |
143 $code=$xml->Error->Code; | 143 $code=$xml->Error->Code; |
144 if (!$code) { | 144 if (!$code) { |
145 $code=$xml->Items->Request->Errors->Error->Code; | 145 $code=$xml->Items->Request->Errors->Error->Code; |
146 } | 146 } |
147 $errorCode=$code; | |
147 file_put_contents('/var/ywww/debug/phpDebug',"Losing: ".$mm[0].", $resName, $code, $requestIP, $requestURI\n",FILE_APPEND); | 148 file_put_contents('/var/ywww/debug/phpDebug',"Losing: ".$mm[0].", $resName, $code, $requestIP, $requestURI\n",FILE_APPEND); |
148 if ($code=='RequestThrottled') { | 149 if ($code=='RequestThrottled') { |
149 usleep(200000); // Try to reduce throttling until we get a | 150 usleep(200000); // Try to reduce throttling until we get a |
150 // principled solution in place | 151 // principled solution in place |
151 } | 152 } |
290 if($go == 1) { | 291 if($go == 1) { |
291 $item = $xml->Items->Item[0]; | 292 $item = $xml->Items->Item[0]; |
292 if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) { | 293 if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) { |
293 $title = $item->ItemAttributes->Title; } | 294 $title = $item->ItemAttributes->Title; } |
294 else { $title = "[no title]"; }; | 295 else { $title = "[no title]"; }; |
295 file_put_contents('/var/ywww/debug/phpDebug',"win: ". | 296 file_put_contents('/var/ywww/debug/phpDebug',"win: |$errorCode| ". |
296 $title."\n", | 297 $title."\n", |
297 FILE_APPEND); | 298 FILE_APPEND); |
298 return $output; | 299 return $output; |
299 } | 300 } |
300 else | 301 else |
316 } | 317 } |
317 else { | 318 else { |
318 $pubDate="\"$pubDate\""; | 319 $pubDate="\"$pubDate\""; |
319 } | 320 } |
320 $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher; | 321 $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher; |
321 if ($publisher and strlen($publisher)>30) { | |
322 $publisher=substr($publisher,0,30); | |
323 } | |
324 if ($author and strlen($author)>30) { | |
325 $author=substr($author,0,30); | |
326 } | |
327 if ($title and strlen($title)>100) { | |
328 $title=substr($title,0,100); | |
329 } | |
330 $publisher=mysqli_real_escape_string($link,$publisher); | |
331 $author=mysqli_real_escape_string($link,$author); | |
332 $title=mysqli_real_escape_string($link,$title); | |
333 } | 322 } |
334 else { | 323 else { |
335 $title = $salesRank = ""; | 324 $title = $salesRank = ""; |
336 $dewey = "null"; | 325 $dewey = "null"; |
337 } | 326 } |
390 } | 379 } |
391 | 380 |
392 if($salesRank == "") | 381 if($salesRank == "") |
393 $salesRank = "null"; | 382 $salesRank = "null"; |
394 | 383 |
395 $title = strtr($title, '"', "'"); | |
396 include "../../private/db.php"; | |
397 $review1 = mysqli_real_escape_string($link,$review1); | |
398 if (strlen($review1)>500) { $review1=substr($review1,0,500);} | |
399 $review2 = mysqli_real_escape_string($link,$review2); | |
400 if (strlen($review2)>500) { $review2=substr($review2,0,500);} | |
401 $review3 = mysqli_real_escape_string($link,$review3); | |
402 if (strlen($review3)>500) { $review3=substr($review3,0,500);} | |
403 | |
404 if($title != "") | 384 if($title != "") |
405 { | 385 { |
406 $queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; | 386 include "../../private/db.php"; |
387 if ($publisher->count()==0) { | |
388 $publisher="null"; | |
389 } | |
390 else { | |
391 $publisher=mysqli_real_escape_string($link,$publisher); | |
392 if (strlen($publisher)>30) { | |
393 $publisher=rtrim(substr($publisher,0,30),"\\"); | |
394 } | |
395 $publisher="\"".$publisher."\""; | |
396 } | |
397 if ($author->count()==0) { | |
398 $author="unknown"; | |
399 } | |
400 else { | |
401 $author=mysqli_real_escape_string($link,$author); | |
402 if (strlen($author)>30) { | |
403 $author=rtrim(substr($author,0,30),"\\"); | |
404 } | |
405 } | |
406 $author="\"".$author."\""; | |
407 $title=mysqli_real_escape_string($link,$title); | |
408 if (strlen($title)>100) { | |
409 $title=rtrim(substr($title,0,100),"\\"); | |
410 } | |
411 $title="\"".$title."\""; | |
412 $review1 = mysqli_real_escape_string($link,$review1); | |
413 if (strlen($review1)>500) { $review1=rtrim(substr($review1,0,500),"\\");} | |
414 $review2 = mysqli_real_escape_string($link,$review2); | |
415 if (strlen($review2)>500) { $review2=rtrim(substr($review2,0,500),"\\");} | |
416 $review3 = mysqli_real_escape_string($link,$review3); | |
417 if (strlen($review3)>500) { $review3=rtrim(substr($review3,0,500),"\\");} | |
418 | |
419 $queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",$title, $author,\"$binding\",\"$imageURL\", $dewey, $salesRank,$pubDate,$publisher,$g1,$g2,$g3,$loc)"; | |
407 //echo $queryInsert; | 420 //echo $queryInsert; |
408 | 421 |
409 $res = mysqli_query($link, $queryInsert); | 422 $res = mysqli_query($link, $queryInsert); |
410 if (!$res) { | 423 if (!$res) { |
411 $err=mysqli_error( $link ); | 424 $err=mysqli_error( $link ); |
412 mysqli_close($link); | 425 mysqli_close($link); |
413 file_put_contents('/var/ywww/debug/phpDebug', | 426 file_put_contents('/var/ywww/debug/phpDebug', |
414 "anb failed: $err, $pubDate, $g2, $publisher, $title\n", | 427 "anb failed: $queryInsert\n$err\n", |
415 FILE_APPEND); | 428 FILE_APPEND); |
416 exit($err); | 429 exit($err); |
417 } | 430 } |
418 $queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")"; | 431 $queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")"; |
419 if($review1 != "" && $review2 != "" && $review3 != "") { | 432 if($review1 != "") { |
420 $res = mysqli_query($link, $queryInsertReviews); | 433 $res = mysqli_query($link, $queryInsertReviews); |
421 if (!$res) { | 434 if (!$res) { |
422 $err=mysqli_error( $link ); | 435 $err=mysqli_error( $link ); |
423 mysqli_close($link); | 436 mysqli_close($link); |
424 file_put_contents('/var/ywww/debug/phpDebug', | 437 file_put_contents('/var/ywww/debug/phpDebug', |
425 "anr failed: $err, $pubDate, $g2, $publisher, $title\n", | 438 "anr failed: $queryInsertReviews\n", |
426 FILE_APPEND); | 439 FILE_APPEND); |
427 exit($err); | 440 exit($err); |
428 } | 441 } |
429 } | 442 } |
430 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | 443 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |