--- /dev/null
+<?php\r
+// --------------------------------------------------------------------------------\r
+// PhpConcept Library - Zip Module 1.3\r
+// --------------------------------------------------------------------------------\r
+// License GNU/LGPL - Vincent Blavet - January 2003\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$\r
+// --------------------------------------------------------------------------------\r
+\r
+ // ----- Constants\r
+ define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );\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 = "1.3";\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_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
+\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
+\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
+ // --------------------------------------------------------------------------------\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
+\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_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, $p_add_dir="", $p_remove_dir="")\r
+ function create($p_filelist /*, options */)\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_add_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
+ // ----- 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
+ 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_ADD_PATH])) {\r
+ $v_add_path = $v_options[PCLZIP_OPT_ADD_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
+ }\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_add_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, "add_path='$v_add_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_all_path?'true':'false')."'");\r
+\r
+ // ----- Look if the $p_filelist is really an array\r
+ $p_result_list = array();\r
+ if (is_array($p_filelist))\r
+ {\r
+ // ----- Call the create fct\r
+ $v_result = $this->privCreate($p_filelist, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);\r
+ }\r
+\r
+ // ----- Look if the $p_filelist is a string\r
+ else if (is_string($p_filelist))\r
+ {\r
+ // ----- Create a list with the elements from the string\r
+ $v_list = explode(" ", $p_filelist);\r
+\r
+ // ----- Call the create fct\r
+ $v_result = $this->privCreate($v_list, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);\r
+ }\r
+\r
+ // ----- Invalid variable\r
+ else\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");\r
+ $v_result = PCLZIP_ERR_INVALID_PARAMETER;\r
+ }\r
+\r
+ if ($v_result != 1)\r
+ {\r
+ // ----- Return\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_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, $p_add_dir="", $p_remove_dir="")\r
+ function add($p_filelist /* options */)\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_add_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
+ // ----- 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
+ 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_ADD_PATH])) {\r
+ $v_add_path = $v_options[PCLZIP_OPT_ADD_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
+ }\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_add_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, "add_path='$v_add_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_all_path?'true':'false')."'");\r
+\r
+ // ----- Look if the $p_filelist is really an array\r
+ $p_result_list = array();\r
+ if (is_array($p_filelist))\r
+ {\r
+ // ----- Call the create fct\r
+ $v_result = $this->privAdd($p_filelist, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);\r
+ }\r
+\r
+ // ----- Look if the $p_filelist is a string\r
+ else if (is_string($p_filelist))\r
+ {\r
+ // ----- Create a list with the elements from the string\r
+ $v_list = explode(" ", $p_filelist);\r
+\r
+ // ----- Call the create fct\r
+ $v_result = $this->privAdd($v_list, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);\r
+ }\r
+\r
+ // ----- Invalid variable\r
+ else\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");\r
+ $v_result = PCLZIP_ERR_INVALID_PARAMETER;\r
+ }\r
+\r
+ if ($v_result != 1)\r
+ {\r
+ // ----- Return\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($p_path="./", $p_remove_path="")\r
+ function extract(/* options */)\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_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
+ // ----- 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
+ 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
+ if (($v_result = $this->privExtract($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) != 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
+ // 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_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, $p_path="./", $p_remove_path="")\r
+ function extractByIndex($p_index /* $options */)\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_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
+ // ----- 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_ADD_PATH => 'optional',\r
+ PCLZIP_CB_PRE_EXTRACT => 'optional',\r
+ PCLZIP_CB_POST_EXTRACT => 'optional',\r
+ PCLZIP_OPT_SET_CHMOD => 'optional' ));\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__, 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
+ // ----- Look if the $p_index is really an integer\r
+ if (is_integer($p_index))\r
+ {\r
+ // ----- Call the extracting fct\r
+ if (($v_result = $this->privExtractByIndex($p_list, "$p_index", $v_path, $v_remove_path, $v_remove_all_path, $v_options)) != 1)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+ return(0);\r
+ }\r
+ }\r
+\r
+ // ----- Look if the index is a string\r
+ else if (is_string($p_index))\r
+ {\r
+ // ----- Call the extracting fct\r
+ if (($v_result = $this->privExtractByIndex($p_list, $p_index, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) != 1)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+ return(0);\r
+ }\r
+ }\r
+\r
+ // ----- Invalid variable\r
+ else\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type $p_index");\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 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 : deleteByIndex()\r
+ // Description :\r
+ // This method delete somes files or folder entries from the zip archive.\r
+ // The entries (files or folders) are identified by their index in the\r
+ // archive (0-n).\r
+ // Note that if the index identify a folder entry, only the folder entry\r
+ // is deleted, and not all the files included in the folder.\r
+ // Parameters :\r
+ // $p_index : A single index (integer) or a string of indexes of files to\r
+ // delete. 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
+ // 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 deleteByIndex($p_index)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "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
+ // ----- Look if the $p_index is really an integer\r
+ if (is_integer($p_index))\r
+ {\r
+ // ----- Call the delete fct\r
+ if (($v_result = $this->privDeleteByIndex("$p_index", $p_list)) != 1)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+ return(0);\r
+ }\r
+ }\r
+\r
+ // ----- Look if the index is a string\r
+ else if (is_string($p_index))\r
+ {\r
+ // ----- Call the delete fct\r
+ if (($v_result = $this->privDeleteByIndex($p_index, $p_list)) != 1)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());\r
+ return(0);\r
+ }\r
+ }\r
+\r
+ // ----- Invalid variable\r
+ else\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type $p_index");\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 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 : 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
+ // ----- Check archive\r
+ if (!$this->privCheckFormat()) {\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
+ // ----- 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
+ //--(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
+ // ----- 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
+\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 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)\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 requested\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]] = strtr($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 no value\r
+ case PCLZIP_OPT_REMOVE_ALL_PATH :\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, "Unknown optional parameter '".$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
+ 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
+ // ----- 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_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list, result_list, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\r
+ $v_result=1;\r
+ $v_list_detail = array();\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_list, $p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options);\r
+\r
+ // ----- Close\r
+ $this->privCloseFd();\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_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list, result_list, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\r
+ $v_result=1;\r
+ $v_list_detail = array();\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, create it.");\r
+\r
+ // ----- Do a create\r
+ $v_result = $this->privCreate($p_list, $p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options);\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 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
+\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_list, $v_header_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options)) != 1)\r
+ {\r
+ fclose($v_zip_temp_fd);\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
+ // ----- 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
+\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
+\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
+\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
+ // ----- 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
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\r
+ $v_result=1;\r
+\r
+ // ----- Add the files\r
+ $v_header_list = array();\r
+ if (($v_result = $this->privAddFileList($p_list, $v_header_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $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
+\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
+ // $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\r
+ // run the lib 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 privAddFileList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "list, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\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<count($p_list)) && ($v_result==1); $j++)\r
+ {\r
+ // ----- Recuperate the filename\r
+ $p_filename = $p_list[$j];\r
+\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file [$p_filename]");\r
+\r
+ // ----- Skip empty file names\r
+ if ($p_filename == "")\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");\r
+ continue;\r
+ }\r
+\r
+ // ----- Check the filename\r
+ if (!file_exists($p_filename))\r
+ {\r
+ // ----- Error log\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '$p_filename' does not exists");\r
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '$p_filename' does not exists");\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+ return PclZip::errorCode();\r
+ }\r
+\r
+ /* This test is done later\r
+ // ----- Check the path length\r
+ if (strlen($p_filename) > 0xFF)\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(-5, "File name is too long (max. 255) : '$p_filename'");\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+ return PclZip::errorCode();\r
+ }\r
+ */\r
+\r
+ // ----- Look if it is a file or a dir with no all pathnre move\r
+ if ((is_file($p_filename)) || ((is_dir($p_filename)) && !$p_remove_all_dir)) {\r
+ // ----- Add the file\r
+ if (($v_result = $this->privAddFile($p_filename, $v_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options)) != 1)\r
+ {\r
+ // ----- Return status\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
+ // ----- Look for directory\r
+ if (is_dir($p_filename))\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "$p_filename is a directory");\r
+\r
+ // ----- Look for path\r
+ if ($p_filename != ".")\r
+ $v_path = $p_filename."/";\r
+ else\r
+ $v_path = "";\r
+\r
+ // ----- Read the directory for files and sub-directories\r
+ $p_hdir = opendir($p_filename);\r
+ $p_hitem = readdir($p_hdir); // '.' directory\r
+ $p_hitem = readdir($p_hdir); // '..' directory\r
+ while ($p_hitem = readdir($p_hdir))\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for $p_hitem in the directory");\r
+\r
+ // ----- Look for a file\r
+ if (is_file($v_path.$p_hitem))\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Add the file '".$v_path.$p_hitem."'");\r
+\r
+ // ----- Add the file\r
+ if (($v_result = $this->privAddFile($v_path.$p_hitem, $v_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options)) != 1)\r
+ {\r
+ // ----- Return status\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
+ // ----- Recursive call to privAddFileList()\r
+ else\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Add the directory '".$v_path.$p_hitem."'");\r
+\r
+ // ----- Need an array as parameter\r
+ $p_temp_list[0] = $v_path.$p_hitem;\r
+ $v_result = $this->privAddFileList($p_temp_list, $p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options);\r
+\r
+ // ----- Update the number of elements of the list\r
+ $v_nb = sizeof($p_result_list);\r
+ }\r
+ }\r
+\r
+ // ----- Free memory for the recursive loop\r
+ unset($p_temp_list);\r
+ unset($p_hdir);\r
+ unset($p_hitem);\r
+ }\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_filename, &$p_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='$p_filename', add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\r
+ $v_result=1;\r
+\r
+ if ($p_filename == "")\r
+ {\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
+ // ----- Calculate the stored filename\r
+ $v_stored_filename = $p_filename;\r
+\r
+ // ----- Look for all path to remove\r
+ if ($p_remove_all_dir) {\r
+ $v_stored_filename = basename($p_filename);\r
+ }\r
+ // ----- Look for partial path remove\r
+ else if ($p_remove_dir != "")\r
+ {\r
+ if (substr($p_remove_dir, -1) != '/')\r
+ $p_remove_dir .= "/";\r
+\r
+ if ((substr($p_filename, 0, 2) == "./") || (substr($p_remove_dir, 0, 2) == "./"))\r
+ {\r
+ if ((substr($p_filename, 0, 2) == "./") && (substr($p_remove_dir, 0, 2) != "./"))\r
+ $p_remove_dir = "./".$p_remove_dir;\r
+ if ((substr($p_filename, 0, 2) != "./") && (substr($p_remove_dir, 0, 2) == "./"))\r
+ $p_remove_dir = substr($p_remove_dir, 2);\r
+ }\r
+\r
+ if (substr($p_filename, 0, strlen($p_remove_dir)) == $p_remove_dir)\r
+ {\r
+ $v_stored_filename = substr($p_filename, strlen($p_remove_dir));\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Remove path '$p_remove_dir' in file '$p_filename' = '$v_stored_filename'");\r
+ }\r
+ }\r
+ // ----- Look for path to add\r
+ if ($p_add_dir != "")\r
+ {\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
+ // ----- Filename (reduce the path of stored name)\r
+ $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);\r
+\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Filename (reduced) '$v_stored_filename', strlen ".strlen($v_stored_filename));\r
+\r
+ /* filename length moved after call-back in release 1.3\r
+ // ----- Check the path length\r
+ if (strlen($v_stored_filename) > 0xFF)\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(-5, "Stored file name is too long (max. 255) : '$v_stored_filename'");\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+ return PclZip::errorCode();\r
+ }\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['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
+ // ----- 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
+ // ----- Open the source file\r
+ if (($v_file = @fopen($p_filename, "rb")) == 0)\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+ return PclZip::errorCode();\r
+ }\r
+\r
+ // ----- Creates a compressed temporary file\r
+ if (($v_file_compressed = @gzopen($p_filename.'.gz', "wb")) == 0)\r
+ {\r
+ // ----- Close the file\r
+ fclose($v_file);\r
+\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Unable to open file '$p_filename.gz' in gz binary write mode");\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+ return PclZip::errorCode();\r
+ }\r
+\r
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks\r
+ $v_size = filesize($p_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__, 2, "Read $v_read_size bytes");\r
+ $v_buffer = fread($v_file, $v_read_size);\r
+ $v_binary_data = pack('a'.$v_read_size, $v_buffer);\r
+ @gzputs($v_file_compressed, $v_binary_data, $v_read_size);\r
+ $v_size -= $v_read_size;\r
+ }\r
+\r
+ // ----- Close the file\r
+ @fclose($v_file);\r
+ @gzclose($v_file_compressed);\r
+\r
+ // ----- Check the minimum file size\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "gzip file size ".filesize($p_filename.'.gz'));\r
+ if (filesize($p_filename.'.gz') < 18)\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Invalid file "'.$p_filename.'.gz'.'" size (less than header size)');\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+ return PclZip::errorCode();\r
+ }\r
+\r
+ // ----- Extract the compressed attributes\r
+ if (($v_file_compressed = @fopen($p_filename.'.gz', "rb")) == 0)\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename.gz' in gz 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 gzip file header\r
+ $v_binary_data = @fread($v_file_compressed, 10);\r
+ $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);\r
+\r
+ // ----- Check some parameters\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[id1]='.bin2hex($v_data_header['id1']));\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[id2]='.bin2hex($v_data_header['id2']));\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[cm]='.bin2hex($v_data_header['cm']));\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[flag]='.bin2hex($v_data_header['flag']));\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[mtime]='.$v_data_header['mtime']);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[xfl]='.bin2hex($v_data_header['xfl']));\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[os]='.bin2hex($v_data_header['os']));\r
+ $v_data_header['os'] = bin2hex($v_data_header['os']);\r
+\r
+ // ----- Read the gzip file footer\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position after header ".ftell($v_file_compressed));\r
+ @fseek($v_file_compressed, filesize($p_filename.'.gz')-8);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position at beginning of footer ".ftell($v_file_compressed));\r
+ $v_binary_data = @fread($v_file_compressed, 8);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position after footer ".ftell($v_file_compressed));\r
+ $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);\r
+\r
+ // ----- Set the attributes\r
+ $p_header['compression'] = ord($v_data_header['cm']);\r
+ //$p_header['mtime'] = $v_data_header['mtime'];\r
+ $p_header['crc'] = $v_data_footer['crc'];\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Compressed size ".(filesize($p_filename.'.gz')-18));\r
+ $p_header['compressed_size'] = filesize($p_filename.'.gz')-18;\r
+\r
+ // ----- Close the file\r
+ @fclose($v_file_compressed);\r
+\r
+ // ----- Call the header generation\r
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1)\r
+ {\r
+ // ----- Return status\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\r
+\r
+ // ----- Add the compressed data\r
+ if (($v_file_compressed = @fopen($p_filename.'.gz', "rb")) == 0)\r
+ {\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename.gz' in gz 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 file by PCLZIP_READ_BLOCK_SIZE octets blocks\r
+ fseek($v_file_compressed, 10);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position before reading compressed data ".ftell($v_file_compressed));\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, ' '.$p_header['compressed_size'].' bytes to read');\r
+ $v_size = $p_header['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($v_file_compressed, $v_read_size);\r
+ $v_binary_data = pack('a'.$v_read_size, $v_buffer);\r
+ @fwrite($this->zip_fd, $v_binary_data, $v_read_size);\r
+ $v_size -= $v_read_size;\r
+ }\r
+\r
+ // ----- Close the file\r
+ @fclose($v_file_compressed);\r
+\r
+ // ----- Unlink the temporary file\r
+ @unlink($p_filename.'.gz');\r
+ }\r
+\r
+ // ----- Look for a directory\r
+ else\r
+ {\r
+ // ----- Set the file properties\r
+ $p_header['filename'] .= '/';\r
+ $p_header['filename_len']++;\r
+ $p_header['size'] = 0;\r
+ $p_header['external'] = 0x41FF0010; // Value for a folder : to be checked\r
+\r
+ // ----- Call the header generation\r
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1)\r
+ {\r
+ // ----- Return status\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\r
+ }\r
+ }\r
+\r
+ // ----- Look for pre-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 : 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
+ // 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
+ // ----- 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, $p_header['version'], $p_header['flag'],\r
+ $p_header['compression'], $v_mtime, $v_mdate,\r
+ $p_header['crc'], $p_header['compressed_size'], $p_header['size'],\r
+ strlen($p_header['stored_filename']), $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, $p_header['version'], $p_header['version_extracted'],\r
+ $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'],\r
+ $p_header['compressed_size'], $p_header['size'],\r
+ strlen($p_header['stored_filename']), $p_header['extra_len'], $p_header['comment_len'],\r
+ $p_header['disk'], $p_header['internal'], $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, $p_nb_entries, $p_size, $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
+ // ----- 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
+ // ----- 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
+ //--(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
+ // ----- 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
+ //--(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
+ // ----- 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']==0x41FF0010);\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 : privExtract()\r
+ // Description :\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 privExtract(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtract", "list, path=$p_path, remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");\r
+ $v_result=1;\r
+\r
+ // ----- Check the path\r
+ if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../")))\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
+ //--(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
+\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
+ for ($i=0; $i<$v_central_dir['entries']; $i++)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file entry : $i'");\r
+\r
+ // ----- Read next Central dir entry\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+ @rewind($this->zip_fd);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "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__, 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
+\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
+ // ----- Go to the file position\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+ @rewind($this->zip_fd);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "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
+ // ----- 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
+ // ----- Extracting the file\r
+ if (($v_result = $this->privExtractFile($v_header, $p_path, $p_remove_path, $p_remove_all_path, $p_options)) != 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
+ // ----- Get the only interesting attributes\r
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$i])) != 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
+\r
+ // ----- Close the zip file\r
+ $this->privCloseFd();\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\r
+ // --------------------------------------------------------------------------------\r
+\r
+ // --------------------------------------------------------------------------------\r
+ // Function : privExtractByIndex()\r
+ // Description :\r
+ // Parameters :\r
+ // $p_file_list : An array where will be placed the properties of each\r
+ // extracted file\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 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 privExtractByIndex(&$p_file_list, $p_index, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByIndex", "list, index='$p_index', path=$p_path, remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");\r
+ $v_result=1;\r
+\r
+ // ----- Check the path\r
+ if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../")))\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
+ //--(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
+\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\r
+\r
+ // ----- Manipulate the index list\r
+ $p_index = strtr($p_index, ' ', '');\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Reduced index : '$p_index'");\r
+ $v_index_list = explode(",", $p_index);\r
+ // TBC : Here I should sort the index. However a simple sort is not enought.\r
+ // look for the use of usort()\r
+ //sort($v_index_list);\r
+\r
+ // ----- Start at beginning of Central Dir\r
+ $v_pos_entry = $v_central_dir['offset'];\r
+\r
+ // ----- Read each entry\r
+ for ($i=0, $j_start=0, $v_nb_extracted=0; ($i<$v_central_dir['entries']) && ($j_start<sizeof($v_index_list)); $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__, 3, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+ @rewind($this->zip_fd);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "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__, 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
+\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 if the index is in the list\r
+ $v_extract = false;\r
+ for ($j=$j_start; ($j<sizeof($v_index_list)) && (!$v_extract); $j++)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in '".$v_index_list[$j]."'");\r
+\r
+ // ----- Extract range\r
+ $v_item_list = explode("-", $v_index_list[$j]);\r
+ $v_size_item_list = sizeof($v_item_list);\r
+ if ($v_size_item_list == 1)\r
+ {\r
+ if ($i==$v_item_list[0])\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as a single index");\r
+ $v_extract = true;\r
+ }\r
+ if ($i>=$v_item_list[0])\r
+ {\r
+ $j_start = $j+1;\r
+ }\r
+ }\r
+ else if ($v_size_item_list == 2)\r
+ {\r
+ if (($i>=$v_item_list[0]) && ($i<=$v_item_list[1]))\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");\r
+ $v_extract = true;\r
+ }\r
+ if ($i>=$v_item_list[1])\r
+ {\r
+ $j_start = $j+1;\r
+ }\r
+ }\r
+ if ($v_item_list[0]>$i)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Range is greater than index, stop loop");\r
+ break;\r
+ }\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__, 3, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+ @rewind($this->zip_fd);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "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
+ // ----- 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
+ // ----- Extracting the file\r
+ if (($v_result = $this->privExtractFile($v_header, $p_path, $p_remove_path, $p_remove_all_path, $p_options)) != 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
+ // ----- 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
+\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\r
+ }\r
+ }\r
+\r
+ // ----- Close the zip file\r
+ $this->privCloseFd();\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
+ 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
+ // TBC\r
+\r
+ // ----- Look for all path to remove\r
+ if ($p_remove_all_path == true) {\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
+ //if (strcmp($p_remove_path, $p_entry['filename'])==0)\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
+ {\r
+ $p_entry['filename'] = $p_path."/".$p_entry['filename'];\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
+ }\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
+ // ----- 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
+ // ----- Return\r
+ ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ //return $v_result;\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
+ // ----- Return\r
+ ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ //return $v_result;\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
+\r
+ // ----- Change the file status\r
+ $p_entry['status'] = "newer_exist";\r
+\r
+ // ----- Return\r
+ ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ //return $v_result;\r
+ }\r
+ }\r
+\r
+ // ----- Check the directory availability and create it if necessary\r
+ else {\r
+ if (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']==0x41FF0010))) != 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']==0x41FF0010))\r
+ {\r
+\r
+ // ----- Look for not compressed file\r
+ if ($p_entry['compressed_size'] == $p_entry['size'])\r
+ {\r
+ // ----- Trace\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, "Reading '".$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
+ $v_binary_data = pack('a'.$v_read_size, $v_buffer);\r
+ @fwrite($v_dest_file, $v_binary_data, $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
+ else\r
+ {\r
+ // ----- Trace\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file");\r
+\r
+ // ----- Open the destination file in write mode\r
+ if (($v_dest_file = @fopen($p_entry['filename'].'.gz', '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, "Start extraction of '".$p_entry['filename']."'");\r
+\r
+ // ----- Write gz file format header\r
+ $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));\r
+ fwrite($v_dest_file, $v_binary_data, 10);\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
+ $v_binary_data = pack('a'.$v_read_size, $v_buffer);\r
+ @fwrite($v_dest_file, $v_binary_data, $v_read_size);\r
+ $v_size -= $v_read_size;\r
+ }\r
+\r
+ // ----- Write gz file format footer\r
+ $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);\r
+ fwrite($v_dest_file, $v_binary_data, 8);\r
+\r
+ // ----- Close the temporary file\r
+ fclose($v_dest_file);\r
+\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after extract [".ftell($this->zip_fd)."]");\r
+\r
+ // ----- Uncompress\r
+ if (($v_src_file = gzopen($p_entry['filename'].'.gz', 'rb')) == 0)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in read binary mode");\r
+\r
+ // ----- Change the file status\r
+ $p_entry['status'] = "read_error";\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\r
+\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
+ gzclose($v_src_file);\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\r
+\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File size is '.filesize($p_entry['filename'].'.gz'));\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '$p_entry[size]' bytes");\r
+\r
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks\r
+ $v_size = $p_entry['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 = gzread($v_src_file, $v_read_size);\r
+ $v_binary_data = pack('a'.$v_read_size, $v_buffer);\r
+ @fwrite($v_dest_file, $v_binary_data, $v_read_size);\r
+ $v_size -= $v_read_size;\r
+ }\r
+ fclose($v_dest_file);\r
+ gzclose($v_src_file);\r
+\r
+ // ----- Change the file mtime\r
+ touch($p_entry['filename'], $p_entry['mtime']);\r
+\r
+ // ----- Delete the temporary file\r
+ @unlink($p_entry['filename'].'.gz');\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
+ // ----- Trace\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");\r
+ }\r
+ }\r
+\r
+ // ----- Look for post-extract callback\r
+ if (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
+\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['compression'] = $v_data['compression'];\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.bin2hex($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 : \''.$p_header['crc'].'\'');\r
+ $p_header['flag'] = $v_data['flag'];\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\'');\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
+ // ----- Other informations\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compression type : ".$v_data['compression']);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Version : ".$v_data['version']);\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__, 2, "Header : '".$v_binary_data."'");\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "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__, 3, "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__, 3, 'Filename : \''.$p_header['filename'].'\'');\r
+\r
+ // ----- Get extra\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "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__, 3, 'Extra : \''.$p_header['extra'].'\'');\r
+\r
+ // ----- Get comment\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "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__, 3, 'Comment : \''.$p_header['comment'].'\'');\r
+\r
+ // ----- Extract properties\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 : \''.$p_header['crc'].'\'');\r
+ //$p_header['flag'] = $v_data['flag'];\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\'');\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, '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__, 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
+ // ----- 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__, 2, "external (Hex) : '".sprintf("Ox%04X", $p_header['external'])."' (".($p_header['external']==0x41FF0010?'is a folder':'is a file').')');\r
+ if (substr($p_header['filename'], -1) == '/')\r
+ {\r
+ $p_header['external'] = 0x41FF0010;\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Force folder external : \''.$p_header['external'].'\'');\r
+ }\r
+\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
+ // ----- 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 max 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
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\'');\r
+\r
+ // ----- Read for bytes\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'] == 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
+ $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 : \''.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
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Fail to find the right siganture");\r
+\r
+ // ----- Error log\r
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Fail to find the right signature");\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());\r
+ return PclZip::errorCode();\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 : privDeleteByIndex()\r
+ // Description :\r
+ // Parameters :\r
+ // Return Values :\r
+ // --------------------------------------------------------------------------------\r
+ function privDeleteByIndex($p_index, &$p_result_list)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByIndex", "index='$p_index'");\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
+ // ----- Manipulate the index list\r
+ $p_index = strtr($p_index, ' ', '');\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Reduced index : '$p_index'");\r
+ $v_index_list = explode(",", $p_index);\r
+ // TBC : Here I should sort the index. However a simple sort is not enought.\r
+ // look for the use of usort()\r
+ //sort($v_index_list);\r
+\r
+ // ----- Start at beginning of Central Dir\r
+ $v_pos_entry = $v_central_dir['offset'];\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position before rewind : ".ftell($this->zip_fd)."'");\r
+ @rewind($this->zip_fd);\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "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__, 3, "Position after fseek : ".ftell($this->zip_fd)."'");\r
+\r
+ // ----- Read each entry\r
+ $v_header_list = array();\r
+ for ($i=0, $j_start=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 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
+ // ----- Store the index\r
+ $v_header_list[$v_nb_extracted]['index'] = $i;\r
+\r
+ // ----- Look if the index is in the list\r
+ for ($j=$j_start, $v_found = false; ($j<sizeof($v_index_list)) && (!$v_found); $j++)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in '".$v_index_list[$j]."'");\r
+\r
+ // ----- Extract range\r
+ $v_item_list = explode("-", $v_index_list[$j]);\r
+ $v_size_item_list = sizeof($v_item_list);\r
+ if ($v_size_item_list == 1)\r
+ {\r
+ if ($i==$v_item_list[0])\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as a single index");\r
+ $v_found = true;\r
+ }\r
+ if ($i>=$v_item_list[0])\r
+ {\r
+ $j_start = $j+1;\r
+ }\r
+ }\r
+ else if ($v_size_item_list == 2)\r
+ {\r
+ if (($i>=$v_item_list[0]) && ($i<=$v_item_list[1]))\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");\r
+ $v_found = true;\r
+ }\r
+ if ($i>=$v_item_list[1])\r
+ {\r
+ $j_start = $j+1;\r
+ }\r
+ }\r
+ if ($v_item_list[0]>$i)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Range is greater than index, stop loop");\r
+ break;\r
+ }\r
+ }\r
+\r
+ // ----- Look for deletion\r
+ if ($v_found)\r
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header['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['filename']."', index '$i' will not be deleted");\r
+ $v_nb_extracted++;\r
+ }\r
+ }\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
+ {\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
+ {\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry : $i'");\r
+\r
+ // ----- Calculate the position of the header\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "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
+ {\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
+ if (($v_result = $this->privReadFileHeader($v_header_list[$i])) != 1)\r
+ {\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
+ // ----- Write the file header\r
+ if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1)\r
+ {\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__, 3, "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
+ {\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__, 4, "New offset of central dir : $v_offset");\r
+\r
+ // ----- Re-Create the Central Dir files header\r
+ for ($i=0; $i<sizeof($v_header_list); $i++)\r
+ {\r
+ // ----- Create the file header\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Offset of file : ".$v_header_list[$i]['offset']);\r
+ if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1)\r
+ {\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
+ // ----- Zip file comment\r
+ $v_comment = '';\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
+ {\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
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\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
+ // ----- Zip file comment\r
+ // TBC : I should merge the two comments\r
+ $v_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 = 1;\r
+ $this->error_string = '';\r
+ }\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
+ {\r
+ // ----- Explode path by directory names\r
+ $v_list = explode("/", $p_dir);\r
+\r
+ // ----- Study directories from last to first\r
+ for ($i=sizeof($v_list)-1; $i>=0; $i--)\r
+ {\r
+ // ----- Look for current path\r
+ if ($v_list[$i] == ".")\r
+ {\r
+ // ----- Ignore this directory\r
+ // Should be the first $i=0, but no check is done\r
+ }\r
+ else if ($v_list[$i] == "..")\r
+ {\r
+ // ----- Ignore it and ignore the $i-1\r
+ $i--;\r
+ }\r
+ else if (($v_list[$i] == "") && ($i!=(sizeof($v_list)-1)) && ($i!=0))\r
+ {\r
+ // ----- Ignore only the double '//' in path,\r
+ // but not the first and last '/'\r
+ }\r
+ else\r
+ {\r
+ $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");\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
+ // ----- 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 (($v_list_path[$j] == '') && ($j < $v_list_path_size)) $j++;\r
+ while (($v_list_dir[$i] == '') && ($i < $v_list_dir_size)) $i++;\r
+ //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Looking on dir($i)='".$v_list_dir[$i]."' and path($j)='".$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
+ switch ($p_option) {\r
+ case PCLZIP_OPT_PATH :\r
+ $v_result = 'PCLZIP_OPT_PATH';\r
+ break;\r
+ case PCLZIP_OPT_ADD_PATH :\r
+ $v_result = 'PCLZIP_OPT_ADD_PATH';\r
+ break;\r
+ case PCLZIP_OPT_REMOVE_PATH :\r
+ $v_result = 'PCLZIP_OPT_REMOVE_PATH';\r
+ break;\r
+ case PCLZIP_OPT_REMOVE_ALL_PATH :\r
+ $v_result = 'PCLZIP_OPT_REMOVE_ALL_PATH';\r
+ break;\r
+ case PCLZIP_OPT_SET_CHMOD :\r
+ $v_result = 'PCLZIP_OPT_SET_CHMOD';\r
+ break;\r
+\r
+\r
+ case PCLZIP_CB_PRE_EXTRACT :\r
+ $v_result = 'PCLZIP_CB_PRE_EXTRACT';\r
+ break;\r
+ case PCLZIP_CB_POST_EXTRACT :\r
+ $v_result = 'PCLZIP_CB_POST_EXTRACT';\r
+ break;\r
+ case PCLZIP_CB_PRE_ADD :\r
+ $v_result = 'PCLZIP_CB_PRE_ADD';\r
+ break;\r
+ case PCLZIP_CB_POST_ADD :\r
+ $v_result = 'PCLZIP_CB_POST_ADD';\r
+ break;\r
+\r
+ default :\r
+ $v_result = 'Unknown';\r
+ }\r
+\r
+ // ----- Return\r
+ //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);\r
+ return $v_result;\r
+ }\r
+ // --------------------------------------------------------------------------------\r
+\r
+?>
\ No newline at end of file