diff fr/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 077b0a0a3e6d
children a67bf725e87b
line wrap: on
line diff
--- 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>