Gain Limb - Back to life
 
 

 

   
  Search  
 

 

 
 
Contact the administrator of this site."; $err_index = "The index file could not be opened.
Check the path and permissions and try again."; $index_complete = "Your site has been indexed."; $index_cleared = "Your site index has been cleared.
No search results will be found until you re-index your site."; $no_files = "No files in the specified directory were available for indexing."; $no_dir = "The directory you specified cannot be found."; $err_index_empty = "The index file was found, but it contained no data."; // Uncomment this line to debug the script. // DEFINE("DEBUG", true); // Sets the version. $version = "1.7.7d"; // Sets start time. $timeparts = explode(" ",microtime()); $starttime = $timeparts[1].substr($timeparts[0],1); if (isset($_POST['query'])) s_control($_POST['query']); elseif (isset($_GET['index'])) i_control(); else s_print_search_form(""); c_print_footer(); function s_control($q) { $orig = $q; $result_arr = s_search($q); $result_count = sizeof($result_arr); if ($result_count < 1) { echo "

$GLOBALS[err_no_results]

"; s_print_search_form($q); } else { echo "
Search Results
Results 1 - $result_count for \"$orig\"
    "; foreach ($result_arr as $result) s_print_title_desc($result); echo "
"; s_print_search_form($orig); } } function s_search($query) { // Searches for query in the index file. // Multiple word search originally contributed by Matthew Furister $query = trim(strtolower(c_strip_chars($query))); $search_data = @file($GLOBALS[index_file]) or die("

$GLOBALS[err_no_search_db]

