Merge commit 'rajbot/newui' into newui
[bookreader.git] / BookReaderIA / datanode / BookReaderPreview.php
1 <?
2 /*
3
4 Provides access to preview images of book.  It is run with privileges and provides a reduced
5 access wrapper around BookReaderImages.
6
7 Michael Ang <http://github.com/mangtronix>
8
9 Copyright (c) 2010 Internet Archive. Software license AGPL version 3.
10
11 This file is part of BookReader.
12
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.
17
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.
22
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/>.
25 */
26
27 require_once('BookReaderImages.inc.php');
28
29 function BRfatal($message) {
30     header("HTTP/1.0 404 Not Found");
31     header("Content-type: text/plain");
32     print $message;
33     die(-1);
34 }
35
36 $allowedPages = array('title','cover','preview');
37 $allowedPattern = '#^(' . join('|', $allowedPages) . ')#';
38
39 $page = $_REQUEST['page'];
40
41 if (preg_match($allowedPattern, $page)) { 
42     // Return image data
43     $bri = new BookReaderImages();
44     
45     try {
46         $bri->serveLookupRequest($_REQUEST);
47     } catch (Exception $e) {
48         header("HTTP/1.0 404 Not Found");
49         header("Content-type: text/plain");
50         
51         print "Error serving request:\n";
52         print "  " . $e->getMessage() . "\n\n";
53         print "Debugging information:\n";
54         echo $e->getTraceAsString();
55     }
56 } else {
57     BRfatal("Bad or no page specified");
58 }
59
60
61 ?>