--- loncom/interface/londocs.pm 2024/12/20 15:15:04 1.712
+++ loncom/interface/londocs.pm 2024/12/22 03:12:53 1.713
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.712 2024/12/20 15:15:04 raeburn Exp $
+# $Id: londocs.pm,v 1.713 2024/12/22 03:12:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -48,6 +48,7 @@ use Apache::lonpublisher();
use Apache::loncourserespicker();
use HTML::Entities;
use HTML::TokeParser;
+use HTML::LCParser;
use GDBM_File;
use File::MMagic;
use File::Copy;
@@ -804,8 +805,7 @@ ENDJS
return '';
}
if (keys(%tocopy)) {
- my $mm = new File::MMagic;
- my ($notopdir,%newdir,%newfile);
+ my ($notopdir,%newdir,%newfile,%checkdeps);
$r->print('
'.&mt('Copy to: [_1]',
''.$desturl.'/'.$subdir.'').
'
'."\n");
@@ -896,13 +896,191 @@ ENDJS
$newfile{$file} = 1;
if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
-#FIXME set distribution/copyright to author's default instead of custom. set author to $ca:$cd instead of $cdom:$cnum
+ if (open(my $fh,'<',$dest.'.meta')) {
+ my ($output,$now);
+ $now = time;
+ while (my $line=<$fh>) {
+ chomp($line);
+ if ($line eq "$coursenum:$coursedom") {
+ $output .= "$ca:$cd\n";
+ } elsif ($line eq 'custom') {
+ $output .= "default\n";
+ } elsif ($line =~ m{^\d+$}) {
+ $output .= "$now\n";
+ } elsif ($line eq "/res/$coursedom/$coursenum/default.rights") {
+ $output .= "\n";
+ } elsif ($line eq "$coursedom") {
+ $output .= "$cd\n";
+ } elsif ($line =~ m{^\d+$}) {
+ $output .= "$now\n";
+ } elsif ($line =~ m{^$match_username:$match_domain$}) {
+ $output .= "$env{'user.name'}:$env{'user.domain'}\n";
+ } elsif ($line eq "$coursenum:$coursedom") {
+ $output .= "$ca:$cd\n";
+ } elsif ($line =~ m{^(.+)$}) {
+ my @deps = split(/\s*,\s*/,$1);
+ my @newdeps;
+ my $changed = 0;
+ foreach my $dep (@deps) {
+ if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
+ my $rest = $1;
+ push(@newdeps,"/res/$cd/$ca/$rest");
+ $checkdeps{$rest} = 1;
+ $changed ++;
+ } else {
+ push(@newdeps,$dep);
+ }
+ }
+ if ($changed) {
+ $output .= ''.join(',',@newdeps).''."\n";
+ }
+ } else {
+ $output .= "$line\n";
+ }
+ }
+ close($fh);
+ if (open(my $fh,'>',$dest.'.meta')) {
+ print $fh $output;
+ close($fh);
+ }
+ }
}
}
my ($ext) = ($file =~ /\.(\w+)$/);
my $embstyle=&Apache::loncommon::fileembstyle($ext);
if ($embstyle eq 'ssi') {
-#FIXME in any src or href attributes replace /res/$coursedom/$coursenum/ with /res/$cd/$ca/$subdir
+ my $outstring='';
+ my $changes = 0;
+ my @parser;
+ $parser[0]=HTML::LCParser->new($src);
+ $parser[-1]->xml_mode(1);
+ my $token;
+ while (@parser) {
+ while ($token=$parser[-1]->get_token) {
+ if ($token->[0] eq 'S') {
+ my $tag=$token->[1];
+ my $lctag=lc($tag);
+ my %parms=%{$token->[2]};
+ foreach my $type ('src','href','background','bgimg') {
+ foreach my $key (keys(%parms)) {
+ if ($key =~ /^$type$/i) {
+ next if (($lctag eq 'img') && ($type eq 'src') &&
+ ($parms{$key} =~ m{^data\:image/gif;base64,}));
+ if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
+ $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
+ $changes ++;
+ }
+ }
+ }
+ }
+ # probably a image type