--- loncom/publisher/lonpublisher.pm 2002/09/17 15:01:36 1.96 +++ loncom/publisher/lonpublisher.pm 2002/09/18 15:43:06 1.97 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.96 2002/09/17 15:01:36 www Exp $ +# $Id: lonpublisher.pm,v 1.97 2002/09/18 15:43:06 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -805,7 +805,7 @@ I ######################################### sub publish { - my ($source,$target,$style)=@_; + my ($source,$target,$style,$batch)=@_; my $logfile; my $scrout=''; my $allmeta=''; @@ -896,10 +896,11 @@ sub publish { my %oldparmstores=(); - + unless ($batch) { $scrout.='

Metadata Information ' . Apache::loncommon::help_open_topic("Metadata_Description") . '

'; + } # ------------------------------------------------ First, check out environment unless (-e $source.'.meta') { @@ -993,6 +994,33 @@ sub publish { # ------------------------------------------------------- Now have all metadata + my %keywords=(); + + if (length($content)<500000) { + my $textonly=$content; + $textonly=~s/\//g; + $textonly=~s/\[^\<]+\<\/m\>//g; + $textonly=~s/\<[^\>]*\>//g; + $textonly=~tr/A-Z/a-z/; + $textonly=~s/[\$\&][a-z]\w*//g; + $textonly=~s/[^a-z\s]//g; + + foreach ($textonly=~m/(\w+)/g) { + unless ($nokey{$_}) { + $keywords{$_}=1; + } + } + } + + + foreach (split(/\W+/,$metadatafields{'keywords'})) { + $keywords{$_}=1; + } +# --------------------------------------------------- Now we also have keywords +# ============================================================================= +# INTERACTIVE MODE +# + unless ($batch) { $scrout.= '
'. '

'. @@ -1028,28 +1056,6 @@ function uncheckAll(field) END $keywordout.=''; my $colcount=0; - my %keywords=(); - - if (length($content)<500000) { - my $textonly=$content; - $textonly=~s/\//g; - $textonly=~s/\[^\<]+\<\/m\>//g; - $textonly=~s/\<[^\>]*\>//g; - $textonly=~tr/A-Z/a-z/; - $textonly=~s/[\$\&][a-z]\w*//g; - $textonly=~s/[^a-z\s]//g; - - foreach ($textonly=~m/(\w+)/g) { - unless ($nokey{$_}) { - $keywords{$_}=1; - } - } - } - - - foreach (split(/\W+/,$metadatafields{'keywords'})) { - $keywords{$_}=1; - } foreach (sort keys %keywords) { $keywordout.='

'; +# ============================================================================= +# BATCH MODE +# + } else { +# Transfer metadata directly to environment for stage 2 + foreach (keys %metadatafields) { + $ENV{'form.'.$_}=$metadatafields{$_}; + } + $ENV{'form.addkey'}=''; + $ENV{'form.keywords'}=''; + foreach (keys %keywords) { + if ($metadatafields{'keywords'}) { + if ($metadatafields{'keywords'}=~/$_/) { + $ENV{'form.keywords'}.=$_.','; + } + } elsif (&Apache::loncommon::keyword($_)) { + $ENV{'form.keywords'}.=$_.','; + } + } + $ENV{'form.keywords'}=~s/\,$//; + unless ($ENV{'form.creationdate'}) { $ENV{'form.creationdate'}=time; } + $ENV{'form.lastrevisiondate'}=time; + if ((($style eq 'rat') && ($ENV{'form.copyright'} eq 'public')) || + (!$ENV{'form.copyright'})) { + $ENV{'form.copyright'}='default'; + } + $ENV{'form.allmeta'}=&Apache::lonnet::escape($allmeta); + return $scrout; + } } ######################################### @@ -1324,10 +1359,10 @@ if (-e $target) { } if (copy($source,$copyfile)) { - print $logfile "Copied original source to ".$copyfile."\n"; + print $logfile "\nCopied original source to ".$copyfile."\n"; $scrout.='

Copied source file'; } else { - print $logfile "Unable to write ".$copyfile.':'.$!."\n"; + print $logfile "\nUnable to write ".$copyfile.':'.$!."\n"; return "Failed to copy source, $!, FAIL"; } @@ -1336,10 +1371,10 @@ if (-e $target) { $copyfile=$copyfile.'.meta'; if (copy($source.'.meta',$copyfile)) { - print $logfile "Copied original metadata to ".$copyfile."\n"; + print $logfile "\nCopied original metadata to ".$copyfile."\n"; $scrout.='

Copied metadata'; } else { - print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n"; + print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n"; return "Failed to write metadata copy, $!, FAIL"; } @@ -1385,28 +1420,45 @@ if (-e $target) { '

Back to Source'. '

Back to Source Directory'; + } else { + return $warning.$scrout; } } ######################################### sub batchpublish { - my ($r,$srcfile)=@_; + my ($r,$srcfile,$targetfile)=@_; my $thisdisfn=$srcfile; $thisdisfn=~s/\/home\/korte\/public_html\///; $srcfile=~s/\/+/\//g; + my $docroot=$r->dir_config('lonDocRoot'); + my $thisdistarget=$targetfile; + $thisdistarget=~s/^$docroot//; + undef %metadatafields; undef %metadatakeys; %metadatafields=(); %metadatakeys=(); + $srcfile=~/\.(\w+)$/; + my $thistype=$1; + + + my $thisembstyle=&Apache::loncommon::fileembstyle($thistype); $r->print('

Publishing '.$thisdisfn.'

'); + +# phase one takes +# my ($source,$target,$style,$batch)=@_; + $r->print('

'.&publish($srcfile,$targetfile,$thisembstyle,1).'

'); # phase two takes # my ($source,$target,$style,$distarget,batch)=@_; -# $ENV{'form.allmeta'} - +# $ENV{'form.allmeta'},$ENV{'form.title'},$ENV{'form.author'},... + $r->print( +'

'.&phasetwo($srcfile,$targetfile,$thisembstyle,$thisdistarget,1).'

'); + return ''; } ######################################### @@ -1453,7 +1505,7 @@ sub publishdirectory { $publishthis=1; } if ($publishthis) { - &batchpublish($r,$fn.'/'.$filename); + &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename); } else { $r->print('
Skipping '.$filename.'
'); }