32 |
32 |
33 // ----- File list separator |
33 // ----- File list separator |
34 // In version 1.x of PclZip, the separator for file list is a space |
34 // In version 1.x of PclZip, the separator for file list is a space |
35 // (which is not a very smart choice, specifically for windows paths !). |
35 // (which is not a very smart choice, specifically for windows paths !). |
36 // A better separator should be a comma (,). This constant gives you the |
36 // A better separator should be a comma (,). This constant gives you the |
37 // abilty to change that. |
37 // ability to change that. |
38 // However notice that changing this value, may have impact on existing |
38 // However notice that changing this value, may have impact on existing |
39 // scripts, using space separated filenames. |
39 // scripts, using space separated filenames. |
40 // Recommanded values for compatibility with older versions : |
40 // Recommended values for compatibility with older versions : |
41 //define( 'PCLZIP_SEPARATOR', ' ' ); |
41 //define( 'PCLZIP_SEPARATOR', ' ' ); |
42 // Recommanded values for smart separation of filenames. |
42 // Recommended values for smart separation of filenames. |
43 if (!defined('PCLZIP_SEPARATOR')) { |
43 if (!defined('PCLZIP_SEPARATOR')) { |
44 define( 'PCLZIP_SEPARATOR', ',' ); |
44 define( 'PCLZIP_SEPARATOR', ',' ); |
45 } |
45 } |
46 |
46 |
47 // ----- Error configuration |
47 // ----- Error configuration |
66 define( 'PCLZIP_TEMPORARY_DIR', '' ); |
66 define( 'PCLZIP_TEMPORARY_DIR', '' ); |
67 } |
67 } |
68 |
68 |
69 // ----- Optional threshold ratio for use of temporary files |
69 // ----- Optional threshold ratio for use of temporary files |
70 // Pclzip sense the size of the file to add/extract and decide to |
70 // Pclzip sense the size of the file to add/extract and decide to |
71 // use or not temporary file. The algorythm is looking for |
71 // use or not temporary file. The algorithm is looking for |
72 // memory_limit of PHP and apply a ratio. |
72 // memory_limit of PHP and apply a ratio. |
73 // threshold = memory_limit * ratio. |
73 // threshold = memory_limit * ratio. |
74 // Recommended values are under 0.5. Default 0.47. |
74 // Recommended values are under 0.5. Default 0.47. |
75 // Samples : |
75 // Samples : |
76 // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); |
76 // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); |
246 // are added in the archive. See the parameters description for the |
246 // are added in the archive. See the parameters description for the |
247 // supported format of $p_filelist. |
247 // supported format of $p_filelist. |
248 // When a directory is in the list, the directory and its content is added |
248 // When a directory is in the list, the directory and its content is added |
249 // in the archive. |
249 // in the archive. |
250 // In this synopsis, the function takes an optional variable list of |
250 // In this synopsis, the function takes an optional variable list of |
251 // options. See bellow the supported options. |
251 // options. See below the supported options. |
252 // Parameters : |
252 // Parameters : |
253 // $p_filelist : An array containing file or directory names, or |
253 // $p_filelist : An array containing file or directory names, or |
254 // a string containing one filename or one directory name, or |
254 // a string containing one filename or one directory name, or |
255 // a string containing a list of filenames and/or directory |
255 // a string containing a list of filenames and/or directory |
256 // names separated by spaces. |
256 // names separated by spaces. |
680 // If you want to ignore the 'root' part of path of the memorized files |
680 // If you want to ignore the 'root' part of path of the memorized files |
681 // you can indicate this in the optional $p_remove_path parameter. |
681 // you can indicate this in the optional $p_remove_path parameter. |
682 // By default, if a newer file with the same name already exists, the |
682 // By default, if a newer file with the same name already exists, the |
683 // file is not extracted. |
683 // file is not extracted. |
684 // |
684 // |
685 // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions |
685 // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH options |
686 // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append |
686 // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append |
687 // at the end of the path value of PCLZIP_OPT_PATH. |
687 // at the end of the path value of PCLZIP_OPT_PATH. |
688 // Parameters : |
688 // Parameters : |
689 // $p_path : Path where the files and directories are to be extracted |
689 // $p_path : Path where the files and directories are to be extracted |
690 // $p_remove_path : First part ('root' part) of the memorized path |
690 // $p_remove_path : First part ('root' part) of the memorized path |
1062 |
1062 |
1063 // -------------------------------------------------------------------------------- |
1063 // -------------------------------------------------------------------------------- |
1064 // Function : deleteByIndex() |
1064 // Function : deleteByIndex() |
1065 // Description : |
1065 // Description : |
1066 // ***** Deprecated ***** |
1066 // ***** Deprecated ***** |
1067 // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered. |
1067 // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be preferred. |
1068 // -------------------------------------------------------------------------------- |
1068 // -------------------------------------------------------------------------------- |
1069 function deleteByIndex($p_index) |
1069 function deleteByIndex($p_index) |
1070 { |
1070 { |
1071 |
1071 |
1072 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); |
1072 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); |
1389 // ----- Error log |
1389 // ----- Error log |
1390 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
1390 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
1391 return(false); |
1391 return(false); |
1392 } |
1392 } |
1393 |
1393 |
1394 // ----- Check that the file is readeable |
1394 // ----- Check that the file is readable |
1395 if (!is_readable($this->zipname)) { |
1395 if (!is_readable($this->zipname)) { |
1396 // ----- Error log |
1396 // ----- Error log |
1397 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
1397 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
1398 return(false); |
1398 return(false); |
1399 } |
1399 } |
1696 |
1696 |
1697 // ----- Look for list sort |
1697 // ----- Look for list sort |
1698 if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
1698 if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
1699 $v_sort_flag=true; |
1699 $v_sort_flag=true; |
1700 |
1700 |
1701 // ----- TBC : An automatic sort should be writen ... |
1701 // ----- TBC : An automatic sort should be written ... |
1702 // ----- Error log |
1702 // ----- Error log |
1703 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1703 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1704 |
1704 |
1705 // ----- Return |
1705 // ----- Return |
1706 return PclZip::errorCode(); |
1706 return PclZip::errorCode(); |
2187 |
2187 |
2188 // ----- Return |
2188 // ----- Return |
2189 return $v_result; |
2189 return $v_result; |
2190 } |
2190 } |
2191 |
2191 |
2192 // ----- Read the central directory informations |
2192 // ----- Read the central directory information |
2193 $v_central_dir = array(); |
2193 $v_central_dir = array(); |
2194 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
2194 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
2195 { |
2195 { |
2196 $this->privCloseFd(); |
2196 $this->privCloseFd(); |
2197 $this->privSwapBackMagicQuotes(); |
2197 $this->privSwapBackMagicQuotes(); |
2199 } |
2199 } |
2200 |
2200 |
2201 // ----- Go to beginning of File |
2201 // ----- Go to beginning of File |
2202 @rewind($this->zip_fd); |
2202 @rewind($this->zip_fd); |
2203 |
2203 |
2204 // ----- Creates a temporay file |
2204 // ----- Creates a temporary file |
2205 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
2205 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
2206 |
2206 |
2207 // ----- Open the temporary file in write mode |
2207 // ----- Open the temporary file in write mode |
2208 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
2208 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
2209 { |
2209 { |
2389 |
2389 |
2390 // -------------------------------------------------------------------------------- |
2390 // -------------------------------------------------------------------------------- |
2391 // Function : privAddList() |
2391 // Function : privAddList() |
2392 // Description : |
2392 // Description : |
2393 // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is |
2393 // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is |
2394 // different from the real path of the file. This is usefull if you want to have PclTar |
2394 // different from the real path of the file. This is useful if you want to have PclTar |
2395 // running in any directory, and memorize relative path from an other directory. |
2395 // running in any directory, and memorize relative path from an other directory. |
2396 // Parameters : |
2396 // Parameters : |
2397 // $p_list : An array containing the file or directory names to add in the tar |
2397 // $p_list : An array containing the file or directory names to add in the tar |
2398 // $p_result_list : list of added files with their properties (specially the status field) |
2398 // $p_result_list : list of added files with their properties (specially the status field) |
2399 // $p_add_dir : Path to add in the filename path archived |
2399 // $p_add_dir : Path to add in the filename path archived |
2629 // ----- Change the file status |
2629 // ----- Change the file status |
2630 $p_header['status'] = "skipped"; |
2630 $p_header['status'] = "skipped"; |
2631 $v_result = 1; |
2631 $v_result = 1; |
2632 } |
2632 } |
2633 |
2633 |
2634 // ----- Update the informations |
2634 // ----- Update the information |
2635 // Only some fields can be modified |
2635 // Only some fields can be modified |
2636 if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { |
2636 if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { |
2637 $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); |
2637 $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); |
2638 } |
2638 } |
2639 } |
2639 } |
2944 |
2944 |
2945 // ----- Look for path and/or short name change |
2945 // ----- Look for path and/or short name change |
2946 else { |
2946 else { |
2947 |
2947 |
2948 // ----- Look for short name change |
2948 // ----- Look for short name change |
2949 // Its when we cahnge just the filename but not the path |
2949 // Its when we change just the filename but not the path |
2950 if (isset($p_filedescr['new_short_name'])) { |
2950 if (isset($p_filedescr['new_short_name'])) { |
2951 $v_path_info = pathinfo($p_filename); |
2951 $v_path_info = pathinfo($p_filename); |
2952 $v_dir = ''; |
2952 $v_dir = ''; |
2953 if ($v_path_info['dirname'] != '') { |
2953 if ($v_path_info['dirname'] != '') { |
2954 $v_dir = $v_path_info['dirname'].'/'; |
2954 $v_dir = $v_path_info['dirname'].'/'; |
3167 |
3167 |
3168 // ----- Return |
3168 // ----- Return |
3169 return PclZip::errorCode(); |
3169 return PclZip::errorCode(); |
3170 } |
3170 } |
3171 |
3171 |
3172 // ----- Read the central directory informations |
3172 // ----- Read the central directory information |
3173 $v_central_dir = array(); |
3173 $v_central_dir = array(); |
3174 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
3174 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
3175 { |
3175 { |
3176 $this->privSwapBackMagicQuotes(); |
3176 $this->privSwapBackMagicQuotes(); |
3177 return $v_result; |
3177 return $v_result; |
3218 // -------------------------------------------------------------------------------- |
3218 // -------------------------------------------------------------------------------- |
3219 |
3219 |
3220 // -------------------------------------------------------------------------------- |
3220 // -------------------------------------------------------------------------------- |
3221 // Function : privConvertHeader2FileInfo() |
3221 // Function : privConvertHeader2FileInfo() |
3222 // Description : |
3222 // Description : |
3223 // This function takes the file informations from the central directory |
3223 // This function takes the file information from the central directory |
3224 // entries and extract the interesting parameters that will be given back. |
3224 // entries and extract the interesting parameters that will be given back. |
3225 // The resulting file infos are set in the array $p_info |
3225 // The resulting file infos are set in the array $p_info |
3226 // $p_info['filename'] : Filename with full path. Given by user (add), |
3226 // $p_info['filename'] : Filename with full path. Given by user (add), |
3227 // extracted in the filesystem (extract). |
3227 // extracted in the filesystem (extract). |
3228 // $p_info['stored_filename'] : Stored filename in the archive. |
3228 // $p_info['stored_filename'] : Stored filename in the archive. |
3311 { |
3311 { |
3312 $this->privSwapBackMagicQuotes(); |
3312 $this->privSwapBackMagicQuotes(); |
3313 return $v_result; |
3313 return $v_result; |
3314 } |
3314 } |
3315 |
3315 |
3316 // ----- Read the central directory informations |
3316 // ----- Read the central directory information |
3317 $v_central_dir = array(); |
3317 $v_central_dir = array(); |
3318 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
3318 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
3319 { |
3319 { |
3320 // ----- Close the zip file |
3320 // ----- Close the zip file |
3321 $this->privCloseFd(); |
3321 $this->privCloseFd(); |
3711 // ----- This status is internal and will be changed in 'skipped' |
3711 // ----- This status is internal and will be changed in 'skipped' |
3712 $p_entry['status'] = "aborted"; |
3712 $p_entry['status'] = "aborted"; |
3713 $v_result = PCLZIP_ERR_USER_ABORTED; |
3713 $v_result = PCLZIP_ERR_USER_ABORTED; |
3714 } |
3714 } |
3715 |
3715 |
3716 // ----- Update the informations |
3716 // ----- Update the information |
3717 // Only some fields can be modified |
3717 // Only some fields can be modified |
3718 $p_entry['filename'] = $v_local_header['filename']; |
3718 $p_entry['filename'] = $v_local_header['filename']; |
3719 } |
3719 } |
3720 |
3720 |
3721 |
3721 |
4078 // ----- This status is internal and will be changed in 'skipped' |
4078 // ----- This status is internal and will be changed in 'skipped' |
4079 $p_entry['status'] = "aborted"; |
4079 $p_entry['status'] = "aborted"; |
4080 $v_result = PCLZIP_ERR_USER_ABORTED; |
4080 $v_result = PCLZIP_ERR_USER_ABORTED; |
4081 } |
4081 } |
4082 |
4082 |
4083 // ----- Update the informations |
4083 // ----- Update the information |
4084 // Only some fields can be modified |
4084 // Only some fields can be modified |
4085 $p_entry['filename'] = $v_local_header['filename']; |
4085 $p_entry['filename'] = $v_local_header['filename']; |
4086 } |
4086 } |
4087 |
4087 |
4088 // ----- Trace |
4088 // ----- Trace |
4191 // ----- This status is internal and will be changed in 'skipped' |
4191 // ----- This status is internal and will be changed in 'skipped' |
4192 $p_entry['status'] = "aborted"; |
4192 $p_entry['status'] = "aborted"; |
4193 $v_result = PCLZIP_ERR_USER_ABORTED; |
4193 $v_result = PCLZIP_ERR_USER_ABORTED; |
4194 } |
4194 } |
4195 |
4195 |
4196 // ----- Update the informations |
4196 // ----- Update the information |
4197 // Only some fields can be modified |
4197 // Only some fields can be modified |
4198 $p_entry['filename'] = $v_local_header['filename']; |
4198 $p_entry['filename'] = $v_local_header['filename']; |
4199 } |
4199 } |
4200 |
4200 |
4201 |
4201 |
4822 } |
4822 } |
4823 |
4823 |
4824 // ----- Look if something need to be deleted |
4824 // ----- Look if something need to be deleted |
4825 if ($v_nb_extracted > 0) { |
4825 if ($v_nb_extracted > 0) { |
4826 |
4826 |
4827 // ----- Creates a temporay file |
4827 // ----- Creates a temporary file |
4828 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
4828 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
4829 |
4829 |
4830 // ----- Creates a temporary zip archive |
4830 // ----- Creates a temporary zip archive |
4831 $v_temp_zip = new PclZip($v_zip_temp_name); |
4831 $v_temp_zip = new PclZip($v_zip_temp_name); |
4832 |
4832 |
5093 |
5093 |
5094 // ----- Return |
5094 // ----- Return |
5095 return $v_result; |
5095 return $v_result; |
5096 } |
5096 } |
5097 |
5097 |
5098 // ----- Read the central directory informations |
5098 // ----- Read the central directory information |
5099 $v_central_dir_to_add = array(); |
5099 $v_central_dir_to_add = array(); |
5100 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) |
5100 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) |
5101 { |
5101 { |
5102 $this->privCloseFd(); |
5102 $this->privCloseFd(); |
5103 $p_archive_to_add->privCloseFd(); |
5103 $p_archive_to_add->privCloseFd(); |
5106 } |
5106 } |
5107 |
5107 |
5108 // ----- Go to beginning of File |
5108 // ----- Go to beginning of File |
5109 @rewind($p_archive_to_add->zip_fd); |
5109 @rewind($p_archive_to_add->zip_fd); |
5110 |
5110 |
5111 // ----- Creates a temporay file |
5111 // ----- Creates a temporary file |
5112 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
5112 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
5113 |
5113 |
5114 // ----- Open the temporary file in write mode |
5114 // ----- Open the temporary file in write mode |
5115 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
5115 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
5116 { |
5116 { |
5324 // -------------------------------------------------------------------------------- |
5324 // -------------------------------------------------------------------------------- |
5325 function privDisableMagicQuotes() |
5325 function privDisableMagicQuotes() |
5326 { |
5326 { |
5327 $v_result=1; |
5327 $v_result=1; |
5328 |
5328 |
|
5329 // EDIT for WordPress 5.3.0 |
|
5330 // magic_quote functions are deprecated in PHP 7.4, now assuming it's always off. |
|
5331 /* |
|
5332 |
5329 // ----- Look if function exists |
5333 // ----- Look if function exists |
5330 if ( (!function_exists("get_magic_quotes_runtime")) |
5334 if ( (!function_exists("get_magic_quotes_runtime")) |
5331 || (!function_exists("set_magic_quotes_runtime"))) { |
5335 || (!function_exists("set_magic_quotes_runtime"))) { |
5332 return $v_result; |
5336 return $v_result; |
5333 } |
5337 } |
5357 // Return Values : |
5362 // Return Values : |
5358 // -------------------------------------------------------------------------------- |
5363 // -------------------------------------------------------------------------------- |
5359 function privSwapBackMagicQuotes() |
5364 function privSwapBackMagicQuotes() |
5360 { |
5365 { |
5361 $v_result=1; |
5366 $v_result=1; |
|
5367 |
|
5368 // EDIT for WordPress 5.3.0 |
|
5369 // magic_quote functions are deprecated in PHP 7.4, now assuming it's always off. |
|
5370 /* |
5362 |
5371 |
5363 // ----- Look if function exists |
5372 // ----- Look if function exists |
5364 if ( (!function_exists("get_magic_quotes_runtime")) |
5373 if ( (!function_exists("get_magic_quotes_runtime")) |
5365 || (!function_exists("set_magic_quotes_runtime"))) { |
5374 || (!function_exists("set_magic_quotes_runtime"))) { |
5366 return $v_result; |
5375 return $v_result; |