#!/usr/bin/perl -w # !C:\xampp\xampp\perl\bin\perl.exe # ################################################################### # # lit_search1.pl # # Moes G. 2005 # # ################################################################### # Change here the names of the needed files # The name of the results template $tplfile="../httpdocs/results1.htm"; # Path to file containing all urls # $url_file="index_1.txt"; # #################################################################### # Get the data from the form # &parse_form; use CGI; my $query = new CGI; # neues CGI-Objekt erzeugen $SEARCH = $query->param('text'); @TEXTS = split(/\s+/, $SEARCH); @ALLURLS = $query->param('auswahl'); $BOOL = $query->param('boolean'); #@texts = split(/\s+/, $FORM{'text'}); # $text = $FORM{'text'}; foreach $text (@TEXTS) { if ($text eq "") { # print $cgi->start_html( -title => 'Literatursuche'); print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "Literatursuche\n"; print "\n"; print "\n"; print "\n"; print ""; exit; } } # Read the template if (open(FILE,"$tplfile")) { @TEMPLATE = ; close(FILE); } else { &error_open; } # Locates ##LOOP-START## and ##LOOP-END## in the template $loopstart = 0; $loopend = 0; $tempsize=@TEMPLATE; for($n=0; $n<$tempsize; $n++) { $line=$TEMPLATE[$n]; if($line =~ /LOOP-STARTS/i) { $loopstart=$n; } if($line =~ /LOOP-ENDS/i) { $loopend=$n; } } # print the top of the page print "Content-type: text/html\n\n"; for($n=0; $n<$loopstart; $n++) { $line=$TEMPLATE[$n]; # $line =~ s/##TEXT##/$text/gi; # Use of uninitialized value in substitution (s///), print $line; } # flags definition $flag_any = 0; $flag_page = 0; $counter = 0; # Read urls from index file if (open(FILE,"$url_file")) # Use of uninitialized value in join or string { @ALLURLS = ; close(FILE); } else { @ALLURLS = $query->param('auswahl'); # @ALLURLS = $FORM{'auswahl'}; } # { # &error_open; # } # Loops through all urls for($n=0; $n<@ALLURLS; $n++) { $flag_page=0; # split between the URL and the page description @PARTS = split(/\|/, $ALLURLS[$n]); if (open(CONTENT_FILE,"$PARTS[0]")) { @CONTENT = ; $all = @CONTENT; close(CONTENT_FILE); for($m=0; $m<@CONTENT && $flag_page < 10000; $m++) { $line=$CONTENT[$m]; # Remove html tags from $line $line =~ s/<(.*?)>/\.\.\./g; $i=1; if ($BOOL eq 'oder'){ #if ($FORM{'boolean'} eq 'oder'){ foreach $text (@TEXTS) { # $i; if($line =~ /$text/){ # Highligt the text found $line=~ s/$text/$text<\/b>/g; &result; } $i = $i++; } } elsif ($BOOL eq 'und'){ #elsif ($FORM{'boolean'} eq 'und'){ if($line =~ /$TEXTS[0]/) { if ($line =~ /$TEXTS[1]/) { # Use of uninitialized value in join or string if ($line =~ /$TEXTS[2]/) { # Use of uninitialized value in join or string if ($line =~ /$TEXTS[3]/) {# Use of uninitialized value in join or string if ($line =~ /$TEXTS[4]/) {# Use of uninitialized value in join or string # Highligt the text found foreach $text (@TEXTS) { # $i; $line=~ s/$text/$text<\/b>/g; } &result; $i = $i++; } } } } } } } } else { &error_open; } } # Prints the rest of the page if ($flag_any == 0) { print "
"; print "
"; print ""; print ""; print ""; print "<\/tr>"; print "<\/table>"; print "<\/center>"; print "<\/div>"; } for($n=$loopend; $n<$tempsize; $n++) { $line=$TEMPLATE[$n]; $line =~ s/##QUERY##/$query/gi; print $line; } exit; sub parse_form { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (length($buffer) < 5) { $buffer = $ENV{QUERY_STRING}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if($name eq "category") { $value =~ s/ /_/g; $value="#".lc($value); $value=$FORM{'category'}.$value; } $FORM{$name} = $value; } } sub error_open { print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "Fehler!\n"; print "\n"; print "\n"; print "

"; print "Die Datei $filename konnte nicht geƶffnet werden oder wurde nicht gefunden."; print "


"; print ""; exit; } sub result { $counter = $counter + 1; # Prints this record looping throug the template for($tpline=$loopstart; $tpline<$loopend && $flag_page == 0; $tpline++) { $linet=$TEMPLATE[$tpline]; $linet =~ s/##DESCRIPTION##/$PARTS[1]/gi; # $linet =~ s/##URL##/$PARTS[0]/gi; # $linet =~ s/##NUM##/$i/gi; $linet=~ s/##ALL##/$all /gi; print $linet; } print "
Kein passender Eintrag gefunden."; print ""; print $line; print"
"; print "<\/font>"; print "<\/td>"; print "<\/tr>"; $flag_page = $flag_page+1; if ($flag_page == 2) {$counter--;} $flag_any = 1; }