]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15928 switched to zip PHP extensions
authorskodak <skodak>
Mon, 4 Aug 2008 16:45:08 +0000 (16:45 +0000)
committerskodak <skodak>
Mon, 4 Aug 2008 16:45:08 +0000 (16:45 +0000)
admin/environment.xml
admin/settings/server.php
backup/backuplib.php
install/stringnames.txt
lang/en_utf8/admin.php
lib/db/upgrade.php
lib/deprecatedlib.php
lib/moodlelib.php
version.php

index e67c9e0b67cd50c68bcc2631e3067172b4ccad65..92d1c9509fdc6d28b0e65098a50d27bcdf5a1e46 100644 (file)
           <ON_CHECK message="xmlrpcrecommended" />
         </FEEDBACK>
       </PHP_EXTENSION>
-     <PHP_EXTENSION name="ctype" level="required">
+      <PHP_EXTENSION name="ctype" level="required">
         <FEEDBACK>
           <ON_ERROR message="ctyperequired" />
         </FEEDBACK>
       </PHP_EXTENSION>
+      <PHP_EXTENSION name="zip" level="required">
+        <FEEDBACK>
+          <ON_ERROR message="ziprequired" />
+        </FEEDBACK>
+      </PHP_EXTENSION>
     </PHP_EXTENSIONS>
     <CUSTOM_CHECKS>
       <CUSTOM_CHECK file="lib/customcheckslib.php" function="php_check_register_globals" level="optional">
index 095c0b5850df8921331d233eb7989c2ca9e38e69..d00d24bb3b70d967d87a6434ead08cdcff9c3c58 100644 (file)
@@ -10,8 +10,6 @@ $temp = new admin_settingpage('systempaths', get_string('systempaths','admin'));
 $temp->add(new admin_setting_configselect('gdversion', get_string('gdversion','admin'), get_string('configgdversion', 'admin'), check_gd_version(), array('0' => get_string('gdnot'),
                                                                                                                                                           '1' => get_string('gd1'),
                                                                                                                                                           '2' => get_string('gd2'))));
-$temp->add(new admin_setting_configexecutable('zip', get_string('pathtozip','admin'), get_string('configzip', 'admin'), ''));
-$temp->add(new admin_setting_configexecutable('unzip', get_string('pathtounzip','admin'), get_string('configunzip', 'admin'), ''));
 $temp->add(new admin_setting_configexecutable('pathtodu', get_string('pathtodu', 'admin'), get_string('configpathtodu', 'admin'), ''));
 $temp->add(new admin_setting_configexecutable('aspellpath', get_string('aspellpath', 'admin'), get_string('edhelpaspellpath'), ''));
 $ADMIN->add('server', $temp, 0);
index 3b62bfed9a0697d5df8246b3b7e30d1dab340804..336bce67866ca2d8ebc1ffa5219c956fe190850d 100644 (file)
         fwrite ($bf,full_tag("DATE",2,false,$preferences->backup_unique_code));
         //The original site wwwroot
         fwrite ($bf,full_tag("ORIGINAL_WWWROOT",2,false,$CFG->wwwroot));
-        //The zip method used
-        if (!empty($CFG->zip)) {
-            $zipmethod = 'external';
-        } else {
-            $zipmethod = 'internal';
-        }
         //Indicate if it includes external MNET users
         $sql = "SELECT b.old_id
                   FROM {backup_ids} b
         if ($DB->record_exists_sql($sql, array($preferences->backup_unique_code, $CFG->mnet_localhost_id))) {
             fwrite ($bf,full_tag("MNET_REMOTEUSERS",2,false,'true'));
         }
-        fwrite ($bf,full_tag("ZIP_METHOD",2,false,$zipmethod));
         //Te includes tag
         fwrite ($bf,start_tag("DETAILS",2,true));
         //Now, go to mod element of preferences to print its status
index 8b17f03a16aefbc12a0a53ad0f227c9ae7c495cb..41a8e479eed4d4e2fa9fe9e3bddf7622b88f5fb0 100644 (file)
@@ -251,3 +251,4 @@ wwwroot
 wwwrooterror
 yourchoice
 xmlrpcrecommended
+ziprequired
index 004ed39a51538fbaf88ebaafc380a05efcce41d8..d8308239b77eccdf5987db6329910e2569604334 100644 (file)
@@ -783,5 +783,6 @@ $string['webproxy'] = 'Web proxy';
 $string['webproxyinfo'] = 'Fill in following options if your Moodle server can not access internet directly. Internet access is required for download of environment data, language packs, RSS feeds, timezones, etc.<br /><em>PHP cURL extension is highly recommended.</em>';
 $string['xmlrpcrecommended'] = 'Installing the optional xmlrpc extension is useful for Moodle Networking functionality.';
 $string['xmlstrictheaders'] = 'XML strict headers';
