Diff for /loncom/publisher/lonpublisher.pm between versions 1.264 and 1.271

version 1.264, 2009/11/24 01:44:44 version 1.271, 2011/10/22 23:09:44
Line 266  sub metaread { Line 266  sub metaread {
     my ($logfile,$fn,$prefix)=@_;      my ($logfile,$fn,$prefix)=@_;
     unless (-e $fn) {      unless (-e $fn) {
  print($logfile 'No file '.$fn."\n");   print($logfile 'No file '.$fn."\n");
         return '<div><b>'          return '<p class="LC_warning">'
               .&mt('No file: [_1]'                .&mt('No file: [_1]',&Apache::loncfile::display($fn))
                   ,'</b> <tt>'.&Apache::loncfile::display($fn).'</tt></div>');                .'</p>';
     }      }
     print($logfile 'Processing '.$fn."\n");      print($logfile 'Processing '.$fn."\n");
     my $metastring;      my $metastring;
Line 277  sub metaread { Line 277  sub metaread {
  $metastring=join('',<$metafh>);   $metastring=join('',<$metafh>);
     }      }
     &metaeval($metastring,$prefix);      &metaeval($metastring,$prefix);
     return '<div><b>'      return '<p class="LC_info">'
           .&mt('Processed file: [_1]'            .&mt('Processed file: [_1]',&Apache::loncfile::display($fn))
               ,'</b> <tt>'.&Apache::loncfile::display($fn).'</tt></div>');            .'</p>';
 }  }
   
 #########################################  #########################################
