[LON-CAPA-cvs] cvs: loncom /publisher lonpublisher.pm
www
lon-capa-cvs@mail.lon-capa.org
Wed, 18 Sep 2002 15:43:06 -0000
www Wed Sep 18 11:43:06 2002 EDT
Modified files:
/loncom/publisher lonpublisher.pm
Log:
Still has problems with picking up keywords.
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.96 loncom/publisher/lonpublisher.pm:1.97
--- loncom/publisher/lonpublisher.pm:1.96 Tue Sep 17 11:01:36 2002
+++ loncom/publisher/lonpublisher.pm Wed Sep 18 11:43:06 2002
@@ -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 @@
#########################################
sub publish {
- my ($source,$target,$style)=@_;
+ my ($source,$target,$style,$batch)=@_;
my $logfile;
my $scrout='';
my $allmeta='';
@@ -896,10 +896,11 @@
my %oldparmstores=();
-
+ unless ($batch) {
$scrout.='<h3>Metadata Information ' .
Apache::loncommon::help_open_topic("Metadata_Description")
. '</h3>';
+ }
# ------------------------------------------------ First, check out environment
unless (-e $source.'.meta') {
@@ -993,6 +994,33 @@
# ------------------------------------------------------- Now have all metadata
+ my %keywords=();
+
+ if (length($content)<500000) {
+ my $textonly=$content;
+ $textonly=~s/\<script[^\<]+\<\/script\>//g;
+ $textonly=~s/\<m\>[^\<]+\<\/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.=
'<form name="pubform" action="/adm/publish" method="post">'.
'<p><input type="submit" value="Finalize Publication" /></p>'.
@@ -1028,28 +1056,6 @@
END
$keywordout.='<table border=2><tr>';
my $colcount=0;
- my %keywords=();
-
- if (length($content)<500000) {
- my $textonly=$content;
- $textonly=~s/\<script[^\<]+\<\/script\>//g;
- $textonly=~s/\<m\>[^\<]+\<\/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.='<td><input type=checkbox name="keywords" value="'.$_.'"';
@@ -1123,6 +1129,35 @@
$scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge;
return $scrout.
'<p><input type="submit" value="Finalize Publication" /></p></form>';
+# =============================================================================
+# 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 (copy($source,$copyfile)) {
- print $logfile "Copied original source to ".$copyfile."\n";
+ print $logfile "\nCopied original source to ".$copyfile."\n";
$scrout.='<p>Copied source file';
} else {
- print $logfile "Unable to write ".$copyfile.':'.$!."\n";
+ print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
return "<font color=red>Failed to copy source, $!, FAIL</font>";
}
@@ -1336,10 +1371,10 @@
$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.='<p>Copied metadata';
} else {
- print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
+ print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";
return
"<font color=red>Failed to write metadata copy, $!, FAIL</font>";
}
@@ -1385,28 +1420,45 @@
'<p><a href="'.$thissrc.'"><font size=+2>Back to Source</font></a>'.
'<p><a href="'.$thissrcdir.
'"><font size="+2">Back to Source Directory</font></a>';
+ } 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('<h2>Publishing <tt>'.$thisdisfn.'</tt></h2>');
+
+# phase one takes
+# my ($source,$target,$style,$batch)=@_;
+ $r->print('<p>'.&publish($srcfile,$targetfile,$thisembstyle,1).'</p>');
# phase two takes
# my ($source,$target,$style,$distarget,batch)=@_;
-# $ENV{'form.allmeta'}
-
+# $ENV{'form.allmeta'},$ENV{'form.title'},$ENV{'form.author'},...
+ $r->print(
+'<p>'.&phasetwo($srcfile,$targetfile,$thisembstyle,$thisdistarget,1).'</p>');
+ return '';
}
#########################################
@@ -1453,7 +1505,7 @@
$publishthis=1;
}
if ($publishthis) {
- &batchpublish($r,$fn.'/'.$filename);
+ &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename);
} else {
$r->print('<br />Skipping '.$filename.'<br />');
}