<?PHP
# Copyright 2005 by Magnus Manske
# Licensed under GPL

$scriptname = "xlook.php" ;

if ( isset ( $_GET["source"] ) ) {
   print "<html><head></head><body><tt>" ;
   print str_replace ( "\t" , "&nbsp; &nbsp;" , str_replace ( "\n" , "<br/>" , htmlentities ( file_get_contents ( $scriptname ) ) ) ) ;
   print "</tt></body></html>" ;
} else {
   if ( isset ( $_POST["search"] ) ) $x = $_POST["search"] ;
   else if ( isset ( $_GET["search"] ) ) $x = $_GET["search"] ;
   else $x = "" ;
   
   $out = "
   <html><head></head><body>
   <div style='float:right'><a href='{$scriptname}?source=1'>View the source code of this script</a></div>
   <form method='post'>
   Search : <input type='text' name='search'/> <input type='submit' name='OK' value='OK'/>
   </form>
   " ;
   
   if ( $x != "" ) {
      $y = urlencode ( $x ) ;
      $wpg = "http://www.google.com/search?q={$y}+site%3Awikipedia.org&ie=utf-8&oe=utf-8" ;
      $commons = "http://www.google.com/search?q={$y}+site%3Acommons.wikimedia.org&ie=utf-8&oe=utf-8" ;
      $EB1911 = "http://www.google.com/search?q={$y}+site%3A1911encyclopedia.org&ie=utf-8&oe=utf-8" ;
      $EB2006 = "http://www.britannica.com/search?query={$y}&go_button.x=0&go_button.y=0&ct=" ;
      $pgb = "http://www.gutenberg.org/author/{$y}" ;
      $yahoo = "http://search.yahoo.com/search?p={$y}&sm=Yahoo%21+Search&fr=FP-tab-web-t&toggle=1&cop=&ei=UTF-8" ;
      
      $out .= "Search was for : <b>" . $x . "</b><br/>" ;
      $out .= "<table width='90%' height='80%' border=1><tr>" ;
      $out .= "<td>Wikipedia via Google<br/><iframe src='{$wpg}' width='100%' height='90%'></iframe></td>" ;
      $out .= "<td>Commons via Google<br/><iframe src='{$commons}' width='100%' height='90%'></iframe></td>" ;
      $out .= "</tr><tr>" ;
      $out .= "<td>EB1911 via Google<br/><iframe src='{$EB1911}' width='100%' height='90%'></iframe></td>" ;
      $out .= "<td>EB2006<br/><iframe src='{$EB2006}' width='100%' height='90%'></iframe></td>" ;
      $out .= "</tr><tr>" ;
      $out .= "<td>Project Gutenberg<br/><iframe src='{$pgb}' width='100%' height='90%'></iframe></td>" ;
      $out .= "<td>Yahoo<br/><iframe src='{$yahoo}' width='100%' height='90%'></iframe></td>" ;
      $out .= "</tr></table>" ;
   }
   
   $out .= "</body></html>" ;
   print $out ;
}

?>