-
+ 00F67E82C1C9704C47E73C6EF538B2A3859B0E79A9C39E74B0BFA5FF2E2AA11DB6AC811F8A0702F08ED373846F650ECEC2C2224C72ADA4BD67A7CB6A818CA3DFmp-wp/wp-admin/includes/class-pclzip.php(0 . 0)(1 . 5759)
 24405 <?php
 24406 /**
 24407  * PhpConcept Library - Zip Module 2.5
 24408  *
 24409  * Presentation :
 24410  *   PclZip is a PHP library that manage ZIP archives.
 24411  *   So far tests show that archives generated by PclZip are readable by
 24412  *   WinZip application and other tools.
 24413  *
 24414  * Warning :
 24415  *   This library and the associated files are non commercial, non professional
 24416  *   work.
 24417  *   It should not have unexpected results. However if any damage is caused by
 24418  *   this software the author can not be responsible.
 24419  *   The use of this software is at the risk of the user.
 24420  *
 24421  * @package External
 24422  * @subpackage PclZip
 24423  *
 24424  * @license License GNU/LGPL
 24425  * @copyright March 2006 Vincent Blavet
 24426  * @author Vincent Blavet
 24427  * @link http://www.phpconcept.net
 24428  * @version $Id: pclzip.lib.php,v 1.44 2006/03/08 21:23:59 vblavet Exp $
 24429  */
 24430 
 24431 /**
 24432  * The read block size for reading zip files.
 24433  *
 24434  * @since 2.5
 24435  */
 24436 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
 24437 
 24438 /**
 24439  * File list separator
 24440  *
 24441  * In version 1.x of PclZip, the separator for file list is a space(which is not
 24442  * a very smart choice, specifically for windows paths !). A better separator
 24443  * should be a comma (,). This constant gives you the abilty to change that.
 24444  *
 24445  * However notice that changing this value, may have impact on existing scripts,
 24446  * using space separated filenames. Recommanded values for compatibility with
 24447  * older versions :
 24448  * <code>define( 'PCLZIP_SEPARATOR', ' ' );</code>
 24449  * Recommanded values for smart separation of filenames.
 24450  */
 24451 define( 'PCLZIP_SEPARATOR', ',' );
 24452 
 24453 /**
 24454  * Error configuration
 24455  *
 24456  * 0 : PclZip Class integrated error handling
 24457  * 1 : PclError external library error handling. By enabling this you must
 24458  *     ensure that you have included PclError library.
 24459  * [2,...] : reserved for future use
 24460  */
 24461 define( 'PCLZIP_ERROR_EXTERNAL', 0 );
 24462 
 24463   // ----- Optional static temporary directory
 24464   //       By default temporary files are generated in the script current
 24465   //       path.
 24466   //       If defined :
 24467   //       - MUST BE terminated by a '/'.
 24468   //       - MUST be a valid, already created directory
 24469   //       Samples :
 24470   // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
 24471   // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
 24472   define( 'PCLZIP_TEMPORARY_DIR', '' );
 24473 
 24474 // --------------------------------------------------------------------------------
 24475 // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
 24476 // --------------------------------------------------------------------------------
 24477 
 24478   // ----- Global variables
 24479   $g_pclzip_version = "2.5";
 24480 
 24481   // ----- Error codes
 24482   //   -1 : Unable to open file in binary write mode
 24483   //   -2 : Unable to open file in binary read mode
 24484   //   -3 : Invalid parameters
 24485   //   -4 : File does not exist
 24486   //   -5 : Filename is too long (max. 255)
 24487   //   -6 : Not a valid zip file
 24488   //   -7 : Invalid extracted file size
 24489   //   -8 : Unable to create directory
 24490   //   -9 : Invalid archive extension
 24491   //  -10 : Invalid archive format
 24492   //  -11 : Unable to delete file (unlink)
 24493   //  -12 : Unable to rename file (rename)
 24494   //  -13 : Invalid header checksum
 24495   //  -14 : Invalid archive size
 24496   define( 'PCLZIP_ERR_USER_ABORTED', 2 );
 24497   define( 'PCLZIP_ERR_NO_ERROR', 0 );
 24498   define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
 24499   define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
 24500   define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
 24501   define( 'PCLZIP_ERR_MISSING_FILE', -4 );
 24502   define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
 24503   define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
 24504   define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
 24505   define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
 24506   define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
 24507   define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
 24508   define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
 24509   define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
 24510   define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
 24511   define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
 24512   define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
 24513   define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
 24514   define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
 24515   define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
 24516   define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
 24517   define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
 24518   define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
 24519 
 24520   // ----- Options values
 24521   define( 'PCLZIP_OPT_PATH', 77001 );
 24522   define( 'PCLZIP_OPT_ADD_PATH', 77002 );
 24523   define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
 24524   define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
 24525   define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
 24526   define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
 24527   define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
 24528   define( 'PCLZIP_OPT_BY_NAME', 77008 );
 24529   define( 'PCLZIP_OPT_BY_INDEX', 77009 );
 24530   define( 'PCLZIP_OPT_BY_EREG', 77010 );
 24531   define( 'PCLZIP_OPT_BY_PREG', 77011 );
 24532   define( 'PCLZIP_OPT_COMMENT', 77012 );
 24533   define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
 24534   define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
 24535   define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
 24536   define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
 24537   define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
 24538   // Having big trouble with crypt. Need to multiply 2 long int
 24539   // which is not correctly supported by PHP ...
 24540   //define( 'PCLZIP_OPT_CRYPT', 77018 );
 24541   define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
 24542 
 24543   // ----- File description attributes
 24544   define( 'PCLZIP_ATT_FILE_NAME', 79001 );
 24545   define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
 24546   define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
 24547 
 24548   // ----- Call backs values
 24549   define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
 24550   define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
 24551   define( 'PCLZIP_CB_PRE_ADD', 78003 );
 24552   define( 'PCLZIP_CB_POST_ADD', 78004 );
 24553   /* For future use
 24554   define( 'PCLZIP_CB_PRE_LIST', 78005 );
 24555   define( 'PCLZIP_CB_POST_LIST', 78006 );
 24556   define( 'PCLZIP_CB_PRE_DELETE', 78007 );
 24557   define( 'PCLZIP_CB_POST_DELETE', 78008 );
 24558   */
 24559 
 24560   // --------------------------------------------------------------------------------
 24561   // Class : PclZip
 24562   // Description :
 24563   //   PclZip is the class that represent a Zip archive.
 24564   //   The public methods allow the manipulation of the archive.
 24565   // Attributes :
 24566   //   Attributes must not be accessed directly.
 24567   // Methods :
 24568   //   PclZip() : Object creator
 24569   //   create() : Creates the Zip archive
 24570   //   listContent() : List the content of the Zip archive
 24571   //   extract() : Extract the content of the archive
 24572   //   properties() : List the properties of the archive
 24573   // --------------------------------------------------------------------------------
 24574   class PclZip
 24575   {
 24576     // ----- Filename of the zip file
 24577     var $zipname = '';
 24578 
 24579     // ----- File descriptor of the zip file
 24580     var $zip_fd = 0;
 24581 
 24582     // ----- Internal error handling
 24583     var $error_code = 1;
 24584     var $error_string = '';
 24585 
 24586     // ----- Current status of the magic_quotes_runtime
 24587     // This value store the php configuration for magic_quotes
 24588     // The class can then disable the magic_quotes and reset it after
 24589     var $magic_quotes_status;
 24590 
 24591   // --------------------------------------------------------------------------------
 24592   // Function : PclZip()
 24593   // Description :
 24594   //   Creates a PclZip object and set the name of the associated Zip archive
 24595   //   filename.
 24596   //   Note that no real action is taken, if the archive does not exist it is not
 24597   //   created. Use create() for that.
 24598   // --------------------------------------------------------------------------------
 24599   function PclZip($p_zipname)
 24600   {
 24601     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");
 24602 
 24603     // ----- Tests the zlib
 24604     if (!function_exists('gzopen'))
 24605     {
 24606       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing");
 24607       die('Abort '.basename(__FILE__).' : Missing zlib extensions');
 24608     }
 24609 
 24610     // ----- Set the attributes
 24611     $this->zipname = $p_zipname;
 24612     $this->zip_fd = 0;
 24613     $this->magic_quotes_status = -1;
 24614 
 24615     // ----- Return
 24616     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);
 24617     return;
 24618   }
 24619   // --------------------------------------------------------------------------------
 24620 
 24621   // --------------------------------------------------------------------------------
 24622   // Function :
 24623   //   create($p_filelist, $p_add_dir="", $p_remove_dir="")
 24624   //   create($p_filelist, $p_option, $p_option_value, ...)
 24625   // Description :
 24626   //   This method supports two different synopsis. The first one is historical.
 24627   //   This method creates a Zip Archive. The Zip file is created in the
 24628   //   filesystem. The files and directories indicated in $p_filelist
 24629   //   are added in the archive. See the parameters description for the
 24630   //   supported format of $p_filelist.
 24631   //   When a directory is in the list, the directory and its content is added
 24632   //   in the archive.
 24633   //   In this synopsis, the function takes an optional variable list of
 24634   //   options. See bellow the supported options.
 24635   // Parameters :
 24636   //   $p_filelist : An array containing file or directory names, or
 24637   //                 a string containing one filename or one directory name, or
 24638   //                 a string containing a list of filenames and/or directory
 24639   //                 names separated by spaces.
 24640   //   $p_add_dir : A path to add before the real path of the archived file,
 24641   //                in order to have it memorized in the archive.
 24642   //   $p_remove_dir : A path to remove from the real path of the file to archive,
 24643   //                   in order to have a shorter path memorized in the archive.
 24644   //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
 24645   //                   is removed first, before $p_add_dir is added.
 24646   // Options :
 24647   //   PCLZIP_OPT_ADD_PATH :
 24648   //   PCLZIP_OPT_REMOVE_PATH :
 24649   //   PCLZIP_OPT_REMOVE_ALL_PATH :
 24650   //   PCLZIP_OPT_COMMENT :
 24651   //   PCLZIP_CB_PRE_ADD :
 24652   //   PCLZIP_CB_POST_ADD :
 24653   // Return Values :
 24654   //   0 on failure,
 24655   //   The list of the added files, with a status of the add action.
 24656   //   (see PclZip::listContent() for list entry format)
 24657   // --------------------------------------------------------------------------------
 24658   function create($p_filelist)
 24659   {
 24660     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ...");
 24661     $v_result=1;
 24662 
 24663     // ----- Reset the error handler
 24664     $this->privErrorReset();
 24665 
 24666     // ----- Set default values
 24667     $v_options = array();
 24668     $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
 24669 
 24670     // ----- Look for variable options arguments
 24671     $v_size = func_num_args();
 24672     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
 24673 
 24674     // ----- Look for arguments
 24675     if ($v_size > 1) {
 24676       // ----- Get the arguments
 24677       $v_arg_list = func_get_args();
 24678 
 24679       // ----- Remove from the options list the first argument
 24680       array_shift($v_arg_list);
 24681       $v_size--;
 24682 
 24683       // ----- Look for first arg
 24684       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 24685         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
 24686 
 24687         // ----- Parse the options
 24688         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 24689                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
 24690                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 24691                                                    PCLZIP_OPT_ADD_PATH => 'optional',
 24692                                                    PCLZIP_CB_PRE_ADD => 'optional',
 24693                                                    PCLZIP_CB_POST_ADD => 'optional',
 24694                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
 24695                                                    PCLZIP_OPT_COMMENT => 'optional'
 24696                                                    //, PCLZIP_OPT_CRYPT => 'optional'
 24697                                              ));
 24698         if ($v_result != 1) {
 24699           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24700           return 0;
 24701         }
 24702       }
 24703 
 24704       // ----- Look for 2 args
 24705       // Here we need to support the first historic synopsis of the
 24706       // method.
 24707       else {
 24708         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
 24709 
 24710         // ----- Get the first argument
 24711         $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
 24712 
 24713         // ----- Look for the optional second argument
 24714         if ($v_size == 2) {
 24715           $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
 24716         }
 24717         else if ($v_size > 2) {
 24718           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
 24719 		                       "Invalid number / type of arguments");
 24720           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 24721           return 0;
 24722         }
 24723       }
 24724     }
 24725 
 24726     // ----- Init
 24727     $v_string_list = array();
 24728     $v_att_list = array();
 24729     $v_filedescr_list = array();
 24730     $p_result_list = array();
 24731 
 24732     // ----- Look if the $p_filelist is really an array
 24733     if (is_array($p_filelist)) {
 24734 
 24735       // ----- Look if the first element is also an array
 24736       //       This will mean that this is a file description entry
 24737       if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
 24738         $v_att_list = $p_filelist;
 24739       }
 24740 
 24741       // ----- The list is a list of string names
 24742       else {
 24743         $v_string_list = $p_filelist;
 24744       }
 24745     }
 24746 
 24747     // ----- Look if the $p_filelist is a string
 24748     else if (is_string($p_filelist)) {
 24749       // ----- Create a list from the string
 24750       $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
 24751     }
 24752 
 24753     // ----- Invalid variable type for $p_filelist
 24754     else {
 24755       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
 24756       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24757       return 0;
 24758     }
 24759 
 24760     // ----- Reformat the string list
 24761     if (sizeof($v_string_list) != 0) {
 24762       foreach ($v_string_list as $v_string) {
 24763         if ($v_string != '') {
 24764           $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
 24765         }
 24766         else {
 24767           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename");
 24768         }
 24769       }
 24770     }
 24771 
 24772     // ----- For each file in the list check the attributes
 24773     $v_supported_attributes
 24774     = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
 24775              ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
 24776              ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
 24777 						);
 24778     foreach ($v_att_list as $v_entry) {
 24779       $v_result = $this->privFileDescrParseAtt($v_entry,
 24780                                                $v_filedescr_list[],
 24781                                                $v_options,
 24782                                                $v_supported_attributes);
 24783       if ($v_result != 1) {
 24784         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24785         return 0;
 24786       }
 24787     }
 24788 
 24789     // ----- Expand the filelist (expand directories)
 24790     $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
 24791     if ($v_result != 1) {
 24792       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24793       return 0;
 24794     }
 24795 
 24796     // ----- Call the create fct
 24797     $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
 24798     if ($v_result != 1) {
 24799       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24800       return 0;
 24801     }
 24802 
 24803     // ----- Return
 24804     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
 24805     return $p_result_list;
 24806   }
 24807   // --------------------------------------------------------------------------------
 24808 
 24809   // --------------------------------------------------------------------------------
 24810   // Function :
 24811   //   add($p_filelist, $p_add_dir="", $p_remove_dir="")
 24812   //   add($p_filelist, $p_option, $p_option_value, ...)
 24813   // Description :
 24814   //   This method supports two synopsis. The first one is historical.
 24815   //   This methods add the list of files in an existing archive.
 24816   //   If a file with the same name already exists, it is added at the end of the
 24817   //   archive, the first one is still present.
 24818   //   If the archive does not exist, it is created.
 24819   // Parameters :
 24820   //   $p_filelist : An array containing file or directory names, or
 24821   //                 a string containing one filename or one directory name, or
 24822   //                 a string containing a list of filenames and/or directory
 24823   //                 names separated by spaces.
 24824   //   $p_add_dir : A path to add before the real path of the archived file,
 24825   //                in order to have it memorized in the archive.
 24826   //   $p_remove_dir : A path to remove from the real path of the file to archive,
 24827   //                   in order to have a shorter path memorized in the archive.
 24828   //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
 24829   //                   is removed first, before $p_add_dir is added.
 24830   // Options :
 24831   //   PCLZIP_OPT_ADD_PATH :
 24832   //   PCLZIP_OPT_REMOVE_PATH :
 24833   //   PCLZIP_OPT_REMOVE_ALL_PATH :
 24834   //   PCLZIP_OPT_COMMENT :
 24835   //   PCLZIP_OPT_ADD_COMMENT :
 24836   //   PCLZIP_OPT_PREPEND_COMMENT :
 24837   //   PCLZIP_CB_PRE_ADD :
 24838   //   PCLZIP_CB_POST_ADD :
 24839   // Return Values :
 24840   //   0 on failure,
 24841   //   The list of the added files, with a status of the add action.
 24842   //   (see PclZip::listContent() for list entry format)
 24843   // --------------------------------------------------------------------------------
 24844   function add($p_filelist)
 24845   {
 24846     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ...");
 24847     $v_result=1;
 24848 
 24849     // ----- Reset the error handler
 24850     $this->privErrorReset();
 24851 
 24852     // ----- Set default values
 24853     $v_options = array();
 24854     $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
 24855 
 24856     // ----- Look for variable options arguments
 24857     $v_size = func_num_args();
 24858     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
 24859 
 24860     // ----- Look for arguments
 24861     if ($v_size > 1) {
 24862       // ----- Get the arguments
 24863       $v_arg_list = func_get_args();
 24864 
 24865       // ----- Remove form the options list the first argument
 24866       array_shift($v_arg_list);
 24867       $v_size--;
 24868 
 24869       // ----- Look for first arg
 24870       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 24871         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
 24872 
 24873         // ----- Parse the options
 24874         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 24875                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
 24876                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 24877                                                    PCLZIP_OPT_ADD_PATH => 'optional',
 24878                                                    PCLZIP_CB_PRE_ADD => 'optional',
 24879                                                    PCLZIP_CB_POST_ADD => 'optional',
 24880                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
 24881                                                    PCLZIP_OPT_COMMENT => 'optional',
 24882                                                    PCLZIP_OPT_ADD_COMMENT => 'optional',
 24883                                                    PCLZIP_OPT_PREPEND_COMMENT => 'optional'
 24884                                                    //, PCLZIP_OPT_CRYPT => 'optional'
 24885 												   ));
 24886         if ($v_result != 1) {
 24887           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24888           return 0;
 24889         }
 24890       }
 24891 
 24892       // ----- Look for 2 args
 24893       // Here we need to support the first historic synopsis of the
 24894       // method.
 24895       else {
 24896         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
 24897 
 24898         // ----- Get the first argument
 24899         $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
 24900 
 24901         // ----- Look for the optional second argument
 24902         if ($v_size == 2) {
 24903           $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
 24904         }
 24905         else if ($v_size > 2) {
 24906           // ----- Error log
 24907           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 24908 
 24909           // ----- Return
 24910           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 24911           return 0;
 24912         }
 24913       }
 24914     }
 24915 
 24916     // ----- Init
 24917     $v_string_list = array();
 24918     $v_att_list = array();
 24919     $v_filedescr_list = array();
 24920     $p_result_list = array();
 24921 
 24922     // ----- Look if the $p_filelist is really an array
 24923     if (is_array($p_filelist)) {
 24924 
 24925       // ----- Look if the first element is also an array
 24926       //       This will mean that this is a file description entry
 24927       if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
 24928         $v_att_list = $p_filelist;
 24929       }
 24930 
 24931       // ----- The list is a list of string names
 24932       else {
 24933         $v_string_list = $p_filelist;
 24934       }
 24935     }
 24936 
 24937     // ----- Look if the $p_filelist is a string
 24938     else if (is_string($p_filelist)) {
 24939       // ----- Create a list from the string
 24940       $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
 24941     }
 24942 
 24943     // ----- Invalid variable type for $p_filelist
 24944     else {
 24945       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
 24946       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24947       return 0;
 24948     }
 24949 
 24950     // ----- Reformat the string list
 24951     if (sizeof($v_string_list) != 0) {
 24952       foreach ($v_string_list as $v_string) {
 24953         $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
 24954       }
 24955     }
 24956 
 24957     // ----- For each file in the list check the attributes
 24958     $v_supported_attributes
 24959     = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
 24960              ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
 24961              ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
 24962 						);
 24963     foreach ($v_att_list as $v_entry) {
 24964       $v_result = $this->privFileDescrParseAtt($v_entry,
 24965                                                $v_filedescr_list[],
 24966                                                $v_options,
 24967                                                $v_supported_attributes);
 24968       if ($v_result != 1) {
 24969         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24970         return 0;
 24971       }
 24972     }
 24973 
 24974     // ----- Expand the filelist (expand directories)
 24975     $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
 24976     if ($v_result != 1) {
 24977       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24978       return 0;
 24979     }
 24980 
 24981     // ----- Call the create fct
 24982     $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
 24983     if ($v_result != 1) {
 24984       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 24985       return 0;
 24986     }
 24987 
 24988     // ----- Return
 24989     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
 24990     return $p_result_list;
 24991   }
 24992   // --------------------------------------------------------------------------------
 24993 
 24994   // --------------------------------------------------------------------------------
 24995   // Function : listContent()
 24996   // Description :
 24997   //   This public method, gives the list of the files and directories, with their
 24998   //   properties.
 24999   //   The properties of each entries in the list are (used also in other functions) :
 25000   //     filename : Name of the file. For a create or add action it is the filename
 25001   //                given by the user. For an extract function it is the filename
 25002   //                of the extracted file.
 25003   //     stored_filename : Name of the file / directory stored in the archive.
 25004   //     size : Size of the stored file.
 25005   //     compressed_size : Size of the file's data compressed in the archive
 25006   //                       (without the headers overhead)
 25007   //     mtime : Last known modification date of the file (UNIX timestamp)
 25008   //     comment : Comment associated with the file
 25009   //     folder : true | false
 25010   //     index : index of the file in the archive
 25011   //     status : status of the action (depending of the action) :
 25012   //              Values are :
 25013   //                ok : OK !
 25014   //                filtered : the file / dir is not extracted (filtered by user)
 25015   //                already_a_directory : the file can not be extracted because a
 25016   //                                      directory with the same name already exists
 25017   //                write_protected : the file can not be extracted because a file
 25018   //                                  with the same name already exists and is
 25019   //                                  write protected
 25020   //                newer_exist : the file was not extracted because a newer file exists
 25021   //                path_creation_fail : the file is not extracted because the folder
 25022   //                                     does not exists and can not be created
 25023   //                write_error : the file was not extracted because there was a
 25024   //                              error while writing the file
 25025   //                read_error : the file was not extracted because there was a error
 25026   //                             while reading the file
 25027   //                invalid_header : the file was not extracted because of an archive
 25028   //                                 format error (bad file header)
 25029   //   Note that each time a method can continue operating when there
 25030   //   is an action error on a file, the error is only logged in the file status.
 25031   // Return Values :
 25032   //   0 on an unrecoverable failure,
 25033   //   The list of the files in the archive.
 25034   // --------------------------------------------------------------------------------
 25035   function listContent()
 25036   {
 25037     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");
 25038     $v_result=1;
 25039 
 25040     // ----- Reset the error handler
 25041     $this->privErrorReset();
 25042 
 25043     // ----- Check archive
 25044     if (!$this->privCheckFormat()) {
 25045       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25046       return(0);
 25047     }
 25048 
 25049     // ----- Call the extracting fct
 25050     $p_list = array();
 25051     if (($v_result = $this->privList($p_list)) != 1)
 25052     {
 25053       unset($p_list);
 25054       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
 25055       return(0);
 25056     }
 25057 
 25058     // ----- Return
 25059     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
 25060     return $p_list;
 25061   }
 25062   // --------------------------------------------------------------------------------
 25063 
 25064   // --------------------------------------------------------------------------------
 25065   // Function :
 25066   //   extract($p_path="./", $p_remove_path="")
 25067   //   extract([$p_option, $p_option_value, ...])
 25068   // Description :
 25069   //   This method supports two synopsis. The first one is historical.
 25070   //   This method extract all the files / directories from the archive to the
 25071   //   folder indicated in $p_path.
 25072   //   If you want to ignore the 'root' part of path of the memorized files
 25073   //   you can indicate this in the optional $p_remove_path parameter.
 25074   //   By default, if a newer file with the same name already exists, the
 25075   //   file is not extracted.
 25076   //
 25077   //   If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
 25078   //   are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
 25079   //   at the end of the path value of PCLZIP_OPT_PATH.
 25080   // Parameters :
 25081   //   $p_path : Path where the files and directories are to be extracted
 25082   //   $p_remove_path : First part ('root' part) of the memorized path
 25083   //                    (if any similar) to remove while extracting.
 25084   // Options :
 25085   //   PCLZIP_OPT_PATH :
 25086   //   PCLZIP_OPT_ADD_PATH :
 25087   //   PCLZIP_OPT_REMOVE_PATH :
 25088   //   PCLZIP_OPT_REMOVE_ALL_PATH :
 25089   //   PCLZIP_CB_PRE_EXTRACT :
 25090   //   PCLZIP_CB_POST_EXTRACT :
 25091   // Return Values :
 25092   //   0 or a negative value on failure,
 25093   //   The list of the extracted files, with a status of the action.
 25094   //   (see PclZip::listContent() for list entry format)
 25095   // --------------------------------------------------------------------------------
 25096   function extract()
 25097   {
 25098     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");
 25099     $v_result=1;
 25100 
 25101     // ----- Reset the error handler
 25102     $this->privErrorReset();
 25103 
 25104     // ----- Check archive
 25105     if (!$this->privCheckFormat()) {
 25106       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25107       return(0);
 25108     }
 25109 
 25110     // ----- Set default values
 25111     $v_options = array();
 25112 //    $v_path = "./";
 25113     $v_path = '';
 25114     $v_remove_path = "";
 25115     $v_remove_all_path = false;
 25116 
 25117     // ----- Look for variable options arguments
 25118     $v_size = func_num_args();
 25119     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
 25120 
 25121     // ----- Default values for option
 25122     $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 25123 
 25124     // ----- Look for arguments
 25125     if ($v_size > 0) {
 25126       // ----- Get the arguments
 25127       $v_arg_list = func_get_args();
 25128 
 25129       // ----- Look for first arg
 25130       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 25131         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
 25132 
 25133         // ----- Parse the options
 25134         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 25135                                             array (PCLZIP_OPT_PATH => 'optional',
 25136                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
 25137                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 25138                                                    PCLZIP_OPT_ADD_PATH => 'optional',
 25139                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
 25140                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
 25141                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
 25142                                                    PCLZIP_OPT_BY_NAME => 'optional',
 25143                                                    PCLZIP_OPT_BY_EREG => 'optional',
 25144                                                    PCLZIP_OPT_BY_PREG => 'optional',
 25145                                                    PCLZIP_OPT_BY_INDEX => 'optional',
 25146                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
 25147                                                    PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
 25148                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
 25149                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
 25150                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
 25151 												    ));
 25152         if ($v_result != 1) {
 25153           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25154           return 0;
 25155         }
 25156 
 25157         // ----- Set the arguments
 25158         if (isset($v_options[PCLZIP_OPT_PATH])) {
 25159           $v_path = $v_options[PCLZIP_OPT_PATH];
 25160         }
 25161         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
 25162           $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
 25163         }
 25164         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 25165           $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 25166         }
 25167         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
 25168           // ----- Check for '/' in last path char
 25169           if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
 25170             $v_path .= '/';
 25171           }
 25172           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
 25173         }
 25174       }
 25175 
 25176       // ----- Look for 2 args
 25177       // Here we need to support the first historic synopsis of the
 25178       // method.
 25179       else {
 25180         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
 25181 
 25182         // ----- Get the first argument
 25183         $v_path = $v_arg_list[0];
 25184 
 25185         // ----- Look for the optional second argument
 25186         if ($v_size == 2) {
 25187           $v_remove_path = $v_arg_list[1];
 25188         }
 25189         else if ($v_size > 2) {
 25190           // ----- Error log
 25191           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 25192 
 25193           // ----- Return
 25194           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
 25195           return 0;
 25196         }
 25197       }
 25198     }
 25199 
 25200     // ----- Trace
 25201     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");
 25202 
 25203     // ----- Call the extracting fct
 25204     $p_list = array();
 25205     $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
 25206 	                                     $v_remove_all_path, $v_options);
 25207     if ($v_result < 1) {
 25208       unset($p_list);
 25209       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
 25210       return(0);
 25211     }
 25212 
 25213     // ----- Return
 25214     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
 25215     return $p_list;
 25216   }
 25217   // --------------------------------------------------------------------------------
 25218 
 25219 
 25220   // --------------------------------------------------------------------------------
 25221   // Function :
 25222   //   extractByIndex($p_index, $p_path="./", $p_remove_path="")
 25223   //   extractByIndex($p_index, [$p_option, $p_option_value, ...])
 25224   // Description :
 25225   //   This method supports two synopsis. The first one is historical.
 25226   //   This method is doing a partial extract of the archive.
 25227   //   The extracted files or folders are identified by their index in the
 25228   //   archive (from 0 to n).
 25229   //   Note that if the index identify a folder, only the folder entry is
 25230   //   extracted, not all the files included in the archive.
 25231   // Parameters :
 25232   //   $p_index : A single index (integer) or a string of indexes of files to
 25233   //              extract. The form of the string is "0,4-6,8-12" with only numbers
 25234   //              and '-' for range or ',' to separate ranges. No spaces or ';'
 25235   //              are allowed.
 25236   //   $p_path : Path where the files and directories are to be extracted
 25237   //   $p_remove_path : First part ('root' part) of the memorized path
 25238   //                    (if any similar) to remove while extracting.
 25239   // Options :
 25240   //   PCLZIP_OPT_PATH :
 25241   //   PCLZIP_OPT_ADD_PATH :
 25242   //   PCLZIP_OPT_REMOVE_PATH :
 25243   //   PCLZIP_OPT_REMOVE_ALL_PATH :
 25244   //   PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
 25245   //     not as files.
 25246   //     The resulting content is in a new field 'content' in the file
 25247   //     structure.
 25248   //     This option must be used alone (any other options are ignored).
 25249   //   PCLZIP_CB_PRE_EXTRACT :
 25250   //   PCLZIP_CB_POST_EXTRACT :
 25251   // Return Values :
 25252   //   0 on failure,
 25253   //   The list of the extracted files, with a status of the action.
 25254   //   (see PclZip::listContent() for list entry format)
 25255   // --------------------------------------------------------------------------------
 25256   //function extractByIndex($p_index, options...)
 25257   function extractByIndex($p_index)
 25258   {
 25259     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");
 25260     $v_result=1;
 25261 
 25262     // ----- Reset the error handler
 25263     $this->privErrorReset();
 25264 
 25265     // ----- Check archive
 25266     if (!$this->privCheckFormat()) {
 25267       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25268       return(0);
 25269     }
 25270 
 25271     // ----- Set default values
 25272     $v_options = array();
 25273 //    $v_path = "./";
 25274     $v_path = '';
 25275     $v_remove_path = "";
 25276     $v_remove_all_path = false;
 25277 
 25278     // ----- Look for variable options arguments
 25279     $v_size = func_num_args();
 25280     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
 25281 
 25282     // ----- Default values for option
 25283     $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 25284 
 25285     // ----- Look for arguments
 25286     if ($v_size > 1) {
 25287       // ----- Get the arguments
 25288       $v_arg_list = func_get_args();
 25289 
 25290       // ----- Remove form the options list the first argument
 25291       array_shift($v_arg_list);
 25292       $v_size--;
 25293 
 25294       // ----- Look for first arg
 25295       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 25296         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
 25297 
 25298         // ----- Parse the options
 25299         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 25300                                             array (PCLZIP_OPT_PATH => 'optional',
 25301                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
 25302                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 25303                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
 25304                                                    PCLZIP_OPT_ADD_PATH => 'optional',
 25305                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
 25306                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
 25307                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
 25308                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
 25309                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
 25310                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
 25311 												   ));
 25312         if ($v_result != 1) {
 25313           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25314           return 0;
 25315         }
 25316 
 25317         // ----- Set the arguments
 25318         if (isset($v_options[PCLZIP_OPT_PATH])) {
 25319           $v_path = $v_options[PCLZIP_OPT_PATH];
 25320         }
 25321         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
 25322           $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
 25323         }
 25324         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 25325           $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 25326         }
 25327         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
 25328           // ----- Check for '/' in last path char
 25329           if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
 25330             $v_path .= '/';
 25331           }
 25332           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
 25333         }
 25334         if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
 25335           $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 25336           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set.");
 25337         }
 25338         else {
 25339             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set.");
 25340         }
 25341       }
 25342 
 25343       // ----- Look for 2 args
 25344       // Here we need to support the first historic synopsis of the
 25345       // method.
 25346       else {
 25347         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
 25348 
 25349         // ----- Get the first argument
 25350         $v_path = $v_arg_list[0];
 25351 
 25352         // ----- Look for the optional second argument
 25353         if ($v_size == 2) {
 25354           $v_remove_path = $v_arg_list[1];
 25355         }
 25356         else if ($v_size > 2) {
 25357           // ----- Error log
 25358           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 25359 
 25360           // ----- Return
 25361           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 25362           return 0;
 25363         }
 25364       }
 25365     }
 25366 
 25367     // ----- Trace
 25368     //--(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')."'");
 25369 
 25370     // ----- Trick
 25371     // Here I want to reuse extractByRule(), so I need to parse the $p_index
 25372     // with privParseOptions()
 25373     $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
 25374     $v_options_trick = array();
 25375     $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
 25376                                         array (PCLZIP_OPT_BY_INDEX => 'optional' ));
 25377     if ($v_result != 1) {
 25378         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25379         return 0;
 25380     }
 25381     $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
 25382 
 25383     // ----- Call the extracting fct
 25384     if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
 25385         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
 25386         return(0);
 25387     }
 25388 
 25389     // ----- Return
 25390     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
 25391     return $p_list;
 25392   }
 25393   // --------------------------------------------------------------------------------
 25394 
 25395   // --------------------------------------------------------------------------------
 25396   // Function :
 25397   //   delete([$p_option, $p_option_value, ...])
 25398   // Description :
 25399   //   This method removes files from the archive.
 25400   //   If no parameters are given, then all the archive is emptied.
 25401   // Parameters :
 25402   //   None or optional arguments.
 25403   // Options :
 25404   //   PCLZIP_OPT_BY_INDEX :
 25405   //   PCLZIP_OPT_BY_NAME :
 25406   //   PCLZIP_OPT_BY_EREG :
 25407   //   PCLZIP_OPT_BY_PREG :
 25408   // Return Values :
 25409   //   0 on failure,
 25410   //   The list of the files which are still present in the archive.
 25411   //   (see PclZip::listContent() for list entry format)
 25412   // --------------------------------------------------------------------------------
 25413   function delete()
 25414   {
 25415     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");
 25416     $v_result=1;
 25417 
 25418     // ----- Reset the error handler
 25419     $this->privErrorReset();
 25420 
 25421     // ----- Check archive
 25422     if (!$this->privCheckFormat()) {
 25423       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25424       return(0);
 25425     }
 25426 
 25427     // ----- Set default values
 25428     $v_options = array();
 25429 
 25430     // ----- Look for variable options arguments
 25431     $v_size = func_num_args();
 25432     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
 25433 
 25434     // ----- Look for arguments
 25435     if ($v_size > 0) {
 25436       // ----- Get the arguments
 25437       $v_arg_list = func_get_args();
 25438 
 25439       // ----- Parse the options
 25440       $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 25441                                         array (PCLZIP_OPT_BY_NAME => 'optional',
 25442                                                PCLZIP_OPT_BY_EREG => 'optional',
 25443                                                PCLZIP_OPT_BY_PREG => 'optional',
 25444                                                PCLZIP_OPT_BY_INDEX => 'optional' ));
 25445       if ($v_result != 1) {
 25446           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25447           return 0;
 25448       }
 25449     }
 25450 
 25451     // ----- Magic quotes trick
 25452     $this->privDisableMagicQuotes();
 25453 
 25454     // ----- Call the delete fct
 25455     $v_list = array();
 25456     if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
 25457       $this->privSwapBackMagicQuotes();
 25458       unset($v_list);
 25459       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
 25460       return(0);
 25461     }
 25462 
 25463     // ----- Magic quotes trick
 25464     $this->privSwapBackMagicQuotes();
 25465 
 25466     // ----- Return
 25467     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);
 25468     return $v_list;
 25469   }
 25470   // --------------------------------------------------------------------------------
 25471 
 25472   // --------------------------------------------------------------------------------
 25473   // Function : deleteByIndex()
 25474   // Description :
 25475   //   ***** Deprecated *****
 25476   //   delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
 25477   // --------------------------------------------------------------------------------
 25478   function deleteByIndex($p_index)
 25479   {
 25480     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'");
 25481 
 25482     $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
 25483 
 25484     // ----- Return
 25485     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
 25486     return $p_list;
 25487   }
 25488   // --------------------------------------------------------------------------------
 25489 
 25490   // --------------------------------------------------------------------------------
 25491   // Function : properties()
 25492   // Description :
 25493   //   This method gives the properties of the archive.
 25494   //   The properties are :
 25495   //     nb : Number of files in the archive
 25496   //     comment : Comment associated with the archive file
 25497   //     status : not_exist, ok
 25498   // Parameters :
 25499   //   None
 25500   // Return Values :
 25501   //   0 on failure,
 25502   //   An array with the archive properties.
 25503   // --------------------------------------------------------------------------------
 25504   function properties()
 25505   {
 25506     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");
 25507 
 25508     // ----- Reset the error handler
 25509     $this->privErrorReset();
 25510 
 25511     // ----- Magic quotes trick
 25512     $this->privDisableMagicQuotes();
 25513 
 25514     // ----- Check archive
 25515     if (!$this->privCheckFormat()) {
 25516       $this->privSwapBackMagicQuotes();
 25517       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25518       return(0);
 25519     }
 25520 
 25521     // ----- Default properties
 25522     $v_prop = array();
 25523     $v_prop['comment'] = '';
 25524     $v_prop['nb'] = 0;
 25525     $v_prop['status'] = 'not_exist';
 25526 
 25527     // ----- Look if file exists
 25528     if (@is_file($this->zipname))
 25529     {
 25530       // ----- Open the zip file
 25531       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 25532       if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
 25533       {
 25534         $this->privSwapBackMagicQuotes();
 25535 
 25536         // ----- Error log
 25537         PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
 25538 
 25539         // ----- Return
 25540         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);
 25541         return 0;
 25542       }
 25543 
 25544       // ----- Read the central directory informations
 25545       $v_central_dir = array();
 25546       if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
 25547       {
 25548         $this->privSwapBackMagicQuotes();
 25549         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25550         return 0;
 25551       }
 25552 
 25553       // ----- Close the zip file
 25554       $this->privCloseFd();
 25555 
 25556       // ----- Set the user attributes
 25557       $v_prop['comment'] = $v_central_dir['comment'];
 25558       $v_prop['nb'] = $v_central_dir['entries'];
 25559       $v_prop['status'] = 'ok';
 25560     }
 25561 
 25562     // ----- Magic quotes trick
 25563     $this->privSwapBackMagicQuotes();
 25564 
 25565     // ----- Return
 25566     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);
 25567     return $v_prop;
 25568   }
 25569   // --------------------------------------------------------------------------------
 25570 
 25571   // --------------------------------------------------------------------------------
 25572   // Function : duplicate()
 25573   // Description :
 25574   //   This method creates an archive by copying the content of an other one. If
 25575   //   the archive already exist, it is replaced by the new one without any warning.
 25576   // Parameters :
 25577   //   $p_archive : The filename of a valid archive, or
 25578   //                a valid PclZip object.
 25579   // Return Values :
 25580   //   1 on success.
 25581   //   0 or a negative value on error (error code).
 25582   // --------------------------------------------------------------------------------
 25583   function duplicate($p_archive)
 25584   {
 25585     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");
 25586     $v_result = 1;
 25587 
 25588     // ----- Reset the error handler
 25589     $this->privErrorReset();
 25590 
 25591     // ----- Look if the $p_archive is a PclZip object
 25592     if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
 25593     {
 25594       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");
 25595 
 25596       // ----- Duplicate the archive
 25597       $v_result = $this->privDuplicate($p_archive->zipname);
 25598     }
 25599 
 25600     // ----- Look if the $p_archive is a string (so a filename)
 25601     else if (is_string($p_archive))
 25602     {
 25603       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");
 25604 
 25605       // ----- Check that $p_archive is a valid zip file
 25606       // TBC : Should also check the archive format
 25607       if (!is_file($p_archive)) {
 25608         // ----- Error log
 25609         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
 25610         $v_result = PCLZIP_ERR_MISSING_FILE;
 25611       }
 25612       else {
 25613         // ----- Duplicate the archive
 25614         $v_result = $this->privDuplicate($p_archive);
 25615       }
 25616     }
 25617 
 25618     // ----- Invalid variable
 25619     else
 25620     {
 25621       // ----- Error log
 25622       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
 25623       $v_result = PCLZIP_ERR_INVALID_PARAMETER;
 25624     }
 25625 
 25626     // ----- Return
 25627     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 25628     return $v_result;
 25629   }
 25630   // --------------------------------------------------------------------------------
 25631 
 25632   // --------------------------------------------------------------------------------
 25633   // Function : merge()
 25634   // Description :
 25635   //   This method merge the $p_archive_to_add archive at the end of the current
 25636   //   one ($this).
 25637   //   If the archive ($this) does not exist, the merge becomes a duplicate.
 25638   //   If the $p_archive_to_add archive does not exist, the merge is a success.
 25639   // Parameters :
 25640   //   $p_archive_to_add : It can be directly the filename of a valid zip archive,
 25641   //                       or a PclZip object archive.
 25642   // Return Values :
 25643   //   1 on success,
 25644   //   0 or negative values on error (see below).
 25645   // --------------------------------------------------------------------------------
 25646   function merge($p_archive_to_add)
 25647   {
 25648     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");
 25649     $v_result = 1;
 25650 
 25651     // ----- Reset the error handler
 25652     $this->privErrorReset();
 25653 
 25654     // ----- Check archive
 25655     if (!$this->privCheckFormat()) {
 25656       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
 25657       return(0);
 25658     }
 25659 
 25660     // ----- Look if the $p_archive_to_add is a PclZip object
 25661     if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
 25662     {
 25663       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");
 25664 
 25665       // ----- Merge the archive
 25666       $v_result = $this->privMerge($p_archive_to_add);
 25667     }
 25668 
 25669     // ----- Look if the $p_archive_to_add is a string (so a filename)
 25670     else if (is_string($p_archive_to_add))
 25671     {
 25672       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");
 25673 
 25674       // ----- Create a temporary archive
 25675       $v_object_archive = new PclZip($p_archive_to_add);
 25676 
 25677       // ----- Merge the archive
 25678       $v_result = $this->privMerge($v_object_archive);
 25679     }
 25680 
 25681     // ----- Invalid variable
 25682     else
 25683     {
 25684       // ----- Error log
 25685       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
 25686       $v_result = PCLZIP_ERR_INVALID_PARAMETER;
 25687     }
 25688 
 25689     // ----- Return
 25690     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 25691     return $v_result;
 25692   }
 25693   // --------------------------------------------------------------------------------
 25694 
 25695 
 25696 
 25697   // --------------------------------------------------------------------------------
 25698   // Function : errorCode()
 25699   // Description :
 25700   // Parameters :
 25701   // --------------------------------------------------------------------------------
 25702   function errorCode()
 25703   {
 25704     if (PCLZIP_ERROR_EXTERNAL == 1) {
 25705       return(PclErrorCode());
 25706     }
 25707     else {
 25708       return($this->error_code);
 25709     }
 25710   }
 25711   // --------------------------------------------------------------------------------
 25712 
 25713   // --------------------------------------------------------------------------------
 25714   // Function : errorName()
 25715   // Description :
 25716   // Parameters :
 25717   // --------------------------------------------------------------------------------
 25718   function errorName($p_with_code=false)
 25719   {
 25720     $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
 25721                       PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
 25722                       PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
 25723                       PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
 25724                       PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
 25725                       PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
 25726                       PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
 25727                       PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
 25728                       PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
 25729                       PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
 25730                       PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
 25731                       PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
 25732                       PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
 25733                       PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
 25734                       PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
 25735                       PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
 25736                       PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
 25737                       PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
 25738                       PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
 25739                       ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
 25740                       ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
 25741                     );
 25742 
 25743     if (isset($v_name[$this->error_code])) {
 25744       $v_value = $v_name[$this->error_code];
 25745     }
 25746     else {
 25747       $v_value = 'NoName';
 25748     }
 25749 
 25750     if ($p_with_code) {
 25751       return($v_value.' ('.$this->error_code.')');
 25752     }
 25753     else {
 25754       return($v_value);
 25755     }
 25756   }
 25757   // --------------------------------------------------------------------------------
 25758 
 25759   // --------------------------------------------------------------------------------
 25760   // Function : errorInfo()
 25761   // Description :
 25762   // Parameters :
 25763   // --------------------------------------------------------------------------------
 25764   function errorInfo($p_full=false)
 25765   {
 25766     if (PCLZIP_ERROR_EXTERNAL == 1) {
 25767       return(PclErrorString());
 25768     }
 25769     else {
 25770       if ($p_full) {
 25771         return($this->errorName(true)." : ".$this->error_string);
 25772       }
 25773       else {
 25774         return($this->error_string." [code ".$this->error_code."]");
 25775       }
 25776     }
 25777   }
 25778   // --------------------------------------------------------------------------------
 25779 
 25780 
 25781 // --------------------------------------------------------------------------------
 25782 // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
 25783 // *****                                                        *****
 25784 // *****       THESES FUNCTIONS MUST NOT BE USED DIRECTLY       *****
 25785 // --------------------------------------------------------------------------------
 25786 
 25787 
 25788 
 25789   // --------------------------------------------------------------------------------
 25790   // Function : privCheckFormat()
 25791   // Description :
 25792   //   This method check that the archive exists and is a valid zip archive.
 25793   //   Several level of check exists. (futur)
 25794   // Parameters :
 25795   //   $p_level : Level of check. Default 0.
 25796   //              0 : Check the first bytes (magic codes) (default value))
 25797   //              1 : 0 + Check the central directory (futur)
 25798   //              2 : 1 + Check each file header (futur)
 25799   // Return Values :
 25800   //   true on success,
 25801   //   false on error, the error code is set.
 25802   // --------------------------------------------------------------------------------
 25803   function privCheckFormat($p_level=0)
 25804   {
 25805     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");
 25806     $v_result = true;
 25807 
 25808 	// ----- Reset the file system cache
 25809     clearstatcache();
 25810 
 25811     // ----- Reset the error handler
 25812     $this->privErrorReset();
 25813 
 25814     // ----- Look if the file exits
 25815     if (!is_file($this->zipname)) {
 25816       // ----- Error log
 25817       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
 25818       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
 25819       return(false);
 25820     }
 25821 
 25822     // ----- Check that the file is readeable
 25823     if (!is_readable($this->zipname)) {
 25824       // ----- Error log
 25825       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
 25826       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
 25827       return(false);
 25828     }
 25829 
 25830     // ----- Check the magic code
 25831     // TBC
 25832 
 25833     // ----- Check the central header
 25834     // TBC
 25835 
 25836     // ----- Check each file header
 25837     // TBC
 25838 
 25839     // ----- Return
 25840     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 25841     return $v_result;
 25842   }
 25843   // --------------------------------------------------------------------------------
 25844 
 25845   // --------------------------------------------------------------------------------
 25846   // Function : privParseOptions()
 25847   // Description :
 25848   //   This internal methods reads the variable list of arguments ($p_options_list,
 25849   //   $p_size) and generate an array with the options and values ($v_result_list).
 25850   //   $v_requested_options contains the options that can be present and those that
 25851   //   must be present.
 25852   //   $v_requested_options is an array, with the option value as key, and 'optional',
 25853   //   or 'mandatory' as value.
 25854   // Parameters :
 25855   //   See above.
 25856   // Return Values :
 25857   //   1 on success.
 25858   //   0 on failure.
 25859   // --------------------------------------------------------------------------------
 25860   function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
 25861   {
 25862     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");
 25863     $v_result=1;
 25864 
 25865     // ----- Read the options
 25866     $i=0;
 25867     while ($i<$p_size) {
 25868       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'");
 25869 
 25870       // ----- Check if the option is supported
 25871       if (!isset($v_requested_options[$p_options_list[$i]])) {
 25872         // ----- Error log
 25873         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
 25874 
 25875         // ----- Return
 25876         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 25877         return PclZip::errorCode();
 25878       }
 25879 
 25880       // ----- Look for next option
 25881       switch ($p_options_list[$i]) {
 25882         // ----- Look for options that request a path value
 25883         case PCLZIP_OPT_PATH :
 25884         case PCLZIP_OPT_REMOVE_PATH :
 25885         case PCLZIP_OPT_ADD_PATH :
 25886           // ----- Check the number of parameters
 25887           if (($i+1) >= $p_size) {
 25888             // ----- Error log
 25889             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 25890 
 25891             // ----- Return
 25892             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 25893             return PclZip::errorCode();
 25894           }
 25895 
 25896           // ----- Get the value
 25897           $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
 25898           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
 25899           $i++;
 25900         break;
 25901 
 25902         case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
 25903           // ----- Check the number of parameters
 25904           if (($i+1) >= $p_size) {
 25905             // ----- Error log
 25906             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 25907 
 25908             // ----- Return
 25909             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 25910             return PclZip::errorCode();
 25911           }
 25912 
 25913           // ----- Get the value
 25914           if (   is_string($p_options_list[$i+1])
 25915               && ($p_options_list[$i+1] != '')) {
 25916             $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
 25917             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
 25918             $i++;
 25919           }
 25920           else {
 25921             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored.");
 25922           }
 25923         break;
 25924 
 25925         // ----- Look for options that request an array of string for value
 25926         case PCLZIP_OPT_BY_NAME :
 25927           // ----- Check the number of parameters
 25928           if (($i+1) >= $p_size) {
 25929             // ----- Error log
 25930             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 25931 
 25932             // ----- Return
 25933             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 25934             return PclZip::errorCode();
 25935           }
 25936 
 25937           // ----- Get the value
 25938           if (is_string($p_options_list[$i+1])) {
 25939               $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
 25940           }
 25941           else if (is_array($p_options_list[$i+1])) {
 25942               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
 25943           }
 25944           else {
 25945             // ----- Error log
 25946             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 25947 
 25948             // ----- Return
 25949             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 25950             return PclZip::errorCode();
 25951           }
 25952           ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
 25953           $i++;
 25954         break;
 25955 
 25956         // ----- Look for options that request an EREG or PREG expression
 25957         case PCLZIP_OPT_BY_EREG :
 25958         case PCLZIP_OPT_BY_PREG :
 25959         //case PCLZIP_OPT_CRYPT :
 25960           // ----- Check the number of parameters
 25961           if (($i+1) >= $p_size) {
 25962             // ----- Error log
 25963             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 25964 
 25965             // ----- Return
 25966             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 25967             return PclZip::errorCode();
 25968           }
 25969 
 25970           // ----- Get the value
 25971           if (is_string($p_options_list[$i+1])) {
 25972               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
 25973           }
 25974           else {
 25975             // ----- Error log
 25976             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 25977 
 25978             // ----- Return
 25979             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 25980             return PclZip::errorCode();
 25981           }
 25982           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
 25983           $i++;
 25984         break;
 25985 
 25986         // ----- Look for options that takes a string
 25987         case PCLZIP_OPT_COMMENT :
 25988         case PCLZIP_OPT_ADD_COMMENT :
 25989         case PCLZIP_OPT_PREPEND_COMMENT :
 25990           // ----- Check the number of parameters
 25991           if (($i+1) >= $p_size) {
 25992             // ----- Error log
 25993             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
 25994 			                     "Missing parameter value for option '"
 25995 								 .PclZipUtilOptionText($p_options_list[$i])
 25996 								 ."'");
 25997 
 25998             // ----- Return
 25999             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26000             return PclZip::errorCode();
 26001           }
 26002 
 26003           // ----- Get the value
 26004           if (is_string($p_options_list[$i+1])) {
 26005               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
 26006           }
 26007           else {
 26008             // ----- Error log
 26009             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
 26010 			                     "Wrong parameter value for option '"
 26011 								 .PclZipUtilOptionText($p_options_list[$i])
 26012 								 ."'");
 26013 
 26014             // ----- Return
 26015             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26016             return PclZip::errorCode();
 26017           }
 26018           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
 26019           $i++;
 26020         break;
 26021 
 26022         // ----- Look for options that request an array of index
 26023         case PCLZIP_OPT_BY_INDEX :
 26024           // ----- Check the number of parameters
 26025           if (($i+1) >= $p_size) {
 26026             // ----- Error log
 26027             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 26028 
 26029             // ----- Return
 26030             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26031             return PclZip::errorCode();
 26032           }
 26033 
 26034           // ----- Get the value
 26035           $v_work_list = array();
 26036           if (is_string($p_options_list[$i+1])) {
 26037               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'");
 26038 
 26039               // ----- Remove spaces
 26040               $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
 26041 
 26042               // ----- Parse items
 26043               $v_work_list = explode(",", $p_options_list[$i+1]);
 26044           }
 26045           else if (is_integer($p_options_list[$i+1])) {
 26046               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'");
 26047               $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
 26048           }
 26049           else if (is_array($p_options_list[$i+1])) {
 26050               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array");
 26051               $v_work_list = $p_options_list[$i+1];
 26052           }
 26053           else {
 26054             // ----- Error log
 26055             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 26056 
 26057             // ----- Return
 26058             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26059             return PclZip::errorCode();
 26060           }
 26061 
 26062           // ----- Reduce the index list
 26063           // each index item in the list must be a couple with a start and
 26064           // an end value : [0,3], [5-5], [8-10], ...
 26065           // ----- Check the format of each item
 26066           $v_sort_flag=false;
 26067           $v_sort_value=0;
 26068           for ($j=0; $j<sizeof($v_work_list); $j++) {
 26069               // ----- Explode the item
 26070               $v_item_list = explode("-", $v_work_list[$j]);
 26071               $v_size_item_list = sizeof($v_item_list);
 26072 
 26073               // ----- TBC : Here we might check that each item is a
 26074               // real integer ...
 26075 
 26076               // ----- Look for single value
 26077               if ($v_size_item_list == 1) {
 26078                   // ----- Set the option value
 26079                   $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
 26080                   $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
 26081               }
 26082               elseif ($v_size_item_list == 2) {
 26083                   // ----- Set the option value
 26084                   $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
 26085                   $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
 26086               }
 26087               else {
 26088                   // ----- Error log
 26089                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 26090 
 26091                   // ----- Return
 26092                   //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26093                   return PclZip::errorCode();
 26094               }
 26095 
 26096               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extracted index item = [".$v_result_list[$p_options_list[$i]][$j]['start'].",".$v_result_list[$p_options_list[$i]][$j]['end']."]");
 26097 
 26098               // ----- Look for list sort
 26099               if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
 26100                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ...");
 26101                   $v_sort_flag=true;
 26102 
 26103                   // ----- TBC : An automatic sort should be writen ...
 26104                   // ----- Error log
 26105                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 26106 
 26107                   // ----- Return
 26108                   //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26109                   return PclZip::errorCode();
 26110               }
 26111               $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
 26112           }
 26113 
 26114           // ----- Sort the items
 26115           if ($v_sort_flag) {
 26116               // TBC : To Be Completed
 26117               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ...");
 26118           }
 26119 
 26120           // ----- Next option
 26121           $i++;
 26122         break;
 26123 
 26124         // ----- Look for options that request no value
 26125         case PCLZIP_OPT_REMOVE_ALL_PATH :
 26126         case PCLZIP_OPT_EXTRACT_AS_STRING :
 26127         case PCLZIP_OPT_NO_COMPRESSION :
 26128         case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
 26129         case PCLZIP_OPT_REPLACE_NEWER :
 26130         case PCLZIP_OPT_STOP_ON_ERROR :
 26131           $v_result_list[$p_options_list[$i]] = true;
 26132           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
 26133         break;
 26134 
 26135         // ----- Look for options that request an octal value
 26136         case PCLZIP_OPT_SET_CHMOD :
 26137           // ----- Check the number of parameters
 26138           if (($i+1) >= $p_size) {
 26139             // ----- Error log
 26140             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 26141 
 26142             // ----- Return
 26143             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26144             return PclZip::errorCode();
 26145           }
 26146 
 26147           // ----- Get the value
 26148           $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
 26149           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
 26150           $i++;
 26151         break;
 26152 
 26153         // ----- Look for options that request a call-back
 26154         case PCLZIP_CB_PRE_EXTRACT :
 26155         case PCLZIP_CB_POST_EXTRACT :
 26156         case PCLZIP_CB_PRE_ADD :
 26157         case PCLZIP_CB_POST_ADD :
 26158         /* for futur use
 26159         case PCLZIP_CB_PRE_DELETE :
 26160         case PCLZIP_CB_POST_DELETE :
 26161         case PCLZIP_CB_PRE_LIST :
 26162         case PCLZIP_CB_POST_LIST :
 26163         */
 26164           // ----- Check the number of parameters
 26165           if (($i+1) >= $p_size) {
 26166             // ----- Error log
 26167             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 26168 
 26169             // ----- Return
 26170             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26171             return PclZip::errorCode();
 26172           }
 26173 
 26174           // ----- Get the value
 26175           $v_function_name = $p_options_list[$i+1];
 26176           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'");
 26177 
 26178           // ----- Check that the value is a valid existing function
 26179           if (!function_exists($v_function_name)) {
 26180             // ----- Error log
 26181             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
 26182 
 26183             // ----- Return
 26184             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26185             return PclZip::errorCode();
 26186           }
 26187 
 26188           // ----- Set the attribute
 26189           $v_result_list[$p_options_list[$i]] = $v_function_name;
 26190           $i++;
 26191         break;
 26192 
 26193         default :
 26194           // ----- Error log
 26195           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
 26196 		                       "Unknown parameter '"
 26197 							   .$p_options_list[$i]."'");
 26198 
 26199           // ----- Return
 26200           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26201           return PclZip::errorCode();
 26202       }
 26203 
 26204       // ----- Next options
 26205       $i++;
 26206     }
 26207 
 26208     // ----- Look for mandatory options
 26209     if ($v_requested_options !== false) {
 26210       for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
 26211         // ----- Look for mandatory option
 26212         if ($v_requested_options[$key] == 'mandatory') {
 26213           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
 26214           // ----- Look if present
 26215           if (!isset($v_result_list[$key])) {
 26216             // ----- Error log
 26217             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
 26218 
 26219             // ----- Return
 26220             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26221             return PclZip::errorCode();
 26222           }
 26223         }
 26224       }
 26225     }
 26226 
 26227     // ----- Return
 26228     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26229     return $v_result;
 26230   }
 26231   // --------------------------------------------------------------------------------
 26232 
 26233   // --------------------------------------------------------------------------------
 26234   // Function : privFileDescrParseAtt()
 26235   // Description :
 26236   // Parameters :
 26237   // Return Values :
 26238   //   1 on success.
 26239   //   0 on failure.
 26240   // --------------------------------------------------------------------------------
 26241   function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
 26242   {
 26243     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", "");
 26244     $v_result=1;
 26245 
 26246     // ----- For each file in the list check the attributes
 26247     foreach ($p_file_list as $v_key => $v_value) {
 26248 
 26249       // ----- Check if the option is supported
 26250       if (!isset($v_requested_options[$v_key])) {
 26251         // ----- Error log
 26252         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
 26253 
 26254         // ----- Return
 26255         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26256         return PclZip::errorCode();
 26257       }
 26258 
 26259       // ----- Look for attribute
 26260       switch ($v_key) {
 26261         case PCLZIP_ATT_FILE_NAME :
 26262           if (!is_string($v_value)) {
 26263             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
 26264             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26265             return PclZip::errorCode();
 26266           }
 26267 
 26268           $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
 26269           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
 26270 
 26271           if ($p_filedescr['filename'] == '') {
 26272             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
 26273             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26274             return PclZip::errorCode();
 26275           }
 26276 
 26277         break;
 26278 
 26279         case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
 26280           if (!is_string($v_value)) {
 26281             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
 26282             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26283             return PclZip::errorCode();
 26284           }
 26285 
 26286           $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
 26287           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
 26288 
 26289           if ($p_filedescr['new_short_name'] == '') {
 26290             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
 26291             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26292             return PclZip::errorCode();
 26293           }
 26294         break;
 26295 
 26296         case PCLZIP_ATT_FILE_NEW_FULL_NAME :
 26297           if (!is_string($v_value)) {
 26298             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
 26299             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26300             return PclZip::errorCode();
 26301           }
 26302 
 26303           $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
 26304           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
 26305 
 26306           if ($p_filedescr['new_full_name'] == '') {
 26307             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
 26308             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26309             return PclZip::errorCode();
 26310           }
 26311         break;
 26312 
 26313         default :
 26314           // ----- Error log
 26315           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
 26316 		                           "Unknown parameter '".$v_key."'");
 26317 
 26318           // ----- Return
 26319           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26320           return PclZip::errorCode();
 26321       }
 26322 
 26323       // ----- Look for mandatory options
 26324       if ($v_requested_options !== false) {
 26325         for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
 26326           // ----- Look for mandatory option
 26327           if ($v_requested_options[$key] == 'mandatory') {
 26328             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
 26329             // ----- Look if present
 26330             if (!isset($p_file_list[$key])) {
 26331               PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
 26332               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26333               return PclZip::errorCode();
 26334             }
 26335           }
 26336         }
 26337       }
 26338 
 26339     // end foreach
 26340     }
 26341 
 26342     // ----- Return
 26343     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26344     return $v_result;
 26345   }
 26346   // --------------------------------------------------------------------------------
 26347 
 26348   // --------------------------------------------------------------------------------
 26349   // Function : privFileDescrExpand()
 26350   // Description :
 26351   // Parameters :
 26352   // Return Values :
 26353   //   1 on success.
 26354   //   0 on failure.
 26355   // --------------------------------------------------------------------------------
 26356   function privFileDescrExpand(&$p_filedescr_list, &$p_options)
 26357   {
 26358     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", "");
 26359     $v_result=1;
 26360 
 26361     // ----- Create a result list
 26362     $v_result_list = array();
 26363 
 26364     // ----- Look each entry
 26365     for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
 26366       // ----- Get filedescr
 26367       $v_descr = $p_filedescr_list[$i];
 26368 
 26369       // ----- Reduce the filename
 26370       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'");
 26371       $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']);
 26372       $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
 26373       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'");
 26374 
 26375       // ----- Get type of descr
 26376       if (!file_exists($v_descr['filename'])) {
 26377         // ----- Error log
 26378         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exists");
 26379         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists");
 26380 
 26381         // ----- Return
 26382         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26383         return PclZip::errorCode();
 26384       }
 26385       if (@is_file($v_descr['filename'])) {
 26386         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file");
 26387         $v_descr['type'] = 'file';
 26388       }
 26389       else if (@is_dir($v_descr['filename'])) {
 26390         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder");
 26391         $v_descr['type'] = 'folder';
 26392       }
 26393       else if (@is_link($v_descr['filename'])) {
 26394         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link");
 26395         // skip
 26396         continue;
 26397       }
 26398       else {
 26399         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type");
 26400         // skip
 26401         continue;
 26402       }
 26403 
 26404       // ----- Calculate the stored filename
 26405       $this->privCalculateStoredFilename($v_descr, $p_options);
 26406 
 26407       // ----- Add the descriptor in result list
 26408       $v_result_list[sizeof($v_result_list)] = $v_descr;
 26409 
 26410       // ----- Look for folder
 26411       if ($v_descr['type'] == 'folder') {
 26412         // ----- List of items in folder
 26413         $v_dirlist_descr = array();
 26414         $v_dirlist_nb = 0;
 26415         if ($v_folder_handler = @opendir($v_descr['filename'])) {
 26416           while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
 26417             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory");
 26418 
 26419             // ----- Skip '.' and '..'
 26420             if (($v_item_handler == '.') || ($v_item_handler == '..')) {
 26421                 continue;
 26422             }
 26423 
 26424             // ----- Compose the full filename
 26425             $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
 26426 
 26427             // ----- Look for different stored filename
 26428             // Because the name of the folder was changed, the name of the
 26429             // files/sub-folders also change
 26430             if ($v_descr['stored_filename'] != $v_descr['filename']) {
 26431               $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
 26432             }
 26433 
 26434             $v_dirlist_nb++;
 26435           }
 26436         }
 26437         else {
 26438           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped.");
 26439           // TBC : unable to open folder in read mode
 26440         }
 26441 
 26442         // ----- Expand each element of the list
 26443         if ($v_dirlist_nb != 0) {
 26444           // ----- Expand
 26445           if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
 26446             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26447             return $v_result;
 26448           }
 26449 
 26450           // ----- Concat the resulting list
 26451           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')");
 26452           $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
 26453           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'");
 26454         }
 26455         else {
 26456           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand.");
 26457         }
 26458 
 26459         // ----- Free local array
 26460         unset($v_dirlist_descr);
 26461       }
 26462     }
 26463 
 26464     // ----- Get the result list
 26465     $p_filedescr_list = $v_result_list;
 26466 
 26467     // ----- Return
 26468     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26469     return $v_result;
 26470   }
 26471   // --------------------------------------------------------------------------------
 26472 
 26473   // --------------------------------------------------------------------------------
 26474   // Function : privCreate()
 26475   // Description :
 26476   // Parameters :
 26477   // Return Values :
 26478   // --------------------------------------------------------------------------------
 26479   function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
 26480   {
 26481     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list");
 26482     $v_result=1;
 26483     $v_list_detail = array();
 26484 
 26485     // ----- Magic quotes trick
 26486     $this->privDisableMagicQuotes();
 26487 
 26488     // ----- Open the file in write mode
 26489     if (($v_result = $this->privOpenFd('wb')) != 1)
 26490     {
 26491       // ----- Return
 26492       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26493       return $v_result;
 26494     }
 26495 
 26496     // ----- Add the list of files
 26497     $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
 26498 
 26499     // ----- Close
 26500     $this->privCloseFd();
 26501 
 26502     // ----- Magic quotes trick
 26503     $this->privSwapBackMagicQuotes();
 26504 
 26505     // ----- Return
 26506     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26507     return $v_result;
 26508   }
 26509   // --------------------------------------------------------------------------------
 26510 
 26511   // --------------------------------------------------------------------------------
 26512   // Function : privAdd()
 26513   // Description :
 26514   // Parameters :
 26515   // Return Values :
 26516   // --------------------------------------------------------------------------------
 26517   function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
 26518   {
 26519     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list");
 26520     $v_result=1;
 26521     $v_list_detail = array();
 26522 
 26523     // ----- Look if the archive exists or is empty
 26524     if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
 26525     {
 26526       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it.");
 26527 
 26528       // ----- Do a create
 26529       $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
 26530 
 26531       // ----- Return
 26532       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26533       return $v_result;
 26534     }
 26535     // ----- Magic quotes trick
 26536     $this->privDisableMagicQuotes();
 26537 
 26538     // ----- Open the zip file
 26539     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 26540     if (($v_result=$this->privOpenFd('rb')) != 1)
 26541     {
 26542       // ----- Magic quotes trick
 26543       $this->privSwapBackMagicQuotes();
 26544 
 26545       // ----- Return
 26546       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26547       return $v_result;
 26548     }
 26549 
 26550     // ----- Read the central directory informations
 26551     $v_central_dir = array();
 26552     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
 26553     {
 26554       $this->privCloseFd();
 26555       $this->privSwapBackMagicQuotes();
 26556       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26557       return $v_result;
 26558     }
 26559 
 26560     // ----- Go to beginning of File
 26561     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
 26562     @rewind($this->zip_fd);
 26563     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
 26564 
 26565     // ----- Creates a temporay file
 26566     $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
 26567 
 26568     // ----- Open the temporary file in write mode
 26569     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 26570     if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
 26571     {
 26572       $this->privCloseFd();
 26573       $this->privSwapBackMagicQuotes();
 26574 
 26575       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
 26576 
 26577       // ----- Return
 26578       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26579       return PclZip::errorCode();
 26580     }
 26581 
 26582     // ----- Copy the files from the archive to the temporary file
 26583     // TBC : Here I should better append the file and go back to erase the central dir
 26584     $v_size = $v_central_dir['offset'];
 26585     while ($v_size != 0)
 26586     {
 26587       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
 26588       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 26589       $v_buffer = fread($this->zip_fd, $v_read_size);
 26590       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
 26591       $v_size -= $v_read_size;
 26592     }
 26593 
 26594     // ----- Swap the file descriptor
 26595     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
 26596     // the following methods on the temporary fil and not the real archive
 26597     $v_swap = $this->zip_fd;
 26598     $this->zip_fd = $v_zip_temp_fd;
 26599     $v_zip_temp_fd = $v_swap;
 26600 
 26601     // ----- Add the files
 26602     $v_header_list = array();
 26603     if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
 26604     {
 26605       fclose($v_zip_temp_fd);
 26606       $this->privCloseFd();
 26607       @unlink($v_zip_temp_name);
 26608       $this->privSwapBackMagicQuotes();
 26609 
 26610       // ----- Return
 26611       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26612       return $v_result;
 26613     }
 26614 
 26615     // ----- Store the offset of the central dir
 26616     $v_offset = @ftell($this->zip_fd);
 26617     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");
 26618 
 26619     // ----- Copy the block of file headers from the old archive
 26620     $v_size = $v_central_dir['size'];
 26621     while ($v_size != 0)
 26622     {
 26623       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
 26624       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 26625       $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
 26626       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
 26627       $v_size -= $v_read_size;
 26628     }
 26629 
 26630     // ----- Create the Central Dir files header
 26631     for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
 26632     {
 26633       // ----- Create the file header
 26634       if ($v_header_list[$i]['status'] == 'ok') {
 26635         if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
 26636           fclose($v_zip_temp_fd);
 26637           $this->privCloseFd();
 26638           @unlink($v_zip_temp_name);
 26639           $this->privSwapBackMagicQuotes();
 26640 
 26641           // ----- Return
 26642           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26643           return $v_result;
 26644         }
 26645         $v_count++;
 26646       }
 26647 
 26648       // ----- Transform the header to a 'usable' info
 26649       $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
 26650     }
 26651 
 26652     // ----- Zip file comment
 26653     $v_comment = $v_central_dir['comment'];
 26654     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
 26655       $v_comment = $p_options[PCLZIP_OPT_COMMENT];
 26656     }
 26657     if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
 26658       $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
 26659     }
 26660     if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
 26661       $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
 26662     }
 26663 
 26664     // ----- Calculate the size of the central header
 26665     $v_size = @ftell($this->zip_fd)-$v_offset;
 26666 
 26667     // ----- Create the central dir footer
 26668     if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
 26669     {
 26670       // ----- Reset the file list
 26671       unset($v_header_list);
 26672       $this->privSwapBackMagicQuotes();
 26673 
 26674       // ----- Return
 26675       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26676       return $v_result;
 26677     }
 26678 
 26679     // ----- Swap back the file descriptor
 26680     $v_swap = $this->zip_fd;
 26681     $this->zip_fd = $v_zip_temp_fd;
 26682     $v_zip_temp_fd = $v_swap;
 26683 
 26684     // ----- Close
 26685     $this->privCloseFd();
 26686 
 26687     // ----- Close the temporary file
 26688     @fclose($v_zip_temp_fd);
 26689 
 26690     // ----- Magic quotes trick
 26691     $this->privSwapBackMagicQuotes();
 26692 
 26693     // ----- Delete the zip file
 26694     // TBC : I should test the result ...
 26695     @unlink($this->zipname);
 26696 
 26697     // ----- Rename the temporary file
 26698     // TBC : I should test the result ...
 26699     //@rename($v_zip_temp_name, $this->zipname);
 26700     PclZipUtilRename($v_zip_temp_name, $this->zipname);
 26701 
 26702     // ----- Return
 26703     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26704     return $v_result;
 26705   }
 26706   // --------------------------------------------------------------------------------
 26707 
 26708   // --------------------------------------------------------------------------------
 26709   // Function : privOpenFd()
 26710   // Description :
 26711   // Parameters :
 26712   // --------------------------------------------------------------------------------
 26713   function privOpenFd($p_mode)
 26714   {
 26715     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode);
 26716     $v_result=1;
 26717 
 26718     // ----- Look if already open
 26719     if ($this->zip_fd != 0)
 26720     {
 26721       // ----- Error log
 26722       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
 26723 
 26724       // ----- Return
 26725       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26726       return PclZip::errorCode();
 26727     }
 26728 
 26729     // ----- Open the zip file
 26730     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode');
 26731     if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
 26732     {
 26733       // ----- Error log
 26734       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
 26735 
 26736       // ----- Return
 26737       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26738       return PclZip::errorCode();
 26739     }
 26740 
 26741     // ----- Return
 26742     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26743     return $v_result;
 26744   }
 26745   // --------------------------------------------------------------------------------
 26746 
 26747   // --------------------------------------------------------------------------------
 26748   // Function : privCloseFd()
 26749   // Description :
 26750   // Parameters :
 26751   // --------------------------------------------------------------------------------
 26752   function privCloseFd()
 26753   {
 26754     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", "");
 26755     $v_result=1;
 26756 
 26757     if ($this->zip_fd != 0)
 26758       @fclose($this->zip_fd);
 26759     $this->zip_fd = 0;
 26760 
 26761     // ----- Return
 26762     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26763     return $v_result;
 26764   }
 26765   // --------------------------------------------------------------------------------
 26766 
 26767   // --------------------------------------------------------------------------------
 26768   // Function : privAddList()
 26769   // Description :
 26770   //   $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
 26771   //   different from the real path of the file. This is usefull if you want to have PclTar
 26772   //   running in any directory, and memorize relative path from an other directory.
 26773   // Parameters :
 26774   //   $p_list : An array containing the file or directory names to add in the tar
 26775   //   $p_result_list : list of added files with their properties (specially the status field)
 26776   //   $p_add_dir : Path to add in the filename path archived
 26777   //   $p_remove_dir : Path to remove in the filename path archived
 26778   // Return Values :
 26779   // --------------------------------------------------------------------------------
 26780 //  function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
 26781   function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
 26782   {
 26783     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list");
 26784     $v_result=1;
 26785 
 26786     // ----- Add the files
 26787     $v_header_list = array();
 26788     if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
 26789     {
 26790       // ----- Return
 26791       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26792       return $v_result;
 26793     }
 26794 
 26795     // ----- Store the offset of the central dir
 26796     $v_offset = @ftell($this->zip_fd);
 26797 
 26798     // ----- Create the Central Dir files header
 26799     for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
 26800     {
 26801       // ----- Create the file header
 26802       if ($v_header_list[$i]['status'] == 'ok') {
 26803         if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
 26804           // ----- Return
 26805           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26806           return $v_result;
 26807         }
 26808         $v_count++;
 26809       }
 26810 
 26811       // ----- Transform the header to a 'usable' info
 26812       $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
 26813     }
 26814 
 26815     // ----- Zip file comment
 26816     $v_comment = '';
 26817     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
 26818       $v_comment = $p_options[PCLZIP_OPT_COMMENT];
 26819     }
 26820 
 26821     // ----- Calculate the size of the central header
 26822     $v_size = @ftell($this->zip_fd)-$v_offset;
 26823 
 26824     // ----- Create the central dir footer
 26825     if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
 26826     {
 26827       // ----- Reset the file list
 26828       unset($v_header_list);
 26829 
 26830       // ----- Return
 26831       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26832       return $v_result;
 26833     }
 26834 
 26835     // ----- Return
 26836     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26837     return $v_result;
 26838   }
 26839   // --------------------------------------------------------------------------------
 26840 
 26841   // --------------------------------------------------------------------------------
 26842   // Function : privAddFileList()
 26843   // Description :
 26844   // Parameters :
 26845   //   $p_filedescr_list : An array containing the file description
 26846   //                      or directory names to add in the zip
 26847   //   $p_result_list : list of added files with their properties (specially the status field)
 26848   // Return Values :
 26849   // --------------------------------------------------------------------------------
 26850   function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
 26851   {
 26852     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list");
 26853     $v_result=1;
 26854     $v_header = array();
 26855 
 26856     // ----- Recuperate the current number of elt in list
 26857     $v_nb = sizeof($p_result_list);
 26858     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements");
 26859 
 26860     // ----- Loop on the files
 26861     for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
 26862       // ----- Format the filename
 26863       $p_filedescr_list[$j]['filename']
 26864       = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
 26865 
 26866       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'");
 26867 
 26868       // ----- Skip empty file names
 26869       // TBC : Can this be possible ? not checked in DescrParseAtt ?
 26870       if ($p_filedescr_list[$j]['filename'] == "") {
 26871         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");
 26872         continue;
 26873       }
 26874 
 26875       // ----- Check the filename
 26876       if (!file_exists($p_filedescr_list[$j]['filename'])) {
 26877         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exists");
 26878         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists");
 26879         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26880         return PclZip::errorCode();
 26881       }
 26882 
 26883       // ----- Look if it is a file or a dir with no all path remove option
 26884       if (   (is_file($p_filedescr_list[$j]['filename']))
 26885           || (   is_dir($p_filedescr_list[$j]['filename'])
 26886               && (   !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
 26887                   || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
 26888 
 26889         // ----- Add the file
 26890         $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
 26891                                        $p_options);
 26892         if ($v_result != 1) {
 26893           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26894           return $v_result;
 26895         }
 26896 
 26897         // ----- Store the file infos
 26898         $p_result_list[$v_nb++] = $v_header;
 26899       }
 26900     }
 26901     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements");
 26902 
 26903     // ----- Return
 26904     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 26905     return $v_result;
 26906   }
 26907   // --------------------------------------------------------------------------------
 26908 
 26909   // --------------------------------------------------------------------------------
 26910   // Function : privAddFile()
 26911   // Description :
 26912   // Parameters :
 26913   // Return Values :
 26914   // --------------------------------------------------------------------------------
 26915   function privAddFile($p_filedescr, &$p_header, &$p_options)
 26916   {
 26917     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'");
 26918     $v_result=1;
 26919 
 26920     // ----- Working variable
 26921     $p_filename = $p_filedescr['filename'];
 26922 
 26923     // TBC : Already done in the fileAtt check ... ?
 26924     if ($p_filename == "") {
 26925       // ----- Error log
 26926       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
 26927 
 26928       // ----- Return
 26929       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 26930       return PclZip::errorCode();
 26931     }
 26932 
 26933     // ----- Look for a stored different filename
 26934     if (isset($p_filedescr['stored_filename'])) {
 26935       $v_stored_filename = $p_filedescr['stored_filename'];
 26936       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"');
 26937     }
 26938     else {
 26939       $v_stored_filename = $p_filedescr['stored_filename'];
 26940       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same');
 26941     }
 26942 
 26943     // ----- Set the file properties
 26944     clearstatcache();
 26945     $p_header['version'] = 20;
 26946     $p_header['version_extracted'] = 10;
 26947     $p_header['flag'] = 0;
 26948     $p_header['compression'] = 0;
 26949     $p_header['mtime'] = filemtime($p_filename);
 26950     $p_header['crc'] = 0;
 26951     $p_header['compressed_size'] = 0;
 26952     $p_header['size'] = filesize($p_filename);
 26953     $p_header['filename_len'] = strlen($p_filename);
 26954     $p_header['extra_len'] = 0;
 26955     $p_header['comment_len'] = 0;
 26956     $p_header['disk'] = 0;
 26957     $p_header['internal'] = 0;
 26958 //    $p_header['external'] = (is_file($p_filename)?0xFE49FFE0:0x41FF0010);
 26959     $p_header['external'] = (is_file($p_filename)?0x00000000:0x00000010);
 26960     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'");
 26961     $p_header['offset'] = 0;
 26962     $p_header['filename'] = $p_filename;
 26963     $p_header['stored_filename'] = $v_stored_filename;
 26964     $p_header['extra'] = '';
 26965     $p_header['comment'] = '';
 26966     $p_header['status'] = 'ok';
 26967     $p_header['index'] = -1;
 26968 
 26969     // ----- Look for pre-add callback
 26970     if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
 26971       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction");
 26972 
 26973       // ----- Generate a local information
 26974       $v_local_header = array();
 26975       $this->privConvertHeader2FileInfo($p_header, $v_local_header);
 26976 
 26977       // ----- Call the callback
 26978       // Here I do not use call_user_func() because I need to send a reference to the
 26979       // header.
 26980       eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
 26981       if ($v_result == 0) {
 26982         // ----- Change the file status
 26983         $p_header['status'] = "skipped";
 26984         $v_result = 1;
 26985       }
 26986 
 26987       // ----- Update the informations
 26988       // Only some fields can be modified
 26989       if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
 26990         $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
 26991         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'");
 26992       }
 26993     }
 26994 
 26995     // ----- Look for empty stored filename
 26996     if ($p_header['stored_filename'] == "") {
 26997       $p_header['status'] = "filtered";
 26998     }
 26999 
 27000     // ----- Check the path length
 27001     if (strlen($p_header['stored_filename']) > 0xFF) {
 27002       $p_header['status'] = 'filename_too_long';
 27003     }
 27004 
 27005     // ----- Look if no error, or file not skipped
 27006     if ($p_header['status'] == 'ok') {
 27007 
 27008       // ----- Look for a file
 27009       if (is_file($p_filename))
 27010       {
 27011         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");
 27012         // ----- Open the source file
 27013         if (($v_file = @fopen($p_filename, "rb")) == 0) {
 27014           PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
 27015           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 27016           return PclZip::errorCode();
 27017         }
 27018 
 27019         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
 27020           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");
 27021           // ----- Read the file content
 27022           $v_content_compressed = @fread($v_file, $p_header['size']);
 27023 
 27024           // ----- Calculate the CRC
 27025           $p_header['crc'] = @crc32($v_content_compressed);
 27026 
 27027           // ----- Set header parameters
 27028           $p_header['compressed_size'] = $p_header['size'];
 27029           $p_header['compression'] = 0;
 27030         }
 27031         else {
 27032           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");
 27033           // ----- Read the file content
 27034           $v_content = @fread($v_file, $p_header['size']);
 27035 
 27036           // ----- Calculate the CRC
 27037           $p_header['crc'] = @crc32($v_content);
 27038 
 27039           // ----- Compress the file
 27040           $v_content_compressed = @gzdeflate($v_content);
 27041 
 27042           // ----- Set header parameters
 27043           $p_header['compressed_size'] = strlen($v_content_compressed);
 27044           $p_header['compression'] = 8;
 27045         }
 27046 
 27047         // ----- Look for encryption
 27048         /*
 27049         if ((isset($p_options[PCLZIP_OPT_CRYPT]))
 27050 		    && ($p_options[PCLZIP_OPT_CRYPT] != "")) {
 27051           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ....");
 27052 
 27053           // Should be a random header
 27054           $v_header = 'xxxxxxxxxxxx';
 27055 	      $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,
 27056 		                                           $p_header['compressed_size'],
 27057 	                                               $v_header,
 27058 												   $p_header['crc'],
 27059 												   "test");
 27060 
 27061           $p_header['compressed_size'] += 12;
 27062           $p_header['flag'] = 1;
 27063 
 27064           // ----- Add the header to the data
 27065           $v_content_compressed = $v_header.$v_content_compressed;
 27066           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed)."");
 27067         }
 27068         */
 27069 
 27070         // ----- Call the header generation
 27071         if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
 27072           @fclose($v_file);
 27073           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27074           return $v_result;
 27075         }
 27076 
 27077         // ----- Write the compressed (or not) content
 27078         @fwrite($this->zip_fd,
 27079 		            $v_content_compressed, $p_header['compressed_size']);
 27080 
 27081         // ----- Close the file
 27082         @fclose($v_file);
 27083       }
 27084 
 27085       // ----- Look for a directory
 27086       else {
 27087         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder");
 27088         // ----- Look for directory last '/'
 27089         if (@substr($p_header['stored_filename'], -1) != '/') {
 27090           $p_header['stored_filename'] .= '/';
 27091         }
 27092 
 27093         // ----- Set the file properties
 27094         $p_header['size'] = 0;
 27095         //$p_header['external'] = 0x41FF0010;   // Value for a folder : to be checked
 27096         $p_header['external'] = 0x00000010;   // Value for a folder : to be checked
 27097 
 27098         // ----- Call the header generation
 27099         if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
 27100         {
 27101           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27102           return $v_result;
 27103         }
 27104       }
 27105     }
 27106 
 27107     // ----- Look for post-add callback
 27108     if (isset($p_options[PCLZIP_CB_POST_ADD])) {
 27109       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction");
 27110 
 27111       // ----- Generate a local information
 27112       $v_local_header = array();
 27113       $this->privConvertHeader2FileInfo($p_header, $v_local_header);
 27114 
 27115       // ----- Call the callback
 27116       // Here I do not use call_user_func() because I need to send a reference to the
 27117       // header.
 27118       eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
 27119       if ($v_result == 0) {
 27120         // ----- Ignored
 27121         $v_result = 1;
 27122       }
 27123 
 27124       // ----- Update the informations
 27125       // Nothing can be modified
 27126     }
 27127 
 27128     // ----- Return
 27129     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27130     return $v_result;
 27131   }
 27132   // --------------------------------------------------------------------------------
 27133 
 27134   // --------------------------------------------------------------------------------
 27135   // Function : privCalculateStoredFilename()
 27136   // Description :
 27137   //   Based on file descriptor properties and global options, this method
 27138   //   calculate the filename that will be stored in the archive.
 27139   // Parameters :
 27140   // Return Values :
 27141   // --------------------------------------------------------------------------------
 27142   function privCalculateStoredFilename(&$p_filedescr, &$p_options)
 27143   {
 27144     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'");
 27145     $v_result=1;
 27146 
 27147     // ----- Working variables
 27148     $p_filename = $p_filedescr['filename'];
 27149     if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
 27150       $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
 27151     }
 27152     else {
 27153       $p_add_dir = '';
 27154     }
 27155     if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
 27156       $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
 27157     }
 27158     else {
 27159       $p_remove_dir = '';
 27160     }
 27161     if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 27162       $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 27163     }
 27164     else {
 27165       $p_remove_all_dir = 0;
 27166     }
 27167 
 27168     // ----- Look for full name change
 27169     if (isset($p_filedescr['new_full_name'])) {
 27170       $v_stored_filename = $p_filedescr['new_full_name'];
 27171       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'");
 27172     }
 27173 
 27174     // ----- Look for path and/or short name change
 27175     else {
 27176 
 27177       // ----- Look for short name change
 27178       if (isset($p_filedescr['new_short_name'])) {
 27179         $v_path_info = pathinfo($p_filename);
 27180         $v_dir = '';
 27181         if ($v_path_info['dirname'] != '') {
 27182           $v_dir = $v_path_info['dirname'].'/';
 27183         }
 27184         $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
 27185         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'");
 27186       }
 27187       else {
 27188         // ----- Calculate the stored filename
 27189         $v_stored_filename = $p_filename;
 27190       }
 27191 
 27192       // ----- Look for all path to remove
 27193       if ($p_remove_all_dir) {
 27194         $v_stored_filename = basename($p_filename);
 27195         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'");
 27196       }
 27197       // ----- Look for partial path remove
 27198       else if ($p_remove_dir != "") {
 27199         if (substr($p_remove_dir, -1) != '/')
 27200           $p_remove_dir .= "/";
 27201 
 27202         if (   (substr($p_filename, 0, 2) == "./")
 27203             || (substr($p_remove_dir, 0, 2) == "./")) {
 27204 
 27205           if (   (substr($p_filename, 0, 2) == "./")
 27206               && (substr($p_remove_dir, 0, 2) != "./")) {
 27207             $p_remove_dir = "./".$p_remove_dir;
 27208           }
 27209           if (   (substr($p_filename, 0, 2) != "./")
 27210               && (substr($p_remove_dir, 0, 2) == "./")) {
 27211             $p_remove_dir = substr($p_remove_dir, 2);
 27212           }
 27213         }
 27214 
 27215         $v_compare = PclZipUtilPathInclusion($p_remove_dir,
 27216                                              $v_stored_filename);
 27217         if ($v_compare > 0) {
 27218           if ($v_compare == 2) {
 27219             $v_stored_filename = "";
 27220             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder");
 27221           }
 27222           else {
 27223             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'");
 27224             $v_stored_filename = substr($v_stored_filename,
 27225                                         strlen($p_remove_dir));
 27226             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'");
 27227           }
 27228         }
 27229       }
 27230       // ----- Look for path to add
 27231       if ($p_add_dir != "") {
 27232         if (substr($p_add_dir, -1) == "/")
 27233           $v_stored_filename = $p_add_dir.$v_stored_filename;
 27234         else
 27235           $v_stored_filename = $p_add_dir."/".$v_stored_filename;
 27236         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'");
 27237       }
 27238     }
 27239 
 27240     // ----- Filename (reduce the path of stored name)
 27241     $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
 27242     $p_filedescr['stored_filename'] = $v_stored_filename;
 27243     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename']));
 27244 
 27245     // ----- Return
 27246     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27247     return $v_result;
 27248   }
 27249   // --------------------------------------------------------------------------------
 27250 
 27251   // --------------------------------------------------------------------------------
 27252   // Function : privWriteFileHeader()
 27253   // Description :
 27254   // Parameters :
 27255   // Return Values :
 27256   // --------------------------------------------------------------------------------
 27257   function privWriteFileHeader(&$p_header)
 27258   {
 27259     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');
 27260     $v_result=1;
 27261 
 27262     // ----- Store the offset position of the file
 27263     $p_header['offset'] = ftell($this->zip_fd);
 27264     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']);
 27265 
 27266     // ----- Transform UNIX mtime to DOS format mdate/mtime
 27267     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
 27268     $v_date = getdate($p_header['mtime']);
 27269     $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
 27270     $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
 27271 
 27272     // ----- Packed data
 27273     $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
 27274 	                      $p_header['version_extracted'], $p_header['flag'],
 27275                           $p_header['compression'], $v_mtime, $v_mdate,
 27276                           $p_header['crc'], $p_header['compressed_size'],
 27277 						  $p_header['size'],
 27278                           strlen($p_header['stored_filename']),
 27279 						  $p_header['extra_len']);
 27280 
 27281     // ----- Write the first 148 bytes of the header in the archive
 27282     fputs($this->zip_fd, $v_binary_data, 30);
 27283 
 27284     // ----- Write the variable fields
 27285     if (strlen($p_header['stored_filename']) != 0)
 27286     {
 27287       fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
 27288     }
 27289     if ($p_header['extra_len'] != 0)
 27290     {
 27291       fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
 27292     }
 27293 
 27294     // ----- Return
 27295     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27296     return $v_result;
 27297   }
 27298   // --------------------------------------------------------------------------------
 27299 
 27300   // --------------------------------------------------------------------------------
 27301   // Function : privWriteCentralFileHeader()
 27302   // Description :
 27303   // Parameters :
 27304   // Return Values :
 27305   // --------------------------------------------------------------------------------
 27306   function privWriteCentralFileHeader(&$p_header)
 27307   {
 27308     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');
 27309     $v_result=1;
 27310 
 27311     // TBC
 27312     //for(reset($p_header); $key = key($p_header); next($p_header)) {
 27313     //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]);
 27314     //}
 27315 
 27316     // ----- Transform UNIX mtime to DOS format mdate/mtime
 27317     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
 27318     $v_date = getdate($p_header['mtime']);
 27319     $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
 27320     $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
 27321 
 27322     // ----- Packed data
 27323     $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
 27324 	                      $p_header['version'], $p_header['version_extracted'],
 27325                           $p_header['flag'], $p_header['compression'],
 27326 						  $v_mtime, $v_mdate, $p_header['crc'],
 27327                           $p_header['compressed_size'], $p_header['size'],
 27328                           strlen($p_header['stored_filename']),
 27329 						  $p_header['extra_len'], $p_header['comment_len'],
 27330                           $p_header['disk'], $p_header['internal'],
 27331 						  $p_header['external'], $p_header['offset']);
 27332 
 27333     // ----- Write the 42 bytes of the header in the zip file
 27334     fputs($this->zip_fd, $v_binary_data, 46);
 27335 
 27336     // ----- Write the variable fields
 27337     if (strlen($p_header['stored_filename']) != 0)
 27338     {
 27339       fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
 27340     }
 27341     if ($p_header['extra_len'] != 0)
 27342     {
 27343       fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
 27344     }
 27345     if ($p_header['comment_len'] != 0)
 27346     {
 27347       fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
 27348     }
 27349 
 27350     // ----- Return
 27351     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27352     return $v_result;
 27353   }
 27354   // --------------------------------------------------------------------------------
 27355 
 27356   // --------------------------------------------------------------------------------
 27357   // Function : privWriteCentralHeader()
 27358   // Description :
 27359   // Parameters :
 27360   // Return Values :
 27361   // --------------------------------------------------------------------------------
 27362   function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
 27363   {
 27364     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"');
 27365     $v_result=1;
 27366 
 27367     // ----- Packed data
 27368     $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
 27369 	                      $p_nb_entries, $p_size,
 27370 						  $p_offset, strlen($p_comment));
 27371 
 27372     // ----- Write the 22 bytes of the header in the zip file
 27373     fputs($this->zip_fd, $v_binary_data, 22);
 27374 
 27375     // ----- Write the variable fields
 27376     if (strlen($p_comment) != 0)
 27377     {
 27378       fputs($this->zip_fd, $p_comment, strlen($p_comment));
 27379     }
 27380 
 27381     // ----- Return
 27382     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27383     return $v_result;
 27384   }
 27385   // --------------------------------------------------------------------------------
 27386 
 27387   // --------------------------------------------------------------------------------
 27388   // Function : privList()
 27389   // Description :
 27390   // Parameters :
 27391   // Return Values :
 27392   // --------------------------------------------------------------------------------
 27393   function privList(&$p_list)
 27394   {
 27395     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list");
 27396     $v_result=1;
 27397 
 27398     // ----- Magic quotes trick
 27399     $this->privDisableMagicQuotes();
 27400 
 27401     // ----- Open the zip file
 27402     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 27403     if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
 27404     {
 27405       // ----- Magic quotes trick
 27406       $this->privSwapBackMagicQuotes();
 27407 
 27408       // ----- Error log
 27409       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
 27410 
 27411       // ----- Return
 27412       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 27413       return PclZip::errorCode();
 27414     }
 27415 
 27416     // ----- Read the central directory informations
 27417     $v_central_dir = array();
 27418     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
 27419     {
 27420       $this->privSwapBackMagicQuotes();
 27421       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27422       return $v_result;
 27423     }
 27424 
 27425     // ----- Go to beginning of Central Dir
 27426     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'");
 27427     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
 27428     @rewind($this->zip_fd);
 27429     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
 27430     if (@fseek($this->zip_fd, $v_central_dir['offset']))
 27431     {
 27432       $this->privSwapBackMagicQuotes();
 27433 
 27434       // ----- Error log
 27435       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
 27436 
 27437       // ----- Return
 27438       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 27439       return PclZip::errorCode();
 27440     }
 27441     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
 27442 
 27443     // ----- Read each entry
 27444     for ($i=0; $i<$v_central_dir['entries']; $i++)
 27445     {
 27446       // ----- Read the file header
 27447       if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
 27448       {
 27449         $this->privSwapBackMagicQuotes();
 27450         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27451         return $v_result;
 27452       }
 27453       $v_header['index'] = $i;
 27454 
 27455       // ----- Get the only interesting attributes
 27456       $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
 27457       unset($v_header);
 27458     }
 27459 
 27460     // ----- Close the zip file
 27461     $this->privCloseFd();
 27462 
 27463     // ----- Magic quotes trick
 27464     $this->privSwapBackMagicQuotes();
 27465 
 27466     // ----- Return
 27467     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27468     return $v_result;
 27469   }
 27470   // --------------------------------------------------------------------------------
 27471 
 27472   // --------------------------------------------------------------------------------
 27473   // Function : privConvertHeader2FileInfo()
 27474   // Description :
 27475   //   This function takes the file informations from the central directory
 27476   //   entries and extract the interesting parameters that will be given back.
 27477   //   The resulting file infos are set in the array $p_info
 27478   //     $p_info['filename'] : Filename with full path. Given by user (add),
 27479   //                           extracted in the filesystem (extract).
 27480   //     $p_info['stored_filename'] : Stored filename in the archive.
 27481   //     $p_info['size'] = Size of the file.
 27482   //     $p_info['compressed_size'] = Compressed size of the file.
 27483   //     $p_info['mtime'] = Last modification date of the file.
 27484   //     $p_info['comment'] = Comment associated with the file.
 27485   //     $p_info['folder'] = true/false : indicates if the entry is a folder or not.
 27486   //     $p_info['status'] = status of the action on the file.
 27487   // Parameters :
 27488   // Return Values :
 27489   // --------------------------------------------------------------------------------
 27490   function privConvertHeader2FileInfo($p_header, &$p_info)
 27491   {
 27492     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'");
 27493     $v_result=1;
 27494 
 27495     // ----- Get the interesting attributes
 27496     $p_info['filename'] = $p_header['filename'];
 27497     $p_info['stored_filename'] = $p_header['stored_filename'];
 27498     $p_info['size'] = $p_header['size'];
 27499     $p_info['compressed_size'] = $p_header['compressed_size'];
 27500     $p_info['mtime'] = $p_header['mtime'];
 27501     $p_info['comment'] = $p_header['comment'];
 27502     $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
 27503     $p_info['index'] = $p_header['index'];
 27504     $p_info['status'] = $p_header['status'];
 27505 
 27506     // ----- Return
 27507     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27508     return $v_result;
 27509   }
 27510   // --------------------------------------------------------------------------------
 27511 
 27512   // --------------------------------------------------------------------------------
 27513   // Function : privExtractByRule()
 27514   // Description :
 27515   //   Extract a file or directory depending of rules (by index, by name, ...)
 27516   // Parameters :
 27517   //   $p_file_list : An array where will be placed the properties of each
 27518   //                  extracted file
 27519   //   $p_path : Path to add while writing the extracted files
 27520   //   $p_remove_path : Path to remove (from the file memorized path) while writing the
 27521   //                    extracted files. If the path does not match the file path,
 27522   //                    the file is extracted with its memorized path.
 27523   //                    $p_remove_path does not apply to 'list' mode.
 27524   //                    $p_path and $p_remove_path are commulative.
 27525   // Return Values :
 27526   //   1 on success,0 or less on error (see error code list)
 27527   // --------------------------------------------------------------------------------
 27528   function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
 27529   {
 27530     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");
 27531     $v_result=1;
 27532 
 27533     // ----- Magic quotes trick
 27534     $this->privDisableMagicQuotes();
 27535 
 27536     // ----- Check the path
 27537     if (   ($p_path == "")
 27538 	    || (   (substr($p_path, 0, 1) != "/")
 27539 		    && (substr($p_path, 0, 3) != "../")
 27540 			&& (substr($p_path,1,2)!=":/")))
 27541       $p_path = "./".$p_path;
 27542 
 27543     // ----- Reduce the path last (and duplicated) '/'
 27544     if (($p_path != "./") && ($p_path != "/"))
 27545     {
 27546       // ----- Look for the path end '/'
 27547       while (substr($p_path, -1) == "/")
 27548       {
 27549         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");
 27550         $p_path = substr($p_path, 0, strlen($p_path)-1);
 27551         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");
 27552       }
 27553     }
 27554 
 27555     // ----- Look for path to remove format (should end by /)
 27556     if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
 27557     {
 27558       $p_remove_path .= '/';
 27559     }
 27560     $p_remove_path_size = strlen($p_remove_path);
 27561 
 27562     // ----- Open the zip file
 27563     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 27564     if (($v_result = $this->privOpenFd('rb')) != 1)
 27565     {
 27566       $this->privSwapBackMagicQuotes();
 27567       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27568       return $v_result;
 27569     }
 27570 
 27571     // ----- Read the central directory informations
 27572     $v_central_dir = array();
 27573     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
 27574     {
 27575       // ----- Close the zip file
 27576       $this->privCloseFd();
 27577       $this->privSwapBackMagicQuotes();
 27578 
 27579       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27580       return $v_result;
 27581     }
 27582 
 27583     // ----- Start at beginning of Central Dir
 27584     $v_pos_entry = $v_central_dir['offset'];
 27585 
 27586     // ----- Read each entry
 27587     $j_start = 0;
 27588     for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
 27589     {
 27590       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'");
 27591 
 27592       // ----- Read next Central dir entry
 27593       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'");
 27594       @rewind($this->zip_fd);
 27595       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'");
 27596       if (@fseek($this->zip_fd, $v_pos_entry))
 27597       {
 27598         // ----- Close the zip file
 27599         $this->privCloseFd();
 27600         $this->privSwapBackMagicQuotes();
 27601 
 27602         // ----- Error log
 27603         PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
 27604 
 27605         // ----- Return
 27606         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 27607         return PclZip::errorCode();
 27608       }
 27609       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'");
 27610 
 27611       // ----- Read the file header
 27612       $v_header = array();
 27613       if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
 27614       {
 27615         // ----- Close the zip file
 27616         $this->privCloseFd();
 27617         $this->privSwapBackMagicQuotes();
 27618 
 27619         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27620         return $v_result;
 27621       }
 27622 
 27623       // ----- Store the index
 27624       $v_header['index'] = $i;
 27625 
 27626       // ----- Store the file position
 27627       $v_pos_entry = ftell($this->zip_fd);
 27628 
 27629       // ----- Look for the specific extract rules
 27630       $v_extract = false;
 27631 
 27632       // ----- Look for extract by name rule
 27633       if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
 27634           && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
 27635           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");
 27636 
 27637           // ----- Look if the filename is in the list
 27638           for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
 27639               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");
 27640 
 27641               // ----- Look for a directory
 27642               if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
 27643                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");
 27644 
 27645                   // ----- Look if the directory is in the filename path
 27646                   if (   (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
 27647                       && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
 27648                       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");
 27649                       $v_extract = true;
 27650                   }
 27651               }
 27652               // ----- Look for a filename
 27653               elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
 27654                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");
 27655                   $v_extract = true;
 27656               }
 27657           }
 27658       }
 27659 
 27660       // ----- Look for extract by ereg rule
 27661       else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))
 27662                && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
 27663           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");
 27664 
 27665           if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
 27666               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
 27667               $v_extract = true;
 27668           }
 27669       }
 27670 
 27671       // ----- Look for extract by preg rule
 27672       else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
 27673                && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
 27674           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");
 27675 
 27676           if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
 27677               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
 27678               $v_extract = true;
 27679           }
 27680       }
 27681 
 27682       // ----- Look for extract by index rule
 27683       else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
 27684                && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
 27685           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");
 27686 
 27687           // ----- Look if the index is in the list
 27688           for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
 27689               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");
 27690 
 27691               if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
 27692                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");
 27693                   $v_extract = true;
 27694               }
 27695               if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
 27696                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");
 27697                   $j_start = $j+1;
 27698               }
 27699 
 27700               if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
 27701                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");
 27702                   break;
 27703               }
 27704           }
 27705       }
 27706 
 27707       // ----- Look for no rule, which means extract all the archive
 27708       else {
 27709           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)");
 27710           $v_extract = true;
 27711       }
 27712 
 27713 	  // ----- Check compression method
 27714 	  if (   ($v_extract)
 27715 	      && (   ($v_header['compression'] != 8)
 27716 		      && ($v_header['compression'] != 0))) {
 27717           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")");
 27718           $v_header['status'] = 'unsupported_compression';
 27719 
 27720           // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
 27721           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
 27722 		      && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
 27723               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
 27724 
 27725               $this->privSwapBackMagicQuotes();
 27726 
 27727               PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
 27728 			                       "Filename '".$v_header['stored_filename']."' is "
 27729 				  	    	  	   ."compressed by an unsupported compression "
 27730 				  	    	  	   ."method (".$v_header['compression'].") ");
 27731 
 27732               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 27733               return PclZip::errorCode();
 27734 		  }
 27735 	  }
 27736 
 27737 	  // ----- Check encrypted files
 27738 	  if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
 27739           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption");
 27740           $v_header['status'] = 'unsupported_encryption';
 27741 
 27742           // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
 27743           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
 27744 		      && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
 27745               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
 27746 
 27747               $this->privSwapBackMagicQuotes();
 27748 
 27749               PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
 27750 			                       "Unsupported encryption for "
 27751 				  	    	  	   ." filename '".$v_header['stored_filename']
 27752 								   ."'");
 27753 
 27754               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 27755               return PclZip::errorCode();
 27756 		  }
 27757     }
 27758 
 27759       // ----- Look for real extraction
 27760       if (($v_extract) && ($v_header['status'] != 'ok')) {
 27761           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract");
 27762           $v_result = $this->privConvertHeader2FileInfo($v_header,
 27763 		                                        $p_file_list[$v_nb_extracted++]);
 27764           if ($v_result != 1) {
 27765               $this->privCloseFd();
 27766               $this->privSwapBackMagicQuotes();
 27767               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27768               return $v_result;
 27769           }
 27770 
 27771           $v_extract = false;
 27772       }
 27773 
 27774       // ----- Look for real extraction
 27775       if ($v_extract)
 27776       {
 27777         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'");
 27778 
 27779         // ----- Go to the file position
 27780         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
 27781         @rewind($this->zip_fd);
 27782         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
 27783         if (@fseek($this->zip_fd, $v_header['offset']))
 27784         {
 27785           // ----- Close the zip file
 27786           $this->privCloseFd();
 27787 
 27788           $this->privSwapBackMagicQuotes();
 27789 
 27790           // ----- Error log
 27791           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
 27792 
 27793           // ----- Return
 27794           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 27795           return PclZip::errorCode();
 27796         }
 27797         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
 27798 
 27799         // ----- Look for extraction as string
 27800         if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
 27801 
 27802           // ----- Extracting the file
 27803           $v_result1 = $this->privExtractFileAsString($v_header, $v_string);
 27804           if ($v_result1 < 1) {
 27805             $this->privCloseFd();
 27806             $this->privSwapBackMagicQuotes();
 27807             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
 27808             return $v_result1;
 27809           }
 27810 
 27811           // ----- Get the only interesting attributes
 27812           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
 27813           {
 27814             // ----- Close the zip file
 27815             $this->privCloseFd();
 27816             $this->privSwapBackMagicQuotes();
 27817 
 27818             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27819             return $v_result;
 27820           }
 27821 
 27822           // ----- Set the file content
 27823           $p_file_list[$v_nb_extracted]['content'] = $v_string;
 27824 
 27825           // ----- Next extracted file
 27826           $v_nb_extracted++;
 27827 
 27828           // ----- Look for user callback abort
 27829           if ($v_result1 == 2) {
 27830           	break;
 27831           }
 27832         }
 27833         // ----- Look for extraction in standard output
 27834         elseif (   (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
 27835 		        && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
 27836           // ----- Extracting the file in standard output
 27837           $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
 27838           if ($v_result1 < 1) {
 27839             $this->privCloseFd();
 27840             $this->privSwapBackMagicQuotes();
 27841             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
 27842             return $v_result1;
 27843           }
 27844 
 27845           // ----- Get the only interesting attributes
 27846           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
 27847             $this->privCloseFd();
 27848             $this->privSwapBackMagicQuotes();
 27849             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27850             return $v_result;
 27851           }
 27852 
 27853           // ----- Look for user callback abort
 27854           if ($v_result1 == 2) {
 27855           	break;
 27856           }
 27857         }
 27858         // ----- Look for normal extraction
 27859         else {
 27860           // ----- Extracting the file
 27861           $v_result1 = $this->privExtractFile($v_header,
 27862 		                                      $p_path, $p_remove_path,
 27863 											  $p_remove_all_path,
 27864 											  $p_options);
 27865           if ($v_result1 < 1) {
 27866             $this->privCloseFd();
 27867             $this->privSwapBackMagicQuotes();
 27868             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
 27869             return $v_result1;
 27870           }
 27871 
 27872           // ----- Get the only interesting attributes
 27873           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
 27874           {
 27875             // ----- Close the zip file
 27876             $this->privCloseFd();
 27877             $this->privSwapBackMagicQuotes();
 27878 
 27879             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27880             return $v_result;
 27881           }
 27882 
 27883           // ----- Look for user callback abort
 27884           if ($v_result1 == 2) {
 27885           	break;
 27886           }
 27887         }
 27888       }
 27889     }
 27890 
 27891     // ----- Close the zip file
 27892     $this->privCloseFd();
 27893     $this->privSwapBackMagicQuotes();
 27894 
 27895     // ----- Return
 27896     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27897     return $v_result;
 27898   }
 27899   // --------------------------------------------------------------------------------
 27900 
 27901   // --------------------------------------------------------------------------------
 27902   // Function : privExtractFile()
 27903   // Description :
 27904   // Parameters :
 27905   // Return Values :
 27906   //
 27907   // 1 : ... ?
 27908   // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
 27909   // --------------------------------------------------------------------------------
 27910   function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
 27911   {
 27912     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");
 27913     $v_result=1;
 27914 
 27915     // ----- Read the file header
 27916     if (($v_result = $this->privReadFileHeader($v_header)) != 1)
 27917     {
 27918       // ----- Return
 27919       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27920       return $v_result;
 27921     }
 27922 
 27923     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
 27924 
 27925     // ----- Check that the file header is coherent with $p_entry info
 27926     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
 27927         // TBC
 27928     }
 27929 
 27930     // ----- Look for all path to remove
 27931     if ($p_remove_all_path == true) {
 27932         // ----- Look for folder entry that not need to be extracted
 27933         if (($p_entry['external']&0x00000010)==0x00000010) {
 27934             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered");
 27935 
 27936             $p_entry['status'] = "filtered";
 27937 
 27938             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27939             return $v_result;
 27940         }
 27941 
 27942         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed");
 27943         // ----- Get the basename of the path
 27944         $p_entry['filename'] = basename($p_entry['filename']);
 27945     }
 27946 
 27947     // ----- Look for path to remove
 27948     else if ($p_remove_path != "")
 27949     {
 27950       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove");
 27951       if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
 27952       {
 27953         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'");
 27954 
 27955         // ----- Change the file status
 27956         $p_entry['status'] = "filtered";
 27957 
 27958         // ----- Return
 27959         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 27960         return $v_result;
 27961       }
 27962 
 27963       $p_remove_path_size = strlen($p_remove_path);
 27964       if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
 27965       {
 27966         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'");
 27967 
 27968         // ----- Remove the path
 27969         $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
 27970 
 27971         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'");
 27972       }
 27973     }
 27974 
 27975     // ----- Add the path
 27976     if ($p_path != '') {
 27977       $p_entry['filename'] = $p_path."/".$p_entry['filename'];
 27978     }
 27979 
 27980     // ----- Check a base_dir_restriction
 27981     if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
 27982       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction");
 27983       $v_inclusion
 27984       = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
 27985                                 $p_entry['filename']);
 27986       if ($v_inclusion == 0) {
 27987         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction");
 27988 
 27989         PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
 27990 			                     "Filename '".$p_entry['filename']."' is "
 27991 								 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
 27992 
 27993         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 27994         return PclZip::errorCode();
 27995       }
 27996     }
 27997 
 27998     // ----- Look for pre-extract callback
 27999     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
 28000       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");
 28001 
 28002       // ----- Generate a local information
 28003       $v_local_header = array();
 28004       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
 28005 
 28006       // ----- Call the callback
 28007       // Here I do not use call_user_func() because I need to send a reference to the
 28008       // header.
 28009       eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
 28010       if ($v_result == 0) {
 28011         // ----- Change the file status
 28012         $p_entry['status'] = "skipped";
 28013         $v_result = 1;
 28014       }
 28015 
 28016       // ----- Look for abort result
 28017       if ($v_result == 2) {
 28018         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
 28019         // ----- This status is internal and will be changed in 'skipped'
 28020         $p_entry['status'] = "aborted";
 28021       	$v_result = PCLZIP_ERR_USER_ABORTED;
 28022       }
 28023 
 28024       // ----- Update the informations
 28025       // Only some fields can be modified
 28026       $p_entry['filename'] = $v_local_header['filename'];
 28027       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");
 28028     }
 28029 
 28030     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");
 28031 
 28032     // ----- Look if extraction should be done
 28033     if ($p_entry['status'] == 'ok') {
 28034 
 28035     // ----- Look for specific actions while the file exist
 28036     if (file_exists($p_entry['filename']))
 28037     {
 28038       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists");
 28039 
 28040       // ----- Look if file is a directory
 28041       if (is_dir($p_entry['filename']))
 28042       {
 28043         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory");
 28044 
 28045         // ----- Change the file status
 28046         $p_entry['status'] = "already_a_directory";
 28047 
 28048         // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
 28049         // For historical reason first PclZip implementation does not stop
 28050         // when this kind of error occurs.
 28051         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
 28052 		    && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
 28053             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
 28054 
 28055             PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
 28056 			                     "Filename '".$p_entry['filename']."' is "
 28057 								 ."already used by an existing directory");
 28058 
 28059             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28060             return PclZip::errorCode();
 28061 		}
 28062       }
 28063       // ----- Look if file is write protected
 28064       else if (!is_writeable($p_entry['filename']))
 28065       {
 28066         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected");
 28067 
 28068         // ----- Change the file status
 28069         $p_entry['status'] = "write_protected";
 28070 
 28071         // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
 28072         // For historical reason first PclZip implementation does not stop
 28073         // when this kind of error occurs.
 28074         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
 28075 		    && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
 28076             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
 28077 
 28078             PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
 28079 			                     "Filename '".$p_entry['filename']."' exists "
 28080 								 ."and is write protected");
 28081 
 28082             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28083             return PclZip::errorCode();
 28084 		}
 28085       }
 28086 
 28087       // ----- Look if the extracted file is older
 28088       else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
 28089       {
 28090         //--(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']).")");
 28091         // ----- Change the file status
 28092         if (   (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
 28093 		    && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
 28094             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced");
 28095 		}
 28096 		else {
 28097             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced");
 28098             $p_entry['status'] = "newer_exist";
 28099 
 28100             // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
 28101             // For historical reason first PclZip implementation does not stop
 28102             // when this kind of error occurs.
 28103             if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
 28104 		        && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
 28105                 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
 28106 
 28107                 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
 28108 			             "Newer version of '".$p_entry['filename']."' exists "
 28109 					    ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
 28110 
 28111                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28112                 return PclZip::errorCode();
 28113 		    }
 28114 		}
 28115       }
 28116       else {
 28117         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is older than the extrated one - will be replaced by the extracted one (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")");
 28118       }
 28119     }
 28120 
 28121     // ----- Check the directory availability and create it if necessary
 28122     else {
 28123       if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
 28124         $v_dir_to_check = $p_entry['filename'];
 28125       else if (!strstr($p_entry['filename'], "/"))
 28126         $v_dir_to_check = "";
 28127       else
 28128         $v_dir_to_check = dirname($p_entry['filename']);
 28129 
 28130       if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
 28131         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'");
 28132 
 28133         // ----- Change the file status
 28134         $p_entry['status'] = "path_creation_fail";
 28135 
 28136         // ----- Return
 28137         ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28138         //return $v_result;
 28139         $v_result = 1;
 28140       }
 28141     }
 28142     }
 28143 
 28144     // ----- Look if extraction should be done
 28145     if ($p_entry['status'] == 'ok') {
 28146 
 28147       // ----- Do the extraction (if not a folder)
 28148       if (!(($p_entry['external']&0x00000010)==0x00000010))
 28149       {
 28150         // ----- Look for not compressed file
 28151         if ($p_entry['compression'] == 0) {
 28152           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
 28153 
 28154 		  // ----- Opening destination file
 28155           if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
 28156           {
 28157             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode");
 28158 
 28159             // ----- Change the file status
 28160             $p_entry['status'] = "write_error";
 28161 
 28162             // ----- Return
 28163             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28164             return $v_result;
 28165           }
 28166 
 28167           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes");
 28168 
 28169           // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
 28170           $v_size = $p_entry['compressed_size'];
 28171           while ($v_size != 0)
 28172           {
 28173             $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
 28174             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes");
 28175             $v_buffer = @fread($this->zip_fd, $v_read_size);
 28176             /* Try to speed up the code
 28177             $v_binary_data = pack('a'.$v_read_size, $v_buffer);
 28178             @fwrite($v_dest_file, $v_binary_data, $v_read_size);
 28179             */
 28180             @fwrite($v_dest_file, $v_buffer, $v_read_size);
 28181             $v_size -= $v_read_size;
 28182           }
 28183 
 28184           // ----- Closing the destination file
 28185           fclose($v_dest_file);
 28186 
 28187           // ----- Change the file mtime
 28188           touch($p_entry['filename'], $p_entry['mtime']);
 28189 
 28190 
 28191         }
 28192         else {
 28193           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")");
 28194           // ----- TBC
 28195           // Need to be finished
 28196           if (($p_entry['flag'] & 1) == 1) {
 28197               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted");
 28198             /*
 28199               // ----- Read the encryption header
 28200               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes");
 28201               $v_encryption_header = @fread($this->zip_fd, 12);
 28202 
 28203               // ----- Read the encrypted & compressed file in a buffer
 28204               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes");
 28205               $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12);
 28206 
 28207               // ----- Decrypt the buffer
 28208               $this->privDecrypt($v_encryption_header, $v_buffer,
 28209 			                     $p_entry['compressed_size']-12, $p_entry['crc']);
 28210               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'");
 28211               */
 28212           }
 28213           else {
 28214               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes");
 28215               // ----- Read the compressed file in a buffer (one shot)
 28216               $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
 28217           }
 28218 
 28219           // ----- Decompress the file
 28220           $v_file_content = @gzinflate($v_buffer);
 28221           unset($v_buffer);
 28222           if ($v_file_content === FALSE) {
 28223             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file");
 28224 
 28225             // ----- Change the file status
 28226             // TBC
 28227             $p_entry['status'] = "error";
 28228 
 28229             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28230             return $v_result;
 28231           }
 28232 
 28233           // ----- Opening destination file
 28234           if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
 28235             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode");
 28236 
 28237             // ----- Change the file status
 28238             $p_entry['status'] = "write_error";
 28239 
 28240             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28241             return $v_result;
 28242           }
 28243 
 28244           // ----- Write the uncompressed data
 28245           @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
 28246           unset($v_file_content);
 28247 
 28248           // ----- Closing the destination file
 28249           @fclose($v_dest_file);
 28250 
 28251           // ----- Change the file mtime
 28252           @touch($p_entry['filename'], $p_entry['mtime']);
 28253         }
 28254 
 28255         // ----- Look for chmod option
 28256         if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
 28257           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'");
 28258 
 28259           // ----- Change the mode of the file
 28260           @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
 28261         }
 28262 
 28263         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
 28264       }
 28265     }
 28266 
 28267 	// ----- Change abort status
 28268 	if ($p_entry['status'] == "aborted") {
 28269       $p_entry['status'] = "skipped";
 28270 	}
 28271 
 28272     // ----- Look for post-extract callback
 28273     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
 28274       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");
 28275 
 28276       // ----- Generate a local information
 28277       $v_local_header = array();
 28278       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
 28279 
 28280       // ----- Call the callback
 28281       // Here I do not use call_user_func() because I need to send a reference to the
 28282       // header.
 28283       eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
 28284 
 28285       // ----- Look for abort result
 28286       if ($v_result == 2) {
 28287         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
 28288       	$v_result = PCLZIP_ERR_USER_ABORTED;
 28289       }
 28290     }
 28291 
 28292     // ----- Return
 28293     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28294     return $v_result;
 28295   }
 28296   // --------------------------------------------------------------------------------
 28297 
 28298   // --------------------------------------------------------------------------------
 28299   // Function : privExtractFileInOutput()
 28300   // Description :
 28301   // Parameters :
 28302   // Return Values :
 28303   // --------------------------------------------------------------------------------
 28304   function privExtractFileInOutput(&$p_entry, &$p_options)
 28305   {
 28306     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', "");
 28307     $v_result=1;
 28308 
 28309     // ----- Read the file header
 28310     if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
 28311       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28312       return $v_result;
 28313     }
 28314 
 28315     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
 28316 
 28317     // ----- Check that the file header is coherent with $p_entry info
 28318     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
 28319         // TBC
 28320     }
 28321 
 28322     // ----- Look for pre-extract callback
 28323     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
 28324       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");
 28325 
 28326       // ----- Generate a local information
 28327       $v_local_header = array();
 28328       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
 28329 
 28330       // ----- Call the callback
 28331       // Here I do not use call_user_func() because I need to send a reference to the
 28332       // header.
 28333       eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
 28334       if ($v_result == 0) {
 28335         // ----- Change the file status
 28336         $p_entry['status'] = "skipped";
 28337         $v_result = 1;
 28338       }
 28339 
 28340       // ----- Look for abort result
 28341       if ($v_result == 2) {
 28342         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
 28343         // ----- This status is internal and will be changed in 'skipped'
 28344         $p_entry['status'] = "aborted";
 28345       	$v_result = PCLZIP_ERR_USER_ABORTED;
 28346       }
 28347 
 28348       // ----- Update the informations
 28349       // Only some fields can be modified
 28350       $p_entry['filename'] = $v_local_header['filename'];
 28351       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");
 28352     }
 28353 
 28354     // ----- Trace
 28355     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");
 28356 
 28357     // ----- Look if extraction should be done
 28358     if ($p_entry['status'] == 'ok') {
 28359 
 28360       // ----- Do the extraction (if not a folder)
 28361       if (!(($p_entry['external']&0x00000010)==0x00000010)) {
 28362         // ----- Look for not compressed file
 28363         if ($p_entry['compressed_size'] == $p_entry['size']) {
 28364           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
 28365           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");
 28366 
 28367           // ----- Read the file in a buffer (one shot)
 28368           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
 28369 
 28370           // ----- Send the file to the output
 28371           echo $v_buffer;
 28372           unset($v_buffer);
 28373         }
 28374         else {
 28375           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file");
 28376           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes");
 28377 
 28378           // ----- Read the compressed file in a buffer (one shot)
 28379           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
 28380 
 28381           // ----- Decompress the file
 28382           $v_file_content = gzinflate($v_buffer);
 28383           unset($v_buffer);
 28384 
 28385           // ----- Send the file to the output
 28386           echo $v_file_content;
 28387           unset($v_file_content);
 28388         }
 28389         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
 28390       }
 28391     }
 28392 
 28393 	// ----- Change abort status
 28394 	if ($p_entry['status'] == "aborted") {
 28395       $p_entry['status'] = "skipped";
 28396 	}
 28397 
 28398     // ----- Look for post-extract callback
 28399     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
 28400       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");
 28401 
 28402       // ----- Generate a local information
 28403       $v_local_header = array();
 28404       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
 28405 
 28406       // ----- Call the callback
 28407       // Here I do not use call_user_func() because I need to send a reference to the
 28408       // header.
 28409       eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
 28410 
 28411       // ----- Look for abort result
 28412       if ($v_result == 2) {
 28413         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
 28414       	$v_result = PCLZIP_ERR_USER_ABORTED;
 28415       }
 28416     }
 28417 
 28418     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28419     return $v_result;
 28420   }
 28421   // --------------------------------------------------------------------------------
 28422 
 28423   // --------------------------------------------------------------------------------
 28424   // Function : privExtractFileAsString()
 28425   // Description :
 28426   // Parameters :
 28427   // Return Values :
 28428   // --------------------------------------------------------------------------------
 28429   function privExtractFileAsString(&$p_entry, &$p_string)
 28430   {
 28431     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'");
 28432     $v_result=1;
 28433 
 28434     // ----- Read the file header
 28435     $v_header = array();
 28436     if (($v_result = $this->privReadFileHeader($v_header)) != 1)
 28437     {
 28438       // ----- Return
 28439       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28440       return $v_result;
 28441     }
 28442 
 28443     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
 28444 
 28445     // ----- Check that the file header is coherent with $p_entry info
 28446     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
 28447         // TBC
 28448     }
 28449 
 28450     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'");
 28451 
 28452     // ----- Do the extraction (if not a folder)
 28453     if (!(($p_entry['external']&0x00000010)==0x00000010))
 28454     {
 28455       // ----- Look for not compressed file
 28456 //      if ($p_entry['compressed_size'] == $p_entry['size'])
 28457       if ($p_entry['compression'] == 0) {
 28458         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
 28459         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");
 28460 
 28461         // ----- Reading the file
 28462         $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
 28463       }
 28464       else {
 28465         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')");
 28466 
 28467         // ----- Reading the file
 28468         $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
 28469 
 28470         // ----- Decompress the file
 28471         if (($p_string = @gzinflate($v_data)) === FALSE) {
 28472             // TBC
 28473         }
 28474       }
 28475 
 28476       // ----- Trace
 28477       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
 28478     }
 28479     else {
 28480         // TBC : error : can not extract a folder in a string
 28481     }
 28482 
 28483     // ----- Return
 28484     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28485     return $v_result;
 28486   }
 28487   // --------------------------------------------------------------------------------
 28488 
 28489   // --------------------------------------------------------------------------------
 28490   // Function : privReadFileHeader()
 28491   // Description :
 28492   // Parameters :
 28493   // Return Values :
 28494   // --------------------------------------------------------------------------------
 28495   function privReadFileHeader(&$p_header)
 28496   {
 28497     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", "");
 28498     $v_result=1;
 28499 
 28500     // ----- Read the 4 bytes signature
 28501     $v_binary_data = @fread($this->zip_fd, 4);
 28502     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
 28503     $v_data = unpack('Vid', $v_binary_data);
 28504     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
 28505 
 28506     // ----- Check signature
 28507     if ($v_data['id'] != 0x04034b50)
 28508     {
 28509       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header");
 28510 
 28511       // ----- Error log
 28512       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
 28513 
 28514       // ----- Return
 28515       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28516       return PclZip::errorCode();
 28517     }
 28518 
 28519     // ----- Read the first 42 bytes of the header
 28520     $v_binary_data = fread($this->zip_fd, 26);
 28521 
 28522     // ----- Look for invalid block size
 28523     if (strlen($v_binary_data) != 26)
 28524     {
 28525       $p_header['filename'] = "";
 28526       $p_header['status'] = "invalid_header";
 28527       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));
 28528 
 28529       // ----- Error log
 28530       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
 28531 
 28532       // ----- Return
 28533       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28534       return PclZip::errorCode();
 28535     }
 28536 
 28537     // ----- Extract the values
 28538     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'");
 28539     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'");
 28540     $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
 28541 
 28542     // ----- Get filename
 28543     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']);
 28544     $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
 28545     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\'');
 28546 
 28547     // ----- Get extra_fields
 28548     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']);
 28549     if ($v_data['extra_len'] != 0) {
 28550       $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
 28551     }
 28552     else {
 28553       $p_header['extra'] = '';
 28554     }
 28555     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\'');
 28556 
 28557     // ----- Extract properties
 28558     $p_header['version_extracted'] = $v_data['version'];
 28559     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\'');
 28560     $p_header['compression'] = $v_data['compression'];
 28561     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\'');
 28562     $p_header['size'] = $v_data['size'];
 28563     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\'');
 28564     $p_header['compressed_size'] = $v_data['compressed_size'];
 28565     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\'');
 28566     $p_header['crc'] = $v_data['crc'];
 28567     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\'');
 28568     $p_header['flag'] = $v_data['flag'];
 28569     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\'');
 28570     $p_header['filename_len'] = $v_data['filename_len'];
 28571     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\'');
 28572 
 28573     // ----- Recuperate date in UNIX format
 28574     $p_header['mdate'] = $v_data['mdate'];
 28575     $p_header['mtime'] = $v_data['mtime'];
 28576     if ($p_header['mdate'] && $p_header['mtime'])
 28577     {
 28578       // ----- Extract time
 28579       $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
 28580       $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
 28581       $v_seconde = ($p_header['mtime'] & 0x001F)*2;
 28582 
 28583       // ----- Extract date
 28584       $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
 28585       $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
 28586       $v_day = $p_header['mdate'] & 0x001F;
 28587 
 28588       // ----- Get UNIX date format
 28589       $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
 28590 
 28591       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
 28592     }
 28593     else
 28594     {
 28595       $p_header['mtime'] = time();
 28596       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
 28597     }
 28598 
 28599     // TBC
 28600     //for(reset($v_data); $key = key($v_data); next($v_data)) {
 28601     //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]);
 28602     //}
 28603 
 28604     // ----- Set the stored filename
 28605     $p_header['stored_filename'] = $p_header['filename'];
 28606 
 28607     // ----- Set the status field
 28608     $p_header['status'] = "ok";
 28609 
 28610     // ----- Return
 28611     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28612     return $v_result;
 28613   }
 28614   // --------------------------------------------------------------------------------
 28615 
 28616   // --------------------------------------------------------------------------------
 28617   // Function : privReadCentralFileHeader()
 28618   // Description :
 28619   // Parameters :
 28620   // Return Values :
 28621   // --------------------------------------------------------------------------------
 28622   function privReadCentralFileHeader(&$p_header)
 28623   {
 28624     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", "");
 28625     $v_result=1;
 28626 
 28627     // ----- Read the 4 bytes signature
 28628     $v_binary_data = @fread($this->zip_fd, 4);
 28629     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
 28630     $v_data = unpack('Vid', $v_binary_data);
 28631     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
 28632 
 28633     // ----- Check signature
 28634     if ($v_data['id'] != 0x02014b50)
 28635     {
 28636       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature");
 28637 
 28638       // ----- Error log
 28639       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
 28640 
 28641       // ----- Return
 28642       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28643       return PclZip::errorCode();
 28644     }
 28645 
 28646     // ----- Read the first 42 bytes of the header
 28647     $v_binary_data = fread($this->zip_fd, 42);
 28648 
 28649     // ----- Look for invalid block size
 28650     if (strlen($v_binary_data) != 42)
 28651     {
 28652       $p_header['filename'] = "";
 28653       $p_header['status'] = "invalid_header";
 28654       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));
 28655 
 28656       // ----- Error log
 28657       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
 28658 
 28659       // ----- Return
 28660       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28661       return PclZip::errorCode();
 28662     }
 28663 
 28664     // ----- Extract the values
 28665     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'");
 28666     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'");
 28667     $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);
 28668 
 28669     // ----- Get filename
 28670     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']);
 28671     if ($p_header['filename_len'] != 0)
 28672       $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
 28673     else
 28674       $p_header['filename'] = '';
 28675     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\'');
 28676 
 28677     // ----- Get extra
 28678     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']);
 28679     if ($p_header['extra_len'] != 0)
 28680       $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
 28681     else
 28682       $p_header['extra'] = '';
 28683     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\'');
 28684 
 28685     // ----- Get comment
 28686     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']);
 28687     if ($p_header['comment_len'] != 0)
 28688       $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
 28689     else
 28690       $p_header['comment'] = '';
 28691     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\'');
 28692 
 28693     // ----- Extract properties
 28694     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\'');
 28695     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\'');
 28696     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\'');
 28697     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\'');
 28698     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\'');
 28699     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\'');
 28700     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\'');
 28701 
 28702     // ----- Recuperate date in UNIX format
 28703     if ($p_header['mdate'] && $p_header['mtime'])
 28704     {
 28705       // ----- Extract time
 28706       $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
 28707       $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
 28708       $v_seconde = ($p_header['mtime'] & 0x001F)*2;
 28709 
 28710       // ----- Extract date
 28711       $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
 28712       $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
 28713       $v_day = $p_header['mdate'] & 0x001F;
 28714 
 28715       // ----- Get UNIX date format
 28716       $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
 28717 
 28718       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
 28719     }
 28720     else
 28721     {
 28722       $p_header['mtime'] = time();
 28723       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
 28724     }
 28725 
 28726     // ----- Set the stored filename
 28727     $p_header['stored_filename'] = $p_header['filename'];
 28728 
 28729     // ----- Set default status to ok
 28730     $p_header['status'] = 'ok';
 28731 
 28732     // ----- Look if it is a directory
 28733     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'");
 28734     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "External (Hex) : '".sprintf("Ox%04X", $p_header['external'])."' (".(($p_header['external']&0x00000010)==0x00000010?'is a folder':'is a file').')');
 28735     if (substr($p_header['filename'], -1) == '/') {
 28736       //$p_header['external'] = 0x41FF0010;
 28737       $p_header['external'] = 0x00000010;
 28738       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\'');
 28739     }
 28740 
 28741     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\'');
 28742 
 28743     // ----- Return
 28744     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28745     return $v_result;
 28746   }
 28747   // --------------------------------------------------------------------------------
 28748 
 28749   // --------------------------------------------------------------------------------
 28750   // Function : privCheckFileHeaders()
 28751   // Description :
 28752   // Parameters :
 28753   // Return Values :
 28754   //   1 on success,
 28755   //   0 on error;
 28756   // --------------------------------------------------------------------------------
 28757   function privCheckFileHeaders(&$p_local_header, &$p_central_header)
 28758   {
 28759     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", "");
 28760     $v_result=1;
 28761 
 28762 	// ----- Check the static values
 28763 	// TBC
 28764 	if ($p_local_header['filename'] != $p_central_header['filename']) {
 28765         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed');
 28766 	}
 28767 	if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
 28768         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed');
 28769 	}
 28770 	if ($p_local_header['flag'] != $p_central_header['flag']) {
 28771         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed');
 28772 	}
 28773 	if ($p_local_header['compression'] != $p_central_header['compression']) {
 28774         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed');
 28775 	}
 28776 	if ($p_local_header['mtime'] != $p_central_header['mtime']) {
 28777         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed');
 28778 	}
 28779 	if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
 28780         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed');
 28781 	}
 28782 
 28783 	// ----- Look for flag bit 3
 28784 	if (($p_local_header['flag'] & 8) == 8) {
 28785         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !');
 28786         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header');
 28787         $p_local_header['size'] = $p_central_header['size'];
 28788         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\'');
 28789         $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
 28790         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\'');
 28791         $p_local_header['crc'] = $p_central_header['crc'];
 28792         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\'');
 28793 	}
 28794 
 28795     // ----- Return
 28796     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28797     return $v_result;
 28798   }
 28799   // --------------------------------------------------------------------------------
 28800 
 28801   // --------------------------------------------------------------------------------
 28802   // Function : privReadEndCentralDir()
 28803   // Description :
 28804   // Parameters :
 28805   // Return Values :
 28806   // --------------------------------------------------------------------------------
 28807   function privReadEndCentralDir(&$p_central_dir)
 28808   {
 28809     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", "");
 28810     $v_result=1;
 28811 
 28812     // ----- Go to the end of the zip file
 28813     $v_size = filesize($this->zipname);
 28814     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size");
 28815     @fseek($this->zip_fd, $v_size);
 28816     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\'');
 28817     if (@ftell($this->zip_fd) != $v_size)
 28818     {
 28819       // ----- Error log
 28820       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
 28821 
 28822       // ----- Return
 28823       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28824       return PclZip::errorCode();
 28825     }
 28826 
 28827     // ----- First try : look if this is an archive with no commentaries (most of the time)
 28828     // in this case the end of central dir is at 22 bytes of the file end
 28829     $v_found = 0;
 28830     if ($v_size > 26) {
 28831       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment');
 28832       @fseek($this->zip_fd, $v_size-22);
 28833       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\'');
 28834       if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
 28835       {
 28836         // ----- Error log
 28837         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
 28838 
 28839         // ----- Return
 28840         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28841         return PclZip::errorCode();
 28842       }
 28843 
 28844       // ----- Read for bytes
 28845       $v_binary_data = @fread($this->zip_fd, 4);
 28846       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
 28847       $v_data = @unpack('Vid', $v_binary_data);
 28848       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
 28849 
 28850       // ----- Check signature
 28851       if ($v_data['id'] == 0x06054b50) {
 28852         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position.");
 28853         $v_found = 1;
 28854       }
 28855 
 28856       $v_pos = ftell($this->zip_fd);
 28857     }
 28858 
 28859     // ----- Go back to the maximum possible size of the Central Dir End Record
 28860     if (!$v_found) {
 28861       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir');
 28862       $v_maximum_size = 65557; // 0xFFFF + 22;
 28863       if ($v_maximum_size > $v_size)
 28864         $v_maximum_size = $v_size;
 28865       @fseek($this->zip_fd, $v_size-$v_maximum_size);
 28866       if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
 28867       {
 28868         // ----- Error log
 28869         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
 28870 
 28871         // ----- Return
 28872         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28873         return PclZip::errorCode();
 28874       }
 28875       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\'');
 28876 
 28877       // ----- Read byte per byte in order to find the signature
 28878       $v_pos = ftell($this->zip_fd);
 28879       $v_bytes = 0x00000000;
 28880       while ($v_pos < $v_size)
 28881       {
 28882         // ----- Read a byte
 28883         $v_byte = @fread($this->zip_fd, 1);
 28884 
 28885         // -----  Add the byte
 28886         // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
 28887         // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
 28888         $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
 28889 
 28890         // ----- Compare the bytes
 28891         if ($v_bytes == 0x504b0506)
 28892         {
 28893           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\'');
 28894           $v_pos++;
 28895           break;
 28896         }
 28897 
 28898         $v_pos++;
 28899       }
 28900 
 28901       // ----- Look if not found end of central dir
 28902       if ($v_pos == $v_size)
 28903       {
 28904         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature");
 28905 
 28906         // ----- Error log
 28907         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
 28908 
 28909         // ----- Return
 28910         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28911         return PclZip::errorCode();
 28912       }
 28913     }
 28914 
 28915     // ----- Read the first 18 bytes of the header
 28916     $v_binary_data = fread($this->zip_fd, 18);
 28917 
 28918     // ----- Look for invalid block size
 28919     if (strlen($v_binary_data) != 18)
 28920     {
 28921       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
 28922 
 28923       // ----- Error log
 28924       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
 28925 
 28926       // ----- Return
 28927       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28928       return PclZip::errorCode();
 28929     }
 28930 
 28931     // ----- Extract the values
 28932     ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'");
 28933     ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'");
 28934     $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
 28935 
 28936     // ----- Check the global size
 28937     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']);
 28938     if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
 28939       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive.");
 28940 
 28941 	  // ----- Removed in release 2.2 see readme file
 28942 	  // The check of the file size is a little too strict.
 28943 	  // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
 28944 	  // While decrypted, zip has training 0 bytes
 28945 	  if (0) {
 28946       // ----- Error log
 28947       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
 28948 	                       'The central dir is not at the end of the archive.'
 28949 						   .' Some trailing bytes exists after the archive.');
 28950 
 28951       // ----- Return
 28952       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 28953       return PclZip::errorCode();
 28954 	  }
 28955     }
 28956 
 28957     // ----- Get comment
 28958     if ($v_data['comment_size'] != 0)
 28959       $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
 28960     else
 28961       $p_central_dir['comment'] = '';
 28962     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\'');
 28963 
 28964     $p_central_dir['entries'] = $v_data['entries'];
 28965     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\'');
 28966     $p_central_dir['disk_entries'] = $v_data['disk_entries'];
 28967     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\'');
 28968     $p_central_dir['offset'] = $v_data['offset'];
 28969     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\'');
 28970     $p_central_dir['size'] = $v_data['size'];
 28971     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\'');
 28972     $p_central_dir['disk'] = $v_data['disk'];
 28973     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\'');
 28974     $p_central_dir['disk_start'] = $v_data['disk_start'];
 28975     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\'');
 28976 
 28977     // TBC
 28978     //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
 28979     //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]);
 28980     //}
 28981 
 28982     // ----- Return
 28983     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 28984     return $v_result;
 28985   }
 28986   // --------------------------------------------------------------------------------
 28987 
 28988   // --------------------------------------------------------------------------------
 28989   // Function : privDeleteByRule()
 28990   // Description :
 28991   // Parameters :
 28992   // Return Values :
 28993   // --------------------------------------------------------------------------------
 28994   function privDeleteByRule(&$p_result_list, &$p_options)
 28995   {
 28996     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", "");
 28997     $v_result=1;
 28998     $v_list_detail = array();
 28999 
 29000     // ----- Open the zip file
 29001     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 29002     if (($v_result=$this->privOpenFd('rb')) != 1)
 29003     {
 29004       // ----- Return
 29005       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29006       return $v_result;
 29007     }
 29008 
 29009     // ----- Read the central directory informations
 29010     $v_central_dir = array();
 29011     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
 29012     {
 29013       $this->privCloseFd();
 29014       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29015       return $v_result;
 29016     }
 29017 
 29018     // ----- Go to beginning of File
 29019     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
 29020     @rewind($this->zip_fd);
 29021     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
 29022 
 29023     // ----- Scan all the files
 29024     // ----- Start at beginning of Central Dir
 29025     $v_pos_entry = $v_central_dir['offset'];
 29026     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
 29027     @rewind($this->zip_fd);
 29028     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
 29029     if (@fseek($this->zip_fd, $v_pos_entry))
 29030     {
 29031       // ----- Close the zip file
 29032       $this->privCloseFd();
 29033 
 29034       // ----- Error log
 29035       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
 29036 
 29037       // ----- Return
 29038       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 29039       return PclZip::errorCode();
 29040     }
 29041     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
 29042 
 29043     // ----- Read each entry
 29044     $v_header_list = array();
 29045     $j_start = 0;
 29046     for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
 29047     {
 29048       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')");
 29049 
 29050       // ----- Read the file header
 29051       $v_header_list[$v_nb_extracted] = array();
 29052       if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
 29053       {
 29054         // ----- Close the zip file
 29055         $this->privCloseFd();
 29056 
 29057         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29058         return $v_result;
 29059       }
 29060 
 29061       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'");
 29062 
 29063       // ----- Store the index
 29064       $v_header_list[$v_nb_extracted]['index'] = $i;
 29065 
 29066       // ----- Look for the specific extract rules
 29067       $v_found = false;
 29068 
 29069       // ----- Look for extract by name rule
 29070       if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
 29071           && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
 29072           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");
 29073 
 29074           // ----- Look if the filename is in the list
 29075           for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
 29076               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");
 29077 
 29078               // ----- Look for a directory
 29079               if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
 29080                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");
 29081 
 29082                   // ----- Look if the directory is in the filename path
 29083                   if (   (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
 29084                       && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
 29085                       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");
 29086                       $v_found = true;
 29087                   }
 29088                   elseif (   (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
 29089                           && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
 29090                       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory");
 29091                       $v_found = true;
 29092                   }
 29093               }
 29094               // ----- Look for a filename
 29095               elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
 29096                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");
 29097                   $v_found = true;
 29098               }
 29099           }
 29100       }
 29101 
 29102       // ----- Look for extract by ereg rule
 29103       else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))
 29104                && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
 29105           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");
 29106 
 29107           if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
 29108               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
 29109               $v_found = true;
 29110           }
 29111       }
 29112 
 29113       // ----- Look for extract by preg rule
 29114       else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
 29115                && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
 29116           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");
 29117 
 29118           if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
 29119               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
 29120               $v_found = true;
 29121           }
 29122       }
 29123 
 29124       // ----- Look for extract by index rule
 29125       else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
 29126                && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
 29127           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");
 29128 
 29129           // ----- Look if the index is in the list
 29130           for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
 29131               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");
 29132 
 29133               if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
 29134                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");
 29135                   $v_found = true;
 29136               }
 29137               if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
 29138                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");
 29139                   $j_start = $j+1;
 29140               }
 29141 
 29142               if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
 29143                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");
 29144                   break;
 29145               }
 29146           }
 29147       }
 29148       else {
 29149         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file");
 29150       	$v_found = true;
 29151       }
 29152 
 29153       // ----- Look for deletion
 29154       if ($v_found)
 29155       {
 29156         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted");
 29157         unset($v_header_list[$v_nb_extracted]);
 29158       }
 29159       else
 29160       {
 29161         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted");
 29162         $v_nb_extracted++;
 29163       }
 29164     }
 29165 
 29166     // ----- Look if something need to be deleted
 29167     if ($v_nb_extracted > 0) {
 29168 
 29169         // ----- Creates a temporay file
 29170         $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
 29171 
 29172         // ----- Creates a temporary zip archive
 29173         $v_temp_zip = new PclZip($v_zip_temp_name);
 29174 
 29175         // ----- Open the temporary zip file in write mode
 29176         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode");
 29177         if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
 29178             $this->privCloseFd();
 29179 
 29180             // ----- Return
 29181             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29182             return $v_result;
 29183         }
 29184 
 29185         // ----- Look which file need to be kept
 29186         for ($i=0; $i<sizeof($v_header_list); $i++) {
 29187             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'");
 29188 
 29189             // ----- Calculate the position of the header
 29190             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'");
 29191             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
 29192             @rewind($this->zip_fd);
 29193             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
 29194             if (@fseek($this->zip_fd,  $v_header_list[$i]['offset'])) {
 29195                 // ----- Close the zip file
 29196                 $this->privCloseFd();
 29197                 $v_temp_zip->privCloseFd();
 29198                 @unlink($v_zip_temp_name);
 29199 
 29200                 // ----- Error log
 29201                 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
 29202 
 29203                 // ----- Return
 29204                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 29205                 return PclZip::errorCode();
 29206             }
 29207             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
 29208 
 29209             // ----- Read the file header
 29210             $v_local_header = array();
 29211             if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
 29212                 // ----- Close the zip file
 29213                 $this->privCloseFd();
 29214                 $v_temp_zip->privCloseFd();
 29215                 @unlink($v_zip_temp_name);
 29216 
 29217                 // ----- Return
 29218                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29219                 return $v_result;
 29220             }
 29221 
 29222             // ----- Check that local file header is same as central file header
 29223             if ($this->privCheckFileHeaders($v_local_header,
 29224 			                                $v_header_list[$i]) != 1) {
 29225                 // TBC
 29226             }
 29227             unset($v_local_header);
 29228 
 29229             // ----- Write the file header
 29230             if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
 29231                 // ----- Close the zip file
 29232                 $this->privCloseFd();
 29233                 $v_temp_zip->privCloseFd();
 29234                 @unlink($v_zip_temp_name);
 29235 
 29236                 // ----- Return
 29237                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29238                 return $v_result;
 29239             }
 29240             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'");
 29241 
 29242             // ----- Read/write the data block
 29243             if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
 29244                 // ----- Close the zip file
 29245                 $this->privCloseFd();
 29246                 $v_temp_zip->privCloseFd();
 29247                 @unlink($v_zip_temp_name);
 29248 
 29249                 // ----- Return
 29250                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29251                 return $v_result;
 29252             }
 29253         }
 29254 
 29255         // ----- Store the offset of the central dir
 29256         $v_offset = @ftell($v_temp_zip->zip_fd);
 29257         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset");
 29258 
 29259         // ----- Re-Create the Central Dir files header
 29260         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory");
 29261         for ($i=0; $i<sizeof($v_header_list); $i++) {
 29262             // ----- Create the file header
 29263             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']);
 29264             if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
 29265                 $v_temp_zip->privCloseFd();
 29266                 $this->privCloseFd();
 29267                 @unlink($v_zip_temp_name);
 29268 
 29269                 // ----- Return
 29270                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29271                 return $v_result;
 29272             }
 29273 
 29274             // ----- Transform the header to a 'usable' info
 29275             $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
 29276         }
 29277 
 29278         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer");
 29279 
 29280         // ----- Zip file comment
 29281         $v_comment = '';
 29282         if (isset($p_options[PCLZIP_OPT_COMMENT])) {
 29283           $v_comment = $p_options[PCLZIP_OPT_COMMENT];
 29284         }
 29285 
 29286         // ----- Calculate the size of the central header
 29287         $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
 29288 
 29289         // ----- Create the central dir footer
 29290         if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
 29291             // ----- Reset the file list
 29292             unset($v_header_list);
 29293             $v_temp_zip->privCloseFd();
 29294             $this->privCloseFd();
 29295             @unlink($v_zip_temp_name);
 29296 
 29297             // ----- Return
 29298             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29299             return $v_result;
 29300         }
 29301 
 29302         // ----- Close
 29303         $v_temp_zip->privCloseFd();
 29304         $this->privCloseFd();
 29305 
 29306         // ----- Delete the zip file
 29307         // TBC : I should test the result ...
 29308         @unlink($this->zipname);
 29309 
 29310         // ----- Rename the temporary file
 29311         // TBC : I should test the result ...
 29312         //@rename($v_zip_temp_name, $this->zipname);
 29313         PclZipUtilRename($v_zip_temp_name, $this->zipname);
 29314 
 29315         // ----- Destroy the temporary archive
 29316         unset($v_temp_zip);
 29317     }
 29318 
 29319     // ----- Remove every files : reset the file
 29320     else if ($v_central_dir['entries'] != 0) {
 29321         $this->privCloseFd();
 29322 
 29323         if (($v_result = $this->privOpenFd('wb')) != 1) {
 29324           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29325           return $v_result;
 29326         }
 29327 
 29328         if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
 29329           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29330           return $v_result;
 29331         }
 29332 
 29333         $this->privCloseFd();
 29334     }
 29335 
 29336     // ----- Return
 29337     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29338     return $v_result;
 29339   }
 29340   // --------------------------------------------------------------------------------
 29341 
 29342   // --------------------------------------------------------------------------------
 29343   // Function : privDirCheck()
 29344   // Description :
 29345   //   Check if a directory exists, if not it creates it and all the parents directory
 29346   //   which may be useful.
 29347   // Parameters :
 29348   //   $p_dir : Directory path to check.
 29349   // Return Values :
 29350   //    1 : OK
 29351   //   -1 : Unable to create directory
 29352   // --------------------------------------------------------------------------------
 29353   function privDirCheck($p_dir, $p_is_dir=false)
 29354   {
 29355     $v_result = 1;
 29356 
 29357     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'");
 29358 
 29359     // ----- Remove the final '/'
 29360     if (($p_is_dir) && (substr($p_dir, -1)=='/'))
 29361     {
 29362       $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
 29363     }
 29364     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'");
 29365 
 29366     // ----- Check the directory availability
 29367     if ((is_dir($p_dir)) || ($p_dir == ""))
 29368     {
 29369       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory");
 29370       return 1;
 29371     }
 29372 
 29373     // ----- Extract parent directory
 29374     $p_parent_dir = dirname($p_dir);
 29375     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'");
 29376 
 29377     // ----- Just a check
 29378     if ($p_parent_dir != $p_dir)
 29379     {
 29380       // ----- Look for parent directory
 29381       if ($p_parent_dir != "")
 29382       {
 29383         if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
 29384         {
 29385           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29386           return $v_result;
 29387         }
 29388       }
 29389     }
 29390 
 29391     // ----- Create the directory
 29392     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'");
 29393     if (!@mkdir($p_dir, 0777))
 29394     {
 29395       // ----- Error log
 29396       PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
 29397 
 29398       // ----- Return
 29399       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 29400       return PclZip::errorCode();
 29401     }
 29402 
 29403     // ----- Return
 29404     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created");
 29405     return $v_result;
 29406   }
 29407   // --------------------------------------------------------------------------------
 29408 
 29409   // --------------------------------------------------------------------------------
 29410   // Function : privMerge()
 29411   // Description :
 29412   //   If $p_archive_to_add does not exist, the function exit with a success result.
 29413   // Parameters :
 29414   // Return Values :
 29415   // --------------------------------------------------------------------------------
 29416   function privMerge(&$p_archive_to_add)
 29417   {
 29418     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'");
 29419     $v_result=1;
 29420 
 29421     // ----- Look if the archive_to_add exists
 29422     if (!is_file($p_archive_to_add->zipname))
 29423     {
 29424       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge.");
 29425 
 29426       // ----- Nothing to merge, so merge is a success
 29427       $v_result = 1;
 29428 
 29429       // ----- Return
 29430       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29431       return $v_result;
 29432     }
 29433 
 29434     // ----- Look if the archive exists
 29435     if (!is_file($this->zipname))
 29436     {
 29437       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add.");
 29438 
 29439       // ----- Do a duplicate
 29440       $v_result = $this->privDuplicate($p_archive_to_add->zipname);
 29441 
 29442       // ----- Return
 29443       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29444       return $v_result;
 29445     }
 29446 
 29447     // ----- Open the zip file
 29448     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 29449     if (($v_result=$this->privOpenFd('rb')) != 1)
 29450     {
 29451       // ----- Return
 29452       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29453       return $v_result;
 29454     }
 29455 
 29456     // ----- Read the central directory informations
 29457     $v_central_dir = array();
 29458     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
 29459     {
 29460       $this->privCloseFd();
 29461       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29462       return $v_result;
 29463     }
 29464 
 29465     // ----- Go to beginning of File
 29466     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");
 29467     @rewind($this->zip_fd);
 29468     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");
 29469 
 29470     // ----- Open the archive_to_add file
 29471     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode");
 29472     if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
 29473     {
 29474       $this->privCloseFd();
 29475 
 29476       // ----- Return
 29477       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29478       return $v_result;
 29479     }
 29480 
 29481     // ----- Read the central directory informations
 29482     $v_central_dir_to_add = array();
 29483     if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
 29484     {
 29485       $this->privCloseFd();
 29486       $p_archive_to_add->privCloseFd();
 29487 
 29488       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29489       return $v_result;
 29490     }
 29491 
 29492     // ----- Go to beginning of File
 29493     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");
 29494     @rewind($p_archive_to_add->zip_fd);
 29495     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");
 29496 
 29497     // ----- Creates a temporay file
 29498     $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
 29499 
 29500     // ----- Open the temporary file in write mode
 29501     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 29502     if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
 29503     {
 29504       $this->privCloseFd();
 29505       $p_archive_to_add->privCloseFd();
 29506 
 29507       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
 29508 
 29509       // ----- Return
 29510       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 29511       return PclZip::errorCode();
 29512     }
 29513 
 29514     // ----- Copy the files from the archive to the temporary file
 29515     // TBC : Here I should better append the file and go back to erase the central dir
 29516     $v_size = $v_central_dir['offset'];
 29517     while ($v_size != 0)
 29518     {
 29519       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
 29520       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 29521       $v_buffer = fread($this->zip_fd, $v_read_size);
 29522       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
 29523       $v_size -= $v_read_size;
 29524     }
 29525 
 29526     // ----- Copy the files from the archive_to_add into the temporary file
 29527     $v_size = $v_central_dir_to_add['offset'];
 29528     while ($v_size != 0)
 29529     {
 29530       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
 29531       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 29532       $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
 29533       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
 29534       $v_size -= $v_read_size;
 29535     }
 29536 
 29537     // ----- Store the offset of the central dir
 29538     $v_offset = @ftell($v_zip_temp_fd);
 29539     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");
 29540 
 29541     // ----- Copy the block of file headers from the old archive
 29542     $v_size = $v_central_dir['size'];
 29543     while ($v_size != 0)
 29544     {
 29545       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
 29546       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 29547       $v_buffer = @fread($this->zip_fd, $v_read_size);
 29548       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
 29549       $v_size -= $v_read_size;
 29550     }
 29551 
 29552     // ----- Copy the block of file headers from the archive_to_add
 29553     $v_size = $v_central_dir_to_add['size'];
 29554     while ($v_size != 0)
 29555     {
 29556       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
 29557       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 29558       $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
 29559       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
 29560       $v_size -= $v_read_size;
 29561     }
 29562 
 29563     // ----- Merge the file comments
 29564     $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
 29565 
 29566     // ----- Calculate the size of the (new) central header
 29567     $v_size = @ftell($v_zip_temp_fd)-$v_offset;
 29568 
 29569     // ----- Swap the file descriptor
 29570     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
 29571     // the following methods on the temporary fil and not the real archive fd
 29572     $v_swap = $this->zip_fd;
 29573     $this->zip_fd = $v_zip_temp_fd;
 29574     $v_zip_temp_fd = $v_swap;
 29575 
 29576     // ----- Create the central dir footer
 29577     if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
 29578     {
 29579       $this->privCloseFd();
 29580       $p_archive_to_add->privCloseFd();
 29581       @fclose($v_zip_temp_fd);
 29582       $this->zip_fd = null;
 29583 
 29584       // ----- Reset the file list
 29585       unset($v_header_list);
 29586 
 29587       // ----- Return
 29588       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29589       return $v_result;
 29590     }
 29591 
 29592     // ----- Swap back the file descriptor
 29593     $v_swap = $this->zip_fd;
 29594     $this->zip_fd = $v_zip_temp_fd;
 29595     $v_zip_temp_fd = $v_swap;
 29596 
 29597     // ----- Close
 29598     $this->privCloseFd();
 29599     $p_archive_to_add->privCloseFd();
 29600 
 29601     // ----- Close the temporary file
 29602     @fclose($v_zip_temp_fd);
 29603 
 29604     // ----- Delete the zip file
 29605     // TBC : I should test the result ...
 29606     @unlink($this->zipname);
 29607 
 29608     // ----- Rename the temporary file
 29609     // TBC : I should test the result ...
 29610     //@rename($v_zip_temp_name, $this->zipname);
 29611     PclZipUtilRename($v_zip_temp_name, $this->zipname);
 29612 
 29613     // ----- Return
 29614     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29615     return $v_result;
 29616   }
 29617   // --------------------------------------------------------------------------------
 29618 
 29619   // --------------------------------------------------------------------------------
 29620   // Function : privDuplicate()
 29621   // Description :
 29622   // Parameters :
 29623   // Return Values :
 29624   // --------------------------------------------------------------------------------
 29625   function privDuplicate($p_archive_filename)
 29626   {
 29627     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'");
 29628     $v_result=1;
 29629 
 29630     // ----- Look if the $p_archive_filename exists
 29631     if (!is_file($p_archive_filename))
 29632     {
 29633       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate.");
 29634 
 29635       // ----- Nothing to duplicate, so duplicate is a success.
 29636       $v_result = 1;
 29637 
 29638       // ----- Return
 29639       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29640       return $v_result;
 29641     }
 29642 
 29643     // ----- Open the zip file
 29644     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 29645     if (($v_result=$this->privOpenFd('wb')) != 1)
 29646     {
 29647       // ----- Return
 29648       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29649       return $v_result;
 29650     }
 29651 
 29652     // ----- Open the temporary file in write mode
 29653     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
 29654     if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
 29655     {
 29656       $this->privCloseFd();
 29657 
 29658       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
 29659 
 29660       // ----- Return
 29661       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
 29662       return PclZip::errorCode();
 29663     }
 29664 
 29665     // ----- Copy the files from the archive to the temporary file
 29666     // TBC : Here I should better append the file and go back to erase the central dir
 29667     $v_size = filesize($p_archive_filename);
 29668     while ($v_size != 0)
 29669     {
 29670       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
 29671       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes");
 29672       $v_buffer = fread($v_zip_temp_fd, $v_read_size);
 29673       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
 29674       $v_size -= $v_read_size;
 29675     }
 29676 
 29677     // ----- Close
 29678     $this->privCloseFd();
 29679 
 29680     // ----- Close the temporary file
 29681     @fclose($v_zip_temp_fd);
 29682 
 29683     // ----- Return
 29684     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29685     return $v_result;
 29686   }
 29687   // --------------------------------------------------------------------------------
 29688 
 29689   // --------------------------------------------------------------------------------
 29690   // Function : privErrorLog()
 29691   // Description :
 29692   // Parameters :
 29693   // --------------------------------------------------------------------------------
 29694   function privErrorLog($p_error_code=0, $p_error_string='')
 29695   {
 29696     if (PCLZIP_ERROR_EXTERNAL == 1) {
 29697       PclError($p_error_code, $p_error_string);
 29698     }
 29699     else {
 29700       $this->error_code = $p_error_code;
 29701       $this->error_string = $p_error_string;
 29702     }
 29703   }
 29704   // --------------------------------------------------------------------------------
 29705 
 29706   // --------------------------------------------------------------------------------
 29707   // Function : privErrorReset()
 29708   // Description :
 29709   // Parameters :
 29710   // --------------------------------------------------------------------------------
 29711   function privErrorReset()
 29712   {
 29713     if (PCLZIP_ERROR_EXTERNAL == 1) {
 29714       PclErrorReset();
 29715     }
 29716     else {
 29717       $this->error_code = 0;
 29718       $this->error_string = '';
 29719     }
 29720   }
 29721   // --------------------------------------------------------------------------------
 29722 
 29723   // --------------------------------------------------------------------------------
 29724   // Function : privDecrypt()
 29725   // Description :
 29726   // Parameters :
 29727   // Return Values :
 29728   // --------------------------------------------------------------------------------
 29729   function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc)
 29730   {
 29731     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size."");
 29732     $v_result=1;
 29733 
 29734     // ----- To Be Modified ;-)
 29735     $v_pwd = "test";
 29736 
 29737     $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header,
 29738 	                                 $p_crc, $v_pwd);
 29739 
 29740     // ----- Return
 29741     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29742     return $v_result;
 29743   }
 29744   // --------------------------------------------------------------------------------
 29745 
 29746   // --------------------------------------------------------------------------------
 29747   // Function : privDisableMagicQuotes()
 29748   // Description :
 29749   // Parameters :
 29750   // Return Values :
 29751   // --------------------------------------------------------------------------------
 29752   function privDisableMagicQuotes()
 29753   {
 29754     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', "");
 29755     $v_result=1;
 29756 
 29757     // ----- Look if function exists
 29758     if (   (!function_exists("get_magic_quotes_runtime"))
 29759 	    || (!function_exists("set_magic_quotes_runtime"))) {
 29760       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");
 29761       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29762       return $v_result;
 29763 	}
 29764 
 29765     // ----- Look if already done
 29766     if ($this->magic_quotes_status != -1) {
 29767       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled");
 29768       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29769       return $v_result;
 29770 	}
 29771 
 29772 	// ----- Get and memorize the magic_quote value
 29773 	$this->magic_quotes_status = @get_magic_quotes_runtime();
 29774     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'");
 29775 
 29776 	// ----- Disable magic_quotes
 29777 	if ($this->magic_quotes_status == 1) {
 29778       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes");
 29779 	  @set_magic_quotes_runtime(0);
 29780 	}
 29781 
 29782     // ----- Return
 29783     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29784     return $v_result;
 29785   }
 29786   // --------------------------------------------------------------------------------
 29787 
 29788   // --------------------------------------------------------------------------------
 29789   // Function : privSwapBackMagicQuotes()
 29790   // Description :
 29791   // Parameters :
 29792   // Return Values :
 29793   // --------------------------------------------------------------------------------
 29794   function privSwapBackMagicQuotes()
 29795   {
 29796     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', "");
 29797     $v_result=1;
 29798 
 29799     // ----- Look if function exists
 29800     if (   (!function_exists("get_magic_quotes_runtime"))
 29801 	    || (!function_exists("set_magic_quotes_runtime"))) {
 29802       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");
 29803       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29804       return $v_result;
 29805 	}
 29806 
 29807     // ----- Look if something to do
 29808     if ($this->magic_quotes_status != -1) {
 29809       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified");
 29810       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29811       return $v_result;
 29812 	}
 29813 
 29814 	// ----- Swap back magic_quotes
 29815 	if ($this->magic_quotes_status == 1) {
 29816       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes");
 29817   	  @set_magic_quotes_runtime($this->magic_quotes_status);
 29818 	}
 29819 
 29820     // ----- Return
 29821     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29822     return $v_result;
 29823   }
 29824   // --------------------------------------------------------------------------------
 29825 
 29826   }
 29827   // End of class
 29828   // --------------------------------------------------------------------------------
 29829 
 29830   // --------------------------------------------------------------------------------
 29831   // Function : PclZipUtilPathReduction()
 29832   // Description :
 29833   // Parameters :
 29834   // Return Values :
 29835   // --------------------------------------------------------------------------------
 29836   function PclZipUtilPathReduction($p_dir)
 29837   {
 29838     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'");
 29839     $v_result = "";
 29840 
 29841     // ----- Look for not empty path
 29842     if ($p_dir != "") {
 29843       // ----- Explode path by directory names
 29844       $v_list = explode("/", $p_dir);
 29845 
 29846       // ----- Study directories from last to first
 29847       $v_skip = 0;
 29848       for ($i=sizeof($v_list)-1; $i>=0; $i--) {
 29849         // ----- Look for current path
 29850         if ($v_list[$i] == ".") {
 29851           // ----- Ignore this directory
 29852           // Should be the first $i=0, but no check is done
 29853         }
 29854         else if ($v_list[$i] == "..") {
 29855 		  $v_skip++;
 29856         }
 29857         else if ($v_list[$i] == "") {
 29858 		  // ----- First '/' i.e. root slash
 29859 		  if ($i == 0) {
 29860             $v_result = "/".$v_result;
 29861 		    if ($v_skip > 0) {
 29862 		        // ----- It is an invalid path, so the path is not modified
 29863 		        // TBC
 29864 		        $v_result = $p_dir;
 29865                 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged");
 29866                 $v_skip = 0;
 29867 		    }
 29868 		  }
 29869 		  // ----- Last '/' i.e. indicates a directory
 29870 		  else if ($i == (sizeof($v_list)-1)) {
 29871             $v_result = $v_list[$i];
 29872 		  }
 29873 		  // ----- Double '/' inside the path
 29874 		  else {
 29875             // ----- Ignore only the double '//' in path,
 29876             // but not the first and last '/'
 29877 		  }
 29878         }
 29879         else {
 29880 		  // ----- Look for item to skip
 29881 		  if ($v_skip > 0) {
 29882 		    $v_skip--;
 29883 		  }
 29884 		  else {
 29885             $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
 29886 		  }
 29887         }
 29888       }
 29889 
 29890       // ----- Look for skip
 29891       if ($v_skip > 0) {
 29892         while ($v_skip > 0) {
 29893             $v_result = '../'.$v_result;
 29894             $v_skip--;
 29895         }
 29896       }
 29897     }
 29898 
 29899     // ----- Return
 29900     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29901     return $v_result;
 29902   }
 29903   // --------------------------------------------------------------------------------
 29904 
 29905   // --------------------------------------------------------------------------------
 29906   // Function : PclZipUtilPathInclusion()
 29907   // Description :
 29908   //   This function indicates if the path $p_path is under the $p_dir tree. Or,
 29909   //   said in an other way, if the file or sub-dir $p_path is inside the dir
 29910   //   $p_dir.
 29911   //   The function indicates also if the path is exactly the same as the dir.
 29912   //   This function supports path with duplicated '/' like '//', but does not
 29913   //   support '.' or '..' statements.
 29914   // Parameters :
 29915   // Return Values :
 29916   //   0 if $p_path is not inside directory $p_dir
 29917   //   1 if $p_path is inside directory $p_dir
 29918   //   2 if $p_path is exactly the same as $p_dir
 29919   // --------------------------------------------------------------------------------
 29920   function PclZipUtilPathInclusion($p_dir, $p_path)
 29921   {
 29922     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'");
 29923     $v_result = 1;
 29924 
 29925     // ----- Look for path beginning by ./
 29926     if (   ($p_dir == '.')
 29927         || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
 29928       $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
 29929       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'");
 29930     }
 29931     if (   ($p_path == '.')
 29932         || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
 29933       $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
 29934       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'");
 29935     }
 29936 
 29937     // ----- Explode dir and path by directory separator
 29938     $v_list_dir = explode("/", $p_dir);
 29939     $v_list_dir_size = sizeof($v_list_dir);
 29940     $v_list_path = explode("/", $p_path);
 29941     $v_list_path_size = sizeof($v_list_path);
 29942 
 29943     // ----- Study directories paths
 29944     $i = 0;
 29945     $j = 0;
 29946     while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
 29947       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'");
 29948 
 29949       // ----- Look for empty dir (path reduction)
 29950       if ($v_list_dir[$i] == '') {
 29951         $i++;
 29952         continue;
 29953       }
 29954       if ($v_list_path[$j] == '') {
 29955         $j++;
 29956         continue;
 29957       }
 29958 
 29959       // ----- Compare the items
 29960       if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != ''))  {
 29961         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different");
 29962         $v_result = 0;
 29963       }
 29964 
 29965       // ----- Next items
 29966       $i++;
 29967       $j++;
 29968     }
 29969 
 29970     // ----- Look if everything seems to be the same
 29971     if ($v_result) {
 29972       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break");
 29973       // ----- Skip all the empty items
 29974       while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
 29975       while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
 29976       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Looking on dir($i)='".($i < $v_list_dir_size?$v_list_dir[$i]:'')."' and path($j)='".($j < $v_list_path_size?$v_list_path[$j]:'')."'");
 29977 
 29978       if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
 29979         // ----- There are exactly the same
 29980         $v_result = 2;
 29981       }
 29982       else if ($i < $v_list_dir_size) {
 29983         // ----- The path is shorter than the dir
 29984         $v_result = 0;
 29985       }
 29986     }
 29987 
 29988     // ----- Return
 29989     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 29990     return $v_result;
 29991   }
 29992   // --------------------------------------------------------------------------------
 29993 
 29994   // --------------------------------------------------------------------------------
 29995   // Function : PclZipUtilCopyBlock()
 29996   // Description :
 29997   // Parameters :
 29998   //   $p_mode : read/write compression mode
 29999   //             0 : src & dest normal
 30000   //             1 : src gzip, dest normal
 30001   //             2 : src normal, dest gzip
 30002   //             3 : src & dest gzip
 30003   // Return Values :
 30004   // --------------------------------------------------------------------------------
 30005   function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
 30006   {
 30007     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode");
 30008     $v_result = 1;
 30009 
 30010     if ($p_mode==0)
 30011     {
 30012       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src)));
 30013       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest)));
 30014       while ($p_size != 0)
 30015       {
 30016         $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
 30017         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 30018         $v_buffer = @fread($p_src, $v_read_size);
 30019         @fwrite($p_dest, $v_buffer, $v_read_size);
 30020         $p_size -= $v_read_size;
 30021       }
 30022       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src)));
 30023       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest)));
 30024     }
 30025     else if ($p_mode==1)
 30026     {
 30027       while ($p_size != 0)
 30028       {
 30029         $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
 30030         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 30031         $v_buffer = @gzread($p_src, $v_read_size);
 30032         @fwrite($p_dest, $v_buffer, $v_read_size);
 30033         $p_size -= $v_read_size;
 30034       }
 30035     }
 30036     else if ($p_mode==2)
 30037     {
 30038       while ($p_size != 0)
 30039       {
 30040         $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
 30041         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 30042         $v_buffer = @fread($p_src, $v_read_size);
 30043         @gzwrite($p_dest, $v_buffer, $v_read_size);
 30044         $p_size -= $v_read_size;
 30045       }
 30046     }
 30047     else if ($p_mode==3)
 30048     {
 30049       while ($p_size != 0)
 30050       {
 30051         $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
 30052         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
 30053         $v_buffer = @gzread($p_src, $v_read_size);
 30054         @gzwrite($p_dest, $v_buffer, $v_read_size);
 30055         $p_size -= $v_read_size;
 30056       }
 30057     }
 30058 
 30059     // ----- Return
 30060     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 30061     return $v_result;
 30062   }
 30063   // --------------------------------------------------------------------------------
 30064 
 30065   // --------------------------------------------------------------------------------
 30066   // Function : PclZipUtilRename()
 30067   // Description :
 30068   //   This function tries to do a simple rename() function. If it fails, it
 30069   //   tries to copy the $p_src file in a new $p_dest file and then unlink the
 30070   //   first one.
 30071   // Parameters :
 30072   //   $p_src : Old filename
 30073   //   $p_dest : New filename
 30074   // Return Values :
 30075   //   1 on success, 0 on failure.
 30076   // --------------------------------------------------------------------------------
 30077   function PclZipUtilRename($p_src, $p_dest)
 30078   {
 30079     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest");
 30080     $v_result = 1;
 30081 
 30082     // ----- Try to rename the files
 30083     if (!@rename($p_src, $p_dest)) {
 30084       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink");
 30085 
 30086       // ----- Try to copy & unlink the src
 30087       if (!@copy($p_src, $p_dest)) {
 30088         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file");
 30089         $v_result = 0;
 30090       }
 30091       else if (!@unlink($p_src)) {
 30092         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename");
 30093         $v_result = 0;
 30094       }
 30095     }
 30096 
 30097     // ----- Return
 30098     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 30099     return $v_result;
 30100   }
 30101   // --------------------------------------------------------------------------------
 30102 
 30103   // --------------------------------------------------------------------------------
 30104   // Function : PclZipUtilOptionText()
 30105   // Description :
 30106   //   Translate option value in text. Mainly for debug purpose.
 30107   // Parameters :
 30108   //   $p_option : the option value.
 30109   // Return Values :
 30110   //   The option text value.
 30111   // --------------------------------------------------------------------------------
 30112   function PclZipUtilOptionText($p_option)
 30113   {
 30114     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'");
 30115 
 30116     $v_list = get_defined_constants();
 30117     for (reset($v_list); $v_key = key($v_list); next($v_list)) {
 30118 	  $v_prefix = substr($v_key, 0, 10);
 30119 	  if ((   ($v_prefix == 'PCLZIP_OPT')
 30120          || ($v_prefix == 'PCLZIP_CB_')
 30121          || ($v_prefix == 'PCLZIP_ATT'))
 30122 	      && ($v_list[$v_key] == $p_option)) {
 30123           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key);
 30124           return $v_key;
 30125 	    }
 30126     }
 30127 
 30128     $v_result = 'Unknown';
 30129 
 30130     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
 30131     return $v_result;
 30132   }
 30133   // --------------------------------------------------------------------------------
 30134 
 30135   // --------------------------------------------------------------------------------
 30136   // Function : PclZipUtilTranslateWinPath()
 30137   // Description :
 30138   //   Translate windows path by replacing '\' by '/' and optionally removing
 30139   //   drive letter.
 30140   // Parameters :
 30141   //   $p_path : path to translate.
 30142   //   $p_remove_disk_letter : true | false
 30143   // Return Values :
 30144   //   The path translated.
 30145   // --------------------------------------------------------------------------------
 30146   function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
 30147   {
 30148     if (stristr(php_uname(), 'windows')) {
 30149       // ----- Look for potential disk letter
 30150       if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
 30151           $p_path = substr($p_path, $v_position+1);
 30152       }
 30153       // ----- Change potential windows directory separator
 30154       if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
 30155           $p_path = strtr($p_path, '\\', '/');
 30156       }
 30157     }
 30158     return $p_path;
 30159   }
 30160   // --------------------------------------------------------------------------------
 30161 
 30162 
 30163 ?>