4 Provides access to preview images of book. It is run with privileges and provides a reduced
5 access wrapper around BookReaderImages.
7 Michael Ang <http://github.com/mangtronix>
9 Copyright (c) 2010 Internet Archive. Software license AGPL version 3.
11 This file is part of BookReader.
13 BookReader is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Affero General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 BookReader is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Affero General Public License for more details.
23 You should have received a copy of the GNU Affero General Public License
24 along with BookReader. If not, see <http://www.gnu.org/licenses/>.
27 require_once('BookReaderMeta.inc.php');
28 require_once('BookReaderImages.inc.php');
30 function BRfatal($message) {
31 header("HTTP/1.0 404 Not Found");
32 header("Content-type: text/plain");
37 $brm = new BookReaderMeta();
39 $metadata = $brm->buildMetadata($_REQUEST['id'], $_REQUEST['itemPath'], $_REQUEST['bookId'], $_REQUEST['server']);
40 } catch (Exception $e) {
41 BRfatal($e->getMessage);
44 $knownPages = array('title','cover','preview');
45 $page = $_REQUEST['page'];
46 if (! in_array($page, $knownPages) ) {
47 BRfatal("Bad or no page specified");
50 // Index of image to return
55 if (! array_key_exists('titleIndex', $metadata)) {
56 BRfatal("No title page asserted in book");
58 $imageIndex = $metadata['titleIndex'];
62 if (! array_key_exists('coverIndices', $metadata)) {
63 BRfatal("No cover asserted in book");
65 $imageIndex = $metadata['coverIndices'][0]; // $$$ TODO add support for other covers
70 // Cover page if book was published >= 1950
76 header('Content-type: text/plain');
77 print 'Date ' . $metadata['date'];
78 print 'Year ' . $brm->parseYear($metadata['date']);
81 if ( array_key_exists('date', $metadata) && array_key_exists('coverIndices', $metadata) ) {
82 if ($brm->parseYear($metadata['date']) >= 1950) {
83 $imageIndex = $metadata['coverIndices'][0];
87 if (array_key_exists('titleIndex', $metadata)) {
88 $imageIndex = $metadata['titleIndex'];
91 if (array_key_exists('coverIndices', $metadata)) {
92 $imageIndex = $metadata['coverIndices'][0];
101 // Shouldn't be possible
102 BRfatal("Couldn't find page");
107 $leaf = $brm->leafForIndex($imageIndex, $metadata['leafNums']);
110 'zip' => $metadata['zip'],
111 'file' => $brm->imageFilePath($leaf, $metadata['bookId'], $metadata['imageFormat']),
115 // Return image data - will check privs
116 $bri = new BookReaderImages();
118 $bri->serveRequest($requestEnv);
119 } catch (Exception $e) {
120 header("HTTP/1.0 404 Not Found");
121 header("Content-type: text/plain");
122 print "Error serving request:";
123 print " " . $e->getMessage();
124 print "Debugging information:";
125 echo $e->getTraceAsString();