';
@@ -377,9 +400,9 @@ sub publish {
}
}
}
- } keys %allow;
+ }
$outstring=~s/(\<\/[^\>]+\>\s*)$/$allowstr$1/s;
- }
+
# ------------------------------------------------------------- Write modified
{
@@ -432,30 +455,30 @@ sub publish {
my $currentpath='/home/'.$cuname.'/';
- map {
+ foreach (@urlparts) {
$currentpath.=$_.'/';
$scrout.=&metaread($logfile,$currentpath.'default.meta');
- } @urlparts;
+ }
# ------------------- Clear out parameters and stores (there should not be any)
- map {
+ foreach (keys %metadatafields) {
if (($_=~/^parameter/) || ($_=~/^stores/)) {
delete $metadatafields{$_};
}
- } keys %metadatafields;
+ }
} else {
# ---------------------- Read previous metafile, remember parameters and stores
$scrout.=&metaread($logfile,$source.'.meta');
- map {
+ foreach (keys %metadatafields) {
if (($_=~/^parameter/) || ($_=~/^stores/)) {
$oldparmstores{$_}=1;
delete $metadatafields{$_};
}
- } keys %metadatafields;
+ }
}
@@ -472,7 +495,7 @@ sub publish {
# ---------------- Find and document discrepancies in the parameters and stores
my $chparms='';
- map {
+ foreach (sort keys %metadatafields) {
if (($_=~/^parameter/) || ($_=~/^stores/)) {
unless ($_=~/\.\w+$/) {
unless ($oldparmstores{$_}) {
@@ -481,14 +504,14 @@ sub publish {
}
}
}
- } sort keys %metadatafields;
+ }
if ($chparms) {
$scrout.='New parameters or stored values: '.
$chparms;
}
my $chparms='';
- map {
+ foreach (sort keys %oldparmstores) {
if (($_=~/^parameter/) || ($_=~/^stores/)) {
unless (($metadatafields{$_.'.name'}) ||
($metadatafields{$_.'.package'}) || ($_=~/\.\w+$/)) {
@@ -496,7 +519,7 @@ sub publish {
$chparms.=$_.' ';
}
}
- } sort keys %oldparmstores;
+ }
if ($chparms) {
$scrout.='
Obsolete parameters or stored values: '.
$chparms;
@@ -506,6 +529,7 @@ sub publish {
$scrout.=
'
';
+ '';
}
# -------------------------------------------------------- Publication Step Two
@@ -631,13 +665,14 @@ sub phasetwo {
$metadatafields{'lastrevisiondate'}=$ENV{'form.lastrevisiondate'};
$metadatafields{'owner'}=$ENV{'form.owner'};
$metadatafields{'copyright'}=$ENV{'form.copyright'};
+ $metadatafields{'dependencies'}=$ENV{'form.dependencies'};
my $allkeywords=$ENV{'form.addkey'};
- map {
+ foreach (keys %ENV) {
if ($_=~/^form\.key\.(\w+)/) {
$allkeywords.=','.$1;
}
- } keys %ENV;
+ }
$allkeywords=~s/\W+/\,/;
$allkeywords=~s/^\,//;
$metadatafields{'keywords'}=$allkeywords;
@@ -648,44 +683,36 @@ sub phasetwo {
unless ($mfh=Apache::File->new('>'.$source.'.meta')) {
return
'Could not write metadata, FAIL';
- }
- map {
+ }
+ foreach (sort keys %metadatafields) {
unless ($_=~/\./) {
my $unikey=$_;
$unikey=~/^([A-Za-z]+)/;
my $tag=$1;
$tag=~tr/A-Z/a-z/;
print $mfh "\n\<$tag";
- map {
+ foreach (split(/\,/,$metadatakeys{$unikey})) {
my $value=$metadatafields{$unikey.'.'.$_};
$value=~s/\"/\'\'/g;
print $mfh ' '.$_.'="'.$value.'"';
- } split(/\,/,$metadatakeys{$unikey});
+ }
print $mfh '>'.$metadatafields{$unikey}.''.$tag.'>';
}
- } sort keys %metadatafields;
+ }
$scrout.='Wrote Metadata';
print $logfile "\nWrote metadata";
}
# -------------------------------- Synchronize entry with SQL metadata database
- my %perlvar;
- open (CONFIG,"/etc/httpd/conf/access.conf") || die "Can't read access.conf";
- my $configline;
- while ($configline=) {
- if ($configline =~ /PerlSetVar/) {
- my ($dummy,$varname,$varvalue)=split(/\s+/,$configline);
- chomp($varvalue);
- $perlvar{$varname}=$varvalue;
- }
- }
- close(CONFIG);
+ my $warning;
+
+ unless ($metadatafields{'copyright'} eq 'priv') {
- my $warning;
my $dbh;
{
unless (
- $dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0})
+ $dbh = DBI->connect("DBI:mysql:loncapa","www",
+ $Apache::lonnet::perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0})
) {
$warning='WARNING: Cannot connect to '.
'database!';
@@ -697,11 +724,12 @@ sub phasetwo {
'delete from metadata where url like binary'.
'"'.$sqldatafields{'url'}.'"');
$sth->execute();
- map {my $field=$metadatafields{$_}; $field=~s/\"/\'\'/g;
- $sqldatafields{$_}=$field;}
- ('title','author','subject','keywords','notes','abstract',
+ foreach ('title','author','subject','keywords','notes','abstract',
'mime','language','creationdate','lastrevisiondate','owner',
- 'copyright');
+ 'copyright') {
+ my $field=$metadatafields{$_}; $field=~s/\"/\'\'/g;
+ $sqldatafields{$_}=$field;
+ }
$sth=$dbh->prepare('insert into metadata values ('.
'"'.delete($sqldatafields{'title'}).'"'.','.
@@ -730,7 +758,11 @@ sub phasetwo {
}
}
-
+} else {
+ $scrout.='Private Publication - did not synchronize database';
+ print $logfile "\nPrivate: Did not synchronize data into ".
+ "SQL metadata database";
+}
# ----------------------------------------------------------- Copy old versions
if (-e $target) {
@@ -909,7 +941,7 @@ sub handler {
# Get query string for limited number of parameters
- map {
+ foreach (split(/&/,$ENV{'QUERY_STRING'})) {
my ($name, $value) = split(/=/,$_);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
@@ -918,7 +950,7 @@ sub handler {
$ENV{'form.'.$name}=$value;
}
}
- } (split(/&/,$ENV{'QUERY_STRING'}));
+ }
# -------------------------------------------------------------- Check filename
@@ -993,31 +1025,11 @@ unless ($ENV{'form.phase'} eq 'two') {
{
my $fh=Apache::File->new($r->dir_config('lonIncludes').'/un_keyword.tab');
- map {
+ while (<$fh>) {
my $word=$_;
chomp($word);
$nokey{$word}=1;
- } <$fh>;
- }
-
- %language=();
-
- {
- my $fh=Apache::File->new($r->dir_config('lonTabDir').'/language.tab');
- map {
- $_=~/(\w+)\s+([\w\s\-]+)/;
- $language{$1}=$2;
- } <$fh>;
- }
-
- %cprtag=();
-
- {
- my $fh=Apache::File->new($r->dir_config('lonIncludes').'/copyright.tab');
- map {
- $_=~/(\w+)\s+([\w\s\-]+)/;
- $cprtag{$1}=$2;
- } <$fh>;
+ }
}
}
@@ -1036,7 +1048,7 @@ unless ($ENV{'form.phase'} eq 'two') {
{
$thisfn=~/\.(\w+)$/;
my $thistype=$1;
- my $thisembstyle=&Apache::lonnet::fileembstyle($thistype);
+ my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
my $thistarget=$thisfn;
@@ -1050,7 +1062,7 @@ unless ($ENV{'form.phase'} eq 'two') {
$thisdisfn=~s/^\/home\/$cuname\/public_html\///;
$r->print('
Publishing '.
- &Apache::lonnet::filedescription($thistype).' '.
+ &Apache::loncommon::filedescription($thistype).' '.
$thisdisfn.'
Target: '.$thisdistarget.'');
if (($cuname ne $ENV{'user.name'}) || ($cudom ne $ENV{'user.domain'})) {
@@ -1058,7 +1070,7 @@ unless ($ENV{'form.phase'} eq 'two') {
'');
}
- if (&Apache::lonnet::fileembstyle($thistype) eq 'ssi') {
+ if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') {
$r->print('
Diffs with Current Version
');
@@ -1083,9 +1095,107 @@ unless ($ENV{'form.phase'} eq 'two') {
1;
__END__
+=head1 NAME
+
+Apache::lonpublisher - Publication Handler
+
+=head1 SYNOPSIS
+
+Invoked by /etc/httpd/conf/srm.conf:
+
+
+ PerlAccessHandler Apache::lonacc
+ SetHandler perl-script
+ PerlHandler Apache::lonpublisher
+ ErrorDocument 403 /adm/login
+ ErrorDocument 404 /adm/notfound.html
+ ErrorDocument 406 /adm/unauthorized.html
+ ErrorDocument 500 /adm/errorhandler
+
+
+=head1 INTRODUCTION
+
+This module publishes a file. This involves gathering metadata,
+versioning the file, copying file from construction space to
+publication space, and copying metadata from construction space
+to publication space.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 HANDLER SUBROUTINE
+
+This routine is called by Apache and mod_perl.
+
+=over 4
+
+=item *
+
+Get query string for limited number of parameters
+
+=item *
+
+Check filename
+
+=item *
+
+File is there and owned, init lookup tables
+
+=item *
+
+Start page output
+
+=item *
+
+Individual file
+
+=item *
+
+publish from $thisfn to $thistarget with $thisembstyle
+
+=back
+
+=head1 OTHER SUBROUTINES
+
+=over 4
+
+=item *
+
+metaeval() : Evaluate string with metadata
+
+=item *
+
+metaread() : Read a metadata file
+
+=item *
+
+sqltime() : convert 'time' format into a datetime sql format
+
+=item *
+
+textfield() : form field
+
+=item *
+
+hiddenfield() : form field
+
+=item *
+
+selectbox() : form field
+
+=item *
+
+urlfixup() : fixup URL (Publication Step One)
+=item *
+publish() : publish (Publication Step One)
+=item *
+phasetwo() : render second interface showing status of publication steps
+(Publication Step Two)
+=back
+=cut