+$string['ziprequired'] = 'The Zip PHP extension is now required by Moodle, info-ZIP binaries or PclZip library are not used anymore.';
 
 ?>
index 3eb0821f0bfadf285ba80107fe6ebcf314b070a1..ce0461e02c3867a371675005915ad55091bc0476 100644 (file)
@@ -566,6 +566,13 @@ function xmldb_main_upgrade($oldversion=0) {
         upgrade_main_savepoint($result, 2008080400);
     }
 
+    if ($result && $oldversion < 2008080401) {
+        // zip binaries not used anymore
+        unset_config('zip');
+        unset_config('unzip');
+        /// Main savepoint reached
+        upgrade_main_savepoint($result, 2008080401);
+    }
     return $result;
 }
 
index 213ac7b46e3fd0b6e5ad2b56cdf01d2a6b590235..cfeac99e1e35a6fd3657d617961c9a23bc8f7a87 100644 (file)
@@ -389,6 +389,74 @@ function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
     return true;
 }
 
+/**
+ * Zip an array of files/dirs to a destination zip file
+ * Both parameters must be FULL paths to the files/dirs
+ */
+function zip_files ($originalfiles, $destination) {
+    global $CFG;
+
+    //Extract everything from destination
+    $path_parts = pathinfo(cleardoubleslashes($destination));
+    $destpath = $path_parts["dirname"];       //The path of the zip file
+    $destfilename = $path_parts["basename"];  //The name of the zip file
+    $extension = $path_parts["extension"];    //The extension of the file
+
+    //If no file, error
+    if (empty($destfilename)) {
+        return false;
+    }
+
+    //If no extension, add it
+    if (empty($extension)) {
+        $extension = 'zip';
+        $destfilename = $destfilename.'.'.$extension;
+    }
+
+    //Check destination path exists
+    if (!is_dir($destpath)) {
+        return false;
+    }
+
+    //Check destination path is writable. TODO!!
+
+    //Clean destination filename
+    $destfilename = clean_filename($destfilename);
+
+    //Now check and prepare every file
+    $files = array();
+    $origpath = NULL;
+
+    foreach ($originalfiles as $file) {  //Iterate over each file
+        //Check for every file
+        $tempfile = cleardoubleslashes($file); // no doubleslashes!
+        //Calculate the base path for all files if it isn't set
+        if ($origpath === NULL) {
+            $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
+        }
+        //See if the file is readable
+        if (!is_readable($tempfile)) {  //Is readable
+            continue;
+        }
+        //See if the file/dir is in the same directory than the rest
+        if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
+            continue;
+        }
+        //Add the file to the array
+        $files[] = $tempfile;
+    }
+
+    $zipfiles = array();
+    $start = strlen($origpath)+1;
+    foreach($files as $file) {
+        $zipfiles[substr($file, $start)] = $file;
+    }
+
+    $packer = get_file_packer();
+
+    return $packer->zip_files_to_pathname($zipfiles, $destfilename);
+}
+
 /////////////////////////////////////////////////////////////
 /// Old functions not used anymore - candidates for removal
 /////////////////////////////////////////////////////////////
index 44c3afeac93f58141b0229d513ad1b8c34be6482..30b6c2e4b9189649953c53fbbd8b103bc2d573ce 100644 (file)
@@ -7227,176 +7227,6 @@ function cleardoubleslashes ($path) {
     return preg_replace('/(\/|\\\){1,}/','/',$path);
 }
 
