4 Provides access to preview images of book.
6 Michael Ang <http://github.com/mangtronix>
8 Copyright (c) 2010 Internet Archive. Software license AGPL version 3.
10 This file is part of BookReader.
12 BookReader is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Affero General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 BookReader is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Affero General Public License for more details.
22 You should have received a copy of the GNU Affero General Public License
23 along with BookReader. If not, see <http://www.gnu.org/licenses/>.
26 require_once('BookReaderMeta.inc.php');
27 require_once('BookReaderImages.inc.php');
29 function BRfatal($message) {
30 header("HTTP/1.0 404 Not Found");
31 header("Content-type: text/plain");
36 $brm = new BookReaderMeta();
38 $metadata = $brm->buildMetadata($_REQUEST['id'], $_REQUEST['itemPath'], $_REQUEST['bookId'], $_REQUEST['server']);
39 } catch (Exception $e) {
40 BRfatal($e->getMessage);
43 $knownPages = array('title','cover','preview');
44 $page = $_REQUEST['page'];
45 if (! in_array($page, $knownPages) ) {
46 BRfatal("Bad or no page specified");
49 // Index of image to return
54 if (! array_key_exists('titleIndex', $metadata)) {
55 BRfatal("No title page asserted in book");
57 $imageIndex = $metadata['titleIndex'];
61 if (! array_key_exists('coverIndices', $metadata)) {
62 BRfatal("No cover asserted in book");
64 $imageIndex = $metadata['coverIndices'][0]; // $$$ TODO add support for other covers
72 if (array_key_exists('titleIndex', $metadata)) {
73 $imageIndex = $metadata['titleIndex'];
74 } else if (array_key_exists('coverIndices', $metadata)) {
75 $imageIndex = $metadata['coverIndices'][0];
82 // Shouldn't be possible
83 BRfatal("Couldn't find page");
87 $leaf = $brm->leafForIndex($imageIndex, $metadata['leafNums']);
90 'zip' => $metadata['zip'],
91 'file' => $brm->imageFilePath($leaf, $metadata['bookId'], $metadata['imageFormat']),
95 // Return image data - will check privs
96 $bri = new BookReaderImages();
98 $bri->serveRequest($requestEnv);
99 } catch (Exception $e) {
100 header("HTTP/1.0 404 Not Found");
101 header("Content-type: text/plain");
102 print "Error serving request:";
103 print " " . $e->getMessage();
104 print "Debugging information:";
105 echo $e->getTraceAsString();