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

www lon-capa-cvs@mail.lon-capa.org
Thu, 22 Jun 2006 18:17:26 -0000


www		Thu Jun 22 14:17:26 2006 EDT

  Modified files:              
    /loncom/interface	lonsource.pm 
  Log:
  Remember the original source in a meta tag, so it can survive downloading
  and uploading, too.
  
  
Index: loncom/interface/lonsource.pm
diff -u loncom/interface/lonsource.pm:1.16 loncom/interface/lonsource.pm:1.17
--- loncom/interface/lonsource.pm:1.16	Wed Mar 15 14:41:26 2006
+++ loncom/interface/lonsource.pm	Thu Jun 22 14:17:23 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Souce Code handler
 #
-# $Id: lonsource.pm,v 1.16 2006/03/15 19:41:26 albertel Exp $
+# $Id: lonsource.pm,v 1.17 2006/06/22 18:17:23 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,6 +40,7 @@
 use Apache::File;
 use Apache::lonlocal;
 use HTML::Entities;
+use LONCAPA;
 
 sub make_link {
     my ($filename, $listname) = @_;
@@ -166,7 +167,7 @@
     }
     $r->print("<br /><b>Copying File</b>");
     my $problem_filename = $Apache::lonnet::perlvar{'lonDocRoot'}.$filename;
-    my $file_output = &Apache::lonnet::getfile($problem_filename);
+    my $file_output = &includemeta(&Apache::lonnet::getfile($problem_filename),$filename);
     my $fs=Apache::File->new(">$path_to_new_file");
     if (defined($fs)) {
         print $fs $file_output;
@@ -178,9 +179,7 @@
 
 sub print_item {
     my ($r, $filename) = @_;
-    $filename = $Apache::lonnet::perlvar{'lonDocRoot'}.$filename;
-    &Apache::lonnet::logthis("print_item filename = $filename");
-    my $file_output = &Apache::lonnet::getfile($filename);
+    my $file_output = &includemeta(&Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$filename),$filename);
     my $count=0;
     my $maxlength=-1;
     foreach (split ("\n", $file_output)) {
@@ -198,6 +197,22 @@
 
 }
 
+sub includemeta {
+    my ($file_output,$orgfilename)=@_;
+    my $escfilename=&escape($orgfilename);
+    my $copytime=time;
+    if ($file_output=~/\<meta\s*name\=\"isbasedonres\"/i) {
+	$file_output=~s/(\<meta\s*name\=\"isbasedonres\"\s*content\=\"[^\"]*)\"/$1\,\Q$escfilename\E\"/i;
+    } else {
+	$file_output=~s/(\<(?:html|problem)[^\>]*\>)/$1\n\<meta name=\"isbasedonres\" content=\"\Q$escfilename\E\" \/\>/i;
+    }
+    if ($file_output=~/\<meta\s*name\=\"isbasedontime\"/i) {
+	$file_output=~s/(\<meta\s*name\=\"isbasedontime\"\s*content\=\"[^\"]*)\"/$1\,\Q$copytime\E\"/i;
+    } else {
+	$file_output=~s/(\<(?:html|problem)[^\>]*\>)/$1\n\<meta name=\"isbasedontime\" content=\"\Q$copytime\E\" \/\>/i;
+    }
+    return $file_output;
+}
 
 sub handler {
     my $r=shift;