Make WordPress Core

Changeset 11038


Ignore:
Timestamp:
04/21/2009 10:42:25 PM (16 years ago)
Author:
ryan
Message:

Use dist pczlip. see #9615 #9464

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-pclzip.php

    r11025 r11038  
    2828  // ----- Constants
    2929  if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
    30     define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
     30    define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
    3131  }
    3232 
     
    4242  // Recommanded values for smart separation of filenames.
    4343  if (!defined('PCLZIP_SEPARATOR')) {
    44     define( 'PCLZIP_SEPARATOR', ',' );
     44    define( 'PCLZIP_SEPARATOR', ',' );
    4545  }
    4646
     
    4848  // 0 : PclZip Class integrated error handling
    4949  // 1 : PclError external library error handling. By enabling this
    50   //    you must ensure that you have included PclError library.
     50  //    you must ensure that you have included PclError library.
    5151  // [2,...] : reserved for futur use
    5252  if (!defined('PCLZIP_ERROR_EXTERNAL')) {
    53     define( 'PCLZIP_ERROR_EXTERNAL', 0 );
     53    define( 'PCLZIP_ERROR_EXTERNAL', 0 );
    5454  }
    5555
    5656  // ----- 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 :
     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 :
    6363  // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
    6464  // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
    6565  if (!defined('PCLZIP_TEMPORARY_DIR')) {
    66     define( 'PCLZIP_TEMPORARY_DIR', '' );
     66    define( 'PCLZIP_TEMPORARY_DIR', '' );
    6767  }
    6868
     
    175175  class PclZip
    176176  {
    177     // ----- Filename of the zip file
    178     var $zipname = '';
    179 
    180     // ----- File descriptor of the zip file
    181     var $zip_fd = 0;
    182 
    183     // ----- Internal error handling
    184     var $error_code = 1;
    185     var $error_string = '';
    186    
    187     // ----- Current status of the magic_quotes_runtime
    188     // This value store the php configuration for magic_quotes
    189     // The class can then disable the magic_quotes and reset it after
    190     var $magic_quotes_status;
     177    // ----- Filename of the zip file
     178    var $zipname = '';
     179
     180    // ----- File descriptor of the zip file
     181    var $zip_fd = 0;
     182
     183    // ----- Internal error handling
     184    var $error_code = 1;
     185    var $error_string = '';
     186   
     187    // ----- Current status of the magic_quotes_runtime
     188    // This value store the php configuration for magic_quotes
     189    // The class can then disable the magic_quotes and reset it after
     190    var $magic_quotes_status;
    191191
    192192  // --------------------------------------------------------------------------------
     
    200200  function PclZip($p_zipname)
    201201  {
    202     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");
    203 
    204     // ----- Tests the zlib
    205     if (!function_exists('gzopen'))
    206     {
    207       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing");
    208       die('Abort '.basename(__FILE__).' : Missing zlib extensions');
    209     }
    210 
    211     // ----- Set the attributes
    212     $this->zipname = $p_zipname;
    213     $this->zip_fd = 0;
    214     $this->magic_quotes_status = -1;
    215 
    216     // ----- Return
    217     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);
    218     return;
     202    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");
     203
     204    // ----- Tests the zlib
     205    if (!function_exists('gzopen'))
     206    {
     207      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing");
     208      die('Abort '.basename(__FILE__).' : Missing zlib extensions');
     209    }
     210
     211    // ----- Set the attributes
     212    $this->zipname = $p_zipname;
     213    $this->zip_fd = 0;
     214    $this->magic_quotes_status = -1;
     215
     216    // ----- Return
     217    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);
     218    return;
    219219  }
    220220  // --------------------------------------------------------------------------------
     
    236236  // Parameters :
    237237  //   $p_filelist : An array containing file or directory names, or
    238   //                a string containing one filename or one directory name, or
    239   //                a string containing a list of filenames and/or directory
    240   //                names separated by spaces.
     238  //                a string containing one filename or one directory name, or
     239  //                a string containing a list of filenames and/or directory
     240  //                names separated by spaces.
    241241  //   $p_add_dir : A path to add before the real path of the archived file,
    242   //                in order to have it memorized in the archive.
     242  //                in order to have it memorized in the archive.
    243243  //   $p_remove_dir : A path to remove from the real path of the file to archive,
    244   //                   in order to have a shorter path memorized in the archive.
    245   //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
    246   //                   is removed first, before $p_add_dir is added.
     244  //                   in order to have a shorter path memorized in the archive.
     245  //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
     246  //                   is removed first, before $p_add_dir is added.
    247247  // Options :
    248248  //   PCLZIP_OPT_ADD_PATH :
     
    259259  function create($p_filelist)
    260260  {
    261     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ...");
    262     $v_result=1;
    263 
    264     // ----- Reset the error handler
    265     $this->privErrorReset();
    266 
    267     // ----- Set default values
    268     $v_options = array();
    269     $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
    270 
    271     // ----- Look for variable options arguments
    272     $v_size = func_num_args();
    273     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
    274 
    275     // ----- Look for arguments
    276     if ($v_size > 1) {
    277       // ----- Get the arguments
    278       $v_arg_list = func_get_args();
    279 
    280       // ----- Remove from the options list the first argument
    281       array_shift($v_arg_list);
    282       $v_size--;
    283 
    284       // ----- Look for first arg
    285       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
    286         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
    287 
    288         // ----- Parse the options
    289         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
    290                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
    291                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
    292                                                    PCLZIP_OPT_ADD_PATH => 'optional',
    293                                                    PCLZIP_CB_PRE_ADD => 'optional',
    294                                                    PCLZIP_CB_POST_ADD => 'optional',
    295                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
    296                                                    PCLZIP_OPT_COMMENT => 'optional',
    297                                                    PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD => 'optional',
    298                                                    PCLZIP_OPT_ADD_TEMP_FILE_ON => 'optional',
    299                                                    PCLZIP_OPT_ADD_TEMP_FILE_OFF => 'optional'
    300                                                    //, PCLZIP_OPT_CRYPT => 'optional'
    301                                             ));
    302         if ($v_result != 1) {
    303           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    304           return 0;
    305         }
    306       }
    307 
    308       // ----- Look for 2 args
    309       // Here we need to support the first historic synopsis of the
    310       // method.
    311       else {
    312         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
    313 
    314         // ----- Get the first argument
    315         $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
    316 
    317         // ----- Look for the optional second argument
    318         if ($v_size == 2) {
    319           $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
    320         }
    321         else if ($v_size > 2) {
    322           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
    323                                "Invalid number / type of arguments");
    324           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    325           return 0;
    326         }
    327       }
    328     }
    329    
    330     // ----- Look for default option values
    331     if (!isset($v_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {
    332       $this->privOptionDefaultThreshold($v_options);
    333     }
    334 
    335     // ----- Init
    336     $v_string_list = array();
    337     $v_att_list = array();
    338     $v_filedescr_list = array();
    339     $p_result_list = array();
    340    
    341     // ----- Look if the $p_filelist is really an array
    342     if (is_array($p_filelist)) {
    343    
    344       // ----- Look if the first element is also an array
    345       //       This will mean that this is a file description entry
    346       if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
    347         $v_att_list = $p_filelist;
    348       }
    349      
    350       // ----- The list is a list of string names
    351       else {
    352         $v_string_list = $p_filelist;
    353       }
    354     }
    355 
    356     // ----- Look if the $p_filelist is a string
    357     else if (is_string($p_filelist)) {
    358       // ----- Create a list from the string
    359       $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
    360     }
    361 
    362     // ----- Invalid variable type for $p_filelist
    363     else {
    364       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
    365       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    366       return 0;
    367     }
    368    
    369     // ----- Reformat the string list
    370     if (sizeof($v_string_list) != 0) {
    371       foreach ($v_string_list as $v_string) {
    372         if ($v_string != '') {
    373           $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
    374         }
    375         else {
    376           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename");
    377         }
    378       }
    379     }
    380    
    381     // ----- For each file in the list check the attributes
    382     $v_supported_attributes
    383     = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
    384             ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
    385             ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
    386             ,PCLZIP_ATT_FILE_MTIME => 'optional'
    387             ,PCLZIP_ATT_FILE_CONTENT => 'optional'
    388             ,PCLZIP_ATT_FILE_COMMENT => 'optional'
     261    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ...");
     262    $v_result=1;
     263
     264    // ----- Reset the error handler
     265    $this->privErrorReset();
     266
     267    // ----- Set default values
     268    $v_options = array();
     269    $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
     270
     271    // ----- Look for variable options arguments
     272    $v_size = func_num_args();
     273    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
     274
     275    // ----- Look for arguments
     276    if ($v_size > 1) {
     277      // ----- Get the arguments
     278      $v_arg_list = func_get_args();
     279
     280      // ----- Remove from the options list the first argument
     281      array_shift($v_arg_list);
     282      $v_size--;
     283
     284      // ----- Look for first arg
     285      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
     286        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
     287
     288        // ----- Parse the options
     289        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
     290                                            array (PCLZIP_OPT_REMOVE_PATH => 'optional',
     291                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
     292                                                   PCLZIP_OPT_ADD_PATH => 'optional',
     293                                                   PCLZIP_CB_PRE_ADD => 'optional',
     294                                                   PCLZIP_CB_POST_ADD => 'optional',
     295                                                   PCLZIP_OPT_NO_COMPRESSION => 'optional',
     296                                                   PCLZIP_OPT_COMMENT => 'optional',
     297                                                   PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD => 'optional',
     298                                                   PCLZIP_OPT_ADD_TEMP_FILE_ON => 'optional',
     299                                                   PCLZIP_OPT_ADD_TEMP_FILE_OFF => 'optional'
     300                                                   //, PCLZIP_OPT_CRYPT => 'optional'
     301                                            ));
     302        if ($v_result != 1) {
     303          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     304          return 0;
     305        }
     306      }
     307
     308      // ----- Look for 2 args
     309      // Here we need to support the first historic synopsis of the
     310      // method.
     311      else {
     312        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
     313
     314        // ----- Get the first argument
     315        $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
     316
     317        // ----- Look for the optional second argument
     318        if ($v_size == 2) {
     319          $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
     320        }
     321        else if ($v_size > 2) {
     322          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
     323                               "Invalid number / type of arguments");
     324          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     325          return 0;
     326        }
     327      }
     328    }
     329   
     330    // ----- Look for default option values
     331    if (!isset($v_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {
     332      $this->privOptionDefaultThreshold($v_options);
     333    }
     334
     335    // ----- Init
     336    $v_string_list = array();
     337    $v_att_list = array();
     338    $v_filedescr_list = array();
     339    $p_result_list = array();
     340   
     341    // ----- Look if the $p_filelist is really an array
     342    if (is_array($p_filelist)) {
     343   
     344      // ----- Look if the first element is also an array
     345      //       This will mean that this is a file description entry
     346      if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
     347        $v_att_list = $p_filelist;
     348      }
     349     
     350      // ----- The list is a list of string names
     351      else {
     352        $v_string_list = $p_filelist;
     353      }
     354    }
     355
     356    // ----- Look if the $p_filelist is a string
     357    else if (is_string($p_filelist)) {
     358      // ----- Create a list from the string
     359      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
     360    }
     361
     362    // ----- Invalid variable type for $p_filelist
     363    else {
     364      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
     365      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     366      return 0;
     367    }
     368   
     369    // ----- Reformat the string list
     370    if (sizeof($v_string_list) != 0) {
     371      foreach ($v_string_list as $v_string) {
     372        if ($v_string != '') {
     373          $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
     374        }
     375        else {
     376          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename");
     377        }
     378      }
     379    }
     380   
     381    // ----- For each file in the list check the attributes
     382    $v_supported_attributes
     383    = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
     384            ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
     385            ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
     386            ,PCLZIP_ATT_FILE_MTIME => 'optional'
     387            ,PCLZIP_ATT_FILE_CONTENT => 'optional'
     388            ,PCLZIP_ATT_FILE_COMMENT => 'optional'
    389389                        );
    390     foreach ($v_att_list as $v_entry) {
    391       $v_result = $this->privFileDescrParseAtt($v_entry,
    392                                                $v_filedescr_list[],
    393                                                $v_options,
    394                                                $v_supported_attributes);
    395       if ($v_result != 1) {
    396         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    397         return 0;
    398       }
    399     }
    400 
    401     // ----- Expand the filelist (expand directories)
    402     $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
    403     if ($v_result != 1) {
    404       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    405       return 0;
    406     }
    407 
    408     // ----- Call the create fct
    409     $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
    410     if ($v_result != 1) {
    411       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    412       return 0;
    413     }
    414 
    415     // ----- Return
    416     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
    417     return $p_result_list;
     390    foreach ($v_att_list as $v_entry) {
     391      $v_result = $this->privFileDescrParseAtt($v_entry,
     392                                               $v_filedescr_list[],
     393                                               $v_options,
     394                                               $v_supported_attributes);
     395      if ($v_result != 1) {
     396        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     397        return 0;
     398      }
     399    }
     400
     401    // ----- Expand the filelist (expand directories)
     402    $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
     403    if ($v_result != 1) {
     404      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     405      return 0;
     406    }
     407
     408    // ----- Call the create fct
     409    $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
     410    if ($v_result != 1) {
     411      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     412      return 0;
     413    }
     414
     415    // ----- Return
     416    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
     417    return $p_result_list;
    418418  }
    419419  // --------------------------------------------------------------------------------
     
    431431  // Parameters :
    432432  //   $p_filelist : An array containing file or directory names, or
    433   //                a string containing one filename or one directory name, or
    434   //                a string containing a list of filenames and/or directory
    435   //                names separated by spaces.
     433  //                a string containing one filename or one directory name, or
     434  //                a string containing a list of filenames and/or directory
     435  //                names separated by spaces.
    436436  //   $p_add_dir : A path to add before the real path of the archived file,
    437   //                in order to have it memorized in the archive.
     437  //                in order to have it memorized in the archive.
    438438  //   $p_remove_dir : A path to remove from the real path of the file to archive,
    439   //                   in order to have a shorter path memorized in the archive.
    440   //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
    441   //                   is removed first, before $p_add_dir is added.
     439  //                   in order to have a shorter path memorized in the archive.
     440  //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
     441  //                   is removed first, before $p_add_dir is added.
    442442  // Options :
    443443  //   PCLZIP_OPT_ADD_PATH :
     
    456456  function add($p_filelist)
    457457  {
    458     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ...");
    459     $v_result=1;
    460 
    461     // ----- Reset the error handler
    462     $this->privErrorReset();
    463 
    464     // ----- Set default values
    465     $v_options = array();
    466     $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
    467 
    468     // ----- Look for variable options arguments
    469     $v_size = func_num_args();
    470     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
    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         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
    484 
    485         // ----- Parse the options
    486         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
    487                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
    488                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
    489                                                    PCLZIP_OPT_ADD_PATH => 'optional',
    490                                                    PCLZIP_CB_PRE_ADD => 'optional',
    491                                                    PCLZIP_CB_POST_ADD => 'optional',
    492                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
    493                                                    PCLZIP_OPT_COMMENT => 'optional',
    494                                                    PCLZIP_OPT_ADD_COMMENT => 'optional',
    495                                                    PCLZIP_OPT_PREPEND_COMMENT => 'optional',
    496                                                    PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD => 'optional',
    497                                                    PCLZIP_OPT_ADD_TEMP_FILE_ON => 'optional',
    498                                                    PCLZIP_OPT_ADD_TEMP_FILE_OFF => 'optional'
    499                                                    //, PCLZIP_OPT_CRYPT => 'optional'
     458    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ...");
     459    $v_result=1;
     460
     461    // ----- Reset the error handler
     462    $this->privErrorReset();
     463
     464    // ----- Set default values
     465    $v_options = array();
     466    $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
     467
     468    // ----- Look for variable options arguments
     469    $v_size = func_num_args();
     470    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
     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        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
     484
     485        // ----- Parse the options
     486        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
     487                                            array (PCLZIP_OPT_REMOVE_PATH => 'optional',
     488                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
     489                                                   PCLZIP_OPT_ADD_PATH => 'optional',
     490                                                   PCLZIP_CB_PRE_ADD => 'optional',
     491                                                   PCLZIP_CB_POST_ADD => 'optional',
     492                                                   PCLZIP_OPT_NO_COMPRESSION => 'optional',
     493                                                   PCLZIP_OPT_COMMENT => 'optional',
     494                                                   PCLZIP_OPT_ADD_COMMENT => 'optional',
     495                                                   PCLZIP_OPT_PREPEND_COMMENT => 'optional',
     496                                                   PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD => 'optional',
     497                                                   PCLZIP_OPT_ADD_TEMP_FILE_ON => 'optional',
     498                                                   PCLZIP_OPT_ADD_TEMP_FILE_OFF => 'optional'
     499                                                   //, PCLZIP_OPT_CRYPT => 'optional'
    500500                                                   ));
    501         if ($v_result != 1) {
    502           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    503           return 0;
    504         }
    505       }
    506 
    507       // ----- Look for 2 args
    508       // Here we need to support the first historic synopsis of the
    509       // method.
    510       else {
    511         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
    512 
    513         // ----- Get the first argument
    514         $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
    515 
    516         // ----- Look for the optional second argument
    517         if ($v_size == 2) {
    518           $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
    519         }
    520         else if ($v_size > 2) {
    521           // ----- Error log
    522           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
    523 
    524           // ----- Return
    525           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    526           return 0;
    527         }
    528       }
    529     }
    530 
    531     // ----- Look for default option values
    532     if (!isset($v_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {
    533       $this->privOptionDefaultThreshold($v_options);
    534     }
    535 
    536     // ----- Init
    537     $v_string_list = array();
    538     $v_att_list = array();
    539     $v_filedescr_list = array();
    540     $p_result_list = array();
    541    
    542     // ----- Look if the $p_filelist is really an array
    543     if (is_array($p_filelist)) {
    544    
    545       // ----- Look if the first element is also an array
    546       //       This will mean that this is a file description entry
    547       if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
    548         $v_att_list = $p_filelist;
    549       }
    550      
    551       // ----- The list is a list of string names
    552       else {
    553         $v_string_list = $p_filelist;
    554       }
    555     }
    556 
    557     // ----- Look if the $p_filelist is a string
    558     else if (is_string($p_filelist)) {
    559       // ----- Create a list from the string
    560       $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
    561     }
    562 
    563     // ----- Invalid variable type for $p_filelist
    564     else {
    565       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
    566       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    567       return 0;
    568     }
    569    
    570     // ----- Reformat the string list
    571     if (sizeof($v_string_list) != 0) {
    572       foreach ($v_string_list as $v_string) {
    573         $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
    574       }
    575     }
    576    
    577     // ----- For each file in the list check the attributes
    578     $v_supported_attributes
    579     = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
    580             ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
    581             ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
    582             ,PCLZIP_ATT_FILE_MTIME => 'optional'
    583             ,PCLZIP_ATT_FILE_CONTENT => 'optional'
    584             ,PCLZIP_ATT_FILE_COMMENT => 'optional'
     501        if ($v_result != 1) {
     502          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     503          return 0;
     504        }
     505      }
     506
     507      // ----- Look for 2 args
     508      // Here we need to support the first historic synopsis of the
     509      // method.
     510      else {
     511        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
     512
     513        // ----- Get the first argument
     514        $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
     515
     516        // ----- Look for the optional second argument
     517        if ($v_size == 2) {
     518          $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
     519        }
     520        else if ($v_size > 2) {
     521          // ----- Error log
     522          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
     523
     524          // ----- Return
     525          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     526          return 0;
     527        }
     528      }
     529    }
     530
     531    // ----- Look for default option values
     532    if (!isset($v_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {
     533      $this->privOptionDefaultThreshold($v_options);
     534    }
     535
     536    // ----- Init
     537    $v_string_list = array();
     538    $v_att_list = array();
     539    $v_filedescr_list = array();
     540    $p_result_list = array();
     541   
     542    // ----- Look if the $p_filelist is really an array
     543    if (is_array($p_filelist)) {
     544   
     545      // ----- Look if the first element is also an array
     546      //       This will mean that this is a file description entry
     547      if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
     548        $v_att_list = $p_filelist;
     549      }
     550     
     551      // ----- The list is a list of string names
     552      else {
     553        $v_string_list = $p_filelist;
     554      }
     555    }
     556
     557    // ----- Look if the $p_filelist is a string
     558    else if (is_string($p_filelist)) {
     559      // ----- Create a list from the string
     560      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
     561    }
     562
     563    // ----- Invalid variable type for $p_filelist
     564    else {
     565      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
     566      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     567      return 0;
     568    }
     569   
     570    // ----- Reformat the string list
     571    if (sizeof($v_string_list) != 0) {
     572      foreach ($v_string_list as $v_string) {
     573        $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
     574      }
     575    }
     576   
     577    // ----- For each file in the list check the attributes
     578    $v_supported_attributes
     579    = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
     580            ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
     581            ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
     582            ,PCLZIP_ATT_FILE_MTIME => 'optional'
     583            ,PCLZIP_ATT_FILE_CONTENT => 'optional'
     584            ,PCLZIP_ATT_FILE_COMMENT => 'optional'
    585585                        );
    586     foreach ($v_att_list as $v_entry) {
    587       $v_result = $this->privFileDescrParseAtt($v_entry,
    588                                                $v_filedescr_list[],
    589                                                $v_options,
    590                                                $v_supported_attributes);
    591       if ($v_result != 1) {
    592         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    593         return 0;
    594       }
    595     }
    596 
    597     // ----- Expand the filelist (expand directories)
    598     $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
    599     if ($v_result != 1) {
    600       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    601       return 0;
    602     }
    603 
    604     // ----- Call the create fct
    605     $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
    606     if ($v_result != 1) {
    607       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    608       return 0;
    609     }
    610 
    611     // ----- Return
    612     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
    613     return $p_result_list;
     586    foreach ($v_att_list as $v_entry) {
     587      $v_result = $this->privFileDescrParseAtt($v_entry,
     588                                               $v_filedescr_list[],
     589                                               $v_options,
     590                                               $v_supported_attributes);
     591      if ($v_result != 1) {
     592        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     593        return 0;
     594      }
     595    }
     596
     597    // ----- Expand the filelist (expand directories)
     598    $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
     599    if ($v_result != 1) {
     600      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     601      return 0;
     602    }
     603
     604    // ----- Call the create fct
     605    $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
     606    if ($v_result != 1) {
     607      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     608      return 0;
     609    }
     610
     611    // ----- Return
     612    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
     613    return $p_result_list;
    614614  }
    615615  // --------------------------------------------------------------------------------
     
    621621  //   properties.
    622622  //   The properties of each entries in the list are (used also in other functions) :
    623   //    filename : Name of the file. For a create or add action it is the filename
    624   //                given by the user. For an extract function it is the filename
    625   //                of the extracted file.
    626   //    stored_filename : Name of the file / directory stored in the archive.
    627   //    size : Size of the stored file.
    628   //    compressed_size : Size of the file's data compressed in the archive
    629   //                       (without the headers overhead)
    630   //    mtime : Last known modification date of the file (UNIX timestamp)
    631   //    comment : Comment associated with the file
    632   //    folder : true | false
    633   //    index : index of the file in the archive
    634   //    status : status of the action (depending of the action) :
    635   //              Values are :
    636   //                ok : OK !
    637   //                filtered : the file / dir is not extracted (filtered by user)
    638   //                already_a_directory : the file can not be extracted because a
    639   //                                      directory with the same name already exists
    640   //                write_protected : the file can not be extracted because a file
    641   //                                  with the same name already exists and is
    642   //                                  write protected
    643   //                newer_exist : the file was not extracted because a newer file exists
    644   //                path_creation_fail : the file is not extracted because the folder
    645   //                                    does not exist and can not be created
    646   //                write_error : the file was not extracted because there was a
    647   //                              error while writing the file
    648   //                read_error : the file was not extracted because there was a error
    649   //                            while reading the file
    650   //                invalid_header : the file was not extracted because of an archive
    651   //                                format error (bad file header)
     623  //    filename : Name of the file. For a create or add action it is the filename
     624  //                given by the user. For an extract function it is the filename
     625  //                of the extracted file.
     626  //    stored_filename : Name of the file / directory stored in the archive.
     627  //    size : Size of the stored file.
     628  //    compressed_size : Size of the file's data compressed in the archive
     629  //                       (without the headers overhead)
     630  //    mtime : Last known modification date of the file (UNIX timestamp)
     631  //    comment : Comment associated with the file
     632  //    folder : true | false
     633  //    index : index of the file in the archive
     634  //    status : status of the action (depending of the action) :
     635  //              Values are :
     636  //                ok : OK !
     637  //                filtered : the file / dir is not extracted (filtered by user)
     638  //                already_a_directory : the file can not be extracted because a
     639  //                                      directory with the same name already exists
     640  //                write_protected : the file can not be extracted because a file
     641  //                                  with the same name already exists and is
     642  //                                  write protected
     643  //                newer_exist : the file was not extracted because a newer file exists
     644  //                path_creation_fail : the file is not extracted because the folder
     645  //                                    does not exist and can not be created
     646  //                write_error : the file was not extracted because there was a
     647  //                              error while writing the file
     648  //                read_error : the file was not extracted because there was a error
     649  //                            while reading the file
     650  //                invalid_header : the file was not extracted because of an archive
     651  //                                format error (bad file header)
    652652  //   Note that each time a method can continue operating when there
    653653  //   is an action error on a file, the error is only logged in the file status.
     
    658658  function listContent()
    659659  {
    660     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");
    661     $v_result=1;
    662 
    663     // ----- Reset the error handler
    664     $this->privErrorReset();
    665 
    666     // ----- Check archive
    667     if (!$this->privCheckFormat()) {
    668       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    669       return(0);
    670     }
    671 
    672     // ----- Call the extracting fct
    673     $p_list = array();
    674     if (($v_result = $this->privList($p_list)) != 1)
    675     {
    676       unset($p_list);
    677       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
    678       return(0);
    679     }
    680 
    681     // ----- Return
    682     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
    683     return $p_list;
     660    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");
     661    $v_result=1;
     662
     663    // ----- Reset the error handler
     664    $this->privErrorReset();
     665
     666    // ----- Check archive
     667    if (!$this->privCheckFormat()) {
     668      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     669      return(0);
     670    }
     671
     672    // ----- Call the extracting fct
     673    $p_list = array();
     674    if (($v_result = $this->privList($p_list)) != 1)
     675    {
     676      unset($p_list);
     677      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
     678      return(0);
     679    }
     680
     681    // ----- Return
     682    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
     683    return $p_list;
    684684  }
    685685  // --------------------------------------------------------------------------------
     
    704704  //   $p_path : Path where the files and directories are to be extracted
    705705  //   $p_remove_path : First part ('root' part) of the memorized path
    706   //                    (if any similar) to remove while extracting.
     706  //                    (if any similar) to remove while extracting.
    707707  // Options :
    708708  //   PCLZIP_OPT_PATH :
     
    719719  function extract()
    720720  {
    721     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");
    722     $v_result=1;
    723 
    724     // ----- Reset the error handler
    725     $this->privErrorReset();
    726 
    727     // ----- Check archive
    728     if (!$this->privCheckFormat()) {
    729       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    730       return(0);
    731     }
    732 
    733     // ----- Set default values
    734     $v_options = array();
    735 //  $v_path = "./";
    736     $v_path = '';
    737     $v_remove_path = "";
    738     $v_remove_all_path = false;
    739 
    740     // ----- Look for variable options arguments
    741     $v_size = func_num_args();
    742     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
    743 
    744     // ----- Default values for option
    745     $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
    746 
    747     // ----- Look for arguments
    748     if ($v_size > 0) {
    749       // ----- Get the arguments
    750       $v_arg_list = func_get_args();
    751 
    752       // ----- Look for first arg
    753       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
    754         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
    755 
    756         // ----- Parse the options
    757         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
    758                                             array (PCLZIP_OPT_PATH => 'optional',
    759                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
    760                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
    761                                                    PCLZIP_OPT_ADD_PATH => 'optional',
    762                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
    763                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
    764                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
    765                                                    PCLZIP_OPT_BY_NAME => 'optional',
    766                                                    PCLZIP_OPT_BY_EREG => 'optional',
    767                                                    PCLZIP_OPT_BY_PREG => 'optional',
    768                                                    PCLZIP_OPT_BY_INDEX => 'optional',
    769                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
    770                                                    PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
    771                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
    772                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
    773                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
    774                                                     ));
    775         if ($v_result != 1) {
    776           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    777           return 0;
    778         }
    779 
    780         // ----- Set the arguments
    781         if (isset($v_options[PCLZIP_OPT_PATH])) {
    782           $v_path = $v_options[PCLZIP_OPT_PATH];
    783         }
    784         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
    785           $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
    786         }
    787         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
    788           $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
    789         }
    790         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
    791           // ----- Check for '/' in last path char
    792           if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
    793             $v_path .= '/';
    794           }
    795           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
    796         }
    797       }
    798 
    799       // ----- Look for 2 args
    800       // Here we need to support the first historic synopsis of the
    801       // method.
    802       else {
    803         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
    804 
    805         // ----- Get the first argument
    806         $v_path = $v_arg_list[0];
    807 
    808         // ----- Look for the optional second argument
    809         if ($v_size == 2) {
    810           $v_remove_path = $v_arg_list[1];
    811         }
    812         else if ($v_size > 2) {
    813           // ----- Error log
    814           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
    815 
    816           // ----- Return
    817           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
    818           return 0;
    819         }
    820       }
    821     }
    822 
    823     // ----- Trace
    824     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");
    825 
    826     // ----- Call the extracting fct
    827     $p_list = array();
    828     $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
    829                                         $v_remove_all_path, $v_options);
    830     if ($v_result < 1) {
    831       unset($p_list);
    832       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
    833       return(0);
    834     }
    835 
    836     // ----- Return
    837     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
    838     return $p_list;
     721    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");
     722    $v_result=1;
     723
     724    // ----- Reset the error handler
     725    $this->privErrorReset();
     726
     727    // ----- Check archive
     728    if (!$this->privCheckFormat()) {
     729      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     730      return(0);
     731    }
     732
     733    // ----- Set default values
     734    $v_options = array();
     735//    $v_path = "./";
     736    $v_path = '';
     737    $v_remove_path = "";
     738    $v_remove_all_path = false;
     739
     740    // ----- Look for variable options arguments
     741    $v_size = func_num_args();
     742    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
     743
     744    // ----- Default values for option
     745    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
     746
     747    // ----- Look for arguments
     748    if ($v_size > 0) {
     749      // ----- Get the arguments
     750      $v_arg_list = func_get_args();
     751
     752      // ----- Look for first arg
     753      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
     754        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
     755
     756        // ----- Parse the options
     757        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
     758                                            array (PCLZIP_OPT_PATH => 'optional',
     759                                                   PCLZIP_OPT_REMOVE_PATH => 'optional',
     760                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
     761                                                   PCLZIP_OPT_ADD_PATH => 'optional',
     762                                                   PCLZIP_CB_PRE_EXTRACT => 'optional',
     763                                                   PCLZIP_CB_POST_EXTRACT => 'optional',
     764                                                   PCLZIP_OPT_SET_CHMOD => 'optional',
     765                                                   PCLZIP_OPT_BY_NAME => 'optional',
     766                                                   PCLZIP_OPT_BY_EREG => 'optional',
     767                                                   PCLZIP_OPT_BY_PREG => 'optional',
     768                                                   PCLZIP_OPT_BY_INDEX => 'optional',
     769                                                   PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
     770                                                   PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
     771                                                   PCLZIP_OPT_REPLACE_NEWER => 'optional'
     772                                                   ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
     773                                                   ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
     774                                                    ));
     775        if ($v_result != 1) {
     776          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     777          return 0;
     778        }
     779
     780        // ----- Set the arguments
     781        if (isset($v_options[PCLZIP_OPT_PATH])) {
     782          $v_path = $v_options[PCLZIP_OPT_PATH];
     783        }
     784        if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
     785          $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
     786        }
     787        if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
     788          $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
     789        }
     790        if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
     791          // ----- Check for '/' in last path char
     792          if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
     793            $v_path .= '/';
     794          }
     795          $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
     796        }
     797      }
     798
     799      // ----- Look for 2 args
     800      // Here we need to support the first historic synopsis of the
     801      // method.
     802      else {
     803        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
     804
     805        // ----- Get the first argument
     806        $v_path = $v_arg_list[0];
     807
     808        // ----- Look for the optional second argument
     809        if ($v_size == 2) {
     810          $v_remove_path = $v_arg_list[1];
     811        }
     812        else if ($v_size > 2) {
     813          // ----- Error log
     814          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
     815
     816          // ----- Return
     817          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
     818          return 0;
     819        }
     820      }
     821    }
     822
     823    // ----- Trace
     824    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");
     825
     826    // ----- Call the extracting fct
     827    $p_list = array();
     828    $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
     829                                        $v_remove_all_path, $v_options);
     830    if ($v_result < 1) {
     831      unset($p_list);
     832      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
     833      return(0);
     834    }
     835
     836    // ----- Return
     837    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
     838    return $p_list;
    839839  }
    840840  // --------------------------------------------------------------------------------
     
    854854  // Parameters :
    855855  //   $p_index : A single index (integer) or a string of indexes of files to
    856   //              extract. The form of the string is "0,4-6,8-12" with only numbers
    857   //              and '-' for range or ',' to separate ranges. No spaces or ';'
    858   //              are allowed.
     856  //              extract. The form of the string is "0,4-6,8-12" with only numbers
     857  //              and '-' for range or ',' to separate ranges. No spaces or ';'
     858  //              are allowed.
    859859  //   $p_path : Path where the files and directories are to be extracted
    860860  //   $p_remove_path : First part ('root' part) of the memorized path
    861   //                    (if any similar) to remove while extracting.
     861  //                    (if any similar) to remove while extracting.
    862862  // Options :
    863863  //   PCLZIP_OPT_PATH :
     
    866866  //   PCLZIP_OPT_REMOVE_ALL_PATH :
    867867  //   PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
    868   //    not as files.
    869   //    The resulting content is in a new field 'content' in the file
    870   //    structure.
    871   //    This option must be used alone (any other options are ignored).
     868  //    not as files.
     869  //    The resulting content is in a new field 'content' in the file
     870  //    structure.
     871  //    This option must be used alone (any other options are ignored).
    872872  //   PCLZIP_CB_PRE_EXTRACT :
    873873  //   PCLZIP_CB_POST_EXTRACT :
     
    880880  function extractByIndex($p_index)
    881881  {
    882     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");
    883     $v_result=1;
    884 
    885     // ----- Reset the error handler
    886     $this->privErrorReset();
    887 
    888     // ----- Check archive
    889     if (!$this->privCheckFormat()) {
    890       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    891       return(0);
    892     }
    893 
    894     // ----- Set default values
    895     $v_options = array();
    896 //  $v_path = "./";
    897     $v_path = '';
    898     $v_remove_path = "";
    899     $v_remove_all_path = false;
    900 
    901     // ----- Look for variable options arguments
    902     $v_size = func_num_args();
    903     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
    904 
    905     // ----- Default values for option
    906     $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
    907 
    908     // ----- Look for arguments
    909     if ($v_size > 1) {
    910       // ----- Get the arguments
    911       $v_arg_list = func_get_args();
    912 
    913       // ----- Remove form the options list the first argument
    914       array_shift($v_arg_list);
    915       $v_size--;
    916 
    917       // ----- Look for first arg
    918       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
    919         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
    920 
    921         // ----- Parse the options
    922         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
    923                                             array (PCLZIP_OPT_PATH => 'optional',
    924                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
    925                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
    926                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
    927                                                    PCLZIP_OPT_ADD_PATH => 'optional',
    928                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
    929                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
    930                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
    931                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
    932                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
    933                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
     882    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");
     883    $v_result=1;
     884
     885    // ----- Reset the error handler
     886    $this->privErrorReset();
     887
     888    // ----- Check archive
     889    if (!$this->privCheckFormat()) {
     890      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     891      return(0);
     892    }
     893
     894    // ----- Set default values
     895    $v_options = array();
     896//    $v_path = "./";
     897    $v_path = '';
     898    $v_remove_path = "";
     899    $v_remove_all_path = false;
     900
     901    // ----- Look for variable options arguments
     902    $v_size = func_num_args();
     903    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
     904
     905    // ----- Default values for option
     906    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
     907
     908    // ----- Look for arguments
     909    if ($v_size > 1) {
     910      // ----- Get the arguments
     911      $v_arg_list = func_get_args();
     912
     913      // ----- Remove form the options list the first argument
     914      array_shift($v_arg_list);
     915      $v_size--;
     916
     917      // ----- Look for first arg
     918      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
     919        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
     920
     921        // ----- Parse the options
     922        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
     923                                            array (PCLZIP_OPT_PATH => 'optional',
     924                                                   PCLZIP_OPT_REMOVE_PATH => 'optional',
     925                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
     926                                                   PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
     927                                                   PCLZIP_OPT_ADD_PATH => 'optional',
     928                                                   PCLZIP_CB_PRE_EXTRACT => 'optional',
     929                                                   PCLZIP_CB_POST_EXTRACT => 'optional',
     930                                                   PCLZIP_OPT_SET_CHMOD => 'optional',
     931                                                   PCLZIP_OPT_REPLACE_NEWER => 'optional'
     932                                                   ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
     933                                                   ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
    934934                                                   ));
    935         if ($v_result != 1) {
    936           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    937           return 0;
    938         }
    939 
    940         // ----- Set the arguments
    941         if (isset($v_options[PCLZIP_OPT_PATH])) {
    942           $v_path = $v_options[PCLZIP_OPT_PATH];
    943         }
    944         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
    945           $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
    946         }
    947         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
    948           $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
    949         }
    950         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
    951           // ----- Check for '/' in last path char
    952           if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
    953             $v_path .= '/';
    954           }
    955           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
    956         }
    957         if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
    958           $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
    959           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set.");
    960         }
    961         else {
    962             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set.");
    963         }
    964       }
    965 
    966       // ----- Look for 2 args
    967       // Here we need to support the first historic synopsis of the
    968       // method.
    969       else {
    970         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
    971 
    972         // ----- Get the first argument
    973         $v_path = $v_arg_list[0];
    974 
    975         // ----- Look for the optional second argument
    976         if ($v_size == 2) {
    977           $v_remove_path = $v_arg_list[1];
    978         }
    979         else if ($v_size > 2) {
    980           // ----- Error log
    981           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
    982 
    983           // ----- Return
    984           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    985           return 0;
    986         }
    987       }
    988     }
    989 
    990     // ----- Trace
    991     //--(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')."'");
    992 
    993     // ----- Trick
    994     // Here I want to reuse extractByRule(), so I need to parse the $p_index
    995     // with privParseOptions()
    996     $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
    997     $v_options_trick = array();
    998     $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
    999                                         array (PCLZIP_OPT_BY_INDEX => 'optional' ));
    1000     if ($v_result != 1) {
    1001         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    1002         return 0;
    1003     }
    1004     $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
    1005 
    1006     // ----- Call the extracting fct
    1007     if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
    1008         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
    1009         return(0);
    1010     }
    1011 
    1012     // ----- Return
    1013     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
    1014     return $p_list;
     935        if ($v_result != 1) {
     936          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     937          return 0;
     938        }
     939
     940        // ----- Set the arguments
     941        if (isset($v_options[PCLZIP_OPT_PATH])) {
     942          $v_path = $v_options[PCLZIP_OPT_PATH];
     943        }
     944        if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
     945          $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
     946        }
     947        if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
     948          $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
     949        }
     950        if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
     951          // ----- Check for '/' in last path char
     952          if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
     953            $v_path .= '/';
     954          }
     955          $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
     956        }
     957        if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
     958          $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
     959          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set.");
     960        }
     961        else {
     962            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set.");
     963        }
     964      }
     965
     966      // ----- Look for 2 args
     967      // Here we need to support the first historic synopsis of the
     968      // method.
     969      else {
     970        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
     971
     972        // ----- Get the first argument
     973        $v_path = $v_arg_list[0];
     974
     975        // ----- Look for the optional second argument
     976        if ($v_size == 2) {
     977          $v_remove_path = $v_arg_list[1];
     978        }
     979        else if ($v_size > 2) {
     980          // ----- Error log
     981          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
     982
     983          // ----- Return
     984          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     985          return 0;
     986        }
     987      }
     988    }
     989
     990    // ----- Trace
     991    //--(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')."'");
     992
     993    // ----- Trick
     994    // Here I want to reuse extractByRule(), so I need to parse the $p_index
     995    // with privParseOptions()
     996    $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
     997    $v_options_trick = array();
     998    $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
     999                                        array (PCLZIP_OPT_BY_INDEX => 'optional' ));
     1000    if ($v_result != 1) {
     1001        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     1002        return 0;
     1003    }
     1004    $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
     1005
     1006    // ----- Call the extracting fct
     1007    if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
     1008        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
     1009        return(0);
     1010    }
     1011
     1012    // ----- Return
     1013    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
     1014    return $p_list;
    10151015  }
    10161016  // --------------------------------------------------------------------------------
     
    10361036  function delete()
    10371037  {
    1038     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");
    1039     $v_result=1;
    1040 
    1041     // ----- Reset the error handler
    1042     $this->privErrorReset();
    1043 
    1044     // ----- Check archive
    1045     if (!$this->privCheckFormat()) {
    1046       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    1047       return(0);
    1048     }
    1049 
    1050     // ----- Set default values
    1051     $v_options = array();
    1052 
    1053     // ----- Look for variable options arguments
    1054     $v_size = func_num_args();
    1055     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
    1056 
    1057     // ----- Look for arguments
    1058     if ($v_size > 0) {
    1059       // ----- Get the arguments
    1060       $v_arg_list = func_get_args();
    1061 
    1062       // ----- Parse the options
    1063       $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
    1064                                         array (PCLZIP_OPT_BY_NAME => 'optional',
    1065                                                PCLZIP_OPT_BY_EREG => 'optional',
    1066                                                PCLZIP_OPT_BY_PREG => 'optional',
    1067                                                PCLZIP_OPT_BY_INDEX => 'optional' ));
    1068       if ($v_result != 1) {
    1069           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    1070           return 0;
    1071       }
    1072     }
    1073 
    1074     // ----- Magic quotes trick
    1075     $this->privDisableMagicQuotes();
    1076 
    1077     // ----- Call the delete fct
    1078     $v_list = array();
    1079     if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
    1080       $this->privSwapBackMagicQuotes();
    1081       unset($v_list);
    1082       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
    1083       return(0);
    1084     }
    1085 
    1086     // ----- Magic quotes trick
    1087     $this->privSwapBackMagicQuotes();
    1088 
    1089     // ----- Return
    1090     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);
    1091     return $v_list;
     1038    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");
     1039    $v_result=1;
     1040
     1041    // ----- Reset the error handler
     1042    $this->privErrorReset();
     1043
     1044    // ----- Check archive
     1045    if (!$this->privCheckFormat()) {
     1046      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     1047      return(0);
     1048    }
     1049
     1050    // ----- Set default values
     1051    $v_options = array();
     1052
     1053    // ----- Look for variable options arguments
     1054    $v_size = func_num_args();
     1055    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
     1056
     1057    // ----- Look for arguments
     1058    if ($v_size > 0) {
     1059      // ----- Get the arguments
     1060      $v_arg_list = func_get_args();
     1061
     1062      // ----- Parse the options
     1063      $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
     1064                                        array (PCLZIP_OPT_BY_NAME => 'optional',
     1065                                               PCLZIP_OPT_BY_EREG => 'optional',
     1066                                               PCLZIP_OPT_BY_PREG => 'optional',
     1067                                               PCLZIP_OPT_BY_INDEX => 'optional' ));
     1068      if ($v_result != 1) {
     1069          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     1070          return 0;
     1071      }
     1072    }
     1073
     1074    // ----- Magic quotes trick
     1075    $this->privDisableMagicQuotes();
     1076
     1077    // ----- Call the delete fct
     1078    $v_list = array();
     1079    if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
     1080      $this->privSwapBackMagicQuotes();
     1081      unset($v_list);
     1082      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
     1083      return(0);
     1084    }
     1085
     1086    // ----- Magic quotes trick
     1087    $this->privSwapBackMagicQuotes();
     1088
     1089    // ----- Return
     1090    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);
     1091    return $v_list;
    10921092  }
    10931093  // --------------------------------------------------------------------------------
     
    11011101  function deleteByIndex($p_index)
    11021102  {
    1103     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'");
    1104    
    1105     $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
    1106 
    1107     // ----- Return
    1108     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
    1109     return $p_list;
     1103    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'");
     1104   
     1105    $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
     1106
     1107    // ----- Return
     1108    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
     1109    return $p_list;
    11101110  }
    11111111  // --------------------------------------------------------------------------------
     
    11161116  //   This method gives the properties of the archive.
    11171117  //   The properties are :
    1118   //    nb : Number of files in the archive
    1119   //    comment : Comment associated with the archive file
    1120   //    status : not_exist, ok
     1118  //    nb : Number of files in the archive
     1119  //    comment : Comment associated with the archive file
     1120  //    status : not_exist, ok
    11211121  // Parameters :
    11221122  //   None
     
    11271127  function properties()
    11281128  {
    1129     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");
    1130 
    1131     // ----- Reset the error handler
    1132     $this->privErrorReset();
    1133 
    1134     // ----- Magic quotes trick
    1135     $this->privDisableMagicQuotes();
    1136 
    1137     // ----- Check archive
    1138     if (!$this->privCheckFormat()) {
    1139       $this->privSwapBackMagicQuotes();
    1140       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    1141       return(0);
    1142     }
    1143 
    1144     // ----- Default properties
    1145     $v_prop = array();
    1146     $v_prop['comment'] = '';
    1147     $v_prop['nb'] = 0;
    1148     $v_prop['status'] = 'not_exist';
    1149 
    1150     // ----- Look if file exists
    1151     if (@is_file($this->zipname))
    1152     {
    1153       // ----- Open the zip file
    1154       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
    1155       if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
    1156       {
    1157         $this->privSwapBackMagicQuotes();
    1158        
    1159         // ----- Error log
    1160         PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
    1161 
    1162         // ----- Return
    1163         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);
    1164         return 0;
    1165       }
    1166 
    1167       // ----- Read the central directory informations
    1168       $v_central_dir = array();
    1169       if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
    1170       {
    1171         $this->privSwapBackMagicQuotes();
    1172         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    1173         return 0;
    1174       }
    1175 
    1176       // ----- Close the zip file
    1177       $this->privCloseFd();
    1178 
    1179       // ----- Set the user attributes
    1180       $v_prop['comment'] = $v_central_dir['comment'];
    1181       $v_prop['nb'] = $v_central_dir['entries'];
    1182       $v_prop['status'] = 'ok';
    1183     }
    1184 
    1185     // ----- Magic quotes trick
    1186     $this->privSwapBackMagicQuotes();
    1187 
    1188     // ----- Return
    1189     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);
    1190     return $v_prop;
     1129    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");
     1130
     1131    // ----- Reset the error handler
     1132    $this->privErrorReset();
     1133
     1134    // ----- Magic quotes trick
     1135    $this->privDisableMagicQuotes();
     1136
     1137    // ----- Check archive
     1138    if (!$this->privCheckFormat()) {
     1139      $this->privSwapBackMagicQuotes();
     1140      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     1141      return(0);
     1142    }
     1143
     1144    // ----- Default properties
     1145    $v_prop = array();
     1146    $v_prop['comment'] = '';
     1147    $v_prop['nb'] = 0;
     1148    $v_prop['status'] = 'not_exist';
     1149
     1150    // ----- Look if file exists
     1151    if (@is_file($this->zipname))
     1152    {
     1153      // ----- Open the zip file
     1154      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
     1155      if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
     1156      {
     1157        $this->privSwapBackMagicQuotes();
     1158       
     1159        // ----- Error log
     1160        PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
     1161
     1162        // ----- Return
     1163        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);
     1164        return 0;
     1165      }
     1166
     1167      // ----- Read the central directory informations
     1168      $v_central_dir = array();
     1169      if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
     1170      {
     1171        $this->privSwapBackMagicQuotes();
     1172        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     1173        return 0;
     1174      }
     1175
     1176      // ----- Close the zip file
     1177      $this->privCloseFd();
     1178
     1179      // ----- Set the user attributes
     1180      $v_prop['comment'] = $v_central_dir['comment'];
     1181      $v_prop['nb'] = $v_central_dir['entries'];
     1182      $v_prop['status'] = 'ok';
     1183    }
     1184
     1185    // ----- Magic quotes trick
     1186    $this->privSwapBackMagicQuotes();
     1187
     1188    // ----- Return
     1189    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);
     1190    return $v_prop;
    11911191  }
    11921192  // --------------------------------------------------------------------------------
     
    11991199  // Parameters :
    12001200  //   $p_archive : The filename of a valid archive, or
    1201   //                a valid PclZip object.
     1201  //                a valid PclZip object.
    12021202  // Return Values :
    12031203  //   1 on success.
     
    12061206  function duplicate($p_archive)
    12071207  {
    1208     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");
    1209     $v_result = 1;
    1210 
    1211     // ----- Reset the error handler
    1212     $this->privErrorReset();
    1213 
    1214     // ----- Look if the $p_archive is a PclZip object
    1215     if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
    1216     {
    1217       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");
    1218 
    1219       // ----- Duplicate the archive
    1220       $v_result = $this->privDuplicate($p_archive->zipname);
    1221     }
    1222 
    1223     // ----- Look if the $p_archive is a string (so a filename)
    1224     else if (is_string($p_archive))
    1225     {
    1226       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");
    1227 
    1228       // ----- Check that $p_archive is a valid zip file
    1229       // TBC : Should also check the archive format
    1230       if (!is_file($p_archive)) {
    1231         // ----- Error log
    1232         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
    1233         $v_result = PCLZIP_ERR_MISSING_FILE;
    1234       }
    1235       else {
    1236         // ----- Duplicate the archive
    1237         $v_result = $this->privDuplicate($p_archive);
    1238       }
    1239     }
    1240 
    1241     // ----- Invalid variable
    1242     else
    1243     {
    1244       // ----- Error log
    1245       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
    1246       $v_result = PCLZIP_ERR_INVALID_PARAMETER;
    1247     }
    1248 
    1249     // ----- Return
    1250     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    1251     return $v_result;
     1208    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");
     1209    $v_result = 1;
     1210
     1211    // ----- Reset the error handler
     1212    $this->privErrorReset();
     1213
     1214    // ----- Look if the $p_archive is a PclZip object
     1215    if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
     1216    {
     1217      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");
     1218
     1219      // ----- Duplicate the archive
     1220      $v_result = $this->privDuplicate($p_archive->zipname);
     1221    }
     1222
     1223    // ----- Look if the $p_archive is a string (so a filename)
     1224    else if (is_string($p_archive))
     1225    {
     1226      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");
     1227
     1228      // ----- Check that $p_archive is a valid zip file
     1229      // TBC : Should also check the archive format
     1230      if (!is_file($p_archive)) {
     1231        // ----- Error log
     1232        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
     1233        $v_result = PCLZIP_ERR_MISSING_FILE;
     1234      }
     1235      else {
     1236        // ----- Duplicate the archive
     1237        $v_result = $this->privDuplicate($p_archive);
     1238      }
     1239    }
     1240
     1241    // ----- Invalid variable
     1242    else
     1243    {
     1244      // ----- Error log
     1245      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
     1246      $v_result = PCLZIP_ERR_INVALID_PARAMETER;
     1247    }
     1248
     1249    // ----- Return
     1250    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     1251    return $v_result;
    12521252  }
    12531253  // --------------------------------------------------------------------------------
     
    12621262  // Parameters :
    12631263  //   $p_archive_to_add : It can be directly the filename of a valid zip archive,
    1264   //                       or a PclZip object archive.
     1264  //                       or a PclZip object archive.
    12651265  // Return Values :
    12661266  //   1 on success,
     
    12691269  function merge($p_archive_to_add)
    12701270  {
    1271     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");
    1272     $v_result = 1;
    1273 
    1274     // ----- Reset the error handler
    1275     $this->privErrorReset();
    1276 
    1277     // ----- Check archive
    1278     if (!$this->privCheckFormat()) {
    1279       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    1280       return(0);
    1281     }
    1282 
    1283     // ----- Look if the $p_archive_to_add is a PclZip object
    1284     if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
    1285     {
    1286       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");
    1287 
    1288       // ----- Merge the archive
    1289       $v_result = $this->privMerge($p_archive_to_add);
    1290     }
    1291 
    1292     // ----- Look if the $p_archive_to_add is a string (so a filename)
    1293     else if (is_string($p_archive_to_add))
    1294     {
    1295       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");
    1296 
    1297       // ----- Create a temporary archive
    1298       $v_object_archive = new PclZip($p_archive_to_add);
    1299 
    1300       // ----- Merge the archive
    1301       $v_result = $this->privMerge($v_object_archive);
    1302     }
    1303 
    1304     // ----- Invalid variable
    1305     else
    1306     {
    1307       // ----- Error log
    1308       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
    1309       $v_result = PCLZIP_ERR_INVALID_PARAMETER;
    1310     }
    1311 
    1312     // ----- Return
    1313     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    1314     return $v_result;
     1271    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");
     1272    $v_result = 1;
     1273
     1274    // ----- Reset the error handler
     1275    $this->privErrorReset();
     1276
     1277    // ----- Check archive
     1278    if (!$this->privCheckFormat()) {
     1279      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
     1280      return(0);
     1281    }
     1282
     1283    // ----- Look if the $p_archive_to_add is a PclZip object
     1284    if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
     1285    {
     1286      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");
     1287
     1288      // ----- Merge the archive
     1289      $v_result = $this->privMerge($p_archive_to_add);
     1290    }
     1291
     1292    // ----- Look if the $p_archive_to_add is a string (so a filename)
     1293    else if (is_string($p_archive_to_add))
     1294    {
     1295      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");
     1296
     1297      // ----- Create a temporary archive
     1298      $v_object_archive = new PclZip($p_archive_to_add);
     1299
     1300      // ----- Merge the archive
     1301      $v_result = $this->privMerge($v_object_archive);
     1302    }
     1303
     1304    // ----- Invalid variable
     1305    else
     1306    {
     1307      // ----- Error log
     1308      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
     1309      $v_result = PCLZIP_ERR_INVALID_PARAMETER;
     1310    }
     1311
     1312    // ----- Return
     1313    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     1314    return $v_result;
    13151315  }
    13161316  // --------------------------------------------------------------------------------
     
    13251325  function errorCode()
    13261326  {
    1327     if (PCLZIP_ERROR_EXTERNAL == 1) {
    1328       return(PclErrorCode());
    1329     }
    1330     else {
    1331       return($this->error_code);
    1332     }
     1327    if (PCLZIP_ERROR_EXTERNAL == 1) {
     1328      return(PclErrorCode());
     1329    }
     1330    else {
     1331      return($this->error_code);
     1332    }
    13331333  }
    13341334  // --------------------------------------------------------------------------------
     
    13411341  function errorName($p_with_code=false)
    13421342  {
    1343     $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
    1344                       PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
    1345                       PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
    1346                       PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
    1347                       PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
    1348                       PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
    1349                       PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
    1350                       PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
    1351                       PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
    1352                       PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
    1353                       PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
    1354                       PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
    1355                       PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
    1356                       PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
    1357                       PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
    1358                       PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
    1359                       PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
    1360                       PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
    1361                       PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION',
    1362                       PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE',
    1363                       PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
    1364                     );
    1365 
    1366     if (isset($v_name[$this->error_code])) {
    1367       $v_value = $v_name[$this->error_code];
    1368     }
    1369     else {
    1370       $v_value = 'NoName';
    1371     }
    1372 
    1373     if ($p_with_code) {
    1374       return($v_value.' ('.$this->error_code.')');
    1375     }
    1376     else {
    1377       return($v_value);
    1378     }
     1343    $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
     1344                      PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
     1345                      PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
     1346                      PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
     1347                      PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
     1348                      PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
     1349                      PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
     1350                      PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
     1351                      PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
     1352                      PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
     1353                      PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
     1354                      PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
     1355                      PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
     1356                      PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
     1357                      PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
     1358                      PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
     1359                      PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
     1360                      PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
     1361                      PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
     1362                      ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
     1363                      ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
     1364                    );
     1365
     1366    if (isset($v_name[$this->error_code])) {
     1367      $v_value = $v_name[$this->error_code];
     1368    }
     1369    else {
     1370      $v_value = 'NoName';
     1371    }
     1372
     1373    if ($p_with_code) {
     1374      return($v_value.' ('.$this->error_code.')');
     1375    }
     1376    else {
     1377      return($v_value);
     1378    }
    13791379  }
    13801380  // --------------------------------------------------------------------------------
     
    13871387  function errorInfo($p_full=false)
    13881388  {
    1389     if (PCLZIP_ERROR_EXTERNAL == 1) {
    1390       return(PclErrorString());
    1391     }
    1392     else {
    1393       if ($p_full) {
    1394         return($this->errorName(true)." : ".$this->error_string);
    1395       }
    1396       else {
    1397         return($this->error_string." [code ".$this->error_code."]");
    1398       }
    1399     }
     1389    if (PCLZIP_ERROR_EXTERNAL == 1) {
     1390      return(PclErrorString());
     1391    }
     1392    else {
     1393      if ($p_full) {
     1394        return($this->errorName(true)." : ".$this->error_string);
     1395      }
     1396      else {
     1397        return($this->error_string." [code ".$this->error_code."]");
     1398      }
     1399    }
    14001400  }
    14011401  // --------------------------------------------------------------------------------
     
    14041404// --------------------------------------------------------------------------------
    14051405// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
    1406 // *****       THESES FUNCTIONS MUST NOT BE USED DIRECTLY      *****
     1406// *****                                                        *****
     1407// *****       THESES FUNCTIONS MUST NOT BE USED DIRECTLY       *****
    14071408// --------------------------------------------------------------------------------
    14081409
     
    14161417  // Parameters :
    14171418  //   $p_level : Level of check. Default 0.
    1418   //              0 : Check the first bytes (magic codes) (default value))
    1419   //              1 : 0 + Check the central directory (futur)
    1420   //              2 : 1 + Check each file header (futur)
     1419  //              0 : Check the first bytes (magic codes) (default value))
     1420  //              1 : 0 + Check the central directory (futur)
     1421  //              2 : 1 + Check each file header (futur)
    14211422  // Return Values :
    14221423  //   true on success,
     
    14251426  function privCheckFormat($p_level=0)
    14261427  {
    1427     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");
    1428     $v_result = true;
     1428    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");
     1429    $v_result = true;
    14291430
    14301431    // ----- Reset the file system cache
    1431     clearstatcache();
    1432 
    1433     // ----- Reset the error handler
    1434     $this->privErrorReset();
    1435 
    1436     // ----- Look if the file exits
    1437     if (!is_file($this->zipname)) {
    1438       // ----- Error log
    1439       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
    1440       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
    1441       return(false);
    1442     }
    1443 
    1444     // ----- Check that the file is readeable
    1445     if (!is_readable($this->zipname)) {
    1446       // ----- Error log
    1447       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
    1448       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
    1449       return(false);
    1450     }
    1451 
    1452     // ----- Check the magic code
    1453     // TBC
    1454 
    1455     // ----- Check the central header
    1456     // TBC
    1457 
    1458     // ----- Check each file header
    1459     // TBC
    1460 
    1461     // ----- Return
    1462     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    1463     return $v_result;
     1432    clearstatcache();
     1433
     1434    // ----- Reset the error handler
     1435    $this->privErrorReset();
     1436
     1437    // ----- Look if the file exits
     1438    if (!is_file($this->zipname)) {
     1439      // ----- Error log
     1440      PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
     1441      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
     1442      return(false);
     1443    }
     1444
     1445    // ----- Check that the file is readeable
     1446    if (!is_readable($this->zipname)) {
     1447      // ----- Error log
     1448      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
     1449      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
     1450      return(false);
     1451    }
     1452
     1453    // ----- Check the magic code
     1454    // TBC
     1455
     1456    // ----- Check the central header
     1457    // TBC
     1458
     1459    // ----- Check each file header
     1460    // TBC
     1461
     1462    // ----- Return
     1463    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     1464    return $v_result;
    14641465  }
    14651466  // --------------------------------------------------------------------------------
     
    14821483  function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
    14831484  {
    1484     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");
    1485     $v_result=1;
    1486    
    1487     // ----- Read the options
    1488     $i=0;
    1489     while ($i<$p_size) {
    1490       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'");
    1491 
    1492       // ----- Check if the option is supported
    1493       if (!isset($v_requested_options[$p_options_list[$i]])) {
    1494         // ----- Error log
    1495         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
    1496 
    1497         // ----- Return
    1498         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1499         return PclZip::errorCode();
    1500       }
    1501 
    1502       // ----- Look for next option
    1503       switch ($p_options_list[$i]) {
    1504         // ----- Look for options that request a path value
    1505         case PCLZIP_OPT_PATH :
    1506         case PCLZIP_OPT_REMOVE_PATH :
    1507         case PCLZIP_OPT_ADD_PATH :
    1508           // ----- Check the number of parameters
    1509           if (($i+1) >= $p_size) {
    1510             // ----- Error log
    1511             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1512 
    1513             // ----- Return
    1514             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1515             return PclZip::errorCode();
    1516           }
    1517 
    1518           // ----- Get the value
    1519           $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
    1520           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1521           $i++;
    1522         break;
    1523 
    1524         case PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD :
    1525           // ----- Check the number of parameters
    1526           if (($i+1) >= $p_size) {
    1527             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1528             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1529             return PclZip::errorCode();
    1530           }
    1531          
    1532           // ----- Check for incompatible options
    1533           if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) {
    1534             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_OFF'");
    1535             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1536             return PclZip::errorCode();
    1537           }
    1538          
    1539           // ----- Check the value
    1540           $v_value = $p_options_list[$i+1];
    1541           if ((!is_integer($v_value)) || ($v_value<0)) {
    1542             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1543             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1544             return PclZip::errorCode();
    1545           }
    1546 
    1547           // ----- Get the value (and convert it in bytes)
    1548           $v_result_list[$p_options_list[$i]] = $v_value*1048576;
    1549           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1550           $i++;
    1551         break;
    1552 
    1553         case PCLZIP_OPT_ADD_TEMP_FILE_ON :
    1554           // ----- Check for incompatible options
    1555           if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) {
    1556             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_OFF'");
    1557             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1558             return PclZip::errorCode();
    1559           }
    1560          
    1561           $v_result_list[$p_options_list[$i]] = true;
    1562           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1563         break;
    1564 
    1565         case PCLZIP_OPT_ADD_TEMP_FILE_OFF :
    1566           // ----- Check for incompatible options
    1567           if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_ON])) {
    1568             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_ON'");
    1569             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1570             return PclZip::errorCode();
    1571           }
    1572           // ----- Check for incompatible options
    1573           if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {
    1574             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD'");
    1575             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1576             return PclZip::errorCode();
    1577           }
    1578          
    1579           $v_result_list[$p_options_list[$i]] = true;
    1580           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1581         break;
    1582 
    1583         case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
    1584           // ----- Check the number of parameters
    1585           if (($i+1) >= $p_size) {
    1586             // ----- Error log
    1587             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1588 
    1589             // ----- Return
    1590             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1591             return PclZip::errorCode();
    1592           }
    1593 
    1594           // ----- Get the value
    1595           if (   is_string($p_options_list[$i+1])
    1596               && ($p_options_list[$i+1] != '')) {
    1597             $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
    1598             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1599             $i++;
    1600           }
    1601           else {
    1602             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored.");
    1603           }
    1604         break;
    1605 
    1606         // ----- Look for options that request an array of string for value
    1607         case PCLZIP_OPT_BY_NAME :
    1608           // ----- Check the number of parameters
    1609           if (($i+1) >= $p_size) {
    1610             // ----- Error log
    1611             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1612 
    1613             // ----- Return
    1614             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1615             return PclZip::errorCode();
    1616           }
    1617 
    1618           // ----- Get the value
    1619           if (is_string($p_options_list[$i+1])) {
    1620               $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
    1621           }
    1622           else if (is_array($p_options_list[$i+1])) {
    1623               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
    1624           }
    1625           else {
    1626             // ----- Error log
    1627             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1628 
    1629             // ----- Return
    1630             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1631             return PclZip::errorCode();
    1632           }
    1633           ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1634           $i++;
    1635         break;
    1636 
    1637         // ----- Look for options that request an EREG or PREG expression
    1638         case PCLZIP_OPT_BY_EREG :
    1639         case PCLZIP_OPT_BY_PREG :
    1640         //case PCLZIP_OPT_CRYPT :
    1641           // ----- Check the number of parameters
    1642           if (($i+1) >= $p_size) {
    1643             // ----- Error log
    1644             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1645 
    1646             // ----- Return
    1647             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1648             return PclZip::errorCode();
    1649           }
    1650 
    1651           // ----- Get the value
    1652           if (is_string($p_options_list[$i+1])) {
    1653               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
    1654           }
    1655           else {
    1656             // ----- Error log
    1657             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1658 
    1659             // ----- Return
    1660             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1661             return PclZip::errorCode();
    1662           }
    1663           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1664           $i++;
    1665         break;
    1666 
    1667         // ----- Look for options that takes a string
    1668         case PCLZIP_OPT_COMMENT :
    1669         case PCLZIP_OPT_ADD_COMMENT :
    1670         case PCLZIP_OPT_PREPEND_COMMENT :
    1671           // ----- Check the number of parameters
    1672           if (($i+1) >= $p_size) {
    1673             // ----- Error log
    1674             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
    1675                                 "Missing parameter value for option '"
     1485    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");
     1486    $v_result=1;
     1487   
     1488    // ----- Read the options
     1489    $i=0;
     1490    while ($i<$p_size) {
     1491      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'");
     1492
     1493      // ----- Check if the option is supported
     1494      if (!isset($v_requested_options[$p_options_list[$i]])) {
     1495        // ----- Error log
     1496        PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
     1497
     1498        // ----- Return
     1499        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1500        return PclZip::errorCode();
     1501      }
     1502
     1503      // ----- Look for next option
     1504      switch ($p_options_list[$i]) {
     1505        // ----- Look for options that request a path value
     1506        case PCLZIP_OPT_PATH :
     1507        case PCLZIP_OPT_REMOVE_PATH :
     1508        case PCLZIP_OPT_ADD_PATH :
     1509          // ----- Check the number of parameters
     1510          if (($i+1) >= $p_size) {
     1511            // ----- Error log
     1512            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1513
     1514            // ----- Return
     1515            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1516            return PclZip::errorCode();
     1517          }
     1518
     1519          // ----- Get the value
     1520          $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
     1521          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1522          $i++;
     1523        break;
     1524
     1525        case PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD :
     1526          // ----- Check the number of parameters
     1527          if (($i+1) >= $p_size) {
     1528            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1529            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1530            return PclZip::errorCode();
     1531          }
     1532         
     1533          // ----- Check for incompatible options
     1534          if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) {
     1535            PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_OFF'");
     1536            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1537            return PclZip::errorCode();
     1538          }
     1539         
     1540          // ----- Check the value
     1541          $v_value = $p_options_list[$i+1];
     1542          if ((!is_integer($v_value)) || ($v_value<0)) {
     1543            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1544            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1545            return PclZip::errorCode();
     1546          }
     1547
     1548          // ----- Get the value (and convert it in bytes)
     1549          $v_result_list[$p_options_list[$i]] = $v_value*1048576;
     1550          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1551          $i++;
     1552        break;
     1553
     1554        case PCLZIP_OPT_ADD_TEMP_FILE_ON :
     1555          // ----- Check for incompatible options
     1556          if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) {
     1557            PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_OFF'");
     1558            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1559            return PclZip::errorCode();
     1560          }
     1561         
     1562          $v_result_list[$p_options_list[$i]] = true;
     1563          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1564        break;
     1565
     1566        case PCLZIP_OPT_ADD_TEMP_FILE_OFF :
     1567          // ----- Check for incompatible options
     1568          if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_ON])) {
     1569            PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_ON'");
     1570            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1571            return PclZip::errorCode();
     1572          }
     1573          // ----- Check for incompatible options
     1574          if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {
     1575            PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD'");
     1576            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1577            return PclZip::errorCode();
     1578          }
     1579         
     1580          $v_result_list[$p_options_list[$i]] = true;
     1581          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1582        break;
     1583
     1584        case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
     1585          // ----- Check the number of parameters
     1586          if (($i+1) >= $p_size) {
     1587            // ----- Error log
     1588            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1589
     1590            // ----- Return
     1591            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1592            return PclZip::errorCode();
     1593          }
     1594
     1595          // ----- Get the value
     1596          if (   is_string($p_options_list[$i+1])
     1597              && ($p_options_list[$i+1] != '')) {
     1598            $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
     1599            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1600            $i++;
     1601          }
     1602          else {
     1603            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored.");
     1604          }
     1605        break;
     1606
     1607        // ----- Look for options that request an array of string for value
     1608        case PCLZIP_OPT_BY_NAME :
     1609          // ----- Check the number of parameters
     1610          if (($i+1) >= $p_size) {
     1611            // ----- Error log
     1612            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1613
     1614            // ----- Return
     1615            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1616            return PclZip::errorCode();
     1617          }
     1618
     1619          // ----- Get the value
     1620          if (is_string($p_options_list[$i+1])) {
     1621              $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
     1622          }
     1623          else if (is_array($p_options_list[$i+1])) {
     1624              $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
     1625          }
     1626          else {
     1627            // ----- Error log
     1628            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1629
     1630            // ----- Return
     1631            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1632            return PclZip::errorCode();
     1633          }
     1634          ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1635          $i++;
     1636        break;
     1637
     1638        // ----- Look for options that request an EREG or PREG expression
     1639        case PCLZIP_OPT_BY_EREG :
     1640        case PCLZIP_OPT_BY_PREG :
     1641        //case PCLZIP_OPT_CRYPT :
     1642          // ----- Check the number of parameters
     1643          if (($i+1) >= $p_size) {
     1644            // ----- Error log
     1645            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1646
     1647            // ----- Return
     1648            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1649            return PclZip::errorCode();
     1650          }
     1651
     1652          // ----- Get the value
     1653          if (is_string($p_options_list[$i+1])) {
     1654              $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
     1655          }
     1656          else {
     1657            // ----- Error log
     1658            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1659
     1660            // ----- Return
     1661            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1662            return PclZip::errorCode();
     1663          }
     1664          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1665          $i++;
     1666        break;
     1667
     1668        // ----- Look for options that takes a string
     1669        case PCLZIP_OPT_COMMENT :
     1670        case PCLZIP_OPT_ADD_COMMENT :
     1671        case PCLZIP_OPT_PREPEND_COMMENT :
     1672          // ----- Check the number of parameters
     1673          if (($i+1) >= $p_size) {
     1674            // ----- Error log
     1675            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
     1676                                "Missing parameter value for option '"
    16761677                                 .PclZipUtilOptionText($p_options_list[$i])
    16771678                                 ."'");
    16781679
    1679             // ----- Return
    1680             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1681             return PclZip::errorCode();
    1682           }
    1683 
    1684           // ----- Get the value
    1685           if (is_string($p_options_list[$i+1])) {
    1686               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
    1687           }
    1688           else {
    1689             // ----- Error log
    1690             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
    1691                                 "Wrong parameter value for option '"
     1680            // ----- Return
     1681            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1682            return PclZip::errorCode();
     1683          }
     1684
     1685          // ----- Get the value
     1686          if (is_string($p_options_list[$i+1])) {
     1687              $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
     1688          }
     1689          else {
     1690            // ----- Error log
     1691            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
     1692                                "Wrong parameter value for option '"
    16921693                                 .PclZipUtilOptionText($p_options_list[$i])
    16931694                                 ."'");
    16941695
    1695             // ----- Return
    1696             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1697             return PclZip::errorCode();
    1698           }
    1699           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1700           $i++;
    1701         break;
    1702 
    1703         // ----- Look for options that request an array of index
    1704         case PCLZIP_OPT_BY_INDEX :
    1705           // ----- Check the number of parameters
    1706           if (($i+1) >= $p_size) {
    1707             // ----- Error log
    1708             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1709 
    1710             // ----- Return
    1711             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1712             return PclZip::errorCode();
    1713           }
    1714 
    1715           // ----- Get the value
    1716           $v_work_list = array();
    1717           if (is_string($p_options_list[$i+1])) {
    1718               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'");
    1719 
    1720               // ----- Remove spaces
    1721               $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
    1722 
    1723               // ----- Parse items
    1724               $v_work_list = explode(",", $p_options_list[$i+1]);
    1725           }
    1726           else if (is_integer($p_options_list[$i+1])) {
    1727               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'");
    1728               $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
    1729           }
    1730           else if (is_array($p_options_list[$i+1])) {
    1731               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array");
    1732               $v_work_list = $p_options_list[$i+1];
    1733           }
    1734           else {
    1735             // ----- Error log
    1736             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1737 
    1738             // ----- Return
    1739             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1740             return PclZip::errorCode();
    1741           }
    1742          
    1743           // ----- Reduce the index list
    1744           // each index item in the list must be a couple with a start and
    1745           // an end value : [0,3], [5-5], [8-10], ...
    1746           // ----- Check the format of each item
    1747           $v_sort_flag=false;
    1748           $v_sort_value=0;
    1749           for ($j=0; $j<sizeof($v_work_list); $j++) {
    1750               // ----- Explode the item
    1751               $v_item_list = explode("-", $v_work_list[$j]);
    1752               $v_size_item_list = sizeof($v_item_list);
    1753              
    1754               // ----- TBC : Here we might check that each item is a
    1755               // real integer ...
    1756              
    1757               // ----- Look for single value
    1758               if ($v_size_item_list == 1) {
    1759                   // ----- Set the option value
    1760                   $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
    1761                   $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
    1762               }
    1763               elseif ($v_size_item_list == 2) {
    1764                   // ----- Set the option value
    1765                   $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
    1766                   $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
    1767               }
    1768               else {
    1769                   // ----- Error log
    1770                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1771 
    1772                   // ----- Return
    1773                   //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1774                   return PclZip::errorCode();
    1775               }
    1776 
    1777               //--(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']."]");
    1778 
    1779               // ----- Look for list sort
    1780               if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
    1781                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ...");
    1782                   $v_sort_flag=true;
    1783 
    1784                   // ----- TBC : An automatic sort should be writen ...
    1785                   // ----- Error log
    1786                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1787 
    1788                   // ----- Return
    1789                   //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1790                   return PclZip::errorCode();
    1791               }
    1792               $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
    1793           }
    1794          
    1795           // ----- Sort the items
    1796           if ($v_sort_flag) {
    1797               // TBC : To Be Completed
    1798               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ...");
    1799           }
    1800 
    1801           // ----- Next option
    1802           $i++;
    1803         break;
    1804 
    1805         // ----- Look for options that request no value
    1806         case PCLZIP_OPT_REMOVE_ALL_PATH :
    1807         case PCLZIP_OPT_EXTRACT_AS_STRING :
    1808         case PCLZIP_OPT_NO_COMPRESSION :
    1809         case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
    1810         case PCLZIP_OPT_REPLACE_NEWER :
    1811         case PCLZIP_OPT_STOP_ON_ERROR :
    1812           $v_result_list[$p_options_list[$i]] = true;
    1813           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1814         break;
    1815 
    1816         // ----- Look for options that request an octal value
    1817         case PCLZIP_OPT_SET_CHMOD :
    1818           // ----- Check the number of parameters
    1819           if (($i+1) >= $p_size) {
    1820             // ----- Error log
    1821             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1822 
    1823             // ----- Return
    1824             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1825             return PclZip::errorCode();
    1826           }
    1827 
    1828           // ----- Get the value
    1829           $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
    1830           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
    1831           $i++;
    1832         break;
    1833 
    1834         // ----- Look for options that request a call-back
    1835         case PCLZIP_CB_PRE_EXTRACT :
    1836         case PCLZIP_CB_POST_EXTRACT :
    1837         case PCLZIP_CB_PRE_ADD :
    1838         case PCLZIP_CB_POST_ADD :
    1839         /* for futur use
    1840         case PCLZIP_CB_PRE_DELETE :
    1841         case PCLZIP_CB_POST_DELETE :
    1842         case PCLZIP_CB_PRE_LIST :
    1843         case PCLZIP_CB_POST_LIST :
    1844         */
    1845           // ----- Check the number of parameters
    1846           if (($i+1) >= $p_size) {
    1847             // ----- Error log
    1848             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1849 
    1850             // ----- Return
    1851             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1852             return PclZip::errorCode();
    1853           }
    1854 
    1855           // ----- Get the value
    1856           $v_function_name = $p_options_list[$i+1];
    1857           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'");
    1858 
    1859           // ----- Check that the value is a valid existing function
    1860           if (!function_exists($v_function_name)) {
    1861             // ----- Error log
    1862             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
    1863 
    1864             // ----- Return
    1865             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1866             return PclZip::errorCode();
    1867           }
    1868 
    1869           // ----- Set the attribute
    1870           $v_result_list[$p_options_list[$i]] = $v_function_name;
    1871           $i++;
    1872         break;
    1873 
    1874         default :
    1875           // ----- Error log
    1876           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
    1877                                "Unknown parameter '"
     1696            // ----- Return
     1697            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1698            return PclZip::errorCode();
     1699          }
     1700          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1701          $i++;
     1702        break;
     1703
     1704        // ----- Look for options that request an array of index
     1705        case PCLZIP_OPT_BY_INDEX :
     1706          // ----- Check the number of parameters
     1707          if (($i+1) >= $p_size) {
     1708            // ----- Error log
     1709            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1710
     1711            // ----- Return
     1712            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1713            return PclZip::errorCode();
     1714          }
     1715
     1716          // ----- Get the value
     1717          $v_work_list = array();
     1718          if (is_string($p_options_list[$i+1])) {
     1719              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'");
     1720
     1721              // ----- Remove spaces
     1722              $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
     1723
     1724              // ----- Parse items
     1725              $v_work_list = explode(",", $p_options_list[$i+1]);
     1726          }
     1727          else if (is_integer($p_options_list[$i+1])) {
     1728              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'");
     1729              $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
     1730          }
     1731          else if (is_array($p_options_list[$i+1])) {
     1732              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array");
     1733              $v_work_list = $p_options_list[$i+1];
     1734          }
     1735          else {
     1736            // ----- Error log
     1737            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1738
     1739            // ----- Return
     1740            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1741            return PclZip::errorCode();
     1742          }
     1743         
     1744          // ----- Reduce the index list
     1745          // each index item in the list must be a couple with a start and
     1746          // an end value : [0,3], [5-5], [8-10], ...
     1747          // ----- Check the format of each item
     1748          $v_sort_flag=false;
     1749          $v_sort_value=0;
     1750          for ($j=0; $j<sizeof($v_work_list); $j++) {
     1751              // ----- Explode the item
     1752              $v_item_list = explode("-", $v_work_list[$j]);
     1753              $v_size_item_list = sizeof($v_item_list);
     1754             
     1755              // ----- TBC : Here we might check that each item is a
     1756              // real integer ...
     1757             
     1758              // ----- Look for single value
     1759              if ($v_size_item_list == 1) {
     1760                  // ----- Set the option value
     1761                  $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
     1762                  $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
     1763              }
     1764              elseif ($v_size_item_list == 2) {
     1765                  // ----- Set the option value
     1766                  $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
     1767                  $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
     1768              }
     1769              else {
     1770                  // ----- Error log
     1771                  PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1772
     1773                  // ----- Return
     1774                  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1775                  return PclZip::errorCode();
     1776              }
     1777
     1778              //--(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']."]");
     1779
     1780              // ----- Look for list sort
     1781              if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
     1782                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ...");
     1783                  $v_sort_flag=true;
     1784
     1785                  // ----- TBC : An automatic sort should be writen ...
     1786                  // ----- Error log
     1787                  PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1788
     1789                  // ----- Return
     1790                  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1791                  return PclZip::errorCode();
     1792              }
     1793              $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
     1794          }
     1795         
     1796          // ----- Sort the items
     1797          if ($v_sort_flag) {
     1798              // TBC : To Be Completed
     1799              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ...");
     1800          }
     1801
     1802          // ----- Next option
     1803          $i++;
     1804        break;
     1805
     1806        // ----- Look for options that request no value
     1807        case PCLZIP_OPT_REMOVE_ALL_PATH :
     1808        case PCLZIP_OPT_EXTRACT_AS_STRING :
     1809        case PCLZIP_OPT_NO_COMPRESSION :
     1810        case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
     1811        case PCLZIP_OPT_REPLACE_NEWER :
     1812        case PCLZIP_OPT_STOP_ON_ERROR :
     1813          $v_result_list[$p_options_list[$i]] = true;
     1814          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1815        break;
     1816
     1817        // ----- Look for options that request an octal value
     1818        case PCLZIP_OPT_SET_CHMOD :
     1819          // ----- Check the number of parameters
     1820          if (($i+1) >= $p_size) {
     1821            // ----- Error log
     1822            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1823
     1824            // ----- Return
     1825            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1826            return PclZip::errorCode();
     1827          }
     1828
     1829          // ----- Get the value
     1830          $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
     1831          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
     1832          $i++;
     1833        break;
     1834
     1835        // ----- Look for options that request a call-back
     1836        case PCLZIP_CB_PRE_EXTRACT :
     1837        case PCLZIP_CB_POST_EXTRACT :
     1838        case PCLZIP_CB_PRE_ADD :
     1839        case PCLZIP_CB_POST_ADD :
     1840        /* for futur use
     1841        case PCLZIP_CB_PRE_DELETE :
     1842        case PCLZIP_CB_POST_DELETE :
     1843        case PCLZIP_CB_PRE_LIST :
     1844        case PCLZIP_CB_POST_LIST :
     1845        */
     1846          // ----- Check the number of parameters
     1847          if (($i+1) >= $p_size) {
     1848            // ----- Error log
     1849            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1850
     1851            // ----- Return
     1852            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1853            return PclZip::errorCode();
     1854          }
     1855
     1856          // ----- Get the value
     1857          $v_function_name = $p_options_list[$i+1];
     1858          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'");
     1859
     1860          // ----- Check that the value is a valid existing function
     1861          if (!function_exists($v_function_name)) {
     1862            // ----- Error log
     1863            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     1864
     1865            // ----- Return
     1866            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1867            return PclZip::errorCode();
     1868          }
     1869
     1870          // ----- Set the attribute
     1871          $v_result_list[$p_options_list[$i]] = $v_function_name;
     1872          $i++;
     1873        break;
     1874
     1875        default :
     1876          // ----- Error log
     1877          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
     1878                               "Unknown parameter '"
    18781879                               .$p_options_list[$i]."'");
    18791880
    1880           // ----- Return
    1881           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1882           return PclZip::errorCode();
    1883       }
    1884 
    1885       // ----- Next options
    1886       $i++;
    1887     }
    1888 
    1889     // ----- Look for mandatory options
    1890     if ($v_requested_options !== false) {
    1891       for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
    1892         // ----- Look for mandatory option
    1893         if ($v_requested_options[$key] == 'mandatory') {
    1894           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
    1895           // ----- Look if present
    1896           if (!isset($v_result_list[$key])) {
    1897             // ----- Error log
    1898             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
    1899 
    1900             // ----- Return
    1901             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1902             return PclZip::errorCode();
    1903           }
    1904         }
    1905       }
    1906     }
    1907    
    1908     // ----- Look for default values
    1909     if (!isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {
    1910       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Calculate auto threshold");
    1911      
    1912     }
    1913 
    1914     // ----- Return
    1915     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    1916     return $v_result;
     1881          // ----- Return
     1882          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1883          return PclZip::errorCode();
     1884      }
     1885
     1886      // ----- Next options
     1887      $i++;
     1888    }
     1889
     1890    // ----- Look for mandatory options
     1891    if ($v_requested_options !== false) {
     1892      for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
     1893        // ----- Look for mandatory option
     1894        if ($v_requested_options[$key] == 'mandatory') {
     1895          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
     1896          // ----- Look if present
     1897          if (!isset($v_result_list[$key])) {
     1898            // ----- Error log
     1899            PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
     1900
     1901            // ----- Return
     1902            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1903            return PclZip::errorCode();
     1904          }
     1905        }
     1906      }
     1907    }
     1908   
     1909    // ----- Look for default values
     1910    if (!isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {
     1911      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Calculate auto threshold");
     1912     
     1913    }
     1914
     1915    // ----- Return
     1916    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     1917    return $v_result;
    19171918  }
    19181919  // --------------------------------------------------------------------------------
     
    19261927  function privOptionDefaultThreshold(&$p_options)
    19271928  {
    1928     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOptionDefaultThreshold", "");
    1929     $v_result=1;
    1930    
    1931     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Create an auto-threshold for use of temporay files");
    1932     // ----- Get 'memory_limit' configuration value
    1933     $v_memory_limit = ini_get('memory_limit');
    1934     $v_memory_limit = trim($v_memory_limit);
    1935     $last = strtolower(substr($v_memory_limit, -1));
     1929    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOptionDefaultThreshold", "");
     1930    $v_result=1;
     1931   
     1932    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Create an auto-threshold for use of temporay files");
     1933    // ----- Get 'memory_limit' configuration value
     1934    $v_memory_limit = ini_get('memory_limit');
     1935    $v_memory_limit = trim($v_memory_limit);
     1936    $last = strtolower(substr($v_memory_limit, -1));
    19361937 
    1937     if($last == 'g')
    1938         //$v_memory_limit = $v_memory_limit*1024*1024*1024;
    1939         $v_memory_limit = $v_memory_limit*1073741824;
    1940     if($last == 'm')
    1941         //$v_memory_limit = $v_memory_limit*1024*1024;
    1942         $v_memory_limit = $v_memory_limit*1048576;
    1943     if($last == 'k')
    1944         $v_memory_limit = $v_memory_limit*1024;
    1945            
    1946     $p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] = floor($v_memory_limit/2);
    1947    
    1948     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Threshold value is : ".$p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]." bytes");
    1949 
    1950     // ----- Sanity check : No threshold if value lower than 1M
    1951     if ($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] < 1048576) {
    1952       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Unset the threshold (value ".$p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD].") because under 1Mo sanity check)");
    1953       unset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]);
    1954     }
    1955          
    1956     // ----- Return
    1957     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    1958     return $v_result;
     1938    if($last == 'g')
     1939        //$v_memory_limit = $v_memory_limit*1024*1024*1024;
     1940        $v_memory_limit = $v_memory_limit*1073741824;
     1941    if($last == 'm')
     1942        //$v_memory_limit = $v_memory_limit*1024*1024;
     1943        $v_memory_limit = $v_memory_limit*1048576;
     1944    if($last == 'k')
     1945        $v_memory_limit = $v_memory_limit*1024;
     1946           
     1947    $p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] = floor($v_memory_limit/2);
     1948   
     1949    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Threshold value is : ".$p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]." bytes");
     1950
     1951    // ----- Sanity check : No threshold if value lower than 1M
     1952    if ($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] < 1048576) {
     1953      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Unset the threshold (value ".$p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD].") because under 1Mo sanity check)");
     1954      unset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]);
     1955    }
     1956         
     1957    // ----- Return
     1958    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     1959    return $v_result;
    19591960  }
    19601961  // --------------------------------------------------------------------------------
     
    19701971  function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
    19711972  {
    1972     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", "");
    1973     $v_result=1;
    1974    
    1975     // ----- For each file in the list check the attributes
    1976     foreach ($p_file_list as $v_key => $v_value) {
    1977    
    1978       // ----- Check if the option is supported
    1979       if (!isset($v_requested_options[$v_key])) {
    1980         // ----- Error log
    1981         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
    1982 
    1983         // ----- Return
    1984         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1985         return PclZip::errorCode();
    1986       }
    1987 
    1988       // ----- Look for attribute
    1989       switch ($v_key) {
    1990         case PCLZIP_ATT_FILE_NAME :
    1991           if (!is_string($v_value)) {
    1992             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
    1993             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    1994             return PclZip::errorCode();
    1995           }
    1996 
    1997           $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
    1998           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
    1999          
    2000           if ($p_filedescr['filename'] == '') {
    2001             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
    2002             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2003             return PclZip::errorCode();
    2004           }
    2005 
    2006         break;
    2007 
    2008         case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
    2009           if (!is_string($v_value)) {
    2010             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
    2011             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2012             return PclZip::errorCode();
    2013           }
    2014 
    2015           $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
    2016           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
    2017 
    2018           if ($p_filedescr['new_short_name'] == '') {
    2019             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
    2020             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2021             return PclZip::errorCode();
    2022           }
    2023         break;
    2024 
    2025         case PCLZIP_ATT_FILE_NEW_FULL_NAME :
    2026           if (!is_string($v_value)) {
    2027             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
    2028             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2029             return PclZip::errorCode();
    2030           }
    2031 
    2032           $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
    2033           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
    2034 
    2035           if ($p_filedescr['new_full_name'] == '') {
    2036             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
    2037             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2038             return PclZip::errorCode();
    2039           }
    2040         break;
    2041 
    2042         // ----- Look for options that takes a string
    2043         case PCLZIP_ATT_FILE_COMMENT :
    2044           if (!is_string($v_value)) {
    2045             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
    2046             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2047             return PclZip::errorCode();
    2048           }
    2049 
    2050           $p_filedescr['comment'] = $v_value;
    2051           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
    2052         break;
    2053 
    2054         case PCLZIP_ATT_FILE_MTIME :
    2055           if (!is_integer($v_value)) {
    2056             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
    2057             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2058             return PclZip::errorCode();
    2059           }
    2060 
    2061           $p_filedescr['mtime'] = $v_value;
    2062           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
    2063         break;
    2064 
    2065         case PCLZIP_ATT_FILE_CONTENT :
    2066           $p_filedescr['content'] = $v_value;
    2067           ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
    2068         break;
    2069 
    2070         default :
    2071           // ----- Error log
    2072           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
    2073                                    "Unknown parameter '".$v_key."'");
    2074 
    2075           // ----- Return
    2076           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2077           return PclZip::errorCode();
    2078       }
    2079 
    2080       // ----- Look for mandatory options
    2081       if ($v_requested_options !== false) {
    2082         for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
    2083           // ----- Look for mandatory option
    2084           if ($v_requested_options[$key] == 'mandatory') {
    2085             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
    2086             // ----- Look if present
    2087             if (!isset($p_file_list[$key])) {
    2088               PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
    2089               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2090               return PclZip::errorCode();
    2091             }
    2092           }
    2093         }
    2094       }
    2095    
    2096     // end foreach
    2097     }
    2098    
    2099     // ----- Return
    2100     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2101     return $v_result;
     1973    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", "");
     1974    $v_result=1;
     1975   
     1976    // ----- For each file in the list check the attributes
     1977    foreach ($p_file_list as $v_key => $v_value) {
     1978   
     1979      // ----- Check if the option is supported
     1980      if (!isset($v_requested_options[$v_key])) {
     1981        // ----- Error log
     1982        PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
     1983
     1984        // ----- Return
     1985        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1986        return PclZip::errorCode();
     1987      }
     1988
     1989      // ----- Look for attribute
     1990      switch ($v_key) {
     1991        case PCLZIP_ATT_FILE_NAME :
     1992          if (!is_string($v_value)) {
     1993            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
     1994            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     1995            return PclZip::errorCode();
     1996          }
     1997
     1998          $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
     1999          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
     2000         
     2001          if ($p_filedescr['filename'] == '') {
     2002            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
     2003            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2004            return PclZip::errorCode();
     2005          }
     2006
     2007        break;
     2008
     2009        case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
     2010          if (!is_string($v_value)) {
     2011            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
     2012            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2013            return PclZip::errorCode();
     2014          }
     2015
     2016          $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
     2017          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
     2018
     2019          if ($p_filedescr['new_short_name'] == '') {
     2020            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
     2021            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2022            return PclZip::errorCode();
     2023          }
     2024        break;
     2025
     2026        case PCLZIP_ATT_FILE_NEW_FULL_NAME :
     2027          if (!is_string($v_value)) {
     2028            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
     2029            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2030            return PclZip::errorCode();
     2031          }
     2032
     2033          $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
     2034          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
     2035
     2036          if ($p_filedescr['new_full_name'] == '') {
     2037            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
     2038            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2039            return PclZip::errorCode();
     2040          }
     2041        break;
     2042
     2043        // ----- Look for options that takes a string
     2044        case PCLZIP_ATT_FILE_COMMENT :
     2045          if (!is_string($v_value)) {
     2046            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
     2047            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2048            return PclZip::errorCode();
     2049          }
     2050
     2051          $p_filedescr['comment'] = $v_value;
     2052          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
     2053        break;
     2054
     2055        case PCLZIP_ATT_FILE_MTIME :
     2056          if (!is_integer($v_value)) {
     2057            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
     2058            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2059            return PclZip::errorCode();
     2060          }
     2061
     2062          $p_filedescr['mtime'] = $v_value;
     2063          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
     2064        break;
     2065
     2066        case PCLZIP_ATT_FILE_CONTENT :
     2067          $p_filedescr['content'] = $v_value;
     2068          ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
     2069        break;
     2070
     2071        default :
     2072          // ----- Error log
     2073          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
     2074                                   "Unknown parameter '".$v_key."'");
     2075
     2076          // ----- Return
     2077          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2078          return PclZip::errorCode();
     2079      }
     2080
     2081      // ----- Look for mandatory options
     2082      if ($v_requested_options !== false) {
     2083        for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
     2084          // ----- Look for mandatory option
     2085          if ($v_requested_options[$key] == 'mandatory') {
     2086            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
     2087            // ----- Look if present
     2088            if (!isset($p_file_list[$key])) {
     2089              PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
     2090              //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2091              return PclZip::errorCode();
     2092            }
     2093          }
     2094        }
     2095      }
     2096   
     2097    // end foreach
     2098    }
     2099   
     2100    // ----- Return
     2101    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2102    return $v_result;
    21022103  }
    21032104  // --------------------------------------------------------------------------------
     
    21192120  function privFileDescrExpand(&$p_filedescr_list, &$p_options)
    21202121  {
    2121     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", "");
    2122     $v_result=1;
    2123    
    2124     // ----- Create a result list
    2125     $v_result_list = array();
    2126    
    2127     // ----- Look each entry
    2128     for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
    2129       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i.".");
    2130      
    2131       // ----- Get filedescr
    2132       $v_descr = $p_filedescr_list[$i];
    2133      
    2134       // ----- Reduce the filename
    2135       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'");
    2136       $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
    2137       $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
    2138       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'");
    2139      
    2140       // ----- Look for real file or folder
    2141       if (file_exists($v_descr['filename'])) {
    2142         if (@is_file($v_descr['filename'])) {
    2143           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file");
    2144           $v_descr['type'] = 'file';
    2145         }
    2146         else if (@is_dir($v_descr['filename'])) {
    2147           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder");
    2148           $v_descr['type'] = 'folder';
    2149         }
    2150         else if (@is_link($v_descr['filename'])) {
    2151           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link");
    2152           // skip
    2153           continue;
    2154         }
    2155         else {
    2156           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type");
    2157           // skip
    2158           continue;
    2159         }
    2160       }
    2161      
    2162       // ----- Look for string added as file
    2163       else if (isset($v_descr['content'])) {
    2164         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a string added as a file");
    2165         $v_descr['type'] = 'virtual_file';
    2166       }
    2167      
    2168       // ----- Missing file
    2169       else {
    2170         // ----- Error log
    2171         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exist");
    2172         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
    2173 
    2174         // ----- Return
    2175         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2176         return PclZip::errorCode();
    2177       }
    2178      
    2179       // ----- Calculate the stored filename
    2180       $this->privCalculateStoredFilename($v_descr, $p_options);
    2181      
    2182       // ----- Add the descriptor in result list
    2183       $v_result_list[sizeof($v_result_list)] = $v_descr;
    2184      
    2185       // ----- Look for folder
    2186       if ($v_descr['type'] == 'folder') {
    2187         // ----- List of items in folder
    2188         $v_dirlist_descr = array();
    2189         $v_dirlist_nb = 0;
    2190         if ($v_folder_handler = @opendir($v_descr['filename'])) {
    2191           while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
    2192             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory");
    2193 
    2194             // ----- Skip '.' and '..'
    2195             if (($v_item_handler == '.') || ($v_item_handler == '..')) {
    2196                 continue;
    2197             }
    2198            
    2199             // ----- Compose the full filename
    2200             $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
    2201            
    2202             // ----- Look for different stored filename
    2203             // Because the name of the folder was changed, the name of the
    2204             // files/sub-folders also change
    2205             if ($v_descr['stored_filename'] != $v_descr['filename']) {
    2206               if ($v_descr['stored_filename'] != '') {
    2207                 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
    2208               }
    2209               else {
    2210                 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
    2211               }
    2212             }
    2213      
    2214             $v_dirlist_nb++;
    2215           }
    2216          
    2217           @closedir($v_folder_handler);
    2218         }
    2219         else {
    2220           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped.");
    2221           // TBC : unable to open folder in read mode
    2222         }
    2223        
    2224         // ----- Expand each element of the list
    2225         if ($v_dirlist_nb != 0) {
    2226           // ----- Expand
    2227           if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
    2228             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2229             return $v_result;
    2230           }
    2231          
    2232           // ----- Concat the resulting list
    2233           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')");
    2234           $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
    2235           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'");
    2236         }
    2237         else {
    2238           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand.");
    2239         }
    2240          
    2241         // ----- Free local array
    2242         unset($v_dirlist_descr);
    2243       }
    2244     }
    2245    
    2246     // ----- Get the result list
    2247     $p_filedescr_list = $v_result_list;
    2248 
    2249     // ----- Return
    2250     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2251     return $v_result;
     2122    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", "");
     2123    $v_result=1;
     2124   
     2125    // ----- Create a result list
     2126    $v_result_list = array();
     2127   
     2128    // ----- Look each entry
     2129    for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
     2130      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i.".");
     2131     
     2132      // ----- Get filedescr
     2133      $v_descr = $p_filedescr_list[$i];
     2134     
     2135      // ----- Reduce the filename
     2136      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'");
     2137      $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
     2138      $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
     2139      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'");
     2140     
     2141      // ----- Look for real file or folder
     2142      if (file_exists($v_descr['filename'])) {
     2143        if (@is_file($v_descr['filename'])) {
     2144          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file");
     2145          $v_descr['type'] = 'file';
     2146        }
     2147        else if (@is_dir($v_descr['filename'])) {
     2148          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder");
     2149          $v_descr['type'] = 'folder';
     2150        }
     2151        else if (@is_link($v_descr['filename'])) {
     2152          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link");
     2153          // skip
     2154          continue;
     2155        }
     2156        else {
     2157          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type");
     2158          // skip
     2159          continue;
     2160        }
     2161      }
     2162     
     2163      // ----- Look for string added as file
     2164      else if (isset($v_descr['content'])) {
     2165        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a string added as a file");
     2166        $v_descr['type'] = 'virtual_file';
     2167      }
     2168     
     2169      // ----- Missing file
     2170      else {
     2171        // ----- Error log
     2172        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exist");
     2173        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
     2174
     2175        // ----- Return
     2176        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2177        return PclZip::errorCode();
     2178      }
     2179     
     2180      // ----- Calculate the stored filename
     2181      $this->privCalculateStoredFilename($v_descr, $p_options);
     2182     
     2183      // ----- Add the descriptor in result list
     2184      $v_result_list[sizeof($v_result_list)] = $v_descr;
     2185     
     2186      // ----- Look for folder
     2187      if ($v_descr['type'] == 'folder') {
     2188        // ----- List of items in folder
     2189        $v_dirlist_descr = array();
     2190        $v_dirlist_nb = 0;
     2191        if ($v_folder_handler = @opendir($v_descr['filename'])) {
     2192          while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
     2193            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory");
     2194
     2195            // ----- Skip '.' and '..'
     2196            if (($v_item_handler == '.') || ($v_item_handler == '..')) {
     2197                continue;
     2198            }
     2199           
     2200            // ----- Compose the full filename
     2201            $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
     2202           
     2203            // ----- Look for different stored filename
     2204            // Because the name of the folder was changed, the name of the
     2205            // files/sub-folders also change
     2206            if ($v_descr['stored_filename'] != $v_descr['filename']) {
     2207              if ($v_descr['stored_filename'] != '') {
     2208                $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
     2209              }
     2210              else {
     2211                $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
     2212              }
     2213            }
     2214     
     2215            $v_dirlist_nb++;
     2216          }
     2217         
     2218          @closedir($v_folder_handler);
     2219        }
     2220        else {
     2221          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped.");
     2222          // TBC : unable to open folder in read mode
     2223        }
     2224       
     2225        // ----- Expand each element of the list
     2226        if ($v_dirlist_nb != 0) {
     2227          // ----- Expand
     2228          if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
     2229            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2230            return $v_result;
     2231          }
     2232         
     2233          // ----- Concat the resulting list
     2234          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')");
     2235          $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
     2236          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'");
     2237        }
     2238        else {
     2239          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand.");
     2240        }
     2241         
     2242        // ----- Free local array
     2243        unset($v_dirlist_descr);
     2244      }
     2245    }
     2246   
     2247    // ----- Get the result list
     2248    $p_filedescr_list = $v_result_list;
     2249
     2250    // ----- Return
     2251    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2252    return $v_result;
    22522253  }
    22532254  // --------------------------------------------------------------------------------
     
    22612262  function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
    22622263  {
    2263     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list");
    2264     $v_result=1;
    2265     $v_list_detail = array();
    2266    
    2267     // ----- Magic quotes trick
    2268     $this->privDisableMagicQuotes();
    2269 
    2270     // ----- Open the file in write mode
    2271     if (($v_result = $this->privOpenFd('wb')) != 1)
    2272     {
    2273       // ----- Return
    2274       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2275       return $v_result;
    2276     }
    2277 
    2278     // ----- Add the list of files
    2279     $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
    2280 
    2281     // ----- Close
    2282     $this->privCloseFd();
    2283 
    2284     // ----- Magic quotes trick
    2285     $this->privSwapBackMagicQuotes();
    2286 
    2287     // ----- Return
    2288     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2289     return $v_result;
     2264    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list");
     2265    $v_result=1;
     2266    $v_list_detail = array();
     2267   
     2268    // ----- Magic quotes trick
     2269    $this->privDisableMagicQuotes();
     2270
     2271    // ----- Open the file in write mode
     2272    if (($v_result = $this->privOpenFd('wb')) != 1)
     2273    {
     2274      // ----- Return
     2275      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2276      return $v_result;
     2277    }
     2278
     2279    // ----- Add the list of files
     2280    $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
     2281
     2282    // ----- Close
     2283    $this->privCloseFd();
     2284
     2285    // ----- Magic quotes trick
     2286    $this->privSwapBackMagicQuotes();
     2287
     2288    // ----- Return
     2289    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2290    return $v_result;
    22902291  }
    22912292  // --------------------------------------------------------------------------------
     
    22992300  function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
    23002301  {
    2301     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list");
    2302     $v_result=1;
    2303     $v_list_detail = array();
    2304 
    2305     // ----- Look if the archive exists or is empty
    2306     if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
    2307     {
    2308       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it.");
    2309 
    2310       // ----- Do a create
    2311       $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
    2312 
    2313       // ----- Return
    2314       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2315       return $v_result;
    2316     }
    2317     // ----- Magic quotes trick
    2318     $this->privDisableMagicQuotes();
    2319 
    2320     // ----- Open the zip file
    2321     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
    2322     if (($v_result=$this->privOpenFd('rb')) != 1)
    2323     {
    2324       // ----- Magic quotes trick
    2325       $this->privSwapBackMagicQuotes();
    2326 
    2327       // ----- Return
    2328       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2329       return $v_result;
    2330     }
    2331 
    2332     // ----- Read the central directory informations
    2333     $v_central_dir = array();
    2334     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
    2335     {
    2336       $this->privCloseFd();
    2337       $this->privSwapBackMagicQuotes();
    2338       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2339       return $v_result;
    2340     }
    2341 
    2342     // ----- Go to beginning of File
    2343     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
    2344     @rewind($this->zip_fd);
    2345     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
    2346 
    2347     // ----- Creates a temporay file
    2348     $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
    2349 
    2350     // ----- Open the temporary file in write mode
    2351     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
    2352     if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
    2353     {
    2354       $this->privCloseFd();
    2355       $this->privSwapBackMagicQuotes();
    2356 
    2357       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
    2358 
    2359       // ----- Return
    2360       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2361       return PclZip::errorCode();
    2362     }
    2363 
    2364     // ----- Copy the files from the archive to the temporary file
    2365     // TBC : Here I should better append the file and go back to erase the central dir
    2366     $v_size = $v_central_dir['offset'];
    2367     while ($v_size != 0)
    2368     {
    2369       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
    2370       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
    2371       $v_buffer = fread($this->zip_fd, $v_read_size);
    2372       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
    2373       $v_size -= $v_read_size;
    2374     }
    2375 
    2376     // ----- Swap the file descriptor
    2377     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
    2378     // the following methods on the temporary fil and not the real archive
    2379     $v_swap = $this->zip_fd;
    2380     $this->zip_fd = $v_zip_temp_fd;
    2381     $v_zip_temp_fd = $v_swap;
    2382 
    2383     // ----- Add the files
    2384     $v_header_list = array();
    2385     if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
    2386     {
    2387       fclose($v_zip_temp_fd);
    2388       $this->privCloseFd();
    2389       @unlink($v_zip_temp_name);
    2390       $this->privSwapBackMagicQuotes();
    2391 
    2392       // ----- Return
    2393       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2394       return $v_result;
    2395     }
    2396 
    2397     // ----- Store the offset of the central dir
    2398     $v_offset = @ftell($this->zip_fd);
    2399     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");
    2400 
    2401     // ----- Copy the block of file headers from the old archive
    2402     $v_size = $v_central_dir['size'];
    2403     while ($v_size != 0)
    2404     {
    2405       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
    2406       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
    2407       $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
    2408       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
    2409       $v_size -= $v_read_size;
    2410     }
    2411 
    2412     // ----- Create the Central Dir files header
    2413     for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
    2414     {
    2415       // ----- Create the file header
    2416       if ($v_header_list[$i]['status'] == 'ok') {
    2417         if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
    2418           fclose($v_zip_temp_fd);
    2419           $this->privCloseFd();
    2420           @unlink($v_zip_temp_name);
    2421           $this->privSwapBackMagicQuotes();
    2422 
    2423           // ----- Return
    2424           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2425           return $v_result;
    2426         }
    2427         $v_count++;
    2428       }
    2429 
    2430       // ----- Transform the header to a 'usable' info
    2431       $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
    2432     }
    2433 
    2434     // ----- Zip file comment
    2435     $v_comment = $v_central_dir['comment'];
    2436     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
    2437       $v_comment = $p_options[PCLZIP_OPT_COMMENT];
    2438     }
    2439     if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
    2440       $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
    2441     }
    2442     if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
    2443       $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
    2444     }
    2445 
    2446     // ----- Calculate the size of the central header
    2447     $v_size = @ftell($this->zip_fd)-$v_offset;
    2448 
    2449     // ----- Create the central dir footer
    2450     if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
    2451     {
    2452       // ----- Reset the file list
    2453       unset($v_header_list);
    2454       $this->privSwapBackMagicQuotes();
    2455 
    2456       // ----- Return
    2457       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2458       return $v_result;
    2459     }
    2460 
    2461     // ----- Swap back the file descriptor
    2462     $v_swap = $this->zip_fd;
    2463     $this->zip_fd = $v_zip_temp_fd;
    2464     $v_zip_temp_fd = $v_swap;
    2465 
    2466     // ----- Close
    2467     $this->privCloseFd();
    2468 
    2469     // ----- Close the temporary file
    2470     @fclose($v_zip_temp_fd);
    2471 
    2472     // ----- Magic quotes trick
    2473     $this->privSwapBackMagicQuotes();
    2474 
    2475     // ----- Delete the zip file
    2476     // TBC : I should test the result ...
    2477     @unlink($this->zipname);
    2478 
    2479     // ----- Rename the temporary file
    2480     // TBC : I should test the result ...
    2481     //@rename($v_zip_temp_name, $this->zipname);
    2482     PclZipUtilRename($v_zip_temp_name, $this->zipname);
    2483 
    2484     // ----- Return
    2485     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2486     return $v_result;
     2302    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list");
     2303    $v_result=1;
     2304    $v_list_detail = array();
     2305
     2306    // ----- Look if the archive exists or is empty
     2307    if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
     2308    {
     2309      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it.");
     2310
     2311      // ----- Do a create
     2312      $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
     2313
     2314      // ----- Return
     2315      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2316      return $v_result;
     2317    }
     2318    // ----- Magic quotes trick
     2319    $this->privDisableMagicQuotes();
     2320
     2321    // ----- Open the zip file
     2322    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
     2323    if (($v_result=$this->privOpenFd('rb')) != 1)
     2324    {
     2325      // ----- Magic quotes trick
     2326      $this->privSwapBackMagicQuotes();
     2327
     2328      // ----- Return
     2329      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2330      return $v_result;
     2331    }
     2332
     2333    // ----- Read the central directory informations
     2334    $v_central_dir = array();
     2335    if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
     2336    {
     2337      $this->privCloseFd();
     2338      $this->privSwapBackMagicQuotes();
     2339      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2340      return $v_result;
     2341    }
     2342
     2343    // ----- Go to beginning of File
     2344    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
     2345    @rewind($this->zip_fd);
     2346    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
     2347
     2348    // ----- Creates a temporay file
     2349    $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
     2350
     2351    // ----- Open the temporary file in write mode
     2352    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
     2353    if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
     2354    {
     2355      $this->privCloseFd();
     2356      $this->privSwapBackMagicQuotes();
     2357
     2358      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
     2359
     2360      // ----- Return
     2361      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2362      return PclZip::errorCode();
     2363    }
     2364
     2365    // ----- Copy the files from the archive to the temporary file
     2366    // TBC : Here I should better append the file and go back to erase the central dir
     2367    $v_size = $v_central_dir['offset'];
     2368    while ($v_size != 0)
     2369    {
     2370      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
     2371      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
     2372      $v_buffer = fread($this->zip_fd, $v_read_size);
     2373      @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
     2374      $v_size -= $v_read_size;
     2375    }
     2376
     2377    // ----- Swap the file descriptor
     2378    // Here is a trick : I swap the temporary fd with the zip fd, in order to use
     2379    // the following methods on the temporary fil and not the real archive
     2380    $v_swap = $this->zip_fd;
     2381    $this->zip_fd = $v_zip_temp_fd;
     2382    $v_zip_temp_fd = $v_swap;
     2383
     2384    // ----- Add the files
     2385    $v_header_list = array();
     2386    if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
     2387    {
     2388      fclose($v_zip_temp_fd);
     2389      $this->privCloseFd();
     2390      @unlink($v_zip_temp_name);
     2391      $this->privSwapBackMagicQuotes();
     2392
     2393      // ----- Return
     2394      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2395      return $v_result;
     2396    }
     2397
     2398    // ----- Store the offset of the central dir
     2399    $v_offset = @ftell($this->zip_fd);
     2400    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");
     2401
     2402    // ----- Copy the block of file headers from the old archive
     2403    $v_size = $v_central_dir['size'];
     2404    while ($v_size != 0)
     2405    {
     2406      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
     2407      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
     2408      $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
     2409      @fwrite($this->zip_fd, $v_buffer, $v_read_size);
     2410      $v_size -= $v_read_size;
     2411    }
     2412
     2413    // ----- Create the Central Dir files header
     2414    for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
     2415    {
     2416      // ----- Create the file header
     2417      if ($v_header_list[$i]['status'] == 'ok') {
     2418        if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
     2419          fclose($v_zip_temp_fd);
     2420          $this->privCloseFd();
     2421          @unlink($v_zip_temp_name);
     2422          $this->privSwapBackMagicQuotes();
     2423
     2424          // ----- Return
     2425          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2426          return $v_result;
     2427        }
     2428        $v_count++;
     2429      }
     2430
     2431      // ----- Transform the header to a 'usable' info
     2432      $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
     2433    }
     2434
     2435    // ----- Zip file comment
     2436    $v_comment = $v_central_dir['comment'];
     2437    if (isset($p_options[PCLZIP_OPT_COMMENT])) {
     2438      $v_comment = $p_options[PCLZIP_OPT_COMMENT];
     2439    }
     2440    if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
     2441      $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
     2442    }
     2443    if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
     2444      $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
     2445    }
     2446
     2447    // ----- Calculate the size of the central header
     2448    $v_size = @ftell($this->zip_fd)-$v_offset;
     2449
     2450    // ----- Create the central dir footer
     2451    if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
     2452    {
     2453      // ----- Reset the file list
     2454      unset($v_header_list);
     2455      $this->privSwapBackMagicQuotes();
     2456
     2457      // ----- Return
     2458      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2459      return $v_result;
     2460    }
     2461
     2462    // ----- Swap back the file descriptor
     2463    $v_swap = $this->zip_fd;
     2464    $this->zip_fd = $v_zip_temp_fd;
     2465    $v_zip_temp_fd = $v_swap;
     2466
     2467    // ----- Close
     2468    $this->privCloseFd();
     2469
     2470    // ----- Close the temporary file
     2471    @fclose($v_zip_temp_fd);
     2472
     2473    // ----- Magic quotes trick
     2474    $this->privSwapBackMagicQuotes();
     2475
     2476    // ----- Delete the zip file
     2477    // TBC : I should test the result ...
     2478    @unlink($this->zipname);
     2479
     2480    // ----- Rename the temporary file
     2481    // TBC : I should test the result ...
     2482    //@rename($v_zip_temp_name, $this->zipname);
     2483    PclZipUtilRename($v_zip_temp_name, $this->zipname);
     2484
     2485    // ----- Return
     2486    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2487    return $v_result;
    24872488  }
    24882489  // --------------------------------------------------------------------------------
     
    24952496  function privOpenFd($p_mode)
    24962497  {
    2497     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode);
    2498     $v_result=1;
    2499 
    2500     // ----- Look if already open
    2501     if ($this->zip_fd != 0)
    2502     {
    2503       // ----- Error log
    2504       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
    2505 
    2506       // ----- Return
    2507       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2508       return PclZip::errorCode();
    2509     }
    2510 
    2511     // ----- Open the zip file
    2512     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode');
    2513     if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
    2514     {
    2515       // ----- Error log
    2516       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
    2517 
    2518       // ----- Return
    2519       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2520       return PclZip::errorCode();
    2521     }
    2522 
    2523     // ----- Return
    2524     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2525     return $v_result;
     2498    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode);
     2499    $v_result=1;
     2500
     2501    // ----- Look if already open
     2502    if ($this->zip_fd != 0)
     2503    {
     2504      // ----- Error log
     2505      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
     2506
     2507      // ----- Return
     2508      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2509      return PclZip::errorCode();
     2510    }
     2511
     2512    // ----- Open the zip file
     2513    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode');
     2514    if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
     2515    {
     2516      // ----- Error log
     2517      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
     2518
     2519      // ----- Return
     2520      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2521      return PclZip::errorCode();
     2522    }
     2523
     2524    // ----- Return
     2525    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2526    return $v_result;
    25262527  }
    25272528  // --------------------------------------------------------------------------------
     
    25342535  function privCloseFd()
    25352536  {
    2536     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", "");
    2537     $v_result=1;
    2538 
    2539     if ($this->zip_fd != 0)
    2540       @fclose($this->zip_fd);
    2541     $this->zip_fd = 0;
    2542 
    2543     // ----- Return
    2544     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2545     return $v_result;
     2537    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", "");
     2538    $v_result=1;
     2539
     2540    if ($this->zip_fd != 0)
     2541      @fclose($this->zip_fd);
     2542    $this->zip_fd = 0;
     2543
     2544    // ----- Return
     2545    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2546    return $v_result;
    25462547  }
    25472548  // --------------------------------------------------------------------------------
     
    25632564  function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
    25642565  {
    2565     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list");
    2566     $v_result=1;
    2567 
    2568     // ----- Add the files
    2569     $v_header_list = array();
    2570     if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
    2571     {
    2572       // ----- Return
    2573       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2574       return $v_result;
    2575     }
    2576 
    2577     // ----- Store the offset of the central dir
    2578     $v_offset = @ftell($this->zip_fd);
    2579 
    2580     // ----- Create the Central Dir files header
    2581     for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
    2582     {
    2583       // ----- Create the file header
    2584       if ($v_header_list[$i]['status'] == 'ok') {
    2585         if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
    2586           // ----- Return
    2587           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2588           return $v_result;
    2589         }
    2590         $v_count++;
    2591       }
    2592 
    2593       // ----- Transform the header to a 'usable' info
    2594       $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
    2595     }
    2596 
    2597     // ----- Zip file comment
    2598     $v_comment = '';
    2599     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
    2600       $v_comment = $p_options[PCLZIP_OPT_COMMENT];
    2601     }
    2602 
    2603     // ----- Calculate the size of the central header
    2604     $v_size = @ftell($this->zip_fd)-$v_offset;
    2605 
    2606     // ----- Create the central dir footer
    2607     if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
    2608     {
    2609       // ----- Reset the file list
    2610       unset($v_header_list);
    2611 
    2612       // ----- Return
    2613       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2614       return $v_result;
    2615     }
    2616 
    2617     // ----- Return
    2618     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2619     return $v_result;
     2566    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list");
     2567    $v_result=1;
     2568
     2569    // ----- Add the files
     2570    $v_header_list = array();
     2571    if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
     2572    {
     2573      // ----- Return
     2574      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2575      return $v_result;
     2576    }
     2577
     2578    // ----- Store the offset of the central dir
     2579    $v_offset = @ftell($this->zip_fd);
     2580
     2581    // ----- Create the Central Dir files header
     2582    for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
     2583    {
     2584      // ----- Create the file header
     2585      if ($v_header_list[$i]['status'] == 'ok') {
     2586        if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
     2587          // ----- Return
     2588          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2589          return $v_result;
     2590        }
     2591        $v_count++;
     2592      }
     2593
     2594      // ----- Transform the header to a 'usable' info
     2595      $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
     2596    }
     2597
     2598    // ----- Zip file comment
     2599    $v_comment = '';
     2600    if (isset($p_options[PCLZIP_OPT_COMMENT])) {
     2601      $v_comment = $p_options[PCLZIP_OPT_COMMENT];
     2602    }
     2603
     2604    // ----- Calculate the size of the central header
     2605    $v_size = @ftell($this->zip_fd)-$v_offset;
     2606
     2607    // ----- Create the central dir footer
     2608    if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
     2609    {
     2610      // ----- Reset the file list
     2611      unset($v_header_list);
     2612
     2613      // ----- Return
     2614      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2615      return $v_result;
     2616    }
     2617
     2618    // ----- Return
     2619    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2620    return $v_result;
    26202621  }
    26212622  // --------------------------------------------------------------------------------
     
    26262627  // Parameters :
    26272628  //   $p_filedescr_list : An array containing the file description
    2628   //                      or directory names to add in the zip
     2629  //                      or directory names to add in the zip
    26292630  //   $p_result_list : list of added files with their properties (specially the status field)
    26302631  // Return Values :
     
    26322633  function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
    26332634  {
    2634     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list");
    2635     $v_result=1;
    2636     $v_header = array();
    2637 
    2638     // ----- Recuperate the current number of elt in list
    2639     $v_nb = sizeof($p_result_list);
    2640     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements");
    2641 
    2642     // ----- Loop on the files
    2643     for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
    2644       // ----- Format the filename
    2645       $p_filedescr_list[$j]['filename']
    2646       = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
    2647      
    2648       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'");
    2649 
    2650       // ----- Skip empty file names
    2651       // TBC : Can this be possible ? not checked in DescrParseAtt ?
    2652       if ($p_filedescr_list[$j]['filename'] == "") {
    2653         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");
    2654         continue;
    2655       }
    2656 
    2657       // ----- Check the filename
    2658       if (   ($p_filedescr_list[$j]['type'] != 'virtual_file')
    2659           && (!file_exists($p_filedescr_list[$j]['filename']))) {
    2660         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
    2661         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
    2662         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2663         return PclZip::errorCode();
    2664       }
    2665 
    2666       // ----- Look if it is a file or a dir with no all path remove option
    2667       // or a dir with all its path removed
    2668 //    if (   (is_file($p_filedescr_list[$j]['filename']))
    2669 //        || (   is_dir($p_filedescr_list[$j]['filename'])
    2670       if (   ($p_filedescr_list[$j]['type'] == 'file')
    2671           || ($p_filedescr_list[$j]['type'] == 'virtual_file')
    2672           || (   ($p_filedescr_list[$j]['type'] == 'folder')
    2673               && (   !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
    2674                   || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
    2675           ) {
    2676 
    2677         // ----- Add the file
    2678         $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
    2679                                        $p_options);
    2680         if ($v_result != 1) {
    2681           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2682           return $v_result;
    2683         }
    2684 
    2685         // ----- Store the file infos
    2686         $p_result_list[$v_nb++] = $v_header;
    2687       }
    2688     }
    2689     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements");
    2690 
    2691     // ----- Return
    2692     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2693     return $v_result;
     2635    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list");
     2636    $v_result=1;
     2637    $v_header = array();
     2638
     2639    // ----- Recuperate the current number of elt in list
     2640    $v_nb = sizeof($p_result_list);
     2641    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements");
     2642
     2643    // ----- Loop on the files
     2644    for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
     2645      // ----- Format the filename
     2646      $p_filedescr_list[$j]['filename']
     2647      = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
     2648     
     2649      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'");
     2650
     2651      // ----- Skip empty file names
     2652      // TBC : Can this be possible ? not checked in DescrParseAtt ?
     2653      if ($p_filedescr_list[$j]['filename'] == "") {
     2654        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");
     2655        continue;
     2656      }
     2657
     2658      // ----- Check the filename
     2659      if (   ($p_filedescr_list[$j]['type'] != 'virtual_file')
     2660          && (!file_exists($p_filedescr_list[$j]['filename']))) {
     2661        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
     2662        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
     2663        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2664        return PclZip::errorCode();
     2665      }
     2666
     2667      // ----- Look if it is a file or a dir with no all path remove option
     2668      // or a dir with all its path removed
     2669//      if (   (is_file($p_filedescr_list[$j]['filename']))
     2670//          || (   is_dir($p_filedescr_list[$j]['filename'])
     2671      if (   ($p_filedescr_list[$j]['type'] == 'file')
     2672          || ($p_filedescr_list[$j]['type'] == 'virtual_file')
     2673          || (   ($p_filedescr_list[$j]['type'] == 'folder')
     2674              && (   !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
     2675                  || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
     2676          ) {
     2677
     2678        // ----- Add the file
     2679        $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
     2680                                       $p_options);
     2681        if ($v_result != 1) {
     2682          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2683          return $v_result;
     2684        }
     2685
     2686        // ----- Store the file infos
     2687        $p_result_list[$v_nb++] = $v_header;
     2688      }
     2689    }
     2690    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements");
     2691
     2692    // ----- Return
     2693    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2694    return $v_result;
    26942695  }
    26952696  // --------------------------------------------------------------------------------
     
    27032704  function privAddFile($p_filedescr, &$p_header, &$p_options)
    27042705  {
    2705     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'");
    2706     $v_result=1;
    2707    
    2708     // ----- Working variable
    2709     $p_filename = $p_filedescr['filename'];
    2710 
    2711     // TBC : Already done in the fileAtt check ... ?
    2712     if ($p_filename == "") {
    2713       // ----- Error log
    2714       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
    2715 
    2716       // ----- Return
    2717       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2718       return PclZip::errorCode();
    2719     }
     2706    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'");
     2707    $v_result=1;
     2708   
     2709    // ----- Working variable
     2710    $p_filename = $p_filedescr['filename'];
     2711
     2712    // TBC : Already done in the fileAtt check ... ?
     2713    if ($p_filename == "") {
     2714      // ----- Error log
     2715      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
     2716
     2717      // ----- Return
     2718      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2719      return PclZip::errorCode();
     2720    }
    27202721 
    2721     // ----- Look for a stored different filename
    2722     /* TBC : Removed
    2723     if (isset($p_filedescr['stored_filename'])) {
    2724       $v_stored_filename = $p_filedescr['stored_filename'];
    2725       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"');
    2726     }
    2727     else {
    2728       $v_stored_filename = $p_filedescr['stored_filename'];
    2729       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same');
    2730     }
    2731     */
    2732 
    2733     // ----- Set the file properties
    2734     clearstatcache();
    2735     $p_header['version'] = 20;
    2736     $p_header['version_extracted'] = 10;
    2737     $p_header['flag'] = 0;
    2738     $p_header['compression'] = 0;
    2739     $p_header['crc'] = 0;
    2740     $p_header['compressed_size'] = 0;
    2741     $p_header['filename_len'] = strlen($p_filename);
    2742     $p_header['extra_len'] = 0;
    2743     $p_header['disk'] = 0;
    2744     $p_header['internal'] = 0;
    2745     $p_header['offset'] = 0;
    2746     $p_header['filename'] = $p_filename;
    2747 // TBC : Removed    $p_header['stored_filename'] = $v_stored_filename;
    2748     $p_header['stored_filename'] = $p_filedescr['stored_filename'];
    2749     $p_header['extra'] = '';
    2750     $p_header['status'] = 'ok';
    2751     $p_header['index'] = -1;
    2752 
    2753     // ----- Look for regular file
    2754     if ($p_filedescr['type']=='file') {
    2755       $p_header['external'] = 0x00000000;
    2756       $p_header['size'] = filesize($p_filename);
    2757     }
    2758    
    2759     // ----- Look for regular folder
    2760     else if ($p_filedescr['type']=='folder') {
    2761       $p_header['external'] = 0x00000010;
    2762       $p_header['mtime'] = filemtime($p_filename);
    2763       $p_header['size'] = filesize($p_filename);
    2764     }
    2765    
    2766     // ----- Look for virtual file
    2767     else if ($p_filedescr['type'] == 'virtual_file') {
    2768       $p_header['external'] = 0x00000000;
    2769       $p_header['size'] = strlen($p_filedescr['content']);
    2770     }
    2771    
    2772     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'");
    2773 
    2774     // ----- Look for filetime
    2775     if (isset($p_filedescr['mtime'])) {
    2776       $p_header['mtime'] = $p_filedescr['mtime'];
    2777     }
    2778     else if ($p_filedescr['type'] == 'virtual_file') {
    2779       $p_header['mtime'] = time();
    2780     }
    2781     else {
    2782       $p_header['mtime'] = filemtime($p_filename);
    2783     }
    2784 
    2785     // ------ Look for file comment
    2786     if (isset($p_filedescr['comment'])) {
    2787       $p_header['comment_len'] = strlen($p_filedescr['comment']);
    2788       $p_header['comment'] = $p_filedescr['comment'];
    2789     }
    2790     else {
    2791       $p_header['comment_len'] = 0;
    2792       $p_header['comment'] = '';
    2793     }
    2794 
    2795     // ----- Look for pre-add callback
    2796     if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
    2797       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction");
    2798 
    2799       // ----- Generate a local information
    2800       $v_local_header = array();
    2801       $this->privConvertHeader2FileInfo($p_header, $v_local_header);
    2802 
    2803       // ----- Call the callback
    2804       // Here I do not use call_user_func() because I need to send a reference to the
    2805       // header.
    2806       eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
    2807       if ($v_result == 0) {
    2808         // ----- Change the file status
    2809         $p_header['status'] = "skipped";
    2810         $v_result = 1;
    2811       }
    2812 
    2813       // ----- Update the informations
    2814       // Only some fields can be modified
    2815       if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
    2816         $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
    2817         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'");
    2818       }
    2819     }
    2820 
    2821     // ----- Look for empty stored filename
    2822     if ($p_header['stored_filename'] == "") {
    2823       $p_header['status'] = "filtered";
    2824     }
    2825    
    2826     // ----- Check the path length
    2827     if (strlen($p_header['stored_filename']) > 0xFF) {
    2828       $p_header['status'] = 'filename_too_long';
    2829     }
    2830 
    2831     // ----- Look if no error, or file not skipped
    2832     if ($p_header['status'] == 'ok') {
    2833 
    2834       // ----- Look for a file
    2835       if ($p_filedescr['type'] == 'file') {
    2836         // ----- Look for using temporary file to zip
    2837         if ( (!isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_OFF]))
    2838             && (isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_ON])
    2839                 || (isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])
    2840                     && ($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
    2841           $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
    2842           if ($v_result >= PCLZIP_ERR_NO_ERROR) {
    2843             return $v_result;
    2844           }
    2845         }
    2846        
    2847         // ----- Use "in memory" zip algo
    2848         else {
    2849          
    2850         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");
    2851 
    2852         // ----- Open the source file
    2853         if (($v_file = @fopen($p_filename, "rb")) == 0) {
    2854           PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
    2855           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    2856           return PclZip::errorCode();
    2857         }
    2858 
    2859         // ----- Read the file content
    2860         $v_content = @fread($v_file, $p_header['size']);
    2861 
    2862         // ----- Close the file
    2863         @fclose($v_file);
    2864 
    2865         // ----- Calculate the CRC
    2866         $p_header['crc'] = @crc32($v_content);
    2867        
    2868         // ----- Look for no compression
    2869         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
    2870           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");
    2871           // ----- Set header parameters
    2872           $p_header['compressed_size'] = $p_header['size'];
    2873           $p_header['compression'] = 0;
    2874         }
    2875        
    2876         // ----- Look for normal compression
    2877         else {
    2878           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");
    2879           // ----- Compress the content
    2880           $v_content = @gzdeflate($v_content);
    2881 
    2882           // ----- Set header parameters
    2883           $p_header['compressed_size'] = strlen($v_content);
    2884           $p_header['compression'] = 8;
    2885         }
    2886        
    2887         // ----- Look for encryption
    2888         /*
    2889         if ((isset($p_options[PCLZIP_OPT_CRYPT]))
    2890             && ($p_options[PCLZIP_OPT_CRYPT] != "")) {
    2891           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ....");
    2892          
    2893           // Should be a random header
    2894           $v_header = 'xxxxxxxxxxxx';
    2895           $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,
    2896                                                    $p_header['compressed_size'],
    2897                                                    $v_header,
     2722    // ----- Look for a stored different filename
     2723    /* TBC : Removed
     2724    if (isset($p_filedescr['stored_filename'])) {
     2725      $v_stored_filename = $p_filedescr['stored_filename'];
     2726      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"');
     2727    }
     2728    else {
     2729      $v_stored_filename = $p_filedescr['stored_filename'];
     2730      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same');
     2731    }
     2732    */
     2733
     2734    // ----- Set the file properties
     2735    clearstatcache();
     2736    $p_header['version'] = 20;
     2737    $p_header['version_extracted'] = 10;
     2738    $p_header['flag'] = 0;
     2739    $p_header['compression'] = 0;
     2740    $p_header['crc'] = 0;
     2741    $p_header['compressed_size'] = 0;
     2742    $p_header['filename_len'] = strlen($p_filename);
     2743    $p_header['extra_len'] = 0;
     2744    $p_header['disk'] = 0;
     2745    $p_header['internal'] = 0;
     2746    $p_header['offset'] = 0;
     2747    $p_header['filename'] = $p_filename;
     2748// TBC : Removed    $p_header['stored_filename'] = $v_stored_filename;
     2749    $p_header['stored_filename'] = $p_filedescr['stored_filename'];
     2750    $p_header['extra'] = '';
     2751    $p_header['status'] = 'ok';
     2752    $p_header['index'] = -1;
     2753
     2754    // ----- Look for regular file
     2755    if ($p_filedescr['type']=='file') {
     2756      $p_header['external'] = 0x00000000;
     2757      $p_header['size'] = filesize($p_filename);
     2758    }
     2759   
     2760    // ----- Look for regular folder
     2761    else if ($p_filedescr['type']=='folder') {
     2762      $p_header['external'] = 0x00000010;
     2763      $p_header['mtime'] = filemtime($p_filename);
     2764      $p_header['size'] = filesize($p_filename);
     2765    }
     2766   
     2767    // ----- Look for virtual file
     2768    else if ($p_filedescr['type'] == 'virtual_file') {
     2769      $p_header['external'] = 0x00000000;
     2770      $p_header['size'] = strlen($p_filedescr['content']);
     2771    }
     2772   
     2773    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'");
     2774
     2775    // ----- Look for filetime
     2776    if (isset($p_filedescr['mtime'])) {
     2777      $p_header['mtime'] = $p_filedescr['mtime'];
     2778    }
     2779    else if ($p_filedescr['type'] == 'virtual_file') {
     2780      $p_header['mtime'] = time();
     2781    }
     2782    else {
     2783      $p_header['mtime'] = filemtime($p_filename);
     2784    }
     2785
     2786    // ------ Look for file comment
     2787    if (isset($p_filedescr['comment'])) {
     2788      $p_header['comment_len'] = strlen($p_filedescr['comment']);
     2789      $p_header['comment'] = $p_filedescr['comment'];
     2790    }
     2791    else {
     2792      $p_header['comment_len'] = 0;
     2793      $p_header['comment'] = '';
     2794    }
     2795
     2796    // ----- Look for pre-add callback
     2797    if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
     2798      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction");
     2799
     2800      // ----- Generate a local information
     2801      $v_local_header = array();
     2802      $this->privConvertHeader2FileInfo($p_header, $v_local_header);
     2803
     2804      // ----- Call the callback
     2805      // Here I do not use call_user_func() because I need to send a reference to the
     2806      // header.
     2807      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
     2808      if ($v_result == 0) {
     2809        // ----- Change the file status
     2810        $p_header['status'] = "skipped";
     2811        $v_result = 1;
     2812      }
     2813
     2814      // ----- Update the informations
     2815      // Only some fields can be modified
     2816      if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
     2817        $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
     2818        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'");
     2819      }
     2820    }
     2821
     2822    // ----- Look for empty stored filename
     2823    if ($p_header['stored_filename'] == "") {
     2824      $p_header['status'] = "filtered";
     2825    }
     2826   
     2827    // ----- Check the path length
     2828    if (strlen($p_header['stored_filename']) > 0xFF) {
     2829      $p_header['status'] = 'filename_too_long';
     2830    }
     2831
     2832    // ----- Look if no error, or file not skipped
     2833    if ($p_header['status'] == 'ok') {
     2834
     2835      // ----- Look for a file
     2836      if ($p_filedescr['type'] == 'file') {
     2837        // ----- Look for using temporary file to zip
     2838        if ( (!isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_OFF]))
     2839            && (isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_ON])
     2840                || (isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])
     2841                    && ($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
     2842          $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
     2843          if ($v_result >= PCLZIP_ERR_NO_ERROR) {
     2844            return $v_result;
     2845          }
     2846        }
     2847       
     2848        // ----- Use "in memory" zip algo
     2849        else {
     2850         
     2851        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");
     2852
     2853        // ----- Open the source file
     2854        if (($v_file = @fopen($p_filename, "rb")) == 0) {
     2855          PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
     2856          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
     2857          return PclZip::errorCode();
     2858        }
     2859
     2860        // ----- Read the file content
     2861        $v_content = @fread($v_file, $p_header['size']);
     2862
     2863        // ----- Close the file
     2864        @fclose($v_file);
     2865
     2866        // ----- Calculate the CRC
     2867        $p_header['crc'] = @crc32($v_content);
     2868       
     2869        // ----- Look for no compression
     2870        if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
     2871          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");
     2872          // ----- Set header parameters
     2873          $p_header['compressed_size'] = $p_header['size'];
     2874          $p_header['compression'] = 0;
     2875        }
     2876       
     2877        // ----- Look for normal compression
     2878        else {
     2879          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");
     2880          // ----- Compress the content
     2881          $v_content = @gzdeflate($v_content);
     2882
     2883          // ----- Set header parameters
     2884          $p_header['compressed_size'] = strlen($v_content);
     2885          $p_header['compression'] = 8;
     2886        }
     2887       
     2888        // ----- Look for encryption
     2889        /*
     2890        if ((isset($p_options[PCLZIP_OPT_CRYPT]))
     2891            && ($p_options[PCLZIP_OPT_CRYPT] != "")) {
     2892          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ....");
     2893         
     2894          // Should be a random header
     2895          $v_header = 'xxxxxxxxxxxx';
     2896          $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,
     2897                                                   $p_header['compressed_size'],
     2898                                                   $v_header,
    28982899                                                   $p_header['crc'],
    28992900                                                   "test");
    29002901                                                   
    2901           $p_header['compressed_size'] += 12;
    2902           $p_header['flag'] = 1;
    2903          
    2904           // ----- Add the header to the data
    2905           $v_content_compressed = $v_header.$v_content_compressed;
    2906           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed)."");
    2907         }
    2908         */
    2909 
    2910         // ----- Call the header generation
    2911         if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
    2912           @fclose($v_file);
    2913           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2914           return $v_result;
    2915         }
    2916 
    2917         // ----- Write the compressed (or not) content
    2918         @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
    2919 
    2920         }
    2921 
    2922       }
    2923 
    2924       // ----- Look for a virtual file (a file from string)
    2925       else if ($p_filedescr['type'] == 'virtual_file') {
    2926          
    2927         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Add by string");
    2928         $v_content = $p_filedescr['content'];
    2929 
    2930         // ----- Calculate the CRC
    2931         $p_header['crc'] = @crc32($v_content);
    2932        
    2933         // ----- Look for no compression
    2934         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
    2935           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");
    2936           // ----- Set header parameters
    2937           $p_header['compressed_size'] = $p_header['size'];
    2938           $p_header['compression'] = 0;
    2939         }
    2940        
    2941         // ----- Look for normal compression
    2942         else {
    2943           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");
    2944           // ----- Compress the content
    2945           $v_content = @gzdeflate($v_content);
    2946 
    2947           // ----- Set header parameters
    2948           $p_header['compressed_size'] = strlen($v_content);
    2949           $p_header['compression'] = 8;
    2950         }
    2951        
    2952         // ----- Look for encryption
    2953         /*
    2954         if ((isset($p_options[PCLZIP_OPT_CRYPT]))
    2955             && ($p_options[PCLZIP_OPT_CRYPT] != "")) {
    2956           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ....");
    2957          
    2958           // Should be a random header
    2959           $v_header = 'xxxxxxxxxxxx';
    2960           $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,
    2961                                                    $p_header['compressed_size'],
    2962                                                    $v_header,
     2902          $p_header['compressed_size'] += 12;
     2903          $p_header['flag'] = 1;
     2904         
     2905          // ----- Add the header to the data
     2906          $v_content_compressed = $v_header.$v_content_compressed;
     2907          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed)."");
     2908        }
     2909        */
     2910
     2911        // ----- Call the header generation
     2912        if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
     2913          @fclose($v_file);
     2914          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2915          return $v_result;
     2916        }
     2917
     2918        // ----- Write the compressed (or not) content
     2919        @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
     2920
     2921        }
     2922
     2923      }
     2924
     2925      // ----- Look for a virtual file (a file from string)
     2926      else if ($p_filedescr['type'] == 'virtual_file') {
     2927         
     2928        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Add by string");
     2929        $v_content = $p_filedescr['content'];
     2930
     2931        // ----- Calculate the CRC
     2932        $p_header['crc'] = @crc32($v_content);
     2933       
     2934        // ----- Look for no compression
     2935        if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
     2936          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");
     2937          // ----- Set header parameters
     2938          $p_header['compressed_size'] = $p_header['size'];
     2939          $p_header['compression'] = 0;
     2940        }
     2941       
     2942        // ----- Look for normal compression
     2943        else {
     2944          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");
     2945          // ----- Compress the content
     2946          $v_content = @gzdeflate($v_content);
     2947
     2948          // ----- Set header parameters
     2949          $p_header['compressed_size'] = strlen($v_content);
     2950          $p_header['compression'] = 8;
     2951        }
     2952       
     2953        // ----- Look for encryption
     2954        /*
     2955        if ((isset($p_options[PCLZIP_OPT_CRYPT]))
     2956            && ($p_options[PCLZIP_OPT_CRYPT] != "")) {
     2957          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ....");
     2958         
     2959          // Should be a random header
     2960          $v_header = 'xxxxxxxxxxxx';
     2961          $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,
     2962                                                   $p_header['compressed_size'],
     2963                                                   $v_header,
    29632964                                                   $p_header['crc'],
    29642965                                                   "test");
    29652966                                                   
    2966           $p_header['compressed_size'] += 12;
    2967           $p_header['flag'] = 1;
    2968          
    2969           // ----- Add the header to the data
    2970           $v_content_compressed = $v_header.$v_content_compressed;
    2971           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed)."");
    2972         }
    2973         */
    2974 
    2975         // ----- Call the header generation
    2976         if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
    2977           @fclose($v_file);
    2978           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    2979           return $v_result;
    2980         }
    2981 
    2982         // ----- Write the compressed (or not) content
    2983         @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
    2984       }
    2985 
    2986       // ----- Look for a directory
    2987       else if ($p_filedescr['type'] == 'folder') {
    2988         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder");
    2989         // ----- Look for directory last '/'
    2990         if (@substr($p_header['stored_filename'], -1) != '/') {
    2991           $p_header['stored_filename'] .= '/';
    2992         }
    2993 
    2994         // ----- Set the file properties
    2995         $p_header['size'] = 0;
    2996         //$p_header['external'] = 0x41FF0010;   // Value for a folder : to be checked
    2997         $p_header['external'] = 0x00000010;   // Value for a folder : to be checked
    2998 
    2999         // ----- Call the header generation
    3000         if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
    3001         {
    3002           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    3003           return $v_result;
    3004         }
    3005       }
    3006     }
    3007 
    3008     // ----- Look for post-add callback
    3009     if (isset($p_options[PCLZIP_CB_POST_ADD])) {
    3010       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction");
    3011 
    3012       // ----- Generate a local information
    3013       $v_local_header = array();
    3014       $this->privConvertHeader2FileInfo($p_header, $v_local_header);
    3015 
    3016       // ----- Call the callback
    3017       // Here I do not use call_user_func() because I need to send a reference to the
    3018       // header.
    3019       eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
    3020       if ($v_result == 0) {
    3021         // ----- Ignored
    3022         $v_result = 1;
    3023       }
    3024 
    3025       // ----- Update the informations
    3026       // Nothing can be modified
    3027     }
    3028 
    3029     // ----- Return
    3030     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
    3031     return $v_result;
     2967          $p_header['compressed_size'] += 12;
     2968          $p_header['flag'] = 1;
     2969         
     2970          // ----- Add the header to the data
     2971          $v_content_compressed = $v_header.$v_content_compressed;
     2972          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed)."");
     2973        }
     2974        */
     2975
     2976        // ----- Call the header generation
     2977        if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
     2978          @fclose($v_file);
     2979          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     2980          return $v_result;
     2981        }
     2982
     2983        // ----- Write the compressed (or not) content
     2984        @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
     2985      }
     2986
     2987      // ----- Look for a directory
     2988      else if ($p_filedescr['type'] == 'folder') {
     2989        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder");
     2990        // ----- Look for directory last '/'
     2991        if (@substr($p_header['stored_filename'], -1) != '/') {
     2992          $p_header['stored_filename'] .= '/';
     2993        }
     2994
     2995        // ----- Set the file properties
     2996        $p_header['size'] = 0;
     2997        //$p_header['external'] = 0x41FF0010;   // Value for a folder : to be checked
     2998        $p_header['external'] = 0x00000010;   // Value for a folder : to be checked
     2999
     3000        // ----- Call the header generation
     3001        if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
     3002        {
     3003          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     3004          return $v_result;
     3005        }
     3006      }
     3007    }
     3008
     3009    // ----- Look for post-add callback
     3010    if (isset($p_options[PCLZIP_CB_POST_ADD])) {
     3011      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction");
     3012
     3013      // ----- Generate a local information
     3014      $v_local_header = array();
     3015      $this->privConvertHeader2FileInfo($p_header, $v_local_header);
     3016
     3017      // ----- Call the callback
     3018      // Here I do not use call_user_func() because I need to send a reference to the
     3019      // header.
     3020      eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
     3021      if ($v_result == 0) {
     3022        // ----- Ignored
     3023        $v_result = 1;
     3024      }
     3025
     3026      // ----- Update the informations
     3027      // Nothing can be modified
     3028    }
     3029
     3030    // ----- Return
     3031    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
     3032    return $v_result;
    30323033  }
    30333034  // --------------------------------------------------------------------------------
     
    30413042  function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
    30423043  {
    3043     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileUsingTempFile", "filename='".$p_filedescr['filename']."'");
    3044     $v_result=PCLZIP_ERR_NO_ERROR;
    3045    
    3046     // ----- Working variable
    3047     $p_filename = $p_filedescr['filename'];
    3048 
    3049     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");
    3050 
    3051     // ----- Open the source file
    3052     if (($v_file = @fopen($p_filename, "rb")) == 0) {
    3053       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
    3054       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    3055       return PclZip::errorCode();
    3056     }
    3057 
    3058     // ----- Creates a compressed temporary file
    3059     $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
    3060     if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
    3061       fclose($v_file);
    3062       PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
    3063       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
    3064       return PclZip::errorCode();
    3065     }
    3066 
    3067     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
    3068     $v_size = filesize($p_filename);
    3069     while ($v_size != 0) {
    3070       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
    3071       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes");
    3072       $v_buffer = fread($v_file, $v_read_size);
    3073       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
    3074       @gzputs($v_file_compressed, $v_buffer, $v_read_size);
    3075       $v_size -= $v_read_size;
    3076     }
    3077 
    3078     // ----- Close the file
    3079     @fclose($v_file);
    3080     @gzclose($v_file_compressed);
    3081 
    3082     // ----- Check the minimum file size
    3083     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "gzip file size ".filesize($v_gzip_temp_name));