]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15919 deprecated old unzip_files()
authorskodak <skodak>
Sat, 2 Aug 2008 18:59:00 +0000 (18:59 +0000)
committerskodak <skodak>
Sat, 2 Aug 2008 18:59:00 +0000 (18:59 +0000)
lib/deprecatedlib.php
lib/moodlelib.php

index fdc76f9568b7a15e0d04e1d082c1342576d31896..213ac7b46e3fd0b6e5ad2b56cdf01d2a6b590235 100644 (file)
@@ -328,6 +328,67 @@ function detect_munged_arguments($string, $allowdots=1) {
 }
 
 
+/**
+ * Unzip one zip file to a destination dir
+ * Both parameters must be FULL paths
+ * If destination isn't specified, it will be the
+ * SAME directory where the zip file resides.
+ */
+function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
+    global $CFG;
+
+    //Extract everything from zipfile
+    $path_parts = pathinfo(cleardoubleslashes($zipfile));
+    $zippath = $path_parts["dirname"];       //The path of the zip file
+    $zipfilename = $path_parts["basename"];  //The name of the zip file
+    $extension = $path_parts["extension"];    //The extension of the file
+
+    //If no file, error
+    if (empty($zipfilename)) {
+        return false;
+    }
+
+    //If no extension, error
+    if (empty($extension)) {
+        return false;
+    }
+
+    //Clear $zipfile
+    $zipfile = cleardoubleslashes($zipfile);
+
+    //Check zipfile exists
+    if (!file_exists($zipfile)) {
+        return false;
+    }
+
+    //If no destination, passed let's go with the same directory
+    if (empty($destination)) {
+        $destination = $zippath;
+    }
+
+    //Clear $destination
+    $destpath = rtrim(cleardoubleslashes($destination), "/");
+
+    //Check destination path exists
+    if (!is_dir($destpath)) {
+        return false;
+    }
+
+    $result = get_file_packer()->unzip_files_to_pathname($zipfile, $destpath);
+
+    if ($result === false) {
+        return false;
+    }
+
+    foreach ($result as $status) {
+        if ($status !== true) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
 /////////////////////////////////////////////////////////////
 /// Old functions not used anymore - candidates for removal
 /////////////////////////////////////////////////////////////
index ed8664bb94f056782162f6fdd1e62eddb49955b2..fe3080fd1bf687dd4b671587ac18da81a04604dd 100644 (file)
@@ -7302,98 +7302,6 @@ function zip_files ($originalfiles, $destination) {
     return true;
 }
 
-/**
- * Unzip one zip file to a destination dir
- * Both parameters must be FULL paths
- * If destination isn't specified, it will be the
- * SAME directory where the zip file resides.
- */
-function unzip_file($zipfile, $destination = '', $showstatus = true) {
-    global $CFG;
-
-    //Extract everything from zipfile
-    $path_parts = pathinfo(cleardoubleslashes($zipfile));
-    $zippath = $path_parts["dirname"];       //The path of the zip file
-    $zipfilename = $path_parts["basename"];  //The name of the zip file
-    $extension = $path_parts["extension"];    //The extension of the file
-
-    //If no file, error
-    if (empty($zipfilename)) {
-        return false;
-    }
-
-    //If no extension, error
-    if (empty($extension)) {
-        return false;
-    }
-
-    //Clear $zipfile
-    $zipfile = cleardoubleslashes($zipfile);
-
-    //Check zipfile exists
-    if (!file_exists($zipfile)) {
-        return false;
-    }
-
-    //If no destination, passed let's go with the same directory
-    if (empty($destination)) {
-        $destination = $zippath;
-    }
-
-    //Clear $destination
-    $destpath = rtrim(cleardoubleslashes($destination), "/");
-
-    //Check destination path exists
-    if (!is_dir($destpath)) {
-        return false;
-    }
-
-    //Check destination path is writable. TODO!!
-
-    //Everything is ready:
-    //    -$zippath is the path where the zip file resides (dir)
-    //    -$zipfilename is the name of the zip file (without path)
-    //    -$destpath is the destination path where the zip file will uncompressed (dir)
-
-    $list = null;
-
-    if (empty($CFG->unzip)) {    // Use built-in php-based unzip function
-
-        include_once("$CFG->libdir/pclzip/pclzip.lib.php");
-        $archive = new PclZip(cleardoubleslashes("$zippath/$zipfilename"));
-        if (!$list = $archive->extract(PCLZIP_OPT_PATH, $destpath,
-                                       PCLZIP_CB_PRE_EXTRACT, 'unzip_cleanfilename',
-                                       PCLZIP_OPT_EXTRACT_DIR_RESTRICTION, $destpath)) {
-            if (!empty($showstatus)) {
-                notice($archive->errorInfo(true));
-            }
-            return false;
-        }
-
-    } else {                     // Use external unzip program
-
-        $separator = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? ' &' : ' ;';
-        $redirection = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? '' : ' 2>&1';
-
-        $command = 'cd '.escapeshellarg($zippath).$separator.
-                    escapeshellarg($CFG->unzip).' -o '.
-                    escapeshellarg(cleardoubleslashes("$zippath/$zipfilename")).' -d '.
-                    escapeshellarg($destpath).$redirection;
-        //All converted to backslashes in WIN
-        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
-            $command = str_replace('/','\\',$command);
-        }
-        Exec($command,$list);
-    }
-
-    //Display some info about the unzip execution
-    if ($showstatus) {
-        unzip_show_status($list,$destpath);
-    }
-
-    return true;
-}
-
 /**
  * This function is used as callback in unzip_file() function
  * to clean illegal characters for given platform and to prevent directory traversal.