<?php
// define server variabl
// keep server as localhost unless your web server
// doesn't allow this as this provides optimal retrieval time
$server = "localhost"; // server that Alkaline runs from
$port = "9999"; // port that Alkaline runs from
// the following two must be identical on your web server and Alkaline server
// ie www.foo.com/search/index.php must correspond to
// www.foo.com:9999/search/index.php
$dirname = "search/"; // the directory from which you run this script from (note the '/')
$docname = "index.php"; // name of this script.
// define Alkaline variables
$boolean = "on"; // allow AND OR NOT boolean terms
$allrecords = "off"; // ensures * cannot be used to return all records
// main section
$rawsearch = urldecode($search);
if (strlen($rawsearch) < 1)
{
$rawsearch = urldecode(substr(stristr($QUERY_STRING, "search="), 7));
}
$runfrom = $dirname.$docname;
if (trim($search) == "" || ($allrecords = "off" && trim($search)== "*" ))
unset($search); // kills the $search variable with undesirable searches
if (isset($search))
{
if ($boolean = "on")
{
$search = str_replace("and ", urlencode("+"), $search);
$search = str_replace("or ", " ", $search);
$search=str_replace("not ", urlencode("-"), $search);
}
$fp = fopen("http://$server:$port/$runfrom?search=$search", "r");
}
elseif (isset($QUERY_STRING))
{
$fp = fopen("http://$server:$port/$runfrom?$QUERY_STRING","r");
}
if($fp)
{
while (!feof ($fp))
{
$buffer .= fgets($fp, 4096);
}
$results = get_tag($buffer, "results");
$next = get_tag($buffer, "next");
$hits = get_tag($buffer, "hits");
}
// define html variables
// any head content
$headcontent = "<title>searching for $search with Alkaline</title>";
// any body header content
$body_top = "<hr>";
// any body footer content
$body_bottom = "<hr>";
// page text, shown if nothing has been searched
$alternate_text = "Welcome to Alkaline";
// search form
$topform=\"
<form action=\"$docname\" method=\"post\">
<input name=\"search\" type=\"text\" value=\"$rawsearch\">
<input type=\"submit\" value=\"Search!\">
</form>";
// write body
function get_tag($source, $tagname)
{
ereg("<$tagname>(.*)</$tagname>", $source, $tmp);
return $tmp[1];
}
echo "<html>
<head>$headcontent</head>
<body>
$hits
$topform
$body_top";
if (isset($results))
{
echo $results;
echo $next;
}
else
{
echo $alternate_text;
}
echo " $body_bottom
</body>
</html>";
?>
|