Diff for /loncom/interface/lonhelp.pm between versions 1.1 and 1.7

version 1.1, 2002/07/05 16:12:31 version 1.7, 2003/07/29 15:06:47
Line 31  package Apache::lonhelp; Line 31  package Apache::lonhelp;
   
 use strict;  use strict;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Apache::File;  use Apache::File();
 use Apache::loncommon;  use Apache::loncommon();
 use tth;  use Apache::lonacc();
 use GDBM_File;  use Apache::lontexconvert();
   use tth();
   use GDBM_File();
   
 # This sub takes the name of a label in, and converts it to something  # This sub takes the name of a label in, and converts it to something
 # that is a valid anchor name.  # that is a valid anchor name.
Line 56  $r->print(<<HEADER); Line 58  $r->print(<<HEADER);
         <title>LON-CAPA Help</title>          <title>LON-CAPA Help</title>
     </head>      </head>
     <body bgcolor="#FFFFFF">      <body bgcolor="#FFFFFF">
       <h3 style="font: sans-serif"><img align="right"
       src="/adm/help/gif/lonhelpheader.gif"/>LON-CAPA Help<hr /></h3>
       <!-- BEGIN -->
 HEADER  HEADER
   
     $r->print($tex);      $r->print($tex);
   
 $r->print(<<FOOTER);  $r->print(<<FOOTER);
       <!-- END -->
       <hr />
       <center><font size="-1"><a href="/adm/help/abouthelp.html">About
       LON-CAPA help and More Help</a></font></center>
     </body>      </body>
 </html>  </html>
 FOOTER  FOOTER
Line 70  FOOTER Line 79  FOOTER
 # HTML equivalent  # HTML equivalent
 sub render   sub render 
 {  {
     my ($tex) = @_;      my ($tex, $docroot, $serverroot) = @_;
     tie (my %fragmentLabels, 'GDBM_File', '/home/httpd/html/adm/help/fragmentLabels.gdbm', 0, 0);      tie (my %fragmentLabels, 'GDBM_File', $docroot . '/adm/help/fragmentLabels.gdbm', 0, 0);
   
     # This tells TtH what to do with captions, labels, and other      # This tells TtH what to do with captions, labels, and other
     # things      # things
Line 79  sub render Line 88  sub render
   
     # We process these ourselves because TtH can't handle then without      # We process these ourselves because TtH can't handle then without
     # LaTeX .aux files      # LaTeX .aux files
       # absolute paths for use with help.loncapa.org
     $tex =~ s|  \\ref\{([^}]*)\}      $tex =~ s|  \\ref\{([^}]*)\}
              |'\\href{' .                |'\\begin{html}<a href="http://' . $serverroot ."/adm/help/".
               substr($fragmentLabels{$1}, 0, -4) .                substr($fragmentLabels{$1}, 0, -4) .
               '#' . processLabelName($1) .                 '.hlp#' . processLabelName($1) . 
              '}{graphic}'               '"><img src="http://' . $serverroot . '/adm/help/gif/smallHelp.gif" border="0" /></a>' .
                '\\end{html}'
              |gxe;               |gxe;
   
       # Backslashes
       $tex =~ s|\\textbackslash|###BACKSLASH###|g;
   
     # Figures leftover without captions      # Figures leftover without captions
     $tex =~ s|  \\includegraphics(\[[^]]*\])*\{([^}]*)\}      $tex =~ s|  \\includegraphics(\[[^]]*\])*\{([^}]*)\}
              |  '\\begin{html}<img src="gif/' . $2 . '.gif" border="2"'.               |  '\\begin{html}<img src="http://' . $serverroot . '/adm/help/gif/' . $2 . '.gif" border="2"'.
                 ' bordercolor="#000000"/>\\end{html}'                  ' bordercolor="#000000"/>\\end{html}'
              |gxe;               |gxe;
   
     $tex = tth::tth($tex);  
       $tex=&Apache::lontexconvert::converted(\$tex);
       
       # Finish backslashes
       $tex =~ s/###BACKSLASH###/'\\'/ge;
    
       # Fix the pretty quotes
       $tex =~ s/('')|(``)/&quot;/g; #" to get emacs syntax highlighter happy
   
     # For some reason all captions come out as "Figure 0:", so      # For some reason all captions come out as "Figure 0:", so
     # just duck the issue...      # just duck the issue...
   
     $tex =~ s/Figure 0://g;      $tex =~ s/Figure 0://g;
        $tex.=$Apache::lontexconvert::errorstring;
     untie %fragmentLabels;      untie %fragmentLabels;
   
     return $tex;      return $tex;
 }  }
   
 # UNCOMMENT FOR HANDLER ONLY  
 sub handler  sub handler
 {  {
      my $r = shift;       my $r = shift;
   
      my $filename = substr ($ENV{'REQUEST_URI'} ,        my $docroot = $r->dir_config('lonDocRoot');
        my $serverroot = $ENV{'HTTP_HOST'};
   
        my $filenames = substr ($ENV{'REQUEST_URI'} , 
     rindex($ENV{'REQUEST_URI'}, '/') + 1, -4);      rindex($ENV{'REQUEST_URI'}, '/') + 1, -4);
             
      # Security check on the file; the whole filename must consist       # Security check on the file; the whole filename must consist
      # of nothing but alphanums, ' ,, or ., or the file       # of nothing but alphanums, ' ,, or ., or the file
      # will be "not found", no matter what.       # will be "not found", no matter what.
             
      return 404 if ($filename !~ /\A[-0-9a-zA-z_'',.]+\Z/);       return HTTP_NOT_FOUND if ($filenames !~ /\A[-0-9a-zA-z_'',:.]+\Z/);
   
        # Join together the tex files, return HTTP_NOT_FOUND if any of
        # them are not found
        my $tex = '';
        # Since in insertlist.tab I want to specify multiple files,
        # and insertlist.tab also uses commas, I need something else
        # so replace ! with ,
        $filenames =~ s/:/,/g;
        my @files = split(/,/, $filenames);
        
        for my $filename (@files) {
    (my $file = Apache::File->new($docroot
      . '/adm/help/tex/'.$filename.'.tex'))
        or return HTTP_NOT_FOUND;
    $tex .= join('', <$file>);
        }
   
        # get me my environment if it exists
        &Apache::lonacc::handler($r);
   
        if ($ENV{'browser.mathml'}) {
    $r->content_type('text/xml');
    &tth::ttminit();
    if ($ENV{'browser.unicode'}) {
        &tth::ttmoptions('-L -u1');
    } else {
        &tth::ttmoptions('-L -u0');
    }
        } else {
    $r->content_type("text/html");
    &tth::tthinit();
    if ($ENV{'browser.unicode'}) {
        &tth::tthoptions('-L -u1');
    } else {
        &tth::tthoptions('-L -u0');
    }
        }
   
      (my $file = Apache::File->new("/home/httpd/html/adm/help/tex/".$filename.'.tex'))       $tex = render($tex, $docroot, $serverroot);
  or return 404;  
      my $tex = join('', <$file>);  
      $tex = render($tex);  
      $r->content_type("text/html");  
      serveTex($tex, $r);       serveTex($tex, $r);
   
      return OK;       return OK;

Removed from v.1.1  
changed lines
  Added in v.1.7


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>