Line 1080  sub publish { Line 1080  sub publish {
 # ------------------------------------------------ Check out directory hierachy  # ------------------------------------------------ Check out directory hierachy
   
         my $thisdisfn=$source;          my $thisdisfn=$source;
         $thisdisfn=~s/^\/home\/\Q$cuname\E\///;  
   
         my @urlparts=split(/\//,$thisdisfn);          $thisdisfn=~s/^\Q$docroot\E\/priv\/\Q$cudom\E\/\Q$cuname\E\///;
           my @urlparts=('.',split(/\//,$thisdisfn));
         $#urlparts--;          $#urlparts--;
   
         my $currentpath='/home/'.$cuname.'/';          my $currentpath=$docroot.'/priv/'.$cudom.'/'.$cuname.'/';
   
  my $prefix='../'x($#urlparts);   my $prefix='../'x($#urlparts);
         foreach (@urlparts) {          foreach my $subdir (@urlparts) {
     $currentpath.=$_.'/';      $currentpath.=$subdir.'/';
             $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);              $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);
     $prefix=~s|^\.\./||;      $prefix=~s|^\.\./||;
         }          }
Line 1121  sub publish { Line 1121  sub publish {
 # ------------------------------------------------------------- Save some stuff  # ------------------------------------------------------------- Save some stuff
         my %savemeta=();          my %savemeta=();
         foreach ('title') {          foreach ('title') {
             $savemeta{$_}=$metadatafields{$_};              if ($metadatafields{$_}) { $savemeta{$_}=$metadatafields{$_}; }
  }   }
 # ------------------------------------------ See if anything new in file itself  # ------------------------------------------ See if anything new in file itself
     
Line 1228  sub publish { Line 1228  sub publish {
                     .'</p>'                      .'</p>'
                     .'<p><input type="submit" value="'                      .'<p><input type="submit" value="'
                     .&mt('Finalize Publication')                      .&mt('Finalize Publication')
                     .'" /></p>';                      .'" /> <a href="'.&Apache::loncfile::url($source).'">'.&mt('Cancel').'</a></p>';
     }      }
     $intr_scrout.=&Apache::lonhtmlcommon::start_pick_box();      $intr_scrout.=&Apache::lonhtmlcommon::start_pick_box();
     $intr_scrout.=      $intr_scrout.=
Line 1668  sub phasetwo { Line 1668  sub phasetwo {
                   
         if (copy($target,$copyfile)) {          if (copy($target,$copyfile)) {
     print $logfile "Copied old target to ".$copyfile."\n";      print $logfile "Copied old target to ".$copyfile."\n";
             $r->print('<p>'.&mt('Copied old target file').'</p>');              $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old target file')));
         } else {          } else {
     print $logfile "Unable to write ".$copyfile.':'.$!."\n";      print $logfile "Unable to write ".$copyfile.':'.$!."\n";
             $r->print("<span class=\"LC_error\">".&mt('Failed to copy old target').              $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Failed to copy old target').", $!",1));
  ", $!, ".&mt('FAIL')."</span>");  
     return 0;      return 0;
         }          }
                   
Line 1682  sub phasetwo { Line 1681  sub phasetwo {
                   
         if (copy($target.'.meta',$copyfile)) {          if (copy($target.'.meta',$copyfile)) {
     print $logfile "Copied old target metadata to ".$copyfile."\n";      print $logfile "Copied old target metadata to ".$copyfile."\n";
             $r->print('<p>'.&mt('Copied old metadata').'</p>')              $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old metadata')));
         } else {          } else {
     print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";      print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
             if (-e $target.'.meta') {              if (-e $target.'.meta') {
                 $r->print(                   $r->print(&Apache::lonhtmlcommon::confirm_success(
                     "<span class=\"LC_error\">".                             &mt('Failed to write old metadata copy').", $!",1));
 &mt('Failed to write old metadata copy').", $!, ".&mt('FAIL')."</span>");  
  return 0;   return 0;
     }      }
         }          }
Line 1721  sub phasetwo { Line 1719  sub phasetwo {
           
     if (copy($source,$copyfile)) {      if (copy($source,$copyfile)) {
         print $logfile "\nCopied original source to ".$copyfile."\n";          print $logfile "\nCopied original source to ".$copyfile."\n";
         $r->print('<p>'.&mt('Copied source file').'</p>');          $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied source file')));
     } else {      } else {
         print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";          print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
         $r->print("<span class=\"LC_error\">".          $r->print(&Apache::lonhtmlcommon::confirm_success(
     &mt('Failed to copy source').", $!, ".&mt('FAIL')."</span>");      &mt('Failed to copy source').", $!",1));
  return 0;   return 0;
     }      }
           
   # ---------------------------------------------- Delete local tmp-preview files
       unlink($copyfile.'.tmp');
 # --------------------------------------------------------------- Copy Metadata  # --------------------------------------------------------------- Copy Metadata
   
     $copyfile=$copyfile.'.meta';      $copyfile=$copyfile.'.meta';
           
     if (copy($source.'.meta',$copyfile)) {      if (copy($source.'.meta',$copyfile)) {
         print $logfile "\nCopied original metadata to ".$copyfile."\n";          print $logfile "\nCopied original metadata to ".$copyfile."\n";
         $r->print('<p>'.&mt('Copied metadata').'</p>');          $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied metadata')));
     } else {      } else {
         print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";          print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n";
         $r->print(          $r->print(&Apache::lonhtmlcommon::confirm_success(
             "<span class=\"LC_error\">".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."</span>");                    &mt('Failed to write metadata copy').", $!",1));
  return 0;   return 0;
     }      }
     $r->rflush;      $r->rflush;
Line 1765  sub phasetwo { Line 1765  sub phasetwo {
   
 # ------------------------------------------------ Provide link to new resource  # ------------------------------------------------ Provide link to new resource
     unless ($batch) {      unless ($batch) {
         my $thissrc=$source;  
         $thissrc=~s{^/home/($match_username)/public_html}{/priv/$1};  
                   
           my $thissrc=&Apache::loncfile::url($source);
         my $thissrcdir=$thissrc;          my $thissrcdir=$thissrc;
         $thissrcdir=~s/\/[^\/]+$/\//;          $thissrcdir=~s/\/[^\/]+$/\//;
                   
Line 1837  sub batchpublish { Line 1836  sub batchpublish {
     my %oldenv=%env;      my %oldenv=%env;
     $srcfile=~s/\/+/\//g;      $srcfile=~s/\/+/\//g;
     $targetfile=~s/\/+/\//g;      $targetfile=~s/\/+/\//g;
     my $thisdisfn=$srcfile;  
     $thisdisfn=~s/\/home\/korte\/public_html\///;  
     $srcfile=~s/\/+/\//g;      $srcfile=~s/\/+/\//g;
   
     my $docroot=$r->dir_config('lonDocRoot');      my $docroot=$r->dir_config('lonDocRoot');
Line 1855  sub batchpublish { Line 1852  sub batchpublish {
     my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);      my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
             
     $r->print('<h2>'      $r->print('<h2>'
              .&mt('Publishing [_1]'               .&mt('Publishing [_1]',&Apache::loncfile::display($srcfile))
                  ,'<span class="LC_filename">'.$thisdisfn.'</span>')  
              .'</h2>'               .'</h2>'
     );      );
   
Line 1971  sub publishdirectory { Line 1967  sub publishdirectory {
   
 sub defaultmetapublish {  sub defaultmetapublish {
     my ($r,$fn,$cuname,$cudom)=@_;      my ($r,$fn,$cuname,$cudom)=@_;
     $fn=~s/^\/\~$cuname\//\/home\/$cuname\/public_html\//;  
     unless (-e $fn) {      unless (-e $fn) {
        return HTTP_NOT_FOUND;         return HTTP_NOT_FOUND;
     }      }
     my $target=$fn;      my $target=$fn;
     $target=~s/^\/home\/$cuname\/public_html\//$Apache::lonnet::perlvar{'lonDocRoot'}\/res\/$cudom\/$cuname\//;      $target=~s/^\Q$Apache::lonnet::perlvar{'lonDocRoot'}\E\/priv\//\Q$Apache::lonnet::perlvar{'lonDocRoot'}\E\/res\//;
   
   
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
Line 2019  sub defaultmetapublish { Line 2014  sub defaultmetapublish {
  $r->print($reply.'</p><br />');$r->rflush;   $r->print($reply.'</p><br />');$r->rflush;
     }      }
 # ------------------------------------------------------------------- Link back  # ------------------------------------------------------------------- Link back
     my $link=$fn;      $r->print("<a href='".&Apache::lonnet::display($fn)."'>".&mt('Back to Metadata').'</a>');
     $link=~s/^\/home\/$cuname\/public_html\//\/priv\/$cuname\//;  
     $r->print("<a href='$link'>".&mt('Back to Metadata').'</a>');  
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
     return OK;      return OK;
 }  }
Line 2085  sub handler { Line 2078  sub handler {
 # -------------------------------------------------------------- Check filename  # -------------------------------------------------------------- Check filename
   
     my $fn=&unescape($env{'form.filename'});      my $fn=&unescape($env{'form.filename'});
       ($cuname,$cudom)=&Apache::loncacc::constructaccess($fn);
   # ----------------------------------------------------- Do we have permissions?
        unless (($cuname) && ($cudom)) {
          $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
                         ' trying to publish file '.$env{'form.filename'}.
                         ' - not authorized', 
                         $r->filename); 
          return HTTP_NOT_ACCEPTABLE;
        }
   # ----------------------------------------------------------------- Get docroot
       $docroot=$r->dir_config('lonDocRoot');
   
     ($cuname,$cudom)=  
  &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));  
   
 # special publication: default.meta file  # special publication: default.meta file
     if ($fn=~/\/default.meta$/) {      if ($fn=~/\/default.meta$/) {
  return &defaultmetapublish($r,$fn,$cuname,$cudom);    return &defaultmetapublish($r,$fn,$cuname,$cudom); 
     }      }
     $fn=~s/\.meta$//;      $fn=~s/\.meta$//;
     
   # sanity test on the filename 
    
     unless ($fn) {       unless ($fn) { 
  $r->log_reason($cuname.' at '.$cudom.   $r->log_reason($cuname.' at '.$cudom.
        ' trying to publish empty filename', $r->filename);          ' trying to publish empty filename', $r->filename); 
  return HTTP_NOT_FOUND;   return HTTP_NOT_FOUND;
     }       } 
   
     unless (($cuname) && ($cudom)) {      unless (-e $docroot.$fn) { 
  $r->log_reason($cuname.' at '.$cudom.  
        ' trying to publish file '.$env{'form.filename'}.  
        ' ('.$fn.') - not authorized',   
        $r->filename);   
  return HTTP_NOT_ACCEPTABLE;  
     }  
   
     my $home=&Apache::lonnet::homeserver($cuname,$cudom);  
     my $allowed=0;  
     my @ids=&Apache::lonnet::current_machine_ids();  
     foreach my $id (@ids) { if ($id eq $home) { $allowed = 1; }  }  
     unless ($allowed) {  
  $r->log_reason($cuname.' at '.$cudom.  
        ' trying to publish file '.$env{'form.filename'}.  
        ' ('.$fn.') - not homeserver ('.$home.')',   
        $r->filename);   
  return HTTP_NOT_ACCEPTABLE;  
     }  
   
     $fn=~s{^http://[^/]+}{};  
     $fn=~s{^/~($match_username)}{/home/$1/public_html};  
   
     my $targetdir='';  
     $docroot=$r->dir_config('lonDocRoot');   
     if ($1 ne $cuname) {  
  $r->log_reason($cuname.' at '.$cudom.  
        ' trying to publish unowned file '.  
        $env{'form.filename'}.' ('.$fn.')',   
        $r->filename);   
  return HTTP_NOT_ACCEPTABLE;  
     } else {  
  $targetdir=$docroot.'/res/'.$cudom;  
     }  
                                    
     
     unless (-e $fn) {   
  $r->log_reason($cuname.' at '.$cudom.   $r->log_reason($cuname.' at '.$cudom.
        ' trying to publish non-existing file '.         ' trying to publish non-existing file '.
        $env{'form.filename'}.' ('.$fn.')',          $env{'form.filename'}.' ('.$fn.')', 
Line 2192  sub handler { Line 2160  sub handler {
                   &Apache::loncommon::CSTR_pageheader()) # FIXME crumbs broken?                    &Apache::loncommon::CSTR_pageheader()) # FIXME crumbs broken?
     );      );
   
       my $thisdisfn=&HTML::Entities::encode($fn,'<>&"');
     my $thisfn=$fn;      my $thistarget=$fn;
       $thistarget=~s/^\/priv\//\/res\//;
     my $thistarget=$thisfn;      my $thisdistarget=&HTML::Entities::encode($thistarget,'<>&"');
         
     $thistarget=~s/^\/home/$targetdir/;  
     $thistarget=~s/\/public\_html//;  
   
     my $thisdistarget=$thistarget;  
     $thisdistarget=~s/^\Q$docroot\E//;  
   
     my $thisdisfn=$thisfn;  
     $thisdisfn=~s/^\/home\/\Q$cuname\E\/public_html\///;  
   
     if ($fn=~/\/$/) {      if ($fn=~/\/$/) {
 # -------------------------------------------------------- This is a directory  # -------------------------------------------------------- This is a directory
  &publishdirectory($r,$fn,$thisdisfn);   &publishdirectory($r,$fn,$thisdisfn);
  $r->print('<hr /><a href="/priv/'   $r->print('<hr /><a href="'.$thisdisfn.'">'.&mt('Return to Directory').'</a>');
   .$cuname.'/'.$thisdisfn  
   .'">'.&mt('Return to Directory').'</a>');  
   
   
     } else {      } else {
 # ---------------------- Evaluate individual file, and then output information.  # ---------------------- Evaluate individual file, and then output information.
  $thisfn=~/\.(\w+)$/;   $fn=~/\.(\w+)$/;
  my $thistype=$1;   my $thistype=$1;
  my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);   my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
         if ($thistype eq 'page') {  $thisembstyle = 'rat'; }          if ($thistype eq 'page') {  $thisembstyle = 'rat'; }
Line 2240  sub handler { Line 2195  sub handler {
                  .'<tt>'                   .'<tt>'
                  );                   );
  $r->print(<<ENDCAPTION);   $r->print(<<ENDCAPTION);
 <a href='javascript:void(window.open("/~$cuname/$thisdisfn","cat","height=300,width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'>  <a href='javascript:void(window.open("$thisdisfn","cat","height=300,width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'>
 $thisdisfn</a>  $thisdisfn</a>
 ENDCAPTION  ENDCAPTION
         $r->print('</tt>'          $r->print('</tt>'
Line 2263  ENDCAPTION Line 2218  ENDCAPTION
             $r->print(&Apache::lonhtmlcommon::row_closure()              $r->print(&Apache::lonhtmlcommon::row_closure()
                      .&Apache::lonhtmlcommon::row_title(&mt('Diffs')));                       .&Apache::lonhtmlcommon::row_title(&mt('Diffs')));
     $r->print(<<ENDDIFF);      $r->print(<<ENDDIFF);
 <a href='javascript:void(window.open("/adm/diff?filename=/~$cuname/$thisdisfn&versiontwo=priv","cat","height=300,width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'>  <a href='javascript:void(window.open("/adm/diff?filename=$thisdisfn&versiontwo=priv","cat","height=300,width=500,scrollbars=1,resizable=1,menubar=0,location=1"))'>
 ENDDIFF  ENDDIFF
             $r->print(&mt('Diffs with Current Version').'</a>');              $r->print(&mt('Diffs with Current Version').'</a>');
  }   }
Line 2272  ENDDIFF Line 2227  ENDDIFF
                  .&Apache::lonhtmlcommon::end_pick_box()                   .&Apache::lonhtmlcommon::end_pick_box()
                  );                   );
       
 # ------------------ Publishing from $thisfn to $thistarget with $thisembstyle.  # ---------------------- Publishing from $fn to $thistarget with $thisembstyle.
   
  unless ($env{'form.phase'} eq 'two') {   unless ($env{'form.phase'} eq 'two') {
 # ---------------------------------------------------------- Parse for problems  # ---------------------------------------------------------- Parse for problems
     my ($warningcount,$errorcount);      my ($warningcount,$errorcount);
     if ($thisembstyle eq 'ssi') {      if ($thisembstyle eq 'ssi') {
  ($warningcount,$errorcount)=&checkonthis($r,$thisfn);   ($warningcount,$errorcount)=&checkonthis($r,$fn);
     }      }
     unless ($errorcount) {      unless ($errorcount) {
  my ($outstring,$error)=   my ($outstring,$error)=
     &publish($thisfn,$thistarget,$thisembstyle);      &publish($docroot.$fn,$thistarget,$thisembstyle);
  $r->print($outstring);   $r->print($outstring);
     } else {      } else {
  $r->print('<h3 class="LC_error">'.   $r->print('<h3 class="LC_error">'.
Line 2290  ENDDIFF Line 2245  ENDDIFF
   '</h3>');    '</h3>');
     }      }
  } else {   } else {
     &phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget);       &phasetwo($r,$fn,$thistarget,$thisembstyle,$thisdistarget); 
  }   }
     }      }
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());

Removed from v.1.264  
changed lines
  Added in v.1.271


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