Mercurial > hg > ywww
changeset 19:84a412b8122c
try to protect against a range of missing info
author | Charlie Root |
---|---|
date | Thu, 30 Aug 2018 17:18:12 -0400 |
parents | c41a5802b26c |
children | 7679346abfdb |
files | ca/index.php de/index.php fr/index.php index.php php/read/updateLink.php uk/index.php us/index.php xml/getAmazonInfo.php |
diffstat | 8 files changed, 284 insertions(+), 109 deletions(-) [+] |
line wrap: on
line diff
--- a/ca/index.php Sun Jul 30 05:34:46 2017 -0400 +++ b/ca/index.php Thu Aug 30 17:18:12 2018 -0400 @@ -60,7 +60,7 @@ { echo "<head>"; echo "<meta name=\"fragment\" content=\"!\">"; - + echo "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />"; echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"; echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"../Books.css\">"; @@ -140,8 +140,25 @@ { $bookDetails = getAmazonDet($isbn,1,'ca'); $bookXML = new SimpleXMLElement($bookDetails); - $title = $bookXML->Items->Item[0]->ItemAttributes->Title; - $author = $bookXML->Items->Item[0]->ItemAttributes->Author; + if ($bookXML->Items && $bookXML->Items->Item[0] && + $bookXML->Items->Item[0]->ItemAttributes) + { $attrs=$bookXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $title = $attrs->Title; } + else { + $title ="[no Title]"; + } + if ($attrs->Author) { + $author = $attrs->Author; + } + else { + $author ="[no Author]"; + } + } + else { + $title ="[no Title]"; + $author = "[no Author]"; + } } $linkedBooks = include "../php/read/getLinkedBooks.php"; @@ -166,8 +183,21 @@ { $bookLDetails = getAmazonDet($linkedISBN,1,'ca'); $bookLXML = new SimpleXMLElement($bookLDetails); - $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title; - $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author; + if ($bookLXML->Items && + $bookLXML->Items->Item[0] && + $bookLXML->Items->Item[0]->ItemAttributes) { + $attrs=$bookLXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $titleL = $attrs->Title; } + else { + $titleL = ""; } + if ($attrs->Author) { + $authorL = $attrs->Author; } + else { + $authorL = ""; } + } + else { + $titleL = ""; } } if($titleL != "") { @@ -204,6 +234,7 @@ echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../raphael-min.js\"></script>"; echo $launchScript;//"<script type=\"text/javascript\" language=\"javascript\" src=\"../books/books.nocache.js\"></script>"; } + echo "</head>"; echo "<body>"; @@ -222,7 +253,7 @@ catch(Exception $e) { echo 'Message: ' .$e->getMessage(); - } + } } } else @@ -252,6 +283,7 @@ echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../raphael-min.js\"></script>"; echo $launchScript;//"<script type=\"text/javascript\" language=\"javascript\" src=\"../books/books.nocache.js\"></script>"; } + echo "</head>"; echo "<body>"; @@ -271,7 +303,7 @@ FB.Canvas.setSize(obj); </script>"; } - } + } ?> <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
--- a/de/index.php Sun Jul 30 05:34:46 2017 -0400 +++ b/de/index.php Thu Aug 30 17:18:12 2018 -0400 @@ -124,7 +124,7 @@ $ret = 1; $countryCode = 3; - include "../../private/db.php"; + include "../../private/db.php"; $query = "CALL b_getBookInfo('$isbn', $countryCode)"; //echo $query; $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); @@ -138,10 +138,27 @@ } else { - $bookDetails = getAmazonDet($isbn,1,'ca'); + $bookDetails = getAmazonDet($isbn,1,'de'); $bookXML = new SimpleXMLElement($bookDetails); - $title = $bookXML->Items->Item[0]->ItemAttributes->Title; - $author = $bookXML->Items->Item[0]->ItemAttributes->Author; + if ($bookXML->Items && $bookXML->Items->Item[0] && + $bookXML->Items->Item[0]->ItemAttributes) + { $attrs=$bookXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $title = $attrs->Title; } + else { + $title ="[no Title]"; + } + if ($attrs->Author) { + $author = $attrs->Author; + } + else { + $author ="[no Author]"; + } + } + else { + $title ="[no Title]"; + $author = "[no Author]"; + } } $linkedBooks = include "../php/read/getLinkedBooks.php"; @@ -166,8 +183,21 @@ { $bookLDetails = getAmazonDet($linkedISBN,1,'de'); $bookLXML = new SimpleXMLElement($bookLDetails); - $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title; - $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author; + if ($bookLXML->Items && + $bookLXML->Items->Item[0] && + $bookLXML->Items->Item[0]->ItemAttributes) { + $attrs=$bookLXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $titleL = $attrs->Title; } + else { + $titleL = ""; } + if ($attrs->Author) { + $authorL = $attrs->Author; } + else { + $authorL = ""; } + } + else { + $titleL = ""; } } if($titleL != "") { @@ -273,7 +303,7 @@ FB.Canvas.setSize(obj); </script>"; } - } + } ?> <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
--- a/fr/index.php Sun Jul 30 05:34:46 2017 -0400 +++ b/fr/index.php Thu Aug 30 17:18:12 2018 -0400 @@ -117,7 +117,7 @@ } else { - try{ + try{ $isbn = substr($isbn, 5); $chars = explode("/",$isbn); $isbn = $chars[0]; @@ -140,8 +140,25 @@ { $bookDetails = getAmazonDet($isbn,1,'fr'); $bookXML = new SimpleXMLElement($bookDetails); - $title = $bookXML->Items->Item[0]->ItemAttributes->Title; - $author = $bookXML->Items->Item[0]->ItemAttributes->Author; + if ($bookXML->Items && $bookXML->Items->Item[0] && + $bookXML->Items->Item[0]->ItemAttributes) + { $attrs=$bookXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $title = $attrs->Title; } + else { + $title ="[no Title]"; + } + if ($attrs->Author) { + $author = $attrs->Author; + } + else { + $author ="[no Author]"; + } + } + else { + $title ="[no Title]"; + $author = "[no Author]"; + } } $linkedBooks = include "../php/read/getLinkedBooks.php"; @@ -166,8 +183,21 @@ { $bookLDetails = getAmazonDet($linkedISBN,1,'fr'); $bookLXML = new SimpleXMLElement($bookLDetails); - $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title; - $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author; + if ($bookLXML->Items && + $bookLXML->Items->Item[0] && + $bookLXML->Items->Item[0]->ItemAttributes) { + $attrs=$bookLXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $titleL = $attrs->Title; } + else { + $titleL = ""; } + if ($attrs->Author) { + $authorL = $attrs->Author; } + else { + $authorL = ""; } + } + else { + $titleL = ""; } } if($titleL != "") { @@ -245,13 +275,13 @@ </noscript>"; if($iPhone && !$iPad) { - echo "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />"; - echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../booksMob/books.nocache.js\"></script>"; + echo "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />"; + echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../booksMob/books.nocache.js\"></script>"; } else { - echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../raphael-min.js\"></script>"; - echo $launchScript;//"<script type=\"text/javascript\" language=\"javascript\" src=\"../books/books.nocache.js\"></script>"; + echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../raphael-min.js\"></script>"; + echo $launchScript;//"<script type=\"text/javascript\" language=\"javascript\" src=\"../books/books.nocache.js\"></script>"; } echo "</head>"; @@ -273,7 +303,7 @@ FB.Canvas.setSize(obj); </script>"; } - } + } ?> <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
--- a/index.php Sun Jul 30 05:34:46 2017 -0400 +++ b/index.php Thu Aug 30 17:18:12 2018 -0400 @@ -35,5 +35,6 @@ <meta name="google-site-verification" content="0XCtbGM_bvOH363P2XE6DVjh-APTICOREquY8F38T84" /> </HEAD> <body> +<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=322bafc0-69fa-4664-8e1c-0b9159259748"></script> </body>
--- a/php/read/updateLink.php Sun Jul 30 05:34:46 2017 -0400 +++ b/php/read/updateLink.php Thu Aug 30 17:18:12 2018 -0400 @@ -6,6 +6,7 @@ echo $change; $dir = strval($_GET['dir']); echo $dir; +$userID=""; $userID = strval($_GET['userID']); echo $userID;
--- a/uk/index.php Sun Jul 30 05:34:46 2017 -0400 +++ b/uk/index.php Thu Aug 30 17:18:12 2018 -0400 @@ -140,8 +140,25 @@ { $bookDetails = getAmazonDet($isbn,1,'uk'); $bookXML = new SimpleXMLElement($bookDetails); - $title = $bookXML->Items->Item[0]->ItemAttributes->Title; - $author = $bookXML->Items->Item[0]->ItemAttributes->Author; + if ($bookXML->Items && $bookXML->Items->Item[0] && + $bookXML->Items->Item[0]->ItemAttributes) + { $attrs=$bookXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $title = $attrs->Title; } + else { + $title ="[no Title]"; + } + if ($attrs->Author) { + $author = $attrs->Author; + } + else { + $author ="[no Author]"; + } + } + else { + $title ="[no Title]"; + $author = "[no Author]"; + } } $linkedBooks = include "../php/read/getLinkedBooks.php"; @@ -166,8 +183,21 @@ { $bookLDetails = getAmazonDet($linkedISBN,1,'uk'); $bookLXML = new SimpleXMLElement($bookLDetails); - $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title; - $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author; + if ($bookLXML->Items && + $bookLXML->Items->Item[0] && + $bookLXML->Items->Item[0]->ItemAttributes) { + $attrs=$bookLXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $titleL = $attrs->Title; } + else { + $titleL = ""; } + if ($attrs->Author) { + $authorL = $attrs->Author; } + else { + $authorL = ""; } + } + else { + $titleL = ""; } } if($titleL != "") {
--- a/us/index.php Sun Jul 30 05:34:46 2017 -0400 +++ b/us/index.php Thu Aug 30 17:18:12 2018 -0400 @@ -151,16 +151,41 @@ // principled solution in place } $title = ""; + $author = ""; } else { - $title = $bookXML->Items->Item[0]->ItemAttributes->Title; - $author = $bookXML->Items->Item[0]->ItemAttributes->Author; + if ($bookXML->Items && $bookXML->Items->Item[0] && + $bookXML->Items->Item[0]->ItemAttributes) + { $attrs=$bookXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $title = $attrs->Title; } + else { + $title ="[no Title]"; + } + if ($attrs->Author) { + $author = $attrs->Author; + } + else { + $author ="[no Author]"; + } + } + else { + $title ="[no Title]"; + $author = "[no Author]"; + } } } - $linkedBooks = include "../php/read/getLinkedBooks.php"; + $linkedBooks = include "../php/read/getLinkedBooks.php"; + try { $xml = new SimpleXMLElement($linkedBooks); - + } + catch (Exception $e) { + file_put_contents('/var/ywww/debug/phpDebug', + "Bad XML?: ".$linkedBooks, + FILE_APPEND); + throw $e; + } $recommended = ""; $linkedRecommended = ""; for($i=0;$i<sizeof($xml->isbn);$i++){ @@ -202,8 +227,21 @@ $titleL = ""; } else { - $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title; - $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author; + if ($bookLXML->Items && + $bookLXML->Items->Item[0] && + $bookLXML->Items->Item[0]->ItemAttributes) { + $attrs=$bookLXML->Items->Item[0]->ItemAttributes; + if ($attrs->Title) { + $titleL = $attrs->Title; } + else { + $titleL = ""; } + if ($attrs->Author) { + $authorL = $attrs->Author; } + else { + $authorL = ""; } + } + else { + $titleL = ""; } } } restore_error_handler(); @@ -327,5 +365,6 @@ pageTracker._setAllowLinker(true); pageTracker._trackPageview(); } catch(err) {}</script> - </body> + <script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=322bafc0-69fa-4664-8e1c-0b9159259748"></script> + </body> </html>
--- a/xml/getAmazonInfo.php Sun Jul 30 05:34:46 2017 -0400 +++ b/xml/getAmazonInfo.php Thu Aug 30 17:18:12 2018 -0400 @@ -108,6 +108,9 @@ /*$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>");*/ $review = ""; + $review1 = ""; + $review2 = ""; + $review3 = ""; // HST added this if (preg_match("<Error>",$output)) { $xml = new SimpleXMLElement($output); @@ -145,9 +148,6 @@ // cause restore_error_handler(); //echo $review; - $review1 = ""; - $review2 = ""; - $review3 = ""; } if ($review != "") { @@ -260,95 +260,107 @@ if($errorCode != "AccountLimitExceeded") { 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: ". - $xml->Items->Item->ItemAttributes->Title."\n", + $title."\n", FILE_APPEND); return $output; } - else - { - $title = $xml->Items->Item->ItemAttributes->Title; - $author = $xml->Items->Item->ItemAttributes->Author; - $binding = $xml->Items->Item->ItemAttributes->Binding; - $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber; - if($dewey == "") - $dewey = "null"; - $imageURL = $xml->Items->Item->MediumImage->URL; - $salesRank = $xml->Items->Item->SalesRank; - $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate; - $publisher = $xml->Items->Item->ItemAttributes->Publisher; - - $genreID = ""; - $genre = ""; - $genArr = array(); + 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; + $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher; + } + else { + $title = $salesRank = ""; + $dewey = "null"; + } - for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ - //sexy recursive function - findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); + $genreID = ""; + $genre = ""; + $genArr = array(); + + if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) { + for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ + //sexy recursive function + findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); - if($genre != "") - $genArr[strval($genreID)] = strval($genre); - //$genArr[$i] = array(strval($genreID) => strval($genre)); + if($genre != "") + $genArr[strval($genreID)] = strval($genre); + //$genArr[$i] = array(strval($genreID) => strval($genre)); - //echo $genre; - //echo $genreID; + //echo $genre; + //echo $genreID; - $genre = ""; - $genreID = ""; - } + $genre = ""; + $genreID = ""; + } + } - $g1 = "null"; - $g2 = "null"; - $g3 = "null"; - $loop = 1; + $g1 = "null"; + $g2 = "null"; + $g3 = "null"; + $loop = 1; - foreach ($genArr as $key => $value) { - //echo "$key => $value"; - $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table - //echo $queryG; - include "../../private/db.php"; - $resG = mysqli_query($link, $queryG); - mysqli_close($link); + foreach ($genArr as $key => $value) { + //echo "$key => $value"; + $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table + //echo $queryG; + include "../../private/db.php"; + $resG = mysqli_query($link, $queryG); + mysqli_close($link); - switch ($loop) { - case 1: - $g1 = $key; - break; - case 2: - $g2 = $key; - break; - case 3: - $g3 = $key; - break; - } + switch ($loop) { + case 1: + $g1 = $key; + break; + case 2: + $g2 = $key; + break; + case 3: + $g3 = $key; + break; + } - $loop++; - } + $loop++; + } - if($salesRank == "") - $salesRank = "null"; + if($salesRank == "") + $salesRank = "null"; - $title = strtr($title, '"', "'"); - include "../../private/db.php"; - $review1 = mysqli_real_escape_string($link,$review1); - $review2 = mysqli_real_escape_string($link,$review2); - $review3 = mysqli_real_escape_string($link,$review3); + $title = strtr($title, '"', "'"); + include "../../private/db.php"; + $review1 = mysqli_real_escape_string($link,$review1); + $review2 = mysqli_real_escape_string($link,$review2); + $review3 = mysqli_real_escape_string($link,$review3); - if($title != "") - { - $queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; - //echo $queryInsert; - $queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")"; + if($title != "") + { + $queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; + //echo $queryInsert; + $queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")"; - $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); - if($review1 != "" && $review2 != "" && $review3 != "") - $resG = mysqli_query($link, $queryInsertReviews) or exit( mysqli_error( $link )); + $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); + if($review1 != "" && $review2 != "" && $review3 != "") + $resG = mysqli_query($link, $queryInsertReviews) or exit( mysqli_error( $link )); - mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop - } + mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop + } - echo $output; - } + echo $output; + } } else {