Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,16 +12,31 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use InvalidArgumentException;
|
||||
use IPS\GeoLocation;
|
||||
use IPS\Helpers\Form\Address;
|
||||
use IPS\Http\Request\Exception;
|
||||
use IPS\Log;
|
||||
use IPS\nexus\Tax;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
use function in_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumer/business address input class for Form Builder
|
||||
*/
|
||||
class _BusinessAddress extends \IPS\Helpers\Form\Address
|
||||
class BusinessAddress extends Address
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
@@ -33,7 +48,7 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
protected array $defaultOptions = array(
|
||||
'minimize' => FALSE,
|
||||
'requireFullAddress' => TRUE,
|
||||
'vat' => FALSE
|
||||
@@ -44,14 +59,14 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_forms.js', 'nexus', 'global' ) );
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'global_forms.js', 'nexus', 'global' ) );
|
||||
|
||||
/* 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 ( $defaultCountry = static::calculateDefaultCountry() )
|
||||
{
|
||||
$this->value->country = $defaultCountry;
|
||||
@@ -65,7 +80,7 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
|
||||
}
|
||||
|
||||
/* Display */
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->businessAddress( $this->name, $this->value, \IPS\Settings::i()->googleplacesautocomplete ? \IPS\Settings::i()->google_maps_api_key : NULL, $this->options['minimize'], $this->options['requireFullAddress'], $this->htmlId, $this->options['vat'] );
|
||||
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->businessAddress( $this->name, $this->value, Settings::i()->googleplacesautocomplete ? Settings::i()->google_maps_api_key : NULL, $this->options['minimize'], $this->options['requireFullAddress'], $this->htmlId, $this->options['vat'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +88,7 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): mixed
|
||||
{
|
||||
/* Get the normal address stuff */
|
||||
$value = parent::getValue();
|
||||
@@ -82,13 +97,13 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
|
||||
if ( $value )
|
||||
{
|
||||
$name = $this->name;
|
||||
if( \IPS\Request::i()->$name['type'] === 'business' )
|
||||
if( Request::i()->$name['type'] === 'business' )
|
||||
{
|
||||
$value->business = \IPS\Request::i()->$name['business'];
|
||||
$value->business = Request::i()->$name['business'];
|
||||
|
||||
if ( $this->options['vat'] and \in_array( $value->country, array('AT','BE','BG','HR','CY','CZ','DK','EE','FI','FR','DE','GR','HU','IE','IT','LV','LT','LU','MT','NL','PL','PT','RO','SK','SI','ES','SE','GB') ) and \IPS\Request::i()->$name['vat'] )
|
||||
if ( $this->options['vat'] and in_array( $value->country, array('AT','BE','BG','HR','CY','CZ','DK','EE','FI','FR','DE','GR','HU','IE','IT','LV','LT','LU','MT','NL','PL','PT','RO','SK','SI','ES','SE','GB') ) and Request::i()->$name['vat'] )
|
||||
{
|
||||
$value->vat = \IPS\Request::i()->$name['vat'];
|
||||
$value->vat = Request::i()->$name['vat'];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,10 +124,10 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
public function validate(): bool
|
||||
{
|
||||
parent::validate();
|
||||
|
||||
@@ -120,27 +135,27 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
|
||||
{
|
||||
if ( $this->value->business === '' )
|
||||
{
|
||||
throw new \DomainException('cm_business_name_required');
|
||||
throw new DomainException('cm_business_name_required');
|
||||
}
|
||||
|
||||
if ( $this->value->vat )
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\nexus\Tax::validateVAT( $this->value->vat );
|
||||
$response = Tax::validateVAT( $this->value->vat );
|
||||
if ( !$response )
|
||||
{
|
||||
throw new \DomainException('cm_checkout_vat_invalid');
|
||||
throw new DomainException('cm_checkout_vat_invalid');
|
||||
}
|
||||
elseif ( $response['countryCode'] !== $this->value->country )
|
||||
{
|
||||
throw new \DomainException('cm_checkout_vat_wrong_country');
|
||||
throw new DomainException('cm_checkout_vat_wrong_country');
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'vat-validation' );
|
||||
throw new \DomainException('cm_checkout_vat_error');
|
||||
Log::log( $e, 'vat-validation' );
|
||||
throw new DomainException('cm_checkout_vat_error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,33 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\CreditCard as CreditCardClass;
|
||||
use IPS\nexus\Customer\CreditCard as CustomerCardClass;
|
||||
use IPS\Theme;
|
||||
use LogicException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function intval;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit card input class for Form Builder
|
||||
*/
|
||||
class _CreditCard extends \IPS\Helpers\Form\FormAbstract
|
||||
class CreditCard extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
@@ -38,7 +55,7 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
protected array $defaultOptions = array(
|
||||
'types' => array(),
|
||||
'save' => NULL,
|
||||
'member' => NULL,
|
||||
@@ -55,22 +72,22 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
$member = $this->options['member'] ?: \IPS\Member::loggedIn();
|
||||
$member = $this->options['member'] ?: Member::loggedIn();
|
||||
|
||||
$number = '';
|
||||
$expMonth = NULL;
|
||||
$expYear = NULL;
|
||||
$ccv = '';
|
||||
if ( \is_array( $this->value ) )
|
||||
if ( is_array( $this->value ) )
|
||||
{
|
||||
$number = $this->value['number'];
|
||||
$expMonth = $this->value['exp_month'];
|
||||
$expYear = $this->value['exp_year'];
|
||||
$ccv = $this->value['ccv'];
|
||||
}
|
||||
elseif ( $this->value instanceof \IPS\nexus\CreditCard )
|
||||
elseif ( $this->value instanceof CreditCardClass )
|
||||
{
|
||||
$number = $this->value->number;
|
||||
$expMonth = $this->value->expMonth;
|
||||
@@ -81,34 +98,34 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
|
||||
$types = array();
|
||||
foreach ( $this->options['types'] as $type )
|
||||
{
|
||||
$types[ $type ] = \IPS\Member::loggedIn()->language()->addToStack( 'card_type_' . $type );
|
||||
$types[ $type ] = Member::loggedIn()->language()->addToStack( 'card_type_' . $type );
|
||||
}
|
||||
|
||||
$storedCards = array();
|
||||
if ( $member->member_id and $this->options['save'] )
|
||||
{
|
||||
foreach( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=? AND card_method=?', $member->member_id, $this->options['save']->id ) ) as $card )
|
||||
foreach( Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=? AND card_method=?', $member->member_id, $this->options['save']->id ) ) as $card )
|
||||
{
|
||||
try
|
||||
{
|
||||
$card = \IPS\nexus\Customer\CreditCard::constructFromData( $card );
|
||||
$card = CustomerCardClass::constructFromData( $card );
|
||||
$card->card; // This is just to make the API call now and cache the response so we can catch the exception if one is thrown
|
||||
$storedCards[ $card->id ] = $card;
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
catch ( Exception ) {}
|
||||
}
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->creditCard( $this, $types, $number, \intval( $expMonth ), \intval( $expYear ), $ccv, $storedCards );
|
||||
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->creditCard( $this, $types, $number, intval( $expMonth ), intval( $expYear ), $ccv, $storedCards );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @param \IPS\Helpers\Form|null $form Form helper object
|
||||
* @param Form|null $form Form helper object
|
||||
* @return string
|
||||
*/
|
||||
public function rowHtml( $form=NULL )
|
||||
public function rowHtml( Form $form=NULL ): string
|
||||
{
|
||||
if ( !$this->htmlId and $form )
|
||||
{
|
||||
@@ -123,16 +140,16 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function formatValue()
|
||||
public function formatValue(): mixed
|
||||
{
|
||||
$member = $this->options['member'] ?: \IPS\Member::loggedIn();
|
||||
$member = $this->options['member'] ?: Member::loggedIn();
|
||||
|
||||
if ( $this->value !== NULL and !( $this->value instanceof \IPS\nexus\CreditCard ) and !( $this->value instanceof \IPS\nexus\Customer\CreditCard ) )
|
||||
if ( $this->value !== NULL and !( $this->value instanceof CreditCard ) and !( $this->value instanceof CustomerCardClass) )
|
||||
{
|
||||
/* Stored Card */
|
||||
if ( $this->options['save'] and isset( $this->value['stored'] ) and $this->value['stored'] and ( !isset( $this->value['number'] ) or !$this->value['number'] ) and ( !isset( $this->value['token'] ) or !$this->value['token'] ) )
|
||||
{
|
||||
$card = \IPS\nexus\Customer\CreditCard::load( $this->value['stored'] );
|
||||
$card = CustomerCardClass::load( $this->value['stored'] );
|
||||
if ( $card->member->member_id === $member->member_id and $card->method->id === $this->options['save']->id )
|
||||
{
|
||||
return $card;
|
||||
@@ -144,7 +161,7 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
|
||||
/* If we don't send the values, we won't have them */
|
||||
if ( !$this->options['names'] )
|
||||
{
|
||||
$obj = new \IPS\nexus\CreditCard;
|
||||
$obj = new CustomerCardClass;
|
||||
if ( isset( $this->value['token'] ) )
|
||||
{
|
||||
$obj->token = $this->value['token'];
|
||||
@@ -165,18 +182,20 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
|
||||
/* But if we do, we can build an object */
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\CreditCard::build( $this->value['number'], $this->value['exp_month'], $this->value['exp_year'], $this->value['ccv'], ( $this->options['save'] and isset( $this->value['save'] ) and $this->value['save'] ) );
|
||||
return CreditCardClass::build( $this->value['number'], $this->value['exp_month'], $this->value['exp_year'], $this->value['ccv'], ( $this->options['save'] and isset( $this->value['save'] ) and $this->value['save'] ) );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
catch ( InvalidArgumentException $e )
|
||||
{
|
||||
throw new \DomainException( $e->getMessage() );
|
||||
throw new DomainException( $e->getMessage() );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
catch ( DomainException )
|
||||
{
|
||||
throw new \DomainException( 'card_expire_expired' );
|
||||
throw new DomainException( 'card_expire_expired' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,13 +203,13 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate()
|
||||
public function validate(): bool
|
||||
{
|
||||
if ( $this->value instanceof \IPS\nexus\CreditCard )
|
||||
if ( $this->value instanceof CreditCard )
|
||||
{
|
||||
if ( $this->value->type and !\in_array( $this->value->type, $this->options['types'] ) )
|
||||
if ( $this->value->type and !in_array( $this->value->type, $this->options['types'] ) )
|
||||
{
|
||||
throw new \LogicException( \IPS\Member::loggedIn()->language()->addToStack( 'card_bad_type', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( "card_type_" . $this->value->type ) ) ) ) );
|
||||
throw new LogicException( Member::loggedIn()->language()->addToStack( 'card_bad_type', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( "card_type_" . $this->value->type ) ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,36 +12,46 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\nexus\Package;
|
||||
use IPS\nexus\Package\Group;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk discount input class for Form Builder
|
||||
*/
|
||||
class _DiscountBulk extends \IPS\Helpers\Form\FormAbstract
|
||||
class DiscountBulk extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
$selectedPackage = NULL;
|
||||
try
|
||||
{
|
||||
$selectedPackage = ( \is_array( $this->value ) AND isset( $this->value['package'] ) ) ? \IPS\nexus\Package::load( $this->value['package'] ) : array();
|
||||
$selectedPackage = ( is_array( $this->value ) AND isset( $this->value['package'] ) ) ? Package::load( $this->value['package'] ) : array();
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
catch ( OutOfRangeException ) {}
|
||||
|
||||
$nodeSelect = new \IPS\Helpers\Form\Node( "{$this->name}[package]", $selectedPackage, FALSE, array( 'class' => 'IPS\nexus\Package\Group', 'permissionCheck' => function( $node )
|
||||
$nodeSelect = new Node( "{$this->name}[package]", $selectedPackage, FALSE, array( 'class' => 'IPS\nexus\Package\Group', 'permissionCheck' => function( $node )
|
||||
{
|
||||
return !( $node instanceof \IPS\nexus\Package\Group );
|
||||
return !( $node instanceof Group );
|
||||
} ) );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'discountforms' )->bulk( $this, $nodeSelect->html() );
|
||||
return Theme::i()->getTemplate( 'discountforms' )->bulk( $this, $nodeSelect->html() );
|
||||
}
|
||||
}
|
||||
@@ -12,36 +12,46 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\nexus\Package;
|
||||
use IPS\nexus\Package\Group;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loyalty discount input class for Form Builder
|
||||
*/
|
||||
class _DiscountLoyalty extends \IPS\Helpers\Form\FormAbstract
|
||||
class DiscountLoyalty extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
$selectedPackage = NULL;
|
||||
try
|
||||
{
|
||||
$selectedPackage = ( \is_array( $this->value ) AND isset( $this->value['package'] ) ) ? \IPS\nexus\Package::load( $this->value['package'] ) : NULL;
|
||||
$selectedPackage = ( is_array( $this->value ) AND isset( $this->value['package'] ) ) ? Package::load( $this->value['package'] ) : NULL;
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
catch ( OutOfRangeException ) {}
|
||||
|
||||
$nodeSelect = new \IPS\Helpers\Form\Node( "{$this->name}[package]", $selectedPackage, FALSE, array( 'class' => 'IPS\nexus\Package\Group', 'permissionCheck' => function( $node )
|
||||
$nodeSelect = new Node( "{$this->name}[package]", $selectedPackage, FALSE, array( 'class' => 'IPS\nexus\Package\Group', 'permissionCheck' => function( $node )
|
||||
{
|
||||
return !( $node instanceof \IPS\nexus\Package\Group );
|
||||
return !( $node instanceof Group );
|
||||
} ) );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'discountforms' )->loyalty( $this, $nodeSelect->html() );
|
||||
return Theme::i()->getTemplate( 'discountforms' )->loyalty( $this, $nodeSelect->html() );
|
||||
}
|
||||
}
|
||||
@@ -12,24 +12,29 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Usergroup discount input class for Form Builder
|
||||
*/
|
||||
class _DiscountUsergroup extends \IPS\Helpers\Form\FormAbstract
|
||||
class DiscountUsergroup extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'discountforms' )->usergroup( $this );
|
||||
return Theme::i()->getTemplate( 'discountforms' )->usergroup( $this );
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,13 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Helpers\Form\Ftp as FtpHelper;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -22,7 +26,7 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
* Ftp input class for Form Builder
|
||||
* @note This class is necessary, because it is defined as an additional field type for Commerce Custom Fields, which will attempt to load this class.
|
||||
*/
|
||||
class _Ftp extends \IPS\Helpers\Form\Ftp
|
||||
class Ftp extends FtpHelper
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Length input class for Form Builder
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 19 Jun 2014
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Length input class for Form Builder
|
||||
*/
|
||||
class _Length extends \IPS\Helpers\Form\FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
* @code
|
||||
$defaultOptions = array(
|
||||
'unlimitedLang' => 'unlimited', // Language string to use for unlimited checkbox label
|
||||
'round' => 2, // Decimal points to round to
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
'round' => 2,
|
||||
);
|
||||
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
$unit = \IPS\nexus\Shipping\Length::bestUnit();
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->length( $this->name, $this->value ? round( $this->value->float( $unit ), $this->options['round'] ) : 0, $unit );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format Value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function formatValue()
|
||||
{
|
||||
$val = $this->value;
|
||||
if ( $val instanceof \IPS\nexus\Shipping\Length )
|
||||
{
|
||||
return $val;
|
||||
}
|
||||
|
||||
if ( isset( $val['amount'] ) )
|
||||
{
|
||||
return new \IPS\nexus\Shipping\Length( $val['amount'], $val['unit'] );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if ( $this->required and !$this->value->cm )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,26 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\nexus\Money as MoneyClass;
|
||||
use IPS\Theme;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
use function is_numeric;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Money input class for Form Builder
|
||||
*/
|
||||
class _Money extends \IPS\Helpers\Form\FormAbstract
|
||||
class Money extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
@@ -33,7 +43,7 @@ class _Money extends \IPS\Helpers\Form\FormAbstract
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
protected array $defaultOptions = array(
|
||||
'unlimitedLang' => NULL,
|
||||
'unlimitedTogglesOn' => array(),
|
||||
'unlimitedTogglesOff' => array(),
|
||||
@@ -44,42 +54,42 @@ class _Money extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->money( $this->name, $this->value, $this->options );
|
||||
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->money( $this->name, $this->value, $this->options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format Value
|
||||
*
|
||||
* @return mixed
|
||||
* @return array|string
|
||||
*/
|
||||
public function formatValue()
|
||||
public function formatValue(): array|string
|
||||
{
|
||||
if ( ( $this->options['unlimitedLang'] and isset( $this->value['__unlimited'] ) ) or $this->value === '*' )
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
|
||||
$_value = \is_array( $this->value ) ? $this->value : @json_decode( $this->value, TRUE );
|
||||
$_value = is_array( $this->value ) ? $this->value : @json_decode( $this->value, TRUE );
|
||||
$value = array();
|
||||
if ( \is_array( $_value ) )
|
||||
if ( is_array( $_value ) )
|
||||
{
|
||||
foreach ( $_value as $currency => $amount )
|
||||
{
|
||||
if ( $amount !== '' )
|
||||
{
|
||||
if ( $amount instanceof \IPS\nexus\Money )
|
||||
if ( $amount instanceof MoneyClass )
|
||||
{
|
||||
$value[ $currency ] = $amount;
|
||||
}
|
||||
elseif ( \is_array( $amount ) and isset( $amount['amount'] ) )
|
||||
elseif ( is_array( $amount ) and isset( $amount['amount'] ) )
|
||||
{
|
||||
$value[ $currency ] = new \IPS\nexus\Money( $amount['amount'], $currency );
|
||||
$value[ $currency ] = new MoneyClass( $amount['amount'], $currency );
|
||||
}
|
||||
elseif ( \is_numeric( $amount ) )
|
||||
elseif ( is_numeric( $amount ) )
|
||||
{
|
||||
$value[ $currency ] = new \IPS\nexus\Money( $amount, $currency );
|
||||
$value[ $currency ] = new MoneyClass( $amount, $currency );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,19 +100,19 @@ class _Money extends \IPS\Helpers\Form\FormAbstract
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
public function validate(): bool
|
||||
{
|
||||
if ( $this->required )
|
||||
{
|
||||
if ( ( $this->options['unlimitedLang'] and $this->value === '*' ) or \count( $this->value ) )
|
||||
if ( ( $this->options['unlimitedLang'] and $this->value === '*' ) or count( $this->value ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
throw new InvalidArgumentException('form_required');
|
||||
}
|
||||
return parent::validate();
|
||||
}
|
||||
@@ -111,9 +121,9 @@ class _Money extends \IPS\Helpers\Form\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 );
|
||||
}
|
||||
|
||||
@@ -12,16 +12,29 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Money;
|
||||
use IPS\nexus\Purchase\RenewalTerm as RenewalTermClass;
|
||||
use IPS\Theme;
|
||||
use LengthException;
|
||||
use OutOfRangeException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renewal Term input class for Form Builder
|
||||
*/
|
||||
class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
class RenewalTerm extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
@@ -41,7 +54,7 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
protected array $defaultOptions = array(
|
||||
'customer' => NULL,
|
||||
'currency' => NULL,
|
||||
'allCurrencies' => FALSE,
|
||||
@@ -60,9 +73,9 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->renewalTerm( $this->name, $this->value, $this->options );
|
||||
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->renewalTerm( $this->name, $this->value, $this->options );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,9 +83,9 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function formatValue()
|
||||
public function formatValue(): mixed
|
||||
{
|
||||
if ( \is_array( $this->value ) )
|
||||
if ( is_array( $this->value ) )
|
||||
{
|
||||
if ( isset( $this->value['null'] ) /* or !isset( $this->value['term'] ) or !$this->value['term'] or !isset( $this->value['unit'] ) or !$this->value['unit'] */ )
|
||||
{
|
||||
@@ -84,11 +97,11 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
if ( $this->options['allCurrencies'] )
|
||||
{
|
||||
$costs = array();
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
foreach ( Money::currencies() as $currency )
|
||||
{
|
||||
if ( isset( $this->value[ 'amount_' . $currency ] ) )
|
||||
{
|
||||
$costs[ $currency ] = new \IPS\nexus\Money( $this->value[ 'amount_' . $currency ], $currency );
|
||||
$costs[ $currency ] = new Money( $this->value[ 'amount_' . $currency ], $currency );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -104,10 +117,16 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
}
|
||||
else
|
||||
{
|
||||
$currencies = \IPS\nexus\Money::currencies();
|
||||
$currencies = Money::currencies();
|
||||
$currency = array_shift( $currencies );
|
||||
}
|
||||
$costs = isset( $this->value['amount'] ) ? new \IPS\nexus\Money( $this->value['amount'], $currency ) : NULL;
|
||||
$costs = isset( $this->value['amount'] ) ? new Money( $this->value['amount'], $currency ) : NULL;
|
||||
}
|
||||
|
||||
/* If we have no price specified, stop here */
|
||||
if( $costs === NULL OR ( is_array( $costs ) AND !count( $costs ) ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Work out term */
|
||||
@@ -124,20 +143,20 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
|
||||
if ( $this->value['term'] < 1 )
|
||||
{
|
||||
$this->value = new \IPS\nexus\Purchase\RenewalTerm( $costs, new \DateInterval( 'P' . 1 . mb_strtoupper( $this->value['unit'] ) ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
throw new \LengthException( \IPS\Member::loggedIn()->language()->addToStack('form_number_min', FALSE, array( 'sprintf' => array( 0 ) ) ) );
|
||||
$this->value = new RenewalTermClass( $costs, new DateInterval( 'P' . 1 . mb_strtoupper( $this->value['unit'] ) ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
throw new LengthException( Member::loggedIn()->language()->addToStack('form_number_min', FALSE, array( 'sprintf' => array( 0 ) ) ) );
|
||||
}
|
||||
if ( !\in_array( $this->value['unit'], array( 'd', 'm', 'y' ) ) )
|
||||
if ( !in_array( $this->value['unit'], array( 'd', 'm', 'y' ) ) )
|
||||
{
|
||||
$this->value = new \IPS\nexus\Purchase\RenewalTerm( $costs, new \DateInterval( 'P' . $this->value['term'] . 'D' ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
throw new \OutOfRangeException( 'form_bad_value' );
|
||||
$this->value = new RenewalTermClass( $costs, new DateInterval( 'P' . $this->value['term'] . 'D' ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
throw new OutOfRangeException( 'form_bad_value' );
|
||||
}
|
||||
|
||||
$term = new \DateInterval( 'P' . $this->value['term'] . mb_strtoupper( $this->value['unit'] ) );
|
||||
$term = new DateInterval( 'P' . $this->value['term'] . mb_strtoupper( $this->value['unit'] ) );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return new \IPS\nexus\Purchase\RenewalTerm( $costs, $term, NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
return new RenewalTermClass( $costs, $term, NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Shipping method input class for Form Builder
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 19 Mar 2014
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shipping method input class for Form Builder
|
||||
*/
|
||||
class _Shipping extends \IPS\Helpers\Form\FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
* @code
|
||||
$defaultOptions = array(
|
||||
'options' => array( // Options
|
||||
'set1' => array( // Group items into sets with similar methods
|
||||
'items' => array( // Array of item data
|
||||
'itemName' => '', // Name
|
||||
),
|
||||
'methods' => array( // Array of methods (classes which implement \IPS\nexus\Shipping\Rate)
|
||||
\IPS\nexus\Shipping\Rate,
|
||||
...
|
||||
)
|
||||
),
|
||||
'set2' => array(...), // Repeat for however many sets you like
|
||||
),
|
||||
'currency' => 'USD', // Currency to display prices in
|
||||
'invoice' => \IPS\nexus\Invoice::load(1), // Invoice (some shipping methods may use it for determining price)
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
'options' => NULL,
|
||||
'currency' => NULL,
|
||||
'invoice' => NULL,
|
||||
);
|
||||
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->shipping( $this->name, $this->value, $this->options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
foreach ( $this->options['options'] as $group => $options )
|
||||
{
|
||||
if ( !isset( $this->value[ $group ] ) or !$this->value[ $group ] )
|
||||
{
|
||||
if ( $this->required )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
}
|
||||
}
|
||||
elseif ( !\in_array( $this->value[ $group ], array_keys( $options['methods'] ) ) )
|
||||
{
|
||||
throw new \OutOfRangeException( 'form_bad_value' );
|
||||
}
|
||||
}
|
||||
|
||||
return parent::validate();
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,25 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\GeoLocation;
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Request;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Country/State input class for Form Builder
|
||||
*/
|
||||
class _StateSelect extends \IPS\Helpers\Form\FormAbstract
|
||||
class StateSelect extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
@@ -31,7 +40,7 @@ class _StateSelect extends \IPS\Helpers\Form\FormAbstract
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
protected array $defaultOptions = array(
|
||||
'unlimitedLang' => NULL
|
||||
);
|
||||
|
||||
@@ -40,9 +49,9 @@ class _StateSelect extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->stateSelect( $this->name, $this->value, $this->options['unlimitedLang'] );
|
||||
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->stateSelect( $this->name, $this->value, $this->options['unlimitedLang'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,12 +59,12 @@ class _StateSelect extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): mixed
|
||||
{
|
||||
if ( $this->options['unlimitedLang'] )
|
||||
{
|
||||
$unlimitedName = "{$this->name}_unlimited";
|
||||
if ( isset( \IPS\Request::i()->$unlimitedName ) )
|
||||
if ( isset( Request::i()->$unlimitedName ) )
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
@@ -69,14 +78,14 @@ class _StateSelect extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function formatValue()
|
||||
public function formatValue(): mixed
|
||||
{
|
||||
if ( \is_array( $this->value ) )
|
||||
if ( is_array( $this->value ) )
|
||||
{
|
||||
$value = array();
|
||||
foreach ( $this->value as $k => $v )
|
||||
{
|
||||
if ( \in_array( (string) $k, \IPS\GeoLocation::$countries ) )
|
||||
if ( in_array( (string) $k, GeoLocation::$countries ) )
|
||||
{
|
||||
$value[ $k ] = $v;
|
||||
}
|
||||
|
||||
@@ -12,32 +12,39 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Text\Encrypt;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Username & Password input class for Form Builder
|
||||
*/
|
||||
class _UserPass extends \IPS\Helpers\Form\FormAbstract
|
||||
class UserPass extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
$value = \is_array( $this->value ) ? $this->value : json_decode( \IPS\Text\Encrypt::fromTag( $this->value )->decrypt(), TRUE );
|
||||
$defaultValue = \is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( \IPS\Text\Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
|
||||
$value = is_array( $this->value ) ? $this->value : json_decode( Encrypt::fromTag( $this->value )->decrypt(), TRUE );
|
||||
$defaultValue = is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
|
||||
if ( isset( $value['pw'] ) and isset( $defaultValue['pw'] ) and $value['pw'] and $value['pw'] === $defaultValue['pw'] and !$this->error )
|
||||
{
|
||||
$value['pw'] = '********';
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->usernamePassword( $this->name, $value );
|
||||
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->usernamePassword( $this->name, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,13 +52,13 @@ class _UserPass extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): mixed
|
||||
{
|
||||
$value = parent::getValue();
|
||||
|
||||
if ( isset( $value['pw'] ) and $value['pw'] === '********' )
|
||||
{
|
||||
$defaultValue = \is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( \IPS\Text\Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
|
||||
$defaultValue = is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
|
||||
$value['pw'] = $defaultValue['pw'];
|
||||
}
|
||||
|
||||
@@ -62,10 +69,10 @@ class _UserPass extends \IPS\Helpers\Form\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 \IPS\Text\Encrypt::fromPlaintext( json_encode( $value ) )->tag();
|
||||
return Encrypt::fromPlaintext( json_encode( $value ) )->tag();
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Weight input class for Form Builder
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 14 Feb 2014
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Weight input class for Form Builder
|
||||
*/
|
||||
class _Weight extends \IPS\Helpers\Form\FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
* @code
|
||||
$defaultOptions = array(
|
||||
'unlimitedLang' => 'unlimited', // Language string to use for unlimited checkbox label
|
||||
'round' => 2, // Decimal points to round to
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
'unlimitedLang' => NULL,
|
||||
'round' => 2,
|
||||
);
|
||||
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
$unit = \IPS\nexus\Shipping\Weight::bestUnit();
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->weight( $this->name, ( $this->value and $this->value !== '*' ) ? round( $this->value->float( $unit ), $this->options['round'] ) : 0, $unit, $this->options['unlimitedLang'], $this->value === '*' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format Value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function formatValue()
|
||||
{
|
||||
$val = $this->value;
|
||||
if ( $val instanceof \IPS\nexus\Shipping\Weight )
|
||||
{
|
||||
return $val;
|
||||
}
|
||||
|
||||
if ( $this->options['unlimitedLang'] and ( $val === '*' or isset( $val['unlimited'] ) ) )
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
if ( isset( $val['amount'] ) )
|
||||
{
|
||||
return new \IPS\nexus\Shipping\Weight( $val['amount'], $val['unit'] );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if ( $this->required and !$this->value->kilograms )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user