Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief 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 18 Feb 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -109,6 +109,16 @@ class _Form
|
||||
*/
|
||||
public $copyButton = NULL;
|
||||
|
||||
/**
|
||||
* @brief Language keys to preload for efficiency
|
||||
*/
|
||||
protected $languageKeys = array();
|
||||
|
||||
/**
|
||||
* @brief This form can be reloaded after saving
|
||||
*/
|
||||
public $canSaveAndReload = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -127,7 +137,7 @@ class _Form
|
||||
|
||||
if( $submitLang )
|
||||
{
|
||||
$this->actionButtons[] = \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->button( $submitLang, 'submit', null, 'ipsButton ipsButton_primary', array( 'accesskey' => 's' ) );
|
||||
$this->actionButtons[] = \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->button( $submitLang, 'submit', null, 'ipsButton ipsButton_primary', array( 'tabindex' => '2', 'accesskey' => 's' ) );
|
||||
}
|
||||
|
||||
$this->hiddenValues['csrfKey'] = \IPS\Session::i()->csrfKey;
|
||||
@@ -147,6 +157,12 @@ class _Form
|
||||
$potentialMaxUploadValues[] = \IPS\File::returnBytes( ini_get('memory_limit') );
|
||||
}
|
||||
$this->uploadField = min( $potentialMaxUploadValues );
|
||||
|
||||
/* This can be overridden in userland code, but by default takes the value sent by \IPS\Node\Controller::_afterSave() */
|
||||
if ( isset( \IPS\Request::i()->activeTab ) )
|
||||
{
|
||||
$this->activeTab = \IPS\Request::i()->activeTab;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,8 +272,7 @@ class _Form
|
||||
*/
|
||||
public function addMatrix( $name, $matrix )
|
||||
{
|
||||
//$matrix->manageable = FALSE;
|
||||
$matrix->id = $this->id;
|
||||
$matrix->formId = $this->id;
|
||||
$this->tabClasses[ $this->currentTab ] = 'ipsMatrix';
|
||||
$this->elements[ $this->currentTab ][ $name ] = $matrix;
|
||||
}
|
||||
@@ -327,6 +342,40 @@ class _Form
|
||||
{
|
||||
$this->hiddenValues[ $input->name ] = TRUE;
|
||||
}
|
||||
|
||||
$preloadTypes = array( 'CheckboxSet', 'Radio' );
|
||||
|
||||
/* Some form fields check for _desc and _warning so preload these */
|
||||
foreach( $preloadTypes as $type )
|
||||
{
|
||||
$class = 'IPS\Helpers\Form\\' . $type;
|
||||
|
||||
if ( is_a( $input, $class ) )
|
||||
{
|
||||
$this->languageKeys[] = $input->name . '_desc';
|
||||
$this->languageKeys[] = $input->name . '_warning';
|
||||
|
||||
if ( isset( $input->options['options'] ) and count( $input->options['options'] ) )
|
||||
{
|
||||
$this->languageKeys = array_merge( $this->languageKeys, array_map(
|
||||
function ($v )
|
||||
{
|
||||
return $v . '_desc';
|
||||
},
|
||||
array_values( $input->options['options'] )
|
||||
)
|
||||
);
|
||||
$this->languageKeys = array_merge( $this->languageKeys, array_map(
|
||||
function ($v )
|
||||
{
|
||||
return $v . '_warning';
|
||||
},
|
||||
array_values( $input->options['options'] )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,6 +385,16 @@ class _Form
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
/* Preload languages */
|
||||
if ( count( $this->languageKeys ) and !( \IPS\Member::loggedIn()->language() instanceof \IPS\Lang\Setup\Lang ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->get( $this->languageKeys );
|
||||
}
|
||||
catch( \UnderflowException $e ) { }
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$html = array();
|
||||
@@ -357,13 +416,22 @@ class _Form
|
||||
$html[ $tab ] .= ( $element instanceof \IPS\Helpers\Form\FormAbstract ) ? $element->rowHtml( $this ) : (string) $element;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $this->canSaveAndReload )
|
||||
{
|
||||
$this->addButton( 'save_and_reload', 'submit', null, 'ipsButton ipsButton_primary', array( 'name' => 'save_and_reload', 'value' => 1 ) );
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core' )->template( $this->id, $this->action, $html, $this->activeTab, $this->error, $errorTabs, $this->hiddenValues, $this->actionButtons, $this->uploadField, $this->sidebar, $this->tabClasses, $this->class, $this->attributes, $this->tabs, $this->iconTabs );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\IPS::exceptionHandler( $e );
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
\IPS\IPS::exceptionHandler( $e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,6 +453,16 @@ class _Form
|
||||
$args = array();
|
||||
}
|
||||
|
||||
/* Preload languages */
|
||||
if ( count( $this->languageKeys ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->get( $this->languageKeys );
|
||||
}
|
||||
catch( \UnderflowException $e ) { }
|
||||
}
|
||||
|
||||
$errorTabs = array();
|
||||
foreach ( $this->elements as $tab => $elements )
|
||||
{
|
||||
@@ -407,6 +485,22 @@ class _Form
|
||||
return call_user_func_array( $template, array_merge( $args, array( $this->id, $this->action, $this->elements, $this->hiddenValues, $this->actionButtons, $this->uploadField, $this->class, $this->attributes, $this->sidebar, $this, $errorTabs ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last used tab in the current form
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getLastUsedTab()
|
||||
{
|
||||
$name = "{$this->id}_activeTab";
|
||||
if ( isset( \IPS\Request::i()->$name ) )
|
||||
{
|
||||
return \IPS\Request::i()->$name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get submitted values
|
||||
*
|
||||
@@ -422,6 +516,66 @@ class _Form
|
||||
/* Did we submit the form? */
|
||||
if( isset( \IPS\Request::i()->$name ) and \IPS\Request::i()->csrfKey === \IPS\Session::i()->csrfKey )
|
||||
{
|
||||
/* Work out which fields are being toggled by other fields */
|
||||
$htmlIdsToIgnoreBecauseTheyAreHiddenByToggles = array();
|
||||
$htmlIdsWeWantBecauseTheyAreActivatedByToggles = array();
|
||||
foreach ( $this->elements as $elements )
|
||||
{
|
||||
foreach ( $elements as $_name => $element )
|
||||
{
|
||||
if ( isset( $element->options['togglesOn'] ) )
|
||||
{
|
||||
if ( !$element->value )
|
||||
{
|
||||
$htmlIdsToIgnoreBecauseTheyAreHiddenByToggles = array_merge( $htmlIdsToIgnoreBecauseTheyAreHiddenByToggles, $element->options['togglesOn'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$htmlIdsWeWantBecauseTheyAreActivatedByToggles = array_merge( $htmlIdsWeWantBecauseTheyAreActivatedByToggles, $element->options['togglesOn'] );
|
||||
}
|
||||
}
|
||||
if ( isset( $element->options['togglesOff'] ) )
|
||||
{
|
||||
if ( $element->value )
|
||||
{
|
||||
$htmlIdsToIgnoreBecauseTheyAreHiddenByToggles = array_merge( $htmlIdsToIgnoreBecauseTheyAreHiddenByToggles, $element->options['togglesOff'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$htmlIdsWeWantBecauseTheyAreActivatedByToggles = array_merge( $htmlIdsWeWantBecauseTheyAreActivatedByToggles, $element->options['togglesOff'] );
|
||||
}
|
||||
}
|
||||
if ( isset( $element->options['zeroValTogglesOff'] ) )
|
||||
{
|
||||
if ( $element->value === 0 )
|
||||
{
|
||||
$htmlIdsToIgnoreBecauseTheyAreHiddenByToggles = array_merge( $htmlIdsToIgnoreBecauseTheyAreHiddenByToggles, $element->options['zeroValTogglesOff'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$htmlIdsWeWantBecauseTheyAreActivatedByToggles = array_merge( $htmlIdsWeWantBecauseTheyAreActivatedByToggles, $element->options['zeroValTogglesOff'] );
|
||||
}
|
||||
}
|
||||
if ( isset( $element->options['toggles'] ) )
|
||||
{
|
||||
foreach ( $element->options['toggles'] as $toggleValue => $toggleHtmlIds )
|
||||
{
|
||||
$match = is_array( $element->value ) ? in_array( $toggleValue, $element->value ) : $toggleValue == $element->value;
|
||||
if ( !$match )
|
||||
{
|
||||
$htmlIdsToIgnoreBecauseTheyAreHiddenByToggles = array_merge( $htmlIdsToIgnoreBecauseTheyAreHiddenByToggles, $toggleHtmlIds );
|
||||
}
|
||||
else
|
||||
{
|
||||
$htmlIdsWeWantBecauseTheyAreActivatedByToggles = array_merge( $htmlIdsWeWantBecauseTheyAreActivatedByToggles, $toggleHtmlIds );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$htmlIdsToIgnore = array_diff( array_unique( $htmlIdsToIgnoreBecauseTheyAreHiddenByToggles ), array_unique( $htmlIdsWeWantBecauseTheyAreActivatedByToggles ) );
|
||||
|
||||
/* Loop elements */
|
||||
foreach ( $this->elements as $elements )
|
||||
{
|
||||
@@ -440,6 +594,14 @@ class _Form
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If this is dependant on a toggle which isn't set, don't return a value so that it doesn't
|
||||
trigger an error we cannot see */
|
||||
if ( $element->htmlId and in_array( $element->htmlId, $htmlIdsToIgnore ) )
|
||||
{
|
||||
$values[ $_name ] = $element->defaultValue;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Make sure we have a value (someone might try to be sneaky and remove the HTML from the form before submitting) */
|
||||
if ( !$element->valueSet )
|
||||
{
|
||||
@@ -519,11 +681,12 @@ class _Form
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save values to settings table
|
||||
*
|
||||
* @return bool
|
||||
* @param array|NULL $values Form Values
|
||||
* @return bool
|
||||
*/
|
||||
public function saveAsSettings( $values=NULL )
|
||||
{
|
||||
@@ -559,7 +722,7 @@ class _Form
|
||||
{
|
||||
if ( time() - \IPS\Member::loggedIn()->member_last_post < \IPS\Settings::i()->flood_control )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('error_flood_control', FALSE, array( 'sprintf' => array( time() - \IPS\Member::loggedIn()->member_last_post ) ) ) );
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('error_flood_control', FALSE, array( 'sprintf' => array( \IPS\Settings::i()->flood_control - ( time() - \IPS\Member::loggedIn()->member_last_post ) ) ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user