--- loncom/publisher/lonpublisher.pm 2005/05/19 03:22:04 1.194 +++ loncom/publisher/lonpublisher.pm 2006/05/30 12:47:41 1.209 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.194 2005/05/19 03:22:04 www Exp $ +# $Id: lonpublisher.pm,v 1.209 2006/05/30 12:47:41 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -129,6 +129,9 @@ use Apache::loncfile; use LONCAPA::lonmetadata; use Apache::lonmsg; use vars qw(%metadatafields %metadatakeys); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + my %addid; my %nokey; @@ -355,7 +358,8 @@ sub hiddenfield { sub checkbox { my ($name,$text)=@_; - return "\n
".&mt($text); + return "\n
"; } sub selectbox { @@ -507,7 +511,6 @@ sub get_subscribed_hosts { if ( $sh=Apache::File->new("$target.subscription") ) { &Apache::lonnet::logthis("opened $target.subscription"); while (my $subline=<$sh>) { - &Apache::lonnet::logthis("Trying $subline"); if ($subline =~ /(^\w+):/) { if ($1 ne $Apache::lonnet::perlvar{'lonHostID'}) { push(@subscribed,$1); @@ -547,6 +550,7 @@ sub get_max_ids_indices { my %duplicatedids; my $parser=HTML::LCParser->new($content); + $parser->xml_mode(1); my $token; while ($token=$parser->get_token) { if ($token->[0] eq 'S') { @@ -676,6 +680,7 @@ sub fix_ids_and_indices { $allow{$token->[2]->{'src'}}=1; next; } + if ($lctag eq 'base') { next; } my %parms=%{$token->[2]}; $counter=$addid{$tag}; if (!$counter) { $counter=$addid{$lctag}; } @@ -685,7 +690,9 @@ sub fix_ids_and_indices { $parms{'id'}!~/^\s*$/) { $maxid++; $parms{'id'}=$maxid; - print $logfile 'ID: '.$tag.':'.$maxid."\n"; + print $logfile 'ID(new) : '.$tag.':'.$maxid."\n"; + } else { + print $logfile 'ID(kept): '.$tag.':'.$parms{'id'}."\n"; } } elsif ($counter eq 'index') { unless (defined($parms{'index'}) && @@ -696,12 +703,14 @@ sub fix_ids_and_indices { } } } - foreach my $type ('src','href','background','bgimg') { - foreach my $key (keys(%parms)) { - if ($key =~ /^$type$/i) { - $parms{$key}=&set_allow(\%allow,$logfile, - $target,$tag, - $parms{$key}); + unless ($parms{'type'} eq 'zombie') { + foreach my $type ('src','href','background','bgimg') { + foreach my $key (keys(%parms)) { + if ($key =~ /^$type$/i) { + $parms{$key}=&set_allow(\%allow,$logfile, + $target,$tag, + $parms{$key}); + } } } } @@ -1020,7 +1029,7 @@ sub publish { } # ------------------------------------------------ First, check out environment - unless (-e $source.'.meta') { + if ((!(-e $source.'.meta')) || ($env{'form.forceoverride'})) { $metadatafields{'author'}=$env{'environment.firstname'}.' '. $env{'environment.middlename'}.' '. $env{'environment.lastname'}.' '. @@ -1070,10 +1079,18 @@ sub publish { delete $metadatafields{$_}; } } +# ------------------------------------------------------------- Save some stuff + my %savemeta=(); + foreach ('title') { + $savemeta{$_}=$metadatafields{$_}; + } # ------------------------------------------ See if anything new in file itself $allmeta=&parseformeta($source,$style); - +# ----------------------------------------------------------- Restore the stuff + foreach (keys %savemeta) { + $metadatafields{$_}=$savemeta{$_}; + } } @@ -1154,7 +1171,7 @@ sub publish { '

'.($env{'form.makeobsolete'}?'':'').'

