PalmaSolutions

780403fa468.php

May 3rd, 2018
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 106.02 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.   $this->zipname = $p_zipname;
  5.   $this->zip_fd = 0;
  6.   $this->magic_quotes_status = -1;
  7.  
  8.   return;
  9. }
  10.  
  11. function create($p_filelist)
  12. {
  13.   $v_result=1;
  14.  
  15.   $this->privErrorReset();
  16.  
  17.   $v_options = array();
  18.   $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
  19.  
  20.   $v_size = func_num_args();
  21.  
  22.   if ($v_size > 1) {
  23.     $v_arg_list = func_get_args();
  24.  
  25.     array_shift($v_arg_list);
  26.     $v_size--;
  27.  
  28.     if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  29.  
  30.       $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  31.                                           array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  32.                                                  PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  33.                                                  PCLZIP_OPT_ADD_PATH => 'optional',
  34.                                                  PCLZIP_CB_PRE_ADD => 'optional',
  35.                                                  PCLZIP_CB_POST_ADD => 'optional',
  36.                                                  PCLZIP_OPT_NO_COMPRESSION => 'optional',
  37.                                                  PCLZIP_OPT_COMMENT => 'optional',
  38.                                                  PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  39.                                                  PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  40.                                                  PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  41.                                                  
  42.                                            ));
  43.       if ($v_result != 1) {
  44.         return 0;
  45.       }
  46.     }
  47.  
  48.     else {
  49.  
  50.       $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
  51.  
  52.       if ($v_size == 2) {
  53.         $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
  54.       }
  55.       else if ($v_size > 2) {
  56.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
  57.                            "Invalid number / type of arguments");
  58.         return 0;
  59.       }
  60.     }
  61.   }
  62.  
  63.   $this->privOptionDefaultThreshold($v_options);
  64.  
  65.   $v_string_list = array();
  66.   $v_att_list = array();
  67.   $v_filedescr_list = array();
  68.   $p_result_list = array();
  69.  
  70.   if (is_array($p_filelist)) {
  71.  
  72.     if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
  73.       $v_att_list = $p_filelist;
  74.     }
  75.    
  76.     else {
  77.       $v_string_list = $p_filelist;
  78.     }
  79.   }
  80.  
  81.   else if (is_string($p_filelist)) {
  82.     $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
  83.   }
  84.  
  85.   else {
  86.     PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
  87.     return 0;
  88.   }
  89.  
  90.   if (sizeof($v_string_list) != 0) {
  91.     foreach ($v_string_list as $v_string) {
  92.       if ($v_string != '') {
  93.         $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
  94.       }
  95.       else {
  96.       }
  97.     }
  98.   }
  99.  
  100.   $v_supported_attributes
  101.   = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
  102.            ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
  103.            ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
  104.            ,PCLZIP_ATT_FILE_MTIME => 'optional'
  105.            ,PCLZIP_ATT_FILE_CONTENT => 'optional'
  106.            ,PCLZIP_ATT_FILE_COMMENT => 'optional'
  107.                     );
  108.   foreach ($v_att_list as $v_entry) {
  109.     $v_result = $this->privFileDescrParseAtt($v_entry,
  110.                                              $v_filedescr_list[],
  111.                                              $v_options,
  112.                                              $v_supported_attributes);
  113.     if ($v_result != 1) {
  114.       return 0;
  115.     }
  116.   }
  117.  
  118.   $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
  119.   if ($v_result != 1) {
  120.     return 0;
  121.   }
  122.  
  123.   $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
  124.   if ($v_result != 1) {
  125.     return 0;
  126.   }
  127.  
  128.   return $p_result_list;
  129. }
  130.  
  131. function add($p_filelist)
  132. {
  133.   $v_result=1;
  134.  
  135.   $this->privErrorReset();
  136.  
  137.   $v_options = array();
  138.   $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
  139.  
  140.   $v_size = func_num_args();
  141.  
  142.   if ($v_size > 1) {
  143.     $v_arg_list = func_get_args();
  144.  
  145.     array_shift($v_arg_list);
  146.     $v_size--;
  147.  
  148.     if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  149.  
  150.       $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  151.                                           array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  152.                                                  PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  153.                                                  PCLZIP_OPT_ADD_PATH => 'optional',
  154.                                                  PCLZIP_CB_PRE_ADD => 'optional',
  155.                                                  PCLZIP_CB_POST_ADD => 'optional',
  156.                                                  PCLZIP_OPT_NO_COMPRESSION => 'optional',
  157.                                                  PCLZIP_OPT_COMMENT => 'optional',
  158.                                                  PCLZIP_OPT_ADD_COMMENT => 'optional',
  159.                                                  PCLZIP_OPT_PREPEND_COMMENT => 'optional',
  160.                                                  PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  161.                                                  PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  162.                                                  PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  163.                                                  
  164.                                                ));
  165.       if ($v_result != 1) {
  166.         return 0;
  167.       }
  168.     }
  169.  
  170.     else {
  171.  
  172.       $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
  173.  
  174.       if ($v_size == 2) {
  175.         $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
  176.       }
  177.       else if ($v_size > 2) {
  178.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  179.  
  180.         return 0;
  181.       }
  182.     }
  183.   }
  184.  
  185.   $this->privOptionDefaultThreshold($v_options);
  186.  
  187.   $v_string_list = array();
  188.   $v_att_list = array();
  189.   $v_filedescr_list = array();
  190.   $p_result_list = array();
  191.  
  192.   if (is_array($p_filelist)) {
  193.  
  194.     if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
  195.       $v_att_list = $p_filelist;
  196.     }
  197.    
  198.     else {
  199.       $v_string_list = $p_filelist;
  200.     }
  201.   }
  202.  
  203.   else if (is_string($p_filelist)) {
  204.     $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
  205.   }
  206.  
  207.   else {
  208.     PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
  209.     return 0;
  210.   }
  211.  
  212.   if (sizeof($v_string_list) != 0) {
  213.     foreach ($v_string_list as $v_string) {
  214.       $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
  215.     }
  216.   }
  217.  
  218.   $v_supported_attributes
  219.   = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
  220.            ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
  221.            ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
  222.            ,PCLZIP_ATT_FILE_MTIME => 'optional'
  223.            ,PCLZIP_ATT_FILE_CONTENT => 'optional'
  224.            ,PCLZIP_ATT_FILE_COMMENT => 'optional'
  225.                     );
  226.   foreach ($v_att_list as $v_entry) {
  227.     $v_result = $this->privFileDescrParseAtt($v_entry,
  228.                                              $v_filedescr_list[],
  229.                                              $v_options,
  230.                                              $v_supported_attributes);
  231.     if ($v_result != 1) {
  232.       return 0;
  233.     }
  234.   }
  235.  
  236.   $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
  237.   if ($v_result != 1) {
  238.     return 0;
  239.   }
  240.  
  241.   $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
  242.   if ($v_result != 1) {
  243.     return 0;
  244.   }
  245.  
  246.   return $p_result_list;
  247. }
  248.  
  249. function listContent()
  250. {
  251.   $v_result=1;
  252.  
  253.   $this->privErrorReset();
  254.  
  255.   if (!$this->privCheckFormat()) {
  256.     return(0);
  257.   }
  258.  
  259.   $p_list = array();
  260.   if (($v_result = $this->privList($p_list)) != 1)
  261.   {
  262.     unset($p_list);
  263.     return(0);
  264.   }
  265.  
  266.   return $p_list;
  267. }
  268.  
  269. function extract()
  270. {
  271.   $v_result=1;
  272.  
  273.   $this->privErrorReset();
  274.  
  275.   if (!$this->privCheckFormat()) {
  276.     return(0);
  277.   }
  278.  
  279.   $v_options = array();
  280.   $v_path = '';
  281.   $v_remove_path = "";
  282.   $v_remove_all_path = false;
  283.  
  284.   $v_size = func_num_args();
  285.  
  286.   $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  287.  
  288.   if ($v_size > 0) {
  289.     $v_arg_list = func_get_args();
  290.  
  291.     if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  292.  
  293.       $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  294.                                           array (PCLZIP_OPT_PATH => 'optional',
  295.                                                  PCLZIP_OPT_REMOVE_PATH => 'optional',
  296.                                                  PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  297.                                                  PCLZIP_OPT_ADD_PATH => 'optional',
  298.                                                  PCLZIP_CB_PRE_EXTRACT => 'optional',
  299.                                                  PCLZIP_CB_POST_EXTRACT => 'optional',
  300.                                                  PCLZIP_OPT_SET_CHMOD => 'optional',
  301.                                                  PCLZIP_OPT_BY_NAME => 'optional',
  302.                                                  PCLZIP_OPT_BY_EREG => 'optional',
  303.                                                  PCLZIP_OPT_BY_PREG => 'optional',
  304.                                                  PCLZIP_OPT_BY_INDEX => 'optional',
  305.                                                  PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  306.                                                  PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
  307.                                                  PCLZIP_OPT_REPLACE_NEWER => 'optional'
  308.                                                  ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
  309.                                                  ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
  310.                                                  PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  311.                                                  PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  312.                                                  PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  313.                                                 ));
  314.       if ($v_result != 1) {
  315.         return 0;
  316.       }
  317.  
  318.       if (isset($v_options[PCLZIP_OPT_PATH])) {
  319.         $v_path = $v_options[PCLZIP_OPT_PATH];
  320.       }
  321.       if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  322.         $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  323.       }
  324.       if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  325.         $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  326.       }
  327.       if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  328.         if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
  329.           $v_path .= '/';
  330.         }
  331.         $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  332.       }
  333.     }
  334.  
  335.     else {
  336.  
  337.       $v_path = $v_arg_list[0];
  338.  
  339.       if ($v_size == 2) {
  340.         $v_remove_path = $v_arg_list[1];
  341.       }
  342.       else if ($v_size > 2) {
  343.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  344.  
  345.         return 0;
  346.       }
  347.     }
  348.   }
  349.  
  350.   $this->privOptionDefaultThreshold($v_options);
  351.  
  352.  
  353.   $p_list = array();
  354.   $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
  355.                                      $v_remove_all_path, $v_options);
  356.   if ($v_result < 1) {
  357.     unset($p_list);
  358.     return(0);
  359.   }
  360.  
  361.   return $p_list;
  362. }
  363.  
  364.  
  365.  
  366. function extractByIndex($p_index)
  367. {
  368.   $v_result=1;
  369.  
  370.   $this->privErrorReset();
  371.  
  372.   if (!$this->privCheckFormat()) {
  373.     return(0);
  374.   }
  375.  
  376.   $v_options = array();
  377.   $v_path = '';
  378.   $v_remove_path = "";
  379.   $v_remove_all_path = false;
  380.  
  381.   $v_size = func_num_args();
  382.  
  383.   $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  384.  
  385.   if ($v_size > 1) {
  386.     $v_arg_list = func_get_args();
  387.  
  388.     array_shift($v_arg_list);
  389.     $v_size--;
  390.  
  391.     if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  392.  
  393.       $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  394.                                           array (PCLZIP_OPT_PATH => 'optional',
  395.                                                  PCLZIP_OPT_REMOVE_PATH => 'optional',
  396.                                                  PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  397.                                                  PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  398.                                                  PCLZIP_OPT_ADD_PATH => 'optional',
  399.                                                  PCLZIP_CB_PRE_EXTRACT => 'optional',
  400.                                                  PCLZIP_CB_POST_EXTRACT => 'optional',
  401.                                                  PCLZIP_OPT_SET_CHMOD => 'optional',
  402.                                                  PCLZIP_OPT_REPLACE_NEWER => 'optional'
  403.                                                  ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
  404.                                                  ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
  405.                                                  PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  406.                                                  PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  407.                                                  PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  408.                                                ));
  409.       if ($v_result != 1) {
  410.         return 0;
  411.       }
  412.  
  413.       if (isset($v_options[PCLZIP_OPT_PATH])) {
  414.         $v_path = $v_options[PCLZIP_OPT_PATH];
  415.       }
  416.       if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  417.         $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  418.       }
  419.       if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  420.         $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  421.       }
  422.       if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  423.         if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
  424.           $v_path .= '/';
  425.         }
  426.         $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  427.       }
  428.       if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
  429.         $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  430.       }
  431.       else {
  432.       }
  433.     }
  434.  
  435.     else {
  436.  
  437.       $v_path = $v_arg_list[0];
  438.  
  439.       if ($v_size == 2) {
  440.         $v_remove_path = $v_arg_list[1];
  441.       }
  442.       else if ($v_size > 2) {
  443.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  444.  
  445.         return 0;
  446.       }
  447.     }
  448.   }
  449.  
  450.  
  451.   $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
  452.   $v_options_trick = array();
  453.   $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
  454.                                       array (PCLZIP_OPT_BY_INDEX => 'optional' ));
  455.   if ($v_result != 1) {
  456.       return 0;
  457.   }
  458.   $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
  459.  
  460.   $this->privOptionDefaultThreshold($v_options);
  461.  
  462.   if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
  463.       return(0);
  464.   }
  465.  
  466.   return $p_list;
  467. }
  468.  
  469. function delete()
  470. {
  471.   $v_result=1;
  472.  
  473.   $this->privErrorReset();
  474.  
  475.   if (!$this->privCheckFormat()) {
  476.     return(0);
  477.   }
  478.  
  479.   $v_options = array();
  480.  
  481.   $v_size = func_num_args();
  482.  
  483.   if ($v_size > 0) {
  484.     $v_arg_list = func_get_args();
  485.  
  486.     $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  487.                                       array (PCLZIP_OPT_BY_NAME => 'optional',
  488.                                              PCLZIP_OPT_BY_EREG => 'optional',
  489.                                              PCLZIP_OPT_BY_PREG => 'optional',
  490.                                              PCLZIP_OPT_BY_INDEX => 'optional' ));
  491.     if ($v_result != 1) {
  492.         return 0;
  493.     }
  494.   }
  495.  
  496.   $this->privDisableMagicQuotes();
  497.  
  498.   $v_list = array();
  499.   if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
  500.     $this->privSwapBackMagicQuotes();
  501.     unset($v_list);
  502.     return(0);
  503.   }
  504.  
  505.   $this->privSwapBackMagicQuotes();
  506.  
  507.   return $v_list;
  508. }
  509.  
  510. function deleteByIndex($p_index)
  511. {
  512.  
  513.   $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
  514.  
  515.   return $p_list;
  516. }
  517.  
  518. function properties()
  519. {
  520.  
  521.   $this->privErrorReset();
  522.  
  523.   $this->privDisableMagicQuotes();
  524.  
  525.   if (!$this->privCheckFormat()) {
  526.     $this->privSwapBackMagicQuotes();
  527.     return(0);
  528.   }
  529.  
  530.   $v_prop = array();
  531.   $v_prop['comment'] = '';
  532.   $v_prop['nb'] = 0;
  533.   $v_prop['status'] = 'not_exist';
  534.  
  535.   if (@is_file($this->zipname))
  536.   {
  537.     if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
  538.     {
  539.       $this->privSwapBackMagicQuotes();
  540.      
  541.       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
  542.  
  543.       return 0;
  544.     }
  545.  
  546.     $v_central_dir = array();
  547.     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  548.     {
  549.       $this->privSwapBackMagicQuotes();
  550.       return 0;
  551.     }
  552.  
  553.     $this->privCloseFd();
  554.  
  555.     $v_prop['comment'] = $v_central_dir['comment'];
  556.     $v_prop['nb'] = $v_central_dir['entries'];
  557.     $v_prop['status'] = 'ok';
  558.   }
  559.  
  560.   $this->privSwapBackMagicQuotes();
  561.  
  562.   return $v_prop;
  563. }
  564.  
  565. function duplicate($p_archive)
  566. {
  567.   $v_result = 1;
  568.  
  569.   $this->privErrorReset();
  570.  
  571.   if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
  572.   {
  573.  
  574.     $v_result = $this->privDuplicate($p_archive->zipname);
  575.   }
  576.  
  577.   else if (is_string($p_archive))
  578.   {
  579.  
  580.     if (!is_file($p_archive)) {
  581.       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
  582.       $v_result = PCLZIP_ERR_MISSING_FILE;
  583.     }
  584.     else {
  585.       $v_result = $this->privDuplicate($p_archive);
  586.     }
  587.   }
  588.  
  589.   else
  590.   {
  591.     PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  592.     $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  593.   }
  594.  
  595.   return $v_result;
  596. }
  597.  
  598. function merge($p_archive_to_add)
  599. {
  600.   $v_result = 1;
  601.  
  602.   $this->privErrorReset();
  603.  
  604.   if (!$this->privCheckFormat()) {
  605.     return(0);
  606.   }
  607.  
  608.   if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
  609.   {
  610.  
  611.     $v_result = $this->privMerge($p_archive_to_add);
  612.   }
  613.  
  614.   else if (is_string($p_archive_to_add))
  615.   {
  616.  
  617.     $v_object_archive = new PclZip($p_archive_to_add);
  618.  
  619.     $v_result = $this->privMerge($v_object_archive);
  620.   }
  621.  
  622.   else
  623.   {
  624.     PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  625.     $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  626.   }
  627.  
  628.   return $v_result;
  629. }
  630.  
  631.  
  632.  
  633. function errorCode()
  634. {
  635.   if (PCLZIP_ERROR_EXTERNAL == 1) {
  636.     return(PclErrorCode());
  637.   }
  638.   else {
  639.     return($this->error_code);
  640.   }
  641. }
  642.  
  643. function errorName($p_with_code=false)
  644. {
  645.   $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
  646.                     PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
  647.                     PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
  648.                     PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
  649.                     PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
  650.                     PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
  651.                     PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
  652.                     PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
  653.                     PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
  654.                     PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
  655.                     PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
  656.                     PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
  657.                     PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
  658.                     PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
  659.                     PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
  660.                     PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
  661.                     PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
  662.                     PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
  663.                     PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
  664.                     ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
  665.                     ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
  666.                   );
  667.  
  668.   if (isset($v_name[$this->error_code])) {
  669.     $v_value = $v_name[$this->error_code];
  670.   }
  671.   else {
  672.     $v_value = 'NoName';
  673.   }
  674.  
  675.   if ($p_with_code) {
  676.     return($v_value.' ('.$this->error_code.')');
  677.   }
  678.   else {
  679.     return($v_value);
  680.   }
  681. }
  682.  
  683. function errorInfo($p_full=false)
  684. {
  685.   if (PCLZIP_ERROR_EXTERNAL == 1) {
  686.     return(PclErrorString());
  687.   }
  688.   else {
  689.     if ($p_full) {
  690.       return($this->errorName(true)." : ".$this->error_string);
  691.     }
  692.     else {
  693.       return($this->error_string." [code ".$this->error_code."]");
  694.     }
  695.   }
  696. }
  697.  
  698.  
  699.  
  700.  
  701.  
  702. function privCheckFormat($p_level=0)
  703. {
  704.   $v_result = true;
  705.  
  706.   clearstatcache();
  707.  
  708.   $this->privErrorReset();
  709.  
  710.   if (!is_file($this->zipname)) {
  711.     PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
  712.     return(false);
  713.   }
  714.  
  715.   if (!is_readable($this->zipname)) {
  716.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
  717.     return(false);
  718.   }
  719.  
  720.  
  721.  
  722.  
  723.   return $v_result;
  724. }
  725.  
  726. function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
  727. {
  728.   $v_result=1;
  729.  
  730.   $i=0;
  731.   while ($i<$p_size) {
  732.  
  733.     if (!isset($v_requested_options[$p_options_list[$i]])) {
  734.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
  735.  
  736.       return PclZip::errorCode();
  737.     }
  738.  
  739.     switch ($p_options_list[$i]) {
  740.       case PCLZIP_OPT_PATH :
  741.       case PCLZIP_OPT_REMOVE_PATH :
  742.       case PCLZIP_OPT_ADD_PATH :
  743.         if (($i+1) >= $p_size) {
  744.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  745.  
  746.           return PclZip::errorCode();
  747.         }
  748.  
  749.         $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
  750.         $i++;
  751.       break;
  752.  
  753.       case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
  754.         if (($i+1) >= $p_size) {
  755.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  756.           return PclZip::errorCode();
  757.         }
  758.        
  759.         if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
  760.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
  761.           return PclZip::errorCode();
  762.         }
  763.        
  764.         $v_value = $p_options_list[$i+1];
  765.         if ((!is_integer($v_value)) || ($v_value<0)) {
  766.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  767.           return PclZip::errorCode();
  768.         }
  769.  
  770.         $v_result_list[$p_options_list[$i]] = $v_value*1048576;
  771.         $i++;
  772.       break;
  773.  
  774.       case PCLZIP_OPT_TEMP_FILE_ON :
  775.         if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
  776.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
  777.           return PclZip::errorCode();
  778.         }
  779.        
  780.         $v_result_list[$p_options_list[$i]] = true;
  781.       break;
  782.  
  783.       case PCLZIP_OPT_TEMP_FILE_OFF :
  784.         if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
  785.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
  786.           return PclZip::errorCode();
  787.         }
  788.         if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
  789.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
  790.           return PclZip::errorCode();
  791.         }
  792.        
  793.         $v_result_list[$p_options_list[$i]] = true;
  794.       break;
  795.  
  796.       case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
  797.         if (($i+1) >= $p_size) {
  798.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  799.  
  800.           return PclZip::errorCode();
  801.         }
  802.  
  803.         if (   is_string($p_options_list[$i+1])
  804.             && ($p_options_list[$i+1] != '')) {
  805.           $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
  806.           $i++;
  807.         }
  808.         else {
  809.         }
  810.       break;
  811.  
  812.       case PCLZIP_OPT_BY_NAME :
  813.         if (($i+1) >= $p_size) {
  814.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  815.  
  816.           return PclZip::errorCode();
  817.         }
  818.  
  819.         if (is_string($p_options_list[$i+1])) {
  820.             $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
  821.         }
  822.         else if (is_array($p_options_list[$i+1])) {
  823.             $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  824.         }
  825.         else {
  826.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  827.  
  828.           return PclZip::errorCode();
  829.         }
  830.         $i++;
  831.       break;
  832.  
  833.       case PCLZIP_OPT_BY_EREG :
  834.         $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
  835.       case PCLZIP_OPT_BY_PREG :
  836.         if (($i+1) >= $p_size) {
  837.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  838.  
  839.           return PclZip::errorCode();
  840.         }
  841.  
  842.         if (is_string($p_options_list[$i+1])) {
  843.             $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  844.         }
  845.         else {
  846.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  847.  
  848.           return PclZip::errorCode();
  849.         }
  850.         $i++;
  851.       break;
  852.  
  853.       case PCLZIP_OPT_COMMENT :
  854.       case PCLZIP_OPT_ADD_COMMENT :
  855.       case PCLZIP_OPT_PREPEND_COMMENT :
  856.         if (($i+1) >= $p_size) {
  857.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
  858.                              "Missing parameter value for option '"
  859.                              .PclZipUtilOptionText($p_options_list[$i])
  860.                              ."'");
  861.  
  862.           return PclZip::errorCode();
  863.         }
  864.  
  865.         if (is_string($p_options_list[$i+1])) {
  866.             $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  867.         }
  868.         else {
  869.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
  870.                              "Wrong parameter value for option '"
  871.                              .PclZipUtilOptionText($p_options_list[$i])
  872.                              ."'");
  873.  
  874.           return PclZip::errorCode();
  875.         }
  876.         $i++;
  877.       break;
  878.  
  879.       case PCLZIP_OPT_BY_INDEX :
  880.         if (($i+1) >= $p_size) {
  881.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  882.  
  883.           return PclZip::errorCode();
  884.         }
  885.  
  886.         $v_work_list = array();
  887.         if (is_string($p_options_list[$i+1])) {
  888.  
  889.             $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
  890.  
  891.             $v_work_list = explode(",", $p_options_list[$i+1]);
  892.         }
  893.         else if (is_integer($p_options_list[$i+1])) {
  894.             $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
  895.         }
  896.         else if (is_array($p_options_list[$i+1])) {
  897.             $v_work_list = $p_options_list[$i+1];
  898.         }
  899.         else {
  900.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  901.  
  902.           return PclZip::errorCode();
  903.         }
  904.        
  905.         $v_sort_flag=false;
  906.         $v_sort_value=0;
  907.         for ($j=0; $j<sizeof($v_work_list); $j++) {
  908.             $v_item_list = explode("-", $v_work_list[$j]);
  909.             $v_size_item_list = sizeof($v_item_list);
  910.            
  911.            
  912.             if ($v_size_item_list == 1) {
  913.                 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
  914.                 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
  915.             }
  916.             elseif ($v_size_item_list == 2) {
  917.                 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
  918.                 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
  919.             }
  920.             else {
  921.                 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  922.  
  923.                 return PclZip::errorCode();
  924.             }
  925.  
  926.  
  927.             if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
  928.                 $v_sort_flag=true;
  929.  
  930.                 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  931.  
  932.                 return PclZip::errorCode();
  933.             }
  934.             $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
  935.         }
  936.        
  937.         if ($v_sort_flag) {
  938.         }
  939.  
  940.         $i++;
  941.       break;
  942.  
  943.       case PCLZIP_OPT_REMOVE_ALL_PATH :
  944.       case PCLZIP_OPT_EXTRACT_AS_STRING :
  945.       case PCLZIP_OPT_NO_COMPRESSION :
  946.       case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
  947.       case PCLZIP_OPT_REPLACE_NEWER :
  948.       case PCLZIP_OPT_STOP_ON_ERROR :
  949.         $v_result_list[$p_options_list[$i]] = true;
  950.       break;
  951.  
  952.       case PCLZIP_OPT_SET_CHMOD :
  953.         if (($i+1) >= $p_size) {
  954.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  955.  
  956.           return PclZip::errorCode();
  957.         }
  958.  
  959.         $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  960.         $i++;
  961.       break;
  962.  
  963.       case PCLZIP_CB_PRE_EXTRACT :
  964.       case PCLZIP_CB_POST_EXTRACT :
  965.       case PCLZIP_CB_PRE_ADD :
  966.       case PCLZIP_CB_POST_ADD :
  967.         if (($i+1) >= $p_size) {
  968.           PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  969.  
  970.           return PclZip::errorCode();
  971.         }
  972.  
  973.         $v_function_name = $p_options_list[$i+1];
  974.  
  975.         if (!function_exists($v_function_name)) {
  976.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  977.  
  978.           return PclZip::errorCode();
  979.         }
  980.  
  981.         $v_result_list[$p_options_list[$i]] = $v_function_name;
  982.         $i++;
  983.       break;
  984.  
  985.       default :
  986.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
  987.                            "Unknown parameter '"
  988.                            .$p_options_list[$i]."'");
  989.  
  990.         return PclZip::errorCode();
  991.     }
  992.  
  993.     $i++;
  994.   }
  995.  
  996.   if ($v_requested_options !== false) {
  997.     for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
  998.       if ($v_requested_options[$key] == 'mandatory') {
  999.         if (!isset($v_result_list[$key])) {
  1000.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
  1001.  
  1002.           return PclZip::errorCode();
  1003.         }
  1004.       }
  1005.     }
  1006.   }
  1007.  
  1008.   if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
  1009.    
  1010.   }
  1011.  
  1012.   return $v_result;
  1013. }
  1014.  
  1015. function privOptionDefaultThreshold(&$p_options)
  1016. {
  1017.   $v_result=1;
  1018.  
  1019.   if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
  1020.       || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
  1021.     return $v_result;
  1022.   }
  1023.  
  1024.   $v_memory_limit = ini_get('memory_limit');
  1025.   $v_memory_limit = trim($v_memory_limit);
  1026.   $last = strtolower(substr($v_memory_limit, -1));
  1027.  
  1028.   if($last == 'g')
  1029.       $v_memory_limit = $v_memory_limit*1073741824;
  1030.   if($last == 'm')
  1031.       $v_memory_limit = $v_memory_limit*1048576;
  1032.   if($last == 'k')
  1033.       $v_memory_limit = $v_memory_limit*1024;
  1034.          
  1035.   $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
  1036.  
  1037.  
  1038.   if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
  1039.     unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
  1040.   }
  1041.        
  1042.   return $v_result;
  1043. }
  1044.  
  1045. function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
  1046. {
  1047.   $v_result=1;
  1048.  
  1049.   foreach ($p_file_list as $v_key => $v_value) {
  1050.  
  1051.     if (!isset($v_requested_options[$v_key])) {
  1052.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
  1053.  
  1054.       return PclZip::errorCode();
  1055.     }
  1056.  
  1057.     switch ($v_key) {
  1058.       case PCLZIP_ATT_FILE_NAME :
  1059.         if (!is_string($v_value)) {
  1060.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1061.           return PclZip::errorCode();
  1062.         }
  1063.  
  1064.         $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
  1065.        
  1066.         if ($p_filedescr['filename'] == '') {
  1067.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1068.           return PclZip::errorCode();
  1069.         }
  1070.  
  1071.       break;
  1072.  
  1073.       case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
  1074.         if (!is_string($v_value)) {
  1075.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1076.           return PclZip::errorCode();
  1077.         }
  1078.  
  1079.         $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
  1080.  
  1081.         if ($p_filedescr['new_short_name'] == '') {
  1082.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1083.           return PclZip::errorCode();
  1084.         }
  1085.       break;
  1086.  
  1087.       case PCLZIP_ATT_FILE_NEW_FULL_NAME :
  1088.         if (!is_string($v_value)) {
  1089.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1090.           return PclZip::errorCode();
  1091.         }
  1092.  
  1093.         $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
  1094.  
  1095.         if ($p_filedescr['new_full_name'] == '') {
  1096.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1097.           return PclZip::errorCode();
  1098.         }
  1099.       break;
  1100.  
  1101.       case PCLZIP_ATT_FILE_COMMENT :
  1102.         if (!is_string($v_value)) {
  1103.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1104.           return PclZip::errorCode();
  1105.         }
  1106.  
  1107.         $p_filedescr['comment'] = $v_value;
  1108.       break;
  1109.  
  1110.       case PCLZIP_ATT_FILE_MTIME :
  1111.         if (!is_integer($v_value)) {
  1112.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1113.           return PclZip::errorCode();
  1114.         }
  1115.  
  1116.         $p_filedescr['mtime'] = $v_value;
  1117.       break;
  1118.  
  1119.       case PCLZIP_ATT_FILE_CONTENT :
  1120.         $p_filedescr['content'] = $v_value;
  1121.       break;
  1122.  
  1123.       default :
  1124.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
  1125.                                "Unknown parameter '".$v_key."'");
  1126.  
  1127.         return PclZip::errorCode();
  1128.     }
  1129.  
  1130.     if ($v_requested_options !== false) {
  1131.       for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
  1132.         if ($v_requested_options[$key] == 'mandatory') {
  1133.           if (!isset($p_file_list[$key])) {
  1134.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
  1135.             return PclZip::errorCode();
  1136.           }
  1137.         }
  1138.       }
  1139.     }
  1140.  
  1141.   }
  1142.  
  1143.   return $v_result;
  1144. }
  1145.  
  1146. function privFileDescrExpand(&$p_filedescr_list, &$p_options)
  1147. {
  1148.   $v_result=1;
  1149.  
  1150.   $v_result_list = array();
  1151.  
  1152.   for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
  1153.    
  1154.     $v_descr = $p_filedescr_list[$i];
  1155.    
  1156.     $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
  1157.     $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
  1158.    
  1159.     if (file_exists($v_descr['filename'])) {
  1160.       if (@is_file($v_descr['filename'])) {
  1161.         $v_descr['type'] = 'file';
  1162.       }
  1163.       else if (@is_dir($v_descr['filename'])) {
  1164.         $v_descr['type'] = 'folder';
  1165.       }
  1166.       else if (@is_link($v_descr['filename'])) {
  1167.         continue;
  1168.       }
  1169.       else {
  1170.         continue;
  1171.       }
  1172.     }
  1173.    
  1174.     else if (isset($v_descr['content'])) {
  1175.       $v_descr['type'] = 'virtual_file';
  1176.     }
  1177.    
  1178.     else {
  1179.       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
  1180.  
  1181.       return PclZip::errorCode();
  1182.     }
  1183.    
  1184.     $this->privCalculateStoredFilename($v_descr, $p_options);
  1185.    
  1186.     $v_result_list[sizeof($v_result_list)] = $v_descr;
  1187.    
  1188.     if ($v_descr['type'] == 'folder') {
  1189.       $v_dirlist_descr = array();
  1190.       $v_dirlist_nb = 0;
  1191.       if ($v_folder_handler = @opendir($v_descr['filename'])) {
  1192.         while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
  1193.  
  1194.           if (($v_item_handler == '.') || ($v_item_handler == '..')) {
  1195.               continue;
  1196.           }
  1197.          
  1198.           $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
  1199.          
  1200.           if (($v_descr['stored_filename'] != $v_descr['filename'])
  1201.                && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
  1202.             if ($v_descr['stored_filename'] != '') {
  1203.               $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
  1204.             }
  1205.             else {
  1206.               $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
  1207.             }
  1208.           }
  1209.    
  1210.           $v_dirlist_nb++;
  1211.         }
  1212.        
  1213.         @closedir($v_folder_handler);
  1214.       }
  1215.       else {
  1216.       }
  1217.      
  1218.       if ($v_dirlist_nb != 0) {
  1219.         if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
  1220.           return $v_result;
  1221.         }
  1222.        
  1223.         $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
  1224.       }
  1225.       else {
  1226.       }
  1227.        
  1228.       unset($v_dirlist_descr);
  1229.     }
  1230.   }
  1231.  
  1232.   $p_filedescr_list = $v_result_list;
  1233.  
  1234.   return $v_result;
  1235. }
  1236.  
  1237. function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
  1238. {
  1239.   $v_result=1;
  1240.   $v_list_detail = array();
  1241.  
  1242.   $this->privDisableMagicQuotes();
  1243.  
  1244.   if (($v_result = $this->privOpenFd('wb')) != 1)
  1245.   {
  1246.     return $v_result;
  1247.   }
  1248.  
  1249.   $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
  1250.  
  1251.   $this->privCloseFd();
  1252.  
  1253.   $this->privSwapBackMagicQuotes();
  1254.  
  1255.   return $v_result;
  1256. }
  1257.  
  1258. function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
  1259. {
  1260.   $v_result=1;
  1261.   $v_list_detail = array();
  1262.  
  1263.   if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
  1264.   {
  1265.  
  1266.     $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
  1267.  
  1268.     return $v_result;
  1269.   }
  1270.   $this->privDisableMagicQuotes();
  1271.  
  1272.   if (($v_result=$this->privOpenFd('rb')) != 1)
  1273.   {
  1274.     $this->privSwapBackMagicQuotes();
  1275.  
  1276.     return $v_result;
  1277.   }
  1278.  
  1279.   $v_central_dir = array();
  1280.   if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  1281.   {
  1282.     $this->privCloseFd();
  1283.     $this->privSwapBackMagicQuotes();
  1284.     return $v_result;
  1285.   }
  1286.  
  1287.   @rewind($this->zip_fd);
  1288.  
  1289.   $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  1290.  
  1291.   if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
  1292.   {
  1293.     $this->privCloseFd();
  1294.     $this->privSwapBackMagicQuotes();
  1295.  
  1296.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
  1297.  
  1298.     return PclZip::errorCode();
  1299.   }
  1300.  
  1301.   $v_size = $v_central_dir['offset'];
  1302.   while ($v_size != 0)
  1303.   {
  1304.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  1305.     $v_buffer = fread($this->zip_fd, $v_read_size);
  1306.     @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  1307.     $v_size -= $v_read_size;
  1308.   }
  1309.  
  1310.   $v_swap = $this->zip_fd;
  1311.   $this->zip_fd = $v_zip_temp_fd;
  1312.   $v_zip_temp_fd = $v_swap;
  1313.  
  1314.   $v_header_list = array();
  1315.   if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
  1316.   {
  1317.     fclose($v_zip_temp_fd);
  1318.     $this->privCloseFd();
  1319.     @unlink($v_zip_temp_name);
  1320.     $this->privSwapBackMagicQuotes();
  1321.  
  1322.     return $v_result;
  1323.   }
  1324.  
  1325.   $v_offset = @ftell($this->zip_fd);
  1326.  
  1327.   $v_size = $v_central_dir['size'];
  1328.   while ($v_size != 0)
  1329.   {
  1330.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  1331.     $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
  1332.     @fwrite($this->zip_fd, $v_buffer, $v_read_size);
  1333.     $v_size -= $v_read_size;
  1334.   }
  1335.  
  1336.   for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
  1337.   {
  1338.     if ($v_header_list[$i]['status'] == 'ok') {
  1339.       if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
  1340.         fclose($v_zip_temp_fd);
  1341.         $this->privCloseFd();
  1342.         @unlink($v_zip_temp_name);
  1343.         $this->privSwapBackMagicQuotes();
  1344.  
  1345.         return $v_result;
  1346.       }
  1347.       $v_count++;
  1348.     }
  1349.  
  1350.     $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
  1351.   }
  1352.  
  1353.   $v_comment = $v_central_dir['comment'];
  1354.   if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  1355.     $v_comment = $p_options[PCLZIP_OPT_COMMENT];
  1356.   }
  1357.   if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
  1358.     $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
  1359.   }
  1360.   if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
  1361.     $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
  1362.   }
  1363.  
  1364.   $v_size = @ftell($this->zip_fd)-$v_offset;
  1365.  
  1366.   if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
  1367.   {
  1368.     unset($v_header_list);
  1369.     $this->privSwapBackMagicQuotes();
  1370.  
  1371.     return $v_result;
  1372.   }
  1373.  
  1374.   $v_swap = $this->zip_fd;
  1375.   $this->zip_fd = $v_zip_temp_fd;
  1376.   $v_zip_temp_fd = $v_swap;
  1377.  
  1378.   $this->privCloseFd();
  1379.  
  1380.   @fclose($v_zip_temp_fd);
  1381.  
  1382.   $this->privSwapBackMagicQuotes();
  1383.  
  1384.   @unlink($this->zipname);
  1385.  
  1386.   PclZipUtilRename($v_zip_temp_name, $this->zipname);
  1387.  
  1388.   return $v_result;
  1389. }
  1390.  
  1391. function privOpenFd($p_mode)
  1392. {
  1393.   $v_result=1;
  1394.  
  1395.   if ($this->zip_fd != 0)
  1396.   {
  1397.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
  1398.  
  1399.     return PclZip::errorCode();
  1400.   }
  1401.  
  1402.   if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
  1403.   {
  1404.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
  1405.  
  1406.     return PclZip::errorCode();
  1407.   }
  1408.  
  1409.   return $v_result;
  1410. }
  1411.  
  1412. function privCloseFd()
  1413. {
  1414.   $v_result=1;
  1415.  
  1416.   if ($this->zip_fd != 0)
  1417.     @fclose($this->zip_fd);
  1418.   $this->zip_fd = 0;
  1419.  
  1420.   return $v_result;
  1421. }
  1422.  
  1423. function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
  1424. {
  1425.   $v_result=1;
  1426.  
  1427.   $v_header_list = array();
  1428.   if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
  1429.   {
  1430.     return $v_result;
  1431.   }
  1432.  
  1433.   $v_offset = @ftell($this->zip_fd);
  1434.  
  1435.   for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
  1436.   {
  1437.     if ($v_header_list[$i]['status'] == 'ok') {
  1438.       if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
  1439.         return $v_result;
  1440.       }
  1441.       $v_count++;
  1442.     }
  1443.  
  1444.     $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
  1445.   }
  1446.  
  1447.   $v_comment = '';
  1448.   if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  1449.     $v_comment = $p_options[PCLZIP_OPT_COMMENT];
  1450.   }
  1451.  
  1452.   $v_size = @ftell($this->zip_fd)-$v_offset;
  1453.  
  1454.   if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
  1455.   {
  1456.     unset($v_header_list);
  1457.  
  1458.     return $v_result;
  1459.   }
  1460.  
  1461.   return $v_result;
  1462. }
  1463.  
  1464. function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
  1465. {
  1466.   $v_result=1;
  1467.   $v_header = array();
  1468.  
  1469.   $v_nb = sizeof($p_result_list);
  1470.  
  1471.   for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
  1472.     $p_filedescr_list[$j]['filename']
  1473.     = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
  1474.    
  1475.  
  1476.     if ($p_filedescr_list[$j]['filename'] == "") {
  1477.       continue;
  1478.     }
  1479.  
  1480.     if (   ($p_filedescr_list[$j]['type'] != 'virtual_file')
  1481.         && (!file_exists($p_filedescr_list[$j]['filename']))) {
  1482.       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
  1483.       return PclZip::errorCode();
  1484.     }
  1485.  
  1486.     if (   ($p_filedescr_list[$j]['type'] == 'file')
  1487.         || ($p_filedescr_list[$j]['type'] == 'virtual_file')
  1488.         || (   ($p_filedescr_list[$j]['type'] == 'folder')
  1489.             && (   !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
  1490.                 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
  1491.         ) {
  1492.  
  1493.       $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
  1494.                                      $p_options);
  1495.       if ($v_result != 1) {
  1496.         return $v_result;
  1497.       }
  1498.  
  1499.       $p_result_list[$v_nb++] = $v_header;
  1500.     }
  1501.   }
  1502.  
  1503.   return $v_result;
  1504. }
  1505.  
  1506. function privAddFile($p_filedescr, &$p_header, &$p_options)
  1507. {
  1508.   $v_result=1;
  1509.  
  1510.   $p_filename = $p_filedescr['filename'];
  1511.  
  1512.   if ($p_filename == "") {
  1513.     PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
  1514.  
  1515.     return PclZip::errorCode();
  1516.   }
  1517.  
  1518.  
  1519.   clearstatcache();
  1520.   $p_header['version'] = 20;
  1521.   $p_header['version_extracted'] = 10;
  1522.   $p_header['flag'] = 0;
  1523.   $p_header['compression'] = 0;
  1524.   $p_header['crc'] = 0;
  1525.   $p_header['compressed_size'] = 0;
  1526.   $p_header['filename_len'] = strlen($p_filename);
  1527.   $p_header['extra_len'] = 0;
  1528.   $p_header['disk'] = 0;
  1529.   $p_header['internal'] = 0;
  1530.   $p_header['offset'] = 0;
  1531.   $p_header['filename'] = $p_filename;
  1532.   $p_header['stored_filename'] = $p_filedescr['stored_filename'];
  1533.   $p_header['extra'] = '';
  1534.   $p_header['status'] = 'ok';
  1535.   $p_header['index'] = -1;
  1536.  
  1537.   if ($p_filedescr['type']=='file') {
  1538.     $p_header['external'] = 0x00000000;
  1539.     $p_header['size'] = filesize($p_filename);
  1540.   }
  1541.  
  1542.   else if ($p_filedescr['type']=='folder') {
  1543.     $p_header['external'] = 0x00000010;
  1544.     $p_header['mtime'] = filemtime($p_filename);
  1545.     $p_header['size'] = filesize($p_filename);
  1546.   }
  1547.  
  1548.   else if ($p_filedescr['type'] == 'virtual_file') {
  1549.     $p_header['external'] = 0x00000000;
  1550.     $p_header['size'] = strlen($p_filedescr['content']);
  1551.   }
  1552.  
  1553.  
  1554.   if (isset($p_filedescr['mtime'])) {
  1555.     $p_header['mtime'] = $p_filedescr['mtime'];
  1556.   }
  1557.   else if ($p_filedescr['type'] == 'virtual_file') {
  1558.     $p_header['mtime'] = time();
  1559.   }
  1560.   else {
  1561.     $p_header['mtime'] = filemtime($p_filename);
  1562.   }
  1563.  
  1564.   if (isset($p_filedescr['comment'])) {
  1565.     $p_header['comment_len'] = strlen($p_filedescr['comment']);
  1566.     $p_header['comment'] = $p_filedescr['comment'];
  1567.   }
  1568.   else {
  1569.     $p_header['comment_len'] = 0;
  1570.     $p_header['comment'] = '';
  1571.   }
  1572.  
  1573.   if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
  1574.  
  1575.     $v_local_header = array();
  1576.     $this->privConvertHeader2FileInfo($p_header, $v_local_header);
  1577.  
  1578.     $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
  1579.     if ($v_result == 0) {
  1580.       $p_header['status'] = "skipped";
  1581.       $v_result = 1;
  1582.     }
  1583.  
  1584.     if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
  1585.       $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
  1586.     }
  1587.   }
  1588.  
  1589.   if ($p_header['stored_filename'] == "") {
  1590.     $p_header['status'] = "filtered";
  1591.   }
  1592.  
  1593.   if (strlen($p_header['stored_filename']) > 0xFF) {
  1594.     $p_header['status'] = 'filename_too_long';
  1595.   }
  1596.  
  1597.   if ($p_header['status'] == 'ok') {
  1598.  
  1599.     if ($p_filedescr['type'] == 'file') {
  1600.       if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
  1601.           && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
  1602.               || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
  1603.                   && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
  1604.         $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
  1605.         if ($v_result < PCLZIP_ERR_NO_ERROR) {
  1606.           return $v_result;
  1607.         }
  1608.       }
  1609.      
  1610.       else {
  1611.  
  1612.       if (($v_file = @fopen($p_filename, "rb")) == 0) {
  1613.         PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
  1614.         return PclZip::errorCode();
  1615.       }
  1616.  
  1617.       $v_content = @fread($v_file, $p_header['size']);
  1618.  
  1619.       @fclose($v_file);
  1620.  
  1621.       $p_header['crc'] = @crc32($v_content);
  1622.      
  1623.       if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
  1624.         $p_header['compressed_size'] = $p_header['size'];
  1625.         $p_header['compression'] = 0;
  1626.       }
  1627.      
  1628.       else {
  1629.         $v_content = @gzdeflate($v_content);
  1630.  
  1631.         $p_header['compressed_size'] = strlen($v_content);
  1632.         $p_header['compression'] = 8;
  1633.       }
  1634.      
  1635.       if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  1636.         @fclose($v_file);
  1637.         return $v_result;
  1638.       }
  1639.  
  1640.       @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
  1641.  
  1642.       }
  1643.  
  1644.     }
  1645.  
  1646.     else if ($p_filedescr['type'] == 'virtual_file') {
  1647.        
  1648.       $v_content = $p_filedescr['content'];
  1649.  
  1650.       $p_header['crc'] = @crc32($v_content);
  1651.      
  1652.       if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
  1653.         $p_header['compressed_size'] = $p_header['size'];
  1654.         $p_header['compression'] = 0;
  1655.       }
  1656.      
  1657.       else {
  1658.         $v_content = @gzdeflate($v_content);
  1659.  
  1660.         $p_header['compressed_size'] = strlen($v_content);
  1661.         $p_header['compression'] = 8;
  1662.       }
  1663.      
  1664.       if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  1665.         @fclose($v_file);
  1666.         return $v_result;
  1667.       }
  1668.  
  1669.       @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
  1670.     }
  1671.  
  1672.     else if ($p_filedescr['type'] == 'folder') {
  1673.       if (@substr($p_header['stored_filename'], -1) != '/') {
  1674.         $p_header['stored_filename'] .= '/';
  1675.       }
  1676.  
  1677.       $p_header['size'] = 0;
  1678.  
  1679.       if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
  1680.       {
  1681.         return $v_result;
  1682.       }
  1683.     }
  1684.   }
  1685.  
  1686.   if (isset($p_options[PCLZIP_CB_POST_ADD])) {
  1687.  
  1688.     $v_local_header = array();
  1689.     $this->privConvertHeader2FileInfo($p_header, $v_local_header);
  1690.  
  1691.     $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
  1692.     if ($v_result == 0) {
  1693.       $v_result = 1;
  1694.     }
  1695.  
  1696.   }
  1697.  
  1698.   return $v_result;
  1699. }
  1700.  
  1701. function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
  1702. {
  1703.   $v_result=PCLZIP_ERR_NO_ERROR;
  1704.  
  1705.   $p_filename = $p_filedescr['filename'];
  1706.  
  1707.  
  1708.   if (($v_file = @fopen($p_filename, "rb")) == 0) {
  1709.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
  1710.     return PclZip::errorCode();
  1711.   }
  1712.  
  1713.   $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
  1714.   if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
  1715.     fclose($v_file);
  1716.     PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
  1717.     return PclZip::errorCode();
  1718.   }
  1719.  
  1720.   $v_size = filesize($p_filename);
  1721.   while ($v_size != 0) {
  1722.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  1723.     $v_buffer = @fread($v_file, $v_read_size);
  1724.     @gzputs($v_file_compressed, $v_buffer, $v_read_size);
  1725.     $v_size -= $v_read_size;
  1726.   }
  1727.  
  1728.   @fclose($v_file);
  1729.   @gzclose($v_file_compressed);
  1730.  
  1731.   if (filesize($v_gzip_temp_name) < 18) {
  1732.     PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
  1733.     return PclZip::errorCode();
  1734.   }
  1735.  
  1736.   if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
  1737.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
  1738.     return PclZip::errorCode();
  1739.   }
  1740.  
  1741.   $v_binary_data = @fread($v_file_compressed, 10);
  1742.   $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
  1743.  
  1744.   $v_data_header['os'] = bin2hex($v_data_header['os']);
  1745.  
  1746.   @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
  1747.   $v_binary_data = @fread($v_file_compressed, 8);
  1748.   $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
  1749.  
  1750.   $p_header['compression'] = ord($v_data_header['cm']);
  1751.   $p_header['crc'] = $v_data_footer['crc'];
  1752.   $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
  1753.  
  1754.   @fclose($v_file_compressed);
  1755.  
  1756.   if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  1757.     return $v_result;
  1758.   }
  1759.  
  1760.   if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
  1761.   {
  1762.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
  1763.     return PclZip::errorCode();
  1764.   }
  1765.  
  1766.   fseek($v_file_compressed, 10);
  1767.   $v_size = $p_header['compressed_size'];
  1768.   while ($v_size != 0)
  1769.   {
  1770.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  1771.     $v_buffer = @fread($v_file_compressed, $v_read_size);
  1772.     @fwrite($this->zip_fd, $v_buffer, $v_read_size);
  1773.     $v_size -= $v_read_size;
  1774.   }
  1775.  
  1776.   @fclose($v_file_compressed);
  1777.  
  1778.   @unlink($v_gzip_temp_name);
  1779.  
  1780.   return $v_result;
  1781. }
  1782.  
  1783. function privCalculateStoredFilename(&$p_filedescr, &$p_options)
  1784. {
  1785.   $v_result=1;
  1786.  
  1787.   $p_filename = $p_filedescr['filename'];
  1788.   if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
  1789.     $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
  1790.   }
  1791.   else {
  1792.     $p_add_dir = '';
  1793.   }
  1794.   if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
  1795.     $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
  1796.   }
  1797.   else {
  1798.     $p_remove_dir = '';
  1799.   }
  1800.   if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  1801.     $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  1802.   }
  1803.   else {
  1804.     $p_remove_all_dir = 0;
  1805.   }
  1806.  
  1807.  
  1808.   if (isset($p_filedescr['new_full_name'])) {
  1809.     $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
  1810.   }
  1811.  
  1812.   else {
  1813.  
  1814.     if (isset($p_filedescr['new_short_name'])) {
  1815.       $v_path_info = pathinfo($p_filename);
  1816.       $v_dir = '';
  1817.       if ($v_path_info['dirname'] != '') {
  1818.         $v_dir = $v_path_info['dirname'].'/';
  1819.       }
  1820.       $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
  1821.     }
  1822.     else {
  1823.       $v_stored_filename = $p_filename;
  1824.     }
  1825.  
  1826.     if ($p_remove_all_dir) {
  1827.       $v_stored_filename = basename($p_filename);
  1828.     }
  1829.     else if ($p_remove_dir != "") {
  1830.       if (substr($p_remove_dir, -1) != '/')
  1831.         $p_remove_dir .= "/";
  1832.  
  1833.       if (   (substr($p_filename, 0, 2) == "./")
  1834.           || (substr($p_remove_dir, 0, 2) == "./")) {
  1835.          
  1836.         if (   (substr($p_filename, 0, 2) == "./")
  1837.             && (substr($p_remove_dir, 0, 2) != "./")) {
  1838.           $p_remove_dir = "./".$p_remove_dir;
  1839.         }
  1840.         if (   (substr($p_filename, 0, 2) != "./")
  1841.             && (substr($p_remove_dir, 0, 2) == "./")) {
  1842.           $p_remove_dir = substr($p_remove_dir, 2);
  1843.         }
  1844.       }
  1845.  
  1846.       $v_compare = PclZipUtilPathInclusion($p_remove_dir,
  1847.                                            $v_stored_filename);
  1848.       if ($v_compare > 0) {
  1849.         if ($v_compare == 2) {
  1850.           $v_stored_filename = "";
  1851.         }
  1852.         else {
  1853.           $v_stored_filename = substr($v_stored_filename,
  1854.                                       strlen($p_remove_dir));
  1855.         }
  1856.       }
  1857.     }
  1858.    
  1859.     $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
  1860.    
  1861.     if ($p_add_dir != "") {
  1862.       if (substr($p_add_dir, -1) == "/")
  1863.         $v_stored_filename = $p_add_dir.$v_stored_filename;
  1864.       else
  1865.         $v_stored_filename = $p_add_dir."/".$v_stored_filename;
  1866.     }
  1867.   }
  1868.  
  1869.   $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
  1870.   $p_filedescr['stored_filename'] = $v_stored_filename;
  1871.  
  1872.   return $v_result;
  1873. }
  1874.  
  1875. function privWriteFileHeader(&$p_header)
  1876. {
  1877.   $v_result=1;
  1878.  
  1879.   $p_header['offset'] = ftell($this->zip_fd);
  1880.  
  1881.   $v_date = getdate($p_header['mtime']);
  1882.   $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
  1883.   $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
  1884.  
  1885.   $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
  1886.                       $p_header['version_extracted'], $p_header['flag'],
  1887.                         $p_header['compression'], $v_mtime, $v_mdate,
  1888.                         $p_header['crc'], $p_header['compressed_size'],
  1889.                       $p_header['size'],
  1890.                         strlen($p_header['stored_filename']),
  1891.                       $p_header['extra_len']);
  1892.  
  1893.   fputs($this->zip_fd, $v_binary_data, 30);
  1894.  
  1895.   if (strlen($p_header['stored_filename']) != 0)
  1896.   {
  1897.     fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
  1898.   }
  1899.   if ($p_header['extra_len'] != 0)
  1900.   {
  1901.     fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
  1902.   }
  1903.  
  1904.   return $v_result;
  1905. }
  1906.  
  1907. function privWriteCentralFileHeader(&$p_header)
  1908. {
  1909.   $v_result=1;
  1910.  
  1911.   $v_date = getdate($p_header['mtime']);
  1912.   $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
  1913.   $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
  1914.  
  1915.  
  1916.   $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
  1917.                       $p_header['version'], $p_header['version_extracted'],
  1918.                         $p_header['flag'], $p_header['compression'],
  1919.                       $v_mtime, $v_mdate, $p_header['crc'],
  1920.                         $p_header['compressed_size'], $p_header['size'],
  1921.                         strlen($p_header['stored_filename']),
  1922.                       $p_header['extra_len'], $p_header['comment_len'],
  1923.                         $p_header['disk'], $p_header['internal'],
  1924.                       $p_header['external'], $p_header['offset']);
  1925.  
  1926.   fputs($this->zip_fd, $v_binary_data, 46);
  1927.  
  1928.   if (strlen($p_header['stored_filename']) != 0)
  1929.   {
  1930.     fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
  1931.   }
  1932.   if ($p_header['extra_len'] != 0)
  1933.   {
  1934.     fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
  1935.   }
  1936.   if ($p_header['comment_len'] != 0)
  1937.   {
  1938.     fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
  1939.   }
  1940.  
  1941.   return $v_result;
  1942. }
  1943.  
  1944. function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
  1945. {
  1946.   $v_result=1;
  1947.  
  1948.   $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
  1949.                       $p_nb_entries, $p_size,
  1950.                       $p_offset, strlen($p_comment));
  1951.  
  1952.   fputs($this->zip_fd, $v_binary_data, 22);
  1953.  
  1954.   if (strlen($p_comment) != 0)
  1955.   {
  1956.     fputs($this->zip_fd, $p_comment, strlen($p_comment));
  1957.   }
  1958.  
  1959.   return $v_result;
  1960. }
  1961.  
  1962. function privList(&$p_list)
  1963. {
  1964.   $v_result=1;
  1965.  
  1966.   $this->privDisableMagicQuotes();
  1967.  
  1968.   if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
  1969.   {
  1970.     $this->privSwapBackMagicQuotes();
  1971.    
  1972.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
  1973.  
  1974.     return PclZip::errorCode();
  1975.   }
  1976.  
  1977.   $v_central_dir = array();
  1978.   if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  1979.   {
  1980.     $this->privSwapBackMagicQuotes();
  1981.     return $v_result;
  1982.   }
  1983.  
  1984.   @rewind($this->zip_fd);
  1985.   if (@fseek($this->zip_fd, $v_central_dir['offset']))
  1986.   {
  1987.     $this->privSwapBackMagicQuotes();
  1988.  
  1989.     PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  1990.  
  1991.     return PclZip::errorCode();
  1992.   }
  1993.  
  1994.   for ($i=0; $i<$v_central_dir['entries']; $i++)
  1995.   {
  1996.     if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
  1997.     {
  1998.       $this->privSwapBackMagicQuotes();
  1999.       return $v_result;
  2000.     }
  2001.     $v_header['index'] = $i;
  2002.  
  2003.     $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
  2004.     unset($v_header);
  2005.   }
  2006.  
  2007.   $this->privCloseFd();
  2008.  
  2009.   $this->privSwapBackMagicQuotes();
  2010.  
  2011.   return $v_result;
  2012. }
  2013.  
  2014. function privConvertHeader2FileInfo($p_header, &$p_info)
  2015. {
  2016.   $v_result=1;
  2017.  
  2018.   $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
  2019.   $p_info['filename'] = $v_temp_path;
  2020.   $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
  2021.   $p_info['stored_filename'] = $v_temp_path;
  2022.   $p_info['size'] = $p_header['size'];
  2023.   $p_info['compressed_size'] = $p_header['compressed_size'];
  2024.   $p_info['mtime'] = $p_header['mtime'];
  2025.   $p_info['comment'] = $p_header['comment'];
  2026.   $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
  2027.   $p_info['index'] = $p_header['index'];
  2028.   $p_info['status'] = $p_header['status'];
  2029.   $p_info['crc'] = $p_header['crc'];
  2030.  
  2031.   return $v_result;
  2032. }
  2033.  
  2034. function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
  2035. {
  2036.   $v_result=1;
  2037.  
  2038.   $this->privDisableMagicQuotes();
  2039.  
  2040.   if (   ($p_path == "")
  2041.     || (   (substr($p_path, 0, 1) != "/")
  2042.         && (substr($p_path, 0, 3) != "../")
  2043.         && (substr($p_path,1,2)!=":/")))
  2044.     $p_path = "./".$p_path;
  2045.  
  2046.   if (($p_path != "./") && ($p_path != "/"))
  2047.   {
  2048.     while (substr($p_path, -1) == "/")
  2049.     {
  2050.       $p_path = substr($p_path, 0, strlen($p_path)-1);
  2051.     }
  2052.   }
  2053.  
  2054.   if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
  2055.   {
  2056.     $p_remove_path .= '/';
  2057.   }
  2058.   $p_remove_path_size = strlen($p_remove_path);
  2059.  
  2060.   if (($v_result = $this->privOpenFd('rb')) != 1)
  2061.   {
  2062.     $this->privSwapBackMagicQuotes();
  2063.     return $v_result;
  2064.   }
  2065.  
  2066.   $v_central_dir = array();
  2067.   if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  2068.   {
  2069.     $this->privCloseFd();
  2070.     $this->privSwapBackMagicQuotes();
  2071.  
  2072.     return $v_result;
  2073.   }
  2074.  
  2075.   $v_pos_entry = $v_central_dir['offset'];
  2076.  
  2077.   $j_start = 0;
  2078.   for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
  2079.   {
  2080.  
  2081.     @rewind($this->zip_fd);
  2082.     if (@fseek($this->zip_fd, $v_pos_entry))
  2083.     {
  2084.       $this->privCloseFd();
  2085.       $this->privSwapBackMagicQuotes();
  2086.  
  2087.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  2088.  
  2089.       return PclZip::errorCode();
  2090.     }
  2091.  
  2092.     $v_header = array();
  2093.     if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
  2094.     {
  2095.       $this->privCloseFd();
  2096.       $this->privSwapBackMagicQuotes();
  2097.  
  2098.       return $v_result;
  2099.     }
  2100.  
  2101.     $v_header['index'] = $i;
  2102.  
  2103.     $v_pos_entry = ftell($this->zip_fd);
  2104.  
  2105.     $v_extract = false;
  2106.  
  2107.     if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
  2108.         && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
  2109.  
  2110.         for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
  2111.  
  2112.             if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
  2113.  
  2114.                 if (   (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
  2115.                     && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  2116.                     $v_extract = true;
  2117.                 }
  2118.             }
  2119.             elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
  2120.                 $v_extract = true;
  2121.             }
  2122.         }
  2123.     }
  2124.  
  2125.  
  2126.     else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
  2127.              && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
  2128.  
  2129.         if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
  2130.             $v_extract = true;
  2131.         }
  2132.     }
  2133.  
  2134.     else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
  2135.              && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
  2136.        
  2137.         for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
  2138.  
  2139.             if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
  2140.                 $v_extract = true;
  2141.             }
  2142.             if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
  2143.                 $j_start = $j+1;
  2144.             }
  2145.  
  2146.             if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
  2147.                 break;
  2148.             }
  2149.         }
  2150.     }
  2151.  
  2152.     else {
  2153.         $v_extract = true;
  2154.     }
  2155.  
  2156.   if (   ($v_extract)
  2157.       && (   ($v_header['compression'] != 8)
  2158.           && ($v_header['compression'] != 0))) {
  2159.         $v_header['status'] = 'unsupported_compression';
  2160.  
  2161.         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2162.           && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2163.  
  2164.             $this->privSwapBackMagicQuotes();
  2165.            
  2166.             PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
  2167.                                "Filename '".$v_header['stored_filename']."' is "
  2168.                                ."compressed by an unsupported compression "
  2169.                                ."method (".$v_header['compression'].") ");
  2170.  
  2171.             return PclZip::errorCode();
  2172.       }
  2173.   }
  2174.  
  2175.   if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
  2176.         $v_header['status'] = 'unsupported_encryption';
  2177.  
  2178.         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2179.           && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2180.  
  2181.             $this->privSwapBackMagicQuotes();
  2182.  
  2183.             PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
  2184.                                "Unsupported encryption for "
  2185.                                ." filename '".$v_header['stored_filename']
  2186.                                ."'");
  2187.  
  2188.             return PclZip::errorCode();
  2189.       }
  2190.   }
  2191.  
  2192.     if (($v_extract) && ($v_header['status'] != 'ok')) {
  2193.         $v_result = $this->privConvertHeader2FileInfo($v_header,
  2194.                                             $p_file_list[$v_nb_extracted++]);
  2195.         if ($v_result != 1) {
  2196.             $this->privCloseFd();
  2197.             $this->privSwapBackMagicQuotes();
  2198.             return $v_result;
  2199.         }
  2200.  
  2201.         $v_extract = false;
  2202.     }
  2203.    
  2204.     if ($v_extract)
  2205.     {
  2206.  
  2207.       @rewind($this->zip_fd);
  2208.       if (@fseek($this->zip_fd, $v_header['offset']))
  2209.       {
  2210.         $this->privCloseFd();
  2211.  
  2212.         $this->privSwapBackMagicQuotes();
  2213.  
  2214.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  2215.  
  2216.         return PclZip::errorCode();
  2217.       }
  2218.  
  2219.       if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
  2220.  
  2221.         $v_string = '';
  2222.  
  2223.         $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
  2224.         if ($v_result1 < 1) {
  2225.           $this->privCloseFd();
  2226.           $this->privSwapBackMagicQuotes();
  2227.           return $v_result1;
  2228.         }
  2229.  
  2230.         if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
  2231.         {
  2232.           $this->privCloseFd();
  2233.           $this->privSwapBackMagicQuotes();
  2234.  
  2235.           return $v_result;
  2236.         }
  2237.  
  2238.         $p_file_list[$v_nb_extracted]['content'] = $v_string;
  2239.  
  2240.         $v_nb_extracted++;
  2241.        
  2242.         if ($v_result1 == 2) {
  2243.             break;
  2244.         }
  2245.       }
  2246.       elseif (   (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
  2247.             && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
  2248.         $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
  2249.         if ($v_result1 < 1) {
  2250.           $this->privCloseFd();
  2251.           $this->privSwapBackMagicQuotes();
  2252.           return $v_result1;
  2253.         }
  2254.  
  2255.         if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
  2256.           $this->privCloseFd();
  2257.           $this->privSwapBackMagicQuotes();
  2258.           return $v_result;
  2259.         }
  2260.  
  2261.         if ($v_result1 == 2) {
  2262.             break;
  2263.         }
  2264.       }
  2265.       else {
  2266.         $v_result1 = $this->privExtractFile($v_header,
  2267.                                           $p_path, $p_remove_path,
  2268.                                           $p_remove_all_path,
  2269.                                           $p_options);
  2270.         if ($v_result1 < 1) {
  2271.           $this->privCloseFd();
  2272.           $this->privSwapBackMagicQuotes();
  2273.           return $v_result1;
  2274.         }
  2275.  
  2276.         if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
  2277.         {
  2278.           $this->privCloseFd();
  2279.           $this->privSwapBackMagicQuotes();
  2280.  
  2281.           return $v_result;
  2282.         }
  2283.  
  2284.         if ($v_result1 == 2) {
  2285.             break;
  2286.         }
  2287.       }
  2288.     }
  2289.   }
  2290.  
  2291.   $this->privCloseFd();
  2292.   $this->privSwapBackMagicQuotes();
  2293.  
  2294.   return $v_result;
  2295. }
  2296.  
  2297. function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
  2298. {
  2299.   $v_result=1;
  2300.  
  2301.   if (($v_result = $this->privReadFileHeader($v_header)) != 1)
  2302.   {
  2303.     return $v_result;
  2304.   }
  2305.  
  2306.  
  2307.   if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
  2308.   }
  2309.  
  2310.   if ($p_remove_all_path == true) {
  2311.       if (($p_entry['external']&0x00000010)==0x00000010) {
  2312.  
  2313.           $p_entry['status'] = "filtered";
  2314.  
  2315.           return $v_result;
  2316.       }
  2317.  
  2318.       $p_entry['filename'] = basename($p_entry['filename']);
  2319.   }
  2320.  
  2321.   else if ($p_remove_path != "")
  2322.   {
  2323.     if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
  2324.     {
  2325.  
  2326.       $p_entry['status'] = "filtered";
  2327.  
  2328.       return $v_result;
  2329.     }
  2330.  
  2331.     $p_remove_path_size = strlen($p_remove_path);
  2332.     if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
  2333.     {
  2334.  
  2335.       $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
  2336.  
  2337.     }
  2338.   }
  2339.  
  2340.   if ($p_path != '') {
  2341.     $p_entry['filename'] = $p_path."/".$p_entry['filename'];
  2342.   }
  2343.  
  2344.   if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
  2345.     $v_inclusion
  2346.     = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
  2347.                               $p_entry['filename']);
  2348.     if ($v_inclusion == 0) {
  2349.  
  2350.       PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
  2351.                              "Filename '".$p_entry['filename']."' is "
  2352.                              ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
  2353.  
  2354.       return PclZip::errorCode();
  2355.     }
  2356.   }
  2357.  
  2358.   if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
  2359.  
  2360.     $v_local_header = array();
  2361.     $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2362.  
  2363.     $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
  2364.     if ($v_result == 0) {
  2365.       $p_entry['status'] = "skipped";
  2366.       $v_result = 1;
  2367.     }
  2368.    
  2369.     if ($v_result == 2) {
  2370.       $p_entry['status'] = "aborted";
  2371.         $v_result = PCLZIP_ERR_USER_ABORTED;
  2372.     }
  2373.  
  2374.     $p_entry['filename'] = $v_local_header['filename'];
  2375.   }
  2376.  
  2377.  
  2378.   if ($p_entry['status'] == 'ok') {
  2379.  
  2380.   if (file_exists($p_entry['filename']))
  2381.   {
  2382.  
  2383.     if (is_dir($p_entry['filename']))
  2384.     {
  2385.  
  2386.       $p_entry['status'] = "already_a_directory";
  2387.      
  2388.       if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2389.         && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2390.  
  2391.           PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
  2392.                              "Filename '".$p_entry['filename']."' is "
  2393.                              ."already used by an existing directory");
  2394.  
  2395.           return PclZip::errorCode();
  2396.         }
  2397.     }
  2398.     else if (!is_writeable($p_entry['filename']))
  2399.     {
  2400.  
  2401.       $p_entry['status'] = "write_protected";
  2402.  
  2403.       if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2404.         && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2405.  
  2406.           PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
  2407.                              "Filename '".$p_entry['filename']."' exists "
  2408.                              ."and is write protected");
  2409.  
  2410.           return PclZip::errorCode();
  2411.         }
  2412.     }
  2413.  
  2414.     else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
  2415.     {
  2416.       if (   (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
  2417.         && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
  2418.       }
  2419.         else {
  2420.           $p_entry['status'] = "newer_exist";
  2421.  
  2422.           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2423.             && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2424.  
  2425.               PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
  2426.                      "Newer version of '".$p_entry['filename']."' exists "
  2427.                     ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
  2428.  
  2429.               return PclZip::errorCode();
  2430.           }
  2431.         }
  2432.     }
  2433.     else {
  2434.     }
  2435.   }
  2436.  
  2437.   else {
  2438.     if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
  2439.       $v_dir_to_check = $p_entry['filename'];
  2440.     else if (!strstr($p_entry['filename'], "/"))
  2441.       $v_dir_to_check = "";
  2442.     else
  2443.       $v_dir_to_check = dirname($p_entry['filename']);
  2444.  
  2445.       if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
  2446.  
  2447.         $p_entry['status'] = "path_creation_fail";
  2448.  
  2449.         $v_result = 1;
  2450.       }
  2451.     }
  2452.   }
  2453.  
  2454.   if ($p_entry['status'] == 'ok') {
  2455.  
  2456.     if (!(($p_entry['external']&0x00000010)==0x00000010))
  2457.     {
  2458.       if ($p_entry['compression'] == 0) {
  2459.  
  2460.         if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
  2461.         {
  2462.  
  2463.           $p_entry['status'] = "write_error";
  2464.  
  2465.           return $v_result;
  2466.         }
  2467.  
  2468.  
  2469.         $v_size = $p_entry['compressed_size'];
  2470.         while ($v_size != 0)
  2471.         {
  2472.           $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  2473.           $v_buffer = @fread($this->zip_fd, $v_read_size);
  2474.           @fwrite($v_dest_file, $v_buffer, $v_read_size);            
  2475.           $v_size -= $v_read_size;
  2476.         }
  2477.  
  2478.         fclose($v_dest_file);
  2479.  
  2480.         touch($p_entry['filename'], $p_entry['mtime']);
  2481.        
  2482.  
  2483.       }
  2484.       else {
  2485.         if (($p_entry['flag'] & 1) == 1) {
  2486.           PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
  2487.           return PclZip::errorCode();
  2488.         }
  2489.  
  2490.  
  2491.         if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
  2492.             && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
  2493.                 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
  2494.                     && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
  2495.           $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
  2496.           if ($v_result < PCLZIP_ERR_NO_ERROR) {
  2497.             return $v_result;
  2498.           }
  2499.         }
  2500.        
  2501.         else {
  2502.  
  2503.        
  2504.           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
  2505.          
  2506.           $v_file_content = @gzinflate($v_buffer);
  2507.           unset($v_buffer);
  2508.           if ($v_file_content === FALSE) {
  2509.  
  2510.             $p_entry['status'] = "error";
  2511.            
  2512.             return $v_result;
  2513.           }
  2514.          
  2515.           if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
  2516.  
  2517.             $p_entry['status'] = "write_error";
  2518.  
  2519.             return $v_result;
  2520.           }
  2521.  
  2522.           @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
  2523.           unset($v_file_content);
  2524.  
  2525.           @fclose($v_dest_file);
  2526.          
  2527.         }
  2528.  
  2529.         @touch($p_entry['filename'], $p_entry['mtime']);
  2530.       }
  2531.  
  2532.       if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
  2533.  
  2534.         @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
  2535.       }
  2536.  
  2537.     }
  2538.   }
  2539.  
  2540.     if ($p_entry['status'] == "aborted") {
  2541.       $p_entry['status'] = "skipped";
  2542.     }
  2543.  
  2544.   elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
  2545.  
  2546.     $v_local_header = array();
  2547.     $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2548.  
  2549.     $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
  2550.  
  2551.     if ($v_result == 2) {
  2552.         $v_result = PCLZIP_ERR_USER_ABORTED;
  2553.     }
  2554.   }
  2555.  
  2556.   return $v_result;
  2557. }
  2558.  
  2559. function privExtractFileUsingTempFile(&$p_entry, &$p_options)
  2560. {
  2561.   $v_result=1;
  2562.      
  2563.   $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
  2564.   if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
  2565.     fclose($v_file);
  2566.     PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
  2567.     return PclZip::errorCode();
  2568.   }
  2569.  
  2570.  
  2571.   $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
  2572.   @fwrite($v_dest_file, $v_binary_data, 10);
  2573.  
  2574.   $v_size = $p_entry['compressed_size'];
  2575.   while ($v_size != 0)
  2576.   {
  2577.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  2578.     $v_buffer = @fread($this->zip_fd, $v_read_size);
  2579.     @fwrite($v_dest_file, $v_buffer, $v_read_size);
  2580.     $v_size -= $v_read_size;
  2581.   }
  2582.  
  2583.   $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
  2584.   @fwrite($v_dest_file, $v_binary_data, 8);
  2585.  
  2586.   @fclose($v_dest_file);
  2587.  
  2588.   if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
  2589.     $p_entry['status'] = "write_error";
  2590.     return $v_result;
  2591.   }
  2592.  
  2593.   if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
  2594.     @fclose($v_dest_file);
  2595.     $p_entry['status'] = "read_error";
  2596.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
  2597.     return PclZip::errorCode();
  2598.   }
  2599.  
  2600.  
  2601.   $v_size = $p_entry['size'];
  2602.   while ($v_size != 0) {
  2603.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  2604.     $v_buffer = @gzread($v_src_file, $v_read_size);
  2605.     @fwrite($v_dest_file, $v_buffer, $v_read_size);
  2606.     $v_size -= $v_read_size;
  2607.   }
  2608.   @fclose($v_dest_file);
  2609.   @gzclose($v_src_file);
  2610.  
  2611.   @unlink($v_gzip_temp_name);
  2612.  
  2613.   return $v_result;
  2614. }
  2615.  
  2616. function privExtractFileInOutput(&$p_entry, &$p_options)
  2617. {
  2618.   $v_result=1;
  2619.  
  2620.   if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
  2621.     return $v_result;
  2622.   }
  2623.  
  2624.  
  2625.   if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
  2626.   }
  2627.  
  2628.   if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
  2629.  
  2630.     $v_local_header = array();
  2631.     $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2632.  
  2633.     $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
  2634.     if ($v_result == 0) {
  2635.       $p_entry['status'] = "skipped";
  2636.       $v_result = 1;
  2637.     }
  2638.  
  2639.     if ($v_result == 2) {
  2640.       $p_entry['status'] = "aborted";
  2641.         $v_result = PCLZIP_ERR_USER_ABORTED;
  2642.     }
  2643.  
  2644.     $p_entry['filename'] = $v_local_header['filename'];
  2645.   }
  2646.  
  2647.  
  2648.   if ($p_entry['status'] == 'ok') {
  2649.  
  2650.     if (!(($p_entry['external']&0x00000010)==0x00000010)) {
  2651.       if ($p_entry['compressed_size'] == $p_entry['size']) {
  2652.  
  2653.         $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
  2654.  
  2655.         echo $v_buffer;
  2656.         unset($v_buffer);
  2657.       }
  2658.       else {
  2659.  
  2660.         $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
  2661.        
  2662.         $v_file_content = gzinflate($v_buffer);
  2663.         unset($v_buffer);
  2664.  
  2665.         echo $v_file_content;
  2666.         unset($v_file_content);
  2667.       }
  2668.     }
  2669.   }
  2670.  
  2671. if ($p_entry['status'] == "aborted") {
  2672.     $p_entry['status'] = "skipped";
  2673. }
  2674.  
  2675.   elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
  2676.  
  2677.     $v_local_header = array();
  2678.     $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2679.  
  2680.     $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
  2681.  
  2682.     if ($v_result == 2) {
  2683.         $v_result = PCLZIP_ERR_USER_ABORTED;
  2684.     }
  2685.   }
  2686.  
  2687.   return $v_result;
  2688. }
  2689.  
  2690. function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
  2691. {
  2692.   $v_result=1;
  2693.  
  2694.   $v_header = array();
  2695.   if (($v_result = $this->privReadFileHeader($v_header)) != 1)
  2696.   {
  2697.     return $v_result;
  2698.   }
  2699.  
  2700.  
  2701.   if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
  2702.   }
  2703.  
  2704.   if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
  2705.  
  2706.     $v_local_header = array();
  2707.     $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2708.  
  2709.     $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
  2710.     if ($v_result == 0) {
  2711.       $p_entry['status'] = "skipped";
  2712.       $v_result = 1;
  2713.     }
  2714.    
  2715.     if ($v_result == 2) {
  2716.       $p_entry['status'] = "aborted";
  2717.         $v_result = PCLZIP_ERR_USER_ABORTED;
  2718.     }
  2719.  
  2720.     $p_entry['filename'] = $v_local_header['filename'];
  2721.   }
  2722.  
  2723.  
  2724.   if ($p_entry['status'] == 'ok') {
  2725.  
  2726.     if (!(($p_entry['external']&0x00000010)==0x00000010)) {
  2727.       if ($p_entry['compression'] == 0) {
  2728.  
  2729.         $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
  2730.       }
  2731.       else {
  2732.  
  2733.         $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
  2734.        
  2735.         if (($p_string = @gzinflate($v_data)) === FALSE) {
  2736.         }
  2737.       }
  2738.  
  2739.     }
  2740.     else {
  2741.     }
  2742.    
  2743.   }
  2744.  
  2745.     if ($p_entry['status'] == "aborted") {
  2746.       $p_entry['status'] = "skipped";
  2747.     }
  2748.  
  2749.   elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
  2750.  
  2751.     $v_local_header = array();
  2752.     $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2753.    
  2754.     $v_local_header['content'] = $p_string;
  2755.     $p_string = '';
  2756.  
  2757.     $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
  2758.  
  2759.     $p_string = $v_local_header['content'];
  2760.     unset($v_local_header['content']);
  2761.  
  2762.     if ($v_result == 2) {
  2763.         $v_result = PCLZIP_ERR_USER_ABORTED;
  2764.     }
  2765.   }
  2766.  
  2767.   return $v_result;
  2768. }
  2769.  
  2770. function privReadFileHeader(&$p_header)
  2771. {
  2772.   $v_result=1;
  2773.  
  2774.   $v_binary_data = @fread($this->zip_fd, 4);
  2775.   $v_data = unpack('Vid', $v_binary_data);
  2776.  
  2777.   if ($v_data['id'] != 0x04034b50)
  2778.   {
  2779.  
  2780.     PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
  2781.  
  2782.     return PclZip::errorCode();
  2783.   }
  2784.  
  2785.   $v_binary_data = fread($this->zip_fd, 26);
  2786.  
  2787.   if (strlen($v_binary_data) != 26)
  2788.   {
  2789.     $p_header['filename'] = "";
  2790.     $p_header['status'] = "invalid_header";
  2791.  
  2792.     PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
  2793.  
  2794.     return PclZip::errorCode();
  2795.   }
  2796.  
  2797.   $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
  2798.  
  2799.   $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
  2800.  
  2801.   if ($v_data['extra_len'] != 0) {
  2802.     $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
  2803.   }
  2804.   else {
  2805.     $p_header['extra'] = '';
  2806.   }
  2807.  
  2808.   $p_header['version_extracted'] = $v_data['version'];
  2809.   $p_header['compression'] = $v_data['compression'];
  2810.   $p_header['size'] = $v_data['size'];
  2811.   $p_header['compressed_size'] = $v_data['compressed_size'];
  2812.   $p_header['crc'] = $v_data['crc'];
  2813.   $p_header['flag'] = $v_data['flag'];
  2814.   $p_header['filename_len'] = $v_data['filename_len'];
  2815.  
  2816.   $p_header['mdate'] = $v_data['mdate'];
  2817.   $p_header['mtime'] = $v_data['mtime'];
  2818.   if ($p_header['mdate'] && $p_header['mtime'])
  2819.   {
  2820.     $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
  2821.     $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
  2822.     $v_seconde = ($p_header['mtime'] & 0x001F)*2;
  2823.  
  2824.     $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
  2825.     $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
  2826.     $v_day = $p_header['mdate'] & 0x001F;
  2827.  
  2828.     $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
  2829.  
  2830.   }
  2831.   else
  2832.   {
  2833.     $p_header['mtime'] = time();
  2834.   }
  2835.  
  2836.  
  2837.   $p_header['stored_filename'] = $p_header['filename'];
  2838.  
  2839.   $p_header['status'] = "ok";
  2840.  
  2841.   return $v_result;
  2842. }
  2843.  
  2844. function privReadCentralFileHeader(&$p_header)
  2845. {
  2846.   $v_result=1;
  2847.  
  2848.   $v_binary_data = @fread($this->zip_fd, 4);
  2849.   $v_data = unpack('Vid', $v_binary_data);
  2850.  
  2851.   if ($v_data['id'] != 0x02014b50)
  2852.   {
  2853.  
  2854.     PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
  2855.  
  2856.     return PclZip::errorCode();
  2857.   }
  2858.  
  2859.   $v_binary_data = fread($this->zip_fd, 42);
  2860.  
  2861.   if (strlen($v_binary_data) != 42)
  2862.   {
  2863.     $p_header['filename'] = "";
  2864.     $p_header['status'] = "invalid_header";
  2865.  
  2866.     PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
  2867.  
  2868.     return PclZip::errorCode();
  2869.   }
  2870.  
  2871.   $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);
  2872.  
  2873.   if ($p_header['filename_len'] != 0)
  2874.     $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
  2875.   else
  2876.     $p_header['filename'] = '';
  2877.  
  2878.   if ($p_header['extra_len'] != 0)
  2879.     $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
  2880.   else
  2881.     $p_header['extra'] = '';
  2882.  
  2883.   if ($p_header['comment_len'] != 0)
  2884.     $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
  2885.   else
  2886.     $p_header['comment'] = '';
  2887.  
  2888.   if (1)
  2889.   {
  2890.     $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
  2891.     $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
  2892.     $v_seconde = ($p_header['mtime'] & 0x001F)*2;
  2893.  
  2894.     $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
  2895.     $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
  2896.     $v_day = $p_header['mdate'] & 0x001F;
  2897.  
  2898.     $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
  2899.  
  2900.   }
  2901.   else
  2902.   {
  2903.     $p_header['mtime'] = time();
  2904.   }
  2905.  
  2906.   $p_header['stored_filename'] = $p_header['filename'];
  2907.  
  2908.   $p_header['status'] = 'ok';
  2909.  
  2910.   if (substr($p_header['filename'], -1) == '/') {
  2911.     $p_header['external'] = 0x00000010;
  2912.   }
  2913.  
  2914.  
  2915.   return $v_result;
  2916. }
  2917.  
  2918. function privCheckFileHeaders(&$p_local_header, &$p_central_header)
  2919. {
  2920.   $v_result=1;
  2921.  
  2922.     if ($p_local_header['filename'] != $p_central_header['filename']) {
  2923.     }
  2924.     if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
  2925.     }
  2926.     if ($p_local_header['flag'] != $p_central_header['flag']) {
  2927.     }
  2928.     if ($p_local_header['compression'] != $p_central_header['compression']) {
  2929.     }
  2930.     if ($p_local_header['mtime'] != $p_central_header['mtime']) {
  2931.     }
  2932.     if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
  2933.     }
  2934.  
  2935.     if (($p_local_header['flag'] & 8) == 8) {
  2936.         $p_local_header['size'] = $p_central_header['size'];
  2937.         $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
  2938.         $p_local_header['crc'] = $p_central_header['crc'];
  2939.     }
  2940.  
  2941.   return $v_result;
  2942. }
  2943.  
  2944. function privReadEndCentralDir(&$p_central_dir)
  2945. {
  2946.   $v_result=1;
  2947.  
  2948.   $v_size = filesize($this->zipname);
  2949.   @fseek($this->zip_fd, $v_size);
  2950.   if (@ftell($this->zip_fd) != $v_size)
  2951.   {
  2952.     PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
  2953.  
  2954.     return PclZip::errorCode();
  2955.   }
  2956.  
  2957.   $v_found = 0;
  2958.   if ($v_size > 26) {
  2959.     @fseek($this->zip_fd, $v_size-22);
  2960.     if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
  2961.     {
  2962.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
  2963.  
  2964.       return PclZip::errorCode();
  2965.     }
  2966.  
  2967.     $v_binary_data = @fread($this->zip_fd, 4);
  2968.     $v_data = @unpack('Vid', $v_binary_data);
  2969.  
  2970.     if ($v_data['id'] == 0x06054b50) {
  2971.       $v_found = 1;
  2972.     }
  2973.  
  2974.     $v_pos = ftell($this->zip_fd);
  2975.   }
  2976.  
  2977.   if (!$v_found) {
  2978.     if ($v_maximum_size > $v_size)
  2979.       $v_maximum_size = $v_size;
  2980.     @fseek($this->zip_fd, $v_size-$v_maximum_size);
  2981.     if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
  2982.     {
  2983.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
  2984.  
  2985.       return PclZip::errorCode();
  2986.     }
  2987.  
  2988.     $v_pos = ftell($this->zip_fd);
  2989.     $v_bytes = 0x00000000;
  2990.     while ($v_pos < $v_size)
  2991.     {
  2992.       $v_byte = @fread($this->zip_fd, 1);
  2993.  
  2994.       $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
  2995.  
  2996.       if ($v_bytes == 0x504b0506)
  2997.       {
  2998.         $v_pos++;
  2999.         break;
  3000.       }
  3001.  
  3002.       $v_pos++;
  3003.     }
  3004.  
  3005.     if ($v_pos == $v_size)
  3006.     {
  3007.  
  3008.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
  3009.  
  3010.       return PclZip::errorCode();
  3011.     }
  3012.   }
  3013.  
  3014.   $v_binary_data = fread($this->zip_fd, 18);
  3015.  
  3016.   if (strlen($v_binary_data) != 18)
  3017.   {
  3018.  
  3019.     PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
  3020.  
  3021.     return PclZip::errorCode();
  3022.   }
  3023.  
  3024.   $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
  3025.  
  3026.   if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
  3027.  
  3028.   if (0) {
  3029.     PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
  3030.                        'The central dir is not at the end of the archive.'
  3031.                        .' Some trailing bytes exists after the archive.');
  3032.  
  3033.     return PclZip::errorCode();
  3034.   }
  3035.   }
  3036.  
  3037.   if ($v_data['comment_size'] != 0) {
  3038.     $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
  3039.   }
  3040.   else
  3041.     $p_central_dir['comment'] = '';
  3042.  
  3043.   $p_central_dir['entries'] = $v_data['entries'];
  3044.   $p_central_dir['disk_entries'] = $v_data['disk_entries'];
  3045.   $p_central_dir['offset'] = $v_data['offset'];
  3046.   $p_central_dir['size'] = $v_data['size'];
  3047.   $p_central_dir['disk'] = $v_data['disk'];
  3048.   $p_central_dir['disk_start'] = $v_data['disk_start'];
  3049.  
  3050.  
  3051.   return $v_result;
  3052. }
  3053.  
  3054. function privDeleteByRule(&$p_result_list, &$p_options)
  3055. {
  3056.   $v_result=1;
  3057.   $v_list_detail = array();
  3058.  
  3059.   if (($v_result=$this->privOpenFd('rb')) != 1)
  3060.   {
  3061.     return $v_result;
  3062.   }
  3063.  
  3064.   $v_central_dir = array();
  3065.   if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  3066.   {
  3067.     $this->privCloseFd();
  3068.     return $v_result;
  3069.   }
  3070.  
  3071.   @rewind($this->zip_fd);
  3072.  
  3073.   $v_pos_entry = $v_central_dir['offset'];
  3074.   @rewind($this->zip_fd);
  3075.   if (@fseek($this->zip_fd, $v_pos_entry))
  3076.   {
  3077.     $this->privCloseFd();
  3078.  
  3079.     PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  3080.  
  3081.     return PclZip::errorCode();
  3082.   }
  3083.  
  3084.   $v_header_list = array();
  3085.   $j_start = 0;
  3086.   for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
  3087.   {
  3088.  
  3089.     $v_header_list[$v_nb_extracted] = array();
  3090.     if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
  3091.     {
  3092.       $this->privCloseFd();
  3093.  
  3094.       return $v_result;
  3095.     }
  3096.  
  3097.  
  3098.     $v_header_list[$v_nb_extracted]['index'] = $i;
  3099.  
  3100.     $v_found = false;
  3101.  
  3102.     if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
  3103.         && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
  3104.  
  3105.         for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
  3106.  
  3107.             if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
  3108.  
  3109.                 if (   (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
  3110.                     && (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])) {
  3111.                     $v_found = true;
  3112.                 }
  3113.                 elseif (   (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010)
  3114.                         && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  3115.                     $v_found = true;
  3116.                 }
  3117.             }
  3118.             elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
  3119.                 $v_found = true;
  3120.             }
  3121.         }
  3122.     }
  3123.  
  3124.  
  3125.     else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
  3126.              && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
  3127.  
  3128.         if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
  3129.             $v_found = true;
  3130.         }
  3131.     }
  3132.  
  3133.     else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
  3134.              && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
  3135.  
  3136.         for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
  3137.  
  3138.             if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
  3139.                 $v_found = true;
  3140.             }
  3141.             if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
  3142.                 $j_start = $j+1;
  3143.             }
  3144.  
  3145.             if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
  3146.                 break;
  3147.             }
  3148.         }
  3149.     }
  3150.     else {
  3151.         $v_found = true;
  3152.     }
  3153.  
  3154.     if ($v_found)
  3155.     {
  3156.       unset($v_header_list[$v_nb_extracted]);
  3157.     }
  3158.     else
  3159.     {
  3160.       $v_nb_extracted++;
  3161.     }
  3162.   }
  3163.  
  3164.   if ($v_nb_extracted > 0) {
  3165.  
  3166.       $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  3167.  
  3168.       $v_temp_zip = new PclZip($v_zip_temp_name);
  3169.  
  3170.       if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
  3171.           $this->privCloseFd();
  3172.  
  3173.           return $v_result;
  3174.       }
  3175.  
  3176.       for ($i=0; $i<sizeof($v_header_list); $i++) {
  3177.  
  3178.           @rewind($this->zip_fd);
  3179.           if (@fseek($this->zip_fd,  $v_header_list[$i]['offset'])) {
  3180.               $this->privCloseFd();
  3181.               $v_temp_zip->privCloseFd();
  3182.               @unlink($v_zip_temp_name);
  3183.  
  3184.               PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  3185.  
  3186.               return PclZip::errorCode();
  3187.           }
  3188.  
  3189.           $v_local_header = array();
  3190.           if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
  3191.               $this->privCloseFd();
  3192.               $v_temp_zip->privCloseFd();
  3193.               @unlink($v_zip_temp_name);
  3194.  
  3195.               return $v_result;
  3196.           }
  3197.          
  3198.           if ($this->privCheckFileHeaders($v_local_header,
  3199.                                         $v_header_list[$i]) != 1) {
  3200.           }
  3201.           unset($v_local_header);
  3202.  
  3203.           if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
  3204.               $this->privCloseFd();
  3205.               $v_temp_zip->privCloseFd();
  3206.               @unlink($v_zip_temp_name);
  3207.  
  3208.               return $v_result;
  3209.           }
  3210.  
  3211.           if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
  3212.               $this->privCloseFd();
  3213.               $v_temp_zip->privCloseFd();
  3214.               @unlink($v_zip_temp_name);
  3215.  
  3216.               return $v_result;
  3217.           }
  3218.       }
  3219.  
  3220.       $v_offset = @ftell($v_temp_zip->zip_fd);
  3221.  
  3222.       for ($i=0; $i<sizeof($v_header_list); $i++) {
  3223.           if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
  3224.               $v_temp_zip->privCloseFd();
  3225.               $this->privCloseFd();
  3226.               @unlink($v_zip_temp_name);
  3227.  
  3228.               return $v_result;
  3229.           }
  3230.  
  3231.           $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
  3232.       }
  3233.  
  3234.  
  3235.       $v_comment = '';
  3236.       if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  3237.         $v_comment = $p_options[PCLZIP_OPT_COMMENT];
  3238.       }
  3239.  
  3240.       $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
  3241.  
  3242.       if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
  3243.           unset($v_header_list);
  3244.           $v_temp_zip->privCloseFd();
  3245.           $this->privCloseFd();
  3246.           @unlink($v_zip_temp_name);
  3247.  
  3248.           return $v_result;
  3249.       }
  3250.  
  3251.       $v_temp_zip->privCloseFd();
  3252.       $this->privCloseFd();
  3253.  
  3254.       @unlink($this->zipname);
  3255.  
  3256.       PclZipUtilRename($v_zip_temp_name, $this->zipname);
  3257.  
  3258.       unset($v_temp_zip);
  3259.   }
  3260.  
  3261.   else if ($v_central_dir['entries'] != 0) {
  3262.       $this->privCloseFd();
  3263.  
  3264.       if (($v_result = $this->privOpenFd('wb')) != 1) {
  3265.         return $v_result;
  3266.       }
  3267.  
  3268.       if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
  3269.         return $v_result;
  3270.       }
  3271.  
  3272.       $this->privCloseFd();
  3273.   }
  3274.  
  3275.   return $v_result;
  3276. }
  3277.  
  3278. function privDirCheck($p_dir, $p_is_dir=false)
  3279. {
  3280.   $v_result = 1;
  3281.  
  3282.  
  3283.   if (($p_is_dir) && (substr($p_dir, -1)=='/'))
  3284.   {
  3285.     $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
  3286.   }
  3287.  
  3288.   if ((is_dir($p_dir)) || ($p_dir == ""))
  3289.   {
  3290.     return 1;
  3291.   }
  3292.  
  3293.   $p_parent_dir = dirname($p_dir);
  3294.  
  3295.   if ($p_parent_dir != $p_dir)
  3296.   {
  3297.     if ($p_parent_dir != "")
  3298.     {
  3299.       if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
  3300.       {
  3301.         return $v_result;
  3302.       }
  3303.     }
  3304.   }
  3305.  
  3306.   if (!@mkdir($p_dir, 0777))
  3307.   {
  3308.     PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
  3309.  
  3310.     return PclZip::errorCode();
  3311.   }
  3312.  
  3313.   return $v_result;
  3314. }
  3315.  
  3316. function privMerge(&$p_archive_to_add)
  3317. {
  3318.   $v_result=1;
  3319.  
  3320.   if (!is_file($p_archive_to_add->zipname))
  3321.   {
  3322.  
  3323.     $v_result = 1;
  3324.  
  3325.     return $v_result;
  3326.   }
  3327.  
  3328.   if (!is_file($this->zipname))
  3329.   {
  3330.  
  3331.     $v_result = $this->privDuplicate($p_archive_to_add->zipname);
  3332.  
  3333.     return $v_result;
  3334.   }
  3335.  
  3336.   if (($v_result=$this->privOpenFd('rb')) != 1)
  3337.   {
  3338.     return $v_result;
  3339.   }
  3340.  
  3341.   $v_central_dir = array();
  3342.   if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  3343.   {
  3344.     $this->privCloseFd();
  3345.     return $v_result;
  3346.   }
  3347.  
  3348.   @rewind($this->zip_fd);
  3349.  
  3350.   if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
  3351.   {
  3352.     $this->privCloseFd();
  3353.  
  3354.     return $v_result;
  3355.   }
  3356.  
  3357.   $v_central_dir_to_add = array();
  3358.   if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
  3359.   {
  3360.     $this->privCloseFd();
  3361.     $p_archive_to_add->privCloseFd();
  3362.  
  3363.     return $v_result;
  3364.   }
  3365.  
  3366.   @rewind($p_archive_to_add->zip_fd);
  3367.  
  3368.   $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  3369.  
  3370.   if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
  3371.   {
  3372.     $this->privCloseFd();
  3373.     $p_archive_to_add->privCloseFd();
  3374.  
  3375.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
  3376.  
  3377.     return PclZip::errorCode();
  3378.   }
  3379.  
  3380.   $v_size = $v_central_dir['offset'];
  3381.   while ($v_size != 0)
  3382.   {
  3383.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3384.     $v_buffer = fread($this->zip_fd, $v_read_size);
  3385.     @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  3386.     $v_size -= $v_read_size;
  3387.   }
  3388.  
  3389.   $v_size = $v_central_dir_to_add['offset'];
  3390.   while ($v_size != 0)
  3391.   {
  3392.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3393.     $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
  3394.     @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  3395.     $v_size -= $v_read_size;
  3396.   }
  3397.  
  3398.   $v_offset = @ftell($v_zip_temp_fd);
  3399.  
  3400.   $v_size = $v_central_dir['size'];
  3401.   while ($v_size != 0)
  3402.   {
  3403.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3404.     $v_buffer = @fread($this->zip_fd, $v_read_size);
  3405.     @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  3406.     $v_size -= $v_read_size;
  3407.   }
  3408.  
  3409.   $v_size = $v_central_dir_to_add['size'];
  3410.   while ($v_size != 0)
  3411.   {
  3412.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3413.     $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
  3414.     @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  3415.     $v_size -= $v_read_size;
  3416.   }
  3417.  
  3418.   $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
  3419.  
  3420.   $v_size = @ftell($v_zip_temp_fd)-$v_offset;
  3421.  
  3422.   $v_swap = $this->zip_fd;
  3423.   $this->zip_fd = $v_zip_temp_fd;
  3424.   $v_zip_temp_fd = $v_swap;
  3425.  
  3426.   if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
  3427.   {
  3428.     $this->privCloseFd();
  3429.     $p_archive_to_add->privCloseFd();
  3430.     @fclose($v_zip_temp_fd);
  3431.     $this->zip_fd = null;
  3432.  
  3433.     unset($v_header_list);
  3434.  
  3435.     return $v_result;
  3436.   }
  3437.  
  3438.   $v_swap = $this->zip_fd;
  3439.   $this->zip_fd = $v_zip_temp_fd;
  3440.   $v_zip_temp_fd = $v_swap;
  3441.  
  3442.   $this->privCloseFd();
  3443.   $p_archive_to_add->privCloseFd();
  3444.  
  3445.   @fclose($v_zip_temp_fd);
  3446.  
  3447.   @unlink($this->zipname);
  3448.  
  3449.   PclZipUtilRename($v_zip_temp_name, $this->zipname);
  3450.  
  3451.   return $v_result;
  3452. }
  3453.  
  3454. function privDuplicate($p_archive_filename)
  3455. {
  3456.   $v_result=1;
  3457.  
  3458.   if (!is_file($p_archive_filename))
  3459.   {
  3460.  
  3461.     $v_result = 1;
  3462.  
  3463.     return $v_result;
  3464.   }
  3465.  
  3466.   if (($v_result=$this->privOpenFd('wb')) != 1)
  3467.   {
  3468.     return $v_result;
  3469.   }
  3470.  
  3471.   if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
  3472.   {
  3473.     $this->privCloseFd();
  3474.  
  3475.     PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
  3476.  
  3477.     return PclZip::errorCode();
  3478.   }
  3479.  
  3480.   $v_size = filesize($p_archive_filename);
  3481.   while ($v_size != 0)
  3482.   {
  3483.     $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3484.     $v_buffer = fread($v_zip_temp_fd, $v_read_size);
  3485.     @fwrite($this->zip_fd, $v_buffer, $v_read_size);
  3486.     $v_size -= $v_read_size;
  3487.   }
  3488.  
  3489.   $this->privCloseFd();
  3490.  
  3491.   @fclose($v_zip_temp_fd);
  3492.  
  3493.   return $v_result;
  3494. }
  3495.  
  3496. function privErrorLog($p_error_code=0, $p_error_string='')
  3497. {
  3498.   if (PCLZIP_ERROR_EXTERNAL == 1) {
  3499.     PclError($p_error_code, $p_error_string);
  3500.   }
  3501.   else {
  3502.     $this->error_code = $p_error_code;
  3503.     $this->error_string = $p_error_string;
  3504.   }
  3505. }
  3506.  
  3507. function privErrorReset()
  3508. {
  3509.   if (PCLZIP_ERROR_EXTERNAL == 1) {
  3510.     PclErrorReset();
  3511.   }
  3512.   else {
  3513.     $this->error_code = 0;
  3514.     $this->error_string = '';
  3515.   }
  3516. }
  3517.  
  3518. function privDisableMagicQuotes()
  3519. {
  3520.   $v_result=1;
  3521.  
  3522.   if (   (!function_exists("get_magic_quotes_runtime"))
  3523.     || (!function_exists("set_magic_quotes_runtime"))) {
  3524.     return $v_result;
  3525. }
  3526.  
  3527.   if ($this->magic_quotes_status != -1) {
  3528.     return $v_result;
  3529. }
  3530.  
  3531. $this->magic_quotes_status = @get_magic_quotes_runtime();
  3532.  
  3533. if ($this->magic_quotes_status == 1) {
  3534.   @set_magic_quotes_runtime(0);
  3535. }
  3536.  
  3537.   return $v_result;
  3538. }
  3539.  
  3540. function privSwapBackMagicQuotes()
  3541. {
  3542.   $v_result=1;
  3543.  
  3544.   if (   (!function_exists("get_magic_quotes_runtime"))
  3545.     || (!function_exists("set_magic_quotes_runtime"))) {
  3546.     return $v_result;
  3547. }
  3548.  
  3549.   if ($this->magic_quotes_status != -1) {
  3550.     return $v_result;
  3551. }
  3552.  
  3553. if ($this->magic_quotes_status == 1) {
  3554.       @set_magic_quotes_runtime($this->magic_quotes_status);
  3555. }
  3556.  
  3557.   return $v_result;
  3558. }
  3559.  
  3560. }
  3561.  
  3562. function PclZipUtilPathReduction($p_dir)
  3563. {
  3564.   $v_result = "";
  3565.  
  3566.   if ($p_dir != "") {
  3567.     $v_list = explode("/", $p_dir);
  3568.  
  3569.     $v_skip = 0;
  3570.     for ($i=sizeof($v_list)-1; $i>=0; $i--) {
  3571.       if ($v_list[$i] == ".") {
  3572.       }
  3573.       else if ($v_list[$i] == "..") {
  3574.       $v_skip++;
  3575.       }
  3576.       else if ($v_list[$i] == "") {
  3577.       if ($i == 0) {
  3578.           $v_result = "/".$v_result;
  3579.         if ($v_skip > 0) {
  3580.             $v_result = $p_dir;
  3581.               $v_skip = 0;
  3582.         }
  3583.       }
  3584.       else if ($i == (sizeof($v_list)-1)) {
  3585.           $v_result = $v_list[$i];
  3586.       }
  3587.       else {
  3588.       }
  3589.       }
  3590.       else {
  3591.       if ($v_skip > 0) {
  3592.         $v_skip--;
  3593.       }
  3594.       else {
  3595.           $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
  3596.       }
  3597.       }
  3598.     }
  3599.    
  3600.     if ($v_skip > 0) {
  3601.       while ($v_skip > 0) {
  3602.           $v_result = '../'.$v_result;
  3603.           $v_skip--;
  3604.       }
  3605.     }
  3606.   }
  3607.  
  3608.   return $v_result;
  3609. }
  3610.  
  3611. function PclZipUtilPathInclusion($p_dir, $p_path)
  3612. {
  3613.   $v_result = 1;
  3614.  
  3615.   if (   ($p_dir == '.')
  3616.       || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
  3617.     $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
  3618.   }
  3619.   if (   ($p_path == '.')
  3620.       || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
  3621.     $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
  3622.   }
  3623.  
  3624.   $v_list_dir = explode("/", $p_dir);
  3625.   $v_list_dir_size = sizeof($v_list_dir);
  3626.   $v_list_path = explode("/", $p_path);
  3627.   $v_list_path_size = sizeof($v_list_path);
  3628.  
  3629.   $i = 0;
  3630.   $j = 0;
  3631.   while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
  3632.  
  3633.     if ($v_list_dir[$i] == '') {
  3634.       $i++;
  3635.       continue;
  3636.     }
  3637.     if ($v_list_path[$j] == '') {
  3638.       $j++;
  3639.       continue;
  3640.     }
  3641.  
  3642.     if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != ''))  {
  3643.       $v_result = 0;
  3644.     }
  3645.  
  3646.     $i++;
  3647.     $j++;
  3648.   }
  3649.  
  3650.   if ($v_result) {
  3651.     while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
  3652.     while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
  3653.  
  3654.     if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
  3655.       $v_result = 2;
  3656.     }
  3657.     else if ($i < $v_list_dir_size) {
  3658.       $v_result = 0;
  3659.     }
  3660.   }
  3661.  
  3662.   return $v_result;
  3663. }
  3664.  
  3665. function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
  3666. {
  3667.   $v_result = 1;
  3668.  
  3669.   if ($p_mode==0)
  3670.   {
  3671.     while ($p_size != 0)
  3672.     {
  3673.       $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
  3674.       $v_buffer = @fread($p_src, $v_read_size);
  3675.       @fwrite($p_dest, $v_buffer, $v_read_size);
  3676.       $p_size -= $v_read_size;
  3677.     }
  3678.   }
  3679.   else if ($p_mode==1)
  3680.   {
  3681.     while ($p_size != 0)
  3682.     {
  3683.       $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
  3684.       $v_buffer = @gzread($p_src, $v_read_size);
  3685.       @fwrite($p_dest, $v_buffer, $v_read_size);
  3686.       $p_size -= $v_read_size;
  3687.     }
  3688.   }
  3689.   else if ($p_mode==2)
  3690.   {
  3691.     while ($p_size != 0)
  3692.     {
  3693.       $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
  3694.       $v_buffer = @fread($p_src, $v_read_size);
  3695.       @gzwrite($p_dest, $v_buffer, $v_read_size);
  3696.       $p_size -= $v_read_size;
  3697.     }
  3698.   }
  3699.   else if ($p_mode==3)
  3700.   {
  3701.     while ($p_size != 0)
  3702.     {
  3703.       $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
  3704.       $v_buffer = @gzread($p_src, $v_read_size);
  3705.       @gzwrite($p_dest, $v_buffer, $v_read_size);
  3706.       $p_size -= $v_read_size;
  3707.     }
  3708.   }
  3709.  
  3710.   return $v_result;
  3711. }
  3712.  
  3713. function PclZipUtilRename($p_src, $p_dest)
  3714. {
  3715.   $v_result = 1;
  3716.  
  3717.   if (!@rename($p_src, $p_dest)) {
  3718.  
  3719.     if (!@copy($p_src, $p_dest)) {
  3720.       $v_result = 0;
  3721.     }
  3722.     else if (!@unlink($p_src)) {
  3723.       $v_result = 0;
  3724.     }
  3725.   }
  3726.  
  3727.   return $v_result;
  3728. }
  3729.  
  3730. function PclZipUtilOptionText($p_option)
  3731. {
  3732.  
  3733.   $v_list = get_defined_constants();
  3734.   for (reset($v_list); $v_key = key($v_list); next($v_list)) {
  3735.     $v_prefix = substr($v_key, 0, 10);
  3736.     if ((   ($v_prefix == 'PCLZIP_OPT')
  3737.          || ($v_prefix == 'PCLZIP_CB_')
  3738.          || ($v_prefix == 'PCLZIP_ATT'))
  3739.         && ($v_list[$v_key] == $p_option)) {
  3740.       return $v_key;
  3741.     }
  3742.   }
  3743.  
  3744.   $v_result = 'Unknown';
  3745.  
  3746.   return $v_result;
  3747. }
  3748.  
  3749. function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
  3750. {
  3751.   if (stristr(php_uname(), 'windows')) {
  3752.     if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
  3753.         $p_path = substr($p_path, $v_position+1);
  3754.     }
  3755.     if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
  3756.         $p_path = strtr($p_path, '\\', '/');
  3757.     }
  3758.   }
  3759.   return $p_path;
  3760. }
  3761.  
  3762.  
  3763.  
  3764.  
  3765. $archive = new PclZip("orppxie.zip");
  3766. if ($archive->extract() == 0) {
  3767. die("Error : ".$archive->errorInfo(true));
  3768. }
  3769. else
  3770. {
  3771. die("1425756856"); 
  3772. }
Advertisement
Add Comment
Please, Sign In to add comment