Changes from Archive release 0.9.7. See https://bugs.launchpad.net/gnubook/+mileston...
authorMichael Ang <mang@archive.org>
Fri, 12 Jun 2009 21:50:00 +0000 (21:50 +0000)
committerMichael Ang <mang@archive.org>
Fri, 12 Jun 2009 21:50:00 +0000 (21:50 +0000)
GnuBook/EnableGnuBookBeta.user.js [deleted file]
GnuBookIA/datanode/GnuBookImages.php
GnuBookIA/datanode/GnuBookJSIA.php
GnuBookIA/inc/GnuBook.inc
GnuBookIA/www/GnuBookEmbed.php
GnuBookIA/www/GnuBookJSLocate.php [new file with mode: 0644]
GnuBookIA/www/browserunsupported.php

diff --git a/GnuBook/EnableGnuBookBeta.user.js b/GnuBook/EnableGnuBookBeta.user.js
deleted file mode 100644 (file)
index 3f69717..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// ==UserScript==
-// @name          EnableGnuBookBeta
-// @namespace     http://openlibrary.org/dev/docs/bookreader
-// @description   Enables beta link to GnuBook ajax bookreader on archive.org details pages.
-// @include       http://www.archive.org/details*
-// ==/UserScript==
-
-var dlDiv = document.getElementById('dl');
-var links = dlDiv.getElementsByTagName('a');
-
-var re = new RegExp (/stream\/(\S+)/);
-
-for (var i = 0; i < links.length; i++) { 
-    var url = links[i].getAttribute("href");
-    var reMatch = re.exec(url);
-
-    GM_log(url);
-    if (null != reMatch) {
-        if (2 == reMatch.length) {
-            if("Flip Book" == links[i].firstChild.nodeValue) {
-                var id = reMatch[1];
-                GM_log('got it! ' + id);
-                links[i].href="http://www.us.archive.org/GnuBook/?id="+id;
-                links[i].firstChild.nodeValue = "Flip Book Beta!";
-            }
-        }
-    }
-}
\ No newline at end of file
index a8c16ea..a412a06 100644 (file)
@@ -1,8 +1,4 @@
 <?php
