Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+80 -22
View File
@@ -2,9 +2,9 @@
/**
* @brief Archive Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 28 Jul 2015
* @version SVN_VERSION_NUMBER
*/
@@ -23,11 +23,6 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
abstract class _Archive
{
/**
* @brief The root folder name which should be ignored (with trailing slash)
*/
protected $containerName = '';
/**
* Create object from local file
*
@@ -65,15 +60,26 @@ abstract class _Archive
*/
abstract public function getFileContents( $i );
/**
* @brief The root folder name which should be ignored (with trailing slash)
*/
protected $containerName = '';
/**
* @brief Ignore hidden files?
*/
public $ignoreHiddenFiles = TRUE;
/**
* Extract
*
* @param string $destination Destination directory
* @param int|NULL $limit Number of files to extract
* @param int $offset Offset
* @retrun bool If true, all files were extracted, if false, there is more to extract
* @param string $destination Destination directory
* @param int|NULL $limit Number of files to extract
* @param int $offset Offset
* @param \IPS\Ftp|NULL $ftp If provided, the files will be extracted using FTP, otherwise will attempt to write manually
* @return bool If true, all files were extracted, if false, there is more to extract
*/
public function extract( $destination, $limit=NULL, $offset=0 )
public function extract( $destination, $limit=NULL, $offset=0, \IPS\Ftp $ftp = NULL )
{
$done = 0;
while ( $limit === NULL or $limit > $done ) // OutOfRangeException will break if $limit is NULL
@@ -81,27 +87,79 @@ abstract class _Archive
try
{
$path = $this->getFileName( $offset + $done );
if ( $path and mb_substr( $path, -1 ) !== '/' )
{
if ( $path and mb_substr( $path, -1 ) !== '/' and ( !$this->ignoreHiddenFiles or ( mb_substr( $path, 0, 1 ) !== '.' and mb_substr( $path, 0, 9 ) !== '__MACOSX/' ) ) )
{
/* Create a directory if needed */
$dir = dirname( $path );
if ( !is_dir( $dir ) )
$directories = array( $dir );
while ( $dir != '.' )
{
@mkdir( $dir, \IPS\FOLDER_PERMISSION_NO_WRITE );
$dir = dirname( $dir );
if ( $dir != '.' )
{
$directories[] = $dir;
}
}
foreach ( array_reverse( $directories ) as $dir )
{
if ( !is_dir( $destination . '/' . $dir ) )
{
if ( $ftp )
{
$ftp->mkdir( $dir );
}
else
{
@mkdir( $destination . '/' . $dir, \IPS\FOLDER_PERMISSION_NO_WRITE );
}
}
}
/* Write contents */
$contents = $this->getFileContents( $offset + $done );
$fh = @\fopen( $destination . '/' . $path, 'w+' );
if ( $fh === FALSE )
if ( $ftp )
{
throw new \IPS\Archive\Exception( '', \IPS\Archive\Exception::COULD_NOT_WRITE );
$tmpFile = tempnam( \IPS\TEMP_DIRECTORY, 'IPS' );
\file_put_contents( $tmpFile, $contents );
$ftp->upload( $path, $tmpFile );
@unlink( $tmpFile );
}
if ( @\fwrite( $fh, $contents ) === FALSE )
else
{
throw new \IPS\Archive\Exception( '', \IPS\Archive\Exception::COULD_NOT_WRITE );
/* Determine if the file exists (we'll want to know this later) */
$fileExists = file_exists( $destination . '/' . $path );
$fh = @\fopen( $destination . '/' . $path, 'w+' );
if ( $fh === FALSE )
{
$lastError = error_get_last();
throw new \IPS\Archive\Exception( $lastError['message'], \IPS\Archive\Exception::COULD_NOT_WRITE );
}
if ( @\fwrite( $fh, $contents ) === FALSE )
{
$lastError = error_get_last();
throw new \IPS\Archive\Exception( $lastError['message'], \IPS\Archive\Exception::COULD_NOT_WRITE );
}
else
{
/* If the file existed before we started, we should clear it from opcache if opcache is enabled */
if( $fileExists )
{
if ( function_exists( 'opcache_invalidate' ) )
{
@opcache_invalidate( $destination . '/' . $path );
}
}
/* Otherwise, we should set file permissions on the file if it's brand new in case server defaults to something odd */
else
{
@chmod( $destination . '/' . $path, \IPS\FILE_PERMISSION_NO_WRITE );
}
}
@\fclose( $fh );
}
@\fclose( $fh );
}
$done++;