Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,194 @@
<?php
/**
* @brief Credit card input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 10 Mar 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
/**
* Credit card input class for Form Builder
*/
class _CreditCard extends \IPS\Helpers\Form\FormAbstract
{
/**
* @brief Default Options
* @code
$defaultOptions = array(
'types' => array( \IPS\nexus\CreditCard::TYPE_VISA, ... ), // Accepted card types
'save' => \IPS\nexus\Gateway, // A gateway to handle saving cards (you must save the card manually, but this will allow stored cards to be received)
'member' => \IPS\Member, // The member for saving cards (if NULL, will use currently loggeed in member)
'attr' => array(...), // Will wrap fields in a div with the specified attributes
'jsRequired'=> FALSE, // If true, will add an error in <noscript> tags
'names' => TRUE, // Sets if name="" attributes should be on the fields (for gateways that use JS, this avoids details hitting the server)
);
* @endcode
*/
protected $defaultOptions = array(
'types' => array(),
'save' => NULL,
'member' => NULL,
'attr' => NULL,
'jsRequired'=> FALSE,
'names' => TRUE,
);
/**
* Get HTML
*
* @return string
*/
public function html()
{
$member = $this->options['member'] ?: \IPS\Member::loggedIn();
$number = '';
$expMonth = NULL;
$expYear = NULL;
$ccv = '';
if ( is_array( $this->value ) )
{
$number = $this->value['number'];
$expMonth = $this->value['exp_month'];
$expYear = $this->value['exp_year'];
$expYear = $this->value['ccv'];
}
elseif ( $this->value instanceof \IPS\nexus\CreditCard )
{
$number = $this->value->number;
$expMonth = $this->value->expMonth;
$expYear = $this->value->expYear;
$ccv = $this->value->ccv;
}
$types = array();
foreach ( $this->options['types'] as $type )
{
$types[ $type ] = \IPS\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 )
{
try
{
$card = \IPS\nexus\Customer\CreditCard::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 ) {}
}
}
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->creditCard( $this, $types, $number, intval( $expMonth ), intval( $expYear ), $ccv, $storedCards );
}
/**
* Get HTML
*
* @return string
*/
public function rowHtml( $form=NULL )
{
if ( !$this->htmlId and $form )
{
$this->htmlId = "{$form->id}_{$this->name}";
}
return $this->html();
}
/**
* Format Value
*
* @return mixed
*/
public function formatValue()
{
$member = $this->options['member'] ?: \IPS\Member::loggedIn();
if ( $this->value !== NULL and !( $this->value instanceof \IPS\nexus\CreditCard ) and !( $this->value instanceof \IPS\nexus\Customer\CreditCard ) )
{
/* 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'] );
if ( $card->member->member_id === $member->member_id and $card->method->id === $this->options['save']->id )
{
return $card;
}
}
/* New card */
else
{
/* If we don't send the values, we won't have them */
if ( !$this->options['names'] )
{
$obj = new \IPS\nexus\CreditCard;
if ( isset( $this->value['token'] ) )
{
$obj->token = $this->value['token'];
}
if ( $this->options['save'] and isset( $this->value['save'] ) )
{
$obj->save = $this->value['save'];
}
return $obj;
}
/* Or if we've just not given anything, return NULL */
if ( !$this->value['number'] )
{
return NULL;
}
/* 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'] ) );
}
catch ( \InvalidArgumentException $e )
{
throw new \DomainException( 'card_number_invalid' );
}
catch ( \DomainException $e )
{
throw new \DomainException( 'card_expire_expired' );
}
}
}
}
/**
* Validate
*
* @return mixed
*/
public function validate()
{
if ( $this->value instanceof \IPS\nexus\CreditCard )
{
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 ) ) ) ) );
}
}
return parent::validate();
}
}
@@ -0,0 +1,48 @@
<?php
/**
* @brief Bulk discount input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 2 May 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
/**
* Bulk discount input class for Form Builder
*/
class _DiscountBulk extends \IPS\Helpers\Form\FormAbstract
{
/**
* Get HTML
*
* @return string
*/
public function html()
{
$selectedPackage = NULL;
try
{
$selectedPackage = $this->value['package'] ? \IPS\nexus\Package::load( $this->value['package'] ) : array();
}
catch ( \OutOfRangeException $e ) {}
$nodeSelect = new \IPS\Helpers\Form\Node( "{$this->name}[package]", $selectedPackage, FALSE, array( 'class' => 'IPS\nexus\Package\Group', 'permissionCheck' => function( $node )
{
return !( $node instanceof \IPS\nexus\Package\Group );
} ) );
return \IPS\Theme::i()->getTemplate( 'discountforms' )->bulk( $this, $nodeSelect->html() );
}
}
@@ -0,0 +1,48 @@
<?php
/**
* @brief Loyalty discount input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 2 May 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
/**
* Loyalty discount input class for Form Builder
*/
class _DiscountLoyalty extends \IPS\Helpers\Form\FormAbstract
{
/**
* Get HTML
*
* @return string
*/
public function html()
{
$selectedPackage = NULL;
try
{
$selectedPackage = $this->value['package'] ? \IPS\nexus\Package::load( $this->value['package'] ) : NULL;
}
catch ( \OutOfRangeException $e ) {}
$nodeSelect = new \IPS\Helpers\Form\Node( "{$this->name}[package]", $selectedPackage, FALSE, array( 'class' => 'IPS\nexus\Package\Group', 'permissionCheck' => function( $node )
{
return !( $node instanceof \IPS\nexus\Package\Group );
} ) );
return \IPS\Theme::i()->getTemplate( 'discountforms' )->loyalty( $this, $nodeSelect->html() );
}
}
@@ -0,0 +1,36 @@
<?php
/**
* @brief Usergroup discount input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 2 May 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
/**
* Usergroup discount input class for Form Builder
*/
class _DiscountUsergroup extends \IPS\Helpers\Form\FormAbstract
{
/**
* Get HTML
*
* @return string
*/
public function html()
{
return \IPS\Theme::i()->getTemplate( 'discountforms' )->usergroup( $this );
}
}
@@ -0,0 +1,85 @@
<?php
/**
* @brief Length input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 19 Jun 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
}
+121
View File
@@ -0,0 +1,121 @@
<?php
/**
* @brief Money input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 12 Feb 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
/**
* Money input class for Form Builder
*/
class _Money extends \IPS\Helpers\Form\FormAbstract
{
/**
* @brief Default Options
* @code
$defaultOptions = array(
'unlimitedLang' => 'unlimited', // Language string to use for unlimited checkbox label
'unlimitedTogglesOn' => array(), // IDs to show when unlimited box is ticked
'unlimitedTogglesOff' => array(), // IDs to show when unlimited box is not ticked
);
* @endcode
*/
protected $defaultOptions = array(
'unlimitedLang' => NULL,
'unlimitedTogglesOn' => array(),
'unlimitedTogglesOff' => array(),
);
/**
* Get HTML
*
* @return string
*/
public function html()
{
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->money( $this->name, $this->value, $this->options );
}
/**
* Format Value
*
* @return mixed
*/
public function formatValue()
{
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 = array();
if ( is_array( $_value ) )
{
foreach ( $_value as $currency => $amount )
{
if ( $amount !== '' )
{
if ( $amount instanceof \IPS\nexus\Money )
{
$value[ $currency ] = $amount;
}
elseif ( is_array( $amount ) and isset( $amount['amount'] ) )
{
$value[ $currency ] = new \IPS\nexus\Money( $amount['amount'], $currency );
}
elseif ( is_numeric( $amount ) )
{
$value[ $currency ] = new \IPS\nexus\Money( $amount, $currency );
}
}
}
}
return $value;
}
/**
* Validate
*
* @throws \InvalidArgumentException
* @return TRUE
*/
public function validate()
{
if ( $this->required )
{
if ( ( $this->options['unlimitedLang'] and $this->value === '*' ) or count( $this->value ) )
{
return TRUE;
}
throw new \InvalidArgumentException('form_required');
}
return parent::validate();
}
/**
* String Value
*
* @param mixed $value The value
* @return string
*/
public static function stringValue( $value )
{
return json_encode( $value );
}
}
@@ -0,0 +1,139 @@
<?php
/**
* @brief Renewal Term input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 25 Mar 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
/**
* Renewal Term input class for Form Builder
*/
class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
{
/**
* @brief Default Options
* @code
$defaultOptions = array(
'customer' => \IPS\nexus\Customer, // Customer this is for (sets appropriate default currency)
'currency' => 'USD', // Alternatively to specifying customer, can manually specify currency (defaults to NULL)
'allCurrencies' => FALSE, // If TRUE, will ask for a price in all currencies (defaults to FALSE)
'addToBase' => FALSE, // If TRUE, a checkbox will be added asking if the price should be added to the base price
'lockTerm' => FALSE, // If TRUE, only the price (not the term) will be editable
);
* @endcode
*/
protected $defaultOptions = array(
'customer' => NULL,
'currency' => NULL,
'allCurrencies' => FALSE,
'addToBase' => NULL,
'lockTerm' => FALSE,
);
/**
* Get HTML
*
* @return string
*/
public function html()
{
$value = $this->value;
if ( !$this->value )
{
if ( $this->options['customer'] )
{
$defaultCurrency = $this->options['customer']->defaultCurrency();
}
elseif ( $this->options['currency'] )
{
$defaultCurrency = $this->options['currency'];
}
else
{
$currencies = \IPS\nexus\Money::currencies();
$defaultCurrency = array_shift( $currencies );
}
if ( $this->options['allCurrencies'] )
{
$costs = array();
foreach ( \IPS\nexus\Money::currencies() as $currency )
{
$costs[ $currency ] = new \IPS\nexus\Money( 0, $currency );
}
}
else
{
$costs = new \IPS\nexus\Money( 0, $defaultCurrency );
}
$value = new \IPS\nexus\Purchase\RenewalTerm( $costs, new \DateInterval( 'P0M' ) );
}
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->renewalTerm( $this->name, $value, $this->options );
}
/**
* Format Value
*
* @return mixed
*/
public function formatValue()
{
if ( is_array( $this->value ) )
{
if ( !isset( $this->value['term'] ) or !$this->value['term'] or !isset( $this->value['unit'] ) or !$this->value['unit'] )
{
return NULL;
}
else
{
if ( $this->options['allCurrencies'] )
{
$costs = array();
foreach ( \IPS\nexus\Money::currencies() as $currency )
{
if ( isset( $this->value[ 'amount_' . $currency ] ) )
{
$costs[ $currency ] = new \IPS\nexus\Money( $this->value[ 'amount_' . $currency ], $currency );
}
else
{
$costs[ $currency ] = 0;
}
}
}
else
{
if ( isset( $this->value['currency'] ) )
{
$currency = $this->value['currency'];
}
else
{
$currencies = \IPS\nexus\Money::currencies();
$currency = array_shift( $currencies );
}
$costs = new \IPS\nexus\Money( $this->value['amount'], $currency );
}
return new \IPS\nexus\Purchase\RenewalTerm( $costs, new \DateInterval( 'P' . $this->value['term'] . mb_strtoupper( $this->value['unit'] ) ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
}
}
return $this->value;
}
}
@@ -0,0 +1,89 @@
<?php
/**
* @brief Shipping method input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 19 Mar 2014
* @version SVN_VERSION_NUMBER
*/
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();
}
}
@@ -0,0 +1,84 @@
<?php
/**
* @brief Country/State input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 12 Feb 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
/**
* Country/State input class for Form Builder
*/
class _StateSelect extends \IPS\Helpers\Form\FormAbstract
{
/**
* @brief Default Options
* @code
$defaultOptions = array(
'unlimitedLang' => 'all_locations', // Language string to use for "All locations" option. If NULL, will not be available.
);
* @endcode
*/
protected $defaultOptions = array(
'unlimitedLang' => NULL
);
/**
* Get HTML
*
* @return string
*/
public function html()
{
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->stateSelect( $this->name, $this->value, $this->options['unlimitedLang'] );
}
/**
* Get Value
*
* @return mixed
*/
public function getValue()
{
$value = array();
if ( $this->options['unlimitedLang'] )
{
$unlimitedName = "{$this->name}_unlimited";
if ( isset( \IPS\Request::i()->$unlimitedName ) )
{
return '*';
}
}
foreach ( parent::getValue() as $v )
{
if ( preg_match( '/^([A-Z]{2})-(.*)$/', $v, $matches ) )
{
if ( !isset( $value[ $matches[1] ] ) )
{
$value[ $matches[1] ] = array();
}
$value[ $matches[1] ][] = $matches[2];
}
else
{
$value[ $v ] = '*';
}
}
return $value;
}
}
@@ -0,0 +1,48 @@
<?php
/**
* @brief Username & Password input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 17 Apr 2014
* @version SVN_VERSION_NUMBER
*/
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;
}
/**
* Username & Password input class for Form Builder
*/
class _UserPass extends \IPS\Helpers\Form\FormAbstract
{
/**
* Get HTML
*
* @return string
*/
public function html()
{
$value = is_array( $this->value ) ? $this->value : json_decode( \IPS\Text\Encrypt::fromTag( $this->value )->decrypt(), TRUE );
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->usernamePassword( $this->name, $value );
}
/**
* String Value
*
* @param mixed $value The value
* @return string
*/
public static function stringValue( $value )
{
return \IPS\Text\Encrypt::fromPlaintext( json_encode( $value ) )->tag();
}
}
@@ -0,0 +1,90 @@
<?php
/**
* @brief Weight input class for Form Builder
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 14 Feb 2014
* @version SVN_VERSION_NUMBER
*/
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 ? 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 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;
}
}
Whitespace-only changes.