-/* This file is deprecated -- image stack processing has been 
- * combined into GnuBookImages.php.  This file will eventually
- * be removed.
- */
 
 /*
 Copyright(c)2008 Internet Archive. Software license AGPL version 3.
@@ -61,29 +57,29 @@ if (isset($_REQUEST['height'])) {
     $ratio = floatval($_REQUEST['origHeight']) / floatval($_REQUEST['height']);
     if ($ratio <= 2) {
         $scale = 2;
-        $reduce = 1;    
+        $powReduce = 1;    
     } else if ($ratio <= 4) {
         $scale = 4;
-        $reduce = 2;
+        $powReduce = 2;
     } else {
-        //$reduce = 3; //too blurry!
+        //$powReduce = 3; //too blurry!
         $scale = 2;
-        $reduce = 1;
+        $powReduce = 1;
     }
 
 } else {
     $scale = $_REQUEST['scale'];
     if (1 >= $scale) {
         $scale = 1;
-        $reduce = 0;
+        $powReduce = 0;
     } else if (2 == $scale) {
-        $reduce = 1;
+        $powReduce = 1;
     } else if (4 == $scale) {
-        $reduce = 2;
+        $powReduce = 2;
     } else {
         // $$$ why do we default to such a small scale?
         $scale = 8;
-        $reduce = 3;
+        $powReduce = 3;
     }
 }
 
@@ -101,7 +97,7 @@ $unzipCmd  = 'unzip -p ' .
         
 if ('jp2' == $fileExt) {
     $decompressCmd = 
-        " | /petabox/sw/bin/kdu_expand -no_seek -quiet -reduce $reduce -i /dev/stdin -o " . $stdoutLink;
+        " | /petabox/sw/bin/kdu_expand -no_seek -quiet -reduce $powReduce -i /dev/stdin -o " . $stdoutLink;
     if ($decompressToBmp) {
         $decompressCmd .= ' | bmptopnm ';
     }
@@ -113,7 +109,11 @@ if ('jp2' == $fileExt) {
     $tempFile = tempnam("/tmp", "GnuBookTiff");
     
     if (1 != $scale) {
-        $pbmReduce = ' | pbmreduce -threshold ' . $scale;
+        if (onPowerNode()) {
+            $pbmReduce = ' | pnmscale -reduce ' . $scale;
+        } else {
+            $pbmReduce = ' | pnmscale -nomix -reduce ' . $scale;
+        }
     } else {
         $pbmReduce = '';
     }
@@ -154,5 +154,20 @@ function GBFatal($string) {
     die(-1);
 }
 
+// Returns true if using a power node
+function onPowerNode() {
+    exec("lspci | fgrep -c Realtek", $output, $return);
+    if ("0" != $output[0]) {
+        return true;
+    } else {
+        exec("egrep -q AMD /proc/cpuinfo", $output, $return);
+        if ($return == 0) {
+            return true;
+        }
+    }
+    return false;
+}
+
+
 ?>
 
index 17ccaf0..113cd74 100755 (executable)
@@ -41,6 +41,7 @@ if (!preg_match("|^/[0-3]/items/{$id}$|", $itemPath)) {
 
 $imageFormat = 'unknown';
 $zipFile = "$itemPath/{$id}_jp2.zip";
+
 if (file_exists($zipFile)) {
     $imageFormat = 'jp2';
 } else {
@@ -85,6 +86,21 @@ $metaData = simplexml_load_file($metaDataFile);
 
 gb = new GnuBook();
 
+<?
+/* Output title leaf if marked */
+$titleLeaf = '';
+foreach ($scanData->pageData->page as $page) {
+    if (("Title Page" == $page->pageType) || ("Title" == $page->pageType)) {
+        $titleLeaf = "{$page['leafNum']}";
+        break;
+    }
+}
+    
+if ('' != $titleLeaf) {
+    printf("gb.titleLeaf = %d;\n", $titleLeaf);
+}
+?>
+
 gb.getPageWidth = function(index) {
     //return parseInt(this.pageW[index]/this.reduce);
     return this.pageW[index];
@@ -125,6 +141,23 @@ gb.getPageSide = function(index) {
     //assume the book starts with a cover (right-hand leaf)
     //we should really get handside from scandata.xml
     
+    <? // Use special function if we should infer the page sides based off the title page index
+    if (preg_match('/goog$/', $id) && ('' != $titleLeaf)) {
+    ?>
+    // assume page side based on title page
+    var titleIndex = gb.leafNumToIndex(gb.titleLeaf);
+    // assume title page is RHS
+    var delta = titleIndex - index;
+    if (0 == (delta & 0x1)) {
+        // even delta
+        return 'R';
+    } else {
+        return 'L';
+    }
+    <?
+    }
+    ?>
+    
     // $$$ we should get this from scandata instead of assuming the accessible
     //     leafs are contiguous
     if ('rl' != this.pageProgression) {
@@ -252,20 +285,6 @@ gb.pageNums = [
             ?>    
             ];
             
-<?
-/* Output title leaf if marked */
-$titleLeaf = '';
-foreach ($scanData->pageData->page as $page) {
-    if (("Title Page" == $page->pageType) || ("Title" == $page->pageType)) {
-        $titleLeaf = "{$page['leafNum']}";
-        break;
-    }
-}
-    
-if ('' != $titleLeaf) {
-    printf("gb.titleLeaf = %d;\n", $titleLeaf);
-}
-?>
       
 gb.numLeafs = gb.pageW.length;
 
@@ -296,17 +315,26 @@ if ('bandersnatchhsye00scarrich' == $id) {
 
 
 // Check for config object
+// $$$ change this to use the newer params object
 if (typeof(gbConfig) != 'undefined') {
     if (gbConfig['mode'] == 1) {
       gb.mode = 1;
+      if (typeof(gbConfig['reduce'] != 'undefined')) {
+        gb.reduce = gbConfig['reduce'];
+      }
     } else if (gbConfig['mode'] == 2) {
       gb.mode = 2;
       
-      //$$$mang hack to override request for 2up for RTL until we have full RTL support
-      //        we need a better way to determine the mode and pass config options
-      //if ((typeof(gb.pageProgression) != 'undefined') && (gb.pageProgression == 'rl')) {
-      //  gb.mode = 1;
-      //}
+<?
+      //$$$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 "gb.mode = 1;\n";
+      }
+?>
+
   
     }
 }
@@ -335,4 +363,4 @@ function shouldAddPage($page) {
     return true;
 }
 
-?>
\ No newline at end of file
+?>
index cb8ba40..f7336de 100644 (file)
@@ -2,51 +2,6 @@
 
 class GnuBook
 {
-
-  // Returns true if can display the book in item with a given prefix (typically the item identifier)
-  public static function canDisplay($item, $prefix, $checkOldScandata = false)
-  {
-    
-    // A "book" is an image stack and scandata.
-    // 1. Old items may have scandata.xml or scandata.zip and itemid_{imageformat}.{zip,tar}
-    // 2. Newer items may have multiple {arbitraryname}_scandata.xml and {arbitraryname}_{imageformat}.{zip,tar}
-        
-    $foundScandata = false;
-    $foundImageStack = false;
-    
-    $targetScandata = $prefix . "_scandata.xml";
-    
-    // $$$ 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$@';
-    
-    $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;
-            }
-        }
-        
-        if ($filename == $targetScandata) {
-            $foundScandata = $filename;
-        }
-        
-        if (preg_match($imageFormatRegex, $filename)) {
-            $foundImageStack = $filename;
-        }
-    }
-        
-    if ($foundScandata && $foundImageStack) {
-        return true;
-    }
-    
-    return false;
-  }
-
   public static function draw($server, $mainDir, $identifier, $title,
                               $coverleaf=null, $titlestart='Internet Archive')
   {
@@ -66,8 +21,6 @@ class GnuBook
         echo "No identifier specified!";
         die(-1);
     }
-    
-    $metaURL = GnuBook::jsMetadataURL($server, $identifier, $mainDir);
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
@@ -90,7 +43,7 @@ class GnuBook
   var gbConfig = {};
   gbConfig.mode = 2;
 </script>
-<script type="text/javascript" src="<? echo($metaURL); ?>"></script>
+<script type="text/javascript" src="/bookreader/GnuBookJSLocate.php?id=<?echo $id;?>"></script>
 
 <div id="GnuBookSearch" style="width:190px; right:0px; top:10px; bottom:2em;">
     <form action='javascript:' onsubmit="gb.search($('#GnuBookSearchBox').val());">
@@ -125,25 +78,5 @@ class GnuBook
   <?
     exit;
   }
