楼上的,按你的方法搜了。
搜到这个文件,do_search.php
但我还是看不懂它是怎么样搜内容的,请高抬贵鼠指教,无限感尽!谢谢!
内容如下:
<?
/* K-Search
(C) Rinalds Uzkalns, 2004. All Rights Reserved
http://turn-k.net
Version: 1.01 (12.08.2004)
*/
?>
<?
//time measurement function
function micro() {
return time()+microtime();
}
//wait for certain search engine to retrieve results
function wait_for($id,$key) {
global $times,$en;
while (!file_exists('cache/'.$id.'-'.$key)) {
$i++;
if (!$en['notimeout'])
if ((micro() - $times[$key]) > search_timeout) {return false;} //break in case of timeout
}
}
//format search term to be search engine friendly
function format_term($term) {
$term = str_replace('-','~~',$term);
return str_replace(' ','-',$term);
}
//clean term
$en['term'] = stripslashes($en['term']);
$en['term'] = str_replace("'",'"',$en['term']);
$en['term'] = str_replace("+",' ',$en['term']);
$en['term'] = str_replace(chr(92),' ',$en['term']);
$en['term'] = str_replace('/',' ',$en['term']);
while (substr($en['term'],0,1) == ' ') $en['term'] = substr($en['term'],1);
while (strpos($en['term'],' ') !== false) $en['term'] = str_replace(" ",' ',$en['term']);
while (substr($en['term'],strlen($en['term'])-1,1) == ' ') $en['term'] = substr($en['term'],-1);
//no search source - source = 1
if (!$en['source']) $en['source'] = 1;
//first page = search engine friendly
echo "<br>".$_GET['req'];
echo "<br>".$_GET['cache'];
echo "<br>".first_friendly;
exit;
if (first_friendly == 'Yes' &&
$_GET['req'] != 'xsearch' &&
$en['cache'] != 'no') {
ob_clean();
header('Location: '.constant('dir').'search/'.format_term($en['term']).'/'.$en['source'].'-1.html');
exit;
}
//page title = query
define('page_title',$en['term']);
//filter keywords
if (safe_search == 'Yes') {
$keys = $filtered = array();
$kres = mysql_query("SELECT * FROM $safetable");
while ($line = mysql_fetch_assoc($kres)) $keys[] = $line['s_word'];
$words = explode(' ',$en['term']);
foreach ($words as $key => $value)
if (array_search(strtolower($value),$keys) !== false) {
unset($words[$key]);
$filtered[] = $value;
}
$en['filtered'] = implode('</b>, <b>',$filtered);
$en['term'] = implode(' ',$words);
}
//spellcheck
if (use_spellcheck == 'Yes' &&
function_exists('pspell_new')) {
pspell_config_create("en");
$int = pspell_new("en", "", "", "",PSPELL_FAST);
$q = query_parse($en['term']);
//not for advanced search
if (count($q) < 2) {
$words = $wrds = preg_split('/[/W]+?/',$en['term']);
$misspelled = $return = array();
foreach ($words as $key => $value)
if (!pspell_check($int, $value))
$misspelled[$key] = $value;
foreach ($misspelled as $key => $value) {
$ret = pspell_suggest($int, $value);
$words[$key] = '<i><b>'.$ret[0].'</b></i>';
if ($ret[0] == '' || strtolower($ret[0]) == strtolower($value)) unset($misspelled[$key]);
$wrds[$key] = $ret[0];
$en['is_spellcheck'] = 1;
}
if (count($misspelled) > 0) {
$msp = implode(' ',$words);
$msp = str_replace('</b></i> <i><b>',' ',$msp);
$que = implode(' ',$wrds);
$en['spell_corrected'] = '<a href="'.constant('dir').'index.php?req=search&source='.$en['source'].'&term='.urlencode($que).'">'.$msp.'</a>';
}
}
}
//get search type and result page number
if (isset($en['offs']) &&
!is_numeric($en['offs'])) list($en['source'],$en['offs']) = explode('-',$en['offs']);
if ($en['offs'] == 0) $en['offs'] = 1;
if ($en['source'] == '') $en['source'] = 1;
//search requirements
$times = $rez = array();
$options['keys'] = urlencode($en['term']);
$options['limit'] = result_count;
//load results from cache?
if (cache_results == 'Yes' &&
$en['cache'] != 'no') {
$res = mysql_query("SELECT * FROM $cachetable WHERE c_query='$en[term]'"
." AND c_source='$en[source]'"
) or die(mysql_error());
if (mysql_num_rows($res) > 0)
$cache = mysql_fetch_array($res);
}
//leave source search engines only
foreach ($sites as $key => $value)
if (@constant($key.'_cat') != $en['source'] &&
!$value['spons'])
unset($sites[$key]);
//get results
$search_st = micro();
if (!isset($cache)) {
$queries = queries($options);
if (cache_results == 'Yes' &&
$en['cache'] != 'no') {
mysql_query("INSERT INTO $cachetable (c_query, c_time"
.",c_source"
.") VALUES ('$en[term]', ".time()
.",$en[source]"
.")") or die(mysql_error());
$id = mysql_insert_id();
} else
{
$id = rand(0,100000000);
}
function execInBackground($path, $exe, $args = "") {
global $conf,$par;
$pth = getcwd();
@chdir($path);
if (substr(php_uname(), 0, 7) == "Windows"){
$p = "start /"Title/" /"".path_to_php."/" /"" . $exe . "/" " . $args;
pclose(popen($p, "r"));
} else
{
$q = path_to_php." '".$exe."' '".$par."' >&- <&- >/dev/null &";
exec($q);
}
chdir($pth);
}
//exec search threads
foreach ($sites as $key => $value) {
$times[$key] = micro();
$params = array();
$params['query'] = $queries[$key];
$params['cache'] = "cache/".$id.'-'.$key;
$par = base64_encode(serialize($params));
execinbackground(dirname(path_to_php),getcwd().'/get.php', $par);
}
//wait for results
foreach ($sites as $key => $s) {
wait_for($id,$key);
}
//get retrieved results + save in cache
foreach ($sites as $key => $s) {
$file = "cache/".$id.'-'.$key;
$f = @fopen($file,'r');
if (!$f) { continue;
}
$s = '';
while (!feof($f)) $s .= fgets($f);
fclose($f);
unset($f);
unlink($file);
if (cache_results == 'Yes' &&
$en['cache'] != 'no')
mysql_query("UPDATE $cachetable SET c_{$key}='".mysql_escape_string($s)."' WHERE c_id=$id") or die(mysql_error());
$cache['c_'.$key] = $s;
}
}
//get detailed times needed for each engine
$grr = @fopen('cache/'.$id,'r');
if ($grr) {
$s = fread($grr,4096);
fclose($grr);
$en['search_detail_times'] = str_replace(', ',"/n",$s);
$en['search_time'] = round(micro()-$search_st,4);
@unlink('cache/'.$id);
}
//parse results
foreach ($sites as $key => $value)
$rez[$key]['res'] = check_ranking($key,$options);
//query for related queries
$wrd = $en['term'];
while (strpos($wrd,' ') !== false) $wrd = str_replace(' ',' ',$wrd);
$wrd = str_replace('"','',$wrd);
$words = explode(' ',$wrd);
$en['rel'] = '';
foreach ($words as $c => $word)
if (substr($word,0,1) != '-') {
$en['rel'] .= "AND (q_query REGEXP '(^|[^a-zA-Z])".$word."([^a-zA-Z]|$)')";
$terms[] = $word;
}
$en['rel'] = substr($en['rel'],4);
if ($en['rel'] != '') {
$en['spons'] = str_replace('AND','OR',$en['rel']);
$en['rel'] = '('.$en['rel'].") AND (q_query <> '$wrd')";
}
global $relateds;
$relateds = array();
//suggestions based on previous searches
if (related_ext == 'Yes') {
//find the best available suggestions
$maxq = 0;
foreach ($rez as $key => $value)
if ($value['res']['related_q'] > $maxq) {
$maxq = $value['res']['related_q'];
$rel = $value['res']['related'];
}
}
if (related_ext != 'Yes' || $maxq == 0) {
$res = mysql_query("SELECT * FROM $querytable WHERE ".$en['rel']." ORDER BY q_times DESC LIMIT 20");
while ($line = mysql_fetch_assoc($res)) {
$rel[] = $line['q_query'];
}
}
//prepare suggestions for displaying
if (is_array($rel))
foreach ($rel as $c => $value) {
$relateds[]['show'] = $value;
if (count($relateds) > 20) break;
}
//chop slashes off the end of URL's
foreach ($rez as $key => $value)
if (is_array($value['res']) &&
!($sites[$key]['spons']))
foreach ($value['res'] as $r => $s)
if (substr($s['site'],-1) == '/') $rez[$key]['res'][$r]['site'] = substr($s['site'],0,-1);
//process search results
$out = array();
foreach ($rez as $key => $value) {
if (is_array($value['res']) &&
!($sites[$key]['spons']))
foreach ($value['res'] as $r => $s)
if (is_numeric($r)) {
$pr = $s['site'];
//remove www
$s['site'] = str_replace('http://www.','http://',$s['site']);
if ($s['site'] != $pr) {$www[$s['site']] = true;}
//add points
$out[$s['site']] += ($options['limit']+1-$r);
//register the rank within search engine
$engines_[$s['site']][$key] = $r;
//assign title and description
$s['title'] = strip_tags($s['title']);
if ($s['des']) $des[$s['site']] = $s['des'];
$title[$s['site']] = $s['title'];
//assign rank
$found[$s['site']][$key] = $r;
}
}
arsort($out);
//register queries if not advanced search
$reg = true;
$t = strtolower($en['term']);
if (strpos($t,'"') || strpos($t,' or ') || strpos($t,' and ') || strpos($t,' not ') || strpos($t,' -')) $reg = false;
if ($en['req'] != 'do_advanced' &&
$reg) {
if (count($out) > 0) {
mysql_query("UPDATE $querytable SET q_times=q_times+1 WHERE q_query='$en[term]'") or die(mysql_error());
if (mysql_affected_rows() == 0)
mysql_query("INSERT INTO $querytable (q_query) VALUES ('$en[term]')") or die(mysql_error());
}
}
//max number of points
$sitecnt = 0;
foreach ($rez as $key => $value) {
unset($rez[$key]['res']['title']);
if (is_array($value['res']) &&
!($sites[$key]['spons']))
$sitecnt++;
}
$max = $sitecnt * $options['limit'];
if ($max == 0) $max = 1;
//sponsored results set
foreach ($sites as $key => $value)
if ($value['spons'])
if (is_array($rez[$key]['res'])) {
foreach ($rez[$key]['res'] as $k => $v)
$en['sprez']['res'][] = $v;
}
//prepare results set
$rez = array();
foreach ($out as $key => $value) {
$p = count($rez)+1;
$rez[$p]['url'] = $key;
$rez[$p]['points'] = round(100 * ($value/$max));
$rez[$p]['title'] = $title[$key];
$rez[$p]['des'] = $des[$key];
$rez[$p]['found'] = $found[$key];
}
$en['count'] = count($rez);
//determine count of results per page
if (!defined('def_res_pp')) define('def_res_pp',10);
if (isset($en['pp'])) {
$en['pp'] = $en['pp'];
if ($en['pp'] != def_res_pp) $ugly = true;
}
else
if (isset($_COOKIE['pp'])) {
$en['pp'] = $_COOKIE['pp'];
} else
{
$en['pp'] = def_res_pp;
}
//delete empty cached set
if (cache_results == 'Yes' &&
count($rez) == 0) {
mysql_query("DELETE FROM $cachetable WHERE c_query='$en[term]' AND c_source='$en[source]'") or die(mysql_error());
}
//open result links in new window?
$neww = ($_COOKIE['newwind'] == 'tru');
$en['newwind'] = ($neww ? ' target=blank_' : ' ');
//hide search summaries
$hide = ($_COOKIE['nosum'] == 'tru');
$en['hidesum'] = ($hide ? 'tru' : ' ');
//number of pages
$en['pages'] = ceil($en['count'] / $en['pp']);
//format search term to use for search engine friendly pages
$en['xsrc'] = format_term($en['term']);
//bounds of results set
$en['to'] = $en['offs'] * $en['pp'];
$en['from'] = $en['to'] - $en['pp'] + 1;
//links to result pages
for ($k = 1;
$k <= $en['pages'];
$k++)
$en['rpg'] .= '&nbsp;'.($k == $en['offs'] ? '<b>' : ($ugly ? "<a href='".constant('dir')."index.php?req=xsearch&term=".$en['xsrc'].'&pp='.$en['pp'].'&offs='.$en['source'].($en['source'] != '' ? '-' : '').$k."'>" : "<a href='".constant('dir')."search/".$en['xsrc'].'/'.$en['source'].($en['source'] != '' ? '-' : '').$k.".html'>")).$k.($k == $en['offs'] ? '</b>' : '</a>');
if ($en['offs'] > 1)
$en['rpg'] = '&nbsp;'.($ugly ? "<a href='".constant('dir')."index.php?req=xsearch&term=".$en['xsrc'].'&pp='.$en['pp'].'&offs='.$en['source'].($en['source'] != '' ? '-' : '').($en['offs'] - 1)."'>" : "<a href='".constant('dir')."search/".$en['xsrc'].'/'.$en['source'].($en['source'] != '' ? '-' : '').($en['offs'] - 1).".html'>").'&lt;&lt;'.'</a>' . $en['rpg'];
if ($en['offs'] < $en['pages'])
$en['rpg'] .= '&nbsp;'.($ugly ? "<a href='".constant('dir')."index.php?req=xsearch&term=".$en['xsrc'].'&pp='.$en['pp'].'&offs='.$en['source'].($en['source'] != '' ? '-' : '').($en['offs'] + 1)."'>" : "<a href='".constant('dir')."search/".$en['xsrc'].'/'.$en['source'].($en['source'] != '' ? '-' : '').($en['offs'] + 1).".html'>").'&gt;&gt;'.'</a>';
//highlight search term
foreach ($rez as $key => $value) {
if ($www[$value['url']]) $rez[$key]['url'] = str_replace('http://','http://www.',$rez[$key]['url']);
$rez[$key]['title'] = highlight($rez[$key]['title'],$terms);
$rez[$key]['des'] = highlight($rez[$key]['des'],$terms);
$rez[$key]['url'] = highlight($rez[$key]['url'],$terms);
}
//show results
$en['rez'] = $rez;
if ($xmlsearch) {
//xml results
include 'includes/xml_output.php';
} else
{
//web results
load_template('templates/search_results.tpl');
}
?>