'. &hiddenfield('phase','two'). &hiddenfield('filename',$env{'form.filename'}). - &hiddenfield('allmeta',&Apache::lonnet::escape($allmeta)). + &hiddenfield('allmeta',&escape($allmeta)). &hiddenfield('dependencies',join(',',keys %allow)); unless ($env{'form.makeobsolete'}) { $intr_scrout.= @@ -1301,15 +1318,15 @@ END $defaultsourceoption, \&Apache::loncommon::source_copyrightdescription, (&Apache::loncommon::source_copyrightids)); - $intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights'); +# $intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights'); my $uctitle=&mt('Obsolete'); $intr_scrout.= - "\n

$uctitle:". + "\n

'); + return 0; } } { print $logfile "\nWrite metadata file for ".$source; my $mfh; unless ($mfh=Apache::File->new('>'.$source.'.meta')) { - return + $r->print( ''.&mt('Could not write metadata, FAIL'). - ''; + ''); + return 0; } foreach (sort keys %metadatafields) { unless ($_=~/\./) { @@ -1518,7 +1554,9 @@ sub phasetwo { my $srcd=$1; unless ($srcd=~/^\/home\/httpd\/html\/res/) { print $logfile "\nPANIC: Target dir is ".$srcd; - return "Invalid target directory, FAIL"; + $r->print( + "Invalid target directory, FAIL"); + return 0; } opendir(DIR,$srcd); while ($filename=readdir(DIR)) { @@ -1543,8 +1581,9 @@ sub phasetwo { $r->print('

'.&mt('Copied old target file').'

'); } else { print $logfile "Unable to write ".$copyfile.':'.$!."\n"; - return "".&mt('Failed to copy old target'). - ", $!, ".&mt('FAIL').""; + $r->print("".&mt('Failed to copy old target'). + ", $!, ".&mt('FAIL').""); + return 0; } # --------------------------------------------------------------- Copy Metadata @@ -1557,9 +1596,10 @@ sub phasetwo { } else { print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n"; if (-e $target.'.meta') { - return + $r->print( "". -&mt('Failed to write old metadata copy').", $!, ".&mt('FAIL').""; +&mt('Failed to write old metadata copy').", $!, ".&mt('FAIL').""); + return 0; } } @@ -1590,8 +1630,9 @@ sub phasetwo { $r->print('

'.&mt('Copied source file').'

'); } else { print $logfile "\nUnable to write ".$copyfile.':'.$!."\n"; - return "". - &mt('Failed to copy source').", $!, ".&mt('FAIL').""; + $r->print("". + &mt('Failed to copy source').", $!, ".&mt('FAIL').""); + return 0; } # --------------------------------------------------------------- Copy Metadata @@ -1603,8 +1644,9 @@ sub phasetwo { $r->print('

'.&mt('Copied metadata').'

