Main Page   File List   File Members  

search.php3

Go to the documentation of this file.
00001 <?PHP /* Timing */ $intTimeBegan = time(); /*Safety Measure*/ unset($debug); /*Include User Functions*/ require("search.inc");?><!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD  HTML  4.0 Transitional//EN"  "http://www.w3.org/DTD/HTML4-loose.dtd">
00002 <HTML lang="en-us">
00003 <?PHP
00004 /* This script was designed using HomeSite 4.0 on Windows NT.
00005 ** Whatever you use to edit this script, I suggest it 
00006 ** be something with full PHP3 color-syntax highlighting.
00007 */
00008 ?>
00009 <HEAD>
00010         <TITLE>
00011                 Simple Web Search for &quot;<?PHP print $words;?>&quot;
00012         </TITLE>
00013         <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
00014         <META name="robots" content="index,nofollow">
00015         <META name="description" content="Simple Web Search!">
00016         <LINK href="<?php print $strStyleName ?>" rel="stylesheet" type="text/css" title="Simple Search Style">
00017 </HEAD>
00018 <BODY>
00019 <h2>Simple Web Search</h2>
00020 <div class="cool" style="text-align: center;">
00021         <form method="POST" action="<?php print $strSelf ?>">
00022                 <table style="Width: 40%;" class="panel">
00023                         <tr>
00024                                 <td style="Vertical-Align: Middle; Text-Align: Center;" colspan="2">Search for
00025                                         <input type="hidden" name="do" value="now">
00026                                         <input type="text" size="25" name="words" value="<?PHP print $words;?>">
00027                                         <?PHP 
00028 if (isset ($strSearchSiteKey)) {
00029    $strSearchSiteIndex = $arySearchSiteIndices[chop($strSearchSiteKey)];
00030 } else {
00031    reset ($arySearchSiteIndices);
00032    list( $dummy, $strSearchSiteIndex ) = each( $arySearchSiteIndices );
00033       if (count($arySearchSiteIndices) == 1) {
00034       $strSearchSiteKey = $dummy;
00035                 }
00036 }
00037 
00038 // Print out available Site Indices to select field.
00039 if (count($arySearchSiteIndices) > 1) {
00040    echo "<select name=\"strSearchSiteKey\">\n";
00041    reset ($arySearchSiteIndices);
00042    while (list($key,$val) = each( $arySearchSiteIndices ) ) {
00043       if ($strSearchSiteKey == $key) { echo "\t<option selected>".stripslashes($key)."\n"; }
00044       else {echo "\t<option>".stripslashes($key)."\n"; }
00045    }
00046    echo "</select>\n";
00047 };
00048 
00049 // Print out available Max Hits to select field.
00050 if (count($aryMaxHits) > 1) {
00051    echo "<select name=\"intMaxHits\">\n";
00052    $m = 0;
00053    while($aryMaxHits[$m]) {
00054       if ($intMaxHits == $aryMaxHits[$m]) { echo "\t<option selected>$intMaxHits\n"; }
00055       else { echo "\t<option>$aryMaxHits[$m]\n"; }
00056       $m++ ;
00057    };
00058    echo "</select>\n";
00059 } else { 
00060    $intMaxHits = $aryMaxHits[0];
00061 };
00062 
00063 // Make sure MaxHits is larger than returned results.
00064 $intMaxHitsOffset = $intPageOffset + $intMaxHits;
00065 
00066 ?>
00067                                         <input type="submit" value="Find It!">
00068                                 </td>
00069                         </tr>
00070                         <tr>
00071                                 <td colspan="2">
00072                                         <div style="Font-Size: 10pt; Font-Family: Verdana, Arial, Serif;">This <a
00073 href="http://sunsite.berkeley.edu/SWISH-E/">SWISH-E
00074 2.0</a>  based
00075         search will honor boolean (AND OR NOT), parentheses(), and wild-card*
00076         stemming queries. Examples: <em>john and doe or jane</em>, <em>john and (doe or
00077         jane)</em>, <em>not (john or jane) and doe</em>, <em>j* and doe</em>
00078                                         </div>
00079                                 </td>
00080                         </tr>
00081                         <?PHP
00082 // Determine if we want to use [t] limiting code.
00083 if ($intUseLimits) {
00084 ?>
00085                         <tr>
00086                                 <td>Limit Search:
00087                                 </td>
00088                                 <td style="Vertical-Align: Middle; Text-Align: Center;">
00089                                         <?PHP
00090 
00091         // Lump all of the [t] delimiters together in preparation for the commandline.
00092         // $strLimit is, also, used to determine if a box is checked.
00093         If (is_array($aryLimits)){$strLimit = implode($aryLimits, "");};
00094 
00095         // Print out Search delimiters to checkbox fields.
00096         reset ($arySearchDelimiter);
00097         while (list($key,$val) = each($arySearchDelimiter)) {
00098                 echo "\t\t<INPUT type=\"checkbox\" name=\"aryLimits[]\" value=\"$val\"";
00099                 if (strstr($strLimit,$val)){
00100                         print " checked"; }
00101                 echo ">$key\n";
00102         };
00103 
00104         // Setup Limit code
00105         if ($strLimit != ""){
00106                 $strLimitLine = "-t $strLimit";
00107         } else {
00108                 $strLimitLine = "";
00109         };
00110         print "</TD></TR>\n";
00111 }; // EndIf intUseLimits
00112 
00113 ?>
00114                 </table>
00115         </form>
00116 </div>
00117 <?PHP 
00118 // Why waste time and resources if they haven't performed a search?
00119 If($do != "now") {fncPrintFooter();}; 
00120 ?><h2 class="indexed">Searching for
00121 <q lang="UTF-7">
00122 <?PHP print "$words";?></q>:</h2>
00123 <?PHP
00124 /* Added DN: Adds last updated time of index November 17, 1999 */
00125 
00126 print "<p class=\"updated\">Index of <em>" . ereg_replace("_", " ", stripslashes($strSearchSiteKey)) ."</em> last updated on " . date("D, M jS, Y H:i:s", filemtime($strSearchSiteIndex)) . "</p>";
00127 
00128 /* Bug Fix JB: Parenthesis July 13, 1999
00129 **
00130 ** $words = str_replace('\(','(',str_replace('\)',')',str_replace('\*','*',escapeshellcmd($words))));
00131 **
00132 **
00133 ** Bug Fix JB: Fixes parenthesis fix  July 14, 1999
00134 ** $words = '"'.str_replace('\(','(',str_replace('\)',')',str_replace('\*','*',escapeshellcmd($words).' '))).'"';
00135 **
00136 */
00137 
00138 $words = '"'.chop(str_replace('\(','(',str_replace('\)',')',str_replace('\*','*',escapeshellcmd($words).' ')))).'"';
00139 
00140 
00141 $strCommandLine = $strSearchEngine.escapeshellcmd(" -m $intMaxHitsOffset -f $strSearchSiteIndex $strLimitLine -w ").$words;
00142 
00143 fncDebug("CommandLine", $strCommandLine, 1);
00144 
00145 // Must find a better error message, possibly fix the HTML as well.
00146 Exec($strCommandLine, $aryResults, $return) or fncPrintFooter("<H3>Error performing search!</H3>\n<DL>\n\t<DT>Administrator\n\t\t<DD>Please check System-Specific variables defined at the beginning of the script.</DL>");
00147         // Jump out to HTML and set the table...
00148 
00149 /************************************/
00150 $i=0;
00151 while(substr($aryResults[$i],0,1) == "#" || substr($aryResults[$i],0,3) == "err" && $i < 50):
00152         $strResultsClean = $aryResults[$i];
00153         // Correct for offset caused by SWISH-E Comments.
00154         $intPageOffsetCorrect++;
00155         //Explodes the Comment into an array
00156         $aryComment = Explode(": ", strstr($strResultsClean, " "));
00157                 fncDebug($aryComment[0], $aryComment[1], 2);
00158         
00159             // Print number of results
00160                 If (trim($aryComment[0]) == "Number of hits") {
00161                         $intNumHits = trim($aryComment[1]);
00162                     if ($intNumHits > 0) {
00163                         if ($intNumHits >= $intMaxHits) {
00164 
00165                                 //Print 0 as 1
00166                                 If($intPageOffset == 0){$intPageOffsetOne = $intPageOffset + 1;}
00167                                 Else{$intPageOffsetOne = $intPageOffset;};
00168 
00169                                 // What is the result number of the last document
00170                                 If ($intNumHits > $intMaxHitsOffset){$intPageHitsThru = $intMaxHitsOffset;}
00171                                 Else {$intPageHitsThru = $intNumHits;};
00172 
00173                                 // At which results am I looking
00174                                 echo "Displaying $intPageOffsetOne through $intPageHitsThru of $intNumHits results.<BR>\n\n";
00175                                 print "<DL class=\"result\">\n";
00176                         } else {
00177                                 // If in the off chance it is a small result, under MaxHits.
00178                                 print "$intNumHits results found.<BR>\n\n";
00179                                 print "<DL class=\"result\">\n";
00180                         };
00181                 };
00182         };
00183             // Soundex Yes or ...
00184                 If (trim($aryComment[0]) == "Soundex Applied") {
00185                         if (trim($aryComment[1]) == "1"){
00186                                 print"<dl><dt>Note:<dd>Resulting matches are sound-alikes according to <a href=\"http://www.nara.gov/genealogy/coding.html\">US Census SoundEx codes</a>.</dl>";
00187                         };
00188                 };
00189                 // Stemming yes or ...
00190                 If (trim($aryComment[0]) == "Stemming Applied") {
00191                         if (trim($aryComment[1]) == "1"){
00192                                 print"<dl><dt>Note:<dd>Resulting matches are based on stems of the words in your query. A search for 'testing' will return matches for 'testing', 'tested', 'test', etc.</dl>";
00193                         };
00194                 };
00195         // Set the strBaseURL if it isn't in the config already.
00196         If (trim($aryComment[0]) == "Pointer"  && !isset($strBaseURL)){
00197                 $strBaseURL = trim($aryComment[1]);
00198                 fncDebug("URL Pointer",$strBaseURL, 3);
00199         };
00200         fncDebug("strResultsClean", $strResultsClean, 3);
00201         
00202         //      Crappy No Results "err:" handling.  Will be fixed someday, maybe...
00203         if(substr($strResultsClean,0,3) == "err"){
00204                 print "<H3>No match for your search!</H3>\n";
00205                 print "<P>\n\t<STRONG>User:</STRONG> Please try adjusting the search criteria and/or changing the words.\n</P>";
00206         };
00207         
00208         $i++;
00209 endwhile;
00210 /******************************************/    
00211                         
00212 $i = $intPageOffset + $intPageOffsetCorrect;
00213 while(substr($aryResults[$i],0,1) != "#" && substr($aryResults[$i],0,3) != "err" && $aryResults[$i] != "" && $aryResults[$i] != "." && $i <= $intPageOffset + $intPageOffsetCorrect + $intMaxHits):
00214 
00215         $strResultsClean = $aryResults[$i];
00216 //      if (substr($strResultsClean,0,1) != "#" && substr($strResultsClean,0,3) != "err"){
00217 //      if (!ereg("^#.*",$strResultsClean) && !ereg("^e.*",$strResultsClean) && $i >= $intPageOffset){
00218 
00219                 //$strResultsClean String Format:
00220                 // <RANK> <URL> "<TITLE>" <SIZE>
00221         
00222                 // Array exploded on Double-Quote ("):
00223                 // [RANK URL :0][TITLE:1][ SIZE:2] 
00224                 /* Take note of evil whitespace in the array values,
00225                 ** which must be trimmed later.*/
00226                 $aryResultLine = explode("\"", $strResultsClean);
00227                 
00228                 $j=0;
00229                 while($aryResultLine[$j]):
00230                         // Find the position, from begin, of the first space, then:
00231                         // Rank is everything from begin to the first space trimming whitespace.
00232                         $intResultRank = trim(substr($aryResultLine[0], 0, strpos($aryResultLine[0]," ")));
00233         
00234                         /* URL everything following first space trimming whitespace.
00235                         ** Assuming file is under the DOCUMENT_ROOT directory somewhere.
00236                         ** If not, the file may not be found via HTTP...  However, 
00237                         ** if the indexer is configured correctly this is a 
00238                         ** waste of time.  Too easy of a mistake to ignore, though. */
00239         //                      $strResultURL = trim(strstr($aryResultLine[0]," "));
00240 
00241                         $strResultURL = ereg_replace($strSiteRootDir, "", trim(strstr($aryResultLine[0]," ")));
00242 
00243 
00244                         // The rest is a piece of cake...
00245                         if(trim($aryResultLine[1])){
00246                                 $strResultTitle = trim($aryResultLine[1]);
00247                         }else {
00248                                 $strResultTitle = $strResultURL;
00249                         };
00250                         $intResultBytes = trim($aryResultLine[2]);
00251                         
00252                         // Attempt to grab data from each file
00253                         if (count($aryMetaList) > 0) {
00254                                 unset($aryMetaTags);
00255                                 $strCurrentFile = $strSiteRootDir.$strResultURL ;
00256                                 if (file_exists($strCurrentFile) && $intGetFileData > 0) {
00257                                         // Get the META tags from the file
00258                                         $aryMetaTags = get_meta_tags($strCurrentFile);
00259                                         // Get the modification date stored in the file system
00260                                         $strResultModDate = gmdate("\M\o\d\i\f\i\e\d \a\\t H:i:s, \o\\n M d, Y \G\M\T", filemtime($strCurrentFile));
00261                                         // $aryMetaTags = get_meta_tags("/www/share/apache/htdocs/test/test.html");
00262                                 }
00263                         }
00264                         /* This is broken until I find a means of juggling FileSystem:
00265                         ** versus HTTP resource names.  Field not necessary, slows things down, 
00266                         ** but impressive and useful nonetheless. */
00267                         $j++;
00268                 endwhile;
00269 
00270                 print "\t<DT><A href=\"$strBaseURL$strResultURL\">$strResultTitle</A>\n";
00271                 print "\t<DD>\n";
00272                 fncDebug("Current File", $strCurrentFile, 4);
00273                 reset ($aryMetaList);
00274                 $p = 0;
00275                 while($aryMetaList[$p]) {
00276                         list ($strMetaName, $strLineHeading) = explode("|",$aryMetaList[$p]);
00277                         if ($aryMetaTags["$strMetaName"]){print "\t\t$strLineHeading".$aryMetaTags["$strMetaName"]."<BR>\n";}
00278                         $p++;
00279                 };
00280                 print "\t\t<SPAN style=\"Font-Size: 75%; Font-Weight:900;\">Score: $intResultRank, Size: $intResultBytes Bytes, $strResultModDate</SPAN><P>\n";
00281         $i++;
00282 endwhile;
00283 
00284 If ($intNumHits > 0) {print "</DL>\n";}
00285 
00286 // Print out the Previous and Next buttons
00287 If ($intNumHits > $intMaxHits) {
00288         print "<TABLE>\n<TR>\n";
00289         If ($intMaxHits < $intMaxHitsOffset){
00290                 print "\t<TD>\n";
00291             $intPrevVal = $intMaxHitsOffset - (2 * $intMaxHits);
00292                 print "\t<FORM action=\"$strSelf\" method=\"POST\" name=\"frmPrev\">\n";
00293                 print "\t\t<INPUT type=\"HIDDEN\" name=\"do\" value=\"now\">\n";
00294 /*
00295 ** Bug Fix JB: Parenthesis July 13, 1999
00296 **              print "\t\t<INPUT type=\"HIDDEN\" name=\"words\" value=\"". stripslashes($words) ."\">\n";
00297 */
00298                 print "\t\t<INPUT type=\"HIDDEN\" name=\"words\" value=\"".stripslashes(str_replace('"','',$words)) ."\">\n";
00299                 print "\t\t<INPUT type=\"HIDDEN\" name=\"strSearchSiteKey\" value=\"" . stripslashes($strSearchSiteKey) . "\">\n";
00300                 print "\t\t<INPUT type=\"HIDDEN\" name=\"intMaxHits\" value=\"$intMaxHits\">\n";
00301                 print "\t\t<INPUT type=\"HIDDEN\" name=\"intPageOffset\" value=\"$intPrevVal\">\n";
00302                         // Print out Search delimiters to hidden fields.
00303                         reset ($arySearchDelimiter);
00304                         while (list($key,$val) = each($arySearchDelimiter)) {
00305                                 if (strstr($strLimit,$val)){print "\t\t<INPUT type=\"HIDDEN\" name=\"aryLimits[]\" value=\"$val\">\n";};
00306                         };
00307                 print "\t\t<INPUT type=\"SUBMIT\" name=\"prev$intMaxHits\" value=\"&lt;&lt; Previous $intMaxHits\">\n";
00308                 print "\t</FORM>\n";
00309                 print "\t</TD>\n";
00310         };
00311 
00312         If ($intNumHits > $intMaxHitsOffset){
00313             if ( ( $intNumHits - $intPageHitsThru ) < $intMaxHits ) {
00314                     $intNextVal = ( $intNumHits - $intPageHitsThru );
00315                 } else {
00316                     $intNextVal = $intMaxHits ;
00317                 }
00318                 print "\t<TD>\n";
00319                 print "\t<FORM action=\"$strSelf\" method=\"POST\" name=\"frmNext\">\n";
00320                 print "\t\t<INPUT type=\"HIDDEN\" name=\"do\" value=\"now\">\n";
00321 /* 
00322 ** Bug Fix JB: Parenthesis July 13, 1999
00323 **              print "\t\t<INPUT type=\"HIDDEN\" name=\"words\" value=\"". stripslashes($words) ."\">\n";
00324 */
00325                 print "\t\t<INPUT type=\"HIDDEN\" name=\"words\" value=\"".stripslashes(str_replace('"','',$words)) ."\">\n";
00326                 print "\t\t<INPUT type=\"HIDDEN\" name=\"strSearchSiteKey\" value=\"" . stripslashes($strSearchSiteKey) . "\">\n";
00327                 print "\t\t<INPUT type=\"HIDDEN\" name=\"intMaxHits\" value=\"$intMaxHits\">\n";
00328                 print "\t\t<INPUT type=\"HIDDEN\" name=\"intPageOffset\" value=\"$intMaxHitsOffset\">\n";
00329                         // Print out Search delimiters to hidden fields.
00330                         reset ($arySearchDelimiter);
00331                         while (list($key,$val) = each($arySearchDelimiter)) {
00332                                 if (strstr($strLimit,$val)){print "\t\t<INPUT type=\"HIDDEN\" name=\"aryLimits[]\" value=\"$val\">\n";};
00333                         };
00334                 print "\t\t<INPUT type=\"SUBMIT\" name=\"next$intNextVal\" value=\"Next $intNextVal &gt;&gt;\">\n";
00335                 print "\t</FORM>\n";
00336                 print "\t</TD>\n";
00337         };
00338         print "\t</TR>\n</TABLE>\n";
00339 };      
00340 //Print the footer and exit
00341 $intTimeComplete = time() - $intTimeBegan;
00342 If ($intTimeComplete < 1){$intTimeComplete = "less than 1 second";}
00343 Else {$intTimeComplete = $intTimeComplete." seconds";};
00344 fncPrintFooter("<P>Search completed in $intTimeComplete.");
00345 ?>

Generated at Sun Sep 17 14:33:41 2000 for SWS 1.0 by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000