Changeset 3582 for trunk/admin


Ignore:
Timestamp:
Jul 15, 2009, 1:36:11 PM (15 years ago)
Author:
patdenice
Message:

merge r3581 from branch 2.0 to trunk
Update pclzip library to 2.8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/pclzip.lib.php

    r3282 r3582  
    11<?php
    22// --------------------------------------------------------------------------------
    3 // PhpConcept Library - Zip Module 2.6
     3// PhpConcept Library - Zip Module 2.8
    44// --------------------------------------------------------------------------------
    55// License GNU/LGPL - Vincent Blavet - March 2006
     
    4040}
    4141
    42 
    43 $g_pclzip_version = "2.6";
     42if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
     43  define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
     44}
     45
     46
     47$g_pclzip_version = "2.8";
    4448
    4549define( 'PCLZIP_ERR_USER_ABORTED', 2 );
     
    8589define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
    8690define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
     91define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
     92define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
     93define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
    8794
    8895define( 'PCLZIP_ATT_FILE_NAME', 79001 );
     
    97104define( 'PCLZIP_CB_PRE_ADD', 78003 );
    98105define( 'PCLZIP_CB_POST_ADD', 78004 );
    99 
     106/* For futur use
     107define( 'PCLZIP_CB_PRE_LIST', 78005 );
     108define( 'PCLZIP_CB_POST_LIST', 78006 );
     109define( 'PCLZIP_CB_PRE_DELETE', 78007 );
     110define( 'PCLZIP_CB_POST_DELETE', 78008 );
     111*/
    100112
    101113class PclZip
     
    151163                                                 PCLZIP_CB_POST_ADD => 'optional',
    152164                                                 PCLZIP_OPT_NO_COMPRESSION => 'optional',
    153                                                  PCLZIP_OPT_COMMENT => 'optional'
     165                                                 PCLZIP_OPT_COMMENT => 'optional',
     166                                                 PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
     167                                                 PCLZIP_OPT_TEMP_FILE_ON => 'optional',
     168                                                 PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
    154169                                           ));
    155170      if ($v_result != 1) {
     
    172187    }
    173188  }
     189 
     190  $this->privOptionDefaultThreshold($v_options);
    174191
    175192  $v_string_list = array();
     
    267284                                                 PCLZIP_OPT_COMMENT => 'optional',
    268285                                                 PCLZIP_OPT_ADD_COMMENT => 'optional',
    269                                                  PCLZIP_OPT_PREPEND_COMMENT => 'optional'
     286                                                 PCLZIP_OPT_PREPEND_COMMENT => 'optional',
     287                                                 PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
     288                                                 PCLZIP_OPT_TEMP_FILE_ON => 'optional',
     289                                                 PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
    270290                         ));
    271291      if ($v_result != 1) {
     
    288308    }
    289309  }
     310
     311  $this->privOptionDefaultThreshold($v_options);
    290312
    291313  $v_string_list = array();
     
    411433                                                 PCLZIP_OPT_REPLACE_NEWER => 'optional'
    412434                                                 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
    413                                                  ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
     435                                                 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
     436                                                 PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
     437                                                 PCLZIP_OPT_TEMP_FILE_ON => 'optional',
     438                                                 PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
    414439                          ));
    415440      if ($v_result != 1) {
     
    448473    }
    449474  }
     475
     476  $this->privOptionDefaultThreshold($v_options);
    450477
    451478
     
    500527                                                 PCLZIP_OPT_REPLACE_NEWER => 'optional'
    501528                                                 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
    502                                                  ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
     529                                                 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
     530                                                 PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
     531                                                 PCLZIP_OPT_TEMP_FILE_ON => 'optional',
     532                                                 PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
    503533                         ));
    504534      if ($v_result != 1) {
     
    552582  }
    553583  $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
     584
     585  $this->privOptionDefaultThreshold($v_options);
    554586
    555587  if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
     
    797829  $v_result = true;
    798830
    799     clearstatcache();
     831  clearstatcache();
    800832
    801833  $this->privErrorReset();
     
    842874        $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
    843875        $i++;
     876      break;
     877
     878      case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
     879        if (($i+1) >= $p_size) {
     880          PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     881          return PclZip::errorCode();
     882        }
     883       
     884        if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
     885          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
     886          return PclZip::errorCode();
     887        }
     888       
     889        $v_value = $p_options_list[$i+1];
     890        if ((!is_integer($v_value)) || ($v_value<0)) {
     891          PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     892          return PclZip::errorCode();
     893        }
     894
     895        $v_result_list[$p_options_list[$i]] = $v_value*1048576;
     896        $i++;
     897      break;
     898
     899      case PCLZIP_OPT_TEMP_FILE_ON :
     900        if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
     901          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
     902          return PclZip::errorCode();
     903        }
     904       
     905        $v_result_list[$p_options_list[$i]] = true;
     906      break;
     907
     908      case PCLZIP_OPT_TEMP_FILE_OFF :
     909        if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
     910          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
     911          return PclZip::errorCode();
     912        }
     913        if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
     914          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
     915          return PclZip::errorCode();
     916        }
     917       
     918        $v_result_list[$p_options_list[$i]] = true;
    844919      break;
    845920
     
    10141089      case PCLZIP_CB_PRE_ADD :
    10151090      case PCLZIP_CB_POST_ADD :
    1016 
     1091      /* for futur use
     1092      case PCLZIP_CB_PRE_DELETE :
     1093      case PCLZIP_CB_POST_DELETE :
     1094      case PCLZIP_CB_PRE_LIST :
     1095      case PCLZIP_CB_POST_LIST :
     1096      */
    10171097        if (($i+1) >= $p_size) {
    10181098          PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
     
    10551135    }
    10561136  }
    1057 
     1137 
     1138  if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
     1139   
     1140  }
     1141
     1142  return $v_result;
     1143}
     1144
     1145function privOptionDefaultThreshold(&$p_options)
     1146{
     1147  $v_result=1;
     1148 
     1149  if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
     1150      || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
     1151    return $v_result;
     1152  }
     1153 
     1154  $v_memory_limit = ini_get('memory_limit');
     1155  $v_memory_limit = trim($v_memory_limit);
     1156  $last = strtolower(substr($v_memory_limit, -1));
     1157
     1158  if($last == 'g')
     1159      $v_memory_limit = $v_memory_limit*1073741824;
     1160  if($last == 'm')
     1161      $v_memory_limit = $v_memory_limit*1048576;
     1162  if($last == 'k')
     1163      $v_memory_limit = $v_memory_limit*1024;
     1164         
     1165  $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
     1166 
     1167
     1168  if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
     1169    unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
     1170  }
     1171       
    10581172  return $v_result;
    10591173}
     
    11701284    $v_descr = $p_filedescr_list[$i];
    11711285   
    1172     $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']);
     1286    $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
    11731287    $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
    11741288   
     
    11931307   
    11941308    else {
    1195       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists");
     1309      PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
    11961310
    11971311      return PclZip::errorCode();
     
    14951609    if (   ($p_filedescr_list[$j]['type'] != 'virtual_file')
    14961610        && (!file_exists($p_filedescr_list[$j]['filename']))) {
    1497       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists");
     1611      PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
    14981612      return PclZip::errorCode();
    14991613    }
     
    15311645  }
    15321646
    1533 
     1647  /* TBC : Removed
     1648  if (isset($p_filedescr['stored_filename'])) {
     1649    $v_stored_filename = $p_filedescr['stored_filename'];
     1650  }
     1651  else {
     1652    $v_stored_filename = $p_filedescr['stored_filename'];
     1653  }
     1654  */
    15341655
    15351656  clearstatcache();
     
    15721693  }
    15731694  else if ($p_filedescr['type'] == 'virtual_file') {
    1574     $p_header['mtime'] = mktime();
     1695    $p_header['mtime'] = time();
    15751696  }
    15761697  else {
     
    16131734  if ($p_header['status'] == 'ok') {
    16141735
    1615     if (   ($p_filedescr['type'] == 'file')
    1616         || ($p_filedescr['type'] == 'virtual_file')) {
    1617        
    1618       if ($p_filedescr['type'] == 'file') {       
    1619 
    1620         if (($v_file = @fopen($p_filename, "rb")) == 0) {
    1621           PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
    1622           return PclZip::errorCode();
    1623         }
    1624 
    1625         $v_content = @fread($v_file, $p_header['size']);
    1626 
    1627         @fclose($v_file);
    1628       }
    1629       else if ($p_filedescr['type'] == 'virtual_file') {       
    1630         $v_content = $p_filedescr['content'];
    1631       }
     1736    if ($p_filedescr['type'] == 'file') {
     1737      if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
     1738          && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
     1739              || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
     1740                  && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
     1741        $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
     1742        if ($v_result < PCLZIP_ERR_NO_ERROR) {
     1743          return $v_result;
     1744        }
     1745      }
     1746     
     1747      else {
     1748
     1749      if (($v_file = @fopen($p_filename, "rb")) == 0) {
     1750        PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
     1751        return PclZip::errorCode();
     1752      }
     1753
     1754      $v_content = @fread($v_file, $p_header['size']);
     1755
     1756      @fclose($v_file);
    16321757
    16331758      $p_header['crc'] = @crc32($v_content);
     
    16451770      }
    16461771     
    1647 
    1648 
    16491772      if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
    16501773        @fclose($v_file);
     
    16531776
    16541777      @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
     1778
     1779      }
     1780
     1781    }
     1782
     1783    else if ($p_filedescr['type'] == 'virtual_file') {
     1784       
     1785      $v_content = $p_filedescr['content'];
     1786
     1787      $p_header['crc'] = @crc32($v_content);
     1788     
     1789      if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
     1790        $p_header['compressed_size'] = $p_header['size'];
     1791        $p_header['compression'] = 0;
     1792      }
     1793     
     1794      else {
     1795        $v_content = @gzdeflate($v_content);
     1796
     1797        $p_header['compressed_size'] = strlen($v_content);
     1798        $p_header['compression'] = 8;
     1799      }
     1800     
     1801      if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
     1802        @fclose($v_file);
     1803        return $v_result;
     1804      }
     1805
     1806      @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
    16551807    }
    16561808
     
    16611813
    16621814      $p_header['size'] = 0;
    1663       $p_header['external'] = 0x00000010;
     1815
    16641816      if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
    16651817      {
     
    16841836}
    16851837
     1838function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
     1839{
     1840  $v_result=PCLZIP_ERR_NO_ERROR;
     1841 
     1842  $p_filename = $p_filedescr['filename'];
     1843
     1844
     1845  if (($v_file = @fopen($p_filename, "rb")) == 0) {
     1846    PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
     1847    return PclZip::errorCode();
     1848  }
     1849
     1850  $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
     1851  if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
     1852    fclose($v_file);
     1853    PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
     1854    return PclZip::errorCode();
     1855  }
     1856
     1857  $v_size = filesize($p_filename);
     1858  while ($v_size != 0) {
     1859    $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
     1860    $v_buffer = @fread($v_file, $v_read_size);
     1861    @gzputs($v_file_compressed, $v_buffer, $v_read_size);
     1862    $v_size -= $v_read_size;
     1863  }
     1864
     1865  @fclose($v_file);
     1866  @gzclose($v_file_compressed);
     1867
     1868  if (filesize($v_gzip_temp_name) < 18) {
     1869    PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
     1870    return PclZip::errorCode();
     1871  }
     1872
     1873  if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
     1874    PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
     1875    return PclZip::errorCode();
     1876  }
     1877
     1878  $v_binary_data = @fread($v_file_compressed, 10);
     1879  $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
     1880
     1881  $v_data_header['os'] = bin2hex($v_data_header['os']);
     1882
     1883  @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
     1884  $v_binary_data = @fread($v_file_compressed, 8);
     1885  $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
     1886
     1887  $p_header['compression'] = ord($v_data_header['cm']);
     1888  $p_header['crc'] = $v_data_footer['crc'];
     1889  $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
     1890
     1891  @fclose($v_file_compressed);
     1892
     1893  if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
     1894    return $v_result;
     1895  }
     1896
     1897  if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
     1898  {
     1899    PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
     1900    return PclZip::errorCode();
     1901  }
     1902
     1903  fseek($v_file_compressed, 10);
     1904  $v_size = $p_header['compressed_size'];
     1905  while ($v_size != 0)
     1906  {
     1907    $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
     1908    $v_buffer = @fread($v_file_compressed, $v_read_size);
     1909    @fwrite($this->zip_fd, $v_buffer, $v_read_size);
     1910    $v_size -= $v_read_size;
     1911  }
     1912
     1913  @fclose($v_file_compressed);
     1914
     1915  @unlink($v_gzip_temp_name);
     1916 
     1917  return $v_result;
     1918}
     1919
    16861920function privCalculateStoredFilename(&$p_filedescr, &$p_options)
    16871921{
     
    17091943
    17101944  if (isset($p_filedescr['new_full_name'])) {
    1711     $v_stored_filename = $p_filedescr['new_full_name'];
     1945    $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
    17121946  }
    17131947 
     
    17581992      }
    17591993    }
     1994   
     1995    $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
     1996   
    17601997    if ($p_add_dir != "") {
    17611998      if (substr($p_add_dir, -1) == "/")
     
    19162153  $v_result=1;
    19172154
    1918   $p_info['filename'] = $p_header['filename'];
    1919   $p_info['stored_filename'] = $p_header['stored_filename'];
     2155  $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
     2156  $p_info['filename'] = $v_temp_path;
     2157  $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
     2158  $p_info['stored_filename'] = $v_temp_path;
    19202159  $p_info['size'] = $p_header['size'];
    19212160  $p_info['compressed_size'] = $p_header['compressed_size'];
     
    20592298    }
    20602299
    2061     if (   ($v_extract)
     2300  if (   ($v_extract)
    20622301      && (   ($v_header['compression'] != 8)
    20632302        && ($v_header['compression'] != 0))) {
     
    20782317  }
    20792318 
    2080     if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
     2319  if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
    20812320        $v_header['status'] = 'unsupported_encryption';
    20822321
     
    22972536
    22982537          return PclZip::errorCode();
    2299   }
     2538      }
    23002539    }
    23012540    else if (!is_writeable($p_entry['filename']))
     
    23122551
    23132552          return PclZip::errorCode();
    2314   }
     2553      }
    23152554    }
    23162555
     
    23192558      if (   (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
    23202559      && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
    2321   }
    2322   else {
     2560      }
     2561      else {
    23232562          $p_entry['status'] = "newer_exist";
    23242563
     
    23312570
    23322571              return PclZip::errorCode();
    2333       }
    2334   }
     2572        }
     2573      }
    23352574    }
    23362575    else {
     
    23462585      $v_dir_to_check = dirname($p_entry['filename']);
    23472586
    2348     if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
    2349 
    2350       $p_entry['status'] = "path_creation_fail";
    2351 
    2352       $v_result = 1;
    2353     }
    2354   }
     2587      if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
     2588
     2589        $p_entry['status'] = "path_creation_fail";
     2590
     2591        $v_result = 1;
     2592      }
     2593    }
    23552594  }
    23562595
     
    23612600      if ($p_entry['compression'] == 0) {
    23622601
    2363             if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
     2602        if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
    23642603        {
    23652604
     
    23752614          $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
    23762615          $v_buffer = @fread($this->zip_fd, $v_read_size);
    2377 
     2616          /* Try to speed up the code
     2617          $v_binary_data = pack('a'.$v_read_size, $v_buffer);
     2618          @fwrite($v_dest_file, $v_binary_data, $v_read_size);
     2619          */
    23782620          @fwrite($v_dest_file, $v_buffer, $v_read_size);           
    23792621          $v_size -= $v_read_size;
     
    23882630      else {
    23892631        if (($p_entry['flag'] & 1) == 1) {
    2390 
    2391         }
     2632          PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
     2633          return PclZip::errorCode();
     2634        }
     2635
     2636
     2637        if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
     2638            && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
     2639                || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
     2640                    && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
     2641          $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
     2642          if ($v_result < PCLZIP_ERR_NO_ERROR) {
     2643            return $v_result;
     2644          }
     2645        }
     2646       
    23922647        else {
    2393             $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
    2394         }
     2648
    23952649       
    2396         $v_file_content = @gzinflate($v_buffer);
    2397         unset($v_buffer);
    2398         if ($v_file_content === FALSE) {
    2399 
    2400           $p_entry['status'] = "error";
     2650          $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
    24012651         
    2402           return $v_result;
    2403         }
    2404        
    2405         if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
    2406 
    2407           $p_entry['status'] = "write_error";
    2408 
    2409           return $v_result;
    2410         }
    2411 
    2412         @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
    2413         unset($v_file_content);
    2414 
    2415         @fclose($v_dest_file);
     2652          $v_file_content = @gzinflate($v_buffer);
     2653          unset($v_buffer);
     2654          if ($v_file_content === FALSE) {
     2655
     2656            $p_entry['status'] = "error";
     2657           
     2658            return $v_result;
     2659          }
     2660         
     2661          if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
     2662
     2663            $p_entry['status'] = "write_error";
     2664
     2665            return $v_result;
     2666          }
     2667
     2668          @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
     2669          unset($v_file_content);
     2670
     2671          @fclose($v_dest_file);
     2672         
     2673        }
    24162674
    24172675        @touch($p_entry['filename'], $p_entry['mtime']);
     
    24262684  }
    24272685
    2428   if ($p_entry['status'] == "aborted") {
     2686if ($p_entry['status'] == "aborted") {
    24292687    $p_entry['status'] = "skipped";
    24302688}
     
    24422700  }
    24432701
     2702  return $v_result;
     2703}
     2704
     2705function privExtractFileUsingTempFile(&$p_entry, &$p_options)
     2706{
     2707  $v_result=1;
     2708     
     2709  $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
     2710  if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
     2711    fclose($v_file);
     2712    PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
     2713    return PclZip::errorCode();
     2714  }
     2715
     2716
     2717  $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
     2718  @fwrite($v_dest_file, $v_binary_data, 10);
     2719
     2720  $v_size = $p_entry['compressed_size'];
     2721  while ($v_size != 0)
     2722  {
     2723    $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
     2724    $v_buffer = @fread($this->zip_fd, $v_read_size);
     2725    @fwrite($v_dest_file, $v_buffer, $v_read_size);
     2726    $v_size -= $v_read_size;
     2727  }
     2728
     2729  $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
     2730  @fwrite($v_dest_file, $v_binary_data, 8);
     2731
     2732  @fclose($v_dest_file);
     2733
     2734  if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
     2735    $p_entry['status'] = "write_error";
     2736    return $v_result;
     2737  }
     2738
     2739  if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
     2740    @fclose($v_dest_file);
     2741    $p_entry['status'] = "read_error";
     2742    PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
     2743    return PclZip::errorCode();
     2744  }
     2745
     2746
     2747  $v_size = $p_entry['size'];
     2748  while ($v_size != 0) {
     2749    $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
     2750    $v_buffer = @gzread($v_src_file, $v_read_size);
     2751    @fwrite($v_dest_file, $v_buffer, $v_read_size);
     2752    $v_size -= $v_read_size;
     2753  }
     2754  @fclose($v_dest_file);
     2755  @gzclose($v_src_file);
     2756
     2757  @unlink($v_gzip_temp_name);
     2758 
    24442759  return $v_result;
    24452760}
     
    25002815  }
    25012816
    2502   if ($p_entry['status'] == "aborted") {
     2817if ($p_entry['status'] == "aborted") {
    25032818    $p_entry['status'] = "skipped";
    25042819}
     
    26132928    $v_day = $p_header['mdate'] & 0x001F;
    26142929
    2615     $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
     2930    $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
    26162931
    26172932  }
     
    27083023  $v_result=1;
    27093024
    2710     if ($p_local_header['filename'] != $p_central_header['filename']) {
    2711 }
    2712 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
    2713 }
    2714 if ($p_local_header['flag'] != $p_central_header['flag']) {
    2715 }
    2716 if ($p_local_header['compression'] != $p_central_header['compression']) {
    2717 }
    2718 if ($p_local_header['mtime'] != $p_central_header['mtime']) {
    2719 }
    2720 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
    2721 }
     3025  if ($p_local_header['filename'] != $p_central_header['filename']) {
     3026  }
     3027  if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
     3028  }
     3029  if ($p_local_header['flag'] != $p_central_header['flag']) {
     3030  }
     3031  if ($p_local_header['compression'] != $p_central_header['compression']) {
     3032  }
     3033  if ($p_local_header['mtime'] != $p_central_header['mtime']) {
     3034  }
     3035  if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
     3036  }
    27223037
    27233038  if (($p_local_header['flag'] & 8) == 8) {
    2724       $p_local_header['size'] = $p_central_header['size'];
    2725       $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
    2726       $p_local_header['crc'] = $p_central_header['crc'];
    2727 }
     3039        $p_local_header['size'] = $p_central_header['size'];
     3040        $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
     3041        $p_local_header['crc'] = $p_central_header['crc'];
     3042  }
    27283043
    27293044  return $v_result;
     
    27643079
    27653080  if (!$v_found) {
    2766     $v_maximum_size = 65557;      if ($v_maximum_size > $v_size)
     3081    if ($v_maximum_size > $v_size)
    27673082      $v_maximum_size = $v_size;
    27683083    @fseek($this->zip_fd, $v_size-$v_maximum_size);
     
    28143129  if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
    28153130
    2816           if (0) {
     3131  if (0) {
    28173132    PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
    28183133                       'The central dir is not at the end of the archive.'
     
    28993214                    $v_found = true;
    29003215                }
    2901                 elseif (   (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010)
     3216                elseif (   (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
    29023217                        && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
    29033218                    $v_found = true;
     
    33113626}
    33123627
    3313 function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc)
    3314 {
    3315   $v_result=1;
    3316  
    3317   $v_pwd = "test";
    3318  
    3319   $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header,
    3320                                  $p_crc, $v_pwd);
    3321  
    3322   return $v_result;
    3323 }
    3324 
    33253628function privDisableMagicQuotes()
    33263629{
     
    33363639}
    33373640
    3338   $this->magic_quotes_status = @get_magic_quotes_runtime();
    3339 
    3340   if ($this->magic_quotes_status == 1) {
     3641$this->magic_quotes_status = @get_magic_quotes_runtime();
     3642
     3643if ($this->magic_quotes_status == 1) {
    33413644  @set_magic_quotes_runtime(0);
    33423645}
     
    33583661}
    33593662
    3360   if ($this->magic_quotes_status == 1) {
     3663if ($this->magic_quotes_status == 1) {
    33613664    @set_magic_quotes_runtime($this->magic_quotes_status);
    33623665}
     
    33823685      }
    33833686      else if ($v_list[$i] == "") {
    3384         if ($i == 0) {
     3687    if ($i == 0) {
    33853688          $v_result = "/".$v_result;
    33863689      if ($v_skip > 0) {
    3387                   $v_result = $p_dir;
     3690          $v_result = $p_dir;
    33883691              $v_skip = 0;
    33893692      }
    33903693    }
    3391         else if ($i == (sizeof($v_list)-1)) {
     3694    else if ($i == (sizeof($v_list)-1)) {
    33923695          $v_result = $v_list[$i];
    33933696    }
    3394         else {
     3697    else {
    33953698    }
    33963699      }
    33973700      else {
    3398         if ($v_skip > 0) {
     3701    if ($v_skip > 0) {
    33993702      $v_skip--;
    34003703    }
     
    35403843  $v_list = get_defined_constants();
    35413844  for (reset($v_list); $v_key = key($v_list); next($v_list)) {
    3542   $v_prefix = substr($v_key, 0, 10);
    3543   if ((   ($v_prefix == 'PCLZIP_OPT')
    3544        || ($v_prefix == 'PCLZIP_CB_')
    3545        || ($v_prefix == 'PCLZIP_ATT'))
    3546       && ($v_list[$v_key] == $p_option)) {
    3547         return $v_key;
     3845    $v_prefix = substr($v_key, 0, 10);
     3846    if ((   ($v_prefix == 'PCLZIP_OPT')
     3847         || ($v_prefix == 'PCLZIP_CB_')
     3848         || ($v_prefix == 'PCLZIP_ATT'))
     3849        && ($v_list[$v_key] == $p_option)) {
     3850      return $v_key;
    35483851    }
    35493852  }
Note: See TracChangeset for help on using the changeset viewer.