#!/usr/bin/perl ################################################################################################ #who: Kevin Palmer, KP Web Design #what: perl script which searches a given file for a given string, highlights all matches of # that string, and prints the highlighted text to the screen #last edited: 10/25/01 #why: Slowtwitch Search Engine ################################################################################################ # The CGI.pm module is by far the best CGI module for Perl use CGI qw(:standard); print header(-expires=>"$expire"); my $client=new CGI(); $text = $client->url_param('text'); $url = $client->url_param('url'); #file url $my_url=$client->self_url(); $file = "/home/slowtwitch/slowtwitch.com/www" . substr($url,25); # relative file path from /cgi-bin (cut 'http://www.slowtwitch.com' from url) $path = substr($url,0,rindex($url, '/')); #file path minus filename unless(-e "$file") { die "File does not exist: $file\n"; } open(FILE,"<$file") or die "Cannot open $file.\n"; while() { my $line="$_"; #replace HTML codes for non-enlish characters with english "equivalents" # $line =~ s/\ä\;/a/gi; # $line =~ s/\ü\;/u/gi; #if "unreadable EOL" character exists, split page at "EOLs" to yield "lines" if ($line =~ /\r/) { @lines = split(\r,$line); foreach $x (@lines) { $x =~ s/$text/$&<\/span>/gi; #highlight search text ####edit relative image and file paths for correctness from cgi-bin/ ##edit image paths so image links work properly from cgi-bin/ if ($x =~ m/src=\"\w\w\w\w/i) { #no path, just filename (assumes all filenames are at least 4 characters long) if ($& ne "src=\"http") { #not an absolute link (assumes all absolute links are to outside domains) my @parts = split(/\"/, $&); $x =~ s/src=\"\w\w\w\w/$parts[0]\"$path\/$parts[1]/gi; } } $x =~ s/src=\"\.\./src=\"$path\/\.\./gi; # parent path (relative link) $x =~ s/src=\"\//src=\"$path\//gi; # absolute virtual path ##edit anchor paths so links work properly from cgi-bin/ $x =~ s/$&<\/span>/gi; #highlight search text ####edit relative image and file paths for correctness from cgi-bin/ ##edit image paths so image links work properly from cgi-bin/ if ($line =~ m/src=\"\w\w\w\w/i) { #no path, just filename (assumes all filenames are at least 4 characters long) if ($& ne "src=\"http") { #not an absolute link (assumes all absolute links are to outside domains) my @parts = split(/\"/, $&); $line =~ s/src=\"\w\w\w\w/$parts[0]\"$path\/$parts[1]/gi; } } $line =~ s/src=\"\.\./src=\"$path\/\.\./gi; # parent path (relative link) $line =~ s/src=\"\//src=\"$path\//gi; # absolute virtual path $line =~ s/