. */ // 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 if (strpos($_SERVER["REQUEST_URI"], "/~testflip") === 0) { // Serving out of home dir $_SERVER['DOCUMENT_ROOT']='/home/testflip/petabox/www/sf'; require_once '/home/testflip/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 "
";
$tag_pre = '';
$tag_post = '';
}
else if ($format == "XML")
{
if (false === $callback) {
header('Content-type: text/xml');
} else {
header('application/x-javascript');
}
$tag_pre = '';
$tag_post = ' \n";
}
$time3 = microtime(true) - $time2;
echo $tag_pre . "Fetched document in $time1 ms.$tag_post \n";
echo $tag_pre . "Processed document in $time2 ms.$tag_post \n";
echo $tag_pre . "Printed document in $time3 ms.$tag_post \n";
echo "\n";
}
else if ($format == "XML")
{
$xml = "";
$xml .= ''."\n";
// Added to prevent Internet Explorer from adding default XML stylesheet,
// which messes up processing, Brad Neuberg, bkn3@columbia.edu
$xml .= ''."\n";//fixxx
$xml .= '
\n";
foreach ($pages as $index => $page)
{
echo "Page $page:
\n";
print_r($page);
echo "
\n";
}
}
function checkPrivs($filename) {
if (!is_readable($filename)) {
header('HTTP/1.1 403 Forbidden');
exit(0);
}
}
?>