OSDN Git Service

NP_Paint v1.18
[nucleus-jp/nucleus-plugins.git] / trunk / NP_Paint / sharedlibs / pclzip.lib.php
diff --git a/trunk/NP_Paint/sharedlibs/pclzip.lib.php b/trunk/NP_Paint/sharedlibs/pclzip.lib.php
new file mode 100644 (file)
index 0000000..e2a5eba
--- /dev/null
@@ -0,0 +1,5748 @@
+<?php\r
+// --------------------------------------------------------------------------------\r
+// PhpConcept Library - Zip Module 2.5\r
+// --------------------------------------------------------------------------------\r
+// License GNU/LGPL - Vincent Blavet - March 2006\r
+// http://www.phpconcept.net\r
+// --------------------------------------------------------------------------------\r
+//\r
+// Presentation :\r
+//   PclZip is a PHP library that manage ZIP archives.\r
+//   So far tests show that archives generated by PclZip are readable by\r
+//   WinZip application and other tools.\r
+//\r
+// Description :\r
+//   See readme.txt and http://www.phpconcept.net\r
+//\r
+// Warning :\r
+//   This library and the associated files are non commercial, non professional\r
+//   work.\r
+//   It should not have unexpected results. However if any damage is caused by\r
+//   this software the author can not be responsible.\r
+//   The use of this software is at the risk of the user.\r
+//\r
+// --------------------------------------------------------------------------------\r
+// $Id: pclzip.lib.php,v 1.4 2006/03/19 07:54:59 hsur Exp $\r
+// --------------------------------------------------------------------------------\r
+\r
+  // ----- Constants\r
+  define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );\r
+  \r
+  // ----- File list separator\r
+  // In version 1.x of PclZip, the separator for file list is a space\r
+  // (which is not a very smart choice, specifically for windows paths !).\r
+  // A better separator should be a comma (,). This constant gives you the\r
+  // abilty to change that.\r
+  // However notice that changing this value, may have impact on existing\r
+  // scripts, using space separated filenames.\r
+  // Recommanded values for compatibility with older versions :\r
+  //define( 'PCLZIP_SEPARATOR', ' ' );\r
+  // Recommanded values for smart separation of filenames.\r
+  define( 'PCLZIP_SEPARATOR', ',' );\r
+\r
+  // ----- Error configuration\r
+  // 0 : PclZip Class integrated error handling\r
+  // 1 : PclError external library error handling. By enabling this\r
+  //     you must ensure that you have included PclError library.\r
+  // [2,...] : reserved for futur use\r
+  define( 'PCLZIP_ERROR_EXTERNAL', 0 );\r
+\r
+  // ----- Optional static temporary directory\r
+  //       By default temporary files are generated in the script current\r
+  //       path.\r
+  //       If defined :\r
+  //       - MUST BE terminated by a '/'.\r
+  //       - MUST be a valid, already created directory\r
+  //       Samples :\r
+  // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );\r
+  // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );\r
+  define( 'PCLZIP_TEMPORARY_DIR', '' );\r
+\r
+// --------------------------------------------------------------------------------\r
+// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****\r
+// --------------------------------------------------------------------------------\r
+\r
+  // ----- Global variables\r
+  $g_pclzip_version = "2.5";\r
+\r
+  // ----- Error codes\r
+  //   -1 : Unable to open file in binary write mode\r
+  //   -2 : Unable to open file in binary read mode\r
+  //   -3 : Invalid parameters\r
+  //   -4 : File does not exist\r
+  //   -5 : Filename is too long (max. 255)\r
+  //   -6 : Not a valid zip file\r
+  //   -7 : Invalid extracted file size\r
+  //   -8 : Unable to create directory\r
+  //   -9 : Invalid archive extension\r
+  //  -10 : Invalid archive format\r
+  //  -11 : Unable to delete file (unlink)\r
+  //  -12 : Unable to rename file (rename)\r
+  //  -13 : Invalid header checksum\r
+  //  -14 : Invalid archive size\r
+  define( 'PCLZIP_ERR_USER_ABORTED', 2 );\r
+  define( 'PCLZIP_ERR_NO_ERROR', 0 );\r
+  define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );\r
+  define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );\r
+  define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );\r
+  define( 'PCLZIP_ERR_MISSING_FILE', -4 );\r
+  define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );\r
+  define( 'PCLZIP_ERR_INVALID_ZIP', -6 );\r
+  define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );\r
+  define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );\r
+  define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );\r
+  define( 'PCLZIP_ERR_BAD_FORMAT', -10 );\r
+  define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );\r
+  define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );\r
+  define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );\r
+  define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );\r
+  define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );\r
+  define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );\r
+  define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );\r
+  define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );\r
+  define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );\r
+  define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );\r
+  define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );\r
+\r
+  // ----- Options values\r
+  define( 'PCLZIP_OPT_PATH', 77001 );\r
+  define( 'PCLZIP_OPT_ADD_PATH', 77002 );\r
+  define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );\r
+  define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );\r
+  define( 'PCLZIP_OPT_SET_CHMOD', 77005 );\r
+  define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );\r
+  define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );\r
+  define( 'PCLZIP_OPT_BY_NAME', 77008 );\r
+  define( 'PCLZIP_OPT_BY_INDEX', 77009 );\r
+  define( 'PCLZIP_OPT_BY_EREG', 77010 );\r
+  define( 'PCLZIP_OPT_BY_PREG', 77011 );\r
+  define( 'PCLZIP_OPT_COMMENT', 77012 );\r
+  define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );\r
+  define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );\r
+  define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );\r
+  define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );\r
+  define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );\r
+  // Having big trouble with crypt. Need to multiply 2 long int\r
+  // which is not correctly supported by PHP ...\r
+  //define( 'PCLZIP_OPT_CRYPT', 77018 );\r
+  define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );\r
+  \r
+  // ----- File description attributes\r
+  define( 'PCLZIP_ATT_FILE_NAME', 79001 );\r
+  define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );\r
+  define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );\r
+\r
+  // ----- Call backs values\r
+  define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );\r
+  define( 'PCLZIP_CB_POST_EXTRACT', 78002 );\r
+  define( 'PCLZIP_CB_PRE_ADD', 78003 );\r
+  define( 'PCLZIP_CB_POST_ADD', 78004 );\r
+  /* For futur use\r
+  define( 'PCLZIP_CB_PRE_LIST', 78005 );\r
+  define( 'PCLZIP_CB_POST_LIST', 78006 );\r
+  define( 'PCLZIP_CB_PRE_DELETE', 78007 );\r
+  define( 'PCLZIP_CB_POST_DELETE', 78008 );\r
+  */\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Class : PclZip\r
+  // Description :\r
+  //   PclZip is the class that represent a Zip archive.\r
+  //   The public methods allow the manipulation of the archive.\r
+  // Attributes :\r
+  //   Attributes must not be accessed directly.\r
+  // Methods :\r
+  //   PclZip() : Object creator\r
+  //   create() : Creates the Zip archive\r
+  //   listContent() : List the content of the Zip archive\r
+  //   extract() : Extract the content of the archive\r
+  //   properties() : List the properties of the archive\r
+  // --------------------------------------------------------------------------------\r
+  class PclZip\r
+  {\r
+    // ----- Filename of the zip file\r
+    var $zipname = '';\r
+\r
+    // ----- File descriptor of the zip file\r
+    var $zip_fd = 0;\r
+\r
+    // ----- Internal error handling\r
+    var $error_code = 1;\r
+    var $error_string = '';\r
+    \r
+    // ----- Current status of the magic_quotes_runtime\r
+    // This value store the php configuration for magic_quotes\r
+    // The class can then disable the magic_quotes and reset it after\r
+    var $magic_quotes_status;\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclZip()\r
+  // Description :\r
+  //   Creates a PclZip object and set the name of the associated Zip archive\r
+  //   filename.\r
+  //   Note that no real action is taken, if the archive does not exist it is not\r
+  //   created. Use create() for that.\r
+  // --------------------------------------------------------------------------------\r
+  function PclZip($p_zipname)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");\r
+\r
+    // ----- Tests the zlib\r
+    if (!function_exists('gzopen'))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing");\r
+      die('Abort '.basename(__FILE__).' : Missing zlib extensions');\r
+    }\r
+\r
+    // ----- Set the attributes\r
+    $this->zipname = $p_zipname;\r
+    $this->zip_fd = 0;\r
+    $this->magic_quotes_status = -1;\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);\r
+    return;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function :\r
+  //   create($p_filelist, $p_add_dir="", $p_remove_dir="")\r
+  //   create($p_filelist, $p_option, $p_option_value, ...)\r
+  // Description :\r
+  //   This method supports two different synopsis. The first one is historical.\r
+  //   This method creates a Zip Archive. The Zip file is created in the\r
+  //   filesystem. The files and directories indicated in $p_filelist\r
+  //   are added in the archive. See the parameters description for the\r
+  //   supported format of $p_filelist.\r
+  //   When a directory is in the list, the directory and its content is added\r
+  //   in the archive.\r
+  //   In this synopsis, the function takes an optional variable list of\r
+  //   options. See bellow the supported options.\r
+  // Parameters :\r
+  //   $p_filelist : An array containing file or directory names, or\r
+  //                 a string containing one filename or one directory name, or\r
+  //                 a string containing a list of filenames and/or directory\r
+  //                 names separated by spaces.\r
+  //   $p_add_dir : A path to add before the real path of the archived file,\r
+  //                in order to have it memorized in the archive.\r
+  //   $p_remove_dir : A path to remove from the real path of the file to archive,\r
+  //                   in order to have a shorter path memorized in the archive.\r
+  //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir\r
+  //                   is removed first, before $p_add_dir is added.\r
+  // Options :\r
+  //   PCLZIP_OPT_ADD_PATH :\r
+  //   PCLZIP_OPT_REMOVE_PATH :\r
+  //   PCLZIP_OPT_REMOVE_ALL_PATH :\r
+  //   PCLZIP_OPT_COMMENT :\r
+  //   PCLZIP_CB_PRE_ADD :\r
+  //   PCLZIP_CB_POST_ADD :\r
+  // Return Values :\r
+  //   0 on failure,\r
+  //   The list of the added files, with a status of the add action.\r
+  //   (see PclZip::listContent() for list entry format)\r
+  // --------------------------------------------------------------------------------\r
+  function create($p_filelist)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ...");\r
+    $v_result=1;\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Set default values\r
+    $v_options = array();\r
+    $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;\r
+\r
+    // ----- Look for variable options arguments\r
+    $v_size = func_num_args();\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");\r
+\r
+    // ----- Look for arguments\r
+    if ($v_size > 1) {\r
+      // ----- Get the arguments\r
+      $v_arg_list = func_get_args();\r
+\r
+      // ----- Remove from the options list the first argument\r
+      array_shift($v_arg_list);\r
+      $v_size--;\r
+\r
+      // ----- Look for first arg\r
+      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");\r
+\r
+        // ----- Parse the options\r
+        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,\r
+                                            array (PCLZIP_OPT_REMOVE_PATH => 'optional',\r
+                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',\r
+                                                   PCLZIP_OPT_ADD_PATH => 'optional',\r
+                                                   PCLZIP_CB_PRE_ADD => 'optional',\r
+                                                   PCLZIP_CB_POST_ADD => 'optional',\r
+                                                   PCLZIP_OPT_NO_COMPRESSION => 'optional',\r
+                                                   PCLZIP_OPT_COMMENT => 'optional'\r
+                                                   //, PCLZIP_OPT_CRYPT => 'optional'\r
+                                             ));\r
+        if ($v_result != 1) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+          return 0;\r
+        }\r
+      }\r
+\r
+      // ----- Look for 2 args\r
+      // Here we need to support the first historic synopsis of the\r
+      // method.\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");\r
+\r
+        // ----- Get the first argument\r
+        $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];\r
+\r
+        // ----- Look for the optional second argument\r
+        if ($v_size == 2) {\r
+          $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];\r
+        }\r
+        else if ($v_size > 2) {\r
+          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,\r
+                                      "Invalid number / type of arguments");\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+          return 0;\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Init\r
+    $v_string_list = array();\r
+    $v_att_list = array();\r
+    $v_filedescr_list = array();\r
+    $p_result_list = array();\r
+    \r
+    // ----- Look if the $p_filelist is really an array\r
+    if (is_array($p_filelist)) {\r
+    \r
+      // ----- Look if the first element is also an array\r
+      //       This will mean that this is a file description entry\r
+      if (isset($p_filelist[0]) && is_array($p_filelist[0])) {\r
+        $v_att_list = $p_filelist;\r
+      }\r
+      \r
+      // ----- The list is a list of string names\r
+      else {\r
+        $v_string_list = $p_filelist;\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_filelist)) {\r
+      // ----- Create a list from the string\r
+      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);\r
+    }\r
+\r
+    // ----- Invalid variable type for $p_filelist\r
+    else {\r
+      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return 0;\r
+    }\r
+    \r
+    // ----- Reformat the string list\r
+    if (sizeof($v_string_list) != 0) {\r
+      foreach ($v_string_list as $v_string) {\r
+        if ($v_string != '') {\r
+          $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;\r
+        }\r
+        else {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename");\r
+        }\r
+      }\r
+    }\r
+    \r
+    // ----- For each file in the list check the attributes\r
+    $v_supported_attributes\r
+    = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'\r
+             ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'\r
+             ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'\r
+                                               );\r
+    foreach ($v_att_list as $v_entry) {\r
+      $v_result = $this->privFileDescrParseAtt($v_entry,\r
+                                               $v_filedescr_list[],\r
+                                               $v_options,\r
+                                               $v_supported_attributes);\r
+      if ($v_result != 1) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Expand the filelist (expand directories)\r
+    $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);\r
+    if ($v_result != 1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return 0;\r
+    }\r
+\r
+    // ----- Call the create fct\r
+    $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);\r
+    if ($v_result != 1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return 0;\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);\r
+    return $p_result_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function :\r
+  //   add($p_filelist, $p_add_dir="", $p_remove_dir="")\r
+  //   add($p_filelist, $p_option, $p_option_value, ...)\r
+  // Description :\r
+  //   This method supports two synopsis. The first one is historical.\r
+  //   This methods add the list of files in an existing archive.\r
+  //   If a file with the same name already exists, it is added at the end of the\r
+  //   archive, the first one is still present.\r
+  //   If the archive does not exist, it is created.\r
+  // Parameters :\r
+  //   $p_filelist : An array containing file or directory names, or\r
+  //                 a string containing one filename or one directory name, or\r
+  //                 a string containing a list of filenames and/or directory\r
+  //                 names separated by spaces.\r
+  //   $p_add_dir : A path to add before the real path of the archived file,\r
+  //                in order to have it memorized in the archive.\r
+  //   $p_remove_dir : A path to remove from the real path of the file to archive,\r
+  //                   in order to have a shorter path memorized in the archive.\r
+  //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir\r
+  //                   is removed first, before $p_add_dir is added.\r
+  // Options :\r
+  //   PCLZIP_OPT_ADD_PATH :\r
+  //   PCLZIP_OPT_REMOVE_PATH :\r
+  //   PCLZIP_OPT_REMOVE_ALL_PATH :\r
+  //   PCLZIP_OPT_COMMENT :\r
+  //   PCLZIP_OPT_ADD_COMMENT :\r
+  //   PCLZIP_OPT_PREPEND_COMMENT :\r
+  //   PCLZIP_CB_PRE_ADD :\r
+  //   PCLZIP_CB_POST_ADD :\r
+  // Return Values :\r
+  //   0 on failure,\r
+  //   The list of the added files, with a status of the add action.\r
+  //   (see PclZip::listContent() for list entry format)\r
+  // --------------------------------------------------------------------------------\r
+  function add($p_filelist)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ...");\r
+    $v_result=1;\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Set default values\r
+    $v_options = array();\r
+    $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;\r
+\r
+    // ----- Look for variable options arguments\r
+    $v_size = func_num_args();\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");\r
+\r
+    // ----- Look for arguments\r
+    if ($v_size > 1) {\r
+      // ----- Get the arguments\r
+      $v_arg_list = func_get_args();\r
+\r
+      // ----- Remove form the options list the first argument\r
+      array_shift($v_arg_list);\r
+      $v_size--;\r
+\r
+      // ----- Look for first arg\r
+      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");\r
+\r
+        // ----- Parse the options\r
+        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,\r
+                                            array (PCLZIP_OPT_REMOVE_PATH => 'optional',\r
+                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',\r
+                                                   PCLZIP_OPT_ADD_PATH => 'optional',\r
+                                                   PCLZIP_CB_PRE_ADD => 'optional',\r
+                                                   PCLZIP_CB_POST_ADD => 'optional',\r
+                                                   PCLZIP_OPT_NO_COMPRESSION => 'optional',\r
+                                                   PCLZIP_OPT_COMMENT => 'optional',\r
+                                                   PCLZIP_OPT_ADD_COMMENT => 'optional',\r
+                                                   PCLZIP_OPT_PREPEND_COMMENT => 'optional'\r
+                                                   //, PCLZIP_OPT_CRYPT => 'optional'\r
+                                                                                                  ));\r
+        if ($v_result != 1) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+          return 0;\r
+        }\r
+      }\r
+\r
+      // ----- Look for 2 args\r
+      // Here we need to support the first historic synopsis of the\r
+      // method.\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");\r
+\r
+        // ----- Get the first argument\r
+        $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];\r
+\r
+        // ----- Look for the optional second argument\r
+        if ($v_size == 2) {\r
+          $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];\r
+        }\r
+        else if ($v_size > 2) {\r
+          // ----- Error log\r
+          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");\r
+\r
+          // ----- Return\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+          return 0;\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Init\r
+    $v_string_list = array();\r
+    $v_att_list = array();\r
+    $v_filedescr_list = array();\r
+    $p_result_list = array();\r
+    \r
+    // ----- Look if the $p_filelist is really an array\r
+    if (is_array($p_filelist)) {\r
+    \r
+      // ----- Look if the first element is also an array\r
+      //       This will mean that this is a file description entry\r
+      if (isset($p_filelist[0]) && is_array($p_filelist[0])) {\r
+        $v_att_list = $p_filelist;\r
+      }\r
+      \r
+      // ----- The list is a list of string names\r
+      else {\r
+        $v_string_list = $p_filelist;\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_filelist)) {\r
+      // ----- Create a list from the string\r
+      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);\r
+    }\r
+\r
+    // ----- Invalid variable type for $p_filelist\r
+    else {\r
+      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return 0;\r
+    }\r
+    \r
+    // ----- Reformat the string list\r
+    if (sizeof($v_string_list) != 0) {\r
+      foreach ($v_string_list as $v_string) {\r
+        $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;\r
+      }\r
+    }\r
+    \r
+    // ----- For each file in the list check the attributes\r
+    $v_supported_attributes\r
+    = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'\r
+             ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'\r
+             ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'\r
+                                               );\r
+    foreach ($v_att_list as $v_entry) {\r
+      $v_result = $this->privFileDescrParseAtt($v_entry,\r
+                                               $v_filedescr_list[],\r
+                                               $v_options,\r
+                                               $v_supported_attributes);\r
+      if ($v_result != 1) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Expand the filelist (expand directories)\r
+    $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);\r
+    if ($v_result != 1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return 0;\r
+    }\r
+\r
+    // ----- Call the create fct\r
+    $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);\r
+    if ($v_result != 1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return 0;\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);\r
+    return $p_result_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : listContent()\r
+  // Description :\r
+  //   This public method, gives the list of the files and directories, with their\r
+  //   properties.\r
+  //   The properties of each entries in the list are (used also in other functions) :\r
+  //     filename : Name of the file. For a create or add action it is the filename\r
+  //                given by the user. For an extract function it is the filename\r
+  //                of the extracted file.\r
+  //     stored_filename : Name of the file / directory stored in the archive.\r
+  //     size : Size of the stored file.\r
+  //     compressed_size : Size of the file's data compressed in the archive\r
+  //                       (without the headers overhead)\r
+  //     mtime : Last known modification date of the file (UNIX timestamp)\r
+  //     comment : Comment associated with the file\r
+  //     folder : true | false\r
+  //     index : index of the file in the archive\r
+  //     status : status of the action (depending of the action) :\r
+  //              Values are :\r
+  //                ok : OK !\r
+  //                filtered : the file / dir is not extracted (filtered by user)\r
+  //                already_a_directory : the file can not be extracted because a\r
+  //                                      directory with the same name already exists\r
+  //                write_protected : the file can not be extracted because a file\r
+  //                                  with the same name already exists and is\r
+  //                                  write protected\r
+  //                newer_exist : the file was not extracted because a newer file exists\r
+  //                path_creation_fail : the file is not extracted because the folder\r
+  //                                     does not exists and can not be created\r
+  //                write_error : the file was not extracted because there was a\r
+  //                              error while writing the file\r
+  //                read_error : the file was not extracted because there was a error\r
+  //                             while reading the file\r
+  //                invalid_header : the file was not extracted because of an archive\r
+  //                                 format error (bad file header)\r
+  //   Note that each time a method can continue operating when there\r
+  //   is an action error on a file, the error is only logged in the file status.\r
+  // Return Values :\r
+  //   0 on an unrecoverable failure,\r
+  //   The list of the files in the archive.\r
+  // --------------------------------------------------------------------------------\r
+  function listContent()\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");\r
+    $v_result=1;\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Check archive\r
+    if (!$this->privCheckFormat()) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return(0);\r
+    }\r
+\r
+    // ----- Call the extracting fct\r
+    $p_list = array();\r
+    if (($v_result = $this->privList($p_list)) != 1)\r
+    {\r
+      unset($p_list);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+      return(0);\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function :\r
+  //   extract($p_path="./", $p_remove_path="")\r
+  //   extract([$p_option, $p_option_value, ...])\r
+  // Description :\r
+  //   This method supports two synopsis. The first one is historical.\r
+  //   This method extract all the files / directories from the archive to the\r
+  //   folder indicated in $p_path.\r
+  //   If you want to ignore the 'root' part of path of the memorized files\r
+  //   you can indicate this in the optional $p_remove_path parameter.\r
+  //   By default, if a newer file with the same name already exists, the\r
+  //   file is not extracted.\r
+  //\r
+  //   If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions\r
+  //   are used, the path indicated in PCLZIP_OPT_ADD_PATH is append\r
+  //   at the end of the path value of PCLZIP_OPT_PATH.\r
+  // Parameters :\r
+  //   $p_path : Path where the files and directories are to be extracted\r
+  //   $p_remove_path : First part ('root' part) of the memorized path\r
+  //                    (if any similar) to remove while extracting.\r
+  // Options :\r
+  //   PCLZIP_OPT_PATH :\r
+  //   PCLZIP_OPT_ADD_PATH :\r
+  //   PCLZIP_OPT_REMOVE_PATH :\r
+  //   PCLZIP_OPT_REMOVE_ALL_PATH :\r
+  //   PCLZIP_CB_PRE_EXTRACT :\r
+  //   PCLZIP_CB_POST_EXTRACT :\r
+  // Return Values :\r
+  //   0 or a negative value on failure,\r
+  //   The list of the extracted files, with a status of the action.\r
+  //   (see PclZip::listContent() for list entry format)\r
+  // --------------------------------------------------------------------------------\r
+  function extract()\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");\r
+    $v_result=1;\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Check archive\r
+    if (!$this->privCheckFormat()) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return(0);\r
+    }\r
+\r
+    // ----- Set default values\r
+    $v_options = array();\r
+//    $v_path = "./";\r
+    $v_path = '';\r
+    $v_remove_path = "";\r
+    $v_remove_all_path = false;\r
+\r
+    // ----- Look for variable options arguments\r
+    $v_size = func_num_args();\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");\r
+\r
+    // ----- Default values for option\r
+    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;\r
+\r
+    // ----- Look for arguments\r
+    if ($v_size > 0) {\r
+      // ----- Get the arguments\r
+      $v_arg_list = func_get_args();\r
+\r
+      // ----- Look for first arg\r
+      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");\r
+\r
+        // ----- Parse the options\r
+        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,\r
+                                            array (PCLZIP_OPT_PATH => 'optional',\r
+                                                   PCLZIP_OPT_REMOVE_PATH => 'optional',\r
+                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',\r
+                                                   PCLZIP_OPT_ADD_PATH => 'optional',\r
+                                                   PCLZIP_CB_PRE_EXTRACT => 'optional',\r
+                                                   PCLZIP_CB_POST_EXTRACT => 'optional',\r
+                                                   PCLZIP_OPT_SET_CHMOD => 'optional',\r
+                                                   PCLZIP_OPT_BY_NAME => 'optional',\r
+                                                   PCLZIP_OPT_BY_EREG => 'optional',\r
+                                                   PCLZIP_OPT_BY_PREG => 'optional',\r
+                                                   PCLZIP_OPT_BY_INDEX => 'optional',\r
+                                                   PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',\r
+                                                   PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',\r
+                                                   PCLZIP_OPT_REPLACE_NEWER => 'optional'\r
+                                                   ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'\r
+                                                   ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'\r
+                                                                                                   ));\r
+        if ($v_result != 1) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+          return 0;\r
+        }\r
+\r
+        // ----- Set the arguments\r
+        if (isset($v_options[PCLZIP_OPT_PATH])) {\r
+          $v_path = $v_options[PCLZIP_OPT_PATH];\r
+        }\r
+        if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {\r
+          $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];\r
+        }\r
+        if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {\r
+          $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];\r
+        }\r
+        if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {\r
+          // ----- Check for '/' in last path char\r
+          if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {\r
+            $v_path .= '/';\r
+          }\r
+          $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];\r
+        }\r
+      }\r
+\r
+      // ----- Look for 2 args\r
+      // Here we need to support the first historic synopsis of the\r
+      // method.\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");\r
+\r
+        // ----- Get the first argument\r
+        $v_path = $v_arg_list[0];\r
+\r
+        // ----- Look for the optional second argument\r
+        if ($v_size == 2) {\r
+          $v_remove_path = $v_arg_list[1];\r
+        }\r
+        else if ($v_size > 2) {\r
+          // ----- Error log\r
+          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");\r
+\r
+          // ----- Return\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+          return 0;\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Trace\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");\r
+\r
+    // ----- Call the extracting fct\r
+    $p_list = array();\r
+    $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,\r
+                                            $v_remove_all_path, $v_options);\r
+    if ($v_result < 1) {\r
+      unset($p_list);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+      return(0);\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function :\r
+  //   extractByIndex($p_index, $p_path="./", $p_remove_path="")\r
+  //   extractByIndex($p_index, [$p_option, $p_option_value, ...])\r
+  // Description :\r
+  //   This method supports two synopsis. The first one is historical.\r
+  //   This method is doing a partial extract of the archive.\r
+  //   The extracted files or folders are identified by their index in the\r
+  //   archive (from 0 to n).\r
+  //   Note that if the index identify a folder, only the folder entry is\r
+  //   extracted, not all the files included in the archive.\r
+  // Parameters :\r
+  //   $p_index : A single index (integer) or a string of indexes of files to\r
+  //              extract. The form of the string is "0,4-6,8-12" with only numbers\r
+  //              and '-' for range or ',' to separate ranges. No spaces or ';'\r
+  //              are allowed.\r
+  //   $p_path : Path where the files and directories are to be extracted\r
+  //   $p_remove_path : First part ('root' part) of the memorized path\r
+  //                    (if any similar) to remove while extracting.\r
+  // Options :\r
+  //   PCLZIP_OPT_PATH :\r
+  //   PCLZIP_OPT_ADD_PATH :\r
+  //   PCLZIP_OPT_REMOVE_PATH :\r
+  //   PCLZIP_OPT_REMOVE_ALL_PATH :\r
+  //   PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and\r
+  //     not as files.\r
+  //     The resulting content is in a new field 'content' in the file\r
+  //     structure.\r
+  //     This option must be used alone (any other options are ignored).\r
+  //   PCLZIP_CB_PRE_EXTRACT :\r
+  //   PCLZIP_CB_POST_EXTRACT :\r
+  // Return Values :\r
+  //   0 on failure,\r
+  //   The list of the extracted files, with a status of the action.\r
+  //   (see PclZip::listContent() for list entry format)\r
+  // --------------------------------------------------------------------------------\r
+  //function extractByIndex($p_index, options...)\r
+  function extractByIndex($p_index)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");\r
+    $v_result=1;\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Check archive\r
+    if (!$this->privCheckFormat()) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return(0);\r
+    }\r
+\r
+    // ----- Set default values\r
+    $v_options = array();\r
+//    $v_path = "./";\r
+    $v_path = '';\r
+    $v_remove_path = "";\r
+    $v_remove_all_path = false;\r
+\r
+    // ----- Look for variable options arguments\r
+    $v_size = func_num_args();\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");\r
+\r
+    // ----- Default values for option\r
+    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;\r
+\r
+    // ----- Look for arguments\r
+    if ($v_size > 1) {\r
+      // ----- Get the arguments\r
+      $v_arg_list = func_get_args();\r
+\r
+      // ----- Remove form the options list the first argument\r
+      array_shift($v_arg_list);\r
+      $v_size--;\r
+\r
+      // ----- Look for first arg\r
+      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");\r
+\r
+        // ----- Parse the options\r
+        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,\r
+                                            array (PCLZIP_OPT_PATH => 'optional',\r
+                                                   PCLZIP_OPT_REMOVE_PATH => 'optional',\r
+                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',\r
+                                                   PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',\r
+                                                   PCLZIP_OPT_ADD_PATH => 'optional',\r
+                                                   PCLZIP_CB_PRE_EXTRACT => 'optional',\r
+                                                   PCLZIP_CB_POST_EXTRACT => 'optional',\r
+                                                   PCLZIP_OPT_SET_CHMOD => 'optional',\r
+                                                   PCLZIP_OPT_REPLACE_NEWER => 'optional'\r
+                                                   ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'\r
+                                                   ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'\r
+                                                                                                  ));\r
+        if ($v_result != 1) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+          return 0;\r
+        }\r
+\r
+        // ----- Set the arguments\r
+        if (isset($v_options[PCLZIP_OPT_PATH])) {\r
+          $v_path = $v_options[PCLZIP_OPT_PATH];\r
+        }\r
+        if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {\r
+          $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];\r
+        }\r
+        if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {\r
+          $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];\r
+        }\r
+        if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {\r
+          // ----- Check for '/' in last path char\r
+          if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {\r
+            $v_path .= '/';\r
+          }\r
+          $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];\r
+        }\r
+        if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {\r
+          $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set.");\r
+        }\r
+        else {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set.");\r
+        }\r
+      }\r
+\r
+      // ----- Look for 2 args\r
+      // Here we need to support the first historic synopsis of the\r
+      // method.\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");\r
+\r
+        // ----- Get the first argument\r
+        $v_path = $v_arg_list[0];\r
+\r
+        // ----- Look for the optional second argument\r
+        if ($v_size == 2) {\r
+          $v_remove_path = $v_arg_list[1];\r
+        }\r
+        else if ($v_size > 2) {\r
+          // ----- Error log\r
+          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");\r
+\r
+          // ----- Return\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+          return 0;\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Trace\r
+    //--(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')."'");\r
+\r
+    // ----- Trick\r
+    // Here I want to reuse extractByRule(), so I need to parse the $p_index\r
+    // with privParseOptions()\r
+    $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);\r
+    $v_options_trick = array();\r
+    $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,\r
+                                        array (PCLZIP_OPT_BY_INDEX => 'optional' ));\r
+    if ($v_result != 1) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+        return 0;\r
+    }\r
+    $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];\r
+\r
+    // ----- Call the extracting fct\r
+    if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+        return(0);\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function :\r
+  //   delete([$p_option, $p_option_value, ...])\r
+  // Description :\r
+  //   This method removes files from the archive.\r
+  //   If no parameters are given, then all the archive is emptied.\r
+  // Parameters :\r
+  //   None or optional arguments.\r
+  // Options :\r
+  //   PCLZIP_OPT_BY_INDEX :\r
+  //   PCLZIP_OPT_BY_NAME :\r
+  //   PCLZIP_OPT_BY_EREG : \r
+  //   PCLZIP_OPT_BY_PREG :\r
+  // Return Values :\r
+  //   0 on failure,\r
+  //   The list of the files which are still present in the archive.\r
+  //   (see PclZip::listContent() for list entry format)\r
+  // --------------------------------------------------------------------------------\r
+  function delete()\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");\r
+    $v_result=1;\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Check archive\r
+    if (!$this->privCheckFormat()) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return(0);\r
+    }\r
+\r
+    // ----- Set default values\r
+    $v_options = array();\r
+\r
+    // ----- Look for variable options arguments\r
+    $v_size = func_num_args();\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");\r
+\r
+    // ----- Look for arguments\r
+    if ($v_size > 0) {\r
+      // ----- Get the arguments\r
+      $v_arg_list = func_get_args();\r
+\r
+      // ----- Parse the options\r
+      $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,\r
+                                        array (PCLZIP_OPT_BY_NAME => 'optional',\r
+                                               PCLZIP_OPT_BY_EREG => 'optional',\r
+                                               PCLZIP_OPT_BY_PREG => 'optional',\r
+                                               PCLZIP_OPT_BY_INDEX => 'optional' ));\r
+      if ($v_result != 1) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+          return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privDisableMagicQuotes();\r
+\r
+    // ----- Call the delete fct\r
+    $v_list = array();\r
+    if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {\r
+      $this->privSwapBackMagicQuotes();\r
+      unset($v_list);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+      return(0);\r
+    }\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privSwapBackMagicQuotes();\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);\r
+    return $v_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : deleteByIndex()\r
+  // Description :\r
+  //   ***** Deprecated *****\r
+  //   delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.\r
+  // --------------------------------------------------------------------------------\r
+  function deleteByIndex($p_index)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'");\r
+    \r
+    $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : properties()\r
+  // Description :\r
+  //   This method gives the properties of the archive.\r
+  //   The properties are :\r
+  //     nb : Number of files in the archive\r
+  //     comment : Comment associated with the archive file\r
+  //     status : not_exist, ok\r
+  // Parameters :\r
+  //   None\r
+  // Return Values :\r
+  //   0 on failure,\r
+  //   An array with the archive properties.\r
+  // --------------------------------------------------------------------------------\r
+  function properties()\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privDisableMagicQuotes();\r
+\r
+    // ----- Check archive\r
+    if (!$this->privCheckFormat()) {\r
+      $this->privSwapBackMagicQuotes();\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return(0);\r
+    }\r
+\r
+    // ----- Default properties\r
+    $v_prop = array();\r
+    $v_prop['comment'] = '';\r
+    $v_prop['nb'] = 0;\r
+    $v_prop['status'] = 'not_exist';\r
+\r
+    // ----- Look if file exists\r
+    if (@is_file($this->zipname))\r
+    {\r
+      // ----- Open the zip file\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+      if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)\r
+      {\r
+        $this->privSwapBackMagicQuotes();\r
+        \r
+        // ----- Error log\r
+        PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);\r
+        return 0;\r
+      }\r
+\r
+      // ----- Read the central directory informations\r
+      $v_central_dir = array();\r
+      if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)\r
+      {\r
+        $this->privSwapBackMagicQuotes();\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+        return 0;\r
+      }\r
+\r
+      // ----- Close the zip file\r
+      $this->privCloseFd();\r
+\r
+      // ----- Set the user attributes\r
+      $v_prop['comment'] = $v_central_dir['comment'];\r
+      $v_prop['nb'] = $v_central_dir['entries'];\r
+      $v_prop['status'] = 'ok';\r
+    }\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privSwapBackMagicQuotes();\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);\r
+    return $v_prop;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : duplicate()\r
+  // Description :\r
+  //   This method creates an archive by copying the content of an other one. If\r
+  //   the archive already exist, it is replaced by the new one without any warning.\r
+  // Parameters :\r
+  //   $p_archive : The filename of a valid archive, or\r
+  //                a valid PclZip object.\r
+  // Return Values :\r
+  //   1 on success.\r
+  //   0 or a negative value on error (error code).\r
+  // --------------------------------------------------------------------------------\r
+  function duplicate($p_archive)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");\r
+    $v_result = 1;\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Look if the $p_archive is a PclZip object\r
+    if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");\r
+\r
+      // ----- Duplicate the archive\r
+      $v_result = $this->privDuplicate($p_archive->zipname);\r
+    }\r
+\r
+    // ----- Look if the $p_archive is a string (so a filename)\r
+    else if (is_string($p_archive))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");\r
+\r
+      // ----- Check that $p_archive is a valid zip file\r
+      // TBC : Should also check the archive format\r
+      if (!is_file($p_archive)) {\r
+        // ----- Error log\r
+        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");\r
+        $v_result = PCLZIP_ERR_MISSING_FILE;\r
+      }\r
+      else {\r
+        // ----- Duplicate the archive\r
+        $v_result = $this->privDuplicate($p_archive);\r
+      }\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");\r
+      $v_result = PCLZIP_ERR_INVALID_PARAMETER;\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : merge()\r
+  // Description :\r
+  //   This method merge the $p_archive_to_add archive at the end of the current\r
+  //   one ($this).\r
+  //   If the archive ($this) does not exist, the merge becomes a duplicate.\r
+  //   If the $p_archive_to_add archive does not exist, the merge is a success.\r
+  // Parameters :\r
+  //   $p_archive_to_add : It can be directly the filename of a valid zip archive,\r
+  //                       or a PclZip object archive.\r
+  // Return Values :\r
+  //   1 on success,\r
+  //   0 or negative values on error (see below).\r
+  // --------------------------------------------------------------------------------\r
+  function merge($p_archive_to_add)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");\r
+    $v_result = 1;\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Check archive\r
+    if (!$this->privCheckFormat()) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);\r
+      return(0);\r
+    }\r
+\r
+    // ----- Look if the $p_archive_to_add is a PclZip object\r
+    if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");\r
+\r
+      // ----- Merge the archive\r
+      $v_result = $this->privMerge($p_archive_to_add);\r
+    }\r
+\r
+    // ----- Look if the $p_archive_to_add is a string (so a filename)\r
+    else if (is_string($p_archive_to_add))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");\r
+\r
+      // ----- Create a temporary archive\r
+      $v_object_archive = new PclZip($p_archive_to_add);\r
+\r
+      // ----- Merge the archive\r
+      $v_result = $this->privMerge($v_object_archive);\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");\r
+      $v_result = PCLZIP_ERR_INVALID_PARAMETER;\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : errorCode()\r
+  // Description :\r
+  // Parameters :\r
+  // --------------------------------------------------------------------------------\r
+  function errorCode()\r
+  {\r
+    if (PCLZIP_ERROR_EXTERNAL == 1) {\r
+      return(PclErrorCode());\r
+    }\r
+    else {\r
+      return($this->error_code);\r
+    }\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : errorName()\r
+  // Description :\r
+  // Parameters :\r
+  // --------------------------------------------------------------------------------\r
+  function errorName($p_with_code=false)\r
+  {\r
+    $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',\r
+                      PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',\r
+                      PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',\r
+                      PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',\r
+                      PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',\r
+                      PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',\r
+                      PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',\r
+                      PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',\r
+                      PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',\r
+                      PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',\r
+                      PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',\r
+                      PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',\r
+                      PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',\r
+                      PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',\r
+                      PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',\r
+                      PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',\r
+                      PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',\r
+                      PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',\r
+                      PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'\r
+                      ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'\r
+                      ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'\r
+                    );\r
+\r
+    if (isset($v_name[$this->error_code])) {\r
+      $v_value = $v_name[$this->error_code];\r
+    }\r
+    else {\r
+      $v_value = 'NoName';\r
+    }\r
+\r
+    if ($p_with_code) {\r
+      return($v_value.' ('.$this->error_code.')');\r
+    }\r
+    else {\r
+      return($v_value);\r
+    }\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : errorInfo()\r
+  // Description :\r
+  // Parameters :\r
+  // --------------------------------------------------------------------------------\r
+  function errorInfo($p_full=false)\r
+  {\r
+    if (PCLZIP_ERROR_EXTERNAL == 1) {\r
+      return(PclErrorString());\r
+    }\r
+    else {\r
+      if ($p_full) {\r
+        return($this->errorName(true)." : ".$this->error_string);\r
+      }\r
+      else {\r
+        return($this->error_string." [code ".$this->error_code."]");\r
+      }\r
+    }\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+\r
+// --------------------------------------------------------------------------------\r
+// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****\r
+// *****                                                        *****\r
+// *****       THESES FUNCTIONS MUST NOT BE USED DIRECTLY       *****\r
+// --------------------------------------------------------------------------------\r
+\r
+\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privCheckFormat()\r
+  // Description :\r
+  //   This method check that the archive exists and is a valid zip archive.\r
+  //   Several level of check exists. (futur)\r
+  // Parameters :\r
+  //   $p_level : Level of check. Default 0.\r
+  //              0 : Check the first bytes (magic codes) (default value))\r
+  //              1 : 0 + Check the central directory (futur)\r
+  //              2 : 1 + Check each file header (futur)\r
+  // Return Values :\r
+  //   true on success,\r
+  //   false on error, the error code is set.\r
+  // --------------------------------------------------------------------------------\r
+  function privCheckFormat($p_level=0)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");\r
+    $v_result = true;\r
+\r
+       // ----- Reset the file system cache\r
+    clearstatcache();\r
+\r
+    // ----- Reset the error handler\r
+    $this->privErrorReset();\r
+\r
+    // ----- Look if the file exits\r
+    if (!is_file($this->zipname)) {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());\r
+      return(false);\r
+    }\r
+\r
+    // ----- Check that the file is readeable\r
+    if (!is_readable($this->zipname)) {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());\r
+      return(false);\r
+    }\r
+\r
+    // ----- Check the magic code\r
+    // TBC\r
+\r
+    // ----- Check the central header\r
+    // TBC\r
+\r
+    // ----- Check each file header\r
+    // TBC\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privParseOptions()\r
+  // Description :\r
+  //   This internal methods reads the variable list of arguments ($p_options_list,\r
+  //   $p_size) and generate an array with the options and values ($v_result_list).\r
+  //   $v_requested_options contains the options that can be present and those that\r
+  //   must be present.\r
+  //   $v_requested_options is an array, with the option value as key, and 'optional',\r
+  //   or 'mandatory' as value.\r
+  // Parameters :\r
+  //   See above.\r
+  // Return Values :\r
+  //   1 on success.\r
+  //   0 on failure.\r
+  // --------------------------------------------------------------------------------\r
+  function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");\r
+    $v_result=1;\r
+    \r
+    // ----- Read the options\r
+    $i=0;\r
+    while ($i<$p_size) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'");\r
+\r
+      // ----- Check if the option is supported\r
+      if (!isset($v_requested_options[$p_options_list[$i]])) {\r
+        // ----- Error log\r
+        PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+\r
+      // ----- Look for next option\r
+      switch ($p_options_list[$i]) {\r
+        // ----- Look for options that request a path value\r
+        case PCLZIP_OPT_PATH :\r
+        case PCLZIP_OPT_REMOVE_PATH :\r
+        case PCLZIP_OPT_ADD_PATH :\r
+          // ----- Check the number of parameters\r
+          if (($i+1) >= $p_size) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Get the value\r
+          $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");\r
+          $i++;\r
+        break;\r
+\r
+        case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :\r
+          // ----- Check the number of parameters\r
+          if (($i+1) >= $p_size) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Get the value\r
+          if (   is_string($p_options_list[$i+1])\r
+              && ($p_options_list[$i+1] != '')) {\r
+            $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");\r
+            $i++;\r
+          }\r
+          else {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored.");\r
+          }\r
+        break;\r
+\r
+        // ----- Look for options that request an array of string for value\r
+        case PCLZIP_OPT_BY_NAME :\r
+          // ----- Check the number of parameters\r
+          if (($i+1) >= $p_size) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Get the value\r
+          if (is_string($p_options_list[$i+1])) {\r
+              $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];\r
+          }\r
+          else if (is_array($p_options_list[$i+1])) {\r
+              $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];\r
+          }\r
+          else {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+          ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");\r
+          $i++;\r
+        break;\r
+\r
+        // ----- Look for options that request an EREG or PREG expression\r
+        case PCLZIP_OPT_BY_EREG :\r
+        case PCLZIP_OPT_BY_PREG :\r
+        //case PCLZIP_OPT_CRYPT :\r
+          // ----- Check the number of parameters\r
+          if (($i+1) >= $p_size) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Get the value\r
+          if (is_string($p_options_list[$i+1])) {\r
+              $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];\r
+          }\r
+          else {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");\r
+          $i++;\r
+        break;\r
+\r
+        // ----- Look for options that takes a string\r
+        case PCLZIP_OPT_COMMENT :\r
+        case PCLZIP_OPT_ADD_COMMENT :\r
+        case PCLZIP_OPT_PREPEND_COMMENT :\r
+          // ----- Check the number of parameters\r
+          if (($i+1) >= $p_size) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,\r
+                                            "Missing parameter value for option '"\r
+                                                                .PclZipUtilOptionText($p_options_list[$i])\r
+                                                                ."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Get the value\r
+          if (is_string($p_options_list[$i+1])) {\r
+              $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];\r
+          }\r
+          else {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,\r
+                                            "Wrong parameter value for option '"\r
+                                                                .PclZipUtilOptionText($p_options_list[$i])\r
+                                                                ."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");\r
+          $i++;\r
+        break;\r
+\r
+        // ----- Look for options that request an array of index\r
+        case PCLZIP_OPT_BY_INDEX :\r
+          // ----- Check the number of parameters\r
+          if (($i+1) >= $p_size) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Get the value\r
+          $v_work_list = array();\r
+          if (is_string($p_options_list[$i+1])) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'");\r
+\r
+              // ----- Remove spaces\r
+              $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');\r
+\r
+              // ----- Parse items\r
+              $v_work_list = explode(",", $p_options_list[$i+1]);\r
+          }\r
+          else if (is_integer($p_options_list[$i+1])) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'");\r
+              $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];\r
+          }\r
+          else if (is_array($p_options_list[$i+1])) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array");\r
+              $v_work_list = $p_options_list[$i+1];\r
+          }\r
+          else {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+          \r
+          // ----- Reduce the index list\r
+          // each index item in the list must be a couple with a start and\r
+          // an end value : [0,3], [5-5], [8-10], ...\r
+          // ----- Check the format of each item\r
+          $v_sort_flag=false;\r
+          $v_sort_value=0;\r
+          for ($j=0; $j<sizeof($v_work_list); $j++) {\r
+              // ----- Explode the item\r
+              $v_item_list = explode("-", $v_work_list[$j]);\r
+              $v_size_item_list = sizeof($v_item_list);\r
+              \r
+              // ----- TBC : Here we might check that each item is a\r
+              // real integer ...\r
+              \r
+              // ----- Look for single value\r
+              if ($v_size_item_list == 1) {\r
+                  // ----- Set the option value\r
+                  $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];\r
+                  $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];\r
+              }\r
+              elseif ($v_size_item_list == 2) {\r
+                  // ----- Set the option value\r
+                  $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];\r
+                  $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];\r
+              }\r
+              else {\r
+                  // ----- Error log\r
+                  PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+                  // ----- Return\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+                  return PclZip::errorCode();\r
+              }\r
+\r
+              //--(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']."]");\r
+\r
+              // ----- Look for list sort\r
+              if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ...");\r
+                  $v_sort_flag=true;\r
+\r
+                  // ----- TBC : An automatic sort should be writen ...\r
+                  // ----- Error log\r
+                  PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+                  // ----- Return\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+                  return PclZip::errorCode();\r
+              }\r
+              $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];\r
+          }\r
+          \r
+          // ----- Sort the items\r
+          if ($v_sort_flag) {\r
+              // TBC : To Be Completed\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ...");\r
+          }\r
+\r
+          // ----- Next option\r
+          $i++;\r
+        break;\r
+\r
+        // ----- Look for options that request no value\r
+        case PCLZIP_OPT_REMOVE_ALL_PATH :\r
+        case PCLZIP_OPT_EXTRACT_AS_STRING :\r
+        case PCLZIP_OPT_NO_COMPRESSION :\r
+        case PCLZIP_OPT_EXTRACT_IN_OUTPUT :\r
+        case PCLZIP_OPT_REPLACE_NEWER :\r
+        case PCLZIP_OPT_STOP_ON_ERROR :\r
+          $v_result_list[$p_options_list[$i]] = true;\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");\r
+        break;\r
+\r
+        // ----- Look for options that request an octal value\r
+        case PCLZIP_OPT_SET_CHMOD :\r
+          // ----- Check the number of parameters\r
+          if (($i+1) >= $p_size) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Get the value\r
+          $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");\r
+          $i++;\r
+        break;\r
+\r
+        // ----- Look for options that request a call-back\r
+        case PCLZIP_CB_PRE_EXTRACT :\r
+        case PCLZIP_CB_POST_EXTRACT :\r
+        case PCLZIP_CB_PRE_ADD :\r
+        case PCLZIP_CB_POST_ADD :\r
+        /* for futur use\r
+        case PCLZIP_CB_PRE_DELETE :\r
+        case PCLZIP_CB_POST_DELETE :\r
+        case PCLZIP_CB_PRE_LIST :\r
+        case PCLZIP_CB_POST_LIST :\r
+        */\r
+          // ----- Check the number of parameters\r
+          if (($i+1) >= $p_size) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Get the value\r
+          $v_function_name = $p_options_list[$i+1];\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'");\r
+\r
+          // ----- Check that the value is a valid existing function\r
+          if (!function_exists($v_function_name)) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          // ----- Set the attribute\r
+          $v_result_list[$p_options_list[$i]] = $v_function_name;\r
+          $i++;\r
+        break;\r
+\r
+        default :\r
+          // ----- Error log\r
+          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,\r
+                                      "Unknown parameter '"\r
+                                                          .$p_options_list[$i]."'");\r
+\r
+          // ----- Return\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+          return PclZip::errorCode();\r
+      }\r
+\r
+      // ----- Next options\r
+      $i++;\r
+    }\r
+\r
+    // ----- Look for mandatory options\r
+    if ($v_requested_options !== false) {\r
+      for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {\r
+        // ----- Look for mandatory option\r
+        if ($v_requested_options[$key] == 'mandatory') {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");\r
+          // ----- Look if present\r
+          if (!isset($v_result_list[$key])) {\r
+            // ----- Error log\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privFileDescrParseAtt()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  //   1 on success.\r
+  //   0 on failure.\r
+  // --------------------------------------------------------------------------------\r
+  function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", "");\r
+    $v_result=1;\r
+    \r
+    // ----- For each file in the list check the attributes\r
+    foreach ($p_file_list as $v_key => $v_value) {\r
+    \r
+      // ----- Check if the option is supported\r
+      if (!isset($v_requested_options[$v_key])) {\r
+        // ----- Error log\r
+        PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+\r
+      // ----- Look for attribute\r
+      switch ($v_key) {\r
+        case PCLZIP_ATT_FILE_NAME :\r
+          if (!is_string($v_value)) {\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");\r
+          \r
+          if ($p_filedescr['filename'] == '') {\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+        break;\r
+\r
+        case PCLZIP_ATT_FILE_NEW_SHORT_NAME :\r
+          if (!is_string($v_value)) {\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");\r
+\r
+          if ($p_filedescr['new_short_name'] == '') {\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+        break;\r
+\r
+        case PCLZIP_ATT_FILE_NEW_FULL_NAME :\r
+          if (!is_string($v_value)) {\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+\r
+          $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");\r
+\r
+          if ($p_filedescr['new_full_name'] == '') {\r
+            PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+          }\r
+        break;\r
+\r
+        default :\r
+          // ----- Error log\r
+          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,\r
+                                          "Unknown parameter '".$v_key."'");\r
+\r
+          // ----- Return\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+          return PclZip::errorCode();\r
+      }\r
+\r
+      // ----- Look for mandatory options\r
+      if ($v_requested_options !== false) {\r
+        for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {\r
+          // ----- Look for mandatory option\r
+          if ($v_requested_options[$key] == 'mandatory') {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");\r
+            // ----- Look if present\r
+            if (!isset($p_file_list[$key])) {\r
+              PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");\r
+              //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+              return PclZip::errorCode();\r
+            }\r
+          }\r
+        }\r
+      }\r
+    \r
+    // end foreach\r
+    }\r
+    \r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privFileDescrExpand()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  //   1 on success.\r
+  //   0 on failure.\r
+  // --------------------------------------------------------------------------------\r
+  function privFileDescrExpand(&$p_filedescr_list, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", "");\r
+    $v_result=1;\r
+    \r
+    // ----- Create a result list\r
+    $v_result_list = array();\r
+    \r
+    // ----- Look each entry\r
+    for ($i=0; $i<sizeof($p_filedescr_list); $i++) {\r
+      // ----- Get filedescr\r
+      $v_descr = $p_filedescr_list[$i];\r
+      \r
+      // ----- Reduce the filename\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'");\r
+      $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']);\r
+      $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'");\r
+      \r
+      // ----- Get type of descr\r
+      if (!file_exists($v_descr['filename'])) {\r
+        // ----- Error log\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exists");\r
+        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists");\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+      if (@is_file($v_descr['filename'])) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file");\r
+        $v_descr['type'] = 'file';\r
+      }\r
+      else if (@is_dir($v_descr['filename'])) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder");\r
+        $v_descr['type'] = 'folder';\r
+      }\r
+      else if (@is_link($v_descr['filename'])) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link");\r
+        // skip\r
+        continue;\r
+      }\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type");\r
+        // skip\r
+        continue;\r
+      }\r
+      \r
+      // ----- Calculate the stored filename\r
+      $this->privCalculateStoredFilename($v_descr, $p_options);\r
+      \r
+      // ----- Add the descriptor in result list\r
+      $v_result_list[sizeof($v_result_list)] = $v_descr;\r
+      \r
+      // ----- Look for folder\r
+      if ($v_descr['type'] == 'folder') {\r
+        // ----- List of items in folder\r
+        $v_dirlist_descr = array();\r
+        $v_dirlist_nb = 0;\r
+        if ($v_folder_handler = @opendir($v_descr['filename'])) {\r
+          while (($v_item_handler = @readdir($v_folder_handler)) !== false) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory");\r
+\r
+            // ----- Skip '.' and '..'\r
+            if (($v_item_handler == '.') || ($v_item_handler == '..')) {\r
+                continue;\r
+            }\r
+            \r
+            // ----- Compose the full filename\r
+            $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;\r
+            \r
+            // ----- Look for different stored filename\r
+            // Because the name of the folder was changed, the name of the\r
+            // files/sub-folders also change\r
+            if ($v_descr['stored_filename'] != $v_descr['filename']) {\r
+              $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;\r
+            }\r
+      \r
+            $v_dirlist_nb++;\r
+          }\r
+        }\r
+        else {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped.");\r
+          // TBC : unable to open folder in read mode\r
+        }\r
+        \r
+        // ----- Expand each element of the list\r
+        if ($v_dirlist_nb != 0) {\r
+          // ----- Expand\r
+          if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+          }\r
+          \r
+          // ----- Concat the resulting list\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')");\r
+          $v_result_list = array_merge($v_result_list, $v_dirlist_descr);\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'");\r
+        }\r
+        else {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand.");\r
+        }\r
+          \r
+        // ----- Free local array\r
+        unset($v_dirlist_descr);\r
+      }\r
+    }\r
+    \r
+    // ----- Get the result list\r
+    $p_filedescr_list = $v_result_list;\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privCreate()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privCreate($p_filedescr_list, &$p_result_list, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list");\r
+    $v_result=1;\r
+    $v_list_detail = array();\r
+    \r
+    // ----- Magic quotes trick\r
+    $this->privDisableMagicQuotes();\r
+\r
+    // ----- Open the file in write mode\r
+    if (($v_result = $this->privOpenFd('wb')) != 1)\r
+    {\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Add the list of files\r
+    $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);\r
+\r
+    // ----- Close\r
+    $this->privCloseFd();\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privSwapBackMagicQuotes();\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privAdd()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privAdd($p_filedescr_list, &$p_result_list, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list");\r
+    $v_result=1;\r
+    $v_list_detail = array();\r
+\r
+    // ----- Look if the archive exists or is empty\r
+    if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it.");\r
+\r
+      // ----- Do a create\r
+      $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+    // ----- Magic quotes trick\r
+    $this->privDisableMagicQuotes();\r
+\r
+    // ----- Open the zip file\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($v_result=$this->privOpenFd('rb')) != 1)\r
+    {\r
+      // ----- Magic quotes trick\r
+      $this->privSwapBackMagicQuotes();\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Read the central directory informations\r
+    $v_central_dir = array();\r
+    if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)\r
+    {\r
+      $this->privCloseFd();\r
+      $this->privSwapBackMagicQuotes();\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Go to beginning of File\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");\r
+    @rewind($this->zip_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");\r
+\r
+    // ----- Creates a temporay file\r
+    $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';\r
+\r
+    // ----- Open the temporary file in write mode\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)\r
+    {\r
+      $this->privCloseFd();\r
+      $this->privSwapBackMagicQuotes();\r
+\r
+      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Copy the files from the archive to the temporary file\r
+    // TBC : Here I should better append the file and go back to erase the central dir\r
+    $v_size = $v_central_dir['offset'];\r
+    while ($v_size != 0)\r
+    {\r
+      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+      $v_buffer = fread($this->zip_fd, $v_read_size);\r
+      @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);\r
+      $v_size -= $v_read_size;\r
+    }\r
+\r
+    // ----- Swap the file descriptor\r
+    // Here is a trick : I swap the temporary fd with the zip fd, in order to use\r
+    // the following methods on the temporary fil and not the real archive\r
+    $v_swap = $this->zip_fd;\r
+    $this->zip_fd = $v_zip_temp_fd;\r
+    $v_zip_temp_fd = $v_swap;\r
+\r
+    // ----- Add the files\r
+    $v_header_list = array();\r
+    if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)\r
+    {\r
+      fclose($v_zip_temp_fd);\r
+      $this->privCloseFd();\r
+      @unlink($v_zip_temp_name);\r
+      $this->privSwapBackMagicQuotes();\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Store the offset of the central dir\r
+    $v_offset = @ftell($this->zip_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");\r
+\r
+    // ----- Copy the block of file headers from the old archive\r
+    $v_size = $v_central_dir['size'];\r
+    while ($v_size != 0)\r
+    {\r
+      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+      $v_buffer = @fread($v_zip_temp_fd, $v_read_size);\r
+      @fwrite($this->zip_fd, $v_buffer, $v_read_size);\r
+      $v_size -= $v_read_size;\r
+    }\r
+\r
+    // ----- Create the Central Dir files header\r
+    for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)\r
+    {\r
+      // ----- Create the file header\r
+      if ($v_header_list[$i]['status'] == 'ok') {\r
+        if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {\r
+          fclose($v_zip_temp_fd);\r
+          $this->privCloseFd();\r
+          @unlink($v_zip_temp_name);\r
+          $this->privSwapBackMagicQuotes();\r
+\r
+          // ----- Return\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+        $v_count++;\r
+      }\r
+\r
+      // ----- Transform the header to a 'usable' info\r
+      $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);\r
+    }\r
+\r
+    // ----- Zip file comment\r
+    $v_comment = $v_central_dir['comment'];\r
+    if (isset($p_options[PCLZIP_OPT_COMMENT])) {\r
+      $v_comment = $p_options[PCLZIP_OPT_COMMENT];\r
+    }\r
+    if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {\r
+      $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];\r
+    }\r
+    if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {\r
+      $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;\r
+    }\r
+\r
+    // ----- Calculate the size of the central header\r
+    $v_size = @ftell($this->zip_fd)-$v_offset;\r
+\r
+    // ----- Create the central dir footer\r
+    if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)\r
+    {\r
+      // ----- Reset the file list\r
+      unset($v_header_list);\r
+      $this->privSwapBackMagicQuotes();\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Swap back the file descriptor\r
+    $v_swap = $this->zip_fd;\r
+    $this->zip_fd = $v_zip_temp_fd;\r
+    $v_zip_temp_fd = $v_swap;\r
+\r
+    // ----- Close\r
+    $this->privCloseFd();\r
+\r
+    // ----- Close the temporary file\r
+    @fclose($v_zip_temp_fd);\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privSwapBackMagicQuotes();\r
+\r
+    // ----- Delete the zip file\r
+    // TBC : I should test the result ...\r
+    @unlink($this->zipname);\r
+\r
+    // ----- Rename the temporary file\r
+    // TBC : I should test the result ...\r
+    //@rename($v_zip_temp_name, $this->zipname);\r
+    PclZipUtilRename($v_zip_temp_name, $this->zipname);\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privOpenFd()\r
+  // Description :\r
+  // Parameters :\r
+  // --------------------------------------------------------------------------------\r
+  function privOpenFd($p_mode)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode);\r
+    $v_result=1;\r
+\r
+    // ----- Look if already open\r
+    if ($this->zip_fd != 0)\r
+    {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Open the zip file\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode');\r
+    if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)\r
+    {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privCloseFd()\r
+  // Description :\r
+  // Parameters :\r
+  // --------------------------------------------------------------------------------\r
+  function privCloseFd()\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", "");\r
+    $v_result=1;\r
+\r
+    if ($this->zip_fd != 0)\r
+      @fclose($this->zip_fd);\r
+    $this->zip_fd = 0;\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privAddList()\r
+  // Description :\r
+  //   $p_add_dir and $p_remove_dir will give the ability to memorize a path which is\r
+  //   different from the real path of the file. This is usefull if you want to have PclTar\r
+  //   running in any directory, and memorize relative path from an other directory.\r
+  // Parameters :\r
+  //   $p_list : An array containing the file or directory names to add in the tar\r
+  //   $p_result_list : list of added files with their properties (specially the status field)\r
+  //   $p_add_dir : Path to add in the filename path archived\r
+  //   $p_remove_dir : Path to remove in the filename path archived\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+//  function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)\r
+  function privAddList($p_filedescr_list, &$p_result_list, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list");\r
+    $v_result=1;\r
+\r
+    // ----- Add the files\r
+    $v_header_list = array();\r
+    if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)\r
+    {\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Store the offset of the central dir\r
+    $v_offset = @ftell($this->zip_fd);\r
+\r
+    // ----- Create the Central Dir files header\r
+    for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)\r
+    {\r
+      // ----- Create the file header\r
+      if ($v_header_list[$i]['status'] == 'ok') {\r
+        if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {\r
+          // ----- Return\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+        $v_count++;\r
+      }\r
+\r
+      // ----- Transform the header to a 'usable' info\r
+      $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);\r
+    }\r
+\r
+    // ----- Zip file comment\r
+    $v_comment = '';\r
+    if (isset($p_options[PCLZIP_OPT_COMMENT])) {\r
+      $v_comment = $p_options[PCLZIP_OPT_COMMENT];\r
+    }\r
+\r
+    // ----- Calculate the size of the central header\r
+    $v_size = @ftell($this->zip_fd)-$v_offset;\r
+\r
+    // ----- Create the central dir footer\r
+    if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)\r
+    {\r
+      // ----- Reset the file list\r
+      unset($v_header_list);\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privAddFileList()\r
+  // Description :\r
+  // Parameters :\r
+  //   $p_filedescr_list : An array containing the file description \r
+  //                      or directory names to add in the zip\r
+  //   $p_result_list : list of added files with their properties (specially the status field)\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list");\r
+    $v_result=1;\r
+    $v_header = array();\r
+\r
+    // ----- Recuperate the current number of elt in list\r
+    $v_nb = sizeof($p_result_list);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements");\r
+\r
+    // ----- Loop on the files\r
+    for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {\r
+      // ----- Format the filename\r
+      $p_filedescr_list[$j]['filename']\r
+      = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);\r
+      \r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'");\r
+\r
+      // ----- Skip empty file names\r
+      // TBC : Can this be possible ? not checked in DescrParseAtt ?\r
+      if ($p_filedescr_list[$j]['filename'] == "") {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");\r
+        continue;\r
+      }\r
+\r
+      // ----- Check the filename\r
+      if (!file_exists($p_filedescr_list[$j]['filename'])) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exists");\r
+        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists");\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+\r
+      // ----- Look if it is a file or a dir with no all path remove option\r
+      if (   (is_file($p_filedescr_list[$j]['filename']))\r
+          || (   is_dir($p_filedescr_list[$j]['filename'])\r
+              && (   !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])\r
+                  || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {\r
+\r
+        // ----- Add the file\r
+        $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,\r
+                                       $p_options);\r
+        if ($v_result != 1) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+\r
+        // ----- Store the file infos\r
+        $p_result_list[$v_nb++] = $v_header;\r
+      }\r
+    }\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements");\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privAddFile()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privAddFile($p_filedescr, &$p_header, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'");\r
+    $v_result=1;\r
+    \r
+    // ----- Working variable\r
+    $p_filename = $p_filedescr['filename'];\r
+\r
+    // TBC : Already done in the fileAtt check ... ?\r
+    if ($p_filename == "") {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+  \r
+    // ----- Look for a stored different filename \r
+    if (isset($p_filedescr['stored_filename'])) {\r
+      $v_stored_filename = $p_filedescr['stored_filename'];\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"');\r
+    }\r
+    else {\r
+      $v_stored_filename = $p_filedescr['stored_filename'];\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same');\r
+    }\r
+\r
+    // ----- Set the file properties\r
+    clearstatcache();\r
+    $p_header['version'] = 20;\r
+    $p_header['version_extracted'] = 10;\r
+    $p_header['flag'] = 0;\r
+    $p_header['compression'] = 0;\r
+    $p_header['mtime'] = filemtime($p_filename);\r
+    $p_header['crc'] = 0;\r
+    $p_header['compressed_size'] = 0;\r
+    $p_header['size'] = filesize($p_filename);\r
+    $p_header['filename_len'] = strlen($p_filename);\r
+    $p_header['extra_len'] = 0;\r
+    $p_header['comment_len'] = 0;\r
+    $p_header['disk'] = 0;\r
+    $p_header['internal'] = 0;\r
+//    $p_header['external'] = (is_file($p_filename)?0xFE49FFE0:0x41FF0010);\r
+    $p_header['external'] = (is_file($p_filename)?0x00000000:0x00000010);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'");\r
+    $p_header['offset'] = 0;\r
+    $p_header['filename'] = $p_filename;\r
+    $p_header['stored_filename'] = $v_stored_filename;\r
+    $p_header['extra'] = '';\r
+    $p_header['comment'] = '';\r
+    $p_header['status'] = 'ok';\r
+    $p_header['index'] = -1;\r
+\r
+    // ----- Look for pre-add callback\r
+    if (isset($p_options[PCLZIP_CB_PRE_ADD])) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction");\r
+\r
+      // ----- Generate a local information\r
+      $v_local_header = array();\r
+      $this->privConvertHeader2FileInfo($p_header, $v_local_header);\r
+\r
+      // ----- Call the callback\r
+      // Here I do not use call_user_func() because I need to send a reference to the\r
+      // header.\r
+      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');\r
+      if ($v_result == 0) {\r
+        // ----- Change the file status\r
+        $p_header['status'] = "skipped";\r
+        $v_result = 1;\r
+      }\r
+\r
+      // ----- Update the informations\r
+      // Only some fields can be modified\r
+      if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {\r
+        $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'");\r
+      }\r
+    }\r
+\r
+    // ----- Look for empty stored filename\r
+    if ($p_header['stored_filename'] == "") {\r
+      $p_header['status'] = "filtered";\r
+    }\r
+    \r
+    // ----- Check the path length\r
+    if (strlen($p_header['stored_filename']) > 0xFF) {\r
+      $p_header['status'] = 'filename_too_long';\r
+    }\r
+\r
+    // ----- Look if no error, or file not skipped\r
+    if ($p_header['status'] == 'ok') {\r
+\r
+      // ----- Look for a file\r
+      if (is_file($p_filename))\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");\r
+        // ----- Open the source file\r
+        if (($v_file = @fopen($p_filename, "rb")) == 0) {\r
+          PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+          return PclZip::errorCode();\r
+        }\r
+\r
+        if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");\r
+          // ----- Read the file content\r
+          $v_content_compressed = @fread($v_file, $p_header['size']);\r
+\r
+          // ----- Calculate the CRC\r
+          $p_header['crc'] = @crc32($v_content_compressed);\r
+\r
+          // ----- Set header parameters\r
+          $p_header['compressed_size'] = $p_header['size'];\r
+          $p_header['compression'] = 0;\r
+        }\r
+        else {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");\r
+          // ----- Read the file content\r
+          $v_content = @fread($v_file, $p_header['size']);\r
+\r
+          // ----- Calculate the CRC\r
+          $p_header['crc'] = @crc32($v_content);\r
+\r
+          // ----- Compress the file\r
+          $v_content_compressed = @gzdeflate($v_content);\r
+\r
+          // ----- Set header parameters\r
+          $p_header['compressed_size'] = strlen($v_content_compressed);\r
+          $p_header['compression'] = 8;\r
+        }\r
+        \r
+        // ----- Look for encryption\r
+        /*\r
+        if ((isset($p_options[PCLZIP_OPT_CRYPT]))\r
+                   && ($p_options[PCLZIP_OPT_CRYPT] != "")) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ....");\r
+          \r
+          // Should be a random header\r
+          $v_header = 'xxxxxxxxxxxx';\r
+             $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,\r
+                                                          $p_header['compressed_size'],\r
+                                                      $v_header,\r
+                                                                                                  $p_header['crc'],\r
+                                                                                                  "test");\r
+                                                                                                  \r
+          $p_header['compressed_size'] += 12;\r
+          $p_header['flag'] = 1;\r
+          \r
+          // ----- Add the header to the data\r
+          $v_content_compressed = $v_header.$v_content_compressed;\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed)."");\r
+        }\r
+        */\r
+\r
+        // ----- Call the header generation\r
+        if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {\r
+          @fclose($v_file);\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+\r
+        // ----- Write the compressed (or not) content\r
+        @fwrite($this->zip_fd, \r
+                           $v_content_compressed, $p_header['compressed_size']);\r
+        \r
+        // ----- Close the file\r
+        @fclose($v_file);\r
+      }\r
+\r
+      // ----- Look for a directory\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder");\r
+        // ----- Look for directory last '/'\r
+        if (@substr($p_header['stored_filename'], -1) != '/') {\r
+          $p_header['stored_filename'] .= '/';\r
+        }\r
+\r
+        // ----- Set the file properties\r
+        $p_header['size'] = 0;\r
+        //$p_header['external'] = 0x41FF0010;   // Value for a folder : to be checked\r
+        $p_header['external'] = 0x00000010;   // Value for a folder : to be checked\r
+\r
+        // ----- Call the header generation\r
+        if (($v_result = $this->privWriteFileHeader($p_header)) != 1)\r
+        {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Look for post-add callback\r
+    if (isset($p_options[PCLZIP_CB_POST_ADD])) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction");\r
+\r
+      // ----- Generate a local information\r
+      $v_local_header = array();\r
+      $this->privConvertHeader2FileInfo($p_header, $v_local_header);\r
+\r
+      // ----- Call the callback\r
+      // Here I do not use call_user_func() because I need to send a reference to the\r
+      // header.\r
+      eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');\r
+      if ($v_result == 0) {\r
+        // ----- Ignored\r
+        $v_result = 1;\r
+      }\r
+\r
+      // ----- Update the informations\r
+      // Nothing can be modified\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privCalculateStoredFilename()\r
+  // Description :\r
+  //   Based on file descriptor properties and global options, this method\r
+  //   calculate the filename that will be stored in the archive.\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privCalculateStoredFilename(&$p_filedescr, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'");\r
+    $v_result=1;\r
+    \r
+    // ----- Working variables\r
+    $p_filename = $p_filedescr['filename'];\r
+    if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {\r
+      $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];\r
+    }\r
+    else {\r
+      $p_add_dir = '';\r
+    }\r
+    if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {\r
+      $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];\r
+    }\r
+    else {\r
+      $p_remove_dir = '';\r
+    }\r
+    if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {\r
+      $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];\r
+    }\r
+    else {\r
+      $p_remove_all_dir = 0;\r
+    }\r
+\r
+    // ----- Look for full name change\r
+    if (isset($p_filedescr['new_full_name'])) {\r
+      $v_stored_filename = $p_filedescr['new_full_name'];\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'");\r
+    }\r
+    \r
+    // ----- Look for path and/or short name change\r
+    else {\r
+\r
+      // ----- Look for short name change\r
+      if (isset($p_filedescr['new_short_name'])) {\r
+        $v_path_info = pathinfo($p_filename);\r
+        $v_dir = '';\r
+        if ($v_path_info['dirname'] != '') {\r
+          $v_dir = $v_path_info['dirname'].'/';\r
+        }\r
+        $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'");\r
+      }\r
+      else {\r
+        // ----- Calculate the stored filename\r
+        $v_stored_filename = $p_filename;\r
+      }\r
+\r
+      // ----- Look for all path to remove\r
+      if ($p_remove_all_dir) {\r
+        $v_stored_filename = basename($p_filename);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'");\r
+      }\r
+      // ----- Look for partial path remove\r
+      else if ($p_remove_dir != "") {\r
+        if (substr($p_remove_dir, -1) != '/')\r
+          $p_remove_dir .= "/";\r
+\r
+        if (   (substr($p_filename, 0, 2) == "./")\r
+            || (substr($p_remove_dir, 0, 2) == "./")) {\r
+            \r
+          if (   (substr($p_filename, 0, 2) == "./")\r
+              && (substr($p_remove_dir, 0, 2) != "./")) {\r
+            $p_remove_dir = "./".$p_remove_dir;\r
+          }\r
+          if (   (substr($p_filename, 0, 2) != "./")\r
+              && (substr($p_remove_dir, 0, 2) == "./")) {\r
+            $p_remove_dir = substr($p_remove_dir, 2);\r
+          }\r
+        }\r
+\r
+        $v_compare = PclZipUtilPathInclusion($p_remove_dir,\r
+                                             $v_stored_filename);\r
+        if ($v_compare > 0) {\r
+          if ($v_compare == 2) {\r
+            $v_stored_filename = "";\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder");\r
+          }\r
+          else {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'");\r
+            $v_stored_filename = substr($v_stored_filename,\r
+                                        strlen($p_remove_dir));\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'");\r
+          }\r
+        }\r
+      }\r
+      // ----- Look for path to add\r
+      if ($p_add_dir != "") {\r
+        if (substr($p_add_dir, -1) == "/")\r
+          $v_stored_filename = $p_add_dir.$v_stored_filename;\r
+        else\r
+          $v_stored_filename = $p_add_dir."/".$v_stored_filename;\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'");\r
+      }\r
+    }\r
+\r
+    // ----- Filename (reduce the path of stored name)\r
+    $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);\r
+    $p_filedescr['stored_filename'] = $v_stored_filename;\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename']));\r
+    \r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privWriteFileHeader()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privWriteFileHeader(&$p_header)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');\r
+    $v_result=1;\r
+\r
+    // ----- Store the offset position of the file\r
+    $p_header['offset'] = ftell($this->zip_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']);\r
+\r
+    // ----- Transform UNIX mtime to DOS format mdate/mtime\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');\r
+    $v_date = getdate($p_header['mtime']);\r
+    $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;\r
+    $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];\r
+\r
+    // ----- Packed data\r
+    $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,\r
+                             $p_header['version_extracted'], $p_header['flag'],\r
+                          $p_header['compression'], $v_mtime, $v_mdate,\r
+                          $p_header['crc'], $p_header['compressed_size'],\r
+                                                 $p_header['size'],\r
+                          strlen($p_header['stored_filename']),\r
+                                                 $p_header['extra_len']);\r
+\r
+    // ----- Write the first 148 bytes of the header in the archive\r
+    fputs($this->zip_fd, $v_binary_data, 30);\r
+\r
+    // ----- Write the variable fields\r
+    if (strlen($p_header['stored_filename']) != 0)\r
+    {\r
+      fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));\r
+    }\r
+    if ($p_header['extra_len'] != 0)\r
+    {\r
+      fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privWriteCentralFileHeader()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privWriteCentralFileHeader(&$p_header)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');\r
+    $v_result=1;\r
+\r
+    // TBC\r
+    //for(reset($p_header); $key = key($p_header); next($p_header)) {\r
+    //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]);\r
+    //}\r
+\r
+    // ----- Transform UNIX mtime to DOS format mdate/mtime\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');\r
+    $v_date = getdate($p_header['mtime']);\r
+    $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;\r
+    $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];\r
+\r
+    // ----- Packed data\r
+    $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,\r
+                             $p_header['version'], $p_header['version_extracted'],\r
+                          $p_header['flag'], $p_header['compression'],\r
+                                                 $v_mtime, $v_mdate, $p_header['crc'],\r
+                          $p_header['compressed_size'], $p_header['size'],\r
+                          strlen($p_header['stored_filename']),\r
+                                                 $p_header['extra_len'], $p_header['comment_len'],\r
+                          $p_header['disk'], $p_header['internal'],\r
+                                                 $p_header['external'], $p_header['offset']);\r
+\r
+    // ----- Write the 42 bytes of the header in the zip file\r
+    fputs($this->zip_fd, $v_binary_data, 46);\r
+\r
+    // ----- Write the variable fields\r
+    if (strlen($p_header['stored_filename']) != 0)\r
+    {\r
+      fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));\r
+    }\r
+    if ($p_header['extra_len'] != 0)\r
+    {\r
+      fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);\r
+    }\r
+    if ($p_header['comment_len'] != 0)\r
+    {\r
+      fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privWriteCentralHeader()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"');\r
+    $v_result=1;\r
+\r
+    // ----- Packed data\r
+    $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,\r
+                             $p_nb_entries, $p_size,\r
+                                                 $p_offset, strlen($p_comment));\r
+\r
+    // ----- Write the 22 bytes of the header in the zip file\r
+    fputs($this->zip_fd, $v_binary_data, 22);\r
+\r
+    // ----- Write the variable fields\r
+    if (strlen($p_comment) != 0)\r
+    {\r
+      fputs($this->zip_fd, $p_comment, strlen($p_comment));\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privList()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privList(&$p_list)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list");\r
+    $v_result=1;\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privDisableMagicQuotes();\r
+\r
+    // ----- Open the zip file\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)\r
+    {\r
+      // ----- Magic quotes trick\r
+      $this->privSwapBackMagicQuotes();\r
+      \r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Read the central directory informations\r
+    $v_central_dir = array();\r
+    if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)\r
+    {\r
+      $this->privSwapBackMagicQuotes();\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Go to beginning of Central Dir\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'");\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");\r
+    @rewind($this->zip_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");\r
+    if (@fseek($this->zip_fd, $v_central_dir['offset']))\r
+    {\r
+      $this->privSwapBackMagicQuotes();\r
+\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");\r
+\r
+    // ----- Read each entry\r
+    for ($i=0; $i<$v_central_dir['entries']; $i++)\r
+    {\r
+      // ----- Read the file header\r
+      if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)\r
+      {\r
+        $this->privSwapBackMagicQuotes();\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+      $v_header['index'] = $i;\r
+\r
+      // ----- Get the only interesting attributes\r
+      $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);\r
+      unset($v_header);\r
+    }\r
+\r
+    // ----- Close the zip file\r
+    $this->privCloseFd();\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privSwapBackMagicQuotes();\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privConvertHeader2FileInfo()\r
+  // Description :\r
+  //   This function takes the file informations from the central directory\r
+  //   entries and extract the interesting parameters that will be given back.\r
+  //   The resulting file infos are set in the array $p_info\r
+  //     $p_info['filename'] : Filename with full path. Given by user (add),\r
+  //                           extracted in the filesystem (extract).\r
+  //     $p_info['stored_filename'] : Stored filename in the archive.\r
+  //     $p_info['size'] = Size of the file.\r
+  //     $p_info['compressed_size'] = Compressed size of the file.\r
+  //     $p_info['mtime'] = Last modification date of the file.\r
+  //     $p_info['comment'] = Comment associated with the file.\r
+  //     $p_info['folder'] = true/false : indicates if the entry is a folder or not.\r
+  //     $p_info['status'] = status of the action on the file.\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privConvertHeader2FileInfo($p_header, &$p_info)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'");\r
+    $v_result=1;\r
+\r
+    // ----- Get the interesting attributes\r
+    $p_info['filename'] = $p_header['filename'];\r
+    $p_info['stored_filename'] = $p_header['stored_filename'];\r
+    $p_info['size'] = $p_header['size'];\r
+    $p_info['compressed_size'] = $p_header['compressed_size'];\r
+    $p_info['mtime'] = $p_header['mtime'];\r
+    $p_info['comment'] = $p_header['comment'];\r
+    $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);\r
+    $p_info['index'] = $p_header['index'];\r
+    $p_info['status'] = $p_header['status'];\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privExtractByRule()\r
+  // Description :\r
+  //   Extract a file or directory depending of rules (by index, by name, ...)\r
+  // Parameters :\r
+  //   $p_file_list : An array where will be placed the properties of each\r
+  //                  extracted file\r
+  //   $p_path : Path to add while writing the extracted files\r
+  //   $p_remove_path : Path to remove (from the file memorized path) while writing the\r
+  //                    extracted files. If the path does not match the file path,\r
+  //                    the file is extracted with its memorized path.\r
+  //                    $p_remove_path does not apply to 'list' mode.\r
+  //                    $p_path and $p_remove_path are commulative.\r
+  // Return Values :\r
+  //   1 on success,0 or less on error (see error code list)\r
+  // --------------------------------------------------------------------------------\r
+  function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");\r
+    $v_result=1;\r
+\r
+    // ----- Magic quotes trick\r
+    $this->privDisableMagicQuotes();\r
+\r
+    // ----- Check the path\r
+    if (   ($p_path == "")\r
+           || (   (substr($p_path, 0, 1) != "/")\r
+                   && (substr($p_path, 0, 3) != "../")\r
+                       && (substr($p_path,1,2)!=":/")))\r
+      $p_path = "./".$p_path;\r
+\r
+    // ----- Reduce the path last (and duplicated) '/'\r
+    if (($p_path != "./") && ($p_path != "/"))\r
+    {\r
+      // ----- Look for the path end '/'\r
+      while (substr($p_path, -1) == "/")\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");\r
+        $p_path = substr($p_path, 0, strlen($p_path)-1);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");\r
+      }\r
+    }\r
+\r
+    // ----- Look for path to remove format (should end by /)\r
+    if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))\r
+    {\r
+      $p_remove_path .= '/';\r
+    }\r
+    $p_remove_path_size = strlen($p_remove_path);\r
+\r
+    // ----- Open the zip file\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($v_result = $this->privOpenFd('rb')) != 1)\r
+    {\r
+      $this->privSwapBackMagicQuotes();\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Read the central directory informations\r
+    $v_central_dir = array();\r
+    if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)\r
+    {\r
+      // ----- Close the zip file\r
+      $this->privCloseFd();\r
+      $this->privSwapBackMagicQuotes();\r
+\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Start at beginning of Central Dir\r
+    $v_pos_entry = $v_central_dir['offset'];\r
+\r
+    // ----- Read each entry\r
+    $j_start = 0;\r
+    for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'");\r
+\r
+      // ----- Read next Central dir entry\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+      @rewind($this->zip_fd);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'");\r
+      if (@fseek($this->zip_fd, $v_pos_entry))\r
+      {\r
+        // ----- Close the zip file\r
+        $this->privCloseFd();\r
+        $this->privSwapBackMagicQuotes();\r
+\r
+        // ----- Error log\r
+        PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'");\r
+\r
+      // ----- Read the file header\r
+      $v_header = array();\r
+      if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)\r
+      {\r
+        // ----- Close the zip file\r
+        $this->privCloseFd();\r
+        $this->privSwapBackMagicQuotes();\r
+\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      // ----- Store the index\r
+      $v_header['index'] = $i;\r
+\r
+      // ----- Store the file position\r
+      $v_pos_entry = ftell($this->zip_fd);\r
+\r
+      // ----- Look for the specific extract rules\r
+      $v_extract = false;\r
+\r
+      // ----- Look for extract by name rule\r
+      if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))\r
+          && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");\r
+\r
+          // ----- Look if the filename is in the list\r
+          for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");\r
+\r
+              // ----- Look for a directory\r
+              if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");\r
+\r
+                  // ----- Look if the directory is in the filename path\r
+                  if (   (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))\r
+                      && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {\r
+                      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");\r
+                      $v_extract = true;\r
+                  }\r
+              }\r
+              // ----- Look for a filename\r
+              elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");\r
+                  $v_extract = true;\r
+              }\r
+          }\r
+      }\r
+\r
+      // ----- Look for extract by ereg rule\r
+      else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))\r
+               && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");\r
+\r
+          if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");\r
+              $v_extract = true;\r
+          }\r
+      }\r
+\r
+      // ----- Look for extract by preg rule\r
+      else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))\r
+               && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");\r
+\r
+          if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");\r
+              $v_extract = true;\r
+          }\r
+      }\r
+\r
+      // ----- Look for extract by index rule\r
+      else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))\r
+               && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");\r
+          \r
+          // ----- Look if the index is in the list\r
+          for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");\r
+\r
+              if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");\r
+                  $v_extract = true;\r
+              }\r
+              if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");\r
+                  $j_start = $j+1;\r
+              }\r
+\r
+              if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");\r
+                  break;\r
+              }\r
+          }\r
+      }\r
+\r
+      // ----- Look for no rule, which means extract all the archive\r
+      else {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)");\r
+          $v_extract = true;\r
+      }\r
+\r
+         // ----- Check compression method\r
+         if (   ($v_extract)\r
+             && (   ($v_header['compression'] != 8)\r
+                     && ($v_header['compression'] != 0))) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")");\r
+          $v_header['status'] = 'unsupported_compression';\r
+\r
+          // ----- Look for PCLZIP_OPT_STOP_ON_ERROR\r
+          if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))\r
+                     && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");\r
+\r
+              $this->privSwapBackMagicQuotes();\r
+              \r
+              PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,\r
+                                              "Filename '".$v_header['stored_filename']."' is "\r
+                                                          ."compressed by an unsupported compression "\r
+                                                          ."method (".$v_header['compression'].") ");\r
+\r
+              //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+              return PclZip::errorCode();\r
+                 }\r
+         }\r
+         \r
+         // ----- Check encrypted files\r
+         if (($v_extract) && (($v_header['flag'] & 1) == 1)) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption");\r
+          $v_header['status'] = 'unsupported_encryption';\r
+\r
+          // ----- Look for PCLZIP_OPT_STOP_ON_ERROR\r
+          if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))\r
+                     && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");\r
+\r
+              $this->privSwapBackMagicQuotes();\r
+\r
+              PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,\r
+                                              "Unsupported encryption for "\r
+                                                          ." filename '".$v_header['stored_filename']\r
+                                                                  ."'");\r
+\r
+              //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+              return PclZip::errorCode();\r
+                 }\r
+    }\r
+\r
+      // ----- Look for real extraction\r
+      if (($v_extract) && ($v_header['status'] != 'ok')) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract");\r
+          $v_result = $this->privConvertHeader2FileInfo($v_header,\r
+                                                       $p_file_list[$v_nb_extracted++]);\r
+          if ($v_result != 1) {\r
+              $this->privCloseFd();\r
+              $this->privSwapBackMagicQuotes();\r
+              //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+              return $v_result;\r
+          }\r
+\r
+          $v_extract = false;\r
+      }\r
+      \r
+      // ----- Look for real extraction\r
+      if ($v_extract)\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'");\r
+\r
+        // ----- Go to the file position\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+        @rewind($this->zip_fd);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");\r
+        if (@fseek($this->zip_fd, $v_header['offset']))\r
+        {\r
+          // ----- Close the zip file\r
+          $this->privCloseFd();\r
+\r
+          $this->privSwapBackMagicQuotes();\r
+\r
+          // ----- Error log\r
+          PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');\r
+\r
+          // ----- Return\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+          return PclZip::errorCode();\r
+        }\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");\r
+\r
+        // ----- Look for extraction as string\r
+        if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {\r
+\r
+          // ----- Extracting the file\r
+          $v_result1 = $this->privExtractFileAsString($v_header, $v_string);\r
+          if ($v_result1 < 1) {\r
+            $this->privCloseFd();\r
+            $this->privSwapBackMagicQuotes();\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);\r
+            return $v_result1;\r
+          }\r
+\r
+          // ----- Get the only interesting attributes\r
+          if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)\r
+          {\r
+            // ----- Close the zip file\r
+            $this->privCloseFd();\r
+            $this->privSwapBackMagicQuotes();\r
+\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+          }\r
+\r
+          // ----- Set the file content\r
+          $p_file_list[$v_nb_extracted]['content'] = $v_string;\r
+\r
+          // ----- Next extracted file\r
+          $v_nb_extracted++;\r
+          \r
+          // ----- Look for user callback abort\r
+          if ($v_result1 == 2) {\r
+               break;\r
+          }\r
+        }\r
+        // ----- Look for extraction in standard output\r
+        elseif (   (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))\r
+                       && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {\r
+          // ----- Extracting the file in standard output\r
+          $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);\r
+          if ($v_result1 < 1) {\r
+            $this->privCloseFd();\r
+            $this->privSwapBackMagicQuotes();\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);\r
+            return $v_result1;\r
+          }\r
+\r
+          // ----- Get the only interesting attributes\r
+          if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {\r
+            $this->privCloseFd();\r
+            $this->privSwapBackMagicQuotes();\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+          }\r
+\r
+          // ----- Look for user callback abort\r
+          if ($v_result1 == 2) {\r
+               break;\r
+          }\r
+        }\r
+        // ----- Look for normal extraction\r
+        else {\r
+          // ----- Extracting the file\r
+          $v_result1 = $this->privExtractFile($v_header,\r
+                                                     $p_path, $p_remove_path,\r
+                                                                                         $p_remove_all_path,\r
+                                                                                         $p_options);\r
+          if ($v_result1 < 1) {\r
+            $this->privCloseFd();\r
+            $this->privSwapBackMagicQuotes();\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);\r
+            return $v_result1;\r
+          }\r
+\r
+          // ----- Get the only interesting attributes\r
+          if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)\r
+          {\r
+            // ----- Close the zip file\r
+            $this->privCloseFd();\r
+            $this->privSwapBackMagicQuotes();\r
+\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+          }\r
+\r
+          // ----- Look for user callback abort\r
+          if ($v_result1 == 2) {\r
+               break;\r
+          }\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Close the zip file\r
+    $this->privCloseFd();\r
+    $this->privSwapBackMagicQuotes();\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privExtractFile()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  //\r
+  // 1 : ... ?\r
+  // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback\r
+  // --------------------------------------------------------------------------------\r
+  function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");\r
+    $v_result=1;\r
+\r
+    // ----- Read the file header\r
+    if (($v_result = $this->privReadFileHeader($v_header)) != 1)\r
+    {\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");\r
+\r
+    // ----- Check that the file header is coherent with $p_entry info\r
+    if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {\r
+        // TBC\r
+    }\r
+\r
+    // ----- Look for all path to remove\r
+    if ($p_remove_all_path == true) {\r
+        // ----- Look for folder entry that not need to be extracted\r
+        if (($p_entry['external']&0x00000010)==0x00000010) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered");\r
+\r
+            $p_entry['status'] = "filtered";\r
+\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+        }\r
+\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed");\r
+        // ----- Get the basename of the path\r
+        $p_entry['filename'] = basename($p_entry['filename']);\r
+    }\r
+\r
+    // ----- Look for path to remove\r
+    else if ($p_remove_path != "")\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove");\r
+      if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'");\r
+\r
+        // ----- Change the file status\r
+        $p_entry['status'] = "filtered";\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      $p_remove_path_size = strlen($p_remove_path);\r
+      if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'");\r
+\r
+        // ----- Remove the path\r
+        $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);\r
+\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'");\r
+      }\r
+    }\r
+\r
+    // ----- Add the path\r
+    if ($p_path != '') {\r
+      $p_entry['filename'] = $p_path."/".$p_entry['filename'];\r
+    }\r
+    \r
+    // ----- Check a base_dir_restriction\r
+    if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction");\r
+      $v_inclusion\r
+      = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],\r
+                                $p_entry['filename']); \r
+      if ($v_inclusion == 0) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction");\r
+\r
+        PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,\r
+                                            "Filename '".$p_entry['filename']."' is "\r
+                                                                ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");\r
+\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+    }\r
+\r
+    // ----- Look for pre-extract callback\r
+    if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");\r
+\r
+      // ----- Generate a local information\r
+      $v_local_header = array();\r
+      $this->privConvertHeader2FileInfo($p_entry, $v_local_header);\r
+\r
+      // ----- Call the callback\r
+      // Here I do not use call_user_func() because I need to send a reference to the\r
+      // header.\r
+      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');\r
+      if ($v_result == 0) {\r
+        // ----- Change the file status\r
+        $p_entry['status'] = "skipped";\r
+        $v_result = 1;\r
+      }\r
+      \r
+      // ----- Look for abort result\r
+      if ($v_result == 2) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");\r
+        // ----- This status is internal and will be changed in 'skipped'\r
+        $p_entry['status'] = "aborted";\r
+       $v_result = PCLZIP_ERR_USER_ABORTED;\r
+      }\r
+\r
+      // ----- Update the informations\r
+      // Only some fields can be modified\r
+      $p_entry['filename'] = $v_local_header['filename'];\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");\r
+    }\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");\r
+\r
+    // ----- Look if extraction should be done\r
+    if ($p_entry['status'] == 'ok') {\r
+\r
+    // ----- Look for specific actions while the file exist\r
+    if (file_exists($p_entry['filename']))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists");\r
+\r
+      // ----- Look if file is a directory\r
+      if (is_dir($p_entry['filename']))\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory");\r
+\r
+        // ----- Change the file status\r
+        $p_entry['status'] = "already_a_directory";\r
+        \r
+        // ----- Look for PCLZIP_OPT_STOP_ON_ERROR\r
+        // For historical reason first PclZip implementation does not stop\r
+        // when this kind of error occurs.\r
+        if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))\r
+                   && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");\r
+\r
+            PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,\r
+                                            "Filename '".$p_entry['filename']."' is "\r
+                                                                ."already used by an existing directory");\r
+\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+               }\r
+      }\r
+      // ----- Look if file is write protected\r
+      else if (!is_writeable($p_entry['filename']))\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected");\r
+\r
+        // ----- Change the file status\r
+        $p_entry['status'] = "write_protected";\r
+\r
+        // ----- Look for PCLZIP_OPT_STOP_ON_ERROR\r
+        // For historical reason first PclZip implementation does not stop\r
+        // when this kind of error occurs.\r
+        if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))\r
+                   && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");\r
+\r
+            PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,\r
+                                            "Filename '".$p_entry['filename']."' exists "\r
+                                                                ."and is write protected");\r
+\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+            return PclZip::errorCode();\r
+               }\r
+      }\r
+\r
+      // ----- Look if the extracted file is older\r
+      else if (filemtime($p_entry['filename']) > $p_entry['mtime'])\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is newer (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")");\r
+        // ----- Change the file status\r
+        if (   (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))\r
+                   && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced");\r
+               }\r
+               else {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced");\r
+            $p_entry['status'] = "newer_exist";\r
+\r
+            // ----- Look for PCLZIP_OPT_STOP_ON_ERROR\r
+            // For historical reason first PclZip implementation does not stop\r
+            // when this kind of error occurs.\r
+            if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))\r
+                       && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {\r
+                //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");\r
+\r
+                PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,\r
+                                    "Newer version of '".$p_entry['filename']."' exists "\r
+                                           ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");\r
+\r
+                //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+                return PclZip::errorCode();\r
+                   }\r
+               }\r
+      }\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is older than the extrated one - will be replaced by the extracted one (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")");\r
+      }\r
+    }\r
+\r
+    // ----- Check the directory availability and create it if necessary\r
+    else {\r
+      if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))\r
+        $v_dir_to_check = $p_entry['filename'];\r
+      else if (!strstr($p_entry['filename'], "/"))\r
+        $v_dir_to_check = "";\r
+      else\r
+        $v_dir_to_check = dirname($p_entry['filename']);\r
+\r
+      if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'");\r
+\r
+        // ----- Change the file status\r
+        $p_entry['status'] = "path_creation_fail";\r
+\r
+        // ----- Return\r
+        ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+        //return $v_result;\r
+        $v_result = 1;\r
+      }\r
+    }\r
+    }\r
+\r
+    // ----- Look if extraction should be done\r
+    if ($p_entry['status'] == 'ok') {\r
+\r
+      // ----- Do the extraction (if not a folder)\r
+      if (!(($p_entry['external']&0x00000010)==0x00000010))\r
+      {\r
+        // ----- Look for not compressed file\r
+        if ($p_entry['compression'] == 0) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");\r
+\r
+                 // ----- Opening destination file\r
+          if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)\r
+          {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode");\r
+\r
+            // ----- Change the file status\r
+            $p_entry['status'] = "write_error";\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+          }\r
+\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes");\r
+\r
+          // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks\r
+          $v_size = $p_entry['compressed_size'];\r
+          while ($v_size != 0)\r
+          {\r
+            $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes");\r
+            $v_buffer = @fread($this->zip_fd, $v_read_size);\r
+            /* Try to speed up the code\r
+            $v_binary_data = pack('a'.$v_read_size, $v_buffer);\r
+            @fwrite($v_dest_file, $v_binary_data, $v_read_size);\r
+            */\r
+            @fwrite($v_dest_file, $v_buffer, $v_read_size);            \r
+            $v_size -= $v_read_size;\r
+          }\r
+\r
+          // ----- Closing the destination file\r
+          fclose($v_dest_file);\r
+\r
+          // ----- Change the file mtime\r
+          touch($p_entry['filename'], $p_entry['mtime']);\r
+          \r
+\r
+        }\r
+        else {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")");\r
+          // ----- TBC\r
+          // Need to be finished\r
+          if (($p_entry['flag'] & 1) == 1) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted");\r
+            /*\r
+              // ----- Read the encryption header\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes");\r
+              $v_encryption_header = @fread($this->zip_fd, 12);\r
+              \r
+              // ----- Read the encrypted & compressed file in a buffer\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes");\r
+              $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12);\r
+              \r
+              // ----- Decrypt the buffer\r
+              $this->privDecrypt($v_encryption_header, $v_buffer,\r
+                                            $p_entry['compressed_size']-12, $p_entry['crc']);\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'");\r
+              */\r
+          }\r
+          else {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes");\r
+              // ----- Read the compressed file in a buffer (one shot)\r
+              $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);\r
+          }\r
+          \r
+          // ----- Decompress the file\r
+          $v_file_content = @gzinflate($v_buffer);\r
+          unset($v_buffer);\r
+          if ($v_file_content === FALSE) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file");\r
+\r
+            // ----- Change the file status\r
+            // TBC\r
+            $p_entry['status'] = "error";\r
+            \r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+          }\r
+          \r
+          // ----- Opening destination file\r
+          if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode");\r
+\r
+            // ----- Change the file status\r
+            $p_entry['status'] = "write_error";\r
+\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+          }\r
+\r
+          // ----- Write the uncompressed data\r
+          @fwrite($v_dest_file, $v_file_content, $p_entry['size']);\r
+          unset($v_file_content);\r
+\r
+          // ----- Closing the destination file\r
+          @fclose($v_dest_file);\r
+\r
+          // ----- Change the file mtime\r
+          @touch($p_entry['filename'], $p_entry['mtime']);\r
+        }\r
+\r
+        // ----- Look for chmod option\r
+        if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'");\r
+\r
+          // ----- Change the mode of the file\r
+          @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);\r
+        }\r
+\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");\r
+      }\r
+    }\r
+\r
+       // ----- Change abort status\r
+       if ($p_entry['status'] == "aborted") {\r
+      $p_entry['status'] = "skipped";\r
+       }\r
+       \r
+    // ----- Look for post-extract callback\r
+    elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");\r
+\r
+      // ----- Generate a local information\r
+      $v_local_header = array();\r
+      $this->privConvertHeader2FileInfo($p_entry, $v_local_header);\r
+\r
+      // ----- Call the callback\r
+      // Here I do not use call_user_func() because I need to send a reference to the\r
+      // header.\r
+      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');\r
+\r
+      // ----- Look for abort result\r
+      if ($v_result == 2) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");\r
+       $v_result = PCLZIP_ERR_USER_ABORTED;\r
+      }\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privExtractFileInOutput()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privExtractFileInOutput(&$p_entry, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', "");\r
+    $v_result=1;\r
+\r
+    // ----- Read the file header\r
+    if (($v_result = $this->privReadFileHeader($v_header)) != 1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");\r
+\r
+    // ----- Check that the file header is coherent with $p_entry info\r
+    if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {\r
+        // TBC\r
+    }\r
+\r
+    // ----- Look for pre-extract callback\r
+    if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");\r
+\r
+      // ----- Generate a local information\r
+      $v_local_header = array();\r
+      $this->privConvertHeader2FileInfo($p_entry, $v_local_header);\r
+\r
+      // ----- Call the callback\r
+      // Here I do not use call_user_func() because I need to send a reference to the\r
+      // header.\r
+      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');\r
+      if ($v_result == 0) {\r
+        // ----- Change the file status\r
+        $p_entry['status'] = "skipped";\r
+        $v_result = 1;\r
+      }\r
+\r
+      // ----- Look for abort result\r
+      if ($v_result == 2) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");\r
+        // ----- This status is internal and will be changed in 'skipped'\r
+        $p_entry['status'] = "aborted";\r
+       $v_result = PCLZIP_ERR_USER_ABORTED;\r
+      }\r
+\r
+      // ----- Update the informations\r
+      // Only some fields can be modified\r
+      $p_entry['filename'] = $v_local_header['filename'];\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");\r
+    }\r
+\r
+    // ----- Trace\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");\r
+\r
+    // ----- Look if extraction should be done\r
+    if ($p_entry['status'] == 'ok') {\r
+\r
+      // ----- Do the extraction (if not a folder)\r
+      if (!(($p_entry['external']&0x00000010)==0x00000010)) {\r
+        // ----- Look for not compressed file\r
+        if ($p_entry['compressed_size'] == $p_entry['size']) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");\r
+\r
+          // ----- Read the file in a buffer (one shot)\r
+          $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);\r
+\r
+          // ----- Send the file to the output\r
+          echo $v_buffer;\r
+          unset($v_buffer);\r
+        }\r
+        else {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file");\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes");\r
+\r
+          // ----- Read the compressed file in a buffer (one shot)\r
+          $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);\r
+          \r
+          // ----- Decompress the file\r
+          $v_file_content = gzinflate($v_buffer);\r
+          unset($v_buffer);\r
+\r
+          // ----- Send the file to the output\r
+          echo $v_file_content;\r
+          unset($v_file_content);\r
+        }\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");\r
+      }\r
+    }\r
+\r
+       // ----- Change abort status\r
+       if ($p_entry['status'] == "aborted") {\r
+      $p_entry['status'] = "skipped";\r
+       }\r
+\r
+    // ----- Look for post-extract callback\r
+    elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");\r
+\r
+      // ----- Generate a local information\r
+      $v_local_header = array();\r
+      $this->privConvertHeader2FileInfo($p_entry, $v_local_header);\r
+\r
+      // ----- Call the callback\r
+      // Here I do not use call_user_func() because I need to send a reference to the\r
+      // header.\r
+      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');\r
+\r
+      // ----- Look for abort result\r
+      if ($v_result == 2) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");\r
+       $v_result = PCLZIP_ERR_USER_ABORTED;\r
+      }\r
+    }\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privExtractFileAsString()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privExtractFileAsString(&$p_entry, &$p_string)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'");\r
+    $v_result=1;\r
+\r
+    // ----- Read the file header\r
+    $v_header = array();\r
+    if (($v_result = $this->privReadFileHeader($v_header)) != 1)\r
+    {\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");\r
+\r
+    // ----- Check that the file header is coherent with $p_entry info\r
+    if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {\r
+        // TBC\r
+    }\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'");\r
+\r
+    // ----- Do the extraction (if not a folder)\r
+    if (!(($p_entry['external']&0x00000010)==0x00000010))\r
+    {\r
+      // ----- Look for not compressed file\r
+//      if ($p_entry['compressed_size'] == $p_entry['size'])\r
+      if ($p_entry['compression'] == 0) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");\r
+\r
+        // ----- Reading the file\r
+        $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);\r
+      }\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')");\r
+\r
+        // ----- Reading the file\r
+        $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);\r
+        \r
+        // ----- Decompress the file\r
+        if (($p_string = @gzinflate($v_data)) === FALSE) {\r
+            // TBC\r
+        }\r
+      }\r
+\r
+      // ----- Trace\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");\r
+    }\r
+    else {\r
+        // TBC : error : can not extract a folder in a string\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privReadFileHeader()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privReadFileHeader(&$p_header)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", "");\r
+    $v_result=1;\r
+\r
+    // ----- Read the 4 bytes signature\r
+    $v_binary_data = @fread($this->zip_fd, 4);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");\r
+    $v_data = unpack('Vid', $v_binary_data);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");\r
+\r
+    // ----- Check signature\r
+    if ($v_data['id'] != 0x04034b50)\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header");\r
+\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Read the first 42 bytes of the header\r
+    $v_binary_data = fread($this->zip_fd, 26);\r
+\r
+    // ----- Look for invalid block size\r
+    if (strlen($v_binary_data) != 26)\r
+    {\r
+      $p_header['filename'] = "";\r
+      $p_header['status'] = "invalid_header";\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));\r
+\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Extract the values\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'");\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'");\r
+    $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);\r
+\r
+    // ----- Get filename\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']);\r
+    $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\'');\r
+\r
+    // ----- Get extra_fields\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']);\r
+    if ($v_data['extra_len'] != 0) {\r
+      $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);\r
+    }\r
+    else {\r
+      $p_header['extra'] = '';\r
+    }\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\'');\r
+\r
+    // ----- Extract properties\r
+    $p_header['version_extracted'] = $v_data['version'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\'');\r
+    $p_header['compression'] = $v_data['compression'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\'');\r
+    $p_header['size'] = $v_data['size'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\'');\r
+    $p_header['compressed_size'] = $v_data['compressed_size'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\'');\r
+    $p_header['crc'] = $v_data['crc'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\'');\r
+    $p_header['flag'] = $v_data['flag'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\'');\r
+    $p_header['filename_len'] = $v_data['filename_len'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\'');\r
+\r
+    // ----- Recuperate date in UNIX format\r
+    $p_header['mdate'] = $v_data['mdate'];\r
+    $p_header['mtime'] = $v_data['mtime'];\r
+    if ($p_header['mdate'] && $p_header['mtime'])\r
+    {\r
+      // ----- Extract time\r
+      $v_hour = ($p_header['mtime'] & 0xF800) >> 11;\r
+      $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;\r
+      $v_seconde = ($p_header['mtime'] & 0x001F)*2;\r
+\r
+      // ----- Extract date\r
+      $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;\r
+      $v_month = ($p_header['mdate'] & 0x01E0) >> 5;\r
+      $v_day = $p_header['mdate'] & 0x001F;\r
+\r
+      // ----- Get UNIX date format\r
+      $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);\r
+\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');\r
+    }\r
+    else\r
+    {\r
+      $p_header['mtime'] = time();\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');\r
+    }\r
+\r
+    // TBC\r
+    //for(reset($v_data); $key = key($v_data); next($v_data)) {\r
+    //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]);\r
+    //}\r
+\r
+    // ----- Set the stored filename\r
+    $p_header['stored_filename'] = $p_header['filename'];\r
+\r
+    // ----- Set the status field\r
+    $p_header['status'] = "ok";\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privReadCentralFileHeader()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privReadCentralFileHeader(&$p_header)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", "");\r
+    $v_result=1;\r
+\r
+    // ----- Read the 4 bytes signature\r
+    $v_binary_data = @fread($this->zip_fd, 4);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");\r
+    $v_data = unpack('Vid', $v_binary_data);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");\r
+\r
+    // ----- Check signature\r
+    if ($v_data['id'] != 0x02014b50)\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature");\r
+\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Read the first 42 bytes of the header\r
+    $v_binary_data = fread($this->zip_fd, 42);\r
+\r
+    // ----- Look for invalid block size\r
+    if (strlen($v_binary_data) != 42)\r
+    {\r
+      $p_header['filename'] = "";\r
+      $p_header['status'] = "invalid_header";\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));\r
+\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Extract the values\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'");\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'");\r
+    $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);\r
+\r
+    // ----- Get filename\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']);\r
+    if ($p_header['filename_len'] != 0)\r
+      $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);\r
+    else\r
+      $p_header['filename'] = '';\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\'');\r
+\r
+    // ----- Get extra\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']);\r
+    if ($p_header['extra_len'] != 0)\r
+      $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);\r
+    else\r
+      $p_header['extra'] = '';\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\'');\r
+\r
+    // ----- Get comment\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']);\r
+    if ($p_header['comment_len'] != 0)\r
+      $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);\r
+    else\r
+      $p_header['comment'] = '';\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\'');\r
+\r
+    // ----- Extract properties\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\'');\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\'');\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\'');\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\'');\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\'');\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\'');\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\'');\r
+\r
+    // ----- Recuperate date in UNIX format\r
+    if ($p_header['mdate'] && $p_header['mtime'])\r
+    {\r
+      // ----- Extract time\r
+      $v_hour = ($p_header['mtime'] & 0xF800) >> 11;\r
+      $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;\r
+      $v_seconde = ($p_header['mtime'] & 0x001F)*2;\r
+\r
+      // ----- Extract date\r
+      $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;\r
+      $v_month = ($p_header['mdate'] & 0x01E0) >> 5;\r
+      $v_day = $p_header['mdate'] & 0x001F;\r
+\r
+      // ----- Get UNIX date format\r
+      $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);\r
+\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');\r
+    }\r
+    else\r
+    {\r
+      $p_header['mtime'] = time();\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');\r
+    }\r
+\r
+    // ----- Set the stored filename\r
+    $p_header['stored_filename'] = $p_header['filename'];\r
+\r
+    // ----- Set default status to ok\r
+    $p_header['status'] = 'ok';\r
+\r
+    // ----- Look if it is a directory\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'");\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "External (Hex) : '".sprintf("Ox%04X", $p_header['external'])."' (".(($p_header['external']&0x00000010)==0x00000010?'is a folder':'is a file').')');\r
+    if (substr($p_header['filename'], -1) == '/') {\r
+      //$p_header['external'] = 0x41FF0010;\r
+      $p_header['external'] = 0x00000010;\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\'');\r
+    }\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\'');\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privCheckFileHeaders()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  //   1 on success,\r
+  //   0 on error;\r
+  // --------------------------------------------------------------------------------\r
+  function privCheckFileHeaders(&$p_local_header, &$p_central_header)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", "");\r
+    $v_result=1;\r
+\r
+       // ----- Check the static values\r
+       // TBC\r
+       if ($p_local_header['filename'] != $p_central_header['filename']) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed');\r
+       }\r
+       if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed');\r
+       }\r
+       if ($p_local_header['flag'] != $p_central_header['flag']) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed');\r
+       }\r
+       if ($p_local_header['compression'] != $p_central_header['compression']) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed');\r
+       }\r
+       if ($p_local_header['mtime'] != $p_central_header['mtime']) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed');\r
+       }\r
+       if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed');\r
+       }\r
+\r
+       // ----- Look for flag bit 3\r
+       if (($p_local_header['flag'] & 8) == 8) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !');\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header');\r
+        $p_local_header['size'] = $p_central_header['size'];\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\'');\r
+        $p_local_header['compressed_size'] = $p_central_header['compressed_size'];\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\'');\r
+        $p_local_header['crc'] = $p_central_header['crc'];\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\'');\r
+       }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privReadEndCentralDir()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privReadEndCentralDir(&$p_central_dir)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", "");\r
+    $v_result=1;\r
+\r
+    // ----- Go to the end of the zip file\r
+    $v_size = filesize($this->zipname);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size");\r
+    @fseek($this->zip_fd, $v_size);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\'');\r
+    if (@ftell($this->zip_fd) != $v_size)\r
+    {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- First try : look if this is an archive with no commentaries (most of the time)\r
+    // in this case the end of central dir is at 22 bytes of the file end\r
+    $v_found = 0;\r
+    if ($v_size > 26) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment');\r
+      @fseek($this->zip_fd, $v_size-22);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\'');\r
+      if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))\r
+      {\r
+        // ----- Error log\r
+        PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+\r
+      // ----- Read for bytes\r
+      $v_binary_data = @fread($this->zip_fd, 4);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");\r
+      $v_data = @unpack('Vid', $v_binary_data);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");\r
+\r
+      // ----- Check signature\r
+      if ($v_data['id'] == 0x06054b50) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position.");\r
+        $v_found = 1;\r
+      }\r
+\r
+      $v_pos = ftell($this->zip_fd);\r
+    }\r
+\r
+    // ----- Go back to the maximum possible size of the Central Dir End Record\r
+    if (!$v_found) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir');\r
+      $v_maximum_size = 65557; // 0xFFFF + 22;\r
+      if ($v_maximum_size > $v_size)\r
+        $v_maximum_size = $v_size;\r
+      @fseek($this->zip_fd, $v_size-$v_maximum_size);\r
+      if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))\r
+      {\r
+        // ----- Error log\r
+        PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\'');\r
+\r
+      // ----- Read byte per byte in order to find the signature\r
+      $v_pos = ftell($this->zip_fd);\r
+      $v_bytes = 0x00000000;\r
+      while ($v_pos < $v_size)\r
+      {\r
+        // ----- Read a byte\r
+        $v_byte = @fread($this->zip_fd, 1);\r
+\r
+        // -----  Add the byte\r
+        $v_bytes = ($v_bytes << 8) | Ord($v_byte);\r
+\r
+        // ----- Compare the bytes\r
+        if ($v_bytes == 0x504b0506)\r
+        {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\'');\r
+          $v_pos++;\r
+          break;\r
+        }\r
+\r
+        $v_pos++;\r
+      }\r
+\r
+      // ----- Look if not found end of central dir\r
+      if ($v_pos == $v_size)\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature");\r
+\r
+        // ----- Error log\r
+        PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");\r
+\r
+        // ----- Return\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+        return PclZip::errorCode();\r
+      }\r
+    }\r
+\r
+    // ----- Read the first 18 bytes of the header\r
+    $v_binary_data = fread($this->zip_fd, 18);\r
+\r
+    // ----- Look for invalid block size\r
+    if (strlen($v_binary_data) != 18)\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));\r
+\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Extract the values\r
+    ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'");\r
+    ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'");\r
+    $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);\r
+\r
+    // ----- Check the global size\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']);\r
+    if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive.");\r
+\r
+         // ----- Removed in release 2.2 see readme file\r
+         // The check of the file size is a little too strict.\r
+         // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.\r
+         // While decrypted, zip has training 0 bytes\r
+         if (0) {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,\r
+                              'The central dir is not at the end of the archive.'\r
+                                                  .' Some trailing bytes exists after the archive.');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+         }\r
+    }\r
+\r
+    // ----- Get comment\r
+    if ($v_data['comment_size'] != 0)\r
+      $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);\r
+    else\r
+      $p_central_dir['comment'] = '';\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\'');\r
+\r
+    $p_central_dir['entries'] = $v_data['entries'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\'');\r
+    $p_central_dir['disk_entries'] = $v_data['disk_entries'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\'');\r
+    $p_central_dir['offset'] = $v_data['offset'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\'');\r
+    $p_central_dir['size'] = $v_data['size'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\'');\r
+    $p_central_dir['disk'] = $v_data['disk'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\'');\r
+    $p_central_dir['disk_start'] = $v_data['disk_start'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\'');\r
+\r
+    // TBC\r
+    //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {\r
+    //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]);\r
+    //}\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privDeleteByRule()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privDeleteByRule(&$p_result_list, &$p_options)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", "");\r
+    $v_result=1;\r
+    $v_list_detail = array();\r
+\r
+    // ----- Open the zip file\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($v_result=$this->privOpenFd('rb')) != 1)\r
+    {\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Read the central directory informations\r
+    $v_central_dir = array();\r
+    if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)\r
+    {\r
+      $this->privCloseFd();\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Go to beginning of File\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");\r
+    @rewind($this->zip_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");\r
+\r
+    // ----- Scan all the files\r
+    // ----- Start at beginning of Central Dir\r
+    $v_pos_entry = $v_central_dir['offset'];\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+    @rewind($this->zip_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");\r
+    if (@fseek($this->zip_fd, $v_pos_entry))\r
+    {\r
+      // ----- Close the zip file\r
+      $this->privCloseFd();\r
+\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");\r
+\r
+    // ----- Read each entry\r
+    $v_header_list = array();\r
+    $j_start = 0;\r
+    for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')");\r
+\r
+      // ----- Read the file header\r
+      $v_header_list[$v_nb_extracted] = array();\r
+      if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)\r
+      {\r
+        // ----- Close the zip file\r
+        $this->privCloseFd();\r
+\r
+        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'");\r
+\r
+      // ----- Store the index\r
+      $v_header_list[$v_nb_extracted]['index'] = $i;\r
+\r
+      // ----- Look for the specific extract rules\r
+      $v_found = false;\r
+\r
+      // ----- Look for extract by name rule\r
+      if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))\r
+          && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");\r
+\r
+          // ----- Look if the filename is in the list\r
+          for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");\r
+\r
+              // ----- Look for a directory\r
+              if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");\r
+\r
+                  // ----- Look if the directory is in the filename path\r
+                  if (   (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))\r
+                      && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {\r
+                      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");\r
+                      $v_found = true;\r
+                  }\r
+                  elseif (   (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */\r
+                          && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {\r
+                      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory");\r
+                      $v_found = true;\r
+                  }\r
+              }\r
+              // ----- Look for a filename\r
+              elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");\r
+                  $v_found = true;\r
+              }\r
+          }\r
+      }\r
+\r
+      // ----- Look for extract by ereg rule\r
+      else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))\r
+               && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");\r
+\r
+          if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");\r
+              $v_found = true;\r
+          }\r
+      }\r
+\r
+      // ----- Look for extract by preg rule\r
+      else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))\r
+               && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");\r
+\r
+          if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");\r
+              $v_found = true;\r
+          }\r
+      }\r
+\r
+      // ----- Look for extract by index rule\r
+      else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))\r
+               && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");\r
+\r
+          // ----- Look if the index is in the list\r
+          for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {\r
+              //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");\r
+\r
+              if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");\r
+                  $v_found = true;\r
+              }\r
+              if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");\r
+                  $j_start = $j+1;\r
+              }\r
+\r
+              if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {\r
+                  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");\r
+                  break;\r
+              }\r
+          }\r
+      }\r
+      else {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file");\r
+       $v_found = true;\r
+      }\r
+\r
+      // ----- Look for deletion\r
+      if ($v_found)\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted");\r
+        unset($v_header_list[$v_nb_extracted]);\r
+      }\r
+      else\r
+      {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted");\r
+        $v_nb_extracted++;\r
+      }\r
+    }\r
+\r
+    // ----- Look if something need to be deleted\r
+    if ($v_nb_extracted > 0) {\r
+\r
+        // ----- Creates a temporay file\r
+        $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';\r
+\r
+        // ----- Creates a temporary zip archive\r
+        $v_temp_zip = new PclZip($v_zip_temp_name);\r
+\r
+        // ----- Open the temporary zip file in write mode\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode");\r
+        if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {\r
+            $this->privCloseFd();\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+        }\r
+\r
+        // ----- Look which file need to be kept\r
+        for ($i=0; $i<sizeof($v_header_list); $i++) {\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'");\r
+\r
+            // ----- Calculate the position of the header\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'");\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+            @rewind($this->zip_fd);\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");\r
+            if (@fseek($this->zip_fd,  $v_header_list[$i]['offset'])) {\r
+                // ----- Close the zip file\r
+                $this->privCloseFd();\r
+                $v_temp_zip->privCloseFd();\r
+                @unlink($v_zip_temp_name);\r
+\r
+                // ----- Error log\r
+                PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');\r
+\r
+                // ----- Return\r
+                //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+                return PclZip::errorCode();\r
+            }\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");\r
+\r
+            // ----- Read the file header\r
+            $v_local_header = array();\r
+            if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {\r
+                // ----- Close the zip file\r
+                $this->privCloseFd();\r
+                $v_temp_zip->privCloseFd();\r
+                @unlink($v_zip_temp_name);\r
+\r
+                // ----- Return\r
+                //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+                return $v_result;\r
+            }\r
+            \r
+            // ----- Check that local file header is same as central file header\r
+            if ($this->privCheckFileHeaders($v_local_header,\r
+                                                       $v_header_list[$i]) != 1) {\r
+                // TBC\r
+            }\r
+            unset($v_local_header);\r
+\r
+            // ----- Write the file header\r
+            if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {\r
+                // ----- Close the zip file\r
+                $this->privCloseFd();\r
+                $v_temp_zip->privCloseFd();\r
+                @unlink($v_zip_temp_name);\r
+\r
+                // ----- Return\r
+                //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+                return $v_result;\r
+            }\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'");\r
+\r
+            // ----- Read/write the data block\r
+            if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {\r
+                // ----- Close the zip file\r
+                $this->privCloseFd();\r
+                $v_temp_zip->privCloseFd();\r
+                @unlink($v_zip_temp_name);\r
+\r
+                // ----- Return\r
+                //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+                return $v_result;\r
+            }\r
+        }\r
+\r
+        // ----- Store the offset of the central dir\r
+        $v_offset = @ftell($v_temp_zip->zip_fd);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset");\r
+\r
+        // ----- Re-Create the Central Dir files header\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory");\r
+        for ($i=0; $i<sizeof($v_header_list); $i++) {\r
+            // ----- Create the file header\r
+            //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']);\r
+            if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {\r
+                $v_temp_zip->privCloseFd();\r
+                $this->privCloseFd();\r
+                @unlink($v_zip_temp_name);\r
+\r
+                // ----- Return\r
+                //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+                return $v_result;\r
+            }\r
+\r
+            // ----- Transform the header to a 'usable' info\r
+            $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);\r
+        }\r
+\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer");\r
+\r
+        // ----- Zip file comment\r
+        $v_comment = '';\r
+        if (isset($p_options[PCLZIP_OPT_COMMENT])) {\r
+          $v_comment = $p_options[PCLZIP_OPT_COMMENT];\r
+        }\r
+\r
+        // ----- Calculate the size of the central header\r
+        $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;\r
+\r
+        // ----- Create the central dir footer\r
+        if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {\r
+            // ----- Reset the file list\r
+            unset($v_header_list);\r
+            $v_temp_zip->privCloseFd();\r
+            $this->privCloseFd();\r
+            @unlink($v_zip_temp_name);\r
+\r
+            // ----- Return\r
+            //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+            return $v_result;\r
+        }\r
+\r
+        // ----- Close\r
+        $v_temp_zip->privCloseFd();\r
+        $this->privCloseFd();\r
+\r
+        // ----- Delete the zip file\r
+        // TBC : I should test the result ...\r
+        @unlink($this->zipname);\r
+\r
+        // ----- Rename the temporary file\r
+        // TBC : I should test the result ...\r
+        //@rename($v_zip_temp_name, $this->zipname);\r
+        PclZipUtilRename($v_zip_temp_name, $this->zipname);\r
+    \r
+        // ----- Destroy the temporary archive\r
+        unset($v_temp_zip);\r
+    }\r
+    \r
+    // ----- Remove every files : reset the file\r
+    else if ($v_central_dir['entries'] != 0) {\r
+        $this->privCloseFd();\r
+\r
+        if (($v_result = $this->privOpenFd('wb')) != 1) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+\r
+        if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+\r
+        $this->privCloseFd();\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privDirCheck()\r
+  // Description :\r
+  //   Check if a directory exists, if not it creates it and all the parents directory\r
+  //   which may be useful.\r
+  // Parameters :\r
+  //   $p_dir : Directory path to check.\r
+  // Return Values :\r
+  //    1 : OK\r
+  //   -1 : Unable to create directory\r
+  // --------------------------------------------------------------------------------\r
+  function privDirCheck($p_dir, $p_is_dir=false)\r
+  {\r
+    $v_result = 1;\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'");\r
+\r
+    // ----- Remove the final '/'\r
+    if (($p_is_dir) && (substr($p_dir, -1)=='/'))\r
+    {\r
+      $p_dir = substr($p_dir, 0, strlen($p_dir)-1);\r
+    }\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'");\r
+\r
+    // ----- Check the directory availability\r
+    if ((is_dir($p_dir)) || ($p_dir == ""))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory");\r
+      return 1;\r
+    }\r
+\r
+    // ----- Extract parent directory\r
+    $p_parent_dir = dirname($p_dir);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'");\r
+\r
+    // ----- Just a check\r
+    if ($p_parent_dir != $p_dir)\r
+    {\r
+      // ----- Look for parent directory\r
+      if ($p_parent_dir != "")\r
+      {\r
+        if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)\r
+        {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Create the directory\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'");\r
+    if (!@mkdir($p_dir, 0777))\r
+    {\r
+      // ----- Error log\r
+      PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created");\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privMerge()\r
+  // Description :\r
+  //   If $p_archive_to_add does not exist, the function exit with a success result.\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privMerge(&$p_archive_to_add)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'");\r
+    $v_result=1;\r
+\r
+    // ----- Look if the archive_to_add exists\r
+    if (!is_file($p_archive_to_add->zipname))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge.");\r
+\r
+      // ----- Nothing to merge, so merge is a success\r
+      $v_result = 1;\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Look if the archive exists\r
+    if (!is_file($this->zipname))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add.");\r
+\r
+      // ----- Do a duplicate\r
+      $v_result = $this->privDuplicate($p_archive_to_add->zipname);\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Open the zip file\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($v_result=$this->privOpenFd('rb')) != 1)\r
+    {\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Read the central directory informations\r
+    $v_central_dir = array();\r
+    if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)\r
+    {\r
+      $this->privCloseFd();\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Go to beginning of File\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");\r
+    @rewind($this->zip_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");\r
+\r
+    // ----- Open the archive_to_add file\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode");\r
+    if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)\r
+    {\r
+      $this->privCloseFd();\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Read the central directory informations\r
+    $v_central_dir_to_add = array();\r
+    if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)\r
+    {\r
+      $this->privCloseFd();\r
+      $p_archive_to_add->privCloseFd();\r
+\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Go to beginning of File\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");\r
+    @rewind($p_archive_to_add->zip_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");\r
+\r
+    // ----- Creates a temporay file\r
+    $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';\r
+\r
+    // ----- Open the temporary file in write mode\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)\r
+    {\r
+      $this->privCloseFd();\r
+      $p_archive_to_add->privCloseFd();\r
+\r
+      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Copy the files from the archive to the temporary file\r
+    // TBC : Here I should better append the file and go back to erase the central dir\r
+    $v_size = $v_central_dir['offset'];\r
+    while ($v_size != 0)\r
+    {\r
+      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+      $v_buffer = fread($this->zip_fd, $v_read_size);\r
+      @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);\r
+      $v_size -= $v_read_size;\r
+    }\r
+\r
+    // ----- Copy the files from the archive_to_add into the temporary file\r
+    $v_size = $v_central_dir_to_add['offset'];\r
+    while ($v_size != 0)\r
+    {\r
+      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+      $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);\r
+      @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);\r
+      $v_size -= $v_read_size;\r
+    }\r
+\r
+    // ----- Store the offset of the central dir\r
+    $v_offset = @ftell($v_zip_temp_fd);\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");\r
+\r
+    // ----- Copy the block of file headers from the old archive\r
+    $v_size = $v_central_dir['size'];\r
+    while ($v_size != 0)\r
+    {\r
+      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+      $v_buffer = @fread($this->zip_fd, $v_read_size);\r
+      @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);\r
+      $v_size -= $v_read_size;\r
+    }\r
+\r
+    // ----- Copy the block of file headers from the archive_to_add\r
+    $v_size = $v_central_dir_to_add['size'];\r
+    while ($v_size != 0)\r
+    {\r
+      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+      $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);\r
+      @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);\r
+      $v_size -= $v_read_size;\r
+    }\r
+\r
+    // ----- Merge the file comments\r
+    $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];\r
+\r
+    // ----- Calculate the size of the (new) central header\r
+    $v_size = @ftell($v_zip_temp_fd)-$v_offset;\r
+\r
+    // ----- Swap the file descriptor\r
+    // Here is a trick : I swap the temporary fd with the zip fd, in order to use\r
+    // the following methods on the temporary fil and not the real archive fd\r
+    $v_swap = $this->zip_fd;\r
+    $this->zip_fd = $v_zip_temp_fd;\r
+    $v_zip_temp_fd = $v_swap;\r
+\r
+    // ----- Create the central dir footer\r
+    if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)\r
+    {\r
+      $this->privCloseFd();\r
+      $p_archive_to_add->privCloseFd();\r
+      @fclose($v_zip_temp_fd);\r
+      $this->zip_fd = null;\r
+\r
+      // ----- Reset the file list\r
+      unset($v_header_list);\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Swap back the file descriptor\r
+    $v_swap = $this->zip_fd;\r
+    $this->zip_fd = $v_zip_temp_fd;\r
+    $v_zip_temp_fd = $v_swap;\r
+\r
+    // ----- Close\r
+    $this->privCloseFd();\r
+    $p_archive_to_add->privCloseFd();\r
+\r
+    // ----- Close the temporary file\r
+    @fclose($v_zip_temp_fd);\r
+\r
+    // ----- Delete the zip file\r
+    // TBC : I should test the result ...\r
+    @unlink($this->zipname);\r
+\r
+    // ----- Rename the temporary file\r
+    // TBC : I should test the result ...\r
+    //@rename($v_zip_temp_name, $this->zipname);\r
+    PclZipUtilRename($v_zip_temp_name, $this->zipname);\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privDuplicate()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privDuplicate($p_archive_filename)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'");\r
+    $v_result=1;\r
+\r
+    // ----- Look if the $p_archive_filename exists\r
+    if (!is_file($p_archive_filename))\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate.");\r
+\r
+      // ----- Nothing to duplicate, so duplicate is a success.\r
+      $v_result = 1;\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Open the zip file\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($v_result=$this->privOpenFd('wb')) != 1)\r
+    {\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Open the temporary file in write mode\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+    if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)\r
+    {\r
+      $this->privCloseFd();\r
+\r
+      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');\r
+\r
+      // ----- Return\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+      return PclZip::errorCode();\r
+    }\r
+\r
+    // ----- Copy the files from the archive to the temporary file\r
+    // TBC : Here I should better append the file and go back to erase the central dir\r
+    $v_size = filesize($p_archive_filename);\r
+    while ($v_size != 0)\r
+    {\r
+      $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes");\r
+      $v_buffer = fread($v_zip_temp_fd, $v_read_size);\r
+      @fwrite($this->zip_fd, $v_buffer, $v_read_size);\r
+      $v_size -= $v_read_size;\r
+    }\r
+\r
+    // ----- Close\r
+    $this->privCloseFd();\r
+\r
+    // ----- Close the temporary file\r
+    @fclose($v_zip_temp_fd);\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privErrorLog()\r
+  // Description :\r
+  // Parameters :\r
+  // --------------------------------------------------------------------------------\r
+  function privErrorLog($p_error_code=0, $p_error_string='')\r
+  {\r
+    if (PCLZIP_ERROR_EXTERNAL == 1) {\r
+      PclError($p_error_code, $p_error_string);\r
+    }\r
+    else {\r
+      $this->error_code = $p_error_code;\r
+      $this->error_string = $p_error_string;\r
+    }\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privErrorReset()\r
+  // Description :\r
+  // Parameters :\r
+  // --------------------------------------------------------------------------------\r
+  function privErrorReset()\r
+  {\r
+    if (PCLZIP_ERROR_EXTERNAL == 1) {\r
+      PclErrorReset();\r
+    }\r
+    else {\r
+      $this->error_code = 0;\r
+      $this->error_string = '';\r
+    }\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privDecrypt()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size."");\r
+    $v_result=1;\r
+    \r
+    // ----- To Be Modified ;-)\r
+    $v_pwd = "test";\r
+    \r
+    $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header,\r
+                                        $p_crc, $v_pwd);\r
+    \r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privDisableMagicQuotes()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privDisableMagicQuotes()\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', "");\r
+    $v_result=1;\r
+\r
+    // ----- Look if function exists\r
+    if (   (!function_exists("get_magic_quotes_runtime"))\r
+           || (!function_exists("set_magic_quotes_runtime"))) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+       }\r
+\r
+    // ----- Look if already done\r
+    if ($this->magic_quotes_status != -1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled");\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+       }\r
+\r
+       // ----- Get and memorize the magic_quote value\r
+       $this->magic_quotes_status = @get_magic_quotes_runtime();\r
+    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'");\r
+\r
+       // ----- Disable magic_quotes\r
+       if ($this->magic_quotes_status == 1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes");\r
+         @set_magic_quotes_runtime(0);\r
+       }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : privSwapBackMagicQuotes()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function privSwapBackMagicQuotes()\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', "");\r
+    $v_result=1;\r
+\r
+    // ----- Look if function exists\r
+    if (   (!function_exists("get_magic_quotes_runtime"))\r
+           || (!function_exists("set_magic_quotes_runtime"))) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+       }\r
+\r
+    // ----- Look if something to do\r
+    if ($this->magic_quotes_status != -1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified");\r
+      //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+       }\r
+\r
+       // ----- Swap back magic_quotes\r
+       if ($this->magic_quotes_status == 1) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes");\r
+         @set_magic_quotes_runtime($this->magic_quotes_status);\r
+       }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  }\r
+  // End of class\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclZipUtilPathReduction()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclZipUtilPathReduction($p_dir)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'");\r
+    $v_result = "";\r
+\r
+    // ----- Look for not empty path\r
+    if ($p_dir != "") {\r
+      // ----- Explode path by directory names\r
+      $v_list = explode("/", $p_dir);\r
+\r
+      // ----- Study directories from last to first\r
+      $v_skip = 0;\r
+      for ($i=sizeof($v_list)-1; $i>=0; $i--) {\r
+        // ----- Look for current path\r
+        if ($v_list[$i] == ".") {\r
+          // ----- Ignore this directory\r
+          // Should be the first $i=0, but no check is done\r
+        }\r
+        else if ($v_list[$i] == "..") {\r
+                 $v_skip++;\r
+        }\r
+        else if ($v_list[$i] == "") {\r
+                 // ----- First '/' i.e. root slash\r
+                 if ($i == 0) {\r
+            $v_result = "/".$v_result;\r
+                   if ($v_skip > 0) {\r
+                       // ----- It is an invalid path, so the path is not modified\r
+                       // TBC\r
+                       $v_result = $p_dir;\r
+                //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged");\r
+                $v_skip = 0;\r
+                   }\r
+                 }\r
+                 // ----- Last '/' i.e. indicates a directory\r
+                 else if ($i == (sizeof($v_list)-1)) {\r
+            $v_result = $v_list[$i];\r
+                 }\r
+                 // ----- Double '/' inside the path\r
+                 else {\r
+            // ----- Ignore only the double '//' in path,\r
+            // but not the first and last '/'\r
+                 }\r
+        }\r
+        else {\r
+                 // ----- Look for item to skip\r
+                 if ($v_skip > 0) {\r
+                   $v_skip--;\r
+                 }\r
+                 else {\r
+            $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");\r
+                 }\r
+        }\r
+      }\r
+      \r
+      // ----- Look for skip\r
+      if ($v_skip > 0) {\r
+        while ($v_skip > 0) {\r
+            $v_result = '../'.$v_result;\r
+            $v_skip--;\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclZipUtilPathInclusion()\r
+  // Description :\r
+  //   This function indicates if the path $p_path is under the $p_dir tree. Or,\r
+  //   said in an other way, if the file or sub-dir $p_path is inside the dir\r
+  //   $p_dir.\r
+  //   The function indicates also if the path is exactly the same as the dir.\r
+  //   This function supports path with duplicated '/' like '//', but does not\r
+  //   support '.' or '..' statements.\r
+  // Parameters :\r
+  // Return Values :\r
+  //   0 if $p_path is not inside directory $p_dir\r
+  //   1 if $p_path is inside directory $p_dir\r
+  //   2 if $p_path is exactly the same as $p_dir\r
+  // --------------------------------------------------------------------------------\r
+  function PclZipUtilPathInclusion($p_dir, $p_path)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'");\r
+    $v_result = 1;\r
+    \r
+    // ----- Look for path beginning by ./\r
+    if (   ($p_dir == '.')\r
+        || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {\r
+      $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'");\r
+    }\r
+    if (   ($p_path == '.')\r
+        || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {\r
+      $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'");\r
+    }\r
+\r
+    // ----- Explode dir and path by directory separator\r
+    $v_list_dir = explode("/", $p_dir);\r
+    $v_list_dir_size = sizeof($v_list_dir);\r
+    $v_list_path = explode("/", $p_path);\r
+    $v_list_path_size = sizeof($v_list_path);\r
+\r
+    // ----- Study directories paths\r
+    $i = 0;\r
+    $j = 0;\r
+    while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'");\r
+\r
+      // ----- Look for empty dir (path reduction)\r
+      if ($v_list_dir[$i] == '') {\r
+        $i++;\r
+        continue;\r
+      }\r
+      if ($v_list_path[$j] == '') {\r
+        $j++;\r
+        continue;\r
+      }\r
+\r
+      // ----- Compare the items\r
+      if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != ''))  {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different");\r
+        $v_result = 0;\r
+      }\r
+\r
+      // ----- Next items\r
+      $i++;\r
+      $j++;\r
+    }\r
+\r
+    // ----- Look if everything seems to be the same\r
+    if ($v_result) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break");\r
+      // ----- Skip all the empty items\r
+      while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;\r
+      while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Looking on dir($i)='".($i < $v_list_dir_size?$v_list_dir[$i]:'')."' and path($j)='".($j < $v_list_path_size?$v_list_path[$j]:'')."'");\r
+\r
+      if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {\r
+        // ----- There are exactly the same\r
+        $v_result = 2;\r
+      }\r
+      else if ($i < $v_list_dir_size) {\r
+        // ----- The path is shorter than the dir\r
+        $v_result = 0;\r
+      }\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclZipUtilCopyBlock()\r
+  // Description :\r
+  // Parameters :\r
+  //   $p_mode : read/write compression mode\r
+  //             0 : src & dest normal\r
+  //             1 : src gzip, dest normal\r
+  //             2 : src normal, dest gzip\r
+  //             3 : src & dest gzip\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode");\r
+    $v_result = 1;\r
+\r
+    if ($p_mode==0)\r
+    {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src)));\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest)));\r
+      while ($p_size != 0)\r
+      {\r
+        $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+        $v_buffer = @fread($p_src, $v_read_size);\r
+        @fwrite($p_dest, $v_buffer, $v_read_size);\r
+        $p_size -= $v_read_size;\r
+      }\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src)));\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest)));\r
+    }\r
+    else if ($p_mode==1)\r
+    {\r
+      while ($p_size != 0)\r
+      {\r
+        $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+        $v_buffer = @gzread($p_src, $v_read_size);\r
+        @fwrite($p_dest, $v_buffer, $v_read_size);\r
+        $p_size -= $v_read_size;\r
+      }\r
+    }\r
+    else if ($p_mode==2)\r
+    {\r
+      while ($p_size != 0)\r
+      {\r
+        $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+        $v_buffer = @fread($p_src, $v_read_size);\r
+        @gzwrite($p_dest, $v_buffer, $v_read_size);\r
+        $p_size -= $v_read_size;\r
+      }\r
+    }\r
+    else if ($p_mode==3)\r
+    {\r
+      while ($p_size != 0)\r
+      {\r
+        $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");\r
+        $v_buffer = @gzread($p_src, $v_read_size);\r
+        @gzwrite($p_dest, $v_buffer, $v_read_size);\r
+        $p_size -= $v_read_size;\r
+      }\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclZipUtilRename()\r
+  // Description :\r
+  //   This function tries to do a simple rename() function. If it fails, it\r
+  //   tries to copy the $p_src file in a new $p_dest file and then unlink the\r
+  //   first one.\r
+  // Parameters :\r
+  //   $p_src : Old filename\r
+  //   $p_dest : New filename\r
+  // Return Values :\r
+  //   1 on success, 0 on failure.\r
+  // --------------------------------------------------------------------------------\r
+  function PclZipUtilRename($p_src, $p_dest)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest");\r
+    $v_result = 1;\r
+\r
+    // ----- Try to rename the files\r
+    if (!@rename($p_src, $p_dest)) {\r
+      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink");\r
+\r
+      // ----- Try to copy & unlink the src\r
+      if (!@copy($p_src, $p_dest)) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file");\r
+        $v_result = 0;\r
+      }\r
+      else if (!@unlink($p_src)) {\r
+        //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename");\r
+        $v_result = 0;\r
+      }\r
+    }\r
+\r
+    // ----- Return\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclZipUtilOptionText()\r
+  // Description :\r
+  //   Translate option value in text. Mainly for debug purpose.\r
+  // Parameters :\r
+  //   $p_option : the option value.\r
+  // Return Values :\r
+  //   The option text value.\r
+  // --------------------------------------------------------------------------------\r
+  function PclZipUtilOptionText($p_option)\r
+  {\r
+    //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'");\r
+    \r
+    $v_list = get_defined_constants();\r
+    for (reset($v_list); $v_key = key($v_list); next($v_list)) {\r
+         $v_prefix = substr($v_key, 0, 10);\r
+         if ((   ($v_prefix == 'PCLZIP_OPT')\r
+         || ($v_prefix == 'PCLZIP_CB_')\r
+         || ($v_prefix == 'PCLZIP_ATT'))\r
+             && ($v_list[$v_key] == $p_option)) {\r
+          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key);\r
+          return $v_key;\r
+           }\r
+    }\r
+    \r
+    $v_result = 'Unknown';\r
+\r
+    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclZipUtilTranslateWinPath()\r
+  // Description :\r
+  //   Translate windows path by replacing '\' by '/' and optionally removing\r
+  //   drive letter.\r
+  // Parameters :\r
+  //   $p_path : path to translate.\r
+  //   $p_remove_disk_letter : true | false\r
+  // Return Values :\r
+  //   The path translated.\r
+  // --------------------------------------------------------------------------------\r
+  function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)\r
+  {\r
+    if (stristr(php_uname(), 'windows')) {\r
+      // ----- Look for potential disk letter\r
+      if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {\r
+          $p_path = substr($p_path, $v_position+1);\r
+      }\r
+      // ----- Change potential windows directory separator\r
+      if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {\r
+          $p_path = strtr($p_path, '\\', '/');\r
+      }\r
+    }\r
+    return $p_path;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+\r
+?>\r