Better handling of bookId in metadata generation. Add getURL for handling /download...
authorMichael Ang <mang@archive.org>
Tue, 27 Apr 2010 21:59:10 +0000 (21:59 +0000)
committerMichael Ang <mang@archive.org>
Tue, 27 Apr 2010 21:59:10 +0000 (21:59 +0000)
BookReaderIA/datanode/BookReaderMeta.inc.php
BookReaderIA/inc/BookReader.inc

index ce77e62..7b5910b 100644 (file)
@@ -31,10 +31,10 @@ class BookReaderMeta {
     
         $response = array();
         
-        if (! $subPrefix) {
-            $subPrefix = $id;
+        if (! $bookId) {
+            $bookId = $id;
         }
-        $subItemPath = $itemPath . '/' . $subPrefix;
+        $subItemPath = $itemPath . '/' . $bookId;
         
         if ("" == $id) {
             $this->BRFatal("No identifier specified!");
@@ -62,7 +62,7 @@ class BookReaderMeta {
             $this->BRfatal("File metadata not found!");
         }
         
-        $imageStackInfo = $this->findImageStack($subPrefix, $filesData);
+        $imageStackInfo = $this->findImageStack($bookId, $filesData);
         if ($imageStackInfo['imageFormat'] == 'unknown') {
             $this->BRfatal('Couldn\'t find image stack');
         }
@@ -166,7 +166,7 @@ class BookReaderMeta {
         
         // Internet Archive specific
         $response['itemId'] = $id; // XXX renamed
-        $response['bookId'] = $subPrefix;  // XXX renamed
+        $response['bookId'] = $bookId;  // XXX renamed
         $response['zip'] = $imageStackFile;
         $response['server'] = $server;
         $response['imageFormat'] = $imageFormat;
@@ -292,6 +292,10 @@ class BookReaderMeta {
         }
     }
     
+    function leafForIndex($index, $leafNums) {
+        return $leafNums[$index]; // $$$ todo change to instance variables
+    }
+    
     function imageURL($leafNum, $metadata, $scale, $rotate) {
         // "Under the hood", non-public, dynamically changing (achtung!) image URLs currently look like:
         // http://{server}/BookReader/BookReaderImages.php?zip={zipPath}&file={filePath}&scale={scale}&rotate={rotate}
index e30b0d9..a1e1839 100644 (file)
@@ -205,5 +205,48 @@ class BookReader
     return $url;
   }
   
+  // Return the URL for the requested /download/$path, or null
+  public static function getURL($path, $item) {
+    // $path should look like {itemId}/{operator}/{filename}
+    // Other operators may be added
+    
+    $parts = preg_split('#/#', $path, 3);
+    if (count($parts) != 3) {
+        return null;
+    }
+    $identifier = $parts[0];
+    $operator = $parts[1];
+    $filename = $parts[2];
+    
+    $serverBaseURL = BookReader::serverBaseURL($item->getServer());
+            
+    switch ($operator) {
+        case 'page':
+            // Find bookId and which page was requested
+            $pathParts = pathinfo($filename);
+            
+            // Look for preview request
+            if (preg_match('/^(.*)_(cover|title|preview)$/', $pathParts['filename'], $matches) === 0) {
+                return null;
+            }
+            $bookId = $matches[1];
+            $page = $matches[2];
+            $query = array(
+                'id' => $identifier,
+                'bookId' => $bookId,
+                'itemPath' => $item->getMainDir(),
+                'server' => $serverBaseURL,
+                'page' => $page,
+            );
+            return 'http://' . $serverBaseURL . '/BookReader/BookReaderPreview.php?' . http_build_query($query, '', '&');
+        
+        default:
+            return null;            
+    }
+      
+    return null; // was not handled
+  }
+  
 }
-  ?>
+
+?>
\ No newline at end of file