Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -45,6 +45,7 @@ class _Upload extends FormAbstract
|
||||
'obscure' => TRUE, // Controls if an md5 hash should be added to the filename. *Must* be TRUE unless the uploaded files are public to all users (like emoticons),
|
||||
'supportsDelete' => TRUE // Should the uploaded file be direct deletable from the upload field
|
||||
'allowStockPhotos' => FALSE // If Pixabay enhancement is enabled, this will allow users to select stock art from Pixabay to upload
|
||||
'canBeModerated' => TRUE // Set to TRUE if this uploader is capable of holding the submitted content for moderation
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
@@ -67,7 +68,8 @@ class _Upload extends FormAbstract
|
||||
'default' => NULL,
|
||||
'obscure' => TRUE,
|
||||
'supportsDelete' => TRUE,
|
||||
'allowStockPhotos' => FALSE
|
||||
'allowStockPhotos' => FALSE,
|
||||
'canBeModerated' => FALSE
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -167,7 +169,7 @@ class _Upload extends FormAbstract
|
||||
/* If this has to be an image, set the allowed file types */
|
||||
if ( isset( $options['image'] ) and !isset( $options['image']['optional'] ) and !isset( $options['allowedFileTypes'] ) )
|
||||
{
|
||||
$options['allowedFileTypes'] = \IPS\Image::supportedExtensions();
|
||||
$options['allowedFileTypes'] = \IPS\Image::$imageExtensions;
|
||||
}
|
||||
|
||||
/* Call parent constructor */
|
||||
@@ -256,12 +258,16 @@ class _Upload extends FormAbstract
|
||||
$image->setExifData( $fileObj->contents() );
|
||||
}
|
||||
|
||||
$hasBeenResized = FALSE;
|
||||
if( \is_array( $this->options['image'] ) )
|
||||
{
|
||||
$image->resizeToMax( $this->options['image']['maxWidth'] ?: NULL, $this->options['image']['maxHeight'] ?: NULL );
|
||||
$hasBeenResized = $image->resizeToMax( $this->options['image']['maxWidth'] ?: NULL, $this->options['image']['maxHeight'] ?: NULL );
|
||||
}
|
||||
|
||||
$fileObj->replace( (string) $image );
|
||||
if ( $hasBeenResized or $image->hasBeenRotated )
|
||||
{
|
||||
$fileObj->replace( (string) $image );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
@@ -441,7 +447,6 @@ class _Upload extends FormAbstract
|
||||
'size' => \IPS\Output\Plugin\Filesize::humanReadableFilesize( $file->filesize(), FALSE, TRUE ),
|
||||
'sizeRaw' => $file->filesize(),
|
||||
'default' => ( isset( $attachment ) AND $attachment['default'] ) ? $attachment['default'] : NULL,
|
||||
'securityKey' => ( isset( $attachment ) ) ? $attachment['attach_security_key'] : $file->securityKey
|
||||
);
|
||||
}
|
||||
catch( \UnderflowException $e ){}
|
||||
@@ -482,7 +487,7 @@ class _Upload extends FormAbstract
|
||||
{
|
||||
/* Get the files we had already */
|
||||
$return = array();
|
||||
$tempFiles = iterator_to_array( \IPS\Db::i()->select( 'id,contents,filename,exif', 'core_files_temp', array( 'upload_key=?', md5( $this->name . session_id() ) ) )->setKeyField('id') );
|
||||
$tempFiles = iterator_to_array( \IPS\Db::i()->select( 'id,contents,filename,exif,requires_moderation', 'core_files_temp', array( 'upload_key=?', md5( $this->name . session_id() ) ) )->setKeyField('id') );
|
||||
if ( $this->options['storageExtension'] )
|
||||
{
|
||||
$existingName = $this->name . '_existing';
|
||||
@@ -501,6 +506,7 @@ class _Upload extends FormAbstract
|
||||
/* Reset the original filename to the real file name as $this->originalFilename is generated from the now AWS-safe $this->filename */
|
||||
$file->originalFilename = $tempFiles[ $tempId ]['filename'];
|
||||
$file->exifData = $tempFiles[ $tempId ]['exif'] ? json_decode( $tempFiles[ $tempId ]['exif'], TRUE ) : NULL;
|
||||
$file->requiresModeration = (bool) $tempFiles[ $tempId ]['requires_moderation'];
|
||||
$return[ $id ] = $file;
|
||||
}
|
||||
else
|
||||
@@ -701,7 +707,7 @@ class _Upload extends FormAbstract
|
||||
$ext = mb_strtolower( mb_substr( $file['name'], ( mb_strrpos( $file['name'], '.' ) + 1 ) ) );
|
||||
|
||||
/* Don't allow "XSS" in images */
|
||||
if( \in_array( $ext, \IPS\File::$safeFileExtensions ) AND \in_array( $ext, \IPS\Image::supportedExtensions() ) )
|
||||
if( \in_array( $ext, \IPS\File::$safeFileExtensions ) AND \in_array( $ext, \IPS\Image::$imageExtensions ) )
|
||||
{
|
||||
if( \IPS\File::checkXssInFile( file_get_contents( $file['tmp_name'] ) ) )
|
||||
{
|
||||
@@ -718,36 +724,42 @@ class _Upload extends FormAbstract
|
||||
else
|
||||
{
|
||||
$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 )
|
||||
$canBeModerated = $options['canBeModerated'];
|
||||
|
||||
$fileObjects = \IPS\File::createFromUploads( $this->options['storageExtension'], $fieldName, $this->options['allowedFileTypes'], $this->options['maxFileSize'], $this->options['totalMaxSize'], 0, function( $contents, $filename, $i ) use ( $options, &$requiresModeration, $canBeModerated )
|
||||
{
|
||||
$ext = mb_strtolower( mb_substr( $filename, mb_strrpos( $filename, '.' ) + 1 ) );
|
||||
|
||||
/* Resize images */
|
||||
if ( \in_array( $ext, \IPS\Image::supportedExtensions() ) AND ( \is_array( $options['image'] ) OR $options['checkImage'] ) )
|
||||
/* Do image-specific stuff */
|
||||
if ( \in_array( $ext, \IPS\Image::$imageExtensions ) )
|
||||
{
|
||||
try
|
||||
/* Resize */
|
||||
$image = NULL;
|
||||
$hasBeenResized = FALSE;
|
||||
if ( \is_array( $options['image'] ) OR $options['checkImage'] )
|
||||
{
|
||||
$image = \IPS\Image::create( $contents );
|
||||
|
||||
if( $image::exifSupported() )
|
||||
try
|
||||
{
|
||||
$image->setExifData( $contents );
|
||||
$image = \IPS\Image::create( $contents );
|
||||
|
||||
if( \is_array( $options['image'] ) )
|
||||
{
|
||||
$hasBeenResized = $image->resizeToMax( $options['image']['maxWidth'] ?: NULL, $options['image']['maxHeight'] ?: NULL );
|
||||
}
|
||||
|
||||
if ( $hasBeenResized or $image->hasBeenRotated )
|
||||
{
|
||||
$contents = (string) $image;
|
||||
}
|
||||
}
|
||||
|
||||
if( \is_array( $options['image'] ) )
|
||||
{
|
||||
$image->resizeToMax( $options['image']['maxWidth'] ?: NULL, $options['image']['maxHeight'] ?: NULL );
|
||||
}
|
||||
|
||||
return (string) $image;
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
|
||||
return $contents;
|
||||
}, $this->options['storageContainer'], $this->options['obscure'] );
|
||||
|
||||
foreach ( $fileObjects as $fileObj )
|
||||
foreach ( $fileObjects as $i => $fileObj )
|
||||
{
|
||||
$exif = NULL;
|
||||
|
||||
@@ -756,15 +768,17 @@ class _Upload extends FormAbstract
|
||||
$exif = json_encode( $fileObj->exifData );
|
||||
}
|
||||
|
||||
$insertId = \IPS\Db::i()->insert( 'core_files_temp', array(
|
||||
'upload_key' => md5( $this->name . session_id() ),
|
||||
'filename' => $fileObj->originalFilename,
|
||||
'mime' => \IPS\File::getMimeType( $fileObj->originalFilename ),
|
||||
'contents' => (string) $fileObj,
|
||||
'time' => time(),
|
||||
'storage_extension' => $this->options['storageExtension'],
|
||||
'exif' => $exif
|
||||
) );
|
||||
$data = $this->populateTempData( array(
|
||||
'upload_key' => md5( $this->name . session_id() ),
|
||||
'filename' => $fileObj->originalFilename,
|
||||
'mime' => \IPS\File::getMimeType( $fileObj->originalFilename ),
|
||||
'contents' => (string) $fileObj,
|
||||
'time' => time(),
|
||||
'storage_extension' => $this->options['storageExtension'],
|
||||
'exif' => $exif
|
||||
), $fileObj, $options );
|
||||
|
||||
$insertId = \IPS\Db::i()->insert( 'core_files_temp', $data );
|
||||
|
||||
if ( $this->options['callback'] )
|
||||
{
|
||||
@@ -799,6 +813,19 @@ class _Upload extends FormAbstract
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish populating the data before its inserted
|
||||
*
|
||||
* @param array $data Array of data to change/add to
|
||||
* @param \IPS\File $fileObj File Object data
|
||||
* @param array $options Field options
|
||||
* @return array
|
||||
*/
|
||||
protected function populateTempData( array $data, \IPS\File $fileObj, array $options ): array
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* String Value
|
||||
|
||||
Reference in new issue
Block a user