Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+54 -5
View File
@@ -2,9 +2,9 @@
/**
* @brief URL input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 11 Mar 2013
* @version SVN_VERSION_NUMBER
*/
@@ -28,9 +28,11 @@ class _Url extends Text
* @code
$childDefaultOptions = array(
'allowedProtocols' => array( 'http', 'https' ), // Allowed protocols. Default is http and https. Be careful changing this not to introduce security issues.
'allowedMimes' => 'image/*', // Sets the allowed mimetype(s). Can be string or array. * is a wildcard. Default is NULL, which allows any mimetypes.
'file' => 'Profile', // If provided, the contents of the URL will be fetched and written as a file, an \IPS\File object will then be returned rather than a string. Provide the extension name which specifies the storage location to use.
'allowedMimes' => 'image/*', // Sets the allowed mimetype(s). Can be string or array. * is a wildcard. Default is NULL, which allows any mimetypes. Note, setting this will not allow localhost URLs.
'file' => 'Profile', // If provided, the contents of the URL will be fetched and written as a file, an \IPS\File object will then be returned rather than a string. Provide the extension name which specifies the storage location to use. Note, setting this will not allow localhost URLs.
'maxFileSize' => NULL, // If provided along with 'file', the resulting file that is written to disk cannot be greater than this size in megabytes. NULL for no limit (default is NULL).
'maxDimensions' => NULL, // If supplied as an array with keys 'width' and 'height' and the resulting file is an image, the image will be scaled down to these maximum dimensions. NULL for no limits (default is NULL).
'rateLimit' => 20, // Rate-limit requests to prevent the ability to DOS a remote server - time between allowed attempts in seconds (defaults to 20). NULL to disable rate limiting.
);
* @endcode
*/
@@ -39,6 +41,8 @@ class _Url extends Text
'allowedMimes' => NULL,
'file' => FALSE,
'maxFileSize' => NULL,
'maxDimensions' => NULL,
'rateLimit' => 20
);
/**
@@ -71,6 +75,32 @@ class _Url extends Text
/* Try to fetch it, if necessary */
if ( $this->options['file'] or $this->options['allowedMimes'] )
{
/* Localhost is not allowed as sending a HTTP request to the local server will cause scripts which are relying
on only being accessible to the local machine to execute */
if ( $value->isLocalhost() )
{
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_url_localhost', FALSE, array( 'sprintf' => array( \IPS\Http\Url::internal('')->data['host'] ) ) ) );
}
/* Is rate limiting enabled (the default)? */
if( $this->options['rateLimit'] !== NULL AND intval( $this->options['rateLimit'] ) > 0 )
{
/* We need to rate limit URL fetch requests - have we tried to fetch this field yet? */
$_key = 'url_fetch_' . $this->htmlId;
if( isset( $_SESSION[ $_key ] ) AND $_SESSION[ $_key ] )
{
/* Was it less than 20 seconds ago? If so, make the user wait */
$timeLeft = $_SESSION[ $_key ] - ( time() - intval( $this->options['rateLimit'] ) );
if( $timeLeft > 0 )
{
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_url_too_soon', FALSE, array( 'sprintf' => array( $this->options['rateLimit'], $timeLeft ) ) ) );
}
}
$_SESSION[ $_key ] = time();
}
try
{
$response = $value->request()->get();
@@ -118,6 +148,25 @@ class _Url extends Text
try
{
$this->value = \IPS\File::create( $this->options['file'], $filename, $response );
/* Do we need to resize images down? */
if( $this->value->isImage() AND $this->options['maxDimensions'] !== NULL )
{
try
{
$image = \IPS\Image::create( $this->value->contents() );
if( $image::exifSupported() )
{
$image->setExifData( $this->value->contents() );
}
$image->resizeToMax( $this->options['maxDimensions']['width'] ?: NULL, $this->options['maxDimensions']['height'] ?: NULL );
$this->value->replace( (string) $image );
}
catch ( \Exception $e ) { }
}
}
catch( \InvalidArgumentException $e )
{
@@ -160,7 +209,7 @@ class _Url extends Text
{
try
{
return new \IPS\Http\Url( $this->value );
return \IPS\Http\Url::createFromString( $this->value, TRUE, TRUE );
}
catch ( \InvalidArgumentException $e )
{