PageRenderTime 103ms CodeModel.GetById 19ms app.highlight 62ms RepoModel.GetById 1ms app.codeStats 2ms

/wp-admin/includes/class-pclzip.php

https://bitbucket.org/devbctph/futura_wp
PHP | 5692 lines | 2956 code | 916 blank | 1820 comment | 956 complexity | 59c701d09896cf859689dcf457597084 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2// --------------------------------------------------------------------------------
   3// PhpConcept Library - Zip Module 2.8.2
   4// --------------------------------------------------------------------------------
   5// License GNU/LGPL - Vincent Blavet - August 2009
   6// http://www.phpconcept.net
   7// --------------------------------------------------------------------------------
   8//
   9// Presentation :
  10//   PclZip is a PHP library that manage ZIP archives.
  11//   So far tests show that archives generated by PclZip are readable by
  12//   WinZip application and other tools.
  13//
  14// Description :
  15//   See readme.txt and http://www.phpconcept.net
  16//
  17// Warning :
  18//   This library and the associated files are non commercial, non professional
  19//   work.
  20//   It should not have unexpected results. However if any damage is caused by
  21//   this software the author can not be responsible.
  22//   The use of this software is at the risk of the user.
  23//
  24// --------------------------------------------------------------------------------
  25// $Id: pclzip.lib.php,v 1.60 2009/09/30 21:01:04 vblavet Exp $
  26// --------------------------------------------------------------------------------
  27
  28  // ----- Constants
  29  if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
  30    define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
  31  }
  32
  33  // ----- File list separator
  34  // In version 1.x of PclZip, the separator for file list is a space
  35  // (which is not a very smart choice, specifically for windows paths !).
  36  // A better separator should be a comma (,). This constant gives you the
  37  // abilty to change that.
  38  // However notice that changing this value, may have impact on existing
  39  // scripts, using space separated filenames.
  40  // Recommanded values for compatibility with older versions :
  41  //define( 'PCLZIP_SEPARATOR', ' ' );
  42  // Recommanded values for smart separation of filenames.
  43  if (!defined('PCLZIP_SEPARATOR')) {
  44    define( 'PCLZIP_SEPARATOR', ',' );
  45  }
  46
  47  // ----- Error configuration
  48  // 0 : PclZip Class integrated error handling
  49  // 1 : PclError external library error handling. By enabling this
  50  //     you must ensure that you have included PclError library.
  51  // [2,...] : reserved for futur use
  52  if (!defined('PCLZIP_ERROR_EXTERNAL')) {
  53    define( 'PCLZIP_ERROR_EXTERNAL', 0 );
  54  }
  55
  56  // ----- Optional static temporary directory
  57  //       By default temporary files are generated in the script current
  58  //       path.
  59  //       If defined :
  60  //       - MUST BE terminated by a '/'.
  61  //       - MUST be a valid, already created directory
  62  //       Samples :
  63  // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
  64  // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
  65  if (!defined('PCLZIP_TEMPORARY_DIR')) {
  66    define( 'PCLZIP_TEMPORARY_DIR', '' );
  67  }
  68
  69  // ----- Optional threshold ratio for use of temporary files
  70  //       Pclzip sense the size of the file to add/extract and decide to
  71  //       use or not temporary file. The algorythm is looking for
  72  //       memory_limit of PHP and apply a ratio.
  73  //       threshold = memory_limit * ratio.
  74  //       Recommended values are under 0.5. Default 0.47.
  75  //       Samples :
  76  // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 );
  77  if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
  78    define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
  79  }
  80
  81// --------------------------------------------------------------------------------
  82// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
  83// --------------------------------------------------------------------------------
  84
  85  // ----- Global variables
  86  $g_pclzip_version = "2.8.2";
  87
  88  // ----- Error codes
  89  //   -1 : Unable to open file in binary write mode
  90  //   -2 : Unable to open file in binary read mode
  91  //   -3 : Invalid parameters
  92  //   -4 : File does not exist
  93  //   -5 : Filename is too long (max. 255)
  94  //   -6 : Not a valid zip file
  95  //   -7 : Invalid extracted file size
  96  //   -8 : Unable to create directory
  97  //   -9 : Invalid archive extension
  98  //  -10 : Invalid archive format
  99  //  -11 : Unable to delete file (unlink)
 100  //  -12 : Unable to rename file (rename)
 101  //  -13 : Invalid header checksum
 102  //  -14 : Invalid archive size
 103  define( 'PCLZIP_ERR_USER_ABORTED', 2 );
 104  define( 'PCLZIP_ERR_NO_ERROR', 0 );
 105  define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
 106  define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
 107  define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
 108  define( 'PCLZIP_ERR_MISSING_FILE', -4 );
 109  define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
 110  define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
 111  define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
 112  define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
 113  define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
 114  define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
 115  define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
 116  define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
 117  define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
 118  define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
 119  define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
 120  define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
 121  define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
 122  define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
 123  define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
 124  define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
 125  define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
 126
 127  // ----- Options values
 128  define( 'PCLZIP_OPT_PATH', 77001 );
 129  define( 'PCLZIP_OPT_ADD_PATH', 77002 );
 130  define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
 131  define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
 132  define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
 133  define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
 134  define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
 135  define( 'PCLZIP_OPT_BY_NAME', 77008 );
 136  define( 'PCLZIP_OPT_BY_INDEX', 77009 );
 137  define( 'PCLZIP_OPT_BY_EREG', 77010 );
 138  define( 'PCLZIP_OPT_BY_PREG', 77011 );
 139  define( 'PCLZIP_OPT_COMMENT', 77012 );
 140  define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
 141  define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
 142  define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
 143  define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
 144  define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
 145  // Having big trouble with crypt. Need to multiply 2 long int
 146  // which is not correctly supported by PHP ...
 147  //define( 'PCLZIP_OPT_CRYPT', 77018 );
 148  define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
 149  define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
 150  define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias
 151  define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
 152  define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias
 153  define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
 154  define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias
 155
 156  // ----- File description attributes
 157  define( 'PCLZIP_ATT_FILE_NAME', 79001 );
 158  define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
 159  define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
 160  define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
 161  define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
 162  define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
 163
 164  // ----- Call backs values
 165  define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
 166  define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
 167  define( 'PCLZIP_CB_PRE_ADD', 78003 );
 168  define( 'PCLZIP_CB_POST_ADD', 78004 );
 169  /* For futur use
 170  define( 'PCLZIP_CB_PRE_LIST', 78005 );
 171  define( 'PCLZIP_CB_POST_LIST', 78006 );
 172  define( 'PCLZIP_CB_PRE_DELETE', 78007 );
 173  define( 'PCLZIP_CB_POST_DELETE', 78008 );
 174  */
 175
 176  // --------------------------------------------------------------------------------
 177  // Class : PclZip
 178  // Description :
 179  //   PclZip is the class that represent a Zip archive.
 180  //   The public methods allow the manipulation of the archive.
 181  // Attributes :
 182  //   Attributes must not be accessed directly.
 183  // Methods :
 184  //   PclZip() : Object creator
 185  //   create() : Creates the Zip archive
 186  //   listContent() : List the content of the Zip archive
 187  //   extract() : Extract the content of the archive
 188  //   properties() : List the properties of the archive
 189  // --------------------------------------------------------------------------------
 190  class PclZip
 191  {
 192    // ----- Filename of the zip file
 193    var $zipname = '';
 194
 195    // ----- File descriptor of the zip file
 196    var $zip_fd = 0;
 197
 198    // ----- Internal error handling
 199    var $error_code = 1;
 200    var $error_string = '';
 201
 202    // ----- Current status of the magic_quotes_runtime
 203    // This value store the php configuration for magic_quotes
 204    // The class can then disable the magic_quotes and reset it after
 205    var $magic_quotes_status;
 206
 207  // --------------------------------------------------------------------------------
 208  // Function : PclZip()
 209  // Description :
 210  //   Creates a PclZip object and set the name of the associated Zip archive
 211  //   filename.
 212  //   Note that no real action is taken, if the archive does not exist it is not
 213  //   created. Use create() for that.
 214  // --------------------------------------------------------------------------------
 215  function __construct($p_zipname)
 216  {
 217
 218    // ----- Tests the zlib
 219    if (!function_exists('gzopen'))
 220    {
 221      die('Abort '.basename(__FILE__).' : Missing zlib extensions');
 222    }
 223
 224    // ----- Set the attributes
 225    $this->zipname = $p_zipname;
 226    $this->zip_fd = 0;
 227    $this->magic_quotes_status = -1;
 228
 229    // ----- Return
 230    return;
 231  }
 232
 233  public function PclZip($p_zipname) {
 234    self::__construct($p_zipname);
 235  }
 236  // --------------------------------------------------------------------------------
 237
 238  // --------------------------------------------------------------------------------
 239  // Function :
 240  //   create($p_filelist, $p_add_dir="", $p_remove_dir="")
 241  //   create($p_filelist, $p_option, $p_option_value, ...)
 242  // Description :
 243  //   This method supports two different synopsis. The first one is historical.
 244  //   This method creates a Zip Archive. The Zip file is created in the
 245  //   filesystem. The files and directories indicated in $p_filelist
 246  //   are added in the archive. See the parameters description for the
 247  //   supported format of $p_filelist.
 248  //   When a directory is in the list, the directory and its content is added
 249  //   in the archive.
 250  //   In this synopsis, the function takes an optional variable list of
 251  //   options. See bellow the supported options.
 252  // Parameters :
 253  //   $p_filelist : An array containing file or directory names, or
 254  //                 a string containing one filename or one directory name, or
 255  //                 a string containing a list of filenames and/or directory
 256  //                 names separated by spaces.
 257  //   $p_add_dir : A path to add before the real path of the archived file,
 258  //                in order to have it memorized in the archive.
 259  //   $p_remove_dir : A path to remove from the real path of the file to archive,
 260  //                   in order to have a shorter path memorized in the archive.
 261  //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
 262  //                   is removed first, before $p_add_dir is added.
 263  // Options :
 264  //   PCLZIP_OPT_ADD_PATH :
 265  //   PCLZIP_OPT_REMOVE_PATH :
 266  //   PCLZIP_OPT_REMOVE_ALL_PATH :
 267  //   PCLZIP_OPT_COMMENT :
 268  //   PCLZIP_CB_PRE_ADD :
 269  //   PCLZIP_CB_POST_ADD :
 270  // Return Values :
 271  //   0 on failure,
 272  //   The list of the added files, with a status of the add action.
 273  //   (see PclZip::listContent() for list entry format)
 274  // --------------------------------------------------------------------------------
 275  function create($p_filelist)
 276  {
 277    $v_result=1;
 278
 279    // ----- Reset the error handler
 280    $this->privErrorReset();
 281
 282    // ----- Set default values
 283    $v_options = array();
 284    $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
 285
 286    // ----- Look for variable options arguments
 287    $v_size = func_num_args();
 288
 289    // ----- Look for arguments
 290    if ($v_size > 1) {
 291      // ----- Get the arguments
 292      $v_arg_list = func_get_args();
 293
 294      // ----- Remove from the options list the first argument
 295      array_shift($v_arg_list);
 296      $v_size--;
 297
 298      // ----- Look for first arg
 299      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 300
 301        // ----- Parse the options
 302        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 303                                            array (PCLZIP_OPT_REMOVE_PATH => 'optional',
 304                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 305                                                   PCLZIP_OPT_ADD_PATH => 'optional',
 306                                                   PCLZIP_CB_PRE_ADD => 'optional',
 307                                                   PCLZIP_CB_POST_ADD => 'optional',
 308                                                   PCLZIP_OPT_NO_COMPRESSION => 'optional',
 309                                                   PCLZIP_OPT_COMMENT => 'optional',
 310                                                   PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 311                                                   PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 312                                                   PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 313                                                   //, PCLZIP_OPT_CRYPT => 'optional'
 314                                             ));
 315        if ($v_result != 1) {
 316          return 0;
 317        }
 318      }
 319
 320      // ----- Look for 2 args
 321      // Here we need to support the first historic synopsis of the
 322      // method.
 323      else {
 324
 325        // ----- Get the first argument
 326        $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
 327
 328        // ----- Look for the optional second argument
 329        if ($v_size == 2) {
 330          $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
 331        }
 332        else if ($v_size > 2) {
 333          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
 334		                       "Invalid number / type of arguments");
 335          return 0;
 336        }
 337      }
 338    }
 339
 340    // ----- Look for default option values
 341    $this->privOptionDefaultThreshold($v_options);
 342
 343    // ----- Init
 344    $v_string_list = array();
 345    $v_att_list = array();
 346    $v_filedescr_list = array();
 347    $p_result_list = array();
 348
 349    // ----- Look if the $p_filelist is really an array
 350    if (is_array($p_filelist)) {
 351
 352      // ----- Look if the first element is also an array
 353      //       This will mean that this is a file description entry
 354      if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
 355        $v_att_list = $p_filelist;
 356      }
 357
 358      // ----- The list is a list of string names
 359      else {
 360        $v_string_list = $p_filelist;
 361      }
 362    }
 363
 364    // ----- Look if the $p_filelist is a string
 365    else if (is_string($p_filelist)) {
 366      // ----- Create a list from the string
 367      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
 368    }
 369
 370    // ----- Invalid variable type for $p_filelist
 371    else {
 372      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
 373      return 0;
 374    }
 375
 376    // ----- Reformat the string list
 377    if (sizeof($v_string_list) != 0) {
 378      foreach ($v_string_list as $v_string) {
 379        if ($v_string != '') {
 380          $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
 381        }
 382        else {
 383        }
 384      }
 385    }
 386
 387    // ----- For each file in the list check the attributes
 388    $v_supported_attributes
 389    = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
 390             ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
 391             ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
 392             ,PCLZIP_ATT_FILE_MTIME => 'optional'
 393             ,PCLZIP_ATT_FILE_CONTENT => 'optional'
 394             ,PCLZIP_ATT_FILE_COMMENT => 'optional'
 395						);
 396    foreach ($v_att_list as $v_entry) {
 397      $v_result = $this->privFileDescrParseAtt($v_entry,
 398                                               $v_filedescr_list[],
 399                                               $v_options,
 400                                               $v_supported_attributes);
 401      if ($v_result != 1) {
 402        return 0;
 403      }
 404    }
 405
 406    // ----- Expand the filelist (expand directories)
 407    $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
 408    if ($v_result != 1) {
 409      return 0;
 410    }
 411
 412    // ----- Call the create fct
 413    $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
 414    if ($v_result != 1) {
 415      return 0;
 416    }
 417
 418    // ----- Return
 419    return $p_result_list;
 420  }
 421  // --------------------------------------------------------------------------------
 422
 423  // --------------------------------------------------------------------------------
 424  // Function :
 425  //   add($p_filelist, $p_add_dir="", $p_remove_dir="")
 426  //   add($p_filelist, $p_option, $p_option_value, ...)
 427  // Description :
 428  //   This method supports two synopsis. The first one is historical.
 429  //   This methods add the list of files in an existing archive.
 430  //   If a file with the same name already exists, it is added at the end of the
 431  //   archive, the first one is still present.
 432  //   If the archive does not exist, it is created.
 433  // Parameters :
 434  //   $p_filelist : An array containing file or directory names, or
 435  //                 a string containing one filename or one directory name, or
 436  //                 a string containing a list of filenames and/or directory
 437  //                 names separated by spaces.
 438  //   $p_add_dir : A path to add before the real path of the archived file,
 439  //                in order to have it memorized in the archive.
 440  //   $p_remove_dir : A path to remove from the real path of the file to archive,
 441  //                   in order to have a shorter path memorized in the archive.
 442  //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
 443  //                   is removed first, before $p_add_dir is added.
 444  // Options :
 445  //   PCLZIP_OPT_ADD_PATH :
 446  //   PCLZIP_OPT_REMOVE_PATH :
 447  //   PCLZIP_OPT_REMOVE_ALL_PATH :
 448  //   PCLZIP_OPT_COMMENT :
 449  //   PCLZIP_OPT_ADD_COMMENT :
 450  //   PCLZIP_OPT_PREPEND_COMMENT :
 451  //   PCLZIP_CB_PRE_ADD :
 452  //   PCLZIP_CB_POST_ADD :
 453  // Return Values :
 454  //   0 on failure,
 455  //   The list of the added files, with a status of the add action.
 456  //   (see PclZip::listContent() for list entry format)
 457  // --------------------------------------------------------------------------------
 458  function add($p_filelist)
 459  {
 460    $v_result=1;
 461
 462    // ----- Reset the error handler
 463    $this->privErrorReset();
 464
 465    // ----- Set default values
 466    $v_options = array();
 467    $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
 468
 469    // ----- Look for variable options arguments
 470    $v_size = func_num_args();
 471
 472    // ----- Look for arguments
 473    if ($v_size > 1) {
 474      // ----- Get the arguments
 475      $v_arg_list = func_get_args();
 476
 477      // ----- Remove form the options list the first argument
 478      array_shift($v_arg_list);
 479      $v_size--;
 480
 481      // ----- Look for first arg
 482      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 483
 484        // ----- Parse the options
 485        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 486                                            array (PCLZIP_OPT_REMOVE_PATH => 'optional',
 487                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 488                                                   PCLZIP_OPT_ADD_PATH => 'optional',
 489                                                   PCLZIP_CB_PRE_ADD => 'optional',
 490                                                   PCLZIP_CB_POST_ADD => 'optional',
 491                                                   PCLZIP_OPT_NO_COMPRESSION => 'optional',
 492                                                   PCLZIP_OPT_COMMENT => 'optional',
 493                                                   PCLZIP_OPT_ADD_COMMENT => 'optional',
 494                                                   PCLZIP_OPT_PREPEND_COMMENT => 'optional',
 495                                                   PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 496                                                   PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 497                                                   PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 498                                                   //, PCLZIP_OPT_CRYPT => 'optional'
 499												   ));
 500        if ($v_result != 1) {
 501          return 0;
 502        }
 503      }
 504
 505      // ----- Look for 2 args
 506      // Here we need to support the first historic synopsis of the
 507      // method.
 508      else {
 509
 510        // ----- Get the first argument
 511        $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
 512
 513        // ----- Look for the optional second argument
 514        if ($v_size == 2) {
 515          $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
 516        }
 517        else if ($v_size > 2) {
 518          // ----- Error log
 519          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 520
 521          // ----- Return
 522          return 0;
 523        }
 524      }
 525    }
 526
 527    // ----- Look for default option values
 528    $this->privOptionDefaultThreshold($v_options);
 529
 530    // ----- Init
 531    $v_string_list = array();
 532    $v_att_list = array();
 533    $v_filedescr_list = array();
 534    $p_result_list = array();
 535
 536    // ----- Look if the $p_filelist is really an array
 537    if (is_array($p_filelist)) {
 538
 539      // ----- Look if the first element is also an array
 540      //       This will mean that this is a file description entry
 541      if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
 542        $v_att_list = $p_filelist;
 543      }
 544
 545      // ----- The list is a list of string names
 546      else {
 547        $v_string_list = $p_filelist;
 548      }
 549    }
 550
 551    // ----- Look if the $p_filelist is a string
 552    else if (is_string($p_filelist)) {
 553      // ----- Create a list from the string
 554      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
 555    }
 556
 557    // ----- Invalid variable type for $p_filelist
 558    else {
 559      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
 560      return 0;
 561    }
 562
 563    // ----- Reformat the string list
 564    if (sizeof($v_string_list) != 0) {
 565      foreach ($v_string_list as $v_string) {
 566        $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
 567      }
 568    }
 569
 570    // ----- For each file in the list check the attributes
 571    $v_supported_attributes
 572    = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
 573             ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
 574             ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
 575             ,PCLZIP_ATT_FILE_MTIME => 'optional'
 576             ,PCLZIP_ATT_FILE_CONTENT => 'optional'
 577             ,PCLZIP_ATT_FILE_COMMENT => 'optional'
 578						);
 579    foreach ($v_att_list as $v_entry) {
 580      $v_result = $this->privFileDescrParseAtt($v_entry,
 581                                               $v_filedescr_list[],
 582                                               $v_options,
 583                                               $v_supported_attributes);
 584      if ($v_result != 1) {
 585        return 0;
 586      }
 587    }
 588
 589    // ----- Expand the filelist (expand directories)
 590    $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
 591    if ($v_result != 1) {
 592      return 0;
 593    }
 594
 595    // ----- Call the create fct
 596    $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
 597    if ($v_result != 1) {
 598      return 0;
 599    }
 600
 601    // ----- Return
 602    return $p_result_list;
 603  }
 604  // --------------------------------------------------------------------------------
 605
 606  // --------------------------------------------------------------------------------
 607  // Function : listContent()
 608  // Description :
 609  //   This public method, gives the list of the files and directories, with their
 610  //   properties.
 611  //   The properties of each entries in the list are (used also in other functions) :
 612  //     filename : Name of the file. For a create or add action it is the filename
 613  //                given by the user. For an extract function it is the filename
 614  //                of the extracted file.
 615  //     stored_filename : Name of the file / directory stored in the archive.
 616  //     size : Size of the stored file.
 617  //     compressed_size : Size of the file's data compressed in the archive
 618  //                       (without the headers overhead)
 619  //     mtime : Last known modification date of the file (UNIX timestamp)
 620  //     comment : Comment associated with the file
 621  //     folder : true | false
 622  //     index : index of the file in the archive
 623  //     status : status of the action (depending of the action) :
 624  //              Values are :
 625  //                ok : OK !
 626  //                filtered : the file / dir is not extracted (filtered by user)
 627  //                already_a_directory : the file can not be extracted because a
 628  //                                      directory with the same name already exists
 629  //                write_protected : the file can not be extracted because a file
 630  //                                  with the same name already exists and is
 631  //                                  write protected
 632  //                newer_exist : the file was not extracted because a newer file exists
 633  //                path_creation_fail : the file is not extracted because the folder
 634  //                                     does not exist and can not be created
 635  //                write_error : the file was not extracted because there was a
 636  //                              error while writing the file
 637  //                read_error : the file was not extracted because there was a error
 638  //                             while reading the file
 639  //                invalid_header : the file was not extracted because of an archive
 640  //                                 format error (bad file header)
 641  //   Note that each time a method can continue operating when there
 642  //   is an action error on a file, the error is only logged in the file status.
 643  // Return Values :
 644  //   0 on an unrecoverable failure,
 645  //   The list of the files in the archive.
 646  // --------------------------------------------------------------------------------
 647  function listContent()
 648  {
 649    $v_result=1;
 650
 651    // ----- Reset the error handler
 652    $this->privErrorReset();
 653
 654    // ----- Check archive
 655    if (!$this->privCheckFormat()) {
 656      return(0);
 657    }
 658
 659    // ----- Call the extracting fct
 660    $p_list = array();
 661    if (($v_result = $this->privList($p_list)) != 1)
 662    {
 663      unset($p_list);
 664      return(0);
 665    }
 666
 667    // ----- Return
 668    return $p_list;
 669  }
 670  // --------------------------------------------------------------------------------
 671
 672  // --------------------------------------------------------------------------------
 673  // Function :
 674  //   extract($p_path="./", $p_remove_path="")
 675  //   extract([$p_option, $p_option_value, ...])
 676  // Description :
 677  //   This method supports two synopsis. The first one is historical.
 678  //   This method extract all the files / directories from the archive to the
 679  //   folder indicated in $p_path.
 680  //   If you want to ignore the 'root' part of path of the memorized files
 681  //   you can indicate this in the optional $p_remove_path parameter.
 682  //   By default, if a newer file with the same name already exists, the
 683  //   file is not extracted.
 684  //
 685  //   If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
 686  //   are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
 687  //   at the end of the path value of PCLZIP_OPT_PATH.
 688  // Parameters :
 689  //   $p_path : Path where the files and directories are to be extracted
 690  //   $p_remove_path : First part ('root' part) of the memorized path
 691  //                    (if any similar) to remove while extracting.
 692  // Options :
 693  //   PCLZIP_OPT_PATH :
 694  //   PCLZIP_OPT_ADD_PATH :
 695  //   PCLZIP_OPT_REMOVE_PATH :
 696  //   PCLZIP_OPT_REMOVE_ALL_PATH :
 697  //   PCLZIP_CB_PRE_EXTRACT :
 698  //   PCLZIP_CB_POST_EXTRACT :
 699  // Return Values :
 700  //   0 or a negative value on failure,
 701  //   The list of the extracted files, with a status of the action.
 702  //   (see PclZip::listContent() for list entry format)
 703  // --------------------------------------------------------------------------------
 704  function extract()
 705  {
 706    $v_result=1;
 707
 708    // ----- Reset the error handler
 709    $this->privErrorReset();
 710
 711    // ----- Check archive
 712    if (!$this->privCheckFormat()) {
 713      return(0);
 714    }
 715
 716    // ----- Set default values
 717    $v_options = array();
 718//    $v_path = "./";
 719    $v_path = '';
 720    $v_remove_path = "";
 721    $v_remove_all_path = false;
 722
 723    // ----- Look for variable options arguments
 724    $v_size = func_num_args();
 725
 726    // ----- Default values for option
 727    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 728
 729    // ----- Look for arguments
 730    if ($v_size > 0) {
 731      // ----- Get the arguments
 732      $v_arg_list = func_get_args();
 733
 734      // ----- Look for first arg
 735      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 736
 737        // ----- Parse the options
 738        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 739                                            array (PCLZIP_OPT_PATH => 'optional',
 740                                                   PCLZIP_OPT_REMOVE_PATH => 'optional',
 741                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 742                                                   PCLZIP_OPT_ADD_PATH => 'optional',
 743                                                   PCLZIP_CB_PRE_EXTRACT => 'optional',
 744                                                   PCLZIP_CB_POST_EXTRACT => 'optional',
 745                                                   PCLZIP_OPT_SET_CHMOD => 'optional',
 746                                                   PCLZIP_OPT_BY_NAME => 'optional',
 747                                                   PCLZIP_OPT_BY_EREG => 'optional',
 748                                                   PCLZIP_OPT_BY_PREG => 'optional',
 749                                                   PCLZIP_OPT_BY_INDEX => 'optional',
 750                                                   PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
 751                                                   PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
 752                                                   PCLZIP_OPT_REPLACE_NEWER => 'optional'
 753                                                   ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
 754                                                   ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
 755                                                   PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 756                                                   PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 757                                                   PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 758												    ));
 759        if ($v_result != 1) {
 760          return 0;
 761        }
 762
 763        // ----- Set the arguments
 764        if (isset($v_options[PCLZIP_OPT_PATH])) {
 765          $v_path = $v_options[PCLZIP_OPT_PATH];
 766        }
 767        if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
 768          $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
 769        }
 770        if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 771          $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 772        }
 773        if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
 774          // ----- Check for '/' in last path char
 775          if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
 776            $v_path .= '/';
 777          }
 778          $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
 779        }
 780      }
 781
 782      // ----- Look for 2 args
 783      // Here we need to support the first historic synopsis of the
 784      // method.
 785      else {
 786
 787        // ----- Get the first argument
 788        $v_path = $v_arg_list[0];
 789
 790        // ----- Look for the optional second argument
 791        if ($v_size == 2) {
 792          $v_remove_path = $v_arg_list[1];
 793        }
 794        else if ($v_size > 2) {
 795          // ----- Error log
 796          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 797
 798          // ----- Return
 799          return 0;
 800        }
 801      }
 802    }
 803
 804    // ----- Look for default option values
 805    $this->privOptionDefaultThreshold($v_options);
 806
 807    // ----- Trace
 808
 809    // ----- Call the extracting fct
 810    $p_list = array();
 811    $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
 812	                                     $v_remove_all_path, $v_options);
 813    if ($v_result < 1) {
 814      unset($p_list);
 815      return(0);
 816    }
 817
 818    // ----- Return
 819    return $p_list;
 820  }
 821  // --------------------------------------------------------------------------------
 822
 823
 824  // --------------------------------------------------------------------------------
 825  // Function :
 826  //   extractByIndex($p_index, $p_path="./", $p_remove_path="")
 827  //   extractByIndex($p_index, [$p_option, $p_option_value, ...])
 828  // Description :
 829  //   This method supports two synopsis. The first one is historical.
 830  //   This method is doing a partial extract of the archive.
 831  //   The extracted files or folders are identified by their index in the
 832  //   archive (from 0 to n).
 833  //   Note that if the index identify a folder, only the folder entry is
 834  //   extracted, not all the files included in the archive.
 835  // Parameters :
 836  //   $p_index : A single index (integer) or a string of indexes of files to
 837  //              extract. The form of the string is "0,4-6,8-12" with only numbers
 838  //              and '-' for range or ',' to separate ranges. No spaces or ';'
 839  //              are allowed.
 840  //   $p_path : Path where the files and directories are to be extracted
 841  //   $p_remove_path : First part ('root' part) of the memorized path
 842  //                    (if any similar) to remove while extracting.
 843  // Options :
 844  //   PCLZIP_OPT_PATH :
 845  //   PCLZIP_OPT_ADD_PATH :
 846  //   PCLZIP_OPT_REMOVE_PATH :
 847  //   PCLZIP_OPT_REMOVE_ALL_PATH :
 848  //   PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
 849  //     not as files.
 850  //     The resulting content is in a new field 'content' in the file
 851  //     structure.
 852  //     This option must be used alone (any other options are ignored).
 853  //   PCLZIP_CB_PRE_EXTRACT :
 854  //   PCLZIP_CB_POST_EXTRACT :
 855  // Return Values :
 856  //   0 on failure,
 857  //   The list of the extracted files, with a status of the action.
 858  //   (see PclZip::listContent() for list entry format)
 859  // --------------------------------------------------------------------------------
 860  //function extractByIndex($p_index, options...)
 861  function extractByIndex($p_index)
 862  {
 863    $v_result=1;
 864
 865    // ----- Reset the error handler
 866    $this->privErrorReset();
 867
 868    // ----- Check archive
 869    if (!$this->privCheckFormat()) {
 870      return(0);
 871    }
 872
 873    // ----- Set default values
 874    $v_options = array();
 875//    $v_path = "./";
 876    $v_path = '';
 877    $v_remove_path = "";
 878    $v_remove_all_path = false;
 879
 880    // ----- Look for variable options arguments
 881    $v_size = func_num_args();
 882
 883    // ----- Default values for option
 884    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 885
 886    // ----- Look for arguments
 887    if ($v_size > 1) {
 888      // ----- Get the arguments
 889      $v_arg_list = func_get_args();
 890
 891      // ----- Remove form the options list the first argument
 892      array_shift($v_arg_list);
 893      $v_size--;
 894
 895      // ----- Look for first arg
 896      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 897
 898        // ----- Parse the options
 899        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 900                                            array (PCLZIP_OPT_PATH => 'optional',
 901                                                   PCLZIP_OPT_REMOVE_PATH => 'optional',
 902                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 903                                                   PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
 904                                                   PCLZIP_OPT_ADD_PATH => 'optional',
 905                                                   PCLZIP_CB_PRE_EXTRACT => 'optional',
 906                                                   PCLZIP_CB_POST_EXTRACT => 'optional',
 907                                                   PCLZIP_OPT_SET_CHMOD => 'optional',
 908                                                   PCLZIP_OPT_REPLACE_NEWER => 'optional'
 909                                                   ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
 910                                                   ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
 911                                                   PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 912                                                   PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 913                                                   PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 914												   ));
 915        if ($v_result != 1) {
 916          return 0;
 917        }
 918
 919        // ----- Set the arguments
 920        if (isset($v_options[PCLZIP_OPT_PATH])) {
 921          $v_path = $v_options[PCLZIP_OPT_PATH];
 922        }
 923        if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
 924          $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
 925        }
 926        if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 927          $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 928        }
 929        if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
 930          // ----- Check for '/' in last path char
 931          if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
 932            $v_path .= '/';
 933          }
 934          $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
 935        }
 936        if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
 937          $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 938        }
 939        else {
 940        }
 941      }
 942
 943      // ----- Look for 2 args
 944      // Here we need to support the first historic synopsis of the
 945      // method.
 946      else {
 947
 948        // ----- Get the first argument
 949        $v_path = $v_arg_list[0];
 950
 951        // ----- Look for the optional second argument
 952        if ($v_size == 2) {
 953          $v_remove_path = $v_arg_list[1];
 954        }
 955        else if ($v_size > 2) {
 956          // ----- Error log
 957          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 958
 959          // ----- Return
 960          return 0;
 961        }
 962      }
 963    }
 964
 965    // ----- Trace
 966
 967    // ----- Trick
 968    // Here I want to reuse extractByRule(), so I need to parse the $p_index
 969    // with privParseOptions()
 970    $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
 971    $v_options_trick = array();
 972    $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
 973                                        array (PCLZIP_OPT_BY_INDEX => 'optional' ));
 974    if ($v_result != 1) {
 975        return 0;
 976    }
 977    $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
 978
 979    // ----- Look for default option values
 980    $this->privOptionDefaultThreshold($v_options);
 981
 982    // ----- Call the extracting fct
 983    if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
 984        return(0);
 985    }
 986
 987    // ----- Return
 988    return $p_list;
 989  }
 990  // --------------------------------------------------------------------------------
 991
 992  // --------------------------------------------------------------------------------
 993  // Function :
 994  //   delete([$p_option, $p_option_value, ...])
 995  // Description :
 996  //   This method removes files from the archive.
 997  //   If no parameters are given, then all the archive is emptied.
 998  // Parameters :
 999  //   None or optional arguments.
