| 1 |
package FAQ; |
| 2 |
|
| 3 |
my ($faq,$var,$env,$q,$a,$c,$s,$t,$n); |
| 4 |
my (@faq,%Q,%A,@s); |
| 5 |
my @sections = qw'Meta User Admin Misc'; |
| 6 |
|
| 7 |
@faq = ($faq) = $ENV{PATH_INFO} =~ /(\w+).html/; |
| 8 |
@faq = map {lc} @sections if $faq eq 'all'; |
| 9 |
|
| 10 |
print "<style type=text/css><!-- h2,h3 {font-weight:normal} --></style>\n"; |
| 11 |
|
| 12 |
print '<h1><a name="top" href="/index.html">F*EX</a> '; |
| 13 |
printf "Frequently Asked Questions: %s</h1>\n",ucfirst($faq); |
| 14 |
|
| 15 |
if ($faq ne 'local') { |
| 16 |
print "<h3>Sections: "; |
| 17 |
foreach $s (@sections,'All') { |
| 18 |
if ($s =~ /$faq/i) { |
| 19 |
print "<b>$s</b>\n"; |
| 20 |
} else { |
| 21 |
printf "[<a href=\"%s.html\">%s</a>]\n",lc($s),$s; |
| 22 |
} |
| 23 |
} |
| 24 |
print "</h3>\n"; |
| 25 |
} |
| 26 |
|
| 27 |
print "<p><hr><p>\n"; |
| 28 |
print "<table>\n"; |
| 29 |
|
| 30 |
foreach my $faq (@faq) { |
| 31 |
open $faq,"$faq.faq" or next; |
| 32 |
local $/ = "Q:"; |
| 33 |
local $_ = <$faq>; |
| 34 |
while (<$faq>) { |
| 35 |
if ($::hostname =~ /uni-stuttgart/) { |
| 36 |
while (s/\n.*sex.*\n/\n/i) {} |
| 37 |
} |
| 38 |
chomp; |
| 39 |
while (/\$([\w_]+)\$/) { |
| 40 |
$var = $1; |
| 41 |
$env = $ENV{$var} || ''; |
| 42 |
# s/\$$var\$/<code>$env<\/code>/g; |
| 43 |
s/\$$var\$/$env/g; |
| 44 |
}; |
| 45 |
($q,$a) = split /A:\s*/; |
| 46 |
$q =~ s/[\s\n]+$//; |
| 47 |
$q =~ s/^\s+//; |
| 48 |
$q =~ s! (/\w[\S]+/[\S]+)! <code>$1</code>!g; |
| 49 |
$a =~ s/[\s\n]+$/\n/; |
| 50 |
$a =~ s/^\s+//; |
| 51 |
while ($a =~ s/^(\s*)\*/$1<ul>\n$1<li>/m) { |
| 52 |
while ($a =~ s/(<li>.*\n\s*)\*/$1<li>/g) {} |
| 53 |
$a =~ s:(.*\n)(\s*)(<li>[^\n]+\n):$1$2$3$2</ul>\n:s |
| 54 |
} |
| 55 |
$a =~ s/\n\n/\n<p>\n/g; |
| 56 |
$a =~ s/([^>\n\\])\n/$1<br>\n/g; |
| 57 |
$a =~ s/<pre>(.+?)<\/pre>/pre($1)/ges; |
| 58 |
$a =~ s/\\\n/\n/g; |
| 59 |
# $a =~ s/^\s*<br>\s*//mg; |
| 60 |
$a =~ s/<([^\s<>\@]+\@[\w.-]+)>/<a href="mailto:$1"><$1><\/a>/g; |
| 61 |
$a =~ s! (/\w[\S]+/[\S]+)! <code>$1</code>!g; |
| 62 |
$a =~ s!"(.+?)"\[(https?://[\w-]+\.[^\s<>()]+)\]!<a href="$2">$1</a>!g or |
| 63 |
$a =~ s!(https?://[\w-]+\.[^\s<>()]+)!<a href="$1">[$1]</a>!g or |
| 64 |
$a =~ s!(https?://[^\s<>()]+)!<code>$1</code></a>!g; |
| 65 |
push @{$Q{$faq}},$q; |
| 66 |
push @{$A{$faq}},$a; |
| 67 |
} |
| 68 |
close $faq; |
| 69 |
} |
| 70 |
|
| 71 |
print "<table>\n"; |
| 72 |
|
| 73 |
foreach $s (sections($faq)) { |
| 74 |
|
| 75 |
$c = lc $s; |
| 76 |
$s = '' if $s eq 'Local'; |
| 77 |
$t = ''; |
| 78 |
$t = $s if $faq eq 'all'; |
| 79 |
|
| 80 |
for ($n = 0; $n < scalar(@{$Q{$c}}); $n++) { |
| 81 |
$q = ${Q{$c}[$n]}; |
| 82 |
$qa = anchor($q); |
| 83 |
printf '<tr valign=top><th align=left>'. |
| 84 |
'<a href="#%s%d" style="text-decoration: none">'. |
| 85 |
'<font color="black">%s Q%d</a>:'. |
| 86 |
'<td><a href="#%s">%s</a></tr>'."\n", |
| 87 |
$t,$n+1,$s,$n+1,$qa,$q; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
print "</table>\n"; |
| 92 |
print "<p><hr><p>\n"; |
| 93 |
|
| 94 |
foreach $s (sections($faq)) { |
| 95 |
|
| 96 |
$c = lc $s; |
| 97 |
$s = '' if $s eq 'Local'; |
| 98 |
$t = ''; |
| 99 |
$t = $s if $faq eq 'all'; |
| 100 |
|
| 101 |
for ($n = 0; $n < scalar(@{$Q{$c}}); $n++) { |
| 102 |
$q = ${Q{$c}[$n]}; |
| 103 |
$qa = anchor($q); |
| 104 |
print "<p>\n"; |
| 105 |
print "<table>\n"; |
| 106 |
printf "<tr valign=top><th>". |
| 107 |
"<a name=\"%s%d\">%s Q%d:</a>". |
| 108 |
"<a name=\"%s\"></a>". |
| 109 |
"<td><b>%s</b></tr>\n", |
| 110 |
$t,$n+1,$s,$n+1,$qa,$q; |
| 111 |
printf "<tr valign=top><th>%s A%d:<td>\n%s</tr>\n", |
| 112 |
$s,$n+1,${A{$c}[$n]}; |
| 113 |
print "</table>\n"; |
| 114 |
print "[<a href=\"#top\">↑ Questions</a>]\n"; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
print "<pre>\n"; |
| 119 |
print "\n" x 99; |
| 120 |
print "</pre>\n"; |
| 121 |
|
| 122 |
|
| 123 |
sub sections { |
| 124 |
my $faq = shift; |
| 125 |
if ($faq eq 'all') { |
| 126 |
return @sections; |
| 127 |
} else { |
| 128 |
return ucfirst($faq); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
sub pre { |
| 133 |
local $_ = shift; |
| 134 |
s/<br>//g; |
| 135 |
s/\s+$//; |
| 136 |
return "<pre>$_</pre>\n"; |
| 137 |
} |
| 138 |
|
| 139 |
sub anchor { |
| 140 |
local $_ = shift; |
| 141 |
s/<.+?>//g; |
| 142 |
s/\(.+?\)//g; |
| 143 |
s/\W/_/g; |
| 144 |
s/_+$//; |
| 145 |
return $_; |
| 146 |
} |
| 147 |
|
| 148 |
' '; |