Add "Return this book" under the book's title if it's a borrowed book
[bookreader.git] / BookReaderIA / datanode / BookReaderJSIA.php
index b88a10f..e2b48ef 100644 (file)
@@ -118,6 +118,44 @@ $metaData = simplexml_load_file($metaDataFile);
 //$firstLeaf = $scanData->pageData->page[0]['leafNum'];
 ?>
 
+// Error reporting - this helps us fix errors quickly
+function logError(description,page,line) {
+    if (typeof(archive_analytics) != 'undefined') {
+        var values = {
+            'bookreader': 'error',
+            'description': description,
+            'page': page,
+            'line': line,
+            'itemid': '<?echo $id;?>',
+            'subPrefix': '<?echo $subPrefix;?>',
+            'server': '<?echo $server;?>',
+            'bookPath': '<?echo $subItemPath;?>'
+        };
+
+        // if no referrer set '-' as referrer
+        if (document.referrer == '') {
+            values['referrer'] = '-';
+        } else {
+            values['referrer'] = document.referrer;
+        }
+        
+        if (typeof(br) != 'undefined') {
+            values['itemid'] = br.bookId;
+            values['subPrefix'] = br.subPrefix;
+            values['server'] = br.server;
+            values['bookPath'] = br.bookPath;
+        }
+        
+        var qs = archive_analytics.format_bug(values);
+
+        var error_img = new Image(100,25);
+        error_img.src = archive_analytics.img_src + "?" + qs;
+    }
+
+    return false; // allow browser error handling so user sees there was a problem
+}
+window.onerror=logError;
+
 br = new BookReader();
 
 <?
@@ -320,7 +358,7 @@ br.getEmbedURL = function(viewParams) {
         url += '/' + this.subPrefix;
     }
     url += '?ui=embed';
-    if (viewParams) {
+    if (typeof(viewParams) != 'undefined') {
         url += '#' + this.fragmentFromParams(viewParams);
     }
     return url;
@@ -329,8 +367,8 @@ br.getEmbedURL = function(viewParams) {
 // getEmbedCode
 //________
 // Returns the embed code HTML fragment suitable for copy and paste
-br.getEmbedCode = function() {
-    return "<iframe src='" + this.getEmbedURL() + "' width='480px' height='430px'></iframe>";
+br.getEmbedCode = function(frameWidth, frameHeight, viewParams) {
+    return "<iframe src='" + this.getEmbedURL(viewParams) + "' width='" + frameWidth + "' height='" + frameHeight + "' frameborder='0' ></iframe>";
 }
 
 // getOpenLibraryRecord
@@ -370,7 +408,7 @@ br.buildInfoDiv = function(jInfoDiv) {
         
     // $$$ cover looks weird before it loads
     jInfoDiv.find('.BRfloatCover').append([
-                    '<a href="', this.bookUrl, '"><img src="http://www.archive.org/download/', this.bookId, '/page/cover_t.jpg" alt="' + escapedTitle + '" height="140" /></a>'].join('')
+                    '<div style="height: 140px; min-width: 80px; padding: 0; margin: 0;"><a href="', this.bookUrl, '"><img src="http://www.archive.org/download/', this.bookId, '/page/cover_t.jpg" alt="' + escapedTitle + '" height="140px" /></a></div>'].join('')
     );
 
     jInfoDiv.find('.BRfloatMeta').append([
@@ -385,8 +423,7 @@ br.buildInfoDiv = function(jInfoDiv) {
                         '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '_djvu.txt">Plain Text</a><span>|</span></li>',
                         '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '_daisy.zip">DAISY</a><span>|</span></li>',
                         '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '.epub">ePub</a><span>|</span></li>',
-                        '<li><a href="https://www.amazon.com/gp/digital/fiona/web-to-kindle?clientid=IA&itemid=', this.bookId, '&docid=', this.subPrefix, '">Send to Kindle</a><span>|</span></li>',
-                        '<li><a href="', this.bookUrl, '">More...</a></li>',
+                        '<li><a href="https://www.amazon.com/gp/digital/fiona/web-to-kindle?clientid=IA&itemid=', this.bookId, '&docid=', this.subPrefix, '">Send to Kindle</a></li>',
                     '</ul>',
                     '<p class="moreInfo"><span></span>More information on <a href="'+ this.bookUrl + '">' + domain + '</a>  </p>'].join('\n'));
                     
@@ -402,6 +439,8 @@ br.buildInfoDiv = function(jInfoDiv) {
     }
     
     jInfoDiv.find('.BRfloatTitle a').attr({'href': this.bookUrl, 'alt': this.bookTitle}).text(this.bookTitle);
+    var bookPath = (window.location + '').replace('#','%23');
+    jInfoDiv.find('a.problem').attr('href','http://openlibrary.org/contact?path=' + bookPath);
 
 }
 
@@ -492,6 +531,8 @@ foreach ($metaData->xpath('//collection') as $collection) {
     }
 }
 
+echo "br.olHost = 'http://openlibrary.org'\n";
+
 if ($useOLAuth) {
     echo "br.olAuth = true;\n";
 } else {
@@ -519,23 +560,13 @@ 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
 
 
 function OLAuth() {
-    this.authUrl = 'http://openlibrary.org/ia_auth/' + br.bookId;
+    this.authUrl = br.olHost + '/ia_auth/' + br.bookId;
     this.olConnect = false;
     return this;
 }
@@ -545,7 +576,7 @@ OLAuth.prototype.init = function() {
     htmlStr    +=  '<p>Please wait...</p>';
 
     this.showPopup("#ddd", "#000", htmlStr);
-    $.ajax({url:this.authUrl, dataType:'jsonp', jsonpCallback:'olAuth.initCallback'});
+    $.ajax({url:this.authUrl + '?rand='+Math.random(), dataType:'jsonp', jsonpCallback:'olAuth.initCallback'});
 }
 
 OLAuth.prototype.showPopup = function(bgColor, textColor, msg) {
@@ -609,7 +640,7 @@ 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.');
+          self.showPopup("#f00", "#fff", 'The BookReader cannot reach Open Library. This might mean that you are offline or that Open Library is down. Please check your Internet connection or try again later.');
           clearInterval(self.poller);
           self.ttsPoller = null;        
         } else {
@@ -631,8 +662,34 @@ if (br.olAuth) {
 
 
 function BRFatal($string) {
-    // $$$ TODO log error
-    echo "alert('$string')\n";
+    // log error
+    ?>
+    
+    if (typeof(archive_analytics) != 'undefined') {
+        var values = {
+            'bookreader': 'fatal',
+            'description': "<? echo $string; ?>",
+            'itemid': "<? echo $_REQUEST['id']; ?>",
+            'server': "<? echo $_REQUEST['server']; ?>",
+            'request_uri': "<? echo $_SERVER["REQUEST_URI"]; ?>"
+        }
+        
+        if (document.referrer == '') {
+            values['referrer'] = '-';
+        } else {
+            values['referrer'] = document.referrer;
+        }
+        
+        var qs = archive_analytics.format_bug(values);
+
+        var error_img = new Image(100,25);
+        error_img.src = archive_analytics.img_src + "?" + qs;
+    }
+
+    alert("<? echo $string;?>");
+    
+    <?
+    
     die(-1);
 }