1000  // Options :
1001  //   PCLZIP_OPT_BY_INDEX :
1002  //   PCLZIP_OPT_BY_NAME :
1003  //   PCLZIP_OPT_BY_EREG :
1004  //   PCLZIP_OPT_BY_PREG :
1005  // Return Values :
1006  //   0 on failure,
1007  //   The list of the files which are still present in the archive.
1008  //   (see PclZip::listContent() for list entry format)
1009  // --------------------------------------------------------------------------------
1010  function delete()
1011  {
1012    $v_result=1;
1013
1014    // ----- Reset the error handler
1015    $this->privErrorReset();
1016
1017    // ----- Check archive
1018    if (!$this->privCheckFormat()) {
1019      return(0);
1020    }
1021
1022    // ----- Set default values
1023    $v_options = array();
1024
1025    // ----- Look for variable options arguments
1026    $v_size = func_num_args();
1027
1028    // ----- Look for arguments
1029    if ($v_size > 0) {
1030      // ----- Get the arguments
1031      $v_arg_list = func_get_args();
1032
1033      // ----- Parse the options
1034      $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
1035                                        array (PCLZIP_OPT_BY_NAME => 'optional',
1036                                               PCLZIP_OPT_BY_EREG => 'optional',
1037                                               PCLZIP_OPT_BY_PREG => 'optional',
1038                                               PCLZIP_OPT_BY_INDEX => 'optional' ));
1039      if ($v_result != 1) {
1040          return 0;
1041      }
1042    }
1043
1044    // ----- Magic quotes trick
1045    $this->privDisableMagicQuotes();
1046
1047    // ----- Call the delete fct
1048    $v_list = array();
1049    if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
1050      $this->privSwapBackMagicQuotes();
1051      unset($v_list);
1052      return(0);
1053    }
1054
1055    // ----- Magic quotes trick
1056    $this->privSwapBackMagicQuotes();
1057
1058    // ----- Return
1059    return $v_list;
1060  }
1061  // --------------------------------------------------------------------------------
1062
1063  // --------------------------------------------------------------------------------
1064  // Function : deleteByIndex()
1065  // Description :
1066  //   ***** Deprecated *****
1067  //   delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
1068  // --------------------------------------------------------------------------------
1069  function deleteByIndex($p_index)
1070  {
1071
1072    $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
1073
1074    // ----- Return
1075    return $p_list;
1076  }
1077  // --------------------------------------------------------------------------------
1078
1079  // --------------------------------------------------------------------------------
1080  // Function : properties()
1081  // Description :
1082  //   This method gives the properties of the archive.
1083  //   The properties are :
1084  //     nb : Number of files in the archive
1085  //     comment : Comment associated with the archive file
1086  //     status : not_exist, ok
1087  // Parameters :
1088  //   None
1089  // Return Values :
1090  //   0 on failure,
1091  //   An array with the archive properties.
1092  // --------------------------------------------------------------------------------
1093  function properties()
1094  {
1095
1096    // ----- Reset the error handler
1097    $this->privErrorReset();
1098
1099    // ----- Magic quotes trick
1100    $this->privDisableMagicQuotes();
1101
1102    // ----- Check archive
1103    if (!$this->privCheckFormat()) {
1104      $this->privSwapBackMagicQuotes();
1105      return(0);
1106    }
1107
1108    // ----- Default properties
1109    $v_prop = array();
1110    $v_prop['comment'] = '';
1111    $v_prop['nb'] = 0;
1112    $v_prop['status'] = 'not_exist';
1113
1114    // ----- Look if file exists
1115    if (@is_file($this->zipname))
1116    {
1117      // ----- Open the zip file
1118      if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
1119      {
1120        $this->privSwapBackMagicQuotes();
1121
1122        // ----- Error log
1123        PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
1124
1125        // ----- Return
1126        return 0;
1127      }
1128
1129      // ----- Read the central directory informations
1130      $v_central_dir = array();
1131      if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1132      {
1133        $this->privSwapBackMagicQuotes();
1134        return 0;
1135      }
1136
1137      // ----- Close the zip file
1138      $this->privCloseFd();
1139
1140      // ----- Set the user attributes
1141      $v_prop['comment'] = $v_central_dir['comment'];
1142      $v_prop['nb'] = $v_central_dir['entries'];
1143      $v_prop['status'] = 'ok';
1144    }
1145
1146    // ----- Magic quotes trick
1147    $this->privSwapBackMagicQuotes();
1148
1149    // ----- Return
1150    return $v_prop;
1151  }
1152  // --------------------------------------------------------------------------------
1153
1154  // --------------------------------------------------------------------------------
1155  // Function : duplicate()
1156  // Description :
1157  //   This method creates an archive by copying the content of an other one. If
1158  //   the archive already exist, it is replaced by the new one without any warning.
1159  // Parameters :
1160  //   $p_archive : The filename of a valid archive, or
1161  //                a valid PclZip object.
1162  // Return Values :
1163  //   1 on success.
1164  //   0 or a negative value on error (error code).
1165  // --------------------------------------------------------------------------------
1166  function duplicate($p_archive)
1167  {
1168    $v_result = 1;
1169
1170    // ----- Reset the error handler
1171    $this->privErrorReset();
1172
1173    // ----- Look if the $p_archive is a PclZip object
1174    if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
1175    {
1176
1177      // ----- Duplicate the archive
1178      $v_result = $this->privDuplicate($p_archive->zipname);
1179    }
1180
1181    // ----- Look if the $p_archive is a string (so a filename)
1182    else if (is_string($p_archive))
1183    {
1184
1185      // ----- Check that $p_archive is a valid zip file
1186      // TBC : Should also check the archive format
1187      if (!is_file($p_archive)) {
1188        // ----- Error log
1189        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
1190        $v_result = PCLZIP_ERR_MISSING_FILE;
1191      }
1192      else {
1193        // ----- Duplicate the archive
1194        $v_result = $this->privDuplicate($p_archive);
1195      }
1196    }
1197
1198    // ----- Invalid variable
1199    else
1200    {
1201      // ----- Error log
1202      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
1203      $v_result = PCLZIP_ERR_INVALID_PARAMETER;
1204    }
1205
1206    // ----- Return
1207    return $v_result;
1208  }
1209  // --------------------------------------------------------------------------------
1210
1211  // --------------------------------------------------------------------------------
1212  // Function : merge()
1213  // Description :
1214  //   This method merge the $p_archive_to_add archive at the end of the current
1215  //   one ($this).
1216  //   If the archive ($this) does not exist, the merge becomes a duplicate.
1217  //   If the $p_archive_to_add archive does not exist, the merge is a success.
1218  // Parameters :
1219  //   $p_archive_to_add : It can be directly the filename of a valid zip archive,
1220  //                       or a PclZip object archive.
1221  // Return Values :
1222  //   1 on success,
1223  //   0 or negative values on error (see below).
1224  // --------------------------------------------------------------------------------
1225  function merge($p_archive_to_add)
1226  {
1227    $v_result = 1;
1228
1229    // ----- Reset the error handler
1230    $this->privErrorReset();
1231
1232    // ----- Check archive
1233    if (!$this->privCheckFormat()) {
1234      return(0);
1235    }
1236
1237    // ----- Look if the $p_archive_to_add is a PclZip object
1238    if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
1239    {
1240
1241      // ----- Merge the archive
1242      $v_result = $this->privMerge($p_archive_to_add);
1243    }
1244
1245    // ----- Look if the $p_archive_to_add is a string (so a filename)
1246    else if (is_string($p_archive_to_add))
1247    {
1248
1249      // ----- Create a temporary archive
1250      $v_object_archive = new PclZip($p_archive_to_add);
1251
1252      // ----- Merge the archive
1253      $v_result = $this->privMerge($v_object_archive);
1254    }
1255
1256    // ----- Invalid variable
1257    else
1258    {
1259      // ----- Error log
1260      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
1261      $v_result = PCLZIP_ERR_INVALID_PARAMETER;
1262    }
1263
1264    // ----- Return
1265    return $v_result;
1266  }
1267  // --------------------------------------------------------------------------------
1268
1269
1270
1271  // --------------------------------------------------------------------------------
1272  // Function : errorCode()
1273  // Description :
1274  // Parameters :
1275  // --------------------------------------------------------------------------------
1276  function errorCode()
1277  {
1278    if (PCLZIP_ERROR_EXTERNAL == 1) {
1279      return(PclErrorCode());
1280    }
1281    else {
1282      return($this->error_code);
1283    }
1284  }
1285  // --------------------------------------------------------------------------------
1286
1287  // --------------------------------------------------------------------------------
1288  // Function : errorName()
1289  // Description :
1290  // Parameters :
1291  // --------------------------------------------------------------------------------
1292  function errorName($p_with_code=false)
1293  {
1294    $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
1295                      PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
1296                      PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
1297                      PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
1298                      PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
1299                      PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
1300                      PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
1301                      PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
1302                      PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
1303                      PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
1304                      PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
1305                      PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
1306                      PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
1307                      PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
1308                      PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
1309                      PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
1310                      PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
1311                      PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
1312                      PCLZIP_…

Large files files are truncated, but you can click here to view the full file