Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+209
-90
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Helpers\Form;
|
||||
|
||||
/* 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;
|
||||
@@ -45,7 +45,6 @@ class _Editor extends FormAbstract
|
||||
'maxLength' => FALSE, // The maximum length. Note that the content is HTML, so this isn't the maximum number of visible characters, so should only be used for database limits. The database's max allowed packet will override if smaller
|
||||
'editorId' => NULL, // Passed to editorAttachments. Only necessary if the name may be changed
|
||||
'allowAttachments => TRUE, // Should the editor show upload options?
|
||||
'embedLocalOnly' => FALSE, // Allow local embeds only
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
@@ -65,7 +64,7 @@ class _Editor extends FormAbstract
|
||||
'maxLength' => 16777215, // The default for MEDIUMTEXT */
|
||||
'editorId' => NULL,
|
||||
'allowAttachments' => TRUE,
|
||||
'embedLocalOnly' => FALSE
|
||||
'ipsPlugins' => "ipsautolink,ipsautosave,ipsctrlenter,ipscode,ipscontextmenu,ipsemoticon,ipsimage,ipslink,ipsmentions,ipspage,ipspaste,ipspreview,ipsquote,ipsspoiler,ipsautogrow,ipssource,removeformat"
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -85,18 +84,26 @@ class _Editor extends FormAbstract
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Sets that the field is required if there is a minimum length and vice-versa
|
||||
*
|
||||
* @see \IPS\Helpers\Form\FormAbstract::__construct
|
||||
* @note $name and $htmlId must be different
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool|NULL $required Required? (NULL for not required, but appears to be so)
|
||||
* @param array $options Type-specific options
|
||||
* @param callback $customValidationCode Custom validation code
|
||||
* @param string $prefix HTML to show before input field
|
||||
* @param string $suffix HTML to show after input field
|
||||
* @param string $id The ID to add to the row
|
||||
* @return void
|
||||
* @throws \OutOfBoundsException
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->postKey = md5( $args[3]['autoSaveKey'] . ':' . session_id() );
|
||||
|
||||
$this->postKey = md5( $options['autoSaveKey'] . ':' . session_id() );
|
||||
|
||||
if ( \IPS\Settings::i()->giphy_enabled )
|
||||
{
|
||||
$this->defaultOptions['ipsPlugins'] .= ',ipsgiphy';
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->usingEditor ) and \IPS\Request::i()->isAjax() and \IPS\Dispatcher::hasInstance() and \IPS\Dispatcher::i()->controllerLocation == 'front' )
|
||||
{
|
||||
\IPS\Session::i()->setUsingEditor();
|
||||
@@ -106,32 +113,27 @@ class _Editor extends FormAbstract
|
||||
$this->defaultOptions['controller'] = 'app=core&module=system&controller=editor';
|
||||
|
||||
/* Get our extension */
|
||||
if ( !isset( $args[3]['allButtons'] ) or !$args[3]['allButtons'] )
|
||||
if ( !isset( $options['allButtons'] ) or !$options['allButtons'] )
|
||||
{
|
||||
$extensions = \IPS\Application::load( $args[3]['app'] )->extensions( 'core', 'EditorLocations' );
|
||||
if ( !isset( $extensions[ $args[3]['key'] ] ) )
|
||||
$extensions = \IPS\Application::load( $options['app'] )->extensions( 'core', 'EditorLocations' );
|
||||
if ( !isset( $extensions[ $options['key'] ] ) )
|
||||
{
|
||||
throw new \OutOfBoundsException( $args[3]['key'] );
|
||||
throw new \OutOfBoundsException( $options['key'] );
|
||||
}
|
||||
|
||||
$this->extension = $extensions[ $args[3]['key'] ];
|
||||
|
||||
if ( method_exists( $this->extension, 'embedLocalOnly' ) )
|
||||
{
|
||||
$args[3]['embedLocalOnly'] = $this->extension->embedLocalOnly();
|
||||
}
|
||||
$this->extension = $extensions[ $options['key'] ];
|
||||
}
|
||||
|
||||
/* Don't minimize if we have a value */
|
||||
$name = isset( $args[3]['editorId'] ) ? $args[3]['editorId'] : $args[0];
|
||||
if ( ( !isset( $args[3]['minimizeWithContent'] ) or !$args[3]['minimizeWithContent'] ) and ( $args[1] or \IPS\Request::i()->$name or ( isset( \IPS\Request::i()->cookie['vle_editor'] ) and \IPS\Request::i()->cookie['vle_editor'] ) ) )
|
||||
$name = isset( $options['editorId'] ) ? $options['editorId'] : $name;
|
||||
if ( ( !isset( $options['minimizeWithContent'] ) or !$options['minimizeWithContent'] ) and ( $defaultValue or \IPS\Request::i()->$name or ( isset( \IPS\Request::i()->cookie['vle_editor'] ) and \IPS\Request::i()->cookie['vle_editor'] ) ) )
|
||||
{
|
||||
$args[3]['minimize'] = NULL;
|
||||
$options['minimize'] = NULL;
|
||||
}
|
||||
|
||||
/* Create the upload helper - if the form has been submitted, this has to be done before parent::__construct() as we need the uploader present for getValue(), but for views, we won't load until the editor is clicked */
|
||||
$this->options = array_merge( $this->defaultOptions, $args[3] );
|
||||
if ( $this->canAttach() )
|
||||
$this->options = array_merge( $this->defaultOptions, $options );
|
||||
if ( $this->canAttach() AND $this->options['allowAttachments'] )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->getUploader ) and \IPS\Request::i()->getUploader === $name or ( isset( \IPS\Request::i()->postKey ) and \IPS\Request::i()->postKey === $this->postKey and isset( \IPS\Request::i()->deleteFile ) ) )
|
||||
{
|
||||
@@ -166,14 +168,14 @@ class _Editor extends FormAbstract
|
||||
}
|
||||
if ( \IPS\Data\Store::i()->maxAllowedPacket )
|
||||
{
|
||||
if ( !isset( $args[3]['maxLength'] ) or $args[3]['maxLength'] > \IPS\Data\Store::i()->maxAllowedPacket )
|
||||
if ( !isset( $options['maxLength'] ) or $options['maxLength'] > \IPS\Data\Store::i()->maxAllowedPacket )
|
||||
{
|
||||
$args[3]['maxLength'] = \IPS\Data\Store::i()->maxAllowedPacket;
|
||||
$options['maxLength'] = \IPS\Data\Store::i()->maxAllowedPacket;
|
||||
}
|
||||
}
|
||||
|
||||
/* Go */
|
||||
call_user_func_array( 'parent::__construct', $args );
|
||||
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
|
||||
|
||||
/* Preview? */
|
||||
if ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->_previewField ) and \IPS\Request::i()->_previewField === $this->name )
|
||||
@@ -181,8 +183,8 @@ class _Editor extends FormAbstract
|
||||
\IPS\Output::i()->sendOutput( $this->getValue() );
|
||||
}
|
||||
|
||||
/* Include editor JS - but not if loaded via ajax. JS loader will handle that on demand */
|
||||
if( !\IPS\Request::i()->isAjax() )
|
||||
/* Include editor JS - but not if this page was loaded via ajax OR if we're a guest and the editor is minimized - because the JS loader will handle that on demand */
|
||||
if( ( !$this->options['minimize'] or \IPS\Member::loggedIn()->member_id ) and !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
if ( \IPS\IN_DEV )
|
||||
{
|
||||
@@ -193,6 +195,23 @@ class _Editor extends FormAbstract
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, array( \IPS\Http\Url::internal( 'applications/core/interface/ckeditor/ckeditor/ckeditor.js', 'none', NULL, array(), \IPS\Http\Url::PROTOCOL_RELATIVE ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* And send a preload header for editor.css if we can, but not if we are using IN_DEV */
|
||||
if( !\IPS\Request::i()->isAjax() AND !\IPS\IN_DEV )
|
||||
{
|
||||
/* If we don't have the 'timestamp' parameter cached we need to fetch it */
|
||||
if( !isset( \IPS\Data\Store::i()->editorTimestamp ) OR !\IPS\Data\Store::i()->editorTimestamp )
|
||||
{
|
||||
$scriptCode = \file_get_contents( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/ckeditor.js' );
|
||||
preg_match( "/\{timestamp:\"(.+?)\"/", $scriptCode, $matches );
|
||||
|
||||
\IPS\Data\Store::i()->editorTimestamp = $matches[1];
|
||||
}
|
||||
|
||||
$cssUrl = \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->base_url, '/' ) . '/applications/core/interface/ckeditor/ckeditor/skins/' . \IPS\Theme::i()->editor_skin . '/editor.css?t=' . \IPS\Data\Store::i()->editorTimestamp );
|
||||
|
||||
\IPS\Output::i()->linkTags[] = array( 'as' => 'style', 'rel' => 'preload', 'href' => (string) $cssUrl );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,7 +233,7 @@ class _Editor extends FormAbstract
|
||||
{
|
||||
foreach ( $rows as $rowId => $data )
|
||||
{
|
||||
if ( is_array( $data ) )
|
||||
if ( \is_array( $data ) )
|
||||
{
|
||||
$allowed[ $device ][ $rowId ]['name'] = $data['name'];
|
||||
foreach ( $data['items'] as $k => $v )
|
||||
@@ -253,10 +272,6 @@ class _Editor extends FormAbstract
|
||||
/* Clean resources in ACP */
|
||||
$value = $this->value;
|
||||
\IPS\Output::i()->parseFileObjectUrls( $value );
|
||||
if( \IPS\Dispatcher::hasInstance() AND \IPS\Dispatcher::i()->controllerLocation == 'admin' )
|
||||
{
|
||||
$value = \IPS\Text\Parser::mungeResources( $value );
|
||||
}
|
||||
|
||||
/* Fix Emoji */
|
||||
$value = \IPS\Output::i()->replaceEmojiWithImages( $value );
|
||||
@@ -289,7 +304,7 @@ class _Editor extends FormAbstract
|
||||
/* Or if the user can't attach, just show a bar */
|
||||
else
|
||||
{
|
||||
$attachmentArea = \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->editorAttachmentsPlaceholder( $this->name, $this->postKey, $this->noUploaderError );
|
||||
$attachmentArea = \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->editorAttachmentsPlaceholder( $this->name, $this->postKey, $this->noUploaderError, $this->canUseMediaExtension() );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
@@ -345,7 +360,7 @@ class _Editor extends FormAbstract
|
||||
{
|
||||
$value = preg_replace( '/[\x{200B}\x{2063}]/u', '', $value );
|
||||
}
|
||||
|
||||
|
||||
/* Parse value */
|
||||
if ( $value )
|
||||
{
|
||||
@@ -357,38 +372,58 @@ class _Editor extends FormAbstract
|
||||
if ( $this->uploader )
|
||||
{
|
||||
$inserts = array();
|
||||
$fileAttachments = array();
|
||||
|
||||
foreach ( $this->getAttachments() as $attachment )
|
||||
{
|
||||
if ( !isset( $parser ) or !in_array( $attachment['attach_id'], $parser->mappedAttachments ) or array_key_exists( $attachment['attach_id'], $parser->existingAttachments ) )
|
||||
if ( !isset( $parser ) or !\in_array( $attachment['attach_id'], $parser->mappedAttachments ) or array_key_exists( $attachment['attach_id'], $parser->existingAttachments ) )
|
||||
{
|
||||
$ext = mb_substr( $attachment['attach_file'], mb_strrpos( $attachment['attach_file'], '.' ) + 1 );
|
||||
if ( in_array( mb_strtolower( $ext ), \IPS\File::$videoExtensions ) )
|
||||
if ( \in_array( mb_strtolower( $ext ), \IPS\File::$videoExtensions ) )
|
||||
{
|
||||
$value .= \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedVideo( $attachment['attach_location'], \IPS\Http\Url::baseUrl( \IPS\Http\Url::PROTOCOL_RELATIVE ) . "applications/core/interface/file/attachment.php?id=" . $attachment['attach_id'], $attachment['attach_file'], \IPS\File::getMimeType( $attachment['attach_file'] ), $attachment['attach_id'] );
|
||||
}
|
||||
elseif ( $attachment['attach_is_image'] )
|
||||
{
|
||||
$value .= \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedImage( $attachment['attach_location'], $attachment['attach_thumb_location'] ? $attachment['attach_thumb_location'] : $attachment['attach_location'], $attachment['attach_file'], $attachment['attach_id'] );
|
||||
if ( $attachment['attach_thumb_location'] )
|
||||
{
|
||||
$ratio = round( ( $attachment['attach_thumb_height'] / $attachment['attach_thumb_width'] ) * 100, 2 );
|
||||
$width = $attachment['attach_thumb_width'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ratio = round( ( $attachment['attach_img_height'] / $attachment['attach_img_width'] ) * 100, 2 );
|
||||
$width = $attachment['attach_img_width'];
|
||||
}
|
||||
|
||||
$value .= \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedImage( $attachment['attach_location'], $attachment['attach_thumb_location'] ? $attachment['attach_thumb_location'] : $attachment['attach_location'], $attachment['attach_file'], $attachment['attach_id'], $width, $ratio );
|
||||
}
|
||||
else
|
||||
{
|
||||
$value .= \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedFile( \IPS\Http\Url::baseUrl( \IPS\Http\Url::PROTOCOL_RELATIVE ) . "applications/core/interface/file/attachment.php?id=" . $attachment['attach_id'], $attachment['attach_file'] );
|
||||
$fileAttachments[] = \IPS\Theme::i()->getTemplate( 'editor', 'core', 'global' )->attachedFile( \IPS\Http\Url::baseUrl() . "applications/core/interface/file/attachment.php?id=" . $attachment['attach_id'], $attachment['attach_file'], FALSE, $attachment['attach_ext'], $attachment['attach_id'] );
|
||||
}
|
||||
|
||||
if ( !isset( $parser ) or !in_array( $attachment['attach_id'], $parser->mappedAttachments ) )
|
||||
if ( !isset( $parser ) or !\in_array( $attachment['attach_id'], $parser->mappedAttachments ) )
|
||||
{
|
||||
$inserts[] = array(
|
||||
'attachment_id' => $attachment['attach_id'],
|
||||
'location_key' => "{$this->options['app']}_{$this->options['key']}",
|
||||
'id1' => ( is_array( $this->options['attachIds'] ) and isset( $this->options['attachIds'][0] ) ) ? $this->options['attachIds'][0] : NULL,
|
||||
'id2' => ( is_array( $this->options['attachIds'] ) and isset( $this->options['attachIds'][1] ) ) ? $this->options['attachIds'][1] : NULL,
|
||||
'id3' => ( is_array( $this->options['attachIds'] ) and isset( $this->options['attachIds'][2] ) ) ? $this->options['attachIds'][2] : NULL,
|
||||
'temp' => is_string( $this->options['attachIds'] ) ? $this->options['attachIds'] : ( $this->options['attachIds'] === NULL ? md5( $this->options['autoSaveKey'] ) : $this->options['attachIds'] )
|
||||
'id1' => ( \is_array( $this->options['attachIds'] ) and isset( $this->options['attachIds'][0] ) ) ? $this->options['attachIds'][0] : NULL,
|
||||
'id2' => ( \is_array( $this->options['attachIds'] ) and isset( $this->options['attachIds'][1] ) ) ? $this->options['attachIds'][1] : NULL,
|
||||
'id3' => ( \is_array( $this->options['attachIds'] ) and isset( $this->options['attachIds'][2] ) ) ? $this->options['attachIds'][2] : NULL,
|
||||
'temp' => \is_string( $this->options['attachIds'] ) ? $this->options['attachIds'] : ( $this->options['attachIds'] === NULL ? md5( $this->options['autoSaveKey'] ) : $this->options['attachIds'] )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if( count( $inserts ) and !isset( \IPS\Request::i()->_previewField ) )
|
||||
|
||||
/* Add any file attachments on a single line */
|
||||
if( \count( $fileAttachments ) )
|
||||
{
|
||||
$value .= str_replace( \IPS\Http\Url::baseUrl(), '<___base_url___>/', "<p>" . implode( ' ', $fileAttachments ) . "</p>" );
|
||||
}
|
||||
|
||||
if( \count( $inserts ) and !isset( \IPS\Request::i()->_previewField ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_attachments_map', $inserts, TRUE );
|
||||
}
|
||||
@@ -494,6 +529,33 @@ class _Editor extends FormAbstract
|
||||
}
|
||||
return $canAttach;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the member attach any of his existing media uploads?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function canUseMediaExtension()
|
||||
{
|
||||
/* If we have an extension and it implicit disallows any attaachments, don't allow media extensions too , i.e. contact us form needs this */
|
||||
if ( $this->extension )
|
||||
{
|
||||
$extensionCanAttach = $this->extension->canAttach( \IPS\Member::loggedIn(), $this );
|
||||
if ( $extensionCanAttach === FALSE )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'EditorMedia' ) as $k => $class )
|
||||
{
|
||||
if ( $class->count( \IPS\Member::loggedIn(), '' ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Error message to display if we're not showing the uploader
|
||||
@@ -521,7 +583,7 @@ class _Editor extends FormAbstract
|
||||
{
|
||||
try
|
||||
{
|
||||
$file = \IPS\File::get( 'core_Attachment', $attachment['attach_location'] );
|
||||
$file = \IPS\File::get( 'core_Attachment', $attachment['attach_location'], $attachment['attach_filesize'] );
|
||||
$file->attachmentThumbnailUrl = $attachment['attach_thumb_location'] ? \IPS\File::get( 'core_Attachment', $attachment['attach_thumb_location'] )->url : $file->url;
|
||||
|
||||
/* Reset the original filename based on the attachment record as filenames can be renamed if they contain special characters as AWS being the lowest common denominator cannot
|
||||
@@ -536,49 +598,37 @@ class _Editor extends FormAbstract
|
||||
}
|
||||
|
||||
/* Can we upload more? */
|
||||
$maxTotalSize = array();
|
||||
if ( \IPS\Member::loggedIn()->group['g_attach_max'] > 0 and \IPS\Member::loggedIn()->member_id )
|
||||
$error = NULL;
|
||||
$maxTotalSize = NULL;
|
||||
if ( $maxTotalSize = static::maxTotalAttachmentSize( \IPS\Member::loggedIn(), $currentPostUsage, $error ) )
|
||||
{
|
||||
/* Only query logged in member's usage once per page load, even if there are more than one editor */
|
||||
static $loggedInMembersAttachmentUsage = NULL;
|
||||
|
||||
if( $loggedInMembersAttachmentUsage === NULL )
|
||||
{
|
||||
$loggedInMembersAttachmentUsage = \IPS\Db::i()->select( 'SUM(attach_filesize)', 'core_attachments', array( 'attach_member_id=?', \IPS\Member::loggedIn()->member_id ) )->first();
|
||||
}
|
||||
|
||||
$globalSpaceRemaining = ( ( \IPS\Member::loggedIn()->group['g_attach_max'] * 1024 ) - $loggedInMembersAttachmentUsage ) / 1048576;
|
||||
$maxTotalSize[] = $globalSpaceRemaining;
|
||||
|
||||
if ( $globalSpaceRemaining <= 0 )
|
||||
{
|
||||
$this->noUploaderError = 'editor_used_global_space';
|
||||
}
|
||||
$maxTotalSize = $maxTotalSize / 1048576;
|
||||
$this->noUploaderError = $error;
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->group['g_attach_per_post'] )
|
||||
{
|
||||
$perPostSpaceRemaining = ( ( \IPS\Member::loggedIn()->group['g_attach_per_post'] * 1024 ) - $currentPostUsage ) / 1048576;
|
||||
$maxTotalSize[] = $perPostSpaceRemaining;
|
||||
if ( $perPostSpaceRemaining <= 0 )
|
||||
{
|
||||
$this->noUploaderError = 'editor_used_post_space';
|
||||
}
|
||||
}
|
||||
$maxTotalSize = count( $maxTotalSize ) ? min( $maxTotalSize ) : NULL;
|
||||
|
||||
/* Create the uploader */
|
||||
if ( $maxTotalSize === NULL or $maxTotalSize > 0 )
|
||||
{
|
||||
$maxTotalSize = ( !is_null( $maxTotalSize ) ) ? round( $maxTotalSize, 2 ) : NULL;
|
||||
$maxTotalSize = ( !\is_null( $maxTotalSize ) ) ? $maxTotalSize : NULL;
|
||||
$postKey = $this->postKey;
|
||||
|
||||
|
||||
$allowStockPhotos = FALSE;
|
||||
|
||||
if ( ( \IPS\Settings::i()->pixabay_enabled ) and ( \IPS\Settings::i()->pixabay_editor_permissions == '*' OR \IPS\Member::loggedIn()->inGroup( explode( ',', \IPS\Settings::i()->pixabay_editor_permissions ) ) ) )
|
||||
{
|
||||
$allowStockPhotos = TRUE;
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'allowedFileTypes' => static::allowedFileExtensions(),
|
||||
'template' => 'core.attachments.fileItem',
|
||||
'multiple' => TRUE,
|
||||
'postKey' => $this->postKey,
|
||||
'storageExtension' => 'core_Attachment',
|
||||
'retainDeleted' => TRUE,
|
||||
'totalMaxSize' => $maxTotalSize,
|
||||
'maxFileSize' => \IPS\Member::loggedIn()->group['g_attach_per_post'] ? ( \IPS\Member::loggedIn()->group['g_attach_per_post'] * 1024 ) / 1048576 : NULL,
|
||||
'allowStockPhotos' => $allowStockPhotos,
|
||||
'callback' => function( $file ) use ( $postKey )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_files_temp', array( 'contents=?', (string) $file ) );
|
||||
@@ -586,16 +636,7 @@ class _Editor extends FormAbstract
|
||||
return $attachment['attach_id'];
|
||||
}
|
||||
);
|
||||
|
||||
if ( \IPS\Settings::i()->attach_allowed_types == 'all' and \IPS\Settings::i()->attach_allowed_extensions )
|
||||
{
|
||||
$options['allowedFileTypes'] = explode( ',', \IPS\Settings::i()->attach_allowed_extensions );
|
||||
}
|
||||
elseif ( \IPS\Settings::i()->attach_allowed_types == 'media' )
|
||||
{
|
||||
$options['allowedFileTypes'] = array_merge( \IPS\Image::$imageExtensions, \IPS\File::$videoExtensions );
|
||||
}
|
||||
|
||||
|
||||
if ( \IPS\Settings::i()->attachment_resample_size )
|
||||
{
|
||||
$maxImageSizes = explode( 'x', \IPS\Settings::i()->attachment_resample_size );
|
||||
@@ -639,7 +680,7 @@ class _Editor extends FormAbstract
|
||||
}
|
||||
|
||||
/* Delete the maps - Only do this for attachments that have actually been saved (if they haven't been saved, there's nothing in core_attachments_map for us to delete */
|
||||
if ( isset( $this->options['attachIds'] ) and is_array( $this->options['attachIds'] ) and count( $this->options['attachIds'] ) )
|
||||
if ( isset( $this->options['attachIds'] ) and \is_array( $this->options['attachIds'] ) and \count( $this->options['attachIds'] ) )
|
||||
{
|
||||
$where = array( array( 'location_key=?', "{$this->options['app']}_{$this->options['key']}" ), array( 'attachment_id=?', $attachment['attach_id'] ) );
|
||||
$i = 1;
|
||||
@@ -710,7 +751,7 @@ class _Editor extends FormAbstract
|
||||
{
|
||||
$existingAttachments = '';
|
||||
$where = array();
|
||||
if ( isset( $this->options['attachIds'] ) and is_array( $this->options['attachIds'] ) and count( $this->options['attachIds'] ) )
|
||||
if ( isset( $this->options['attachIds'] ) and \is_array( $this->options['attachIds'] ) and \count( $this->options['attachIds'] ) )
|
||||
{
|
||||
$where = array( array( 'location_key=?', "{$this->options['app']}_{$this->options['key']}" ) );
|
||||
$i = 1;
|
||||
@@ -777,4 +818,82 @@ class _Editor extends FormAbstract
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get allowed extension file types (NULL for any, empty array for none)
|
||||
*
|
||||
* @return array|NULL
|
||||
*/
|
||||
public static function allowedFileExtensions()
|
||||
{
|
||||
if ( \IPS\Settings::i()->attach_allowed_types == 'none' )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
elseif ( \IPS\Settings::i()->attach_allowed_types == 'all' and \IPS\Settings::i()->attach_allowed_extensions )
|
||||
{
|
||||
return explode( ',', \IPS\Settings::i()->attach_allowed_extensions );
|
||||
}
|
||||
elseif ( \IPS\Settings::i()->attach_allowed_types == 'media' )
|
||||
{
|
||||
return array_merge( \IPS\Image::$imageExtensions, \IPS\File::$videoExtensions );
|
||||
}
|
||||
elseif ( \IPS\Settings::i()->attach_allowed_types == 'images' )
|
||||
{
|
||||
return \IPS\Image::$imageExtensions;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Cache used within maxTotalAttachmentSize()
|
||||
*/
|
||||
protected static $membersAttachmentUsage = [];
|
||||
|
||||
/**
|
||||
* Get the maximum combined size of attachments that can be used or NULL for no limit
|
||||
*
|
||||
* @param \IPS\Member $member The member
|
||||
* @param int $currentPostUsage Size, in bytes, of current attachments in the post
|
||||
* @param string $error If a value is passed by reference, will be set to an error string if the value is 0
|
||||
* @return int|NULL
|
||||
*/
|
||||
public static function maxTotalAttachmentSize( \IPS\Member $member, $currentPostUsage, &$error = NULL )
|
||||
{
|
||||
$maxTotalSize = array();
|
||||
|
||||
/* Get the global limit */
|
||||
if ( $member->member_id and $member->group['g_attach_max'] > 0 )
|
||||
{
|
||||
if( !isset( $membersAttachmentUsage[ $member->member_id ] ) )
|
||||
{
|
||||
$membersAttachmentUsage[ $member->member_id ] = \IPS\Db::i()->select( 'SUM(attach_filesize)', 'core_attachments', array( 'attach_member_id=?', \IPS\Member::loggedIn()->member_id ) )->first();
|
||||
}
|
||||
$globalSpaceRemaining = ( ( $member->group['g_attach_max'] * 1024 ) - $membersAttachmentUsage[ $member->member_id ] );
|
||||
|
||||
$maxTotalSize[] = $globalSpaceRemaining;
|
||||
if ( $globalSpaceRemaining <= 0 )
|
||||
{
|
||||
$error = 'editor_used_global_space';
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the per post limit */
|
||||
if ( $member->group['g_attach_per_post'] )
|
||||
{
|
||||
$perPostSpaceRemaining = ( ( $member->group['g_attach_per_post'] * 1024 ) - $currentPostUsage );
|
||||
|
||||
$maxTotalSize[] = $perPostSpaceRemaining;
|
||||
if ( $perPostSpaceRemaining <= 0 )
|
||||
{
|
||||
$error = 'editor_used_post_space';
|
||||
}
|
||||
}
|
||||
|
||||
/* Return whichever is lower */
|
||||
return $maxTotalSize ? min( $maxTotalSize ) : NULL;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user