-function zip_files ($originalfiles, $destination) {
-//Zip an array of files/dirs to a destination zip file
-//Both parameters must be FULL paths to the files/dirs
-
-    global $CFG;
-
-    //Extract everything from destination
-    $path_parts = pathinfo(cleardoubleslashes($destination));
-    $destpath = $path_parts["dirname"];       //The path of the zip file
-    $destfilename = $path_parts["basename"];  //The name of the zip file
-    $extension = $path_parts["extension"];    //The extension of the file
-
-    //If no file, error
-    if (empty($destfilename)) {
-        return false;
-    }
-
-    //If no extension, add it
-    if (empty($extension)) {
-        $extension = 'zip';
-        $destfilename = $destfilename.'.'.$extension;
-    }
-
-    //Check destination path exists
-    if (!is_dir($destpath)) {
-        return false;
-    }
-
-    //Check destination path is writable. TODO!!
-
-    //Clean destination filename
-    $destfilename = clean_filename($destfilename);
-
-    //Now check and prepare every file
-    $files = array();
-    $origpath = NULL;
-
-    foreach ($originalfiles as $file) {  //Iterate over each file
-        //Check for every file
-        $tempfile = cleardoubleslashes($file); // no doubleslashes!
-        //Calculate the base path for all files if it isn't set
-        if ($origpath === NULL) {
-            $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
-        }
-        //See if the file is readable
-        if (!is_readable($tempfile)) {  //Is readable
-            continue;
-        }
-        //See if the file/dir is in the same directory than the rest
-        if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
-            continue;
-        }
-        //Add the file to the array
-        $files[] = $tempfile;
-    }
-
-    //Everything is ready:
-    //    -$origpath is the path where ALL the files to be compressed reside (dir).
-    //    -$destpath is the destination path where the zip file will go (dir).
-    //    -$files is an array of files/dirs to compress (fullpath)
-    //    -$destfilename is the name of the zip file (without path)
-
-    //print_object($files);                  //Debug
-
-    if (empty($CFG->zip)) {    // Use built-in php-based zip function
-
-        include_once("$CFG->libdir/pclzip/pclzip.lib.php");
-        //rewrite filenames because the old method with PCLZIP_OPT_REMOVE_PATH does not work under win32
-        $zipfiles = array();
-        $start = strlen($origpath)+1;
-        foreach($files as $file) {
-            $tf = array();
-            $tf[PCLZIP_ATT_FILE_NAME] = $file;
-            $tf[PCLZIP_ATT_FILE_NEW_FULL_NAME] = substr($file, $start);
-            $zipfiles[] = $tf;
-        }
-        //create the archive
-        $archive = new PclZip(cleardoubleslashes("$destpath/$destfilename"));
-        if (($list = $archive->create($zipfiles) == 0)) {
-            notice($archive->errorInfo(true));
-            return false;
-        }
-
-    } else {                   // Use external zip program
-
-        $filestozip = "";
-        foreach ($files as $filetozip) {
-            $filestozip .= escapeshellarg(basename($filetozip));
-            $filestozip .= " ";
-        }
-        //Construct the command
-        $separator = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? ' &' : ' ;';
-        $command = 'cd '.escapeshellarg($origpath).$separator.
-                    escapeshellarg($CFG->zip).' -r '.
-                    escapeshellarg(cleardoubleslashes("$destpath/$destfilename")).' '.$filestozip;
-        //All converted to backslashes in WIN
-        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
-            $command = str_replace('/','\\',$command);
-        }
-        Exec($command);
-    }
-    return true;
-}
-
-/**
- * This function is used as callback in unzip_file() function
- * to clean illegal characters for given platform and to prevent directory traversal.
- * Produces the same result as info-zip unzip.
- */
-function unzip_cleanfilename ($p_event, &$p_header) {
-    $p_header['filename'] = ereg_replace('[[:cntrl:]]', '', $p_header['filename']); //strip control chars first!
-    $p_header['filename'] = ereg_replace('\.\.+', '', $p_header['filename']); //directory traversal protection
-    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
-        $p_header['filename'] = ereg_replace('[:*"?<>|]', '_', $p_header['filename']); //replace illegal chars
-        $p_header['filename'] = ereg_replace('^([a-zA-Z])_', '\1:', $p_header['filename']); //repair drive letter
-    } else {
-        //Add filtering for other systems here
-        // BSD: none (tested)
-        // Linux: ??
-        // MacosX: ??
-    }
-    $p_header['filename'] = cleardoubleslashes($p_header['filename']); //normalize the slashes/backslashes
-    return 1;
-}
-
-/**
- * This function shows the results of the unzip execution
- * depending of the value of the $CFG->zip, results will be
- * text or an array of files.
- */
-function unzip_show_status ($list,$removepath) {
-    global $CFG;
-
-    if (empty($CFG->unzip)) {    // Use built-in php-based zip function
-        $strname = get_string("name");
-        $strsize = get_string("size");
-        $strmodified = get_string("modified");
-        $strstatus = get_string("status");
-        echo "<table width=\"640\">";
-        echo "<tr><th class=\"header\" scope=\"col\">$strname</th>";
-        echo "<th class=\"header\" align=\"right\" scope=\"col\">$strsize</th>";
-        echo "<th class=\"header\" align=\"right\" scope=\"col\">$strmodified</th>";
-        echo "<th class=\"header\" align=\"right\" scope=\"col\">$strstatus</th></tr>";
-        foreach ($list as $item) {
-            echo "<tr>";
-            $item['filename'] = str_replace(cleardoubleslashes($removepath).'/', "", $item['filename']);
-            print_cell("left", s($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 zip program
-        print_simple_box_start("center");
-        echo "<pre>";
-        foreach ($list as $item) {
-            echo s(str_replace(cleardoubleslashes($removepath.'/'), '', $item)).'<br />';
-        }
-        echo "</pre>";
-        print_simple_box_end();
-    }
-}
-
 /**
  * Is current ip in give list?
  * @param string $list
index e23105522ca57a552206df8e7344f92a35d0e896..140b17fbebc4557ac102ba9d6dfcccc5cf7b3ad0 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2008080400;  // YYYYMMDD   = date of the last version bump
+    $version = 2008080401;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20080804)';  // Human-friendly version name