X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=BookReaderIA%2Finc%2FBookReader.inc;h=94f677335c7b6911568d98ac0c1d1be0589eb1c9;hb=9c27120483f991ca55ec8a6a0bfed2a819cd0c7c;hp=8d96adb5d09f8d04cb0283b3a1d088f7222967b5;hpb=335e84e99d85e60caf1f01847bb557b40d68d4bc;p=bookreader.git diff --git a/BookReaderIA/inc/BookReader.inc b/BookReaderIA/inc/BookReader.inc index 8d96adb..94f6773 100644 --- a/BookReaderIA/inc/BookReader.inc +++ b/BookReaderIA/inc/BookReader.inc @@ -1,8 +1,23 @@ + + <? echo $title; ?> + + + + + + - + - -
Internet Archive BookReader
- -
Internet Archive Bookreader
- + +//
Internet Archive BookReader
+// +//
Internet Archive Bookreader
+// +*/ +?> + +
Internet Archive BookReader
- - - -
-
-

- -

-
-
- Search results -
-
- - -
-
- Internet Archive -
- -
- - - + // Usage stats + if(window.archive_analytics) { window.archive_analytics.values['bookreader'] = 'open'}; getServer()); - + + // Baseline query params + $query = array( + 'id' => $identifier, + 'itemPath' => $item->getMainDir(), + 'server' => $serverBaseURL + ); + if ($subPrefix) { + $query['subPrefix'] = $subPrefix; + } + switch ($operator) { case 'page': - // Find bookId and which page was requested - $pathParts = pathinfo($filename); - // Look for preview request - if (preg_match('/^(.*)_(cover|title|preview)$/', $pathParts['filename'], $matches) === 0) { - return null; + // 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, '', '&'); } - $bookId = $matches[1]; - $page = $matches[2]; - $query = array( - 'id' => $identifier, - 'bookId' => $bookId, - 'itemPath' => $item->getMainDir(), - 'server' => $serverBaseURL, - 'page' => $page, - ); - 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; + } + } -?> \ No newline at end of file +?>