From: moodler Date: Sun, 6 Apr 2003 05:53:47 +0000 (+0000) Subject: Modifications to allow Moodle files management page to use PclZip X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e64984a0bb762f508550288202d6d0b44e0e3e0b;p=moodle.git Modifications to allow Moodle files management page to use PclZip instead of external zip programs. To use the internal PclZip, the config variables "zip" and "unzip" must be left blank. Code for PclZip integration originally from Robert Hetzel, though I've expanded it and modified it a lot. The zip files seem compatible with itself and Windows XP, but I had a compatibility problem trying to unzip a PclZip file using Zip 2.3 on Linux (directories are unpacked as empty files) --- diff --git a/files/index.php b/files/index.php index 7c7d501ccc..5a48baa25d 100644 --- a/files/index.php +++ b/files/index.php @@ -24,14 +24,6 @@ error("Only teachers can edit files"); } - if (!$CFG->zip) { - $CFG->zip = "/usr/bin/zip"; - } - - if (!$CFG->unzip) { - $CFG->unzip = "/usr/bin/unzip"; - } - function html_footer() { global $course; echo ""; @@ -336,13 +328,25 @@ if (!empty($name)) { html_header($course, $wdir); $name = clean_filename($name); - $files = ""; - foreach ($USER->filelist as $file) { - $files .= basename($file); - $files .= " "; + if (empty($CFG->zip)) { // Use built-in php-based zip function + $files = array(); + foreach ($USER->filelist as $file) { + $files[] = "$basedir/$wdir$file"; + } + include_once('../lib/pclzip/pclzip.lib.php'); + $archive = new PclZip("$basedir/$wdir/$name"); + if (($list = $archive->create($files,'',"$basedir/$wdir/")) == 0) { + error($archive->errorInfo(true)); + } + } else { // Use external zip program + $files = ""; + foreach ($USER->filelist as $file) { + $files .= basename($file); + $files .= " "; + } + $command = "cd $basedir/$wdir ; $CFG->zip -r $name $files"; + Exec($command); } - $command = "cd $basedir/$wdir ; $CFG->zip -r $name $files"; - Exec($command); clearfilelist(); displaydir($wdir); @@ -382,19 +386,59 @@ case "unzip": html_header($course, $wdir); if (!empty($file)) { - echo "

Unzipping $file:

"; - print_simple_box_start("center"); - echo "
";
+                $strname = get_string("name");
+                $strsize = get_string("size");
+                $strmodified = get_string("modified");
+                $strstatus = get_string("status");
+                $strok = get_string("ok");
+                $strunpacking = get_string("unpacking", "", $file);
+
+                echo "

$strunpacking:

"; + $file = basename($file); - $command = "cd $basedir/$wdir ; $CFG->unzip -o $file 2>&1"; - passthru($command); - echo "
"; - print_simple_box_end(); + + if (empty($CFG->unzip)) { // Use built-in php-based unzip function + include_once('../lib/pclzip/pclzip.lib.php'); + $archive = new PclZip("$basedir/$wdir/$file"); + if (!$list = $archive->extract("$basedir/$wdir")) { + error($archive->errorInfo(true)); + } else { // print some output + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + foreach ($list as $item) { + echo ""; + $item['filename'] = str_replace("$basedir/$wdir/", "", $item['filename']); + print_cell("left", $item['filename']); + if (! $item['folder']) { + print_cell("right", display_size($item['size'])); + } else { + echo ""; + } + $filedate = userdate($item['mtime'], get_string("strftimedatetime")); + print_cell("right", $filedate); + print_cell("right", $item['status']); + echo ""; + } + echo "
$strname$strsize$strmodified$strstatus
 
"; + } + + } else { // Use external unzip program + print_simple_box_start("center"); + echo "
";
+                    $command = "cd $basedir/$wdir ; $CFG->unzip -o $file 2>&1";
+                    passthru($command);
+                    echo "
"; + print_simple_box_end(); + } + echo "
"; echo " "; echo " "; echo " "; - echo " "; + echo " "; echo "
"; echo "
"; } else { @@ -403,6 +447,54 @@ html_footer(); break; + case "listzip": + html_header($course, $wdir); + if (!empty($file)) { + $strname = get_string("name"); + $strsize = get_string("size"); + $strmodified = get_string("modified"); + $strok = get_string("ok"); + $strlistfiles = get_string("listfiles", "", $file); + + echo "

$strlistfiles:

