Refactor BookReaderImages and BookReaderMeta. New BookReaderPreview to provide acces...
[bookreader.git] / BookReaderIA / datanode / BookReaderJSIA.php
old mode 100755 (executable)
new mode 100644 (file)
index dabfd46..e549d44
@@ -48,7 +48,7 @@ if ("" == $server) {
     BRFatal("No server specified!");
 }
 
-if (!preg_match("|^/[0-3]/items/{$id}$|", $itemPath)) {
+if (!preg_match("|^/\d+/items/{$id}$|", $itemPath)) {
     BRFatal("Bad id!");
 }
 
@@ -224,6 +224,16 @@ br.getPageNum = function(index) {
     }
 }
 
+// Single images in the Internet Archive scandata.xml metadata are (somewhat incorrectly)
+// given a "leaf" number.  Some of these images from the scanning process should not
+// be displayed in the BookReader (for example colour calibration cards).  Since some
+// of the scanned images will not be displayed in the BookReader (those marked with
+// addToAccessFormats false in the scandata.xml) leaf numbers and BookReader page
+// indexes are generally not the same.  This function returns the BookReader page
+// index given a scanned leaf number.
+//
+// This function is used, for example, to map between search results (that use the
+// leaf numbers) and the displayed pages in the BookReader.
 br.leafNumToIndex = function(leafNum) {
     for (var index = 0; index < this.leafMap.length; index++) {
         if (this.leafMap[index] == leafNum) {
@@ -311,7 +321,7 @@ br.getEmbedCode = function() {
     return "<iframe src='" + this.getEmbedURL() + "' width='480px' height='430px'></iframe>";
 }
 
-br.pageW =             [
+br.pageW =  [
             <?
             $i=0;
             foreach ($scanData->pageData->page as $page) {
@@ -324,7 +334,7 @@ br.pageW =          [
             ?>
             ];
 
-br.pageH =             [
+br.pageH =  [
             <?
             $totalHeight = 0;
             $i=0;            
@@ -455,19 +465,25 @@ function shouldAddPage($page) {
 // Returns { 'imageFormat' => , 'archiveFormat' => '} given a sub-item prefix and loaded xml data
 function findImageStack($subPrefix, $filesData) {
 
-    // $$$ Add jpeg here
-    $imageFormats = array('TIFF' => 'tif', 'JP2' => 'jp2', 'JPEG' => 'jpg');
+    // $$$ The order of the image formats determines which will be returned first
+    $imageFormats = array('JP2' => 'jp2', 'TIFF' => 'tif', 'JPEG' => 'jpg');
     $archiveFormats = array('ZIP' => 'zip', 'Tar' => 'tar');
     $imageGroup = implode('|', array_keys($imageFormats));
     $archiveGroup = implode('|', array_keys($archiveFormats));
+    // $$$ Currently only return processed images
     $imageStackRegex = "/Single Page (Processed) (${imageGroup}) (${archiveGroup})/";
         
     foreach ($filesData->file as $file) {        
-        if (strpos($file['name'], $subPrefix) === 0) { // subprefix matches beginning    
+        if (strpos($file['name'], $subPrefix) === 0) { // subprefix matches beginning
             if (preg_match($imageStackRegex, $file->format, $matches)) {
-                return array('imageFormat' => $imageFormats[$matches[2]],
-                             'archiveFormat' => $archiveFormats[$matches[3]],
-                             'imageStackFile' => $file['name']);
+            
+                // Make sure we have a regular image stack
+                $imageFormat = $imageFormats[$matches[2]];
+                if (strpos($file['name'], $subPrefix . '_' . $imageFormat) === 0) {            
+                    return array('imageFormat' => $imageFormat,
+                                 'archiveFormat' => $archiveFormats[$matches[3]],
+                                 'imageStackFile' => $file['name']);
+                }
             }
         }
     }