#################### FUNCTION ############################################
// NB. mySQL database Host / Name / Username / Password ect. are at top of this inc page in file.
// I would like to hack this function, in order to update my database with the meta tag data parsed by the
// meta search engine script below. When a user makes a search. Any ideas??? on the best way too merge these
// two scripts.
// Greg🙂
// DIRECTORY SCRIPT FUNCTION
// The function is currently called off a other script like so.
// if ($action == "addlink")
// {
// add_link($link_name, $link_url, $link_desc, $link_cat, $link_recommended);
// }
// function() (Title --- URL --- Description --- 0 --- yes)
function add_link($link_name, $link_url, $link_desc, $link_cat, $link_recommended)
{
// adds a link to the database
global $db_host, $db_name, $db_user, $db_pass, $admin, $sitename;
if ((!$link_name) || (!$link_url) || (!$link_desc) || (!isset($link_cat)))
{
echo html_header("$sitename - Error");
echo ss_template('error_addlink.tmpl');
echo html_footer();
exit;
}
if (!$admin)
{
header("Location: links.php?action=logout");
exit;
}
if (!$link_recommended)
$link_recommended = "no";
$cnx = mysql_connect($db_host, $db_user, $db_pass)
or custom_die("Unable to connect to database server.");
mysql_select_db($db_name, $cnx)
or custom_die("Unable to select database.");
$time = time();
$sql = "INSERT INTO sslinks SET
link_name = '$link_name',
link_cat = '$link_cat',
link_url = '$link_url',
link_desc = '$link_desc',
link_numvotes = '0',
link_dateadd = '$time',
link_totalrate = '0',
link_validated = 'yes',
link_recommended = '$link_recommended'";
$result = mysql_query($sql);
if (!$result)
{
custom_die("SQL result failed - link was not added");
}
else
{
// Rebuild number of links for categories
build_numlinks();
header("Location: links.php?cat=$link_cat");
exit;
}
}
#################### FUNCTION END ##############################
<HEAD>
<TITLE>Meta Search Engine</TITLE>
</HEAD>
<BODY>
<font face=Verdana,Arial,Helvetica,sans-serif size=-1>
<FORM method=get>
Search: <input type=text name=search><input type=submit name=Search><br>
</FORM>
<hr size=1 noshade>
<?
#- Grab a search page
#- Start search
if($search) {
$q = urlencode($search);
$start = time();
$eng[0]['url'] = "http://www.google.com/search?q=$q&hl=en&lr=&safe=off&start=0&sa=N";
$eng[0]['name'] = "Google";
$eng[0]['reg'] = "/<p><A HREF=(.?)>(.?)<\/A><font.?<br>(.?)<br>/";
$eng[1]['url'] = "http://www.alltheweb.com/cgi-bin/search?offset=0&type=all&query=$q";
$eng[1]['name'] = "Fast";
$eng[1]['reg'] = "/<dt>.?status=\'(.?)\';.?true\">(.?)<\/a>.?=t>(.?)<\/span>/";
$urls = array();
$x=0;
$y=0;
$t=0;
foreach($eng as $c)
{
$text1 = join("",file($c['url']));
$i = preg_match_all($c['reg'],$text1,$matches);
$num=count($matches[0]);
#- Prepare the master list
for($x=1;$x<$num;$x++)
{
$urls[$y]['url'] = strip_tags($matches[1][$x]);
$urls[$y]['title'] = strip_tags($matches[2][$x]);
$urls[$y]['description'] = strip_tags($matches[3][$x]);
$urls[$y]['engine'] = $c['name'];
$y++;
}
#- Top results
$top[$t][url] = strip_tags($matches[1][0]);
$top[$t][title] = strip_tags($matches[2][0]);
$top[$t][description] = strip_tags($matches[3][0]);
$top[$t][engine] = $c[name];
$t++;
}#rof
$end = time();
$secs = $end-$start;
print "$y results returned in $secs seconds.<br><br>";
#- Display the top results
print "<b>Top $t results:</b><br>";
reset($top);
foreach($top as $rec)
{
$url = $rec[url];
if(!ereg("http://",$url))
$url = "http://".$url;
$title = $rec['title'];
$description = $rec['description'];
$engine = $rec['engine'];
echo "<p>
<a href=$url>$title</a><br>
$description<br>
<font size=-2>$url</font> <font color=green size=-2>($engine)</font>
</p>";
}#rof
print "<hr size=1 noshade>";
#- Display the bottom results
usort($urls,"cmp");
reset($urls);
foreach($urls as $rec)
{
$url = $rec[url];
if(!ereg("http://",$url))
$url = "http://".$url;
$title = $rec['title'];
$description = $rec['description'];
$engine = $rec['engine'];
echo "<p>
<a href=$url>$title</a><br>
$description<br>
<font size=-2>$url</font> <font color=green size=-2>($engine)</font>
</p>";
}#rof
}#end search
?>
</font>
</BODY>
<?
function cmp($a,$b)
{
return strcmp($a["title"],$b["title"]);
}
?>