diff --git a/index.php b/index.php index 8b0555b..ad20c16 100644 --- a/index.php +++ b/index.php @@ -31,14 +31,33 @@ $tjson = getsslJSONfile ($_GET["root"], true); if(!$tjson) {$tjson = getsslJSONfile ($_GET["root"].".json", true);} -if (isset($tjson["@context"]) and $tjson["@context"] == "http://iiif.io/api/presentation/3/context.json") - {$rootDets = $tjson;} -else +$rootDets = false; + +if (isset($tjson["@context"])) { + if (is_array($tjson["@context"])) + { + if (in_array("http://iiif.io/api/presentation/3/context.json", $tjson["@context"])) + {$rootDets = $tjson;} + else if (in_array("https://iiif.io/api/presentation/3/context.json", $tjson["@context"])) + {$rootDets = $tjson;} + } + else if ($tjson["@context"] == "http://iiif.io/api/presentation/3/context.json") + {$rootDets = $tjson;} + } + +if (!$rootDets) {$rootDets = getsslJSONfile ($defaultPath.$defaultCollection, true); $_GET["root"] = $defaultCollection;} -$title = getLangValue ($rootDets["label"], "en"); -$comment = getLangValue ($rootDets["summary"], "en"); +if (isset($rootDets["label"])) + {$title = getLangValue ($rootDets["label"], "en");} +else + {$title = "Unknown";} + +if (isset($rootDets["summary"])) + {$comment = getLangValue ($rootDets["summary"], "en");} +else + {$comment = "";} $hasCols = false; $hasTable = false; @@ -72,12 +91,15 @@ { if ($avr["type"] == "Collection") {$hasCols = true;} - - $children[$avr["label"]["en"][0]] = $avr["id"]; - $path_parts = pathinfo($avr["id"]); - $avrList .= formatIIIFCard ($avr["id"], "./?root=".$path_parts["filename"]); - - $check = getsslJSONfile($avr["id"]); + + if (isset($avr["label"])) + {$clabel = getLangValue ($rootDets["label"], "en"); + $children[$clabel] = $avr["id"]; + $path_parts = pathinfo($avr["id"]); + $avrList .= formatIIIFCard ($avr["id"], "./?root=".$path_parts["filename"]); + $check = getsslJSONfile($avr["id"]);} + else + {$check = false;} if ($check) { @@ -113,7 +135,7 @@ $extraCSS .= $rootDets["table"]["cssScripts"]; } else - { + { $check = getsslJSONfile($rootDets["id"]); if ($check) {$cats[] = $rootDets["id"];} @@ -149,8 +171,9 @@ $M3Display = "block";} $mda = array(); + foreach ($rootDets["metadata"] as $k => $md) - {$tmp = getMDLVpair ($md); + {$tmp = getMDLVpair ($md); $mda[$tmp["label"]] = $tmp["value"];} if (isset($mda["Manifest Author"])) @@ -259,7 +282,7 @@ ]); END; $m3JS = ob_get_contents(); - ob_end_clean(); // Don't send output to client + ob_end_clean(); // Don't send output to client } else {$m3HTML = false; @@ -276,7 +299,10 @@ if (preg_match("/^.+href=.(http.+)[\"][>](.+)[<].+$/", $mvv, $m)) {$mvv = $m[1]; $mvk = $m[2];} - $links[] = "$mvk"; + + // Only include values that are links + if (filter_var($mvv, FILTER_VALIDATE_URL)) + {$links[] = "$mvk";} //// Could pull details from NG website - but does not work due to network issues. //if (preg_match("/^.+article$/", $mvk, $m)) @@ -290,13 +316,15 @@ { // in case links have been wrapped in html if (preg_match("/^.+href=.(http.+)[\"][>].+$/", $mv, $m)) - {$mv = $m[1];} - $links[] = "$mk"; + {$mv = $m[1];} + // Only include values that are links + if (filter_var($mv, FILTER_VALIDATE_URL)) + {$links[] = "$mk";} } } $links = implode(", ", $links); if ($links) - {$links = "
National Gallery Website Links
".$links;} + {$links = "
Additional Links
".$links;} ob_start(); echo << @@ -458,9 +485,20 @@