]> git.mjollnir.org Git - moodle.git/commitdiff
Now Editor's FileManager is using central zip and unzip functions.
authorstronk7 <stronk7>
Sun, 17 Oct 2004 23:11:14 +0000 (23:11 +0000)
committerstronk7 <stronk7>
Sun, 17 Oct 2004 23:11:14 +0000 (23:11 +0000)
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
lib/editor/courseimages.php

index d2415279c3332c7af17e8f1b8a48c547a5626f40..f7088d2623e57523947b64f21be6c45b8921218f 100644 (file)
@@ -1,4 +1,4 @@
-<?PHP // $Id$
+<?php // $Id$
 
 //  Manage all uploaded files in a course file area
 
             if (!empty($name)) {
                 html_header($course, $wdir);
                 $name = clean_filename($name);
-                if (empty($CFG->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);
 
         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);
 
 
                 $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 "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=\"640\">\n";
-                        echo "<tr><th align=\"left\">$strname</th>\n";
-                        echo "<th align=\"right\">$strsize</th>\n";
-                        echo "<th align=\"right\">$strmodified</th>\n";
-                        echo "<th align=\"right\">$strstatus</th></tr>\n";
-                        foreach ($list as $item) {
-                            echo "<tr>";
-                            $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 "<td>&nbsp;</td>";
-                            }
-                            $filedate  = userdate($item['mtime'], get_string("strftimedatetime"));
-                            print_cell("right", $filedate);
-                            print_cell("right", $item['status']);
-                            echo "</tr>";
-                        }
-                        echo "</table>\n";
-                    }
-
-                } else {                     // Use external unzip program
-                    print_simple_box_start("center");
-                    echo "<pre>";
-                    $command = "cd $basedir/$wdir ; $CFG->unzip -o $file 2>&1";
-                    passthru($command);
-                    echo "</pre>";
-                    print_simple_box_end();
+                if (!unzip_file("$basedir/$wdir/$file")) {
+                    error(get_string("unzipfileserror","error"));
                 }
 
                 echo "<center><form action=\"".$_SERVER['PHP_SELF']."\" method=\"get\">\n";
index e4fa479e4dbfce9891595893de5bfdec3c675699..faf10f4764d1e034301f94de01059621b5d72ff9 100644 (file)
@@ -1,4 +1,4 @@
-<?PHP // $Id$
+<?php // $Id$
 
 //  Manage all uploaded files in a course file area
 
             if (!empty($name)) {
                 html_header($course, $wdir);
                 $name = clean_filename($name);
-                if (empty($CFG->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);
                    
         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);
 
 
                 $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 "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=640>";
-                        echo "<tr><th align=left>$strname</th>";
-                        echo "<th align=right>$strsize</th>";
-                        echo "<th align=right>$strmodified</th>";
-                        echo "<th align=right>$strstatus</th></tr>";
-                        foreach ($list as $item) {
-                            echo "<tr>";
-                            $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 "<td>&nbsp;</td>";
-                            }
-                            $filedate  = userdate($item['mtime'], get_string("strftimedatetime"));
-                            print_cell("right", $filedate);
-                            print_cell("right", $item['status']);
-                            echo "</tr>";
-                        }
-                        echo "</table>";
-                    }
-                    
-                } else {                     // Use external unzip program
-                    print_simple_box_start("center");
-                    echo "<PRE>";
-                    $command = "cd $basedir/$wdir ; $CFG->unzip -o $file 2>&1";
-                    passthru($command);
-                    echo "</PRE>";
-                    print_simple_box_end();
+                if (!unzip_file("$basedir/$wdir/$file")) {
+                    error(get_string("unzipfileserror","error"));
                 }
 
                 echo "<CENTER><FORM ACTION=\"".$_SERVER['PHP_SELF']."\" METHOD=get>";