#!/usr/bin/perl ########################################################################## ## ## ## SmartFAQ v3.0 ## ## ------------- ## ## A script by SmarterScripts.com ## ## ## ## TERMS OF USE: ## ## This is a free script, if anyone sold it to you please contact us ## ## at the following e-mail address: webmaster@smarterscripts.com ## ## By using this script you agree not to remove any copyright messages ## ## or links to our website. The links keep this CGI free for everyone. ## ## But, you can register this script and get a version with NO links ## ## to our site on it. Just go to the following URL for more info: ## ## http://www.smarterscripts.com/register.shtml ## ## ## ## (c) copyright 2003 R3N3 Internet Services & SmarterScripts.com ## ########################################################################## print "Content-type: text/html; charset=EUC-JP\n\n"; require "vars.cgi"; &parse; $answer = $input{'answer'}; $id = $input{'id'}; $subject = $input{'subject'}; $cat = $input{'cat'}; $keywords = $input{'keywords'}; $match = $input{'match'}; if($answer && $answer =~ /[^0-9A-z\-_]/) { &error("Invalid Input."); } if($subject && $subject =~ /[^0-9A-z\-_]/) { &error("Invalid Input."); } if($cat && $cat =~ /[^0-9A-z\-_]/) { &error("Invalid Input."); } $keywords=Jcode::convert(\$keywords,$prog_kcode); open(DATA,"$header_file"); @head = ; close(DATA); open(DATA,"$footer_file"); @foot = ; close(DATA); if($answer) { &answer; } if($subject || $cat) { &cat; } if($keywords) { &search; } open(DATA,"data/categories.txt"); @cats = ; close(DATA); @cats = sort @cats; print @head; foreach $line(@cats) { chomp($line); ($category, $catid) = split(/&&/,$line); $html = "
  • $category
    • \n"; open(DATA,"data/$catid.cat"); @catlist = ; close(DATA); $count = 0; foreach $line(@catlist) { $count++; ($pos, $id) = split(/&&/,$line); open(DATA,"data/$id.qa"); @entry = ; close(DATA); $entry = join('',@entry); ($question, $answer) = split(/\|/,$entry); $html .= "
    • $question
    • \n"; } $html .= "

\n"; if($count) { print $html; } } print qq|

Powered by SmartFAQ
|; print @foot; sub answer { open(DATA,"data/$answer.qa") || &error("Unable to locate FAQ entry file ($answer.qa)"); @content = ; close(DATA); $content = join('',@content); ($q, $a) = split(/\|/,$content); print qq| @head

$q

$a

|; if($related_topics eq 1) { print "関連項目:
\n"; open(DATA,"data/categories.txt"); @cats = ; close(DATA); @cats = sort @cats; foreach $line(@cats) { chomp($line); ($cat, $catid) = split(/&&/,$line); open(DATA,"data/$catid.cat"); @catlist = ; close(DATA); $found = 0; $count = 0; foreach $line(@catlist) { ($pos, $qid) = split(/&&/,$line); if($qid eq $answer) { print qq| $cat
|; last; } } } } elsif($related_topics eq 2) { %related = {}; $totalf = 0; open(DATA,"data/categories.txt"); @cats = ; close(DATA); @cats = sort @cats; foreach $line(@cats) { chomp($line); ($cat, $catid) = split(/&&/,$line); open(DATA,"data/$catid.cat"); @catlist = ; close(DATA); $found = 0; $count = 0; %related2 = {}; foreach $line(@catlist) { ($pos, $qid) = split(/&&/,$line); if($qid eq $answer) { $found = 1; } else { $related2{$qid} = 1; } } if($found) { foreach $key (keys %related2) { $totalf++; $related{$key} = 1; } } } if($totalf) { print "関連項目:
\n"; foreach $key (keys %related) { open(DATA,"data/$key.qa") || next; @content = ; close(DATA); $content = join('',@content); ($q, $a) = split(/\|/,$content); print qq|$q
|; } } } print qq|

