Diff for /loncom/interface/lonhelp.pm between versions 1.2 and 1.16

version 1.2, 2002/07/08 20:47:41 version 1.16, 2005/02/17 08:29:42
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 Apache::lonnavmaps; # for advancedUser
   use Apache::lonlocal;
   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 49  sub processLabelName Line 53  sub processLabelName
 sub serveTex  sub serveTex
 {  {
     my ($tex, $r) = @_;      my ($tex, $r) = @_;
       my $html=&Apache::lonxml::xmlbegin();
 $r->print(<<HEADER);      my $bugs=&Apache::loncommon::help_open_bug('Documentation');
 <html>      my $header=&mt('LON-CAPA Help');
       my $footer=&mt('About LON-CAPA help and More Help');
       $r->print(<<HEADER);
   $html
     <head>      <head>
         <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"/>$header<hr />$bugs</h3>
     <!-- BEGIN -->      <!-- BEGIN -->
 HEADER  HEADER
   
     $r->print($tex);      $r->print($tex);
   
       if (Apache::lonnavmaps::advancedUser()) {
 $r->print(<<FOOTER);  $r->print(<<FOOTER);
     <!-- END -->      <!-- END -->
       <hr />
       <center><font size="-1"><a href="/adm/help/abouthelp.html">$footer</a></font></center>
       </body>
   </html>
   FOOTER
   } else {
       $r->print(<<FOOTER);
       <!-- END -->
     </body>      </body>
 </html>  </html>
 FOOTER  FOOTER
 }  }
   }
   
 # Render takes a tex fragment, transforms it for TtH, and returns the  # Render takes a tex fragment, transforms it for TtH, and returns the
 # HTML equivalent  # HTML equivalent
Line 83  sub render Line 102  sub render
     # LaTeX .aux files      # LaTeX .aux files
     # absolute paths for use with help.loncapa.org      # absolute paths for use with help.loncapa.org
     $tex =~ s|  \\ref\{([^}]*)\}      $tex =~ s|  \\ref\{([^}]*)\}
              |'\\begin{html}<a href="http://' . $serverroot ."/adm/help/".               |
                 if (not(exists($fragmentLabels{$1}))) {
             &Apache::lonnet::logthis("ERROR: $1 not a valid help label");
                 };
                '\\begin{html}<a href="http://' . $serverroot ."/adm/help/".
               substr($fragmentLabels{$1}, 0, -4) .                substr($fragmentLabels{$1}, 0, -4) .
               '.hlp#' . processLabelName($1) .                 '.hlp#' . processLabelName($1) . 
              '"><img src="http://' . $serverroot . '/adm/help/gif/smallHelp.gif" border="0" /></a>' .               '"><img src="http://' . $serverroot . '/adm/help/gif/smallHelp.gif" border="0" /></a>' .
              '\\end{html}'               '\\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="http://' . $serverroot . '/adm/help/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;
Line 115  sub handler Line 148  sub handler
      my $docroot = $r->dir_config('lonDocRoot');       my $docroot = $r->dir_config('lonDocRoot');
      my $serverroot = $ENV{'HTTP_HOST'};       my $serverroot = $ENV{'HTTP_HOST'};
   
      my $filename = substr ($ENV{'REQUEST_URI'} ,        my $filenames = &Apache::lonnet::unescape(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/);
   
        &Apache::lonlocal::get_language_handle($r);
   
        # 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) {
    if (-e $docroot.'/adm/help/tex/'.
        &Apache::lonlocal::current_language().'/'.
        $filename.'.tex') {
        $filename=&Apache::lonlocal::current_language().'/'.$filename;
    }
    (my $file = Apache::File->new($docroot
      . '/adm/help/tex/'.$filename.'.tex'))
        or return HTTP_NOT_FOUND;
    $tex .= join('', <$file>);
        }
   
        if ($ENV{'browser.mathml'}) {
    &Apache::loncommon::content_type($r,'text/xml');
    &tth::ttminit();
    if ($ENV{'browser.unicode'}) {
        &tth::ttmoptions('-L -u1');
    } else {
        &tth::ttmoptions('-L -u0');
    }
        } else {
    &Apache::loncommon::content_type($r,"text/html");
    &tth::tthinit();
    if ($ENV{'browser.unicode'}) {
        &tth::tthoptions('-L -u1');
    } else {
        &tth::tthoptions('-L -u0');
    }
        }
   
      (my $file = Apache::File->new($docroot . "/adm/help/tex/".$filename.'.tex'))       $r->send_http_header;
  or return 404;  
      my $tex = join('', <$file>);  
      $tex = render($tex, $docroot, $serverroot);       $tex = render($tex, $docroot, $serverroot);
      $r->content_type("text/html");  
      serveTex($tex, $r);       serveTex($tex, $r);
   
      return OK;       return OK;

Removed from v.1.2  
changed lines
  Added in v.1.16


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