]> git.mjollnir.org Git - moodle.git/commitdiff
Modifications to allow Moodle files management page to use PclZip
authormoodler <moodler>
Sun, 6 Apr 2003 05:53:47 +0000 (05:53 +0000)
committermoodler <moodler>
Sun, 6 Apr 2003 05:53:47 +0000 (05:53 +0000)
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)

files/index.php
lang/en/moodle.php
lib/defaults.php

index 7c7d501ccccad9e40b3900084abbda5cc9b2b02b..5a48baa25db34cb2787467d84c243c5c3b730f73 100644 (file)
         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 "</td></tr></table></body></html>";
             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);
                     
         case "unzip":
             html_header($course, $wdir);
             if (!empty($file)) {
-                echo "<P ALIGN=CENTER>Unzipping $file:</P>";
-                print_simple_box_start("center");
-                echo "<PRE>";
+                $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 "<P ALIGN=CENTER>$strunpacking:</P>";
+
                 $file = basename($file);
-                $command = "cd $basedir/$wdir ; $CFG->unzip -o $file 2>&1";
-                passthru($command);
-                echo "</PRE>";
-                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 "<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();
+                }
+
                 echo "<CENTER><FORM ACTION=index.php METHOD=get>";
                 echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
                 echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
                 echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
-                echo " <INPUT TYPE=submit VALUE=\"OK\">";
+                echo " <INPUT TYPE=submit VALUE=\"$strok\">";
                 echo "</FORM>";
                 echo "</CENTER>";
             } else {
             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 "<P ALIGN=CENTER>$strlistfiles:</P>";
+                $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 "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=640>";
+                    echo "<tr><th align=left>$strname</th><th align=right>$strsize</th><th align=right>$strmodified</th></tr>";
+                    foreach ($list as $item) {
+                        echo "<tr>";
+                        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);
+                        echo "</tr>";
+                    }
+                    echo "</table>";
+                }
+                echo "<br><center><form action=index.php method=get>";
+                echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
+                echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
+                echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
+                echo " <INPUT TYPE=submit VALUE=\"$strok\">";
+                echo "</FORM>";
+                echo "</CENTER>";
+            } 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 "<FORM ACTION=\"index.php\" METHOD=post NAME=dirform>";
@@ -621,7 +714,8 @@ function displaydir ($wdir) {
             if ($icon == "text.gif" || $icon == "html.gif") {
                 $edittext = "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit\">$stredit</A>";
             } else if ($icon == "zip.gif") {
-                $edittext = "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip\">$strunzip</A>";
+                $edittext = "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip\">$strunzip</A>&nbsp;";
+                $edittext .= "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip\">$strlist</A> ";
             } else {
                 $edittext = "";
             }
index 730df260ddf65a077808f7507b4fb1ac7b9e51c4..f8ec58ef7a33d57d26d60543a803c89a9625dc7f 100644 (file)
@@ -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";
index 7dee176a108cb7f30dba91c750177f79b7afdbdd..66211b785374d475d394dfbb81ffe946f663fb2e 100644 (file)
@@ -14,8 +14,8 @@
        "smtppass"         => "",
        "gdversion"        =>  1,
        "longtimenosee"    =>  100,
-       "zip"              => "/usr/bin/zip",
-       "unzip"            => "/usr/bin/unzip",
+       "zip"              => "",
+       "unzip"            => "",
        "slasharguments"   =>  1,
        "htmleditor"       =>  true,
        "proxyhost"        => "",