
JC
Novice
May 29, 2000, 4:28 AM
Post #3 of 16
(1987 views)
|
Yep figure as much just don't see where, thanks. here's the code ... #!/usr/bin/perl ### Based on Compu-Stu search script copyright copyright Team 25018 of ### Thinkquest 99 (of which Pete was a member) ### Pete's AskStu - by Pete Stein (pete@slack.net) - 11-2-99 ### http://www.slack.net/~pete/perl ### ### This script copyright Pete Stein, pete@slack.net from Pete's Perl Scripts ### at http://www.slack.net. Users of this script acknowledge the following ### terms and conditions. This script is provided free of charge and as a ### result is Freeware, but still owned and copyright Pete Stein. Users may ### modify the script but may not in any circumstance redistribute or sell ### this script in any form or fashion without express consent of Pete Stein ### Users are not obligated to provide any acknowledgement of the origin of ### this script if used on their site, but they certainly may if they so ### desire. ### All images contained in this distribution, stubox.jpg and stu.jpg ### follow the same aforementioned conditions ## base directory, like /home/pete ## no trailing slash $basedir = '/home/tea'; ## name of the directory where answer files are stored ## no trailing slash $studir = 'teafiles'; ## baseurl, like http://www.slack.net/~pete, wherever stu.jpg will be stored ## no trailing slash $baseurl = 'http://theteacabinet.com/images'; ## location of this script $thiscgi = 'http://theteacabinet.com/cgi-bin/Ask-Stu/askstu.cgi'; print "Content-type: text/html\n\n"; # (post method) # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @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; $FORM{$name} = $value; } sub doanswer { $file = $FORM{'answer'}; open(FILE,"$basedir/$studir/$file"); @lines = <FILE>; close(FILE); $string = join(' ',@lines); $string =~ s/\n//g; if ($string =~ /<answer>(.*)<\/answer>/i) { @answer = "$1"; } if ($string =~ /<title>(.*)<\/title>/i) { $title = "$1"; } print " <html> <head> <title>I know that!</title></head> <body> <center> <table border=0 cellspacing=0 cellpadding=0 width=500> <tr><td> <img src=\"$baseurl/teabutton.gif\"> </td> <td width=10> <br> </td> <td> <b> <font face=\"Arial, Verdana, Helvetica\" size=\"3\"> <center>$title</center></font></b><p><br> <font face=\"Arial, Verdana, Helvetica\" size=\"2\"> @answer </font> <p> <center> <font face=\"Arial, Verdana, Helvetica\" size=\"2\"> <b><a href=\"Javascript:history.back(); history.back();\"><<<< Return</a><p> <a href=\"Javascript:history.back();\"><<< Back</a></b> </center> </font> <P>"; # you can remove this blurb if you want.... # don't feel guilty # really # it's nooo problem # *sniff* print "<font size=1>This script provided by <a href=\"http://www.slack.net/~pete/perl\">Pete's Perl Scripts</a><P> Compu-Stu is from <a href=\"http://library.advanced.org/25018\">UCS: The Ultimate Computer Source</a>, a <a href=\"http://www.thinkquest.org\">Thinkquest</a> entry. Compu-Stu provided interactive help to visitors of the site. We welcome you to visit it </td></tr></table> <p><br> </body> </html> "; } #Get the files here for later... @files = ('*.stu'); &get_files; $num=0; #Split the user's question by spaces $daquest = $FORM{'question'}; if ($daquest =~ /\?/) { chop($daquest); } @terms = split(/\s+/, $daquest); $i=0; if ($FORM{'step'} eq "answer") { &doanswer; } foreach $FILE (@FILES) { #Loop through each file and search for keywords $i++; $ismatch=0; #Open file here and store it in @lines open(FILE,"$FILE"); @lines = <FILE>; close(FILE); $string = join(' ',@lines); $string =~ s/\n//g; if ($string =~ /<keywords>(.*)<\/keywords>/i) { $keywords = "$1"; } #split the keywords up too @words = split(/\s+/, $keywords); foreach $word (@words) { #loop through each word and compare it to every keyword foreach $term (@terms) { if ("\L$term\E" EQ "\L$word\E") { $ismatch=1; } } } #Now ismatch should be 1 if something is found and 0 if it wasn't #Now we have to add this file to an array somehow if ($ismatch==1) { $stus{$i}="yes"; $nme{$i}=$FILE; $num++; } if ($string =~ /<title>(.*)<\/title>/i) { $question{$i} = "$1"; } } #Loop here to print out the code for the questions and the answers they can recieve $k=0; if ($num>0) { print " <html> <head> <title>I think I know the answer!</title> </head> <body> <p> <center> <table border=0 cellspacing=0 cellpadding=0 width=500> <tr><td valign=\"top\"> <img src=\"$baseurl/answlist.gif\" align=\"left\" hspace=\"5\"><b> <font face=\"Arial, Verdana, Helvetica\" size=\"3\"> <center>We think we have the Answer!</center></font></b><p> <div align=\"justify\">We searched our knowledge database and we matched your question with some of the potential questions we can answer. We made a list for you. Use the pulldown box below to locate the question you're looking for. Click answer, and you've got it!</div><P> <form method=\"post\" action=\"$thiscgi\"> <input type=hidden name=step value=answer> <select name=\"answer\">"; for ($j=1; $j<=$i; $j++) { if($stus{$j} EQ "yes") { print "<option value=$nme{$j}>$question{$j}</option>"; } } print "</select> <input type=\"submit\" value=\"Answer\"> </form> <center> <font face=\"Arial, Verdana, Helvetica\" size=\"2\"> <b><a href=\"Javascript:history.back();\"><< Back</a></b> </font> </center> <P>"; # you can remove this blurb if you want.... # don't feel guilty # really # it's nooo problem # *sniff* print " <font size=1>This script provided by <a href=\"http://www.slack.net/~pete/perl\">Pete's Perl Scripts</a><P> Compu-Stu is from <a href=\"http://library.advanced.org/25018\">UCS: The Ultimate Computer Source</a>, a <a href=\"http://www.thinkquest.org\">Thinkquest</a> entry. Compu-Stu provided interactive help to visitors of the site. We welcome you to visit it. </td></tr></table> "; } if ($num==0) { print " <html> <head><title>Sorry...</title></head> <body> <center> <table border=0 cellspacing=0 cellpadding=0 width=500> <tr><td> <img src=\"stu.jpg\" align=\"right\"><b> <center><b>I am sorry, I don't have an answer to that.</b></center><font size=2><p> </b> I'm sorry, I do not know the answer to your question. Maybe you can find it elsewhere in the site, or use different words in your question?<P> </font><p></td></tr></table> <font face=\"Arial, Verdana, Helvetica\" size=\"2\"> <b><a href=\"Javascript:history.back();\"><< Back</a></b> </font> </center> </body> </html> "; } sub get_files { chdir("$basedir/$studir"); foreach $file (@files) { $ls = `ls $file`; @ls = split(/\s+/,$ls); foreach $temp_file (@ls) { if (-d $file) { $filename = "$file$temp_file"; if (-T $filename) { push(@FILES,$filename); } } elsif (-T $temp_file) { push(@FILES,$temp_file); } } } } Thanks JC [This message has been edited by JC (edited 05-29-2000).]
|