--- loncom/publisher/lonpublisher.pm 2003/10/21 19:50:15 1.139 +++ loncom/publisher/lonpublisher.pm 2003/12/22 21:57:25 1.148 @@ -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.148 2003/12/22 21:57:25 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -143,6 +143,7 @@ use Apache::lonnet(); use Apache::loncommon(); use Apache::lonmysql; use Apache::lonlocal; +use Apache::loncfile; use vars qw(%metadatafields %metadatakeys); my %addid; @@ -180,8 +181,12 @@ nothing ######################################### ######################################### +# +# Modifies global %metadatafields %metadatakeys +# + sub metaeval { - my $metastring=shift; + my ($metastring,$prefix)=@_; my $parser=HTML::LCParser->new(\$metastring); my $token; @@ -209,14 +214,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,19 +264,21 @@ 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.''; + return '
'.&mt('No file').': '. + &Apache::loncfile::display($fn).''; } 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); - return '
Processed file: '.$fn.''; + &metaeval($metastring,$prefix); + return '
'.&mt('Processed file').': '. + &Apache::loncfile::display($fn).''; } ######################################### @@ -325,6 +331,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:". @@ -619,7 +628,7 @@ sub fix_ids_and_indices { join(', ',@duplicatedids)); if ($duplicateids) { print $logfile "Duplicate ID(s) exist, ".join(', ',@duplicatedids)."\n"; - my $outstring='Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are: '.join(', ',@duplicatedids).''; + my $outstring=''.&mt('Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are').': '.join(', ',@duplicatedids).''; return ($outstring,1); } if ($needsfixup) { @@ -684,8 +693,15 @@ sub fix_ids_and_indices { } if ($lctag eq 'applet') { my $codebase=''; - if (defined($parms{'codebase'})) { - my $oldcodebase=$parms{'codebase'}; + my $havecodebase=0; + foreach my $key (keys(%parms)) { + if (lc($key) eq 'codebase') { + $codebase=$parms{$key}; + $havecodebase=1; + } + } + if ($havecodebase) { + my $oldcodebase=$codebase; unless ($oldcodebase=~/\/$/) { $oldcodebase.='/'; } @@ -699,14 +715,13 @@ sub fix_ids_and_indices { } $allow{&absoluteurl($codebase,$target).'/*'}=1; } else { - foreach ('archive','code','object') { - if (defined($parms{$_})) { - my $oldurl=$parms{$_}; + foreach my $key (keys(%parms)) { + if ($key =~ /(archive|code|object)/i) { + my $oldurl=$parms{$key}; my $newurl=&urlfixup($oldurl,$target); $newurl=~s/\/[^\/]+$/\/\*/; - print $logfile 'Allow: applet '.$_.':'. - $oldurl.' allows '. - $newurl."\n"; + print $logfile 'Allow: applet '.lc($key).':'. + $oldurl.' allows '.$newurl."\n"; $allow{&absoluteurl($newurl,$target)}=1; } } @@ -808,6 +823,26 @@ sub store_metadata { return (undef,$status); } + +# ============================================== Parse file itself for metadata +# +# parses a file with target meta, sets global %metadatafields %metadatakeys + +sub parseformeta { + my ($source,$style)=@_; + my $allmeta=''; + 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); + } + return $allmeta; +} + ######################################### ######################################### @@ -839,7 +874,7 @@ sub publish { my %allow=(); unless ($logfile=Apache::File->new('>>'.$source.'.log')) { - return ('No write permission to user directory, FAIL',1); + return (''.&mt('No write permission to user directory, FAIL').'',1); } print $logfile "\n\n================= Publish ".localtime()." Phase One ================\n".$ENV{'user.name'}.'@'.$ENV{'user.domain'}."\n"; @@ -863,7 +898,7 @@ sub publish { if ($error) { return ($outstring,$error); } # ------------------------------------------------------------ Construct Allows - $scrout.='

Dependencies

'; + $scrout.='

'.&mt('Dependencies').'

'; my $allowstr=''; foreach (sort(keys(%allow))) { my $thisdep=$_; @@ -881,7 +916,7 @@ sub publish { if ( &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'. $thisdep.'.meta') eq '-1') { - $scrout.= ' - Currently not available'. + $scrout.= ' - '.&mt('Currently not available'). ''; } else { my %temphash=(&Apache::lonnet::declutter($target).'___'. @@ -920,7 +955,8 @@ sub publish { # -------------------------------------------- Initial step done, now metadata. # --------------------------------------- Storage for metadata keys and fields. - +# these are globals +# %metadatafields=(); %metadatakeys=(); @@ -945,6 +981,10 @@ sub publish { $ENV{'user.domain'}; $metadatafields{'authorspace'}=$cuname.'@'.$cudom; +# ----------------------------------------------------------- Parse file itself +# read %metadatafields from file itself + + $allmeta=&parseformeta($source,$style); # ------------------------------------------------ Check out directory hierachy my $thisdisfn=$source; @@ -955,9 +995,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) @@ -979,20 +1021,12 @@ sub publish { delete $metadatafields{$_}; } } - - } +# ------------------------------------------ See if anything new in file itself + + $allmeta=&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=''; @@ -1023,7 +1057,9 @@ sub publish { } if ($chparms) { $scrout.='

'.&mt('Obsolete parameters or stored values').': '. - $chparms.'

'; + $chparms.'

'.&mt('Warning!'). + '

'. + &mt('If this resource is in active use, student performance data from the previous version may become inaccessible.').'


'; } # ------------------------------------------------------- Now have all metadata @@ -1057,7 +1093,7 @@ sub publish { unless ($batch) { $scrout.= '
'. - '

'. + '

'. &hiddenfield('phase','two'). &hiddenfield('filename',$ENV{'form.filename'}). &hiddenfield('allmeta',&Apache::lonnet::escape($allmeta)). @@ -1069,6 +1105,9 @@ sub publish { # --------------------------------------------------- Scan content for keywords my $keywords_help = Apache::loncommon::help_open_topic("Publishing_Keywords"); + my $KEYWORDS=&mt('KEYWORDS'); + my $CheckAll=&mt('check all'); + my $UncheckAll=&mt('uncheck all'); my $keywordout=<<"END"; -

KEYWORDS: +

$KEYWORDS: $keywords_help - - + +


END @@ -1117,7 +1156,7 @@ END $scrout.=&textfield('Notes','notes',$metadatafields{'notes'}); $scrout.= - "\n

ABSTRACT:". + "\n

".&mt('ABSTRACT').":". "


". '

';