Powered by SmartFAQ
|; print @foot; if($log_count) { #log hit open(DATA,"data/log.txt"); flock (DATA,2); @log = ; flock (DATA,8); close(DATA); $found = 0; foreach $line(@log) { chomp($line); ($num,$id) = split(/\t/,$line); if($id eq $answer) { $num++; $found = 1; push(@newlog,"$num\t$id\n"); } else { push(@newlog,"$line\n"); } } if($found) { @newlog = sort {$b <=> $a} @newlog; open(DATA,">data/log.txt"); flock (DATA,2); print DATA @newlog; flock (DATA,8); close(DATA); } else { open(DATA,">>data/log.txt"); flock (DATA,2); print DATA "1\t$answer\n"; flock (DATA,8); close(DATA); } } exit; } sub cat { open(DATA,"data/$cat.cat"); @catlist = ; close(DATA); $cnum = @catlist; if(!$cnum) { &error("There are currently no entries in this category of the FAQ."); } open(DATA,"data/categories.txt"); @cats = ; close(DATA); @cats = sort @cats; foreach $line(@cats) { chomp($line); ($category, $id) = split(/&&/,$line); if($id eq $cat) { $catname = $category; last; } } #$sa = 0; #$newcat = $catname; #@catsep2 = split(/\//,$newcat); #@catsep2 = reverse @catsep2; #while($newcat ne "" && $sa < 50) { #@catsep = split(/\//,$newcat); #@catsep = reverse @catsep; #delete $catsep[0]; #@catsep = reverse @catsep; #$newcat = join('/',@catsep); #chop($newcat); # foreach $line(@cats) { # chomp($line); # ($category, $id) = split(/&&/,$line); # if($category eq $newcat) { # @cat3 = split(/\//,$category); # @cat3 = reverse @cat3; # push(@newcatlist,"$cat3[0]&&$id"); # last; # } # } #$sa++; #} #@newcatlist = reverse @newcatlist; #push(@newcatlist,$catsep2[0]); # #foreach $line(@newcatlist) { #($category, $id) = split(/&&/,$line); # if($id) { # $cathtml .= "$category / "; # } else { # $cathtml .= "$category"; # } #} print qq| @head

$catname

|; if($layout eq 1) { print "

    \n"; foreach $line(@catlist) { ($pos, $qid) = split(/&&/,$line); open(DATA,"data/$qid.qa"); @$qid = ; close(DATA); $entry = join('',@$qid); ($question, $answer) = split(/\|/,$entry); print "
  • $question
  • \n"; } print "


\n"; foreach $line(@catlist) { ($pos, $qid) = split(/&&/,$line); $entry = join('',@$qid); ($question, $answer) = split(/\|/,$entry); print "$question
$answer

\n"; } } elsif($layout eq 2) { foreach $line(@catlist) { ($pos, $qid) = split(/&&/,$line); open(DATA,"data/$qid.qa"); @entry = ; close(DATA); $entry = join('',@entry); ($question, $answer) = split(/\|/,$entry); print "$question
$answer

\n"; } } else { print "

    \n"; foreach $line(@catlist) { ($pos, $qid) = split(/&&/,$line); open(DATA,"data/$qid.qa"); @entry = ; close(DATA); $entry = join('',@entry); ($question, $answer) = split(/\|/,$entry); print "
  • $question
  • \n"; } print "
\n"; } print qq|

Powered by SmartFAQ
|; print @foot; exit; } sub search { %matches = {}; @key = split(/ /,$keywords); open(DATA,"data/categories.txt"); @cats = ; close(DATA); @cats = sort @cats; print @head; print qq|$keywords」の検索結果:

|; foreach $line(@cats) { chomp($line); ($category, $catid) = split(/&&/,$line); open(DATA,"data/$catid.cat"); @catlist = ; close(DATA); foreach $line(@catlist) { ($pos, $id) = split(/&&/,$line); open(DATA,"data/$id.qa"); @$id = ; close(DATA); $entry = join('',@$id); ($question, $answer) = split(/\|/,$entry); $found = 0; $fcount = 0; if($match eq "any") { foreach $key(@key) { $q = $question; $q =~ s/.*?$key.*?/$fcount++/eig; $a = $answer; $a =~ s/.*?$key.*?/$fcount++/eig; if($question =~ /$key/i || $answer =~ /$key/i) { $found = 1; } } } else { $words = @key; $count = 0; foreach $key(@key) { $q = $question; $q =~ s/.*?$key.*?/$fcount++/eig; $a = $answer; $a =~ s/.*?$key.*?/$fcount++/eig; if($question =~ /$key/i || $answer =~ /$key/i) { $count++; } } if($count >= $words) { $found = 1; } } if($found) { $matches{$id} = $fcount; } } } $total = 0; foreach $key (keys %matches) { if($matches{$key}) { $total++; push(@matches,"$matches{$key}\t$key"); } } if($total) { print "

    \n"; @matches = reverse sort { $a <=> $b } @matches; foreach $line(@matches) { ($num,$id) = split(/\t/,$line); $entry = join('',@$id); ($question, $answer) = split(/\|/,$entry); foreach $key(@key) { $question =~ s/$key/$key<\/b>/ig; } print "
  • $question
  • \n"; } print "

$total 件が見つかりました。\n"; } else { print "No results found.\n"; } print qq|

Powered by SmartFAQ
|; print @foot; exit; }