"); $pages_found = " "; foreach ($search_data as $search_page) { $page_arr = explode("|", $search_page); $found_count = 0; $qry_array = split('[, ]+',trim(strtolower($query))); foreach ($qry_array as $qry) { if (in_array($qry, $page_arr)) { ++$found_count; $pages_found .= $page_arr[0] . " "; } } if ($found_count == count($qry_array)) $result_arr[] = $page_arr[0]; } return $result_arr; } function s_print_title_desc($file_n) { $file = @file($file_n); if ($file) { $line_complete = implode('', $file); eregi("(.*)", $line_complete, $out); $title = trim($out[1]); if(isset($title)&&strlen($title)>0) $line_complete = str_replace($title, "", $line_complete); $line_complete = strip_tags($line_complete); $line_complete = trim($line_complete); $line_complete = trim(substr($line_complete, 0, 400)); echo "
  • "; if (isset($title)&&strlen($title)>0) echo "$title- $file_n"; else echo "$file_n"; echo "
    $line_complete...\n
     "; } else { echo "
  • $file_n
    ..."; } } function s_print_search_form($query) { // Function to print the search form. ?>

    You have selected to index your site.

    You can index your site using meta tag \"keywords\" or you can perform a \"full\" index.
    Which action do you wish to perform?

    "; } else { if (is_dir($GLOBALS[file_root])) { $file_array = i_get_files($GLOBALS[file_root]); $file_array = i_strip_extentions($file_array); $file_array = i_strip_files($file_array); if(is_array($file_array)) { set_time_limit(0); $fd = @fopen($GLOBALS[index_file], "w") or die("

    $GLOBALS[err_index]

    "); foreach ($file_array as $file) { if (($_POST[s] == "submit_full") || (substr($file, -3) == "txt")) $line = i_full_index_file($file); elseif ($_POST[s] == "submit_meta")$line = i_meta_index_file($file); if (substr_count($line, "|") > 1) fputs($fd, "$line\n"); } fclose($fd); echo "

    $GLOBALS[index_complete]

    "; } else { echo "

    $GLOBALS[no_files]

    "; } } else { echo "

    $GLOBALS[no_dir]

    "; } } } function i_full_index_file($file_name) { // Retrieves a list of keywords from a file. global $http_root, $file_root; $file_contents = @file($file_name); if ($file_contents) { $URL = str_replace($file_root, $http_root , $file_name); $keywords = "$URL|"; $file_contents = implode(" ", $file_contents); $file_contents = strip_tags($file_contents); $file_contents = strtolower($file_contents); $file_contents = str_replace("\n", "", $file_contents); $file_contents = c_strip_chars($file_contents); $file_contents = str_replace(",", "", $file_contents); $file_contents = explode(" ", $file_contents); foreach($file_contents as $word) { $word = trim($word); if ($word != "") { $keywords .= "$word|"; } } } $complete = str_replace("|||", "|", $keywords); $complete = str_replace("||", "|", $complete); $complete = i_strip_words($complete); return $complete; } function i_meta_index_file($file) { // Indexes a page by it's meta tags. global $index_file, $http_root, $file_root; $URL = str_replace($file_root, $http_root , $file); $mt = @get_meta_tags($file); $line = $mt[keywords]; if ($line) { $line = explode(",", $line); foreach ($line as $word) { $word = trim($word); if ($word != "") { $keywords .= "$word|"; } } $keyword = str_replace(",", "", $keywords); $keywords = c_strip_chars($keywords); $keywords = i_strip_words($keywords); $keywords = "$URL|$keywords"; return $keywords; } else { return "$URL|"; } } function i_get_files($dirname) { // Navigates through the directories recurrsively and retrieves a listing in an array. // File permission bit by Abhay Jain if($dirname[strlen($dirname)-1] != "/") $dirname.="/"; static $result_array = array(); $mode = fileperms($dirname); if(($mode & 0x4000) == 0x4000 && ($mode & 0x00004) == 0x00004) { chdir($dirname); $handle = @opendir($dirname); } if(isset($handle)) { while ($file = readdir($handle)) { if($file=='.'||$file=='..') continue; if(is_dir($dirname.$file)) i_get_files($dirname.$file.'/'); else $result_array[] = $dirname.$file; } closedir($handle); } return $result_array; } function i_strip_extentions($array) { // Runs through the extention array and // returns all files with the selected extentions. global $include_extentions; if(is_array($array)) { foreach ($include_extentions as $ext) { $str_len = strlen($ext); foreach ($array as $file) { if (substr($file, -$str_len) == $ext) $result_array[] = $file; } } return $result_array; } else return $array; } function i_strip_files($array) { // Reads the exclude file removed unwanted file form the array. // Filtering and regex added by: // Timo Haberkern 10/10/01 // Bug: 18/10: Array check. // Bug: 21/10/01: Type error, eregi returns int not bool. Causes probs on some systems. global $file_root, $exclude_files; if(is_array($array)) { $exclude = @file($exclude_files); if ($exclude) { // Create the filter lists foreach($exclude as $exc_file) { $exc_file = trim($exc_file); // Is it a filter? if ($exc_file[0] == "/") { $file[] = $exc_file; } else { $filter[] = $exc_file; } } // Do the filtering foreach ($array as $act_file) { $act_file = str_replace($file_root, "", $act_file); $bMatchedFilter = false; $bFoundInExcludingList = false; // Test the filters first if(is_array($filter)) { foreach ($filter as $curFilter) { if (eregi($curFilter, $act_file)) { $bMatchedFilter = true; break; } } } // Test for excluding if ($bMatchedFilter == false) { // Test only if the file list is not empty if (sizeof($file) != 0) { if (in_array($act_file, $file)) { $bFoundInExcludingList = true; break; } } } if (!$bFoundInExcludingList AND !$bMatchedFilter) $result_array[] = "$file_root$act_file"; } return $result_array; } else return $array; } else return $array; } function i_strip_words($line) { $file = @file($GLOBALS['exclude_words']); if ($file) { foreach ($file as $word) { $word = trim($word); $word = "|$word|"; $line = str_replace("$word", "|", $line); } } return $line; } function i_clear_index() { // Checks for a confirmation and then clears the index file. global $username, $password; if ($_POST['s'] == "submit") { $fd = @fopen($GLOBALS[index_file], "w") or die("

    $GLOBALS[err_index]

    "); fclose($fd); echo "

    $GLOBALS[index_cleared]

    "; } else { echo "
    You have selected to clear your site index.
    No search results will be found until you re-index your site.
    Are you sure?
    "; } } function i_view_index() { // Displays the index file in a table. if(file_exists($GLOBALS[index_file])) { $file = @file($GLOBALS[index_file]); if(is_array($file)) { echo "

    Your index file:

    "; foreach ($file as $key => $line) { $exp_line = explode("|", $line); $key = $key + 1; echo " \n"; foreach ($exp_line as $key => $word) { if ($key == 0) { echo " \n "; } else { echo ""; } } echo " \n\n"; } echo "
    # URL Keywords
    $key$word$word
    "; } else { echo "

    $GLOBALS[err_index_empty]

    "; } } else { echo "

    $GLOBALS[err_index]

    "; } } function i_print_options() { // Prints the indexer options. global $username, $password; echo "

    Indexer Options:
    Create Site Index
    View Site Index
    Clear Site Index
    "; } function i_print_logon($msg) { // Prints the indexer logon. echo "
    $msg

    Logon:
    Username:
    Password:
    "; } function c_strip_chars($line) { // Strips various characters from $line. // $line = str_replace(".", " ", $line); $line = str_replace("\"", " ", $line); $line = str_replace("'", "", $line); $line = str_replace("+", " ", $line); $line = str_replace("-", " ", $line); $line = str_replace("*", " ", $line); $line = str_replace("/", " ", $line); $line = str_replace("!", " ", $line); $line = str_replace("%", " ", $line); $line = str_replace(">", " ", $line); $line = str_replace("<", " ", $line); $line = str_replace("^", " ", $line); $line = str_replace("(", " ", $line); $line = str_replace(")", " ", $line); $line = str_replace("[", " ", $line); $line = str_replace("]", " ", $line); $line = str_replace("{", " ", $line); $line = str_replace("}", " ", $line); $line = str_replace("\\", " ", $line); $line = str_replace("=", " ", $line); $line = str_replace("$", " ", $line); $line = str_replace("#", " ", $line); $line = str_replace("?", " ", $line); $line = str_replace("~", " ", $line); $line = str_replace(":", " ", $line); $line = str_replace("_", " ", $line); $line = str_replace(" ", " ", $line); $line = str_replace("&", " ", $line); $line = str_replace("©", " ", $line); $line = str_replace(" ", " ", $line); $line = str_replace(""", " ", $line); $line = str_replace("ü", "ü", $line); $line = str_replace("Ü", "Ü", $line); $line = str_replace("&", " ", $line); $line = str_replace(";", " ", $line); $line = str_replace("\n", " ", $line); return $line; } function c_print_footer() { // Prints the footer of the page. echo " "; } // Display time taken. if(isset($query)) { if($show_time_search) { $timeparts = explode(" ",microtime()); $total_time = ($timeparts[1].substr($timeparts[0],1)) - $starttime; echo "
    In: ".substr($total_time,0,4)." secs.
    "; } } elseif (substr($QUERY_STRING,0,5) == "index") { if($show_time_index) { $timeparts = explode(" ",microtime()); $total_time = ($timeparts[1].substr($timeparts[0],1)) - $starttime; echo "
    In: ".substr($total_time,0,4)." secs.
    "; } } if(DEFINED("DEBUG")) { echo "\n\n
    \n

    Debug:

    Variables

    VariableValue
    HTTP_HOST: $HTTP_HOST
    SCRIPT_FILENAME: $SCRIPT_FILENAME
    SCRIPT_NAME: $SCRIPT_NAME
    PHP_SELF: $PHP_SELF
    file_root: $file_root
    http_root: $http_root
    index_file: $index_file
    exclude_words: $exclude_words
    exclude_files: $exclude_files

    Extra Checks

    Red = Error, see solution at end of line.
    Green = No problem.


    "; if(is_dir($file_root)) echo "$file_root is a directory."; else echo "$file_root is not a directory. Solution: Check \$file_root variable."; if(file_exists($index_file)) { echo "
    $index_file exists."; if(is_readable($index_file)) echo "
  • It is readable."; else echo "
  • It is not readable. Solution: Check that $index_file is readable by the webserver."; if(is_writable($index_file)) echo "
  • It is writable."; else echo "
  • It is not writable. Solution: Check that $index_file is writable by the webserver."; } else echo "
    $index_file does not exist. Solution: Check that \$index_file variable."; if(file_exists($exclude_words)) { echo "
    $$exclude_words exists."; if(is_readable($exclude_words)) echo "
  • It is readable."; else echo "
  • It is not readable. Solution: Check that $exclude_words is readable by the webserver."; } else echo "
    $exclude_words does not exist. Solution: Check that \$exclude_words variable"; if(file_exists($exclude_files)) { echo "
    $exclude_files exists."; if(is_readable($exclude_files)) echo "
  • It is readable."; else echo "
  • It is not readable. Solution: Check that $exclude_files is readable by the webserver."; } else echo "
    $exclude_files does not exist. Solution: Check \$exclude_files variable."; echo "
  • "; } ?>
  •  
    Contact  |  Search  |  Disclaimer