[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm londocs.pm
raeburn
raeburn at source.lon-capa.org
Sun Apr 8 18:34:58 EDT 2012
raeburn Sun Apr 8 22:34:58 2012 EDT
Modified files:
/loncom/interface loncommon.pm londocs.pm
Log:
- Extraction of contents of archive files (zip, tar etc.) from a file
uploaded directly to a course.
- Where session is server is not course's home server, prompt home server
to fetch files extracted from archive.
- For Camtasia zip files, give option to process contents automatically.
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1066 loncom/interface/loncommon.pm:1.1067
--- loncom/interface/loncommon.pm:1.1066 Fri Apr 6 01:23:11 2012
+++ loncom/interface/loncommon.pm Sun Apr 8 22:34:57 2012
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1066 2012/04/06 01:23:11 raeburn Exp $
+# $Id: loncommon.pm,v 1.1067 2012/04/08 22:34:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -9931,20 +9931,26 @@
my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
my %lt = &Apache::lonlocal::texthash (
this => 'This file is an archive file.',
+ camt => 'This file is a Camtasia archive file.',
itsc => 'Its contents are as follows:',
youm => 'You may wish to extract its contents.',
- camt => 'Extraction of contents is recommended for Camtasia zip files.',
extr => 'Extract contents',
+ auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
+ proa => 'Process automatically?',
yes => 'Yes',
no => 'No',
+ fold => 'Title for folder containing movie',
+ movi => 'Title for page containing embedded movie',
);
- my $output = '<p>'.$lt{'this'};
my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
- my (%toplevel, at paths);
+ my ($is_camtasia,$topdir,%toplevel, at paths);
my $info = &list_archive_contents($fileloc,\@paths);
if (@paths) {
foreach my $path (@paths) {
$path =~ s{^/}{};
+ if ($path =~ m{^([^/]+)/$}) {
+ $topdir = $1;
+ }
if ($path =~ m{^([^/]+)/}) {
$toplevel{$1} = $path;
} else {
@@ -9952,12 +9958,53 @@
}
}
}
- if ($info eq '') {
- $output .= ' '.$lt{'youm'}.'</p>'."\n";
+ if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
+ my @camtasia = ("$topdir/","$topdir/index.html",
+ "$topdir/media/",
+ "$topdir/media/$topdir.mp4",
+ "$topdir/media/FirstFrame.png",
+ "$topdir/media/player.swf",
+ "$topdir/media/swfobject.js",
+ "$topdir/media/expressInstall.swf");
+ my @diffs = &compare_arrays(\@paths,\@camtasia);
+ if (@diffs == 0) {
+ $is_camtasia = 1;
+ }
+ }
+ my $output;
+ if ($is_camtasia) {
+ $output = <<"ENDCAM";
+<script type="text/javascript" language="Javascript">
+// <![CDATA[
+
+function camtasiaToggle() {
+ for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
+ if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
+ if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
+
+ document.getElementById('camtasia_titles').style.display='block';
+ } else {
+ document.getElementById('camtasia_titles').style.display='none';
+ }
+ }
+ }
+ return;
+}
+
+// ]]>
+</script>
+<p>$lt{'camt'}</p>
+ENDCAM
} else {
- $output .= ' '.$lt{'itsc'}.'</p>'."\n".
- '<div><pre>'.$info.'</pre></div>';
+ $output = '<p>'.$lt{'this'};
+ if ($info eq '') {
+ $output .= ' '.$lt{'youm'}.'</p>'."\n";
+ } else {
+ $output .= ' '.$lt{'itsc'}.'</p>'."\n".
+ '<div><pre>'.$info.'</pre></div>';
+ }
}
+ $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
my $duplicates;
my $num = 0;
if (ref($dirlist) eq 'ARRAY') {
@@ -9993,9 +10040,28 @@
} else {
$itemcount = 1;
}
+ if ($is_camtasia) {
+ $output .= $lt{'auto'}.'<br />'.
+ '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
+ '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
+ $lt{'yes'}.'</label> <label>'.
+ '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
+ $lt{'no'}.'</label></span><br />'.
+ '<div id="camtasia_titles" style="display:block">'.
+ &Apache::lonhtmlcommon::start_pick_box().
+ &Apache::lonhtmlcommon::row_title($lt{'fold'}).
+ '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
+ &Apache::lonhtmlcommon::row_closure().
+ &Apache::lonhtmlcommon::row_title($lt{'movi'}).
+ '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::end_pick_box().
+ '</div>';
+ }
$output .=
'<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
- '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'."\n";
+ '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
+ "\n";
if ($duplicates ne '') {
$output .= '<p><span class="LC_warning">'.
&mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
@@ -10011,24 +10077,17 @@
&end_data_table().
'</p>';
}
- if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
- $output .= '<p>'.$lt{'camt'}.'</p>';
- }
- $output .= <<"START";
-<div id="uploadfileresult">
- <form name="uploaded_decompress" action="$action" method="post">
- <input type="hidden" name="archiveurl" value="$archiveurl" />
-START
+ $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
if (ref($hiddenelements) eq 'HASH') {
foreach my $hidden (sort(keys(%{$hiddenelements}))) {
$output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
}
}
$output .= <<"END";
+<br />
<input type="submit" name="decompress" value="$lt{'extr'}" />
</form>
$noextract
-</div>
END
return $output;
}
@@ -10199,8 +10258,11 @@
}
}
if (@contents > 0) {
+ my $wantform;
+ unless ($env{'form.autoextract_camtasia'}) {
+ $wantform = 1;
+ }
my (%children,%parent,%dirorder,%titles);
- my $wantform = 1;
my ($count,$datatable) = &get_extracted($docudom,$docuname,
$currdir,\%is_dir,
\%children,\%parent,
@@ -10213,6 +10275,50 @@
$output .= &archive_javascript($startcount,$count,
\%titles,\%children);
}
+ if ($env{'form.autoextract_camtasia'}) {
+ my %displayed;
+ my $total = 1;
+ $env{'form.archive_directory'} = [];
+ foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
+ my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
+ $path =~ s{/$}{};
+ my $item;
+ if ($path ne '') {
+ $item = "$path/$titles{$i}";
+ } else {
+ $item = $titles{$i};
+ }
+ $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
+ if ($item eq $contents[0]) {
+ push(@{$env{'form.archive_directory'}},$i);
+ $env{'form.archive_'.$i} = 'display';
+ $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
+ $displayed{'folder'} = $i;
+ } elsif ($item eq "$contents[0]/index.html") {
+ $env{'form.archive_'.$i} = 'display';
+ $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
+ $displayed{'web'} = $i;
+ } else {
+ if ($item eq "$contents[0]/media") {
+ push(@{$env{'form.archive_directory'}},$i);
+ }
+ $env{'form.archive_'.$i} = 'dependency';
+ }
+ $total ++;
+ }
+ for (my $i=1; $i<$total; $i++) {
+ next if ($i == $displayed{'web'});
+ next if ($i == $displayed{'folder'});
+ $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
+ }
+ $env{'form.phase'} = 'decompress_cleanup';
+ $env{'form.archivedelete'} = 1;
+ $env{'form.archive_count'} = $total-1;
+ $output .=
+ &process_extracted_files('coursedocs',$docudom,
+ $docuname,$destination,
+ $dir_root,$hiddenelem);
+ }
} else {
$warning = &mt('No new items extracted from archive file.');
}
@@ -10611,12 +10717,12 @@
}
sub process_extracted_files {
- my ($context,$docudom,$docuname,$url,$destination,$dir_root,$hiddenelem) = @_;
+ my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
my $numitems = $env{'form.archive_count'};
return unless ($numitems);
my @ids=&Apache::lonnet::current_machine_ids();
my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
- %folders,%containers,%mapinner);
+ %folders,%containers,%mapinner,%prompttofetch);
my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
if (grep(/^\Q$docuhome\E$/, at ids)) {
$prefix = &LONCAPA::propath($docudom,$docuname);
@@ -10652,7 +10758,7 @@
}
}
}
- my ($output,%children,%parent,%titles,%dirorder);
+ my ($output,%children,%parent,%titles,%dirorder,$result);
if (keys(%toplevelitems) > 0) {
my @contents = sort(keys(%toplevelitems));
(my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
@@ -10713,6 +10819,9 @@
$docuname.'/'.$folders{$outer}.
'.'.$containers{$outer},1);
$newseqid{$i} = $newidx;
+ unless ($errtext) {
+ $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
+ }
}
} else {
if ($context eq 'coursedocs') {
@@ -10729,6 +10838,11 @@
if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
$newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
+ unless ($ishome) {
+ my $fetch = "$newdest{$i}/$title";
+ $fetch =~ s/^\Q$prefix$dir\E//;
+ $prompttofetch{$fetch} = 1;
+ }
}
$LONCAPA::map::resources[$newidx]=
$docstitle.':'.$url.':false:normal:res';
@@ -10737,6 +10851,11 @@
&LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
$docuname.'/'.$folders{$outer}.
'.'.$containers{$outer},1);
+ unless ($errtext) {
+ if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
+ $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
+ }
+ }
}
}
} elsif ($env{'form.archive_'.$i} eq 'dependency') {
@@ -10744,7 +10863,7 @@
$referrer{$i} = $env{'form.archive_dependent_on_'.$i};
if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
if (ref($dirorder{$i}) eq 'ARRAY') {
- my ($itemidx,$fullpath);
+ my ($itemidx,$fullpath,$relpath);
for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
my $container = $dirorder{$referrer{$i}}->[-1];
@@ -10763,6 +10882,7 @@
if (grep(/^\Q$dirorder{$i}->[$j]\E$/, at archdirs)) {
unless (defined($newseqid{$dirorder{$i}->[$j]})) {
$fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
+ $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
if (!-e $fullpath) {
mkdir($fullpath,0755);
}
@@ -10781,6 +10901,7 @@
} elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/, at archdirs)) {
unless (defined($newseqid{$dirorder{$i}->[$j]})) {
$fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
+ $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
if (!-e $fullpath) {
mkdir($fullpath,0755);
}
@@ -10791,7 +10912,23 @@
}
}
if ($fullpath ne '') {
- system("mv $prefix$path $fullpath/$title");
+ if (-e "$prefix$path") {
+ system("mv $prefix$path $fullpath/$title");
+ }
+ if (-e "$fullpath/$title") {
+ my $showpath;
+ if ($relpath ne '') {
+ $showpath = "$relpath/$title";
+ } else {
+ $showpath = "/$title";
+ }
+ $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
+ }
+ unless ($ishome) {
+ my $fetch = "$fullpath/$title";
+ $fetch =~ s/^\Q$prefix$dir\E//;
+ $prompttofetch{$fetch} = 1;
+ }
}
}
}
@@ -10819,6 +10956,26 @@
&cleanup_empty_dirs($prefix."$pathtocheck/$dir");
}
}
+ if ($result ne '') {
+ $output .= '<ul>'."\n".
+ $result."\n".
+ '</ul>';
+ }
+ unless ($ishome) {
+ my $replicationfail;
+ foreach my $item (keys(%prompttofetch)) {
+ my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
+ unless ($fetchresult eq 'ok') {
+ $replicationfail .= '<li>'.$item.'</li>'."\n";
+ }
+ }
+ if ($replicationfail) {
+ $output .= '<p class="LC_error">'.
+ &mt('Course home server failed to retrieve:').'<ul>'.
+ $replicationfail.
+ '</ul></p>';
+ }
+ }
} else {
$warning = &mt('No items found in archive.');
}
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.480 loncom/interface/londocs.pm:1.481
--- loncom/interface/londocs.pm:1.480 Thu Apr 5 15:22:39 2012
+++ loncom/interface/londocs.pm Sun Apr 8 22:34:58 2012
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.480 2012/04/05 15:22:39 raeburn Exp $
+# $Id: londocs.pm,v 1.481 2012/04/08 22:34:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3047,7 +3047,13 @@
$error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
} else {
my $file = $1;
- $output = &Apache::loncommon::process_decompression($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem);
+ $output =
+ &Apache::loncommon::process_decompression($docudom,$docuname,$file,
+ $destination,$dir_root,
+ $hiddenelem);
+ if ($env{'form.autoextract_camtasia'}) {
+ $output .= &remove_archive($docudom,$docuname,$container);
+ }
}
if ($error) {
$output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
@@ -3062,12 +3068,12 @@
sub decompression_phase_two {
my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
&decompression_info();
- my ($output,$url);
+ my $output;
if ($env{'form.archivedelete'}) {
- ($output,$url) = &remove_archive($docudom,$docuname,$container);
+ $output = &remove_archive($docudom,$docuname,$container);
}
$output .=
- &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,$url,
+ &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
$destination,$dir_root,$hiddenelem);
return $output;
}
@@ -3075,7 +3081,7 @@
sub remove_archive {
my ($docudom,$docuname,$container) = @_;
my $map = $env{'form.folder'}.'.'.$container;
- my ($output,$delwarning,$delresult,$url,$outcome);
+ my ($output,$delwarning,$delresult,$url);
my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
if ($fatal) {
if ($container eq 'page') {
@@ -3100,9 +3106,8 @@
$delwarning = &mt('An error occurred updating the contents of the current folder.');
}
} else {
- $outcome = 'ok';
+ $delresult = &mt('Archive file removed.');
}
- $delresult = &mt('Archive file removed.');
}
}
$env{'form.cmd'} = $currcmd;
@@ -3117,7 +3122,7 @@
$delresult.
'</p>';
}
- return ($output,$url,$outcome);
+ return $output;
}
sub generate_admin_options {
@@ -3166,7 +3171,7 @@
$activetab = $env{'form.active'};
}
my $backicon = $iconpath.'clickhere.gif';
- my $backtext = &mt('Back to Overview');
+ my $backtext = &mt('To Overview');
$form = '<div class="LC_Box" style="margin:0;">'.
'<ul id="navigation'.$tid.'" class="LC_TabContent">'.
'<li class="goback">'.
More information about the LON-CAPA-cvs
mailing list