--- loncom/interface/londocs.pm 2025/01/03 02:10:55 1.716
+++ loncom/interface/londocs.pm 2025/01/07 21:01:37 1.722
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.716 2025/01/03 02:10:55 raeburn Exp $
+# $Id: londocs.pm,v 1.722 2025/01/07 21:01:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -884,7 +884,7 @@ ENDJS
if (keys(%tocopy)) {
my (%resdirs,%resfiles);
&Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
- my ($notopdir,%newdir,%newfile,%checkdeps);
+ my ($notopdir,%newdir,%newfile,%checkdeps,%newresfile);
$r->print('
'.&mt('Copy to: [_1]',
''.$desturl.'/'.$subdir.'').
'
'."\n");
@@ -995,231 +995,164 @@ ENDJS
''.$desturl.'/'.$subdir.'/'.$file.'').
''."\n");
} elsif (($src ne '') && ($dest ne '')) {
- if ($is_course_home) {
- if (&File::Copy::copy($src,$dest)) {
- $newfile{$file} = 1;
- }
- } else {
- if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
- $newfile{$file} = 1;
- }
- }
- if ($newfile{$file}) {
- my $gotmeta;
- if ($is_course_home) {
- if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
- if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
- $gotmeta = 1;
- }
- }
- } else {
- if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
- $gotmeta = 1;
+ my $ressrc = $docroot.$resurl.'/'.$file;
+ my $ressrcmeta = $ressrc.'.meta';
+ my ($ext) = ($file =~ /\.(\w+)$/);
+ my $embstyle=&Apache::loncommon::fileembstyle($ext);
+ my ($getres,$getresmeta);
+ if ($respublish) {
+ if ($path eq '') {
+ if ((ref($resfiles{'/'}) eq 'HASH') &&
+ (exists($resfiles{'/'}{$fname}))) {
+ $getres = 1;
+ $getresmeta = 1;
}
+ } elsif ((ref($resfiles{$path}) eq 'HASH') &&
+ (exists($resfiles{$path}{$fname}))) {
+ $getres = 1;
+ $getresmeta = 1;
}
- if ($gotmeta) {
- if (open(my $fh,'<',$dest.'.meta')) {
- my ($output,$now,$setsourceavail);
- $now = time;
- if (($file =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($file =~ /$LONCAPA::assess_re/)) {
- $setsourceavail = 1;
- }
- while (my $line=<$fh>) {
- chomp($line);
- if ($line eq "$coursenum:$coursedom") {
- $output .= "$ca:$cd\n";
- } elsif ($line eq 'custom') {
- $output .= "$copyright\n";
- } elsif ($line =~ m{^\d+$}) {
- $output .= "$now\n";
- } elsif ($line eq "/res/$coursedom/$coursenum/default.rights") {
- $output .= "$customdistfile\n";
- } elsif ($line =~ m{^(open|closed)$}) {
- if ($setsourceavail) {
- $output .= "$sourceavail\n";
+ }
+ if ($is_course_home) {
+ my ($needpriv,$needprivmeta);
+ if ($respublish) {
+ if ($getres) {
+ if (&Apache::londiff::are_different_files($src,$ressrc)) {
+ $needpriv = 1;
+ if (&File::Copy::copy($ressrc,$dest)) {
+ if ($embstyle eq 'ssi') {
+ &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
}
- } 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);
- }
+ }
+ } else {
+ if (&File::Copy::copy($src,$dest)) {
+ $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
+ if ($embstyle eq 'ssi') {
+ &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
}
- if ($changed) {
- $output .= ''.join(',',@newdeps).''."\n";
+ }
+ }
+ } else {
+ $needpriv = 1;
+ }
+ if ($getresmeta) {
+ if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
+ if (&Apache::londiff::are_different_files($src.'.meta',$ressrc.'.meta')) {
+ if (&File::Copy::copy($ressrc.'.meta',$dest.'.meta')) {
+ &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
+ $customdistfile,$sourceavail,\%checkdeps);
}
+ $needprivmeta = 1;
} else {
- $output .= "$line\n";
+ if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
+ &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
+ $customdistfile,$sourceavail,\%checkdeps);
+ }
}
}
- close($fh);
- if (open(my $fh,'>',$dest.'.meta')) {
- print $fh $output;
- close($fh);
+ }
+ if ($getres) {
+ my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
+ if (-e $dest) {
+ my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
+ if (-e $destresfile) {
+ $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
+ }
}
}
+ } else {
+ $needpriv = 1;
+ if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
+ $needprivmeta = 1;
+ }
}
- my ($ext) = ($file =~ /\.(\w+)$/);
- my $embstyle=&Apache::loncommon::fileembstyle($ext);
- if ($embstyle eq 'ssi') {
- my $outstring='';
- my $changes = 0;
- my @parser;
- $parser[0]=HTML::LCParser->new($dest);
- $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