X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=BookReaderIA%2Finc%2FBookReader.inc;h=68eff3c2a7e6b62b3caf9ce8dd5f3d5ae5476d2f;hb=e08b87d9dd895da41cb728db29ea8bf33e0bdbfd;hp=f3c1b7a891da7e55e7db18ac453df22eea153a86;hpb=2434a662ca02c528d3022e749a8e73333f69e17a;p=bookreader.git diff --git a/BookReaderIA/inc/BookReader.inc b/BookReaderIA/inc/BookReader.inc index f3c1b7a..68eff3c 100644 --- a/BookReaderIA/inc/BookReader.inc +++ b/BookReaderIA/inc/BookReader.inc @@ -1,8 +1,23 @@ metadataGrabber->mainDir . '/'); foreach ($item->getFiles() as $location => $fileInfo) { @@ -51,15 +66,18 @@ class BookReader public static function findPrefix($urlPortion) { if (!preg_match('#[^/&?]+#', $urlPortion, $matches)) { + // URL portion was empty or started with /, &, or ? -- no item identifier return false; } - $prefix = $matches[0]; // identifier + $prefix = $matches[0]; // item identifier // $$$ Currently swallows the rest of the URL. // If we want to support e.g. /stream/itemid/subdir/prefix/page/23 will need to adjust. if (preg_match('#[^/&?]+/([^&?]+)#', $urlPortion, $matches)) { - $prefix = $matches[1]; // sub prefix + // Match is everything after item identifier and slash, up to end or ? or & + // e.g. itemid/{match/these/parts}?foo=bar + $prefix = $matches[1]; // sub prefix -- } return $prefix; @@ -73,7 +91,7 @@ class BookReader { // Set title to default if not set if (!$title) { - $title = 'Bookreader'; + $title = 'BookReader'; } $id = $identifier; @@ -81,7 +99,12 @@ class BookReader // manually update with Launchpad version number at each checkin so that browsers // do not use old cached version // see https://bugs.launchpad.net/gnubook/+bug/330748 - $version = "0.9.18"; + $version = "r28"; + + if (BookReader::getDevHost($server)) { + // on dev host - add time to force reload + $version .= '_' . time(); + } if ("" == $id) { echo "No identifier specified!"; @@ -94,6 +117,8 @@ class BookReader + + <? echo $title; ?> + + + - + - -
Internet Archive BookReader
- -
Internet Archive Bookreader
- + +//
Internet Archive BookReader
+// +//
Internet Archive Bookreader
+// +*/ +?> + +
Internet Archive BookReader
+ + +
+
+
+
+ + + + + + + +
+
I. The Minotaur | Page 1
+
+ +
+
II. The Griffon | Page 44
+
+ +
+
III. The Firedrake | Page 129
+
+ +
+
V. The Pegasus | Page 201
+
+ +
+
VI. The Goblin | Page 255
+
+ +
+
+ A related distinction is between the emotion and the results of the emotion, principally behaviors and emotional expressions. People often behave in certain ways as a direct result of their emotional state, such as crying, fighting or fleeing. Page 163 +
IV. The Witch | Page 163
+
+
+ +
+
+ - +

@@ -159,26 +383,65 @@ class BookReader $(document).ready(function() { $(window).trigger('resize'); }); + + //XXXmang + function hideFace() { + $('#BookReader').die('mousemove').live('mousemove',function(event) { + var toolpos = $('#BRtoolbar').offset(); + var tooltop = toolpos.top; + var navkey = $(document).height() - 75; + if ((event.pageY < 76) || (event.pageY > navkey)) { + if (tooltop == -60) { + $('#BRtoolbar').animate({top:'0'}); + $('#BRnav').animate({bottom:'0'}); + }; + } else if ($('.bt-wrapper').size() == 0) { + if (tooltop == 0) { + $('#BRtoolbar').animate({top:'-60'}); + $('#BRnav').animate({bottom:'-60'}); + } + }; + }); + }; + window.onload = function() { + window.setTimeout(hideFace, 3000); + }; $identifier, 'itemPath' => $mainDir, 'server' => $server ); if ($subPrefix) { $params['subPrefix'] = $subPrefix; @@ -197,5 +460,135 @@ class BookReader return $url; } + // Return the URL for the requested /download/$path, or null + public static function getURL($path, $item) { + // $path should look like {itemId}/{operator}/{filename} + // Other operators may be added + + $urlParts = BookReader::parsePath($path); + + // Check for non-handled cases + $required = array('identifier', 'operator', 'operand'); + foreach ($required as $key) { + if (!array_key_exists($key, $urlParts)) { + return null; + } + } + + $identifier = $urlParts['identifier']; + $operator = $urlParts['operator']; + $filename = $urlParts['operand']; + $subPrefix = $urlParts['subPrefix']; + + $serverBaseURL = BookReader::serverBaseURL($item->getServer()); + + // Baseline query params + $query = array( + 'id' => $identifier, + 'itemPath' => $item->getMainDir(), + 'server' => $serverBaseURL + ); + if ($subPrefix) { + $query['subPrefix'] = $subPrefix; + } + + switch ($operator) { + case 'page': + + // Look for old-style preview request - e.g. {identifier}_cover.jpg + if (preg_match('/^(.*)_((cover|title|preview).*)/', $filename, $matches) === 1) { + // Serve preview image + $page = $matches[2]; + $query['page'] = $page; + return 'http://' . $serverBaseURL . '/BookReader/BookReaderPreview.php?' . http_build_query($query, '', '&'); + } + + // New-style preview request - e.g. cover_thumb.jpg + if (preg_match('/^(cover|title|preview)/', $filename, $matches) === 1) { + $query['page'] = $filename; + return 'http://' . $serverBaseURL . '/BookReader/BookReaderPreview.php?' . http_build_query($query, '', '&'); + } + + // Asking for a non-preview page + $query['page'] = $filename; + return 'http://' . $serverBaseURL . '/BookReader/BookReaderImages.php?' . http_build_query($query, '', '&'); + + default: + // Unknown operator + return null; + } + + return null; // was not handled + } + + public static function browserFromUserAgent($userAgent) { + $browserPatterns = array( + 'ipad' => '/iPad/', + 'iphone' => '/iPhone/', // Also cover iPod Touch + 'android' => '/Android/', + ); + + foreach ($browserPatterns as $browser => $pattern) { + if (preg_match($pattern, $userAgent)) { + return $browser; + } + } + return null; + } + + + // $$$ Ideally we will not rely on user agent, but for the moment we do + public static function paramsFromUserAgent($userAgent) { + // $$$ using 'embed' here for devices with assumed small screens -- really should just use CSS3 media queries + $browserParams = array( + 'ipad' => array( 'ui' => 'touch' ), + 'iphone' => array( 'ui' => 'embed', 'mode' => '1up' ), + 'android' => array( 'ui' => 'embed', 'mode' => '1up' ), + ); + + $browser = BookReader::browserFromUserAgent($userAgent); + if ($browser) { + return $browserParams[$browser]; + } + return array(); + } + + public static function parsePath($path) { + // Parse the BookReader path and return the parts + // e.g. itemid/some/sub/dir/page/cover.jpg -> array( 'identifier' => 'itemid', 'subPrefix' => 'some/sub/dir', + // 'operator' => 'page', 'filename' => 'cover.jpg') + + $parts = array(); + + // Pull off query, e.g. ?foo=bar + if (preg_match('#(.*?)(\?.*)#', $path, $matches) === 1) { + $parts['query'] = $matches[2]; + $path = $matches[1]; + } + + // Pull off identifier + if (preg_match('#[^/&?]+#', $path, $matches) === 0) { + // no match + return $parts; + } + $parts['identifier'] = $matches[0]; + $path = substr($path, strlen($matches[0])); + + // Look for operators + // The sub-prefix can be arbitrary, so we match up until the first operator + $operators = '(' . join('|', self::$downloadOperators) . ')'; + $pattern = '#(?P.*?)/(?P' . $operators . ')/(?P.*)#'; + if (preg_match($pattern, $path, $matches) === 1) { + $parts['subPrefix'] = substr($matches['subPrefix'], 1); // remove leading '/' + $parts['operator'] = $matches['operator']; + $parts['operand'] = $matches['operand']; + } else { + $parts['subPrefix'] = $path; + } + + return $parts; + } + } - ?> + +?>