--- loncom/publisher/lonpublisher.pm 2009/04/03 16:41:13 1.255
+++ loncom/publisher/lonpublisher.pm 2024/06/01 22:41:28 1.295.2.1.2.2
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.255 2009/04/03 16:41:13 bisitz Exp $
+# $Id: lonpublisher.pm,v 1.295.2.1.2.2 2024/06/01 22:41:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -66,10 +66,10 @@ invocation by F:
=head1 OVERVIEW
-Authors can only write-access the C~authorname/> space. They can
-copy resources into the resource area through the publication step,
-and move them back through a recover step. Authors do not have direct
-write-access to their resource space.
+Authors can only write-access the C space.
+They can copy resources into the resource area through the
+publication step, and move them back through a recover step.
+Authors do not have direct write-access to their resource space.
During the publication step, several events will be
triggered. Metadata is gathered, where a wizard manages default
@@ -102,8 +102,6 @@ to publication space.
Many of the undocumented subroutines implement various magical
parsing shortcuts.
-=over 4
-
=cut
######################################################################
@@ -121,7 +119,6 @@ use HTML::LCParser;
use HTML::Entities;
use Encode::Encoder;
use Apache::lonxml;
-use Apache::loncacc;
use DBI;
use Apache::lonnet;
use Apache::loncommon();
@@ -150,6 +147,8 @@ my $lock;
=pod
+=over 4
+
=item B
Evaluates a string that contains metadata. This subroutine
@@ -201,12 +200,12 @@ sub metaeval {
if (defined($token->[2]->{'name'})) {
$unikey.="\0".$token->[2]->{'name'};
}
- foreach (@{$token->[3]}) {
- $metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
+ foreach my $item (@{$token->[3]}) {
+ $metadatafields{$unikey.'.'.$item}=$token->[2]->{$item};
if ($metadatakeys{$unikey}) {
- $metadatakeys{$unikey}.=','.$_;
+ $metadatakeys{$unikey}.=','.$item;
} else {
- $metadatakeys{$unikey}=$_;
+ $metadatakeys{$unikey}=$item;
}
}
my $newentry=$parser->get_text('/'.$entry);
@@ -266,9 +265,9 @@ sub metaread {
my ($logfile,$fn,$prefix)=@_;
unless (-e $fn) {
print($logfile 'No file '.$fn."\n");
- return '
';
}
#########################################
@@ -294,8 +293,8 @@ sub coursedependencies {
my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
$aauthor,$regexp);
my %courses=();
- foreach (keys %evaldata) {
- if ($_=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
+ foreach my $item (keys(%evaldata)) {
+ if ($item=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
$courses{$1}=1;
}
}
@@ -319,8 +318,12 @@ string which presents the form field (fo
=item B
+=item B
+
=item B
+=item B
+
=item B
=back
@@ -368,7 +371,7 @@ sub hiddenfield {
sub checkbox {
my ($name,$text)=@_;
- return "\n
'.&mt('Warning!').
- '
'.
- &mt('Copyright/distribution option "Private" is no longer supported. Select another option from below. Consider "Custom Rights" for maximum control over the usage of your resource.').'
';
+ $scrout.='
'.&mt('Warning!').' '
+ .&mt('Copyright/distribution option "Private" is no longer supported. Select another option from below. Consider "Custom Rights" for maximum control over the usage of your resource.')
+ .'
';
}
# ------------------------------------------------------- Now have all metadata
@@ -1227,14 +1378,14 @@ sub publish {
.''
.'';
+ .'" /> '.&mt('Cancel').'';
}
$intr_scrout.=&Apache::lonhtmlcommon::start_pick_box();
$intr_scrout.=
&hiddenfield('phase','two').
&hiddenfield('filename',$env{'form.filename'}).
&hiddenfield('allmeta',&escape($allmeta)).
- &hiddenfield('dependencies',join(',',keys %allow));
+ &hiddenfield('dependencies',join(',',keys(%allow)));
unless ($env{'form.makeobsolete'}) {
$intr_scrout.=
&textfield('Title','title',$metadatafields{'title'}).
@@ -1401,9 +1552,9 @@ END
(&Apache::loncommon::source_copyrightids));
# $intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights');
my $uctitle=&mt('Obsolete');
- my $obsolete_checked=($metadatafields{'obsolete'})?' checked="1" ':'';
+ my $obsolete_checked=($metadatafields{'obsolete'})?' checked="checked"':'';
$intr_scrout.="\n".&Apache::lonhtmlcommon::row_title($uctitle)
- .''
+ .''
.&Apache::lonhtmlcommon::row_closure(1);
$intr_scrout.=&text_with_browse_field('Suggested Replacement for Obsolete File',
'obsoletereplacement',
@@ -1479,6 +1630,8 @@ Returns:
0: fail
1: success
+=back
+
=cut
#'stupid emacs
@@ -1532,7 +1685,33 @@ sub phasetwo {
%metadatakeys=();
&metaeval(&unescape($env{'form.allmeta'}));
-
+
+ if ($batch) {
+ my %commonaccess;
+ map { $commonaccess{$_} = 1; } &Apache::loncommon::get_env_multiple('form.commonaccess');
+ if ($commonaccess{'dist'}) {
+ unless ($style eq 'prv') {
+ if ($env{'form.commondistselect'} eq 'custom') {
+ unless ($source =~ /\.rights$/) {
+ if ($env{'form.commoncustomrights'} =~ m{^/res/.+\.rights$}) {
+ $env{'form.customdistributionfile'} = $env{'form.commoncustomrights'};
+ $env{'form.copyright'} = $env{'form.commondistselect'};
+ }
+ }
+ } elsif ($env{'form.commondistselect'} =~ /^default|domain|public$/) {
+ $env{'form.copyright'} = $env{'form.commondistselect'};
+ }
+ }
+ }
+ unless ($style eq 'prv') {
+ if ($commonaccess{'source'}) {
+ if (($env{'form.commonsourceselect'} eq 'open') || ($env{'form.commonsourceselect'} eq 'closed')) {
+ $env{'form.sourceavail'} = $env{'form.commonsourceselect'};
+ }
+ }
+ }
+ }
+
$metadatafields{'title'}=$env{'form.title'};
$metadatafields{'author'}=$env{'form.author'};
$metadatafields{'subject'}=$env{'form.subject'};
@@ -1593,17 +1772,17 @@ sub phasetwo {
'');
return 0;
}
- foreach (sort keys %metadatafields) {
- unless ($_=~/\./) {
- my $unikey=$_;
+ foreach my $field (sort(keys(%metadatafields))) {
+ unless ($field=~/\./) {
+ my $unikey=$field;
$unikey=~/^([A-Za-z]+)/;
my $tag=$1;
$tag=~tr/A-Z/a-z/;
print $mfh "\n\<$tag";
- foreach (split(/\,/,$metadatakeys{$unikey})) {
- my $value=$metadatafields{$unikey.'.'.$_};
+ foreach my $item (split(/\,/,$metadatakeys{$unikey})) {
+ my $value=$metadatafields{$unikey.'.'.$item};
$value=~s/\"/\'\'/g;
- print $mfh ' '.$_.'="'.$value.'"';
+ print $mfh ' '.$item.'="'.$value.'"';
}
print $mfh '>'.
&HTML::Entities::encode($metadatafields{$unikey},'<>&"')
@@ -1640,7 +1819,8 @@ sub phasetwo {
my $srcf=$2;
my $srct=$3;
my $srcd=$1;
- unless ($srcd=~/^\/home\/httpd\/html\/res/) {
+ my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ unless ($srcd=~/^\Q$docroot\E\/res/) {
print $logfile "\nPANIC: Target dir is ".$srcd;
$r->print(
"".&mt('Invalid target directory, FAIL')."");
@@ -1666,11 +1846,10 @@ sub phasetwo {
if (copy($target,$copyfile)) {
print $logfile "Copied old target to ".$copyfile."\n";
- $r->print('
'.&mt('Copied old target file').'
');
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old target file')));
} else {
print $logfile "Unable to write ".$copyfile.':'.$!."\n";
- $r->print("".&mt('Failed to copy old target').
- ", $!, ".&mt('FAIL')."");
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Failed to copy old target').", $!",1));
return 0;
}
@@ -1680,13 +1859,12 @@ sub phasetwo {
if (copy($target.'.meta',$copyfile)) {
print $logfile "Copied old target metadata to ".$copyfile."\n";
- $r->print('
'.&mt('Copied old metadata').'
')
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old metadata')));
} else {
print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
if (-e $target.'.meta') {
- $r->print(
- "".
-&mt('Failed to write old metadata copy').", $!, ".&mt('FAIL')."");
+ $r->print(&Apache::lonhtmlcommon::confirm_success(
+ &mt('Failed to write old metadata copy').", $!",1));
return 0;
}
}
@@ -1719,35 +1897,34 @@ sub phasetwo {
if (copy($source,$copyfile)) {
print $logfile "\nCopied original source to ".$copyfile."\n";
- $r->print('
'.&mt('Copied source file').'
');
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied source file')));
} else {
print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
- $r->print("".
- &mt('Failed to copy source').", $!, ".&mt('FAIL')."");
+ $r->print(&Apache::lonhtmlcommon::confirm_success(
+ &mt('Failed to copy source').", $!",1));
return 0;
}
+# ---------------------------------------------- Delete local tmp-preview files
+ unlink($copyfile.'.tmp');
# --------------------------------------------------------------- Copy Metadata
$copyfile=$copyfile.'.meta';
if (copy($source.'.meta',$copyfile)) {
print $logfile "\nCopied original metadata to ".$copyfile."\n";
- $r->print('
'.&mt('Copied metadata').'
');
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied metadata')));
} else {
print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";
- $r->print(
- "".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."");
+ $r->print(&Apache::lonhtmlcommon::confirm_success(
+ &mt('Failed to write metadata copy').", $!",1));
return 0;
}
$r->rflush;
# ------------------------------------------------------------- Trigger updates
push(@{$modified_urls},[$target,$source]);
- unless ($registered_cleanup) {
- $r->register_cleanup(\¬ify);
- $registered_cleanup=1;
- }
+ ¬ify_in_cleanup($r);
# ---------------------------------------------------------- Clear local caches
my $thisdistarget=$target;
@@ -1762,25 +1939,36 @@ sub phasetwo {
# ------------------------------------------------ Provide link to new resource
unless ($batch) {
- my $thissrc=$source;
- $thissrc=~s{^/home/($match_username)/public_html}{/priv/$1};
+ my $thissrc=&Apache::loncfile::url($source);
my $thissrcdir=$thissrc;
$thissrcdir=~s/\/[^\/]+$/\//;
-
$r->print(
- ''.
- &mt('View Published Version').''.
- '