--- loncom/publisher/lonpublisher.pm 2010/05/27 18:27:43 1.266
+++ 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.266 2010/05/27 18:27:43 www 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
';
}
$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'}).
@@ -1482,6 +1630,8 @@ Returns:
0: fail
1: success
+=back
+
=cut
#'stupid emacs
@@ -1535,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'};
@@ -1596,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},'<>&"')
@@ -1748,11 +1924,7 @@ sub phasetwo {
# ------------------------------------------------------------- Trigger updates
push(@{$modified_urls},[$target,$source]);
- unless ($registered_cleanup) {
- my $handlers = $r->get_handlers('PerlCleanupHandler');
- $r->set_handlers('PerlCleanupHandler' => [\¬ify,@{$handlers}]);
- $registered_cleanup=1;
- }
+ ¬ify_in_cleanup($r);
# ---------------------------------------------------------- Clear local caches
my $thisdistarget=$target;
@@ -1767,32 +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(&Apache::loncommon::head_subbox(
- &Apache::lonhtmlcommon::start_funclist().
- &Apache::lonhtmlcommon::add_item_funclist(
+ $r->print(
+ &Apache::lonhtmlcommon::actionbox([
''.
&mt('View Published Version').
- '').
- &Apache::lonhtmlcommon::add_item_funclist(
+ '',
''.
&mt('Back to Source').
- '').
- &Apache::lonhtmlcommon::add_item_funclist(
+ '',
''.
&mt('Back to Source Directory').
- '').
- &Apache::lonhtmlcommon::end_funclist())
+ ''])
);
}
return 1;
}
+sub notify_in_cleanup {
+ my ($r) = @_;
+ unless ($registered_cleanup) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\¬ify,@{$handlers}]);
+ $registered_cleanup=1;
+ }
+}
+
# =============================================================== Notifications
sub notify {
# --------------------------------------------------- Send update notifications
@@ -1817,9 +1993,9 @@ sub notify {
# --------------------------------------------------- Notify subscribed courses
my %courses=&coursedependencies($target);
my $now=time;
- foreach (keys %courses) {
- print $logfile "\nNotifying course ".$_.':';
- my ($cdom,$cname)=split(/\_/,$_);
+ foreach my $course (keys(%courses)) {
+ print $logfile "\nNotifying course ".$course.':';
+ my ($cdom,$cname)=split(/\_/,$course);
my $reply=&Apache::lonnet::cput
('versionupdate',{$target => $now},$cdom,$cname);
print $logfile $reply;
@@ -1839,8 +2015,6 @@ sub batchpublish {
my %oldenv=%env;
$srcfile=~s/\/+/\//g;
$targetfile=~s/\/+/\//g;
- my $thisdisfn=$srcfile;
- $thisdisfn=~s/\/home\/korte\/public_html\///;
$srcfile=~s/\/+/\//g;
my $docroot=$r->dir_config('lonDocRoot');
@@ -1857,8 +2031,7 @@ sub batchpublish {
my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
$r->print('