'); } else { print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n"; - return - "".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL').""; + $r->print( + "".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL').""); + return 0; } $r->rflush; @@ -1614,10 +1656,16 @@ sub phasetwo { $r->register_cleanup(\¬ify); $registered_cleanup=1; } + +# ---------------------------------------------------------- Clear local caches + my $thisdistarget=$target; + $thisdistarget=~s/^\Q$docroot\E//; + &Apache::lonnet::devalidate_cache_new('resversion',$target); + &Apache::lonnet::devalidate_cache_new('meta', + &Apache::lonnet::declutter($thisdistarget)); + # ------------------------------------------------ Provide link to new resource unless ($batch) { - my $thisdistarget=$target; - $thisdistarget=~s/^\Q$docroot\E//; my $thissrc=$source; $thissrc=~s/^\/home\/(\w+)\/public_html/\/priv\/$1/; @@ -1636,7 +1684,8 @@ sub phasetwo { &mt('Back to Source Directory').'

'); } $logfile->close(); - return '

'.&mt('Done').'

'; + $r->print('

'.&mt('Done').'

'); + return 1; } # =============================================================== Notifications @@ -1739,17 +1788,9 @@ sub publishdirectory { &hiddenfield('filename',$env{'form.filename'}). &checkbox('pubrec','include subdirectories'). &checkbox('forcerepub','force republication of previously published files'). - &checkbox('forceobsolete','make file(s) obsolete')); - my %allcopyrights=('keep','Keep current copyright'); - my %ratcopyrights=%allcopyrights; - foreach (&Apache::loncommon::copyrightids) { - $allcopyrights{$_}=&Apache::loncommon::copyrightdescription($_); - unless ($_ eq 'public') { $ratcopyrights{$_}=$allcopyrights{$_}; } - } - $r->print('
'.&mt('Copyright for all files:').&Apache::loncommon::select_form('keep','forceallcopy',%allcopyrights)); - $r->print('
'.&mt('Copyright for pages/sequences:').&Apache::loncommon::select_form('keep','forceratcopy',%ratcopyrights)); - $r->print(&text_with_browse_field('Custom Distribution File','forcecustomfile')); - $r->print('
'); + &checkbox('obsolete','make file(s) obsolete'). + &checkbox('forceoverride','force directory level catalog information over existing'). + '
'); } else { # actually publish things opendir(DIR,$fn); @@ -1811,8 +1852,7 @@ sub defaultmetapublish { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - $r->print('LON-CAPA Publishing'); - $r->print(&Apache::loncommon::bodytag('Catalog Information Publication')); + $r->print(&Apache::loncommon::start_page('Catalog Information Publication')); # ---------------------------------------------------------------- Write Source my $copyfile=$target; @@ -1848,7 +1888,7 @@ sub defaultmetapublish { my $link=$fn; $link=~s/^\/home\/$cuname\/public_html\//\/priv\/$cuname\//; $r->print("".&mt('Back to Catalog Information').''); - $r->print(''); + $r->print(&Apache::loncommon::end_page()); return OK; } ######################################### @@ -1910,7 +1950,7 @@ sub handler { @{$modified_urls}=(); # -------------------------------------------------------------- Check filename - my $fn=&Apache::lonnet::unescape($env{'form.filename'}); + my $fn=&unescape($env{'form.filename'}); ($cuname,$cudom)= &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); @@ -1971,30 +2011,26 @@ sub handler { return HTTP_NOT_FOUND; } - unless ($env{'form.phase'} eq 'two') { - # -------------------------------- File is there and owned, init lookup tables. - %addid=(); - - { - my $fh=Apache::File->new($r->dir_config('lonTabDir').'/addid.tab'); - while (<$fh>=~/(\w+)\s+(\w+)/) { - $addid{$1}=$2; - } + %addid=(); + + { + my $fh=Apache::File->new($r->dir_config('lonTabDir').'/addid.tab'); + while (<$fh>=~/(\w+)\s+(\w+)/) { + $addid{$1}=$2; } + } - %nokey=(); + %nokey=(); - { - my $fh=Apache::File->new($r->dir_config('lonIncludes').'/un_keyword.tab'); - while (<$fh>) { - my $word=$_; - chomp($word); - $nokey{$word}=1; - } + { + my $fh=Apache::File->new($r->dir_config('lonIncludes').'/un_keyword.tab'); + while (<$fh>) { + my $word=$_; + chomp($word); + $nokey{$word}=1; } - } # ---------------------------------------------------------- Start page output. @@ -2002,11 +2038,10 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - my $js=&Apache::loncommon::browser_and_searcher_javascript(); - $r->print('LON-CAPA Publishing - '); - $r->print(&Apache::loncommon::bodytag('Resource Publication')); + my $js=''; + $r->print(&Apache::loncommon::start_page('Resource Publication')); my $thisfn=$fn; @@ -2035,6 +2070,7 @@ sub handler { $thisfn=~/\.(\w+)$/; my $thistype=$1; my $thisembstyle=&Apache::loncommon::fileembstyle($thistype); + if ($thistype eq 'page') { $thisembstyle = 'rat'; } $r->print('

'.&mt('Publishing').' '. &Apache::loncommon::filedescription($thistype).' '); @@ -2076,11 +2112,11 @@ ENDDIFF '

'); } } else { - $r->print('
'. - &phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget)); + &phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget); + $r->print('
'); } } - $r->print(''); + $r->print(&Apache::loncommon::end_page()); return OK; }