6 // Returns true if can display the book in item with a given prefix (typically the item identifier)
7 public static function canDisplay($item, $prefix, $checkOldScandata = false)
10 // A "book" is an image stack and scandata.
11 // 1. Old items may have scandata.xml or scandata.zip and itemid_{imageformat}.{zip,tar}
12 // 2. Newer items may have multiple {arbitraryname}_scandata.xml and {arbitraryname}_{imageformat}.{zip,tar}
14 $foundScandata = false;
15 $foundImageStack = false;
17 $targetScandata = $prefix . "_scandata.xml";
19 // $$$ TODO add support for jpg and tar stacks
20 // https://bugs.edge.launchpad.net/gnubook/+bug/323003
21 // https://bugs.edge.launchpad.net/gnubook/+bug/385397
22 $imageFormatRegex = '@' . preg_quote($prefix, '@') . '_(jp2|tif|jpg)\.(zip|tar)$@';
24 $baseLength = strlen($item->metadataGrabber->mainDir . '/');
25 foreach ($item->getFiles() as $location => $fileInfo) {
26 $filename = substr($location, $baseLength);
28 if ($checkOldScandata) {
29 if ($filename == 'scandata.xml' || $filename == 'scandata.zip') {
30 $foundScandata = $filename;
34 if ($filename == $targetScandata) {
35 $foundScandata = $filename;
38 if (preg_match($imageFormatRegex, $filename)) {
39 $foundImageStack = $filename;
43 if ($foundScandata && $foundImageStack) {
50 // Finds the prefix to use for the book given the part of the URL trailing after /stream/
51 public static function findPrefix($urlPortion)
53 if (!preg_match('#[^/&?]+#', $urlPortion, $matches)) {
57 $prefix = $matches[0]; // identifier
59 // $$$ Currently swallows the rest of the URL.
60 // If we want to support e.g. /stream/itemid/subdir/prefix/page/23 will need to adjust.
61 if (preg_match('#[^/&?]+/([^&?]+)#', $urlPortion, $matches)) {
62 $prefix = $matches[1]; // sub prefix
68 // $$$ would be cleaner to use different templates instead of the uiMode param
70 // @param subprefix Optional prefix to display a book inside an item (e.g. if does not match identifier)
71 public static function draw($server, $mainDir, $identifier, $subPrefix, $title,
72 $coverLeaf=null, $titleStart='Internet Archive', $uiMode='full')
74 // Set title to default if not set
76 $title = 'BookReader';
81 // manually update with Launchpad version number at each checkin so that browsers
82 // do not use old cached version
83 // see https://bugs.launchpad.net/gnubook/+bug/330748
86 if (BookReader::getDevHost($server)) {
87 // on dev host - add time to force reload
88 $version .= '_' . time();
92 echo "No identifier specified!";
96 $metaURL = BookReader::jsMetadataURL($server, $identifier, $mainDir, $subPrefix);
99 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
102 <meta name="viewport" content="width=device-width, maximum-scale=1.0" />
103 <title><? echo $title; ?></title>
105 <meta http-equiv="refresh" content="2; URL=/bookreader/browserunsupported.php?id=<? echo($id); ?>">
107 <link rel="stylesheet" type="text/css" href="/bookreader/BookReader.css?v=<? echo($version); ?>">
108 <? if ($uiMode == "embed") { ?>
109 <link rel="stylesheet" type="text/css" href="/bookreader/BookReaderEmbed.css?v=<? echo($version); ?>">
110 <? } elseif ($uiMode == "touch") { ?>
111 <link rel="stylesheet" type="text/css" href="/bookreader/touch/BookReaderTouch.css?v=<? echo($version); ?>">
113 <script src="/includes/jquery-1.4.2.min.js" type="text/javascript"></script>
114 <script type="text/javascript" src="/bookreader/jquery-ui-1.8.1.custom.min.js"></script>
115 <script type="text/javascript" src="/bookreader/dragscrollable.js"></script>
116 <script type="text/javascript" src="/bookreader/BookReader.js?v=<? echo($version); ?>"></script>
118 <body style="background-color: #FFFFFF;">
120 <? if ($uiMode == 'full') { ?>
121 <div id="BookReader" style="left:10px; right:200px; top:10px; bottom:2em;">Internet Archive BookReader <noscript>requires JavaScript to be enabled.</noscript></div>
123 <div id="BookReader" style="left:0; right:0; top:0; bottom:0; border:0">Internet Archive Bookreader <noscript>requires JavaScript to be enabled.</noscript></div>
126 <script type="text/javascript">
127 // Set some config variables -- $$$ NB: Config object format has not been finalized
129 <? if ($uiMode == 'embed') { ?>
130 brConfig["mode"] = 1;
131 brConfig["reduce"] = 8;
132 brConfig["ui"] = "embed";
134 brConfig["mode"] = 2;
137 <!-- The script included below is dynamically generated JavaScript that includes the book metadata and page image access functions -->
138 <script type="text/javascript" src="<? echo($metaURL); ?>"></script>
140 <? if ($uiMode == 'full') { ?>
141 <div id="BookReaderSearch" style="width:190px; right:0px; top:10px; bottom:2em;">
142 <form action='javascript:' onsubmit="br.search($('#BookReaderSearchBox').val());">
143 <p style="display: inline">
144 <input id="BookReaderSearchBox" type="text" size="20" value="search..." onfocus="if('search...'==this.value)this.value='';" /><input type="submit" value="go" />
147 <div id="BookReaderSearchResults">
154 <div class="BRlogotype">
155 <a href="http://archive.org/" class="BRblack">Internet Archive</a>
157 <div class="BRnavlinks">
158 <!-- <a class="BRblack" href="http://openlibrary.org/dev/docs/bookreader">About the Bookreader</a> | -->
159 <a class="BRblack" href="http://www.archive.org/about/faqs.php#Report_Item">Content Problems</a> |
160 <a class="BRblack" href="https://bugs.launchpad.net/bookreader/+filebug">Report Bugs</a> |
161 <a class="BRblack" href="http://www.archive.org/details/texts">Texts Collection</a> |
162 <a class="BRblack" href="http://www.archive.org/about/contact.php">Contact Us</a>
167 <script type="text/javascript">
168 // $$$ hack to workaround sizing bug when starting in two-up mode
169 $(document).ready(function() {
170 $(window).trigger('resize');
177 // Returns the user part of dev host from URL, or null
178 public static function getDevHost($server)
180 if (preg_match("/^www-(\w+)/", $_SERVER["SERVER_NAME"], $match)) {
188 public static function serverBaseURL($server)
190 // Check if we're on a dev vhost and point to JSIA in the user's public_html
192 // $$$ the remapping isn't totally automatic yet and requires user to
193 // ln -s ~/petabox/www/datanode/BookReader ~/public_html/BookReader
194 // so we enable it only for known hosts
195 $devhost = BookReader::getDevHost($server);
196 $devhosts = array('mang', 'testflip', 'rkumar');
197 if (in_array($devhost, $devhosts)) {
198 $server = $server . "/~" . $devhost;
204 public static function jsMetadataURL($server, $identifier, $mainDir, $subPrefix = '')
206 $serverBaseURL = BookReader::serverBaseURL($server);
208 $params = array( 'id' => $identifier, 'itemPath' => $mainDir, 'server' => $server );
210 $params['subPrefix'] = $subPrefix;
213 $keys = array_keys($params);
214 $lastParam = end($keys);
215 $url = "http://{$serverBaseURL}/BookReader/BookReaderJSIA.php?";
216 foreach($params as $param=>$value) {
217 $url .= $param . '=' . $value;
218 if ($param != $lastParam) {
226 // Return the URL for the requested /download/$path, or null
227 public static function getURL($path, $item) {
228 // $path should look like {itemId}/{operator}/{filename}
229 // Other operators may be added
231 $parts = preg_split('#/#', $path, 3);
232 if (count($parts) != 3) {
235 $identifier = $parts[0];
236 $operator = $parts[1];
237 $filename = $parts[2];
239 $serverBaseURL = BookReader::serverBaseURL($item->getServer());
243 // Find bookId and which page was requested
244 $pathParts = pathinfo($filename);
246 // Look for preview request
247 if (preg_match('/^(.*)_(cover|title|preview)$/', $pathParts['filename'], $matches) === 0) {
250 $bookId = $matches[1];
255 'itemPath' => $item->getMainDir(),
256 'server' => $serverBaseURL,
259 return 'http://' . $serverBaseURL . '/BookReader/BookReaderPreview.php?' . http_build_query($query, '', '&');
265 return null; // was not handled