Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -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;
|
||||
@@ -33,12 +33,11 @@ class _Stack extends FormAbstract
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor: Store the form element to stack
|
||||
* Constructor
|
||||
*
|
||||
* @see \IPS\Helpers\Form\FormAbstract::__construct
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool $required Required?
|
||||
* @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
|
||||
@@ -47,8 +46,8 @@ class _Stack extends FormAbstract
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
|
||||
{
|
||||
call_user_func_array( 'parent::__construct', func_get_args() );
|
||||
{
|
||||
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'jquery/jquery-ui.js', 'core', 'interface' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'jquery/jquery-touchpunch.js', 'core', 'interface' ) );
|
||||
@@ -57,7 +56,7 @@ class _Stack extends FormAbstract
|
||||
/* Test for javascript disabled add stack */
|
||||
if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
|
||||
{
|
||||
if ( ( \IPS\Request::i()->valueFromArray('form_remove_stack') !== NULL OR isset( \IPS\Request::i()->form_add_stack ) ) and \IPS\Request::i()->csrfKey === \IPS\Session::i()->csrfKey )
|
||||
if ( ( \IPS\Request::i()->valueFromArray('form_remove_stack') !== NULL OR isset( \IPS\Request::i()->form_add_stack ) ) and \IPS\Login::compareHashes( (string) \IPS\Session::i()->csrfKey, (string) \IPS\Request::i()->csrfKey ) )
|
||||
{
|
||||
$this->reloadForm = true;
|
||||
}
|
||||
@@ -76,13 +75,13 @@ class _Stack extends FormAbstract
|
||||
$remove = \IPS\Request::i()->valueFromArray('form_remove_stack');
|
||||
|
||||
/* The JS fallback needs a unique key for the field to remove */
|
||||
$remove = ( is_array( $remove ) ) ? key( $remove ) : null;
|
||||
$remove = ( \is_array( $remove ) ) ? key( $remove ) : null;
|
||||
|
||||
if( count($this->value) )
|
||||
if( \count($this->value) )
|
||||
{
|
||||
foreach( $this->value as $k => $v )
|
||||
{
|
||||
$class = ( new $classType( $this->name . '[' . count($fields) . ']', $v, FALSE, $this->options, $this->customValidationCode, $this->prefix, $this->suffix, $this->htmlId . '_' . count($fields) ) );
|
||||
$class = ( new $classType( $this->name . '[' . \count($fields) . ']', $v, FALSE, $this->options, $this->customValidationCode, $this->prefix, $this->suffix, $this->htmlId . '_' . \count($fields) ) );
|
||||
$class->setValue( TRUE );
|
||||
$html = $class->html();
|
||||
|
||||
@@ -94,7 +93,7 @@ class _Stack extends FormAbstract
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = ( new $classType( $this->name . '[0]', NULL, FALSE, $this->options, $this->customValidationCode, $this->prefix, $this->suffix, $this->htmlId . '_' . count($fields) ) );
|
||||
$class = ( new $classType( $this->name . '[0]', NULL, FALSE, $this->options, $this->customValidationCode, $this->prefix, $this->suffix, $this->htmlId . '_' . \count($fields) ) );
|
||||
$class->setValue( TRUE );
|
||||
$html = $class->html();
|
||||
|
||||
@@ -107,7 +106,7 @@ class _Stack extends FormAbstract
|
||||
/* We hit the add stack button with JS disabled */
|
||||
if ( $this->reloadForm === TRUE AND $remove === NULL )
|
||||
{
|
||||
$class = ( new $classType( $this->name . '[]', NULL, FALSE, $this->options, $this->customValidationCode, $this->prefix, $this->suffix, $this->htmlId . '_' . count($fields) ) );
|
||||
$class = ( new $classType( $this->name . '[]', NULL, FALSE, $this->options, $this->customValidationCode, $this->prefix, $this->suffix, $this->htmlId . '_' . \count($fields) ) );
|
||||
$class->setValue( TRUE );
|
||||
$html = $class->html();
|
||||
$fields[] = $html;
|
||||
@@ -150,7 +149,7 @@ class _Stack extends FormAbstract
|
||||
|
||||
if( mb_substr( $name, 0, 8 ) !== '_new_[x]' and isset( \IPS\Request::i()->$name ) )
|
||||
{
|
||||
if( is_array( \IPS\Request::i()->$name ) AND count( \IPS\Request::i()->$name ) )
|
||||
if( \is_array( \IPS\Request::i()->$name ) AND \count( \IPS\Request::i()->$name ) )
|
||||
{
|
||||
foreach( \IPS\Request::i()->$name as $k => $v )
|
||||
{
|
||||
@@ -162,7 +161,7 @@ class _Stack extends FormAbstract
|
||||
|
||||
return ( $this->options['removeEmptyValues'] ) ? array_filter( $values ) : $values;
|
||||
}
|
||||
else if ( is_array( $this->value ) AND count( $this->value ) )
|
||||
else if ( \is_array( $this->value ) AND \count( $this->value ) )
|
||||
{
|
||||
foreach( $this->value as $k => $v )
|
||||
{
|
||||
@@ -192,12 +191,12 @@ class _Stack extends FormAbstract
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
}
|
||||
|
||||
if ( $this->options['maxItems'] !== NULL and count( $this->value ) > $this->options['maxItems'] )
|
||||
if ( $this->options['maxItems'] !== NULL and \count( $this->value ) > $this->options['maxItems'] )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_items_max', FALSE, array( 'pluralize' => array( $this->options['maxItems'] ) ) ) );
|
||||
}
|
||||
|
||||
if ( $this->options['minItems'] !== NULL and count( $this->value ) < $this->options['minItems'] )
|
||||
if ( $this->options['minItems'] !== NULL and \count( $this->value ) < $this->options['minItems'] )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_items_min', FALSE, array( 'pluralize' => array( $this->options['minItems'] ) ) ) );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user