[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm

raeburn raeburn at source.lon-capa.org
Wed Nov 2 15:12:41 EDT 2011


raeburn		Wed Nov  2 19:12:41 2011 EDT

  Modified files:              
    /loncom/publisher	loncfile.pm 
  Log:
  - Fix Construction breadcrumb trails for /adm/loncfile
  - use lonDocRoot perlvar in place of static string: '/home/httpd/html'
  - coding style
     - eliminate leaning toothpicks
  
  
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.112 loncom/publisher/loncfile.pm:1.113
--- loncom/publisher/loncfile.pm:1.112	Sun Oct 30 19:27:27 2011
+++ loncom/publisher/loncfile.pm	Wed Nov  2 19:12:40 2011
@@ -9,7 +9,7 @@
 #  and displays a page showing the results of the action.
 #
 #
-# $Id: loncfile.pm,v 1.112 2011/10/30 19:27:27 raeburn Exp $
+# $Id: loncfile.pm,v 1.113 2011/11/02 19:12:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -158,26 +158,28 @@
 sub URLToPath {
     my $Url = shift;
     &Debug($r, "UrlToPath got: $Url");
-    $Url=~ s/\/+/\//g;
-    $Url=~ s/^https?\:\/\/[^\/]+//;
-    $Url=~ s/^\///;
-    $Url='/home/httpd/html/'.$Url;
+    $Url=~ s{^https?\://[^/]+}{};
+    $Url=~ s{//+}{/}g;
+    $Url=~ s{^/}{};
+    $Url=$Apache::lonnet::perlvar{'lonDocRoot'}."/$Url";
     &Debug($r, "Returning $Url \n");
     return $Url;
 }
 
 sub url {
     my $fn=shift;
-    $fn=~s/^\/home\/httpd\/html//;
-    $fn=~s/\/\.\//\//g;
+    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+    $fn=~ s/^\Q$londocroot\E//;
+    $fn=~s{/\./}{/}g;
     $fn=&HTML::Entities::encode($fn,'<>"&');
     return $fn;
 }
 
 sub display {
     my $fn=shift;
-    $fn=~s/^\/home\/httpd\/html//;
-    $fn=~s/\/\.\//\//g;
+    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+    $fn=~s/^\Q$londocroot\E//;
+    $fn=~s{/\./}{/}g;
     return '<span class="LC_filename">'.$fn.'</span>';
 }
 
@@ -395,15 +397,16 @@
     my $error = '';
     if ($newfilename=~/^\//) {
 # absolute, simply add path
-	$newfilename='/home/httpd/html/res/'.$udom.'/'.$uname.'/';
+        my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+	$newfilename="$londocroot/res/$udom/$uname/";
     } else {
 	my $dir=$fn;
-	$dir=~s/\/[^\/]+$//;
+	$dir=~s{/[^/]+$}{};
 	$newfilename=$dir.'/'.$newfilename;
     }
-    $newfilename=~s://+:/:g; # remove duplicate /
-    while ($newfilename=~m:/\.\./:) {
-	$newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
+    $newfilename=~s{//+}{/}g; # remove duplicate /
+    while ($newfilename=~m{/\.\./}) {
+	$newfilename=~ s{/[^/]+/\.\./}{/}g; #remove dir/..
     }
     my ($authorname,$authordom)=&Apache::loncacc::constructaccess($newfilename);
     unless (($authorname) && ($authordom)) {
@@ -1437,13 +1440,11 @@
     } 
 
 # ----------------------------------------------------------- Start page output
-    my $uname;
-    my $udom;
 
-    ($uname,$udom)=&Apache::loncacc::constructaccess($fn);
+    my ($uname,$udom) = &Apache::loncacc::constructaccess($fn);
     &Debug($r, 
 	   "loncfile::handler constructaccess uname = $uname domain = $udom");
-    unless (($uname) && ($udom)) {
+    if (($uname eq '') || ($udom eq '')) {
 	$r->log_reason($uname.' at '.$udom.
 		       ' trying to manipulate file '.$env{'form.filename'}.
 		       ' ('.$fn.') - not authorized', 
@@ -1470,6 +1471,10 @@
 |;
 	$loaditem{'onload'} = "writeDone()";
     }
+
+    my $londocroot = $r->dir_config('lonDocRoot');
+    my $trailfile = $fn;
+    $trailfile =~ s{^/(priv/)}{$londocroot/$1};
     
     # Breadcrumbs
     &Apache::lonhtmlcommon::clear_breadcrumbs();
@@ -1488,7 +1493,7 @@
 					     {'add_entries' => \%loaditem,})
              .&Apache::lonhtmlcommon::breadcrumbs()
              .&Apache::loncommon::head_subbox(
-                  &Apache::loncommon::CSTR_pageheader())
+                  &Apache::loncommon::CSTR_pageheader($trailfile))
     );
   
     $r->print('<h3>'.&mt('Location').': '.&display($fn).'</h3>');




More information about the LON-CAPA-cvs mailing list