Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+79 -42
View File
@@ -11,7 +11,7 @@
namespace IPS\File;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -252,12 +252,12 @@ class _FileSystem extends \IPS\File
if ( $this->contents === FALSE )
{
throw new \IPS\File\Exception( $this->container . '/' . $this->filename, \IPS\File\Exception::CANNOT_OPEN );
throw new \IPS\File\Exception( $this->container . '/' . $this->filename, \IPS\File\Exception::CANNOT_OPEN, $this->originalFilename );
}
}
else
{
throw new \IPS\File\Exception( $this->container . '/' . $this->filename, \IPS\File\Exception::DOES_NOT_EXIST );
throw new \IPS\File\Exception( $this->container . '/' . $this->filename, \IPS\File\Exception::DOES_NOT_EXIST, $this->originalFilename );
}
}
@@ -313,7 +313,7 @@ class _FileSystem extends \IPS\File
if( !@\copy( $this->temporaryFilePath, "{$folder}/{$this->filename}" ) )
{
\IPS\Log::log( "Could not copy file {$folder}/{$this->filename}" , 'FileSystem' );
throw new \IPS\File\Exception( "{$folder}/{$this->filename}", \IPS\File\Exception::CANNOT_COPY );
throw new \IPS\File\Exception( "{$folder}/{$this->filename}", \IPS\File\Exception::CANNOT_COPY, $this->originalFilename );
}
}
else
@@ -321,7 +321,7 @@ class _FileSystem extends \IPS\File
if( !@\rename( $this->temporaryFilePath, "{$folder}/{$this->filename}" ) )
{
\IPS\Log::log( "Could not move file {$folder}/{$this->filename}" , 'FileSystem' );
throw new \IPS\File\Exception( "{$folder}/{$this->filename}", \IPS\File\Exception::CANNOT_MOVE );
throw new \IPS\File\Exception( "{$folder}/{$this->filename}", \IPS\File\Exception::CANNOT_MOVE, $this->originalFilename );
}
}
@@ -334,7 +334,7 @@ class _FileSystem extends \IPS\File
if ( !@\file_put_contents( "{$folder}/{$this->filename}", $contents ) )
{
\IPS\Log::log( "Could not write file {$folder}/{$this->filename}" , 'FileSystem' );
throw new \IPS\File\Exception( "{$folder}/{$this->filename}", \IPS\File\Exception::CANNOT_WRITE );
throw new \IPS\File\Exception( "{$folder}/{$this->filename}", \IPS\File\Exception::CANNOT_WRITE, $this->originalFilename );
}
@chmod( "{$folder}/{$this->filename}", \IPS\IPS_FILE_PERMISSION );
@@ -347,7 +347,7 @@ class _FileSystem extends \IPS\File
}
/* Clear zend opcache if enabled */
if ( function_exists( 'opcache_invalidate' ) )
if ( \function_exists( 'opcache_invalidate' ) )
{
@opcache_invalidate( "{$folder}/{$this->filename}" );
}
@@ -367,7 +367,7 @@ class _FileSystem extends \IPS\File
$immediateCaller = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 );
$debug = array_map( function( $row ) {
return array_filter( $row, function( $key ) {
return in_array( $key, array( 'class', 'function', 'line' ) );
return \in_array( $key, array( 'class', 'function', 'line' ) );
}, ARRAY_FILTER_USE_KEY );
}, debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) );
$this->log( "file_deletion", 'delete', $debug, 'log' );
@@ -377,7 +377,7 @@ class _FileSystem extends \IPS\File
$result = @unlink( "{$this->configuration['dir']}/{$this->container}/{$this->filename}" );
/* Clear zend opcache if enabled */
if ( function_exists( 'opcache_invalidate' ) )
if ( \function_exists( 'opcache_invalidate' ) )
{
@opcache_invalidate( "{$this->configuration['dir']}/{$this->container}/{$this->filename}" );
}
@@ -433,7 +433,7 @@ class _FileSystem extends \IPS\File
unlink( $file );
/* Clear zend opcache if enabled */
if( $skipClear === FALSE and function_exists( 'opcache_invalidate' ) )
if( $skipClear === FALSE and \function_exists( 'opcache_invalidate' ) )
{
@opcache_invalidate( $file );
}
@@ -451,44 +451,75 @@ class _FileSystem extends \IPS\File
}
/**
* Append more contents in a chunked upload
* Initiate a chunked upload
*
* @param string $filename The filename that was created
* @param string $chunk The temp filename for the new chunk to append
* @param string|NULL $rename If a value is provided, rename the file after appending (will be provided for the last chunk)
* @param string|NULL $container Key to identify container for storage
* @return string
* @param string $filename The desired filename
* @param string|null $container Key to identify container for storage
* @param bool $obscure Controls if an md5 hash should be added to the filename
* @return mixed A reference to be passed to chunkProcess() and chunkFinish()
* @throws \RuntimeException
*/
public function chunkAppend( $filename, $chunk, $rename=NULL, $container=NULL )
public function chunkInit( $filename, $container = '', $obscure = TRUE )
{
/* If we don't have a chunk folder, create one */
$tempFolder = $this->getFolder( 'chunks' );
/* Get the final folder name */
$folder = $this->getFolder( $container );
$file = fopen( "{$this->configuration['dir']}/{$folder}/{$filename}", 'ab' );
$_chunk = fopen( $chunk, 'rb' );
while ( $buffer = fread( $_chunk, 4096 ) )
{
\fwrite( $file, $buffer );
}
fclose( $file );
@unlink( $chunk );
/* Clear zend opcache if enabled */
if ( function_exists( 'opcache_invalidate' ) )
{
@opcache_invalidate( "{$this->configuration['dir']}/{$folder}/{$filename}" );
}
if ( $rename )
{
$newFileName = static::obscureFilename( $rename );
rename( "{$this->configuration['dir']}/{$folder}/{$filename}", "{$this->configuration['dir']}/{$folder}/{$newFileName}" );
return "{$folder}/{$newFileName}";
}
return "{$folder}/{$filename}";
$return = array( 'temp' => "{$this->configuration['dir']}/{$tempFolder}/chunk-" . md5( uniqid() ) . '.txt', 'final' => "{$folder}/" . ( $obscure ? static::obscureFilename( $filename ) : $filename ) );
touch( $return['temp'] );
return $return;
}
/**
* Append more contents in a chunked upload
*
* @param mixed $ref The reference for this upload as returned by chunkInit()
* @param string $temporaryFileOrContents The contents to write, or the path to the temporary file on disk with the contents
* @param int $chunkNumber Which chunk this is (0 for the first chunk, 1 for the second, etc)
* @param bool $isContents If TRUE, $temporaryFileOrContents is treated as raw contents. If FALSE, is path to file
* @return mixed Updated reference fore future chunkProcess() calls and chunkFinish()
* @throws \RuntimeException
*/
public function chunkProcess( $ref, $temporaryFileOrContents, $chunkNumber, $isContents = FALSE )
{
$file = fopen( $ref['temp'], 'ab' );
if ( $isContents )
{
\fwrite( $file, $temporaryFileOrContents );
}
else
{
$_chunk = fopen( $temporaryFileOrContents, 'rb' );
while ( $buffer = fread( $_chunk, 4096 ) )
{
\fwrite( $file, $buffer );
}
@unlink( $temporaryFileOrContents );
}
fclose( $file );
if ( \function_exists( 'opcache_invalidate' ) )
{
@opcache_invalidate( $ref['temp'] );
}
return $ref;
}
/**
* Finalize a chunked upload
*
* @param mixed $ref The reference for this upload as returned by chunkInit()
* @return string The file's reference which can be passed to \IPS\File::get() as the URL
* @throws \RuntimeException
*/
public function chunkFinish( $ref )
{
rename( $ref['temp'], "{$this->configuration['dir']}/{$ref['final']}" );
return $ref['final'];
}
/* !File System Utility Methods */
@@ -599,10 +630,16 @@ class _FileSystem extends \IPS\File
/**
* Get filesize (in bytes)
*
* @return string
* @return string|bool
*/
public function filesize()
{
return file_exists( $this->configuration['dir'] . '/' . $this->container . '/' . $this->filename ) ? @filesize( $this->configuration['dir'] . '/' . $this->container . '/' . $this->filename ) : NULL;
if( $this->_cachedFilesize !== NULL )
{
return $this->_cachedFilesize;
}
$this->_cachedFilesize = file_exists( $this->configuration['dir'] . '/' . $this->container . '/' . $this->filename ) ? @filesize( $this->configuration['dir'] . '/' . $this->container . '/' . $this->filename ) : FALSE;
return $this->_cachedFilesize;
}
}