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

+47 -15
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;
@@ -82,6 +82,11 @@ class _Matrix extends \IPS\Helpers\Form
* @brief Manageable? (Rows can be added and deleted)
*/
public $manageable = TRUE;
/**
* @brief Sortable?
*/
public $sortable = FALSE;
/**
* @brief Squash fields? (values in the matrix are json_encode'd as a single value to get around max_post_vars limits)
@@ -135,7 +140,7 @@ class _Matrix extends \IPS\Helpers\Form
{
try
{
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->matrix( $this->id, array_keys( $this->columns ), $this->elements(), $this->action, $this->hiddenValues, $this->actionButtons, $this->langPrefix, $this->calculateWidths(), $this->manageable, $this->checkAlls, $this->checkAllRows, $this->classes, $this->showTooltips, $this->squashFields );
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->matrix( $this->id, array_keys( $this->columns ), $this->elements(), $this->action, $this->hiddenValues, $this->actionButtons, $this->langPrefix, $this->calculateWidths(), $this->manageable, $this->checkAlls, $this->checkAllRows, $this->classes, $this->showTooltips, $this->squashFields, $this->sortable );
}
catch ( \Exception $e )
{
@@ -154,7 +159,7 @@ class _Matrix extends \IPS\Helpers\Form
*/
public function nested()
{
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->matrixNested( $this->id, array_keys( $this->columns ), $this->elements(), $this->action, $this->hiddenValues, $this->actionButtons, $this->langPrefix, $this->calculateWidths(), $this->manageable, $this->checkAlls, $this->checkAllRows, $this->classes, $this->showTooltips, $this->squashFields );
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->matrixNested( $this->id, array_keys( $this->columns ), $this->elements(), $this->action, $this->hiddenValues, $this->actionButtons, $this->langPrefix, $this->calculateWidths(), $this->manageable, $this->checkAlls, $this->checkAllRows, $this->classes, $this->showTooltips, $this->squashFields, $this->sortable );
}
/**
@@ -165,12 +170,12 @@ class _Matrix extends \IPS\Helpers\Form
protected function calculateWidths()
{
$widths = $this->widths;
$width = ( ( 100 - array_sum( $this->widths ) ) / count( $this->columns ) );
$width = ( ( 100 - array_sum( $this->widths ) ) / \count( $this->columns ) );
foreach ( array_keys( $this->columns ) as $c )
{
if ( !isset( $widths[ $c ] ) )
{
$widths[ $c ] = $width;
$widths[ $c ] = number_format( $width, 2, '.', '' );
}
}
@@ -180,7 +185,7 @@ class _Matrix extends \IPS\Helpers\Form
/**
* Get elements
*
* @param $bool Get values?
* @param bool $getValues Get values?
* @return array
*/
public function elements( $getValues=TRUE )
@@ -246,7 +251,7 @@ class _Matrix extends \IPS\Helpers\Form
{
if( $pos = mb_strpos( $inputKey, '_new_' ) AND $inputKey !== '_new_' )
{
if( is_array( $inputValue ) AND isset( $inputValue[ $newId ] ) )
if( \is_array( $inputValue ) AND isset( $inputValue[ $newId ] ) )
{
/* @note This previously used an array_merge() however this was causing elements to be overwritten with a blank value in some cases */
foreach( $inputValue[ $newId ] AS $key => $value )
@@ -260,8 +265,8 @@ class _Matrix extends \IPS\Helpers\Form
}
}
$this->elements["_new_[{$i}]"] = $this->buildRow( "_new_[{$i}]", $data );
$this->addedRows[] = "_new_[{$i}]";
$this->elements["_new_[{$newId}]"] = $this->buildRow( "_new_[{$newId}]", $data );
$this->addedRows[] = "_new_[{$newId}]";
$i++;
}
}
@@ -272,6 +277,24 @@ class _Matrix extends \IPS\Helpers\Form
{
$this->elements["_new_[x]"] = $blankRow;
}
/* Do we need to order it? */
if ( $this->sortable )
{
$matrixOrderName = "{$this->id}_matrixOrder";
if ( isset( \IPS\Request::i()->$matrixOrderName ) )
{
$matrixOrderValues = \IPS\Request::i()->$matrixOrderName;
uksort( $this->elements, function( $a, $b ) use ( $matrixOrderValues ) {
if ( \in_array( $a, $matrixOrderValues ) and \in_array( $b, $matrixOrderValues ) )
{
return array_search( $a, $matrixOrderValues ) - array_search( $b, $matrixOrderValues );
}
return 0;
} );
}
}
}
return $this->elements;
@@ -287,7 +310,7 @@ class _Matrix extends \IPS\Helpers\Form
protected function buildRow( $rowId, $data )
{
$row = array();
if ( is_string( $data ) )
if ( \is_string( $data ) )
{
return $data;
}
@@ -296,7 +319,7 @@ class _Matrix extends \IPS\Helpers\Form
$inputName = "{$rowId}[{$columnName}]";
/* Create using array */
if ( is_array( $columnData ) )
if ( \is_array( $columnData ) )
{
$classname = '\IPS\Helpers\Form\\' . $columnData[0];
$row[ $columnName ] = new $classname(
@@ -309,7 +332,7 @@ class _Matrix extends \IPS\Helpers\Form
/* Create using callback function */
else
{
$row[ $columnName ] = call_user_func( $columnData, $inputName, isset( $data[ $columnName ] ) ? $data[ $columnName ] : NULL, $data );
$row[ $columnName ] = $columnData( $inputName, isset( $data[ $columnName ] ) ? $data[ $columnName ] : NULL, $data );
}
}
if ( isset( $data['_level'] ) )
@@ -331,7 +354,7 @@ class _Matrix extends \IPS\Helpers\Form
$values = array();
$name = "{$this->id}_submitted";
if( $force or ( isset( \IPS\Request::i()->$name ) and \IPS\Request::i()->csrfKey === \IPS\Session::i()->csrfKey ) )
if( $force or ( isset( \IPS\Request::i()->$name ) and \IPS\Login::compareHashes( (string) \IPS\Session::i()->csrfKey, (string) \IPS\Request::i()->csrfKey ) ) )
{
// Do we need to unsquash any values?
// Squashed values are json_encoded by javascript to prevent us exceeding max_post_vars
@@ -353,12 +376,12 @@ class _Matrix extends \IPS\Helpers\Form
foreach ( $this->elements( FALSE ) as $rowId => $columns )
{
if ( is_array( $columns ) )
if ( \is_array( $columns ) )
{
foreach ( $columns as $columnName => $element )
{
/* If this was a ehader or something, skip it */
if ( !is_object( $element ) )
if ( !\is_object( $element ) )
{
continue;
}
@@ -384,6 +407,15 @@ class _Matrix extends \IPS\Helpers\Form
$element->value = $value;
}
}
if ( isset( $element->options['nullLang'] ) )
{
$nullKey = "{$rowId}[{$columnName}_null]";
if ( $value = \IPS\Request::i()->valueFromArray( $nullKey ) )
{
$element->value = NULL;
}
}
/* Set value */
$values[ $rowId ][ $columnName ] = $element->value;