| @@ -9,28 +9,14 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | class FrmCurrencyHelper { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Gets the currency data from the currency code. | |
| 14 | - * | |
| 15 | - * @since 6.30 The first parameter is optional. | |
| 16 | - * | |
| 17 | - * @param string|null $currency Currency code. Default is `null`, which use the currency in the global settings. | |
| 18 | - * | |
| 13 | + * @param string $currency | |
| 19 | 14 | * @return array |
| 20 | 15 | */ |
| 21 | - public static function get_currency( $currency = null ) { | |
| 22 | - if ( ! $currency ) { | |
| 23 | - $currency = trim( FrmAppHelper::get_settings()->currency ); | |
| 24 | - } | |
| 25 | - | |
| 26 | - if ( ! $currency ) { | |
| 27 | - $currency = 'USD'; | |
| 28 | - } | |
| 29 | - | |
| 16 | + public static function get_currency( $currency ) { | |
| 30 | 17 | $currency = strtoupper( $currency ); |
| 31 | 18 | $currencies = self::get_currencies(); |
| 32 | - | |
| 33 | 19 | if ( isset( $currencies[ $currency ] ) ) { |
| 34 | 20 | $currency = $currencies[ $currency ]; |
| 35 | 21 | } elseif ( isset( $currencies[ strtolower( $currency ) ] ) ) { |
| 36 | 22 | $currency = $currencies[ strtolower( $currency ) ]; |
| @@ -36,127 +22,12 @@ | ||
| 36 | 22 | $currency = $currencies[ strtolower( $currency ) ]; |
| 37 | 23 | } else { |
| 38 | 24 | $currency = $currencies['USD']; |
| 39 | 25 | } |
| 40 | - | |
| 41 | 26 | return $currency; |
| 42 | 27 | } |
| 43 | 28 | |
| 44 | 29 | /** |
| 45 | - * Checks if the given format is a valid currency format. | |
| 46 | - * | |
| 47 | - * @since 6.18 | |
| 48 | - * | |
| 49 | - * @param string $format_value The format value to check. | |
| 50 | - * | |
| 51 | - * @return bool | |
| 52 | - */ | |
| 53 | - public static function is_currency_format( $format_value ) { | |
| 54 | - return in_array( $format_value, array( 'currency', 'number' ), true ); | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Adds the currency symbol to the given amount. | |
| 59 | - * | |
| 60 | - * @param float|string $amount | |
| 61 | - * @param array|null $currency | |
| 62 | - * | |
| 63 | - * @return string | |
| 64 | - */ | |
| 65 | - public static function format_price( $amount, $currency = null ) { | |
| 66 | - if ( ! $currency ) { | |
| 67 | - $currency = self::get_currency(); | |
| 68 | - } | |
| 69 | - | |
| 70 | - if ( is_string( $amount ) ) { | |
| 71 | - $amount = floatval( self::prepare_price( $amount, $currency ) ); | |
| 72 | - } | |
| 73 | - | |
| 74 | - $amount = number_format( $amount, $currency['decimals'], $currency['decimal_separator'], $currency['thousand_separator'] ); | |
| 75 | - | |
| 76 | - if ( '' !== $currency['symbol_left'] ) { | |
| 77 | - $amount = $currency['symbol_left'] . $currency['symbol_padding'] . $amount; | |
| 78 | - } | |
| 79 | - | |
| 80 | - if ( '' !== $currency['symbol_right'] ) { | |
| 81 | - $amount .= $currency['symbol_padding'] . $currency['symbol_right']; | |
| 82 | - } | |
| 83 | - | |
| 84 | - return $amount; | |
| 85 | - } | |
| 86 | - | |
| 87 | - /** | |
| 88 | - * @since 6.30 | |
| 89 | - * | |
| 90 | - * @param string $price | |
| 91 | - * @param array $currency | |
| 92 | - * | |
| 93 | - * @return float|string | |
| 94 | - */ | |
| 95 | - public static function prepare_price( $price, $currency ) { | |
| 96 | - $price = trim( $price ); | |
| 97 | - | |
| 98 | - if ( ! $price ) { | |
| 99 | - return 0; | |
| 100 | - } | |
| 101 | - | |
| 102 | - preg_match_all( '/[\-]*[0-9,.]*\.?\,?[0-9]+/', $price, $matches ); | |
| 103 | - $price = $matches ? end( $matches[0] ) : 0; | |
| 104 | - | |
| 105 | - if ( ! $price ) { | |
| 106 | - return 0; | |
| 107 | - } | |
| 108 | - | |
| 109 | - $price = self::maybe_use_decimal( $price, $currency ); | |
| 110 | - return str_replace( $currency['decimal_separator'], '.', str_replace( $currency['thousand_separator'], '', $price ) ); | |
| 111 | - } | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * @since 6.30 | |
| 115 | - * | |
| 116 | - * @param string $amount | |
| 117 | - * @param array $currency | |
| 118 | - * | |
| 119 | - * @return string | |
| 120 | - */ | |
| 121 | - private static function maybe_use_decimal( $amount, $currency ) { | |
| 122 | - if ( $currency['thousand_separator'] !== '.' ) { | |
| 123 | - return $amount; | |
| 124 | - } | |
| 125 | - | |
| 126 | - $amount_parts = explode( '.', $amount ); | |
| 127 | - $used_for_decimal = count( $amount_parts ) === 2 && in_array( strlen( $amount_parts[1] ), array( 1, 2 ), true ); | |
| 128 | - | |
| 129 | - if ( $used_for_decimal ) { | |
| 130 | - return str_replace( '.', $currency['decimal_separator'], $amount ); | |
| 131 | - } | |
| 132 | - | |
| 133 | - return $amount; | |
| 134 | - } | |
| 135 | - | |
| 136 | - /** | |
| 137 | - * If the currency is needed for this form, add it to the global. | |
| 138 | - * This is later included in the footer. | |
| 139 | - * | |
| 140 | - * @since 6.30 | |
| 141 | - * | |
| 142 | - * @param int|string $form_id Form ID. This is used for Pro compatibility. | |
| 143 | - * | |
| 144 | - * @return void | |
| 145 | - */ | |
| 146 | - public static function add_currency_to_global( $form_id ) { | |
| 147 | - global $frm_vars; | |
| 148 | - | |
| 149 | - if ( ! isset( $frm_vars['currency'] ) ) { | |
| 150 | - $frm_vars['currency'] = array(); | |
| 151 | - } | |
| 152 | - | |
| 153 | - if ( ! isset( $frm_vars['currency'][ $form_id ] ) ) { | |
| 154 | - $frm_vars['currency'][ $form_id ] = self::get_currency(); | |
| 155 | - } | |
| 156 | - } | |
| 157 | - | |
| 158 | - /** | |
| 159 | 30 | * Get a list of all supported currencies. |
| 160 | 31 | * |
| 161 | 32 | * @since 6.5. |
| 162 | 33 | * |
| @@ -418,9 +289,9 @@ | ||
| 418 | 289 | ), |
| 419 | 290 | 'TRY' => array( |
| 420 | 291 | 'name' => __( 'Turkish Liras', 'formidable' ), |
| 421 | 292 | 'symbol_left' => '', |
| 422 | - 'symbol_right' => '₺', | |
| 293 | + 'symbol_right' => '€', | |
| 423 | 294 | 'symbol_padding' => ' ', |
| 424 | 295 | 'thousand_separator' => '.', |
| 425 | 296 | 'decimal_separator' => ',', |
| 426 | 297 | 'decimals' => 2, |