Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+17 -16
View File
@@ -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;
@@ -58,16 +58,18 @@ class _Number extends FormAbstract
/**
* Constructor
* Formats the value appropriately
*
* @see \IPS\Helpers\Form\FormAbstract::__construct
* @param string $name Name
* @param mixed $defaultValue Default value
* @param bool $required Required?
* @param array $options Type-specific options
* @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
*/
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array() )
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
{
/* Specify there's a value if the unlimited element contains a value */
$unlimitedName = "{$name}_unlimited";
@@ -77,21 +79,20 @@ class _Number extends FormAbstract
}
/* Work out the step */
$args = func_get_args();
if ( !isset( $options['step'] ) and isset( $options['decimals'] ) )
{
if ( $options['decimals'] === TRUE )
{
$args[3]['step'] = 'any';
$options['step'] = 'any';
}
else
{
$args[3]['step'] = 1 / ( pow( 10, $options['decimals'] ) );
$options['step'] = 1 / ( pow( 10, $options['decimals'] ) );
}
}
/* Call parent constructor */
call_user_func_array( 'parent::__construct', $args );
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
}
/**
@@ -185,7 +186,7 @@ class _Number extends FormAbstract
$value = str_replace( trim( \IPS\Member::loggedIn()->language()->locale['decimal_point'] ), '.', $value );
/* If it's not numeric, throw an exception */
if ( ( !is_numeric( $value ) and $value !== '' and $this->required === FALSE ) or ( !is_numeric( $value ) and $this->required === TRUE ) )
if ( ( !\is_numeric( $value ) and $value !== '' and $this->required === FALSE ) or ( !\is_numeric( $value ) and $this->required === TRUE ) )
{
throw new \InvalidArgumentException( 'form_number_bad' );
}
@@ -193,15 +194,15 @@ class _Number extends FormAbstract
/* Convert to int/float */
if ( $this->options['decimals'] )
{
$value = floatval( $value );
if ( is_int( $this->options['decimals'] ) )
$value = \floatval( $value );
if ( \is_int( $this->options['decimals'] ) )
{
$value = round( $value, $this->options['decimals'] );
}
}
else
{
$value = intval( $value );
$value = \intval( $value );
}
/* Return */