X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=BookReaderIA%2Finc%2FBookReader.inc;h=936cf695ab6e9d518a9eb063c04c9a8fc0de17e4;hb=067dbeedbf050f83f8473fca9f09b88c1551a086;hp=319f7ce70569605c76f3e7556354aea439bcda10;hpb=e746f84b0b4e231a706e0c68f1d5ad77e4bf6b7c;p=bookreader.git
diff --git a/BookReaderIA/inc/BookReader.inc b/BookReaderIA/inc/BookReader.inc
index 319f7ce..936cf69 100644
--- a/BookReaderIA/inc/BookReader.inc
+++ b/BookReaderIA/inc/BookReader.inc
@@ -19,12 +19,12 @@ class BookReader
// $$$ TODO add support for jpg and tar stacks
// https://bugs.edge.launchpad.net/gnubook/+bug/323003
// https://bugs.edge.launchpad.net/gnubook/+bug/385397
- $imageFormatRegex = '@' . preg_quote($prefix, '@') . '_(jp2|tif)\.zip$@';
+ $imageFormatRegex = '@' . preg_quote($prefix, '@') . '_(jp2|tif|jpg)\.(zip|tar)$@';
$baseLength = strlen($item->metadataGrabber->mainDir . '/');
foreach ($item->getFiles() as $location => $fileInfo) {
$filename = substr($location, $baseLength);
-
+
if ($checkOldScandata) {
if ($filename == 'scandata.xml' || $filename == 'scandata.zip') {
$foundScandata = $filename;
@@ -39,7 +39,7 @@ class BookReader
$foundImageStack = $filename;
}
}
-
+
if ($foundScandata && $foundImageStack) {
return true;
}
@@ -73,7 +73,7 @@ class BookReader
{
// Set title to default if not set
if (!$title) {
- $title = 'Bookreader';
+ $title = 'BookReader';
}
$id = $identifier;
@@ -81,7 +81,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 = "r25";
+
+ if (BookReader::getDevHost($server)) {
+ // on dev host - add time to force reload
+ $version .= '_' . time();
+ }
if ("" == $id) {
echo "No identifier specified!";
@@ -94,6 +99,7 @@ class BookReader
+
echo $title; ?>
if ($uiMode == 'full') { ?>
@@ -147,7 +157,7 @@ class BookReader
@@ -164,21 +174,37 @@ class BookReader
exit;
}
- public static function jsMetadataURL($server, $identifier, $mainDir, $subPrefix = '')
+ // Returns the user part of dev host from URL, or null
+ public static function getDevHost($server)
{
- $serverBaseURL = $server;
-
- // Check if we're on a dev vhost and point to JSIA in the user's public_html on the datanode
- if (preg_match("/^www-(\w+)/", $_SERVER["SERVER_NAME"], $match)) {
+ if (preg_match("/^www-(\w+)/", $_SERVER["SERVER_NAME"], $match)) {
+ return $match[1];
+ }
+
+ return null;
+ }
+
+
+ public static function serverBaseURL($server)
+ {
+ // Check if we're on a dev vhost and point to JSIA in the user's public_html
+ // on the datanode
// $$$ the remapping isn't totally automatic yet and requires user to
// ln -s ~/petabox/www/datanode/BookReader ~/public_html/BookReader
// so we enable it only for known hosts
- $devhosts = array('mang', 'testflip');
- if (in_array($match[1], $devhosts)) {
- $serverBaseURL = $serverBaseURL . ":81/~" . $match[1];
+ $devhost = BookReader::getDevHost($server);
+ $devhosts = array('mang', 'testflip', 'rkumar');
+ if (in_array($devhost, $devhosts)) {
+ $server = $server . "/~" . $devhost;
}
- }
-
+ return $server;
+ }
+
+
+ public static function jsMetadataURL($server, $identifier, $mainDir, $subPrefix = '')
+ {
+ $serverBaseURL = BookReader::serverBaseURL($server);
+
$params = array( 'id' => $identifier, 'itemPath' => $mainDir, 'server' => $server );
if ($subPrefix) {
$params['subPrefix'] = $subPrefix;
@@ -197,5 +223,48 @@ 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
+
+ $parts = preg_split('#/#', $path, 3);
+ if (count($parts) != 3) {
+ return null;
+ }
+ $identifier = $parts[0];
+ $operator = $parts[1];
+ $filename = $parts[2];
+
+ $serverBaseURL = BookReader::serverBaseURL($item->getServer());
+
+ 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;
+ }
+ $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, '', '&');
+
+ default:
+ return null;
+ }
+
+ return null; // was not handled
+ }
+
}
- ?>
+
+?>
\ No newline at end of file