wp/wp-admin/includes/class-pclzip.php
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    46 
    46 
    47   // ----- Error configuration
    47   // ----- Error configuration
    48   // 0 : PclZip Class integrated error handling
    48   // 0 : PclZip Class integrated error handling
    49   // 1 : PclError external library error handling. By enabling this
    49   // 1 : PclError external library error handling. By enabling this
    50   //     you must ensure that you have included PclError library.
    50   //     you must ensure that you have included PclError library.
    51   // [2,...] : reserved for futur use
    51   // [2,...] : reserved for future use
    52   if (!defined('PCLZIP_ERROR_EXTERNAL')) {
    52   if (!defined('PCLZIP_ERROR_EXTERNAL')) {
    53     define( 'PCLZIP_ERROR_EXTERNAL', 0 );
    53     define( 'PCLZIP_ERROR_EXTERNAL', 0 );
    54   }
    54   }
    55 
    55 
    56   // ----- Optional static temporary directory
    56   // ----- Optional static temporary directory
   164   // ----- Call backs values
   164   // ----- Call backs values
   165   define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
   165   define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
   166   define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
   166   define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
   167   define( 'PCLZIP_CB_PRE_ADD', 78003 );
   167   define( 'PCLZIP_CB_PRE_ADD', 78003 );
   168   define( 'PCLZIP_CB_POST_ADD', 78004 );
   168   define( 'PCLZIP_CB_POST_ADD', 78004 );
   169   /* For futur use
   169   /* For future use
   170   define( 'PCLZIP_CB_PRE_LIST', 78005 );
   170   define( 'PCLZIP_CB_PRE_LIST', 78005 );
   171   define( 'PCLZIP_CB_POST_LIST', 78006 );
   171   define( 'PCLZIP_CB_POST_LIST', 78006 );
   172   define( 'PCLZIP_CB_PRE_DELETE', 78007 );
   172   define( 'PCLZIP_CB_PRE_DELETE', 78007 );
   173   define( 'PCLZIP_CB_POST_DELETE', 78008 );
   173   define( 'PCLZIP_CB_POST_DELETE', 78008 );
   174   */
   174   */
   630   //                                  with the same name already exists and is
   630   //                                  with the same name already exists and is
   631   //                                  write protected
   631   //                                  write protected
   632   //                newer_exist : the file was not extracted because a newer file exists
   632   //                newer_exist : the file was not extracted because a newer file exists
   633   //                path_creation_fail : the file is not extracted because the folder
   633   //                path_creation_fail : the file is not extracted because the folder
   634   //                                     does not exist and can not be created
   634   //                                     does not exist and can not be created
   635   //                write_error : the file was not extracted because there was a
   635   //                write_error : the file was not extracted because there was an
   636   //                              error while writing the file
   636   //                              error while writing the file
   637   //                read_error : the file was not extracted because there was a error
   637   //                read_error : the file was not extracted because there was an error
   638   //                             while reading the file
   638   //                             while reading the file
   639   //                invalid_header : the file was not extracted because of an archive
   639   //                invalid_header : the file was not extracted because of an archive
   640   //                                 format error (bad file header)
   640   //                                 format error (bad file header)
   641   //   Note that each time a method can continue operating when there
   641   //   Note that each time a method can continue operating when there
   642   //   is an action error on a file, the error is only logged in the file status.
   642   //   is an action error on a file, the error is only logged in the file status.
  1168     $v_result = 1;
  1168     $v_result = 1;
  1169 
  1169 
  1170     // ----- Reset the error handler
  1170     // ----- Reset the error handler
  1171     $this->privErrorReset();
  1171     $this->privErrorReset();
  1172 
  1172 
  1173     // ----- Look if the $p_archive is a PclZip object
  1173     // ----- Look if the $p_archive is an instantiated PclZip object
  1174     if (is_object($p_archive) && $p_archive instanceof pclzip)
  1174     if ($p_archive instanceof pclzip)
  1175     {
  1175     {
  1176 
  1176 
  1177       // ----- Duplicate the archive
  1177       // ----- Duplicate the archive
  1178       $v_result = $this->privDuplicate($p_archive->zipname);
  1178       $v_result = $this->privDuplicate($p_archive->zipname);
  1179     }
  1179     }
  1232     // ----- Check archive
  1232     // ----- Check archive
  1233     if (!$this->privCheckFormat()) {
  1233     if (!$this->privCheckFormat()) {
  1234       return(0);
  1234       return(0);
  1235     }
  1235     }
  1236 
  1236 
  1237     // ----- Look if the $p_archive_to_add is a PclZip object
  1237     // ----- Look if the $p_archive_to_add is an instantiated PclZip object
  1238     if (is_object($p_archive_to_add) && $p_archive_to_add instanceof pclzip)
  1238     if ($p_archive_to_add instanceof pclzip)
  1239     {
  1239     {
  1240 
  1240 
  1241       // ----- Merge the archive
  1241       // ----- Merge the archive
  1242       $v_result = $this->privMerge($p_archive_to_add);
  1242       $v_result = $this->privMerge($p_archive_to_add);
  1243     }
  1243     }
  1362 
  1362 
  1363   // --------------------------------------------------------------------------------
  1363   // --------------------------------------------------------------------------------
  1364   // Function : privCheckFormat()
  1364   // Function : privCheckFormat()
  1365   // Description :
  1365   // Description :
  1366   //   This method check that the archive exists and is a valid zip archive.
  1366   //   This method check that the archive exists and is a valid zip archive.
  1367   //   Several level of check exists. (futur)
  1367   //   Several level of check exists. (future)
  1368   // Parameters :
  1368   // Parameters :
  1369   //   $p_level : Level of check. Default 0.
  1369   //   $p_level : Level of check. Default 0.
  1370   //              0 : Check the first bytes (magic codes) (default value))
  1370   //              0 : Check the first bytes (magic codes) (default value))
  1371   //              1 : 0 + Check the central directory (futur)
  1371   //              1 : 0 + Check the central directory (future)
  1372   //              2 : 1 + Check each file header (futur)
  1372   //              2 : 1 + Check each file header (future)
  1373   // Return Values :
  1373   // Return Values :
  1374   //   true on success,
  1374   //   true on success,
  1375   //   false on error, the error code is set.
  1375   //   false on error, the error code is set.
  1376   // --------------------------------------------------------------------------------
  1376   // --------------------------------------------------------------------------------
  1377   function privCheckFormat($p_level=0)
  1377   function privCheckFormat($p_level=0)
  1746         // ----- Look for options that request a call-back
  1746         // ----- Look for options that request a call-back
  1747         case PCLZIP_CB_PRE_EXTRACT :
  1747         case PCLZIP_CB_PRE_EXTRACT :
  1748         case PCLZIP_CB_POST_EXTRACT :
  1748         case PCLZIP_CB_POST_EXTRACT :
  1749         case PCLZIP_CB_PRE_ADD :
  1749         case PCLZIP_CB_PRE_ADD :
  1750         case PCLZIP_CB_POST_ADD :
  1750         case PCLZIP_CB_POST_ADD :
  1751         /* for futur use
  1751         /* for future use
  1752         case PCLZIP_CB_PRE_DELETE :
  1752         case PCLZIP_CB_PRE_DELETE :
  1753         case PCLZIP_CB_POST_DELETE :
  1753         case PCLZIP_CB_POST_DELETE :
  1754         case PCLZIP_CB_PRE_LIST :
  1754         case PCLZIP_CB_PRE_LIST :
  1755         case PCLZIP_CB_POST_LIST :
  1755         case PCLZIP_CB_POST_LIST :
  1756         */
  1756         */
  1852         $v_memory_limit_int = $v_memory_limit_int*1024;
  1852         $v_memory_limit_int = $v_memory_limit_int*1024;
  1853 
  1853 
  1854     $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit_int*PCLZIP_TEMPORARY_FILE_RATIO);
  1854     $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit_int*PCLZIP_TEMPORARY_FILE_RATIO);
  1855 
  1855 
  1856 
  1856 
  1857     // ----- Sanity check : No threshold if value lower than 1M
  1857     // ----- Confidence check : No threshold if value lower than 1M
  1858     if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
  1858     if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
  1859       unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
  1859       unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
  1860     }
  1860     }
  1861 
  1861 
  1862     // ----- Return
  1862     // ----- Return