[LON-CAPA-cvs] cvs: loncom /interface lonhelp.pm

bowersj2 lon-capa-cvs@mail.lon-capa.org
Mon, 08 Jul 2002 20:47:41 -0000


bowersj2		Mon Jul  8 16:47:41 2002 EDT

  Modified files:              
    /loncom/interface	lonhelp.pm 
  Log:
  Changes for integration with FAQ-O-Matic. Actual graphic loaded for
  links instead of the word "graphic". Path to html directory no longer
  hardcoded. Links and image hrefs fully qualified now.
  
  
  
Index: loncom/interface/lonhelp.pm
diff -u loncom/interface/lonhelp.pm:1.1 loncom/interface/lonhelp.pm:1.2
--- loncom/interface/lonhelp.pm:1.1	Fri Jul  5 12:12:31 2002
+++ loncom/interface/lonhelp.pm	Mon Jul  8 16:47:41 2002
@@ -56,11 +56,13 @@
         <title>LON-CAPA Help</title>
     </head>
     <body bgcolor="#FFFFFF">
+    <!-- BEGIN -->
 HEADER
 
     $r->print($tex);
 
 $r->print(<<FOOTER);
+    <!-- END -->
     </body>
 </html>
 FOOTER
@@ -70,8 +72,8 @@
 # HTML equivalent
 sub render 
 {
-    my ($tex) = @_;
-    tie (my %fragmentLabels, 'GDBM_File', '/home/httpd/html/adm/help/fragmentLabels.gdbm', 0, 0);
+    my ($tex, $docroot, $serverroot) = @_;
+    tie (my %fragmentLabels, 'GDBM_File', $docroot . '/adm/help/fragmentLabels.gdbm', 0, 0);
 
     # This tells TtH what to do with captions, labels, and other
     # things
@@ -79,16 +81,18 @@
 
     # We process these ourselves because TtH can't handle then without
     # LaTeX .aux files
+    # absolute paths for use with help.loncapa.org
     $tex =~ s|  \\ref\{([^}]*)\}
-             |'\\href{' . 
+             |'\\begin{html}<a href="http://' . $serverroot ."/adm/help/".
               substr($fragmentLabels{$1}, 0, -4) .
-              '#' . processLabelName($1) . 
-             '}{graphic}'
+              '.hlp#' . processLabelName($1) . 
+             '"><img src="http://' . $serverroot . '/adm/help/gif/smallHelp.gif" border="0" /></a>' .
+             '\\end{html}'
              |gxe;
 
     # Figures leftover without captions
     $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}'
              |gxe;
 
@@ -104,11 +108,13 @@
     return $tex;
 }
 
-# UNCOMMENT FOR HANDLER ONLY
 sub handler
 {
      my $r = shift;
 
+     my $docroot = $r->dir_config('lonDocRoot');
+     my $serverroot = $ENV{'HTTP_HOST'};
+
      my $filename = substr ($ENV{'REQUEST_URI'} , 
 			    rindex($ENV{'REQUEST_URI'}, '/') + 1, -4);
      
@@ -118,10 +124,10 @@
      
      return 404 if ($filename !~ /\A[-0-9a-zA-z_'',.]+\Z/);
 
-     (my $file = Apache::File->new("/home/httpd/html/adm/help/tex/".$filename.'.tex'))
+     (my $file = Apache::File->new($docroot . "/adm/help/tex/".$filename.'.tex'))
 	 or return 404;
      my $tex = join('', <$file>);
-     $tex = render($tex);
+     $tex = render($tex, $docroot, $serverroot);
      $r->content_type("text/html");
      serveTex($tex, $r);