Annotation of loncom/interface/lonhelp.pm, revision 1.14
1.1 bowersj2 1: # The LearningOnline Network with CAPA
2: # .tex help system web server handler
3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26: # .tex file help handler
27: # YEAR=2002
28: # 7/4 Jeremy Bowers
29:
30: package Apache::lonhelp;
31:
32: use strict;
33: use Apache::Constants qw(:common :http);
1.5 albertel 34: use Apache::File();
35: use Apache::loncommon();
36: use Apache::lonacc();
37: use Apache::lontexconvert();
1.9 bowersj2 38: use Apache::lonnavmaps; # for advancedUser
1.11 albertel 39: use Apache::lonlocal;
1.5 albertel 40: use tth();
41: use GDBM_File();
1.1 bowersj2 42:
43: # This sub takes the name of a label in, and converts it to something
44: # that is a valid anchor name.
45: sub processLabelName
46: {
47: my ($name) = @_;
48: $name =~ tr/a-zA-Z0-9/_/cs;
49: return $name;
50: }
51:
52: # Serve out the Tex
53: sub serveTex
54: {
55: my ($tex, $r) = @_;
1.14 ! www 56: my $bugs=&Apache::loncommon::help_open_bug('Documentation');
! 57: my $header=&mt('LON-CAPA Help');
! 58: my $footer=&mt('About LON-CAPA help and More Help');
1.1 bowersj2 59: $r->print(<<HEADER);
60: <html>
61: <head>
62: <title>LON-CAPA Help</title>
63: </head>
64: <body bgcolor="#FFFFFF">
1.4 bowersj2 65: <h3 style="font: sans-serif"><img align="right"
1.14 ! www 66: src="/adm/help/gif/lonhelpheader.gif"/>$header<hr />$bugs</h3>
1.2 bowersj2 67: <!-- BEGIN -->
1.1 bowersj2 68: HEADER
69:
70: $r->print($tex);
71:
1.9 bowersj2 72: if (Apache::lonnavmaps::advancedUser()) {
1.1 bowersj2 73: $r->print(<<FOOTER);
1.2 bowersj2 74: <!-- END -->
1.4 bowersj2 75: <hr />
1.14 ! www 76: <center><font size="-1"><a href="/adm/help/abouthelp.html">$footer</a></font></center>
1.1 bowersj2 77: </body>
78: </html>
79: FOOTER
1.9 bowersj2 80: } else {
81: $r->print(<<FOOTER);
82: <!-- END -->
83: </body>
84: </html>
85: FOOTER
86: }
1.1 bowersj2 87: }
88:
89: # Render takes a tex fragment, transforms it for TtH, and returns the
90: # HTML equivalent
91: sub render
92: {
1.2 bowersj2 93: my ($tex, $docroot, $serverroot) = @_;
94: tie (my %fragmentLabels, 'GDBM_File', $docroot . '/adm/help/fragmentLabels.gdbm', 0, 0);
1.1 bowersj2 95:
96: # This tells TtH what to do with captions, labels, and other
97: # things
98: $tex = "\\documentclass{article}\n" . $tex;
99:
100: # We process these ourselves because TtH can't handle then without
101: # LaTeX .aux files
1.2 bowersj2 102: # absolute paths for use with help.loncapa.org
1.1 bowersj2 103: $tex =~ s| \\ref\{([^}]*)\}
1.2 bowersj2 104: |'\\begin{html}<a href="http://' . $serverroot ."/adm/help/".
1.1 bowersj2 105: substr($fragmentLabels{$1}, 0, -4) .
1.2 bowersj2 106: '.hlp#' . processLabelName($1) .
107: '"><img src="http://' . $serverroot . '/adm/help/gif/smallHelp.gif" border="0" /></a>' .
108: '\\end{html}'
1.1 bowersj2 109: |gxe;
110:
1.3 bowersj2 111: # Backslashes
112: $tex =~ s|\\textbackslash|###BACKSLASH###|g;
113:
1.1 bowersj2 114: # Figures leftover without captions
115: $tex =~ s| \\includegraphics(\[[^]]*\])*\{([^}]*)\}
1.2 bowersj2 116: | '\\begin{html}<img src="http://' . $serverroot . '/adm/help/gif/' . $2 . '.gif" border="2"'.
1.1 bowersj2 117: ' bordercolor="#000000"/>\\end{html}'
118: |gxe;
119:
1.3 bowersj2 120:
1.5 albertel 121: $tex=&Apache::lontexconvert::converted(\$tex);
122:
1.3 bowersj2 123: # Finish backslashes
124: $tex =~ s/###BACKSLASH###/'\\'/ge;
125:
126: # Fix the pretty quotes
127: $tex =~ s/('')|(``)/"/g; #" to get emacs syntax highlighter happy
1.1 bowersj2 128:
129: # For some reason all captions come out as "Figure 0:", so
130: # just duck the issue...
131:
132: $tex =~ s/Figure 0://g;
1.5 albertel 133: $tex.=$Apache::lontexconvert::errorstring;
1.1 bowersj2 134: untie %fragmentLabels;
135:
136: return $tex;
137: }
138:
139: sub handler
140: {
141: my $r = shift;
142:
1.2 bowersj2 143: my $docroot = $r->dir_config('lonDocRoot');
144: my $serverroot = $ENV{'HTTP_HOST'};
145:
1.12 www 146: my $filenames = &Apache::lonnet::unescape(substr ($ENV{'REQUEST_URI'} ,
147: rindex($ENV{'REQUEST_URI'}, '/') + 1, -4));
1.1 bowersj2 148:
149: # Security check on the file; the whole filename must consist
150: # of nothing but alphanums, ' ,, or ., or the file
151: # will be "not found", no matter what.
152:
1.7 bowersj2 153: return HTTP_NOT_FOUND if ($filenames !~ /\A[-0-9a-zA-z_'',:.]+\Z/);
1.1 bowersj2 154:
1.10 www 155: &Apache::lonlocal::get_language_handle($r);
156:
1.6 bowersj2 157: # Join together the tex files, return HTTP_NOT_FOUND if any of
158: # them are not found
159: my $tex = '';
1.7 bowersj2 160: # Since in insertlist.tab I want to specify multiple files,
161: # and insertlist.tab also uses commas, I need something else
1.8 bowersj2 162: # so replace : with ,
1.7 bowersj2 163: $filenames =~ s/:/,/g;
1.6 bowersj2 164: my @files = split(/,/, $filenames);
165:
166: for my $filename (@files) {
1.11 albertel 167: if (-e $docroot.'/adm/help/tex/'.
168: &Apache::lonlocal::current_language().'/'.
169: $filename.'.tex') {
170: $filename=&Apache::lonlocal::current_language().'/'.$filename;
1.10 www 171: }
1.6 bowersj2 172: (my $file = Apache::File->new($docroot
173: . '/adm/help/tex/'.$filename.'.tex'))
174: or return HTTP_NOT_FOUND;
175: $tex .= join('', <$file>);
176: }
1.5 albertel 177:
178: if ($ENV{'browser.mathml'}) {
1.10 www 179: &Apache::loncommon::content_type($r,'text/xml');
1.5 albertel 180: &tth::ttminit();
181: if ($ENV{'browser.unicode'}) {
182: &tth::ttmoptions('-L -u1');
183: } else {
184: &tth::ttmoptions('-L -u0');
185: }
186: } else {
1.10 www 187: &Apache::loncommon::content_type($r,"text/html");
1.5 albertel 188: &tth::tthinit();
189: if ($ENV{'browser.unicode'}) {
190: &tth::tthoptions('-L -u1');
191: } else {
192: &tth::tthoptions('-L -u0');
193: }
194: }
195:
1.13 www 196: $r->send_http_header;
1.2 bowersj2 197: $tex = render($tex, $docroot, $serverroot);
1.1 bowersj2 198: serveTex($tex, $r);
199:
200: return OK;
201: }
202:
203: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>