X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=BookReaderIA%2Fdatanode%2FBookReaderJSIA.php;h=0f7b6bf00d4916d6d96d82903d297586484c4b92;hb=9b78fb72adadda83576c133dfc52423d3ea65f1c;hp=1a9ac106b945a241b84a2eafc4a58988d9695d59;hpb=2434a662ca02c528d3022e749a8e73333f69e17a;p=bookreader.git
diff --git a/BookReaderIA/datanode/BookReaderJSIA.php b/BookReaderIA/datanode/BookReaderJSIA.php
old mode 100755
new mode 100644
index 1a9ac10..0f7b6bf
--- a/BookReaderIA/datanode/BookReaderJSIA.php
+++ b/BookReaderIA/datanode/BookReaderJSIA.php
@@ -18,15 +18,24 @@ This file is part of BookReader.
along with BookReader. If not, see
Published ', this.bookPublished, + //, Publisher name', + //'
', + //'Written in Language
', + 'More information on ' + domain + '
'].join('\n')); + + jInfoDiv.find('.BRfloatFoot').append([ + '|', + 'Report a problem', + ].join('\n')); + + if (domain == 'archive.org') { + jInfoDiv.find('.BRfloatMeta p.moreInfo span').css( + {'background': 'url(http://www.archive.org/favicon.ico) no-repeat', 'width': 22, 'height': 18 } + ); + } + + jInfoDiv.find('.BRfloatTitle a').attr({'href': this.bookUrl, 'alt': this.bookTitle}).text(this.bookTitle); + +} + +br.pageW = [ $i=0; foreach ($scanData->pageData->page as $page) { @@ -324,7 +418,7 @@ br.pageW = [ ?> ]; -br.pageH = [ +br.pageH = [ $totalHeight = 0; $i=0; @@ -385,10 +479,23 @@ br.archiveFormat = ''; # Load some values from meta.xml if ('' != $metaData->{'page-progression'}) { - echo "br.pageProgression = '" . $metaData->{"page-progression"} . "';"; + echo "br.pageProgression = '" . $metaData->{"page-progression"} . "';\n"; } else { // Assume page progression is Left To Right - echo "br.pageProgression = 'lr';"; + echo "br.pageProgression = 'lr';\n"; +} + +$useOLAuth = false; +foreach ($metaData->xpath('//collection') as $collection) { + if('browserlending' == $collection) { + $useOLAuth = true; + } +} + +if ($useOLAuth) { + echo "br.olAuth = true;\n"; +} else { + echo "br.olAuth = false;\n"; } # Special cases @@ -412,23 +519,104 @@ if (typeof(brConfig) != 'undefined') { br.reduce = brConfig['reduce']; } } else if (brConfig['mode'] == 2) { - br.mode = 2; - - - //$$$mang hack to override request for 2up for books with attribution page - // as first page until we can display that page in 2up - $needle = 'goog'; - if (strrpos($id, $needle) === strlen($id)-strlen($needle)) { - print "// override for books with attribution page\n"; - print "br.mode = 1;\n"; - } -?> + br.mode = 2; } } // brConfig -br.cleanupMetadata(); -br.init(); +function OLAuth() { + this.authUrl = 'http://openlibrary.org/ia_auth/' + br.bookId; + this.olConnect = false; + return this; +} + +OLAuth.prototype.init = function() { + var htmlStr = 'Authenticating in-browser loan with openlibrary.org!
'; + htmlStr += 'Please wait...
'; + + this.showPopup("#ddd", "#000", htmlStr); + $.ajax({url:this.authUrl, dataType:'jsonp', jsonpCallback:'olAuth.initCallback'}); +} + +OLAuth.prototype.showPopup = function(bgColor, textColor, msg) { + this.popup = document.createElement("div"); + $(this.popup).css({ + position: 'absolute', + top: '20px', + left: ($('#BookReader').attr('clientWidth')-400)/2 + 'px', + width: '400px', + padding: "20px", + border: "3px double #999999", + zIndex: 3, + backgroundColor: bgColor, + color: textColor + }).appendTo('#BookReader'); + + this.popup.innerHTML = msg; + +} + +OLAuth.prototype.initCallback = function(obj) { + if (false == obj.success) { + $(this.popup).css({ + backgroundColor: "#f00", + color: "#fff" + }); + + this.popup.innerHTML = obj.msg; + return; + } + + //user is authenticated + this.setCookie(obj.token); + this.olConnect = true; + this.startPolling(); + br.init(); +} + +OLAuth.prototype.callback = function(obj) { + if (false == obj.success) { + this.showPopup("#f00", "#fff", obj.msg); + clearInterval(this.poller); + this.ttsPoller = null; + } else { + this.olConnect = true; + this.setCookie(obj.token); + } +} + +OLAuth.prototype.setCookie = function(value) { + var date = new Date(); + date.setTime(date.getTime()+(24*60*60*1000)); //one day expiry + var expiry = date.toGMTString(); + var cookie = 'loan-'+br.bookId+'='+value; + cookie += '; expires='+expiry; + cookie += '; path=/; domain=.archive.org;'; + document.cookie = cookie; +} + +OLAuth.prototype.startPolling = function () { + var self = this; + this.poller=setInterval(function(){ + if (!self.olConnect) { + self.showPopup("#f00", "#fff", 'Cound not connect to Open Library for authentication. Please check to see if you are still connected to the Internet, and then reload this web page.'); + clearInterval(self.poller); + self.ttsPoller = null; + } else { + self.olConnect = false; + //be sure to add random param to authUrl to avoid stale cache + $.ajax({url:self.authUrl+'?rand='+Math.random(), dataType:'jsonp', jsonpCallback:'olAuth.callback'}); + } + },300000); +} + +br.cleanupMetadata(); +if (br.olAuth) { + var olAuth = new OLAuth(); + olAuth.init(); +} else { + br.init(); +} @@ -455,19 +643,25 @@ function shouldAddPage($page) { // Returns { 'imageFormat' => , 'archiveFormat' => '} given a sub-item prefix and loaded xml data function findImageStack($subPrefix, $filesData) { - // $$$ Add jpeg here - $imageFormats = array('TIFF' => 'tif', 'JP2' => 'jp2'); + // $$$ The order of the image formats determines which will be returned first + $imageFormats = array('JP2' => 'jp2', 'TIFF' => 'tif', 'JPEG' => 'jpg'); $archiveFormats = array('ZIP' => 'zip', 'Tar' => 'tar'); $imageGroup = implode('|', array_keys($imageFormats)); $archiveGroup = implode('|', array_keys($archiveFormats)); - $imageStackRegex = "/Single Page (Processed|Original) (${imageGroup}) (${archiveGroup})/"; + // $$$ Currently only return processed images + $imageStackRegex = "/Single Page (Processed) (${imageGroup}) (${archiveGroup})/"; foreach ($filesData->file as $file) { - if (strpos($file['name'], $subPrefix) === 0) { // subprefix matches beginning + if (strpos($file['name'], $subPrefix) === 0) { // subprefix matches beginning if (preg_match($imageStackRegex, $file->format, $matches)) { - return array('imageFormat' => $imageFormats[$matches[2]], - 'archiveFormat' => $archiveFormats[$matches[3]], - 'imageStackFile' => $file['name']); + + // Make sure we have a regular image stack + $imageFormat = $imageFormats[$matches[2]]; + if (strpos($file['name'], $subPrefix . '_' . $imageFormat) === 0) { + return array('imageFormat' => $imageFormat, + 'archiveFormat' => $archiveFormats[$matches[3]], + 'imageStackFile' => $file['name']); + } } } } @@ -477,3 +671,4 @@ function findImageStack($subPrefix, $filesData) { } ?> +