} else {
$callback = null;
}
-
+
+ if ( !file_exists($zipPath) ) {
+ $this->BRfatal('Image stack does not exist');
+ }
// Make sure the image stack is readable - return 403 if not
$this->checkPrivs($zipPath);
$filenameForClient = $this->filenameForClient($file, $ext);
- $headers = array('Content-type: '. $MIMES[$ext],
+ $headers = array('Content-type: '. $MIMES[$ext], // XXX is nginx swallowing this?
'Cache-Control: max-age=15552000',
'Content-disposition: inline; filename=' . $filenameForClient);
--- /dev/null
+<?php
+
+/*
+Copyright(c) 2008-2010 Internet Archive. Software license AGPL version 3.
+
+This file is part of BookReader. The full source code can be found at GitHub:
+http://github.com/openlibrary/bookreader
+
+The canonical short name of an image type is the same as in the MIME type.
+For example both .jpeg and .jpg are considered to have type "jpeg" since
+the MIME type is "image/jpeg".
+
+ BookReader is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BookReader is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with BookReader. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// Include BookReaderImages class definition
+require_once('BookReaderImages.inc.php');
+
+// Serve request
+$bri = new BookReaderImages();
+$bri->serveRequest($_REQUEST);
+
+?>
+
--- /dev/null
+<?
+/*
+
+Builds metadata about a book on the Internet Archive in json(p) format so that the book
+can be accessed by other software including the Internet Archive BookReader.
+
+Michael Ang <http://github.com/mangtronix>
+
+Copyright (c) 2008-2010 Internet Archive. Software license AGPL version 3.
+
+This file is part of BookReader.
+
+ BookReader is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BookReader is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with BookReader. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+require_once('BookReaderMeta.inc.php');
+
+$brm = new BookReaderMeta();
+$brm->processRequest($_REQUEST);
+
+
+?>
// Internet Archive specific
$response['itemId'] = $id; // XXX renamed
$response['bookId'] = $bookId; // XXX renamed
+ $response['itemPath'] = $itemPath;
$response['zip'] = $imageStackFile;
$response['server'] = $server;
$response['imageFormat'] = $imageFormat;
$response['archiveFormat'] = $archiveFormat;
$response['leafNums'] = $leafNums;
+ $response['previewImage'] = $this->previewURL('preview', $response);
// URL to title image
if ('' != $titleLeaf) {
- $response['titleImage'] = $this->imageURL($titleLeaf, $response);
+ $response['titleImage'] = $this->previewURL('title', $response);
}
if (count($coverLeafs) > 0) {
$coverImages = array();
foreach ($coverLeafs as $key => $leafNum) {
array_push($coverIndices, $this->indexForLeaf($leafNum, $leafNums));
+ // $$$ TODO use preview API once it supports multiple covers
array_push($coverImages, $this->imageUrl($leafNum, $response));
}
$response['coverIndices'] = $coverIndices;
$response['coverImages'] = $coverImages;
}
-
- // Determine "preview" image, which may be the cover, title, or first page
- if (array_key_exists('titleImage', $response)) {
- // Use title image if was assert
- $previewImage = $response['titleImage'];
- } else if (array_key_exists('coverImages', $response)) {
- // Try for the cover page
- $previewImage = $response['coverImages'][0];
- } else {
- // Neither title nor cover asserted, use first page
- $previewImage = $this->imageURL(0, $response);
- }
- $response['previewImage'] = $previewImage;
-
+
return $response;
}
return $url;
}
+ // $$$ move inside BookReaderPreview
+ function previewURL($page, $metadata) {
+ $query = array(
+ 'id' => $metadata['itemId'],
+ 'bookId' => $metadata['bookId'],
+ 'itemPath' => $metadata['itemPath'],
+ 'server' => $metadata['server'],
+ 'page' => $page,
+ );
+
+ return 'http://' . $metadata['server'] . '/BookReader/BookReaderPreview.php?' . http_build_query($query, '', '&');
+ }
+
function imageFilePath($leafNum, $bookId, $format) {
return sprintf("%s_%s/%s_%04d.%s", $bookId, $format, $bookId, intval($leafNum), $format);
}
--- /dev/null
+<?
+/*
+
+Provides access to preview images of book.
+
+Michael Ang <http://github.com/mangtronix>
+
+Copyright (c) 2010 Internet Archive. Software license AGPL version 3.
+
+This file is part of BookReader.
+
+ BookReader is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BookReader is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with BookReader. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+require_once('BookReaderMeta.inc.php');
+require_once('BookReaderImages.inc.php');
+
+function BRfatal($message) {
+ header("HTTP/1.0 404 Not Found");
+ print $message;
+ exit();
+}
+
+$brm = new BookReaderMeta();
+$metadata = $brm->buildMetadata($_REQUEST['id'], $_REQUEST['itemPath'], $_REQUEST['bookId'], $_REQUEST['server']);
+
+$knownPages = array('title','cover','preview');
+$page = $_REQUEST['page'];
+if (! in_array($page, $knownPages) ) {
+ BRfatal("Bad or no page specified");
+}
+
+// Index of image to return
+$imageIndex = null;
+
+switch ($page) {
+ case 'title':
+ if (! array_key_exists('titleIndex', $metadata)) {
+ BRfatal("No title page asserted in book");
+ }
+ $imageIndex = $metadata['titleIndex'];
+ break;
+
+ case 'cover':
+ if (! array_key_exists('coverIndices', $metadata)) {
+ BRfatal("No cover asserted in book");
+ }
+ $imageIndex = $metadata['coverIndices'][0]; // $$$ TODO add support for other covers
+ break;
+
+ case 'preview':
+ // Preference is:
+ // Title page
+ // Cover page
+ // Page 0
+ if (array_key_exists('titleIndex', $metadata)) {
+ $imageIndex = $metadata['titleIndex'];
+ } else if (array_key_exists('coverIndices', $metadata)) {
+ $imageIndex = $metadata['coverIndices'][0];
+ } else {
+ $imageIndex = 0;
+ }
+ break;
+
+ default:
+ // Shouldn't be possible
+ BRfatal("Couldn't find page");
+ break;
+}
+
+$leaf = $brm->leafForIndex($imageIndex, $metadata['leafNums']);
+
+$requestEnv = array(
+ 'zip' => $metadata['zip'],
+ 'file' => $brm->imageFilePath($leaf, $metadata['bookId'], $metadata['imageFormat']),
+ 'ext' => 'jpg',
+ 'reduce' => 2, // XXX
+);
+
+// Return image data - will check privs
+$bri = new BookReaderImages();
+$bri->serveRequest($requestEnv);
+
+?>
\ No newline at end of file