Index: moodlelib.php =================================================================== --- moodlelib.php (.../vender/moodle_16_stable/lib/moodlelib.php) (revision 854) +++ moodlelib.php (.../branches/bit16/lib/moodlelib.php) (revision 854) @@ -6466,7 +6475,7 @@ return preg_replace('/(\/|\\\){1,}/','/',$path); } -function zip_files ($originalfiles, $destination) { +function zip_files ($originalfiles, $destination, $charset = 'UTF-8') { //Zip an array of files/dirs to a destination zip file //Both parameters must be FULL paths to the files/dirs @@ -6499,6 +6508,8 @@ //Clean destination filename $destfilename = clean_filename($destfilename); + $CFG->zip_charset = $charset; + //Now check and prepare every file $files = array(); $origpath = NULL; @@ -6534,7 +6545,9 @@ include_once("$CFG->libdir/pclzip/pclzip.lib.php"); $archive = new PclZip(cleardoubleslashes("$destpath/$destfilename")); - if (($list = $archive->create($files, PCLZIP_OPT_REMOVE_PATH,$origpath) == 0)) { + if (($list = $archive->create($files, + PCLZIP_OPT_REMOVE_PATH,$origpath, + PCLZIP_CB_PRE_ADD, 'zip_cleanfilename') == 0)) { notice($archive->errorInfo(true)); return false; } @@ -6560,7 +6573,17 @@ return true; } -function unzip_file ($zipfile, $destination = '', $showstatus = true) { +function zip_cleanfilename($p_event, &$p_header) { + global $CFG; + + if ($CFG->zip_charset != 'UTF-8') { + $p_header['stored_filename'] = iconv('UTF-8', $CFG->zip_charset, $p_header['stored_filename']); + } + + return 1; +} + +function unzip_file ($zipfile, $destination = '', $showstatus = true, $charset = 'UTF-8') { //Unzip one zip file to a destination dir //Both parameters must be FULL paths //If destination isn't specified, it will be the @@ -6605,6 +6628,9 @@ return false; } + //Set charset for unzip + $CFG->unzip_charset = $charset; + //Check destination path is writable. TODO!! //Everything is ready: @@ -6649,6 +6675,7 @@ function unzip_cleanfilename ($p_event, &$p_header) { //This function is used as callback in unzip_file() function //to clean illegal characters for given platform and to prevent directory traversal. + global $CFG; //Produces the same result as info-zip unzip. $p_header['filename'] = ereg_replace('[[:cntrl:]]', '', $p_header['filename']); //strip control chars first! $p_header['filename'] = ereg_replace('\.\.+', '', $p_header['filename']); //directory traversal protection @@ -6662,6 +6689,9 @@ // MacosX: ?? } $p_header['filename'] = cleardoubleslashes($p_header['filename']); //normalize the slashes/backslashes + if ($CFG->unzip_charset != 'UTF-8') { + $p_header['filename'] = iconv($CFG->unzip_charset, 'UTF-8', $p_header['filename']); + } return 1; }