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['subPrefix'], $_REQUEST['server']);
40 } catch (Exception $e) {
41 BRfatal($e->getMessage);
44 // $$$ allow size information
45 $knownPages = array('title','cover','preview');
46 $page = $_REQUEST['page'];
47 if (! in_array($page, $knownPages) ) {
48 BRfatal("Bad or no page specified");
51 // Index of image to return
56 if (! array_key_exists('titleIndex', $metadata)) {
57 BRfatal("No title page asserted in book");
59 $imageIndex = $metadata['titleIndex'];
63 if (! array_key_exists('coverIndices', $metadata)) {
64 BRfatal("No cover asserted in book");
66 $imageIndex = $metadata['coverIndices'][0]; // $$$ TODO add support for other covers
71 // Cover page if book was published >= 1950
77 header('Content-type: text/plain');
78 print 'Date ' . $metadata['date'];
79 print 'Year ' . $brm->parseYear($metadata['date']);
82 if ( array_key_exists('date', $metadata) && array_key_exists('coverIndices', $metadata) ) {
83 if ($brm->parseYear($metadata['date']) >= 1950) {
84 $imageIndex = $metadata['coverIndices'][0];
88 if (array_key_exists('titleIndex', $metadata)) {
89 $imageIndex = $metadata['titleIndex'];
92 if (array_key_exists('coverIndices', $metadata)) {
93 $imageIndex = $metadata['coverIndices'][0];
102 // Shouldn't be possible
103 BRfatal("Couldn't find page");
108 $leaf = $brm->leafForIndex($imageIndex, $metadata['leafNums']);
111 'zip' => $metadata['zip'],
112 'file' => $brm->imageFilePath($leaf, $metadata['subPrefix'], $metadata['imageFormat']),
116 // Return image data - will check privs
117 $bri = new BookReaderImages();
119 $bri->serveRequest($requestEnv);
120 } catch (Exception $e) {
121 header("HTTP/1.0 404 Not Found");
122 header("Content-type: text/plain");
123 print "Error serving request:";
124 print " " . $e->getMessage();
125 print "Debugging information:";
126 echo $e->getTraceAsString();