Diff for /loncom/interface/londocs.pm between versions 1.196 and 1.197

version 1.196, 2005/07/25 02:35:29 version 1.197, 2005/07/26 13:30:34
Line 249  sub dumpcourse { Line 249  sub dumpcourse {
 # ------------------------------------------------------ Generate "export" button  # ------------------------------------------------------ Generate "export" button
   
 sub exportbutton {  sub exportbutton {
     return '';  
     return '</td><td bgcolor="#DDDDCC">'.      return '</td><td bgcolor="#DDDDCC">'.
             '<input type="submit" name="exportcourse" value="'.              '<input type="submit" name="exportcourse" value="'.
             &mt('Export Course to IMS').'" />'.              &mt('Export Course to IMS').'" />'.
Line 748  sub replicate_content { Line 747  sub replicate_content {
         if ($copiedfile = Apache::File->new('>'.$destination)) {          if ($copiedfile = Apache::File->new('>'.$destination)) {
             my $content;              my $content;
             if ($caller eq 'resource') {              if ($caller eq 'resource') {
                 $content = &Apache::lonnet::getfile('/home/httpd/html/res/'.$url);                  my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
                   my $filepath = &Apache::lonnet::filelocation($respath,$url);
                   $content = &Apache::lonnet::getfile($filepath);
                 if ($content eq -1) {                  if ($content eq -1) {
                     $$message = 'Could not copy file '.$filename;                      $$message = 'Could not copy file '.$filename;
                 } else {                  } else {
                     &extract_media($content,$count,$tempexport,$href,'resource');                      &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
                     $repstatus = 'ok';                      $repstatus = 'ok';
                 }                  }
             } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {              } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
Line 760  sub replicate_content { Line 761  sub replicate_content {
                 $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);                  $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
                 if ($repstatus eq 'ok') {                  if ($repstatus eq 'ok') {
                     if ($url =~ /\.html?$/i) {                      if ($url =~ /\.html?$/i) {
                         &extract_media(\$content,$count,$tempexport,$href,'uploaded');                          &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
                     }                      }
                 } else {                  } else {
                     $$message = 'Could not render '.$url.' server message - '.$rtncode;                      $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
                 }                  }
             } elsif ($caller eq 'noedit') {              } elsif ($caller eq 'noedit') {
 # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.   # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. 
Line 775  sub replicate_content { Line 776  sub replicate_content {
             }              }
             close($copiedfile);              close($copiedfile);
         } else {          } else {
             $$message = 'Could not open destination file for '.$filename."\n";              $$message = 'Could not open destination file for '.$filename."<br />\n";
         }          }
     } else {      } else {
         $$message = 'Could not determine name of file for '.$symb."\n";          $$message = 'Could not determine name of file for '.$symb."<br />\n";
     }      }
     if ($repstatus eq 'ok') {      if ($repstatus eq 'ok') {
         $content_name = $count.'/'.$filename;          $content_name = $count.'/'.$filename;
Line 787  sub replicate_content { Line 788  sub replicate_content {
 }  }
   
 sub extract_media {  sub extract_media {
     my ($content,$count,$tempexport,$href,$caller) = @_;      my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
 # @$href will contain path to any embedded resources in the content.      my %allfiles = ();
 # For LON-CAPA problems this would be images. applets etc.       my %codebase = ();
 # For uploaded HTML files this would be images etc.      $url =~ s#([^/]+)$##;
 # paths will be in the form $count/res/$file, and urls in the $content will be rewritten with the new paths.       &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content);
       foreach my $embed_file (keys(%allfiles)) {
           my $filename;
           if ($embed_file =~ m#([^/]+)$#) {
               $filename = $1;
           } else {
               $filename = $embed_file;
           }
           my $newname = 'res/'.$filename;
           my ($rtncode,$embed_content,$repstatus);
           my $embed_url;
           if ($embed_file =~ m-^/-) {
               $embed_url = $embed_file;           # points to absolute path
           } else {
               if ($embed_file =~ m-https?://-) {
                   next;                           # points to url
               } else {
                   $embed_url = $url.$embed_file;  # points to relative path
               }
           }
           if ($caller eq 'resource') {
               my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';  
               my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); 
               $embed_content = &Apache::lonnet::getfile($embed_path);
               unless ($embed_content eq -1) {
                   $repstatus = 'ok';
               }
           } elsif ($caller eq 'uploaded') {
               
               $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
           }
           if ($repstatus eq 'ok') {
               my $destination = $tempexport.'/resources/'.$count.'/res';
               if (!-e "$destination") {
                   mkdir($destination,0755);
               }
               $destination .= '/'.$filename;
               my $copiedfile;
               if ($copiedfile = Apache::File->new('>'.$destination)) {
                   print $copiedfile $embed_content;
                   push @{$href}, .'resources/'.$count.'/res/'.$filename;
                   my $attrib_regexp = '';
                   if (@{$allfiles{$embed_file}} > 1) {
                       $attrib_regexp = join('|',@{$allfiles{$embed_file}});
                   } else {
                       $attrib_regexp = $allfiles{$embed_file}[0];
                   }
                   $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
                   if ($caller eq 'resource' && $url =~ /\.(problem|library)$/) {
                       $$content =~ s#\Q$embed_file\E#$newname#gi;
                   }
               }
           } else {
               $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
           }
       }
     return;      return;
 }  }
   

Removed from v.1.196  
changed lines
  Added in v.1.197


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