Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -30,6 +30,7 @@ class _Upload extends FormAbstract
|
||||
'storageContainer' => NULL, // The file storage container to use.
|
||||
'multiple' => TRUE, // Specifies if the field should allow multiple file uploads. Default is FALSE.
|
||||
'image' => array( 'maxWidth' => 100, 'maxHeight' => 100 ), // If the upload must be an image, can pass TRUE or an array with max width and height (in which case, image will be resized appropriately). Default is NULL. Max width/height cannot be used in conjunction with temporary uploads. If it can be, but doesn't have to an image, and you still want to specify max width and height, add an "optional" property set to true
|
||||
'checkImage' => TRUE, // If TRUE, will load uploaded images into the image processing engine to automatically reorient if needed
|
||||
'allowedFileTypes' => array( 'pdf', 'txt' ), // Allowed file extensions. NULL allows any. Default is NULL.
|
||||
'maxFileSize' => 100, // Maximum file size in megabytes. NULL is no limit. Default is NULL. Note that there *may* be server limitations regardless of this value which are calculated automatically.
|
||||
'totalMaxSize' => 100, // If this is a "multiple" upload field, the maximum storage space allowed in total in megabytes.
|
||||
@@ -48,6 +49,7 @@ class _Upload extends FormAbstract
|
||||
protected $defaultOptions = array(
|
||||
'multiple' => FALSE,
|
||||
'image' => NULL,
|
||||
'checkImage' => TRUE,
|
||||
'allowedFileTypes' => NULL,
|
||||
'maxFileSize' => NULL,
|
||||
'totalMaxSize' => NULL,
|
||||
@@ -212,10 +214,8 @@ class _Upload extends FormAbstract
|
||||
/* If there is an error, an exception will be thrown and will be caught below like normal */
|
||||
\IPS\File::validateUpload( $fileArray, $this->options['allowedFileTypes'], $this->options['maxFileSize'] );
|
||||
|
||||
if ( is_array( $this->options['image'] ) and $fileObj->isImage() )
|
||||
if ( $fileObj->isImage() AND ( $this->options['checkImage'] OR is_array( $this->options['image'] ) ) )
|
||||
{
|
||||
$options = $this->options;
|
||||
|
||||
try
|
||||
{
|
||||
$image = \IPS\Image::create( $fileObj->contents() );
|
||||
@@ -225,7 +225,10 @@ class _Upload extends FormAbstract
|
||||
$image->setExifData( $fileObj->contents() );
|
||||
}
|
||||
|
||||
$image->resizeToMax( $options['image']['maxWidth'] ?: NULL, $options['image']['maxHeight'] ?: NULL );
|
||||
if( is_array( $this->options['image'] ) )
|
||||
{
|
||||
$image->resizeToMax( $this->options['image']['maxWidth'] ?: NULL, $this->options['image']['maxHeight'] ?: NULL );
|
||||
}
|
||||
|
||||
$fileObj->replace( (string) $image );
|
||||
}
|
||||
@@ -254,6 +257,7 @@ class _Upload extends FormAbstract
|
||||
'id' => $insertId,
|
||||
'key' => $_SERVER['HTTP_X_PLUPLOAD'],
|
||||
'imagesrc' => $fileObj->isImage() ? (string) $fileObj->url : NULL,
|
||||
'videosrc' => $fileObj->isVideo() ? (string) $fileObj->url : NULL,
|
||||
'thumbnail' => ( $fileObj->isImage() AND $fileObj->attachmentThumbnailUrl !== NULL and is_string( $fileObj->attachmentThumbnailUrl ) ) ? \IPS\File::get( $this->options['storageExtension'], $fileObj->attachmentThumbnailUrl )->url : NULL,
|
||||
) );
|
||||
}
|
||||
@@ -270,6 +274,7 @@ class _Upload extends FormAbstract
|
||||
'id' => $insertId,
|
||||
'key' => $_SERVER['HTTP_X_PLUPLOAD'],
|
||||
'imagesrc' => $fileObj->isImage() ? (string) $fileObj->url : NULL,
|
||||
'videosrc' => $fileObj->isVideo() ? (string) $fileObj->url : NULL,
|
||||
'thumbnail' => ( $fileObj->isImage() AND $fileObj->attachmentThumbnailUrl !== NULL and is_string( $fileObj->attachmentThumbnailUrl ) ) ? \IPS\File::get( $this->options['storageExtension'], $fileObj->attachmentThumbnailUrl )->url : NULL,
|
||||
) );
|
||||
}
|
||||
@@ -583,6 +588,16 @@ class _Upload extends FormAbstract
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('uploaderr_total_size', FALSE, array( 'sprintf' => array( $this->options['totalMaxSize'] ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Now fix the array in case we are using the defaultValue which was array( fileurl =>, default => ) */
|
||||
$toReturn = array();
|
||||
|
||||
foreach( $return as $k => $v )
|
||||
{
|
||||
$toReturn[ $k ] = ( is_array( $v ) AND isset( $v['fileurl'] ) ) ? $v['fileurl'] : $v;
|
||||
}
|
||||
|
||||
$return = $toReturn;
|
||||
|
||||
/* Return */
|
||||
if ( !$this->options['multiple'] )
|
||||
@@ -630,33 +645,30 @@ class _Upload extends FormAbstract
|
||||
/* Normal - send to storage extension */
|
||||
else
|
||||
{
|
||||
if ( is_array( $this->options['image'] ) )
|
||||
$options = $this->options;
|
||||
$fileObjects = \IPS\File::createFromUploads( $this->options['storageExtension'], $fieldName, $this->options['allowedFileTypes'], $this->options['maxFileSize'], $this->options['totalMaxSize'], 0, function( $contents, $filename ) use ( $options )
|
||||
{
|
||||
$options = $this->options;
|
||||
$fileObjects = \IPS\File::createFromUploads( $this->options['storageExtension'], $fieldName, $this->options['allowedFileTypes'], $this->options['maxFileSize'], $this->options['totalMaxSize'], 0, function( $contents, $filename ) use ( $options )
|
||||
{
|
||||
$ext = mb_strtolower( mb_substr( $filename, mb_strrpos( $filename, '.' ) + 1 ) );
|
||||
$ext = mb_strtolower( mb_substr( $filename, mb_strrpos( $filename, '.' ) + 1 ) );
|
||||
|
||||
/* Resize images */
|
||||
if ( in_array( $ext, \IPS\Image::$imageExtensions ) )
|
||||
/* Resize images */
|
||||
if ( in_array( $ext, \IPS\Image::$imageExtensions ) AND ( is_array( $options['image'] ) OR $options['checkImage'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
$image = \IPS\Image::create( $contents );
|
||||
|
||||
if( is_array( $options['image'] ) )
|
||||
{
|
||||
$image = \IPS\Image::create( $contents );
|
||||
$image->resizeToMax( $options['image']['maxWidth'] ?: NULL, $options['image']['maxHeight'] ?: NULL );
|
||||
|
||||
return (string) $image;
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
|
||||
return (string) $image;
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}, $this->options['storageContainer'], $this->options['obscure'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$fileObjects = \IPS\File::createFromUploads( $this->options['storageExtension'], $fieldName, $this->options['allowedFileTypes'], $this->options['maxFileSize'], $this->options['totalMaxSize'], 0, NULL, $this->options['storageContainer'], $this->options['obscure'] );
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}, $this->options['storageContainer'], $this->options['obscure'] );
|
||||
|
||||
foreach ( $fileObjects as $fileObj )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user