Move Archive-specific files into different directories.
authorMichael Ang <mang@archive.org>
Fri, 12 Jun 2009 21:36:24 +0000 (21:36 +0000)
committerMichael Ang <mang@archive.org>
Fri, 12 Jun 2009 21:36:24 +0000 (21:36 +0000)
14 files changed:
GnuBookIA/GnuBookEmbed.php [deleted file]
GnuBookIA/GnuBookImages.php [deleted file]
GnuBookIA/GnuBookJP2.php [deleted file]
GnuBookIA/GnuBookJSIA.php [deleted file]
GnuBookIA/GnuBookJSLocate.php [deleted file]
GnuBookIA/browserunsupported.php [deleted file]
GnuBookIA/datanode/GnuBookImages.php [new file with mode: 0644]
GnuBookIA/datanode/GnuBookJSIA.php [new file with mode: 0755]
GnuBookIA/datanode/flipbook_search_gb.php [new file with mode: 0755]
GnuBookIA/flipbook_search_gb.php [deleted file]
GnuBookIA/inc/GnuBook.inc [new file with mode: 0644]
GnuBookIA/index.php [deleted file]
GnuBookIA/www/GnuBookEmbed.php [new file with mode: 0644]
GnuBookIA/www/browserunsupported.php [new file with mode: 0644]

