From 261dac37a66f5f7eb71bea394da39d21d27081aa Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 17 Oct 2004 23:11:14 +0000 Subject: [PATCH] Now Editor's FileManager is using central zip and unzip functions. NOTE: What is the courseimages.php file, I haven't tested it because I didn't find how to do it! Merged from MOODLE_14_STABLE --- lib/editor/coursefiles.php | 70 +++++++------------------------------ lib/editor/courseimages.php | 70 +++++++------------------------------ 2 files changed, 24 insertions(+), 116 deletions(-) diff --git a/lib/editor/coursefiles.php b/lib/editor/coursefiles.php index d2415279c3..f7088d2623 100644 --- a/lib/editor/coursefiles.php +++ b/lib/editor/coursefiles.php @@ -1,4 +1,4 @@ -zip)) { // Use built-in php-based zip function - $files = array(); - foreach ($USER->filelist as $file) { - $files[] = "$basedir/$file"; - } - include_once('../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); + + $files = array(); + foreach ($USER->filelist as $file) { + $files[] = "$basedir/$file"; + } + + if (!zip_files($files,"$basedir/$wdir/$name")) { + error(get_string("zipfileserror","error")); } + clearfilelist(); displaydir($wdir); @@ -493,10 +484,6 @@ case "unzip": html_header($course, $wdir); if (!empty($file)) { - $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); @@ -504,41 +491,8 @@ $file = basename($file); - if (empty($CFG->unzip)) { // Use built-in php-based unzip function - include_once('../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 "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - 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
 
\n"; - } - - } 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(); + if (!unzip_file("$basedir/$wdir/$file")) { + error(get_string("unzipfileserror","error")); } echo "
\n"; diff --git a/lib/editor/courseimages.php b/lib/editor/courseimages.php index e4fa479e4d..faf10f4764 100644 --- a/lib/editor/courseimages.php +++ b/lib/editor/courseimages.php @@ -1,4 +1,4 @@ -zip)) { // Use built-in php-based zip function - $files = array(); - foreach ($USER->filelist as $file) { - $files[] = "$basedir/$file"; - } - include_once('../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); + + $files = array(); + foreach ($USER->filelist as $file) { + $files[] = "$basedir/$file"; + } + + if (!zip_files($files,"$basedir/$wdir/$name")) { + error(get_string("zipfileserror","error")); } + clearfilelist(); displaydir($wdir); @@ -415,10 +406,6 @@ case "unzip": html_header($course, $wdir); if (!empty($file)) { - $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); @@ -426,41 +413,8 @@ $file = basename($file); - if (empty($CFG->unzip)) { // Use built-in php-based unzip function - include_once('../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(); + if (!unzip_file("$basedir/$wdir/$file")) { + error(get_string("unzipfileserror","error")); } echo "
"; -- 2.39.5