16.10.2003, 06:17
|
# 1
|
|
Junior Member
Регистрация: 01.08.2003
Адрес: Холон, Израиль
Сообщения: 145
|
Обьясните куда надо ставить этот скрипт и как
Я скачал скрипт поиска по сайту на языке Перл
там в архиве несколько файлов, я закачал скрипт на сайт, и теперь не знаю как его вставить в мою страничку
Цитата:
#!/usr/bin/perl
############################################################
# #
# Virtual Visions :: "Fetch" Search Engine #
# Script coded by Barracuda #
# Email - baracuda@feartech.com #
# #
############################################################
# this is the url of your site
$base_url = 'http://127.0.0.1';
# this is the path equivalent of $base_url
$base_dir = '/omnihttpd/htdocs';
# this is the url of fetch.pl
$search_url = 'http://127.0.0.1/cgi-bin/fetch/fetch.pl';
# this is the path to header.shtml
$header = '/path/to/header.shtml';
# this is the path to footer.shtml
$footer = '/path/to/footer.shtml';
# the background color of fetch... behind the keyword field
$bg = 'bgcolor=#800000';
# the directories you want to search in, note the trailing "/"
# you cannot search only '' as a directory and expect it to
# search all of your directories if you have $subdirs set to
# yes... you must specify directories
@dirs = ('','directory1/','directory2/subdir1/','directory3/');
# allow fetch to search in subdirectories of the above
# directories?
$subdirs = "yes";
# what types of files do you want to search in? note that
# htm works for htm, html, phtml, shtml, etc...
@searchtypes = ('htm');
############################################################
use CGI qw(:standard);
$search = new CGI;
$result_num = $search->param('result_num');
$show_search = $search->param('show_search');
$show_summary = $search->param('show_summary');
$keyword = $search->param('keyword');
$page = $search->param('page');
$connector = $search->param('connector');
$case = $search->param('case');
&get_header_footer;
&display_page unless $show_search eq "no";
############################################################
@keywords = split(/\s+/,$keyword);
foreach $type (@dirs)
{
chomp($type);
$dir = "$base_dir/$type";
chdir($dir);
opendir (DIR, $dir) || &cgiError ("Opening $dir Failed:", "$!");
@allfiles = readdir(DIR);
$totalnum=@allfiles;
closedir (DIR);
for($i=1; $i<$totalnum; $i++)
{
if (-d $allfiles[$i])
{
if ($allfiles[$i] ne "." && $allfiles[$i] ne ".." && $type ne "" && $subdirs eq "yes")
{
push(@dirs,"$type$allfiles[$i]/");
}
}
if (-f $allfiles[$i])
{
($file,$ext) = split(/\./, $allfiles[$i]);
foreach $searchtype (@searchtypes)
{
if ($ext =~ /$searchtype/i)
{
open (SEARCH,"$allfiles[$i]") || &cgiError ("Open $allfiles[$i] Failed:", "$!");
@search = <SEARCH>;
close(SEARCH);
$temp_file = "$type$allfiles[$i]";
foreach $text (@search)
{
chomp($text);
if ($text =~ /<title>(.*)<\/title>/i)
{
$title=$1;
}
$text =~ s/<([^>]|\n)*>//g;
$text =~ s/&([^;])*;//g;
$text =~ s/<!--([^-->])*-->//g;
if ($connector eq "or" && $case eq "insensitive")
{
foreach $word (@keywords)
{
if (!($text =~ /$word/i)) { $match = 0; }
else { $matches{$temp_file} = $text; last; }
}
}
if ($connector eq "and" && $case eq "insensitive")
{
if (!($text =~ /$keyword/i)) { $match = 0; }
else { $matches{$temp_file} = $text; last; }
}
if ($connector eq "or" && $case eq "sensitive")
{
foreach $word (@keywords)
{
if (!($text =~ /$word/)) { $match = 0; }
else { $matches{$temp_file} = $text; last; }
}
}
if ($connector eq "and" && $case eq "sensitive")
{
if (!($text =~ /$keyword/)) { $match = 0; }
else { $matches{$temp_file} = $text; last; }
}
}
}
}
}
}
}
foreach $key (sort(keys %matches))
{
push(@matches,$key);
push(@summary,$matches{$key});
}
&print_header;
print "<p align=\"right\"><b><font size=\"+1\">FearTech Unlimited Productions :: Search </font></b></p><br>\n\n";
print "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"top\"><td width=\"50%\"><font size=\"+1\"><b>Search Results</b></font><br><br></td>\n";
print "<td width=\"50%\"><p align=\"right\">\n";
$total = @matches;
$real_total = $total;
$totalnum = int(($total + $result_num)/ $result_num);
if ($page )
{
($liststart,$listend) = split(/ /,$page);
}
else
{
if ($total < $result_num) { $liststart = 0; $listend = $total; }
else { $liststart = 0; $listend = $result_num; }
}
if ($total > $result_num)
{
print "<form action=\"$search_url\" method=\"POST\"><select name=\"page\">";
for($i=0; $i<$totalnum; $i++)
{
$num = ($i * $result_num);
$end = ($num + $result_num);
if ($matches[$num] )
{
if ($total<$end) { $end = $total; }
$real_num = $num;
eval { $num = ($num + 1); };
print " <option value=\"$real_num $end\">Display Results $num - $end</option>\n";
eval { $num = ($num - 1); };
}
}
print "</select><input type=\"hidden\" name=\"show_search\" value=\"no\">";
print "<input type=\"hidden\" name=\"show_summary\" value=\"$show_summary\">";
print "<input type=\"hidden\" name=\"result_num\" value=\"$result_num\">";
print "<input type=\"hidden\" name=\"case\" value=\"$case\">";
print "<input type=\"hidden\" name=\"connector\" value=\"$connector\">";
print "<input type=\"hidden\" name=\"keyword\" value=\"$keyword\"> <input type=submit value=\"GO!\"></form></p>\n";
}
$first = ($liststart + 1);
$last = $listend;
if ($listend<=$result_num && $end<=$result_num) { $last = $total; }
print "</td></tr></table>\n";
print "Below are the results of your search for: <b>$keyword</b><br>Documents $first - $last of $real_total Matches.<br><br>\n";
print "<blockquote>\n";
if ($total eq "0")
{
print "<b>Sorry, No Matches Found!</b><br>\nWe did not find anything that matched your search criteria.<br>Please try searching again with a different combination of keywords.\n";
}
else
{
if ($liststart eq "$listend")
{
$liststart = ($liststart - 1);
}
for($liststart; $liststart<$listend; $liststart++)
{
if ($matches[$liststart])
{
$match = $matches[$liststart];
$summary = $summary[$liststart];
if ($summary eq "")
{
$summary = "No summary available.";
}
print "<b><a href=\"$base_url/$match\">$match</a></b><br>\n";
print "<b>URL:</b> $base_url/$match<br>\n";
if ($show_summary eq "yes")
{
print "<b>Summary:</b> $summary<br>";
}
print "<br>\n\n";
}
}
}
print "</blockquote><br>Didn't find what you were looking for? Try searching again with a more specific keyword.<br><br>\n\n";
print "<ul><form action=\"$search_url\" method=\"POST\"><input type=\"hidden\" name=\"show_search\" value=\"no\"><b>Search For:</b> <input type=\"text\" size=\"36\" name=\"keyword\" MAXLENGTH=\"35\"><br><br>\n";
print "<input type=\"hidden\" name=\"show_search\" value=\"no\">\n";
print "<input type=\"hidden\" name=\"result_num\" value=\"$result_num\">\n";
print "<input type=\"hidden\" name=\"case\" value=\"$case\">\n";
print "<input type=\"hidden\" name=\"connector\" value=\"$connector\">\n";
print "<input type=\"hidden\" name=\"show_summary\" value=\"$show_summary\">\n";
print "<input type=\"submit\" value=\"Search!\"></form></ul>\n";
&print_footer;
################
# sub routines #
################
sub display_page
{
&print_header;
print qq~
<p align="right"><b><font size="+1">FearTech Unlimited Productions :: Search </font></b></p><br>
Enter a few words to search for and you will get a list of every file that contains a match.<br><br>
<form action="$search_url" method="POST"><table width="100%" border="0" cellpadding="8" cellspacing="0"><tr valign="center"><td width="25%" $bg><tt><b>Search For:</b></tt></td><td width="75%" colspan="2" $bg><input type="text" size="36" name="keyword" MAXLENGTH=\"35\"> <input type="submit" value="Search!"></td></tr>
<tr><td><tt><b> Search<br> As:</b></tt></td><td><input type="radio" name="connector" value="or" CHECKED>Keywords <input type="radio" name="connector" value="and">Phrase</td></tr>
<tr><td><tt><b> Case:</b></tt></td><td><input type="radio" name="case" value="insensitive" CHECKED>Insensitive <input type="radio" name="case" value="sensitive">Sensitive</td></tr>
<tr><td><tt><b> Show<br> Summaries:</b></tt></td><td><input type="radio" name="show_summary" value="yes" CHECKED>Yes <input type="radio" name="show_summary" value="no">No</td></tr>
<tr><td><tt><b> Results<br> Per Page:</b></tt></td><td><input type="radio" name="result_num" value="10">10 <input type="radio" name="result_num" value="20" CHECKED>20 <input type="radio" name="result_num" value="30">30 <input type="radio" name="result_num" value="40">40 <input type="radio" name="result_num" value="50">50</td></tr>
</table><input type="hidden" name="show_search" value="no"></form>
~;
&print_footer;
exit;
}
sub print_header
{
print "Content-type: text/html\n\n";
foreach $line (@dataa)
{
chomp($line);
print "$line\n";
}
}
sub print_footer
{
foreach $line (@datab)
{
chomp($line);
print "$line\n";
}
}
sub get_header_footer
{
open (FILEA,"$header") || &cgiError ("Reading Header Failed:", "$!");
@dataa = <FILEA>;
close(FILEA);
open (FILEB,"$footer") || &cgiError ("Reading Footer Failed:", "$!");
@datab = <FILEB>;
close(FILEB);
}
sub cgiError
{
my ($error_cause,$error) = @_;
if ($error_cause eq "") { $error_cause = "Error:"; }
if ($error eq "") { $error = "The script encountered problems and terminated"; }
&print_header;
print "<h3>$error_cause</h3>$error<br><br>";
&print_footer;
exit;
}
|
__________________
|
|
|