100) { return; } $s_dir=""; for ($c=0; $c<=$dir_depth; $c++) { $s_dir .= $cur_path[$c]; } $dhandle=opendir("$s_dir"); while ($file = readdir($dhandle)) { if (($file!=".") && ($file!="..")) { if (is_file($s_dir.$file)) { $file_ext = substr($file, strlen($file)-4, 4); if ($file_ext == "html" || $file_ext == ".htm" || $file_ext == ".txt" || $file_ext == ".pdf") { search_file($s_dir.$file); } } elseif (is_dir($file)) { $cur_path[++$dir_depth] = ($file."/"); search_dir(); $dir_depth--; } } } } function strip_tag_script($html) { $pos1 = false; $pos2 = false; do { if ($pos1 !== false && $pos2 !== false) { $first = NULL; $second = NULL; if ($pos1 > 0) $first = substr($html, 0, $pos1); if ($pos2 < strlen($html) - 1) $second = substr($html, $pos2); $html = $first . $second; } preg_match("/]*>/i", $html, $matches); $str1 =& $matches[0]; preg_match("/<\/script>/i", $html, $matches); $str2 =& $matches[0]; $pos1 = strpos($html, $str1); $pos2 = strpos($html, $str2); if ($pos2 !== false) $pos2 += strlen($str2); } while ($pos1 !== false && $pos2 !== false); return $html; } function search_file ($file) { global $searchterm, $results, $r_text,$matches; $s_dir=""; for ($c=0; $c<=$dir_depth; $c++) { $s_dir .= $cur_path[$c]; } $f_size = filesize($file); $f_handle = fopen($file, "r"); $f_data = fread($f_handle, $f_size); if ($text = strstr($f_data, 'SSIGNORE')) { return; } $f_dlc = strtolower($f_data); $t_text = ""; $in_tag = 0; $text = strip_tag_script($f_dlc); $text = str_replace (">", "", $text); $text = strip_tags($text); if ($text = strstr($text, $searchterm)) { $results[$matches] = str_replace('./', '', $file); $text = str_replace ($searchterm, "".$searchterm. "", $text); $r_text [$matches] = "...". $text. "..."; $pos = strrpos($text, '[$php'); if ($pos === false) $matches++; } fclose($f_handle); } $searchterm=strtolower($searchterm); if (strcmp($searchterm, "")!=0) { search_dir(); } $file = "$searchpage"; if (file_exists($file)) { $file = "$searchpage"; $f = fopen ($file, "r"); $tpl = fread ($f,filesize ($file)); fclose ($f); $msgs = substr($tpl, strpos($tpl,'') + 25, strpos($tpl, '') - (strpos($tpl,'') + 25)); $pre = substr($tpl, 0, strpos($tpl,'')); $post = substr($tpl, strpos($tpl, '')+23); $tpl = $pre.'[$PHP_SITESEARCH]'.$post; $out = ''; for ($a=0; $a<$matches; $a++) { $out = $out.$msgs; $out = str_replace('[$PHP_TARGET]', ''.$results[$a].'', $out); $out = str_replace('[$PHP_TEXT]', $r_text[$a], $out); } $tpl = str_replace('[$PHP_SITESEARCH]', $out, $tpl); $tpl = str_replace('[$PHP_SEARCHTERM]', $searchterm, $tpl); $tpl = str_replace('[$PHP_COUNTER]', $matches, $tpl); echo "$tpl"; } ?>