root/releases/elgg0.8rc2/lib/pclzip/pclzip.lib.php
| Revision 269, 223.4 kB (checked in by ben, 3 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | <?php |
| 2 | // -------------------------------------------------------------------------------- |
| 3 | // PhpConcept Library - Zip Module 2.4 |
| 4 | // -------------------------------------------------------------------------------- |
| 5 | // License GNU/LGPL - Vincent Blavet - November 2004 |
| 6 | // http://www.phpconcept.net |
| 7 | // -------------------------------------------------------------------------------- |
| 8 | // |
| 9 | // Presentation : |
| 10 | // PclZip is a PHP library that manage ZIP archives. |
| 11 | // So far tests show that archives generated by PclZip are readable by |
| 12 | // WinZip application and other tools. |
| 13 | // |
| 14 | // Description : |
| 15 | // See readme.txt and http://www.phpconcept.net |
| 16 | // |
| 17 | // Warning : |
| 18 | // This library and the associated files are non commercial, non professional |
| 19 | // work. |
| 20 | // It should not have unexpected results. However if any damage is caused by |
| 21 | // this software the author can not be responsible. |
| 22 | // The use of this software is at the risk of the user. |
| 23 | // |
| 24 | // -------------------------------------------------------------------------------- |
| 25 | // $Id: pclzip.lib.php,v 1.11 2005/10/15 09:58:36 stronk7 Exp $ |
| 26 | // -------------------------------------------------------------------------------- |
| 27 | |
| 28 | // ----- Constants |
| 29 | define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); |
| 30 | |
| 31 | // ----- File list separator |
| 32 | // In version 1.x of PclZip, the separator for file list is a space |
| 33 | // (which is not a very smart choice, specifically for windows paths !). |
| 34 | // A better separator should be a comma (,). This constant gives you the |
| 35 | // abilty to change that. |
| 36 | // However notice that changing this value, may have impact on existing |
| 37 | // scripts, using space separated filenames. |
| 38 | // Recommanded values for compatibility with older versions : |
| 39 | //define( 'PCLZIP_SEPARATOR', ' ' ); |
| 40 | // Recommanded values for smart separation of filenames. |
| 41 | define( 'PCLZIP_SEPARATOR', ',' ); |
| 42 | |
| 43 | // ----- Error configuration |
| 44 | // 0 : PclZip Class integrated error handling |
| 45 | // 1 : PclError external library error handling. By enabling this |
| 46 | // you must ensure that you have included PclError library. |
| 47 | // [2,...] : reserved for futur use |
| 48 | define( 'PCLZIP_ERROR_EXTERNAL', 0 ); |
| 49 | |
| 50 | // ----- Optional static temporary directory |
| 51 | // By default temporary files are generated in the script current |
| 52 | // path. |
| 53 | // If defined : |
| 54 | // - MUST BE terminated by a '/'. |
| 55 | // - MUST be a valid, already created directory |
| 56 | // Samples : |
| 57 | // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); |
| 58 | // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); |
| 59 | define( 'PCLZIP_TEMPORARY_DIR', '' ); |
| 60 | |
| 61 | // -------------------------------------------------------------------------------- |
| 62 | // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED ***** |
| 63 | // -------------------------------------------------------------------------------- |
| 64 | |
| 65 | // ----- Global variables |
| 66 | $g_pclzip_version = "2.4"; |
| 67 | |
| 68 | // ----- Error codes |
| 69 | // -1 : Unable to open file in binary write mode |
| 70 | // -2 : Unable to open file in binary read mode |
| 71 | // -3 : Invalid parameters |
| 72 | // -4 : File does not exist |
| 73 | // -5 : Filename is too long (max. 255) |
| 74 | // -6 : Not a valid zip file |
| 75 | // -7 : Invalid extracted file size |
| 76 | // -8 : Unable to create directory |
| 77 | // -9 : Invalid archive extension |
| 78 | // -10 : Invalid archive format |
| 79 | // -11 : Unable to delete file (unlink) |
| 80 | // -12 : Unable to rename file (rename) |
| 81 | // -13 : Invalid header checksum |
| 82 | // -14 : Invalid archive size |
| 83 | define( 'PCLZIP_ERR_USER_ABORTED', 2 ); |
| 84 | define( 'PCLZIP_ERR_NO_ERROR', 0 ); |
| 85 | define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); |
| 86 | define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); |
| 87 | define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); |
| 88 | define( 'PCLZIP_ERR_MISSING_FILE', -4 ); |
| 89 | define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); |
| 90 | define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); |
| 91 | define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); |
| 92 | define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); |
| 93 | define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); |
| 94 | define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); |
| 95 | define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); |
| 96 | define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); |
| 97 | define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); |
| 98 | define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); |
| 99 | define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); |
| 100 | define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); |
| 101 | define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); |
| 102 | define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); |
| 103 | define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); |
| 104 | |
| 105 | // ----- Options values |
| 106 | define( 'PCLZIP_OPT_PATH', 77001 ); |
| 107 | define( 'PCLZIP_OPT_ADD_PATH', 77002 ); |
| 108 | define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); |
| 109 | define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); |
| 110 | define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); |
| 111 | define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); |
| 112 | define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); |
| 113 | define( 'PCLZIP_OPT_BY_NAME', 77008 ); |
| 114 | define( 'PCLZIP_OPT_BY_INDEX', 77009 ); |
| 115 | define( 'PCLZIP_OPT_BY_EREG', 77010 ); |
| 116 | define( 'PCLZIP_OPT_BY_PREG', 77011 ); |
| 117 | define( 'PCLZIP_OPT_COMMENT', 77012 ); |
| 118 | define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); |
| 119 | define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); |
| 120 | define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); |
| 121 | define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); |
| 122 | define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); |
| 123 | // Having big trouble with crypt. Need to multiply 2 long int |
| 124 | // which is not correctly supported by PHP ... |
| 125 | //define( 'PCLZIP_OPT_CRYPT', 77018 ); |
| 126 | |
| 127 | // ----- Call backs values |
| 128 | define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); |
| 129 | define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); |
| 130 | define( 'PCLZIP_CB_PRE_ADD', 78003 ); |
| 131 | define( 'PCLZIP_CB_POST_ADD', 78004 ); |
| 132 | /* For futur use |
| 133 | define( 'PCLZIP_CB_PRE_LIST', 78005 ); |
| 134 | define( 'PCLZIP_CB_POST_LIST', 78006 ); |
| 135 | define( 'PCLZIP_CB_PRE_DELETE', 78007 ); |
| 136 | define( 'PCLZIP_CB_POST_DELETE', 78008 ); |
| 137 | */ |
| 138 | |
| 139 | // -------------------------------------------------------------------------------- |
| 140 | // Class : PclZip |
| 141 | // Description : |
| 142 | // PclZip is the class that represent a Zip archive. |
| 143 | // The public methods allow the manipulation of the archive. |
| 144 | // Attributes : |
| 145 | // Attributes must not be accessed directly. |
| 146 | // Methods : |
| 147 | // PclZip() : Object creator |
| 148 | // create() : Creates the Zip archive |
| 149 | // listContent() : List the content of the Zip archive |
| 150 | // extract() : Extract the content of the archive |
| 151 | // properties() : List the properties of the archive |
| 152 | // -------------------------------------------------------------------------------- |
| 153 | class PclZip |
| 154 | { |
| 155 | // ----- Filename of the zip file |
| 156 | var $zipname = ''; |
| 157 | |
| 158 | // ----- File descriptor of the zip file |
| 159 | var $zip_fd = 0; |
| 160 | |
| 161 | // ----- Internal error handling |
| 162 | var $error_code = 1; |
| 163 | var $error_string = ''; |
| 164 | |
| 165 | // ----- Current status of the magic_quotes_runtime |
| 166 | // This value store the php configuration for magic_quotes |
| 167 | // The class can then disable the magic_quotes and reset it after |
| 168 | var $magic_quotes_status; |
| 169 | |
| 170 | // -------------------------------------------------------------------------------- |
| 171 | // Function : PclZip() |
| 172 | // Description : |
| 173 | // Creates a PclZip object and set the name of the associated Zip archive |
| 174 | // filename. |
| 175 | // Note that no real action is taken, if the archive does not exist it is not |
| 176 | // created. Use create() for that. |
| 177 | // -------------------------------------------------------------------------------- |
| 178 | function PclZip($p_zipname) |
| 179 | { |
| 180 | //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname"); |
| 181 | |
| 182 | // ----- Tests the zlib |
| 183 | if (!function_exists('gzopen')) |
| 184 | { |
| 185 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing"); |
| 186 | die('Abort '.basename(__FILE__).' : Missing zlib extensions'); |
| 187 | } |
| 188 | |
| 189 | // ----- Set the attributes |
| 190 | $this->zipname = $p_zipname; |
| 191 | $this->zip_fd = 0; |
| 192 | $this->magic_quotes_status = -1; |
| 193 | |
| 194 | // ----- Return |
| 195 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1); |
| 196 | return; |
| 197 | } |
| 198 | // -------------------------------------------------------------------------------- |
| 199 | |
| 200 | // -------------------------------------------------------------------------------- |
| 201 | // Function : |
| 202 | // create($p_filelist, $p_add_dir="", $p_remove_dir="") |
| 203 | // create($p_filelist, $p_option, $p_option_value, ...) |
| 204 | // Description : |
| 205 | // This method supports two different synopsis. The first one is historical. |
| 206 | // This method creates a Zip Archive. The Zip file is created in the |
| 207 | // filesystem. The files and directories indicated in $p_filelist |
| 208 | // are added in the archive. See the parameters description for the |
| 209 | // supported format of $p_filelist. |
| 210 | // When a directory is in the list, the directory and its content is added |
| 211 | // in the archive. |
| 212 | // In this synopsis, the function takes an optional variable list of |
| 213 | // options. See bellow the supported options. |
| 214 | // Parameters : |
| 215 | // $p_filelist : An array containing file or directory names, or |
| 216 | // a string containing one filename or one directory name, or |
| 217 | // a string containing a list of filenames and/or directory |
| 218 | // names separated by spaces. |
| 219 | // $p_add_dir : A path to add before the real path of the archived file, |
| 220 | // in order to have it memorized in the archive. |
| 221 | // $p_remove_dir : A path to remove from the real path of the file to archive, |
| 222 | // in order to have a shorter path memorized in the archive. |
| 223 | // When $p_add_dir and $p_remove_dir are set, $p_remove_dir |
| 224 | // is removed first, before $p_add_dir is added. |
| 225 | // Options : |
| 226 | // PCLZIP_OPT_ADD_PATH : |
| 227 | // PCLZIP_OPT_REMOVE_PATH : |
| 228 | // PCLZIP_OPT_REMOVE_ALL_PATH : |
| 229 | // PCLZIP_OPT_COMMENT : |
| 230 | // PCLZIP_CB_PRE_ADD : |
| 231 | // PCLZIP_CB_POST_ADD : |
| 232 | // Return Values : |
| 233 | // 0 on failure, |
| 234 | // The list of the added files, with a status of the add action. |
| 235 | // (see PclZip::listContent() for list entry format) |
| 236 | // -------------------------------------------------------------------------------- |
| 237 | // function create($p_filelist, $p_add_dir="", $p_remove_dir="") |
| 238 | function create($p_filelist /*, options */) |
| 239 | { |
| 240 | //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ..."); |
| 241 | $v_result=1; |
| 242 | |
| 243 | // ----- Reset the error handler |
| 244 | $this->privErrorReset(); |
| 245 | |
| 246 | // ----- Set default values |
| 247 | $v_options = array(); |
| 248 | $v_add_path = ""; |
| 249 | $v_remove_path = ""; |
| 250 | $v_remove_all_path = false; |
| 251 | $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; |
| 252 | |
| 253 | // ----- Look for variable options arguments |
| 254 | $v_size = func_num_args(); |
| 255 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); |
| 256 | |
| 257 | // ----- Look for arguments |
| 258 | if ($v_size > 1) { |
| 259 | // ----- Get the arguments |
| 260 | $v_arg_list = &func_get_args(); |
| 261 | |
| 262 | // ----- Remove form the options list the first argument |
| 263 | array_shift($v_arg_list); |
| 264 | $v_size--; |
| 265 | |
| 266 | // ----- Look for first arg |
| 267 | if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
| 268 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); |
| 269 | |
| 270 | // ----- Parse the options |
| 271 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 272 | array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
| 273 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 274 | PCLZIP_OPT_ADD_PATH => 'optional', |
| 275 | PCLZIP_CB_PRE_ADD => 'optional', |
| 276 | PCLZIP_CB_POST_ADD => 'optional', |
| 277 | PCLZIP_OPT_NO_COMPRESSION => 'optional', |
| 278 | PCLZIP_OPT_COMMENT => 'optional' |
| 279 | //, PCLZIP_OPT_CRYPT => 'optional' |
| 280 | )); |
| 281 | if ($v_result != 1) { |
| 282 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | // ----- Set the arguments |
| 287 | if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
| 288 | $v_add_path = $v_options[PCLZIP_OPT_ADD_PATH]; |
| 289 | } |
| 290 | if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
| 291 | $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
| 292 | } |
| 293 | if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
| 294 | $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // ----- Look for 2 args |
| 299 | // Here we need to support the first historic synopsis of the |
| 300 | // method. |
| 301 | else { |
| 302 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); |
| 303 | |
| 304 | // ----- Get the first argument |
| 305 | $v_add_path = $v_arg_list[0]; |
| 306 | |
| 307 | // ----- Look for the optional second argument |
| 308 | if ($v_size == 2) { |
| 309 | $v_remove_path = $v_arg_list[1]; |
| 310 | } |
| 311 | else if ($v_size > 2) { |
| 312 | // ----- Error log |
| 313 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
| 314 | "Invalid number / type of arguments"); |
| 315 | |
| 316 | // ----- Return |
| 317 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
| 318 | return 0; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // ----- Trace |
| 324 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "add_path='$v_add_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_all_path?'true':'false')."'"); |
| 325 | |
| 326 | // ----- Look if the $p_filelist is really an array |
| 327 | $p_result_list = array(); |
| 328 | if (is_array($p_filelist)) |
| 329 | { |
| 330 | // ----- Call the create fct |
| 331 | $v_result = $this->privCreate($p_filelist, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options); |
| 332 | } |
| 333 | |
| 334 | // ----- Look if the $p_filelist is a string |
| 335 | else if (is_string($p_filelist)) |
| 336 | { |
| 337 | // ----- Create a list with the elements from the string |
| 338 | $v_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
| 339 | |
| 340 | // ----- Call the create fct |
| 341 | $v_result = $this->privCreate($v_list, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options); |
| 342 | } |
| 343 | |
| 344 | // ----- Invalid variable |
| 345 | else |
| 346 | { |
| 347 | // ----- Error log |
| 348 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); |
| 349 | $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
| 350 | } |
| 351 | |
| 352 | if ($v_result != 1) |
| 353 | { |
| 354 | // ----- Return |
| 355 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | // ----- Return |
| 360 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); |
| 361 | return $p_result_list; |
| 362 | } |
| 363 | // -------------------------------------------------------------------------------- |
| 364 | |
| 365 | // -------------------------------------------------------------------------------- |
| 366 | // Function : |
| 367 | // add($p_filelist, $p_add_dir="", $p_remove_dir="") |
| 368 | // add($p_filelist, $p_option, $p_option_value, ...) |
| 369 | // Description : |
| 370 | // This method supports two synopsis. The first one is historical. |
| 371 | // This methods add the list of files in an existing archive. |
| 372 | // If a file with the same name already exists, it is added at the end of the |
| 373 | // archive, the first one is still present. |
| 374 | // If the archive does not exist, it is created. |
| 375 | // Parameters : |
| 376 | // $p_filelist : An array containing file or directory names, or |
| 377 | // a string containing one filename or one directory name, or |
| 378 | // a string containing a list of filenames and/or directory |
| 379 | // names separated by spaces. |
| 380 | // $p_add_dir : A path to add before the real path of the archived file, |
| 381 | // in order to have it memorized in the archive. |
| 382 | // $p_remove_dir : A path to remove from the real path of the file to archive, |
| 383 | // in order to have a shorter path memorized in the archive. |
| 384 | // When $p_add_dir and $p_remove_dir are set, $p_remove_dir |
| 385 | // is removed first, before $p_add_dir is added. |
| 386 | // Options : |
| 387 | // PCLZIP_OPT_ADD_PATH : |
| 388 | // PCLZIP_OPT_REMOVE_PATH : |
| 389 | // PCLZIP_OPT_REMOVE_ALL_PATH : |
| 390 | // PCLZIP_OPT_COMMENT : |
| 391 | // PCLZIP_OPT_ADD_COMMENT : |
| 392 | // PCLZIP_OPT_PREPEND_COMMENT : |
| 393 | // PCLZIP_CB_PRE_ADD : |
| 394 | // PCLZIP_CB_POST_ADD : |
| 395 | // Return Values : |
| 396 | // 0 on failure, |
| 397 | // The list of the added files, with a status of the add action. |
| 398 | // (see PclZip::listContent() for list entry format) |
| 399 | // -------------------------------------------------------------------------------- |
| 400 | // function add($p_filelist, $p_add_dir="", $p_remove_dir="") |
| 401 | function add($p_filelist /* options */) |
| 402 | { |
| 403 | //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ..."); |
| 404 | $v_result=1; |
| 405 | |
| 406 | // ----- Reset the error handler |
| 407 | $this->privErrorReset(); |
| 408 | |
| 409 | // ----- Set default values |
| 410 | $v_options = array(); |
| 411 | $v_add_path = ""; |
| 412 | $v_remove_path = ""; |
| 413 | $v_remove_all_path = false; |
| 414 | $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; |
| 415 | |
| 416 | // ----- Look for variable options arguments |
| 417 | $v_size = func_num_args(); |
| 418 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); |
| 419 | |
| 420 | // ----- Look for arguments |
| 421 | if ($v_size > 1) { |
| 422 | // ----- Get the arguments |
| 423 | $v_arg_list = &func_get_args(); |
| 424 | |
| 425 | // ----- Remove form the options list the first argument |
| 426 | array_shift($v_arg_list); |
| 427 | $v_size--; |
| 428 | |
| 429 | // ----- Look for first arg |
| 430 | if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
| 431 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); |
| 432 | |
| 433 | // ----- Parse the options |
| 434 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 435 | array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
| 436 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 437 | PCLZIP_OPT_ADD_PATH => 'optional', |
| 438 | PCLZIP_CB_PRE_ADD => 'optional', |
| 439 | PCLZIP_CB_POST_ADD => 'optional', |
| 440 | PCLZIP_OPT_NO_COMPRESSION => 'optional', |
| 441 | PCLZIP_OPT_COMMENT => 'optional', |
| 442 | PCLZIP_OPT_ADD_COMMENT => 'optional', |
| 443 | PCLZIP_OPT_PREPEND_COMMENT => 'optional' |
| 444 | //, PCLZIP_OPT_CRYPT => 'optional' |
| 445 | )); |
| 446 | if ($v_result != 1) { |
| 447 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | // ----- Set the arguments |
| 452 | if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
| 453 | $v_add_path = $v_options[PCLZIP_OPT_ADD_PATH]; |
| 454 | } |
| 455 | if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
| 456 | $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
| 457 | } |
| 458 | if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
| 459 | $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // ----- Look for 2 args |
| 464 | // Here we need to support the first historic synopsis of the |
| 465 | // method. |
| 466 | else { |
| 467 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); |
| 468 | |
| 469 | // ----- Get the first argument |
| 470 | $v_add_path = $v_arg_list[0]; |
| 471 | |
| 472 | // ----- Look for the optional second argument |
| 473 | if ($v_size == 2) { |
| 474 | $v_remove_path = $v_arg_list[1]; |
| 475 | } |
| 476 | else if ($v_size > 2) { |
| 477 | // ----- Error log |
| 478 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
| 479 | |
| 480 | // ----- Return |
| 481 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
| 482 | return 0; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | // ----- Trace |
| 488 | //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "add_path='$v_add_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_all_path?'true':'false')."'"); |
| 489 | |
| 490 | // ----- Look if the $p_filelist is really an array |
| 491 | $p_result_list = array(); |
| 492 | if (is_array($p_filelist)) |
| 493 | { |
| 494 | // ----- Call the create fct |
| 495 | $v_result = $this->privAdd($p_filelist, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options); |
| 496 | } |
| 497 | |
| 498 | // ----- Look if the $p_filelist is a string |
| 499 | else if (is_string($p_filelist)) |
| 500 | { |
| 501 | // ----- Create a list with the elements from the string |
| 502 | $v_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
| 503 | |
| 504 | // ----- Call the create fct |
| 505 | $v_result = $this->privAdd($v_list, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options); |
| 506 | } |
| 507 | |
| 508 | // ----- Invalid variable |
| 509 | else |
| 510 | { |
| 511 | // ----- Error log |
| 512 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); |
| 513 | $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
| 514 | } |
| 515 | |
| 516 | if ($v_result != 1) |
| 517 | { |
| 518 | // ----- Return |
| 519 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | // ----- Return |
| 524 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); |
| 525 | return $p_result_list; |
| 526 | } |
| 527 | // -------------------------------------------------------------------------------- |
| 528 | |
| 529 | // -------------------------------------------------------------------------------- |
| 530 | // Function : listContent() |
| 531 | // Description : |
| 532 | // This public method, gives the list of the files and directories, with their |
| 533 | // properties. |
| 534 | // The properties of each entries in the list are (used also in other functions) : |
| 535 | // filename : Name of the file. For a create or add action it is the filename |
| 536 | // given by the user. For an extract function it is the filename |
| 537 | // of the extracted file. |
| 538 | // stored_filename : Name of the file / directory stored in the archive. |
| 539 | // size : Size of the stored file. |
| 540 | // compressed_size : Size of the file's data compressed in the archive |
| 541 | // (without the headers overhead) |
| 542 | // mtime : Last known modification date of the file (UNIX timestamp) |
| 543 | // comment : Comment associated with the file |
| 544 | // folder : true | false |
| 545 | // index : index of the file in the archive |
| 546 | // status : status of the action (depending of the action) : |
| 547 | // Values are : |
| 548 | // ok : OK ! |
| 549 | // filtered : the file / dir is not extracted (filtered by user) |
| 550 | // already_a_directory : the file can not be extracted because a |
| 551 | // directory with the same name already exists |
| 552 | // write_protected : the file can not be extracted because a file |
| 553 | // with the same name already exists and is |
| 554 | // write protected |
| 555 | // newer_exist : the file was not extracted because a newer file exists |
| 556 | // path_creation_fail : the file is not extracted because the folder |
| 557 | // does not exists and can not be created |
| 558 | // write_error : the file was not extracted because there was a |
| 559 | // error while writing the file |
| 560 | // read_error : the file was not extracted because there was a error |
| 561 | // while reading the file |
| 562 | // invalid_header : the file was not extracted because of an archive |
| 563 | // format error (bad file header) |
| 564 | // Note that each time a method can continue operating when there |
| 565 | // is an action error on a file, the error is only logged in the file status. |
| 566 | // Return Values : |
| 567 | // 0 on an unrecoverable failure, |
| 568 | // The list of the files in the archive. |
| 569 | // -------------------------------------------------------------------------------- |
| 570 | function listContent() |
| 571 | { |
| 572 | //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', ""); |
| 573 | $v_result=1; |
| 574 | |
| 575 | // ----- Reset the error handler |
| 576 | $this->privErrorReset(); |
| 577 | |
| 578 | // ----- Check archive |
| 579 | if (!$this->privCheckFormat()) { |
| 580 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); |
| 581 | return(0); |
| 582 | } |
| 583 | |
| 584 | // ----- Call the extracting fct |
| 585 | $p_list = array(); |
| 586 | if (($v_result = $this->privList($p_list)) != 1) |
| 587 | { |
| 588 | unset($p_list); |
| 589 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); |
| 590 | return(0); |
| 591 | } |
| 592 | |
| 593 | // ----- Return |
| 594 | //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); |
| 595 | return $p_list; |
| 596 | } |
| 597 | // -------------------------------------------------------------------------------- |
| 598 | |
| 599 | // -------------------------------------------------------------------------------- |
| 600 | // Function : |
| 601 | // extract($p_path="./", $p_remove_path="") |
| 602 | // extract([$p_option, $p_option_value, ...]) |
| 603 | // Description : |
| 604 | // |
