From 143b7e3a73fa553e21f8130ca521f1503c32cac5 Mon Sep 17 00:00:00 2001 From: Michael Ang Date: Tue, 27 Apr 2010 21:59:10 +0000 Subject: [PATCH] Better handling of bookId in metadata generation. Add getURL for handling /download/ in BookReader.inc --- BookReaderIA/datanode/BookReaderMeta.inc.php | 14 +++--- BookReaderIA/inc/BookReader.inc | 45 +++++++++++++++++++- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/BookReaderIA/datanode/BookReaderMeta.inc.php b/BookReaderIA/datanode/BookReaderMeta.inc.php index ce77e62..7b5910b 100644 --- a/BookReaderIA/datanode/BookReaderMeta.inc.php +++ b/BookReaderIA/datanode/BookReaderMeta.inc.php @@ -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} diff --git a/BookReaderIA/inc/BookReader.inc b/BookReaderIA/inc/BookReader.inc index e30b0d9..a1e1839 100644 --- a/BookReaderIA/inc/BookReader.inc +++ b/BookReaderIA/inc/BookReader.inc @@ -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 -- 2.20.1