| Server IP : 78.24.162.143 / Your IP : 216.73.216.61 Web Server : Apache System : Linux hosting.cormo.systems 5.15.0-179-generic #189-Ubuntu SMP Tue May 5 18:20:56 UTC 2026 x86_64 User : web63 ( 5058) PHP Version : 7.4.33 Disable Function : create_functions,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/clients/client34/web63/web/wp-content/plugins/pods/classes/fields/ |
Upload File : |
<?php
/**
* @package Pods\Fields
*/
class PodsField_Currency extends PodsField_Number {
/**
* {@inheritdoc}
*/
public static $group = 'Number';
/**
* {@inheritdoc}
*/
public static $type = 'currency';
/**
* {@inheritdoc}
*/
public static $label = 'Currency';
/**
* {@inheritdoc}
*/
public static $prepare = '%d';
/**
* Currency Formats
*
* @var array
* @since 2.0.0
*/
public static $currencies = array();
/**
* {@inheritdoc}
*/
public function setup() {
static::$group = __( 'Number', 'pods' );
static::$label = __( 'Currency', 'pods' );
static::data_currencies();
}
/**
* {@inheritdoc}
*/
public function options() {
$currency_options = array();
foreach ( static::$currencies as $key => $value ) {
$currency = $value['label'];
if ( $value['label'] !== $value['name'] ) {
$currency .= ': ' . $value['name'];
}
$currency .= ' (' . $value['sign'] . ')';
$currency_options[ $key ] = $currency;
}
$options = array(
static::$type . '_format_type' => array(
'label' => __( 'Input Type', 'pods' ),
'default' => 'number',
'type' => 'pick',
'data' => array(
'number' => __( 'Freeform Number', 'pods' ),
'slider' => __( 'Slider', 'pods' ),
),
'pick_show_select_text' => 0,
'dependency' => true,
),
static::$type . '_format_sign' => array(
'label' => __( 'Currency Sign', 'pods' ),
'default' => apply_filters( 'pods_form_ui_field_number_currency_default', 'usd' ),
'type' => 'pick',
'data' => apply_filters( 'pods_form_ui_field_number_currency_options', $currency_options ),
'pick_show_select_text' => 0,
),
static::$type . '_format_placement' => array(
'label' => __( 'Currency Placement on Display', 'pods' ),
'default' => apply_filters( 'pods_form_ui_field_number_currency_placement_default', 'before' ),
'help' => __( 'This is the placement of the currency sign when displaying the value. The input will always have the sign on the left to identify the currency', 'pods' ),
'type' => 'pick',
'data' => array(
'before' => __( 'Before (ex. $100)', 'pods' ),
'after' => __( 'After (ex. 100$)', 'pods' ),
'before_space' => __( 'Before with space (ex. $ 100)', 'pods' ),
'after_space' => __( 'After with space (ex. 100 $)', 'pods' ),
'none' => __( 'None (ex. 100)', 'pods' ),
'beforeaftercode' => __( 'Before with Currency Code after (ex. $100 USD)', 'pods' ),
'beforeaftercode_space' => __( 'Before with space and with Currency Code after (ex. $ 100 USD)', 'pods' ),
),
'pick_show_select_text' => 0,
),
static::$type . '_format' => array(
'label' => __( 'Number Format', 'pods' ),
'default' => apply_filters( 'pods_form_ui_field_number_currency_format_default', 'i18n' ),
'type' => 'pick',
'data' => array(
'i18n' => __( 'Localized Default', 'pods' ),
'9,999.99' => '1,234.00',
'9999.99' => '1234.00',
'9.999,99' => '1.234,00',
'9999,99' => '1234,00',
'9 999,99' => '1 234,00',
'9\'999.99' => '1\'234.00',
),
'pick_show_select_text' => 0,
),
static::$type . '_decimals' => array(
'label' => __( 'Decimals', 'pods' ),
'default' => 2,
'type' => 'number',
'help' => __( 'Set to a positive number to enable decimals. The upper limit in the database for this field is 30 decimals.', 'pods' ),
),
static::$type . '_decimal_handling' => array(
'label' => __( 'Decimal handling when zero', 'pods' ),
'default' => 'none',
'type' => 'pick',
'data' => array(
'none' => __( 'Default', 'pods' ),
'remove' => __( 'Remove decimals', 'pods' ),
'dash' => __( 'Convert to dash', 'pods' ) . ' (-)',
),
'pick_show_select_text' => 0,
),
static::$type . '_step' => array(
'label' => __( 'Slider Increment (Step)', 'pods' ),
'depends-on' => array( static::$type . '_format_type' => 'slider' ),
'default' => 1,
'type' => 'text',
),
static::$type . '_min' => array(
'label' => __( 'Minimum Number', 'pods' ),
'depends-on-any' => array(
static::$type . '_format_type' => 'slider',
static::$type . '_html5' => true,
),
'default' => 0,
'type' => 'text',
),
static::$type . '_max' => array(
'label' => __( 'Maximum Number', 'pods' ),
'depends-on-any' => array(
static::$type . '_format_type' => 'slider',
static::$type . '_html5' => true,
),
'default' => 1000,
'type' => 'text',
),
static::$type . '_max_length' => array(
'label' => __( 'Maximum Digits', 'pods' ),
'default' => 12,
'type' => 'number',
'help' => __( 'Set to -1 for no limit. The upper limit in the database for this field is 64 digits.', 'pods' ),
),
static::$type . '_html5' => array(
'label' => __( 'Enable HTML5 Input Field', 'pods' ),
'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
'type' => 'boolean',
),
static::$type . '_placeholder' => array(
'label' => __( 'HTML Placeholder', 'pods' ),
'default' => '',
'type' => 'text',
'help' => array(
__( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
),
),
);
return $options;
}
/**
* {@inheritdoc}
*/
public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
$value = $this->format( $value, $name, $options, $pod, $id );
$currency = 'usd';
if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, - 1 ) ] ) ) {
$currency = pods_v( static::$type . '_format_sign', $options );
}
$currency_sign = static::$currencies[ $currency ]['sign'];
$currency_label = static::$currencies[ $currency ]['label'];
$placement = pods_v( static::$type . '_format_placement', $options, 'before', true );
// Currency placement policy.
// Single sign currencies: 100$, £100
// Multiple sign currencies: 100 Fr, Kr 100
$currency_gap = '';
if ( mb_strlen( $currency_sign ) > 1 && false === strpos( $currency_sign, '&' ) ) {
$currency_gap = ' ';
} elseif ( in_array( $placement, array( 'before_space', 'after_space', 'beforeaftercode_space' ), true ) ) {
$currency_gap = ' ';
}
switch ( $placement ) {
case 'before':
case 'before_space':
$value = $currency_sign . $currency_gap . $value;
break;
case 'after':
case 'after_space':
$value .= $currency_gap . $currency_sign;
break;
case 'beforeaftercode':
case 'beforeaftercode_space':
$value = $currency_sign . $currency_gap . $value . ' ' . $currency_label;
break;
}
return $value;
}
/**
* {@inheritdoc}
*/
public function regex( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
$format_args = $this->get_number_format_args( $options );
$thousands = $format_args['thousands'];
$dot = $format_args['dot'];
$currency = 'usd';
if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, - 1 ) ] ) ) {
$currency = pods_v( static::$type . '_format_sign', $options );
}
$currency_sign = static::$currencies[ $currency ]['sign'];
return '\-*\\' . $currency_sign . '*[0-9\\' . implode( '\\', array_filter( array( $dot, $thousands ) ) ) . ']+';
}
/**
* {@inheritdoc}
*/
public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
$currency = 'usd';
if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, - 1 ) ] ) ) {
$currency = pods_v( static::$type . '_format_sign', $options );
}
$currency_sign = static::$currencies[ $currency ]['sign'];
$currency_entity = static::$currencies[ $currency ]['entity'];
// Remove currency and thousands symbols.
$value = str_replace(
array(
$currency_sign,
$currency_entity,
html_entity_decode( $currency_sign ),
html_entity_decode( $currency_entity ),
),
'',
$value
);
return parent::validate( $value, $name, $options, $fields, $pod, $id, $params );
}
/**
* {@inheritdoc}
*/
public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
$currency = 'usd';
if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, - 1 ) ] ) ) {
$currency = pods_v( static::$type . '_format_sign', $options );
}
$currency_sign = static::$currencies[ $currency ]['sign'];
$currency_entity = static::$currencies[ $currency ]['entity'];
// Convert decimal type for numeric type.
$value = str_replace(
array(
$currency_sign,
$currency_entity,
html_entity_decode( $currency_sign ),
html_entity_decode( $currency_entity ),
),
'',
$value
);
// Remove trailing dash only from the end of the string.
$value = rtrim( $value, '-' );
return parent::pre_save( $value, $id, $name, $options, $fields, $pod, $params );
}
/**
* {@inheritdoc}
*/
public function format( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
$value = parent::format( $value, $name, $options, $pod, $id );
if ( null === $value ) {
return $value;
}
// Additional output handling for decimals
$decimal_handling = pods_v( static::$type . '_decimal_handling', $options, 'none' );
if ( 'none' !== $decimal_handling ) {
$format_args = $this->get_number_format_args( $options );
$dot = $format_args['dot'];
$value_parts = explode( $dot, $value );
// Make sure decimals are empty.
if ( isset( $value_parts[1] ) && ! (int) $value_parts[1] ) {
if ( 'remove' === $decimal_handling ) {
array_pop( $value_parts );
} elseif ( 'dash' === $decimal_handling ) {
array_pop( $value_parts );
$value_parts[] = '-';
}
$value = implode( $dot, $value_parts );
}
}
return $value;
}
/**
* Get the currencies and place them in the local property
*
* @since 2.6.8
* @return array
*/
public static function data_currencies() {
// If it's already done, do not redo the filter.
if ( ! empty( static::$currencies ) ) {
return static::$currencies;
}
$default_currencies = array(
'aud' => array(
'label' => 'AUD',
'name' => __( 'Australian Dollar', 'pods' ),
'sign' => '$',
'entity' => '$',
),
'brl' => array(
'label' => 'BRL',
'name' => __( 'Brazilian Real', 'pods' ),
'sign' => 'R$',
'entity' => 'R$',
),
'gbp' => array(
'label' => 'GBP',
'name' => __( 'British Pound', 'pods' ),
'sign' => '£',
'entity' => '£',
),
'cad' => array(
'label' => 'CAD',
'name' => __( 'Canadian Dollar', 'pods' ),
'sign' => '$',
'entity' => '$',
),
'cny' => array(
'label' => 'CNY',
'name' => __( 'Chinese Yen (¥)', 'pods' ),
'sign' => '¥',
'entity' => '¥',
),
'cny2' => array(
'label' => 'CNY',
'name' => __( 'Chinese Yuan (元)', 'pods' ),
'sign' => '元',
'entity' => '元',
),
'czk' => array(
'label' => 'CZK',
'name' => __( 'Czech Koruna', 'pods' ),
'sign' => 'Kč',
'entity' => 'Kč',
),
'dkk' => array(
'label' => 'DKK',
'name' => __( 'Danish Krone', 'pods' ),
'sign' => 'kr.',
'entity' => 'kr.',
),
'euro' => array(
'label' => 'EUR',
'name' => __( 'Euro', 'pods' ),
'sign' => '€',
'entity' => '€',
),
'hkd' => array(
'label' => 'HKD',
'name' => __( 'Hong Kong Dollar', 'pods' ),
'sign' => '$',
'entity' => '$',
),
'huf' => array(
'label' => 'HUF',
'name' => __( 'Hungarian Forint', 'pods' ),
'sign' => 'Ft',
'entity' => 'Ft',
),
'inr' => array(
'label' => 'INR',
'name' => __( 'Indian Rupee', 'pods' ),
'sign' => '₹',
'entity' => '₹',
),
'idr' => array(
'label' => 'IDR',
'name' => __( 'Indonesian Rupiah', 'pods' ),
'sign' => 'Rp',
'entity' => 'Rp',
),
'ils' => array(
'label' => 'ILS',
'name' => __( 'Israeli New Sheqel', 'pods' ),
'sign' => '₪',
'entity' => '₪',
),
'jpy' => array(
'label' => 'JPY',
'name' => __( 'Japanese Yen', 'pods' ),
'sign' => '¥',
'entity' => '¥',
),
'krw' => array(
'label' => 'KRW',
'name' => __( 'Korean Won', 'pods' ),
'sign' => '₩',
'entity' => '₩',
),
'myr' => array(
'label' => 'MYR',
'name' => __( 'Malaysian Ringgit', 'pods' ),
'sign' => 'RM',
'entity' => 'RM',
),
'mxn' => array(
'label' => 'MXN',
'name' => __( 'Mexican Peso', 'pods' ),
'sign' => '$',
'entity' => '$',
),
'ngn' => array(
'label' => 'NGN',
'name' => __( 'Nigerian Naira', 'pods' ),
'sign' => '₦',
'entity' => '₦',
),
'nzd' => array(
'label' => 'NZD',
'name' => __( 'New Zealand Dollar', 'pods' ),
'sign' => '$',
'entity' => '$',
),
'nok' => array(
'label' => 'NOK',
'name' => __( 'Norwegian Krone', 'pods' ),
'sign' => 'kr',
'entity' => 'kr',
),
'php' => array(
'label' => 'PHP',
'name' => __( 'Philippine Peso', 'pods' ),
'sign' => '₱',
'entity' => '₱',
),
'pln' => array(
'label' => 'PLN',
'name' => __( 'Polish Złoty', 'pods' ),
'sign' => 'zł',
'entity' => 'zł',
),
'rub' => array(
'label' => 'RUB',
'name' => __( 'Russian Ruble', 'pods' ),
'sign' => '₽',
'entity' => '₽',
),
'sek' => array(
'label' => 'SEK',
'name' => __( 'Swedish Krona', 'pods' ),
'sign' => 'kr',
'entity' => 'kr',
),
'sgd' => array(
'label' => 'SGD',
'name' => __( 'Singapore Dollar', 'pods' ),
'sign' => '$',
'entity' => '$',
),
'zar' => array(
'label' => 'ZAR',
'name' => __( 'South African Rand', 'pods' ),
'sign' => 'R',
'entity' => 'R',
),
'chf' => array(
'label' => 'CHF',
'name' => __( 'Swiss Franc', 'pods' ),
'sign' => 'Fr',
'entity' => 'Fr',
),
'twd' => array(
'label' => 'TWD',
'name' => __( 'Taiwan New Dollar', 'pods' ),
'sign' => '$',
'entity' => '$',
),
'thb' => array(
'label' => 'THB',
'name' => __( 'Thai Baht', 'pods' ),
'sign' => '฿',
'entity' => '฿',
),
'trl' => array(
'label' => 'TRL',
'name' => __( 'Turkish Lira', 'pods' ),
'sign' => '₺',
'entity' => '₺',
),
'usd' => array(
'label' => 'USD',
'name' => __( 'US Dollar', 'pods' ),
'sign' => '$',
'entity' => '$',
),
'usdcent' => array(
'label' => 'USDCENT',
'name' => __( 'US Dollar Cent', 'pods' ),
'sign' => '¢',
'entity' => '¢',
),
'vnd' => array(
'label' => 'VND',
'name' => __( 'Vietnamese Dong', 'pods' ),
'sign' => '₫',
'entity' => '₫',
),
);
/**
* Add custom currencies
*
* @param array $options {
* Required array of arrays.
*
* @type array {
* @type string $label The label (example: USD).
* @type string $name The full name (example: US Dollar).
* @type string $sign The sign (example: $).
* @type string $entity The HTML entity (example: $).
* }
* }
* @return array
*/
static::$currencies = apply_filters( 'pods_form_ui_field_currency_currencies', $default_currencies );
// Sort the currencies
ksort( static::$currencies );
// Backwards compatibility
foreach ( static::$currencies as $key => $value ) {
if ( is_string( $value ) ) {
static::$currencies[ $key ] = array(
'label' => strtoupper( $key ),
'name' => strtoupper( $key ),
'sign' => $value,
'entity' => $value,
);
} elseif ( is_array( $value ) ) {
// Make sure all required values are set
if ( empty( $value['label'] ) ) {
$value['label'] = $key;
}
if ( empty( $value['name'] ) ) {
$value['name'] = $key;
}
if ( empty( $value['sign'] ) ) {
$value['sign'] = $key;
}
if ( empty( $value['entity'] ) ) {
$value['entity'] = $key;
}
} else {
// Invalid
unset( static::$currencies[ $key ] );
}//end if
}//end foreach
return static::$currencies;
}
/**
* Get the max allowed decimals.
* Overwrites the default value of Number field. 2 decimals instead of 0.
*
* @since 2.7.0
*
* @param array $options Field options.
*
* @return int
*/
public function get_max_decimals( $options ) {
$length = (int) pods_v( static::$type . '_max_length', $options, 12, true );
if ( $length < 1 || 64 < $length ) {
$length = 64;
}
$decimals = (int) pods_v( static::$type . '_decimals', $options, 2 );
if ( $decimals < 1 ) {
$decimals = 0;
} elseif ( 30 < $decimals ) {
$decimals = 30;
}
if ( $length < $decimals ) {
$decimals = $length;
}
return $decimals;
}
}