--- loncom/publisher/lonpublisher.pm 2003/10/21 19:50:15 1.139
+++ loncom/publisher/lonpublisher.pm 2003/11/01 17:38:58 1.142
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.139 2003/10/21 19:50:15 albertel Exp $
+# $Id: lonpublisher.pm,v 1.142 2003/11/01 17:38:58 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -181,7 +181,7 @@ nothing
#########################################
#########################################
sub metaeval {
- my $metastring=shift;
+ my ($metastring,$prefix)=@_;
my $parser=HTML::LCParser->new(\$metastring);
my $token;
@@ -209,14 +209,13 @@ sub metaeval {
$metadatakeys{$unikey}=$_;
}
}
- if ($metadatafields{$unikey}) {
- my $newentry=$parser->get_text('/'.$entry);
- unless (($metadatafields{$unikey}=~/\Q$newentry\E/) ||
- ($newentry eq '')) {
- $metadatafields{$unikey}.=', '.$newentry;
- }
- } else {
- $metadatafields{$unikey}=$parser->get_text('/'.$entry);
+ my $newentry=$parser->get_text('/'.$entry);
+ if ($entry eq 'customdistributionfile') {
+ $newentry=~s/^\s*//;
+ if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; }
+ }
+ unless ($metadatafields{$unikey}=~/\w/) {
+ $metadatafields{$unikey}=$newentry;
}
}
}
@@ -260,7 +259,7 @@ XHTML text that indicates successful rea
#########################################
#########################################
sub metaread {
- my ($logfile,$fn)=@_;
+ my ($logfile,$fn,$prefix)=@_;
unless (-e $fn) {
print($logfile 'No file '.$fn."\n");
return '
No file: '.$fn.'';
@@ -268,10 +267,10 @@ sub metaread {
print($logfile 'Processing '.$fn."\n");
my $metastring;
{
- my $metafh=Apache::File->new($fn);
- $metastring=join('',<$metafh>);
+ my $metafh=Apache::File->new($fn);
+ $metastring=join('',<$metafh>);
}
- &metaeval($metastring);
+ &metaeval($metastring,$prefix);
return '
Processed file: '.$fn.'';
}
@@ -325,6 +324,9 @@ string which presents the form field (fo
#########################################
sub textfield {
my ($title,$name,$value)=@_;
+ $value=~s/^\s+//gs;
+ $value=~s/\s+$//gs;
+ $value=~s/\s+/ /gs;
$title=&mt($title);
my $uctitle=uc($title);
return "\n
$uctitle:". @@ -808,6 +810,23 @@ sub store_metadata { return (undef,$status); } + +# ============================================== Parse file itself for metadata + + +sub parseformeta { + my ($source,$style)=@_; + if (($style eq 'ssi') || ($style eq 'prv')) { + my $dir=$source; + $dir=~s-/[^/]*$--; + my $file=$source; + $file=(split('/',$file))[-1]; + $source=&Apache::lonnet::hreflocation($dir,$file); + my $allmeta=&Apache::lonnet::ssi_body($source,('grade_target' => 'meta')); + &metaeval($allmeta); + } +} + ######################################### ######################################### @@ -945,6 +964,9 @@ sub publish { $ENV{'user.domain'}; $metadatafields{'authorspace'}=$cuname.'@'.$cudom; +# ----------------------------------------------------------- Parse file itself + + &parseformeta($source,$style); # ------------------------------------------------ Check out directory hierachy my $thisdisfn=$source; @@ -955,9 +977,11 @@ sub publish { my $currentpath='/home/'.$cuname.'/'; + my $prefix='../'x($#urlparts); foreach (@urlparts) { $currentpath.=$_.'/'; - $scrout.=&metaread($logfile,$currentpath.'default.meta'); + $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix); + $prefix=~s|^\.\./||; } # ------------------- Clear out parameters and stores (there should not be any) @@ -981,18 +1005,10 @@ sub publish { } } +# ------------------------------------------ See if anything new in file itself + + &parseformeta($source,$style); -# -------------------------------------------------- Parse content for metadata - if (($style eq 'ssi') || ($style eq 'prv')) { - my $dir=$source; - $dir=~s-/[^/]*$--; - my $file=$source; - $file=(split('/',$file))[-1]; - $source=&Apache::lonnet::hreflocation($dir,$file); - $allmeta=&Apache::lonnet::ssi_body($source,('grade_target' => 'meta')); - - &metaeval($allmeta); - } # ---------------- Find and document discrepancies in the parameters and stores my $chparms='';