"; + $file = basename($file); + + include_once('../lib/pclzip/pclzip.lib.php'); + $archive = new PclZip("$basedir/$wdir/$file"); + if (!$list = $archive->listContent("$basedir/$wdir")) { + notify($archive->errorInfo(true)); + + } else { + echo ""; + echo ""; + foreach ($list as $item) { + echo ""; + print_cell("left", $item['filename']); + if (! $item['folder']) { + print_cell("right", display_size($item['size'])); + } else { + echo ""; + } + $filedate = userdate($item['mtime'], get_string("strftimedatetime")); + print_cell("right", $filedate); + echo ""; + } + echo "
$strname$strsize$strmodified
 
"; + } + echo "
"; + echo " "; + echo " "; + echo " "; + echo " "; + echo "
"; + echo "
"; + } else { + displaydir($wdir); + } + html_footer(); + break; + + case "cancel"; clearfilelist(); @@ -541,6 +633,7 @@ function displaydir ($wdir) { $strrename = get_string("rename"); $stredit = get_string("edit"); $strunzip = get_string("unzip"); + $strlist = get_string("list"); echo "
"; @@ -621,7 +714,8 @@ function displaydir ($wdir) { if ($icon == "text.gif" || $icon == "html.gif") { $edittext = "$stredit"; } else if ($icon == "zip.gif") { - $edittext = "$strunzip"; + $edittext = "$strunzip "; + $edittext .= "$strlist "; } else { $edittext = ""; } diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 730df260dd..f8ec58ef7a 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -73,9 +73,9 @@ $string['configsessiontimeout'] = "If people logged in to this site are idle for $string['configslasharguments'] = "Files (images, uploads etc) are provided via a script using 'slash arguments' (the second option here). This method allows files to be more easily cached in web browsers, proxy servers etc. Unfortunately, some PHP servers don't allow this method, so if you have trouble viewing uploaded files or images (eg user pictures), set this variable to the first option"; $string['configsmtphosts'] = "Give the full name of one or more local SMTP servers that Moodle should use to send mail (eg 'mail.a.com' or 'mail.a.com;mail.b.com'). If you leave it blank, Moodle will use the PHP default method of sending mail."; $string['configsmtpuser'] = "If you have specified an SMTP server above, and the server requires authentication, then enter the username and password here."; -$string['configunzip'] = "Indicate the location of your unzip program (Unix only). This is needed to unpack zip archives on the server."; +$string['configunzip'] = "Indicate the location of your unzip program (Unix only, optional). If specified, this will be used to unpack zip archives on the server. If you leave this blank, then Moodle will use internal routines."; $string['configvariables'] = "Configure variables"; -$string['configzip'] = "Indicate the location of your zip program (Unix only). This is needed to create zip archives on the server."; +$string['configzip'] = "Indicate the location of your zip program (Unix only, optional). If specified, this will be used to create zip archives on the server. If you leave this blank, then Moodle will use internal routines."; $string['confirmed'] = "Your registration has been confirmed"; $string['courseupdates'] = "Course updates"; $string['cookiesenabled'] = "Cookies must be enabled in your browser"; @@ -260,6 +260,8 @@ $string['lastedited'] = "Last edited"; $string['lastmodified'] = "Last modified"; $string['lastname'] = "Last name"; $string['latestnews'] = "Latest news"; +$string['list'] = "List"; +$string['listfiles'] = "List of files in \$a"; $string['listofallpeople'] = "List of all people"; $string['license'] = "GPL License"; $string['livelogs'] = "Live logs from the past hour"; @@ -509,6 +511,7 @@ $string['undecided'] = "Undecided"; $string['unenrol'] = "Unenrol"; $string['unenrolme'] = "Unenrol me from \$a"; $string['unenrolsure'] = "Are you sure you want to unenrol \$a from this course?"; +$string['unpacking'] = "Unpacking \$a"; $string['unsafepassword'] = "Unsafe password - try something else"; $string['unusedaccounts'] = "Accounts unused for more than \$a days are automatically unenrolled"; $string['unzip'] = "Unzip"; diff --git a/lib/defaults.php b/lib/defaults.php index 7dee176a10..66211b7853 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -14,8 +14,8 @@ "smtppass" => "", "gdversion" => 1, "longtimenosee" => 100, - "zip" => "/usr/bin/zip", - "unzip" => "/usr/bin/unzip", + "zip" => "", + "unzip" => "", "slasharguments" => 1, "htmleditor" => true, "proxyhost" => "",