--- loncom/interface/londocs.pm 2005/07/24 19:31:00 1.194 +++ loncom/interface/londocs.pm 2005/08/01 17:24:18 1.200 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.194 2005/07/24 19:31:00 raeburn Exp $ +# $Id: londocs.pm,v 1.200 2005/08/01 17:24:18 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -249,7 +249,6 @@ sub dumpcourse { # ------------------------------------------------------ Generate "export" button sub exportbutton { - return ''; return ''. ''. @@ -491,10 +490,21 @@ sub create_ims_store { ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'. ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'. ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n". +' + + + + '.$env{'request.course.id'}.' + + '.$env{'course.'.$env{'request.course.id'}.'.description'}.' + + + + '."\n". ' '."\n". ' '."\n". -' '.$env{'request.'.$env{'request.course.id'}.'.description'}.'' +' '.$env{'course.'.$env{'request.course.id'}.'.description'}.'' } else { $$outcome .= 'An error occurred opening the IMS manifest file.
' ; @@ -542,7 +552,6 @@ sub build_package { $count = 0; my $imsresources; my $pkgdepth; - my $included = 0; while ($curRes = $it->next()) { if ($curRes == $it->BEGIN_MAP()) { $prevdepth = $depth; @@ -565,10 +574,13 @@ sub build_package { unless ($curRes->is_sequence()) { $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"'; } - if (($depth <= $prevdepth) && ($count > 1) && ($included)) { - print $ims_manifest "\n".' '."\n"; + my $step = $prevdepth - $depth; + if (($step >= 0) && ($count > 1)) { + while ($step >= 0) { + print $ims_manifest "\n".' '."\n"; + $step --; + } } - $included = 1; $prevdepth = $depth; my $itementry = @@ -610,8 +622,6 @@ sub build_package { } } $pkgdepth = $depth; - } else { - $included = 0; } } } @@ -646,7 +656,6 @@ sub process_content { my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_; my $content_type; my $message; -# find where user is author or co-author my @uploads = (); if ($curRes->is_sequence()) { $content_type = 'sequence'; @@ -700,6 +709,7 @@ sub process_content { if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) { $canedit= 1; } +# only include problem code where current user is author if ($canedit) { $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource'); } else { @@ -748,11 +758,13 @@ sub replicate_content { if ($copiedfile = Apache::File->new('>'.$destination)) { my $content; if ($caller eq 'resource') { - $content = &Apache::lonnet::getfile('/home/httpd/html/res/'.$url); + my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'; + my $filepath = &Apache::lonnet::filelocation($respath,$url); + $content = &Apache::lonnet::getfile($filepath); if ($content eq -1) { $$message = 'Could not copy file '.$filename; } else { - &extract_media($content,$count,$tempexport,$href,'resource'); + &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource'); $repstatus = 'ok'; } } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') { @@ -760,10 +772,10 @@ sub replicate_content { $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode); if ($repstatus eq 'ok') { if ($url =~ /\.html?$/i) { - &extract_media(\$content,$count,$tempexport,$href,'uploaded'); + &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded'); } } else { - $$message = 'Could not render '.$url.' server message - '.$rtncode; + $$message = 'Could not render '.$url.' server message - '.$rtncode."
\n"; } } elsif ($caller eq 'noedit') { # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. @@ -775,23 +787,85 @@ sub replicate_content { } close($copiedfile); } else { - $$message = 'Could not open destination file for '.$filename."\n"; + $$message = 'Could not open destination file for '.$filename."
\n"; } } else { - $$message = 'Could not determine name of file for '.$symb."\n"; + $$message = 'Could not determine name of file for '.$symb."
\n"; } if ($repstatus eq 'ok') { - $content_name = $count.'/'.$filename; + $content_name = 'resources/'.$count.'/'.$filename; } return $content_name; } sub extract_media { - my ($content,$count,$tempexport,$href,$caller) = @_; -# @$href will contain path to any embedded resources in the content. -# For LON-CAPA problems this would be images. applets etc. -# For uploaded HTML files this would be images etc. -# paths will be in the form $count/res/$file, and urls in the $content will be rewritten with the new paths. + my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_; + my ($dirpath,$container); + my %allfiles = (); + my %codebase = (); + if ($url =~ m-(.*/)([^/]+)$-) { + $dirpath = $1; + $container = $2; + } else { + $dirpath = $url; + $container = ''; + } + &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content); + foreach my $embed_file (keys(%allfiles)) { + my $filename; + if ($embed_file =~ m#([^/]+)$#) { + $filename = $1; + } else { + $filename = $embed_file; + } + my $newname = 'res/'.$filename; + my ($rtncode,$embed_content,$repstatus); + my $embed_url; + if ($embed_file =~ m-^/-) { + $embed_url = $embed_file; # points to absolute path + } else { + if ($embed_file =~ m-https?://-) { + next; # points to url + } else { + $embed_url = $dirpath.$embed_file; # points to relative path + } + } + if ($caller eq 'resource') { + my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'; + my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); + $embed_content = &Apache::lonnet::getfile($embed_path); + unless ($embed_content eq -1) { + $repstatus = 'ok'; + } + } elsif ($caller eq 'uploaded') { + + $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode); + } + if ($repstatus eq 'ok') { + my $destination = $tempexport.'/resources/'.$count.'/res'; + if (!-e "$destination") { + mkdir($destination,0755); + } + $destination .= '/'.$filename; + my $copiedfile; + if ($copiedfile = Apache::File->new('>'.$destination)) { + print $copiedfile $embed_content; + push @{$href}, 'resources/'.$count.'/res/'.$filename; + my $attrib_regexp = ''; + if (@{$allfiles{$embed_file}} > 1) { + $attrib_regexp = join('|',@{$allfiles{$embed_file}}); + } else { + $attrib_regexp = $allfiles{$embed_file}[0]; + } + $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi; + if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) { + $$content =~ s#\Q$embed_file\E#$newname#gi; + } + } + } else { + $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."
\n"; + } + } return; } @@ -812,9 +886,9 @@ sub store_template { close($storetemplate); } if ($content_type eq 'external') { - return $count.'/'.$content_type.'.html'; + return 'resources/'.$count.'/'.$content_type.'.html'; } else { - return $count.'/'.$content_type.'.xml'; + return 'resources/'.$count.'/'.$content_type.'.xml'; } } } @@ -1288,9 +1362,12 @@ sub process_secondary_uploads { my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_; my $folder=$env{'form.folder'}; my $destination = 'docs/'; - if ($folder eq 'default') { + if ($folder =~ /^supplemental/) { + $destination = 'supplemental/'; + } + if (($folder eq 'default') || ($folder eq 'supplemental')) { $destination .= 'default/'; - } elsif ($folder =~ /^default_(\d+)$/) { + } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) { $destination .= $1.'/'; } $destination .= $newidx; @@ -2660,7 +2737,15 @@ ENDBLOCK
-
$lt{'comment'}:
+
+
+ + + +

+$lt{'comment'}: