Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+81 -6
View File
@@ -25,8 +25,13 @@ abstract class _File
/**
* @brief File extensions considered safe. Not an exhaustive list but these are the files we're most interested in being recognised.
*/
public static $safeFileExtensions = array( 'js', 'css', 'txt', 'xml', 'ico', 'gif', 'jpg', 'jpe', 'jpeg', 'png', 'mp4', '3gp', 'mov', 'ogg', 'ogv', 'mp3', 'mpg', 'mpeg', 'ico', 'flv', 'webm', 'wmv', 'avi', 'm4v', 'svg' );
public static $safeFileExtensions = array( 'js', 'css', 'txt', 'xml', 'ico', 'gif', 'jpg', 'jpe', 'jpeg', 'png', 'mp4', '3gp', 'mov', 'ogg', 'ogv', 'mp3', 'mpg', 'mpeg', 'ico', 'flv', 'webm', 'wmv', 'avi', 'm4v' );
/**
* @brief File extensions for HTML5 compatible videos
*/
public static $videoExtensions = array( 'mp4', '3gp', 'mov', 'ogg', 'ogv', 'mpg', 'mpeg', 'flv', 'webm', 'wmv', 'avi', 'm4v' );
/**
* @brief Does this storage method support chunked uploads?
*/
@@ -72,12 +77,36 @@ abstract class _File
else
{
$settings = json_decode( \IPS\Settings::i()->upload_settings, TRUE );
/* If this storage extension hasn't been set yet, grab the first *valid* configuration and use that (and set it for future use) */
if ( !isset( $settings[ "filestorage__{$storageExtension}" ] ) )
{
foreach ( static::$storageConfigurations as $k => $data )
{
$configurationId = $k;
break;
/* Test the storage config - the first one that works wins! */
$classname = 'IPS\File\\' . $data['method'];
$class = new $classname( json_decode( $data['configuration'], TRUE ) );
$class->configurationId = $k;
try
{
/* Test - if no LogicException is thrown we are ok */
$configSettings = json_decode( $data['configuration'], TRUE );
$class->testSettings( $configSettings );
/* Still here? Then let's use this configuration. */
$configurationId = $k;
/* Now store this for future reference */
$settings["filestorage__{$storageExtension}"] = $configurationId;
\IPS\Settings::i()->changeValues( array( 'upload_settings' => json_encode( $settings ) ) );
break;
}
catch( \LogicException $e )
{
/* Move on to the next file storage configuration */
continue;
}
}
}
else
@@ -113,6 +142,7 @@ abstract class _File
}
else
{
$configurationId = $settings[ "filestorage__{$storageExtension}" ];
$storageConfigurations = static::$storageConfigurations;
static::$storageConfigurations[ $settings[ "filestorage__{$storageExtension}" ] ] = array_shift( $storageConfigurations );
}
@@ -153,6 +183,11 @@ abstract class _File
return static::$storageConfigurations;
}
/**
* @brief Copy files instead of moving them
*/
public static $copyFiles = FALSE;
/**
* Create File
*
@@ -816,7 +851,7 @@ abstract class _File
/* Make sure name doesn't have anything that may break URLs */
if ( preg_match( '#[^a-zA-Z0-9!\-_\.\*\(\)\@]#', $filename ) )
{
$filename = uniqid() . '_' . preg_replace( '#[^a-zA-Z0-9!\-_\.\*\(\)\@]#', '', $filename );
$filename = mt_rand() . '_' . preg_replace( '#[^a-zA-Z0-9!\-_\.\*\(\)\@]#', '', $filename );
}
if ( $obscure )
@@ -859,7 +894,7 @@ abstract class _File
$filename = str_replace( '.' . $matches[2], '_' . $matches[2], $filename );
}
return str_replace( array( ' ', '#' ), '_', $filename ) . '.' . md5( uniqid( \IPS\SUITE_UNIQUE_KEY ) . mt_rand() ) . ( ( $safe ) ? '.' . $ext : '' );
return str_replace( array( ' ', '#' ), '_', $filename ) . '.' . md5( mt_rand() ) . ( ( $safe ) ? '.' . $ext : '' );
}
/**
@@ -1213,6 +1248,44 @@ abstract class _File
return FALSE;
}
/**
* Determine if the file is a video
*
* @return bool
*/
public function isVideo()
{
$ext = mb_substr( $this->originalFilename, mb_strrpos( $this->originalFilename, '.' ) + 1 );
if ( in_array( mb_strtolower( $ext ), \IPS\File::$videoExtensions ) )
{
return TRUE;
}
return FALSE;
}
/**
* Get media type ("file", "image" or "video")
*
* @return bool
*/
public function mediaType()
{
if ( $this->isVideo() )
{
return 'video';
}
elseif ( $this->isImage() )
{
return 'image';
}
else
{
return 'file';
}
}
/**
* If the file is an image, get the dimensions
@@ -1220,6 +1293,7 @@ abstract class _File
* @return array
* @throws \DomainException
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function getImageDimensions()
{
@@ -1492,12 +1566,13 @@ abstract class _File
/**
* Get output for API
*
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
* @return array
* @apiresponse string name The filename
* @apiresponse string url URL to where file is stored
* @apiresponse int size Filesize in bytes
*/
public function apiOutput()
public function apiOutput( \IPS\Member $authorizedMember = NULL )
{
return array(
'name' => $this->originalFilename,