Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+34 -24
View File
@@ -11,16 +11,26 @@
namespace IPS\Helpers\Form;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadFunctionCallException;
use InvalidArgumentException;
use IPS\GeoLocation;
use IPS\Settings;
use IPS\Theme;
use function defined;
use function in_array;
use function is_array;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Address input class for Form Builder
*/
class _Address extends FormAbstract
class Address extends FormAbstract
{
/**
* @brief Default Options
@@ -31,7 +41,7 @@ class _Address extends FormAbstract
);
* @endcode
*/
protected $defaultOptions = array(
protected array $defaultOptions = array(
'minimize' => FALSE,
'requireFullAddress' => TRUE,
'preselectCountry' => TRUE,
@@ -42,12 +52,12 @@ class _Address extends FormAbstract
*
* @return string
*/
public function html()
public function html(): string
{
/* If we don't have a value, set their country based on the HTTP headers */
if ( !$this->value OR ( $this->value instanceof \IPS\GeoLocation AND !$this->value->country ) )
if ( !$this->value OR ( $this->value instanceof GeoLocation AND !$this->value->country ) )
{
$this->value = ( $this->value instanceof \IPS\GeoLocation ) ? $this->value : new \IPS\GeoLocation;
$this->value = ( $this->value instanceof GeoLocation ) ? $this->value : new GeoLocation;
if ( $this->options['preselectCountry'] and $defaultCountry = static::calculateDefaultCountry() )
{
$this->value->country = $defaultCountry;
@@ -55,7 +65,7 @@ class _Address extends FormAbstract
}
/* Display */
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->address( $this->name, $this->value, \IPS\Settings::i()->googleplacesautocomplete ? \IPS\Settings::i()->google_maps_api_key : NULL, $this->options['minimize'], $this->options['requireFullAddress'] );
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->address( $this->name, $this->value, Settings::i()->googleplacesautocomplete ? Settings::i()->google_maps_api_key : NULL, $this->options['minimize'], $this->options['requireFullAddress'] );
}
/**
@@ -63,7 +73,7 @@ class _Address extends FormAbstract
*
* @return string|NULL
*/
public static function calculateDefaultCountry()
public static function calculateDefaultCountry(): ?string
{
if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
{
@@ -86,7 +96,7 @@ class _Address extends FormAbstract
$dashPos = mb_strpos( $language, '-' );
$country = mb_strtoupper( $dashPos ? mb_substr( $language, $dashPos + 1 ) : $language );
if ( \in_array( $country, \IPS\GeoLocation::$countries ) )
if ( in_array( $country, GeoLocation::$countries ) )
{
return $country;
}
@@ -101,12 +111,12 @@ class _Address extends FormAbstract
*
* @return mixed
*/
public function getValue()
public function getValue(): mixed
{
/* Create the object */
$input = parent::getValue();
$value = new \IPS\GeoLocation;
$value->addressLines = ( isset( $input['address'] ) and \is_array( $input['address'] ) ) ? array_filter( $input['address'] ) : array();
$value = new GeoLocation;
$value->addressLines = ( isset( $input['address'] ) and is_array( $input['address'] ) ) ? array_filter( $input['address'] ) : array();
if ( empty( $value->addressLines ) )
{
$value->addressLines = array( NULL );
@@ -167,7 +177,7 @@ class _Address extends FormAbstract
$partiallyCompleted = TRUE;
}
if ( array_key_exists( $value->country, \IPS\GeoLocation::$states ) )
if ( array_key_exists( $value->country, GeoLocation::$states ) )
{
if ( !$value->region )
{
@@ -181,8 +191,8 @@ class _Address extends FormAbstract
}
if ( trim( $value->region ) )
{
$states = ( isset( \IPS\GeoLocation::$states[ $value->country ] ) ) ? \IPS\GeoLocation::$states[ $value->country ] : array();
if ( !array_key_exists( $value->country, \IPS\GeoLocation::$states ) or $value->region != array_shift( $states ) )
$states = ( isset( GeoLocation::$states[ $value->country ] ) ) ? GeoLocation::$states[ $value->country ] : array();
if ( !array_key_exists( $value->country, GeoLocation::$states ) or $value->region != array_shift( $states ) )
{
$partiallyCompleted = TRUE;
}
@@ -195,11 +205,11 @@ class _Address extends FormAbstract
{
if ( $this->required )
{
throw new \InvalidArgumentException('form_partial_address_req');
throw new InvalidArgumentException('form_partial_address_req');
}
else
{
throw new \InvalidArgumentException('form_partial_address_opt');
throw new InvalidArgumentException('form_partial_address_opt');
}
}
else
@@ -222,7 +232,7 @@ class _Address extends FormAbstract
{
$value->getLatLong();
}
catch( \BadFunctionCallException $e ){}
catch( BadFunctionCallException $e ){}
/* Return */
return $value;
@@ -231,14 +241,14 @@ class _Address extends FormAbstract
/**
* Validate
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
* @return TRUE
*/
public function validate()
public function validate(): bool
{
if( $this->value === NULL and $this->required )
{
throw new \InvalidArgumentException('form_required');
throw new InvalidArgumentException('form_required');
}
return parent::validate();
@@ -248,9 +258,9 @@ class _Address extends FormAbstract
* String Value
*
* @param mixed $value The value
* @return string
* @return string|int|null
*/
public static function stringValue( $value )
public static function stringValue( mixed $value ): string|int|null
{
return json_encode( $value );
}