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

+18 -11
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;
@@ -34,6 +34,7 @@ class _Address extends FormAbstract
protected $defaultOptions = array(
'minimize' => FALSE,
'requireFullAddress' => TRUE,
'preselectCountry' => TRUE,
);
/**
@@ -47,7 +48,7 @@ class _Address extends FormAbstract
if ( !$this->value OR ( $this->value instanceof \IPS\GeoLocation AND !$this->value->country ) )
{
$this->value = ( $this->value instanceof \IPS\GeoLocation ) ? $this->value : new \IPS\GeoLocation;
if ( $this->options['requireFullAddress'] and $defaultCountry = static::calculateDefaultCountry() )
if ( $this->options['preselectCountry'] and $defaultCountry = static::calculateDefaultCountry() )
{
$this->value->country = $defaultCountry;
}
@@ -63,24 +64,30 @@ class _Address extends FormAbstract
* @return string|NULL
*/
public static function calculateDefaultCountry()
{
{
if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
{
if( mb_strpos( $_SERVER['HTTP_ACCEPT_LANGUAGE'], ',' ) )
{
$exploded = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
$exploded = $exploded[0];
$languages = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
}
else
{
$exploded = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$languages = array( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
}
$exploded = explode( '-', $exploded );
if ( isset( $exploded[1] ) )
foreach( $languages as $language )
{
$country = mb_strtoupper( $exploded[1] );
if ( in_array( $country, \IPS\GeoLocation::$countries ) )
/* Remove quotient if it exists */
if( mb_strpos( $language, ';' ) !== FALSE )
{
$language = mb_substr( $language, 0, mb_strpos( $language, ';' ) );
}
$dashPos = mb_strpos( $language, '-' );
$country = mb_strtoupper( $dashPos ? mb_substr( $language, $dashPos + 1 ) : $language );
if ( \in_array( $country, \IPS\GeoLocation::$countries ) )
{
return $country;
}
}
@@ -110,7 +117,7 @@ class _Address extends FormAbstract
/* 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->addressLines = ( isset( $input['address'] ) and \is_array( $input['address'] ) ) ? array_filter( $input['address'] ) : array();
if ( empty( $value->addressLines ) )
{
$value->addressLines = array( NULL );