diff --git a/GnuBookIA/GnuBookEmbed.php b/GnuBookIA/GnuBookEmbed.php
deleted file mode 100644 (file)
index f9055a8..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?
-/*
-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/>.
-*/
-
-$id = $_REQUEST['id'];
-
-if ("" == $id) {
-    echo "No identifier specified!";
-    die(-1);
-}
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-<head>
-    <title>bookreader demo</title>
-    <link rel="stylesheet" type="text/css" href="/GnuBook/GnuBook.css">
-    <!-- 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>
-</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
-  var gbConfig = {};
-  gbConfig["mode"] = 1;
-</script>
-
-<script type="text/javascript" src="/GnuBook/GnuBookJSLocate.php?id=<?echo $id;?>"></script>
-<script type="text/javascript">
-  gb.zoom1up(-1);
-</script>
-</body>
-</html>
diff --git a/GnuBookIA/GnuBookImages.php b/GnuBookIA/GnuBookImages.php
deleted file mode 100644 (file)
index a8c16ea..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-<?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.
-
-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/>.
-*/
-
-$MIMES = array('jpg' => 'image/jpeg',
-               'png' => 'image/png');
-
-$zipPath  = $_REQUEST['zip'];
-$file     = $_REQUEST['file'];
-
-// Unfortunately kakadu requires us to know a priori if the
-// output file should be .ppm or .pgm.  By decompressing to
-// .bmp kakadu will write a file we can consistently turn into
-// .pnm.  Really kakadu should support .pnm as the file output
-// extension and automatically write ppm or pgm format as
-// appropriate.
-$decompressToBmp = true;
-if ($decompressToBmp) {
-  $stdoutLink = '/tmp/stdout.bmp';
-} else {
-  $stdoutLink = '/tmp/stdout.ppm';
-}
-
-if (isset($_REQUEST['ext'])) {
-  $ext = $_REQUEST['ext'];
-} else {
-  // Default to jpg
-  $ext = 'jpg';
-}
-
-$fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
-
-// Png conversion options
-$pngOptions = '';
-
-// The pbmreduce reduction factor produces an image with dimension 1/n
-// The kakadu reduction factor produceds an image with dimension 1/(2^n)
-
-if (isset($_REQUEST['height'])) {
-    $ratio = floatval($_REQUEST['origHeight']) / floatval($_REQUEST['height']);
-    if ($ratio <= 2) {
-        $scale = 2;
-        $reduce = 1;    
-    } else if ($ratio <= 4) {
-        $scale = 4;
-        $reduce = 2;
-    } else {
-        //$reduce = 3; //too blurry!
-        $scale = 2;
-        $reduce = 1;
-    }
-
-} else {
-    $scale = $_REQUEST['scale'];
-    if (1 >= $scale) {
-        $scale = 1;
-        $reduce = 0;
-    } else if (2 == $scale) {
-        $reduce = 1;
-    } else if (4 == $scale) {
-        $reduce = 2;
-    } else {
-        // $$$ why do we default to such a small scale?
-        $scale = 8;
-        $reduce = 3;
-    }
-}
-
-if (!file_exists($stdoutLink)) 
-{  
-  system('ln -s /dev/stdout ' . $stdoutLink);  
-}
-
-
-putenv('LD_LIBRARY_PATH=/petabox/sw/lib/kakadu');
-
-$unzipCmd  = 'unzip -p ' . 
-        escapeshellarg($zipPath) .
-        ' ' . escapeshellarg($file);
-        
-if ('jp2' == $fileExt) {
-    $decompressCmd = 
-        " | /petabox/sw/bin/kdu_expand -no_seek -quiet -reduce $reduce -i /dev/stdin -o " . $stdoutLink;
-    if ($decompressToBmp) {
-        $decompressCmd .= ' | bmptopnm ';
-    }
-} else if ('tif' == $fileExt) {
-    // We need to create a temporary file for tifftopnm since it cannot
-    // work on a pipe (the file must be seekable).
-    // We use the GnuBookTiff prefix to give a hint in case things don't
-    // get cleaned up.
-    $tempFile = tempnam("/tmp", "GnuBookTiff");
-    
-    if (1 != $scale) {
-        $pbmReduce = ' | pbmreduce -threshold ' . $scale;
-    } else {
-        $pbmReduce = '';
-    }
-    
-    $decompressCmd = 
-        ' > ' . $tempFile . ' ; tifftopnm ' . $tempFile . ' 2>/dev/null' . $pbmReduce;
-
-} else {
-    GBfatal('Unknown source file extension: ' . $fileExt);
-}
-       
-// Non-integer scaling is currently disabled on the cluster
-// if (isset($_REQUEST['height'])) {
-//     $cmd .= " | pnmscale -height {$_REQUEST['height']} ";
-// }
-
-if ('jpg' == $ext) {
-    $compressCmd = ' | pnmtojpeg -quality 90';
-} else if ('png' == $ext) {
-    $compressCmd = ' | pnmtopng $pngOptions';
-}
-
-$cmd = $unzipCmd . $decompressCmd . $compressCmd;
-
-//print $cmd;
-
-header('Content-type: ' . $MIMES[$ext]);
-header('Cache-Control: max-age=15552000');
-
-passthru ($cmd);
-
-if (isset($tempFile)) {
-  unlink($tempFile);
-}
-
-function GBFatal($string) {
-    echo "alert('$string')\n";
-    die(-1);
-}
-
-?>
-
diff --git a/GnuBookIA/GnuBookJP2.php b/GnuBookIA/GnuBookJP2.php
deleted file mode 100644 (file)
index 5ac812a..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-/*
-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/>.
-*/
-
-header('Content-type: image/jpeg');
-header('Cache-Control: max-age=15552000');
-
-$zipPath  = $_REQUEST['zip'];
-$file     = $_REQUEST['file'];
-
-
-if (isset($_REQUEST['height'])) {
-    $ratio = floatval($_REQUEST['origHeight']) / floatval($_REQUEST['height']);
-    if ($ratio <= 2) {
-        $reduce = 1;    
-    } else if ($ratio <= 4) {
-        $reduce = 2;
-    } else {
-        //$reduce = 3; //too blurry!
-        $reduce = 1;
-    }
-
-} else {
-    $scale    = $_REQUEST['scale'];
-    if (1 >= $scale) {
-        $reduce = 0;
-    } else if (2 == $scale) {
-        $reduce = 1;
-    } else if (4 == $scale) {
-        $reduce = 2;
-    } else {
-        $reduce = 3;
-    }
-}
-
-if (!file_exists('/tmp/stdout.ppm')) 
-{  
-  system('ln -s /dev/stdout /tmp/stdout.ppm');  
-}
-
-
-putenv('LD_LIBRARY_PATH=/petabox/sw/lib/kakadu');
-
-
-$cmd  = 'unzip -p ' . 
-        escapeshellarg($zipPath) .
-        ' ' .
-        escapeshellarg($file) .
-        " | /petabox/sw/bin/kdu_expand -no_seek -quiet -reduce $reduce -i /dev/stdin -o /tmp/stdout.ppm ";
-        
-if (isset($_REQUEST['height'])) {
-    $cmd .= " | pnmscale -height {$_REQUEST['height']} ";
-}
-
-$cmd .= ' | pnmtojpeg -quality 90';
-
-
-passthru ($cmd);
-#print $cmd;
-?>
-
diff --git a/GnuBookIA/GnuBookJSIA.php b/GnuBookIA/GnuBookJSIA.php
deleted file mode 100755 (executable)
index 17ccaf0..0000000
+++ /dev/null
@@ -1,338 +0,0 @@
-<?
-/*
-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/>.
-*/
-
-$id = $_REQUEST['id'];
-$itemPath = $_REQUEST['itemPath'];
-$server = $_REQUEST['server']; 
-
-if ("" == $id) {
-    GBFatal("No identifier specified!");
-}
-
-if ("" == $itemPath) {
-    GBFatal("No itemPath specified!");
-}
-
-if ("" == $server) {
-    GBFatal("No server specified!");
-}
-
-
-if (!preg_match("|^/[0-3]/items/{$id}$|", $itemPath)) {
-    GBFatal("Bad id!");
-}
-
-$imageFormat = 'unknown';
-$zipFile = "$itemPath/{$id}_jp2.zip";
-if (file_exists($zipFile)) {
-    $imageFormat = 'jp2';
-} else {
-  $zipFile = "$itemPath/${id}_tif.zip";
-  if (file_exists($zipFile)) {
-    $imageFormat = 'tif';
-  }
-}
-
-if ("unknown" == $imageFormat) {
-  GBfatal("Unknown image format");
-}
-
-$scanDataFile = "$itemPath/{$id}_scandata.xml";
-$scanDataZip  = "$itemPath/scandata.zip";
-if (file_exists($scanDataFile)) {
-    $scanData = simplexml_load_file($scanDataFile);
-} else if (file_exists($scanDataZip)) {
-    $cmd  = 'unzip -p ' . escapeshellarg($scanDataZip) . ' scandata.xml';
-    exec($cmd, $output, $retval);
-    if ($retval != 0) GBFatal("Could not unzip ScanData!");
-    
-    $dump = join("\n", $output);
-    $scanData = simplexml_load_string($dump);
-} else if (file_exists("$itemPath/scandata.xml")) {
-    // For e.g. Scribe v.0 books!
-    $scanData = simplexml_load_file("$itemPath/scandata.xml");
-} else {
-    GBFatal("ScanData file not found!");
-}
-
-$metaDataFile = "$itemPath/{$id}_meta.xml";
-if (!file_exists($metaDataFile)) {
-    GBFatal("MetaData file not found!");
-}
-
-
-$metaData = simplexml_load_file($metaDataFile);
-
-//$firstLeaf = $scanData->pageData->page[0]['leafNum'];
-?>
-
-gb = new GnuBook();
-
-gb.getPageWidth = function(index) {
-    //return parseInt(this.pageW[index]/this.reduce);
-    return this.pageW[index];
-}
-
-gb.getPageHeight = function(index) {
-    //return parseInt(this.pageH[index]/this.reduce);
-    return this.pageH[index];
-}
-
-gb.getPageURI = function(index) {
-    var leafStr = '0000';            
-    var imgStr = this.leafMap[index].toString();
-    var re = new RegExp("0{"+imgStr.length+"}$");
-
-    if (1==this.mode) {
-        var url = 'http://'+this.server+'/GnuBook/GnuBookImages.php?zip='+this.zip+'&file='+this.bookId+'_'+this.imageFormat+'/'+this.bookId+'_'+leafStr.replace(re, imgStr) + '.'+this.imageFormat+'&scale='+this.reduce;
-    } else {
-        var ratio = this.getPageHeight(index) / this.twoPageH;
-        var scale;
-        // $$$ we make an assumption here that the scales are available pow2 (like kakadu)
-        if (ratio <= 2) {
-            scale = 1;
-        } else if (ratio <= 4) {
-            scale = 2;
-        } else {
-            scale = 4;
-        }        
-    
-        //var url = 'http://'+this.server+'/GnuBook/GnuBookImages.php?zip='+this.zip+'&file='+this.bookId+'_jp2/'+this.bookId+'_'+leafStr.replace(re, imgStr) + '.jp2&height='+this.twoPageH+'&origHeight='+this.getPageHeight(index);
-        var url = 'http://'+this.server+'/GnuBook/GnuBookImages.php?zip='+this.zip+'&file='+this.bookId+'_'+this.imageFormat+'/'+this.bookId+'_'+leafStr.replace(re, imgStr) + '.'+this.imageFormat+'&scale='+scale;
-        
-    }
-    return url;
-}
-
-gb.getPageSide = function(index) {
-    //assume the book starts with a cover (right-hand leaf)
-    //we should really get handside from scandata.xml
-    
-    // $$$ we should get this from scandata instead of assuming the accessible
-    //     leafs are contiguous
-    if ('rl' != this.pageProgression) {
-        // If pageProgression is not set RTL we assume it is LTR
-        if (0 == (index & 0x1)) {
-            // Even-numbered page
-            return 'R';
-        } else {
-            // Odd-numbered page
-            return 'L';
-        }
-    } else {
-        // RTL
-        if (0 == (index & 0x1)) {
-            return 'L';
-        } else {
-            return 'R';
-        }
-    }
-}
-
-gb.getPageNum = function(index) {
-    return this.pageNums[index];
-}
-
-gb.leafNumToIndex = function(leafNum) {
-    var index = jQuery.inArray(leafNum, this.leafMap);
-    if (-1 == index) {
-        return null;
-    } else {
-        return index;
-    }
-}
-
-// This function returns the left and right indices for the user-visible
-// spread that contains the given index.  The return values may be
-// null if there is no facing page or the index is invalid.
-gb.getSpreadIndices = function(pindex) {
-    // $$$ we could make a separate function for the RTL case and
-    //      only bind it if necessary instead of always checking
-    // $$$ we currently assume there are no gaps
-    
-    var spreadIndices = [null, null]; 
-    if ('rl' == this.pageProgression) {
-        // Right to Left
-        if (this.getPageSide(pindex) == 'R') {
-            spreadIndices[1] = pindex;
-            spreadIndices[0] = pindex + 1;
-        } else {
-            // Given index was LHS
-            spreadIndices[0] = pindex;
-            spreadIndices[1] = pindex - 1;
-        }
-    } else {
-        // Left to right
-        if (this.getPageSide(pindex) == 'L') {
-            spreadIndices[0] = pindex;
-            spreadIndices[1] = pindex + 1;
-        } else {
-            // Given index was RHS
-            spreadIndices[1] = pindex;
-            spreadIndices[0] = pindex - 1;
-        }
-    }
-    
-    //console.log("   index %d mapped to spread %d,%d", pindex, spreadIndices[0], spreadIndices[1]);
-    
-    return spreadIndices;
-}
-
-gb.pageW =             [
-            <?
-            $i=0;
-            foreach ($scanData->pageData->page as $page) {
-                if (shouldAddPage($page)) {
-                    if(0 != $i) echo ",";   //stupid IE
-                    echo "{$page->cropBox->w}";
-                    $i++;
-                }
-            }
-            ?>
-            ];
-
-gb.pageH =             [
-            <?
-            $totalHeight = 0;
-            $i=0;            
-            foreach ($scanData->pageData->page as $page) {
-                if (shouldAddPage($page)) {
-                    if(0 != $i) echo ",";   //stupid IE                
-                    echo "{$page->cropBox->h}";
-                    $totalHeight += intval($page->cropBox->h/4) + 10;
-                    $i++;
-                }
-            }
-            ?>
-            ];
-gb.leafMap = [
-            <?
-            $i=0;
-            foreach ($scanData->pageData->page as $page) {
-                if (shouldAddPage($page)) {
-                    if(0 != $i) echo ",";   //stupid IE
-                    echo "{$page['leafNum']}";
-                    $i++;
-                }
-            }
-            ?>    
-            ];
-
-gb.pageNums = [
-            <?
-            $i=0;
-            foreach ($scanData->pageData->page as $page) {
-                if (shouldAddPage($page)) {
-                    if(0 != $i) echo ",";   //stupid IE                
-                    if (array_key_exists('pageNumber', $page) && ('' != $page->pageNumber)) {
-                        echo "'{$page->pageNumber}'";
-                    } else {
-                        echo "null";
-                    }
-                    $i++;
-                }
-            }
-            ?>    
-            ];
-            
-<?
-/* 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;
-
-gb.bookId   = '<?echo $id;?>';
-gb.zip      = '<?echo $zipFile;?>';
-gb.server   = '<?echo $server;?>';
-gb.bookTitle= '<?echo preg_replace("/\'/", "\\'", $metaData->title);?>';
-gb.bookPath = '<?echo $itemPath;?>';
-gb.bookUrl  = '<?echo "http://www.archive.org/details/$id";?>';
-gb.imageFormat = '<?echo $imageFormat;?>';
-<?
-
-# Load some values from meta.xml
-if ('' != $metaData->{'page-progression'}) {
-  echo "gb.pageProgression = '" . $metaData->{"page-progression"} . "';";
-} else {
-  // Assume page progression is Left To Right
-  echo "gb.pageProgression = 'lr';";
-}
-
-# Special cases
-if ('bandersnatchhsye00scarrich' == $id) {
-    echo "gb.mode     = 2;\n";
-    echo "gb.auto     = true;\n";
-}
-
-?>
-
-
-// Check for config object
-if (typeof(gbConfig) != 'undefined') {
-    if (gbConfig['mode'] == 1) {
-      gb.mode = 1;
-    } 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;
-      //}
-  
-    }
-}
-
-gb.init();
-
-<?
-
-
-function GBFatal($string) {
-    echo "alert('$string')\n";
-    die(-1);
-}
-
-// Returns true if a page should be added based on it's information in
-// the metadata
-function shouldAddPage($page) {
-    // Return false only if the page is marked addToAccessFormats false.
-    // If there is no assertion we assume it should be added.
-    if (isset($page->addToAccessFormats)) {
-        if ("false" == strtolower(trim($page->addToAccessFormats))) {
-            return false;
-        }
-    }
-    
-    return true;
-}
-
-?>
\ No newline at end of file
diff --git a/GnuBookIA/GnuBookJSLocate.php b/GnuBookIA/GnuBookJSLocate.php
deleted file mode 100644 (file)
index 5ec166f..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?
-/*
-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
diff --git a/GnuBookIA/browserunsupported.php b/GnuBookIA/browserunsupported.php
deleted file mode 100644 (file)
index 98732a6..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-<?
-/*
-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/>.
-*/
-
-
-$id = $_REQUEST['id'];
-
-// Sanitize since we put this value in the page
-$id = urlencode($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); ?>">
-    <link rel="stylesheet" href="http://www.archive.org/stylesheets/archive.css?v=1.99" type="text/css">
-</head>
-<body>
-
-<table style="background-color:white " cellspacing="0" width="100%" border="0" cellpadding="0">
-  <tbody>
-    <tr> 
-      <td style="width:100px; height:72px; vertical-align:top; background-color:#000000;">
-
-        <a href="http://www.archive.org/"><img style="border:0;" alt="(logo)" src="http://www.archive.org/images/logo.jpg" width="84" height="70"/></a>
-      </td>
-      <td valign="bottom" style="background-image:url(http://www.archive.org/images/blendbar.jpg);">
-        <table width="100%" border="0" cellpadding="5">
-          <tr> 
-            <td class="level1Header">
-              <div class="tab"><a href="http://www.archive.org/web/web.php">Web</a></div><div class="tab"><a href="http://www.archive.org/details/movies">Moving Images</a></div><div class="tab"><a href="http://www.archive.org/details/texts">Texts</a></div><div class="tab"><a href="http://www.archive.org/details/audio">Audio</a></div><div class="tab"><a href="http://www.archive.org/details/software">Software</a></div><div class="tab"><a href="http://www.archive.org/details/education">Education</a></div><div class="tab"><a href="http://www.archive.org/account/login.changepw.php">Patron Info</a></div><div class="tab"><a href="http://www.archive.org/about/about.php">About IA</a></div>            </td>
-
-          </tr>
-                    
-        </table>
-      </td>
-      <td style="width:80px; height:72px; vertical-align:top; text-align: right">
-        <a href="http://www.archive.org/about/about.php"><img alt="(navigation image)" src="http://www.archive.org/images/main-header.jpg" style="margin:0; border:0; vertical-align:top;" /></a>      </td>
-    </tr>
-  </tbody>
-</table>
-
-<!--BEGIN HEADER 2-->
-<table width="100%" class="level2Header">
-  <tbody>
-    <tr>
-      <td align="left" valign="top" class="level2HeaderLeft">
-        <a class="level2Header" href="http://www.archive.org/">Home</a>
-      </td>
-      <td style="width:100%;" class="level2Header">
-        <a href="http://www.archive.org/donate/index.php">Donate</a> | 
-
-<a href="http://www.archive.org/iathreads/forums.php">Forums</a> | 
-<a href="http://www.archive.org/about/faqs.php">FAQs</a> | 
-<a href="http://www.archive.org/contribute.php">Contributions</a> | 
-<a href="http://www.archive.org/about/terms.php">Terms, Privacy, &amp; Copyright</a> | 
-<a href="http://www.archive.org/about/contact.php">Contact</a> | 
-<a href="http://www.archive.org/about/jobs.php">Jobs</a> | 
-
-<a href="http://www.archive.org/about/bios.php">Bios</a>
-      </td>
-    </tr>
-  </tbody>
-</table>
-
-
-<div class="box">
-<p>
-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>,
-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>.
-</p>
-
-<p>
-You will be automatically redirected to the older viewer in 10 seconds.
-</p>
-
-</div>
-
-<p id="iafoot">
-  <a href="http://www.archive.org/about/terms.php">Terms of Use (10 Mar 2001)</a>
-
-</p>
-
-</body>
-</html>
diff --git a/GnuBookIA/datanode/GnuBookImages.php b/GnuBookIA/datanode/GnuBookImages.php
new file mode 100644 (file)
index 0000000..a8c16ea
--- /dev/null
@@ -0,0 +1,158 @@
+<?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.
+
+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/>.
+*/
+
+$MIMES = array('jpg' => 'image/jpeg',
+               'png' => 'image/png');
+
+$zipPath  = $_REQUEST['zip'];
+$file     = $_REQUEST['file'];
+
+// Unfortunately kakadu requires us to know a priori if the
+// output file should be .ppm or .pgm.  By decompressing to
+// .bmp kakadu will write a file we can consistently turn into
+// .pnm.  Really kakadu should support .pnm as the file output
+// extension and automatically write ppm or pgm format as
+// appropriate.
+$decompressToBmp = true;
+if ($decompressToBmp) {
+  $stdoutLink = '/tmp/stdout.bmp';
+} else {
+  $stdoutLink = '/tmp/stdout.ppm';
+}
+
+if (isset($_REQUEST['ext'])) {
+  $ext = $_REQUEST['ext'];
+} else {
+  // Default to jpg
+  $ext = 'jpg';
+}
+
+$fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
+
+// Png conversion options
+$pngOptions = '';
+
+// The pbmreduce reduction factor produces an image with dimension 1/n
+// The kakadu reduction factor produceds an image with dimension 1/(2^n)
+
+if (isset($_REQUEST['height'])) {
+    $ratio = floatval($_REQUEST['origHeight']) / floatval($_REQUEST['height']);
+    if ($ratio <= 2) {
+        $scale = 2;
+        $reduce = 1;    
+    } else if ($ratio <= 4) {
+        $scale = 4;
+        $reduce = 2;
+    } else {
+        //$reduce = 3; //too blurry!
+        $scale = 2;
+        $reduce = 1;
+    }
+
+} else {
+    $scale = $_REQUEST['scale'];
+    if (1 >= $scale) {
+        $scale = 1;
+        $reduce = 0;
+    } else if (2 == $scale) {
+        $reduce = 1;
+    } else if (4 == $scale) {
+        $reduce = 2;
+    } else {
+        // $$$ why do we default to such a small scale?
+        $scale = 8;
+        $reduce = 3;
+    }
+}
+
+if (!file_exists($stdoutLink)) 
+{  
+  system('ln -s /dev/stdout ' . $stdoutLink);  
+}
+
+
+putenv('LD_LIBRARY_PATH=/petabox/sw/lib/kakadu');
+
+$unzipCmd  = 'unzip -p ' . 
+        escapeshellarg($zipPath) .
+        ' ' . escapeshellarg($file);
+        
+if ('jp2' == $fileExt) {
+    $decompressCmd = 
+        " | /petabox/sw/bin/kdu_expand -no_seek -quiet -reduce $reduce -i /dev/stdin -o " . $stdoutLink;
+    if ($decompressToBmp) {
+        $decompressCmd .= ' | bmptopnm ';
+    }
+} else if ('tif' == $fileExt) {
+    // We need to create a temporary file for tifftopnm since it cannot
+    // work on a pipe (the file must be seekable).
+    // We use the GnuBookTiff prefix to give a hint in case things don't
+    // get cleaned up.
+    $tempFile = tempnam("/tmp", "GnuBookTiff");
+    
+    if (1 != $scale) {
+        $pbmReduce = ' | pbmreduce -threshold ' . $scale;
+    } else {
+        $pbmReduce = '';
+    }
+    
+    $decompressCmd = 
+        ' > ' . $tempFile . ' ; tifftopnm ' . $tempFile . ' 2>/dev/null' . $pbmReduce;
+
+} else {
+    GBfatal('Unknown source file extension: ' . $fileExt);
+}
+       
+// Non-integer scaling is currently disabled on the cluster
+// if (isset($_REQUEST['height'])) {
+//     $cmd .= " | pnmscale -height {$_REQUEST['height']} ";
+// }
+
+if ('jpg' == $ext) {
+    $compressCmd = ' | pnmtojpeg -quality 90';
+} else if ('png' == $ext) {
+    $compressCmd = ' | pnmtopng $pngOptions';
+}
+
+$cmd = $unzipCmd . $decompressCmd . $compressCmd;
+
+//print $cmd;
+
+header('Content-type: ' . $MIMES[$ext]);
+header('Cache-Control: max-age=15552000');
+
+passthru ($cmd);
+
+if (isset($tempFile)) {
+  unlink($tempFile);
+}
+
+function GBFatal($string) {
+    echo "alert('$string')\n";
+    die(-1);
+}
+
+?>
+
diff --git a/GnuBookIA/datanode/GnuBookJSIA.php b/GnuBookIA/datanode/GnuBookJSIA.php
new file mode 100755 (executable)
index 0000000..17ccaf0
--- /dev/null
@@ -0,0 +1,338 @@
+<?
+/*
+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/>.
+*/
+
+$id = $_REQUEST['id'];
+$itemPath = $_REQUEST['itemPath'];
+$server = $_REQUEST['server']; 
+
+if ("" == $id) {
+    GBFatal("No identifier specified!");
+}
+
+if ("" == $itemPath) {
+    GBFatal("No itemPath specified!");
+}
+
+if ("" == $server) {
+    GBFatal("No server specified!");
+}
+
+
+if (!preg_match("|^/[0-3]/items/{$id}$|", $itemPath)) {
+    GBFatal("Bad id!");
+}
+
+$imageFormat = 'unknown';
+$zipFile = "$itemPath/{$id}_jp2.zip";
+if (file_exists($zipFile)) {
+    $imageFormat = 'jp2';
+} else {
+  $zipFile = "$itemPath/${id}_tif.zip";
+  if (file_exists($zipFile)) {
+    $imageFormat = 'tif';
+  }
+}
+
+if ("unknown" == $imageFormat) {
+  GBfatal("Unknown image format");
+}
+
+$scanDataFile = "$itemPath/{$id}_scandata.xml";
+$scanDataZip  = "$itemPath/scandata.zip";
+if (file_exists($scanDataFile)) {
+    $scanData = simplexml_load_file($scanDataFile);
+} else if (file_exists($scanDataZip)) {
+    $cmd  = 'unzip -p ' . escapeshellarg($scanDataZip) . ' scandata.xml';
+    exec($cmd, $output, $retval);
+    if ($retval != 0) GBFatal("Could not unzip ScanData!");
+    
+    $dump = join("\n", $output);
+    $scanData = simplexml_load_string($dump);
+} else if (file_exists("$itemPath/scandata.xml")) {
+    // For e.g. Scribe v.0 books!
+    $scanData = simplexml_load_file("$itemPath/scandata.xml");
+} else {
+    GBFatal("ScanData file not found!");
+}
+
+$metaDataFile = "$itemPath/{$id}_meta.xml";
+if (!file_exists($metaDataFile)) {
+    GBFatal("MetaData file not found!");
+}
+
+
+$metaData = simplexml_load_file($metaDataFile);
+
+//$firstLeaf = $scanData->pageData->page[0]['leafNum'];
+?>
+
+gb = new GnuBook();
+
+gb.getPageWidth = function(index) {
+    //return parseInt(this.pageW[index]/this.reduce);
+    return this.pageW[index];
+}
+
+gb.getPageHeight = function(index) {
+    //return parseInt(this.pageH[index]/this.reduce);
+    return this.pageH[index];
+}
+
+gb.getPageURI = function(index) {
+    var leafStr = '0000';            
+    var imgStr = this.leafMap[index].toString();
+    var re = new RegExp("0{"+imgStr.length+"}$");
+
+    if (1==this.mode) {
+        var url = 'http://'+this.server+'/GnuBook/GnuBookImages.php?zip='+this.zip+'&file='+this.bookId+'_'+this.imageFormat+'/'+this.bookId+'_'+leafStr.replace(re, imgStr) + '.'+this.imageFormat+'&scale='+this.reduce;
+    } else {
+        var ratio = this.getPageHeight(index) / this.twoPageH;
+        var scale;
+        // $$$ we make an assumption here that the scales are available pow2 (like kakadu)
+        if (ratio <= 2) {
+            scale = 1;
+        } else if (ratio <= 4) {
+            scale = 2;
+        } else {
+            scale = 4;
+        }        
+    
+        //var url = 'http://'+this.server+'/GnuBook/GnuBookImages.php?zip='+this.zip+'&file='+this.bookId+'_jp2/'+this.bookId+'_'+leafStr.replace(re, imgStr) + '.jp2&height='+this.twoPageH+'&origHeight='+this.getPageHeight(index);
+        var url = 'http://'+this.server+'/GnuBook/GnuBookImages.php?zip='+this.zip+'&file='+this.bookId+'_'+this.imageFormat+'/'+this.bookId+'_'+leafStr.replace(re, imgStr) + '.'+this.imageFormat+'&scale='+scale;
+        
+    }
+    return url;
+}
+
+gb.getPageSide = function(index) {
+    //assume the book starts with a cover (right-hand leaf)
+    //we should really get handside from scandata.xml
+    
+    // $$$ we should get this from scandata instead of assuming the accessible
+    //     leafs are contiguous
+    if ('rl' != this.pageProgression) {
+        // If pageProgression is not set RTL we assume it is LTR
+        if (0 == (index & 0x1)) {
+            // Even-numbered page
+            return 'R';
+        } else {
+            // Odd-numbered page
+            return 'L';
+        }
+    } else {
+        // RTL
+        if (0 == (index & 0x1)) {
+            return 'L';
+        } else {
+            return 'R';
+        }
+    }
+}
+
+gb.getPageNum = function(index) {
+    return this.pageNums[index];
+}
+
+gb.leafNumToIndex = function(leafNum) {
+    var index = jQuery.inArray(leafNum, this.leafMap);
+    if (-1 == index) {
+        return null;
+    } else {
+        return index;
+    }
+}
+
+// This function returns the left and right indices for the user-visible
+// spread that contains the given index.  The return values may be
+// null if there is no facing page or the index is invalid.
+gb.getSpreadIndices = function(pindex) {
+    // $$$ we could make a separate function for the RTL case and
+    //      only bind it if necessary instead of always checking
+    // $$$ we currently assume there are no gaps
+    
+    var spreadIndices = [null, null]; 
+    if ('rl' == this.pageProgression) {
+        // Right to Left
+        if (this.getPageSide(pindex) == 'R') {
+            spreadIndices[1] = pindex;
+            spreadIndices[0] = pindex + 1;
+        } else {
+            // Given index was LHS
+            spreadIndices[0] = pindex;
+            spreadIndices[1] = pindex - 1;
+        }
+    } else {
+        // Left to right
+        if (this.getPageSide(pindex) == 'L') {
+            spreadIndices[0] = pindex;
+            spreadIndices[1] = pindex + 1;
+        } else {
+            // Given index was RHS
+            spreadIndices[1] = pindex;
+            spreadIndices[0] = pindex - 1;
+        }
+    }
+    
+    //console.log("   index %d mapped to spread %d,%d", pindex, spreadIndices[0], spreadIndices[1]);
+    
+    return spreadIndices;
+}
+
+gb.pageW =             [
+            <?
+            $i=0;
+            foreach ($scanData->pageData->page as $page) {
+                if (shouldAddPage($page)) {
+                    if(0 != $i) echo ",";   //stupid IE
+                    echo "{$page->cropBox->w}";
+                    $i++;
+                }
+            }
+            ?>
+            ];
+
+gb.pageH =             [
+            <?
+            $totalHeight = 0;
+            $i=0;            
+            foreach ($scanData->pageData->page as $page) {
+                if (shouldAddPage($page)) {
+                    if(0 != $i) echo ",";   //stupid IE                
+                    echo "{$page->cropBox->h}";
+                    $totalHeight += intval($page->cropBox->h/4) + 10;
+                    $i++;
+                }
+            }
+            ?>
+            ];
+gb.leafMap = [
+            <?
+            $i=0;
+            foreach ($scanData->pageData->page as $page) {
+                if (shouldAddPage($page)) {
+                    if(0 != $i) echo ",";   //stupid IE
+                    echo "{$page['leafNum']}";
+                    $i++;
+                }
+            }
+            ?>    
+            ];
+
+gb.pageNums = [
+            <?
+            $i=0;
+            foreach ($scanData->pageData->page as $page) {
+                if (shouldAddPage($page)) {
+                    if(0 != $i) echo ",";   //stupid IE                
+                    if (array_key_exists('pageNumber', $page) && ('' != $page->pageNumber)) {
+                        echo "'{$page->pageNumber}'";
+                    } else {
+                        echo "null";
+                    }
+                    $i++;
+                }
+            }
+            ?>    
+            ];
+            
+<?
+/* 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;
+
+gb.bookId   = '<?echo $id;?>';
+gb.zip      = '<?echo $zipFile;?>';
+gb.server   = '<?echo $server;?>';
+gb.bookTitle= '<?echo preg_replace("/\'/", "\\'", $metaData->title);?>';
+gb.bookPath = '<?echo $itemPath;?>';
+gb.bookUrl  = '<?echo "http://www.archive.org/details/$id";?>';
+gb.imageFormat = '<?echo $imageFormat;?>';
+<?
+
+# Load some values from meta.xml
+if ('' != $metaData->{'page-progression'}) {
+  echo "gb.pageProgression = '" . $metaData->{"page-progression"} . "';";
+} else {
+  // Assume page progression is Left To Right
+  echo "gb.pageProgression = 'lr';";
+}
+
+# Special cases
+if ('bandersnatchhsye00scarrich' == $id) {
+    echo "gb.mode     = 2;\n";
+    echo "gb.auto     = true;\n";
+}
+
+?>
+
+
+// Check for config object
+if (typeof(gbConfig) != 'undefined') {
+    if (gbConfig['mode'] == 1) {
+      gb.mode = 1;
+    } 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;
+      //}
+  
+    }
+}
+
+gb.init();
+
+<?
+
+
+function GBFatal($string) {
+    echo "alert('$string')\n";
+    die(-1);
+}
+
+// Returns true if a page should be added based on it's information in
+// the metadata
+function shouldAddPage($page) {
+    // Return false only if the page is marked addToAccessFormats false.
+    // If there is no assertion we assume it should be added.
+    if (isset($page->addToAccessFormats)) {
+        if ("false" == strtolower(trim($page->addToAccessFormats))) {
+            return false;
+        }
+    }
+    
+    return true;
+}
+
+?>
\ No newline at end of file
diff --git a/GnuBookIA/datanode/flipbook_search_gb.php b/GnuBookIA/datanode/flipbook_search_gb.php
new file mode 100755 (executable)
index 0000000..e9154d4
--- /dev/null
@@ -0,0 +1,310 @@
+<?php
+/*
+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/>.
+*/
+
+// FIXME: TODO: Change path above to production installation location of perl
+// when we deploy, Brad Neuberg, bkn3@columbia.edu
+//
+// From:
+//   search.cgi v0.4
+//   by Ralf Muehlen
+//
+// slight alterations by Brad Neuberg, bkn3@columbia.edu
+//
+// ported from perl to php by tracey, Oct 2005
+
+//fixxx require_once '/petabox/setup.inc';
+//I think this fixxx refers to the need to set DOCUMENT_ROOT below -- mang
+
+if (strpos($_SERVER["REQUEST_URI"], "/~mang") === 0) { // Serving out of home dir
+    $_SERVER['DOCUMENT_ROOT']='/home/mang/petabox/www/sf';
+    require_once '/home/mang/petabox/setup.inc';
+} else {
+    $_SERVER['DOCUMENT_ROOT']='/petabox/www/sf';
+    require_once '/petabox/setup.inc';
+}
+
+ini_set("memory_limit","200M"); // XML can be big, esp. brittanica (100MB)
+
+/////// SETUP /////////////////////////////////////////////////////////////
+
+$debug_level = 0; // 0=least, 3=most debugging info
+
+$num_pre  = 3; // context words before search term
+$num_post = 9; // context words after  search term
+
+// defaults for testing (when no args given)
+$url ='http://ia300202.us.archive.org/0/items/englishbookbindings00davenuoft/englishbookbindings00davenuoft_djvuxml.xml';
+
+$term = "history";
+$format = "XML";
+$callback = false;
+
+/////// SETUP /////////////////////////////////////////////////////////////
+
+
+// fixxx prolly should escapesystemcall() these...
+if (isset($_GET['url']))
+  $url =        $_GET['url'];
+if (isset($_GET['term']))
+  $term =       $_GET['term'];
+if (isset($_GET['format']))
+  $format =     $_GET['format'];
+if (isset($_GET['callback']))
+  $callback =     $_GET['callback'];
+
+//$url='http://homeserver.hq.archive.org/metafetch/thespy00cooparch_djvu.xml';
+//$url='http://homeserver.hq.archive.org/metafetch/oldchristmas00irviarch_djvu.xml';
+//$url = 'http://homeserver.hq.archive.org/metafetch/intlepisode00jamearch_djvu.xml';
+  
+
+if ($format == "XML")
+{
+  // This is kinda weird (confession!) but allows existing calls to "fatal()"
+  // to throw an exception instead of dumping HTML to stdout/browser!
+  $GLOBALS['fatal-exceptions']=1;
+}
+try
+{
+
+
+// pageFiles was added to keep track of on what page each search match was
+// found, Brad Neuberg, bkn3@columbia.edu
+// pageHeights and pageWidths was added to track the size of each page so that
+// we can send it over to the client; this is necessary for scaling the images
+// for search, Brad Neuberg, bkn3@columbia.edu
+$pages =       array();
+$pageFiles =   array();
+$pageHeights = array();
+$pageWidths =  array();
+
+
+$time0 = microtime(true);
+$timestamp = date('Y-m-d H:i:s');
+$pid = posix_getpid();
+debug_msg("Invoked at ".$time0."=$timestamp under UID ".posix_getuid(),2);
+
+
+//////////////////////////////////////
+
+debug_msg("query: ".$_SERVER['QUERY_STRING'],3);
+
+
+$term = preg_replace('/[^A-Za-z0-9 ]/', ' ', $term); // legal characters
+$terms = explode(' ',$term);
+debug_msg("url,term,format: $url,".var_export($terms,true).",$format",3);
+
+
+if ($format == "HTML")
+{
+  echo "<html><head><title>Search</title></head> <body> Searching <p>";
+  $tag_pre  = '<b style="color:black;background-color:#A0FFFF">';
+  $tag_post = '</b>';
+}
+else if ($format == "XML")
+{
+  if (false === $callback) {
+      header('Content-type: text/xml');
+  } else {
+      header('application/x-javascript');
+  }
+  $tag_pre  = '</CONTEXT>';
+  $tag_post = '<CONTEXT>';
+}
+else
+{
+  fatal("Unknown format request. ");
+}
+
+// This looks like where we load the djvu.xml
+if (!($document = file_get_contents($url)))
+  fatal("could not load $url");
+
+
+
+$time1 = microtime(true) - $time0;
+
+
+//// Pass 1 - build up page* arrays with xml fragments corresponding to matches
+$pagenumber=0;
+foreach (explode('</OBJECT>', $document) as $page)
+{
+  $pagenumber++;
+  if (matches_terms($page, $terms)  &&
+      // 2nd clause here is to ensure that we aren't matching in the end
+      // of the overall XML document -- thus we ensure that OBJECT tag starts
+      // in the chunk we just were handed.  (traceyj)
+      strstr($page, '<OBJECT '))
+  {
+    // extract the page value so that we know what page we are on,
+    // Brad Neuberg, bkn3@columbia.edu
+    if (!preg_match('|<PARAM name="PAGE" value="([^"]*)"\s*\/>|', $page, $match))
+      fatal("page value not set on page number $pagenumber in $page!");
+    $pageFile = $match[1];
+    
+    // extract the page width and height, Brad Neuberg, bkn3@columbia.edu
+    if (!preg_match('/width="([^"]*)"/', $page, $match))
+      fatal("page width not set!");
+    $pageWidth = $match[1];
+
+    if (!preg_match('/height="([^"]*)"/', $page, $match))
+      fatal("page height not set!");
+    $pageHeight = $match[1];
+    
+    $page_new='';
+    foreach (explode('</WORD>',$page) as $token)
+    {
+      if (matches_terms($token, $terms))
+      {
+        list($junk, $keep) = explode('<WORD ',$token);
+        $token = " $tag_pre<WORD $keep</WORD>$tag_post "; 
+      }
+      else
+      {
+        $token = preg_replace('/<[^<]*>/','', $token);     //mark-up
+        $token = preg_replace('/[\&\#\d+;]/', ' ', $token);//non-ascii chars
+        $token = preg_replace('/\s+/', ' ', $token);       //white space
+      }
+
+      $page_new .= $token;
+    }
+
+    
+    
+    $page_new =
+      preg_replace('|.*((\W\w*){'.$num_pre.'}'.$tag_pre.')|',"$1",$page_new);
+    $page_new =
+      preg_replace('/('.$tag_post.'(\w*\W){'.$num_post.'}).*/',"$1",$page_new);
+    
+    
+    // added to keep track of the page we are on
+    // Brad Neuberg, bkn3@columbia.edu
+    $pageFiles  [$pagenumber] = $pageFile;
+    $pages      [$pagenumber] = $page_new;
+    // added to keep track of page widths and heights
+    $pageWidths [$pagenumber] = $pageWidth;
+    $pageHeights[$pagenumber] = $pageHeight;
+  }
+}
+
+
+$time2 =  microtime(true) - $time1;
+
+//// Pass 2 - generate output from previously built arrays
+
+
+if ($format == "HTML")
+{
+  echo "Found ".count($pages)." pages containing $tag_pre";
+  print_r($terms);
+  echo "$tag_post.<br>\n";
+  foreach ($pages as $index => $page)
+  {
+    echo "<h4>Page $page:</h4>\n";
+    print_r($page);
+    echo "<p><br><p>\n";
+  }
+  $time3 = microtime(true) - $time2;
+  echo $tag_pre . "Fetched document in $time1 ms.$tag_post<p>\n";
+  echo $tag_pre . "Processed document in $time2 ms.$tag_post<p>\n";
+  echo $tag_pre . "Printed document in $time3 ms.$tag_post<p>\n";
+  echo "</body></html>\n";
+}
+else if ($format == "XML")
+{
+  $xml = "";
+  $xml .= '<?xml version="1.0" encoding="utf-8"?>'."\n";
+  // Added to prevent Internet Explorer from adding default XML stylesheet,
+  // which messes up processing, Brad Neuberg, bkn3@columbia.edu
+  $xml .= '<?xml-stylesheet type="text/css" href="blank.css"?>'."\n";//fixxx
+  $xml .= '<SEARCH>';
+
+  foreach ($pages as $index => $page)
+  {
+    $xml .= "<PAGE file=\"{$pageFiles[$index]}\" width=\"{$pageWidths[$index]}\" height=\"{$pageHeights[$index]}\">\n";
+    $xml .= "<CONTEXT>\n";
+    $xml .= $page;
+    $xml .= "</CONTEXT>\n";
+    $xml .= "</PAGE>\n";
+  }
+  $xml .= "</SEARCH>\n";
+  
+  // The XML contains the page numbers from the DJVU XML.  We must remap them to flipbook indices
+  // since the flipbook indices are monotonically increasing generated from the pages with
+  // addToAccessFormats true (maybe)
+  $fsm = FlipSearchMap::buildSearchMap($url);
+  if (false === $callback) {
+      echo $fsm->remapSearch($xml);
+  } else {
+      $patterns[0] = '/\n/';
+      $patterns[1] = "/\'/"; 
+      $replac[0]   = '';
+      $replac[1]   = '&#39;';
+      
+      // We don't have FlipSearchMap remap since we have our own mapping between
+      // scandata.xml leaf numbers and GB indices that happens in GBSearchCallback
+      echo "$callback('". preg_replace($patterns, $replac, $xml)."');";
+  }
+  //echo $xml;
+}
+
+//////
+debug_msg("Done and exiting!",2);
+exit;
+//////
+}
+catch (Exception $e)
+{
+  // an internal method call invoked "fatal()"...
+  XML::resultMessage('error','internal_error', $e->getMessage());
+}
+
+
+
+
+function matches_terms(&$text, // search space
+                       &$terms)// array of search terms
+{
+  foreach ($terms as $term)
+  {
+    if (preg_match("/$term/i", $text))
+      return true;
+  }
+  return false;
+}
+
+
+function debug_msg($msg, $level)
+{
+  global $debug_level;
+  global $pid;
+  global $format;
+  if ($level <= $debug_level)
+  {
+    if ($format == "XML")
+      echo "<!-- FILL  ($pid):$level: $msg -->\n";
+    else
+      echo "FILL  ($pid):$level: $msg<br/>\n";
+  }
+}
+
+
+?>
diff --git a/GnuBookIA/flipbook_search_gb.php b/GnuBookIA/flipbook_search_gb.php
deleted file mode 100755 (executable)
index e9154d4..0000000
+++ /dev/null
@@ -1,310 +0,0 @@
-<?php
-/*
-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/>.
-*/
-
-// FIXME: TODO: Change path above to production installation location of perl
-// when we deploy, Brad Neuberg, bkn3@columbia.edu
-//
-// From:
-//   search.cgi v0.4
-//   by Ralf Muehlen
-//
-// slight alterations by Brad Neuberg, bkn3@columbia.edu
-//
-// ported from perl to php by tracey, Oct 2005
-
-//fixxx require_once '/petabox/setup.inc';
-//I think this fixxx refers to the need to set DOCUMENT_ROOT below -- mang
-
-if (strpos($_SERVER["REQUEST_URI"], "/~mang") === 0) { // Serving out of home dir
-    $_SERVER['DOCUMENT_ROOT']='/home/mang/petabox/www/sf';
-    require_once '/home/mang/petabox/setup.inc';
-} else {
-    $_SERVER['DOCUMENT_ROOT']='/petabox/www/sf';
-    require_once '/petabox/setup.inc';
-}
-
-ini_set("memory_limit","200M"); // XML can be big, esp. brittanica (100MB)
-
-/////// SETUP /////////////////////////////////////////////////////////////
-
-$debug_level = 0; // 0=least, 3=most debugging info
-
-$num_pre  = 3; // context words before search term
-$num_post = 9; // context words after  search term
-
-// defaults for testing (when no args given)
-$url ='http://ia300202.us.archive.org/0/items/englishbookbindings00davenuoft/englishbookbindings00davenuoft_djvuxml.xml';
-
-$term = "history";
-$format = "XML";
-$callback = false;
-
-/////// SETUP /////////////////////////////////////////////////////////////
-
-
-// fixxx prolly should escapesystemcall() these...
-if (isset($_GET['url']))
-  $url =        $_GET['url'];
-if (isset($_GET['term']))
-  $term =       $_GET['term'];
-if (isset($_GET['format']))
-  $format =     $_GET['format'];
-if (isset($_GET['callback']))
-  $callback =     $_GET['callback'];
-
-//$url='http://homeserver.hq.archive.org/metafetch/thespy00cooparch_djvu.xml';
-//$url='http://homeserver.hq.archive.org/metafetch/oldchristmas00irviarch_djvu.xml';
-//$url = 'http://homeserver.hq.archive.org/metafetch/intlepisode00jamearch_djvu.xml';
-  
-
-if ($format == "XML")
-{
-  // This is kinda weird (confession!) but allows existing calls to "fatal()"
-  // to throw an exception instead of dumping HTML to stdout/browser!
-  $GLOBALS['fatal-exceptions']=1;
-}
-try
-{
-
-
-// pageFiles was added to keep track of on what page each search match was
-// found, Brad Neuberg, bkn3@columbia.edu
-// pageHeights and pageWidths was added to track the size of each page so that
-// we can send it over to the client; this is necessary for scaling the images
-// for search, Brad Neuberg, bkn3@columbia.edu
-$pages =       array();
-$pageFiles =   array();
-$pageHeights = array();
-$pageWidths =  array();
-
-
-$time0 = microtime(true);
-$timestamp = date('Y-m-d H:i:s');
-$pid = posix_getpid();
-debug_msg("Invoked at ".$time0."=$timestamp under UID ".posix_getuid(),2);
-
-
-//////////////////////////////////////
-
-debug_msg("query: ".$_SERVER['QUERY_STRING'],3);
-
-
-$term = preg_replace('/[^A-Za-z0-9 ]/', ' ', $term); // legal characters
-$terms = explode(' ',$term);
-debug_msg("url,term,format: $url,".var_export($terms,true).",$format",3);
-
-
-if ($format == "HTML")
-{
-  echo "<html><head><title>Search</title></head> <body> Searching <p>";
-  $tag_pre  = '<b style="color:black;background-color:#A0FFFF">';
-  $tag_post = '</b>';
-}
-else if ($format == "XML")
-{
-  if (false === $callback) {
-      header('Content-type: text/xml');
-  } else {
-      header('application/x-javascript');
-  }
-  $tag_pre  = '</CONTEXT>';
-  $tag_post = '<CONTEXT>';
-}
-else
-{
-  fatal("Unknown format request. ");
-}
-
-// This looks like where we load the djvu.xml
-if (!($document = file_get_contents($url)))
-  fatal("could not load $url");
-
-
-
-$time1 = microtime(true) - $time0;
-
-
-//// Pass 1 - build up page* arrays with xml fragments corresponding to matches
-$pagenumber=0;
-foreach (explode('</OBJECT>', $document) as $page)
-{
-  $pagenumber++;
-  if (matches_terms($page, $terms)  &&
-      // 2nd clause here is to ensure that we aren't matching in the end
-      // of the overall XML document -- thus we ensure that OBJECT tag starts
-      // in the chunk we just were handed.  (traceyj)
-      strstr($page, '<OBJECT '))
-  {
-    // extract the page value so that we know what page we are on,
-    // Brad Neuberg, bkn3@columbia.edu
-    if (!preg_match('|<PARAM name="PAGE" value="([^"]*)"\s*\/>|', $page, $match))
-      fatal("page value not set on page number $pagenumber in $page!");
-    $pageFile = $match[1];
-    
-    // extract the page width and height, Brad Neuberg, bkn3@columbia.edu
-    if (!preg_match('/width="([^"]*)"/', $page, $match))
-      fatal("page width not set!");
-    $pageWidth = $match[1];
-
-    if (!preg_match('/height="([^"]*)"/', $page, $match))
-      fatal("page height not set!");
-    $pageHeight = $match[1];
-    
-    $page_new='';
-    foreach (explode('</WORD>',$page) as $token)
-    {
-      if (matches_terms($token, $terms))
-      {
-        list($junk, $keep) = explode('<WORD ',$token);
-        $token = " $tag_pre<WORD $keep</WORD>$tag_post "; 
-      }
-      else
-      {
-        $token = preg_replace('/<[^<]*>/','', $token);     //mark-up
-        $token = preg_replace('/[\&\#\d+;]/', ' ', $token);//non-ascii chars
-        $token = preg_replace('/\s+/', ' ', $token);       //white space
-      }
-
-      $page_new .= $token;
-    }
-
-    
-    
-    $page_new =
-      preg_replace('|.*((\W\w*){'.$num_pre.'}'.$tag_pre.')|',"$1",$page_new);
-    $page_new =
-      preg_replace('/('.$tag_post.'(\w*\W){'.$num_post.'}).*/',"$1",$page_new);
-    
-    
-    // added to keep track of the page we are on
-    // Brad Neuberg, bkn3@columbia.edu
-    $pageFiles  [$pagenumber] = $pageFile;
-    $pages      [$pagenumber] = $page_new;
-    // added to keep track of page widths and heights
-    $pageWidths [$pagenumber] = $pageWidth;
-    $pageHeights[$pagenumber] = $pageHeight;
-  }
-}
-
-
-$time2 =  microtime(true) - $time1;
-
-//// Pass 2 - generate output from previously built arrays
-
-
-if ($format == "HTML")
-{
-  echo "Found ".count($pages)." pages containing $tag_pre";
-  print_r($terms);
-  echo "$tag_post.<br>\n";
-  foreach ($pages as $index => $page)
-  {
-    echo "<h4>Page $page:</h4>\n";
-    print_r($page);
-    echo "<p><br><p>\n";
-  }
-  $time3 = microtime(true) - $time2;
-  echo $tag_pre . "Fetched document in $time1 ms.$tag_post<p>\n";
-  echo $tag_pre . "Processed document in $time2 ms.$tag_post<p>\n";
-  echo $tag_pre . "Printed document in $time3 ms.$tag_post<p>\n";
-  echo "</body></html>\n";
-}
-else if ($format == "XML")
-{
-  $xml = "";
-  $xml .= '<?xml version="1.0" encoding="utf-8"?>'."\n";
-  // Added to prevent Internet Explorer from adding default XML stylesheet,
-  // which messes up processing, Brad Neuberg, bkn3@columbia.edu
-  $xml .= '<?xml-stylesheet type="text/css" href="blank.css"?>'."\n";//fixxx
-  $xml .= '<SEARCH>';
-
-  foreach ($pages as $index => $page)
-  {
-    $xml .= "<PAGE file=\"{$pageFiles[$index]}\" width=\"{$pageWidths[$index]}\" height=\"{$pageHeights[$index]}\">\n";
-    $xml .= "<CONTEXT>\n";
-    $xml .= $page;
-    $xml .= "</CONTEXT>\n";
-    $xml .= "</PAGE>\n";
-  }
-  $xml .= "</SEARCH>\n";
-  
-  // The XML contains the page numbers from the DJVU XML.  We must remap them to flipbook indices
-  // since the flipbook indices are monotonically increasing generated from the pages with
-  // addToAccessFormats true (maybe)
-  $fsm = FlipSearchMap::buildSearchMap($url);
-  if (false === $callback) {
-      echo $fsm->remapSearch($xml);
-  } else {
-      $patterns[0] = '/\n/';
-      $patterns[1] = "/\'/"; 
-      $replac[0]   = '';
-      $replac[1]   = '&#39;';
-      
-      // We don't have FlipSearchMap remap since we have our own mapping between
-      // scandata.xml leaf numbers and GB indices that happens in GBSearchCallback
-      echo "$callback('". preg_replace($patterns, $replac, $xml)."');";
-  }
-  //echo $xml;
-}
-
-//////
-debug_msg("Done and exiting!",2);
-exit;
-//////
-}
-catch (Exception $e)
-{
-  // an internal method call invoked "fatal()"...
-  XML::resultMessage('error','internal_error', $e->getMessage());
-}
-
-
-
-
-function matches_terms(&$text, // search space
-                       &$terms)// array of search terms
-{
-  foreach ($terms as $term)
-  {
-    if (preg_match("/$term/i", $text))
-      return true;
-  }
-  return false;
-}
-
-
-function debug_msg($msg, $level)
-{
-  global $debug_level;
-  global $pid;
-  global $format;
-  if ($level <= $debug_level)
-  {
-    if ($format == "XML")
-      echo "<!-- FILL  ($pid):$level: $msg -->\n";
-    else
-      echo "FILL  ($pid):$level: $msg<br/>\n";
-  }
-}
-
-
-?>
diff --git a/GnuBookIA/inc/GnuBook.inc b/GnuBookIA/inc/GnuBook.inc
new file mode 100644 (file)
index 0000000..cb8ba40
--- /dev/null
@@ -0,0 +1,149 @@
+<?
+
+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')
+  {
+    // Set title to default if not set
+    if (!$title) {
+        $title = 'Bookreader';
+    }
+    
+    $id = $identifier;
+    
+    // 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.7";
+    
+    if ("" == $id) {
+        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>
+<head>
+    <title><? echo $title; ?></title>
+<!--[if lte IE 6]>
+    <meta http-equiv="refresh" content="2; URL=/bookreader/browserunsupported.php?id=<? echo($id); ?>">
+<![endif]-->
+    <link rel="stylesheet" type="text/css" href="/bookreader/GnuBook.css?v=<? echo($version); ?>">    
+    <script src="http://www.archive.org/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: #FFFFFF;">
+
+<div id="GnuBook" style="left:10px; right:200px; top:10px; bottom:2em;">x</div>
+
+<script type="text/javascript">
+  // Set some config variables -- $$$ NB: Config object format has not been finalized
+  var gbConfig = {};
+  gbConfig.mode = 2;
+</script>
+<script type="text/javascript" src="<? echo($metaURL); ?>"></script>
+
+<div id="GnuBookSearch" style="width:190px; right:0px; top:10px; bottom:2em;">
+    <form action='javascript:' onsubmit="gb.search($('#GnuBookSearchBox').val());">
+        <p style="display: inline">
+            <input id="GnuBookSearchBox" type="text" size="20" value="search..." onfocus="if('search...'==this.value)this.value='';" /><input type="submit" value="go" />
+        </p>
+    </form>
+    <div id="GnuBookSearchResults">
+        Search results
+    </div>
+</div>
+
+
+<div id="GBfooter">
+    <div class="GBlogotype">
+        <a href="http://archive.org/" class="GBblack">Internet Archive</a>
+    </div>
+    <div class="GBnavlinks">
+        <!-- <a class="GBblack" href="http://openlibrary.org/dev/docs/bookreader">About the Bookreader</a> | -->
+        <a class="GBblack" href="https://bugs.launchpad.net/bookserver/+filebug-advanced">Report Errors</a> |
+        <a class="GBblack" href="http://www.archive.org/details/texts">Texts Collection</a> |
+        <a class="GBblack" href="http://www.archive.org/about/contact.php">Contact Us</a>
+    </div>
+</div>
+
+<script type="text/javascript">
+    // $$$ hack to workaround sizing bug when starting in two-up mode
+    $(document).ready(function() {
+        $(window).trigger('resize');
+    });
+</script>
+  <?
+    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;
+  }
+  
+}
+  ?>
diff --git a/GnuBookIA/index.php b/GnuBookIA/index.php
deleted file mode 100644 (file)
index 8c139dd..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-<?
-/*
-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/>.
-*/
-
-$id = $_REQUEST['id'];
-
-// 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.5";
-
-if ("" == $id) {
-    echo "No identifier specified!";
-    die(-1);
-}
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-<head>
-    <title>bookreader demo</title>
-<!-- $$$ we should have IE6 support RSN and move browser support detection inside GnuBook proper -->    
-<!--[if lte IE 6]>
-    <meta http-equiv="refresh" content="2; URL=browserunsupported.php?id=<? echo($id); ?>">
-<![endif]-->
-    <link rel="stylesheet" type="text/css" href="/GnuBook/GnuBook.css?v=<? echo($version); ?>">    
-    <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?v=<? echo($version); ?>"></script>
-    <script type="text/javascript" src="/GnuBook/jquery.easing.1.3.js"></script>
-</head>
-<body style="background-color: #FFFFFF;">
-
-<div id="GnuBook" style="left:10px; right:200px; top:10px; bottom:2em;">x</div>
-
-<script type="text/javascript">
-  // Set some config variables -- $$$ NB: Config object format has not been finalized
-  var gbConfig = {};
-  gbConfig.mode = 2;
-</script>
-<script type="text/javascript" src="/GnuBook/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());">
-        <p style="display: inline">
-            <input id="GnuBookSearchBox" type="text" size="20" value="search..." onfocus="if('search...'==this.value)this.value='';" /><input type="submit" value="go" />
-        </p>
-    </form>
-    <div id="GnuBookSearchResults">
-        Search results
-    </div>
-</div>
-
-
-<div id="GBfooter">
-    <div class="GBlogotype">
-        <a href="http://archive.org/" class="GBblack">Internet Archive</a>
-    </div>
-    <div class="GBnavlinks">
-        <a class="GBblack" href="http://openlibrary.org/dev/docs/bookreader">About the Bookreader</a> |
-        <a class="GBblack" href="https://bugs.launchpad.net/gnubook/+filebug-advanced">Report Errors</a> |
-        <a class="GBblack" href="http://www.archive.org/details/texts">Texts Collection</a> |
-        <a class="GBblack" href="http://www.archive.org/about/contact.php">Contact Us</a>
-    </div>
-</div>
-
-<script type="text/javascript">
-    // $$$ hack to workaround sizing bug when starting in two-up mode
-    $(document).ready(function() {
-        $(window).trigger('resize');
-    });
-</script>
-
-</body>
-</html>
diff --git a/GnuBookIA/www/GnuBookEmbed.php b/GnuBookIA/www/GnuBookEmbed.php
new file mode 100644 (file)
index 0000000..f9055a8
--- /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/>.
+*/
+
+$id = $_REQUEST['id'];
+
+if ("" == $id) {
+    echo "No identifier specified!";
+    die(-1);
+}
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+    <title>bookreader demo</title>
+    <link rel="stylesheet" type="text/css" href="/GnuBook/GnuBook.css">
+    <!-- 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>
+</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
+  var gbConfig = {};
+  gbConfig["mode"] = 1;
+</script>
+
+<script type="text/javascript" src="/GnuBook/GnuBookJSLocate.php?id=<?echo $id;?>"></script>
+<script type="text/javascript">
+  gb.zoom1up(-1);
+</script>
+</body>
+</html>
diff --git a/GnuBookIA/www/browserunsupported.php b/GnuBookIA/www/browserunsupported.php
new file mode 100644 (file)
index 0000000..98732a6
--- /dev/null
@@ -0,0 +1,107 @@
+<?
+/*
+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/>.
+*/
+
+
+$id = $_REQUEST['id'];
+
+// Sanitize since we put this value in the page
+$id = urlencode($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); ?>">
+    <link rel="stylesheet" href="http://www.archive.org/stylesheets/archive.css?v=1.99" type="text/css">
+</head>
+<body>
+
+<table style="background-color:white " cellspacing="0" width="100%" border="0" cellpadding="0">
+  <tbody>
+    <tr> 
+      <td style="width:100px; height:72px; vertical-align:top; background-color:#000000;">
+
+        <a href="http://www.archive.org/"><img style="border:0;" alt="(logo)" src="http://www.archive.org/images/logo.jpg" width="84" height="70"/></a>
+      </td>
+      <td valign="bottom" style="background-image:url(http://www.archive.org/images/blendbar.jpg);">
+        <table width="100%" border="0" cellpadding="5">
+          <tr> 
+            <td class="level1Header">
+              <div class="tab"><a href="http://www.archive.org/web/web.php">Web</a></div><div class="tab"><a href="http://www.archive.org/details/movies">Moving Images</a></div><div class="tab"><a href="http://www.archive.org/details/texts">Texts</a></div><div class="tab"><a href="http://www.archive.org/details/audio">Audio</a></div><div class="tab"><a href="http://www.archive.org/details/software">Software</a></div><div class="tab"><a href="http://www.archive.org/details/education">Education</a></div><div class="tab"><a href="http://www.archive.org/account/login.changepw.php">Patron Info</a></div><div class="tab"><a href="http://www.archive.org/about/about.php">About IA</a></div>            </td>
+
+          </tr>
+                    
+        </table>
+      </td>
+      <td style="width:80px; height:72px; vertical-align:top; text-align: right">
+        <a href="http://www.archive.org/about/about.php"><img alt="(navigation image)" src="http://www.archive.org/images/main-header.jpg" style="margin:0; border:0; vertical-align:top;" /></a>      </td>
+    </tr>
+  </tbody>
+</table>
+
+<!--BEGIN HEADER 2-->
+<table width="100%" class="level2Header">
+  <tbody>
+    <tr>
+      <td align="left" valign="top" class="level2HeaderLeft">
+        <a class="level2Header" href="http://www.archive.org/">Home</a>
+      </td>
+      <td style="width:100%;" class="level2Header">
+        <a href="http://www.archive.org/donate/index.php">Donate</a> | 
+
+<a href="http://www.archive.org/iathreads/forums.php">Forums</a> | 
+<a href="http://www.archive.org/about/faqs.php">FAQs</a> | 
+<a href="http://www.archive.org/contribute.php">Contributions</a> | 
+<a href="http://www.archive.org/about/terms.php">Terms, Privacy, &amp; Copyright</a> | 
+<a href="http://www.archive.org/about/contact.php">Contact</a> | 
+<a href="http://www.archive.org/about/jobs.php">Jobs</a> | 
+
+<a href="http://www.archive.org/about/bios.php">Bios</a>
+      </td>
+    </tr>
+  </tbody>
+</table>
+
+
+<div class="box">
+<p>
+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>,
+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>.
+</p>
+
+<p>
+You will be automatically redirected to the older viewer in 10 seconds.
+</p>
+
+</div>
+
+<p id="iafoot">
+  <a href="http://www.archive.org/about/terms.php">Terms of Use (10 Mar 2001)</a>
+
+</p>
+
+</body>
+</html>