diff us/index.php @ 19:84a412b8122c

try to protect against a range of missing info
author Charlie Root
date Thu, 30 Aug 2018 17:18:12 -0400
parents 226f00d9f6f5
children d606320ec331
line wrap: on
line diff
--- 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>