-  
-  public static function jsMetadataURL($server, $identifier, $mainDir)
-  {
-    $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)) {
-      // $$$ the remapping isn't totally automatic yet and requires user to
-      //     ln -s ~/petabox/www/datanode/GnuBook ~/public_html/GnuBook
-      //     so we enable it only for known hosts
-      $devhosts = array('mang', 'testflip');
-      if (in_array($match[1], $devhosts)) {
-        $serverBaseURL = $serverBaseURL . ":81/~" . $match[1];
-      }
-    }
-
-    $url = "http://{$serverBaseURL}/GnuBook/GnuBookJSIA.php?id={$identifier}&itemPath={$mainDir}&server={$serverBaseURL}";
-    return $url;
-  }
-  
 }
   ?>
index f9055a8..5f91c63 100644 (file)
@@ -20,6 +20,11 @@ This file is part of GnuBook.
 
 $id = $_REQUEST['id'];
 
+// manually update with Launchpad version number at each release so that browsers
+// do not use old cached version
+// see https://bugs.launchpad.net/gnubook/+bug/330748
+$version = "0.9.7";
+
 if ("" == $id) {
     echo "No identifier specified!";
     die(-1);
@@ -29,26 +34,25 @@ if ("" == $id) {
 <html>
 <head>
     <title>bookreader demo</title>
-    <link rel="stylesheet" type="text/css" href="/GnuBook/GnuBook.css">
+    <link rel="stylesheet" type="text/css" href="/bookreader/GnuBook.css?v=<? echo($version); ?>">
     <!-- Set minimal style by overriding with embed-specific styles -->
-    <link rel="stylesheet" type="text/css" href="/GnuBook/GnuBookEmbed.css">
-    <script src="http://www.archive.org/includes/jquery-1.2.6.min.js" type="text/javascript"></script>
-    <script type="text/javascript" src="/GnuBook/GnuBook.js"></script>
-    <script type="text/javascript" src="/GnuBook/jquery.easing.1.3.js"></script>
+    <link rel="stylesheet" type="text/css" href="/bookreader/GnuBookEmbed.css?v=<? echo($version); ?>">
+    <script src="/includes/jquery-1.2.6.min.js" type="text/javascript"></script>
+    <script type="text/javascript" src="/bookreader/GnuBook.js?v=<? echo($version); ?>"></script>
+    <script type="text/javascript" src="/bookreader/jquery.easing.1.3.js"></script>
 </head>
 <body style="background-color: rgb(249, 248, 208);margin:0px;">
 
 <div id="GnuBook" style="width:100%;height:100%;border:0px;">x</div>
 
 <script type="text/javascript">
-  // Set some config variables -- $$$ NB: The configuration object format is not final
+// Set some config variables -- $$$ NB: The configuration object format is not final
   var gbConfig = {};
   gbConfig["mode"] = 1;
+  gbConfig["reduce"] = 8;
 </script>
 
-<script type="text/javascript" src="/GnuBook/GnuBookJSLocate.php?id=<?echo $id;?>"></script>
-<script type="text/javascript">
-  gb.zoom1up(-1);
-</script>
+
+<script type="text/javascript" src="/bookreader/id/<?echo $id . '.js';?>"></script>
 </body>
 </html>
diff --git a/GnuBookIA/www/GnuBookJSLocate.php b/GnuBookIA/www/GnuBookJSLocate.php
new file mode 100644 (file)
index 0000000..5ec166f
--- /dev/null
@@ -0,0 +1,54 @@
+<?
+/*
+Copyright(c)2008 Internet Archive. Software license AGPL version 3.
+
+This file is part of GnuBook.
+
+    GnuBook is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    GnuBook is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with GnuBook.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+require_once '/petabox/setup.inc';
+
+$id = $_REQUEST['id'];
+
+if ("" == $id) {
+    echo "No identifier specified!";
+    die(-1);
+}
+
+$locator      = new Locator();
+
+$results = $locator->locateUDP($id, 1, false);
+
+$serverBaseURL = $results[0][0];
+
+// 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)) {
+    // $$$ the remapping isn't totally automatic yet and requires user to
+    //     ln -s ~/petabox/www/datanode/GnuBook ~/public_html/GnuBook
+    //     so we enable it only for known hosts
+    $devhosts = array('mang', 'testflip');
+    if (in_array($match[1], $devhosts)) {
+        $serverBaseURL = $serverBaseURL . ":81/~" . $match[1];
+    }
+}
+
+$url = "http://{$serverBaseURL}/GnuBook/GnuBookJSIA.php?id={$id}&itemPath={$results[0][1]}&server={$serverBaseURL}";
+
+
+if (("" != $results[0][0]) && ("" != $results[0][1])) {
+    header("Location: $url");
+}
+
+?>
\ No newline at end of file
index 98732a6..ccfa452 100644 (file)
@@ -24,12 +24,14 @@ $id = $_REQUEST['id'];
 // Sanitize since we put this value in the page
 $id = urlencode($id);
 
+$flippyURL = "http://" . $_SERVER['SERVER_NAME'] . "/texts/flipbook/flippy.php?id=" . $id;
+
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
     <title>Unsupported browser</title>
-    <meta http-equiv="refresh" content="10;url=http://www.archive.org/stream/<? echo($id); ?>">
+    <meta http-equiv="refresh" content="10;url=<? echo($flippyURL); ?>">
     <link rel="stylesheet" href="http://www.archive.org/stylesheets/archive.css?v=1.99" type="text/css">
 </head>
 <body>
@@ -87,9 +89,9 @@ Sorry, but our new viewer does not work in this browser yet.
 </p>
 
 <p>
-Either go to our <a href="http://www.archive.org/stream/<? echo($id) ?>">old viewer</a>,
+Either go to our <a href="<? echo($flippyURL); ?>">old viewer</a>,
 or download <a href="http://www.mozilla.com/en-US/firefox/">Firefox</a> or
-<a href="http://www.microsoft.com/windows/internet-explorer/download-ie.aspx">IE7</a>.
+<a href="http://www.microsoft.com/windows/internet-explorer/download-ie.aspx">IE7 (or higher)</a>.
 </p>
 
 <p>