Diff for /loncom/publisher/lonpublisher.pm between versions 1.96 and 1.97

version 1.96, 2002/09/17 15:01:36 version 1.97, 2002/09/18 15:43:06
Line 805  I<Additional documentation needed.> Line 805  I<Additional documentation needed.>
 #########################################  #########################################
 sub publish {  sub publish {
   
     my ($source,$target,$style)=@_;      my ($source,$target,$style,$batch)=@_;
     my $logfile;      my $logfile;
     my $scrout='';      my $scrout='';
     my $allmeta='';      my $allmeta='';
Line 896  sub publish { Line 896  sub publish {
             
      my %oldparmstores=();       my %oldparmstores=();
             
            unless ($batch) {
      $scrout.='<h3>Metadata Information ' .       $scrout.='<h3>Metadata Information ' .
        Apache::loncommon::help_open_topic("Metadata_Description")         Apache::loncommon::help_open_topic("Metadata_Description")
        . '</h3>';         . '</h3>';
       }
   
 # ------------------------------------------------ First, check out environment  # ------------------------------------------------ First, check out environment
      unless (-e $source.'.meta') {       unless (-e $source.'.meta') {
Line 993  sub publish { Line 994  sub publish {
   
 # ------------------------------------------------------- Now have all metadata  # ------------------------------------------------------- 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.=          $scrout.=
      '<form name="pubform" action="/adm/publish" method="post">'.       '<form name="pubform" action="/adm/publish" method="post">'.
        '<p><input type="submit" value="Finalize Publication" /></p>'.         '<p><input type="submit" value="Finalize Publication" /></p>'.
Line 1028  function uncheckAll(field) Line 1056  function uncheckAll(field)
 END  END
         $keywordout.='<table border=2><tr>';          $keywordout.='<table border=2><tr>';
         my $colcount=0;          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) {              foreach (sort keys %keywords) {
                 $keywordout.='<td><input type=checkbox name="keywords" value="'.$_.'"';                  $keywordout.='<td><input type=checkbox name="keywords" value="'.$_.'"';
Line 1123  END Line 1129  END
     $scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge;      $scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge;
     return $scrout.      return $scrout.
         '<p><input type="submit" value="Finalize Publication" /></p></form>';          '<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;
     }
 }  }
   
 #########################################  #########################################
Line 1324  if (-e $target) { Line 1359  if (-e $target) {
            }             }
   
         if (copy($source,$copyfile)) {          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';              $scrout.='<p>Copied source file';
         } else {          } 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>";              return "<font color=red>Failed to copy source, $!, FAIL</font>";
         }          }
   
Line 1336  if (-e $target) { Line 1371  if (-e $target) {
         $copyfile=$copyfile.'.meta';          $copyfile=$copyfile.'.meta';
   
         if (copy($source.'.meta',$copyfile)) {          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';              $scrout.='<p>Copied metadata';
         } else {          } else {
     print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";      print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";
             return               return 
           "<font color=red>Failed to write metadata copy, $!, FAIL</font>";            "<font color=red>Failed to write metadata copy, $!, FAIL</font>";
         }          }
Line 1385  if (-e $target) { Line 1420  if (-e $target) {
       '<p><a href="'.$thissrc.'"><font size=+2>Back to Source</font></a>'.        '<p><a href="'.$thissrc.'"><font size=+2>Back to Source</font></a>'.
       '<p><a href="'.$thissrcdir.        '<p><a href="'.$thissrcdir.
       '"><font size="+2">Back to Source Directory</font></a>';        '"><font size="+2">Back to Source Directory</font></a>';
     } else {
       return $warning.$scrout;
   }    }
 }  }
   
 #########################################  #########################################
   
 sub batchpublish {  sub batchpublish {
     my ($r,$srcfile)=@_;      my ($r,$srcfile,$targetfile)=@_;
     my $thisdisfn=$srcfile;      my $thisdisfn=$srcfile;
     $thisdisfn=~s/\/home\/korte\/public_html\///;      $thisdisfn=~s/\/home\/korte\/public_html\///;
     $srcfile=~s/\/+/\//g;      $srcfile=~s/\/+/\//g;
   
       my $docroot=$r->dir_config('lonDocRoot');
       my $thisdistarget=$targetfile;
       $thisdistarget=~s/^$docroot//;
   
   
     undef %metadatafields;      undef %metadatafields;
     undef %metadatakeys;      undef %metadatakeys;
      %metadatafields=();       %metadatafields=();
      %metadatakeys=();       %metadatakeys=();
         $srcfile=~/\.(\w+)$/;
         my $thistype=$1;
   
   
         my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
             
     $r->print('<h2>Publishing <tt>'.$thisdisfn.'</tt></h2>');      $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  # phase two takes
 # my ($source,$target,$style,$distarget,batch)=@_;  # 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 '';
 }  }
   
 #########################################  #########################################
Line 1453  sub publishdirectory { Line 1505  sub publishdirectory {
  $publishthis=1;   $publishthis=1;
      }       }
              if ($publishthis) {               if ($publishthis) {
                 &batchpublish($r,$fn.'/'.$filename);                  &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename);
      } else {       } else {
                  $r->print('<br />Skipping '.$filename.'<br />');                   $r->print('<br />Skipping '.$filename.'<br />');
              }               }

Removed from v.1.96  
changed lines
  Added in v.1.97


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>