Changeset 2836
- Timestamp:
- Nov 6, 2008, 3:44:51 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions_upgrade.php
r2819 r2836 24 24 function check_upgrade() 25 25 { 26 // Is Piwigo already installed ? 27 if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE) 26 if (defined('PHPWG_IN_UPGRADE')) 28 27 { 29 $message = 'Piwigo is not in upgrade mode. In include/mysql.inc.php, 30 insert line 31 <pre style="background-color:lightgray"> 32 define(\'PHPWG_IN_UPGRADE\', true); 33 </pre> 34 if you want to upgrade'; 35 die($message); 28 return PHPWG_IN_UPGRADE; 36 29 } 30 return false; 37 31 } 38 32 … … 138 132 } 139 133 134 // Check access rights 135 function check_upgrade_access_rights($current_release, $username, $password) 136 { 137 global $conf, $page; 138 139 if (version_compare($current_release, '1.5.0', '<')) 140 { 141 $query = ' 142 SELECT password, status 143 FROM '.PREFIX_TABLE.'users 144 WHERE username = "'.$username.'" 145 ;'; 146 } 147 else 148 { 149 $query = ' 150 SELECT u.password, ui.status 151 FROM '.$conf['users_table'].' AS u 152 INNER JOIN '.PREFIX_TABLE.'user_infos AS ui 153 ON u.id = ui.user_id 154 WHERE '.$conf['user_fields']['username'].'="'.$username.'" 155 ;'; 156 } 157 $row = mysql_fetch_assoc(mysql_query($query)); 158 159 if (!isset($conf['pass_convert'])) 160 { 161 $conf['pass_convert'] = create_function('$s', 'return md5($s);'); 162 } 163 164 if ($row['password'] != $conf['pass_convert']($_POST['password'])) 165 { 166 array_push($page['errors'], l10n('invalid_pwd')); 167 } 168 elseif ($row['status'] != 'admin' and $row['status'] != 'webmaster') 169 { 170 array_push($page['errors'], l10n('You do not have access rights to run upgrade')); 171 } 172 else 173 { 174 define('PHPWG_IN_UPGRADE', true); 175 } 176 } 140 177 ?> -
trunk/admin/include/pclzip.lib.php
r2242 r2836 23 23 // 24 24 // -------------------------------------------------------------------------------- 25 // $Id$ 26 // -------------------------------------------------------------------------------- 27 28 // ----- Constants 29 if (!defined('PCLZIP_READ_BLOCK_SIZE')) { 30 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); 31 } 32 33 // ----- File list separator 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 !). 36 // A better separator should be a comma (,). This constant gives you the 37 // abilty to change that. 38 // However notice that changing this value, may have impact on existing 39 // scripts, using space separated filenames. 40 // Recommanded values for compatibility with older versions : 41 //define( 'PCLZIP_SEPARATOR', ' ' ); 42 // Recommanded values for smart separation of filenames. 43 if (!defined('PCLZIP_SEPARATOR')) { 44 define( 'PCLZIP_SEPARATOR', ',' ); 45 } 46 47 // ----- Error configuration 48 // 0 : PclZip Class integrated error handling 49 // 1 : PclError external library error handling. By enabling this 50 // you must ensure that you have included PclError library. 51 // [2,...] : reserved for futur use 52 if (!defined('PCLZIP_ERROR_EXTERNAL')) { 53 define( 'PCLZIP_ERROR_EXTERNAL', 0 ); 54 } 55 56 // ----- Optional static temporary directory 57 // By default temporary files are generated in the script current 58 // path. 59 // If defined : 60 // - MUST BE terminated by a '/'. 61 // - MUST be a valid, already created directory 62 // Samples : 63 // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); 64 // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); 65 if (!defined('PCLZIP_TEMPORARY_DIR')) { 66 define( 'PCLZIP_TEMPORARY_DIR', '' ); 67 } 68 69 // -------------------------------------------------------------------------------- 70 // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED ***** 71 // -------------------------------------------------------------------------------- 72 73 // ----- Global variables 74 $g_pclzip_version = "2.6"; 75 76 // ----- Error codes 77 // -1 : Unable to open file in binary write mode 78 // -2 : Unable to open file in binary read mode 79 // -3 : Invalid parameters 80 // -4 : File does not exist 81 // -5 : Filename is too long (max. 255) 82 // -6 : Not a valid zip file 83 // -7 : Invalid extracted file size 84 // -8 : Unable to create directory 85 // -9 : Invalid archive extension 86 // -10 : Invalid archive format 87 // -11 : Unable to delete file (unlink) 88 // -12 : Unable to rename file (rename) 89 // -13 : Invalid header checksum 90 // -14 : Invalid archive size 91 define( 'PCLZIP_ERR_USER_ABORTED', 2 ); 92 define( 'PCLZIP_ERR_NO_ERROR', 0 ); 93 define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); 94 define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); 95 define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); 96 define( 'PCLZIP_ERR_MISSING_FILE', -4 ); 97 define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); 98 define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); 99 define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); 100 define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); 101 define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); 102 define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); 103 define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); 104 define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); 105 define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); 106 define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); 107 define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); 108 define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); 109 define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); 110 define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); 111 define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); 112 define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); 113 define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); 114 115 // ----- Options values 116 define( 'PCLZIP_OPT_PATH', 77001 ); 117 define( 'PCLZIP_OPT_ADD_PATH', 77002 ); 118 define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); 119 define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); 120 define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); 121 define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); 122 define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); 123 define( 'PCLZIP_OPT_BY_NAME', 77008 ); 124 define( 'PCLZIP_OPT_BY_INDEX', 77009 ); 125 define( 'PCLZIP_OPT_BY_EREG', 77010 ); 126 define( 'PCLZIP_OPT_BY_PREG', 77011 ); 127 define( 'PCLZIP_OPT_COMMENT', 77012 ); 128 define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); 129 define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); 130 define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); 131 define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); 132 define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); 133 // Having big trouble with crypt. Need to multiply 2 long int 134 // which is not correctly supported by PHP ... 135 //define( 'PCLZIP_OPT_CRYPT', 77018 ); 136 define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); 137 138 // ----- File description attributes 139 define( 'PCLZIP_ATT_FILE_NAME', 79001 ); 140 define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); 141 define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); 142 define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); 143 define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); 144 define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); 145 146 // ----- Call backs values 147 define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); 148 define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); 149 define( 'PCLZIP_CB_PRE_ADD', 78003 ); 150 define( 'PCLZIP_CB_POST_ADD', 78004 ); 151 /* For futur use 152 define( 'PCLZIP_CB_PRE_LIST', 78005 ); 153 define( 'PCLZIP_CB_POST_LIST', 78006 ); 154 define( 'PCLZIP_CB_PRE_DELETE', 78007 ); 155 define( 'PCLZIP_CB_POST_DELETE', 78008 ); 156 */ 157 158 // -------------------------------------------------------------------------------- 159 // Class : PclZip 160 // Description : 161 // PclZip is the class that represent a Zip archive. 162 // The public methods allow the manipulation of the archive. 163 // Attributes : 164 // Attributes must not be accessed directly. 165 // Methods : 166 // PclZip() : Object creator 167 // create() : Creates the Zip archive 168 // listContent() : List the content of the Zip archive 169 // extract() : Extract the content of the archive 170 // properties() : List the properties of the archive 171 // -------------------------------------------------------------------------------- 172 class PclZip 173 { 174 // ----- Filename of the zip file 175 var $zipname = ''; 176 177 // ----- File descriptor of the zip file 178 var $zip_fd = 0; 179 180 // ----- Internal error handling 181 var $error_code = 1; 182 var $error_string = ''; 25 26 if (!defined('PCLZIP_READ_BLOCK_SIZE')) { 27 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); 28 } 29 30 if (!defined('PCLZIP_SEPARATOR')) { 31 define( 'PCLZIP_SEPARATOR', ',' ); 32 } 33 34 if (!defined('PCLZIP_ERROR_EXTERNAL')) { 35 define( 'PCLZIP_ERROR_EXTERNAL', 0 ); 36 } 37 38 if (!defined('PCLZIP_TEMPORARY_DIR')) { 39 define( 'PCLZIP_TEMPORARY_DIR', '' ); 40 } 41 42 43 $g_pclzip_version = "2.6"; 44 45 define( 'PCLZIP_ERR_USER_ABORTED', 2 ); 46 define( 'PCLZIP_ERR_NO_ERROR', 0 ); 47 define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); 48 define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); 49 define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); 50 define( 'PCLZIP_ERR_MISSING_FILE', -4 ); 51 define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); 52 define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); 53 define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); 54 define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); 55 define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); 56 define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); 57 define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); 58 define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); 59 define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); 60 define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); 61 define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); 62 define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); 63 define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); 64 define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); 65 define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); 66 define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); 67 define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); 68 69 define( 'PCLZIP_OPT_PATH', 77001 ); 70 define( 'PCLZIP_OPT_ADD_PATH', 77002 ); 71 define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); 72 define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); 73 define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); 74 define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); 75 define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); 76 define( 'PCLZIP_OPT_BY_NAME', 77008 ); 77 define( 'PCLZIP_OPT_BY_INDEX', 77009 ); 78 define( 'PCLZIP_OPT_BY_EREG', 77010 ); 79 define( 'PCLZIP_OPT_BY_PREG', 77011 ); 80 define( 'PCLZIP_OPT_COMMENT', 77012 ); 81 define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); 82 define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); 83 define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); 84 define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); 85 define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); 86 define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); 87 88 define( 'PCLZIP_ATT_FILE_NAME', 79001 ); 89 define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); 90 define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); 91 define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); 92 define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); 93 define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); 94 95 define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); 96 define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); 97 define( 'PCLZIP_CB_PRE_ADD', 78003 ); 98 define( 'PCLZIP_CB_POST_ADD', 78004 ); 99 100 101 class PclZip 102 { 103 var $zipname = ''; 104 105 var $zip_fd = 0; 106 107 var $error_code = 1; 108 var $error_string = ''; 109 110 var $magic_quotes_status; 111 112 function PclZip($p_zipname) 113 { 114 115 if (!function_exists('gzopen')) 116 { 117 die('Abort '.basename(__FILE__).' : Missing zlib extensions'); 118 } 119 120 $this->zipname = $p_zipname; 121 $this->zip_fd = 0; 122 $this->magic_quotes_status = -1; 123 124 return; 125 } 126 127 function create($p_filelist) 128 { 129 $v_result=1; 130 131 $this->privErrorReset(); 132 133 $v_options = array(); 134 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; 135 136 $v_size = func_num_args(); 137 138 if ($v_size > 1) { 139 $v_arg_list = func_get_args(); 140 141 array_shift($v_arg_list); 142 $v_size--; 143 144 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 145 146 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 147 array (PCLZIP_OPT_REMOVE_PATH => 'optional', 148 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 149 PCLZIP_OPT_ADD_PATH => 'optional', 150 PCLZIP_CB_PRE_ADD => 'optional', 151 PCLZIP_CB_POST_ADD => 'optional', 152 PCLZIP_OPT_NO_COMPRESSION => 'optional', 153 PCLZIP_OPT_COMMENT => 'optional' 154 )); 155 if ($v_result != 1) { 156 return 0; 157 } 158 } 159 160 else { 161 162 $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; 163 164 if ($v_size == 2) { 165 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; 166 } 167 else if ($v_size > 2) { 168 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 169 "Invalid number / type of arguments"); 170 return 0; 171 } 172 } 173 } 174 175 $v_string_list = array(); 176 $v_att_list = array(); 177 $v_filedescr_list = array(); 178 $p_result_list = array(); 179 180 if (is_array($p_filelist)) { 181 182 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 183 $v_att_list = $p_filelist; 184 } 183 185 184 // ----- Current status of the magic_quotes_runtime 185 // This value store the php configuration for magic_quotes 186 // The class can then disable the magic_quotes and reset it after 187 var $magic_quotes_status; 188 189 // -------------------------------------------------------------------------------- 190 // Function : PclZip() 191 // Description : 192 // Creates a PclZip object and set the name of the associated Zip archive 193 // filename. 194 // Note that no real action is taken, if the archive does not exist it is not 195 // created. Use create() for that. 196 // -------------------------------------------------------------------------------- 197 function PclZip($p_zipname) 198 { 199 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname"); 200 201 // ----- Tests the zlib 202 if (!function_exists('gzopen')) 203 { 204 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing"); 205 die('Abort '.basename(__FILE__).' : Missing zlib extensions'); 206 } 207 208 // ----- Set the attributes 209 $this->zipname = $p_zipname; 210 $this->zip_fd = 0; 211 $this->magic_quotes_status = -1; 212 213 // ----- Return 214 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1); 215 return; 216 } 217 // -------------------------------------------------------------------------------- 218 219 // -------------------------------------------------------------------------------- 220 // Function : 221 // create($p_filelist, $p_add_dir="", $p_remove_dir="") 222 // create($p_filelist, $p_option, $p_option_value, ...) 223 // Description : 224 // This method supports two different synopsis. The first one is historical. 225 // This method creates a Zip Archive. The Zip file is created in the 226 // filesystem. The files and directories indicated in $p_filelist 227 // are added in the archive. See the parameters description for the 228 // supported format of $p_filelist. 229 // When a directory is in the list, the directory and its content is added 230 // in the archive. 231 // In this synopsis, the function takes an optional variable list of 232 // options. See bellow the supported options. 233 // Parameters : 234 // $p_filelist : An array containing file or directory names, or 235 // a string containing one filename or one directory name, or 236 // a string containing a list of filenames and/or directory 237 // names separated by spaces. 238 // $p_add_dir : A path to add before the real path of the archived file, 239 // in order to have it memorized in the archive. 240 // $p_remove_dir : A path to remove from the real path of the file to archive, 241 // in order to have a shorter path memorized in the archive. 242 // When $p_add_dir and $p_remove_dir are set, $p_remove_dir 243 // is removed first, before $p_add_dir is added. 244 // Options : 245 // PCLZIP_OPT_ADD_PATH : 246 // PCLZIP_OPT_REMOVE_PATH : 247 // PCLZIP_OPT_REMOVE_ALL_PATH : 248 // PCLZIP_OPT_COMMENT : 249 // PCLZIP_CB_PRE_ADD : 250 // PCLZIP_CB_POST_ADD : 251 // Return Values : 252 // 0 on failure, 253 // The list of the added files, with a status of the add action. 254 // (see PclZip::listContent() for list entry format) 255 // -------------------------------------------------------------------------------- 256 function create($p_filelist) 257 { 258 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ..."); 259 $v_result=1; 260 261 // ----- Reset the error handler 262 $this->privErrorReset(); 263 264 // ----- Set default values 265 $v_options = array(); 266 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; 267 268 // ----- Look for variable options arguments 269 $v_size = func_num_args(); 270 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 271 272 // ----- Look for arguments 273 if ($v_size > 1) { 274 // ----- Get the arguments 275 $v_arg_list = func_get_args(); 276 277 // ----- Remove from the options list the first argument 278 array_shift($v_arg_list); 279 $v_size--; 280 281 // ----- Look for first arg 282 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 283 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); 284 285 // ----- Parse the options 286 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 287 array (PCLZIP_OPT_REMOVE_PATH => 'optional', 288 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 289 PCLZIP_OPT_ADD_PATH => 'optional', 290 PCLZIP_CB_PRE_ADD => 'optional', 291 PCLZIP_CB_POST_ADD => 'optional', 292 PCLZIP_OPT_NO_COMPRESSION => 'optional', 293 PCLZIP_OPT_COMMENT => 'optional' 294 //, PCLZIP_OPT_CRYPT => 'optional' 295 )); 296 if ($v_result != 1) { 297 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 298 return 0; 299 } 300 } 301 302 // ----- Look for 2 args 303 // Here we need to support the first historic synopsis of the 304 // method. 186 else { 187 $v_string_list = $p_filelist; 188 } 189 } 190 191 else if (is_string($p_filelist)) { 192 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); 193 } 194 195 else { 196 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); 197 return 0; 198 } 199 200 if (sizeof($v_string_list) != 0) { 201 foreach ($v_string_list as $v_string) { 202 if ($v_string != '') { 203 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 204 } 305 205 else { 306 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 307 308 // ----- Get the first argument 309 $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; 310 311 // ----- Look for the optional second argument 312 if ($v_size == 2) { 313 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; 314 } 315 else if ($v_size > 2) { 316 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 317 "Invalid number / type of arguments"); 318 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 319 return 0; 320 } 321 } 322 } 323 324 // ----- Init 325 $v_string_list = array(); 326 $v_att_list = array(); 327 $v_filedescr_list = array(); 328 $p_result_list = array(); 206 } 207 } 208 } 209 210 $v_supported_attributes 211 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 212 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 213 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 214 ,PCLZIP_ATT_FILE_MTIME => 'optional' 215 ,PCLZIP_ATT_FILE_CONTENT => 'optional' 216 ,PCLZIP_ATT_FILE_COMMENT => 'optional' 217 ); 218 foreach ($v_att_list as $v_entry) { 219 $v_result = $this->privFileDescrParseAtt($v_entry, 220 $v_filedescr_list[], 221 $v_options, 222 $v_supported_attributes); 223 if ($v_result != 1) { 224 return 0; 225 } 226 } 227 228 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); 229 if ($v_result != 1) { 230 return 0; 231 } 232 233 $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); 234 if ($v_result != 1) { 235 return 0; 236 } 237 238 return $p_result_list; 239 } 240 241 function add($p_filelist) 242 { 243 $v_result=1; 244 245 $this->privErrorReset(); 246 247 $v_options = array(); 248 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; 249 250 $v_size = func_num_args(); 251 252 if ($v_size > 1) { 253 $v_arg_list = func_get_args(); 254 255 array_shift($v_arg_list); 256 $v_size--; 257 258 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 259 260 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 261 array (PCLZIP_OPT_REMOVE_PATH => 'optional', 262 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 263 PCLZIP_OPT_ADD_PATH => 'optional', 264 PCLZIP_CB_PRE_ADD => 'optional', 265 PCLZIP_CB_POST_ADD => 'optional', 266 PCLZIP_OPT_NO_COMPRESSION => 'optional', 267 PCLZIP_OPT_COMMENT => 'optional', 268 PCLZIP_OPT_ADD_COMMENT => 'optional', 269 PCLZIP_OPT_PREPEND_COMMENT => 'optional' 270 )); 271 if ($v_result != 1) { 272 return 0; 273 } 274 } 275 276 else { 277 278 $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; 279 280 if ($v_size == 2) { 281 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; 282 } 283 else if ($v_size > 2) { 284 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 285 286 return 0; 287 } 288 } 289 } 290 291 $v_string_list = array(); 292 $v_att_list = array(); 293 $v_filedescr_list = array(); 294 $p_result_list = array(); 295 296 if (is_array($p_filelist)) { 297 298 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 299 $v_att_list = $p_filelist; 300 } 329 301 330 // ----- Look if the $p_filelist is really an array 331 if (is_array($p_filelist)) { 332 333 // ----- Look if the first element is also an array 334 // This will mean that this is a file description entry 335 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 336 $v_att_list = $p_filelist; 337 } 338 339 // ----- The list is a list of string names 302 else { 303 $v_string_list = $p_filelist; 304 } 305 } 306 307 else if (is_string($p_filelist)) { 308 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); 309 } 310 311 else { 312 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); 313 return 0; 314 } 315 316 if (sizeof($v_string_list) != 0) { 317 foreach ($v_string_list as $v_string) { 318 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 319 } 320 } 321 322 $v_supported_attributes 323 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 324 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 325 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 326 ,PCLZIP_ATT_FILE_MTIME => 'optional' 327 ,PCLZIP_ATT_FILE_CONTENT => 'optional' 328 ,PCLZIP_ATT_FILE_COMMENT => 'optional' 329 ); 330 foreach ($v_att_list as $v_entry) { 331 $v_result = $this->privFileDescrParseAtt($v_entry, 332 $v_filedescr_list[], 333 $v_options, 334 $v_supported_attributes); 335 if ($v_result != 1) { 336 return 0; 337 } 338 } 339 340 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); 341 if ($v_result != 1) { 342 return 0; 343 } 344 345 $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); 346 if ($v_result != 1) { 347 return 0; 348 } 349 350 return $p_result_list; 351 } 352 353 function listContent() 354 { 355 $v_result=1; 356 357 $this->privErrorReset(); 358 359 if (!$this->privCheckFormat()) { 360 return(0); 361 } 362 363 $p_list = array(); 364 if (($v_result = $this->privList($p_list)) != 1) 365 { 366 unset($p_list); 367 return(0); 368 } 369 370 return $p_list; 371 } 372 373 function extract() 374 { 375 $v_result=1; 376 377 $this->privErrorReset(); 378 379 if (!$this->privCheckFormat()) { 380 return(0); 381 } 382 383 $v_options = array(); 384 $v_path = ''; 385 $v_remove_path = ""; 386 $v_remove_all_path = false; 387 388 $v_size = func_num_args(); 389 390 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 391 392 if ($v_size > 0) { 393 $v_arg_list = func_get_args(); 394 395 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 396 397 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 398 array (PCLZIP_OPT_PATH => 'optional', 399 PCLZIP_OPT_REMOVE_PATH => 'optional', 400 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 401 PCLZIP_OPT_ADD_PATH => 'optional', 402 PCLZIP_CB_PRE_EXTRACT => 'optional', 403 PCLZIP_CB_POST_EXTRACT => 'optional', 404 PCLZIP_OPT_SET_CHMOD => 'optional', 405 PCLZIP_OPT_BY_NAME => 'optional', 406 PCLZIP_OPT_BY_EREG => 'optional', 407 PCLZIP_OPT_BY_PREG => 'optional', 408 PCLZIP_OPT_BY_INDEX => 'optional', 409 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', 410 PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', 411 PCLZIP_OPT_REPLACE_NEWER => 'optional' 412 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' 413 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' 414 )); 415 if ($v_result != 1) { 416 return 0; 417 } 418 419 if (isset($v_options[PCLZIP_OPT_PATH])) { 420 $v_path = $v_options[PCLZIP_OPT_PATH]; 421 } 422 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { 423 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; 424 } 425 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 426 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 427 } 428 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { 429 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { 430 $v_path .= '/'; 431 } 432 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; 433 } 434 } 435 436 else { 437 438 $v_path = $v_arg_list[0]; 439 440 if ($v_size == 2) { 441 $v_remove_path = $v_arg_list[1]; 442 } 443 else if ($v_size > 2) { 444 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 445 446 return 0; 447 } 448 } 449 } 450 451 452 $p_list = array(); 453 $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, 454 $v_remove_all_path, $v_options); 455 if ($v_result < 1) { 456 unset($p_list); 457 return(0); 458 } 459 460 return $p_list; 461 } 462 463 464 function extractByIndex($p_index) 465 { 466 $v_result=1; 467 468 $this->privErrorReset(); 469 470 if (!$this->privCheckFormat()) { 471 return(0); 472 } 473 474 $v_options = array(); 475 $v_path = ''; 476 $v_remove_path = ""; 477 $v_remove_all_path = false; 478 479 $v_size = func_num_args(); 480 481 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 482 483 if ($v_size > 1) { 484 $v_arg_list = func_get_args(); 485 486 array_shift($v_arg_list); 487 $v_size--; 488 489 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 490 491 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 492 array (PCLZIP_OPT_PATH => 'optional', 493 PCLZIP_OPT_REMOVE_PATH => 'optional', 494 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 495 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', 496 PCLZIP_OPT_ADD_PATH => 'optional', 497 PCLZIP_CB_PRE_EXTRACT => 'optional', 498 PCLZIP_CB_POST_EXTRACT => 'optional', 499 PCLZIP_OPT_SET_CHMOD => 'optional', 500 PCLZIP_OPT_REPLACE_NEWER => 'optional' 501 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' 502 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' 503 )); 504 if ($v_result != 1) { 505 return 0; 506 } 507 508 if (isset($v_options[PCLZIP_OPT_PATH])) { 509 $v_path = $v_options[PCLZIP_OPT_PATH]; 510 } 511 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { 512 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; 513 } 514 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 515 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 516 } 517 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { 518 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { 519 $v_path .= '/'; 520 } 521 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; 522 } 523 if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { 524 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 525 } 340 526 else { 341 $v_string_list = $p_filelist; 342 } 343 } 344 345 // ----- Look if the $p_filelist is a string 346 else if (is_string($p_filelist)) { 347 // ----- Create a list from the string 348 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); 349 } 350 351 // ----- Invalid variable type for $p_filelist 527 } 528 } 529 352 530 else { 353 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); 354 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 531 532 $v_path = $v_arg_list[0]; 533 534 if ($v_size == 2) { 535 $v_remove_path = $v_arg_list[1]; 536 } 537 else if ($v_size > 2) { 538 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 539 540 return 0; 541 } 542 } 543 } 544 545 546 $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); 547 $v_options_trick = array(); 548 $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, 549 array (PCLZIP_OPT_BY_INDEX => 'optional' )); 550 if ($v_result != 1) { 355 551 return 0; 356 } 357 358 // ----- Reformat the string list 359 if (sizeof($v_string_list) != 0) { 360 foreach ($v_string_list as $v_string) { 361 if ($v_string != '') { 362 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 363 } 364 else { 365 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename"); 366 } 367 } 368 } 369 370 // ----- For each file in the list check the attributes 371 $v_supported_attributes 372 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 373 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 374 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 375 ,PCLZIP_ATT_FILE_MTIME => 'optional' 376 ,PCLZIP_ATT_FILE_CONTENT => 'optional' 377 ,PCLZIP_ATT_FILE_COMMENT => 'optional' 378 ); 379 foreach ($v_att_list as $v_entry) { 380 $v_result = $this->privFileDescrParseAtt($v_entry, 381 $v_filedescr_list[], 382 $v_options, 383 $v_supported_attributes); 384 if ($v_result != 1) { 385 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 552 } 553 $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; 554 555 if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { 556 return(0); 557 } 558 559 return $p_list; 560 } 561 562 function delete() 563 { 564 $v_result=1; 565 566 $this->privErrorReset(); 567 568 if (!$this->privCheckFormat()) { 569 return(0); 570 } 571 572 $v_options = array(); 573 574 $v_size = func_num_args(); 575 576 if ($v_size > 0) { 577 $v_arg_list = func_get_args(); 578 579 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 580 array (PCLZIP_OPT_BY_NAME => 'optional', 581 PCLZIP_OPT_BY_EREG => 'optional', 582 PCLZIP_OPT_BY_PREG => 'optional', 583 PCLZIP_OPT_BY_INDEX => 'optional' )); 584 if ($v_result != 1) { 386 585 return 0; 387 } 388 } 389 390 // ----- Expand the filelist (expand directories) 391 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); 392 if ($v_result != 1) { 393 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 394 return 0; 395 } 396 397 // ----- Call the create fct 398 $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); 399 if ($v_result != 1) { 400 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 401 return 0; 402 } 403 404 // ----- Return 405 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); 406 return $p_result_list; 407 } 408 // -------------------------------------------------------------------------------- 409 410 // -------------------------------------------------------------------------------- 411 // Function : 412 // add($p_filelist, $p_add_dir="", $p_remove_dir="") 413 // add($p_filelist, $p_option, $p_option_value, ...) 414 // Description : 415 // This method supports two synopsis. The first one is historical. 416 // This methods add the list of files in an existing archive. 417 // If a file with the same name already exists, it is added at the end of the 418 // archive, the first one is still present. 419 // If the archive does not exist, it is created. 420 // Parameters : 421 // $p_filelist : An array containing file or directory names, or 422 // a string containing one filename or one directory name, or 423 // a string containing a list of filenames and/or directory 424 // names separated by spaces. 425 // $p_add_dir : A path to add before the real path of the archived file, 426 // in order to have it memorized in the archive. 427 // $p_remove_dir : A path to remove from the real path of the file to archive, 428 // in order to have a shorter path memorized in the archive. 429 // When $p_add_dir and $p_remove_dir are set, $p_remove_dir 430 // is removed first, before $p_add_dir is added. 431 // Options : 432 // PCLZIP_OPT_ADD_PATH : 433 // PCLZIP_OPT_REMOVE_PATH : 434 // PCLZIP_OPT_REMOVE_ALL_PATH : 435 // PCLZIP_OPT_COMMENT : 436 // PCLZIP_OPT_ADD_COMMENT : 437 // PCLZIP_OPT_PREPEND_COMMENT : 438 // PCLZIP_CB_PRE_ADD : 439 // PCLZIP_CB_POST_ADD : 440 // Return Values : 441 // 0 on failure, 442 // The list of the added files, with a status of the add action. 443 // (see PclZip::listContent() for list entry format) 444 // -------------------------------------------------------------------------------- 445 function add($p_filelist) 446 { 447 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ..."); 448 $v_result=1; 449 450 // ----- Reset the error handler 451 $this->privErrorReset(); 452 453 // ----- Set default values 454 $v_options = array(); 455 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; 456 457 // ----- Look for variable options arguments 458 $v_size = func_num_args(); 459 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 460 461 // ----- Look for arguments 462 if ($v_size > 1) { 463 // ----- Get the arguments 464 $v_arg_list = func_get_args(); 465 466 // ----- Remove form the options list the first argument 467 array_shift($v_arg_list); 468 $v_size--; 469 470 // ----- Look for first arg 471 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 472 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); 473 474 // ----- Parse the options 475 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 476 array (PCLZIP_OPT_REMOVE_PATH => 'optional', 477 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 478 PCLZIP_OPT_ADD_PATH => 'optional', 479 PCLZIP_CB_PRE_ADD => 'optional', 480 PCLZIP_CB_POST_ADD => 'optional', 481 PCLZIP_OPT_NO_COMPRESSION => 'optional', 482 PCLZIP_OPT_COMMENT => 'optional', 483 PCLZIP_OPT_ADD_COMMENT => 'optional', 484 PCLZIP_OPT_PREPEND_COMMENT => 'optional' 485 //, PCLZIP_OPT_CRYPT => 'optional' 486 )); 487 if ($v_result != 1) { 488 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 489 return 0; 490 } 491 } 492 493 // ----- Look for 2 args 494 // Here we need to support the first historic synopsis of the 495 // method. 496 else { 497 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 498 499 // ----- Get the first argument 500 $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; 501 502 // ----- Look for the optional second argument 503 if ($v_size == 2) { 504 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; 505 } 506 else if ($v_size > 2) { 507 // ----- Error log 508 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 509 510 // ----- Return 511 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 512 return 0; 513 } 514 } 515 } 516 517 // ----- Init 518 $v_string_list = array(); 519 $v_att_list = array(); 520 $v_filedescr_list = array(); 521 $p_result_list = array(); 522 523 // ----- Look if the $p_filelist is really an array 524 if (is_array($p_filelist)) { 525 526 // ----- Look if the first element is also an array 527 // This will mean that this is a file description entry 528 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 529 $v_att_list = $p_filelist; 530 } 531 532 // ----- The list is a list of string names 533 else { 534 $v_string_list = $p_filelist; 535 } 536 } 537 538 // ----- Look if the $p_filelist is a string 539 else if (is_string($p_filelist)) { 540 // ----- Create a list from the string 541 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); 542 } 543 544 // ----- Invalid variable type for $p_filelist 545 else { 546 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); 547 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 548 return 0; 549 } 550 551 // ----- Reformat the string list 552 if (sizeof($v_string_list) != 0) { 553 foreach ($v_string_list as $v_string) { 554 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 555 } 556 } 557 558 // ----- For each file in the list check the attributes 559 $v_supported_attributes 560 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 561 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 562 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 563 ,PCLZIP_ATT_FILE_MTIME => 'optional' 564 ,PCLZIP_ATT_FILE_CONTENT => 'optional' 565 ,PCLZIP_ATT_FILE_COMMENT => 'optional' 566 ); 567 foreach ($v_att_list as $v_entry) { 568 $v_result = $this->privFileDescrParseAtt($v_entry, 569 $v_filedescr_list[], 570 $v_options, 571 $v_supported_attributes); 572 if ($v_result != 1) { 573 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 574 return 0; 575 } 576 } 577 578 // ----- Expand the filelist (expand directories) 579 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); 580 if ($v_result != 1) { 581 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 582 return 0; 583 } 584 585 // ----- Call the create fct 586 $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); 587 if ($v_result != 1) { 588 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 589 return 0; 590 } 591 592 // ----- Return 593 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); 594 return $p_result_list; 595 } 596 // -------------------------------------------------------------------------------- 597 598 // -------------------------------------------------------------------------------- 599 // Function : listContent() 600 // Description : 601 // This public method, gives the list of the files and directories, with their 602 // properties. 603 // The properties of each entries in the list are (used also in other functions) : 604 // filename : Name of the file. For a create or add action it is the filename 605 // given by the user. For an extract function it is the filename 606 // of the extracted file. 607 // stored_filename : Name of the file / directory stored in the archive. 608 // size : Size of the stored file. 609 // compressed_size : Size of the file's data compressed in the archive 610 // (without the headers overhead) 611 // mtime : Last known modification date of the file (UNIX timestamp) 612 // comment : Comment associated with the file 613 // folder : true | false 614 // index : index of the file in the archive 615 // status : status of the action (depending of the action) : 616 // Values are : 617 // ok : OK ! 618 // filtered : the file / dir is not extracted (filtered by user) 619 // already_a_directory : the file can not be extracted because a 620 // directory with the same name already exists 621 // write_protected : the file can not be extracted because a file 622 // with the same name already exists and is 623 // write protected 624 // newer_exist : the file was not extracted because a newer file exists 625 // path_creation_fail : the file is not extracted because the folder 626 // does not exists and can not be created 627 // write_error : the file was not extracted because there was a 628 // error while writing the file 629 // read_error : the file was not extracted because there was a error 630 // while reading the file 631 // invalid_header : the file was not extracted because of an archive 632 // format error (bad file header) 633 // Note that each time a method can continue operating when there 634 // is an action error on a file, the error is only logged in the file status. 635 // Return Values : 636 // 0 on an unrecoverable failure, 637 // The list of the files in the archive. 638 // -------------------------------------------------------------------------------- 639 function listContent() 640 { 641 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', ""); 642 $v_result=1; 643 644 // ----- Reset the error handler 645 $this->privErrorReset(); 646 647 // ----- Check archive 648 if (!$this->privCheckFormat()) { 649 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 650 return(0); 651 } 652 653 // ----- Call the extracting fct 654 $p_list = array(); 655 if (($v_result = $this->privList($p_list)) != 1) 656 { 657 unset($p_list); 658 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 659 return(0); 660 } 661 662 // ----- Return 663 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); 664 return $p_list; 665 } 666 // -------------------------------------------------------------------------------- 667 668 // -------------------------------------------------------------------------------- 669 // Function : 670 // extract($p_path="./", $p_remove_path="") 671 // extract([$p_option, $p_option_value, ...]) 672 // Description : 673 // This method supports two synopsis. The first one is historical. 674 // This method extract all the files / directories from the archive to the 675 // folder indicated in $p_path. 676 // If you want to ignore the 'root' part of path of the memorized files 677 // you can indicate this in the optional $p_remove_path parameter. 678 // By default, if a newer file with the same name already exists, the 679 // file is not extracted. 680 // 681 // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions 682 // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append 683 // at the end of the path value of PCLZIP_OPT_PATH. 684 // Parameters : 685 // $p_path : Path where the files and directories are to be extracted 686 // $p_remove_path : First part ('root' part) of the memorized path 687 // (if any similar) to remove while extracting. 688 // Options : 689 // PCLZIP_OPT_PATH : 690 // PCLZIP_OPT_ADD_PATH : 691 // PCLZIP_OPT_REMOVE_PATH : 692 // PCLZIP_OPT_REMOVE_ALL_PATH : 693 // PCLZIP_CB_PRE_EXTRACT : 694 // PCLZIP_CB_POST_EXTRACT : 695 // Return Values : 696 // 0 or a negative value on failure, 697 // The list of the extracted files, with a status of the action. 698 // (see PclZip::listContent() for list entry format) 699 // -------------------------------------------------------------------------------- 700 function extract() 701 { 702 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", ""); 703 $v_result=1; 704 705 // ----- Reset the error handler 706 $this->privErrorReset(); 707 708 // ----- Check archive 709 if (!$this->privCheckFormat()) { 710 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 711 return(0); 712 } 713 714 // ----- Set default values 715 $v_options = array(); 716 // $v_path = "./"; 717 $v_path = ''; 718 $v_remove_path = ""; 719 $v_remove_all_path = false; 720 721 // ----- Look for variable options arguments 722 $v_size = func_num_args(); 723 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 724 725 // ----- Default values for option 726 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 727 728 // ----- Look for arguments 729 if ($v_size > 0) { 730 // ----- Get the arguments 731 $v_arg_list = func_get_args(); 732 733 // ----- Look for first arg 734 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 735 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options"); 736 737 // ----- Parse the options 738 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 739 array (PCLZIP_OPT_PATH => 'optional', 740 PCLZIP_OPT_REMOVE_PATH => 'optional', 741 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 742 PCLZIP_OPT_ADD_PATH => 'optional', 743 PCLZIP_CB_PRE_EXTRACT => 'optional', 744 PCLZIP_CB_POST_EXTRACT => 'optional', 745 PCLZIP_OPT_SET_CHMOD => 'optional', 746 PCLZIP_OPT_BY_NAME => 'optional', 747 PCLZIP_OPT_BY_EREG => 'optional', 748 PCLZIP_OPT_BY_PREG => 'optional', 749 PCLZIP_OPT_BY_INDEX => 'optional', 750 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', 751 PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', 752 PCLZIP_OPT_REPLACE_NEWER => 'optional' 753 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' 754 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' 755 )); 756 if ($v_result != 1) { 757 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 758 return 0; 759 } 760 761 // ----- Set the arguments 762 if (isset($v_options[PCLZIP_OPT_PATH])) { 763 $v_path = $v_options[PCLZIP_OPT_PATH]; 764 } 765 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { 766 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; 767 } 768 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 769 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 770 } 771 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { 772 // ----- Check for '/' in last path char 773 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { 774 $v_path .= '/'; 775 } 776 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; 777 } 778 } 779 780 // ----- Look for 2 args 781 // Here we need to support the first historic synopsis of the 782 // method. 783 else { 784 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 785 786 // ----- Get the first argument 787 $v_path = $v_arg_list[0]; 788 789 // ----- Look for the optional second argument 790 if ($v_size == 2) { 791 $v_remove_path = $v_arg_list[1]; 792 } 793 else if ($v_size > 2) { 794 // ----- Error log 795 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 796 797 // ----- Return 798 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 799 return 0; 800 } 801 } 802 } 803 804 // ----- Trace 805 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'"); 806 807 // ----- Call the extracting fct 808 $p_list = array(); 809 $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, 810 $v_remove_all_path, $v_options); 811 if ($v_result < 1) { 812 unset($p_list); 813 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 814 return(0); 815 } 816 817 // ----- Return 818 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); 819 return $p_list; 820 } 821 // -------------------------------------------------------------------------------- 822 823 824 // -------------------------------------------------------------------------------- 825 // Function : 826 // extractByIndex($p_index, $p_path="./", $p_remove_path="") 827 // extractByIndex($p_index, [$p_option, $p_option_value, ...]) 828 // Description : 829 // This method supports two synopsis. The first one is historical. 830 // This method is doing a partial extract of the archive. 831 // The extracted files or folders are identified by their index in the 832 // archive (from 0 to n). 833 // Note that if the index identify a folder, only the folder entry is 834 // extracted, not all the files included in the archive. 835 // Parameters : 836 // $p_index : A single index (integer) or a string of indexes of files to 837 // extract. The form of the string is "0,4-6,8-12" with only numbers 838 // and '-' for range or ',' to separate ranges. No spaces or ';' 839 // are allowed. 840 // $p_path : Path where the files and directories are to be extracted 841 // $p_remove_path : First part ('root' part) of the memorized path 842 // (if any similar) to remove while extracting. 843 // Options : 844 // PCLZIP_OPT_PATH : 845 // PCLZIP_OPT_ADD_PATH : 846 // PCLZIP_OPT_REMOVE_PATH : 847 // PCLZIP_OPT_REMOVE_ALL_PATH : 848 // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and 849 // not as files. 850 // The resulting content is in a new field 'content' in the file 851 // structure. 852 // This option must be used alone (any other options are ignored). 853 // PCLZIP_CB_PRE_EXTRACT : 854 // PCLZIP_CB_POST_EXTRACT : 855 // Return Values : 856 // 0 on failure, 857 // The list of the extracted files, with a status of the action. 858 // (see PclZip::listContent() for list entry format) 859 // -------------------------------------------------------------------------------- 860 //function extractByIndex($p_index, options...) 861 function extractByIndex($p_index) 862 { 863 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ..."); 864 $v_result=1; 865 866 // ----- Reset the error handler 867 $this->privErrorReset(); 868 869 // ----- Check archive 870 if (!$this->privCheckFormat()) { 871 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 872 return(0); 873 } 874 875 // ----- Set default values 876 $v_options = array(); 877 // $v_path = "./"; 878 $v_path = ''; 879 $v_remove_path = ""; 880 $v_remove_all_path = false; 881 882 // ----- Look for variable options arguments 883 $v_size = func_num_args(); 884 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 885 886 // ----- Default values for option 887 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 888 889 // ----- Look for arguments 890 if ($v_size > 1) { 891 // ----- Get the arguments 892 $v_arg_list = func_get_args(); 893 894 // ----- Remove form the options list the first argument 895 array_shift($v_arg_list); 896 $v_size--; 897 898 // ----- Look for first arg 899 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 900 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options"); 901 902 // ----- Parse the options 903 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 904 array (PCLZIP_OPT_PATH => 'optional', 905 PCLZIP_OPT_REMOVE_PATH => 'optional', 906 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 907 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', 908 PCLZIP_OPT_ADD_PATH => 'optional', 909 PCLZIP_CB_PRE_EXTRACT => 'optional', 910 PCLZIP_CB_POST_EXTRACT => 'optional', 911 PCLZIP_OPT_SET_CHMOD => 'optional', 912 PCLZIP_OPT_REPLACE_NEWER => 'optional' 913 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' 914 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' 915 )); 916 if ($v_result != 1) { 917 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 918 return 0; 919 } 920 921 // ----- Set the arguments 922 if (isset($v_options[PCLZIP_OPT_PATH])) { 923 $v_path = $v_options[PCLZIP_OPT_PATH]; 924 } 925 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { 926 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; 927 } 928 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 929 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 930 } 931 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { 932 // ----- Check for '/' in last path char 933 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { 934 $v_path .= '/'; 935 } 936 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; 937 } 938 if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { 939 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 940 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set."); 941 } 942 else { 943 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set."); 944 } 945 } 946 947 // ----- Look for 2 args 948 // Here we need to support the first historic synopsis of the 949 // method. 950 else { 951 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 952 953 // ----- Get the first argument 954 $v_path = $v_arg_list[0]; 955 956 // ----- Look for the optional second argument 957 if ($v_size == 2) { 958 $v_remove_path = $v_arg_list[1]; 959 } 960 else if ($v_size > 2) { 961 // ----- Error log 962 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 963 964 // ----- Return 965 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 966 return 0; 967 } 968 } 969 } 970 971 // ----- Trace 972 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "index='$p_index', path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'"); 973 974 // ----- Trick 975 // Here I want to reuse extractByRule(), so I need to parse the $p_index 976 // with privParseOptions() 977 $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); 978 $v_options_trick = array(); 979 $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, 980 array (PCLZIP_OPT_BY_INDEX => 'optional' )); 981 if ($v_result != 1) { 982 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 983 return 0; 984 } 985 $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; 986 987 // ----- Call the extracting fct 988 if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { 989 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 990 return(0); 991 } 992 993 // ----- Return 994 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); 995 return $p_list; 996 } 997 // -------------------------------------------------------------------------------- 998 999 // -------------------------------------------------------------------------------- 1000 // Function : 1001 // delete([$p_option, $p_option_value, ...]) 1002 // Description : 1003 // This method removes files from the archive. 1004 // If no parameters are given, then all the archive is emptied. 1005 // Parameters : 1006 // None or optional arguments. 1007 // Options : 1008 // PCLZIP_OPT_BY_INDEX : 1009 // PCLZIP_OPT_BY_NAME : 1010 // PCLZIP_OPT_BY_EREG : 1011 // PCLZIP_OPT_BY_PREG : 1012 // Return Values : 1013 // 0 on failure, 1014 // The list of the files which are still present in the archive. 1015 // (see PclZip::listContent() for list entry format) 1016 // -------------------------------------------------------------------------------- 1017 function delete() 1018 { 1019 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", ""); 1020 $v_result=1; 1021 1022 // ----- Reset the error handler 1023 $this->privErrorReset(); 1024 1025 // ----- Check archive 1026 if (!$this->privCheckFormat()) { 1027 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1028 return(0); 1029 } 1030 1031 // ----- Set default values 1032 $v_options = array(); 1033 1034 // ----- Look for variable options arguments 1035 $v_size = func_num_args(); 1036 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 1037 1038 // ----- Look for arguments 1039 if ($v_size > 0) { 1040 // ----- Get the arguments 1041 $v_arg_list = func_get_args(); 1042 1043 // ----- Parse the options 1044 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 1045 array (PCLZIP_OPT_BY_NAME => 'optional', 1046 PCLZIP_OPT_BY_EREG => 'optional', 1047 PCLZIP_OPT_BY_PREG => 'optional', 1048 PCLZIP_OPT_BY_INDEX => 'optional' )); 1049 if ($v_result != 1) { 1050 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1051 return 0; 1052 } 1053 } 1054 1055 // ----- Magic quotes trick 1056 $this->privDisableMagicQuotes(); 1057 1058 // ----- Call the delete fct 1059 $v_list = array(); 1060 if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { 1061 $this->privSwapBackMagicQuotes(); 1062 unset($v_list); 1063 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 1064 return(0); 1065 } 1066 1067 // ----- Magic quotes trick 586 } 587 } 588 589 $this->privDisableMagicQuotes(); 590 591 $v_list = array(); 592 if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { 1068 593 $this->privSwapBackMagicQuotes(); 1069 1070 // ----- Return 1071 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list); 1072 return $v_list; 1073 } 1074 // -------------------------------------------------------------------------------- 1075 1076 // -------------------------------------------------------------------------------- 1077 // Function : deleteByIndex() 1078 // Description : 1079 // ***** Deprecated ***** 1080 // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered. 1081 // -------------------------------------------------------------------------------- 1082 function deleteByIndex($p_index) 1083 { 1084 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'"); 1085 1086 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); 1087 1088 // ----- Return 1089 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); 1090 return $p_list; 1091 } 1092 // -------------------------------------------------------------------------------- 1093 1094 // -------------------------------------------------------------------------------- 1095 // Function : properties() 1096 // Description : 1097 // This method gives the properties of the archive. 1098 // The properties are : 1099 // nb : Number of files in the archive 1100 // comment : Comment associated with the archive file 1101 // status : not_exist, ok 1102 // Parameters : 1103 // None 1104 // Return Values : 1105 // 0 on failure, 1106 // An array with the archive properties. 1107 // -------------------------------------------------------------------------------- 1108 function properties() 1109 { 1110 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", ""); 1111 1112 // ----- Reset the error handler 1113 $this->privErrorReset(); 1114 1115 // ----- Magic quotes trick 1116 $this->privDisableMagicQuotes(); 1117 1118 // ----- Check archive 1119 if (!$this->privCheckFormat()) { 1120 $this->privSwapBackMagicQuotes(); 1121 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1122 return(0); 1123 } 1124 1125 // ----- Default properties 1126 $v_prop = array(); 1127 $v_prop['comment'] = ''; 1128 $v_prop['nb'] = 0; 1129 $v_prop['status'] = 'not_exist'; 1130 1131 // ----- Look if file exists 1132 if (@is_file($this->zipname)) 1133 { 1134 // ----- Open the zip file 1135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 1136 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) 1137 { 1138 $this->privSwapBackMagicQuotes(); 1139 1140 // ----- Error log 1141 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); 1142 1143 // ----- Return 1144 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0); 1145 return 0; 1146 } 1147 1148 // ----- Read the central directory informations 1149 $v_central_dir = array(); 1150 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 1151 { 1152 $this->privSwapBackMagicQuotes(); 1153 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1154 return 0; 1155 } 1156 1157 // ----- Close the zip file 1158 $this->privCloseFd(); 1159 1160 // ----- Set the user attributes 1161 $v_prop['comment'] = $v_central_dir['comment']; 1162 $v_prop['nb'] = $v_central_dir['entries']; 1163 $v_prop['status'] = 'ok'; 1164 } 1165 1166 // ----- Magic quotes trick 594 unset($v_list); 595 return(0); 596 } 597 598 $this->privSwapBackMagicQuotes(); 599 600 return $v_list; 601 } 602 603 function deleteByIndex($p_index) 604 { 605 606 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); 607 608 return $p_list; 609 } 610 611 function properties() 612 { 613 614 $this->privErrorReset(); 615 616 $this->privDisableMagicQuotes(); 617 618 if (!$this->privCheckFormat()) { 1167 619 $this->privSwapBackMagicQuotes(); 1168 1169 // ----- Return 1170 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop); 1171 return $v_prop; 1172 } 1173 // -------------------------------------------------------------------------------- 1174 1175 // -------------------------------------------------------------------------------- 1176 // Function : duplicate() 1177 // Description : 1178 // This method creates an archive by copying the content of an other one. If 1179 // the archive already exist, it is replaced by the new one without any warning. 1180 // Parameters : 1181 // $p_archive : The filename of a valid archive, or 1182 // a valid PclZip object. 1183 // Return Values : 1184 // 1 on success. 1185 // 0 or a negative value on error (error code). 1186 // -------------------------------------------------------------------------------- 1187 function duplicate($p_archive) 1188 { 1189 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", ""); 1190 $v_result = 1; 1191 1192 // ----- Reset the error handler 1193 $this->privErrorReset(); 1194 1195 // ----- Look if the $p_archive is a PclZip object 1196 if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) 1197 { 1198 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'"); 1199 1200 // ----- Duplicate the archive 1201 $v_result = $this->privDuplicate($p_archive->zipname); 1202 } 1203 1204 // ----- Look if the $p_archive is a string (so a filename) 1205 else if (is_string($p_archive)) 1206 { 1207 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'"); 1208 1209 // ----- Check that $p_archive is a valid zip file 1210 // TBC : Should also check the archive format 1211 if (!is_file($p_archive)) { 1212 // ----- Error log 1213 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); 1214 $v_result = PCLZIP_ERR_MISSING_FILE; 1215 } 1216 else { 1217 // ----- Duplicate the archive 1218 $v_result = $this->privDuplicate($p_archive); 1219 } 1220 } 1221 1222 // ----- Invalid variable 1223 else 1224 { 1225 // ----- Error log 1226 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); 1227 $v_result = PCLZIP_ERR_INVALID_PARAMETER; 1228 } 1229 1230 // ----- Return 1231 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1232 return $v_result; 1233 } 1234 // -------------------------------------------------------------------------------- 1235 1236 // -------------------------------------------------------------------------------- 1237 // Function : merge() 1238 // Description : 1239 // This method merge the $p_archive_to_add archive at the end of the current 1240 // one ($this). 1241 // If the archive ($this) does not exist, the merge becomes a duplicate. 1242 // If the $p_archive_to_add archive does not exist, the merge is a success. 1243 // Parameters : 1244 // $p_archive_to_add : It can be directly the filename of a valid zip archive, 1245 // or a PclZip object archive. 1246 // Return Values : 1247 // 1 on success, 1248 // 0 or negative values on error (see below). 1249 // -------------------------------------------------------------------------------- 1250 function merge($p_archive_to_add) 1251 { 1252 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", ""); 1253 $v_result = 1; 1254 1255 // ----- Reset the error handler 1256 $this->privErrorReset(); 1257 1258 // ----- Check archive 1259 if (!$this->privCheckFormat()) { 1260 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1261 return(0); 1262 } 1263 1264 // ----- Look if the $p_archive_to_add is a PclZip object 1265 if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) 1266 { 1267 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object"); 1268 1269 // ----- Merge the archive 1270 $v_result = $this->privMerge($p_archive_to_add); 1271 } 1272 1273 // ----- Look if the $p_archive_to_add is a string (so a filename) 1274 else if (is_string($p_archive_to_add)) 1275 { 1276 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename"); 1277 1278 // ----- Create a temporary archive 1279 $v_object_archive = new PclZip($p_archive_to_add); 1280 1281 // ----- Merge the archive 1282 $v_result = $this->privMerge($v_object_archive); 1283 } 1284 1285 // ----- Invalid variable 1286 else 1287 { 1288 // ----- Error log 1289 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); 1290 $v_result = PCLZIP_ERR_INVALID_PARAMETER; 1291 } 1292 1293 // ----- Return 1294 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1295 return $v_result; 1296 } 1297 // -------------------------------------------------------------------------------- 1298 1299 1300 1301 // -------------------------------------------------------------------------------- 1302 // Function : errorCode() 1303 // Description : 1304 // Parameters : 1305 // -------------------------------------------------------------------------------- 1306 function errorCode() 1307 { 1308 if (PCLZIP_ERROR_EXTERNAL == 1) { 1309 return(PclErrorCode()); 1310 } 1311 else { 1312 return($this->error_code); 1313 } 1314 } 1315 // -------------------------------------------------------------------------------- 1316 1317 // -------------------------------------------------------------------------------- 1318 // Function : errorName() 1319 // Description : 1320 // Parameters : 1321 // -------------------------------------------------------------------------------- 1322 function errorName($p_with_code=false) 1323 { 1324 $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', 1325 PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', 1326 PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', 1327 PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', 1328 PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', 1329 PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', 1330 PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', 1331 PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', 1332 PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', 1333 PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', 1334 PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', 1335 PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', 1336 PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', 1337 PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', 1338 PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', 1339 PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', 1340 PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', 1341 PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', 1342 PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' 1343 ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' 1344 ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' 1345 ); 1346 1347 if (isset($v_name[$this->error_code])) { 1348 $v_value = $v_name[$this->error_code]; 1349 } 1350 else { 1351 $v_value = 'NoName'; 1352 } 1353 1354 if ($p_with_code) { 1355 return($v_value.' ('.$this->error_code.')'); 1356 } 1357 else { 1358 return($v_value); 1359 } 1360 } 1361 // -------------------------------------------------------------------------------- 1362 1363 // -------------------------------------------------------------------------------- 1364 // Function : errorInfo() 1365 // Description : 1366 // Parameters : 1367 // -------------------------------------------------------------------------------- 1368 function errorInfo($p_full=false) 1369 { 1370 if (PCLZIP_ERROR_EXTERNAL == 1) { 1371 return(PclErrorString()); 1372 } 1373 else { 1374 if ($p_full) { 1375 return($this->errorName(true)." : ".$this->error_string); 1376 } 1377 else { 1378 return($this->error_string." [code ".$this->error_code."]"); 1379 } 1380 } 1381 } 1382 // -------------------------------------------------------------------------------- 1383 1384 1385 // -------------------------------------------------------------------------------- 1386 // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS ***** 1387 // ***** ***** 1388 // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY ***** 1389 // -------------------------------------------------------------------------------- 1390 1391 1392 1393 // -------------------------------------------------------------------------------- 1394 // Function : privCheckFormat() 1395 // Description : 1396 // This method check that the archive exists and is a valid zip archive. 1397 // Several level of check exists. (futur) 1398 // Parameters : 1399 // $p_level : Level of check. Default 0. 1400 // 0 : Check the first bytes (magic codes) (default value)) 1401 // 1 : 0 + Check the central directory (futur) 1402 // 2 : 1 + Check each file header (futur) 1403 // Return Values : 1404 // true on success, 1405 // false on error, the error code is set. 1406 // -------------------------------------------------------------------------------- 1407 function privCheckFormat($p_level=0) 1408 { 1409 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", ""); 1410 $v_result = true; 1411 1412 // ----- Reset the file system cache 1413 clearstatcache(); 1414 1415 // ----- Reset the error handler 1416 $this->privErrorReset(); 1417 1418 // ----- Look if the file exits 1419 if (!is_file($this->zipname)) { 1420 // ----- Error log 1421 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); 1422 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); 1423 return(false); 1424 } 1425 1426 // ----- Check that the file is readeable 1427 if (!is_readable($this->zipname)) { 1428 // ----- Error log 1429 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); 1430 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); 1431 return(false); 1432 } 1433 1434 // ----- Check the magic code 1435 // TBC 1436 1437 // ----- Check the central header 1438 // TBC 1439 1440 // ----- Check each file header 1441 // TBC 1442 1443 // ----- Return 1444 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1445 return $v_result; 1446 } 1447 // -------------------------------------------------------------------------------- 1448 1449 // -------------------------------------------------------------------------------- 1450 // Function : privParseOptions() 1451 // Description : 1452 // This internal methods reads the variable list of arguments ($p_options_list, 1453 // $p_size) and generate an array with the options and values ($v_result_list). 1454 // $v_requested_options contains the options that can be present and those that 1455 // must be present. 1456 // $v_requested_options is an array, with the option value as key, and 'optional', 1457 // or 'mandatory' as value. 1458 // Parameters : 1459 // See above. 1460 // Return Values : 1461 // 1 on success. 1462 // 0 on failure. 1463 // -------------------------------------------------------------------------------- 1464 function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) 1465 { 1466 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", ""); 1467 $v_result=1; 1468 1469 // ----- Read the options 1470 $i=0; 1471 while ($i<$p_size) { 1472 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'"); 1473 1474 // ----- Check if the option is supported 1475 if (!isset($v_requested_options[$p_options_list[$i]])) { 1476 // ----- Error log 1477 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); 1478 1479 // ----- Return 1480 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1481 return PclZip::errorCode(); 1482 } 1483 1484 // ----- Look for next option 1485 switch ($p_options_list[$i]) { 1486 // ----- Look for options that request a path value 1487 case PCLZIP_OPT_PATH : 1488 case PCLZIP_OPT_REMOVE_PATH : 1489 case PCLZIP_OPT_ADD_PATH : 1490 // ----- Check the number of parameters 1491 if (($i+1) >= $p_size) { 1492 // ----- Error log 1493 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1494 1495 // ----- Return 1496 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1497 return PclZip::errorCode(); 1498 } 1499 1500 // ----- Get the value 1501 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 1502 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1503 $i++; 1504 break; 1505 1506 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : 1507 // ----- Check the number of parameters 1508 if (($i+1) >= $p_size) { 1509 // ----- Error log 1510 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1511 1512 // ----- Return 1513 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1514 return PclZip::errorCode(); 1515 } 1516 1517 // ----- Get the value 1518 if ( is_string($p_options_list[$i+1]) 1519 && ($p_options_list[$i+1] != '')) { 1520 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 1521 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1522 $i++; 1523 } 1524 else { 1525 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored."); 1526 } 1527 break; 1528 1529 // ----- Look for options that request an array of string for value 1530 case PCLZIP_OPT_BY_NAME : 1531 // ----- Check the number of parameters 1532 if (($i+1) >= $p_size) { 1533 // ----- Error log 1534 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1535 1536 // ----- Return 1537 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1538 return PclZip::errorCode(); 1539 } 1540 1541 // ----- Get the value 1542 if (is_string($p_options_list[$i+1])) { 1543 $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; 1544 } 1545 else if (is_array($p_options_list[$i+1])) { 1546 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1547 } 1548 else { 1549 // ----- Error log 1550 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1551 1552 // ----- Return 1553 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1554 return PclZip::errorCode(); 1555 } 1556 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1557 $i++; 1558 break; 1559 1560 // ----- Look for options that request an EREG or PREG expression 1561 case PCLZIP_OPT_BY_EREG : 1562 case PCLZIP_OPT_BY_PREG : 1563 //case PCLZIP_OPT_CRYPT : 1564 // ----- Check the number of parameters 1565 if (($i+1) >= $p_size) { 1566 // ----- Error log 1567 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1568 1569 // ----- Return 1570 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1571 return PclZip::errorCode(); 1572 } 1573 1574 // ----- Get the value 1575 if (is_string($p_options_list[$i+1])) { 1576 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1577 } 1578 else { 1579 // ----- Error log 1580 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1581 1582 // ----- Return 1583 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1584 return PclZip::errorCode(); 1585 } 1586 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1587 $i++; 1588 break; 1589 1590 // ----- Look for options that takes a string 1591 case PCLZIP_OPT_COMMENT : 1592 case PCLZIP_OPT_ADD_COMMENT : 1593 case PCLZIP_OPT_PREPEND_COMMENT : 1594 // ----- Check the number of parameters 1595 if (($i+1) >= $p_size) { 1596 // ----- Error log 1597 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, 1598 "Missing parameter value for option '" 1599 .PclZipUtilOptionText($p_options_list[$i]) 1600 ."'"); 1601 1602 // ----- Return 1603 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1604 return PclZip::errorCode(); 1605 } 1606 1607 // ----- Get the value 1608 if (is_string($p_options_list[$i+1])) { 1609 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1610 } 1611 else { 1612 // ----- Error log 1613 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 1614 "Wrong parameter value for option '" 1615 .PclZipUtilOptionText($p_options_list[$i]) 1616 ."'"); 1617 1618 // ----- Return 1619 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1620 return PclZip::errorCode(); 1621 } 1622 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1623 $i++; 1624 break; 1625 1626 // ----- Look for options that request an array of index 1627 case PCLZIP_OPT_BY_INDEX : 1628 // ----- Check the number of parameters 1629 if (($i+1) >= $p_size) { 1630 // ----- Error log 1631 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1632 1633 // ----- Return 1634 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1635 return PclZip::errorCode(); 1636 } 1637 1638 // ----- Get the value 1639 $v_work_list = array(); 1640 if (is_string($p_options_list[$i+1])) { 1641 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'"); 1642 1643 // ----- Remove spaces 1644 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); 1645 1646 // ----- Parse items 1647 $v_work_list = explode(",", $p_options_list[$i+1]); 1648 } 1649 else if (is_integer($p_options_list[$i+1])) { 1650 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'"); 1651 $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; 1652 } 1653 else if (is_array($p_options_list[$i+1])) { 1654 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array"); 1655 $v_work_list = $p_options_list[$i+1]; 1656 } 1657 else { 1658 // ----- Error log 1659 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1660 1661 // ----- Return 1662 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1663 return PclZip::errorCode(); 1664 } 1665 1666 // ----- Reduce the index list 1667 // each index item in the list must be a couple with a start and 1668 // an end value : [0,3], [5-5], [8-10], ... 1669 // ----- Check the format of each item 1670 $v_sort_flag=false; 1671 $v_sort_value=0; 1672 for ($j=0; $j<sizeof($v_work_list); $j++) { 1673 // ----- Explode the item 1674 $v_item_list = explode("-", $v_work_list[$j]); 1675 $v_size_item_list = sizeof($v_item_list); 1676 1677 // ----- TBC : Here we might check that each item is a 1678 // real integer ... 1679 1680 // ----- Look for single value 1681 if ($v_size_item_list == 1) { 1682 // ----- Set the option value 1683 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; 1684 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; 1685 } 1686 elseif ($v_size_item_list == 2) { 1687 // ----- Set the option value 1688 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; 1689 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; 1690 } 1691 else { 1692 // ----- Error log 1693 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1694 1695 // ----- Return 1696 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1697 return PclZip::errorCode(); 1698 } 1699 1700 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extracted index item = [".$v_result_list[$p_options_list[$i]][$j]['start'].",".$v_result_list[$p_options_list[$i]][$j]['end']."]"); 1701 1702 // ----- Look for list sort 1703 if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { 1704 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ..."); 1705 $v_sort_flag=true; 1706 1707 // ----- TBC : An automatic sort should be writen ... 1708 // ----- Error log 1709 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1710 1711 // ----- Return 1712 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1713 return PclZip::errorCode(); 1714 } 1715 $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; 1716 } 1717 1718 // ----- Sort the items 1719 if ($v_sort_flag) { 1720 // TBC : To Be Completed 1721 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ..."); 1722 } 1723 1724 // ----- Next option 1725 $i++; 1726 break; 1727 1728 // ----- Look for options that request no value 1729 case PCLZIP_OPT_REMOVE_ALL_PATH : 1730 case PCLZIP_OPT_EXTRACT_AS_STRING : 1731 case PCLZIP_OPT_NO_COMPRESSION : 1732 case PCLZIP_OPT_EXTRACT_IN_OUTPUT : 1733 case PCLZIP_OPT_REPLACE_NEWER : 1734 case PCLZIP_OPT_STOP_ON_ERROR : 1735 $v_result_list[$p_options_list[$i]] = true; 1736 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1737 break; 1738 1739 // ----- Look for options that request an octal value 1740 case PCLZIP_OPT_SET_CHMOD : 1741 // ----- Check the number of parameters 1742 if (($i+1) >= $p_size) { 1743 // ----- Error log 1744 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1745 1746 // ----- Return 1747 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1748 return PclZip::errorCode(); 1749 } 1750 1751 // ----- Get the value 1752 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1753 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1754 $i++; 1755 break; 1756 1757 // ----- Look for options that request a call-back 1758 case PCLZIP_CB_PRE_EXTRACT : 1759 case PCLZIP_CB_POST_EXTRACT : 1760 case PCLZIP_CB_PRE_ADD : 1761 case PCLZIP_CB_POST_ADD : 1762 /* for futur use 1763 case PCLZIP_CB_PRE_DELETE : 1764 case PCLZIP_CB_POST_DELETE : 1765 case PCLZIP_CB_PRE_LIST : 1766 case PCLZIP_CB_POST_LIST : 1767 */ 1768 // ----- Check the number of parameters 1769 if (($i+1) >= $p_size) { 1770 // ----- Error log 1771 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1772 1773 // ----- Return 1774 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1775 return PclZip::errorCode(); 1776 } 1777 1778 // ----- Get the value 1779 $v_function_name = $p_options_list[$i+1]; 1780 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'"); 1781 1782 // ----- Check that the value is a valid existing function 1783 if (!function_exists($v_function_name)) { 1784 // ----- Error log 1785 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1786 1787 // ----- Return 1788 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1789 return PclZip::errorCode(); 1790 } 1791 1792 // ----- Set the attribute 1793 $v_result_list[$p_options_list[$i]] = $v_function_name; 1794 $i++; 1795 break; 1796 1797 default : 1798 // ----- Error log 1799 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 1800 "Unknown parameter '" 1801 .$p_options_list[$i]."'"); 1802 1803 // ----- Return 1804 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1805 return PclZip::errorCode(); 1806 } 1807 1808 // ----- Next options 1809 $i++; 1810 } 1811 1812 // ----- Look for mandatory options 1813 if ($v_requested_options !== false) { 1814 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 1815 // ----- Look for mandatory option 1816 if ($v_requested_options[$key] == 'mandatory') { 1817 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); 1818 // ----- Look if present 1819 if (!isset($v_result_list[$key])) { 1820 // ----- Error log 1821 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 1822 1823 // ----- Return 1824 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1825 return PclZip::errorCode(); 1826 } 1827 } 1828 } 1829 } 1830 1831 // ----- Return 1832 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1833 return $v_result; 1834 } 1835 // -------------------------------------------------------------------------------- 1836 1837 // -------------------------------------------------------------------------------- 1838 // Function : privFileDescrParseAtt() 1839 // Description : 1840 // Parameters : 1841 // Return Values : 1842 // 1 on success. 1843 // 0 on failure. 1844 // -------------------------------------------------------------------------------- 1845 function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) 1846 { 1847 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); 1848 $v_result=1; 1849 1850 // ----- For each file in the list check the attributes 1851 foreach ($p_file_list as $v_key => $v_value) { 1852 1853 // ----- Check if the option is supported 1854 if (!isset($v_requested_options[$v_key])) { 1855 // ----- Error log 1856 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); 1857 1858 // ----- Return 1859 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1860 return PclZip::errorCode(); 1861 } 1862 1863 // ----- Look for attribute 1864 switch ($v_key) { 1865 case PCLZIP_ATT_FILE_NAME : 1866 if (!is_string($v_value)) { 1867 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1868 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1869 return PclZip::errorCode(); 1870 } 1871 1872 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); 1873 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1874 1875 if ($p_filedescr['filename'] == '') { 1876 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1877 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1878 return PclZip::errorCode(); 1879 } 1880 1881 break; 1882 1883 case PCLZIP_ATT_FILE_NEW_SHORT_NAME : 1884 if (!is_string($v_value)) { 1885 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1886 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1887 return PclZip::errorCode(); 1888 } 1889 1890 $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); 1891 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1892 1893 if ($p_filedescr['new_short_name'] == '') { 1894 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1895 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1896 return PclZip::errorCode(); 1897 } 1898 break; 1899 1900 case PCLZIP_ATT_FILE_NEW_FULL_NAME : 1901 if (!is_string($v_value)) { 1902 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1903 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1904 return PclZip::errorCode(); 1905 } 1906 1907 $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); 1908 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1909 1910 if ($p_filedescr['new_full_name'] == '') { 1911 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1912 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1913 return PclZip::errorCode(); 1914 } 1915 break; 1916 1917 // ----- Look for options that takes a string 1918 case PCLZIP_ATT_FILE_COMMENT : 1919 if (!is_string($v_value)) { 1920 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1921 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1922 return PclZip::errorCode(); 1923 } 1924 1925 $p_filedescr['comment'] = $v_value; 1926 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1927 break; 1928 1929 case PCLZIP_ATT_FILE_MTIME : 1930 if (!is_integer($v_value)) { 1931 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1932 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1933 return PclZip::errorCode(); 1934 } 1935 1936 $p_filedescr['mtime'] = $v_value; 1937 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1938 break; 1939 1940 case PCLZIP_ATT_FILE_CONTENT : 1941 $p_filedescr['content'] = $v_value; 1942 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1943 break; 1944 1945 default : 1946 // ----- Error log 1947 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 1948 "Unknown parameter '".$v_key."'"); 1949 1950 // ----- Return 1951 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1952 return PclZip::errorCode(); 1953 } 1954 1955 // ----- Look for mandatory options 1956 if ($v_requested_options !== false) { 1957 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 1958 // ----- Look for mandatory option 1959 if ($v_requested_options[$key] == 'mandatory') { 1960 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); 1961 // ----- Look if present 1962 if (!isset($p_file_list[$key])) { 1963 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 1964 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1965 return PclZip::errorCode(); 1966 } 1967 } 1968 } 1969 } 1970 1971 // end foreach 1972 } 1973 1974 // ----- Return 1975 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1976 return $v_result; 1977 } 1978 // -------------------------------------------------------------------------------- 1979 1980 // -------------------------------------------------------------------------------- 1981 // Function : privFileDescrExpand() 1982 // Description : 1983 // Parameters : 1984 // Return Values : 1985 // 1 on success. 1986 // 0 on failure. 1987 // -------------------------------------------------------------------------------- 1988 function privFileDescrExpand(&$p_filedescr_list, &$p_options) 1989 { 1990 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); 1991 $v_result=1; 1992 1993 // ----- Create a result list 1994 $v_result_list = array(); 1995 1996 // ----- Look each entry 1997 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { 1998 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i."."); 1999 2000 // ----- Get filedescr 2001 $v_descr = $p_filedescr_list[$i]; 2002 2003 // ----- Reduce the filename 2004 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'"); 2005 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']); 2006 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); 2007 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'"); 2008 2009 // ----- Look for real file or folder 2010 if (file_exists($v_descr['filename'])) { 2011 if (@is_file($v_descr['filename'])) { 2012 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file"); 2013 $v_descr['type'] = 'file'; 2014 } 2015 else if (@is_dir($v_descr['filename'])) { 2016 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder"); 2017 $v_descr['type'] = 'folder'; 2018 } 2019 else if (@is_link($v_descr['filename'])) { 2020 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link"); 2021 // skip 2022 continue; 2023 } 2024 else { 2025 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type"); 2026 // skip 2027 continue; 2028 } 2029 } 2030 2031 // ----- Look for string added as file 2032 else if (isset($v_descr['content'])) { 2033 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a string added as a file"); 2034 $v_descr['type'] = 'virtual_file'; 2035 } 2036 2037 // ----- Missing file 2038 else { 2039 // ----- Error log 2040 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exists"); 2041 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists"); 2042 2043 // ----- Return 2044 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2045 return PclZip::errorCode(); 2046 } 2047 2048 // ----- Calculate the stored filename 2049 $this->privCalculateStoredFilename($v_descr, $p_options); 2050 2051 // ----- Add the descriptor in result list 2052 $v_result_list[sizeof($v_result_list)] = $v_descr; 2053 2054 // ----- Look for folder 2055 if ($v_descr['type'] == 'folder') { 2056 // ----- List of items in folder 2057 $v_dirlist_descr = array(); 2058 $v_dirlist_nb = 0; 2059 if ($v_folder_handler = @opendir($v_descr['filename'])) { 2060 while (($v_item_handler = @readdir($v_folder_handler)) !== false) { 2061 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory"); 2062 2063 // ----- Skip '.' and '..' 2064 if (($v_item_handler == '.') || ($v_item_handler == '..')) { 2065 continue; 2066 } 2067 2068 // ----- Compose the full filename 2069 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; 2070 2071 // ----- Look for different stored filename 2072 // Because the name of the folder was changed, the name of the 2073 // files/sub-folders also change 2074 if ($v_descr['stored_filename'] != $v_descr['filename']) { 2075 if ($v_descr['stored_filename'] != '') { 2076 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; 2077 } 2078 else { 2079 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; 2080 } 2081 } 2082 2083 $v_dirlist_nb++; 2084 } 2085 2086 @closedir($v_folder_handler); 2087 } 2088 else { 2089 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped."); 2090 // TBC : unable to open folder in read mode 2091 } 2092 2093 // ----- Expand each element of the list 2094 if ($v_dirlist_nb != 0) { 2095 // ----- Expand 2096 if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { 2097 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2098 return $v_result; 2099 } 2100 2101 // ----- Concat the resulting list 2102 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); 2103 $v_result_list = array_merge($v_result_list, $v_dirlist_descr); 2104 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'"); 2105 } 2106 else { 2107 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); 2108 } 2109 2110 // ----- Free local array 2111 unset($v_dirlist_descr); 2112 } 2113 } 2114 2115 // ----- Get the result list 2116 $p_filedescr_list = $v_result_list; 2117 2118 // ----- Return 2119 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2120 return $v_result; 2121 } 2122 // -------------------------------------------------------------------------------- 2123 2124 // -------------------------------------------------------------------------------- 2125 // Function : privCreate() 2126 // Description : 2127 // Parameters : 2128 // Return Values : 2129 // -------------------------------------------------------------------------------- 2130 function privCreate($p_filedescr_list, &$p_result_list, &$p_options) 2131 { 2132 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list"); 2133 $v_result=1; 2134 $v_list_detail = array(); 2135 2136 // ----- Magic quotes trick 2137 $this->privDisableMagicQuotes(); 2138 2139 // ----- Open the file in write mode 2140 if (($v_result = $this->privOpenFd('wb')) != 1) 2141 { 2142 // ----- Return 2143 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2144 return $v_result; 2145 } 2146 2147 // ----- Add the list of files 2148 $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); 2149 2150 // ----- Close 2151 $this->privCloseFd(); 2152 2153 // ----- Magic quotes trick 2154 $this->privSwapBackMagicQuotes(); 2155 2156 // ----- Return 2157 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2158 return $v_result; 2159 } 2160 // -------------------------------------------------------------------------------- 2161 2162 // -------------------------------------------------------------------------------- 2163 // Function : privAdd() 2164 // Description : 2165 // Parameters : 2166 // Return Values : 2167 // -------------------------------------------------------------------------------- 2168 function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 2169 { 2170 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list"); 2171 $v_result=1; 2172 $v_list_detail = array(); 2173 2174 // ----- Look if the archive exists or is empty 2175 if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) 2176 { 2177 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it."); 2178 2179 // ----- Do a create 2180 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); 2181 2182 // ----- Return 2183 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2184 return $v_result; 2185 } 2186 // ----- Magic quotes trick 2187 $this->privDisableMagicQuotes(); 2188 2189 // ----- Open the zip file 2190 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 2191 if (($v_result=$this->privOpenFd('rb')) != 1) 2192 { 2193 // ----- Magic quotes trick 2194 $this->privSwapBackMagicQuotes(); 2195 2196 // ----- Return 2197 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2198 return $v_result; 2199 } 2200 2201 // ----- Read the central directory informations 2202 $v_central_dir = array(); 2203 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 2204 { 2205 $this->privCloseFd(); 2206 $this->privSwapBackMagicQuotes(); 2207 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2208 return $v_result; 2209 } 2210 2211 // ----- Go to beginning of File 2212 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 2213 @rewind($this->zip_fd); 2214 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 2215 2216 // ----- Creates a temporay file 2217 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 2218 2219 // ----- Open the temporary file in write mode 2220 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 2221 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) 2222 { 2223 $this->privCloseFd(); 2224 $this->privSwapBackMagicQuotes(); 2225 2226 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); 2227 2228 // ----- Return 2229 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2230 return PclZip::errorCode(); 2231 } 2232 2233 // ----- Copy the files from the archive to the temporary file 2234 // TBC : Here I should better append the file and go back to erase the central dir 2235 $v_size = $v_central_dir['offset']; 2236 while ($v_size != 0) 2237 { 2238 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2239 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 2240 $v_buffer = fread($this->zip_fd, $v_read_size); 2241 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 2242 $v_size -= $v_read_size; 2243 } 2244 2245 // ----- Swap the file descriptor 2246 // Here is a trick : I swap the temporary fd with the zip fd, in order to use 2247 // the following methods on the temporary fil and not the real archive 2248 $v_swap = $this->zip_fd; 2249 $this->zip_fd = $v_zip_temp_fd; 2250 $v_zip_temp_fd = $v_swap; 2251 2252 // ----- Add the files 2253 $v_header_list = array(); 2254 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) 2255 { 2256 fclose($v_zip_temp_fd); 2257 $this->privCloseFd(); 2258 @unlink($v_zip_temp_name); 2259 $this->privSwapBackMagicQuotes(); 2260 2261 // ----- Return 2262 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2263 return $v_result; 2264 } 2265 2266 // ----- Store the offset of the central dir 2267 $v_offset = @ftell($this->zip_fd); 2268 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); 2269 2270 // ----- Copy the block of file headers from the old archive 2271 $v_size = $v_central_dir['size']; 2272 while ($v_size != 0) 2273 { 2274 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2275 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 2276 $v_buffer = @fread($v_zip_temp_fd, $v_read_size); 2277 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 2278 $v_size -= $v_read_size; 2279 } 2280 2281 // ----- Create the Central Dir files header 2282 for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) 2283 { 2284 // ----- Create the file header 2285 if ($v_header_list[$i]['status'] == 'ok') { 2286 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 2287 fclose($v_zip_temp_fd); 2288 $this->privCloseFd(); 2289 @unlink($v_zip_temp_name); 2290 $this->privSwapBackMagicQuotes(); 2291 2292 // ----- Return 2293 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2294 return $v_result; 2295 } 2296 $v_count++; 2297 } 2298 2299 // ----- Transform the header to a 'usable' info 2300 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 2301 } 2302 2303 // ----- Zip file comment 2304 $v_comment = $v_central_dir['comment']; 2305 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 2306 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 2307 } 2308 if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { 2309 $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; 2310 } 2311 if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { 2312 $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; 2313 } 2314 2315 // ----- Calculate the size of the central header 2316 $v_size = @ftell($this->zip_fd)-$v_offset; 2317 2318 // ----- Create the central dir footer 2319 if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) 2320 { 2321 // ----- Reset the file list 2322 unset($v_header_list); 2323 $this->privSwapBackMagicQuotes(); 2324 2325 // ----- Return 2326 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2327 return $v_result; 2328 } 2329 2330 // ----- Swap back the file descriptor 2331 $v_swap = $this->zip_fd; 2332 $this->zip_fd = $v_zip_temp_fd; 2333 $v_zip_temp_fd = $v_swap; 2334 2335 // ----- Close 2336 $this->privCloseFd(); 2337 2338 // ----- Close the temporary file 2339 @fclose($v_zip_temp_fd); 2340 2341 // ----- Magic quotes trick 2342 $this->privSwapBackMagicQuotes(); 2343 2344 // ----- Delete the zip file 2345 // TBC : I should test the result ... 2346 @unlink($this->zipname); 2347 2348 // ----- Rename the temporary file 2349 // TBC : I should test the result ... 2350 //@rename($v_zip_temp_name, $this->zipname); 2351 PclZipUtilRename($v_zip_temp_name, $this->zipname); 2352 2353 // ----- Return 2354 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2355 return $v_result; 2356 } 2357 // -------------------------------------------------------------------------------- 2358 2359 // -------------------------------------------------------------------------------- 2360 // Function : privOpenFd() 2361 // Description : 2362 // Parameters : 2363 // -------------------------------------------------------------------------------- 2364 function privOpenFd($p_mode) 2365 { 2366 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode); 2367 $v_result=1; 2368 2369 // ----- Look if already open 2370 if ($this->zip_fd != 0) 2371 { 2372 // ----- Error log 2373 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); 2374 2375 // ----- Return 2376 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2377 return PclZip::errorCode(); 2378 } 2379 2380 // ----- Open the zip file 2381 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode'); 2382 if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) 2383 { 2384 // ----- Error log 2385 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); 2386 2387 // ----- Return 2388 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2389 return PclZip::errorCode(); 2390 } 2391 2392 // ----- Return 2393 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2394 return $v_result; 2395 } 2396 // -------------------------------------------------------------------------------- 2397 2398 // -------------------------------------------------------------------------------- 2399 // Function : privCloseFd() 2400 // Description : 2401 // Parameters : 2402 // -------------------------------------------------------------------------------- 2403 function privCloseFd() 2404 { 2405 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", ""); 2406 $v_result=1; 2407 2408 if ($this->zip_fd != 0) 2409 @fclose($this->zip_fd); 2410 $this->zip_fd = 0; 2411 2412 // ----- Return 2413 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2414 return $v_result; 2415 } 2416 // -------------------------------------------------------------------------------- 2417 2418 // -------------------------------------------------------------------------------- 2419 // Function : privAddList() 2420 // Description : 2421 // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is 2422 // different from the real path of the file. This is usefull if you want to have PclTar 2423 // running in any directory, and memorize relative path from an other directory. 2424 // Parameters : 2425 // $p_list : An array containing the file or directory names to add in the tar 2426 // $p_result_list : list of added files with their properties (specially the status field) 2427 // $p_add_dir : Path to add in the filename path archived 2428 // $p_remove_dir : Path to remove in the filename path archived 2429 // Return Values : 2430 // -------------------------------------------------------------------------------- 2431 // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options) 2432 function privAddList($p_filedescr_list, &$p_result_list, &$p_options) 2433 { 2434 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list"); 2435 $v_result=1; 2436 2437 // ----- Add the files 2438 $v_header_list = array(); 2439 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) 2440 { 2441 // ----- Return 2442 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2443 return $v_result; 2444 } 2445 2446 // ----- Store the offset of the central dir 2447 $v_offset = @ftell($this->zip_fd); 2448 2449 // ----- Create the Central Dir files header 2450 for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) 2451 { 2452 // ----- Create the file header 2453 if ($v_header_list[$i]['status'] == 'ok') { 2454 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 2455 // ----- Return 2456 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2457 return $v_result; 2458 } 2459 $v_count++; 2460 } 2461 2462 // ----- Transform the header to a 'usable' info 2463 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 2464 } 2465 2466 // ----- Zip file comment 2467 $v_comment = ''; 2468 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 2469 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 2470 } 2471 2472 // ----- Calculate the size of the central header 2473 $v_size = @ftell($this->zip_fd)-$v_offset; 2474 2475 // ----- Create the central dir footer 2476 if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) 2477 { 2478 // ----- Reset the file list 2479 unset($v_header_list); 2480 2481 // ----- Return 2482 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2483 return $v_result; 2484 } 2485 2486 // ----- Return 2487 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2488 return $v_result; 2489 } 2490 // -------------------------------------------------------------------------------- 2491 2492 // -------------------------------------------------------------------------------- 2493 // Function : privAddFileList() 2494 // Description : 2495 // Parameters : 2496 // $p_filedescr_list : An array containing the file description 2497 // or directory names to add in the zip 2498 // $p_result_list : list of added files with their properties (specially the status field) 2499 // Return Values : 2500 // -------------------------------------------------------------------------------- 2501 function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) 2502 { 2503 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list"); 2504 $v_result=1; 2505 $v_header = array(); 2506 2507 // ----- Recuperate the current number of elt in list 2508 $v_nb = sizeof($p_result_list); 2509 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements"); 2510 2511 // ----- Loop on the files 2512 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { 2513 // ----- Format the filename 2514 $p_filedescr_list[$j]['filename'] 2515 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); 2516 2517 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'"); 2518 2519 // ----- Skip empty file names 2520 // TBC : Can this be possible ? not checked in DescrParseAtt ? 2521 if ($p_filedescr_list[$j]['filename'] == "") { 2522 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename"); 2523 continue; 2524 } 2525 2526 // ----- Check the filename 2527 if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') 2528 && (!file_exists($p_filedescr_list[$j]['filename']))) { 2529 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exists"); 2530 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists"); 2531 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2532 return PclZip::errorCode(); 2533 } 2534 2535 // ----- Look if it is a file or a dir with no all path remove option 2536 // or a dir with all its path removed 2537 // if ( (is_file($p_filedescr_list[$j]['filename'])) 2538 // || ( is_dir($p_filedescr_list[$j]['filename']) 2539 if ( ($p_filedescr_list[$j]['type'] == 'file') 2540 || ($p_filedescr_list[$j]['type'] == 'virtual_file') 2541 || ( ($p_filedescr_list[$j]['type'] == 'folder') 2542 && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) 2543 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) 2544 ) { 2545 2546 // ----- Add the file 2547 $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, 2548 $p_options); 2549 if ($v_result != 1) { 2550 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2551 return $v_result; 2552 } 2553 2554 // ----- Store the file infos 2555 $p_result_list[$v_nb++] = $v_header; 2556 } 2557 } 2558 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements"); 2559 2560 // ----- Return 2561 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2562 return $v_result; 2563 } 2564 // -------------------------------------------------------------------------------- 2565 2566 // -------------------------------------------------------------------------------- 2567 // Function : privAddFile() 2568 // Description : 2569 // Parameters : 2570 // Return Values : 2571 // -------------------------------------------------------------------------------- 2572 function privAddFile($p_filedescr, &$p_header, &$p_options) 2573 { 2574 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'"); 2575 $v_result=1; 2576 2577 // ----- Working variable 2578 $p_filename = $p_filedescr['filename']; 2579 2580 // TBC : Already done in the fileAtt check ... ? 2581 if ($p_filename == "") { 2582 // ----- Error log 2583 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); 2584 2585 // ----- Return 2586 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2587 return PclZip::errorCode(); 2588 } 2589 2590 // ----- Look for a stored different filename 2591 /* TBC : Removed 2592 if (isset($p_filedescr['stored_filename'])) { 2593 $v_stored_filename = $p_filedescr['stored_filename']; 2594 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"'); 2595 } 2596 else { 2597 $v_stored_filename = $p_filedescr['stored_filename']; 2598 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same'); 2599 } 2600 */ 2601 2602 // ----- Set the file properties 2603 clearstatcache(); 2604 $p_header['version'] = 20; 2605 $p_header['version_extracted'] = 10; 2606 $p_header['flag'] = 0; 2607 $p_header['compression'] = 0; 2608 $p_header['crc'] = 0; 2609 $p_header['compressed_size'] = 0; 2610 $p_header['filename_len'] = strlen($p_filename); 2611 $p_header['extra_len'] = 0; 2612 $p_header['disk'] = 0; 2613 $p_header['internal'] = 0; 2614 $p_header['offset'] = 0; 2615 $p_header['filename'] = $p_filename; 2616 // TBC : Removed $p_header['stored_filename'] = $v_stored_filename; 2617 $p_header['stored_filename'] = $p_filedescr['stored_filename']; 2618 $p_header['extra'] = ''; 2619 $p_header['status'] = 'ok'; 2620 $p_header['index'] = -1; 2621 2622 // ----- Look for regular file 2623 if ($p_filedescr['type']=='file') { 2624 $p_header['external'] = 0x00000000; 2625 $p_header['size'] = filesize($p_filename); 2626 } 2627 2628 // ----- Look for regular folder 2629 else if ($p_filedescr['type']=='folder') { 2630 $p_header['external'] = 0x00000010; 2631 $p_header['mtime'] = filemtime($p_filename); 2632 $p_header['size'] = filesize($p_filename); 2633 } 2634 2635 // ----- Look for virtual file 2636 else if ($p_filedescr['type'] == 'virtual_file') { 2637 $p_header['external'] = 0x00000000; 2638 $p_header['size'] = strlen($p_filedescr['content']); 2639 } 2640 2641 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'"); 2642 2643 // ----- Look for filetime 2644 if (isset($p_filedescr['mtime'])) { 2645 $p_header['mtime'] = $p_filedescr['mtime']; 2646 } 2647 else if ($p_filedescr['type'] == 'virtual_file') { 2648 $p_header['mtime'] = mktime(); 2649 } 2650 else { 2651 $p_header['mtime'] = filemtime($p_filename); 2652 } 2653 2654 // ------ Look for file comment 2655 if (isset($p_filedescr['comment'])) { 2656 $p_header['comment_len'] = strlen($p_filedescr['comment']); 2657 $p_header['comment'] = $p_filedescr['comment']; 2658 } 2659 else { 2660 $p_header['comment_len'] = 0; 2661 $p_header['comment'] = ''; 2662 } 2663 2664 // ----- Look for pre-add callback 2665 if (isset($p_options[PCLZIP_CB_PRE_ADD])) { 2666 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction"); 2667 2668 // ----- Generate a local information 2669 $v_local_header = array(); 2670 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 2671 2672 // ----- Call the callback 2673 // Here I do not use call_user_func() because I need to send a reference to the 2674 // header. 2675 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); 2676 if ($v_result == 0) { 2677 // ----- Change the file status 2678 $p_header['status'] = "skipped"; 2679 $v_result = 1; 2680 } 2681 2682 // ----- Update the informations 2683 // Only some fields can be modified 2684 if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { 2685 $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); 2686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'"); 2687 } 2688 } 2689 2690 // ----- Look for empty stored filename 2691 if ($p_header['stored_filename'] == "") { 2692 $p_header['status'] = "filtered"; 2693 } 2694 2695 // ----- Check the path length 2696 if (strlen($p_header['stored_filename']) > 0xFF) { 2697 $p_header['status'] = 'filename_too_long'; 2698 } 2699 2700 // ----- Look if no error, or file not skipped 2701 if ($p_header['status'] == 'ok') { 2702 2703 // ----- Look for a file 2704 // if (is_file($p_filename)) 2705 if ( ($p_filedescr['type'] == 'file') 2706 || ($p_filedescr['type'] == 'virtual_file')) { 2707 2708 // ----- Get content from real file 2709 if ($p_filedescr['type'] == 'file') { 2710 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); 2711 2712 // ----- Open the source file 2713 if (($v_file = @fopen($p_filename, "rb")) == 0) { 2714 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 2715 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2716 return PclZip::errorCode(); 2717 } 2718 2719 // ----- Read the file content 2720 $v_content = @fread($v_file, $p_header['size']); 2721 2722 // ----- Close the file 2723 @fclose($v_file); 2724 } 2725 else if ($p_filedescr['type'] == 'virtual_file') { 2726 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Add by string"); 2727 $v_content = $p_filedescr['content']; 2728 } 2729 2730 // ----- Calculate the CRC 2731 $p_header['crc'] = @crc32($v_content); 2732 2733 // ----- Look for no compression 2734 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 2735 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); 2736 // ----- Set header parameters 2737 $p_header['compressed_size'] = $p_header['size']; 2738 $p_header['compression'] = 0; 2739 } 2740 2741 // ----- Look for normal compression 2742 else { 2743 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); 2744 // ----- Compress the content 2745 $v_content = @gzdeflate($v_content); 2746 2747 // ----- Set header parameters 2748 $p_header['compressed_size'] = strlen($v_content); 2749 $p_header['compression'] = 8; 2750 } 2751 2752 // ----- Look for encryption 2753 /* 2754 if ((isset($p_options[PCLZIP_OPT_CRYPT])) 2755 && ($p_options[PCLZIP_OPT_CRYPT] != "")) { 2756 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); 2757 2758 // Should be a random header 2759 $v_header = 'xxxxxxxxxxxx'; 2760 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed, 2761 $p_header['compressed_size'], 2762 $v_header, 2763 $p_header['crc'], 2764 "test"); 2765 2766 $p_header['compressed_size'] += 12; 2767 $p_header['flag'] = 1; 2768 2769 // ----- Add the header to the data 2770 $v_content_compressed = $v_header.$v_content_compressed; 2771 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed).""); 2772 } 2773 */ 2774 2775 // ----- Call the header generation 2776 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 2777 @fclose($v_file); 2778 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2779 return $v_result; 2780 } 2781 2782 // ----- Write the compressed (or not) content 2783 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 2784 } 2785 2786 // ----- Look for a directory 2787 else if ($p_filedescr['type'] == 'folder') { 2788 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder"); 2789 // ----- Look for directory last '/' 2790 if (@substr($p_header['stored_filename'], -1) != '/') { 2791 $p_header['stored_filename'] .= '/'; 2792 } 2793 2794 // ----- Set the file properties 2795 $p_header['size'] = 0; 2796 //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked 2797 $p_header['external'] = 0x00000010; // Value for a folder : to be checked 2798 2799 // ----- Call the header generation 2800 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) 2801 { 2802 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2803 return $v_result; 2804 } 2805 } 2806 } 2807 2808 // ----- Look for post-add callback 2809 if (isset($p_options[PCLZIP_CB_POST_ADD])) { 2810 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction"); 2811 2812 // ----- Generate a local information 2813 $v_local_header = array(); 2814 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 2815 2816 // ----- Call the callback 2817 // Here I do not use call_user_func() because I need to send a reference to the 2818 // header. 2819 eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); 2820 if ($v_result == 0) { 2821 // ----- Ignored 2822 $v_result = 1; 2823 } 2824 2825 // ----- Update the informations 2826 // Nothing can be modified 2827 } 2828 2829 // ----- Return 2830 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2831 return $v_result; 2832 } 2833 // -------------------------------------------------------------------------------- 2834 2835 // -------------------------------------------------------------------------------- 2836 // Function : privCalculateStoredFilename() 2837 // Description : 2838 // Based on file descriptor properties and global options, this method 2839 // calculate the filename that will be stored in the archive. 2840 // Parameters : 2841 // Return Values : 2842 // -------------------------------------------------------------------------------- 2843 function privCalculateStoredFilename(&$p_filedescr, &$p_options) 2844 { 2845 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'"); 2846 $v_result=1; 2847 2848 // ----- Working variables 2849 $p_filename = $p_filedescr['filename']; 2850 if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { 2851 $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; 2852 } 2853 else { 2854 $p_add_dir = ''; 2855 } 2856 if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { 2857 $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; 2858 } 2859 else { 2860 $p_remove_dir = ''; 2861 } 2862 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Remove path ='".$p_remove_dir."'"); 2863 if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 2864 $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 2865 } 2866 else { 2867 $p_remove_all_dir = 0; 2868 } 2869 2870 // ----- Look for full name change 2871 if (isset($p_filedescr['new_full_name'])) { 2872 $v_stored_filename = $p_filedescr['new_full_name']; 2873 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'"); 2874 } 2875 2876 // ----- Look for path and/or short name change 2877 else { 2878 2879 // ----- Look for short name change 2880 if (isset($p_filedescr['new_short_name'])) { 2881 $v_path_info = pathinfo($p_filename); 2882 $v_dir = ''; 2883 if ($v_path_info['dirname'] != '') { 2884 $v_dir = $v_path_info['dirname'].'/'; 2885 } 2886 $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; 2887 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'"); 2888 } 2889 else { 2890 // ----- Calculate the stored filename 2891 $v_stored_filename = $p_filename; 2892 } 2893 2894 // ----- Look for all path to remove 2895 if ($p_remove_all_dir) { 2896 $v_stored_filename = basename($p_filename); 2897 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'"); 2898 } 2899 // ----- Look for partial path remove 2900 else if ($p_remove_dir != "") { 2901 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Partial path to remove"); 2902 if (substr($p_remove_dir, -1) != '/') 2903 $p_remove_dir .= "/"; 2904 2905 if ( (substr($p_filename, 0, 2) == "./") 2906 || (substr($p_remove_dir, 0, 2) == "./")) { 2907 2908 if ( (substr($p_filename, 0, 2) == "./") 2909 && (substr($p_remove_dir, 0, 2) != "./")) { 2910 $p_remove_dir = "./".$p_remove_dir; 2911 } 2912 if ( (substr($p_filename, 0, 2) != "./") 2913 && (substr($p_remove_dir, 0, 2) == "./")) { 2914 $p_remove_dir = substr($p_remove_dir, 2); 2915 } 2916 } 2917 2918 $v_compare = PclZipUtilPathInclusion($p_remove_dir, 2919 $v_stored_filename); 2920 if ($v_compare > 0) { 2921 if ($v_compare == 2) { 2922 $v_stored_filename = ""; 2923 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder"); 2924 } 2925 else { 2926 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'"); 2927 $v_stored_filename = substr($v_stored_filename, 2928 strlen($p_remove_dir)); 2929 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'"); 2930 } 2931 } 2932 } 2933 // ----- Look for path to add 2934 if ($p_add_dir != "") { 2935 if (substr($p_add_dir, -1) == "/") 2936 $v_stored_filename = $p_add_dir.$v_stored_filename; 2937 else 2938 $v_stored_filename = $p_add_dir."/".$v_stored_filename; 2939 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'"); 2940 } 2941 } 2942 2943 // ----- Filename (reduce the path of stored name) 2944 $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); 2945 $p_filedescr['stored_filename'] = $v_stored_filename; 2946 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename'])); 2947 2948 // ----- Return 2949 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2950 return $v_result; 2951 } 2952 // -------------------------------------------------------------------------------- 2953 2954 // -------------------------------------------------------------------------------- 2955 // Function : privWriteFileHeader() 2956 // Description : 2957 // Parameters : 2958 // Return Values : 2959 // -------------------------------------------------------------------------------- 2960 function privWriteFileHeader(&$p_header) 2961 { 2962 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); 2963 $v_result=1; 2964 2965 // ----- Store the offset position of the file 2966 $p_header['offset'] = ftell($this->zip_fd); 2967 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']); 2968 2969 // ----- Transform UNIX mtime to DOS format mdate/mtime 2970 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 2971 $v_date = getdate($p_header['mtime']); 2972 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 2973 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 2974 2975 // ----- Packed data 2976 $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, 2977 $p_header['version_extracted'], $p_header['flag'], 2978 $p_header['compression'], $v_mtime, $v_mdate, 2979 $p_header['crc'], $p_header['compressed_size'], 2980 $p_header['size'], 2981 strlen($p_header['stored_filename']), 2982 $p_header['extra_len']); 2983 2984 // ----- Write the first 148 bytes of the header in the archive 2985 fputs($this->zip_fd, $v_binary_data, 30); 2986 2987 // ----- Write the variable fields 2988 if (strlen($p_header['stored_filename']) != 0) 2989 { 2990 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); 2991 } 2992 if ($p_header['extra_len'] != 0) 2993 { 2994 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); 2995 } 2996 2997 // ----- Return 2998 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2999 return $v_result; 3000 } 3001 // -------------------------------------------------------------------------------- 3002 3003 // -------------------------------------------------------------------------------- 3004 // Function : privWriteCentralFileHeader() 3005 // Description : 3006 // Parameters : 3007 // Return Values : 3008 // -------------------------------------------------------------------------------- 3009 function privWriteCentralFileHeader(&$p_header) 3010 { 3011 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); 3012 $v_result=1; 3013 3014 // TBC 3015 //for(reset($p_header); $key = key($p_header); next($p_header)) { 3016 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]); 3017 //} 3018 3019 // ----- Transform UNIX mtime to DOS format mdate/mtime 3020 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 3021 $v_date = getdate($p_header['mtime']); 3022 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 3023 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 3024 3025 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$p_header['comment_len'].'\''); 3026 3027 // ----- Packed data 3028 $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, 3029 $p_header['version'], $p_header['version_extracted'], 3030 $p_header['flag'], $p_header['compression'], 3031 $v_mtime, $v_mdate, $p_header['crc'], 3032 $p_header['compressed_size'], $p_header['size'], 3033 strlen($p_header['stored_filename']), 3034 $p_header['extra_len'], $p_header['comment_len'], 3035 $p_header['disk'], $p_header['internal'], 3036 $p_header['external'], $p_header['offset']); 3037 3038 // ----- Write the 42 bytes of the header in the zip file 3039 fputs($this->zip_fd, $v_binary_data, 46); 3040 3041 // ----- Write the variable fields 3042 if (strlen($p_header['stored_filename']) != 0) 3043 { 3044 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); 3045 } 3046 if ($p_header['extra_len'] != 0) 3047 { 3048 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); 3049 } 3050 if ($p_header['comment_len'] != 0) 3051 { 3052 fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); 3053 } 3054 3055 // ----- Return 3056 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3057 return $v_result; 3058 } 3059 // -------------------------------------------------------------------------------- 3060 3061 // -------------------------------------------------------------------------------- 3062 // Function : privWriteCentralHeader() 3063 // Description : 3064 // Parameters : 3065 // Return Values : 3066 // -------------------------------------------------------------------------------- 3067 function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) 3068 { 3069 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"'); 3070 $v_result=1; 3071 3072 // ----- Packed data 3073 $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, 3074 $p_nb_entries, $p_size, 3075 $p_offset, strlen($p_comment)); 3076 3077 // ----- Write the 22 bytes of the header in the zip file 3078 fputs($this->zip_fd, $v_binary_data, 22); 3079 3080 // ----- Write the variable fields 3081 if (strlen($p_comment) != 0) 3082 { 3083 fputs($this->zip_fd, $p_comment, strlen($p_comment)); 3084 } 3085 3086 // ----- Return 3087 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3088 return $v_result; 3089 } 3090 // -------------------------------------------------------------------------------- 3091 3092 // -------------------------------------------------------------------------------- 3093 // Function : privList() 3094 // Description : 3095 // Parameters : 3096 // Return Values : 3097 // -------------------------------------------------------------------------------- 3098 function privList(&$p_list) 3099 { 3100 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list"); 3101 $v_result=1; 3102 3103 // ----- Magic quotes trick 3104 $this->privDisableMagicQuotes(); 3105 3106 // ----- Open the zip file 3107 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 620 return(0); 621 } 622 623 $v_prop = array(); 624 $v_prop['comment'] = ''; 625 $v_prop['nb'] = 0; 626 $v_prop['status'] = 'not_exist'; 627 628 if (@is_file($this->zipname)) 629 { 3108 630 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) 3109 631 { 3110 // ----- Magic quotes trick3111 632 $this->privSwapBackMagicQuotes(); 3112 633 3113 // ----- Error log3114 634 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); 3115 635 3116 // ----- Return 3117 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3118 return PclZip::errorCode(); 3119 } 3120 3121 // ----- Read the central directory informations 636 return 0; 637 } 638 3122 639 $v_central_dir = array(); 3123 640 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 3124 641 { 3125 642 $this->privSwapBackMagicQuotes(); 3126 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3127 return $v_result; 3128 } 3129 3130 // ----- Go to beginning of Central Dir 3131 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'"); 3132 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3133 @rewind($this->zip_fd); 3134 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3135 if (@fseek($this->zip_fd, $v_central_dir['offset'])) 643 return 0; 644 } 645 646 $this->privCloseFd(); 647 648 $v_prop['comment'] = $v_central_dir['comment']; 649 $v_prop['nb'] = $v_central_dir['entries']; 650 $v_prop['status'] = 'ok'; 651 } 652 653 $this->privSwapBackMagicQuotes(); 654 655 return $v_prop; 656 } 657 658 function duplicate($p_archive) 659 { 660 $v_result = 1; 661 662 $this->privErrorReset(); 663 664 if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) 665 { 666 667 $v_result = $this->privDuplicate($p_archive->zipname); 668 } 669 670 else if (is_string($p_archive)) 671 { 672 673 if (!is_file($p_archive)) { 674 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); 675 $v_result = PCLZIP_ERR_MISSING_FILE; 676 } 677 else { 678 $v_result = $this->privDuplicate($p_archive); 679 } 680 } 681 682 else 683 { 684 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); 685 $v_result = PCLZIP_ERR_INVALID_PARAMETER; 686 } 687 688 return $v_result; 689 } 690 691 function merge($p_archive_to_add) 692 { 693 $v_result = 1; 694 695 $this->privErrorReset(); 696 697 if (!$this->privCheckFormat()) { 698 return(0); 699 } 700 701 if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) 702 { 703 704 $v_result = $this->privMerge($p_archive_to_add); 705 } 706 707 else if (is_string($p_archive_to_add)) 708 { 709 710 $v_object_archive = new PclZip($p_archive_to_add); 711 712 $v_result = $this->privMerge($v_object_archive); 713 } 714 715 else 716 { 717 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); 718 $v_result = PCLZIP_ERR_INVALID_PARAMETER; 719 } 720 721 return $v_result; 722 } 723 724 725 726 function errorCode() 727 { 728 if (PCLZIP_ERROR_EXTERNAL == 1) { 729 return(PclErrorCode()); 730 } 731 else { 732 return($this->error_code); 733 } 734 } 735 736 function errorName($p_with_code=false) 737 { 738 $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', 739 PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', 740 PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', 741 PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', 742 PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', 743 PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', 744 PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', 745 PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', 746 PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', 747 PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', 748 PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', 749 PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', 750 PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', 751 PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', 752 PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', 753 PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', 754 PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', 755 PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', 756 PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' 757 ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' 758 ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' 759 ); 760 761 if (isset($v_name[$this->error_code])) { 762 $v_value = $v_name[$this->error_code]; 763 } 764 else { 765 $v_value = 'NoName'; 766 } 767 768 if ($p_with_code) { 769 return($v_value.' ('.$this->error_code.')'); 770 } 771 else { 772 return($v_value); 773 } 774 } 775 776 function errorInfo($p_full=false) 777 { 778 if (PCLZIP_ERROR_EXTERNAL == 1) { 779 return(PclErrorString()); 780 } 781 else { 782 if ($p_full) { 783 return($this->errorName(true)." : ".$this->error_string); 784 } 785 else { 786 return($this->error_string." [code ".$this->error_code."]"); 787 } 788 } 789 } 790 791 792 793 794 795 function privCheckFormat($p_level=0) 796 { 797 $v_result = true; 798 799 clearstatcache(); 800 801 $this->privErrorReset(); 802 803 if (!is_file($this->zipname)) { 804 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); 805 return(false); 806 } 807 808 if (!is_readable($this->zipname)) { 809 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); 810 return(false); 811 } 812 813 814 815 816 return $v_result; 817 } 818 819 function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) 820 { 821 $v_result=1; 822 823 $i=0; 824 while ($i<$p_size) { 825 826 if (!isset($v_requested_options[$p_options_list[$i]])) { 827 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); 828 829 return PclZip::errorCode(); 830 } 831 832 switch ($p_options_list[$i]) { 833 case PCLZIP_OPT_PATH : 834 case PCLZIP_OPT_REMOVE_PATH : 835 case PCLZIP_OPT_ADD_PATH : 836 if (($i+1) >= $p_size) { 837 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 838 839 return PclZip::errorCode(); 840 } 841 842 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 843 $i++; 844 break; 845 846 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : 847 if (($i+1) >= $p_size) { 848 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 849 850 return PclZip::errorCode(); 851 } 852 853 if ( is_string($p_options_list[$i+1]) 854 && ($p_options_list[$i+1] != '')) { 855 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 856 $i++; 857 } 858 else { 859 } 860 break; 861 862 case PCLZIP_OPT_BY_NAME : 863 if (($i+1) >= $p_size) { 864 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 865 866 return PclZip::errorCode(); 867 } 868 869 if (is_string($p_options_list[$i+1])) { 870 $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; 871 } 872 else if (is_array($p_options_list[$i+1])) { 873 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 874 } 875 else { 876 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 877 878 return PclZip::errorCode(); 879 } 880 $i++; 881 break; 882 883 case PCLZIP_OPT_BY_EREG : 884 case PCLZIP_OPT_BY_PREG : 885 if (($i+1) >= $p_size) { 886 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 887 888 return PclZip::errorCode(); 889 } 890 891 if (is_string($p_options_list[$i+1])) { 892 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 893 } 894 else { 895 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 896 897 return PclZip::errorCode(); 898 } 899 $i++; 900 break; 901 902 case PCLZIP_OPT_COMMENT : 903 case PCLZIP_OPT_ADD_COMMENT : 904 case PCLZIP_OPT_PREPEND_COMMENT : 905 if (($i+1) >= $p_size) { 906 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, 907 "Missing parameter value for option '" 908 .PclZipUtilOptionText($p_options_list[$i]) 909 ."'"); 910 911 return PclZip::errorCode(); 912 } 913 914 if (is_string($p_options_list[$i+1])) { 915 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 916 } 917 else { 918 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 919 "Wrong parameter value for option '" 920 .PclZipUtilOptionText($p_options_list[$i]) 921 ."'"); 922 923 return PclZip::errorCode(); 924 } 925 $i++; 926 break; 927 928 case PCLZIP_OPT_BY_INDEX : 929 if (($i+1) >= $p_size) { 930 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 931 932 return PclZip::errorCode(); 933 } 934 935 $v_work_list = array(); 936 if (is_string($p_options_list[$i+1])) { 937 938 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); 939 940 $v_work_list = explode(",", $p_options_list[$i+1]); 941 } 942 else if (is_integer($p_options_list[$i+1])) { 943 $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; 944 } 945 else if (is_array($p_options_list[$i+1])) { 946 $v_work_list = $p_options_list[$i+1]; 947 } 948 else { 949 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 950 951 return PclZip::errorCode(); 952 } 953 954 $v_sort_flag=false; 955 $v_sort_value=0; 956 for ($j=0; $j<sizeof($v_work_list); $j++) { 957 $v_item_list = explode("-", $v_work_list[$j]); 958 $v_size_item_list = sizeof($v_item_list); 959 960 961 if ($v_size_item_list == 1) { 962 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; 963 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; 964 } 965 elseif ($v_size_item_list == 2) { 966 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; 967 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; 968 } 969 else { 970 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 971 972 return PclZip::errorCode(); 973 } 974 975 976 if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { 977 $v_sort_flag=true; 978 979 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 980 981 return PclZip::errorCode(); 982 } 983 $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; 984 } 985 986 if ($v_sort_flag) { 987 } 988 989 $i++; 990 break; 991 992 case PCLZIP_OPT_REMOVE_ALL_PATH : 993 case PCLZIP_OPT_EXTRACT_AS_STRING : 994 case PCLZIP_OPT_NO_COMPRESSION : 995 case PCLZIP_OPT_EXTRACT_IN_OUTPUT : 996 case PCLZIP_OPT_REPLACE_NEWER : 997 case PCLZIP_OPT_STOP_ON_ERROR : 998 $v_result_list[$p_options_list[$i]] = true; 999 break; 1000 1001 case PCLZIP_OPT_SET_CHMOD : 1002 if (($i+1) >= $p_size) { 1003 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1004 1005 return PclZip::errorCode(); 1006 } 1007 1008 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1009 $i++; 1010 break; 1011 1012 case PCLZIP_CB_PRE_EXTRACT : 1013 case PCLZIP_CB_POST_EXTRACT : 1014 case PCLZIP_CB_PRE_ADD : 1015 case PCLZIP_CB_POST_ADD : 1016 1017 if (($i+1) >= $p_size) { 1018 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1019 1020 return PclZip::errorCode(); 1021 } 1022 1023 $v_function_name = $p_options_list[$i+1]; 1024 1025 if (!function_exists($v_function_name)) { 1026 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1027 1028 return PclZip::errorCode(); 1029 } 1030 1031 $v_result_list[$p_options_list[$i]] = $v_function_name; 1032 $i++; 1033 break; 1034 1035 default : 1036 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 1037 "Unknown parameter '" 1038 .$p_options_list[$i]."'"); 1039 1040 return PclZip::errorCode(); 1041 } 1042 1043 $i++; 1044 } 1045 1046 if ($v_requested_options !== false) { 1047 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 1048 if ($v_requested_options[$key] == 'mandatory') { 1049 if (!isset($v_result_list[$key])) { 1050 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 1051 1052 return PclZip::errorCode(); 1053 } 1054 } 1055 } 1056 } 1057 1058 return $v_result; 1059 } 1060 1061 function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) 1062 { 1063 $v_result=1; 1064 1065 foreach ($p_file_list as $v_key => $v_value) { 1066 1067 if (!isset($v_requested_options[$v_key])) { 1068 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); 1069 1070 return PclZip::errorCode(); 1071 } 1072 1073 switch ($v_key) { 1074 case PCLZIP_ATT_FILE_NAME : 1075 if (!is_string($v_value)) { 1076 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1077 return PclZip::errorCode(); 1078 } 1079 1080 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); 1081 1082 if ($p_filedescr['filename'] == '') { 1083 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1084 return PclZip::errorCode(); 1085 } 1086 1087 break; 1088 1089 case PCLZIP_ATT_FILE_NEW_SHORT_NAME : 1090 if (!is_string($v_value)) { 1091 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1092 return PclZip::errorCode(); 1093 } 1094 1095 $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); 1096 1097 if ($p_filedescr['new_short_name'] == '') { 1098 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1099 return PclZip::errorCode(); 1100 } 1101 break; 1102 1103 case PCLZIP_ATT_FILE_NEW_FULL_NAME : 1104 if (!is_string($v_value)) { 1105 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1106 return PclZip::errorCode(); 1107 } 1108 1109 $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); 1110 1111 if ($p_filedescr['new_full_name'] == '') { 1112 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1113 return PclZip::errorCode(); 1114 } 1115 break; 1116 1117 case PCLZIP_ATT_FILE_COMMENT : 1118 if (!is_string($v_value)) { 1119 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1120 return PclZip::errorCode(); 1121 } 1122 1123 $p_filedescr['comment'] = $v_value; 1124 break; 1125 1126 case PCLZIP_ATT_FILE_MTIME : 1127 if (!is_integer($v_value)) { 1128 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1129 return PclZip::errorCode(); 1130 } 1131 1132 $p_filedescr['mtime'] = $v_value; 1133 break; 1134 1135 case PCLZIP_ATT_FILE_CONTENT : 1136 $p_filedescr['content'] = $v_value; 1137 break; 1138 1139 default : 1140 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 1141 "Unknown parameter '".$v_key."'"); 1142 1143 return PclZip::errorCode(); 1144 } 1145 1146 if ($v_requested_options !== false) { 1147 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 1148 if ($v_requested_options[$key] == 'mandatory') { 1149 if (!isset($p_file_list[$key])) { 1150 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 1151 return PclZip::errorCode(); 1152 } 1153 } 1154 } 1155 } 1156 1157 } 1158 1159 return $v_result; 1160 } 1161 1162 function privFileDescrExpand(&$p_filedescr_list, &$p_options) 1163 { 1164 $v_result=1; 1165 1166 $v_result_list = array(); 1167 1168 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { 1169 1170 $v_descr = $p_filedescr_list[$i]; 1171 1172 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']); 1173 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); 1174 1175 if (file_exists($v_descr['filename'])) { 1176 if (@is_file($v_descr['filename'])) { 1177 $v_descr['type'] = 'file'; 1178 } 1179 else if (@is_dir($v_descr['filename'])) { 1180 $v_descr['type'] = 'folder'; 1181 } 1182 else if (@is_link($v_descr['filename'])) { 1183 continue; 1184 } 1185 else { 1186 continue; 1187 } 1188 } 1189 1190 else if (isset($v_descr['content'])) { 1191 $v_descr['type'] = 'virtual_file'; 1192 } 1193 1194 else { 1195 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists"); 1196 1197 return PclZip::errorCode(); 1198 } 1199 1200 $this->privCalculateStoredFilename($v_descr, $p_options); 1201 1202 $v_result_list[sizeof($v_result_list)] = $v_descr; 1203 1204 if ($v_descr['type'] == 'folder') { 1205 $v_dirlist_descr = array(); 1206 $v_dirlist_nb = 0; 1207 if ($v_folder_handler = @opendir($v_descr['filename'])) { 1208 while (($v_item_handler = @readdir($v_folder_handler)) !== false) { 1209 1210 if (($v_item_handler == '.') || ($v_item_handler == '..')) { 1211 continue; 1212 } 1213 1214 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; 1215 1216 if ($v_descr['stored_filename'] != $v_descr['filename']) { 1217 if ($v_descr['stored_filename'] != '') { 1218 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; 1219 } 1220 else { 1221 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; 1222 } 1223 } 1224 1225 $v_dirlist_nb++; 1226 } 1227 1228 @closedir($v_folder_handler); 1229 } 1230 else { 1231 } 1232 1233 if ($v_dirlist_nb != 0) { 1234 if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { 1235 return $v_result; 1236 } 1237 1238 $v_result_list = array_merge($v_result_list, $v_dirlist_descr); 1239 } 1240 else { 1241 } 1242 1243 unset($v_dirlist_descr); 1244 } 1245 } 1246 1247 $p_filedescr_list = $v_result_list; 1248 1249 return $v_result; 1250 } 1251 1252 function privCreate($p_filedescr_list, &$p_result_list, &$p_options) 1253 { 1254 $v_result=1; 1255 $v_list_detail = array(); 1256 1257 $this->privDisableMagicQuotes(); 1258 1259 if (($v_result = $this->privOpenFd('wb')) != 1) 1260 { 1261 return $v_result; 1262 } 1263 1264 $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); 1265 1266 $this->privCloseFd(); 1267 1268 $this->privSwapBackMagicQuotes(); 1269 1270 return $v_result; 1271 } 1272 1273 function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 1274 { 1275 $v_result=1; 1276 $v_list_detail = array(); 1277 1278 if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) 1279 { 1280 1281 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); 1282 1283 return $v_result; 1284 } 1285 $this->privDisableMagicQuotes(); 1286 1287 if (($v_result=$this->privOpenFd('rb')) != 1) 1288 { 1289 $this->privSwapBackMagicQuotes(); 1290 1291 return $v_result; 1292 } 1293 1294 $v_central_dir = array(); 1295 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 1296 { 1297 $this->privCloseFd(); 1298 $this->privSwapBackMagicQuotes(); 1299 return $v_result; 1300 } 1301 1302 @rewind($this->zip_fd); 1303 1304 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 1305 1306 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) 1307 { 1308 $this->privCloseFd(); 1309 $this->privSwapBackMagicQuotes(); 1310 1311 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); 1312 1313 return PclZip::errorCode(); 1314 } 1315 1316 $v_size = $v_central_dir['offset']; 1317 while ($v_size != 0) 1318 { 1319 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 1320 $v_buffer = fread($this->zip_fd, $v_read_size); 1321 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 1322 $v_size -= $v_read_size; 1323 } 1324 1325 $v_swap = $this->zip_fd; 1326 $this->zip_fd = $v_zip_temp_fd; 1327 $v_zip_temp_fd = $v_swap; 1328 1329 $v_header_list = array(); 1330 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) 1331 { 1332 fclose($v_zip_temp_fd); 1333 $this->privCloseFd(); 1334 @unlink($v_zip_temp_name); 1335 $this->privSwapBackMagicQuotes(); 1336 1337 return $v_result; 1338 } 1339 1340 $v_offset = @ftell($this->zip_fd); 1341 1342 $v_size = $v_central_dir['size']; 1343 while ($v_size != 0) 1344 { 1345 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 1346 $v_buffer = @fread($v_zip_temp_fd, $v_read_size); 1347 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 1348 $v_size -= $v_read_size; 1349 } 1350 1351 for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) 1352 { 1353 if ($v_header_list[$i]['status'] == 'ok') { 1354 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 1355 fclose($v_zip_temp_fd); 1356 $this->privCloseFd(); 1357 @unlink($v_zip_temp_name); 1358 $this->privSwapBackMagicQuotes(); 1359 1360 return $v_result; 1361 } 1362 $v_count++; 1363 } 1364 1365 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 1366 } 1367 1368 $v_comment = $v_central_dir['comment']; 1369 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 1370 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 1371 } 1372 if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { 1373 $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; 1374 } 1375 if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { 1376 $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; 1377 } 1378 1379 $v_size = @ftell($this->zip_fd)-$v_offset; 1380 1381 if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) 1382 { 1383 unset($v_header_list); 1384 $this->privSwapBackMagicQuotes(); 1385 1386 return $v_result; 1387 } 1388 1389 $v_swap = $this->zip_fd; 1390 $this->zip_fd = $v_zip_temp_fd; 1391 $v_zip_temp_fd = $v_swap; 1392 1393 $this->privCloseFd(); 1394 1395 @fclose($v_zip_temp_fd); 1396 1397 $this->privSwapBackMagicQuotes(); 1398 1399 @unlink($this->zipname); 1400 1401 PclZipUtilRename($v_zip_temp_name, $this->zipname); 1402 1403 return $v_result; 1404 } 1405 1406 function privOpenFd($p_mode) 1407 { 1408 $v_result=1; 1409 1410 if ($this->zip_fd != 0) 1411 { 1412 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); 1413 1414 return PclZip::errorCode(); 1415 } 1416 1417 if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) 1418 { 1419 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); 1420 1421 return PclZip::errorCode(); 1422 } 1423 1424 return $v_result; 1425 } 1426 1427 function privCloseFd() 1428 { 1429 $v_result=1; 1430 1431 if ($this->zip_fd != 0) 1432 @fclose($this->zip_fd); 1433 $this->zip_fd = 0; 1434 1435 return $v_result; 1436 } 1437 1438 function privAddList($p_filedescr_list, &$p_result_list, &$p_options) 1439 { 1440 $v_result=1; 1441 1442 $v_header_list = array(); 1443 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) 1444 { 1445 return $v_result; 1446 } 1447 1448 $v_offset = @ftell($this->zip_fd); 1449 1450 for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) 1451 { 1452 if ($v_header_list[$i]['status'] == 'ok') { 1453 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 1454 return $v_result; 1455 } 1456 $v_count++; 1457 } 1458 1459 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 1460 } 1461 1462 $v_comment = ''; 1463 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 1464 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 1465 } 1466 1467 $v_size = @ftell($this->zip_fd)-$v_offset; 1468 1469 if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) 1470 { 1471 unset($v_header_list); 1472 1473 return $v_result; 1474 } 1475 1476 return $v_result; 1477 } 1478 1479 function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) 1480 { 1481 $v_result=1; 1482 $v_header = array(); 1483 1484 $v_nb = sizeof($p_result_list); 1485 1486 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { 1487 $p_filedescr_list[$j]['filename'] 1488 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); 1489 1490 1491 if ($p_filedescr_list[$j]['filename'] == "") { 1492 continue; 1493 } 1494 1495 if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') 1496 && (!file_exists($p_filedescr_list[$j]['filename']))) { 1497 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists"); 1498 return PclZip::errorCode(); 1499 } 1500 1501 if ( ($p_filedescr_list[$j]['type'] == 'file') 1502 || ($p_filedescr_list[$j]['type'] == 'virtual_file') 1503 || ( ($p_filedescr_list[$j]['type'] == 'folder') 1504 && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) 1505 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) 1506 ) { 1507 1508 $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, 1509 $p_options); 1510 if ($v_result != 1) { 1511 return $v_result; 1512 } 1513 1514 $p_result_list[$v_nb++] = $v_header; 1515 } 1516 } 1517 1518 return $v_result; 1519 } 1520 1521 function privAddFile($p_filedescr, &$p_header, &$p_options) 1522 { 1523 $v_result=1; 1524 1525 $p_filename = $p_filedescr['filename']; 1526 1527 if ($p_filename == "") { 1528 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); 1529 1530 return PclZip::errorCode(); 1531 } 1532 1533 1534 1535 clearstatcache(); 1536 $p_header['version'] = 20; 1537 $p_header['version_extracted'] = 10; 1538 $p_header['flag'] = 0; 1539 $p_header['compression'] = 0; 1540 $p_header['crc'] = 0; 1541 $p_header['compressed_size'] = 0; 1542 $p_header['filename_len'] = strlen($p_filename); 1543 $p_header['extra_len'] = 0; 1544 $p_header['disk'] = 0; 1545 $p_header['internal'] = 0; 1546 $p_header['offset'] = 0; 1547 $p_header['filename'] = $p_filename; 1548 $p_header['stored_filename'] = $p_filedescr['stored_filename']; 1549 $p_header['extra'] = ''; 1550 $p_header['status'] = 'ok'; 1551 $p_header['index'] = -1; 1552 1553 if ($p_filedescr['type']=='file') { 1554 $p_header['external'] = 0x00000000; 1555 $p_header['size'] = filesize($p_filename); 1556 } 1557 1558 else if ($p_filedescr['type']=='folder') { 1559 $p_header['external'] = 0x00000010; 1560 $p_header['mtime'] = filemtime($p_filename); 1561 $p_header['size'] = filesize($p_filename); 1562 } 1563 1564 else if ($p_filedescr['type'] == 'virtual_file') { 1565 $p_header['external'] = 0x00000000; 1566 $p_header['size'] = strlen($p_filedescr['content']); 1567 } 1568 1569 1570 if (isset($p_filedescr['mtime'])) { 1571 $p_header['mtime'] = $p_filedescr['mtime']; 1572 } 1573 else if ($p_filedescr['type'] == 'virtual_file') { 1574 $p_header['mtime'] = mktime(); 1575 } 1576 else { 1577 $p_header['mtime'] = filemtime($p_filename); 1578 } 1579 1580 if (isset($p_filedescr['comment'])) { 1581 $p_header['comment_len'] = strlen($p_filedescr['comment']); 1582 $p_header['comment'] = $p_filedescr['comment']; 1583 } 1584 else { 1585 $p_header['comment_len'] = 0; 1586 $p_header['comment'] = ''; 1587 } 1588 1589 if (isset($p_options[PCLZIP_CB_PRE_ADD])) { 1590 1591 $v_local_header = array(); 1592 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 1593 1594 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); 1595 if ($v_result == 0) { 1596 $p_header['status'] = "skipped"; 1597 $v_result = 1; 1598 } 1599 1600 if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { 1601 $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); 1602 } 1603 } 1604 1605 if ($p_header['stored_filename'] == "") { 1606 $p_header['status'] = "filtered"; 1607 } 1608 1609 if (strlen($p_header['stored_filename']) > 0xFF) { 1610 $p_header['status'] = 'filename_too_long'; 1611 } 1612 1613 if ($p_header['status'] == 'ok') { 1614 1615 if ( ($p_filedescr['type'] == 'file') 1616 || ($p_filedescr['type'] == 'virtual_file')) { 1617 1618 if ($p_filedescr['type'] == 'file') { 1619 1620 if (($v_file = @fopen($p_filename, "rb")) == 0) { 1621 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 1622 return PclZip::errorCode(); 1623 } 1624 1625 $v_content = @fread($v_file, $p_header['size']); 1626 1627 @fclose($v_file); 1628 } 1629 else if ($p_filedescr['type'] == 'virtual_file') { 1630 $v_content = $p_filedescr['content']; 1631 } 1632 1633 $p_header['crc'] = @crc32($v_content); 1634 1635 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 1636 $p_header['compressed_size'] = $p_header['size']; 1637 $p_header['compression'] = 0; 1638 } 1639 1640 else { 1641 $v_content = @gzdeflate($v_content); 1642 1643 $p_header['compressed_size'] = strlen($v_content); 1644 $p_header['compression'] = 8; 1645 } 1646 1647 1648 1649 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 1650 @fclose($v_file); 1651 return $v_result; 1652 } 1653 1654 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 1655 } 1656 1657 else if ($p_filedescr['type'] == 'folder') { 1658 if (@substr($p_header['stored_filename'], -1) != '/') { 1659 $p_header['stored_filename'] .= '/'; 1660 } 1661 1662 $p_header['size'] = 0; 1663 $p_header['external'] = 0x00000010; 1664 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) 1665 { 1666 return $v_result; 1667 } 1668 } 1669 } 1670 1671 if (isset($p_options[PCLZIP_CB_POST_ADD])) { 1672 1673 $v_local_header = array(); 1674 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 1675 1676 eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); 1677 if ($v_result == 0) { 1678 $v_result = 1; 1679 } 1680 1681 } 1682 1683 return $v_result; 1684 } 1685 1686 function privCalculateStoredFilename(&$p_filedescr, &$p_options) 1687 { 1688 $v_result=1; 1689 1690 $p_filename = $p_filedescr['filename']; 1691 if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { 1692 $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; 1693 } 1694 else { 1695 $p_add_dir = ''; 1696 } 1697 if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { 1698 $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; 1699 } 1700 else { 1701 $p_remove_dir = ''; 1702 } 1703 if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 1704 $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 1705 } 1706 else { 1707 $p_remove_all_dir = 0; 1708 } 1709 1710 if (isset($p_filedescr['new_full_name'])) { 1711 $v_stored_filename = $p_filedescr['new_full_name']; 1712 } 1713 1714 else { 1715 1716 if (isset($p_filedescr['new_short_name'])) { 1717 $v_path_info = pathinfo($p_filename); 1718 $v_dir = ''; 1719 if ($v_path_info['dirname'] != '') { 1720 $v_dir = $v_path_info['dirname'].'/'; 1721 } 1722 $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; 1723 } 1724 else { 1725 $v_stored_filename = $p_filename; 1726 } 1727 1728 if ($p_remove_all_dir) { 1729 $v_stored_filename = basename($p_filename); 1730 } 1731 else if ($p_remove_dir != "") { 1732 if (substr($p_remove_dir, -1) != '/') 1733 $p_remove_dir .= "/"; 1734 1735 if ( (substr($p_filename, 0, 2) == "./") 1736 || (substr($p_remove_dir, 0, 2) == "./")) { 1737 1738 if ( (substr($p_filename, 0, 2) == "./") 1739 && (substr($p_remove_dir, 0, 2) != "./")) { 1740 $p_remove_dir = "./".$p_remove_dir; 1741 } 1742 if ( (substr($p_filename, 0, 2) != "./") 1743 && (substr($p_remove_dir, 0, 2) == "./")) { 1744 $p_remove_dir = substr($p_remove_dir, 2); 1745 } 1746 } 1747 1748 $v_compare = PclZipUtilPathInclusion($p_remove_dir, 1749 $v_stored_filename); 1750 if ($v_compare > 0) { 1751 if ($v_compare == 2) { 1752 $v_stored_filename = ""; 1753 } 1754 else { 1755 $v_stored_filename = substr($v_stored_filename, 1756 strlen($p_remove_dir)); 1757 } 1758 } 1759 } 1760 if ($p_add_dir != "") { 1761 if (substr($p_add_dir, -1) == "/") 1762 $v_stored_filename = $p_add_dir.$v_stored_filename; 1763 else 1764 $v_stored_filename = $p_add_dir."/".$v_stored_filename; 1765 } 1766 } 1767 1768 $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); 1769 $p_filedescr['stored_filename'] = $v_stored_filename; 1770 1771 return $v_result; 1772 } 1773 1774 function privWriteFileHeader(&$p_header) 1775 { 1776 $v_result=1; 1777 1778 $p_header['offset'] = ftell($this->zip_fd); 1779 1780 $v_date = getdate($p_header['mtime']); 1781 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 1782 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 1783 1784 $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, 1785 $p_header['version_extracted'], $p_header['flag'], 1786 $p_header['compression'], $v_mtime, $v_mdate, 1787 $p_header['crc'], $p_header['compressed_size'], 1788 $p_header['size'], 1789 strlen($p_header['stored_filename']), 1790 $p_header['extra_len']); 1791 1792 fputs($this->zip_fd, $v_binary_data, 30); 1793 1794 if (strlen($p_header['stored_filename']) != 0) 1795 { 1796 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); 1797 } 1798 if ($p_header['extra_len'] != 0) 1799 { 1800 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); 1801 } 1802 1803 return $v_result; 1804 } 1805 1806 function privWriteCentralFileHeader(&$p_header) 1807 { 1808 $v_result=1; 1809 1810 1811 $v_date = getdate($p_header['mtime']); 1812 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 1813 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 1814 1815 1816 $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, 1817 $p_header['version'], $p_header['version_extracted'], 1818 $p_header['flag'], $p_header['compression'], 1819 $v_mtime, $v_mdate, $p_header['crc'], 1820 $p_header['compressed_size'], $p_header['size'], 1821 strlen($p_header['stored_filename']), 1822 $p_header['extra_len'], $p_header['comment_len'], 1823 $p_header['disk'], $p_header['internal'], 1824 $p_header['external'], $p_header['offset']); 1825 1826 fputs($this->zip_fd, $v_binary_data, 46); 1827 1828 if (strlen($p_header['stored_filename']) != 0) 1829 { 1830 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); 1831 } 1832 if ($p_header['extra_len'] != 0) 1833 { 1834 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); 1835 } 1836 if ($p_header['comment_len'] != 0) 1837 { 1838 fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); 1839 } 1840 1841 return $v_result; 1842 } 1843 1844 function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) 1845 { 1846 $v_result=1; 1847 1848 $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, 1849 $p_nb_entries, $p_size, 1850 $p_offset, strlen($p_comment)); 1851 1852 fputs($this->zip_fd, $v_binary_data, 22); 1853 1854 if (strlen($p_comment) != 0) 1855 { 1856 fputs($this->zip_fd, $p_comment, strlen($p_comment)); 1857 } 1858 1859 return $v_result; 1860 } 1861 1862 function privList(&$p_list) 1863 { 1864 $v_result=1; 1865 1866 $this->privDisableMagicQuotes(); 1867 1868 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) 1869 { 1870 $this->privSwapBackMagicQuotes(); 1871 1872 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); 1873 1874 return PclZip::errorCode(); 1875 } 1876 1877 $v_central_dir = array(); 1878 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 1879 { 1880 $this->privSwapBackMagicQuotes(); 1881 return $v_result; 1882 } 1883 1884 @rewind($this->zip_fd); 1885 if (@fseek($this->zip_fd, $v_central_dir['offset'])) 1886 { 1887 $this->privSwapBackMagicQuotes(); 1888 1889 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 1890 1891 return PclZip::errorCode(); 1892 } 1893 1894 for ($i=0; $i<$v_central_dir['entries']; $i++) 1895 { 1896 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) 3136 1897 { 3137 1898 $this->privSwapBackMagicQuotes(); 3138 3139 // ----- Error log 3140 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3141 3142 // ----- Return 3143 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3144 return PclZip::errorCode(); 3145 } 3146 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3147 3148 // ----- Read each entry 3149 for ($i=0; $i<$v_central_dir['entries']; $i++) 1899 return $v_result; 1900 } 1901 $v_header['index'] = $i; 1902 1903 $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); 1904 unset($v_header); 1905 } 1906 1907 $this->privCloseFd(); 1908 1909 $this->privSwapBackMagicQuotes(); 1910 1911 return $v_result; 1912 } 1913 1914 function privConvertHeader2FileInfo($p_header, &$p_info) 1915 { 1916 $v_result=1; 1917 1918 $p_info['filename'] = $p_header['filename']; 1919 $p_info['stored_filename'] = $p_header['stored_filename']; 1920 $p_info['size'] = $p_header['size']; 1921 $p_info['compressed_size'] = $p_header['compressed_size']; 1922 $p_info['mtime'] = $p_header['mtime']; 1923 $p_info['comment'] = $p_header['comment']; 1924 $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); 1925 $p_info['index'] = $p_header['index']; 1926 $p_info['status'] = $p_header['status']; 1927 $p_info['crc'] = $p_header['crc']; 1928 1929 return $v_result; 1930 } 1931 1932 function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) 1933 { 1934 $v_result=1; 1935 1936 $this->privDisableMagicQuotes(); 1937 1938 if ( ($p_path == "") 1939 || ( (substr($p_path, 0, 1) != "/") 1940 && (substr($p_path, 0, 3) != "../") 1941 && (substr($p_path,1,2)!=":/"))) 1942 $p_path = "./".$p_path; 1943 1944 if (($p_path != "./") && ($p_path != "/")) 1945 { 1946 while (substr($p_path, -1) == "/") 3150 1947 { 3151 // ----- Read the file header 3152 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) 3153 { 3154 $this->privSwapBackMagicQuotes(); 3155 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3156 return $v_result; 3157 } 3158 $v_header['index'] = $i; 3159 3160 // ----- Get the only interesting attributes 3161 $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); 3162 unset($v_header); 3163 } 3164 3165 // ----- Close the zip file 1948 $p_path = substr($p_path, 0, strlen($p_path)-1); 1949 } 1950 } 1951 1952 if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) 1953 { 1954 $p_remove_path .= '/'; 1955 } 1956 $p_remove_path_size = strlen($p_remove_path); 1957 1958 if (($v_result = $this->privOpenFd('rb')) != 1) 1959 { 1960 $this->privSwapBackMagicQuotes(); 1961 return $v_result; 1962 } 1963 1964 $v_central_dir = array(); 1965 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 1966 { 3166 1967 $this->privCloseFd(); 3167 3168 // ----- Magic quotes trick3169 1968 $this->privSwapBackMagicQuotes(); 3170 1969 3171 // ----- Return3172 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3173 1970 return $v_result; 3174 1971 } 3175 // -------------------------------------------------------------------------------- 3176 3177 // -------------------------------------------------------------------------------- 3178 // Function : privConvertHeader2FileInfo() 3179 // Description : 3180 // This function takes the file informations from the central directory 3181 // entries and extract the interesting parameters that will be given back. 3182 // The resulting file infos are set in the array $p_info 3183 // $p_info['filename'] : Filename with full path. Given by user (add), 3184 // extracted in the filesystem (extract). 3185 // $p_info['stored_filename'] : Stored filename in the archive. 3186 // $p_info['size'] = Size of the file. 3187 // $p_info['compressed_size'] = Compressed size of the file. 3188 // $p_info['mtime'] = Last modification date of the file. 3189 // $p_info['comment'] = Comment associated with the file. 3190 // $p_info['folder'] = true/false : indicates if the entry is a folder or not. 3191 // $p_info['status'] = status of the action on the file. 3192 // $p_info['crc'] = CRC of the file content. 3193 // Parameters : 3194 // Return Values : 3195 // -------------------------------------------------------------------------------- 3196 function privConvertHeader2FileInfo($p_header, &$p_info) 3197 { 3198 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'"); 3199 $v_result=1; 3200 3201 // ----- Get the interesting attributes 3202 $p_info['filename'] = $p_header['filename']; 3203 $p_info['stored_filename'] = $p_header['stored_filename']; 3204 $p_info['size'] = $p_header['size']; 3205 $p_info['compressed_size'] = $p_header['compressed_size']; 3206 $p_info['mtime'] = $p_header['mtime']; 3207 $p_info['comment'] = $p_header['comment']; 3208 $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); 3209 $p_info['index'] = $p_header['index']; 3210 $p_info['status'] = $p_header['status']; 3211 $p_info['crc'] = $p_header['crc']; 3212 3213 // ----- Return 3214 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3215 return $v_result; 3216 } 3217 // -------------------------------------------------------------------------------- 3218 3219 // -------------------------------------------------------------------------------- 3220 // Function : privExtractByRule() 3221 // Description : 3222 // Extract a file or directory depending of rules (by index, by name, ...) 3223 // Parameters : 3224 // $p_file_list : An array where will be placed the properties of each 3225 // extracted file 3226 // $p_path : Path to add while writing the extracted files 3227 // $p_remove_path : Path to remove (from the file memorized path) while writing the 3228 // extracted files. If the path does not match the file path, 3229 // the file is extracted with its memorized path. 3230 // $p_remove_path does not apply to 'list' mode. 3231 // $p_path and $p_remove_path are commulative. 3232 // Return Values : 3233 // 1 on success,0 or less on error (see error code list) 3234 // -------------------------------------------------------------------------------- 3235 function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) 3236 { 3237 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); 3238 $v_result=1; 3239 3240 // ----- Magic quotes trick 3241 $this->privDisableMagicQuotes(); 3242 3243 // ----- Check the path 3244 if ( ($p_path == "") 3245 || ( (substr($p_path, 0, 1) != "/") 3246 && (substr($p_path, 0, 3) != "../") 3247 && (substr($p_path,1,2)!=":/"))) 3248 $p_path = "./".$p_path; 3249 3250 // ----- Reduce the path last (and duplicated) '/' 3251 if (($p_path != "./") && ($p_path != "/")) 1972 1973 $v_pos_entry = $v_central_dir['offset']; 1974 1975 $j_start = 0; 1976 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) 1977 { 1978 1979 @rewind($this->zip_fd); 1980 if (@fseek($this->zip_fd, $v_pos_entry)) 3252 1981 { 3253 // ----- Look for the path end '/'3254 while (substr($p_path, -1) == "/")3255 {3256 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");3257 $p_path = substr($p_path, 0, strlen($p_path)-1);3258 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");3259 }3260 }3261 3262 // ----- Look for path to remove format (should end by /)3263 if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))3264 {3265 $p_remove_path .= '/';3266 }3267 $p_remove_path_size = strlen($p_remove_path);3268 3269 // ----- Open the zip file3270 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");3271 if (($v_result = $this->privOpenFd('rb')) != 1)3272 {3273 $this->privSwapBackMagicQuotes();3274 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3275 return $v_result;3276 }3277 3278 // ----- Read the central directory informations3279 $v_central_dir = array();3280 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)3281 {3282 // ----- Close the zip file3283 1982 $this->privCloseFd(); 3284 1983 $this->privSwapBackMagicQuotes(); 3285 1984 3286 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1985 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 1986 1987 return PclZip::errorCode(); 1988 } 1989 1990 $v_header = array(); 1991 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) 1992 { 1993 $this->privCloseFd(); 1994 $this->privSwapBackMagicQuotes(); 1995 3287 1996 return $v_result; 3288 1997 } 3289 1998 3290 // ----- Start at beginning of Central Dir 3291 $v_pos_entry = $v_central_dir['offset']; 3292 3293 // ----- Read each entry 3294 $j_start = 0; 3295 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) 1999 $v_header['index'] = $i; 2000 2001 $v_pos_entry = ftell($this->zip_fd); 2002 2003 $v_extract = false; 2004 2005 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) 2006 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { 2007 2008 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { 2009 2010 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { 2011 2012 if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) 2013 && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 2014 $v_extract = true; 2015 } 2016 } 2017 elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { 2018 $v_extract = true; 2019 } 2020 } 2021 } 2022 2023 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) 2024 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { 2025 2026 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { 2027 $v_extract = true; 2028 } 2029 } 2030 2031 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) 2032 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { 2033 2034 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { 2035 $v_extract = true; 2036 } 2037 } 2038 2039 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 2040 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 2041 2042 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { 2043 2044 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { 2045 $v_extract = true; 2046 } 2047 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { 2048 $j_start = $j+1; 2049 } 2050 2051 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { 2052 break; 2053 } 2054 } 2055 } 2056 2057 else { 2058 $v_extract = true; 2059 } 2060 2061 if ( ($v_extract) 2062 && ( ($v_header['compression'] != 8) 2063 && ($v_header['compression'] != 0))) { 2064 $v_header['status'] = 'unsupported_compression'; 2065 2066 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 2067 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 2068 2069 $this->privSwapBackMagicQuotes(); 2070 2071 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, 2072 "Filename '".$v_header['stored_filename']."' is " 2073 ."compressed by an unsupported compression " 2074 ."method (".$v_header['compression'].") "); 2075 2076 return PclZip::errorCode(); 2077 } 2078 } 2079 2080 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { 2081 $v_header['status'] = 'unsupported_encryption'; 2082 2083 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 2084 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 2085 2086 $this->privSwapBackMagicQuotes(); 2087 2088 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 2089 "Unsupported encryption for " 2090 ." filename '".$v_header['stored_filename'] 2091 ."'"); 2092 2093 return PclZip::errorCode(); 2094 } 2095 } 2096 2097 if (($v_extract) && ($v_header['status'] != 'ok')) { 2098 $v_result = $this->privConvertHeader2FileInfo($v_header, 2099 $p_file_list[$v_nb_extracted++]); 2100 if ($v_result != 1) { 2101 $this->privCloseFd(); 2102 $this->privSwapBackMagicQuotes(); 2103 return $v_result; 2104 } 2105 2106 $v_extract = false; 2107 } 2108 2109 if ($v_extract) 3296 2110 { 3297 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'"); 3298 3299 // ----- Read next Central dir entry 3300 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'"); 2111 3301 2112 @rewind($this->zip_fd); 3302 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'"); 3303 if (@fseek($this->zip_fd, $v_pos_entry)) 2113 if (@fseek($this->zip_fd, $v_header['offset'])) 3304 2114 { 3305 // ----- Close the zip file3306 2115 $this->privCloseFd(); 2116 3307 2117 $this->privSwapBackMagicQuotes(); 3308 2118 3309 // ----- Error log3310 2119 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3311 2120 3312 // ----- Return3313 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3314 2121 return PclZip::errorCode(); 3315 2122 } 3316 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'"); 3317 3318 // ----- Read the file header 3319 $v_header = array(); 3320 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) 2123 2124 if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { 2125 2126 $v_result1 = $this->privExtractFileAsString($v_header, $v_string); 2127 if ($v_result1 < 1) { 2128 $this->privCloseFd(); 2129 $this->privSwapBackMagicQuotes(); 2130 return $v_result1; 2131 } 2132 2133 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) 2134 { 2135 $this->privCloseFd(); 2136 $this->privSwapBackMagicQuotes(); 2137 2138 return $v_result; 2139 } 2140 2141 $p_file_list[$v_nb_extracted]['content'] = $v_string; 2142 2143 $v_nb_extracted++; 2144 2145 if ($v_result1 == 2) { 2146 break; 2147 } 2148 } 2149 elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) 2150 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { 2151 $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); 2152 if ($v_result1 < 1) { 2153 $this->privCloseFd(); 2154 $this->privSwapBackMagicQuotes(); 2155 return $v_result1; 2156 } 2157 2158 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { 2159 $this->privCloseFd(); 2160 $this->privSwapBackMagicQuotes(); 2161 return $v_result; 2162 } 2163 2164 if ($v_result1 == 2) { 2165 break; 2166 } 2167 } 2168 else { 2169 $v_result1 = $this->privExtractFile($v_header, 2170 $p_path, $p_remove_path, 2171 $p_remove_all_path, 2172 $p_options); 2173 if ($v_result1 < 1) { 2174 $this->privCloseFd(); 2175 $this->privSwapBackMagicQuotes(); 2176 return $v_result1; 2177 } 2178 2179 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) 2180 { 2181 $this->privCloseFd(); 2182 $this->privSwapBackMagicQuotes(); 2183 2184 return $v_result; 2185 } 2186 2187 if ($v_result1 == 2) { 2188 break; 2189 } 2190 } 2191 } 2192 } 2193 2194 $this->privCloseFd(); 2195 $this->privSwapBackMagicQuotes(); 2196 2197 return $v_result; 2198 } 2199 2200 function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) 2201 { 2202 $v_result=1; 2203 2204 if (($v_result = $this->privReadFileHeader($v_header)) != 1) 2205 { 2206 return $v_result; 2207 } 2208 2209 2210 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 2211 } 2212 2213 if ($p_remove_all_path == true) { 2214 if (($p_entry['external']&0x00000010)==0x00000010) { 2215 2216 $p_entry['status'] = "filtered"; 2217 2218 return $v_result; 2219 } 2220 2221 $p_entry['filename'] = basename($p_entry['filename']); 2222 } 2223 2224 else if ($p_remove_path != "") 2225 { 2226 if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) 2227 { 2228 2229 $p_entry['status'] = "filtered"; 2230 2231 return $v_result; 2232 } 2233 2234 $p_remove_path_size = strlen($p_remove_path); 2235 if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) 2236 { 2237 2238 $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); 2239 2240 } 2241 } 2242 2243 if ($p_path != '') { 2244 $p_entry['filename'] = $p_path."/".$p_entry['filename']; 2245 } 2246 2247 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { 2248 $v_inclusion 2249 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], 2250 $p_entry['filename']); 2251 if ($v_inclusion == 0) { 2252 2253 PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, 2254 "Filename '".$p_entry['filename']."' is " 2255 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); 2256 2257 return PclZip::errorCode(); 2258 } 2259 } 2260 2261 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { 2262 2263 $v_local_header = array(); 2264 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 2265 2266 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); 2267 if ($v_result == 0) { 2268 $p_entry['status'] = "skipped"; 2269 $v_result = 1; 2270 } 2271 2272 if ($v_result == 2) { 2273 $p_entry['status'] = "aborted"; 2274 $v_result = PCLZIP_ERR_USER_ABORTED; 2275 } 2276 2277 $p_entry['filename'] = $v_local_header['filename']; 2278 } 2279 2280 2281 if ($p_entry['status'] == 'ok') { 2282 2283 if (file_exists($p_entry['filename'])) 2284 { 2285 2286 if (is_dir($p_entry['filename'])) 2287 { 2288 2289 $p_entry['status'] = "already_a_directory"; 2290 2291 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 2292 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 2293 2294 PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, 2295 "Filename '".$p_entry['filename']."' is " 2296 ."already used by an existing directory"); 2297 2298 return PclZip::errorCode(); 2299 } 2300 } 2301 else if (!is_writeable($p_entry['filename'])) 2302 { 2303 2304 $p_entry['status'] = "write_protected"; 2305 2306 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 2307 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 2308 2309 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 2310 "Filename '".$p_entry['filename']."' exists " 2311 ."and is write protected"); 2312 2313 return PclZip::errorCode(); 2314 } 2315 } 2316 2317 else if (filemtime($p_entry['filename']) > $p_entry['mtime']) 2318 { 2319 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) 2320 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { 2321 } 2322 else { 2323 $p_entry['status'] = "newer_exist"; 2324 2325 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 2326 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 2327 2328 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 2329 "Newer version of '".$p_entry['filename']."' exists " 2330 ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); 2331 2332 return PclZip::errorCode(); 2333 } 2334 } 2335 } 2336 else { 2337 } 2338 } 2339 2340 else { 2341 if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) 2342 $v_dir_to_check = $p_entry['filename']; 2343 else if (!strstr($p_entry['filename'], "/")) 2344 $v_dir_to_check = ""; 2345 else 2346 $v_dir_to_check = dirname($p_entry['filename']); 2347 2348 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { 2349 2350 $p_entry['status'] = "path_creation_fail"; 2351 2352 $v_result = 1; 2353 } 2354 } 2355 } 2356 2357 if ($p_entry['status'] == 'ok') { 2358 2359 if (!(($p_entry['external']&0x00000010)==0x00000010)) 2360 { 2361 if ($p_entry['compression'] == 0) { 2362 2363 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) 2364 { 2365 2366 $p_entry['status'] = "write_error"; 2367 2368 return $v_result; 2369 } 2370 2371 2372 $v_size = $p_entry['compressed_size']; 2373 while ($v_size != 0) 2374 { 2375 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2376 $v_buffer = @fread($this->zip_fd, $v_read_size); 2377 2378 @fwrite($v_dest_file, $v_buffer, $v_read_size); 2379 $v_size -= $v_read_size; 2380 } 2381 2382 fclose($v_dest_file); 2383 2384 touch($p_entry['filename'], $p_entry['mtime']); 2385 2386 2387 } 2388 else { 2389 if (($p_entry['flag'] & 1) == 1) { 2390 2391 } 2392 else { 2393 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 2394 } 2395 2396 $v_file_content = @gzinflate($v_buffer); 2397 unset($v_buffer); 2398 if ($v_file_content === FALSE) { 2399 2400 $p_entry['status'] = "error"; 2401 2402 return $v_result; 2403 } 2404 2405 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 2406 2407 $p_entry['status'] = "write_error"; 2408 2409 return $v_result; 2410 } 2411 2412 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); 2413 unset($v_file_content); 2414 2415 @fclose($v_dest_file); 2416 2417 @touch($p_entry['filename'], $p_entry['mtime']); 2418 } 2419 2420 if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { 2421 2422 @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); 2423 } 2424 2425 } 2426 } 2427 2428 if ($p_entry['status'] == "aborted") { 2429 $p_entry['status'] = "skipped"; 2430 } 2431 2432 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 2433 2434 $v_local_header = array(); 2435 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 2436 2437 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); 2438 2439 if ($v_result == 2) { 2440 $v_result = PCLZIP_ERR_USER_ABORTED; 2441 } 2442 } 2443 2444 return $v_result; 2445 } 2446 2447 function privExtractFileInOutput(&$p_entry, &$p_options) 2448 { 2449 $v_result=1; 2450 2451 if (($v_result = $this->privReadFileHeader($v_header)) != 1) { 2452 return $v_result; 2453 } 2454 2455 2456 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 2457 } 2458 2459 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { 2460 2461 $v_local_header = array(); 2462 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 2463 2464 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); 2465 if ($v_result == 0) { 2466 $p_entry['status'] = "skipped"; 2467 $v_result = 1; 2468 } 2469 2470 if ($v_result == 2) { 2471 $p_entry['status'] = "aborted"; 2472 $v_result = PCLZIP_ERR_USER_ABORTED; 2473 } 2474 2475 $p_entry['filename'] = $v_local_header['filename']; 2476 } 2477 2478 2479 if ($p_entry['status'] == 'ok') { 2480 2481 if (!(($p_entry['external']&0x00000010)==0x00000010)) { 2482 if ($p_entry['compressed_size'] == $p_entry['size']) { 2483 2484 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 2485 2486 echo $v_buffer; 2487 unset($v_buffer); 2488 } 2489 else { 2490 2491 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 2492 2493 $v_file_content = gzinflate($v_buffer); 2494 unset($v_buffer); 2495 2496 echo $v_file_content; 2497 unset($v_file_content); 2498 } 2499 } 2500 } 2501 2502 if ($p_entry['status'] == "aborted") { 2503 $p_entry['status'] = "skipped"; 2504 } 2505 2506 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 2507 2508 $v_local_header = array(); 2509 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 2510 2511 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); 2512 2513 if ($v_result == 2) { 2514 $v_result = PCLZIP_ERR_USER_ABORTED; 2515 } 2516 } 2517 2518 return $v_result; 2519 } 2520 2521 function privExtractFileAsString(&$p_entry, &$p_string) 2522 { 2523 $v_result=1; 2524 2525 $v_header = array(); 2526 if (($v_result = $this->privReadFileHeader($v_header)) != 1) 2527 { 2528 return $v_result; 2529 } 2530 2531 2532 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 2533 } 2534 2535 2536 if (!(($p_entry['external']&0x00000010)==0x00000010)) 2537 { 2538 if ($p_entry['compression'] == 0) { 2539 2540 $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); 2541 } 2542 else { 2543 2544 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); 2545 2546 if (($p_string = @gzinflate($v_data)) === FALSE) { 2547 } 2548 } 2549 2550 } 2551 else { 2552 } 2553 2554 return $v_result; 2555 } 2556 2557 function privReadFileHeader(&$p_header) 2558 { 2559 $v_result=1; 2560 2561 $v_binary_data = @fread($this->zip_fd, 4); 2562 $v_data = unpack('Vid', $v_binary_data); 2563 2564 if ($v_data['id'] != 0x04034b50) 2565 { 2566 2567 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 2568 2569 return PclZip::errorCode(); 2570 } 2571 2572 $v_binary_data = fread($this->zip_fd, 26); 2573 2574 if (strlen($v_binary_data) != 26) 2575 { 2576 $p_header['filename'] = ""; 2577 $p_header['status'] = "invalid_header"; 2578 2579 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 2580 2581 return PclZip::errorCode(); 2582 } 2583 2584 $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); 2585 2586 $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); 2587 2588 if ($v_data['extra_len'] != 0) { 2589 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); 2590 } 2591 else { 2592 $p_header['extra'] = ''; 2593 } 2594 2595 $p_header['version_extracted'] = $v_data['version']; 2596 $p_header['compression'] = $v_data['compression']; 2597 $p_header['size'] = $v_data['size']; 2598 $p_header['compressed_size'] = $v_data['compressed_size']; 2599 $p_header['crc'] = $v_data['crc']; 2600 $p_header['flag'] = $v_data['flag']; 2601 $p_header['filename_len'] = $v_data['filename_len']; 2602 2603 $p_header['mdate'] = $v_data['mdate']; 2604 $p_header['mtime'] = $v_data['mtime']; 2605 if ($p_header['mdate'] && $p_header['mtime']) 2606 { 2607 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 2608 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 2609 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 2610 2611 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 2612 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 2613 $v_day = $p_header['mdate'] & 0x001F; 2614 2615 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 2616 2617 } 2618 else 2619 { 2620 $p_header['mtime'] = time(); 2621 } 2622 2623 2624 $p_header['stored_filename'] = $p_header['filename']; 2625 2626 $p_header['status'] = "ok"; 2627 2628 return $v_result; 2629 } 2630 2631 function privReadCentralFileHeader(&$p_header) 2632 { 2633 $v_result=1; 2634 2635 $v_binary_data = @fread($this->zip_fd, 4); 2636 $v_data = unpack('Vid', $v_binary_data); 2637 2638 if ($v_data['id'] != 0x02014b50) 2639 { 2640 2641 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 2642 2643 return PclZip::errorCode(); 2644 } 2645 2646 $v_binary_data = fread($this->zip_fd, 42); 2647 2648 if (strlen($v_binary_data) != 42) 2649 { 2650 $p_header['filename'] = ""; 2651 $p_header['status'] = "invalid_header"; 2652 2653 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 2654 2655 return PclZip::errorCode(); 2656 } 2657 2658 $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); 2659 2660 if ($p_header['filename_len'] != 0) 2661 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); 2662 else 2663 $p_header['filename'] = ''; 2664 2665 if ($p_header['extra_len'] != 0) 2666 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); 2667 else 2668 $p_header['extra'] = ''; 2669 2670 if ($p_header['comment_len'] != 0) 2671 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); 2672 else 2673 $p_header['comment'] = ''; 2674 2675 2676 if (1) 2677 { 2678 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 2679 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 2680 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 2681 2682 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 2683 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 2684 $v_day = $p_header['mdate'] & 0x001F; 2685 2686 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 2687 2688 } 2689 else 2690 { 2691 $p_header['mtime'] = time(); 2692 } 2693 2694 $p_header['stored_filename'] = $p_header['filename']; 2695 2696 $p_header['status'] = 'ok'; 2697 2698 if (substr($p_header['filename'], -1) == '/') { 2699 $p_header['external'] = 0x00000010; 2700 } 2701 2702 2703 return $v_result; 2704 } 2705 2706 function privCheckFileHeaders(&$p_local_header, &$p_central_header) 2707 { 2708 $v_result=1; 2709 2710 if ($p_local_header['filename'] != $p_central_header['filename']) { 2711 } 2712 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { 2713 } 2714 if ($p_local_header['flag'] != $p_central_header['flag']) { 2715 } 2716 if ($p_local_header['compression'] != $p_central_header['compression']) { 2717 } 2718 if ($p_local_header['mtime'] != $p_central_header['mtime']) { 2719 } 2720 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { 2721 } 2722 2723 if (($p_local_header['flag'] & 8) == 8) { 2724 $p_local_header['size'] = $p_central_header['size']; 2725 $p_local_header['compressed_size'] = $p_central_header['compressed_size']; 2726 $p_local_header['crc'] = $p_central_header['crc']; 2727 } 2728 2729 return $v_result; 2730 } 2731 2732 function privReadEndCentralDir(&$p_central_dir) 2733 { 2734 $v_result=1; 2735 2736 $v_size = filesize($this->zipname); 2737 @fseek($this->zip_fd, $v_size); 2738 if (@ftell($this->zip_fd) != $v_size) 2739 { 2740 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); 2741 2742 return PclZip::errorCode(); 2743 } 2744 2745 $v_found = 0; 2746 if ($v_size > 26) { 2747 @fseek($this->zip_fd, $v_size-22); 2748 if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) 2749 { 2750 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 2751 2752 return PclZip::errorCode(); 2753 } 2754 2755 $v_binary_data = @fread($this->zip_fd, 4); 2756 $v_data = @unpack('Vid', $v_binary_data); 2757 2758 if ($v_data['id'] == 0x06054b50) { 2759 $v_found = 1; 2760 } 2761 2762 $v_pos = ftell($this->zip_fd); 2763 } 2764 2765 if (!$v_found) { 2766 $v_maximum_size = 65557; if ($v_maximum_size > $v_size) 2767 $v_maximum_size = $v_size; 2768 @fseek($this->zip_fd, $v_size-$v_maximum_size); 2769 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) 2770 { 2771 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 2772 2773 return PclZip::errorCode(); 2774 } 2775 2776 $v_pos = ftell($this->zip_fd); 2777 $v_bytes = 0x00000000; 2778 while ($v_pos < $v_size) 2779 { 2780 $v_byte = @fread($this->zip_fd, 1); 2781 2782 $v_bytes = ($v_bytes << 8) | Ord($v_byte); 2783 2784 if ($v_bytes == 0x504b0506) 3321 2785 { 3322 // ----- Close the zip file 3323 $this->privCloseFd(); 3324 $this->privSwapBackMagicQuotes(); 3325 3326 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3327 return $v_result; 3328 } 3329 3330 // ----- Store the index 3331 $v_header['index'] = $i; 3332 3333 // ----- Store the file position 3334 $v_pos_entry = ftell($this->zip_fd); 3335 3336 // ----- Look for the specific extract rules 3337 $v_extract = false; 3338 3339 // ----- Look for extract by name rule 3340 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) 3341 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { 3342 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); 3343 3344 // ----- Look if the filename is in the list 3345 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { 3346 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'"); 3347 3348 // ----- Look for a directory 3349 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { 3350 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory"); 3351 3352 // ----- Look if the directory is in the filename path 3353 if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) 3354 && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 3355 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); 3356 $v_extract = true; 3357 } 3358 } 3359 // ----- Look for a filename 3360 elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { 3361 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); 3362 $v_extract = true; 3363 } 2786 $v_pos++; 2787 break; 2788 } 2789 2790 $v_pos++; 2791 } 2792 2793 if ($v_pos == $v_size) 2794 { 2795 2796 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); 2797 2798 return PclZip::errorCode(); 2799 } 2800 } 2801 2802 $v_binary_data = fread($this->zip_fd, 18); 2803 2804 if (strlen($v_binary_data) != 18) 2805 { 2806 2807 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 2808 2809 return PclZip::errorCode(); 2810 } 2811 2812 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); 2813 2814 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { 2815 2816 if (0) { 2817 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 2818 'The central dir is not at the end of the archive.' 2819 .' Some trailing bytes exists after the archive.'); 2820 2821 return PclZip::errorCode(); 2822 } 2823 } 2824 2825 if ($v_data['comment_size'] != 0) { 2826 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); 2827 } 2828 else 2829 $p_central_dir['comment'] = ''; 2830 2831 $p_central_dir['entries'] = $v_data['entries']; 2832 $p_central_dir['disk_entries'] = $v_data['disk_entries']; 2833 $p_central_dir['offset'] = $v_data['offset']; 2834 $p_central_dir['size'] = $v_data['size']; 2835 $p_central_dir['disk'] = $v_data['disk']; 2836 $p_central_dir['disk_start'] = $v_data['disk_start']; 2837 2838 2839 return $v_result; 2840 } 2841 2842 function privDeleteByRule(&$p_result_list, &$p_options) 2843 { 2844 $v_result=1; 2845 $v_list_detail = array(); 2846 2847 if (($v_result=$this->privOpenFd('rb')) != 1) 2848 { 2849 return $v_result; 2850 } 2851 2852 $v_central_dir = array(); 2853 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 2854 { 2855 $this->privCloseFd(); 2856 return $v_result; 2857 } 2858 2859 @rewind($this->zip_fd); 2860 2861 $v_pos_entry = $v_central_dir['offset']; 2862 @rewind($this->zip_fd); 2863 if (@fseek($this->zip_fd, $v_pos_entry)) 2864 { 2865 $this->privCloseFd(); 2866 2867 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 2868 2869 return PclZip::errorCode(); 2870 } 2871 2872 $v_header_list = array(); 2873 $j_start = 0; 2874 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) 2875 { 2876 2877 $v_header_list[$v_nb_extracted] = array(); 2878 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) 2879 { 2880 $this->privCloseFd(); 2881 2882 return $v_result; 2883 } 2884 2885 2886 $v_header_list[$v_nb_extracted]['index'] = $i; 2887 2888 $v_found = false; 2889 2890 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) 2891 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { 2892 2893 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { 2894 2895 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { 2896 2897 if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) 2898 && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 2899 $v_found = true; 2900 } 2901 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) 2902 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 2903 $v_found = true; 2904 } 2905 } 2906 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { 2907 $v_found = true; 2908 } 2909 } 2910 } 2911 2912 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) 2913 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { 2914 2915 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { 2916 $v_found = true; 2917 } 2918 } 2919 2920 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) 2921 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { 2922 2923 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { 2924 $v_found = true; 2925 } 2926 } 2927 2928 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 2929 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 2930 2931 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { 2932 2933 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { 2934 $v_found = true; 2935 } 2936 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { 2937 $j_start = $j+1; 2938 } 2939 2940 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { 2941 break; 2942 } 2943 } 2944 } 2945 else { 2946 $v_found = true; 2947 } 2948 2949 if ($v_found) 2950 { 2951 unset($v_header_list[$v_nb_extracted]); 2952 } 2953 else 2954 { 2955 $v_nb_extracted++; 2956 } 2957 } 2958 2959 if ($v_nb_extracted > 0) { 2960 2961 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 2962 2963 $v_temp_zip = new PclZip($v_zip_temp_name); 2964 2965 if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { 2966 $this->privCloseFd(); 2967 2968 return $v_result; 2969 } 2970 2971 for ($i=0; $i<sizeof($v_header_list); $i++) { 2972 2973 @rewind($this->zip_fd); 2974 if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { 2975 $this->privCloseFd(); 2976 $v_temp_zip->privCloseFd(); 2977 @unlink($v_zip_temp_name); 2978 2979 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 2980 2981 return PclZip::errorCode(); 3364 2982 } 3365 } 3366 3367 // ----- Look for extract by ereg rule 3368 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) 3369 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { 3370 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); 3371 3372 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { 3373 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 3374 $v_extract = true; 3375 } 3376 } 3377 3378 // ----- Look for extract by preg rule 3379 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) 3380 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { 3381 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); 3382 3383 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { 3384 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 3385 $v_extract = true; 3386 } 3387 } 3388 3389 // ----- Look for extract by index rule 3390 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 3391 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 3392 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); 3393 3394 // ----- Look if the index is in the list 3395 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { 3396 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]"); 3397 3398 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { 3399 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); 3400 $v_extract = true; 3401 } 3402 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { 3403 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); 3404 $j_start = $j+1; 3405 } 3406 3407 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { 3408 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); 3409 break; 3410 } 3411 } 3412 } 3413 3414 // ----- Look for no rule, which means extract all the archive 3415 else { 3416 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)"); 3417 $v_extract = true; 3418 } 3419 3420 // ----- Check compression method 3421 if ( ($v_extract) 3422 && ( ($v_header['compression'] != 8) 3423 && ($v_header['compression'] != 0))) { 3424 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")"); 3425 $v_header['status'] = 'unsupported_compression'; 3426 3427 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3428 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3429 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3430 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3431 3432 $this->privSwapBackMagicQuotes(); 3433 3434 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, 3435 "Filename '".$v_header['stored_filename']."' is " 3436 ."compressed by an unsupported compression " 3437 ."method (".$v_header['compression'].") "); 3438 3439 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3440 return PclZip::errorCode(); 3441 } 3442 } 3443 3444 // ----- Check encrypted files 3445 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { 3446 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption"); 3447 $v_header['status'] = 'unsupported_encryption'; 3448 3449 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3450 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3451 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3452 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3453 3454 $this->privSwapBackMagicQuotes(); 3455 3456 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 3457 "Unsupported encryption for " 3458 ." filename '".$v_header['stored_filename'] 3459 ."'"); 3460 3461 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3462 return PclZip::errorCode(); 3463 } 3464 } 3465 3466 // ----- Look for real extraction 3467 if (($v_extract) && ($v_header['status'] != 'ok')) { 3468 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract"); 3469 $v_result = $this->privConvertHeader2FileInfo($v_header, 3470 $p_file_list[$v_nb_extracted++]); 3471 if ($v_result != 1) { 2983 2984 $v_local_header = array(); 2985 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { 3472 2986 $this->privCloseFd(); 3473 $this->privSwapBackMagicQuotes(); 3474 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2987 $v_temp_zip->privCloseFd(); 2988 @unlink($v_zip_temp_name); 2989 3475 2990 return $v_result; 3476 2991 } 3477 3478 $v_extract = false; 3479 } 3480 3481 // ----- Look for real extraction 3482 if ($v_extract) 2992 2993 if ($this->privCheckFileHeaders($v_local_header, 2994 $v_header_list[$i]) != 1) { 2995 } 2996 unset($v_local_header); 2997 2998 if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { 2999 $this->privCloseFd(); 3000 $v_temp_zip->privCloseFd(); 3001 @unlink($v_zip_temp_name); 3002 3003 return $v_result; 3004 } 3005 3006 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { 3007 $this->privCloseFd(); 3008 $v_temp_zip->privCloseFd(); 3009 @unlink($v_zip_temp_name); 3010 3011 return $v_result; 3012 } 3013 } 3014 3015 $v_offset = @ftell($v_temp_zip->zip_fd); 3016 3017 for ($i=0; $i<sizeof($v_header_list); $i++) { 3018 if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 3019 $v_temp_zip->privCloseFd(); 3020 $this->privCloseFd(); 3021 @unlink($v_zip_temp_name); 3022 3023 return $v_result; 3024 } 3025 3026 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 3027 } 3028 3029 3030 $v_comment = ''; 3031 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 3032 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 3033 } 3034 3035 $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; 3036 3037 if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { 3038 unset($v_header_list); 3039 $v_temp_zip->privCloseFd(); 3040 $this->privCloseFd(); 3041 @unlink($v_zip_temp_name); 3042 3043 return $v_result; 3044 } 3045 3046 $v_temp_zip->privCloseFd(); 3047 $this->privCloseFd(); 3048 3049 @unlink($this->zipname); 3050 3051 PclZipUtilRename($v_zip_temp_name, $this->zipname); 3052 3053 unset($v_temp_zip); 3054 } 3055 3056 else if ($v_central_dir['entries'] != 0) { 3057 $this->privCloseFd(); 3058 3059 if (($v_result = $this->privOpenFd('wb')) != 1) { 3060 return $v_result; 3061 } 3062 3063 if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { 3064 return $v_result; 3065 } 3066 3067 $this->privCloseFd(); 3068 } 3069 3070 return $v_result; 3071 } 3072 3073 function privDirCheck($p_dir, $p_is_dir=false) 3074 { 3075 $v_result = 1; 3076 3077 3078 if (($p_is_dir) && (substr($p_dir, -1)=='/')) 3079 { 3080 $p_dir = substr($p_dir, 0, strlen($p_dir)-1); 3081 } 3082 3083 if ((is_dir($p_dir)) || ($p_dir == "")) 3084 { 3085 return 1; 3086 } 3087 3088 $p_parent_dir = dirname($p_dir); 3089 3090 if ($p_parent_dir != $p_dir) 3091 { 3092 if ($p_parent_dir != "") 3093 { 3094 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) 3483 3095 { 3484 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'"); 3485 3486 // ----- Go to the file position 3487 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 3488 @rewind($this->zip_fd); 3489 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 3490 if (@fseek($this->zip_fd, $v_header['offset'])) 3491 { 3492 // ----- Close the zip file 3493 $this->privCloseFd(); 3494 3495 $this->privSwapBackMagicQuotes(); 3496 3497 // ----- Error log 3498 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3499 3500 // ----- Return 3501 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3502 return PclZip::errorCode(); 3503 } 3504 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 3505 3506 // ----- Look for extraction as string 3507 if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { 3508 3509 // ----- Extracting the file 3510 $v_result1 = $this->privExtractFileAsString($v_header, $v_string); 3511 if ($v_result1 < 1) { 3512 $this->privCloseFd(); 3513 $this->privSwapBackMagicQuotes(); 3514 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3515 return $v_result1; 3516 } 3517 3518 // ----- Get the only interesting attributes 3519 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) 3520 { 3521 // ----- Close the zip file 3522 $this->privCloseFd(); 3523 $this->privSwapBackMagicQuotes(); 3524 3525 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3526 return $v_result; 3527 } 3528 3529 // ----- Set the file content 3530 $p_file_list[$v_nb_extracted]['content'] = $v_string; 3531 3532 // ----- Next extracted file 3533 $v_nb_extracted++; 3534 3535 // ----- Look for user callback abort 3536 if ($v_result1 == 2) { 3537 break; 3538 } 3539 } 3540 // ----- Look for extraction in standard output 3541 elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) 3542 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { 3543 // ----- Extracting the file in standard output 3544 $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); 3545 if ($v_result1 < 1) { 3546 $this->privCloseFd(); 3547 $this->privSwapBackMagicQuotes(); 3548 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3549 return $v_result1; 3550 } 3551 3552 // ----- Get the only interesting attributes 3553 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { 3554 $this->privCloseFd(); 3555 $this->privSwapBackMagicQuotes(); 3556 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3557 return $v_result; 3558 } 3559 3560 // ----- Look for user callback abort 3561 if ($v_result1 == 2) { 3562 break; 3563 } 3564 } 3565 // ----- Look for normal extraction 3566 else { 3567 // ----- Extracting the file 3568 $v_result1 = $this->privExtractFile($v_header, 3569 $p_path, $p_remove_path, 3570 $p_remove_all_path, 3571 $p_options); 3572 if ($v_result1 < 1) { 3573 $this->privCloseFd(); 3574 $this->privSwapBackMagicQuotes(); 3575 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3576 return $v_result1; 3577 } 3578 3579 // ----- Get the only interesting attributes 3580 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) 3581 { 3582 // ----- Close the zip file 3583 $this->privCloseFd(); 3584 $this->privSwapBackMagicQuotes(); 3585 3586 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3587 return $v_result; 3588 } 3589 3590 // ----- Look for user callback abort 3591 if ($v_result1 == 2) { 3592 break; 3593 } 3594 } 3595 } 3596 } 3597 3598 // ----- Close the zip file 3096 return $v_result; 3097 } 3098 } 3099 } 3100 3101 if (!@mkdir($p_dir, 0777)) 3102 { 3103 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); 3104 3105 return PclZip::errorCode(); 3106 } 3107 3108 return $v_result; 3109 } 3110 3111 function privMerge(&$p_archive_to_add) 3112 { 3113 $v_result=1; 3114 3115 if (!is_file($p_archive_to_add->zipname)) 3116 { 3117 3118 $v_result = 1; 3119 3120 return $v_result; 3121 } 3122 3123 if (!is_file($this->zipname)) 3124 { 3125 3126 $v_result = $this->privDuplicate($p_archive_to_add->zipname); 3127 3128 return $v_result; 3129 } 3130 3131 if (($v_result=$this->privOpenFd('rb')) != 1) 3132 { 3133 return $v_result; 3134 } 3135 3136 $v_central_dir = array(); 3137 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 3138 { 3599 3139 $this->privCloseFd(); 3600 $this->privSwapBackMagicQuotes();3601 3602 // ----- Return3603 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3604 3140 return $v_result; 3605 3141 } 3606 // -------------------------------------------------------------------------------- 3607 3608 // -------------------------------------------------------------------------------- 3609 // Function : privExtractFile() 3610 // Description : 3611 // Parameters : 3612 // Return Values : 3613 // 3614 // 1 : ... ? 3615 // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback 3616 // -------------------------------------------------------------------------------- 3617 function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) 3618 { 3619 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); 3620 $v_result=1; 3621 3622 // ----- Read the file header 3623 if (($v_result = $this->privReadFileHeader($v_header)) != 1) 3624 { 3625 // ----- Return 3626 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3627 return $v_result; 3628 } 3629 3630 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 3631 3632 // ----- Check that the file header is coherent with $p_entry info 3633 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 3634 // TBC 3635 } 3636 3637 // ----- Look for all path to remove 3638 if ($p_remove_all_path == true) { 3639 // ----- Look for folder entry that not need to be extracted 3640 if (($p_entry['external']&0x00000010)==0x00000010) { 3641 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered"); 3642 3643 $p_entry['status'] = "filtered"; 3644 3645 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3646 return $v_result; 3647 } 3648 3649 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed"); 3650 // ----- Get the basename of the path 3651 $p_entry['filename'] = basename($p_entry['filename']); 3652 } 3653 3654 // ----- Look for path to remove 3655 else if ($p_remove_path != "") 3656 { 3657 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove"); 3658 if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) 3659 { 3660 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'"); 3661 3662 // ----- Change the file status 3663 $p_entry['status'] = "filtered"; 3664 3665 // ----- Return 3666 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3667 return $v_result; 3668 } 3669 3670 $p_remove_path_size = strlen($p_remove_path); 3671 if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) 3672 { 3673 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'"); 3674 3675 // ----- Remove the path 3676 $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); 3677 3678 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'"); 3679 } 3680 } 3681 3682 // ----- Add the path 3683 if ($p_path != '') { 3684 $p_entry['filename'] = $p_path."/".$p_entry['filename']; 3685 } 3686 3687 // ----- Check a base_dir_restriction 3688 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { 3689 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction"); 3690 $v_inclusion 3691 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], 3692 $p_entry['filename']); 3693 if ($v_inclusion == 0) { 3694 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction"); 3695 3696 PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, 3697 "Filename '".$p_entry['filename']."' is " 3698 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); 3699 3700 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3701 return PclZip::errorCode(); 3702 } 3703 } 3704 3705 // ----- Look for pre-extract callback 3706 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { 3707 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); 3708 3709 // ----- Generate a local information 3710 $v_local_header = array(); 3711 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 3712 3713 // ----- Call the callback 3714 // Here I do not use call_user_func() because I need to send a reference to the 3715 // header. 3716 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); 3717 if ($v_result == 0) { 3718 // ----- Change the file status 3719 $p_entry['status'] = "skipped"; 3720 $v_result = 1; 3721 } 3722 3723 // ----- Look for abort result 3724 if ($v_result == 2) { 3725 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 3726 // ----- This status is internal and will be changed in 'skipped' 3727 $p_entry['status'] = "aborted"; 3728 $v_result = PCLZIP_ERR_USER_ABORTED; 3729 } 3730 3731 // ----- Update the informations 3732 // Only some fields can be modified 3733 $p_entry['filename'] = $v_local_header['filename']; 3734 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); 3735 } 3736 3737 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 3738 3739 // ----- Look if extraction should be done 3740 if ($p_entry['status'] == 'ok') { 3741 3742 // ----- Look for specific actions while the file exist 3743 if (file_exists($p_entry['filename'])) 3744 { 3745 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists"); 3746 3747 // ----- Look if file is a directory 3748 if (is_dir($p_entry['filename'])) 3749 { 3750 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory"); 3751 3752 // ----- Change the file status 3753 $p_entry['status'] = "already_a_directory"; 3754 3755 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3756 // For historical reason first PclZip implementation does not stop 3757 // when this kind of error occurs. 3758 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3759 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3760 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3761 3762 PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, 3763 "Filename '".$p_entry['filename']."' is " 3764 ."already used by an existing directory"); 3765 3766 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3767 return PclZip::errorCode(); 3768 } 3769 } 3770 // ----- Look if file is write protected 3771 else if (!is_writeable($p_entry['filename'])) 3772 { 3773 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected"); 3774 3775 // ----- Change the file status 3776 $p_entry['status'] = "write_protected"; 3777 3778 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3779 // For historical reason first PclZip implementation does not stop 3780 // when this kind of error occurs. 3781 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3782 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3783 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3784 3785 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 3786 "Filename '".$p_entry['filename']."' exists " 3787 ."and is write protected"); 3788 3789 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3790 return PclZip::errorCode(); 3791 } 3792 } 3793 3794 // ----- Look if the extracted file is older 3795 else if (filemtime($p_entry['filename']) > $p_entry['mtime']) 3796 { 3797 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is newer (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); 3798 // ----- Change the file status 3799 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) 3800 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { 3801 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced"); 3802 } 3803 else { 3804 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced"); 3805 $p_entry['status'] = "newer_exist"; 3806 3807 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3808 // For historical reason first PclZip implementation does not stop 3809 // when this kind of error occurs. 3810 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3811 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3812 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3813 3814 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 3815 "Newer version of '".$p_entry['filename']."' exists " 3816 ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); 3817 3818 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3819 return PclZip::errorCode(); 3820 } 3821 } 3822 } 3823 else { 3824 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is older than the extrated one - will be replaced by the extracted one (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); 3825 } 3826 } 3827 3828 // ----- Check the directory availability and create it if necessary 3829 else { 3830 if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) 3831 $v_dir_to_check = $p_entry['filename']; 3832 else if (!strstr($p_entry['filename'], "/")) 3833 $v_dir_to_check = ""; 3834 else 3835 $v_dir_to_check = dirname($p_entry['filename']); 3836 3837 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { 3838 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'"); 3839 3840 // ----- Change the file status 3841 $p_entry['status'] = "path_creation_fail"; 3842 3843 // ----- Return 3844 ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3845 //return $v_result; 3846 $v_result = 1; 3847 } 3848 } 3849 } 3850 3851 // ----- Look if extraction should be done 3852 if ($p_entry['status'] == 'ok') { 3853 3854 // ----- Do the extraction (if not a folder) 3855 if (!(($p_entry['external']&0x00000010)==0x00000010)) 3856 { 3857 // ----- Look for not compressed file 3858 if ($p_entry['compression'] == 0) { 3859 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 3860 3861 // ----- Opening destination file 3862 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) 3863 { 3864 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); 3865 3866 // ----- Change the file status 3867 $p_entry['status'] = "write_error"; 3868 3869 // ----- Return 3870 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3871 return $v_result; 3872 } 3873 3874 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes"); 3875 3876 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks 3877 $v_size = $p_entry['compressed_size']; 3878 while ($v_size != 0) 3879 { 3880 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3881 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); 3882 $v_buffer = @fread($this->zip_fd, $v_read_size); 3883 /* Try to speed up the code 3884 $v_binary_data = pack('a'.$v_read_size, $v_buffer); 3885 @fwrite($v_dest_file, $v_binary_data, $v_read_size); 3886 */ 3887 @fwrite($v_dest_file, $v_buffer, $v_read_size); 3888 $v_size -= $v_read_size; 3889 } 3890 3891 // ----- Closing the destination file 3892 fclose($v_dest_file); 3893 3894 // ----- Change the file mtime 3895 touch($p_entry['filename'], $p_entry['mtime']); 3896 3897 3898 } 3899 else { 3900 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")"); 3901 // ----- TBC 3902 // Need to be finished 3903 if (($p_entry['flag'] & 1) == 1) { 3904 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted"); 3905 /* 3906 // ----- Read the encryption header 3907 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes"); 3908 $v_encryption_header = @fread($this->zip_fd, 12); 3909 3910 // ----- Read the encrypted & compressed file in a buffer 3911 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes"); 3912 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12); 3913 3914 // ----- Decrypt the buffer 3915 $this->privDecrypt($v_encryption_header, $v_buffer, 3916 $p_entry['compressed_size']-12, $p_entry['crc']); 3917 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'"); 3918 */ 3919 } 3920 else { 3921 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes"); 3922 // ----- Read the compressed file in a buffer (one shot) 3923 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 3924 } 3925 3926 // ----- Decompress the file 3927 $v_file_content = @gzinflate($v_buffer); 3928 unset($v_buffer); 3929 if ($v_file_content === FALSE) { 3930 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file"); 3931 3932 // ----- Change the file status 3933 // TBC 3934 $p_entry['status'] = "error"; 3935 3936 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3937 return $v_result; 3938 } 3939 3940 // ----- Opening destination file 3941 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 3942 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); 3943 3944 // ----- Change the file status 3945 $p_entry['status'] = "write_error"; 3946 3947 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3948 return $v_result; 3949 } 3950 3951 // ----- Write the uncompressed data 3952 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); 3953 unset($v_file_content); 3954 3955 // ----- Closing the destination file 3956 @fclose($v_dest_file); 3957 3958 // ----- Change the file mtime 3959 @touch($p_entry['filename'], $p_entry['mtime']); 3960 } 3961 3962 // ----- Look for chmod option 3963 if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { 3964 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'"); 3965 3966 // ----- Change the mode of the file 3967 @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); 3968 } 3969 3970 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 3971 } 3972 } 3973 3974 // ----- Change abort status 3975 if ($p_entry['status'] == "aborted") { 3976 $p_entry['status'] = "skipped"; 3977 } 3978 3979 // ----- Look for post-extract callback 3980 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 3981 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); 3982 3983 // ----- Generate a local information 3984 $v_local_header = array(); 3985 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 3986 3987 // ----- Call the callback 3988 // Here I do not use call_user_func() because I need to send a reference to the 3989 // header. 3990 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); 3991 3992 // ----- Look for abort result 3993 if ($v_result == 2) { 3994 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 3995 $v_result = PCLZIP_ERR_USER_ABORTED; 3996 } 3997 } 3998 3999 // ----- Return 4000 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3142 3143 @rewind($this->zip_fd); 3144 3145 if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) 3146 { 3147 $this->privCloseFd(); 3148 4001 3149 return $v_result; 4002 3150 } 4003 // -------------------------------------------------------------------------------- 4004 4005 // -------------------------------------------------------------------------------- 4006 // Function : privExtractFileInOutput() 4007 // Description : 4008 // Parameters : 4009 // Return Values : 4010 // -------------------------------------------------------------------------------- 4011 function privExtractFileInOutput(&$p_entry, &$p_options) 4012 { 4013 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', ""); 4014 $v_result=1; 4015 4016 // ----- Read the file header 4017 if (($v_result = $this->privReadFileHeader($v_header)) != 1) { 4018 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4019 return $v_result; 4020 } 4021 4022 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 4023 4024 // ----- Check that the file header is coherent with $p_entry info 4025 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 4026 // TBC 4027 } 4028 4029 // ----- Look for pre-extract callback 4030 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { 4031 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); 4032 4033 // ----- Generate a local information 4034 $v_local_header = array(); 4035 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4036 4037 // ----- Call the callback 4038 // Here I do not use call_user_func() because I need to send a reference to the 4039 // header. 4040 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); 4041 if ($v_result == 0) { 4042 // ----- Change the file status 4043 $p_entry['status'] = "skipped"; 4044 $v_result = 1; 4045 } 4046 4047 // ----- Look for abort result 4048 if ($v_result == 2) { 4049 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4050 // ----- This status is internal and will be changed in 'skipped' 4051 $p_entry['status'] = "aborted"; 4052 $v_result = PCLZIP_ERR_USER_ABORTED; 4053 } 4054 4055 // ----- Update the informations 4056 // Only some fields can be modified 4057 $p_entry['filename'] = $v_local_header['filename']; 4058 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); 4059 } 4060 4061 // ----- Trace 4062 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 4063 4064 // ----- Look if extraction should be done 4065 if ($p_entry['status'] == 'ok') { 4066 4067 // ----- Do the extraction (if not a folder) 4068 if (!(($p_entry['external']&0x00000010)==0x00000010)) { 4069 // ----- Look for not compressed file 4070 if ($p_entry['compressed_size'] == $p_entry['size']) { 4071 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 4072 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); 4073 4074 // ----- Read the file in a buffer (one shot) 4075 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 4076 4077 // ----- Send the file to the output 4078 echo $v_buffer; 4079 unset($v_buffer); 4080 } 4081 else { 4082 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file"); 4083 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes"); 4084 4085 // ----- Read the compressed file in a buffer (one shot) 4086 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 4087 4088 // ----- Decompress the file 4089 $v_file_content = gzinflate($v_buffer); 4090 unset($v_buffer); 4091 4092 // ----- Send the file to the output 4093 echo $v_file_content; 4094 unset($v_file_content); 4095 } 4096 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 4097 } 4098 } 4099 4100 // ----- Change abort status 4101 if ($p_entry['status'] == "aborted") { 4102 $p_entry['status'] = "skipped"; 4103 } 4104 4105 // ----- Look for post-extract callback 4106 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 4107 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); 4108 4109 // ----- Generate a local information 4110 $v_local_header = array(); 4111 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4112 4113 // ----- Call the callback 4114 // Here I do not use call_user_func() because I need to send a reference to the 4115 // header. 4116 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); 4117 4118 // ----- Look for abort result 4119 if ($v_result == 2) { 4120 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4121 $v_result = PCLZIP_ERR_USER_ABORTED; 4122 } 4123 } 4124 4125 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4126 return $v_result; 4127 } 4128 // -------------------------------------------------------------------------------- 4129 4130 // -------------------------------------------------------------------------------- 4131 // Function : privExtractFileAsString() 4132 // Description : 4133 // Parameters : 4134 // Return Values : 4135 // -------------------------------------------------------------------------------- 4136 function privExtractFileAsString(&$p_entry, &$p_string) 4137 { 4138 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'"); 4139 $v_result=1; 4140 4141 // ----- Read the file header 4142 $v_header = array(); 4143 if (($v_result = $this->privReadFileHeader($v_header)) != 1) 4144 { 4145 // ----- Return 4146 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4147 return $v_result; 4148 } 4149 4150 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 4151 4152 // ----- Check that the file header is coherent with $p_entry info 4153 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 4154 // TBC 4155 } 4156 4157 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 4158 4159 // ----- Do the extraction (if not a folder) 4160 if (!(($p_entry['external']&0x00000010)==0x00000010)) 4161 { 4162 // ----- Look for not compressed file 4163 // if ($p_entry['compressed_size'] == $p_entry['size']) 4164 if ($p_entry['compression'] == 0) { 4165 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 4166 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); 4167 4168 // ----- Reading the file 4169 $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); 4170 } 4171 else { 4172 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')"); 4173 4174 // ----- Reading the file 4175 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); 4176 4177 // ----- Decompress the file 4178 if (($p_string = @gzinflate($v_data)) === FALSE) { 4179 // TBC 4180 } 4181 } 4182 4183 // ----- Trace 4184 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 4185 } 4186 else { 4187 // TBC : error : can not extract a folder in a string 4188 } 4189 4190 // ----- Return 4191 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4192 return $v_result; 4193 } 4194 // -------------------------------------------------------------------------------- 4195 4196 // -------------------------------------------------------------------------------- 4197 // Function : privReadFileHeader() 4198 // Description : 4199 // Parameters : 4200 // Return Values : 4201 // -------------------------------------------------------------------------------- 4202 function privReadFileHeader(&$p_header) 4203 { 4204 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", ""); 4205 $v_result=1; 4206 4207 // ----- Read the 4 bytes signature 4208 $v_binary_data = @fread($this->zip_fd, 4); 4209 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4210 $v_data = unpack('Vid', $v_binary_data); 4211 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4212 4213 // ----- Check signature 4214 if ($v_data['id'] != 0x04034b50) 4215 { 4216 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header"); 4217 4218 // ----- Error log 4219 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 4220 4221 // ----- Return 4222 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4223 return PclZip::errorCode(); 4224 } 4225 4226 // ----- Read the first 42 bytes of the header 4227 $v_binary_data = fread($this->zip_fd, 26); 4228 4229 // ----- Look for invalid block size 4230 if (strlen($v_binary_data) != 26) 4231 { 4232 $p_header['filename'] = ""; 4233 $p_header['status'] = "invalid_header"; 4234 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); 4235 4236 // ----- Error log 4237 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 4238 4239 // ----- Return 4240 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4241 return PclZip::errorCode(); 4242 } 4243 4244 // ----- Extract the values 4245 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'"); 4246 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'"); 4247 $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); 4248 4249 // ----- Get filename 4250 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']); 4251 $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); 4252 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\''); 4253 4254 // ----- Get extra_fields 4255 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']); 4256 if ($v_data['extra_len'] != 0) { 4257 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); 4258 } 4259 else { 4260 $p_header['extra'] = ''; 4261 } 4262 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\''); 4263 4264 // ----- Extract properties 4265 $p_header['version_extracted'] = $v_data['version']; 4266 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); 4267 $p_header['compression'] = $v_data['compression']; 4268 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\''); 4269 $p_header['size'] = $v_data['size']; 4270 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\''); 4271 $p_header['compressed_size'] = $v_data['compressed_size']; 4272 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\''); 4273 $p_header['crc'] = $v_data['crc']; 4274 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4275 $p_header['flag'] = $v_data['flag']; 4276 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\''); 4277 $p_header['filename_len'] = $v_data['filename_len']; 4278 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\''); 4279 4280 // ----- Recuperate date in UNIX format 4281 $p_header['mdate'] = $v_data['mdate']; 4282 $p_header['mtime'] = $v_data['mtime']; 4283 if ($p_header['mdate'] && $p_header['mtime']) 4284 { 4285 // ----- Extract time 4286 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 4287 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 4288 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 4289 4290 // ----- Extract date 4291 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 4292 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 4293 $v_day = $p_header['mdate'] & 0x001F; 4294 4295 // ----- Get UNIX date format 4296 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4297 4298 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4299 } 4300 else 4301 { 4302 $p_header['mtime'] = time(); 4303 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4304 } 4305 4306 // TBC 4307 //for(reset($v_data); $key = key($v_data); next($v_data)) { 4308 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]); 4309 //} 4310 4311 // ----- Set the stored filename 4312 $p_header['stored_filename'] = $p_header['filename']; 4313 4314 // ----- Set the status field 4315 $p_header['status'] = "ok"; 4316 4317 // ----- Return 4318 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4319 return $v_result; 4320 } 4321 // -------------------------------------------------------------------------------- 4322 4323 // -------------------------------------------------------------------------------- 4324 // Function : privReadCentralFileHeader() 4325 // Description : 4326 // Parameters : 4327 // Return Values : 4328 // -------------------------------------------------------------------------------- 4329 function privReadCentralFileHeader(&$p_header) 4330 { 4331 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", ""); 4332 $v_result=1; 4333 4334 // ----- Read the 4 bytes signature 4335 $v_binary_data = @fread($this->zip_fd, 4); 4336 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4337 $v_data = unpack('Vid', $v_binary_data); 4338 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4339 4340 // ----- Check signature 4341 if ($v_data['id'] != 0x02014b50) 4342 { 4343 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature"); 4344 4345 // ----- Error log 4346 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 4347 4348 // ----- Return 4349 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4350 return PclZip::errorCode(); 4351 } 4352 4353 // ----- Read the first 42 bytes of the header 4354 $v_binary_data = fread($this->zip_fd, 42); 4355 4356 // ----- Look for invalid block size 4357 if (strlen($v_binary_data) != 42) 4358 { 4359 $p_header['filename'] = ""; 4360 $p_header['status'] = "invalid_header"; 4361 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); 4362 4363 // ----- Error log 4364 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 4365 4366 // ----- Return 4367 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4368 return PclZip::errorCode(); 4369 } 4370 4371 // ----- Extract the values 4372 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'"); 4373 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'"); 4374 $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); 4375 4376 // ----- Get filename 4377 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']); 4378 if ($p_header['filename_len'] != 0) 4379 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); 4380 else 4381 $p_header['filename'] = ''; 4382 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\''); 4383 4384 // ----- Get extra 4385 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']); 4386 if ($p_header['extra_len'] != 0) 4387 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); 4388 else 4389 $p_header['extra'] = ''; 4390 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\''); 4391 4392 // ----- Get comment 4393 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']); 4394 if ($p_header['comment_len'] != 0) 4395 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); 4396 else 4397 $p_header['comment'] = ''; 4398 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\''); 4399 4400 // ----- Extract properties 4401 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\''); 4402 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); 4403 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\''); 4404 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\''); 4405 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4406 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\''); 4407 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\''); 4408 4409 // ----- Recuperate date in UNIX format 4410 //if ($p_header['mdate'] && $p_header['mtime']) 4411 // TBC : bug : this was ignoring time with 0/0/0 4412 if (1) 4413 { 4414 // ----- Extract time 4415 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 4416 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 4417 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 4418 4419 // ----- Extract date 4420 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 4421 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 4422 $v_day = $p_header['mdate'] & 0x001F; 4423 4424 // ----- Get UNIX date format 4425 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4426 4427 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4428 } 4429 else 4430 { 4431 $p_header['mtime'] = time(); 4432 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4433 } 4434 4435 // ----- Set the stored filename 4436 $p_header['stored_filename'] = $p_header['filename']; 4437 4438 // ----- Set default status to ok 4439 $p_header['status'] = 'ok'; 4440 4441 // ----- Look if it is a directory 4442 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'"); 4443 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "External (Hex) : '".sprintf("Ox%04X", $p_header['external'])."' (".(($p_header['external']&0x00000010)==0x00000010?'is a folder':'is a file').')'); 4444 if (substr($p_header['filename'], -1) == '/') { 4445 //$p_header['external'] = 0x41FF0010; 4446 $p_header['external'] = 0x00000010; 4447 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\''); 4448 } 4449 4450 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\''); 4451 4452 // ----- Return 4453 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4454 return $v_result; 4455 } 4456 // -------------------------------------------------------------------------------- 4457 4458 // -------------------------------------------------------------------------------- 4459 // Function : privCheckFileHeaders() 4460 // Description : 4461 // Parameters : 4462 // Return Values : 4463 // 1 on success, 4464 // 0 on error; 4465 // -------------------------------------------------------------------------------- 4466 function privCheckFileHeaders(&$p_local_header, &$p_central_header) 4467 { 4468 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", ""); 4469 $v_result=1; 4470 4471 // ----- Check the static values 4472 // TBC 4473 if ($p_local_header['filename'] != $p_central_header['filename']) { 4474 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed'); 4475 } 4476 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { 4477 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed'); 4478 } 4479 if ($p_local_header['flag'] != $p_central_header['flag']) { 4480 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed'); 4481 } 4482 if ($p_local_header['compression'] != $p_central_header['compression']) { 4483 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed'); 4484 } 4485 if ($p_local_header['mtime'] != $p_central_header['mtime']) { 4486 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed'); 4487 } 4488 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { 4489 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed'); 4490 } 4491 4492 // ----- Look for flag bit 3 4493 if (($p_local_header['flag'] & 8) == 8) { 4494 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !'); 4495 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header'); 4496 $p_local_header['size'] = $p_central_header['size']; 4497 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\''); 4498 $p_local_header['compressed_size'] = $p_central_header['compressed_size']; 4499 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\''); 4500 $p_local_header['crc'] = $p_central_header['crc']; 4501 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\''); 4502 } 4503 4504 // ----- Return 4505 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4506 return $v_result; 4507 } 4508 // -------------------------------------------------------------------------------- 4509 4510 // -------------------------------------------------------------------------------- 4511 // Function : privReadEndCentralDir() 4512 // Description : 4513 // Parameters : 4514 // Return Values : 4515 // -------------------------------------------------------------------------------- 4516 function privReadEndCentralDir(&$p_central_dir) 4517 { 4518 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", ""); 4519 $v_result=1; 4520 4521 // ----- Go to the end of the zip file 4522 $v_size = filesize($this->zipname); 4523 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size"); 4524 @fseek($this->zip_fd, $v_size); 4525 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\''); 4526 if (@ftell($this->zip_fd) != $v_size) 4527 { 4528 // ----- Error log 4529 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); 4530 4531 // ----- Return 4532 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4533 return PclZip::errorCode(); 4534 } 4535 4536 // ----- First try : look if this is an archive with no commentaries (most of the time) 4537 // in this case the end of central dir is at 22 bytes of the file end 4538 $v_found = 0; 4539 if ($v_size > 26) { 4540 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment'); 4541 @fseek($this->zip_fd, $v_size-22); 4542 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\''); 4543 if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) 4544 { 4545 // ----- Error log 4546 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 4547 4548 // ----- Return 4549 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4550 return PclZip::errorCode(); 4551 } 4552 4553 // ----- Read for bytes 4554 $v_binary_data = @fread($this->zip_fd, 4); 4555 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4556 $v_data = @unpack('Vid', $v_binary_data); 4557 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4558 4559 // ----- Check signature 4560 if ($v_data['id'] == 0x06054b50) { 4561 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position."); 4562 $v_found = 1; 4563 } 4564 4565 $v_pos = ftell($this->zip_fd); 4566 } 4567 4568 // ----- Go back to the maximum possible size of the Central Dir End Record 4569 if (!$v_found) { 4570 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir'); 4571 $v_maximum_size = 65557; // 0xFFFF + 22; 4572 if ($v_maximum_size > $v_size) 4573 $v_maximum_size = $v_size; 4574 @fseek($this->zip_fd, $v_size-$v_maximum_size); 4575 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) 4576 { 4577 // ----- Error log 4578 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 4579 4580 // ----- Return 4581 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4582 return PclZip::errorCode(); 4583 } 4584 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\''); 4585 4586 // ----- Read byte per byte in order to find the signature 4587 $v_pos = ftell($this->zip_fd); 4588 $v_bytes = 0x00000000; 4589 while ($v_pos < $v_size) 4590 { 4591 // ----- Read a byte 4592 $v_byte = @fread($this->zip_fd, 1); 4593 4594 // ----- Add the byte 4595 $v_bytes = ($v_bytes << 8) | Ord($v_byte); 4596 4597 // ----- Compare the bytes 4598 if ($v_bytes == 0x504b0506) 4599 { 4600 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\''); 4601 $v_pos++; 4602 break; 4603 } 4604 4605 $v_pos++; 4606 } 4607 4608 // ----- Look if not found end of central dir 4609 if ($v_pos == $v_size) 4610 { 4611 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature"); 4612 4613 // ----- Error log 4614 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); 4615 4616 // ----- Return 4617 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4618 return PclZip::errorCode(); 4619 } 4620 } 4621 4622 // ----- Read the first 18 bytes of the header 4623 $v_binary_data = fread($this->zip_fd, 18); 4624 4625 // ----- Look for invalid block size 4626 if (strlen($v_binary_data) != 18) 4627 { 4628 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 4629 4630 // ----- Error log 4631 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 4632 4633 // ----- Return 4634 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4635 return PclZip::errorCode(); 4636 } 4637 4638 // ----- Extract the values 4639 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'"); 4640 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'"); 4641 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); 4642 4643 // ----- Check the global size 4644 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']); 4645 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { 4646 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive."); 4647 4648 // ----- Removed in release 2.2 see readme file 4649 // The check of the file size is a little too strict. 4650 // Some bugs where found when a zip is encrypted/decrypted with 'crypt'. 4651 // While decrypted, zip has training 0 bytes 4652 if (0) { 4653 // ----- Error log 4654 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 4655 'The central dir is not at the end of the archive.' 4656 .' Some trailing bytes exists after the archive.'); 4657 4658 // ----- Return 4659 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4660 return PclZip::errorCode(); 4661 } 4662 } 4663 4664 // ----- Get comment 4665 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$v_data['comment_size'].'\''); 4666 if ($v_data['comment_size'] != 0) { 4667 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); 4668 } 4669 else 4670 $p_central_dir['comment'] = ''; 4671 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\''); 4672 4673 $p_central_dir['entries'] = $v_data['entries']; 4674 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\''); 4675 $p_central_dir['disk_entries'] = $v_data['disk_entries']; 4676 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\''); 4677 $p_central_dir['offset'] = $v_data['offset']; 4678 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\''); 4679 $p_central_dir['size'] = $v_data['size']; 4680 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\''); 4681 $p_central_dir['disk'] = $v_data['disk']; 4682 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\''); 4683 $p_central_dir['disk_start'] = $v_data['disk_start']; 4684 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\''); 4685 4686 // TBC 4687 //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { 4688 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]); 4689 //} 4690 4691 // ----- Return 4692 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4693 return $v_result; 4694 } 4695 // -------------------------------------------------------------------------------- 4696 4697 // -------------------------------------------------------------------------------- 4698 // Function : privDeleteByRule() 4699 // Description : 4700 // Parameters : 4701 // Return Values : 4702 // -------------------------------------------------------------------------------- 4703 function privDeleteByRule(&$p_result_list, &$p_options) 4704 { 4705 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", ""); 4706 $v_result=1; 4707 $v_list_detail = array(); 4708 4709 // ----- Open the zip file 4710 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 4711 if (($v_result=$this->privOpenFd('rb')) != 1) 4712 { 4713 // ----- Return 4714 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4715 return $v_result; 4716 } 4717 4718 // ----- Read the central directory informations 4719 $v_central_dir = array(); 4720 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 4721 { 4722 $this->privCloseFd(); 4723 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4724 return $v_result; 4725 } 4726 4727 // ----- Go to beginning of File 4728 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 4729 @rewind($this->zip_fd); 4730 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 4731 4732 // ----- Scan all the files 4733 // ----- Start at beginning of Central Dir 4734 $v_pos_entry = $v_central_dir['offset']; 4735 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 4736 @rewind($this->zip_fd); 4737 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 4738 if (@fseek($this->zip_fd, $v_pos_entry)) 4739 { 4740 // ----- Close the zip file 4741 $this->privCloseFd(); 4742 4743 // ----- Error log 4744 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 4745 4746 // ----- Return 4747 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4748 return PclZip::errorCode(); 4749 } 4750 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 4751 4752 // ----- Read each entry 4753 $v_header_list = array(); 4754 $j_start = 0; 4755 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) 4756 { 4757 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')"); 4758 4759 // ----- Read the file header 4760 $v_header_list[$v_nb_extracted] = array(); 4761 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) 4762 { 4763 // ----- Close the zip file 4764 $this->privCloseFd(); 4765 4766 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4767 return $v_result; 4768 } 4769 4770 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'"); 4771 4772 // ----- Store the index 4773 $v_header_list[$v_nb_extracted]['index'] = $i; 4774 4775 // ----- Look for the specific extract rules 4776 $v_found = false; 4777 4778 // ----- Look for extract by name rule 4779 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) 4780 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { 4781 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); 4782 4783 // ----- Look if the filename is in the list 4784 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { 4785 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'"); 4786 4787 // ----- Look for a directory 4788 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { 4789 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory"); 4790 4791 // ----- Look if the directory is in the filename path 4792 if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) 4793 && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 4794 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); 4795 $v_found = true; 4796 } 4797 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ 4798 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 4799 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory"); 4800 $v_found = true; 4801 } 4802 } 4803 // ----- Look for a filename 4804 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { 4805 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); 4806 $v_found = true; 4807 } 4808 } 4809 } 4810 4811 // ----- Look for extract by ereg rule 4812 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) 4813 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { 4814 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); 4815 4816 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { 4817 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 4818 $v_found = true; 4819 } 4820 } 4821 4822 // ----- Look for extract by preg rule 4823 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) 4824 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { 4825 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); 4826 4827 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { 4828 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 4829 $v_found = true; 4830 } 4831 } 4832 4833 // ----- Look for extract by index rule 4834 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 4835 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 4836 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); 4837 4838 // ----- Look if the index is in the list 4839 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { 4840 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]"); 4841 4842 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { 4843 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); 4844 $v_found = true; 4845 } 4846 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { 4847 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); 4848 $j_start = $j+1; 4849 } 4850 4851 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { 4852 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); 4853 break; 4854 } 4855 } 4856 } 4857 else { 4858 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file"); 4859 $v_found = true; 4860 } 4861 4862 // ----- Look for deletion 4863 if ($v_found) 4864 { 4865 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted"); 4866 unset($v_header_list[$v_nb_extracted]); 4867 } 4868 else 4869 { 4870 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted"); 4871 $v_nb_extracted++; 4872 } 4873 } 4874 4875 // ----- Look if something need to be deleted 4876 if ($v_nb_extracted > 0) { 4877 4878 // ----- Creates a temporay file 4879 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 4880 4881 // ----- Creates a temporary zip archive 4882 $v_temp_zip = new PclZip($v_zip_temp_name); 4883 4884 // ----- Open the temporary zip file in write mode 4885 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode"); 4886 if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { 4887 $this->privCloseFd(); 4888 4889 // ----- Return 4890 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4891 return $v_result; 4892 } 4893 4894 // ----- Look which file need to be kept 4895 for ($i=0; $i<sizeof($v_header_list); $i++) { 4896 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'"); 4897 4898 // ----- Calculate the position of the header 4899 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'"); 4900 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 4901 @rewind($this->zip_fd); 4902 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 4903 if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { 4904 // ----- Close the zip file 4905 $this->privCloseFd(); 4906 $v_temp_zip->privCloseFd(); 4907 @unlink($v_zip_temp_name); 4908 4909 // ----- Error log 4910 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 4911 4912 // ----- Return 4913 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4914 return PclZip::errorCode(); 4915 } 4916 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 4917 4918 // ----- Read the file header 4919 $v_local_header = array(); 4920 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { 4921 // ----- Close the zip file 4922 $this->privCloseFd(); 4923 $v_temp_zip->privCloseFd(); 4924 @unlink($v_zip_temp_name); 4925 4926 // ----- Return 4927 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4928 return $v_result; 4929 } 4930 4931 // ----- Check that local file header is same as central file header 4932 if ($this->privCheckFileHeaders($v_local_header, 4933 $v_header_list[$i]) != 1) { 4934 // TBC 4935 } 4936 unset($v_local_header); 4937 4938 // ----- Write the file header 4939 if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { 4940 // ----- Close the zip file 4941 $this->privCloseFd(); 4942 $v_temp_zip->privCloseFd(); 4943 @unlink($v_zip_temp_name); 4944 4945 // ----- Return 4946 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4947 return $v_result; 4948 } 4949 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'"); 4950 4951 // ----- Read/write the data block 4952 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { 4953 // ----- Close the zip file 4954 $this->privCloseFd(); 4955 $v_temp_zip->privCloseFd(); 4956 @unlink($v_zip_temp_name); 4957 4958 // ----- Return 4959 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4960 return $v_result; 4961 } 4962 } 4963 4964 // ----- Store the offset of the central dir 4965 $v_offset = @ftell($v_temp_zip->zip_fd); 4966 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset"); 4967 4968 // ----- Re-Create the Central Dir files header 4969 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory"); 4970 for ($i=0; $i<sizeof($v_header_list); $i++) { 4971 // ----- Create the file header 4972 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']); 4973 if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 4974 $v_temp_zip->privCloseFd(); 4975 $this->privCloseFd(); 4976 @unlink($v_zip_temp_name); 4977 4978 // ----- Return 4979 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4980 return $v_result; 4981 } 4982 4983 // ----- Transform the header to a 'usable' info 4984 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 4985 } 4986 4987 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer"); 4988 4989 // ----- Zip file comment 4990 $v_comment = ''; 4991 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 4992 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 4993 } 4994 4995 // ----- Calculate the size of the central header 4996 $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; 4997 4998 // ----- Create the central dir footer 4999 if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { 5000 // ----- Reset the file list 5001 unset($v_header_list); 5002 $v_temp_zip->privCloseFd(); 5003 $this->privCloseFd(); 5004 @unlink($v_zip_temp_name); 5005 5006 // ----- Return 5007 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5008 return $v_result; 5009 } 5010 5011 // ----- Close 5012 $v_temp_zip->privCloseFd(); 5013 $this->privCloseFd(); 5014 5015 // ----- Delete the zip file 5016 // TBC : I should test the result ... 5017 @unlink($this->zipname); 5018 5019 // ----- Rename the temporary file 5020 // TBC : I should test the result ... 5021 //@rename($v_zip_temp_name, $this->zipname); 5022 PclZipUtilRename($v_zip_temp_name, $this->zipname); 5023 5024 // ----- Destroy the temporary archive 5025 unset($v_temp_zip); 5026 } 5027 5028 // ----- Remove every files : reset the file 5029 else if ($v_central_dir['entries'] != 0) { 5030 $this->privCloseFd(); 5031 5032 if (($v_result = $this->privOpenFd('wb')) != 1) { 5033 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5034 return $v_result; 5035 } 5036 5037 if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { 5038 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5039 return $v_result; 5040 } 5041 5042 $this->privCloseFd(); 5043 } 5044 5045 // ----- Return 5046 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5047 return $v_result; 5048 } 5049 // -------------------------------------------------------------------------------- 5050 5051 // -------------------------------------------------------------------------------- 5052 // Function : privDirCheck() 5053 // Description : 5054 // Check if a directory exists, if not it creates it and all the parents directory 5055 // which may be useful. 5056 // Parameters : 5057 // $p_dir : Directory path to check. 5058 // Return Values : 5059 // 1 : OK 5060 // -1 : Unable to create directory 5061 // -------------------------------------------------------------------------------- 5062 function privDirCheck($p_dir, $p_is_dir=false) 5063 { 5064 $v_result = 1; 5065 5066 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'"); 5067 5068 // ----- Remove the final '/' 5069 if (($p_is_dir) && (substr($p_dir, -1)=='/')) 5070 { 5071 $p_dir = substr($p_dir, 0, strlen($p_dir)-1); 5072 } 5073 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'"); 5074 5075 // ----- Check the directory availability 5076 if ((is_dir($p_dir)) || ($p_dir == "")) 5077 { 5078 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory"); 5079 return 1; 5080 } 5081 5082 // ----- Extract parent directory 5083 $p_parent_dir = dirname($p_dir); 5084 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'"); 5085 5086 // ----- Just a check 5087 if ($p_parent_dir != $p_dir) 5088 { 5089 // ----- Look for parent directory 5090 if ($p_parent_dir != "") 5091 { 5092 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) 5093 { 5094 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5095 return $v_result; 5096 } 5097 } 5098 } 5099 5100 // ----- Create the directory 5101 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'"); 5102 if (!@mkdir($p_dir, 0777)) 5103 { 5104 // ----- Error log 5105 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); 5106 5107 // ----- Return 5108 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5109 return PclZip::errorCode(); 5110 } 5111 5112 // ----- Return 5113 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created"); 5114 return $v_result; 5115 } 5116 // -------------------------------------------------------------------------------- 5117 5118 // -------------------------------------------------------------------------------- 5119 // Function : privMerge() 5120 // Description : 5121 // If $p_archive_to_add does not exist, the function exit with a success result. 5122 // Parameters : 5123 // Return Values : 5124 // -------------------------------------------------------------------------------- 5125 function privMerge(&$p_archive_to_add) 5126 { 5127 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'"); 5128 $v_result=1; 5129 5130 // ----- Look if the archive_to_add exists 5131 if (!is_file($p_archive_to_add->zipname)) 5132 { 5133 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge."); 5134 5135 // ----- Nothing to merge, so merge is a success 5136 $v_result = 1; 5137 5138 // ----- Return 5139 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5140 return $v_result; 5141 } 5142 5143 // ----- Look if the archive exists 5144 if (!is_file($this->zipname)) 5145 { 5146 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add."); 5147 5148 // ----- Do a duplicate 5149 $v_result = $this->privDuplicate($p_archive_to_add->zipname); 5150 5151 // ----- Return 5152 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5153 return $v_result; 5154 } 5155 5156 // ----- Open the zip file 5157 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5158 if (($v_result=$this->privOpenFd('rb')) != 1) 5159 { 5160 // ----- Return 5161 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5162 return $v_result; 5163 } 5164 5165 // ----- Read the central directory informations 5166 $v_central_dir = array(); 5167 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 5168 { 5169 $this->privCloseFd(); 5170 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5171 return $v_result; 5172 } 5173 5174 // ----- Go to beginning of File 5175 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); 5176 @rewind($this->zip_fd); 5177 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); 5178 5179 // ----- Open the archive_to_add file 5180 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode"); 5181 if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) 5182 { 5183 $this->privCloseFd(); 5184 5185 // ----- Return 5186 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5187 return $v_result; 5188 } 5189 5190 // ----- Read the central directory informations 5191 $v_central_dir_to_add = array(); 5192 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) 5193 { 5194 $this->privCloseFd(); 5195 $p_archive_to_add->privCloseFd(); 5196 5197 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5198 return $v_result; 5199 } 5200 5201 // ----- Go to beginning of File 5202 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); 5203 @rewind($p_archive_to_add->zip_fd); 5204 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); 5205 5206 // ----- Creates a temporay file 5207 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 5208 5209 // ----- Open the temporary file in write mode 5210 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5211 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) 5212 { 5213 $this->privCloseFd(); 5214 $p_archive_to_add->privCloseFd(); 5215 5216 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); 5217 5218 // ----- Return 5219 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5220 return PclZip::errorCode(); 5221 } 5222 5223 // ----- Copy the files from the archive to the temporary file 5224 // TBC : Here I should better append the file and go back to erase the central dir 5225 $v_size = $v_central_dir['offset']; 5226 while ($v_size != 0) 5227 { 5228 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5229 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5230 $v_buffer = fread($this->zip_fd, $v_read_size); 5231 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5232 $v_size -= $v_read_size; 5233 } 5234 5235 // ----- Copy the files from the archive_to_add into the temporary file 5236 $v_size = $v_central_dir_to_add['offset']; 5237 while ($v_size != 0) 5238 { 5239 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5240 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5241 $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); 5242 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5243 $v_size -= $v_read_size; 5244 } 5245 5246 // ----- Store the offset of the central dir 5247 $v_offset = @ftell($v_zip_temp_fd); 5248 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); 5249 5250 // ----- Copy the block of file headers from the old archive 5251 $v_size = $v_central_dir['size']; 5252 while ($v_size != 0) 5253 { 5254 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5255 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5256 $v_buffer = @fread($this->zip_fd, $v_read_size); 5257 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5258 $v_size -= $v_read_size; 5259 } 5260 5261 // ----- Copy the block of file headers from the archive_to_add 5262 $v_size = $v_central_dir_to_add['size']; 5263 while ($v_size != 0) 5264 { 5265 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5266 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5267 $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); 5268 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5269 $v_size -= $v_read_size; 5270 } 5271 5272 // ----- Merge the file comments 5273 $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; 5274 5275 // ----- Calculate the size of the (new) central header 5276 $v_size = @ftell($v_zip_temp_fd)-$v_offset; 5277 5278 // ----- Swap the file descriptor 5279 // Here is a trick : I swap the temporary fd with the zip fd, in order to use 5280 // the following methods on the temporary fil and not the real archive fd 5281 $v_swap = $this->zip_fd; 5282 $this->zip_fd = $v_zip_temp_fd; 5283 $v_zip_temp_fd = $v_swap; 5284 5285 // ----- Create the central dir footer 5286 if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) 5287 { 5288 $this->privCloseFd(); 5289 $p_archive_to_add->privCloseFd(); 5290 @fclose($v_zip_temp_fd); 5291 $this->zip_fd = null; 5292 5293 // ----- Reset the file list 5294 unset($v_header_list); 5295 5296 // ----- Return 5297 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5298 return $v_result; 5299 } 5300 5301 // ----- Swap back the file descriptor 5302 $v_swap = $this->zip_fd; 5303 $this->zip_fd = $v_zip_temp_fd; 5304 $v_zip_temp_fd = $v_swap; 5305 5306 // ----- Close 3151 3152 $v_central_dir_to_add = array(); 3153 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) 3154 { 5307 3155 $this->privCloseFd(); 5308 3156 $p_archive_to_add->privCloseFd(); 5309 3157 5310 // ----- Close the temporary file 3158 return $v_result; 3159 } 3160 3161 @rewind($p_archive_to_add->zip_fd); 3162 3163 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 3164 3165 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) 3166 { 3167 $this->privCloseFd(); 3168 $p_archive_to_add->privCloseFd(); 3169 3170 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); 3171 3172 return PclZip::errorCode(); 3173 } 3174 3175 $v_size = $v_central_dir['offset']; 3176 while ($v_size != 0) 3177 { 3178 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3179 $v_buffer = fread($this->zip_fd, $v_read_size); 3180 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 3181 $v_size -= $v_read_size; 3182 } 3183 3184 $v_size = $v_central_dir_to_add['offset']; 3185 while ($v_size != 0) 3186 { 3187 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3188 $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); 3189 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 3190 $v_size -= $v_read_size; 3191 } 3192 3193 $v_offset = @ftell($v_zip_temp_fd); 3194 3195 $v_size = $v_central_dir['size']; 3196 while ($v_size != 0) 3197 { 3198 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3199 $v_buffer = @fread($this->zip_fd, $v_read_size); 3200 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 3201 $v_size -= $v_read_size; 3202 } 3203 3204 $v_size = $v_central_dir_to_add['size']; 3205 while ($v_size != 0) 3206 { 3207 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3208 $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); 3209 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 3210 $v_size -= $v_read_size; 3211 } 3212 3213 $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; 3214 3215 $v_size = @ftell($v_zip_temp_fd)-$v_offset; 3216 3217 $v_swap = $this->zip_fd; 3218 $this->zip_fd = $v_zip_temp_fd; 3219 $v_zip_temp_fd = $v_swap; 3220 3221 if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) 3222 { 3223 $this->privCloseFd(); 3224 $p_archive_to_add->privCloseFd(); 5311 3225 @fclose($v_zip_temp_fd); 5312 5313 // ----- Delete the zip file 5314 // TBC : I should test the result ... 5315 @unlink($this->zipname); 5316 5317 // ----- Rename the temporary file 5318 // TBC : I should test the result ... 5319 //@rename($v_zip_temp_name, $this->zipname); 5320 PclZipUtilRename($v_zip_temp_name, $this->zipname); 5321 5322 // ----- Return 5323 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3226 $this->zip_fd = null; 3227 3228 unset($v_header_list); 3229 5324 3230 return $v_result; 5325 3231 } 5326 // -------------------------------------------------------------------------------- 5327 5328 // -------------------------------------------------------------------------------- 5329 // Function : privDuplicate() 5330 // Description : 5331 // Parameters : 5332 // Return Values : 5333 // -------------------------------------------------------------------------------- 5334 function privDuplicate($p_archive_filename) 5335 { 5336 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'"); 5337 $v_result=1; 5338 5339 // ----- Look if the $p_archive_filename exists 5340 if (!is_file($p_archive_filename)) 3232 3233 $v_swap = $this->zip_fd; 3234 $this->zip_fd = $v_zip_temp_fd; 3235 $v_zip_temp_fd = $v_swap; 3236 3237 $this->privCloseFd(); 3238 $p_archive_to_add->privCloseFd(); 3239 3240 @fclose($v_zip_temp_fd); 3241 3242 @unlink($this->zipname); 3243 3244 PclZipUtilRename($v_zip_temp_name, $this->zipname); 3245 3246 return $v_result; 3247 } 3248 3249 function privDuplicate($p_archive_filename) 3250 { 3251 $v_result=1; 3252 3253 if (!is_file($p_archive_filename)) 3254 { 3255 3256 $v_result = 1; 3257 3258 return $v_result; 3259 } 3260 3261 if (($v_result=$this->privOpenFd('wb')) != 1) 3262 { 3263 return $v_result; 3264 } 3265 3266 if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) 3267 { 3268 $this->privCloseFd(); 3269 3270 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); 3271 3272 return PclZip::errorCode(); 3273 } 3274 3275 $v_size = filesize($p_archive_filename); 3276 while ($v_size != 0) 3277 { 3278 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3279 $v_buffer = fread($v_zip_temp_fd, $v_read_size); 3280 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 3281 $v_size -= $v_read_size; 3282 } 3283 3284 $this->privCloseFd(); 3285 3286 @fclose($v_zip_temp_fd); 3287 3288 return $v_result; 3289 } 3290 3291 function privErrorLog($p_error_code=0, $p_error_string='') 3292 { 3293 if (PCLZIP_ERROR_EXTERNAL == 1) { 3294 PclError($p_error_code, $p_error_string); 3295 } 3296 else { 3297 $this->error_code = $p_error_code; 3298 $this->error_string = $p_error_string; 3299 } 3300 } 3301 3302 function privErrorReset() 3303 { 3304 if (PCLZIP_ERROR_EXTERNAL == 1) { 3305 PclErrorReset(); 3306 } 3307 else { 3308 $this->error_code = 0; 3309 $this->error_string = ''; 3310 } 3311 } 3312 3313 function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc) 3314 { 3315 $v_result=1; 3316 3317 $v_pwd = "test"; 3318 3319 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header, 3320 $p_crc, $v_pwd); 3321 3322 return $v_result; 3323 } 3324 3325 function privDisableMagicQuotes() 3326 { 3327 $v_result=1; 3328 3329 if ( (!function_exists("get_magic_quotes_runtime")) 3330 || (!function_exists("set_magic_quotes_runtime"))) { 3331 return $v_result; 3332 } 3333 3334 if ($this->magic_quotes_status != -1) { 3335 return $v_result; 3336 } 3337 3338 $this->magic_quotes_status = @get_magic_quotes_runtime(); 3339 3340 if ($this->magic_quotes_status == 1) { 3341 @set_magic_quotes_runtime(0); 3342 } 3343 3344 return $v_result; 3345 } 3346 3347 function privSwapBackMagicQuotes() 3348 { 3349 $v_result=1; 3350 3351 if ( (!function_exists("get_magic_quotes_runtime")) 3352 || (!function_exists("set_magic_quotes_runtime"))) { 3353 return $v_result; 3354 } 3355 3356 if ($this->magic_quotes_status != -1) { 3357 return $v_result; 3358 } 3359 3360 if ($this->magic_quotes_status == 1) { 3361 @set_magic_quotes_runtime($this->magic_quotes_status); 3362 } 3363 3364 return $v_result; 3365 } 3366 3367 } 3368 3369 function PclZipUtilPathReduction($p_dir) 3370 { 3371 $v_result = ""; 3372 3373 if ($p_dir != "") { 3374 $v_list = explode("/", $p_dir); 3375 3376 $v_skip = 0; 3377 for ($i=sizeof($v_list)-1; $i>=0; $i--) { 3378 if ($v_list[$i] == ".") { 3379 } 3380 else if ($v_list[$i] == "..") { 3381 $v_skip++; 3382 } 3383 else if ($v_list[$i] == "") { 3384 if ($i == 0) { 3385 $v_result = "/".$v_result; 3386 if ($v_skip > 0) { 3387 $v_result = $p_dir; 3388 $v_skip = 0; 3389 } 3390 } 3391 else if ($i == (sizeof($v_list)-1)) { 3392 $v_result = $v_list[$i]; 3393 } 3394 else { 3395 } 3396 } 3397 else { 3398 if ($v_skip > 0) { 3399 $v_skip--; 3400 } 3401 else { 3402 $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); 3403 } 3404 } 3405 } 3406 3407 if ($v_skip > 0) { 3408 while ($v_skip > 0) { 3409 $v_result = '../'.$v_result; 3410 $v_skip--; 3411 } 3412 } 3413 } 3414 3415 return $v_result; 3416 } 3417 3418 function PclZipUtilPathInclusion($p_dir, $p_path) 3419 { 3420 $v_result = 1; 3421 3422 if ( ($p_dir == '.') 3423 || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { 3424 $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); 3425 } 3426 if ( ($p_path == '.') 3427 || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { 3428 $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); 3429 } 3430 3431 $v_list_dir = explode("/", $p_dir); 3432 $v_list_dir_size = sizeof($v_list_dir); 3433 $v_list_path = explode("/", $p_path); 3434 $v_list_path_size = sizeof($v_list_path); 3435 3436 $i = 0; 3437 $j = 0; 3438 while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { 3439 3440 if ($v_list_dir[$i] == '') { 3441 $i++; 3442 continue; 3443 } 3444 if ($v_list_path[$j] == '') { 3445 $j++; 3446 continue; 3447 } 3448 3449 if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { 3450 $v_result = 0; 3451 } 3452 3453 $i++; 3454 $j++; 3455 } 3456 3457 if ($v_result) { 3458 while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; 3459 while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; 3460 3461 if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { 3462 $v_result = 2; 3463 } 3464 else if ($i < $v_list_dir_size) { 3465 $v_result = 0; 3466 } 3467 } 3468 3469 return $v_result; 3470 } 3471 3472 function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) 3473 { 3474 $v_result = 1; 3475 3476 if ($p_mode==0) 3477 { 3478 while ($p_size != 0) 5341 3479 { 5342 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate."); 5343 5344 // ----- Nothing to duplicate, so duplicate is a success. 5345 $v_result = 1; 5346 5347 // ----- Return 5348 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5349 return $v_result; 5350 } 5351 5352 // ----- Open the zip file 5353 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5354 if (($v_result=$this->privOpenFd('wb')) != 1) 3480 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 3481 $v_buffer = @fread($p_src, $v_read_size); 3482 @fwrite($p_dest, $v_buffer, $v_read_size); 3483 $p_size -= $v_read_size; 3484 } 3485 } 3486 else if ($p_mode==1) 3487 { 3488 while ($p_size != 0) 5355 3489 { 5356 // ----- Return 5357 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5358 return $v_result; 5359 } 5360 5361 // ----- Open the temporary file in write mode 5362 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5363 if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) 3490 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 3491 $v_buffer = @gzread($p_src, $v_read_size); 3492 @fwrite($p_dest, $v_buffer, $v_read_size); 3493 $p_size -= $v_read_size; 3494 } 3495 } 3496 else if ($p_mode==2) 3497 { 3498 while ($p_size != 0) 5364 3499 { 5365 $this->privCloseFd(); 5366 5367 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); 5368 5369 // ----- Return 5370 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5371 return PclZip::errorCode(); 5372 } 5373 5374 // ----- Copy the files from the archive to the temporary file 5375 // TBC : Here I should better append the file and go back to erase the central dir 5376 $v_size = filesize($p_archive_filename); 5377 while ($v_size != 0) 3500 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 3501 $v_buffer = @fread($p_src, $v_read_size); 3502 @gzwrite($p_dest, $v_buffer, $v_read_size); 3503 $p_size -= $v_read_size; 3504 } 3505 } 3506 else if ($p_mode==3) 3507 { 3508 while ($p_size != 0) 5378 3509 { 5379 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5380 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes"); 5381 $v_buffer = fread($v_zip_temp_fd, $v_read_size); 5382 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 5383 $v_size -= $v_read_size; 5384 } 5385 5386 // ----- Close 5387 $this->privCloseFd(); 5388 5389 // ----- Close the temporary file 5390 @fclose($v_zip_temp_fd); 5391 5392 // ----- Return 5393 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5394 return $v_result; 5395 } 5396 // -------------------------------------------------------------------------------- 5397 5398 // -------------------------------------------------------------------------------- 5399 // Function : privErrorLog() 5400 // Description : 5401 // Parameters : 5402 // -------------------------------------------------------------------------------- 5403 function privErrorLog($p_error_code=0, $p_error_string='') 5404 { 5405 if (PCLZIP_ERROR_EXTERNAL == 1) { 5406 PclError($p_error_code, $p_error_string); 5407 } 5408 else { 5409 $this->error_code = $p_error_code; 5410 $this->error_string = $p_error_string; 5411 } 5412 } 5413 // -------------------------------------------------------------------------------- 5414 5415 // -------------------------------------------------------------------------------- 5416 // Function : privErrorReset() 5417 // Description : 5418 // Parameters : 5419 // -------------------------------------------------------------------------------- 5420 function privErrorReset() 5421 { 5422 if (PCLZIP_ERROR_EXTERNAL == 1) { 5423 PclErrorReset(); 5424 } 5425 else { 5426 $this->error_code = 0; 5427 $this->error_string = ''; 5428 } 5429 } 5430 // -------------------------------------------------------------------------------- 5431 5432 // -------------------------------------------------------------------------------- 5433 // Function : privDecrypt() 5434 // Description : 5435 // Parameters : 5436 // Return Values : 5437 // -------------------------------------------------------------------------------- 5438 function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc) 5439 { 5440 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size.""); 5441 $v_result=1; 5442 5443 // ----- To Be Modified ;-) 5444 $v_pwd = "test"; 5445 5446 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header, 5447 $p_crc, $v_pwd); 5448 5449 // ----- Return 5450 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5451 return $v_result; 5452 } 5453 // -------------------------------------------------------------------------------- 5454 5455 // -------------------------------------------------------------------------------- 5456 // Function : privDisableMagicQuotes() 5457 // Description : 5458 // Parameters : 5459 // Return Values : 5460 // -------------------------------------------------------------------------------- 5461 function privDisableMagicQuotes() 5462 { 5463 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', ""); 5464 $v_result=1; 5465 5466 // ----- Look if function exists 5467 if ( (!function_exists("get_magic_quotes_runtime")) 5468 || (!function_exists("set_magic_quotes_runtime"))) { 5469 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported"); 5470 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5471 return $v_result; 5472 } 5473 5474 // ----- Look if already done 5475 if ($this->magic_quotes_status != -1) { 5476 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled"); 5477 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5478 return $v_result; 5479 } 5480 5481 // ----- Get and memorize the magic_quote value 5482 $this->magic_quotes_status = @get_magic_quotes_runtime(); 5483 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'"); 5484 5485 // ----- Disable magic_quotes 5486 if ($this->magic_quotes_status == 1) { 5487 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes"); 5488 @set_magic_quotes_runtime(0); 5489 } 5490 5491 // ----- Return 5492 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5493 return $v_result; 5494 } 5495 // -------------------------------------------------------------------------------- 5496 5497 // -------------------------------------------------------------------------------- 5498 // Function : privSwapBackMagicQuotes() 5499 // Description : 5500 // Parameters : 5501 // Return Values : 5502 // -------------------------------------------------------------------------------- 5503 function privSwapBackMagicQuotes() 5504 { 5505 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', ""); 5506 $v_result=1; 5507 5508 // ----- Look if function exists 5509 if ( (!function_exists("get_magic_quotes_runtime")) 5510 || (!function_exists("set_magic_quotes_runtime"))) { 5511 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported"); 5512 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5513 return $v_result; 5514 } 5515 5516 // ----- Look if something to do 5517 if ($this->magic_quotes_status != -1) { 5518 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified"); 5519 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5520 return $v_result; 5521 } 5522 5523 // ----- Swap back magic_quotes 5524 if ($this->magic_quotes_status == 1) { 5525 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes"); 5526 @set_magic_quotes_runtime($this->magic_quotes_status); 5527 } 5528 5529 // ----- Return 5530 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5531 return $v_result; 5532 } 5533 // -------------------------------------------------------------------------------- 5534 5535 } 5536 // End of class 5537 // -------------------------------------------------------------------------------- 5538 5539 // -------------------------------------------------------------------------------- 5540 // Function : PclZipUtilPathReduction() 5541 // Description : 5542 // Parameters : 5543 // Return Values : 5544 // -------------------------------------------------------------------------------- 5545 function PclZipUtilPathReduction($p_dir) 5546 { 5547 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'"); 5548 $v_result = ""; 5549 5550 // ----- Look for not empty path 5551 if ($p_dir != "") { 5552 // ----- Explode path by directory names 5553 $v_list = explode("/", $p_dir); 5554 5555 // ----- Study directories from last to first 5556 $v_skip = 0; 5557 for ($i=sizeof($v_list)-1; $i>=0; $i--) { 5558 // ----- Look for current path 5559 if ($v_list[$i] == ".") { 5560 // ----- Ignore this directory 5561 // Should be the first $i=0, but no check is done 5562 } 5563 else if ($v_list[$i] == "..") { 5564 $v_skip++; 5565 } 5566 else if ($v_list[$i] == "") { 5567 // ----- First '/' i.e. root slash 5568 if ($i == 0) { 5569 $v_result = "/".$v_result; 5570 if ($v_skip > 0) { 5571 // ----- It is an invalid path, so the path is not modified 5572 // TBC 5573 $v_result = $p_dir; 5574 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged"); 5575 $v_skip = 0; 5576 } 5577 } 5578 // ----- Last '/' i.e. indicates a directory 5579 else if ($i == (sizeof($v_list)-1)) { 5580 $v_result = $v_list[$i]; 5581 } 5582 // ----- Double '/' inside the path 5583 else { 5584 // ----- Ignore only the double '//' in path, 5585 // but not the first and last '/' 5586 } 5587 } 5588 else { 5589 // ----- Look for item to skip 5590 if ($v_skip > 0) { 5591 $v_skip--; 5592 } 5593 else { 5594 $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); 5595 } 5596 } 5597 } 5598 5599 // ----- Look for skip 5600 if ($v_skip > 0) { 5601 while ($v_skip > 0) { 5602 $v_result = '../'.$v_result; 5603 $v_skip--; 5604 } 5605 } 5606 } 5607 5608 // ----- Return 5609 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5610 return $v_result; 5611 } 5612 // -------------------------------------------------------------------------------- 5613 5614 // -------------------------------------------------------------------------------- 5615 // Function : PclZipUtilPathInclusion() 5616 // Description : 5617 // This function indicates if the path $p_path is under the $p_dir tree. Or, 5618 // said in an other way, if the file or sub-dir $p_path is inside the dir 5619 // $p_dir. 5620 // The function indicates also if the path is exactly the same as the dir. 5621 // This function supports path with duplicated '/' like '//', but does not 5622 // support '.' or '..' statements. 5623 // Parameters : 5624 // Return Values : 5625 // 0 if $p_path is not inside directory $p_dir 5626 // 1 if $p_path is inside directory $p_dir 5627 // 2 if $p_path is exactly the same as $p_dir 5628 // -------------------------------------------------------------------------------- 5629 function PclZipUtilPathInclusion($p_dir, $p_path) 5630 { 5631 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'"); 5632 $v_result = 1; 5633 5634 // ----- Look for path beginning by ./ 5635 if ( ($p_dir == '.') 5636 || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { 5637 $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); 5638 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'"); 5639 } 5640 if ( ($p_path == '.') 5641 || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { 5642 $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); 5643 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'"); 5644 } 5645 5646 // ----- Explode dir and path by directory separator 5647 $v_list_dir = explode("/", $p_dir); 5648 $v_list_dir_size = sizeof($v_list_dir); 5649 $v_list_path = explode("/", $p_path); 5650 $v_list_path_size = sizeof($v_list_path); 5651 5652 // ----- Study directories paths 5653 $i = 0; 5654 $j = 0; 5655 while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { 5656 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'"); 5657 5658 // ----- Look for empty dir (path reduction) 5659 if ($v_list_dir[$i] == '') { 5660 $i++; 5661 continue; 5662 } 5663 if ($v_list_path[$j] == '') { 5664 $j++; 5665 continue; 5666 } 5667 5668 // ----- Compare the items 5669 if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { 5670 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different"); 5671 $v_result = 0; 5672 } 5673 5674 // ----- Next items 5675 $i++; 5676 $j++; 5677 } 5678 5679 // ----- Look if everything seems to be the same 5680 if ($v_result) { 5681 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break"); 5682 // ----- Skip all the empty items 5683 while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; 5684 while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; 5685 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Looking on dir($i)='".($i < $v_list_dir_size?$v_list_dir[$i]:'')."' and path($j)='".($j < $v_list_path_size?$v_list_path[$j]:'')."'"); 5686 5687 if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { 5688 // ----- There are exactly the same 5689 $v_result = 2; 5690 } 5691 else if ($i < $v_list_dir_size) { 5692 // ----- The path is shorter than the dir 5693 $v_result = 0; 5694 } 5695 } 5696 5697 // ----- Return 5698 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5699 return $v_result; 5700 } 5701 // -------------------------------------------------------------------------------- 5702 5703 // -------------------------------------------------------------------------------- 5704 // Function : PclZipUtilCopyBlock() 5705 // Description : 5706 // Parameters : 5707 // $p_mode : read/write compression mode 5708 // 0 : src & dest normal 5709 // 1 : src gzip, dest normal 5710 // 2 : src normal, dest gzip 5711 // 3 : src & dest gzip 5712 // Return Values : 5713 // -------------------------------------------------------------------------------- 5714 function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) 5715 { 5716 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode"); 5717 $v_result = 1; 5718 5719 if ($p_mode==0) 5720 { 5721 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src))); 5722 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest))); 5723 while ($p_size != 0) 5724 { 5725 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 5726 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5727 $v_buffer = @fread($p_src, $v_read_size); 5728 @fwrite($p_dest, $v_buffer, $v_read_size); 5729 $p_size -= $v_read_size; 5730 } 5731 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src))); 5732 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest))); 5733 } 5734 else if ($p_mode==1) 5735 { 5736 while ($p_size != 0) 5737 { 5738 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 5739 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5740 $v_buffer = @gzread($p_src, $v_read_size); 5741 @fwrite($p_dest, $v_buffer, $v_read_size); 5742 $p_size -= $v_read_size; 5743 } 5744 } 5745 else if ($p_mode==2) 5746 { 5747 while ($p_size != 0) 5748 { 5749 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 5750 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5751 $v_buffer = @fread($p_src, $v_read_size); 5752 @gzwrite($p_dest, $v_buffer, $v_read_size); 5753 $p_size -= $v_read_size; 5754 } 5755 } 5756 else if ($p_mode==3) 5757 { 5758 while ($p_size != 0) 5759 { 5760 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 5761 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5762 $v_buffer = @gzread($p_src, $v_read_size); 5763 @gzwrite($p_dest, $v_buffer, $v_read_size); 5764 $p_size -= $v_read_size; 5765 } 5766 } 5767 5768 // ----- Return 5769 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5770 return $v_result; 5771 } 5772 // -------------------------------------------------------------------------------- 5773 5774 // -------------------------------------------------------------------------------- 5775 // Function : PclZipUtilRename() 5776 // Description : 5777 // This function tries to do a simple rename() function. If it fails, it 5778 // tries to copy the $p_src file in a new $p_dest file and then unlink the 5779 // first one. 5780 // Parameters : 5781 // $p_src : Old filename 5782 // $p_dest : New filename 5783 // Return Values : 5784 // 1 on success, 0 on failure. 5785 // -------------------------------------------------------------------------------- 5786 function PclZipUtilRename($p_src, $p_dest) 5787 { 5788 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest"); 5789 $v_result = 1; 5790 5791 // ----- Try to rename the files 5792 if (!@rename($p_src, $p_dest)) { 5793 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink"); 5794 5795 // ----- Try to copy & unlink the src 5796 if (!@copy($p_src, $p_dest)) { 5797 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file"); 5798 $v_result = 0; 5799 } 5800 else if (!@unlink($p_src)) { 5801 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename"); 5802 $v_result = 0; 5803 } 5804 } 5805 5806 // ----- Return 5807 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5808 return $v_result; 5809 } 5810 // -------------------------------------------------------------------------------- 5811 5812 // -------------------------------------------------------------------------------- 5813 // Function : PclZipUtilOptionText() 5814 // Description : 5815 // Translate option value in text. Mainly for debug purpose. 5816 // Parameters : 5817 // $p_option : the option value. 5818 // Return Values : 5819 // The option text value. 5820 // -------------------------------------------------------------------------------- 5821 function PclZipUtilOptionText($p_option) 5822 { 5823 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'"); 5824 5825 $v_list = get_defined_constants(); 5826 for (reset($v_list); $v_key = key($v_list); next($v_list)) { 5827 $v_prefix = substr($v_key, 0, 10); 5828 if (( ($v_prefix == 'PCLZIP_OPT') 5829 || ($v_prefix == 'PCLZIP_CB_') 5830 || ($v_prefix == 'PCLZIP_ATT')) 5831 && ($v_list[$v_key] == $p_option)) { 5832 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key); 5833 return $v_key; 5834 } 5835 } 5836 5837 $v_result = 'Unknown'; 5838 5839 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5840 return $v_result; 5841 } 5842 // -------------------------------------------------------------------------------- 5843 5844 // -------------------------------------------------------------------------------- 5845 // Function : PclZipUtilTranslateWinPath() 5846 // Description : 5847 // Translate windows path by replacing '\' by '/' and optionally removing 5848 // drive letter. 5849 // Parameters : 5850 // $p_path : path to translate. 5851 // $p_remove_disk_letter : true | false 5852 // Return Values : 5853 // The path translated. 5854 // -------------------------------------------------------------------------------- 5855 function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) 5856 { 5857 if (stristr(php_uname(), 'windows')) { 5858 // ----- Look for potential disk letter 5859 if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { 5860 $p_path = substr($p_path, $v_position+1); 5861 } 5862 // ----- Change potential windows directory separator 5863 if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { 5864 $p_path = strtr($p_path, '\\', '/'); 5865 } 5866 } 5867 return $p_path; 5868 } 5869 // -------------------------------------------------------------------------------- 5870 5871 3510 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 3511 $v_buffer = @gzread($p_src, $v_read_size); 3512 @gzwrite($p_dest, $v_buffer, $v_read_size); 3513 $p_size -= $v_read_size; 3514 } 3515 } 3516 3517 return $v_result; 3518 } 3519 3520 function PclZipUtilRename($p_src, $p_dest) 3521 { 3522 $v_result = 1; 3523 3524 if (!@rename($p_src, $p_dest)) { 3525 3526 if (!@copy($p_src, $p_dest)) { 3527 $v_result = 0; 3528 } 3529 else if (!@unlink($p_src)) { 3530 $v_result = 0; 3531 } 3532 } 3533 3534 return $v_result; 3535 } 3536 3537 function PclZipUtilOptionText($p_option) 3538 { 3539 3540 $v_list = get_defined_constants(); 3541 for (reset($v_list); $v_key = key($v_list); next($v_list)) { 3542 $v_prefix = substr($v_key, 0, 10); 3543 if (( ($v_prefix == 'PCLZIP_OPT') 3544 || ($v_prefix == 'PCLZIP_CB_') 3545 || ($v_prefix == 'PCLZIP_ATT')) 3546 && ($v_list[$v_key] == $p_option)) { 3547 return $v_key; 3548 } 3549 } 3550 3551 $v_result = 'Unknown'; 3552 3553 return $v_result; 3554 } 3555 3556 function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) 3557 { 3558 if (stristr(php_uname(), 'windows')) { 3559 if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { 3560 $p_path = substr($p_path, $v_position+1); 3561 } 3562 if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { 3563 $p_path = strtr($p_path, '\\', '/'); 3564 } 3565 } 3566 return $p_path; 3567 } 5872 3568 ?> -
trunk/admin/template/goto/upgrade.tpl
r2819 r2836 13 13 {literal} 14 14 <style type="text/css"> 15 #theHeader { height: 105px; }16 17 15 .content { 18 width: 800px;19 min-height: 0px !important;20 margin: auto;21 padding: 25px;22 text-align: left;16 width: 800px; 17 min-height: 0px !important; 18 margin: auto; 19 padding: 25px; 20 text-align: left; 23 21 } 24 22 25 h2 { width: 770px !important; } 23 table { margin: 0px; } 24 td { padding: 3px 10px; } 26 25 </style> 27 26 {/literal} … … 37 36 <h2>Piwigo {$RELEASE} - {'Upgrade'|@translate}</h2> 38 37 39 <p>{'language'|@translate} 40 <select name="language" onchange="document.location = 'upgrade.php?language='+this.options[this.selectedIndex].value;"> 41 {html_options options=$language_options selected=$language_selection} 42 </select> 43 </p> 38 {if isset($errors)} 39 <div class="errors"> 40 <ul> 41 {foreach from=$errors item=error} 42 <li>{$error}</li> 43 {/foreach} 44 </ul> 45 </div> 46 {/if} 47 48 <table> 49 <tr> 50 <td>{'language'|@translate}</td> 51 <td> 52 <select name="language" onchange="document.location = 'upgrade.php?language='+this.options[this.selectedIndex].value;"> 53 {html_options options=$language_options selected=$language_selection} 54 </select> 55 </td> 56 </tr> 57 </table> 44 58 45 59 <p>{'introduction message'|@translate|@sprintf:$introduction.CURRENT_RELEASE}</p> 60 {if isset($login)} 61 <p>{'upgrade login message'|@translate}</p> 62 {/if} 63 64 <form method="POST" action="{$introduction.F_ACTION}" name="upgrade_form"> 65 {if isset($login)} 66 <table> 67 <tr> 68 <td>{'Username'|@translate}</td> 69 <td><input type="text" name="username" id="username" size="25" maxlength="40" style="width: 150px;" /></td> 70 </tr> 71 <tr> 72 <td>{'Password'|@translate}</td> 73 <td><input type="password" name="password" id="password" size="25" maxlength="25" style="width: 150px;" /></td> 74 </tr> 75 </table> 76 {/if} 46 77 47 78 <p style="text-align: center;"> 48 < a href="{$introduction.RUN_UPGRADE_URL}">{'Upgrade from %s to %s'|@translate|@sprintf:$introduction.CURRENT_RELEASE:$RELEASE}</b>79 <input class="submit" type="submit" name="submit" value="{'Upgrade from %s to %s'|@translate|@sprintf:$introduction.CURRENT_RELEASE:$RELEASE}"/> 49 80 </p> 81 </form> 82 <!-- 83 <p style="text-align: center;"> 84 <a href="{$introduction.RUN_UPGRADE_URL}">{'Upgrade from %s to %s'|@translate|@sprintf:$introduction.CURRENT_RELEASE:$RELEASE}</a> 85 </p> 86 --> 87 50 88 {/if} 51 89 -
trunk/install/db/65-database.php
r2512 r2836 130 130 while ( $row=mysql_fetch_assoc($result) ) 131 131 { 132 $lang = $row["language"];133 $lang_def = explode('.', $lang );132 $language = $row["language"]; 133 $lang_def = explode('.', $language); 134 134 if ( count($lang_def)==2 ) 135 135 { … … 142 142 $charset = 'iso-8859-1'; 143 143 } 144 $all_langs[$lang ] = array(144 $all_langs[$language] = array( 145 145 'count' => $row['count'], 146 146 'new_lang' => $new_lang, 147 147 'charset' => $charset, 148 148 ); 149 $upgrade_log .= ">>user_lang\t".$lang ."\t".$row['count']."\n";149 $upgrade_log .= ">>user_lang\t".$language."\t".$row['count']."\n"; 150 150 } 151 151 $upgrade_log .= "\n"; -
trunk/install/upgrade_1.3.1.php
r2306 r2836 592 592 <pre style="background-color:lightgray">?></pre> 593 593 insert 594 <pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);< pre>'594 <pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);</pre>' 595 595 ) 596 596 ); -
trunk/install/upgrade_1.7.0.php
r2819 r2836 117 117 118 118 echo '</pre>'; 119 ob_ clean();119 ob_end_clean(); 120 120 121 121 // now we upgrade from 2.0.0 -
trunk/language/de_DE/upgrade.lang.php
r2819 r2836 33 33 $lang['Upgrade informations'] = 'Upgrade informations'; 34 34 $lang['delete upgrade files'] = '[Security] Delete files "upgrade.php", "upgrade_feed.php", "install.php" and "install" directory'; 35 $lang['remove line from mysql.inc.php'] = 'In include/mysql.inc.php, remove:'; 36 $lang['perform a maintenance check'] = 'Perform a maintenance check in [Administration>General>Maintenance] if you encounter any problem.'; 35 $lang['perform a maintenance check'] = 'Perform a maintenance check in [Administration>Specials>Maintenance] if you encounter any problem.'; 37 36 $lang['deactivated plugins'] = 'As a precaution, following plugins have been deactivated. You must check for plugins upgrade before reactiving them:'; 37 $lang['upgrade login message'] = 'Only administrator can run upgrade: please sign in below.'; 38 $lang['You do not have access rights to run upgrade'] = 'You do not have access rights to run upgrade'; 38 39 39 40 ?> -
trunk/language/en_UK/upgrade.lang.php
r2819 r2836 32 32 $lang['Upgrade informations'] = 'Upgrade informations'; 33 33 $lang['delete upgrade files'] = '[Security] Delete files "upgrade.php", "upgrade_feed.php", "install.php" and "install" directory'; 34 $lang['remove line from mysql.inc.php'] = 'In include/mysql.inc.php, remove:'; 35 $lang['perform a maintenance check'] = 'Perform a maintenance check in [Administration>General>Maintenance] if you encounter any problem.'; 34 $lang['perform a maintenance check'] = 'Perform a maintenance check in [Administration>Specials>Maintenance] if you encounter any problem.'; 36 35 $lang['deactivated plugins'] = 'As a precaution, following plugins have been deactivated. You must check for plugins upgrade before reactiving them:'; 36 $lang['upgrade login message'] = 'Only administrator can run upgrade: please sign in below.'; 37 $lang['You do not have access rights to run upgrade'] = 'You do not have access rights to run upgrade'; 37 38 38 39 ?> -
trunk/language/es_ES/upgrade.lang.php
r2822 r2836 32 32 $lang['Upgrade informations'] = 'Informaciones sobre la puesta al día'; 33 33 $lang['delete upgrade files'] = '[Seguridad] Borre los ficheros "upgrade.php", "upgrade_feed.php", "install.php" así como el expediente "install"'; 34 $lang['remove line from mysql.inc.php'] = 'En el fichero include/mysql.inc.php, borre la línea siguiente:';35 34 $lang['perform a maintenance check'] = 'Por favor, efectúes un mantenimiento en [Administración>Especiales>Mantenimiento] si usted encuentra problemas.'; 36 35 $lang['deactivated plugins'] = 'Por precaución, el plugins siguiente han sido desactivados. Verifique si existen unas posturas al día antes de reactivarlas:'; 36 /*TODO*/$lang['upgrade login message'] = 'Only administrator can run upgrade: please sign in below.'; 37 /*TODO*/$lang['You do not have access rights to run upgrade'] = 'You do not have access rights to run upgrade'; 37 38 38 39 ?> -
trunk/language/fr_FR/upgrade.lang.php
r2819 r2836 24 24 $lang['Upgrade'] = 'Mise à jour'; 25 25 $lang['introduction message'] = 'Cette page vous propose de mettre à jour la base de donnée correspondante à votre ancienne version de piwigo vers la nouvelle version. 26 L\'assistant de mise à jour pense la version actuelle est une <strong>version %s</strong> (ou équivalente).'; 26 L\'assistant de mise à jour pense que la version actuelle est une <strong>version %s</strong> (ou équivalente).'; 27 $lang['upgrade login message'] = 'Seul un adminitrateur peut lancer la mise à jour: veuillez vous identifier ci-dessous.'; 27 28 $lang['Upgrade from %s to %s'] = 'Mise à jour de la version %s à %s'; 28 29 $lang['Statistics'] = 'Statistiques'; … … 32 33 $lang['Upgrade informations'] = 'Informations sur la mise à jour'; 33 34 $lang['delete upgrade files'] = '[Sécurité] Effacez les fichiers "upgrade.php", "upgrade_feed.php", "install.php" ainsi que le dossier "install"'; 34 $lang['remove line from mysql.inc.php'] = 'Dans le fichier include/mysql.inc.php, effacez la ligne suivante:';35 35 $lang['perform a maintenance check'] = 'Veuillez effectuer une maintenance dans [Administration>Spéciales>Maintenance] si vous rencontrez des problèmes.'; 36 36 $lang['deactivated plugins'] = 'Par précaution, les plugins suivants ont été désactivés. Vérifiez s\'il existe des mises à jour avant de les réactiver:'; 37 $lang['upgrade login message'] = 'Seul un adminitrateur peut lancer la mise à jour: veuillez vous identifier ci-dessous.'; 38 $lang['You do not have access rights to run upgrade'] = 'Vous n\'avez pas les droits necessaires pour lancer la mise à jour.'; 37 39 38 40 ?> -
trunk/language/it_IT/upgrade.lang.php
r2819 r2836 26 26 $lang['introduction message'] = 'This page proposes to upgrade your database corresponding to your old version of Piwigo to the current version. 27 27 The upgrade assistant thinks you are currently running a <strong>release %s</strong> (or equivalent).'; 28 $lang['upgrade login message'] = 'Only administrator can run upgrade: please sign in below.'; 28 29 $lang['Upgrade from %s to %s'] = 'Upgrade from version %s to %s'; 29 30 $lang['Statistics'] = 'Statistics'; … … 33 34 $lang['Upgrade informations'] = 'Upgrade informations'; 34 35 $lang['delete upgrade files'] = '[Security] Delete files "upgrade.php", "upgrade_feed.php", "install.php" and "install" directory'; 35 $lang['remove line from mysql.inc.php'] = 'In include/mysql.inc.php, remove:'; 36 $lang['perform a maintenance check'] = 'Perform a maintenance check in [Administration>General>Maintenance] if you encounter any problem.'; 36 $lang['perform a maintenance check'] = 'Perform a maintenance check in [Administration>Specials>Maintenance] if you encounter any problem.'; 37 37 $lang['deactivated plugins'] = 'As a precaution, following plugins have been deactivated. You must check for plugins upgrade before reactiving them:'; 38 $lang['upgrade login message'] = 'Only administrator can run upgrade: please sign in below.'; 39 $lang['You do not have access rights to run upgrade'] = 'You do not have access rights to run upgrade'; 38 40 39 41 ?> -
trunk/language/nl_NL/upgrade.lang.php
r2819 r2836 26 26 $lang['introduction message'] = 'This page proposes to upgrade your database corresponding to your old version of Piwigo to the current version. 27 27 The upgrade assistant thinks you are currently running a <strong>release %s</strong> (or equivalent).'; 28 $lang['upgrade login message'] = 'Only administrator can run upgrade: please sign in below.'; 28 29 $lang['Upgrade from %s to %s'] = 'Upgrade from version %s to %s'; 29 30 $lang['Statistics'] = 'Statistics'; … … 33 34 $lang['Upgrade informations'] = 'Upgrade informations'; 34 35 $lang['delete upgrade files'] = '[Security] Delete files "upgrade.php", "upgrade_feed.php", "install.php" and "install" directory'; 35 $lang['remove line from mysql.inc.php'] = 'In include/mysql.inc.php, remove:'; 36 $lang['perform a maintenance check'] = 'Perform a maintenance check in [Administration>General>Maintenance] if you encounter any problem.'; 36 $lang['perform a maintenance check'] = 'Perform a maintenance check in [Administration>Specials>Maintenance] if you encounter any problem.'; 37 37 $lang['deactivated plugins'] = 'As a precaution, following plugins have been deactivated. You must check for plugins upgrade before reactiving them:'; 38 $lang['upgrade login message'] = 'Only administrator can run upgrade: please sign in below.'; 39 $lang['You do not have access rights to run upgrade'] = 'You do not have access rights to run upgrade'; 38 40 39 41 ?> -
trunk/upgrade.php
r2819 r2836 30 30 define('PHPWG_ROOT_PATH', './'); 31 31 32 if (!file_exists(PHPWG_ROOT_PATH.'include/mysql.inc.php')) 33 { 34 die('Could not find include/mysql.inc.php file.'); 35 } 36 32 37 include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); 33 38 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); … … 37 42 include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); 38 43 @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); 39 40 check_upgrade();41 44 42 45 prepare_conf_upgrade(); … … 54 57 } 55 58 56 // +-----------------------------------------------------------------------+57 // | tricky output |58 // +-----------------------------------------------------------------------+59 echo '<!-- This is an HTML comment given in order to make IE outputs';60 echo ' the code.'."\n";61 echo ' Indeed, IE doesn\'t start to send output until a limit';62 echo ' of XXX bytes '."\n";63 echo str_repeat( ' ', 80 )."\n";64 echo str_repeat( ' ', 80 )."\n";65 echo str_repeat( ' ', 80 )."\n";66 echo '-->'."\n";67 flush();68 59 // +-----------------------------------------------------------------------+ 69 60 // | functions | … … 169 160 } 170 161 171 load_language( 'common.lang', '', array('language'=>$language, 'target_charset'=>'utf-8' ) );172 load_language( 'admin.lang', '', array('language'=>$language, 'target_charset'=>'utf-8' ) );173 load_language( 'upgrade.lang', '', array('language'=>$language, 'target_charset'=>'utf-8' ) );162 load_language( 'common.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); 163 load_language( 'admin.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); 164 load_language( 'upgrade.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) ); 174 165 175 166 // +-----------------------------------------------------------------------+ … … 181 172 $template->assign('RELEASE', PHPWG_VERSION); 182 173 183 foreach (get_languages('utf-8') as $language_code => $language_name)184 {185 if ($language == $language_code)186 {187 $template->assign('language_selection', $language_code);188 }189 $languages_options[$language_code] = $language_name;190 }191 $template->assign('language_options', $languages_options);192 193 174 // +-----------------------------------------------------------------------+ 194 175 // | upgrade choice | … … 198 179 $columns_of = get_columns_of($tables); 199 180 200 if (!isset($_GET['version'])) 201 { 202 // find the current release 203 if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) 204 { 205 // we're in branch 1.3, important upgrade, isn't it? 206 if (in_array(PREFIX_TABLE.'user_category', $tables)) 207 { 208 $current_release = '1.3.1'; 209 } 210 else 211 { 212 $current_release = '1.3.0'; 213 } 214 } 215 else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) 216 { 217 $current_release = '1.4.0'; 218 } 219 else if (!in_array(PREFIX_TABLE.'tags', $tables)) 220 { 221 $current_release = '1.5.0'; 222 } 223 else if ( !in_array(PREFIX_TABLE.'history_summary', $tables) ) 224 { 225 if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) 226 { 227 $current_release = '1.6.0'; 228 } 229 else 230 { 231 $current_release = '1.6.2'; 232 } 233 } 234 else if (!in_array('md5sum', $columns_of[PREFIX_TABLE.'images'])) 235 { 236 $current_release = '1.7.0'; 181 // find the current release 182 if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) 183 { 184 // we're in branch 1.3, important upgrade, isn't it? 185 if (in_array(PREFIX_TABLE.'user_category', $tables)) 186 { 187 $current_release = '1.3.1'; 237 188 } 238 189 else 239 190 { 240 die('No upgrade required, the database structure is up to date'); 241 } 242 243 $template->assign( 244 'introduction', 245 array( 246 'CURRENT_RELEASE' => $current_release, 247 'RUN_UPGRADE_URL' => 248 PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release.'&language='.$language, 249 ) 250 ); 191 $current_release = '1.3.0'; 192 } 193 } 194 else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) 195 { 196 $current_release = '1.4.0'; 197 } 198 else if (!in_array(PREFIX_TABLE.'tags', $tables)) 199 { 200 $current_release = '1.5.0'; 201 } 202 else if ( !in_array(PREFIX_TABLE.'history_summary', $tables) ) 203 { 204 if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) 205 { 206 $current_release = '1.6.0'; 207 } 208 else 209 { 210 $current_release = '1.6.2'; 211 } 212 } 213 else if (!in_array('md5sum', $columns_of[PREFIX_TABLE.'images'])) 214 { 215 $current_release = '1.7.0'; 216 } 217 else 218 { 219 die('No upgrade required, the database structure is up to date'); 251 220 } 252 221 … … 254 223 // | upgrade launch | 255 224 // +-----------------------------------------------------------------------+ 256 257 else 258 { 259 if (in_array('md5sum', $columns_of[PREFIX_TABLE.'images'])) 260 { 261 die('No database upgrade required, do not refresh the page'); 262 } 263 264 $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php'; 225 $page['infos'] = array(); 226 $page['errors'] = array(); 227 228 if (isset($_POST['username']) and isset($_POST['password'])) 229 { 230 check_upgrade_access_rights($current_release, $_POST['username'], $_POST['password']); 231 } 232 233 if (isset($_POST['submit']) and check_upgrade()) 234 { 235 $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$current_release.'.php'; 265 236 if (is_file($upgrade_file)) 266 237 { 267 $page['infos'] = array();268 238 $page['upgrade_start'] = get_moment(); 269 239 $conf['die_on_sql_error'] = false; … … 284 254 'upgrade', 285 255 array( 286 'VERSION' => $ _GET['version'],256 'VERSION' => $current_release, 287 257 'TOTAL_TIME' => get_elapsed_time( 288 258 $page['upgrade_start'], … … 301 271 array_push($page['infos'], 302 272 l10n('delete upgrade files'), 303 l10n('remove line from mysql.inc.php') . '<pre>define(\'PHPWG_IN_UPGRADE\', true);</pre>',304 273 l10n('perform a maintenance check') 305 274 ); 306 307 $template->assign('infos', $page['infos']);308 275 309 276 invalidate_user_cache(); … … 318 285 pwg_query($query); 319 286 } 320 else 321 { 322 die('Hacking attempt'); 323 } 287 } 288 289 // +-----------------------------------------------------------------------+ 290 // | start template output | 291 // +-----------------------------------------------------------------------+ 292 else 293 { 294 foreach (get_languages('utf-8') as $language_code => $language_name) 295 { 296 if ($language == $language_code) 297 { 298 $template->assign('language_selection', $language_code); 299 } 300 $languages_options[$language_code] = $language_name; 301 } 302 $template->assign('language_options', $languages_options); 303 304 $template->assign('introduction', array( 305 'CURRENT_RELEASE' => $current_release, 306 'F_ACTION' => 'upgrade.php?language=' . $language)); 307 308 if (!check_upgrade()) 309 { 310 $template->assign('login', true); 311 } 312 } 313 314 if (count($page['errors']) != 0) 315 { 316 $template->assign('errors', $page['errors']); 317 } 318 319 if (count($page['infos']) != 0) 320 { 321 $template->assign('infos', $page['infos']); 324 322 } 325 323
Note: See TracChangeset
for help on using the changeset viewer.