mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * PhpConcept Library - Zip Module 2.5
mp-wp_genesis 4 *
mp-wp_genesis 5 * Presentation :
mp-wp_genesis 6 * PclZip is a PHP library that manage ZIP archives.
mp-wp_genesis 7 * So far tests show that archives generated by PclZip are readable by
mp-wp_genesis 8 * WinZip application and other tools.
mp-wp_genesis 9 *
mp-wp_genesis 10 * Warning :
mp-wp_genesis 11 * This library and the associated files are non commercial, non professional
mp-wp_genesis 12 * work.
mp-wp_genesis 13 * It should not have unexpected results. However if any damage is caused by
mp-wp_genesis 14 * this software the author can not be responsible.
mp-wp_genesis 15 * The use of this software is at the risk of the user.
mp-wp_genesis 16 *
mp-wp_genesis 17 * @package External
mp-wp_genesis 18 * @subpackage PclZip
mp-wp_genesis 19 *
mp-wp_genesis 20 * @license License GNU/LGPL
mp-wp_genesis 21 * @copyright March 2006 Vincent Blavet
mp-wp_genesis 22 * @author Vincent Blavet
mp-wp_genesis 23 * @link http://www.phpconcept.net
mp-wp_genesis 24 * @version $Id: pclzip.lib.php,v 1.44 2006/03/08 21:23:59 vblavet Exp $
mp-wp_genesis 25 */
mp-wp_genesis 26
mp-wp_genesis 27 /**
mp-wp_genesis 28 * The read block size for reading zip files.
mp-wp_genesis 29 *
mp-wp_genesis 30 * @since 2.5
mp-wp_genesis 31 */
mp-wp_genesis 32 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
mp-wp_genesis 33
mp-wp_genesis 34 /**
mp-wp_genesis 35 * File list separator
mp-wp_genesis 36 *
mp-wp_genesis 37 * In version 1.x of PclZip, the separator for file list is a space(which is not
mp-wp_genesis 38 * a very smart choice, specifically for windows paths !). A better separator
mp-wp_genesis 39 * should be a comma (,). This constant gives you the abilty to change that.
mp-wp_genesis 40 *
mp-wp_genesis 41 * However notice that changing this value, may have impact on existing scripts,
mp-wp_genesis 42 * using space separated filenames. Recommanded values for compatibility with
mp-wp_genesis 43 * older versions :
mp-wp_genesis 44 * <code>define( 'PCLZIP_SEPARATOR', ' ' );</code>
mp-wp_genesis 45 * Recommanded values for smart separation of filenames.
mp-wp_genesis 46 */
mp-wp_genesis 47 define( 'PCLZIP_SEPARATOR', ',' );
mp-wp_genesis 48
mp-wp_genesis 49 /**
mp-wp_genesis 50 * Error configuration
mp-wp_genesis 51 *
mp-wp_genesis 52 * 0 : PclZip Class integrated error handling
mp-wp_genesis 53 * 1 : PclError external library error handling. By enabling this you must
mp-wp_genesis 54 * ensure that you have included PclError library.
mp-wp_genesis 55 * [2,...] : reserved for future use
mp-wp_genesis 56 */
mp-wp_genesis 57 define( 'PCLZIP_ERROR_EXTERNAL', 0 );
mp-wp_genesis 58
mp-wp_genesis 59 // ----- Optional static temporary directory
mp-wp_genesis 60 // By default temporary files are generated in the script current
mp-wp_genesis 61 // path.
mp-wp_genesis 62 // If defined :
mp-wp_genesis 63 // - MUST BE terminated by a '/'.
mp-wp_genesis 64 // - MUST be a valid, already created directory
mp-wp_genesis 65 // Samples :
mp-wp_genesis 66 // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
mp-wp_genesis 67 // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
mp-wp_genesis 68 define( 'PCLZIP_TEMPORARY_DIR', '' );
mp-wp_genesis 69
mp-wp_genesis 70 // --------------------------------------------------------------------------------
mp-wp_genesis 71 // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
mp-wp_genesis 72 // --------------------------------------------------------------------------------
mp-wp_genesis 73
mp-wp_genesis 74 // ----- Global variables
mp-wp_genesis 75 $g_pclzip_version = "2.5";
mp-wp_genesis 76
mp-wp_genesis 77 // ----- Error codes
mp-wp_genesis 78 // -1 : Unable to open file in binary write mode
mp-wp_genesis 79 // -2 : Unable to open file in binary read mode
mp-wp_genesis 80 // -3 : Invalid parameters
mp-wp_genesis 81 // -4 : File does not exist
mp-wp_genesis 82 // -5 : Filename is too long (max. 255)
mp-wp_genesis 83 // -6 : Not a valid zip file
mp-wp_genesis 84 // -7 : Invalid extracted file size
mp-wp_genesis 85 // -8 : Unable to create directory
mp-wp_genesis 86 // -9 : Invalid archive extension
mp-wp_genesis 87 // -10 : Invalid archive format
mp-wp_genesis 88 // -11 : Unable to delete file (unlink)
mp-wp_genesis 89 // -12 : Unable to rename file (rename)
mp-wp_genesis 90 // -13 : Invalid header checksum
mp-wp_genesis 91 // -14 : Invalid archive size
mp-wp_genesis 92 define( 'PCLZIP_ERR_USER_ABORTED', 2 );
mp-wp_genesis 93 define( 'PCLZIP_ERR_NO_ERROR', 0 );
mp-wp_genesis 94 define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
mp-wp_genesis 95 define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
mp-wp_genesis 96 define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
mp-wp_genesis 97 define( 'PCLZIP_ERR_MISSING_FILE', -4 );
mp-wp_genesis 98 define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
mp-wp_genesis 99 define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
mp-wp_genesis 100 define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
mp-wp_genesis 101 define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
mp-wp_genesis 102 define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
mp-wp_genesis 103 define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
mp-wp_genesis 104 define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
mp-wp_genesis 105 define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
mp-wp_genesis 106 define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
mp-wp_genesis 107 define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
mp-wp_genesis 108 define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
mp-wp_genesis 109 define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
mp-wp_genesis 110 define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
mp-wp_genesis 111 define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
mp-wp_genesis 112 define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
mp-wp_genesis 113 define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
mp-wp_genesis 114 define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
mp-wp_genesis 115
mp-wp_genesis 116 // ----- Options values
mp-wp_genesis 117 define( 'PCLZIP_OPT_PATH', 77001 );
mp-wp_genesis 118 define( 'PCLZIP_OPT_ADD_PATH', 77002 );
mp-wp_genesis 119 define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
mp-wp_genesis 120 define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
mp-wp_genesis 121 define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
mp-wp_genesis 122 define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
mp-wp_genesis 123 define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
mp-wp_genesis 124 define( 'PCLZIP_OPT_BY_NAME', 77008 );
mp-wp_genesis 125 define( 'PCLZIP_OPT_BY_INDEX', 77009 );
mp-wp_genesis 126 define( 'PCLZIP_OPT_BY_EREG', 77010 );
mp-wp_genesis 127 define( 'PCLZIP_OPT_BY_PREG', 77011 );
mp-wp_genesis 128 define( 'PCLZIP_OPT_COMMENT', 77012 );
mp-wp_genesis 129 define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
mp-wp_genesis 130 define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
mp-wp_genesis 131 define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
mp-wp_genesis 132 define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
mp-wp_genesis 133 define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
mp-wp_genesis 134 // Having big trouble with crypt. Need to multiply 2 long int
mp-wp_genesis 135 // which is not correctly supported by PHP ...
mp-wp_genesis 136 //define( 'PCLZIP_OPT_CRYPT', 77018 );
mp-wp_genesis 137 define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
mp-wp_genesis 138
mp-wp_genesis 139 // ----- File description attributes
mp-wp_genesis 140 define( 'PCLZIP_ATT_FILE_NAME', 79001 );
mp-wp_genesis 141 define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
mp-wp_genesis 142 define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
mp-wp_genesis 143
mp-wp_genesis 144 // ----- Call backs values
mp-wp_genesis 145 define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
mp-wp_genesis 146 define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
mp-wp_genesis 147 define( 'PCLZIP_CB_PRE_ADD', 78003 );
mp-wp_genesis 148 define( 'PCLZIP_CB_POST_ADD', 78004 );
mp-wp_genesis 149 /* For future use
mp-wp_genesis 150 define( 'PCLZIP_CB_PRE_LIST', 78005 );
mp-wp_genesis 151 define( 'PCLZIP_CB_POST_LIST', 78006 );
mp-wp_genesis 152 define( 'PCLZIP_CB_PRE_DELETE', 78007 );
mp-wp_genesis 153 define( 'PCLZIP_CB_POST_DELETE', 78008 );
mp-wp_genesis 154 */
mp-wp_genesis 155
mp-wp_genesis 156 // --------------------------------------------------------------------------------
mp-wp_genesis 157 // Class : PclZip
mp-wp_genesis 158 // Description :
mp-wp_genesis 159 // PclZip is the class that represent a Zip archive.
mp-wp_genesis 160 // The public methods allow the manipulation of the archive.
mp-wp_genesis 161 // Attributes :
mp-wp_genesis 162 // Attributes must not be accessed directly.
mp-wp_genesis 163 // Methods :
mp-wp_genesis 164 // PclZip() : Object creator
mp-wp_genesis 165 // create() : Creates the Zip archive
mp-wp_genesis 166 // listContent() : List the content of the Zip archive
mp-wp_genesis 167 // extract() : Extract the content of the archive
mp-wp_genesis 168 // properties() : List the properties of the archive
mp-wp_genesis 169 // --------------------------------------------------------------------------------
mp-wp_genesis 170 class PclZip
mp-wp_genesis 171 {
mp-wp_genesis 172 // ----- Filename of the zip file
mp-wp_genesis 173 var $zipname = '';
mp-wp_genesis 174
mp-wp_genesis 175 // ----- File descriptor of the zip file
mp-wp_genesis 176 var $zip_fd = 0;
mp-wp_genesis 177
mp-wp_genesis 178 // ----- Internal error handling
mp-wp_genesis 179 var $error_code = 1;
mp-wp_genesis 180 var $error_string = '';
mp-wp_genesis 181
mp-wp_genesis 182 // ----- Current status of the magic_quotes_runtime
mp-wp_genesis 183 // This value store the php configuration for magic_quotes
mp-wp_genesis 184 // The class can then disable the magic_quotes and reset it after
mp-wp_genesis 185 var $magic_quotes_status;
mp-wp_genesis 186
mp-wp_genesis 187 // --------------------------------------------------------------------------------
mp-wp_genesis 188 // Function : PclZip()
mp-wp_genesis 189 // Description :
mp-wp_genesis 190 // Creates a PclZip object and set the name of the associated Zip archive
mp-wp_genesis 191 // filename.
mp-wp_genesis 192 // Note that no real action is taken, if the archive does not exist it is not
mp-wp_genesis 193 // created. Use create() for that.
mp-wp_genesis 194 // --------------------------------------------------------------------------------
mp-wp_genesis 195 function PclZip($p_zipname)
mp-wp_genesis 196 {
mp-wp_genesis 197 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");
mp-wp_genesis 198
mp-wp_genesis 199 // ----- Tests the zlib
mp-wp_genesis 200 if (!function_exists('gzopen'))
mp-wp_genesis 201 {
mp-wp_genesis 202 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing");
mp-wp_genesis 203 die('Abort '.basename(__FILE__).' : Missing zlib extensions');
mp-wp_genesis 204 }
mp-wp_genesis 205
mp-wp_genesis 206 // ----- Set the attributes
mp-wp_genesis 207 $this->zipname = $p_zipname;
mp-wp_genesis 208 $this->zip_fd = 0;
mp-wp_genesis 209 $this->magic_quotes_status = -1;
mp-wp_genesis 210
mp-wp_genesis 211 // ----- Return
mp-wp_genesis 212 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);
mp-wp_genesis 213 return;
mp-wp_genesis 214 }
mp-wp_genesis 215 // --------------------------------------------------------------------------------
mp-wp_genesis 216
mp-wp_genesis 217 // --------------------------------------------------------------------------------
mp-wp_genesis 218 // Function :
mp-wp_genesis 219 // create($p_filelist, $p_add_dir="", $p_remove_dir="")
mp-wp_genesis 220 // create($p_filelist, $p_option, $p_option_value, ...)
mp-wp_genesis 221 // Description :
mp-wp_genesis 222 // This method supports two different synopsis. The first one is historical.
mp-wp_genesis 223 // This method creates a Zip Archive. The Zip file is created in the
mp-wp_genesis 224 // filesystem. The files and directories indicated in $p_filelist
mp-wp_genesis 225 // are added in the archive. See the parameters description for the
mp-wp_genesis 226 // supported format of $p_filelist.
mp-wp_genesis 227 // When a directory is in the list, the directory and its content is added
mp-wp_genesis 228 // in the archive.
mp-wp_genesis 229 // In this synopsis, the function takes an optional variable list of
mp-wp_genesis 230 // options. See bellow the supported options.
mp-wp_genesis 231 // Parameters :
mp-wp_genesis 232 // $p_filelist : An array containing file or directory names, or
mp-wp_genesis 233 // a string containing one filename or one directory name, or
mp-wp_genesis 234 // a string containing a list of filenames and/or directory
mp-wp_genesis 235 // names separated by spaces.
mp-wp_genesis 236 // $p_add_dir : A path to add before the real path of the archived file,
mp-wp_genesis 237 // in order to have it memorized in the archive.
mp-wp_genesis 238 // $p_remove_dir : A path to remove from the real path of the file to archive,
mp-wp_genesis 239 // in order to have a shorter path memorized in the archive.
mp-wp_genesis 240 // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
mp-wp_genesis 241 // is removed first, before $p_add_dir is added.
mp-wp_genesis 242 // Options :
mp-wp_genesis 243 // PCLZIP_OPT_ADD_PATH :
mp-wp_genesis 244 // PCLZIP_OPT_REMOVE_PATH :
mp-wp_genesis 245 // PCLZIP_OPT_REMOVE_ALL_PATH :
mp-wp_genesis 246 // PCLZIP_OPT_COMMENT :
mp-wp_genesis 247 // PCLZIP_CB_PRE_ADD :
mp-wp_genesis 248 // PCLZIP_CB_POST_ADD :
mp-wp_genesis 249 // Return Values :
mp-wp_genesis 250 // 0 on failure,
mp-wp_genesis 251 // The list of the added files, with a status of the add action.
mp-wp_genesis 252 // (see PclZip::listContent() for list entry format)
mp-wp_genesis 253 // --------------------------------------------------------------------------------
mp-wp_genesis 254 function create($p_filelist)
mp-wp_genesis 255 {
mp-wp_genesis 256 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ...");
mp-wp_genesis 257 $v_result=1;
mp-wp_genesis 258
mp-wp_genesis 259 // ----- Reset the error handler
mp-wp_genesis 260 $this->privErrorReset();
mp-wp_genesis 261
mp-wp_genesis 262 // ----- Set default values
mp-wp_genesis 263 $v_options = array();
mp-wp_genesis 264 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
mp-wp_genesis 265
mp-wp_genesis 266 // ----- Look for variable options arguments
mp-wp_genesis 267 $v_size = func_num_args();
mp-wp_genesis 268 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
mp-wp_genesis 269
mp-wp_genesis 270 // ----- Look for arguments
mp-wp_genesis 271 if ($v_size > 1) {
mp-wp_genesis 272 // ----- Get the arguments
mp-wp_genesis 273 $v_arg_list = func_get_args();
mp-wp_genesis 274
mp-wp_genesis 275 // ----- Remove from the options list the first argument
mp-wp_genesis 276 array_shift($v_arg_list);
mp-wp_genesis 277 $v_size--;
mp-wp_genesis 278
mp-wp_genesis 279 // ----- Look for first arg
mp-wp_genesis 280 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
mp-wp_genesis 281 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
mp-wp_genesis 282
mp-wp_genesis 283 // ----- Parse the options
mp-wp_genesis 284 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
mp-wp_genesis 285 array (PCLZIP_OPT_REMOVE_PATH => 'optional',
mp-wp_genesis 286 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
mp-wp_genesis 287 PCLZIP_OPT_ADD_PATH => 'optional',
mp-wp_genesis 288 PCLZIP_CB_PRE_ADD => 'optional',
mp-wp_genesis 289 PCLZIP_CB_POST_ADD => 'optional',
mp-wp_genesis 290 PCLZIP_OPT_NO_COMPRESSION => 'optional',
mp-wp_genesis 291 PCLZIP_OPT_COMMENT => 'optional'
mp-wp_genesis 292 //, PCLZIP_OPT_CRYPT => 'optional'
mp-wp_genesis 293 ));
mp-wp_genesis 294 if ($v_result != 1) {
mp-wp_genesis 295 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 296 return 0;
mp-wp_genesis 297 }
mp-wp_genesis 298 }
mp-wp_genesis 299
mp-wp_genesis 300 // ----- Look for 2 args
mp-wp_genesis 301 // Here we need to support the first historic synopsis of the
mp-wp_genesis 302 // method.
mp-wp_genesis 303 else {
mp-wp_genesis 304 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
mp-wp_genesis 305
mp-wp_genesis 306 // ----- Get the first argument
mp-wp_genesis 307 $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
mp-wp_genesis 308
mp-wp_genesis 309 // ----- Look for the optional second argument
mp-wp_genesis 310 if ($v_size == 2) {
mp-wp_genesis 311 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
mp-wp_genesis 312 }
mp-wp_genesis 313 else if ($v_size > 2) {
mp-wp_genesis 314 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
mp-wp_genesis 315 "Invalid number / type of arguments");
mp-wp_genesis 316 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 317 return 0;
mp-wp_genesis 318 }
mp-wp_genesis 319 }
mp-wp_genesis 320 }
mp-wp_genesis 321
mp-wp_genesis 322 // ----- Init
mp-wp_genesis 323 $v_string_list = array();
mp-wp_genesis 324 $v_att_list = array();
mp-wp_genesis 325 $v_filedescr_list = array();
mp-wp_genesis 326 $p_result_list = array();
mp-wp_genesis 327
mp-wp_genesis 328 // ----- Look if the $p_filelist is really an array
mp-wp_genesis 329 if (is_array($p_filelist)) {
mp-wp_genesis 330
mp-wp_genesis 331 // ----- Look if the first element is also an array
mp-wp_genesis 332 // This will mean that this is a file description entry
mp-wp_genesis 333 if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
mp-wp_genesis 334 $v_att_list = $p_filelist;
mp-wp_genesis 335 }
mp-wp_genesis 336
mp-wp_genesis 337 // ----- The list is a list of string names
mp-wp_genesis 338 else {
mp-wp_genesis 339 $v_string_list = $p_filelist;
mp-wp_genesis 340 }
mp-wp_genesis 341 }
mp-wp_genesis 342
mp-wp_genesis 343 // ----- Look if the $p_filelist is a string
mp-wp_genesis 344 else if (is_string($p_filelist)) {
mp-wp_genesis 345 // ----- Create a list from the string
mp-wp_genesis 346 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
mp-wp_genesis 347 }
mp-wp_genesis 348
mp-wp_genesis 349 // ----- Invalid variable type for $p_filelist
mp-wp_genesis 350 else {
mp-wp_genesis 351 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
mp-wp_genesis 352 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 353 return 0;
mp-wp_genesis 354 }
mp-wp_genesis 355
mp-wp_genesis 356 // ----- Reformat the string list
mp-wp_genesis 357 if (sizeof($v_string_list) != 0) {
mp-wp_genesis 358 foreach ($v_string_list as $v_string) {
mp-wp_genesis 359 if ($v_string != '') {
mp-wp_genesis 360 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
mp-wp_genesis 361 }
mp-wp_genesis 362 else {
mp-wp_genesis 363 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename");
mp-wp_genesis 364 }
mp-wp_genesis 365 }
mp-wp_genesis 366 }
mp-wp_genesis 367
mp-wp_genesis 368 // ----- For each file in the list check the attributes
mp-wp_genesis 369 $v_supported_attributes
mp-wp_genesis 370 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
mp-wp_genesis 371 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
mp-wp_genesis 372 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
mp-wp_genesis 373 );
mp-wp_genesis 374 foreach ($v_att_list as $v_entry) {
mp-wp_genesis 375 $v_result = $this->privFileDescrParseAtt($v_entry,
mp-wp_genesis 376 $v_filedescr_list[],
mp-wp_genesis 377 $v_options,
mp-wp_genesis 378 $v_supported_attributes);
mp-wp_genesis 379 if ($v_result != 1) {
mp-wp_genesis 380 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 381 return 0;
mp-wp_genesis 382 }
mp-wp_genesis 383 }
mp-wp_genesis 384
mp-wp_genesis 385 // ----- Expand the filelist (expand directories)
mp-wp_genesis 386 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
mp-wp_genesis 387 if ($v_result != 1) {
mp-wp_genesis 388 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 389 return 0;
mp-wp_genesis 390 }
mp-wp_genesis 391
mp-wp_genesis 392 // ----- Call the create fct
mp-wp_genesis 393 $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
mp-wp_genesis 394 if ($v_result != 1) {
mp-wp_genesis 395 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 396 return 0;
mp-wp_genesis 397 }
mp-wp_genesis 398
mp-wp_genesis 399 // ----- Return
mp-wp_genesis 400 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
mp-wp_genesis 401 return $p_result_list;
mp-wp_genesis 402 }
mp-wp_genesis 403 // --------------------------------------------------------------------------------
mp-wp_genesis 404
mp-wp_genesis 405 // --------------------------------------------------------------------------------
mp-wp_genesis 406 // Function :
mp-wp_genesis 407 // add($p_filelist, $p_add_dir="", $p_remove_dir="")
mp-wp_genesis 408 // add($p_filelist, $p_option, $p_option_value, ...)
mp-wp_genesis 409 // Description :
mp-wp_genesis 410 // This method supports two synopsis. The first one is historical.
mp-wp_genesis 411 // This methods add the list of files in an existing archive.
mp-wp_genesis 412 // If a file with the same name already exists, it is added at the end of the
mp-wp_genesis 413 // archive, the first one is still present.
mp-wp_genesis 414 // If the archive does not exist, it is created.
mp-wp_genesis 415 // Parameters :
mp-wp_genesis 416 // $p_filelist : An array containing file or directory names, or
mp-wp_genesis 417 // a string containing one filename or one directory name, or
mp-wp_genesis 418 // a string containing a list of filenames and/or directory
mp-wp_genesis 419 // names separated by spaces.
mp-wp_genesis 420 // $p_add_dir : A path to add before the real path of the archived file,
mp-wp_genesis 421 // in order to have it memorized in the archive.
mp-wp_genesis 422 // $p_remove_dir : A path to remove from the real path of the file to archive,
mp-wp_genesis 423 // in order to have a shorter path memorized in the archive.
mp-wp_genesis 424 // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
mp-wp_genesis 425 // is removed first, before $p_add_dir is added.
mp-wp_genesis 426 // Options :
mp-wp_genesis 427 // PCLZIP_OPT_ADD_PATH :
mp-wp_genesis 428 // PCLZIP_OPT_REMOVE_PATH :
mp-wp_genesis 429 // PCLZIP_OPT_REMOVE_ALL_PATH :
mp-wp_genesis 430 // PCLZIP_OPT_COMMENT :
mp-wp_genesis 431 // PCLZIP_OPT_ADD_COMMENT :
mp-wp_genesis 432 // PCLZIP_OPT_PREPEND_COMMENT :
mp-wp_genesis 433 // PCLZIP_CB_PRE_ADD :
mp-wp_genesis 434 // PCLZIP_CB_POST_ADD :
mp-wp_genesis 435 // Return Values :
mp-wp_genesis 436 // 0 on failure,
mp-wp_genesis 437 // The list of the added files, with a status of the add action.
mp-wp_genesis 438 // (see PclZip::listContent() for list entry format)
mp-wp_genesis 439 // --------------------------------------------------------------------------------
mp-wp_genesis 440 function add($p_filelist)
mp-wp_genesis 441 {
mp-wp_genesis 442 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ...");
mp-wp_genesis 443 $v_result=1;
mp-wp_genesis 444
mp-wp_genesis 445 // ----- Reset the error handler
mp-wp_genesis 446 $this->privErrorReset();
mp-wp_genesis 447
mp-wp_genesis 448 // ----- Set default values
mp-wp_genesis 449 $v_options = array();
mp-wp_genesis 450 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
mp-wp_genesis 451
mp-wp_genesis 452 // ----- Look for variable options arguments
mp-wp_genesis 453 $v_size = func_num_args();
mp-wp_genesis 454 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
mp-wp_genesis 455
mp-wp_genesis 456 // ----- Look for arguments
mp-wp_genesis 457 if ($v_size > 1) {
mp-wp_genesis 458 // ----- Get the arguments
mp-wp_genesis 459 $v_arg_list = func_get_args();
mp-wp_genesis 460
mp-wp_genesis 461 // ----- Remove form the options list the first argument
mp-wp_genesis 462 array_shift($v_arg_list);
mp-wp_genesis 463 $v_size--;
mp-wp_genesis 464
mp-wp_genesis 465 // ----- Look for first arg
mp-wp_genesis 466 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
mp-wp_genesis 467 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
mp-wp_genesis 468
mp-wp_genesis 469 // ----- Parse the options
mp-wp_genesis 470 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
mp-wp_genesis 471 array (PCLZIP_OPT_REMOVE_PATH => 'optional',
mp-wp_genesis 472 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
mp-wp_genesis 473 PCLZIP_OPT_ADD_PATH => 'optional',
mp-wp_genesis 474 PCLZIP_CB_PRE_ADD => 'optional',
mp-wp_genesis 475 PCLZIP_CB_POST_ADD => 'optional',
mp-wp_genesis 476 PCLZIP_OPT_NO_COMPRESSION => 'optional',
mp-wp_genesis 477 PCLZIP_OPT_COMMENT => 'optional',
mp-wp_genesis 478 PCLZIP_OPT_ADD_COMMENT => 'optional',
mp-wp_genesis 479 PCLZIP_OPT_PREPEND_COMMENT => 'optional'
mp-wp_genesis 480 //, PCLZIP_OPT_CRYPT => 'optional'
mp-wp_genesis 481 ));
mp-wp_genesis 482 if ($v_result != 1) {
mp-wp_genesis 483 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 484 return 0;
mp-wp_genesis 485 }
mp-wp_genesis 486 }
mp-wp_genesis 487
mp-wp_genesis 488 // ----- Look for 2 args
mp-wp_genesis 489 // Here we need to support the first historic synopsis of the
mp-wp_genesis 490 // method.
mp-wp_genesis 491 else {
mp-wp_genesis 492 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
mp-wp_genesis 493
mp-wp_genesis 494 // ----- Get the first argument
mp-wp_genesis 495 $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
mp-wp_genesis 496
mp-wp_genesis 497 // ----- Look for the optional second argument
mp-wp_genesis 498 if ($v_size == 2) {
mp-wp_genesis 499 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
mp-wp_genesis 500 }
mp-wp_genesis 501 else if ($v_size > 2) {
mp-wp_genesis 502 // ----- Error log
mp-wp_genesis 503 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
mp-wp_genesis 504
mp-wp_genesis 505 // ----- Return
mp-wp_genesis 506 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 507 return 0;
mp-wp_genesis 508 }
mp-wp_genesis 509 }
mp-wp_genesis 510 }
mp-wp_genesis 511
mp-wp_genesis 512 // ----- Init
mp-wp_genesis 513 $v_string_list = array();
mp-wp_genesis 514 $v_att_list = array();
mp-wp_genesis 515 $v_filedescr_list = array();
mp-wp_genesis 516 $p_result_list = array();
mp-wp_genesis 517
mp-wp_genesis 518 // ----- Look if the $p_filelist is really an array
mp-wp_genesis 519 if (is_array($p_filelist)) {
mp-wp_genesis 520
mp-wp_genesis 521 // ----- Look if the first element is also an array
mp-wp_genesis 522 // This will mean that this is a file description entry
mp-wp_genesis 523 if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
mp-wp_genesis 524 $v_att_list = $p_filelist;
mp-wp_genesis 525 }
mp-wp_genesis 526
mp-wp_genesis 527 // ----- The list is a list of string names
mp-wp_genesis 528 else {
mp-wp_genesis 529 $v_string_list = $p_filelist;
mp-wp_genesis 530 }
mp-wp_genesis 531 }
mp-wp_genesis 532
mp-wp_genesis 533 // ----- Look if the $p_filelist is a string
mp-wp_genesis 534 else if (is_string($p_filelist)) {
mp-wp_genesis 535 // ----- Create a list from the string
mp-wp_genesis 536 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
mp-wp_genesis 537 }
mp-wp_genesis 538
mp-wp_genesis 539 // ----- Invalid variable type for $p_filelist
mp-wp_genesis 540 else {
mp-wp_genesis 541 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
mp-wp_genesis 542 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 543 return 0;
mp-wp_genesis 544 }
mp-wp_genesis 545
mp-wp_genesis 546 // ----- Reformat the string list
mp-wp_genesis 547 if (sizeof($v_string_list) != 0) {
mp-wp_genesis 548 foreach ($v_string_list as $v_string) {
mp-wp_genesis 549 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
mp-wp_genesis 550 }
mp-wp_genesis 551 }
mp-wp_genesis 552
mp-wp_genesis 553 // ----- For each file in the list check the attributes
mp-wp_genesis 554 $v_supported_attributes
mp-wp_genesis 555 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
mp-wp_genesis 556 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
mp-wp_genesis 557 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
mp-wp_genesis 558 );
mp-wp_genesis 559 foreach ($v_att_list as $v_entry) {
mp-wp_genesis 560 $v_result = $this->privFileDescrParseAtt($v_entry,
mp-wp_genesis 561 $v_filedescr_list[],
mp-wp_genesis 562 $v_options,
mp-wp_genesis 563 $v_supported_attributes);
mp-wp_genesis 564 if ($v_result != 1) {
mp-wp_genesis 565 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 566 return 0;
mp-wp_genesis 567 }
mp-wp_genesis 568 }
mp-wp_genesis 569
mp-wp_genesis 570 // ----- Expand the filelist (expand directories)
mp-wp_genesis 571 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
mp-wp_genesis 572 if ($v_result != 1) {
mp-wp_genesis 573 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 574 return 0;
mp-wp_genesis 575 }
mp-wp_genesis 576
mp-wp_genesis 577 // ----- Call the create fct
mp-wp_genesis 578 $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
mp-wp_genesis 579 if ($v_result != 1) {
mp-wp_genesis 580 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 581 return 0;
mp-wp_genesis 582 }
mp-wp_genesis 583
mp-wp_genesis 584 // ----- Return
mp-wp_genesis 585 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
mp-wp_genesis 586 return $p_result_list;
mp-wp_genesis 587 }
mp-wp_genesis 588 // --------------------------------------------------------------------------------
mp-wp_genesis 589
mp-wp_genesis 590 // --------------------------------------------------------------------------------
mp-wp_genesis 591 // Function : listContent()
mp-wp_genesis 592 // Description :
mp-wp_genesis 593 // This public method, gives the list of the files and directories, with their
mp-wp_genesis 594 // properties.
mp-wp_genesis 595 // The properties of each entries in the list are (used also in other functions) :
mp-wp_genesis 596 // filename : Name of the file. For a create or add action it is the filename
mp-wp_genesis 597 // given by the user. For an extract function it is the filename
mp-wp_genesis 598 // of the extracted file.
mp-wp_genesis 599 // stored_filename : Name of the file / directory stored in the archive.
mp-wp_genesis 600 // size : Size of the stored file.
mp-wp_genesis 601 // compressed_size : Size of the file's data compressed in the archive
mp-wp_genesis 602 // (without the headers overhead)
mp-wp_genesis 603 // mtime : Last known modification date of the file (UNIX timestamp)
mp-wp_genesis 604 // comment : Comment associated with the file
mp-wp_genesis 605 // folder : true | false
mp-wp_genesis 606 // index : index of the file in the archive
mp-wp_genesis 607 // status : status of the action (depending of the action) :
mp-wp_genesis 608 // Values are :
mp-wp_genesis 609 // ok : OK !
mp-wp_genesis 610 // filtered : the file / dir is not extracted (filtered by user)
mp-wp_genesis 611 // already_a_directory : the file can not be extracted because a
mp-wp_genesis 612 // directory with the same name already exists
mp-wp_genesis 613 // write_protected : the file can not be extracted because a file
mp-wp_genesis 614 // with the same name already exists and is
mp-wp_genesis 615 // write protected
mp-wp_genesis 616 // newer_exist : the file was not extracted because a newer file exists
mp-wp_genesis 617 // path_creation_fail : the file is not extracted because the folder
mp-wp_genesis 618 // does not exists and can not be created
mp-wp_genesis 619 // write_error : the file was not extracted because there was a
mp-wp_genesis 620 // error while writing the file
mp-wp_genesis 621 // read_error : the file was not extracted because there was a error
mp-wp_genesis 622 // while reading the file
mp-wp_genesis 623 // invalid_header : the file was not extracted because of an archive
mp-wp_genesis 624 // format error (bad file header)
mp-wp_genesis 625 // Note that each time a method can continue operating when there
mp-wp_genesis 626 // is an action error on a file, the error is only logged in the file status.
mp-wp_genesis 627 // Return Values :
mp-wp_genesis 628 // 0 on an unrecoverable failure,
mp-wp_genesis 629 // The list of the files in the archive.
mp-wp_genesis 630 // --------------------------------------------------------------------------------
mp-wp_genesis 631 function listContent()
mp-wp_genesis 632 {
mp-wp_genesis 633 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");
mp-wp_genesis 634 $v_result=1;
mp-wp_genesis 635
mp-wp_genesis 636 // ----- Reset the error handler
mp-wp_genesis 637 $this->privErrorReset();
mp-wp_genesis 638
mp-wp_genesis 639 // ----- Check archive
mp-wp_genesis 640 if (!$this->privCheckFormat()) {
mp-wp_genesis 641 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 642 return(0);
mp-wp_genesis 643 }
mp-wp_genesis 644
mp-wp_genesis 645 // ----- Call the extracting fct
mp-wp_genesis 646 $p_list = array();
mp-wp_genesis 647 if (($v_result = $this->privList($p_list)) != 1)
mp-wp_genesis 648 {
mp-wp_genesis 649 unset($p_list);
mp-wp_genesis 650 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
mp-wp_genesis 651 return(0);
mp-wp_genesis 652 }
mp-wp_genesis 653
mp-wp_genesis 654 // ----- Return
mp-wp_genesis 655 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
mp-wp_genesis 656 return $p_list;
mp-wp_genesis 657 }
mp-wp_genesis 658 // --------------------------------------------------------------------------------
mp-wp_genesis 659
mp-wp_genesis 660 // --------------------------------------------------------------------------------
mp-wp_genesis 661 // Function :
mp-wp_genesis 662 // extract($p_path="./", $p_remove_path="")
mp-wp_genesis 663 // extract([$p_option, $p_option_value, ...])
mp-wp_genesis 664 // Description :
mp-wp_genesis 665 // This method supports two synopsis. The first one is historical.
mp-wp_genesis 666 // This method extract all the files / directories from the archive to the
mp-wp_genesis 667 // folder indicated in $p_path.
mp-wp_genesis 668 // If you want to ignore the 'root' part of path of the memorized files
mp-wp_genesis 669 // you can indicate this in the optional $p_remove_path parameter.
mp-wp_genesis 670 // By default, if a newer file with the same name already exists, the
mp-wp_genesis 671 // file is not extracted.
mp-wp_genesis 672 //
mp-wp_genesis 673 // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
mp-wp_genesis 674 // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
mp-wp_genesis 675 // at the end of the path value of PCLZIP_OPT_PATH.
mp-wp_genesis 676 // Parameters :
mp-wp_genesis 677 // $p_path : Path where the files and directories are to be extracted
mp-wp_genesis 678 // $p_remove_path : First part ('root' part) of the memorized path
mp-wp_genesis 679 // (if any similar) to remove while extracting.
mp-wp_genesis 680 // Options :
mp-wp_genesis 681 // PCLZIP_OPT_PATH :
mp-wp_genesis 682 // PCLZIP_OPT_ADD_PATH :
mp-wp_genesis 683 // PCLZIP_OPT_REMOVE_PATH :
mp-wp_genesis 684 // PCLZIP_OPT_REMOVE_ALL_PATH :
mp-wp_genesis 685 // PCLZIP_CB_PRE_EXTRACT :
mp-wp_genesis 686 // PCLZIP_CB_POST_EXTRACT :
mp-wp_genesis 687 // Return Values :
mp-wp_genesis 688 // 0 or a negative value on failure,
mp-wp_genesis 689 // The list of the extracted files, with a status of the action.
mp-wp_genesis 690 // (see PclZip::listContent() for list entry format)
mp-wp_genesis 691 // --------------------------------------------------------------------------------
mp-wp_genesis 692 function extract()
mp-wp_genesis 693 {
mp-wp_genesis 694 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");
mp-wp_genesis 695 $v_result=1;
mp-wp_genesis 696
mp-wp_genesis 697 // ----- Reset the error handler
mp-wp_genesis 698 $this->privErrorReset();
mp-wp_genesis 699
mp-wp_genesis 700 // ----- Check archive
mp-wp_genesis 701 if (!$this->privCheckFormat()) {
mp-wp_genesis 702 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 703 return(0);
mp-wp_genesis 704 }
mp-wp_genesis 705
mp-wp_genesis 706 // ----- Set default values
mp-wp_genesis 707 $v_options = array();
mp-wp_genesis 708 // $v_path = "./";
mp-wp_genesis 709 $v_path = '';
mp-wp_genesis 710 $v_remove_path = "";
mp-wp_genesis 711 $v_remove_all_path = false;
mp-wp_genesis 712
mp-wp_genesis 713 // ----- Look for variable options arguments
mp-wp_genesis 714 $v_size = func_num_args();
mp-wp_genesis 715 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
mp-wp_genesis 716
mp-wp_genesis 717 // ----- Default values for option
mp-wp_genesis 718 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
mp-wp_genesis 719
mp-wp_genesis 720 // ----- Look for arguments
mp-wp_genesis 721 if ($v_size > 0) {
mp-wp_genesis 722 // ----- Get the arguments
mp-wp_genesis 723 $v_arg_list = func_get_args();
mp-wp_genesis 724
mp-wp_genesis 725 // ----- Look for first arg
mp-wp_genesis 726 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
mp-wp_genesis 727 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
mp-wp_genesis 728
mp-wp_genesis 729 // ----- Parse the options
mp-wp_genesis 730 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
mp-wp_genesis 731 array (PCLZIP_OPT_PATH => 'optional',
mp-wp_genesis 732 PCLZIP_OPT_REMOVE_PATH => 'optional',
mp-wp_genesis 733 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
mp-wp_genesis 734 PCLZIP_OPT_ADD_PATH => 'optional',
mp-wp_genesis 735 PCLZIP_CB_PRE_EXTRACT => 'optional',
mp-wp_genesis 736 PCLZIP_CB_POST_EXTRACT => 'optional',
mp-wp_genesis 737 PCLZIP_OPT_SET_CHMOD => 'optional',
mp-wp_genesis 738 PCLZIP_OPT_BY_NAME => 'optional',
mp-wp_genesis 739 PCLZIP_OPT_BY_EREG => 'optional',
mp-wp_genesis 740 PCLZIP_OPT_BY_PREG => 'optional',
mp-wp_genesis 741 PCLZIP_OPT_BY_INDEX => 'optional',
mp-wp_genesis 742 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
mp-wp_genesis 743 PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
mp-wp_genesis 744 PCLZIP_OPT_REPLACE_NEWER => 'optional'
mp-wp_genesis 745 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
mp-wp_genesis 746 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
mp-wp_genesis 747 ));
mp-wp_genesis 748 if ($v_result != 1) {
mp-wp_genesis 749 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 750 return 0;
mp-wp_genesis 751 }
mp-wp_genesis 752
mp-wp_genesis 753 // ----- Set the arguments
mp-wp_genesis 754 if (isset($v_options[PCLZIP_OPT_PATH])) {
mp-wp_genesis 755 $v_path = $v_options[PCLZIP_OPT_PATH];
mp-wp_genesis 756 }
mp-wp_genesis 757 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
mp-wp_genesis 758 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
mp-wp_genesis 759 }
mp-wp_genesis 760 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
mp-wp_genesis 761 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
mp-wp_genesis 762 }
mp-wp_genesis 763 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
mp-wp_genesis 764 // ----- Check for '/' in last path char
mp-wp_genesis 765 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
mp-wp_genesis 766 $v_path .= '/';
mp-wp_genesis 767 }
mp-wp_genesis 768 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
mp-wp_genesis 769 }
mp-wp_genesis 770 }
mp-wp_genesis 771
mp-wp_genesis 772 // ----- Look for 2 args
mp-wp_genesis 773 // Here we need to support the first historic synopsis of the
mp-wp_genesis 774 // method.
mp-wp_genesis 775 else {
mp-wp_genesis 776 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
mp-wp_genesis 777
mp-wp_genesis 778 // ----- Get the first argument
mp-wp_genesis 779 $v_path = $v_arg_list[0];
mp-wp_genesis 780
mp-wp_genesis 781 // ----- Look for the optional second argument
mp-wp_genesis 782 if ($v_size == 2) {
mp-wp_genesis 783 $v_remove_path = $v_arg_list[1];
mp-wp_genesis 784 }
mp-wp_genesis 785 else if ($v_size > 2) {
mp-wp_genesis 786 // ----- Error log
mp-wp_genesis 787 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
mp-wp_genesis 788
mp-wp_genesis 789 // ----- Return
mp-wp_genesis 790 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
mp-wp_genesis 791 return 0;
mp-wp_genesis 792 }
mp-wp_genesis 793 }
mp-wp_genesis 794 }
mp-wp_genesis 795
mp-wp_genesis 796 // ----- Trace
mp-wp_genesis 797 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");
mp-wp_genesis 798
mp-wp_genesis 799 // ----- Call the extracting fct
mp-wp_genesis 800 $p_list = array();
mp-wp_genesis 801 $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
mp-wp_genesis 802 $v_remove_all_path, $v_options);
mp-wp_genesis 803 if ($v_result < 1) {
mp-wp_genesis 804 unset($p_list);
mp-wp_genesis 805 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
mp-wp_genesis 806 return(0);
mp-wp_genesis 807 }
mp-wp_genesis 808
mp-wp_genesis 809 // ----- Return
mp-wp_genesis 810 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
mp-wp_genesis 811 return $p_list;
mp-wp_genesis 812 }
mp-wp_genesis 813 // --------------------------------------------------------------------------------
mp-wp_genesis 814
mp-wp_genesis 815
mp-wp_genesis 816 // --------------------------------------------------------------------------------
mp-wp_genesis 817 // Function :
mp-wp_genesis 818 // extractByIndex($p_index, $p_path="./", $p_remove_path="")
mp-wp_genesis 819 // extractByIndex($p_index, [$p_option, $p_option_value, ...])
mp-wp_genesis 820 // Description :
mp-wp_genesis 821 // This method supports two synopsis. The first one is historical.
mp-wp_genesis 822 // This method is doing a partial extract of the archive.
mp-wp_genesis 823 // The extracted files or folders are identified by their index in the
mp-wp_genesis 824 // archive (from 0 to n).
mp-wp_genesis 825 // Note that if the index identify a folder, only the folder entry is
mp-wp_genesis 826 // extracted, not all the files included in the archive.
mp-wp_genesis 827 // Parameters :
mp-wp_genesis 828 // $p_index : A single index (integer) or a string of indexes of files to
mp-wp_genesis 829 // extract. The form of the string is "0,4-6,8-12" with only numbers
mp-wp_genesis 830 // and '-' for range or ',' to separate ranges. No spaces or ';'
mp-wp_genesis 831 // are allowed.
mp-wp_genesis 832 // $p_path : Path where the files and directories are to be extracted
mp-wp_genesis 833 // $p_remove_path : First part ('root' part) of the memorized path
mp-wp_genesis 834 // (if any similar) to remove while extracting.
mp-wp_genesis 835 // Options :
mp-wp_genesis 836 // PCLZIP_OPT_PATH :
mp-wp_genesis 837 // PCLZIP_OPT_ADD_PATH :
mp-wp_genesis 838 // PCLZIP_OPT_REMOVE_PATH :
mp-wp_genesis 839 // PCLZIP_OPT_REMOVE_ALL_PATH :
mp-wp_genesis 840 // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
mp-wp_genesis 841 // not as files.
mp-wp_genesis 842 // The resulting content is in a new field 'content' in the file
mp-wp_genesis 843 // structure.
mp-wp_genesis 844 // This option must be used alone (any other options are ignored).
mp-wp_genesis 845 // PCLZIP_CB_PRE_EXTRACT :
mp-wp_genesis 846 // PCLZIP_CB_POST_EXTRACT :
mp-wp_genesis 847 // Return Values :
mp-wp_genesis 848 // 0 on failure,
mp-wp_genesis 849 // The list of the extracted files, with a status of the action.
mp-wp_genesis 850 // (see PclZip::listContent() for list entry format)
mp-wp_genesis 851 // --------------------------------------------------------------------------------
mp-wp_genesis 852 //function extractByIndex($p_index, options...)
mp-wp_genesis 853 function extractByIndex($p_index)
mp-wp_genesis 854 {
mp-wp_genesis 855 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");
mp-wp_genesis 856 $v_result=1;
mp-wp_genesis 857
mp-wp_genesis 858 // ----- Reset the error handler
mp-wp_genesis 859 $this->privErrorReset();
mp-wp_genesis 860
mp-wp_genesis 861 // ----- Check archive
mp-wp_genesis 862 if (!$this->privCheckFormat()) {
mp-wp_genesis 863 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 864 return(0);
mp-wp_genesis 865 }
mp-wp_genesis 866
mp-wp_genesis 867 // ----- Set default values
mp-wp_genesis 868 $v_options = array();
mp-wp_genesis 869 // $v_path = "./";
mp-wp_genesis 870 $v_path = '';
mp-wp_genesis 871 $v_remove_path = "";
mp-wp_genesis 872 $v_remove_all_path = false;
mp-wp_genesis 873
mp-wp_genesis 874 // ----- Look for variable options arguments
mp-wp_genesis 875 $v_size = func_num_args();
mp-wp_genesis 876 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
mp-wp_genesis 877
mp-wp_genesis 878 // ----- Default values for option
mp-wp_genesis 879 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
mp-wp_genesis 880
mp-wp_genesis 881 // ----- Look for arguments
mp-wp_genesis 882 if ($v_size > 1) {
mp-wp_genesis 883 // ----- Get the arguments
mp-wp_genesis 884 $v_arg_list = func_get_args();
mp-wp_genesis 885
mp-wp_genesis 886 // ----- Remove form the options list the first argument
mp-wp_genesis 887 array_shift($v_arg_list);
mp-wp_genesis 888 $v_size--;
mp-wp_genesis 889
mp-wp_genesis 890 // ----- Look for first arg
mp-wp_genesis 891 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
mp-wp_genesis 892 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
mp-wp_genesis 893
mp-wp_genesis 894 // ----- Parse the options
mp-wp_genesis 895 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
mp-wp_genesis 896 array (PCLZIP_OPT_PATH => 'optional',
mp-wp_genesis 897 PCLZIP_OPT_REMOVE_PATH => 'optional',
mp-wp_genesis 898 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
mp-wp_genesis 899 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
mp-wp_genesis 900 PCLZIP_OPT_ADD_PATH => 'optional',
mp-wp_genesis 901 PCLZIP_CB_PRE_EXTRACT => 'optional',
mp-wp_genesis 902 PCLZIP_CB_POST_EXTRACT => 'optional',
mp-wp_genesis 903 PCLZIP_OPT_SET_CHMOD => 'optional',
mp-wp_genesis 904 PCLZIP_OPT_REPLACE_NEWER => 'optional'
mp-wp_genesis 905 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
mp-wp_genesis 906 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
mp-wp_genesis 907 ));
mp-wp_genesis 908 if ($v_result != 1) {
mp-wp_genesis 909 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 910 return 0;
mp-wp_genesis 911 }
mp-wp_genesis 912
mp-wp_genesis 913 // ----- Set the arguments
mp-wp_genesis 914 if (isset($v_options[PCLZIP_OPT_PATH])) {
mp-wp_genesis 915 $v_path = $v_options[PCLZIP_OPT_PATH];
mp-wp_genesis 916 }
mp-wp_genesis 917 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
mp-wp_genesis 918 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
mp-wp_genesis 919 }
mp-wp_genesis 920 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
mp-wp_genesis 921 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
mp-wp_genesis 922 }
mp-wp_genesis 923 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
mp-wp_genesis 924 // ----- Check for '/' in last path char
mp-wp_genesis 925 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
mp-wp_genesis 926 $v_path .= '/';
mp-wp_genesis 927 }
mp-wp_genesis 928 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
mp-wp_genesis 929 }
mp-wp_genesis 930 if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
mp-wp_genesis 931 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
mp-wp_genesis 932 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set.");
mp-wp_genesis 933 }
mp-wp_genesis 934 else {
mp-wp_genesis 935 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set.");
mp-wp_genesis 936 }
mp-wp_genesis 937 }
mp-wp_genesis 938
mp-wp_genesis 939 // ----- Look for 2 args
mp-wp_genesis 940 // Here we need to support the first historic synopsis of the
mp-wp_genesis 941 // method.
mp-wp_genesis 942 else {
mp-wp_genesis 943 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
mp-wp_genesis 944
mp-wp_genesis 945 // ----- Get the first argument
mp-wp_genesis 946 $v_path = $v_arg_list[0];
mp-wp_genesis 947
mp-wp_genesis 948 // ----- Look for the optional second argument
mp-wp_genesis 949 if ($v_size == 2) {
mp-wp_genesis 950 $v_remove_path = $v_arg_list[1];
mp-wp_genesis 951 }
mp-wp_genesis 952 else if ($v_size > 2) {
mp-wp_genesis 953 // ----- Error log
mp-wp_genesis 954 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
mp-wp_genesis 955
mp-wp_genesis 956 // ----- Return
mp-wp_genesis 957 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 958 return 0;
mp-wp_genesis 959 }
mp-wp_genesis 960 }
mp-wp_genesis 961 }
mp-wp_genesis 962
mp-wp_genesis 963 // ----- Trace
mp-wp_genesis 964 //--(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')."'");
mp-wp_genesis 965
mp-wp_genesis 966 // ----- Trick
mp-wp_genesis 967 // Here I want to reuse extractByRule(), so I need to parse the $p_index
mp-wp_genesis 968 // with privParseOptions()
mp-wp_genesis 969 $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
mp-wp_genesis 970 $v_options_trick = array();
mp-wp_genesis 971 $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
mp-wp_genesis 972 array (PCLZIP_OPT_BY_INDEX => 'optional' ));
mp-wp_genesis 973 if ($v_result != 1) {
mp-wp_genesis 974 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 975 return 0;
mp-wp_genesis 976 }
mp-wp_genesis 977 $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
mp-wp_genesis 978
mp-wp_genesis 979 // ----- Call the extracting fct
mp-wp_genesis 980 if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
mp-wp_genesis 981 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
mp-wp_genesis 982 return(0);
mp-wp_genesis 983 }
mp-wp_genesis 984
mp-wp_genesis 985 // ----- Return
mp-wp_genesis 986 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
mp-wp_genesis 987 return $p_list;
mp-wp_genesis 988 }
mp-wp_genesis 989 // --------------------------------------------------------------------------------
mp-wp_genesis 990
mp-wp_genesis 991 // --------------------------------------------------------------------------------
mp-wp_genesis 992 // Function :
mp-wp_genesis 993 // delete([$p_option, $p_option_value, ...])
mp-wp_genesis 994 // Description :
mp-wp_genesis 995 // This method removes files from the archive.
mp-wp_genesis 996 // If no parameters are given, then all the archive is emptied.
mp-wp_genesis 997 // Parameters :
mp-wp_genesis 998 // None or optional arguments.
mp-wp_genesis 999 // Options :
mp-wp_genesis 1000 // PCLZIP_OPT_BY_INDEX :
mp-wp_genesis 1001 // PCLZIP_OPT_BY_NAME :
mp-wp_genesis 1002 // PCLZIP_OPT_BY_EREG :
mp-wp_genesis 1003 // PCLZIP_OPT_BY_PREG :
mp-wp_genesis 1004 // Return Values :
mp-wp_genesis 1005 // 0 on failure,
mp-wp_genesis 1006 // The list of the files which are still present in the archive.
mp-wp_genesis 1007 // (see PclZip::listContent() for list entry format)
mp-wp_genesis 1008 // --------------------------------------------------------------------------------
mp-wp_genesis 1009 function delete()
mp-wp_genesis 1010 {
mp-wp_genesis 1011 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");
mp-wp_genesis 1012 $v_result=1;
mp-wp_genesis 1013
mp-wp_genesis 1014 // ----- Reset the error handler
mp-wp_genesis 1015 $this->privErrorReset();
mp-wp_genesis 1016
mp-wp_genesis 1017 // ----- Check archive
mp-wp_genesis 1018 if (!$this->privCheckFormat()) {
mp-wp_genesis 1019 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 1020 return(0);
mp-wp_genesis 1021 }
mp-wp_genesis 1022
mp-wp_genesis 1023 // ----- Set default values
mp-wp_genesis 1024 $v_options = array();
mp-wp_genesis 1025
mp-wp_genesis 1026 // ----- Look for variable options arguments
mp-wp_genesis 1027 $v_size = func_num_args();
mp-wp_genesis 1028 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
mp-wp_genesis 1029
mp-wp_genesis 1030 // ----- Look for arguments
mp-wp_genesis 1031 if ($v_size > 0) {
mp-wp_genesis 1032 // ----- Get the arguments
mp-wp_genesis 1033 $v_arg_list = func_get_args();
mp-wp_genesis 1034
mp-wp_genesis 1035 // ----- Parse the options
mp-wp_genesis 1036 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
mp-wp_genesis 1037 array (PCLZIP_OPT_BY_NAME => 'optional',
mp-wp_genesis 1038 PCLZIP_OPT_BY_EREG => 'optional',
mp-wp_genesis 1039 PCLZIP_OPT_BY_PREG => 'optional',
mp-wp_genesis 1040 PCLZIP_OPT_BY_INDEX => 'optional' ));
mp-wp_genesis 1041 if ($v_result != 1) {
mp-wp_genesis 1042 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 1043 return 0;
mp-wp_genesis 1044 }
mp-wp_genesis 1045 }
mp-wp_genesis 1046
mp-wp_genesis 1047 // ----- Magic quotes trick
mp-wp_genesis 1048 $this->privDisableMagicQuotes();
mp-wp_genesis 1049
mp-wp_genesis 1050 // ----- Call the delete fct
mp-wp_genesis 1051 $v_list = array();
mp-wp_genesis 1052 if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
mp-wp_genesis 1053 $this->privSwapBackMagicQuotes();
mp-wp_genesis 1054 unset($v_list);
mp-wp_genesis 1055 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
mp-wp_genesis 1056 return(0);
mp-wp_genesis 1057 }
mp-wp_genesis 1058
mp-wp_genesis 1059 // ----- Magic quotes trick
mp-wp_genesis 1060 $this->privSwapBackMagicQuotes();
mp-wp_genesis 1061
mp-wp_genesis 1062 // ----- Return
mp-wp_genesis 1063 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);
mp-wp_genesis 1064 return $v_list;
mp-wp_genesis 1065 }
mp-wp_genesis 1066 // --------------------------------------------------------------------------------
mp-wp_genesis 1067
mp-wp_genesis 1068 // --------------------------------------------------------------------------------
mp-wp_genesis 1069 // Function : deleteByIndex()
mp-wp_genesis 1070 // Description :
mp-wp_genesis 1071 // ***** Deprecated *****
mp-wp_genesis 1072 // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
mp-wp_genesis 1073 // --------------------------------------------------------------------------------
mp-wp_genesis 1074 function deleteByIndex($p_index)
mp-wp_genesis 1075 {
mp-wp_genesis 1076 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'");
mp-wp_genesis 1077
mp-wp_genesis 1078 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
mp-wp_genesis 1079
mp-wp_genesis 1080 // ----- Return
mp-wp_genesis 1081 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
mp-wp_genesis 1082 return $p_list;
mp-wp_genesis 1083 }
mp-wp_genesis 1084 // --------------------------------------------------------------------------------
mp-wp_genesis 1085
mp-wp_genesis 1086 // --------------------------------------------------------------------------------
mp-wp_genesis 1087 // Function : properties()
mp-wp_genesis 1088 // Description :
mp-wp_genesis 1089 // This method gives the properties of the archive.
mp-wp_genesis 1090 // The properties are :
mp-wp_genesis 1091 // nb : Number of files in the archive
mp-wp_genesis 1092 // comment : Comment associated with the archive file
mp-wp_genesis 1093 // status : not_exist, ok
mp-wp_genesis 1094 // Parameters :
mp-wp_genesis 1095 // None
mp-wp_genesis 1096 // Return Values :
mp-wp_genesis 1097 // 0 on failure,
mp-wp_genesis 1098 // An array with the archive properties.
mp-wp_genesis 1099 // --------------------------------------------------------------------------------
mp-wp_genesis 1100 function properties()
mp-wp_genesis 1101 {
mp-wp_genesis 1102 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");
mp-wp_genesis 1103
mp-wp_genesis 1104 // ----- Reset the error handler
mp-wp_genesis 1105 $this->privErrorReset();
mp-wp_genesis 1106
mp-wp_genesis 1107 // ----- Magic quotes trick
mp-wp_genesis 1108 $this->privDisableMagicQuotes();
mp-wp_genesis 1109
mp-wp_genesis 1110 // ----- Check archive
mp-wp_genesis 1111 if (!$this->privCheckFormat()) {
mp-wp_genesis 1112 $this->privSwapBackMagicQuotes();
mp-wp_genesis 1113 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 1114 return(0);
mp-wp_genesis 1115 }
mp-wp_genesis 1116
mp-wp_genesis 1117 // ----- Default properties
mp-wp_genesis 1118 $v_prop = array();
mp-wp_genesis 1119 $v_prop['comment'] = '';
mp-wp_genesis 1120 $v_prop['nb'] = 0;
mp-wp_genesis 1121 $v_prop['status'] = 'not_exist';
mp-wp_genesis 1122
mp-wp_genesis 1123 // ----- Look if file exists
mp-wp_genesis 1124 if (@is_file($this->zipname))
mp-wp_genesis 1125 {
mp-wp_genesis 1126 // ----- Open the zip file
mp-wp_genesis 1127 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 1128 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
mp-wp_genesis 1129 {
mp-wp_genesis 1130 $this->privSwapBackMagicQuotes();
mp-wp_genesis 1131
mp-wp_genesis 1132 // ----- Error log
mp-wp_genesis 1133 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
mp-wp_genesis 1134
mp-wp_genesis 1135 // ----- Return
mp-wp_genesis 1136 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);
mp-wp_genesis 1137 return 0;
mp-wp_genesis 1138 }
mp-wp_genesis 1139
mp-wp_genesis 1140 // ----- Read the central directory informations
mp-wp_genesis 1141 $v_central_dir = array();
mp-wp_genesis 1142 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
mp-wp_genesis 1143 {
mp-wp_genesis 1144 $this->privSwapBackMagicQuotes();
mp-wp_genesis 1145 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 1146 return 0;
mp-wp_genesis 1147 }
mp-wp_genesis 1148
mp-wp_genesis 1149 // ----- Close the zip file
mp-wp_genesis 1150 $this->privCloseFd();
mp-wp_genesis 1151
mp-wp_genesis 1152 // ----- Set the user attributes
mp-wp_genesis 1153 $v_prop['comment'] = $v_central_dir['comment'];
mp-wp_genesis 1154 $v_prop['nb'] = $v_central_dir['entries'];
mp-wp_genesis 1155 $v_prop['status'] = 'ok';
mp-wp_genesis 1156 }
mp-wp_genesis 1157
mp-wp_genesis 1158 // ----- Magic quotes trick
mp-wp_genesis 1159 $this->privSwapBackMagicQuotes();
mp-wp_genesis 1160
mp-wp_genesis 1161 // ----- Return
mp-wp_genesis 1162 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);
mp-wp_genesis 1163 return $v_prop;
mp-wp_genesis 1164 }
mp-wp_genesis 1165 // --------------------------------------------------------------------------------
mp-wp_genesis 1166
mp-wp_genesis 1167 // --------------------------------------------------------------------------------
mp-wp_genesis 1168 // Function : duplicate()
mp-wp_genesis 1169 // Description :
mp-wp_genesis 1170 // This method creates an archive by copying the content of an other one. If
mp-wp_genesis 1171 // the archive already exist, it is replaced by the new one without any warning.
mp-wp_genesis 1172 // Parameters :
mp-wp_genesis 1173 // $p_archive : The filename of a valid archive, or
mp-wp_genesis 1174 // a valid PclZip object.
mp-wp_genesis 1175 // Return Values :
mp-wp_genesis 1176 // 1 on success.
mp-wp_genesis 1177 // 0 or a negative value on error (error code).
mp-wp_genesis 1178 // --------------------------------------------------------------------------------
mp-wp_genesis 1179 function duplicate($p_archive)
mp-wp_genesis 1180 {
mp-wp_genesis 1181 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");
mp-wp_genesis 1182 $v_result = 1;
mp-wp_genesis 1183
mp-wp_genesis 1184 // ----- Reset the error handler
mp-wp_genesis 1185 $this->privErrorReset();
mp-wp_genesis 1186
mp-wp_genesis 1187 // ----- Look if the $p_archive is a PclZip object
mp-wp_genesis 1188 if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
mp-wp_genesis 1189 {
mp-wp_genesis 1190 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");
mp-wp_genesis 1191
mp-wp_genesis 1192 // ----- Duplicate the archive
mp-wp_genesis 1193 $v_result = $this->privDuplicate($p_archive->zipname);
mp-wp_genesis 1194 }
mp-wp_genesis 1195
mp-wp_genesis 1196 // ----- Look if the $p_archive is a string (so a filename)
mp-wp_genesis 1197 else if (is_string($p_archive))
mp-wp_genesis 1198 {
mp-wp_genesis 1199 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");
mp-wp_genesis 1200
mp-wp_genesis 1201 // ----- Check that $p_archive is a valid zip file
mp-wp_genesis 1202 // TBC : Should also check the archive format
mp-wp_genesis 1203 if (!is_file($p_archive)) {
mp-wp_genesis 1204 // ----- Error log
mp-wp_genesis 1205 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
mp-wp_genesis 1206 $v_result = PCLZIP_ERR_MISSING_FILE;
mp-wp_genesis 1207 }
mp-wp_genesis 1208 else {
mp-wp_genesis 1209 // ----- Duplicate the archive
mp-wp_genesis 1210 $v_result = $this->privDuplicate($p_archive);
mp-wp_genesis 1211 }
mp-wp_genesis 1212 }
mp-wp_genesis 1213
mp-wp_genesis 1214 // ----- Invalid variable
mp-wp_genesis 1215 else
mp-wp_genesis 1216 {
mp-wp_genesis 1217 // ----- Error log
mp-wp_genesis 1218 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
mp-wp_genesis 1219 $v_result = PCLZIP_ERR_INVALID_PARAMETER;
mp-wp_genesis 1220 }
mp-wp_genesis 1221
mp-wp_genesis 1222 // ----- Return
mp-wp_genesis 1223 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 1224 return $v_result;
mp-wp_genesis 1225 }
mp-wp_genesis 1226 // --------------------------------------------------------------------------------
mp-wp_genesis 1227
mp-wp_genesis 1228 // --------------------------------------------------------------------------------
mp-wp_genesis 1229 // Function : merge()
mp-wp_genesis 1230 // Description :
mp-wp_genesis 1231 // This method merge the $p_archive_to_add archive at the end of the current
mp-wp_genesis 1232 // one ($this).
mp-wp_genesis 1233 // If the archive ($this) does not exist, the merge becomes a duplicate.
mp-wp_genesis 1234 // If the $p_archive_to_add archive does not exist, the merge is a success.
mp-wp_genesis 1235 // Parameters :
mp-wp_genesis 1236 // $p_archive_to_add : It can be directly the filename of a valid zip archive,
mp-wp_genesis 1237 // or a PclZip object archive.
mp-wp_genesis 1238 // Return Values :
mp-wp_genesis 1239 // 1 on success,
mp-wp_genesis 1240 // 0 or negative values on error (see below).
mp-wp_genesis 1241 // --------------------------------------------------------------------------------
mp-wp_genesis 1242 function merge($p_archive_to_add)
mp-wp_genesis 1243 {
mp-wp_genesis 1244 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");
mp-wp_genesis 1245 $v_result = 1;
mp-wp_genesis 1246
mp-wp_genesis 1247 // ----- Reset the error handler
mp-wp_genesis 1248 $this->privErrorReset();
mp-wp_genesis 1249
mp-wp_genesis 1250 // ----- Check archive
mp-wp_genesis 1251 if (!$this->privCheckFormat()) {
mp-wp_genesis 1252 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
mp-wp_genesis 1253 return(0);
mp-wp_genesis 1254 }
mp-wp_genesis 1255
mp-wp_genesis 1256 // ----- Look if the $p_archive_to_add is a PclZip object
mp-wp_genesis 1257 if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
mp-wp_genesis 1258 {
mp-wp_genesis 1259 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");
mp-wp_genesis 1260
mp-wp_genesis 1261 // ----- Merge the archive
mp-wp_genesis 1262 $v_result = $this->privMerge($p_archive_to_add);
mp-wp_genesis 1263 }
mp-wp_genesis 1264
mp-wp_genesis 1265 // ----- Look if the $p_archive_to_add is a string (so a filename)
mp-wp_genesis 1266 else if (is_string($p_archive_to_add))
mp-wp_genesis 1267 {
mp-wp_genesis 1268 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");
mp-wp_genesis 1269
mp-wp_genesis 1270 // ----- Create a temporary archive
mp-wp_genesis 1271 $v_object_archive = new PclZip($p_archive_to_add);
mp-wp_genesis 1272
mp-wp_genesis 1273 // ----- Merge the archive
mp-wp_genesis 1274 $v_result = $this->privMerge($v_object_archive);
mp-wp_genesis 1275 }
mp-wp_genesis 1276
mp-wp_genesis 1277 // ----- Invalid variable
mp-wp_genesis 1278 else
mp-wp_genesis 1279 {
mp-wp_genesis 1280 // ----- Error log
mp-wp_genesis 1281 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
mp-wp_genesis 1282 $v_result = PCLZIP_ERR_INVALID_PARAMETER;
mp-wp_genesis 1283 }
mp-wp_genesis 1284
mp-wp_genesis 1285 // ----- Return
mp-wp_genesis 1286 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 1287 return $v_result;
mp-wp_genesis 1288 }
mp-wp_genesis 1289 // --------------------------------------------------------------------------------
mp-wp_genesis 1290
mp-wp_genesis 1291
mp-wp_genesis 1292
mp-wp_genesis 1293 // --------------------------------------------------------------------------------
mp-wp_genesis 1294 // Function : errorCode()
mp-wp_genesis 1295 // Description :
mp-wp_genesis 1296 // Parameters :
mp-wp_genesis 1297 // --------------------------------------------------------------------------------
mp-wp_genesis 1298 function errorCode()
mp-wp_genesis 1299 {
mp-wp_genesis 1300 if (PCLZIP_ERROR_EXTERNAL == 1) {
mp-wp_genesis 1301 return(PclErrorCode());
mp-wp_genesis 1302 }
mp-wp_genesis 1303 else {
mp-wp_genesis 1304 return($this->error_code);
mp-wp_genesis 1305 }
mp-wp_genesis 1306 }
mp-wp_genesis 1307 // --------------------------------------------------------------------------------
mp-wp_genesis 1308
mp-wp_genesis 1309 // --------------------------------------------------------------------------------
mp-wp_genesis 1310 // Function : errorName()
mp-wp_genesis 1311 // Description :
mp-wp_genesis 1312 // Parameters :
mp-wp_genesis 1313 // --------------------------------------------------------------------------------
mp-wp_genesis 1314 function errorName($p_with_code=false)
mp-wp_genesis 1315 {
mp-wp_genesis 1316 $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
mp-wp_genesis 1317 PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
mp-wp_genesis 1318 PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
mp-wp_genesis 1319 PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
mp-wp_genesis 1320 PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
mp-wp_genesis 1321 PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
mp-wp_genesis 1322 PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
mp-wp_genesis 1323 PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
mp-wp_genesis 1324 PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
mp-wp_genesis 1325 PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
mp-wp_genesis 1326 PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
mp-wp_genesis 1327 PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
mp-wp_genesis 1328 PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
mp-wp_genesis 1329 PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
mp-wp_genesis 1330 PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
mp-wp_genesis 1331 PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
mp-wp_genesis 1332 PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
mp-wp_genesis 1333 PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
mp-wp_genesis 1334 PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
mp-wp_genesis 1335 ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
mp-wp_genesis 1336 ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
mp-wp_genesis 1337 );
mp-wp_genesis 1338
mp-wp_genesis 1339 if (isset($v_name[$this->error_code])) {
mp-wp_genesis 1340 $v_value = $v_name[$this->error_code];
mp-wp_genesis 1341 }
mp-wp_genesis 1342 else {
mp-wp_genesis 1343 $v_value = 'NoName';
mp-wp_genesis 1344 }
mp-wp_genesis 1345
mp-wp_genesis 1346 if ($p_with_code) {
mp-wp_genesis 1347 return($v_value.' ('.$this->error_code.')');
mp-wp_genesis 1348 }
mp-wp_genesis 1349 else {
mp-wp_genesis 1350 return($v_value);
mp-wp_genesis 1351 }
mp-wp_genesis 1352 }
mp-wp_genesis 1353 // --------------------------------------------------------------------------------
mp-wp_genesis 1354
mp-wp_genesis 1355 // --------------------------------------------------------------------------------
mp-wp_genesis 1356 // Function : errorInfo()
mp-wp_genesis 1357 // Description :
mp-wp_genesis 1358 // Parameters :
mp-wp_genesis 1359 // --------------------------------------------------------------------------------
mp-wp_genesis 1360 function errorInfo($p_full=false)
mp-wp_genesis 1361 {
mp-wp_genesis 1362 if (PCLZIP_ERROR_EXTERNAL == 1) {
mp-wp_genesis 1363 return(PclErrorString());
mp-wp_genesis 1364 }
mp-wp_genesis 1365 else {
mp-wp_genesis 1366 if ($p_full) {
mp-wp_genesis 1367 return($this->errorName(true)." : ".$this->error_string);
mp-wp_genesis 1368 }
mp-wp_genesis 1369 else {
mp-wp_genesis 1370 return($this->error_string." [code ".$this->error_code."]");
mp-wp_genesis 1371 }
mp-wp_genesis 1372 }
mp-wp_genesis 1373 }
mp-wp_genesis 1374 // --------------------------------------------------------------------------------
mp-wp_genesis 1375
mp-wp_genesis 1376
mp-wp_genesis 1377 // --------------------------------------------------------------------------------
mp-wp_genesis 1378 // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
mp-wp_genesis 1379 // ***** *****
mp-wp_genesis 1380 // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
mp-wp_genesis 1381 // --------------------------------------------------------------------------------
mp-wp_genesis 1382
mp-wp_genesis 1383
mp-wp_genesis 1384
mp-wp_genesis 1385 // --------------------------------------------------------------------------------
mp-wp_genesis 1386 // Function : privCheckFormat()
mp-wp_genesis 1387 // Description :
mp-wp_genesis 1388 // This method check that the archive exists and is a valid zip archive.
mp-wp_genesis 1389 // Several level of check exists. (futur)
mp-wp_genesis 1390 // Parameters :
mp-wp_genesis 1391 // $p_level : Level of check. Default 0.
mp-wp_genesis 1392 // 0 : Check the first bytes (magic codes) (default value))
mp-wp_genesis 1393 // 1 : 0 + Check the central directory (futur)
mp-wp_genesis 1394 // 2 : 1 + Check each file header (futur)
mp-wp_genesis 1395 // Return Values :
mp-wp_genesis 1396 // true on success,
mp-wp_genesis 1397 // false on error, the error code is set.
mp-wp_genesis 1398 // --------------------------------------------------------------------------------
mp-wp_genesis 1399 function privCheckFormat($p_level=0)
mp-wp_genesis 1400 {
mp-wp_genesis 1401 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");
mp-wp_genesis 1402 $v_result = true;
mp-wp_genesis 1403
mp-wp_genesis 1404 // ----- Reset the file system cache
mp-wp_genesis 1405 clearstatcache();
mp-wp_genesis 1406
mp-wp_genesis 1407 // ----- Reset the error handler
mp-wp_genesis 1408 $this->privErrorReset();
mp-wp_genesis 1409
mp-wp_genesis 1410 // ----- Look if the file exits
mp-wp_genesis 1411 if (!is_file($this->zipname)) {
mp-wp_genesis 1412 // ----- Error log
mp-wp_genesis 1413 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
mp-wp_genesis 1414 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
mp-wp_genesis 1415 return(false);
mp-wp_genesis 1416 }
mp-wp_genesis 1417
mp-wp_genesis 1418 // ----- Check that the file is readeable
mp-wp_genesis 1419 if (!is_readable($this->zipname)) {
mp-wp_genesis 1420 // ----- Error log
mp-wp_genesis 1421 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
mp-wp_genesis 1422 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
mp-wp_genesis 1423 return(false);
mp-wp_genesis 1424 }
mp-wp_genesis 1425
mp-wp_genesis 1426 // ----- Check the magic code
mp-wp_genesis 1427 // TBC
mp-wp_genesis 1428
mp-wp_genesis 1429 // ----- Check the central header
mp-wp_genesis 1430 // TBC
mp-wp_genesis 1431
mp-wp_genesis 1432 // ----- Check each file header
mp-wp_genesis 1433 // TBC
mp-wp_genesis 1434
mp-wp_genesis 1435 // ----- Return
mp-wp_genesis 1436 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 1437 return $v_result;
mp-wp_genesis 1438 }
mp-wp_genesis 1439 // --------------------------------------------------------------------------------
mp-wp_genesis 1440
mp-wp_genesis 1441 // --------------------------------------------------------------------------------
mp-wp_genesis 1442 // Function : privParseOptions()
mp-wp_genesis 1443 // Description :
mp-wp_genesis 1444 // This internal methods reads the variable list of arguments ($p_options_list,
mp-wp_genesis 1445 // $p_size) and generate an array with the options and values ($v_result_list).
mp-wp_genesis 1446 // $v_requested_options contains the options that can be present and those that
mp-wp_genesis 1447 // must be present.
mp-wp_genesis 1448 // $v_requested_options is an array, with the option value as key, and 'optional',
mp-wp_genesis 1449 // or 'mandatory' as value.
mp-wp_genesis 1450 // Parameters :
mp-wp_genesis 1451 // See above.
mp-wp_genesis 1452 // Return Values :
mp-wp_genesis 1453 // 1 on success.
mp-wp_genesis 1454 // 0 on failure.
mp-wp_genesis 1455 // --------------------------------------------------------------------------------
mp-wp_genesis 1456 function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
mp-wp_genesis 1457 {
mp-wp_genesis 1458 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");
mp-wp_genesis 1459 $v_result=1;
mp-wp_genesis 1460
mp-wp_genesis 1461 // ----- Read the options
mp-wp_genesis 1462 $i=0;
mp-wp_genesis 1463 while ($i<$p_size) {
mp-wp_genesis 1464 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'");
mp-wp_genesis 1465
mp-wp_genesis 1466 // ----- Check if the option is supported
mp-wp_genesis 1467 if (!isset($v_requested_options[$p_options_list[$i]])) {
mp-wp_genesis 1468 // ----- Error log
mp-wp_genesis 1469 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
mp-wp_genesis 1470
mp-wp_genesis 1471 // ----- Return
mp-wp_genesis 1472 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1473 return PclZip::errorCode();
mp-wp_genesis 1474 }
mp-wp_genesis 1475
mp-wp_genesis 1476 // ----- Look for next option
mp-wp_genesis 1477 switch ($p_options_list[$i]) {
mp-wp_genesis 1478 // ----- Look for options that request a path value
mp-wp_genesis 1479 case PCLZIP_OPT_PATH :
mp-wp_genesis 1480 case PCLZIP_OPT_REMOVE_PATH :
mp-wp_genesis 1481 case PCLZIP_OPT_ADD_PATH :
mp-wp_genesis 1482 // ----- Check the number of parameters
mp-wp_genesis 1483 if (($i+1) >= $p_size) {
mp-wp_genesis 1484 // ----- Error log
mp-wp_genesis 1485 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1486
mp-wp_genesis 1487 // ----- Return
mp-wp_genesis 1488 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1489 return PclZip::errorCode();
mp-wp_genesis 1490 }
mp-wp_genesis 1491
mp-wp_genesis 1492 // ----- Get the value
mp-wp_genesis 1493 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
mp-wp_genesis 1494 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
mp-wp_genesis 1495 $i++;
mp-wp_genesis 1496 break;
mp-wp_genesis 1497
mp-wp_genesis 1498 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
mp-wp_genesis 1499 // ----- Check the number of parameters
mp-wp_genesis 1500 if (($i+1) >= $p_size) {
mp-wp_genesis 1501 // ----- Error log
mp-wp_genesis 1502 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1503
mp-wp_genesis 1504 // ----- Return
mp-wp_genesis 1505 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1506 return PclZip::errorCode();
mp-wp_genesis 1507 }
mp-wp_genesis 1508
mp-wp_genesis 1509 // ----- Get the value
mp-wp_genesis 1510 if ( is_string($p_options_list[$i+1])
mp-wp_genesis 1511 && ($p_options_list[$i+1] != '')) {
mp-wp_genesis 1512 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
mp-wp_genesis 1513 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
mp-wp_genesis 1514 $i++;
mp-wp_genesis 1515 }
mp-wp_genesis 1516 else {
mp-wp_genesis 1517 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored.");
mp-wp_genesis 1518 }
mp-wp_genesis 1519 break;
mp-wp_genesis 1520
mp-wp_genesis 1521 // ----- Look for options that request an array of string for value
mp-wp_genesis 1522 case PCLZIP_OPT_BY_NAME :
mp-wp_genesis 1523 // ----- Check the number of parameters
mp-wp_genesis 1524 if (($i+1) >= $p_size) {
mp-wp_genesis 1525 // ----- Error log
mp-wp_genesis 1526 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1527
mp-wp_genesis 1528 // ----- Return
mp-wp_genesis 1529 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1530 return PclZip::errorCode();
mp-wp_genesis 1531 }
mp-wp_genesis 1532
mp-wp_genesis 1533 // ----- Get the value
mp-wp_genesis 1534 if (is_string($p_options_list[$i+1])) {
mp-wp_genesis 1535 $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
mp-wp_genesis 1536 }
mp-wp_genesis 1537 else if (is_array($p_options_list[$i+1])) {
mp-wp_genesis 1538 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
mp-wp_genesis 1539 }
mp-wp_genesis 1540 else {
mp-wp_genesis 1541 // ----- Error log
mp-wp_genesis 1542 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1543
mp-wp_genesis 1544 // ----- Return
mp-wp_genesis 1545 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1546 return PclZip::errorCode();
mp-wp_genesis 1547 }
mp-wp_genesis 1548 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
mp-wp_genesis 1549 $i++;
mp-wp_genesis 1550 break;
mp-wp_genesis 1551
mp-wp_genesis 1552 // ----- Look for options that request an EREG or PREG expression
mp-wp_genesis 1553 case PCLZIP_OPT_BY_EREG :
mp-wp_genesis 1554 case PCLZIP_OPT_BY_PREG :
mp-wp_genesis 1555 //case PCLZIP_OPT_CRYPT :
mp-wp_genesis 1556 // ----- Check the number of parameters
mp-wp_genesis 1557 if (($i+1) >= $p_size) {
mp-wp_genesis 1558 // ----- Error log
mp-wp_genesis 1559 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1560
mp-wp_genesis 1561 // ----- Return
mp-wp_genesis 1562 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1563 return PclZip::errorCode();
mp-wp_genesis 1564 }
mp-wp_genesis 1565
mp-wp_genesis 1566 // ----- Get the value
mp-wp_genesis 1567 if (is_string($p_options_list[$i+1])) {
mp-wp_genesis 1568 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
mp-wp_genesis 1569 }
mp-wp_genesis 1570 else {
mp-wp_genesis 1571 // ----- Error log
mp-wp_genesis 1572 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1573
mp-wp_genesis 1574 // ----- Return
mp-wp_genesis 1575 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1576 return PclZip::errorCode();
mp-wp_genesis 1577 }
mp-wp_genesis 1578 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
mp-wp_genesis 1579 $i++;
mp-wp_genesis 1580 break;
mp-wp_genesis 1581
mp-wp_genesis 1582 // ----- Look for options that takes a string
mp-wp_genesis 1583 case PCLZIP_OPT_COMMENT :
mp-wp_genesis 1584 case PCLZIP_OPT_ADD_COMMENT :
mp-wp_genesis 1585 case PCLZIP_OPT_PREPEND_COMMENT :
mp-wp_genesis 1586 // ----- Check the number of parameters
mp-wp_genesis 1587 if (($i+1) >= $p_size) {
mp-wp_genesis 1588 // ----- Error log
mp-wp_genesis 1589 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
mp-wp_genesis 1590 "Missing parameter value for option '"
mp-wp_genesis 1591 .PclZipUtilOptionText($p_options_list[$i])
mp-wp_genesis 1592 ."'");
mp-wp_genesis 1593
mp-wp_genesis 1594 // ----- Return
mp-wp_genesis 1595 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1596 return PclZip::errorCode();
mp-wp_genesis 1597 }
mp-wp_genesis 1598
mp-wp_genesis 1599 // ----- Get the value
mp-wp_genesis 1600 if (is_string($p_options_list[$i+1])) {
mp-wp_genesis 1601 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
mp-wp_genesis 1602 }
mp-wp_genesis 1603 else {
mp-wp_genesis 1604 // ----- Error log
mp-wp_genesis 1605 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
mp-wp_genesis 1606 "Wrong parameter value for option '"
mp-wp_genesis 1607 .PclZipUtilOptionText($p_options_list[$i])
mp-wp_genesis 1608 ."'");
mp-wp_genesis 1609
mp-wp_genesis 1610 // ----- Return
mp-wp_genesis 1611 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1612 return PclZip::errorCode();
mp-wp_genesis 1613 }
mp-wp_genesis 1614 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
mp-wp_genesis 1615 $i++;
mp-wp_genesis 1616 break;
mp-wp_genesis 1617
mp-wp_genesis 1618 // ----- Look for options that request an array of index
mp-wp_genesis 1619 case PCLZIP_OPT_BY_INDEX :
mp-wp_genesis 1620 // ----- Check the number of parameters
mp-wp_genesis 1621 if (($i+1) >= $p_size) {
mp-wp_genesis 1622 // ----- Error log
mp-wp_genesis 1623 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1624
mp-wp_genesis 1625 // ----- Return
mp-wp_genesis 1626 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1627 return PclZip::errorCode();
mp-wp_genesis 1628 }
mp-wp_genesis 1629
mp-wp_genesis 1630 // ----- Get the value
mp-wp_genesis 1631 $v_work_list = array();
mp-wp_genesis 1632 if (is_string($p_options_list[$i+1])) {
mp-wp_genesis 1633 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'");
mp-wp_genesis 1634
mp-wp_genesis 1635 // ----- Remove spaces
mp-wp_genesis 1636 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
mp-wp_genesis 1637
mp-wp_genesis 1638 // ----- Parse items
mp-wp_genesis 1639 $v_work_list = explode(",", $p_options_list[$i+1]);
mp-wp_genesis 1640 }
mp-wp_genesis 1641 else if (is_integer($p_options_list[$i+1])) {
mp-wp_genesis 1642 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'");
mp-wp_genesis 1643 $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
mp-wp_genesis 1644 }
mp-wp_genesis 1645 else if (is_array($p_options_list[$i+1])) {
mp-wp_genesis 1646 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array");
mp-wp_genesis 1647 $v_work_list = $p_options_list[$i+1];
mp-wp_genesis 1648 }
mp-wp_genesis 1649 else {
mp-wp_genesis 1650 // ----- Error log
mp-wp_genesis 1651 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1652
mp-wp_genesis 1653 // ----- Return
mp-wp_genesis 1654 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1655 return PclZip::errorCode();
mp-wp_genesis 1656 }
mp-wp_genesis 1657
mp-wp_genesis 1658 // ----- Reduce the index list
mp-wp_genesis 1659 // each index item in the list must be a couple with a start and
mp-wp_genesis 1660 // an end value : [0,3], [5-5], [8-10], ...
mp-wp_genesis 1661 // ----- Check the format of each item
mp-wp_genesis 1662 $v_sort_flag=false;
mp-wp_genesis 1663 $v_sort_value=0;
mp-wp_genesis 1664 for ($j=0; $j<sizeof($v_work_list); $j++) {
mp-wp_genesis 1665 // ----- Explode the item
mp-wp_genesis 1666 $v_item_list = explode("-", $v_work_list[$j]);
mp-wp_genesis 1667 $v_size_item_list = sizeof($v_item_list);
mp-wp_genesis 1668
mp-wp_genesis 1669 // ----- TBC : Here we might check that each item is a
mp-wp_genesis 1670 // real integer ...
mp-wp_genesis 1671
mp-wp_genesis 1672 // ----- Look for single value
mp-wp_genesis 1673 if ($v_size_item_list == 1) {
mp-wp_genesis 1674 // ----- Set the option value
mp-wp_genesis 1675 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
mp-wp_genesis 1676 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
mp-wp_genesis 1677 }
mp-wp_genesis 1678 elseif ($v_size_item_list == 2) {
mp-wp_genesis 1679 // ----- Set the option value
mp-wp_genesis 1680 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
mp-wp_genesis 1681 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
mp-wp_genesis 1682 }
mp-wp_genesis 1683 else {
mp-wp_genesis 1684 // ----- Error log
mp-wp_genesis 1685 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1686
mp-wp_genesis 1687 // ----- Return
mp-wp_genesis 1688 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1689 return PclZip::errorCode();
mp-wp_genesis 1690 }
mp-wp_genesis 1691
mp-wp_genesis 1692 //--(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']."]");
mp-wp_genesis 1693
mp-wp_genesis 1694 // ----- Look for list sort
mp-wp_genesis 1695 if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
mp-wp_genesis 1696 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ...");
mp-wp_genesis 1697 $v_sort_flag=true;
mp-wp_genesis 1698
mp-wp_genesis 1699 // ----- TBC : An automatic sort should be writen ...
mp-wp_genesis 1700 // ----- Error log
mp-wp_genesis 1701 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1702
mp-wp_genesis 1703 // ----- Return
mp-wp_genesis 1704 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1705 return PclZip::errorCode();
mp-wp_genesis 1706 }
mp-wp_genesis 1707 $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
mp-wp_genesis 1708 }
mp-wp_genesis 1709
mp-wp_genesis 1710 // ----- Sort the items
mp-wp_genesis 1711 if ($v_sort_flag) {
mp-wp_genesis 1712 // TBC : To Be Completed
mp-wp_genesis 1713 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ...");
mp-wp_genesis 1714 }
mp-wp_genesis 1715
mp-wp_genesis 1716 // ----- Next option
mp-wp_genesis 1717 $i++;
mp-wp_genesis 1718 break;
mp-wp_genesis 1719
mp-wp_genesis 1720 // ----- Look for options that request no value
mp-wp_genesis 1721 case PCLZIP_OPT_REMOVE_ALL_PATH :
mp-wp_genesis 1722 case PCLZIP_OPT_EXTRACT_AS_STRING :
mp-wp_genesis 1723 case PCLZIP_OPT_NO_COMPRESSION :
mp-wp_genesis 1724 case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
mp-wp_genesis 1725 case PCLZIP_OPT_REPLACE_NEWER :
mp-wp_genesis 1726 case PCLZIP_OPT_STOP_ON_ERROR :
mp-wp_genesis 1727 $v_result_list[$p_options_list[$i]] = true;
mp-wp_genesis 1728 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
mp-wp_genesis 1729 break;
mp-wp_genesis 1730
mp-wp_genesis 1731 // ----- Look for options that request an octal value
mp-wp_genesis 1732 case PCLZIP_OPT_SET_CHMOD :
mp-wp_genesis 1733 // ----- Check the number of parameters
mp-wp_genesis 1734 if (($i+1) >= $p_size) {
mp-wp_genesis 1735 // ----- Error log
mp-wp_genesis 1736 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1737
mp-wp_genesis 1738 // ----- Return
mp-wp_genesis 1739 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1740 return PclZip::errorCode();
mp-wp_genesis 1741 }
mp-wp_genesis 1742
mp-wp_genesis 1743 // ----- Get the value
mp-wp_genesis 1744 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
mp-wp_genesis 1745 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
mp-wp_genesis 1746 $i++;
mp-wp_genesis 1747 break;
mp-wp_genesis 1748
mp-wp_genesis 1749 // ----- Look for options that request a call-back
mp-wp_genesis 1750 case PCLZIP_CB_PRE_EXTRACT :
mp-wp_genesis 1751 case PCLZIP_CB_POST_EXTRACT :
mp-wp_genesis 1752 case PCLZIP_CB_PRE_ADD :
mp-wp_genesis 1753 case PCLZIP_CB_POST_ADD :
mp-wp_genesis 1754 /* for futur use
mp-wp_genesis 1755 case PCLZIP_CB_PRE_DELETE :
mp-wp_genesis 1756 case PCLZIP_CB_POST_DELETE :
mp-wp_genesis 1757 case PCLZIP_CB_PRE_LIST :
mp-wp_genesis 1758 case PCLZIP_CB_POST_LIST :
mp-wp_genesis 1759 */
mp-wp_genesis 1760 // ----- Check the number of parameters
mp-wp_genesis 1761 if (($i+1) >= $p_size) {
mp-wp_genesis 1762 // ----- Error log
mp-wp_genesis 1763 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1764
mp-wp_genesis 1765 // ----- Return
mp-wp_genesis 1766 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1767 return PclZip::errorCode();
mp-wp_genesis 1768 }
mp-wp_genesis 1769
mp-wp_genesis 1770 // ----- Get the value
mp-wp_genesis 1771 $v_function_name = $p_options_list[$i+1];
mp-wp_genesis 1772 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'");
mp-wp_genesis 1773
mp-wp_genesis 1774 // ----- Check that the value is a valid existing function
mp-wp_genesis 1775 if (!function_exists($v_function_name)) {
mp-wp_genesis 1776 // ----- Error log
mp-wp_genesis 1777 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
mp-wp_genesis 1778
mp-wp_genesis 1779 // ----- Return
mp-wp_genesis 1780 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1781 return PclZip::errorCode();
mp-wp_genesis 1782 }
mp-wp_genesis 1783
mp-wp_genesis 1784 // ----- Set the attribute
mp-wp_genesis 1785 $v_result_list[$p_options_list[$i]] = $v_function_name;
mp-wp_genesis 1786 $i++;
mp-wp_genesis 1787 break;
mp-wp_genesis 1788
mp-wp_genesis 1789 default :
mp-wp_genesis 1790 // ----- Error log
mp-wp_genesis 1791 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
mp-wp_genesis 1792 "Unknown parameter '"
mp-wp_genesis 1793 .$p_options_list[$i]."'");
mp-wp_genesis 1794
mp-wp_genesis 1795 // ----- Return
mp-wp_genesis 1796 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1797 return PclZip::errorCode();
mp-wp_genesis 1798 }
mp-wp_genesis 1799
mp-wp_genesis 1800 // ----- Next options
mp-wp_genesis 1801 $i++;
mp-wp_genesis 1802 }
mp-wp_genesis 1803
mp-wp_genesis 1804 // ----- Look for mandatory options
mp-wp_genesis 1805 if ($v_requested_options !== false) {
mp-wp_genesis 1806 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
mp-wp_genesis 1807 // ----- Look for mandatory option
mp-wp_genesis 1808 if ($v_requested_options[$key] == 'mandatory') {
mp-wp_genesis 1809 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
mp-wp_genesis 1810 // ----- Look if present
mp-wp_genesis 1811 if (!isset($v_result_list[$key])) {
mp-wp_genesis 1812 // ----- Error log
mp-wp_genesis 1813 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
mp-wp_genesis 1814
mp-wp_genesis 1815 // ----- Return
mp-wp_genesis 1816 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1817 return PclZip::errorCode();
mp-wp_genesis 1818 }
mp-wp_genesis 1819 }
mp-wp_genesis 1820 }
mp-wp_genesis 1821 }
mp-wp_genesis 1822
mp-wp_genesis 1823 // ----- Return
mp-wp_genesis 1824 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 1825 return $v_result;
mp-wp_genesis 1826 }
mp-wp_genesis 1827 // --------------------------------------------------------------------------------
mp-wp_genesis 1828
mp-wp_genesis 1829 // --------------------------------------------------------------------------------
mp-wp_genesis 1830 // Function : privFileDescrParseAtt()
mp-wp_genesis 1831 // Description :
mp-wp_genesis 1832 // Parameters :
mp-wp_genesis 1833 // Return Values :
mp-wp_genesis 1834 // 1 on success.
mp-wp_genesis 1835 // 0 on failure.
mp-wp_genesis 1836 // --------------------------------------------------------------------------------
mp-wp_genesis 1837 function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
mp-wp_genesis 1838 {
mp-wp_genesis 1839 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", "");
mp-wp_genesis 1840 $v_result=1;
mp-wp_genesis 1841
mp-wp_genesis 1842 // ----- For each file in the list check the attributes
mp-wp_genesis 1843 foreach ($p_file_list as $v_key => $v_value) {
mp-wp_genesis 1844
mp-wp_genesis 1845 // ----- Check if the option is supported
mp-wp_genesis 1846 if (!isset($v_requested_options[$v_key])) {
mp-wp_genesis 1847 // ----- Error log
mp-wp_genesis 1848 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
mp-wp_genesis 1849
mp-wp_genesis 1850 // ----- Return
mp-wp_genesis 1851 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1852 return PclZip::errorCode();
mp-wp_genesis 1853 }
mp-wp_genesis 1854
mp-wp_genesis 1855 // ----- Look for attribute
mp-wp_genesis 1856 switch ($v_key) {
mp-wp_genesis 1857 case PCLZIP_ATT_FILE_NAME :
mp-wp_genesis 1858 if (!is_string($v_value)) {
mp-wp_genesis 1859 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
mp-wp_genesis 1860 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1861 return PclZip::errorCode();
mp-wp_genesis 1862 }
mp-wp_genesis 1863
mp-wp_genesis 1864 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
mp-wp_genesis 1865 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
mp-wp_genesis 1866
mp-wp_genesis 1867 if ($p_filedescr['filename'] == '') {
mp-wp_genesis 1868 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
mp-wp_genesis 1869 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1870 return PclZip::errorCode();
mp-wp_genesis 1871 }
mp-wp_genesis 1872
mp-wp_genesis 1873 break;
mp-wp_genesis 1874
mp-wp_genesis 1875 case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
mp-wp_genesis 1876 if (!is_string($v_value)) {
mp-wp_genesis 1877 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
mp-wp_genesis 1878 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1879 return PclZip::errorCode();
mp-wp_genesis 1880 }
mp-wp_genesis 1881
mp-wp_genesis 1882 $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
mp-wp_genesis 1883 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
mp-wp_genesis 1884
mp-wp_genesis 1885 if ($p_filedescr['new_short_name'] == '') {
mp-wp_genesis 1886 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
mp-wp_genesis 1887 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1888 return PclZip::errorCode();
mp-wp_genesis 1889 }
mp-wp_genesis 1890 break;
mp-wp_genesis 1891
mp-wp_genesis 1892 case PCLZIP_ATT_FILE_NEW_FULL_NAME :
mp-wp_genesis 1893 if (!is_string($v_value)) {
mp-wp_genesis 1894 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
mp-wp_genesis 1895 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1896 return PclZip::errorCode();
mp-wp_genesis 1897 }
mp-wp_genesis 1898
mp-wp_genesis 1899 $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
mp-wp_genesis 1900 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
mp-wp_genesis 1901
mp-wp_genesis 1902 if ($p_filedescr['new_full_name'] == '') {
mp-wp_genesis 1903 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
mp-wp_genesis 1904 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1905 return PclZip::errorCode();
mp-wp_genesis 1906 }
mp-wp_genesis 1907 break;
mp-wp_genesis 1908
mp-wp_genesis 1909 default :
mp-wp_genesis 1910 // ----- Error log
mp-wp_genesis 1911 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
mp-wp_genesis 1912 "Unknown parameter '".$v_key."'");
mp-wp_genesis 1913
mp-wp_genesis 1914 // ----- Return
mp-wp_genesis 1915 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1916 return PclZip::errorCode();
mp-wp_genesis 1917 }
mp-wp_genesis 1918
mp-wp_genesis 1919 // ----- Look for mandatory options
mp-wp_genesis 1920 if ($v_requested_options !== false) {
mp-wp_genesis 1921 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
mp-wp_genesis 1922 // ----- Look for mandatory option
mp-wp_genesis 1923 if ($v_requested_options[$key] == 'mandatory') {
mp-wp_genesis 1924 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
mp-wp_genesis 1925 // ----- Look if present
mp-wp_genesis 1926 if (!isset($p_file_list[$key])) {
mp-wp_genesis 1927 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
mp-wp_genesis 1928 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1929 return PclZip::errorCode();
mp-wp_genesis 1930 }
mp-wp_genesis 1931 }
mp-wp_genesis 1932 }
mp-wp_genesis 1933 }
mp-wp_genesis 1934
mp-wp_genesis 1935 // end foreach
mp-wp_genesis 1936 }
mp-wp_genesis 1937
mp-wp_genesis 1938 // ----- Return
mp-wp_genesis 1939 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 1940 return $v_result;
mp-wp_genesis 1941 }
mp-wp_genesis 1942 // --------------------------------------------------------------------------------
mp-wp_genesis 1943
mp-wp_genesis 1944 // --------------------------------------------------------------------------------
mp-wp_genesis 1945 // Function : privFileDescrExpand()
mp-wp_genesis 1946 // Description :
mp-wp_genesis 1947 // Parameters :
mp-wp_genesis 1948 // Return Values :
mp-wp_genesis 1949 // 1 on success.
mp-wp_genesis 1950 // 0 on failure.
mp-wp_genesis 1951 // --------------------------------------------------------------------------------
mp-wp_genesis 1952 function privFileDescrExpand(&$p_filedescr_list, &$p_options)
mp-wp_genesis 1953 {
mp-wp_genesis 1954 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", "");
mp-wp_genesis 1955 $v_result=1;
mp-wp_genesis 1956
mp-wp_genesis 1957 // ----- Create a result list
mp-wp_genesis 1958 $v_result_list = array();
mp-wp_genesis 1959
mp-wp_genesis 1960 // ----- Look each entry
mp-wp_genesis 1961 for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
mp-wp_genesis 1962 // ----- Get filedescr
mp-wp_genesis 1963 $v_descr = $p_filedescr_list[$i];
mp-wp_genesis 1964
mp-wp_genesis 1965 // ----- Reduce the filename
mp-wp_genesis 1966 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'");
mp-wp_genesis 1967 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']);
mp-wp_genesis 1968 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
mp-wp_genesis 1969 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'");
mp-wp_genesis 1970
mp-wp_genesis 1971 // ----- Get type of descr
mp-wp_genesis 1972 if (!file_exists($v_descr['filename'])) {
mp-wp_genesis 1973 // ----- Error log
mp-wp_genesis 1974 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exists");
mp-wp_genesis 1975 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists");
mp-wp_genesis 1976
mp-wp_genesis 1977 // ----- Return
mp-wp_genesis 1978 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 1979 return PclZip::errorCode();
mp-wp_genesis 1980 }
mp-wp_genesis 1981 if (@is_file($v_descr['filename'])) {
mp-wp_genesis 1982 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file");
mp-wp_genesis 1983 $v_descr['type'] = 'file';
mp-wp_genesis 1984 }
mp-wp_genesis 1985 else if (@is_dir($v_descr['filename'])) {
mp-wp_genesis 1986 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder");
mp-wp_genesis 1987 $v_descr['type'] = 'folder';
mp-wp_genesis 1988 }
mp-wp_genesis 1989 else if (@is_link($v_descr['filename'])) {
mp-wp_genesis 1990 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link");
mp-wp_genesis 1991 // skip
mp-wp_genesis 1992 continue;
mp-wp_genesis 1993 }
mp-wp_genesis 1994 else {
mp-wp_genesis 1995 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type");
mp-wp_genesis 1996 // skip
mp-wp_genesis 1997 continue;
mp-wp_genesis 1998 }
mp-wp_genesis 1999
mp-wp_genesis 2000 // ----- Calculate the stored filename
mp-wp_genesis 2001 $this->privCalculateStoredFilename($v_descr, $p_options);
mp-wp_genesis 2002
mp-wp_genesis 2003 // ----- Add the descriptor in result list
mp-wp_genesis 2004 $v_result_list[sizeof($v_result_list)] = $v_descr;
mp-wp_genesis 2005
mp-wp_genesis 2006 // ----- Look for folder
mp-wp_genesis 2007 if ($v_descr['type'] == 'folder') {
mp-wp_genesis 2008 // ----- List of items in folder
mp-wp_genesis 2009 $v_dirlist_descr = array();
mp-wp_genesis 2010 $v_dirlist_nb = 0;
mp-wp_genesis 2011 if ($v_folder_handler = @opendir($v_descr['filename'])) {
mp-wp_genesis 2012 while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
mp-wp_genesis 2013 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory");
mp-wp_genesis 2014
mp-wp_genesis 2015 // ----- Skip '.' and '..'
mp-wp_genesis 2016 if (($v_item_handler == '.') || ($v_item_handler == '..')) {
mp-wp_genesis 2017 continue;
mp-wp_genesis 2018 }
mp-wp_genesis 2019
mp-wp_genesis 2020 // ----- Compose the full filename
mp-wp_genesis 2021 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
mp-wp_genesis 2022
mp-wp_genesis 2023 // ----- Look for different stored filename
mp-wp_genesis 2024 // Because the name of the folder was changed, the name of the
mp-wp_genesis 2025 // files/sub-folders also change
mp-wp_genesis 2026 if ($v_descr['stored_filename'] != $v_descr['filename']) {
mp-wp_genesis 2027 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
mp-wp_genesis 2028 }
mp-wp_genesis 2029
mp-wp_genesis 2030 $v_dirlist_nb++;
mp-wp_genesis 2031 }
mp-wp_genesis 2032 }
mp-wp_genesis 2033 else {
mp-wp_genesis 2034 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped.");
mp-wp_genesis 2035 // TBC : unable to open folder in read mode
mp-wp_genesis 2036 }
mp-wp_genesis 2037
mp-wp_genesis 2038 // ----- Expand each element of the list
mp-wp_genesis 2039 if ($v_dirlist_nb != 0) {
mp-wp_genesis 2040 // ----- Expand
mp-wp_genesis 2041 if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
mp-wp_genesis 2042 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2043 return $v_result;
mp-wp_genesis 2044 }
mp-wp_genesis 2045
mp-wp_genesis 2046 // ----- Concat the resulting list
mp-wp_genesis 2047 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')");
mp-wp_genesis 2048 $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
mp-wp_genesis 2049 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'");
mp-wp_genesis 2050 }
mp-wp_genesis 2051 else {
mp-wp_genesis 2052 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand.");
mp-wp_genesis 2053 }
mp-wp_genesis 2054
mp-wp_genesis 2055 // ----- Free local array
mp-wp_genesis 2056 unset($v_dirlist_descr);
mp-wp_genesis 2057 }
mp-wp_genesis 2058 }
mp-wp_genesis 2059
mp-wp_genesis 2060 // ----- Get the result list
mp-wp_genesis 2061 $p_filedescr_list = $v_result_list;
mp-wp_genesis 2062
mp-wp_genesis 2063 // ----- Return
mp-wp_genesis 2064 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2065 return $v_result;
mp-wp_genesis 2066 }
mp-wp_genesis 2067 // --------------------------------------------------------------------------------
mp-wp_genesis 2068
mp-wp_genesis 2069 // --------------------------------------------------------------------------------
mp-wp_genesis 2070 // Function : privCreate()
mp-wp_genesis 2071 // Description :
mp-wp_genesis 2072 // Parameters :
mp-wp_genesis 2073 // Return Values :
mp-wp_genesis 2074 // --------------------------------------------------------------------------------
mp-wp_genesis 2075 function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
mp-wp_genesis 2076 {
mp-wp_genesis 2077 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list");
mp-wp_genesis 2078 $v_result=1;
mp-wp_genesis 2079 $v_list_detail = array();
mp-wp_genesis 2080
mp-wp_genesis 2081 // ----- Magic quotes trick
mp-wp_genesis 2082 $this->privDisableMagicQuotes();
mp-wp_genesis 2083
mp-wp_genesis 2084 // ----- Open the file in write mode
mp-wp_genesis 2085 if (($v_result = $this->privOpenFd('wb')) != 1)
mp-wp_genesis 2086 {
mp-wp_genesis 2087 // ----- Return
mp-wp_genesis 2088 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2089 return $v_result;
mp-wp_genesis 2090 }
mp-wp_genesis 2091
mp-wp_genesis 2092 // ----- Add the list of files
mp-wp_genesis 2093 $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
mp-wp_genesis 2094
mp-wp_genesis 2095 // ----- Close
mp-wp_genesis 2096 $this->privCloseFd();
mp-wp_genesis 2097
mp-wp_genesis 2098 // ----- Magic quotes trick
mp-wp_genesis 2099 $this->privSwapBackMagicQuotes();
mp-wp_genesis 2100
mp-wp_genesis 2101 // ----- Return
mp-wp_genesis 2102 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2103 return $v_result;
mp-wp_genesis 2104 }
mp-wp_genesis 2105 // --------------------------------------------------------------------------------
mp-wp_genesis 2106
mp-wp_genesis 2107 // --------------------------------------------------------------------------------
mp-wp_genesis 2108 // Function : privAdd()
mp-wp_genesis 2109 // Description :
mp-wp_genesis 2110 // Parameters :
mp-wp_genesis 2111 // Return Values :
mp-wp_genesis 2112 // --------------------------------------------------------------------------------
mp-wp_genesis 2113 function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
mp-wp_genesis 2114 {
mp-wp_genesis 2115 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list");
mp-wp_genesis 2116 $v_result=1;
mp-wp_genesis 2117 $v_list_detail = array();
mp-wp_genesis 2118
mp-wp_genesis 2119 // ----- Look if the archive exists or is empty
mp-wp_genesis 2120 if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
mp-wp_genesis 2121 {
mp-wp_genesis 2122 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it.");
mp-wp_genesis 2123
mp-wp_genesis 2124 // ----- Do a create
mp-wp_genesis 2125 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
mp-wp_genesis 2126
mp-wp_genesis 2127 // ----- Return
mp-wp_genesis 2128 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2129 return $v_result;
mp-wp_genesis 2130 }
mp-wp_genesis 2131 // ----- Magic quotes trick
mp-wp_genesis 2132 $this->privDisableMagicQuotes();
mp-wp_genesis 2133
mp-wp_genesis 2134 // ----- Open the zip file
mp-wp_genesis 2135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 2136 if (($v_result=$this->privOpenFd('rb')) != 1)
mp-wp_genesis 2137 {
mp-wp_genesis 2138 // ----- Magic quotes trick
mp-wp_genesis 2139 $this->privSwapBackMagicQuotes();
mp-wp_genesis 2140
mp-wp_genesis 2141 // ----- Return
mp-wp_genesis 2142 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2143 return $v_result;
mp-wp_genesis 2144 }
mp-wp_genesis 2145
mp-wp_genesis 2146 // ----- Read the central directory informations
mp-wp_genesis 2147 $v_central_dir = array();
mp-wp_genesis 2148 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
mp-wp_genesis 2149 {
mp-wp_genesis 2150 $this->privCloseFd();
mp-wp_genesis 2151 $this->privSwapBackMagicQuotes();
mp-wp_genesis 2152 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2153 return $v_result;
mp-wp_genesis 2154 }
mp-wp_genesis 2155
mp-wp_genesis 2156 // ----- Go to beginning of File
mp-wp_genesis 2157 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
mp-wp_genesis 2158 @rewind($this->zip_fd);
mp-wp_genesis 2159 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
mp-wp_genesis 2160
mp-wp_genesis 2161 // ----- Creates a temporay file
mp-wp_genesis 2162 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
mp-wp_genesis 2163
mp-wp_genesis 2164 // ----- Open the temporary file in write mode
mp-wp_genesis 2165 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 2166 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
mp-wp_genesis 2167 {
mp-wp_genesis 2168 $this->privCloseFd();
mp-wp_genesis 2169 $this->privSwapBackMagicQuotes();
mp-wp_genesis 2170
mp-wp_genesis 2171 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
mp-wp_genesis 2172
mp-wp_genesis 2173 // ----- Return
mp-wp_genesis 2174 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 2175 return PclZip::errorCode();
mp-wp_genesis 2176 }
mp-wp_genesis 2177
mp-wp_genesis 2178 // ----- Copy the files from the archive to the temporary file
mp-wp_genesis 2179 // TBC : Here I should better append the file and go back to erase the central dir
mp-wp_genesis 2180 $v_size = $v_central_dir['offset'];
mp-wp_genesis 2181 while ($v_size != 0)
mp-wp_genesis 2182 {
mp-wp_genesis 2183 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 2184 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 2185 $v_buffer = fread($this->zip_fd, $v_read_size);
mp-wp_genesis 2186 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
mp-wp_genesis 2187 $v_size -= $v_read_size;
mp-wp_genesis 2188 }
mp-wp_genesis 2189
mp-wp_genesis 2190 // ----- Swap the file descriptor
mp-wp_genesis 2191 // Here is a trick : I swap the temporary fd with the zip fd, in order to use
mp-wp_genesis 2192 // the following methods on the temporary fil and not the real archive
mp-wp_genesis 2193 $v_swap = $this->zip_fd;
mp-wp_genesis 2194 $this->zip_fd = $v_zip_temp_fd;
mp-wp_genesis 2195 $v_zip_temp_fd = $v_swap;
mp-wp_genesis 2196
mp-wp_genesis 2197 // ----- Add the files
mp-wp_genesis 2198 $v_header_list = array();
mp-wp_genesis 2199 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
mp-wp_genesis 2200 {
mp-wp_genesis 2201 fclose($v_zip_temp_fd);
mp-wp_genesis 2202 $this->privCloseFd();
mp-wp_genesis 2203 @unlink($v_zip_temp_name);
mp-wp_genesis 2204 $this->privSwapBackMagicQuotes();
mp-wp_genesis 2205
mp-wp_genesis 2206 // ----- Return
mp-wp_genesis 2207 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2208 return $v_result;
mp-wp_genesis 2209 }
mp-wp_genesis 2210
mp-wp_genesis 2211 // ----- Store the offset of the central dir
mp-wp_genesis 2212 $v_offset = @ftell($this->zip_fd);
mp-wp_genesis 2213 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");
mp-wp_genesis 2214
mp-wp_genesis 2215 // ----- Copy the block of file headers from the old archive
mp-wp_genesis 2216 $v_size = $v_central_dir['size'];
mp-wp_genesis 2217 while ($v_size != 0)
mp-wp_genesis 2218 {
mp-wp_genesis 2219 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 2220 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 2221 $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
mp-wp_genesis 2222 @fwrite($this->zip_fd, $v_buffer, $v_read_size);
mp-wp_genesis 2223 $v_size -= $v_read_size;
mp-wp_genesis 2224 }
mp-wp_genesis 2225
mp-wp_genesis 2226 // ----- Create the Central Dir files header
mp-wp_genesis 2227 for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
mp-wp_genesis 2228 {
mp-wp_genesis 2229 // ----- Create the file header
mp-wp_genesis 2230 if ($v_header_list[$i]['status'] == 'ok') {
mp-wp_genesis 2231 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
mp-wp_genesis 2232 fclose($v_zip_temp_fd);
mp-wp_genesis 2233 $this->privCloseFd();
mp-wp_genesis 2234 @unlink($v_zip_temp_name);
mp-wp_genesis 2235 $this->privSwapBackMagicQuotes();
mp-wp_genesis 2236
mp-wp_genesis 2237 // ----- Return
mp-wp_genesis 2238 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2239 return $v_result;
mp-wp_genesis 2240 }
mp-wp_genesis 2241 $v_count++;
mp-wp_genesis 2242 }
mp-wp_genesis 2243
mp-wp_genesis 2244 // ----- Transform the header to a 'usable' info
mp-wp_genesis 2245 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
mp-wp_genesis 2246 }
mp-wp_genesis 2247
mp-wp_genesis 2248 // ----- Zip file comment
mp-wp_genesis 2249 $v_comment = $v_central_dir['comment'];
mp-wp_genesis 2250 if (isset($p_options[PCLZIP_OPT_COMMENT])) {
mp-wp_genesis 2251 $v_comment = $p_options[PCLZIP_OPT_COMMENT];
mp-wp_genesis 2252 }
mp-wp_genesis 2253 if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
mp-wp_genesis 2254 $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
mp-wp_genesis 2255 }
mp-wp_genesis 2256 if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
mp-wp_genesis 2257 $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
mp-wp_genesis 2258 }
mp-wp_genesis 2259
mp-wp_genesis 2260 // ----- Calculate the size of the central header
mp-wp_genesis 2261 $v_size = @ftell($this->zip_fd)-$v_offset;
mp-wp_genesis 2262
mp-wp_genesis 2263 // ----- Create the central dir footer
mp-wp_genesis 2264 if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
mp-wp_genesis 2265 {
mp-wp_genesis 2266 // ----- Reset the file list
mp-wp_genesis 2267 unset($v_header_list);
mp-wp_genesis 2268 $this->privSwapBackMagicQuotes();
mp-wp_genesis 2269
mp-wp_genesis 2270 // ----- Return
mp-wp_genesis 2271 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2272 return $v_result;
mp-wp_genesis 2273 }
mp-wp_genesis 2274
mp-wp_genesis 2275 // ----- Swap back the file descriptor
mp-wp_genesis 2276 $v_swap = $this->zip_fd;
mp-wp_genesis 2277 $this->zip_fd = $v_zip_temp_fd;
mp-wp_genesis 2278 $v_zip_temp_fd = $v_swap;
mp-wp_genesis 2279
mp-wp_genesis 2280 // ----- Close
mp-wp_genesis 2281 $this->privCloseFd();
mp-wp_genesis 2282
mp-wp_genesis 2283 // ----- Close the temporary file
mp-wp_genesis 2284 @fclose($v_zip_temp_fd);
mp-wp_genesis 2285
mp-wp_genesis 2286 // ----- Magic quotes trick
mp-wp_genesis 2287 $this->privSwapBackMagicQuotes();
mp-wp_genesis 2288
mp-wp_genesis 2289 // ----- Delete the zip file
mp-wp_genesis 2290 // TBC : I should test the result ...
mp-wp_genesis 2291 @unlink($this->zipname);
mp-wp_genesis 2292
mp-wp_genesis 2293 // ----- Rename the temporary file
mp-wp_genesis 2294 // TBC : I should test the result ...
mp-wp_genesis 2295 //@rename($v_zip_temp_name, $this->zipname);
mp-wp_genesis 2296 PclZipUtilRename($v_zip_temp_name, $this->zipname);
mp-wp_genesis 2297
mp-wp_genesis 2298 // ----- Return
mp-wp_genesis 2299 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2300 return $v_result;
mp-wp_genesis 2301 }
mp-wp_genesis 2302 // --------------------------------------------------------------------------------
mp-wp_genesis 2303
mp-wp_genesis 2304 // --------------------------------------------------------------------------------
mp-wp_genesis 2305 // Function : privOpenFd()
mp-wp_genesis 2306 // Description :
mp-wp_genesis 2307 // Parameters :
mp-wp_genesis 2308 // --------------------------------------------------------------------------------
mp-wp_genesis 2309 function privOpenFd($p_mode)
mp-wp_genesis 2310 {
mp-wp_genesis 2311 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode);
mp-wp_genesis 2312 $v_result=1;
mp-wp_genesis 2313
mp-wp_genesis 2314 // ----- Look if already open
mp-wp_genesis 2315 if ($this->zip_fd != 0)
mp-wp_genesis 2316 {
mp-wp_genesis 2317 // ----- Error log
mp-wp_genesis 2318 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
mp-wp_genesis 2319
mp-wp_genesis 2320 // ----- Return
mp-wp_genesis 2321 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 2322 return PclZip::errorCode();
mp-wp_genesis 2323 }
mp-wp_genesis 2324
mp-wp_genesis 2325 // ----- Open the zip file
mp-wp_genesis 2326 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode');
mp-wp_genesis 2327 if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
mp-wp_genesis 2328 {
mp-wp_genesis 2329 // ----- Error log
mp-wp_genesis 2330 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
mp-wp_genesis 2331
mp-wp_genesis 2332 // ----- Return
mp-wp_genesis 2333 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 2334 return PclZip::errorCode();
mp-wp_genesis 2335 }
mp-wp_genesis 2336
mp-wp_genesis 2337 // ----- Return
mp-wp_genesis 2338 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2339 return $v_result;
mp-wp_genesis 2340 }
mp-wp_genesis 2341 // --------------------------------------------------------------------------------
mp-wp_genesis 2342
mp-wp_genesis 2343 // --------------------------------------------------------------------------------
mp-wp_genesis 2344 // Function : privCloseFd()
mp-wp_genesis 2345 // Description :
mp-wp_genesis 2346 // Parameters :
mp-wp_genesis 2347 // --------------------------------------------------------------------------------
mp-wp_genesis 2348 function privCloseFd()
mp-wp_genesis 2349 {
mp-wp_genesis 2350 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", "");
mp-wp_genesis 2351 $v_result=1;
mp-wp_genesis 2352
mp-wp_genesis 2353 if ($this->zip_fd != 0)
mp-wp_genesis 2354 @fclose($this->zip_fd);
mp-wp_genesis 2355 $this->zip_fd = 0;
mp-wp_genesis 2356
mp-wp_genesis 2357 // ----- Return
mp-wp_genesis 2358 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2359 return $v_result;
mp-wp_genesis 2360 }
mp-wp_genesis 2361 // --------------------------------------------------------------------------------
mp-wp_genesis 2362
mp-wp_genesis 2363 // --------------------------------------------------------------------------------
mp-wp_genesis 2364 // Function : privAddList()
mp-wp_genesis 2365 // Description :
mp-wp_genesis 2366 // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
mp-wp_genesis 2367 // different from the real path of the file. This is usefull if you want to have PclTar
mp-wp_genesis 2368 // running in any directory, and memorize relative path from an other directory.
mp-wp_genesis 2369 // Parameters :
mp-wp_genesis 2370 // $p_list : An array containing the file or directory names to add in the tar
mp-wp_genesis 2371 // $p_result_list : list of added files with their properties (specially the status field)
mp-wp_genesis 2372 // $p_add_dir : Path to add in the filename path archived
mp-wp_genesis 2373 // $p_remove_dir : Path to remove in the filename path archived
mp-wp_genesis 2374 // Return Values :
mp-wp_genesis 2375 // --------------------------------------------------------------------------------
mp-wp_genesis 2376 // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
mp-wp_genesis 2377 function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
mp-wp_genesis 2378 {
mp-wp_genesis 2379 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list");
mp-wp_genesis 2380 $v_result=1;
mp-wp_genesis 2381
mp-wp_genesis 2382 // ----- Add the files
mp-wp_genesis 2383 $v_header_list = array();
mp-wp_genesis 2384 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
mp-wp_genesis 2385 {
mp-wp_genesis 2386 // ----- Return
mp-wp_genesis 2387 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2388 return $v_result;
mp-wp_genesis 2389 }
mp-wp_genesis 2390
mp-wp_genesis 2391 // ----- Store the offset of the central dir
mp-wp_genesis 2392 $v_offset = @ftell($this->zip_fd);
mp-wp_genesis 2393
mp-wp_genesis 2394 // ----- Create the Central Dir files header
mp-wp_genesis 2395 for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
mp-wp_genesis 2396 {
mp-wp_genesis 2397 // ----- Create the file header
mp-wp_genesis 2398 if ($v_header_list[$i]['status'] == 'ok') {
mp-wp_genesis 2399 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
mp-wp_genesis 2400 // ----- Return
mp-wp_genesis 2401 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2402 return $v_result;
mp-wp_genesis 2403 }
mp-wp_genesis 2404 $v_count++;
mp-wp_genesis 2405 }
mp-wp_genesis 2406
mp-wp_genesis 2407 // ----- Transform the header to a 'usable' info
mp-wp_genesis 2408 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
mp-wp_genesis 2409 }
mp-wp_genesis 2410
mp-wp_genesis 2411 // ----- Zip file comment
mp-wp_genesis 2412 $v_comment = '';
mp-wp_genesis 2413 if (isset($p_options[PCLZIP_OPT_COMMENT])) {
mp-wp_genesis 2414 $v_comment = $p_options[PCLZIP_OPT_COMMENT];
mp-wp_genesis 2415 }
mp-wp_genesis 2416
mp-wp_genesis 2417 // ----- Calculate the size of the central header
mp-wp_genesis 2418 $v_size = @ftell($this->zip_fd)-$v_offset;
mp-wp_genesis 2419
mp-wp_genesis 2420 // ----- Create the central dir footer
mp-wp_genesis 2421 if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
mp-wp_genesis 2422 {
mp-wp_genesis 2423 // ----- Reset the file list
mp-wp_genesis 2424 unset($v_header_list);
mp-wp_genesis 2425
mp-wp_genesis 2426 // ----- Return
mp-wp_genesis 2427 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2428 return $v_result;
mp-wp_genesis 2429 }
mp-wp_genesis 2430
mp-wp_genesis 2431 // ----- Return
mp-wp_genesis 2432 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2433 return $v_result;
mp-wp_genesis 2434 }
mp-wp_genesis 2435 // --------------------------------------------------------------------------------
mp-wp_genesis 2436
mp-wp_genesis 2437 // --------------------------------------------------------------------------------
mp-wp_genesis 2438 // Function : privAddFileList()
mp-wp_genesis 2439 // Description :
mp-wp_genesis 2440 // Parameters :
mp-wp_genesis 2441 // $p_filedescr_list : An array containing the file description
mp-wp_genesis 2442 // or directory names to add in the zip
mp-wp_genesis 2443 // $p_result_list : list of added files with their properties (specially the status field)
mp-wp_genesis 2444 // Return Values :
mp-wp_genesis 2445 // --------------------------------------------------------------------------------
mp-wp_genesis 2446 function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
mp-wp_genesis 2447 {
mp-wp_genesis 2448 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list");
mp-wp_genesis 2449 $v_result=1;
mp-wp_genesis 2450 $v_header = array();
mp-wp_genesis 2451
mp-wp_genesis 2452 // ----- Recuperate the current number of elt in list
mp-wp_genesis 2453 $v_nb = sizeof($p_result_list);
mp-wp_genesis 2454 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements");
mp-wp_genesis 2455
mp-wp_genesis 2456 // ----- Loop on the files
mp-wp_genesis 2457 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
mp-wp_genesis 2458 // ----- Format the filename
mp-wp_genesis 2459 $p_filedescr_list[$j]['filename']
mp-wp_genesis 2460 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
mp-wp_genesis 2461
mp-wp_genesis 2462 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'");
mp-wp_genesis 2463
mp-wp_genesis 2464 // ----- Skip empty file names
mp-wp_genesis 2465 // TBC : Can this be possible ? not checked in DescrParseAtt ?
mp-wp_genesis 2466 if ($p_filedescr_list[$j]['filename'] == "") {
mp-wp_genesis 2467 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");
mp-wp_genesis 2468 continue;
mp-wp_genesis 2469 }
mp-wp_genesis 2470
mp-wp_genesis 2471 // ----- Check the filename
mp-wp_genesis 2472 if (!file_exists($p_filedescr_list[$j]['filename'])) {
mp-wp_genesis 2473 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exists");
mp-wp_genesis 2474 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists");
mp-wp_genesis 2475 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 2476 return PclZip::errorCode();
mp-wp_genesis 2477 }
mp-wp_genesis 2478
mp-wp_genesis 2479 // ----- Look if it is a file or a dir with no all path remove option
mp-wp_genesis 2480 if ( (is_file($p_filedescr_list[$j]['filename']))
mp-wp_genesis 2481 || ( is_dir($p_filedescr_list[$j]['filename'])
mp-wp_genesis 2482 && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
mp-wp_genesis 2483 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
mp-wp_genesis 2484
mp-wp_genesis 2485 // ----- Add the file
mp-wp_genesis 2486 $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
mp-wp_genesis 2487 $p_options);
mp-wp_genesis 2488 if ($v_result != 1) {
mp-wp_genesis 2489 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2490 return $v_result;
mp-wp_genesis 2491 }
mp-wp_genesis 2492
mp-wp_genesis 2493 // ----- Store the file infos
mp-wp_genesis 2494 $p_result_list[$v_nb++] = $v_header;
mp-wp_genesis 2495 }
mp-wp_genesis 2496 }
mp-wp_genesis 2497 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements");
mp-wp_genesis 2498
mp-wp_genesis 2499 // ----- Return
mp-wp_genesis 2500 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2501 return $v_result;
mp-wp_genesis 2502 }
mp-wp_genesis 2503 // --------------------------------------------------------------------------------
mp-wp_genesis 2504
mp-wp_genesis 2505 // --------------------------------------------------------------------------------
mp-wp_genesis 2506 // Function : privAddFile()
mp-wp_genesis 2507 // Description :
mp-wp_genesis 2508 // Parameters :
mp-wp_genesis 2509 // Return Values :
mp-wp_genesis 2510 // --------------------------------------------------------------------------------
mp-wp_genesis 2511 function privAddFile($p_filedescr, &$p_header, &$p_options)
mp-wp_genesis 2512 {
mp-wp_genesis 2513 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'");
mp-wp_genesis 2514 $v_result=1;
mp-wp_genesis 2515
mp-wp_genesis 2516 // ----- Working variable
mp-wp_genesis 2517 $p_filename = $p_filedescr['filename'];
mp-wp_genesis 2518
mp-wp_genesis 2519 // TBC : Already done in the fileAtt check ... ?
mp-wp_genesis 2520 if ($p_filename == "") {
mp-wp_genesis 2521 // ----- Error log
mp-wp_genesis 2522 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
mp-wp_genesis 2523
mp-wp_genesis 2524 // ----- Return
mp-wp_genesis 2525 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 2526 return PclZip::errorCode();
mp-wp_genesis 2527 }
mp-wp_genesis 2528
mp-wp_genesis 2529 // ----- Look for a stored different filename
mp-wp_genesis 2530 if (isset($p_filedescr['stored_filename'])) {
mp-wp_genesis 2531 $v_stored_filename = $p_filedescr['stored_filename'];
mp-wp_genesis 2532 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"');
mp-wp_genesis 2533 }
mp-wp_genesis 2534 else {
mp-wp_genesis 2535 $v_stored_filename = $p_filedescr['stored_filename'];
mp-wp_genesis 2536 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same');
mp-wp_genesis 2537 }
mp-wp_genesis 2538
mp-wp_genesis 2539 // ----- Set the file properties
mp-wp_genesis 2540 clearstatcache();
mp-wp_genesis 2541 $p_header['version'] = 20;
mp-wp_genesis 2542 $p_header['version_extracted'] = 10;
mp-wp_genesis 2543 $p_header['flag'] = 0;
mp-wp_genesis 2544 $p_header['compression'] = 0;
mp-wp_genesis 2545 $p_header['mtime'] = filemtime($p_filename);
mp-wp_genesis 2546 $p_header['crc'] = 0;
mp-wp_genesis 2547 $p_header['compressed_size'] = 0;
mp-wp_genesis 2548 $p_header['size'] = filesize($p_filename);
mp-wp_genesis 2549 $p_header['filename_len'] = strlen($p_filename);
mp-wp_genesis 2550 $p_header['extra_len'] = 0;
mp-wp_genesis 2551 $p_header['comment_len'] = 0;
mp-wp_genesis 2552 $p_header['disk'] = 0;
mp-wp_genesis 2553 $p_header['internal'] = 0;
mp-wp_genesis 2554 // $p_header['external'] = (is_file($p_filename)?0xFE49FFE0:0x41FF0010);
mp-wp_genesis 2555 $p_header['external'] = (is_file($p_filename)?0x00000000:0x00000010);
mp-wp_genesis 2556 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'");
mp-wp_genesis 2557 $p_header['offset'] = 0;
mp-wp_genesis 2558 $p_header['filename'] = $p_filename;
mp-wp_genesis 2559 $p_header['stored_filename'] = $v_stored_filename;
mp-wp_genesis 2560 $p_header['extra'] = '';
mp-wp_genesis 2561 $p_header['comment'] = '';
mp-wp_genesis 2562 $p_header['status'] = 'ok';
mp-wp_genesis 2563 $p_header['index'] = -1;
mp-wp_genesis 2564
mp-wp_genesis 2565 // ----- Look for pre-add callback
mp-wp_genesis 2566 if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
mp-wp_genesis 2567 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction");
mp-wp_genesis 2568
mp-wp_genesis 2569 // ----- Generate a local information
mp-wp_genesis 2570 $v_local_header = array();
mp-wp_genesis 2571 $this->privConvertHeader2FileInfo($p_header, $v_local_header);
mp-wp_genesis 2572
mp-wp_genesis 2573 // ----- Call the callback
mp-wp_genesis 2574 // Here I do not use call_user_func() because I need to send a reference to the
mp-wp_genesis 2575 // header.
mp-wp_genesis 2576 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
mp-wp_genesis 2577 if ($v_result == 0) {
mp-wp_genesis 2578 // ----- Change the file status
mp-wp_genesis 2579 $p_header['status'] = "skipped";
mp-wp_genesis 2580 $v_result = 1;
mp-wp_genesis 2581 }
mp-wp_genesis 2582
mp-wp_genesis 2583 // ----- Update the informations
mp-wp_genesis 2584 // Only some fields can be modified
mp-wp_genesis 2585 if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
mp-wp_genesis 2586 $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
mp-wp_genesis 2587 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'");
mp-wp_genesis 2588 }
mp-wp_genesis 2589 }
mp-wp_genesis 2590
mp-wp_genesis 2591 // ----- Look for empty stored filename
mp-wp_genesis 2592 if ($p_header['stored_filename'] == "") {
mp-wp_genesis 2593 $p_header['status'] = "filtered";
mp-wp_genesis 2594 }
mp-wp_genesis 2595
mp-wp_genesis 2596 // ----- Check the path length
mp-wp_genesis 2597 if (strlen($p_header['stored_filename']) > 0xFF) {
mp-wp_genesis 2598 $p_header['status'] = 'filename_too_long';
mp-wp_genesis 2599 }
mp-wp_genesis 2600
mp-wp_genesis 2601 // ----- Look if no error, or file not skipped
mp-wp_genesis 2602 if ($p_header['status'] == 'ok') {
mp-wp_genesis 2603
mp-wp_genesis 2604 // ----- Look for a file
mp-wp_genesis 2605 if (is_file($p_filename))
mp-wp_genesis 2606 {
mp-wp_genesis 2607 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");
mp-wp_genesis 2608 // ----- Open the source file
mp-wp_genesis 2609 if (($v_file = @fopen($p_filename, "rb")) == 0) {
mp-wp_genesis 2610 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
mp-wp_genesis 2611 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 2612 return PclZip::errorCode();
mp-wp_genesis 2613 }
mp-wp_genesis 2614
mp-wp_genesis 2615 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
mp-wp_genesis 2616 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");
mp-wp_genesis 2617 // ----- Read the file content
mp-wp_genesis 2618 $v_content_compressed = @fread($v_file, $p_header['size']);
mp-wp_genesis 2619
mp-wp_genesis 2620 // ----- Calculate the CRC
mp-wp_genesis 2621 $p_header['crc'] = @crc32($v_content_compressed);
mp-wp_genesis 2622
mp-wp_genesis 2623 // ----- Set header parameters
mp-wp_genesis 2624 $p_header['compressed_size'] = $p_header['size'];
mp-wp_genesis 2625 $p_header['compression'] = 0;
mp-wp_genesis 2626 }
mp-wp_genesis 2627 else {
mp-wp_genesis 2628 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");
mp-wp_genesis 2629 // ----- Read the file content
mp-wp_genesis 2630 $v_content = @fread($v_file, $p_header['size']);
mp-wp_genesis 2631
mp-wp_genesis 2632 // ----- Calculate the CRC
mp-wp_genesis 2633 $p_header['crc'] = @crc32($v_content);
mp-wp_genesis 2634
mp-wp_genesis 2635 // ----- Compress the file
mp-wp_genesis 2636 $v_content_compressed = @gzdeflate($v_content);
mp-wp_genesis 2637
mp-wp_genesis 2638 // ----- Set header parameters
mp-wp_genesis 2639 $p_header['compressed_size'] = strlen($v_content_compressed);
mp-wp_genesis 2640 $p_header['compression'] = 8;
mp-wp_genesis 2641 }
mp-wp_genesis 2642
mp-wp_genesis 2643 // ----- Look for encryption
mp-wp_genesis 2644 /*
mp-wp_genesis 2645 if ((isset($p_options[PCLZIP_OPT_CRYPT]))
mp-wp_genesis 2646 && ($p_options[PCLZIP_OPT_CRYPT] != "")) {
mp-wp_genesis 2647 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ....");
mp-wp_genesis 2648
mp-wp_genesis 2649 // Should be a random header
mp-wp_genesis 2650 $v_header = 'xxxxxxxxxxxx';
mp-wp_genesis 2651 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,
mp-wp_genesis 2652 $p_header['compressed_size'],
mp-wp_genesis 2653 $v_header,
mp-wp_genesis 2654 $p_header['crc'],
mp-wp_genesis 2655 "test");
mp-wp_genesis 2656
mp-wp_genesis 2657 $p_header['compressed_size'] += 12;
mp-wp_genesis 2658 $p_header['flag'] = 1;
mp-wp_genesis 2659
mp-wp_genesis 2660 // ----- Add the header to the data
mp-wp_genesis 2661 $v_content_compressed = $v_header.$v_content_compressed;
mp-wp_genesis 2662 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed)."");
mp-wp_genesis 2663 }
mp-wp_genesis 2664 */
mp-wp_genesis 2665
mp-wp_genesis 2666 // ----- Call the header generation
mp-wp_genesis 2667 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
mp-wp_genesis 2668 @fclose($v_file);
mp-wp_genesis 2669 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2670 return $v_result;
mp-wp_genesis 2671 }
mp-wp_genesis 2672
mp-wp_genesis 2673 // ----- Write the compressed (or not) content
mp-wp_genesis 2674 @fwrite($this->zip_fd,
mp-wp_genesis 2675 $v_content_compressed, $p_header['compressed_size']);
mp-wp_genesis 2676
mp-wp_genesis 2677 // ----- Close the file
mp-wp_genesis 2678 @fclose($v_file);
mp-wp_genesis 2679 }
mp-wp_genesis 2680
mp-wp_genesis 2681 // ----- Look for a directory
mp-wp_genesis 2682 else {
mp-wp_genesis 2683 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder");
mp-wp_genesis 2684 // ----- Look for directory last '/'
mp-wp_genesis 2685 if (@substr($p_header['stored_filename'], -1) != '/') {
mp-wp_genesis 2686 $p_header['stored_filename'] .= '/';
mp-wp_genesis 2687 }
mp-wp_genesis 2688
mp-wp_genesis 2689 // ----- Set the file properties
mp-wp_genesis 2690 $p_header['size'] = 0;
mp-wp_genesis 2691 //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked
mp-wp_genesis 2692 $p_header['external'] = 0x00000010; // Value for a folder : to be checked
mp-wp_genesis 2693
mp-wp_genesis 2694 // ----- Call the header generation
mp-wp_genesis 2695 if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
mp-wp_genesis 2696 {
mp-wp_genesis 2697 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2698 return $v_result;
mp-wp_genesis 2699 }
mp-wp_genesis 2700 }
mp-wp_genesis 2701 }
mp-wp_genesis 2702
mp-wp_genesis 2703 // ----- Look for post-add callback
mp-wp_genesis 2704 if (isset($p_options[PCLZIP_CB_POST_ADD])) {
mp-wp_genesis 2705 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction");
mp-wp_genesis 2706
mp-wp_genesis 2707 // ----- Generate a local information
mp-wp_genesis 2708 $v_local_header = array();
mp-wp_genesis 2709 $this->privConvertHeader2FileInfo($p_header, $v_local_header);
mp-wp_genesis 2710
mp-wp_genesis 2711 // ----- Call the callback
mp-wp_genesis 2712 // Here I do not use call_user_func() because I need to send a reference to the
mp-wp_genesis 2713 // header.
mp-wp_genesis 2714 eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
mp-wp_genesis 2715 if ($v_result == 0) {
mp-wp_genesis 2716 // ----- Ignored
mp-wp_genesis 2717 $v_result = 1;
mp-wp_genesis 2718 }
mp-wp_genesis 2719
mp-wp_genesis 2720 // ----- Update the informations
mp-wp_genesis 2721 // Nothing can be modified
mp-wp_genesis 2722 }
mp-wp_genesis 2723
mp-wp_genesis 2724 // ----- Return
mp-wp_genesis 2725 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2726 return $v_result;
mp-wp_genesis 2727 }
mp-wp_genesis 2728 // --------------------------------------------------------------------------------
mp-wp_genesis 2729
mp-wp_genesis 2730 // --------------------------------------------------------------------------------
mp-wp_genesis 2731 // Function : privCalculateStoredFilename()
mp-wp_genesis 2732 // Description :
mp-wp_genesis 2733 // Based on file descriptor properties and global options, this method
mp-wp_genesis 2734 // calculate the filename that will be stored in the archive.
mp-wp_genesis 2735 // Parameters :
mp-wp_genesis 2736 // Return Values :
mp-wp_genesis 2737 // --------------------------------------------------------------------------------
mp-wp_genesis 2738 function privCalculateStoredFilename(&$p_filedescr, &$p_options)
mp-wp_genesis 2739 {
mp-wp_genesis 2740 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'");
mp-wp_genesis 2741 $v_result=1;
mp-wp_genesis 2742
mp-wp_genesis 2743 // ----- Working variables
mp-wp_genesis 2744 $p_filename = $p_filedescr['filename'];
mp-wp_genesis 2745 if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
mp-wp_genesis 2746 $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
mp-wp_genesis 2747 }
mp-wp_genesis 2748 else {
mp-wp_genesis 2749 $p_add_dir = '';
mp-wp_genesis 2750 }
mp-wp_genesis 2751 if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
mp-wp_genesis 2752 $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
mp-wp_genesis 2753 }
mp-wp_genesis 2754 else {
mp-wp_genesis 2755 $p_remove_dir = '';
mp-wp_genesis 2756 }
mp-wp_genesis 2757 if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
mp-wp_genesis 2758 $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
mp-wp_genesis 2759 }
mp-wp_genesis 2760 else {
mp-wp_genesis 2761 $p_remove_all_dir = 0;
mp-wp_genesis 2762 }
mp-wp_genesis 2763
mp-wp_genesis 2764 // ----- Look for full name change
mp-wp_genesis 2765 if (isset($p_filedescr['new_full_name'])) {
mp-wp_genesis 2766 $v_stored_filename = $p_filedescr['new_full_name'];
mp-wp_genesis 2767 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'");
mp-wp_genesis 2768 }
mp-wp_genesis 2769
mp-wp_genesis 2770 // ----- Look for path and/or short name change
mp-wp_genesis 2771 else {
mp-wp_genesis 2772
mp-wp_genesis 2773 // ----- Look for short name change
mp-wp_genesis 2774 if (isset($p_filedescr['new_short_name'])) {
mp-wp_genesis 2775 $v_path_info = pathinfo($p_filename);
mp-wp_genesis 2776 $v_dir = '';
mp-wp_genesis 2777 if ($v_path_info['dirname'] != '') {
mp-wp_genesis 2778 $v_dir = $v_path_info['dirname'].'/';
mp-wp_genesis 2779 }
mp-wp_genesis 2780 $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
mp-wp_genesis 2781 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'");
mp-wp_genesis 2782 }
mp-wp_genesis 2783 else {
mp-wp_genesis 2784 // ----- Calculate the stored filename
mp-wp_genesis 2785 $v_stored_filename = $p_filename;
mp-wp_genesis 2786 }
mp-wp_genesis 2787
mp-wp_genesis 2788 // ----- Look for all path to remove
mp-wp_genesis 2789 if ($p_remove_all_dir) {
mp-wp_genesis 2790 $v_stored_filename = basename($p_filename);
mp-wp_genesis 2791 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'");
mp-wp_genesis 2792 }
mp-wp_genesis 2793 // ----- Look for partial path remove
mp-wp_genesis 2794 else if ($p_remove_dir != "") {
mp-wp_genesis 2795 if (substr($p_remove_dir, -1) != '/')
mp-wp_genesis 2796 $p_remove_dir .= "/";
mp-wp_genesis 2797
mp-wp_genesis 2798 if ( (substr($p_filename, 0, 2) == "./")
mp-wp_genesis 2799 || (substr($p_remove_dir, 0, 2) == "./")) {
mp-wp_genesis 2800
mp-wp_genesis 2801 if ( (substr($p_filename, 0, 2) == "./")
mp-wp_genesis 2802 && (substr($p_remove_dir, 0, 2) != "./")) {
mp-wp_genesis 2803 $p_remove_dir = "./".$p_remove_dir;
mp-wp_genesis 2804 }
mp-wp_genesis 2805 if ( (substr($p_filename, 0, 2) != "./")
mp-wp_genesis 2806 && (substr($p_remove_dir, 0, 2) == "./")) {
mp-wp_genesis 2807 $p_remove_dir = substr($p_remove_dir, 2);
mp-wp_genesis 2808 }
mp-wp_genesis 2809 }
mp-wp_genesis 2810
mp-wp_genesis 2811 $v_compare = PclZipUtilPathInclusion($p_remove_dir,
mp-wp_genesis 2812 $v_stored_filename);
mp-wp_genesis 2813 if ($v_compare > 0) {
mp-wp_genesis 2814 if ($v_compare == 2) {
mp-wp_genesis 2815 $v_stored_filename = "";
mp-wp_genesis 2816 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder");
mp-wp_genesis 2817 }
mp-wp_genesis 2818 else {
mp-wp_genesis 2819 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'");
mp-wp_genesis 2820 $v_stored_filename = substr($v_stored_filename,
mp-wp_genesis 2821 strlen($p_remove_dir));
mp-wp_genesis 2822 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'");
mp-wp_genesis 2823 }
mp-wp_genesis 2824 }
mp-wp_genesis 2825 }
mp-wp_genesis 2826 // ----- Look for path to add
mp-wp_genesis 2827 if ($p_add_dir != "") {
mp-wp_genesis 2828 if (substr($p_add_dir, -1) == "/")
mp-wp_genesis 2829 $v_stored_filename = $p_add_dir.$v_stored_filename;
mp-wp_genesis 2830 else
mp-wp_genesis 2831 $v_stored_filename = $p_add_dir."/".$v_stored_filename;
mp-wp_genesis 2832 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'");
mp-wp_genesis 2833 }
mp-wp_genesis 2834 }
mp-wp_genesis 2835
mp-wp_genesis 2836 // ----- Filename (reduce the path of stored name)
mp-wp_genesis 2837 $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
mp-wp_genesis 2838 $p_filedescr['stored_filename'] = $v_stored_filename;
mp-wp_genesis 2839 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename']));
mp-wp_genesis 2840
mp-wp_genesis 2841 // ----- Return
mp-wp_genesis 2842 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2843 return $v_result;
mp-wp_genesis 2844 }
mp-wp_genesis 2845 // --------------------------------------------------------------------------------
mp-wp_genesis 2846
mp-wp_genesis 2847 // --------------------------------------------------------------------------------
mp-wp_genesis 2848 // Function : privWriteFileHeader()
mp-wp_genesis 2849 // Description :
mp-wp_genesis 2850 // Parameters :
mp-wp_genesis 2851 // Return Values :
mp-wp_genesis 2852 // --------------------------------------------------------------------------------
mp-wp_genesis 2853 function privWriteFileHeader(&$p_header)
mp-wp_genesis 2854 {
mp-wp_genesis 2855 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');
mp-wp_genesis 2856 $v_result=1;
mp-wp_genesis 2857
mp-wp_genesis 2858 // ----- Store the offset position of the file
mp-wp_genesis 2859 $p_header['offset'] = ftell($this->zip_fd);
mp-wp_genesis 2860 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']);
mp-wp_genesis 2861
mp-wp_genesis 2862 // ----- Transform UNIX mtime to DOS format mdate/mtime
mp-wp_genesis 2863 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
mp-wp_genesis 2864 $v_date = getdate($p_header['mtime']);
mp-wp_genesis 2865 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
mp-wp_genesis 2866 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
mp-wp_genesis 2867
mp-wp_genesis 2868 // ----- Packed data
mp-wp_genesis 2869 $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
mp-wp_genesis 2870 $p_header['version_extracted'], $p_header['flag'],
mp-wp_genesis 2871 $p_header['compression'], $v_mtime, $v_mdate,
mp-wp_genesis 2872 $p_header['crc'], $p_header['compressed_size'],
mp-wp_genesis 2873 $p_header['size'],
mp-wp_genesis 2874 strlen($p_header['stored_filename']),
mp-wp_genesis 2875 $p_header['extra_len']);
mp-wp_genesis 2876
mp-wp_genesis 2877 // ----- Write the first 148 bytes of the header in the archive
mp-wp_genesis 2878 fputs($this->zip_fd, $v_binary_data, 30);
mp-wp_genesis 2879
mp-wp_genesis 2880 // ----- Write the variable fields
mp-wp_genesis 2881 if (strlen($p_header['stored_filename']) != 0)
mp-wp_genesis 2882 {
mp-wp_genesis 2883 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
mp-wp_genesis 2884 }
mp-wp_genesis 2885 if ($p_header['extra_len'] != 0)
mp-wp_genesis 2886 {
mp-wp_genesis 2887 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
mp-wp_genesis 2888 }
mp-wp_genesis 2889
mp-wp_genesis 2890 // ----- Return
mp-wp_genesis 2891 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2892 return $v_result;
mp-wp_genesis 2893 }
mp-wp_genesis 2894 // --------------------------------------------------------------------------------
mp-wp_genesis 2895
mp-wp_genesis 2896 // --------------------------------------------------------------------------------
mp-wp_genesis 2897 // Function : privWriteCentralFileHeader()
mp-wp_genesis 2898 // Description :
mp-wp_genesis 2899 // Parameters :
mp-wp_genesis 2900 // Return Values :
mp-wp_genesis 2901 // --------------------------------------------------------------------------------
mp-wp_genesis 2902 function privWriteCentralFileHeader(&$p_header)
mp-wp_genesis 2903 {
mp-wp_genesis 2904 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');
mp-wp_genesis 2905 $v_result=1;
mp-wp_genesis 2906
mp-wp_genesis 2907 // TBC
mp-wp_genesis 2908 //for(reset($p_header); $key = key($p_header); next($p_header)) {
mp-wp_genesis 2909 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]);
mp-wp_genesis 2910 //}
mp-wp_genesis 2911
mp-wp_genesis 2912 // ----- Transform UNIX mtime to DOS format mdate/mtime
mp-wp_genesis 2913 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
mp-wp_genesis 2914 $v_date = getdate($p_header['mtime']);
mp-wp_genesis 2915 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
mp-wp_genesis 2916 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
mp-wp_genesis 2917
mp-wp_genesis 2918 // ----- Packed data
mp-wp_genesis 2919 $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
mp-wp_genesis 2920 $p_header['version'], $p_header['version_extracted'],
mp-wp_genesis 2921 $p_header['flag'], $p_header['compression'],
mp-wp_genesis 2922 $v_mtime, $v_mdate, $p_header['crc'],
mp-wp_genesis 2923 $p_header['compressed_size'], $p_header['size'],
mp-wp_genesis 2924 strlen($p_header['stored_filename']),
mp-wp_genesis 2925 $p_header['extra_len'], $p_header['comment_len'],
mp-wp_genesis 2926 $p_header['disk'], $p_header['internal'],
mp-wp_genesis 2927 $p_header['external'], $p_header['offset']);
mp-wp_genesis 2928
mp-wp_genesis 2929 // ----- Write the 42 bytes of the header in the zip file
mp-wp_genesis 2930 fputs($this->zip_fd, $v_binary_data, 46);
mp-wp_genesis 2931
mp-wp_genesis 2932 // ----- Write the variable fields
mp-wp_genesis 2933 if (strlen($p_header['stored_filename']) != 0)
mp-wp_genesis 2934 {
mp-wp_genesis 2935 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
mp-wp_genesis 2936 }
mp-wp_genesis 2937 if ($p_header['extra_len'] != 0)
mp-wp_genesis 2938 {
mp-wp_genesis 2939 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
mp-wp_genesis 2940 }
mp-wp_genesis 2941 if ($p_header['comment_len'] != 0)
mp-wp_genesis 2942 {
mp-wp_genesis 2943 fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
mp-wp_genesis 2944 }
mp-wp_genesis 2945
mp-wp_genesis 2946 // ----- Return
mp-wp_genesis 2947 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2948 return $v_result;
mp-wp_genesis 2949 }
mp-wp_genesis 2950 // --------------------------------------------------------------------------------
mp-wp_genesis 2951
mp-wp_genesis 2952 // --------------------------------------------------------------------------------
mp-wp_genesis 2953 // Function : privWriteCentralHeader()
mp-wp_genesis 2954 // Description :
mp-wp_genesis 2955 // Parameters :
mp-wp_genesis 2956 // Return Values :
mp-wp_genesis 2957 // --------------------------------------------------------------------------------
mp-wp_genesis 2958 function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
mp-wp_genesis 2959 {
mp-wp_genesis 2960 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"');
mp-wp_genesis 2961 $v_result=1;
mp-wp_genesis 2962
mp-wp_genesis 2963 // ----- Packed data
mp-wp_genesis 2964 $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
mp-wp_genesis 2965 $p_nb_entries, $p_size,
mp-wp_genesis 2966 $p_offset, strlen($p_comment));
mp-wp_genesis 2967
mp-wp_genesis 2968 // ----- Write the 22 bytes of the header in the zip file
mp-wp_genesis 2969 fputs($this->zip_fd, $v_binary_data, 22);
mp-wp_genesis 2970
mp-wp_genesis 2971 // ----- Write the variable fields
mp-wp_genesis 2972 if (strlen($p_comment) != 0)
mp-wp_genesis 2973 {
mp-wp_genesis 2974 fputs($this->zip_fd, $p_comment, strlen($p_comment));
mp-wp_genesis 2975 }
mp-wp_genesis 2976
mp-wp_genesis 2977 // ----- Return
mp-wp_genesis 2978 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 2979 return $v_result;
mp-wp_genesis 2980 }
mp-wp_genesis 2981 // --------------------------------------------------------------------------------
mp-wp_genesis 2982
mp-wp_genesis 2983 // --------------------------------------------------------------------------------
mp-wp_genesis 2984 // Function : privList()
mp-wp_genesis 2985 // Description :
mp-wp_genesis 2986 // Parameters :
mp-wp_genesis 2987 // Return Values :
mp-wp_genesis 2988 // --------------------------------------------------------------------------------
mp-wp_genesis 2989 function privList(&$p_list)
mp-wp_genesis 2990 {
mp-wp_genesis 2991 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list");
mp-wp_genesis 2992 $v_result=1;
mp-wp_genesis 2993
mp-wp_genesis 2994 // ----- Magic quotes trick
mp-wp_genesis 2995 $this->privDisableMagicQuotes();
mp-wp_genesis 2996
mp-wp_genesis 2997 // ----- Open the zip file
mp-wp_genesis 2998 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 2999 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
mp-wp_genesis 3000 {
mp-wp_genesis 3001 // ----- Magic quotes trick
mp-wp_genesis 3002 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3003
mp-wp_genesis 3004 // ----- Error log
mp-wp_genesis 3005 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
mp-wp_genesis 3006
mp-wp_genesis 3007 // ----- Return
mp-wp_genesis 3008 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3009 return PclZip::errorCode();
mp-wp_genesis 3010 }
mp-wp_genesis 3011
mp-wp_genesis 3012 // ----- Read the central directory informations
mp-wp_genesis 3013 $v_central_dir = array();
mp-wp_genesis 3014 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
mp-wp_genesis 3015 {
mp-wp_genesis 3016 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3017 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3018 return $v_result;
mp-wp_genesis 3019 }
mp-wp_genesis 3020
mp-wp_genesis 3021 // ----- Go to beginning of Central Dir
mp-wp_genesis 3022 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'");
mp-wp_genesis 3023 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3024 @rewind($this->zip_fd);
mp-wp_genesis 3025 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3026 if (@fseek($this->zip_fd, $v_central_dir['offset']))
mp-wp_genesis 3027 {
mp-wp_genesis 3028 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3029
mp-wp_genesis 3030 // ----- Error log
mp-wp_genesis 3031 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
mp-wp_genesis 3032
mp-wp_genesis 3033 // ----- Return
mp-wp_genesis 3034 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3035 return PclZip::errorCode();
mp-wp_genesis 3036 }
mp-wp_genesis 3037 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3038
mp-wp_genesis 3039 // ----- Read each entry
mp-wp_genesis 3040 for ($i=0; $i<$v_central_dir['entries']; $i++)
mp-wp_genesis 3041 {
mp-wp_genesis 3042 // ----- Read the file header
mp-wp_genesis 3043 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
mp-wp_genesis 3044 {
mp-wp_genesis 3045 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3046 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3047 return $v_result;
mp-wp_genesis 3048 }
mp-wp_genesis 3049 $v_header['index'] = $i;
mp-wp_genesis 3050
mp-wp_genesis 3051 // ----- Get the only interesting attributes
mp-wp_genesis 3052 $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
mp-wp_genesis 3053 unset($v_header);
mp-wp_genesis 3054 }
mp-wp_genesis 3055
mp-wp_genesis 3056 // ----- Close the zip file
mp-wp_genesis 3057 $this->privCloseFd();
mp-wp_genesis 3058
mp-wp_genesis 3059 // ----- Magic quotes trick
mp-wp_genesis 3060 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3061
mp-wp_genesis 3062 // ----- Return
mp-wp_genesis 3063 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3064 return $v_result;
mp-wp_genesis 3065 }
mp-wp_genesis 3066 // --------------------------------------------------------------------------------
mp-wp_genesis 3067
mp-wp_genesis 3068 // --------------------------------------------------------------------------------
mp-wp_genesis 3069 // Function : privConvertHeader2FileInfo()
mp-wp_genesis 3070 // Description :
mp-wp_genesis 3071 // This function takes the file informations from the central directory
mp-wp_genesis 3072 // entries and extract the interesting parameters that will be given back.
mp-wp_genesis 3073 // The resulting file infos are set in the array $p_info
mp-wp_genesis 3074 // $p_info['filename'] : Filename with full path. Given by user (add),
mp-wp_genesis 3075 // extracted in the filesystem (extract).
mp-wp_genesis 3076 // $p_info['stored_filename'] : Stored filename in the archive.
mp-wp_genesis 3077 // $p_info['size'] = Size of the file.
mp-wp_genesis 3078 // $p_info['compressed_size'] = Compressed size of the file.
mp-wp_genesis 3079 // $p_info['mtime'] = Last modification date of the file.
mp-wp_genesis 3080 // $p_info['comment'] = Comment associated with the file.
mp-wp_genesis 3081 // $p_info['folder'] = true/false : indicates if the entry is a folder or not.
mp-wp_genesis 3082 // $p_info['status'] = status of the action on the file.
mp-wp_genesis 3083 // Parameters :
mp-wp_genesis 3084 // Return Values :
mp-wp_genesis 3085 // --------------------------------------------------------------------------------
mp-wp_genesis 3086 function privConvertHeader2FileInfo($p_header, &$p_info)
mp-wp_genesis 3087 {
mp-wp_genesis 3088 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'");
mp-wp_genesis 3089 $v_result=1;
mp-wp_genesis 3090
mp-wp_genesis 3091 // ----- Get the interesting attributes
mp-wp_genesis 3092 $p_info['filename'] = $p_header['filename'];
mp-wp_genesis 3093 $p_info['stored_filename'] = $p_header['stored_filename'];
mp-wp_genesis 3094 $p_info['size'] = $p_header['size'];
mp-wp_genesis 3095 $p_info['compressed_size'] = $p_header['compressed_size'];
mp-wp_genesis 3096 $p_info['mtime'] = $p_header['mtime'];
mp-wp_genesis 3097 $p_info['comment'] = $p_header['comment'];
mp-wp_genesis 3098 $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
mp-wp_genesis 3099 $p_info['index'] = $p_header['index'];
mp-wp_genesis 3100 $p_info['status'] = $p_header['status'];
mp-wp_genesis 3101
mp-wp_genesis 3102 // ----- Return
mp-wp_genesis 3103 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3104 return $v_result;
mp-wp_genesis 3105 }
mp-wp_genesis 3106 // --------------------------------------------------------------------------------
mp-wp_genesis 3107
mp-wp_genesis 3108 // --------------------------------------------------------------------------------
mp-wp_genesis 3109 // Function : privExtractByRule()
mp-wp_genesis 3110 // Description :
mp-wp_genesis 3111 // Extract a file or directory depending of rules (by index, by name, ...)
mp-wp_genesis 3112 // Parameters :
mp-wp_genesis 3113 // $p_file_list : An array where will be placed the properties of each
mp-wp_genesis 3114 // extracted file
mp-wp_genesis 3115 // $p_path : Path to add while writing the extracted files
mp-wp_genesis 3116 // $p_remove_path : Path to remove (from the file memorized path) while writing the
mp-wp_genesis 3117 // extracted files. If the path does not match the file path,
mp-wp_genesis 3118 // the file is extracted with its memorized path.
mp-wp_genesis 3119 // $p_remove_path does not apply to 'list' mode.
mp-wp_genesis 3120 // $p_path and $p_remove_path are commulative.
mp-wp_genesis 3121 // Return Values :
mp-wp_genesis 3122 // 1 on success,0 or less on error (see error code list)
mp-wp_genesis 3123 // --------------------------------------------------------------------------------
mp-wp_genesis 3124 function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
mp-wp_genesis 3125 {
mp-wp_genesis 3126 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");
mp-wp_genesis 3127 $v_result=1;
mp-wp_genesis 3128
mp-wp_genesis 3129 // ----- Magic quotes trick
mp-wp_genesis 3130 $this->privDisableMagicQuotes();
mp-wp_genesis 3131
mp-wp_genesis 3132 // ----- Check the path
mp-wp_genesis 3133 if ( ($p_path == "")
mp-wp_genesis 3134 || ( (substr($p_path, 0, 1) != "/")
mp-wp_genesis 3135 && (substr($p_path, 0, 3) != "../")
mp-wp_genesis 3136 && (substr($p_path,1,2)!=":/")))
mp-wp_genesis 3137 $p_path = "./".$p_path;
mp-wp_genesis 3138
mp-wp_genesis 3139 // ----- Reduce the path last (and duplicated) '/'
mp-wp_genesis 3140 if (($p_path != "./") && ($p_path != "/"))
mp-wp_genesis 3141 {
mp-wp_genesis 3142 // ----- Look for the path end '/'
mp-wp_genesis 3143 while (substr($p_path, -1) == "/")
mp-wp_genesis 3144 {
mp-wp_genesis 3145 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");
mp-wp_genesis 3146 $p_path = substr($p_path, 0, strlen($p_path)-1);
mp-wp_genesis 3147 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");
mp-wp_genesis 3148 }
mp-wp_genesis 3149 }
mp-wp_genesis 3150
mp-wp_genesis 3151 // ----- Look for path to remove format (should end by /)
mp-wp_genesis 3152 if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
mp-wp_genesis 3153 {
mp-wp_genesis 3154 $p_remove_path .= '/';
mp-wp_genesis 3155 }
mp-wp_genesis 3156 $p_remove_path_size = strlen($p_remove_path);
mp-wp_genesis 3157
mp-wp_genesis 3158 // ----- Open the zip file
mp-wp_genesis 3159 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 3160 if (($v_result = $this->privOpenFd('rb')) != 1)
mp-wp_genesis 3161 {
mp-wp_genesis 3162 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3163 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3164 return $v_result;
mp-wp_genesis 3165 }
mp-wp_genesis 3166
mp-wp_genesis 3167 // ----- Read the central directory informations
mp-wp_genesis 3168 $v_central_dir = array();
mp-wp_genesis 3169 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
mp-wp_genesis 3170 {
mp-wp_genesis 3171 // ----- Close the zip file
mp-wp_genesis 3172 $this->privCloseFd();
mp-wp_genesis 3173 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3174
mp-wp_genesis 3175 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3176 return $v_result;
mp-wp_genesis 3177 }
mp-wp_genesis 3178
mp-wp_genesis 3179 // ----- Start at beginning of Central Dir
mp-wp_genesis 3180 $v_pos_entry = $v_central_dir['offset'];
mp-wp_genesis 3181
mp-wp_genesis 3182 // ----- Read each entry
mp-wp_genesis 3183 $j_start = 0;
mp-wp_genesis 3184 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
mp-wp_genesis 3185 {
mp-wp_genesis 3186 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'");
mp-wp_genesis 3187
mp-wp_genesis 3188 // ----- Read next Central dir entry
mp-wp_genesis 3189 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3190 @rewind($this->zip_fd);
mp-wp_genesis 3191 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3192 if (@fseek($this->zip_fd, $v_pos_entry))
mp-wp_genesis 3193 {
mp-wp_genesis 3194 // ----- Close the zip file
mp-wp_genesis 3195 $this->privCloseFd();
mp-wp_genesis 3196 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3197
mp-wp_genesis 3198 // ----- Error log
mp-wp_genesis 3199 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
mp-wp_genesis 3200
mp-wp_genesis 3201 // ----- Return
mp-wp_genesis 3202 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3203 return PclZip::errorCode();
mp-wp_genesis 3204 }
mp-wp_genesis 3205 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3206
mp-wp_genesis 3207 // ----- Read the file header
mp-wp_genesis 3208 $v_header = array();
mp-wp_genesis 3209 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
mp-wp_genesis 3210 {
mp-wp_genesis 3211 // ----- Close the zip file
mp-wp_genesis 3212 $this->privCloseFd();
mp-wp_genesis 3213 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3214
mp-wp_genesis 3215 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3216 return $v_result;
mp-wp_genesis 3217 }
mp-wp_genesis 3218
mp-wp_genesis 3219 // ----- Store the index
mp-wp_genesis 3220 $v_header['index'] = $i;
mp-wp_genesis 3221
mp-wp_genesis 3222 // ----- Store the file position
mp-wp_genesis 3223 $v_pos_entry = ftell($this->zip_fd);
mp-wp_genesis 3224
mp-wp_genesis 3225 // ----- Look for the specific extract rules
mp-wp_genesis 3226 $v_extract = false;
mp-wp_genesis 3227
mp-wp_genesis 3228 // ----- Look for extract by name rule
mp-wp_genesis 3229 if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
mp-wp_genesis 3230 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
mp-wp_genesis 3231 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");
mp-wp_genesis 3232
mp-wp_genesis 3233 // ----- Look if the filename is in the list
mp-wp_genesis 3234 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
mp-wp_genesis 3235 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");
mp-wp_genesis 3236
mp-wp_genesis 3237 // ----- Look for a directory
mp-wp_genesis 3238 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
mp-wp_genesis 3239 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");
mp-wp_genesis 3240
mp-wp_genesis 3241 // ----- Look if the directory is in the filename path
mp-wp_genesis 3242 if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
mp-wp_genesis 3243 && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
mp-wp_genesis 3244 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");
mp-wp_genesis 3245 $v_extract = true;
mp-wp_genesis 3246 }
mp-wp_genesis 3247 }
mp-wp_genesis 3248 // ----- Look for a filename
mp-wp_genesis 3249 elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
mp-wp_genesis 3250 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");
mp-wp_genesis 3251 $v_extract = true;
mp-wp_genesis 3252 }
mp-wp_genesis 3253 }
mp-wp_genesis 3254 }
mp-wp_genesis 3255
mp-wp_genesis 3256 // ----- Look for extract by ereg rule
mp-wp_genesis 3257 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
mp-wp_genesis 3258 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
mp-wp_genesis 3259 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");
mp-wp_genesis 3260
mp-wp_genesis 3261 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
mp-wp_genesis 3262 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
mp-wp_genesis 3263 $v_extract = true;
mp-wp_genesis 3264 }
mp-wp_genesis 3265 }
mp-wp_genesis 3266
mp-wp_genesis 3267 // ----- Look for extract by preg rule
mp-wp_genesis 3268 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
mp-wp_genesis 3269 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
mp-wp_genesis 3270 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");
mp-wp_genesis 3271
mp-wp_genesis 3272 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
mp-wp_genesis 3273 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
mp-wp_genesis 3274 $v_extract = true;
mp-wp_genesis 3275 }
mp-wp_genesis 3276 }
mp-wp_genesis 3277
mp-wp_genesis 3278 // ----- Look for extract by index rule
mp-wp_genesis 3279 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
mp-wp_genesis 3280 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
mp-wp_genesis 3281 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");
mp-wp_genesis 3282
mp-wp_genesis 3283 // ----- Look if the index is in the list
mp-wp_genesis 3284 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
mp-wp_genesis 3285 //--(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']."]");
mp-wp_genesis 3286
mp-wp_genesis 3287 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
mp-wp_genesis 3288 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");
mp-wp_genesis 3289 $v_extract = true;
mp-wp_genesis 3290 }
mp-wp_genesis 3291 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
mp-wp_genesis 3292 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");
mp-wp_genesis 3293 $j_start = $j+1;
mp-wp_genesis 3294 }
mp-wp_genesis 3295
mp-wp_genesis 3296 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
mp-wp_genesis 3297 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");
mp-wp_genesis 3298 break;
mp-wp_genesis 3299 }
mp-wp_genesis 3300 }
mp-wp_genesis 3301 }
mp-wp_genesis 3302
mp-wp_genesis 3303 // ----- Look for no rule, which means extract all the archive
mp-wp_genesis 3304 else {
mp-wp_genesis 3305 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)");
mp-wp_genesis 3306 $v_extract = true;
mp-wp_genesis 3307 }
mp-wp_genesis 3308
mp-wp_genesis 3309 // ----- Check compression method
mp-wp_genesis 3310 if ( ($v_extract)
mp-wp_genesis 3311 && ( ($v_header['compression'] != 8)
mp-wp_genesis 3312 && ($v_header['compression'] != 0))) {
mp-wp_genesis 3313 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")");
mp-wp_genesis 3314 $v_header['status'] = 'unsupported_compression';
mp-wp_genesis 3315
mp-wp_genesis 3316 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
mp-wp_genesis 3317 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
mp-wp_genesis 3318 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
mp-wp_genesis 3319 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
mp-wp_genesis 3320
mp-wp_genesis 3321 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3322
mp-wp_genesis 3323 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
mp-wp_genesis 3324 "Filename '".$v_header['stored_filename']."' is "
mp-wp_genesis 3325 ."compressed by an unsupported compression "
mp-wp_genesis 3326 ."method (".$v_header['compression'].") ");
mp-wp_genesis 3327
mp-wp_genesis 3328 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3329 return PclZip::errorCode();
mp-wp_genesis 3330 }
mp-wp_genesis 3331 }
mp-wp_genesis 3332
mp-wp_genesis 3333 // ----- Check encrypted files
mp-wp_genesis 3334 if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
mp-wp_genesis 3335 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption");
mp-wp_genesis 3336 $v_header['status'] = 'unsupported_encryption';
mp-wp_genesis 3337
mp-wp_genesis 3338 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
mp-wp_genesis 3339 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
mp-wp_genesis 3340 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
mp-wp_genesis 3341 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
mp-wp_genesis 3342
mp-wp_genesis 3343 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3344
mp-wp_genesis 3345 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
mp-wp_genesis 3346 "Unsupported encryption for "
mp-wp_genesis 3347 ." filename '".$v_header['stored_filename']
mp-wp_genesis 3348 ."'");
mp-wp_genesis 3349
mp-wp_genesis 3350 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3351 return PclZip::errorCode();
mp-wp_genesis 3352 }
mp-wp_genesis 3353 }
mp-wp_genesis 3354
mp-wp_genesis 3355 // ----- Look for real extraction
mp-wp_genesis 3356 if (($v_extract) && ($v_header['status'] != 'ok')) {
mp-wp_genesis 3357 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract");
mp-wp_genesis 3358 $v_result = $this->privConvertHeader2FileInfo($v_header,
mp-wp_genesis 3359 $p_file_list[$v_nb_extracted++]);
mp-wp_genesis 3360 if ($v_result != 1) {
mp-wp_genesis 3361 $this->privCloseFd();
mp-wp_genesis 3362 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3363 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3364 return $v_result;
mp-wp_genesis 3365 }
mp-wp_genesis 3366
mp-wp_genesis 3367 $v_extract = false;
mp-wp_genesis 3368 }
mp-wp_genesis 3369
mp-wp_genesis 3370 // ----- Look for real extraction
mp-wp_genesis 3371 if ($v_extract)
mp-wp_genesis 3372 {
mp-wp_genesis 3373 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'");
mp-wp_genesis 3374
mp-wp_genesis 3375 // ----- Go to the file position
mp-wp_genesis 3376 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3377 @rewind($this->zip_fd);
mp-wp_genesis 3378 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3379 if (@fseek($this->zip_fd, $v_header['offset']))
mp-wp_genesis 3380 {
mp-wp_genesis 3381 // ----- Close the zip file
mp-wp_genesis 3382 $this->privCloseFd();
mp-wp_genesis 3383
mp-wp_genesis 3384 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3385
mp-wp_genesis 3386 // ----- Error log
mp-wp_genesis 3387 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
mp-wp_genesis 3388
mp-wp_genesis 3389 // ----- Return
mp-wp_genesis 3390 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3391 return PclZip::errorCode();
mp-wp_genesis 3392 }
mp-wp_genesis 3393 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
mp-wp_genesis 3394
mp-wp_genesis 3395 // ----- Look for extraction as string
mp-wp_genesis 3396 if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
mp-wp_genesis 3397
mp-wp_genesis 3398 // ----- Extracting the file
mp-wp_genesis 3399 $v_result1 = $this->privExtractFileAsString($v_header, $v_string);
mp-wp_genesis 3400 if ($v_result1 < 1) {
mp-wp_genesis 3401 $this->privCloseFd();
mp-wp_genesis 3402 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3403 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
mp-wp_genesis 3404 return $v_result1;
mp-wp_genesis 3405 }
mp-wp_genesis 3406
mp-wp_genesis 3407 // ----- Get the only interesting attributes
mp-wp_genesis 3408 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
mp-wp_genesis 3409 {
mp-wp_genesis 3410 // ----- Close the zip file
mp-wp_genesis 3411 $this->privCloseFd();
mp-wp_genesis 3412 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3413
mp-wp_genesis 3414 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3415 return $v_result;
mp-wp_genesis 3416 }
mp-wp_genesis 3417
mp-wp_genesis 3418 // ----- Set the file content
mp-wp_genesis 3419 $p_file_list[$v_nb_extracted]['content'] = $v_string;
mp-wp_genesis 3420
mp-wp_genesis 3421 // ----- Next extracted file
mp-wp_genesis 3422 $v_nb_extracted++;
mp-wp_genesis 3423
mp-wp_genesis 3424 // ----- Look for user callback abort
mp-wp_genesis 3425 if ($v_result1 == 2) {
mp-wp_genesis 3426 break;
mp-wp_genesis 3427 }
mp-wp_genesis 3428 }
mp-wp_genesis 3429 // ----- Look for extraction in standard output
mp-wp_genesis 3430 elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
mp-wp_genesis 3431 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
mp-wp_genesis 3432 // ----- Extracting the file in standard output
mp-wp_genesis 3433 $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
mp-wp_genesis 3434 if ($v_result1 < 1) {
mp-wp_genesis 3435 $this->privCloseFd();
mp-wp_genesis 3436 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3437 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
mp-wp_genesis 3438 return $v_result1;
mp-wp_genesis 3439 }
mp-wp_genesis 3440
mp-wp_genesis 3441 // ----- Get the only interesting attributes
mp-wp_genesis 3442 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
mp-wp_genesis 3443 $this->privCloseFd();
mp-wp_genesis 3444 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3445 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3446 return $v_result;
mp-wp_genesis 3447 }
mp-wp_genesis 3448
mp-wp_genesis 3449 // ----- Look for user callback abort
mp-wp_genesis 3450 if ($v_result1 == 2) {
mp-wp_genesis 3451 break;
mp-wp_genesis 3452 }
mp-wp_genesis 3453 }
mp-wp_genesis 3454 // ----- Look for normal extraction
mp-wp_genesis 3455 else {
mp-wp_genesis 3456 // ----- Extracting the file
mp-wp_genesis 3457 $v_result1 = $this->privExtractFile($v_header,
mp-wp_genesis 3458 $p_path, $p_remove_path,
mp-wp_genesis 3459 $p_remove_all_path,
mp-wp_genesis 3460 $p_options);
mp-wp_genesis 3461 if ($v_result1 < 1) {
mp-wp_genesis 3462 $this->privCloseFd();
mp-wp_genesis 3463 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3464 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
mp-wp_genesis 3465 return $v_result1;
mp-wp_genesis 3466 }
mp-wp_genesis 3467
mp-wp_genesis 3468 // ----- Get the only interesting attributes
mp-wp_genesis 3469 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
mp-wp_genesis 3470 {
mp-wp_genesis 3471 // ----- Close the zip file
mp-wp_genesis 3472 $this->privCloseFd();
mp-wp_genesis 3473 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3474
mp-wp_genesis 3475 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3476 return $v_result;
mp-wp_genesis 3477 }
mp-wp_genesis 3478
mp-wp_genesis 3479 // ----- Look for user callback abort
mp-wp_genesis 3480 if ($v_result1 == 2) {
mp-wp_genesis 3481 break;
mp-wp_genesis 3482 }
mp-wp_genesis 3483 }
mp-wp_genesis 3484 }
mp-wp_genesis 3485 }
mp-wp_genesis 3486
mp-wp_genesis 3487 // ----- Close the zip file
mp-wp_genesis 3488 $this->privCloseFd();
mp-wp_genesis 3489 $this->privSwapBackMagicQuotes();
mp-wp_genesis 3490
mp-wp_genesis 3491 // ----- Return
mp-wp_genesis 3492 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3493 return $v_result;
mp-wp_genesis 3494 }
mp-wp_genesis 3495 // --------------------------------------------------------------------------------
mp-wp_genesis 3496
mp-wp_genesis 3497 // --------------------------------------------------------------------------------
mp-wp_genesis 3498 // Function : privExtractFile()
mp-wp_genesis 3499 // Description :
mp-wp_genesis 3500 // Parameters :
mp-wp_genesis 3501 // Return Values :
mp-wp_genesis 3502 //
mp-wp_genesis 3503 // 1 : ... ?
mp-wp_genesis 3504 // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
mp-wp_genesis 3505 // --------------------------------------------------------------------------------
mp-wp_genesis 3506 function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
mp-wp_genesis 3507 {
mp-wp_genesis 3508 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");
mp-wp_genesis 3509 $v_result=1;
mp-wp_genesis 3510
mp-wp_genesis 3511 // ----- Read the file header
mp-wp_genesis 3512 if (($v_result = $this->privReadFileHeader($v_header)) != 1)
mp-wp_genesis 3513 {
mp-wp_genesis 3514 // ----- Return
mp-wp_genesis 3515 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3516 return $v_result;
mp-wp_genesis 3517 }
mp-wp_genesis 3518
mp-wp_genesis 3519 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
mp-wp_genesis 3520
mp-wp_genesis 3521 // ----- Check that the file header is coherent with $p_entry info
mp-wp_genesis 3522 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
mp-wp_genesis 3523 // TBC
mp-wp_genesis 3524 }
mp-wp_genesis 3525
mp-wp_genesis 3526 // ----- Look for all path to remove
mp-wp_genesis 3527 if ($p_remove_all_path == true) {
mp-wp_genesis 3528 // ----- Look for folder entry that not need to be extracted
mp-wp_genesis 3529 if (($p_entry['external']&0x00000010)==0x00000010) {
mp-wp_genesis 3530 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered");
mp-wp_genesis 3531
mp-wp_genesis 3532 $p_entry['status'] = "filtered";
mp-wp_genesis 3533
mp-wp_genesis 3534 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3535 return $v_result;
mp-wp_genesis 3536 }
mp-wp_genesis 3537
mp-wp_genesis 3538 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed");
mp-wp_genesis 3539 // ----- Get the basename of the path
mp-wp_genesis 3540 $p_entry['filename'] = basename($p_entry['filename']);
mp-wp_genesis 3541 }
mp-wp_genesis 3542
mp-wp_genesis 3543 // ----- Look for path to remove
mp-wp_genesis 3544 else if ($p_remove_path != "")
mp-wp_genesis 3545 {
mp-wp_genesis 3546 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove");
mp-wp_genesis 3547 if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
mp-wp_genesis 3548 {
mp-wp_genesis 3549 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'");
mp-wp_genesis 3550
mp-wp_genesis 3551 // ----- Change the file status
mp-wp_genesis 3552 $p_entry['status'] = "filtered";
mp-wp_genesis 3553
mp-wp_genesis 3554 // ----- Return
mp-wp_genesis 3555 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3556 return $v_result;
mp-wp_genesis 3557 }
mp-wp_genesis 3558
mp-wp_genesis 3559 $p_remove_path_size = strlen($p_remove_path);
mp-wp_genesis 3560 if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
mp-wp_genesis 3561 {
mp-wp_genesis 3562 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'");
mp-wp_genesis 3563
mp-wp_genesis 3564 // ----- Remove the path
mp-wp_genesis 3565 $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
mp-wp_genesis 3566
mp-wp_genesis 3567 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'");
mp-wp_genesis 3568 }
mp-wp_genesis 3569 }
mp-wp_genesis 3570
mp-wp_genesis 3571 // ----- Add the path
mp-wp_genesis 3572 if ($p_path != '') {
mp-wp_genesis 3573 $p_entry['filename'] = $p_path."/".$p_entry['filename'];
mp-wp_genesis 3574 }
mp-wp_genesis 3575
mp-wp_genesis 3576 // ----- Check a base_dir_restriction
mp-wp_genesis 3577 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
mp-wp_genesis 3578 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction");
mp-wp_genesis 3579 $v_inclusion
mp-wp_genesis 3580 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
mp-wp_genesis 3581 $p_entry['filename']);
mp-wp_genesis 3582 if ($v_inclusion == 0) {
mp-wp_genesis 3583 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction");
mp-wp_genesis 3584
mp-wp_genesis 3585 PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
mp-wp_genesis 3586 "Filename '".$p_entry['filename']."' is "
mp-wp_genesis 3587 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
mp-wp_genesis 3588
mp-wp_genesis 3589 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3590 return PclZip::errorCode();
mp-wp_genesis 3591 }
mp-wp_genesis 3592 }
mp-wp_genesis 3593
mp-wp_genesis 3594 // ----- Look for pre-extract callback
mp-wp_genesis 3595 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
mp-wp_genesis 3596 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");
mp-wp_genesis 3597
mp-wp_genesis 3598 // ----- Generate a local information
mp-wp_genesis 3599 $v_local_header = array();
mp-wp_genesis 3600 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
mp-wp_genesis 3601
mp-wp_genesis 3602 // ----- Call the callback
mp-wp_genesis 3603 // Here I do not use call_user_func() because I need to send a reference to the
mp-wp_genesis 3604 // header.
mp-wp_genesis 3605 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
mp-wp_genesis 3606 if ($v_result == 0) {
mp-wp_genesis 3607 // ----- Change the file status
mp-wp_genesis 3608 $p_entry['status'] = "skipped";
mp-wp_genesis 3609 $v_result = 1;
mp-wp_genesis 3610 }
mp-wp_genesis 3611
mp-wp_genesis 3612 // ----- Look for abort result
mp-wp_genesis 3613 if ($v_result == 2) {
mp-wp_genesis 3614 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
mp-wp_genesis 3615 // ----- This status is internal and will be changed in 'skipped'
mp-wp_genesis 3616 $p_entry['status'] = "aborted";
mp-wp_genesis 3617 $v_result = PCLZIP_ERR_USER_ABORTED;
mp-wp_genesis 3618 }
mp-wp_genesis 3619
mp-wp_genesis 3620 // ----- Update the informations
mp-wp_genesis 3621 // Only some fields can be modified
mp-wp_genesis 3622 $p_entry['filename'] = $v_local_header['filename'];
mp-wp_genesis 3623 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");
mp-wp_genesis 3624 }
mp-wp_genesis 3625
mp-wp_genesis 3626 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");
mp-wp_genesis 3627
mp-wp_genesis 3628 // ----- Look if extraction should be done
mp-wp_genesis 3629 if ($p_entry['status'] == 'ok') {
mp-wp_genesis 3630
mp-wp_genesis 3631 // ----- Look for specific actions while the file exist
mp-wp_genesis 3632 if (file_exists($p_entry['filename']))
mp-wp_genesis 3633 {
mp-wp_genesis 3634 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists");
mp-wp_genesis 3635
mp-wp_genesis 3636 // ----- Look if file is a directory
mp-wp_genesis 3637 if (is_dir($p_entry['filename']))
mp-wp_genesis 3638 {
mp-wp_genesis 3639 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory");
mp-wp_genesis 3640
mp-wp_genesis 3641 // ----- Change the file status
mp-wp_genesis 3642 $p_entry['status'] = "already_a_directory";
mp-wp_genesis 3643
mp-wp_genesis 3644 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
mp-wp_genesis 3645 // For historical reason first PclZip implementation does not stop
mp-wp_genesis 3646 // when this kind of error occurs.
mp-wp_genesis 3647 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
mp-wp_genesis 3648 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
mp-wp_genesis 3649 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
mp-wp_genesis 3650
mp-wp_genesis 3651 PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
mp-wp_genesis 3652 "Filename '".$p_entry['filename']."' is "
mp-wp_genesis 3653 ."already used by an existing directory");
mp-wp_genesis 3654
mp-wp_genesis 3655 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3656 return PclZip::errorCode();
mp-wp_genesis 3657 }
mp-wp_genesis 3658 }
mp-wp_genesis 3659 // ----- Look if file is write protected
mp-wp_genesis 3660 else if (!is_writeable($p_entry['filename']))
mp-wp_genesis 3661 {
mp-wp_genesis 3662 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected");
mp-wp_genesis 3663
mp-wp_genesis 3664 // ----- Change the file status
mp-wp_genesis 3665 $p_entry['status'] = "write_protected";
mp-wp_genesis 3666
mp-wp_genesis 3667 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
mp-wp_genesis 3668 // For historical reason first PclZip implementation does not stop
mp-wp_genesis 3669 // when this kind of error occurs.
mp-wp_genesis 3670 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
mp-wp_genesis 3671 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
mp-wp_genesis 3672 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
mp-wp_genesis 3673
mp-wp_genesis 3674 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
mp-wp_genesis 3675 "Filename '".$p_entry['filename']."' exists "
mp-wp_genesis 3676 ."and is write protected");
mp-wp_genesis 3677
mp-wp_genesis 3678 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3679 return PclZip::errorCode();
mp-wp_genesis 3680 }
mp-wp_genesis 3681 }
mp-wp_genesis 3682
mp-wp_genesis 3683 // ----- Look if the extracted file is older
mp-wp_genesis 3684 else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
mp-wp_genesis 3685 {
mp-wp_genesis 3686 //--(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']).")");
mp-wp_genesis 3687 // ----- Change the file status
mp-wp_genesis 3688 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
mp-wp_genesis 3689 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
mp-wp_genesis 3690 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced");
mp-wp_genesis 3691 }
mp-wp_genesis 3692 else {
mp-wp_genesis 3693 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced");
mp-wp_genesis 3694 $p_entry['status'] = "newer_exist";
mp-wp_genesis 3695
mp-wp_genesis 3696 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
mp-wp_genesis 3697 // For historical reason first PclZip implementation does not stop
mp-wp_genesis 3698 // when this kind of error occurs.
mp-wp_genesis 3699 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
mp-wp_genesis 3700 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
mp-wp_genesis 3701 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
mp-wp_genesis 3702
mp-wp_genesis 3703 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
mp-wp_genesis 3704 "Newer version of '".$p_entry['filename']."' exists "
mp-wp_genesis 3705 ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
mp-wp_genesis 3706
mp-wp_genesis 3707 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 3708 return PclZip::errorCode();
mp-wp_genesis 3709 }
mp-wp_genesis 3710 }
mp-wp_genesis 3711 }
mp-wp_genesis 3712 else {
mp-wp_genesis 3713 //--(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']).")");
mp-wp_genesis 3714 }
mp-wp_genesis 3715 }
mp-wp_genesis 3716
mp-wp_genesis 3717 // ----- Check the directory availability and create it if necessary
mp-wp_genesis 3718 else {
mp-wp_genesis 3719 if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
mp-wp_genesis 3720 $v_dir_to_check = $p_entry['filename'];
mp-wp_genesis 3721 else if (!strstr($p_entry['filename'], "/"))
mp-wp_genesis 3722 $v_dir_to_check = "";
mp-wp_genesis 3723 else
mp-wp_genesis 3724 $v_dir_to_check = dirname($p_entry['filename']);
mp-wp_genesis 3725
mp-wp_genesis 3726 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
mp-wp_genesis 3727 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'");
mp-wp_genesis 3728
mp-wp_genesis 3729 // ----- Change the file status
mp-wp_genesis 3730 $p_entry['status'] = "path_creation_fail";
mp-wp_genesis 3731
mp-wp_genesis 3732 // ----- Return
mp-wp_genesis 3733 ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3734 //return $v_result;
mp-wp_genesis 3735 $v_result = 1;
mp-wp_genesis 3736 }
mp-wp_genesis 3737 }
mp-wp_genesis 3738 }
mp-wp_genesis 3739
mp-wp_genesis 3740 // ----- Look if extraction should be done
mp-wp_genesis 3741 if ($p_entry['status'] == 'ok') {
mp-wp_genesis 3742
mp-wp_genesis 3743 // ----- Do the extraction (if not a folder)
mp-wp_genesis 3744 if (!(($p_entry['external']&0x00000010)==0x00000010))
mp-wp_genesis 3745 {
mp-wp_genesis 3746 // ----- Look for not compressed file
mp-wp_genesis 3747 if ($p_entry['compression'] == 0) {
mp-wp_genesis 3748 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
mp-wp_genesis 3749
mp-wp_genesis 3750 // ----- Opening destination file
mp-wp_genesis 3751 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
mp-wp_genesis 3752 {
mp-wp_genesis 3753 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode");
mp-wp_genesis 3754
mp-wp_genesis 3755 // ----- Change the file status
mp-wp_genesis 3756 $p_entry['status'] = "write_error";
mp-wp_genesis 3757
mp-wp_genesis 3758 // ----- Return
mp-wp_genesis 3759 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3760 return $v_result;
mp-wp_genesis 3761 }
mp-wp_genesis 3762
mp-wp_genesis 3763 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes");
mp-wp_genesis 3764
mp-wp_genesis 3765 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
mp-wp_genesis 3766 $v_size = $p_entry['compressed_size'];
mp-wp_genesis 3767 while ($v_size != 0)
mp-wp_genesis 3768 {
mp-wp_genesis 3769 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 3770 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes");
mp-wp_genesis 3771 $v_buffer = @fread($this->zip_fd, $v_read_size);
mp-wp_genesis 3772 /* Try to speed up the code
mp-wp_genesis 3773 $v_binary_data = pack('a'.$v_read_size, $v_buffer);
mp-wp_genesis 3774 @fwrite($v_dest_file, $v_binary_data, $v_read_size);
mp-wp_genesis 3775 */
mp-wp_genesis 3776 @fwrite($v_dest_file, $v_buffer, $v_read_size);
mp-wp_genesis 3777 $v_size -= $v_read_size;
mp-wp_genesis 3778 }
mp-wp_genesis 3779
mp-wp_genesis 3780 // ----- Closing the destination file
mp-wp_genesis 3781 fclose($v_dest_file);
mp-wp_genesis 3782
mp-wp_genesis 3783 // ----- Change the file mtime
mp-wp_genesis 3784 touch($p_entry['filename'], $p_entry['mtime']);
mp-wp_genesis 3785
mp-wp_genesis 3786
mp-wp_genesis 3787 }
mp-wp_genesis 3788 else {
mp-wp_genesis 3789 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")");
mp-wp_genesis 3790 // ----- TBC
mp-wp_genesis 3791 // Need to be finished
mp-wp_genesis 3792 if (($p_entry['flag'] & 1) == 1) {
mp-wp_genesis 3793 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted");
mp-wp_genesis 3794 /*
mp-wp_genesis 3795 // ----- Read the encryption header
mp-wp_genesis 3796 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes");
mp-wp_genesis 3797 $v_encryption_header = @fread($this->zip_fd, 12);
mp-wp_genesis 3798
mp-wp_genesis 3799 // ----- Read the encrypted & compressed file in a buffer
mp-wp_genesis 3800 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes");
mp-wp_genesis 3801 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12);
mp-wp_genesis 3802
mp-wp_genesis 3803 // ----- Decrypt the buffer
mp-wp_genesis 3804 $this->privDecrypt($v_encryption_header, $v_buffer,
mp-wp_genesis 3805 $p_entry['compressed_size']-12, $p_entry['crc']);
mp-wp_genesis 3806 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'");
mp-wp_genesis 3807 */
mp-wp_genesis 3808 }
mp-wp_genesis 3809 else {
mp-wp_genesis 3810 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes");
mp-wp_genesis 3811 // ----- Read the compressed file in a buffer (one shot)
mp-wp_genesis 3812 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
mp-wp_genesis 3813 }
mp-wp_genesis 3814
mp-wp_genesis 3815 // ----- Decompress the file
mp-wp_genesis 3816 $v_file_content = @gzinflate($v_buffer);
mp-wp_genesis 3817 unset($v_buffer);
mp-wp_genesis 3818 if ($v_file_content === FALSE) {
mp-wp_genesis 3819 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file");
mp-wp_genesis 3820
mp-wp_genesis 3821 // ----- Change the file status
mp-wp_genesis 3822 // TBC
mp-wp_genesis 3823 $p_entry['status'] = "error";
mp-wp_genesis 3824
mp-wp_genesis 3825 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3826 return $v_result;
mp-wp_genesis 3827 }
mp-wp_genesis 3828
mp-wp_genesis 3829 // ----- Opening destination file
mp-wp_genesis 3830 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
mp-wp_genesis 3831 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode");
mp-wp_genesis 3832
mp-wp_genesis 3833 // ----- Change the file status
mp-wp_genesis 3834 $p_entry['status'] = "write_error";
mp-wp_genesis 3835
mp-wp_genesis 3836 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3837 return $v_result;
mp-wp_genesis 3838 }
mp-wp_genesis 3839
mp-wp_genesis 3840 // ----- Write the uncompressed data
mp-wp_genesis 3841 @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
mp-wp_genesis 3842 unset($v_file_content);
mp-wp_genesis 3843
mp-wp_genesis 3844 // ----- Closing the destination file
mp-wp_genesis 3845 @fclose($v_dest_file);
mp-wp_genesis 3846
mp-wp_genesis 3847 // ----- Change the file mtime
mp-wp_genesis 3848 @touch($p_entry['filename'], $p_entry['mtime']);
mp-wp_genesis 3849 }
mp-wp_genesis 3850
mp-wp_genesis 3851 // ----- Look for chmod option
mp-wp_genesis 3852 if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
mp-wp_genesis 3853 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'");
mp-wp_genesis 3854
mp-wp_genesis 3855 // ----- Change the mode of the file
mp-wp_genesis 3856 @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
mp-wp_genesis 3857 }
mp-wp_genesis 3858
mp-wp_genesis 3859 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
mp-wp_genesis 3860 }
mp-wp_genesis 3861 }
mp-wp_genesis 3862
mp-wp_genesis 3863 // ----- Change abort status
mp-wp_genesis 3864 if ($p_entry['status'] == "aborted") {
mp-wp_genesis 3865 $p_entry['status'] = "skipped";
mp-wp_genesis 3866 }
mp-wp_genesis 3867
mp-wp_genesis 3868 // ----- Look for post-extract callback
mp-wp_genesis 3869 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
mp-wp_genesis 3870 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");
mp-wp_genesis 3871
mp-wp_genesis 3872 // ----- Generate a local information
mp-wp_genesis 3873 $v_local_header = array();
mp-wp_genesis 3874 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
mp-wp_genesis 3875
mp-wp_genesis 3876 // ----- Call the callback
mp-wp_genesis 3877 // Here I do not use call_user_func() because I need to send a reference to the
mp-wp_genesis 3878 // header.
mp-wp_genesis 3879 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
mp-wp_genesis 3880
mp-wp_genesis 3881 // ----- Look for abort result
mp-wp_genesis 3882 if ($v_result == 2) {
mp-wp_genesis 3883 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
mp-wp_genesis 3884 $v_result = PCLZIP_ERR_USER_ABORTED;
mp-wp_genesis 3885 }
mp-wp_genesis 3886 }
mp-wp_genesis 3887
mp-wp_genesis 3888 // ----- Return
mp-wp_genesis 3889 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3890 return $v_result;
mp-wp_genesis 3891 }
mp-wp_genesis 3892 // --------------------------------------------------------------------------------
mp-wp_genesis 3893
mp-wp_genesis 3894 // --------------------------------------------------------------------------------
mp-wp_genesis 3895 // Function : privExtractFileInOutput()
mp-wp_genesis 3896 // Description :
mp-wp_genesis 3897 // Parameters :
mp-wp_genesis 3898 // Return Values :
mp-wp_genesis 3899 // --------------------------------------------------------------------------------
mp-wp_genesis 3900 function privExtractFileInOutput(&$p_entry, &$p_options)
mp-wp_genesis 3901 {
mp-wp_genesis 3902 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', "");
mp-wp_genesis 3903 $v_result=1;
mp-wp_genesis 3904
mp-wp_genesis 3905 // ----- Read the file header
mp-wp_genesis 3906 if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
mp-wp_genesis 3907 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 3908 return $v_result;
mp-wp_genesis 3909 }
mp-wp_genesis 3910
mp-wp_genesis 3911 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
mp-wp_genesis 3912
mp-wp_genesis 3913 // ----- Check that the file header is coherent with $p_entry info
mp-wp_genesis 3914 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
mp-wp_genesis 3915 // TBC
mp-wp_genesis 3916 }
mp-wp_genesis 3917
mp-wp_genesis 3918 // ----- Look for pre-extract callback
mp-wp_genesis 3919 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
mp-wp_genesis 3920 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");
mp-wp_genesis 3921
mp-wp_genesis 3922 // ----- Generate a local information
mp-wp_genesis 3923 $v_local_header = array();
mp-wp_genesis 3924 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
mp-wp_genesis 3925
mp-wp_genesis 3926 // ----- Call the callback
mp-wp_genesis 3927 // Here I do not use call_user_func() because I need to send a reference to the
mp-wp_genesis 3928 // header.
mp-wp_genesis 3929 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
mp-wp_genesis 3930 if ($v_result == 0) {
mp-wp_genesis 3931 // ----- Change the file status
mp-wp_genesis 3932 $p_entry['status'] = "skipped";
mp-wp_genesis 3933 $v_result = 1;
mp-wp_genesis 3934 }
mp-wp_genesis 3935
mp-wp_genesis 3936 // ----- Look for abort result
mp-wp_genesis 3937 if ($v_result == 2) {
mp-wp_genesis 3938 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
mp-wp_genesis 3939 // ----- This status is internal and will be changed in 'skipped'
mp-wp_genesis 3940 $p_entry['status'] = "aborted";
mp-wp_genesis 3941 $v_result = PCLZIP_ERR_USER_ABORTED;
mp-wp_genesis 3942 }
mp-wp_genesis 3943
mp-wp_genesis 3944 // ----- Update the informations
mp-wp_genesis 3945 // Only some fields can be modified
mp-wp_genesis 3946 $p_entry['filename'] = $v_local_header['filename'];
mp-wp_genesis 3947 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");
mp-wp_genesis 3948 }
mp-wp_genesis 3949
mp-wp_genesis 3950 // ----- Trace
mp-wp_genesis 3951 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");
mp-wp_genesis 3952
mp-wp_genesis 3953 // ----- Look if extraction should be done
mp-wp_genesis 3954 if ($p_entry['status'] == 'ok') {
mp-wp_genesis 3955
mp-wp_genesis 3956 // ----- Do the extraction (if not a folder)
mp-wp_genesis 3957 if (!(($p_entry['external']&0x00000010)==0x00000010)) {
mp-wp_genesis 3958 // ----- Look for not compressed file
mp-wp_genesis 3959 if ($p_entry['compressed_size'] == $p_entry['size']) {
mp-wp_genesis 3960 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
mp-wp_genesis 3961 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");
mp-wp_genesis 3962
mp-wp_genesis 3963 // ----- Read the file in a buffer (one shot)
mp-wp_genesis 3964 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
mp-wp_genesis 3965
mp-wp_genesis 3966 // ----- Send the file to the output
mp-wp_genesis 3967 echo $v_buffer;
mp-wp_genesis 3968 unset($v_buffer);
mp-wp_genesis 3969 }
mp-wp_genesis 3970 else {
mp-wp_genesis 3971 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file");
mp-wp_genesis 3972 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes");
mp-wp_genesis 3973
mp-wp_genesis 3974 // ----- Read the compressed file in a buffer (one shot)
mp-wp_genesis 3975 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
mp-wp_genesis 3976
mp-wp_genesis 3977 // ----- Decompress the file
mp-wp_genesis 3978 $v_file_content = gzinflate($v_buffer);
mp-wp_genesis 3979 unset($v_buffer);
mp-wp_genesis 3980
mp-wp_genesis 3981 // ----- Send the file to the output
mp-wp_genesis 3982 echo $v_file_content;
mp-wp_genesis 3983 unset($v_file_content);
mp-wp_genesis 3984 }
mp-wp_genesis 3985 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
mp-wp_genesis 3986 }
mp-wp_genesis 3987 }
mp-wp_genesis 3988
mp-wp_genesis 3989 // ----- Change abort status
mp-wp_genesis 3990 if ($p_entry['status'] == "aborted") {
mp-wp_genesis 3991 $p_entry['status'] = "skipped";
mp-wp_genesis 3992 }
mp-wp_genesis 3993
mp-wp_genesis 3994 // ----- Look for post-extract callback
mp-wp_genesis 3995 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
mp-wp_genesis 3996 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");
mp-wp_genesis 3997
mp-wp_genesis 3998 // ----- Generate a local information
mp-wp_genesis 3999 $v_local_header = array();
mp-wp_genesis 4000 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
mp-wp_genesis 4001
mp-wp_genesis 4002 // ----- Call the callback
mp-wp_genesis 4003 // Here I do not use call_user_func() because I need to send a reference to the
mp-wp_genesis 4004 // header.
mp-wp_genesis 4005 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
mp-wp_genesis 4006
mp-wp_genesis 4007 // ----- Look for abort result
mp-wp_genesis 4008 if ($v_result == 2) {
mp-wp_genesis 4009 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
mp-wp_genesis 4010 $v_result = PCLZIP_ERR_USER_ABORTED;
mp-wp_genesis 4011 }
mp-wp_genesis 4012 }
mp-wp_genesis 4013
mp-wp_genesis 4014 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4015 return $v_result;
mp-wp_genesis 4016 }
mp-wp_genesis 4017 // --------------------------------------------------------------------------------
mp-wp_genesis 4018
mp-wp_genesis 4019 // --------------------------------------------------------------------------------
mp-wp_genesis 4020 // Function : privExtractFileAsString()
mp-wp_genesis 4021 // Description :
mp-wp_genesis 4022 // Parameters :
mp-wp_genesis 4023 // Return Values :
mp-wp_genesis 4024 // --------------------------------------------------------------------------------
mp-wp_genesis 4025 function privExtractFileAsString(&$p_entry, &$p_string)
mp-wp_genesis 4026 {
mp-wp_genesis 4027 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'");
mp-wp_genesis 4028 $v_result=1;
mp-wp_genesis 4029
mp-wp_genesis 4030 // ----- Read the file header
mp-wp_genesis 4031 $v_header = array();
mp-wp_genesis 4032 if (($v_result = $this->privReadFileHeader($v_header)) != 1)
mp-wp_genesis 4033 {
mp-wp_genesis 4034 // ----- Return
mp-wp_genesis 4035 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4036 return $v_result;
mp-wp_genesis 4037 }
mp-wp_genesis 4038
mp-wp_genesis 4039 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
mp-wp_genesis 4040
mp-wp_genesis 4041 // ----- Check that the file header is coherent with $p_entry info
mp-wp_genesis 4042 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
mp-wp_genesis 4043 // TBC
mp-wp_genesis 4044 }
mp-wp_genesis 4045
mp-wp_genesis 4046 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'");
mp-wp_genesis 4047
mp-wp_genesis 4048 // ----- Do the extraction (if not a folder)
mp-wp_genesis 4049 if (!(($p_entry['external']&0x00000010)==0x00000010))
mp-wp_genesis 4050 {
mp-wp_genesis 4051 // ----- Look for not compressed file
mp-wp_genesis 4052 // if ($p_entry['compressed_size'] == $p_entry['size'])
mp-wp_genesis 4053 if ($p_entry['compression'] == 0) {
mp-wp_genesis 4054 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
mp-wp_genesis 4055 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");
mp-wp_genesis 4056
mp-wp_genesis 4057 // ----- Reading the file
mp-wp_genesis 4058 $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
mp-wp_genesis 4059 }
mp-wp_genesis 4060 else {
mp-wp_genesis 4061 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')");
mp-wp_genesis 4062
mp-wp_genesis 4063 // ----- Reading the file
mp-wp_genesis 4064 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
mp-wp_genesis 4065
mp-wp_genesis 4066 // ----- Decompress the file
mp-wp_genesis 4067 if (($p_string = @gzinflate($v_data)) === FALSE) {
mp-wp_genesis 4068 // TBC
mp-wp_genesis 4069 }
mp-wp_genesis 4070 }
mp-wp_genesis 4071
mp-wp_genesis 4072 // ----- Trace
mp-wp_genesis 4073 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
mp-wp_genesis 4074 }
mp-wp_genesis 4075 else {
mp-wp_genesis 4076 // TBC : error : can not extract a folder in a string
mp-wp_genesis 4077 }
mp-wp_genesis 4078
mp-wp_genesis 4079 // ----- Return
mp-wp_genesis 4080 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4081 return $v_result;
mp-wp_genesis 4082 }
mp-wp_genesis 4083 // --------------------------------------------------------------------------------
mp-wp_genesis 4084
mp-wp_genesis 4085 // --------------------------------------------------------------------------------
mp-wp_genesis 4086 // Function : privReadFileHeader()
mp-wp_genesis 4087 // Description :
mp-wp_genesis 4088 // Parameters :
mp-wp_genesis 4089 // Return Values :
mp-wp_genesis 4090 // --------------------------------------------------------------------------------
mp-wp_genesis 4091 function privReadFileHeader(&$p_header)
mp-wp_genesis 4092 {
mp-wp_genesis 4093 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", "");
mp-wp_genesis 4094 $v_result=1;
mp-wp_genesis 4095
mp-wp_genesis 4096 // ----- Read the 4 bytes signature
mp-wp_genesis 4097 $v_binary_data = @fread($this->zip_fd, 4);
mp-wp_genesis 4098 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
mp-wp_genesis 4099 $v_data = unpack('Vid', $v_binary_data);
mp-wp_genesis 4100 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
mp-wp_genesis 4101
mp-wp_genesis 4102 // ----- Check signature
mp-wp_genesis 4103 if ($v_data['id'] != 0x04034b50)
mp-wp_genesis 4104 {
mp-wp_genesis 4105 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header");
mp-wp_genesis 4106
mp-wp_genesis 4107 // ----- Error log
mp-wp_genesis 4108 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
mp-wp_genesis 4109
mp-wp_genesis 4110 // ----- Return
mp-wp_genesis 4111 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4112 return PclZip::errorCode();
mp-wp_genesis 4113 }
mp-wp_genesis 4114
mp-wp_genesis 4115 // ----- Read the first 42 bytes of the header
mp-wp_genesis 4116 $v_binary_data = fread($this->zip_fd, 26);
mp-wp_genesis 4117
mp-wp_genesis 4118 // ----- Look for invalid block size
mp-wp_genesis 4119 if (strlen($v_binary_data) != 26)
mp-wp_genesis 4120 {
mp-wp_genesis 4121 $p_header['filename'] = "";
mp-wp_genesis 4122 $p_header['status'] = "invalid_header";
mp-wp_genesis 4123 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));
mp-wp_genesis 4124
mp-wp_genesis 4125 // ----- Error log
mp-wp_genesis 4126 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
mp-wp_genesis 4127
mp-wp_genesis 4128 // ----- Return
mp-wp_genesis 4129 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4130 return PclZip::errorCode();
mp-wp_genesis 4131 }
mp-wp_genesis 4132
mp-wp_genesis 4133 // ----- Extract the values
mp-wp_genesis 4134 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'");
mp-wp_genesis 4135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'");
mp-wp_genesis 4136 $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
mp-wp_genesis 4137
mp-wp_genesis 4138 // ----- Get filename
mp-wp_genesis 4139 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']);
mp-wp_genesis 4140 $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
mp-wp_genesis 4141 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\'');
mp-wp_genesis 4142
mp-wp_genesis 4143 // ----- Get extra_fields
mp-wp_genesis 4144 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']);
mp-wp_genesis 4145 if ($v_data['extra_len'] != 0) {
mp-wp_genesis 4146 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
mp-wp_genesis 4147 }
mp-wp_genesis 4148 else {
mp-wp_genesis 4149 $p_header['extra'] = '';
mp-wp_genesis 4150 }
mp-wp_genesis 4151 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\'');
mp-wp_genesis 4152
mp-wp_genesis 4153 // ----- Extract properties
mp-wp_genesis 4154 $p_header['version_extracted'] = $v_data['version'];
mp-wp_genesis 4155 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\'');
mp-wp_genesis 4156 $p_header['compression'] = $v_data['compression'];
mp-wp_genesis 4157 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\'');
mp-wp_genesis 4158 $p_header['size'] = $v_data['size'];
mp-wp_genesis 4159 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\'');
mp-wp_genesis 4160 $p_header['compressed_size'] = $v_data['compressed_size'];
mp-wp_genesis 4161 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\'');
mp-wp_genesis 4162 $p_header['crc'] = $v_data['crc'];
mp-wp_genesis 4163 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\'');
mp-wp_genesis 4164 $p_header['flag'] = $v_data['flag'];
mp-wp_genesis 4165 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\'');
mp-wp_genesis 4166 $p_header['filename_len'] = $v_data['filename_len'];
mp-wp_genesis 4167 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\'');
mp-wp_genesis 4168
mp-wp_genesis 4169 // ----- Recuperate date in UNIX format
mp-wp_genesis 4170 $p_header['mdate'] = $v_data['mdate'];
mp-wp_genesis 4171 $p_header['mtime'] = $v_data['mtime'];
mp-wp_genesis 4172 if ($p_header['mdate'] && $p_header['mtime'])
mp-wp_genesis 4173 {
mp-wp_genesis 4174 // ----- Extract time
mp-wp_genesis 4175 $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
mp-wp_genesis 4176 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
mp-wp_genesis 4177 $v_seconde = ($p_header['mtime'] & 0x001F)*2;
mp-wp_genesis 4178
mp-wp_genesis 4179 // ----- Extract date
mp-wp_genesis 4180 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
mp-wp_genesis 4181 $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
mp-wp_genesis 4182 $v_day = $p_header['mdate'] & 0x001F;
mp-wp_genesis 4183
mp-wp_genesis 4184 // ----- Get UNIX date format
mp-wp_genesis 4185 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
mp-wp_genesis 4186
mp-wp_genesis 4187 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
mp-wp_genesis 4188 }
mp-wp_genesis 4189 else
mp-wp_genesis 4190 {
mp-wp_genesis 4191 $p_header['mtime'] = time();
mp-wp_genesis 4192 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
mp-wp_genesis 4193 }
mp-wp_genesis 4194
mp-wp_genesis 4195 // TBC
mp-wp_genesis 4196 //for(reset($v_data); $key = key($v_data); next($v_data)) {
mp-wp_genesis 4197 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]);
mp-wp_genesis 4198 //}
mp-wp_genesis 4199
mp-wp_genesis 4200 // ----- Set the stored filename
mp-wp_genesis 4201 $p_header['stored_filename'] = $p_header['filename'];
mp-wp_genesis 4202
mp-wp_genesis 4203 // ----- Set the status field
mp-wp_genesis 4204 $p_header['status'] = "ok";
mp-wp_genesis 4205
mp-wp_genesis 4206 // ----- Return
mp-wp_genesis 4207 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4208 return $v_result;
mp-wp_genesis 4209 }
mp-wp_genesis 4210 // --------------------------------------------------------------------------------
mp-wp_genesis 4211
mp-wp_genesis 4212 // --------------------------------------------------------------------------------
mp-wp_genesis 4213 // Function : privReadCentralFileHeader()
mp-wp_genesis 4214 // Description :
mp-wp_genesis 4215 // Parameters :
mp-wp_genesis 4216 // Return Values :
mp-wp_genesis 4217 // --------------------------------------------------------------------------------
mp-wp_genesis 4218 function privReadCentralFileHeader(&$p_header)
mp-wp_genesis 4219 {
mp-wp_genesis 4220 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", "");
mp-wp_genesis 4221 $v_result=1;
mp-wp_genesis 4222
mp-wp_genesis 4223 // ----- Read the 4 bytes signature
mp-wp_genesis 4224 $v_binary_data = @fread($this->zip_fd, 4);
mp-wp_genesis 4225 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
mp-wp_genesis 4226 $v_data = unpack('Vid', $v_binary_data);
mp-wp_genesis 4227 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
mp-wp_genesis 4228
mp-wp_genesis 4229 // ----- Check signature
mp-wp_genesis 4230 if ($v_data['id'] != 0x02014b50)
mp-wp_genesis 4231 {
mp-wp_genesis 4232 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature");
mp-wp_genesis 4233
mp-wp_genesis 4234 // ----- Error log
mp-wp_genesis 4235 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
mp-wp_genesis 4236
mp-wp_genesis 4237 // ----- Return
mp-wp_genesis 4238 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4239 return PclZip::errorCode();
mp-wp_genesis 4240 }
mp-wp_genesis 4241
mp-wp_genesis 4242 // ----- Read the first 42 bytes of the header
mp-wp_genesis 4243 $v_binary_data = fread($this->zip_fd, 42);
mp-wp_genesis 4244
mp-wp_genesis 4245 // ----- Look for invalid block size
mp-wp_genesis 4246 if (strlen($v_binary_data) != 42)
mp-wp_genesis 4247 {
mp-wp_genesis 4248 $p_header['filename'] = "";
mp-wp_genesis 4249 $p_header['status'] = "invalid_header";
mp-wp_genesis 4250 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));
mp-wp_genesis 4251
mp-wp_genesis 4252 // ----- Error log
mp-wp_genesis 4253 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
mp-wp_genesis 4254
mp-wp_genesis 4255 // ----- Return
mp-wp_genesis 4256 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4257 return PclZip::errorCode();
mp-wp_genesis 4258 }
mp-wp_genesis 4259
mp-wp_genesis 4260 // ----- Extract the values
mp-wp_genesis 4261 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'");
mp-wp_genesis 4262 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'");
mp-wp_genesis 4263 $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);
mp-wp_genesis 4264
mp-wp_genesis 4265 // ----- Get filename
mp-wp_genesis 4266 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']);
mp-wp_genesis 4267 if ($p_header['filename_len'] != 0)
mp-wp_genesis 4268 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
mp-wp_genesis 4269 else
mp-wp_genesis 4270 $p_header['filename'] = '';
mp-wp_genesis 4271 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\'');
mp-wp_genesis 4272
mp-wp_genesis 4273 // ----- Get extra
mp-wp_genesis 4274 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']);
mp-wp_genesis 4275 if ($p_header['extra_len'] != 0)
mp-wp_genesis 4276 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
mp-wp_genesis 4277 else
mp-wp_genesis 4278 $p_header['extra'] = '';
mp-wp_genesis 4279 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\'');
mp-wp_genesis 4280
mp-wp_genesis 4281 // ----- Get comment
mp-wp_genesis 4282 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']);
mp-wp_genesis 4283 if ($p_header['comment_len'] != 0)
mp-wp_genesis 4284 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
mp-wp_genesis 4285 else
mp-wp_genesis 4286 $p_header['comment'] = '';
mp-wp_genesis 4287 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\'');
mp-wp_genesis 4288
mp-wp_genesis 4289 // ----- Extract properties
mp-wp_genesis 4290 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\'');
mp-wp_genesis 4291 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\'');
mp-wp_genesis 4292 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\'');
mp-wp_genesis 4293 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\'');
mp-wp_genesis 4294 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\'');
mp-wp_genesis 4295 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\'');
mp-wp_genesis 4296 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\'');
mp-wp_genesis 4297
mp-wp_genesis 4298 // ----- Recuperate date in UNIX format
mp-wp_genesis 4299 if ($p_header['mdate'] && $p_header['mtime'])
mp-wp_genesis 4300 {
mp-wp_genesis 4301 // ----- Extract time
mp-wp_genesis 4302 $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
mp-wp_genesis 4303 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
mp-wp_genesis 4304 $v_seconde = ($p_header['mtime'] & 0x001F)*2;
mp-wp_genesis 4305
mp-wp_genesis 4306 // ----- Extract date
mp-wp_genesis 4307 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
mp-wp_genesis 4308 $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
mp-wp_genesis 4309 $v_day = $p_header['mdate'] & 0x001F;
mp-wp_genesis 4310
mp-wp_genesis 4311 // ----- Get UNIX date format
mp-wp_genesis 4312 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
mp-wp_genesis 4313
mp-wp_genesis 4314 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
mp-wp_genesis 4315 }
mp-wp_genesis 4316 else
mp-wp_genesis 4317 {
mp-wp_genesis 4318 $p_header['mtime'] = time();
mp-wp_genesis 4319 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
mp-wp_genesis 4320 }
mp-wp_genesis 4321
mp-wp_genesis 4322 // ----- Set the stored filename
mp-wp_genesis 4323 $p_header['stored_filename'] = $p_header['filename'];
mp-wp_genesis 4324
mp-wp_genesis 4325 // ----- Set default status to ok
mp-wp_genesis 4326 $p_header['status'] = 'ok';
mp-wp_genesis 4327
mp-wp_genesis 4328 // ----- Look if it is a directory
mp-wp_genesis 4329 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'");
mp-wp_genesis 4330 //--(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').')');
mp-wp_genesis 4331 if (substr($p_header['filename'], -1) == '/') {
mp-wp_genesis 4332 //$p_header['external'] = 0x41FF0010;
mp-wp_genesis 4333 $p_header['external'] = 0x00000010;
mp-wp_genesis 4334 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\'');
mp-wp_genesis 4335 }
mp-wp_genesis 4336
mp-wp_genesis 4337 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\'');
mp-wp_genesis 4338
mp-wp_genesis 4339 // ----- Return
mp-wp_genesis 4340 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4341 return $v_result;
mp-wp_genesis 4342 }
mp-wp_genesis 4343 // --------------------------------------------------------------------------------
mp-wp_genesis 4344
mp-wp_genesis 4345 // --------------------------------------------------------------------------------
mp-wp_genesis 4346 // Function : privCheckFileHeaders()
mp-wp_genesis 4347 // Description :
mp-wp_genesis 4348 // Parameters :
mp-wp_genesis 4349 // Return Values :
mp-wp_genesis 4350 // 1 on success,
mp-wp_genesis 4351 // 0 on error;
mp-wp_genesis 4352 // --------------------------------------------------------------------------------
mp-wp_genesis 4353 function privCheckFileHeaders(&$p_local_header, &$p_central_header)
mp-wp_genesis 4354 {
mp-wp_genesis 4355 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", "");
mp-wp_genesis 4356 $v_result=1;
mp-wp_genesis 4357
mp-wp_genesis 4358 // ----- Check the static values
mp-wp_genesis 4359 // TBC
mp-wp_genesis 4360 if ($p_local_header['filename'] != $p_central_header['filename']) {
mp-wp_genesis 4361 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed');
mp-wp_genesis 4362 }
mp-wp_genesis 4363 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
mp-wp_genesis 4364 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed');
mp-wp_genesis 4365 }
mp-wp_genesis 4366 if ($p_local_header['flag'] != $p_central_header['flag']) {
mp-wp_genesis 4367 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed');
mp-wp_genesis 4368 }
mp-wp_genesis 4369 if ($p_local_header['compression'] != $p_central_header['compression']) {
mp-wp_genesis 4370 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed');
mp-wp_genesis 4371 }
mp-wp_genesis 4372 if ($p_local_header['mtime'] != $p_central_header['mtime']) {
mp-wp_genesis 4373 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed');
mp-wp_genesis 4374 }
mp-wp_genesis 4375 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
mp-wp_genesis 4376 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed');
mp-wp_genesis 4377 }
mp-wp_genesis 4378
mp-wp_genesis 4379 // ----- Look for flag bit 3
mp-wp_genesis 4380 if (($p_local_header['flag'] & 8) == 8) {
mp-wp_genesis 4381 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !');
mp-wp_genesis 4382 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header');
mp-wp_genesis 4383 $p_local_header['size'] = $p_central_header['size'];
mp-wp_genesis 4384 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\'');
mp-wp_genesis 4385 $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
mp-wp_genesis 4386 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\'');
mp-wp_genesis 4387 $p_local_header['crc'] = $p_central_header['crc'];
mp-wp_genesis 4388 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\'');
mp-wp_genesis 4389 }
mp-wp_genesis 4390
mp-wp_genesis 4391 // ----- Return
mp-wp_genesis 4392 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4393 return $v_result;
mp-wp_genesis 4394 }
mp-wp_genesis 4395 // --------------------------------------------------------------------------------
mp-wp_genesis 4396
mp-wp_genesis 4397 // --------------------------------------------------------------------------------
mp-wp_genesis 4398 // Function : privReadEndCentralDir()
mp-wp_genesis 4399 // Description :
mp-wp_genesis 4400 // Parameters :
mp-wp_genesis 4401 // Return Values :
mp-wp_genesis 4402 // --------------------------------------------------------------------------------
mp-wp_genesis 4403 function privReadEndCentralDir(&$p_central_dir)
mp-wp_genesis 4404 {
mp-wp_genesis 4405 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", "");
mp-wp_genesis 4406 $v_result=1;
mp-wp_genesis 4407
mp-wp_genesis 4408 // ----- Go to the end of the zip file
mp-wp_genesis 4409 $v_size = filesize($this->zipname);
mp-wp_genesis 4410 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size");
mp-wp_genesis 4411 @fseek($this->zip_fd, $v_size);
mp-wp_genesis 4412 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\'');
mp-wp_genesis 4413 if (@ftell($this->zip_fd) != $v_size)
mp-wp_genesis 4414 {
mp-wp_genesis 4415 // ----- Error log
mp-wp_genesis 4416 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
mp-wp_genesis 4417
mp-wp_genesis 4418 // ----- Return
mp-wp_genesis 4419 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4420 return PclZip::errorCode();
mp-wp_genesis 4421 }
mp-wp_genesis 4422
mp-wp_genesis 4423 // ----- First try : look if this is an archive with no commentaries (most of the time)
mp-wp_genesis 4424 // in this case the end of central dir is at 22 bytes of the file end
mp-wp_genesis 4425 $v_found = 0;
mp-wp_genesis 4426 if ($v_size > 26) {
mp-wp_genesis 4427 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment');
mp-wp_genesis 4428 @fseek($this->zip_fd, $v_size-22);
mp-wp_genesis 4429 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\'');
mp-wp_genesis 4430 if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
mp-wp_genesis 4431 {
mp-wp_genesis 4432 // ----- Error log
mp-wp_genesis 4433 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
mp-wp_genesis 4434
mp-wp_genesis 4435 // ----- Return
mp-wp_genesis 4436 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4437 return PclZip::errorCode();
mp-wp_genesis 4438 }
mp-wp_genesis 4439
mp-wp_genesis 4440 // ----- Read for bytes
mp-wp_genesis 4441 $v_binary_data = @fread($this->zip_fd, 4);
mp-wp_genesis 4442 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
mp-wp_genesis 4443 $v_data = @unpack('Vid', $v_binary_data);
mp-wp_genesis 4444 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
mp-wp_genesis 4445
mp-wp_genesis 4446 // ----- Check signature
mp-wp_genesis 4447 if ($v_data['id'] == 0x06054b50) {
mp-wp_genesis 4448 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position.");
mp-wp_genesis 4449 $v_found = 1;
mp-wp_genesis 4450 }
mp-wp_genesis 4451
mp-wp_genesis 4452 $v_pos = ftell($this->zip_fd);
mp-wp_genesis 4453 }
mp-wp_genesis 4454
mp-wp_genesis 4455 // ----- Go back to the maximum possible size of the Central Dir End Record
mp-wp_genesis 4456 if (!$v_found) {
mp-wp_genesis 4457 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir');
mp-wp_genesis 4458 $v_maximum_size = 65557; // 0xFFFF + 22;
mp-wp_genesis 4459 if ($v_maximum_size > $v_size)
mp-wp_genesis 4460 $v_maximum_size = $v_size;
mp-wp_genesis 4461 @fseek($this->zip_fd, $v_size-$v_maximum_size);
mp-wp_genesis 4462 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
mp-wp_genesis 4463 {
mp-wp_genesis 4464 // ----- Error log
mp-wp_genesis 4465 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
mp-wp_genesis 4466
mp-wp_genesis 4467 // ----- Return
mp-wp_genesis 4468 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4469 return PclZip::errorCode();
mp-wp_genesis 4470 }
mp-wp_genesis 4471 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\'');
mp-wp_genesis 4472
mp-wp_genesis 4473 // ----- Read byte per byte in order to find the signature
mp-wp_genesis 4474 $v_pos = ftell($this->zip_fd);
mp-wp_genesis 4475 $v_bytes = 0x00000000;
mp-wp_genesis 4476 while ($v_pos < $v_size)
mp-wp_genesis 4477 {
mp-wp_genesis 4478 // ----- Read a byte
mp-wp_genesis 4479 $v_byte = @fread($this->zip_fd, 1);
mp-wp_genesis 4480
mp-wp_genesis 4481 // ----- Add the byte
mp-wp_genesis 4482 // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
mp-wp_genesis 4483 // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
mp-wp_genesis 4484 $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
mp-wp_genesis 4485
mp-wp_genesis 4486 // ----- Compare the bytes
mp-wp_genesis 4487 if ($v_bytes == 0x504b0506)
mp-wp_genesis 4488 {
mp-wp_genesis 4489 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\'');
mp-wp_genesis 4490 $v_pos++;
mp-wp_genesis 4491 break;
mp-wp_genesis 4492 }
mp-wp_genesis 4493
mp-wp_genesis 4494 $v_pos++;
mp-wp_genesis 4495 }
mp-wp_genesis 4496
mp-wp_genesis 4497 // ----- Look if not found end of central dir
mp-wp_genesis 4498 if ($v_pos == $v_size)
mp-wp_genesis 4499 {
mp-wp_genesis 4500 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature");
mp-wp_genesis 4501
mp-wp_genesis 4502 // ----- Error log
mp-wp_genesis 4503 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
mp-wp_genesis 4504
mp-wp_genesis 4505 // ----- Return
mp-wp_genesis 4506 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4507 return PclZip::errorCode();
mp-wp_genesis 4508 }
mp-wp_genesis 4509 }
mp-wp_genesis 4510
mp-wp_genesis 4511 // ----- Read the first 18 bytes of the header
mp-wp_genesis 4512 $v_binary_data = fread($this->zip_fd, 18);
mp-wp_genesis 4513
mp-wp_genesis 4514 // ----- Look for invalid block size
mp-wp_genesis 4515 if (strlen($v_binary_data) != 18)
mp-wp_genesis 4516 {
mp-wp_genesis 4517 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
mp-wp_genesis 4518
mp-wp_genesis 4519 // ----- Error log
mp-wp_genesis 4520 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
mp-wp_genesis 4521
mp-wp_genesis 4522 // ----- Return
mp-wp_genesis 4523 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4524 return PclZip::errorCode();
mp-wp_genesis 4525 }
mp-wp_genesis 4526
mp-wp_genesis 4527 // ----- Extract the values
mp-wp_genesis 4528 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'");
mp-wp_genesis 4529 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'");
mp-wp_genesis 4530 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
mp-wp_genesis 4531
mp-wp_genesis 4532 // ----- Check the global size
mp-wp_genesis 4533 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']);
mp-wp_genesis 4534 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
mp-wp_genesis 4535 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive.");
mp-wp_genesis 4536
mp-wp_genesis 4537 // ----- Removed in release 2.2 see readme file
mp-wp_genesis 4538 // The check of the file size is a little too strict.
mp-wp_genesis 4539 // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
mp-wp_genesis 4540 // While decrypted, zip has training 0 bytes
mp-wp_genesis 4541 if (0) {
mp-wp_genesis 4542 // ----- Error log
mp-wp_genesis 4543 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
mp-wp_genesis 4544 'The central dir is not at the end of the archive.'
mp-wp_genesis 4545 .' Some trailing bytes exists after the archive.');
mp-wp_genesis 4546
mp-wp_genesis 4547 // ----- Return
mp-wp_genesis 4548 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4549 return PclZip::errorCode();
mp-wp_genesis 4550 }
mp-wp_genesis 4551 }
mp-wp_genesis 4552
mp-wp_genesis 4553 // ----- Get comment
mp-wp_genesis 4554 if ($v_data['comment_size'] != 0)
mp-wp_genesis 4555 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
mp-wp_genesis 4556 else
mp-wp_genesis 4557 $p_central_dir['comment'] = '';
mp-wp_genesis 4558 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\'');
mp-wp_genesis 4559
mp-wp_genesis 4560 $p_central_dir['entries'] = $v_data['entries'];
mp-wp_genesis 4561 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\'');
mp-wp_genesis 4562 $p_central_dir['disk_entries'] = $v_data['disk_entries'];
mp-wp_genesis 4563 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\'');
mp-wp_genesis 4564 $p_central_dir['offset'] = $v_data['offset'];
mp-wp_genesis 4565 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\'');
mp-wp_genesis 4566 $p_central_dir['size'] = $v_data['size'];
mp-wp_genesis 4567 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\'');
mp-wp_genesis 4568 $p_central_dir['disk'] = $v_data['disk'];
mp-wp_genesis 4569 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\'');
mp-wp_genesis 4570 $p_central_dir['disk_start'] = $v_data['disk_start'];
mp-wp_genesis 4571 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\'');
mp-wp_genesis 4572
mp-wp_genesis 4573 // TBC
mp-wp_genesis 4574 //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
mp-wp_genesis 4575 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]);
mp-wp_genesis 4576 //}
mp-wp_genesis 4577
mp-wp_genesis 4578 // ----- Return
mp-wp_genesis 4579 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4580 return $v_result;
mp-wp_genesis 4581 }
mp-wp_genesis 4582 // --------------------------------------------------------------------------------
mp-wp_genesis 4583
mp-wp_genesis 4584 // --------------------------------------------------------------------------------
mp-wp_genesis 4585 // Function : privDeleteByRule()
mp-wp_genesis 4586 // Description :
mp-wp_genesis 4587 // Parameters :
mp-wp_genesis 4588 // Return Values :
mp-wp_genesis 4589 // --------------------------------------------------------------------------------
mp-wp_genesis 4590 function privDeleteByRule(&$p_result_list, &$p_options)
mp-wp_genesis 4591 {
mp-wp_genesis 4592 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", "");
mp-wp_genesis 4593 $v_result=1;
mp-wp_genesis 4594 $v_list_detail = array();
mp-wp_genesis 4595
mp-wp_genesis 4596 // ----- Open the zip file
mp-wp_genesis 4597 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 4598 if (($v_result=$this->privOpenFd('rb')) != 1)
mp-wp_genesis 4599 {
mp-wp_genesis 4600 // ----- Return
mp-wp_genesis 4601 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4602 return $v_result;
mp-wp_genesis 4603 }
mp-wp_genesis 4604
mp-wp_genesis 4605 // ----- Read the central directory informations
mp-wp_genesis 4606 $v_central_dir = array();
mp-wp_genesis 4607 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
mp-wp_genesis 4608 {
mp-wp_genesis 4609 $this->privCloseFd();
mp-wp_genesis 4610 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4611 return $v_result;
mp-wp_genesis 4612 }
mp-wp_genesis 4613
mp-wp_genesis 4614 // ----- Go to beginning of File
mp-wp_genesis 4615 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
mp-wp_genesis 4616 @rewind($this->zip_fd);
mp-wp_genesis 4617 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
mp-wp_genesis 4618
mp-wp_genesis 4619 // ----- Scan all the files
mp-wp_genesis 4620 // ----- Start at beginning of Central Dir
mp-wp_genesis 4621 $v_pos_entry = $v_central_dir['offset'];
mp-wp_genesis 4622 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
mp-wp_genesis 4623 @rewind($this->zip_fd);
mp-wp_genesis 4624 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
mp-wp_genesis 4625 if (@fseek($this->zip_fd, $v_pos_entry))
mp-wp_genesis 4626 {
mp-wp_genesis 4627 // ----- Close the zip file
mp-wp_genesis 4628 $this->privCloseFd();
mp-wp_genesis 4629
mp-wp_genesis 4630 // ----- Error log
mp-wp_genesis 4631 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
mp-wp_genesis 4632
mp-wp_genesis 4633 // ----- Return
mp-wp_genesis 4634 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4635 return PclZip::errorCode();
mp-wp_genesis 4636 }
mp-wp_genesis 4637 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
mp-wp_genesis 4638
mp-wp_genesis 4639 // ----- Read each entry
mp-wp_genesis 4640 $v_header_list = array();
mp-wp_genesis 4641 $j_start = 0;
mp-wp_genesis 4642 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
mp-wp_genesis 4643 {
mp-wp_genesis 4644 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')");
mp-wp_genesis 4645
mp-wp_genesis 4646 // ----- Read the file header
mp-wp_genesis 4647 $v_header_list[$v_nb_extracted] = array();
mp-wp_genesis 4648 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
mp-wp_genesis 4649 {
mp-wp_genesis 4650 // ----- Close the zip file
mp-wp_genesis 4651 $this->privCloseFd();
mp-wp_genesis 4652
mp-wp_genesis 4653 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4654 return $v_result;
mp-wp_genesis 4655 }
mp-wp_genesis 4656
mp-wp_genesis 4657 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'");
mp-wp_genesis 4658
mp-wp_genesis 4659 // ----- Store the index
mp-wp_genesis 4660 $v_header_list[$v_nb_extracted]['index'] = $i;
mp-wp_genesis 4661
mp-wp_genesis 4662 // ----- Look for the specific extract rules
mp-wp_genesis 4663 $v_found = false;
mp-wp_genesis 4664
mp-wp_genesis 4665 // ----- Look for extract by name rule
mp-wp_genesis 4666 if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
mp-wp_genesis 4667 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
mp-wp_genesis 4668 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");
mp-wp_genesis 4669
mp-wp_genesis 4670 // ----- Look if the filename is in the list
mp-wp_genesis 4671 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
mp-wp_genesis 4672 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");
mp-wp_genesis 4673
mp-wp_genesis 4674 // ----- Look for a directory
mp-wp_genesis 4675 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
mp-wp_genesis 4676 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");
mp-wp_genesis 4677
mp-wp_genesis 4678 // ----- Look if the directory is in the filename path
mp-wp_genesis 4679 if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
mp-wp_genesis 4680 && (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])) {
mp-wp_genesis 4681 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");
mp-wp_genesis 4682 $v_found = true;
mp-wp_genesis 4683 }
mp-wp_genesis 4684 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
mp-wp_genesis 4685 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
mp-wp_genesis 4686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory");
mp-wp_genesis 4687 $v_found = true;
mp-wp_genesis 4688 }
mp-wp_genesis 4689 }
mp-wp_genesis 4690 // ----- Look for a filename
mp-wp_genesis 4691 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
mp-wp_genesis 4692 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");
mp-wp_genesis 4693 $v_found = true;
mp-wp_genesis 4694 }
mp-wp_genesis 4695 }
mp-wp_genesis 4696 }
mp-wp_genesis 4697
mp-wp_genesis 4698 // ----- Look for extract by ereg rule
mp-wp_genesis 4699 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
mp-wp_genesis 4700 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
mp-wp_genesis 4701 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");
mp-wp_genesis 4702
mp-wp_genesis 4703 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
mp-wp_genesis 4704 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
mp-wp_genesis 4705 $v_found = true;
mp-wp_genesis 4706 }
mp-wp_genesis 4707 }
mp-wp_genesis 4708
mp-wp_genesis 4709 // ----- Look for extract by preg rule
mp-wp_genesis 4710 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
mp-wp_genesis 4711 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
mp-wp_genesis 4712 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");
mp-wp_genesis 4713
mp-wp_genesis 4714 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
mp-wp_genesis 4715 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
mp-wp_genesis 4716 $v_found = true;
mp-wp_genesis 4717 }
mp-wp_genesis 4718 }
mp-wp_genesis 4719
mp-wp_genesis 4720 // ----- Look for extract by index rule
mp-wp_genesis 4721 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
mp-wp_genesis 4722 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
mp-wp_genesis 4723 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");
mp-wp_genesis 4724
mp-wp_genesis 4725 // ----- Look if the index is in the list
mp-wp_genesis 4726 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
mp-wp_genesis 4727 //--(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']."]");
mp-wp_genesis 4728
mp-wp_genesis 4729 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
mp-wp_genesis 4730 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");
mp-wp_genesis 4731 $v_found = true;
mp-wp_genesis 4732 }
mp-wp_genesis 4733 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
mp-wp_genesis 4734 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");
mp-wp_genesis 4735 $j_start = $j+1;
mp-wp_genesis 4736 }
mp-wp_genesis 4737
mp-wp_genesis 4738 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
mp-wp_genesis 4739 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");
mp-wp_genesis 4740 break;
mp-wp_genesis 4741 }
mp-wp_genesis 4742 }
mp-wp_genesis 4743 }
mp-wp_genesis 4744 else {
mp-wp_genesis 4745 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file");
mp-wp_genesis 4746 $v_found = true;
mp-wp_genesis 4747 }
mp-wp_genesis 4748
mp-wp_genesis 4749 // ----- Look for deletion
mp-wp_genesis 4750 if ($v_found)
mp-wp_genesis 4751 {
mp-wp_genesis 4752 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted");
mp-wp_genesis 4753 unset($v_header_list[$v_nb_extracted]);
mp-wp_genesis 4754 }
mp-wp_genesis 4755 else
mp-wp_genesis 4756 {
mp-wp_genesis 4757 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted");
mp-wp_genesis 4758 $v_nb_extracted++;
mp-wp_genesis 4759 }
mp-wp_genesis 4760 }
mp-wp_genesis 4761
mp-wp_genesis 4762 // ----- Look if something need to be deleted
mp-wp_genesis 4763 if ($v_nb_extracted > 0) {
mp-wp_genesis 4764
mp-wp_genesis 4765 // ----- Creates a temporay file
mp-wp_genesis 4766 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
mp-wp_genesis 4767
mp-wp_genesis 4768 // ----- Creates a temporary zip archive
mp-wp_genesis 4769 $v_temp_zip = new PclZip($v_zip_temp_name);
mp-wp_genesis 4770
mp-wp_genesis 4771 // ----- Open the temporary zip file in write mode
mp-wp_genesis 4772 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode");
mp-wp_genesis 4773 if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
mp-wp_genesis 4774 $this->privCloseFd();
mp-wp_genesis 4775
mp-wp_genesis 4776 // ----- Return
mp-wp_genesis 4777 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4778 return $v_result;
mp-wp_genesis 4779 }
mp-wp_genesis 4780
mp-wp_genesis 4781 // ----- Look which file need to be kept
mp-wp_genesis 4782 for ($i=0; $i<sizeof($v_header_list); $i++) {
mp-wp_genesis 4783 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'");
mp-wp_genesis 4784
mp-wp_genesis 4785 // ----- Calculate the position of the header
mp-wp_genesis 4786 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'");
mp-wp_genesis 4787 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
mp-wp_genesis 4788 @rewind($this->zip_fd);
mp-wp_genesis 4789 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
mp-wp_genesis 4790 if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
mp-wp_genesis 4791 // ----- Close the zip file
mp-wp_genesis 4792 $this->privCloseFd();
mp-wp_genesis 4793 $v_temp_zip->privCloseFd();
mp-wp_genesis 4794 @unlink($v_zip_temp_name);
mp-wp_genesis 4795
mp-wp_genesis 4796 // ----- Error log
mp-wp_genesis 4797 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
mp-wp_genesis 4798
mp-wp_genesis 4799 // ----- Return
mp-wp_genesis 4800 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4801 return PclZip::errorCode();
mp-wp_genesis 4802 }
mp-wp_genesis 4803 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
mp-wp_genesis 4804
mp-wp_genesis 4805 // ----- Read the file header
mp-wp_genesis 4806 $v_local_header = array();
mp-wp_genesis 4807 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
mp-wp_genesis 4808 // ----- Close the zip file
mp-wp_genesis 4809 $this->privCloseFd();
mp-wp_genesis 4810 $v_temp_zip->privCloseFd();
mp-wp_genesis 4811 @unlink($v_zip_temp_name);
mp-wp_genesis 4812
mp-wp_genesis 4813 // ----- Return
mp-wp_genesis 4814 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4815 return $v_result;
mp-wp_genesis 4816 }
mp-wp_genesis 4817
mp-wp_genesis 4818 // ----- Check that local file header is same as central file header
mp-wp_genesis 4819 if ($this->privCheckFileHeaders($v_local_header,
mp-wp_genesis 4820 $v_header_list[$i]) != 1) {
mp-wp_genesis 4821 // TBC
mp-wp_genesis 4822 }
mp-wp_genesis 4823 unset($v_local_header);
mp-wp_genesis 4824
mp-wp_genesis 4825 // ----- Write the file header
mp-wp_genesis 4826 if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
mp-wp_genesis 4827 // ----- Close the zip file
mp-wp_genesis 4828 $this->privCloseFd();
mp-wp_genesis 4829 $v_temp_zip->privCloseFd();
mp-wp_genesis 4830 @unlink($v_zip_temp_name);
mp-wp_genesis 4831
mp-wp_genesis 4832 // ----- Return
mp-wp_genesis 4833 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4834 return $v_result;
mp-wp_genesis 4835 }
mp-wp_genesis 4836 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'");
mp-wp_genesis 4837
mp-wp_genesis 4838 // ----- Read/write the data block
mp-wp_genesis 4839 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
mp-wp_genesis 4840 // ----- Close the zip file
mp-wp_genesis 4841 $this->privCloseFd();
mp-wp_genesis 4842 $v_temp_zip->privCloseFd();
mp-wp_genesis 4843 @unlink($v_zip_temp_name);
mp-wp_genesis 4844
mp-wp_genesis 4845 // ----- Return
mp-wp_genesis 4846 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4847 return $v_result;
mp-wp_genesis 4848 }
mp-wp_genesis 4849 }
mp-wp_genesis 4850
mp-wp_genesis 4851 // ----- Store the offset of the central dir
mp-wp_genesis 4852 $v_offset = @ftell($v_temp_zip->zip_fd);
mp-wp_genesis 4853 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset");
mp-wp_genesis 4854
mp-wp_genesis 4855 // ----- Re-Create the Central Dir files header
mp-wp_genesis 4856 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory");
mp-wp_genesis 4857 for ($i=0; $i<sizeof($v_header_list); $i++) {
mp-wp_genesis 4858 // ----- Create the file header
mp-wp_genesis 4859 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']);
mp-wp_genesis 4860 if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
mp-wp_genesis 4861 $v_temp_zip->privCloseFd();
mp-wp_genesis 4862 $this->privCloseFd();
mp-wp_genesis 4863 @unlink($v_zip_temp_name);
mp-wp_genesis 4864
mp-wp_genesis 4865 // ----- Return
mp-wp_genesis 4866 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4867 return $v_result;
mp-wp_genesis 4868 }
mp-wp_genesis 4869
mp-wp_genesis 4870 // ----- Transform the header to a 'usable' info
mp-wp_genesis 4871 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
mp-wp_genesis 4872 }
mp-wp_genesis 4873
mp-wp_genesis 4874 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer");
mp-wp_genesis 4875
mp-wp_genesis 4876 // ----- Zip file comment
mp-wp_genesis 4877 $v_comment = '';
mp-wp_genesis 4878 if (isset($p_options[PCLZIP_OPT_COMMENT])) {
mp-wp_genesis 4879 $v_comment = $p_options[PCLZIP_OPT_COMMENT];
mp-wp_genesis 4880 }
mp-wp_genesis 4881
mp-wp_genesis 4882 // ----- Calculate the size of the central header
mp-wp_genesis 4883 $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
mp-wp_genesis 4884
mp-wp_genesis 4885 // ----- Create the central dir footer
mp-wp_genesis 4886 if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
mp-wp_genesis 4887 // ----- Reset the file list
mp-wp_genesis 4888 unset($v_header_list);
mp-wp_genesis 4889 $v_temp_zip->privCloseFd();
mp-wp_genesis 4890 $this->privCloseFd();
mp-wp_genesis 4891 @unlink($v_zip_temp_name);
mp-wp_genesis 4892
mp-wp_genesis 4893 // ----- Return
mp-wp_genesis 4894 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4895 return $v_result;
mp-wp_genesis 4896 }
mp-wp_genesis 4897
mp-wp_genesis 4898 // ----- Close
mp-wp_genesis 4899 $v_temp_zip->privCloseFd();
mp-wp_genesis 4900 $this->privCloseFd();
mp-wp_genesis 4901
mp-wp_genesis 4902 // ----- Delete the zip file
mp-wp_genesis 4903 // TBC : I should test the result ...
mp-wp_genesis 4904 @unlink($this->zipname);
mp-wp_genesis 4905
mp-wp_genesis 4906 // ----- Rename the temporary file
mp-wp_genesis 4907 // TBC : I should test the result ...
mp-wp_genesis 4908 //@rename($v_zip_temp_name, $this->zipname);
mp-wp_genesis 4909 PclZipUtilRename($v_zip_temp_name, $this->zipname);
mp-wp_genesis 4910
mp-wp_genesis 4911 // ----- Destroy the temporary archive
mp-wp_genesis 4912 unset($v_temp_zip);
mp-wp_genesis 4913 }
mp-wp_genesis 4914
mp-wp_genesis 4915 // ----- Remove every files : reset the file
mp-wp_genesis 4916 else if ($v_central_dir['entries'] != 0) {
mp-wp_genesis 4917 $this->privCloseFd();
mp-wp_genesis 4918
mp-wp_genesis 4919 if (($v_result = $this->privOpenFd('wb')) != 1) {
mp-wp_genesis 4920 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4921 return $v_result;
mp-wp_genesis 4922 }
mp-wp_genesis 4923
mp-wp_genesis 4924 if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
mp-wp_genesis 4925 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4926 return $v_result;
mp-wp_genesis 4927 }
mp-wp_genesis 4928
mp-wp_genesis 4929 $this->privCloseFd();
mp-wp_genesis 4930 }
mp-wp_genesis 4931
mp-wp_genesis 4932 // ----- Return
mp-wp_genesis 4933 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4934 return $v_result;
mp-wp_genesis 4935 }
mp-wp_genesis 4936 // --------------------------------------------------------------------------------
mp-wp_genesis 4937
mp-wp_genesis 4938 // --------------------------------------------------------------------------------
mp-wp_genesis 4939 // Function : privDirCheck()
mp-wp_genesis 4940 // Description :
mp-wp_genesis 4941 // Check if a directory exists, if not it creates it and all the parents directory
mp-wp_genesis 4942 // which may be useful.
mp-wp_genesis 4943 // Parameters :
mp-wp_genesis 4944 // $p_dir : Directory path to check.
mp-wp_genesis 4945 // Return Values :
mp-wp_genesis 4946 // 1 : OK
mp-wp_genesis 4947 // -1 : Unable to create directory
mp-wp_genesis 4948 // --------------------------------------------------------------------------------
mp-wp_genesis 4949 function privDirCheck($p_dir, $p_is_dir=false)
mp-wp_genesis 4950 {
mp-wp_genesis 4951 $v_result = 1;
mp-wp_genesis 4952
mp-wp_genesis 4953 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'");
mp-wp_genesis 4954
mp-wp_genesis 4955 // ----- Remove the final '/'
mp-wp_genesis 4956 if (($p_is_dir) && (substr($p_dir, -1)=='/'))
mp-wp_genesis 4957 {
mp-wp_genesis 4958 $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
mp-wp_genesis 4959 }
mp-wp_genesis 4960 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'");
mp-wp_genesis 4961
mp-wp_genesis 4962 // ----- Check the directory availability
mp-wp_genesis 4963 if ((is_dir($p_dir)) || ($p_dir == ""))
mp-wp_genesis 4964 {
mp-wp_genesis 4965 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory");
mp-wp_genesis 4966 return 1;
mp-wp_genesis 4967 }
mp-wp_genesis 4968
mp-wp_genesis 4969 // ----- Extract parent directory
mp-wp_genesis 4970 $p_parent_dir = dirname($p_dir);
mp-wp_genesis 4971 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'");
mp-wp_genesis 4972
mp-wp_genesis 4973 // ----- Just a check
mp-wp_genesis 4974 if ($p_parent_dir != $p_dir)
mp-wp_genesis 4975 {
mp-wp_genesis 4976 // ----- Look for parent directory
mp-wp_genesis 4977 if ($p_parent_dir != "")
mp-wp_genesis 4978 {
mp-wp_genesis 4979 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
mp-wp_genesis 4980 {
mp-wp_genesis 4981 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 4982 return $v_result;
mp-wp_genesis 4983 }
mp-wp_genesis 4984 }
mp-wp_genesis 4985 }
mp-wp_genesis 4986
mp-wp_genesis 4987 // ----- Create the directory
mp-wp_genesis 4988 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'");
mp-wp_genesis 4989 if (!@mkdir($p_dir, 0777))
mp-wp_genesis 4990 {
mp-wp_genesis 4991 // ----- Error log
mp-wp_genesis 4992 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
mp-wp_genesis 4993
mp-wp_genesis 4994 // ----- Return
mp-wp_genesis 4995 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 4996 return PclZip::errorCode();
mp-wp_genesis 4997 }
mp-wp_genesis 4998
mp-wp_genesis 4999 // ----- Return
mp-wp_genesis 5000 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created");
mp-wp_genesis 5001 return $v_result;
mp-wp_genesis 5002 }
mp-wp_genesis 5003 // --------------------------------------------------------------------------------
mp-wp_genesis 5004
mp-wp_genesis 5005 // --------------------------------------------------------------------------------
mp-wp_genesis 5006 // Function : privMerge()
mp-wp_genesis 5007 // Description :
mp-wp_genesis 5008 // If $p_archive_to_add does not exist, the function exit with a success result.
mp-wp_genesis 5009 // Parameters :
mp-wp_genesis 5010 // Return Values :
mp-wp_genesis 5011 // --------------------------------------------------------------------------------
mp-wp_genesis 5012 function privMerge(&$p_archive_to_add)
mp-wp_genesis 5013 {
mp-wp_genesis 5014 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'");
mp-wp_genesis 5015 $v_result=1;
mp-wp_genesis 5016
mp-wp_genesis 5017 // ----- Look if the archive_to_add exists
mp-wp_genesis 5018 if (!is_file($p_archive_to_add->zipname))
mp-wp_genesis 5019 {
mp-wp_genesis 5020 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge.");
mp-wp_genesis 5021
mp-wp_genesis 5022 // ----- Nothing to merge, so merge is a success
mp-wp_genesis 5023 $v_result = 1;
mp-wp_genesis 5024
mp-wp_genesis 5025 // ----- Return
mp-wp_genesis 5026 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5027 return $v_result;
mp-wp_genesis 5028 }
mp-wp_genesis 5029
mp-wp_genesis 5030 // ----- Look if the archive exists
mp-wp_genesis 5031 if (!is_file($this->zipname))
mp-wp_genesis 5032 {
mp-wp_genesis 5033 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add.");
mp-wp_genesis 5034
mp-wp_genesis 5035 // ----- Do a duplicate
mp-wp_genesis 5036 $v_result = $this->privDuplicate($p_archive_to_add->zipname);
mp-wp_genesis 5037
mp-wp_genesis 5038 // ----- Return
mp-wp_genesis 5039 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5040 return $v_result;
mp-wp_genesis 5041 }
mp-wp_genesis 5042
mp-wp_genesis 5043 // ----- Open the zip file
mp-wp_genesis 5044 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 5045 if (($v_result=$this->privOpenFd('rb')) != 1)
mp-wp_genesis 5046 {
mp-wp_genesis 5047 // ----- Return
mp-wp_genesis 5048 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5049 return $v_result;
mp-wp_genesis 5050 }
mp-wp_genesis 5051
mp-wp_genesis 5052 // ----- Read the central directory informations
mp-wp_genesis 5053 $v_central_dir = array();
mp-wp_genesis 5054 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
mp-wp_genesis 5055 {
mp-wp_genesis 5056 $this->privCloseFd();
mp-wp_genesis 5057 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5058 return $v_result;
mp-wp_genesis 5059 }
mp-wp_genesis 5060
mp-wp_genesis 5061 // ----- Go to beginning of File
mp-wp_genesis 5062 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");
mp-wp_genesis 5063 @rewind($this->zip_fd);
mp-wp_genesis 5064 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");
mp-wp_genesis 5065
mp-wp_genesis 5066 // ----- Open the archive_to_add file
mp-wp_genesis 5067 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode");
mp-wp_genesis 5068 if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
mp-wp_genesis 5069 {
mp-wp_genesis 5070 $this->privCloseFd();
mp-wp_genesis 5071
mp-wp_genesis 5072 // ----- Return
mp-wp_genesis 5073 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5074 return $v_result;
mp-wp_genesis 5075 }
mp-wp_genesis 5076
mp-wp_genesis 5077 // ----- Read the central directory informations
mp-wp_genesis 5078 $v_central_dir_to_add = array();
mp-wp_genesis 5079 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
mp-wp_genesis 5080 {
mp-wp_genesis 5081 $this->privCloseFd();
mp-wp_genesis 5082 $p_archive_to_add->privCloseFd();
mp-wp_genesis 5083
mp-wp_genesis 5084 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5085 return $v_result;
mp-wp_genesis 5086 }
mp-wp_genesis 5087
mp-wp_genesis 5088 // ----- Go to beginning of File
mp-wp_genesis 5089 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");
mp-wp_genesis 5090 @rewind($p_archive_to_add->zip_fd);
mp-wp_genesis 5091 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");
mp-wp_genesis 5092
mp-wp_genesis 5093 // ----- Creates a temporay file
mp-wp_genesis 5094 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
mp-wp_genesis 5095
mp-wp_genesis 5096 // ----- Open the temporary file in write mode
mp-wp_genesis 5097 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 5098 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
mp-wp_genesis 5099 {
mp-wp_genesis 5100 $this->privCloseFd();
mp-wp_genesis 5101 $p_archive_to_add->privCloseFd();
mp-wp_genesis 5102
mp-wp_genesis 5103 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
mp-wp_genesis 5104
mp-wp_genesis 5105 // ----- Return
mp-wp_genesis 5106 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 5107 return PclZip::errorCode();
mp-wp_genesis 5108 }
mp-wp_genesis 5109
mp-wp_genesis 5110 // ----- Copy the files from the archive to the temporary file
mp-wp_genesis 5111 // TBC : Here I should better append the file and go back to erase the central dir
mp-wp_genesis 5112 $v_size = $v_central_dir['offset'];
mp-wp_genesis 5113 while ($v_size != 0)
mp-wp_genesis 5114 {
mp-wp_genesis 5115 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5116 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 5117 $v_buffer = fread($this->zip_fd, $v_read_size);
mp-wp_genesis 5118 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
mp-wp_genesis 5119 $v_size -= $v_read_size;
mp-wp_genesis 5120 }
mp-wp_genesis 5121
mp-wp_genesis 5122 // ----- Copy the files from the archive_to_add into the temporary file
mp-wp_genesis 5123 $v_size = $v_central_dir_to_add['offset'];
mp-wp_genesis 5124 while ($v_size != 0)
mp-wp_genesis 5125 {
mp-wp_genesis 5126 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5127 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 5128 $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
mp-wp_genesis 5129 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
mp-wp_genesis 5130 $v_size -= $v_read_size;
mp-wp_genesis 5131 }
mp-wp_genesis 5132
mp-wp_genesis 5133 // ----- Store the offset of the central dir
mp-wp_genesis 5134 $v_offset = @ftell($v_zip_temp_fd);
mp-wp_genesis 5135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");
mp-wp_genesis 5136
mp-wp_genesis 5137 // ----- Copy the block of file headers from the old archive
mp-wp_genesis 5138 $v_size = $v_central_dir['size'];
mp-wp_genesis 5139 while ($v_size != 0)
mp-wp_genesis 5140 {
mp-wp_genesis 5141 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5142 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 5143 $v_buffer = @fread($this->zip_fd, $v_read_size);
mp-wp_genesis 5144 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
mp-wp_genesis 5145 $v_size -= $v_read_size;
mp-wp_genesis 5146 }
mp-wp_genesis 5147
mp-wp_genesis 5148 // ----- Copy the block of file headers from the archive_to_add
mp-wp_genesis 5149 $v_size = $v_central_dir_to_add['size'];
mp-wp_genesis 5150 while ($v_size != 0)
mp-wp_genesis 5151 {
mp-wp_genesis 5152 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5153 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 5154 $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
mp-wp_genesis 5155 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
mp-wp_genesis 5156 $v_size -= $v_read_size;
mp-wp_genesis 5157 }
mp-wp_genesis 5158
mp-wp_genesis 5159 // ----- Merge the file comments
mp-wp_genesis 5160 $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
mp-wp_genesis 5161
mp-wp_genesis 5162 // ----- Calculate the size of the (new) central header
mp-wp_genesis 5163 $v_size = @ftell($v_zip_temp_fd)-$v_offset;
mp-wp_genesis 5164
mp-wp_genesis 5165 // ----- Swap the file descriptor
mp-wp_genesis 5166 // Here is a trick : I swap the temporary fd with the zip fd, in order to use
mp-wp_genesis 5167 // the following methods on the temporary fil and not the real archive fd
mp-wp_genesis 5168 $v_swap = $this->zip_fd;
mp-wp_genesis 5169 $this->zip_fd = $v_zip_temp_fd;
mp-wp_genesis 5170 $v_zip_temp_fd = $v_swap;
mp-wp_genesis 5171
mp-wp_genesis 5172 // ----- Create the central dir footer
mp-wp_genesis 5173 if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
mp-wp_genesis 5174 {
mp-wp_genesis 5175 $this->privCloseFd();
mp-wp_genesis 5176 $p_archive_to_add->privCloseFd();
mp-wp_genesis 5177 @fclose($v_zip_temp_fd);
mp-wp_genesis 5178 $this->zip_fd = null;
mp-wp_genesis 5179
mp-wp_genesis 5180 // ----- Reset the file list
mp-wp_genesis 5181 unset($v_header_list);
mp-wp_genesis 5182
mp-wp_genesis 5183 // ----- Return
mp-wp_genesis 5184 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5185 return $v_result;
mp-wp_genesis 5186 }
mp-wp_genesis 5187
mp-wp_genesis 5188 // ----- Swap back the file descriptor
mp-wp_genesis 5189 $v_swap = $this->zip_fd;
mp-wp_genesis 5190 $this->zip_fd = $v_zip_temp_fd;
mp-wp_genesis 5191 $v_zip_temp_fd = $v_swap;
mp-wp_genesis 5192
mp-wp_genesis 5193 // ----- Close
mp-wp_genesis 5194 $this->privCloseFd();
mp-wp_genesis 5195 $p_archive_to_add->privCloseFd();
mp-wp_genesis 5196
mp-wp_genesis 5197 // ----- Close the temporary file
mp-wp_genesis 5198 @fclose($v_zip_temp_fd);
mp-wp_genesis 5199
mp-wp_genesis 5200 // ----- Delete the zip file
mp-wp_genesis 5201 // TBC : I should test the result ...
mp-wp_genesis 5202 @unlink($this->zipname);
mp-wp_genesis 5203
mp-wp_genesis 5204 // ----- Rename the temporary file
mp-wp_genesis 5205 // TBC : I should test the result ...
mp-wp_genesis 5206 //@rename($v_zip_temp_name, $this->zipname);
mp-wp_genesis 5207 PclZipUtilRename($v_zip_temp_name, $this->zipname);
mp-wp_genesis 5208
mp-wp_genesis 5209 // ----- Return
mp-wp_genesis 5210 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5211 return $v_result;
mp-wp_genesis 5212 }
mp-wp_genesis 5213 // --------------------------------------------------------------------------------
mp-wp_genesis 5214
mp-wp_genesis 5215 // --------------------------------------------------------------------------------
mp-wp_genesis 5216 // Function : privDuplicate()
mp-wp_genesis 5217 // Description :
mp-wp_genesis 5218 // Parameters :
mp-wp_genesis 5219 // Return Values :
mp-wp_genesis 5220 // --------------------------------------------------------------------------------
mp-wp_genesis 5221 function privDuplicate($p_archive_filename)
mp-wp_genesis 5222 {
mp-wp_genesis 5223 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'");
mp-wp_genesis 5224 $v_result=1;
mp-wp_genesis 5225
mp-wp_genesis 5226 // ----- Look if the $p_archive_filename exists
mp-wp_genesis 5227 if (!is_file($p_archive_filename))
mp-wp_genesis 5228 {
mp-wp_genesis 5229 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate.");
mp-wp_genesis 5230
mp-wp_genesis 5231 // ----- Nothing to duplicate, so duplicate is a success.
mp-wp_genesis 5232 $v_result = 1;
mp-wp_genesis 5233
mp-wp_genesis 5234 // ----- Return
mp-wp_genesis 5235 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5236 return $v_result;
mp-wp_genesis 5237 }
mp-wp_genesis 5238
mp-wp_genesis 5239 // ----- Open the zip file
mp-wp_genesis 5240 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 5241 if (($v_result=$this->privOpenFd('wb')) != 1)
mp-wp_genesis 5242 {
mp-wp_genesis 5243 // ----- Return
mp-wp_genesis 5244 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5245 return $v_result;
mp-wp_genesis 5246 }
mp-wp_genesis 5247
mp-wp_genesis 5248 // ----- Open the temporary file in write mode
mp-wp_genesis 5249 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
mp-wp_genesis 5250 if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
mp-wp_genesis 5251 {
mp-wp_genesis 5252 $this->privCloseFd();
mp-wp_genesis 5253
mp-wp_genesis 5254 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
mp-wp_genesis 5255
mp-wp_genesis 5256 // ----- Return
mp-wp_genesis 5257 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
mp-wp_genesis 5258 return PclZip::errorCode();
mp-wp_genesis 5259 }
mp-wp_genesis 5260
mp-wp_genesis 5261 // ----- Copy the files from the archive to the temporary file
mp-wp_genesis 5262 // TBC : Here I should better append the file and go back to erase the central dir
mp-wp_genesis 5263 $v_size = filesize($p_archive_filename);
mp-wp_genesis 5264 while ($v_size != 0)
mp-wp_genesis 5265 {
mp-wp_genesis 5266 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5267 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes");
mp-wp_genesis 5268 $v_buffer = fread($v_zip_temp_fd, $v_read_size);
mp-wp_genesis 5269 @fwrite($this->zip_fd, $v_buffer, $v_read_size);
mp-wp_genesis 5270 $v_size -= $v_read_size;
mp-wp_genesis 5271 }
mp-wp_genesis 5272
mp-wp_genesis 5273 // ----- Close
mp-wp_genesis 5274 $this->privCloseFd();
mp-wp_genesis 5275
mp-wp_genesis 5276 // ----- Close the temporary file
mp-wp_genesis 5277 @fclose($v_zip_temp_fd);
mp-wp_genesis 5278
mp-wp_genesis 5279 // ----- Return
mp-wp_genesis 5280 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5281 return $v_result;
mp-wp_genesis 5282 }
mp-wp_genesis 5283 // --------------------------------------------------------------------------------
mp-wp_genesis 5284
mp-wp_genesis 5285 // --------------------------------------------------------------------------------
mp-wp_genesis 5286 // Function : privErrorLog()
mp-wp_genesis 5287 // Description :
mp-wp_genesis 5288 // Parameters :
mp-wp_genesis 5289 // --------------------------------------------------------------------------------
mp-wp_genesis 5290 function privErrorLog($p_error_code=0, $p_error_string='')
mp-wp_genesis 5291 {
mp-wp_genesis 5292 if (PCLZIP_ERROR_EXTERNAL == 1) {
mp-wp_genesis 5293 PclError($p_error_code, $p_error_string);
mp-wp_genesis 5294 }
mp-wp_genesis 5295 else {
mp-wp_genesis 5296 $this->error_code = $p_error_code;
mp-wp_genesis 5297 $this->error_string = $p_error_string;
mp-wp_genesis 5298 }
mp-wp_genesis 5299 }
mp-wp_genesis 5300 // --------------------------------------------------------------------------------
mp-wp_genesis 5301
mp-wp_genesis 5302 // --------------------------------------------------------------------------------
mp-wp_genesis 5303 // Function : privErrorReset()
mp-wp_genesis 5304 // Description :
mp-wp_genesis 5305 // Parameters :
mp-wp_genesis 5306 // --------------------------------------------------------------------------------
mp-wp_genesis 5307 function privErrorReset()
mp-wp_genesis 5308 {
mp-wp_genesis 5309 if (PCLZIP_ERROR_EXTERNAL == 1) {
mp-wp_genesis 5310 PclErrorReset();
mp-wp_genesis 5311 }
mp-wp_genesis 5312 else {
mp-wp_genesis 5313 $this->error_code = 0;
mp-wp_genesis 5314 $this->error_string = '';
mp-wp_genesis 5315 }
mp-wp_genesis 5316 }
mp-wp_genesis 5317 // --------------------------------------------------------------------------------
mp-wp_genesis 5318
mp-wp_genesis 5319 // --------------------------------------------------------------------------------
mp-wp_genesis 5320 // Function : privDecrypt()
mp-wp_genesis 5321 // Description :
mp-wp_genesis 5322 // Parameters :
mp-wp_genesis 5323 // Return Values :
mp-wp_genesis 5324 // --------------------------------------------------------------------------------
mp-wp_genesis 5325 function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc)
mp-wp_genesis 5326 {
mp-wp_genesis 5327 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size."");
mp-wp_genesis 5328 $v_result=1;
mp-wp_genesis 5329
mp-wp_genesis 5330 // ----- To Be Modified ;-)
mp-wp_genesis 5331 $v_pwd = "test";
mp-wp_genesis 5332
mp-wp_genesis 5333 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header,
mp-wp_genesis 5334 $p_crc, $v_pwd);
mp-wp_genesis 5335
mp-wp_genesis 5336 // ----- Return
mp-wp_genesis 5337 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5338 return $v_result;
mp-wp_genesis 5339 }
mp-wp_genesis 5340 // --------------------------------------------------------------------------------
mp-wp_genesis 5341
mp-wp_genesis 5342 // --------------------------------------------------------------------------------
mp-wp_genesis 5343 // Function : privDisableMagicQuotes()
mp-wp_genesis 5344 // Description :
mp-wp_genesis 5345 // Parameters :
mp-wp_genesis 5346 // Return Values :
mp-wp_genesis 5347 // --------------------------------------------------------------------------------
mp-wp_genesis 5348 function privDisableMagicQuotes()
mp-wp_genesis 5349 {
mp-wp_genesis 5350 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', "");
mp-wp_genesis 5351 $v_result=1;
mp-wp_genesis 5352
mp-wp_genesis 5353 // ----- Look if function exists
mp-wp_genesis 5354 if ( (!function_exists("get_magic_quotes_runtime"))
mp-wp_genesis 5355 || (!function_exists("set_magic_quotes_runtime"))) {
mp-wp_genesis 5356 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");
mp-wp_genesis 5357 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5358 return $v_result;
mp-wp_genesis 5359 }
mp-wp_genesis 5360
mp-wp_genesis 5361 // ----- Look if already done
mp-wp_genesis 5362 if ($this->magic_quotes_status != -1) {
mp-wp_genesis 5363 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled");
mp-wp_genesis 5364 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5365 return $v_result;
mp-wp_genesis 5366 }
mp-wp_genesis 5367
mp-wp_genesis 5368 // ----- Get and memorize the magic_quote value
mp-wp_genesis 5369 $this->magic_quotes_status = @get_magic_quotes_runtime();
mp-wp_genesis 5370 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'");
mp-wp_genesis 5371
mp-wp_genesis 5372 // ----- Disable magic_quotes
mp-wp_genesis 5373 if ($this->magic_quotes_status == 1) {
mp-wp_genesis 5374 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes");
mp-wp_genesis 5375 @set_magic_quotes_runtime(0);
mp-wp_genesis 5376 }
mp-wp_genesis 5377
mp-wp_genesis 5378 // ----- Return
mp-wp_genesis 5379 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5380 return $v_result;
mp-wp_genesis 5381 }
mp-wp_genesis 5382 // --------------------------------------------------------------------------------
mp-wp_genesis 5383
mp-wp_genesis 5384 // --------------------------------------------------------------------------------
mp-wp_genesis 5385 // Function : privSwapBackMagicQuotes()
mp-wp_genesis 5386 // Description :
mp-wp_genesis 5387 // Parameters :
mp-wp_genesis 5388 // Return Values :
mp-wp_genesis 5389 // --------------------------------------------------------------------------------
mp-wp_genesis 5390 function privSwapBackMagicQuotes()
mp-wp_genesis 5391 {
mp-wp_genesis 5392 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', "");
mp-wp_genesis 5393 $v_result=1;
mp-wp_genesis 5394
mp-wp_genesis 5395 // ----- Look if function exists
mp-wp_genesis 5396 if ( (!function_exists("get_magic_quotes_runtime"))
mp-wp_genesis 5397 || (!function_exists("set_magic_quotes_runtime"))) {
mp-wp_genesis 5398 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");
mp-wp_genesis 5399 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5400 return $v_result;
mp-wp_genesis 5401 }
mp-wp_genesis 5402
mp-wp_genesis 5403 // ----- Look if something to do
mp-wp_genesis 5404 if ($this->magic_quotes_status != -1) {
mp-wp_genesis 5405 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified");
mp-wp_genesis 5406 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5407 return $v_result;
mp-wp_genesis 5408 }
mp-wp_genesis 5409
mp-wp_genesis 5410 // ----- Swap back magic_quotes
mp-wp_genesis 5411 if ($this->magic_quotes_status == 1) {
mp-wp_genesis 5412 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes");
mp-wp_genesis 5413 @set_magic_quotes_runtime($this->magic_quotes_status);
mp-wp_genesis 5414 }
mp-wp_genesis 5415
mp-wp_genesis 5416 // ----- Return
mp-wp_genesis 5417 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5418 return $v_result;
mp-wp_genesis 5419 }
mp-wp_genesis 5420 // --------------------------------------------------------------------------------
mp-wp_genesis 5421
mp-wp_genesis 5422 }
mp-wp_genesis 5423 // End of class
mp-wp_genesis 5424 // --------------------------------------------------------------------------------
mp-wp_genesis 5425
mp-wp_genesis 5426 // --------------------------------------------------------------------------------
mp-wp_genesis 5427 // Function : PclZipUtilPathReduction()
mp-wp_genesis 5428 // Description :
mp-wp_genesis 5429 // Parameters :
mp-wp_genesis 5430 // Return Values :
mp-wp_genesis 5431 // --------------------------------------------------------------------------------
mp-wp_genesis 5432 function PclZipUtilPathReduction($p_dir)
mp-wp_genesis 5433 {
mp-wp_genesis 5434 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'");
mp-wp_genesis 5435 $v_result = "";
mp-wp_genesis 5436
mp-wp_genesis 5437 // ----- Look for not empty path
mp-wp_genesis 5438 if ($p_dir != "") {
mp-wp_genesis 5439 // ----- Explode path by directory names
mp-wp_genesis 5440 $v_list = explode("/", $p_dir);
mp-wp_genesis 5441
mp-wp_genesis 5442 // ----- Study directories from last to first
mp-wp_genesis 5443 $v_skip = 0;
mp-wp_genesis 5444 for ($i=sizeof($v_list)-1; $i>=0; $i--) {
mp-wp_genesis 5445 // ----- Look for current path
mp-wp_genesis 5446 if ($v_list[$i] == ".") {
mp-wp_genesis 5447 // ----- Ignore this directory
mp-wp_genesis 5448 // Should be the first $i=0, but no check is done
mp-wp_genesis 5449 }
mp-wp_genesis 5450 else if ($v_list[$i] == "..") {
mp-wp_genesis 5451 $v_skip++;
mp-wp_genesis 5452 }
mp-wp_genesis 5453 else if ($v_list[$i] == "") {
mp-wp_genesis 5454 // ----- First '/' i.e. root slash
mp-wp_genesis 5455 if ($i == 0) {
mp-wp_genesis 5456 $v_result = "/".$v_result;
mp-wp_genesis 5457 if ($v_skip > 0) {
mp-wp_genesis 5458 // ----- It is an invalid path, so the path is not modified
mp-wp_genesis 5459 // TBC
mp-wp_genesis 5460 $v_result = $p_dir;
mp-wp_genesis 5461 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged");
mp-wp_genesis 5462 $v_skip = 0;
mp-wp_genesis 5463 }
mp-wp_genesis 5464 }
mp-wp_genesis 5465 // ----- Last '/' i.e. indicates a directory
mp-wp_genesis 5466 else if ($i == (sizeof($v_list)-1)) {
mp-wp_genesis 5467 $v_result = $v_list[$i];
mp-wp_genesis 5468 }
mp-wp_genesis 5469 // ----- Double '/' inside the path
mp-wp_genesis 5470 else {
mp-wp_genesis 5471 // ----- Ignore only the double '//' in path,
mp-wp_genesis 5472 // but not the first and last '/'
mp-wp_genesis 5473 }
mp-wp_genesis 5474 }
mp-wp_genesis 5475 else {
mp-wp_genesis 5476 // ----- Look for item to skip
mp-wp_genesis 5477 if ($v_skip > 0) {
mp-wp_genesis 5478 $v_skip--;
mp-wp_genesis 5479 }
mp-wp_genesis 5480 else {
mp-wp_genesis 5481 $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
mp-wp_genesis 5482 }
mp-wp_genesis 5483 }
mp-wp_genesis 5484 }
mp-wp_genesis 5485
mp-wp_genesis 5486 // ----- Look for skip
mp-wp_genesis 5487 if ($v_skip > 0) {
mp-wp_genesis 5488 while ($v_skip > 0) {
mp-wp_genesis 5489 $v_result = '../'.$v_result;
mp-wp_genesis 5490 $v_skip--;
mp-wp_genesis 5491 }
mp-wp_genesis 5492 }
mp-wp_genesis 5493 }
mp-wp_genesis 5494
mp-wp_genesis 5495 // ----- Return
mp-wp_genesis 5496 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5497 return $v_result;
mp-wp_genesis 5498 }
mp-wp_genesis 5499 // --------------------------------------------------------------------------------
mp-wp_genesis 5500
mp-wp_genesis 5501 // --------------------------------------------------------------------------------
mp-wp_genesis 5502 // Function : PclZipUtilPathInclusion()
mp-wp_genesis 5503 // Description :
mp-wp_genesis 5504 // This function indicates if the path $p_path is under the $p_dir tree. Or,
mp-wp_genesis 5505 // said in an other way, if the file or sub-dir $p_path is inside the dir
mp-wp_genesis 5506 // $p_dir.
mp-wp_genesis 5507 // The function indicates also if the path is exactly the same as the dir.
mp-wp_genesis 5508 // This function supports path with duplicated '/' like '//', but does not
mp-wp_genesis 5509 // support '.' or '..' statements.
mp-wp_genesis 5510 // Parameters :
mp-wp_genesis 5511 // Return Values :
mp-wp_genesis 5512 // 0 if $p_path is not inside directory $p_dir
mp-wp_genesis 5513 // 1 if $p_path is inside directory $p_dir
mp-wp_genesis 5514 // 2 if $p_path is exactly the same as $p_dir
mp-wp_genesis 5515 // --------------------------------------------------------------------------------
mp-wp_genesis 5516 function PclZipUtilPathInclusion($p_dir, $p_path)
mp-wp_genesis 5517 {
mp-wp_genesis 5518 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'");
mp-wp_genesis 5519 $v_result = 1;
mp-wp_genesis 5520
mp-wp_genesis 5521 // ----- Look for path beginning by ./
mp-wp_genesis 5522 if ( ($p_dir == '.')
mp-wp_genesis 5523 || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
mp-wp_genesis 5524 $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
mp-wp_genesis 5525 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'");
mp-wp_genesis 5526 }
mp-wp_genesis 5527 if ( ($p_path == '.')
mp-wp_genesis 5528 || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
mp-wp_genesis 5529 $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
mp-wp_genesis 5530 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'");
mp-wp_genesis 5531 }
mp-wp_genesis 5532
mp-wp_genesis 5533 // ----- Explode dir and path by directory separator
mp-wp_genesis 5534 $v_list_dir = explode("/", $p_dir);
mp-wp_genesis 5535 $v_list_dir_size = sizeof($v_list_dir);
mp-wp_genesis 5536 $v_list_path = explode("/", $p_path);
mp-wp_genesis 5537 $v_list_path_size = sizeof($v_list_path);
mp-wp_genesis 5538
mp-wp_genesis 5539 // ----- Study directories paths
mp-wp_genesis 5540 $i = 0;
mp-wp_genesis 5541 $j = 0;
mp-wp_genesis 5542 while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
mp-wp_genesis 5543 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'");
mp-wp_genesis 5544
mp-wp_genesis 5545 // ----- Look for empty dir (path reduction)
mp-wp_genesis 5546 if ($v_list_dir[$i] == '') {
mp-wp_genesis 5547 $i++;
mp-wp_genesis 5548 continue;
mp-wp_genesis 5549 }
mp-wp_genesis 5550 if ($v_list_path[$j] == '') {
mp-wp_genesis 5551 $j++;
mp-wp_genesis 5552 continue;
mp-wp_genesis 5553 }
mp-wp_genesis 5554
mp-wp_genesis 5555 // ----- Compare the items
mp-wp_genesis 5556 if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
mp-wp_genesis 5557 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different");
mp-wp_genesis 5558 $v_result = 0;
mp-wp_genesis 5559 }
mp-wp_genesis 5560
mp-wp_genesis 5561 // ----- Next items
mp-wp_genesis 5562 $i++;
mp-wp_genesis 5563 $j++;
mp-wp_genesis 5564 }
mp-wp_genesis 5565
mp-wp_genesis 5566 // ----- Look if everything seems to be the same
mp-wp_genesis 5567 if ($v_result) {
mp-wp_genesis 5568 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break");
mp-wp_genesis 5569 // ----- Skip all the empty items
mp-wp_genesis 5570 while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
mp-wp_genesis 5571 while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
mp-wp_genesis 5572 //--(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]:'')."'");
mp-wp_genesis 5573
mp-wp_genesis 5574 if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
mp-wp_genesis 5575 // ----- There are exactly the same
mp-wp_genesis 5576 $v_result = 2;
mp-wp_genesis 5577 }
mp-wp_genesis 5578 else if ($i < $v_list_dir_size) {
mp-wp_genesis 5579 // ----- The path is shorter than the dir
mp-wp_genesis 5580 $v_result = 0;
mp-wp_genesis 5581 }
mp-wp_genesis 5582 }
mp-wp_genesis 5583
mp-wp_genesis 5584 // ----- Return
mp-wp_genesis 5585 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5586 return $v_result;
mp-wp_genesis 5587 }
mp-wp_genesis 5588 // --------------------------------------------------------------------------------
mp-wp_genesis 5589
mp-wp_genesis 5590 // --------------------------------------------------------------------------------
mp-wp_genesis 5591 // Function : PclZipUtilCopyBlock()
mp-wp_genesis 5592 // Description :
mp-wp_genesis 5593 // Parameters :
mp-wp_genesis 5594 // $p_mode : read/write compression mode
mp-wp_genesis 5595 // 0 : src & dest normal
mp-wp_genesis 5596 // 1 : src gzip, dest normal
mp-wp_genesis 5597 // 2 : src normal, dest gzip
mp-wp_genesis 5598 // 3 : src & dest gzip
mp-wp_genesis 5599 // Return Values :
mp-wp_genesis 5600 // --------------------------------------------------------------------------------
mp-wp_genesis 5601 function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
mp-wp_genesis 5602 {
mp-wp_genesis 5603 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode");
mp-wp_genesis 5604 $v_result = 1;
mp-wp_genesis 5605
mp-wp_genesis 5606 if ($p_mode==0)
mp-wp_genesis 5607 {
mp-wp_genesis 5608 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src)));
mp-wp_genesis 5609 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest)));
mp-wp_genesis 5610 while ($p_size != 0)
mp-wp_genesis 5611 {
mp-wp_genesis 5612 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5613 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 5614 $v_buffer = @fread($p_src, $v_read_size);
mp-wp_genesis 5615 @fwrite($p_dest, $v_buffer, $v_read_size);
mp-wp_genesis 5616 $p_size -= $v_read_size;
mp-wp_genesis 5617 }
mp-wp_genesis 5618 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src)));
mp-wp_genesis 5619 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest)));
mp-wp_genesis 5620 }
mp-wp_genesis 5621 else if ($p_mode==1)
mp-wp_genesis 5622 {
mp-wp_genesis 5623 while ($p_size != 0)
mp-wp_genesis 5624 {
mp-wp_genesis 5625 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5626 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 5627 $v_buffer = @gzread($p_src, $v_read_size);
mp-wp_genesis 5628 @fwrite($p_dest, $v_buffer, $v_read_size);
mp-wp_genesis 5629 $p_size -= $v_read_size;
mp-wp_genesis 5630 }
mp-wp_genesis 5631 }
mp-wp_genesis 5632 else if ($p_mode==2)
mp-wp_genesis 5633 {
mp-wp_genesis 5634 while ($p_size != 0)
mp-wp_genesis 5635 {
mp-wp_genesis 5636 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5637 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 5638 $v_buffer = @fread($p_src, $v_read_size);
mp-wp_genesis 5639 @gzwrite($p_dest, $v_buffer, $v_read_size);
mp-wp_genesis 5640 $p_size -= $v_read_size;
mp-wp_genesis 5641 }
mp-wp_genesis 5642 }
mp-wp_genesis 5643 else if ($p_mode==3)
mp-wp_genesis 5644 {
mp-wp_genesis 5645 while ($p_size != 0)
mp-wp_genesis 5646 {
mp-wp_genesis 5647 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
mp-wp_genesis 5648 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
mp-wp_genesis 5649 $v_buffer = @gzread($p_src, $v_read_size);
mp-wp_genesis 5650 @gzwrite($p_dest, $v_buffer, $v_read_size);
mp-wp_genesis 5651 $p_size -= $v_read_size;
mp-wp_genesis 5652 }
mp-wp_genesis 5653 }
mp-wp_genesis 5654
mp-wp_genesis 5655 // ----- Return
mp-wp_genesis 5656 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5657 return $v_result;
mp-wp_genesis 5658 }
mp-wp_genesis 5659 // --------------------------------------------------------------------------------
mp-wp_genesis 5660
mp-wp_genesis 5661 // --------------------------------------------------------------------------------
mp-wp_genesis 5662 // Function : PclZipUtilRename()
mp-wp_genesis 5663 // Description :
mp-wp_genesis 5664 // This function tries to do a simple rename() function. If it fails, it
mp-wp_genesis 5665 // tries to copy the $p_src file in a new $p_dest file and then unlink the
mp-wp_genesis 5666 // first one.
mp-wp_genesis 5667 // Parameters :
mp-wp_genesis 5668 // $p_src : Old filename
mp-wp_genesis 5669 // $p_dest : New filename
mp-wp_genesis 5670 // Return Values :
mp-wp_genesis 5671 // 1 on success, 0 on failure.
mp-wp_genesis 5672 // --------------------------------------------------------------------------------
mp-wp_genesis 5673 function PclZipUtilRename($p_src, $p_dest)
mp-wp_genesis 5674 {
mp-wp_genesis 5675 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest");
mp-wp_genesis 5676 $v_result = 1;
mp-wp_genesis 5677
mp-wp_genesis 5678 // ----- Try to rename the files
mp-wp_genesis 5679 if (!@rename($p_src, $p_dest)) {
mp-wp_genesis 5680 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink");
mp-wp_genesis 5681
mp-wp_genesis 5682 // ----- Try to copy & unlink the src
mp-wp_genesis 5683 if (!@copy($p_src, $p_dest)) {
mp-wp_genesis 5684 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file");
mp-wp_genesis 5685 $v_result = 0;
mp-wp_genesis 5686 }
mp-wp_genesis 5687 else if (!@unlink($p_src)) {
mp-wp_genesis 5688 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename");
mp-wp_genesis 5689 $v_result = 0;
mp-wp_genesis 5690 }
mp-wp_genesis 5691 }
mp-wp_genesis 5692
mp-wp_genesis 5693 // ----- Return
mp-wp_genesis 5694 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5695 return $v_result;
mp-wp_genesis 5696 }
mp-wp_genesis 5697 // --------------------------------------------------------------------------------
mp-wp_genesis 5698
mp-wp_genesis 5699 // --------------------------------------------------------------------------------
mp-wp_genesis 5700 // Function : PclZipUtilOptionText()
mp-wp_genesis 5701 // Description :
mp-wp_genesis 5702 // Translate option value in text. Mainly for debug purpose.
mp-wp_genesis 5703 // Parameters :
mp-wp_genesis 5704 // $p_option : the option value.
mp-wp_genesis 5705 // Return Values :
mp-wp_genesis 5706 // The option text value.
mp-wp_genesis 5707 // --------------------------------------------------------------------------------
mp-wp_genesis 5708 function PclZipUtilOptionText($p_option)
mp-wp_genesis 5709 {
mp-wp_genesis 5710 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'");
mp-wp_genesis 5711
mp-wp_genesis 5712 $v_list = get_defined_constants();
mp-wp_genesis 5713 for (reset($v_list); $v_key = key($v_list); next($v_list)) {
mp-wp_genesis 5714 $v_prefix = substr($v_key, 0, 10);
mp-wp_genesis 5715 if (( ($v_prefix == 'PCLZIP_OPT')
mp-wp_genesis 5716 || ($v_prefix == 'PCLZIP_CB_')
mp-wp_genesis 5717 || ($v_prefix == 'PCLZIP_ATT'))
mp-wp_genesis 5718 && ($v_list[$v_key] == $p_option)) {
mp-wp_genesis 5719 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key);
mp-wp_genesis 5720 return $v_key;
mp-wp_genesis 5721 }
mp-wp_genesis 5722 }
mp-wp_genesis 5723
mp-wp_genesis 5724 $v_result = 'Unknown';
mp-wp_genesis 5725
mp-wp_genesis 5726 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
mp-wp_genesis 5727 return $v_result;
mp-wp_genesis 5728 }
mp-wp_genesis 5729 // --------------------------------------------------------------------------------
mp-wp_genesis 5730
mp-wp_genesis 5731 // --------------------------------------------------------------------------------
mp-wp_genesis 5732 // Function : PclZipUtilTranslateWinPath()
mp-wp_genesis 5733 // Description :
mp-wp_genesis 5734 // Translate windows path by replacing '\' by '/' and optionally removing
mp-wp_genesis 5735 // drive letter.
mp-wp_genesis 5736 // Parameters :
mp-wp_genesis 5737 // $p_path : path to translate.
mp-wp_genesis 5738 // $p_remove_disk_letter : true | false
mp-wp_genesis 5739 // Return Values :
mp-wp_genesis 5740 // The path translated.
mp-wp_genesis 5741 // --------------------------------------------------------------------------------
mp-wp_genesis 5742 function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
mp-wp_genesis 5743 {
mp-wp_genesis 5744 if (stristr(php_uname(), 'windows')) {
mp-wp_genesis 5745 // ----- Look for potential disk letter
mp-wp_genesis 5746 if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
mp-wp_genesis 5747 $p_path = substr($p_path, $v_position+1);
mp-wp_genesis 5748 }
mp-wp_genesis 5749 // ----- Change potential windows directory separator
mp-wp_genesis 5750 if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
mp-wp_genesis 5751 $p_path = strtr($p_path, '\\', '/');
mp-wp_genesis 5752 }
mp-wp_genesis 5753 }
mp-wp_genesis 5754 return $p_path;
mp-wp_genesis 5755 }
mp-wp_genesis 5756 // --------------------------------------------------------------------------------
mp-wp_genesis 5757
mp-wp_genesis 5758
mp-wp_genesis 5759 ?>