--- loncom/publisher/loncfile.pm 2019/03/06 02:31:16 1.125 +++ loncom/publisher/loncfile.pm 2024/08/24 22:09:30 1.129.2.1 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.125 2019/03/06 02:31:16 raeburn Exp $ +# $Id: loncfile.pm,v 1.129.2.1 2024/08/24 22:09:30 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,13 +40,13 @@ Apache::loncfile - Authoring space file management. =head1 SYNOPSIS - - Content handler for buttons on the top frame of the construction space + + Content handler for buttons on the top frame of the construction space directory. =head1 INTRODUCTION - loncfile is invoked when buttons in the top frame of the construction + loncfile is invoked when buttons in the top frame of the construction space directory listing are clicked. All operations proceed in two phases. The first phase describes to the user exactly what will be done. If the user confirms the operation, the second phase commits the operation and indicates @@ -70,10 +70,10 @@ use HTML::Entities(); use Apache::Constants qw(:common :http :methods); use Apache::lonnet; use Apache::loncommon(); +use Apache::lonhtmlcommon; use Apache::lonlocal; use LONCAPA qw(:DEFAULT :match); - my $DEBUG=0; my $r; # Needs to be global for some stuff RF. @@ -88,13 +88,13 @@ my $r; # Needs to be global for some Parameters: =over 4 - + =item $request - The current request operation. =item $message - The message to put in the log file. =back - + Returns: nothing. @@ -125,7 +125,7 @@ sub done { =item URLToPath($url) Convert a URL to a file system path. - + In order to manipulate the construction space objects, it is necessary to access url identified objects a filespace objects. This function translates a construction space URL to a file system path. @@ -134,14 +134,14 @@ sub done { =over 4 =item Url - string [in] The url to convert. - + =back - + Returns: =over 4 -=item The corresponding file system path. +=item The corresponding file system path. =back @@ -210,14 +210,14 @@ sub obsolete_unpub { # see if directory is empty # ignores any .meta, .save, .bak, and .log files created for a previously # published file, which has since been marked obsolete and deleted. -# ignores a .DS_Store file put there when viewing directory via webDAV on MacOS. +# ignores a .DS_Store file put there when viewing directory via webDAV on MacOS. sub empty_directory { my ($dirname,$phase) = @_; if (opendir DIR, $dirname) { my @files = grep(!/^\.\.?$/, readdir(DIR)); # ignore . and .. - if (@files) { + if (@files) { my @orphans = grep(/\.(meta|save|log|bak|DS_Store)$/,@files); - if (scalar(@files) - scalar(@orphans) > 0) { + if (scalar(@files) - scalar(@orphans) > 0) { return 0; } else { if (($phase eq 'Delete2') && (@orphans > 0)) { @@ -269,7 +269,7 @@ Returns: =item string - Either where the resource exists as an html string that can be embedded in a dialog or an empty string if the resource does not exist. - + =back =cut @@ -313,7 +313,7 @@ sub exists { =pod =item checksuffix($old, $new) - + Determine if a resource filename suffix (the stuff after the .) would change as a result of this operation. @@ -463,7 +463,7 @@ Parameters: =item $user - string [in] - Name of the user that is initiating the request. -=item $directory - string [in] - Directory in which the operation is +=item $directory - string [in] - Directory in which the operation is being done relative to the top level construction space directory. @@ -479,14 +479,14 @@ sub CloseForm2 { =pod =item Rename1($request, $filename, $user, $domain, $dir) - + Perform phase 1 processing of the file rename operation. Parameters: =over 4 -=item $request - Apache Request Object [in] The request object for the +=item $request - Apache Request Object [in] The request object for the current request. =item $filename - The filename relative to construction space. @@ -509,7 +509,7 @@ new filename relative to the current dir =back -=cut +=cut sub Rename1 { my ($request, $user, $domain, $fn, $newfilename, $style) = @_; @@ -587,7 +587,7 @@ sub Rename1 { ); return; } - + } =pod @@ -601,7 +601,7 @@ Parameters: =over 4 -=item $request - Apache Request Object [in] request object for the current +=item $request - Apache Request Object [in] request object for the current request. =item $user - string [in] Name of the user initiating the request. @@ -632,7 +632,7 @@ sub Delete1 { ); return; } - } else { + } else { unless (&obsolete_unpub($user,$domain,$fn)) { $request->print('
'
.&mt('Cannot delete non-obsolete published file.')
@@ -669,7 +669,7 @@ Parameters:
=over 4
-=item $request - Apache Request Object [in] request object for the current
+=item $request - Apache Request Object [in] request object for the current
request.
=item $user - string [in] Name of the user initiating the request.
@@ -695,7 +695,7 @@ sub Copy1 {
if ($newfilename =~ m|/[^\.]+$|) {
#no extension add on original extension
if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; }
- }
+ }
$newfilename=~s://+:/:g; # remove duplicate /
while ($newfilename=~m:/\.\./:) {
$newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
@@ -740,7 +740,7 @@ sub Copy1 {
=pod
=item NewDir1
-
+
Does all phase 1 processing of directory creation:
Ensures that the user provides a new directory name,
and that the directory does not already exist.
@@ -758,7 +758,7 @@ Parameters:
=item $fn - source file.
-=item $newdir - Name of the directory to be created; path relative to the
+=item $newdir - Name of the directory to be created; path relative to the
top level of construction space.
=back
@@ -819,10 +819,223 @@ sub Decompress1 {
}
}
+sub Archive1 {
+ my ($request,$fn) = @_;
+ my @posstypes = qw(problem library sty sequence page task rights meta xml html xhtml htm xhtm css js tex txt gif jpg jpeg png svg other);
+ my (%location_of,%defaults);
+ my ($compstyle,$canarchive,$cancompress,$numformat,$numcompress,$defext) =
+ &archive_tools(\%location_of,\%defaults);
+ if (!$canarchive) {
+ $request->print(' '.
+ &mt('This LON-CAPA instance does not seem to have either tar or zip installed.').' '
+ .&mt('No such directory: [_1]',
+ &display($fn))
+ .'
'."\n"
+ );
+ &CloseForm1($request, $fn);
+ } else {
+ $request->print(''.$title.'
'."\n".
+ '
'.&mt('Remove existing archive request?').' '."\n". + ''. + (' 'x2)."\n". + '
'."\n". + '