Issues (2873)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

classes/fields/currency.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
require_once PODS_DIR . 'classes/fields/number.php';
3
4
/**
5
 * @package Pods\Fields
6
 */
7
class PodsField_Currency extends PodsField_Number {
8
9
	/**
10
	 * {@inheritdoc}
11
	 */
12
	public static $group = 'Number';
13
14
	/**
15
	 * {@inheritdoc}
16
	 */
17
	public static $type = 'currency';
18
19
	/**
20
	 * {@inheritdoc}
21
	 */
22
	public static $label = 'Currency';
23
24
	/**
25
	 * {@inheritdoc}
26
	 */
27
	public static $prepare = '%d';
28
29
	/**
30
	 * Currency Formats
31
	 *
32
	 * @var array
33
	 * @since 2.0
34
	 */
35
	public static $currencies = array();
36
37
	/**
38
	 * {@inheritdoc}
39
	 */
40
	public function setup() {
41
42
		self::$label = __( 'Currency', 'pods' );
43
		static::data_currencies();
44
	}
45
46
	/**
47
	 * {@inheritdoc}
48
	 */
49
	public function options() {
50
51
		$currency_options = array();
52
		foreach ( static::$currencies as $key => $value ) {
53
			$currency = $value['label'];
54
			if ( $value['label'] !== $value['name'] ) {
55
				$currency .= ': ' . $value['name'];
56
			}
57
			$currency                .= ' (' . $value['sign'] . ')';
58
			$currency_options[ $key ] = $currency;
59
		}
60
61
		$options = array(
62
			static::$type . '_repeatable'       => array(
63
				'label'             => __( 'Repeatable Field', 'pods' ),
64
				'default'           => 0,
65
				'type'              => 'boolean',
66
				'help'              => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
67
				'boolean_yes_label' => '',
68
				'dependency'        => true,
69
				'developer_mode'    => true,
70
			),
71
			static::$type . '_format_type'      => array(
72
				'label'      => __( 'Input Type', 'pods' ),
73
				'default'    => 'number',
74
				'type'       => 'pick',
75
				'data'       => array(
76
					'number' => __( 'Freeform Number', 'pods' ),
77
					'slider' => __( 'Slider', 'pods' ),
78
				),
79
				'dependency' => true,
80
			),
81
			static::$type . '_format_sign'      => array(
82
				'label'   => __( 'Currency Sign', 'pods' ),
83
				'default' => apply_filters( 'pods_form_ui_field_number_currency_default', 'usd' ),
84
				'type'    => 'pick',
85
				'data'    => apply_filters( 'pods_form_ui_field_number_currency_options', $currency_options ),
86
			),
87
			static::$type . '_format_placement' => array(
88
				'label'   => __( 'Currency Placement', 'pods' ),
89
				'default' => apply_filters( 'pods_form_ui_field_number_currency_placement_default', 'before' ),
90
				'type'    => 'pick',
91
				'data'    => array(
92
					'before'                => __( 'Before (ex. $100)', 'pods' ),
93
					'after'                 => __( 'After (ex. 100$)', 'pods' ),
94
					'before_space'          => __( 'Before with space (ex. $ 100)', 'pods' ),
95
					'after_space'           => __( 'After with space (ex. 100 $)', 'pods' ),
96
					'none'                  => __( 'None (ex. 100)', 'pods' ),
97
					'beforeaftercode'       => __( 'Before with Currency Code after (ex. $100 USD)', 'pods' ),
98
					'beforeaftercode_space' => __( 'Before width space and with Currency Code after (ex. $ 100 USD)', 'pods' ),
99
				),
100
			),
101
			static::$type . '_format'           => array(
102
				'label'   => __( 'Format', 'pods' ),
103
				'default' => apply_filters( 'pods_form_ui_field_number_currency_format_default', 'i18n' ),
104
				'type'    => 'pick',
105
				'data'    => array(
106
					'i18n'      => __( 'Localized Default', 'pods' ),
107
					'9,999.99'  => '1,234.00',
108
					'9\'999.99' => '1\'234.00',
109
					'9.999,99'  => '1.234,00',
110
					'9 999,99'  => '1 234,00',
111
					'9999.99'   => '1234.00',
112
					'9999,99'   => '1234,00',
113
				),
114
			),
115
			static::$type . '_decimals'         => array(
116
				'label'   => __( 'Decimals', 'pods' ),
117
				'default' => 2,
118
				'type'    => 'number',
119
			),
120
			static::$type . '_decimal_handling' => array(
121
				'label'   => __( 'Decimal handling when zero', 'pods' ),
122
				'default' => 'none',
123
				'type'    => 'pick',
124
				'data'    => array(
125
					'none'   => __( 'Default', 'pods' ),
126
					'remove' => __( 'Remove decimals', 'pods' ),
127
					'dash'   => __( 'Convert to dash', 'pods' ) . ' (-)',
128
				),
129
			),
130
			static::$type . '_step'             => array(
131
				'label'      => __( 'Slider Increment (Step)', 'pods' ),
132
				'depends-on' => array( static::$type . '_format_type' => 'slider' ),
133
				'default'    => 1,
134
				'type'       => 'text',
135
			),
136
			static::$type . '_min'              => array(
137
				'label'      => __( 'Minimum Number', 'pods' ),
138
				'depends-on' => array( static::$type . '_format_type' => 'slider' ),
139
				'default'    => 0,
140
				'type'       => 'text',
141
			),
142
			static::$type . '_max'              => array(
143
				'label'      => __( 'Maximum Number', 'pods' ),
144
				'depends-on' => array( static::$type . '_format_type' => 'slider' ),
145
				'default'    => 1000,
146
				'type'       => 'text',
147
			),
148
			static::$type . '_max_length'       => array(
149
				'label'   => __( 'Maximum Length', 'pods' ),
150
				'default' => 12,
151
				'type'    => 'number',
152
				'help'    => __( 'Set to -1 for no limit', 'pods' ),
153
			),
154
			static::$type . '_placeholder'      => array(
155
				'label'   => __( 'HTML Placeholder', 'pods' ),
156
				'default' => '',
157
				'type'    => 'text',
158
				'help'    => array(
159
					__( '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' ),
160
					'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
161
				),
162
			),
163
		);
164
165
		return $options;
166
167
	}
168
169
	/**
170
	 * {@inheritdoc}
171
	 */
172
	public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
173
174
		$value = $this->format( $value, $name, $options, $pod, $id );
175
176
		$currency = 'usd';
177
178
		if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, - 1 ) ] ) ) {
179
			$currency = pods_v( static::$type . '_format_sign', $options );
180
		}
181
182
		$currency_sign  = static::$currencies[ $currency ]['sign'];
183
		$currency_label = static::$currencies[ $currency ]['label'];
184
185
		$placement = pods_v( static::$type . '_format_placement', $options, 'before', true );
186
187
		// Currency placement policy
188
		// Single sign currencies: 100$, £100
189
		// Multiple sign currencies: 100 Fr, Kr 100
190
		$currency_gap = '';
191
192
		if ( mb_strlen( $currency_sign ) > 1 && false === strpos( $currency_sign, '&' ) ) {
193
			$currency_gap = ' ';
194
		} elseif ( in_array( $placement, array( 'before_space', 'after_space', 'beforeaftercode_space' ), true ) ) {
195
			$currency_gap = ' ';
196
		}
197
198
		switch ( $placement ) {
199
			case 'before':
200
			case 'before_space':
201
				$value = $currency_sign . $currency_gap . $value;
202
				break;
203
			case 'after':
204
			case 'after_space':
205
				$value .= $currency_gap . $currency_sign;
206
				break;
207
			case 'beforeaftercode':
208
			case 'beforeaftercode_space':
209
				$value = $currency_sign . $currency_gap . $value . ' ' . $currency_label;
210
				break;
211
		}
212
213
		return $value;
214
215
	}
216
217
	/**
218
	 * {@inheritdoc}
219
	 */
220
	public function regex( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
221
222
		$format_args = $this->get_number_format_args( $options );
223
		$thousands   = $format_args['thousands'];
224
		$dot         = $format_args['dot'];
225
226
		$currency = 'usd';
227
228
		if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, - 1 ) ] ) ) {
229
			$currency = pods_v( static::$type . '_format_sign', $options );
230
		}
231
232
		$currency_sign = static::$currencies[ $currency ]['sign'];
233
234
		return '\-*\\' . $currency_sign . '*[0-9\\' . implode( '\\', array_filter( array( $dot, $thousands ) ) ) . ']+';
235
236
	}
237
238
	/**
239
	 * {@inheritdoc}
240
	 */
241
	public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
242
243
		$format_args = $this->get_number_format_args( $options );
244
		$thousands   = $format_args['thousands'];
245
		$dot         = $format_args['dot'];
246
247
		$currency = 'usd';
248
249
		if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, - 1 ) ] ) ) {
250
			$currency = pods_v( static::$type . '_format_sign', $options );
251
		}
252
253
		$currency_sign   = static::$currencies[ $currency ]['sign'];
254
		$currency_entity = static::$currencies[ $currency ]['entity'];
255
256
		// Remove currency and thousands symbols
257
		$check = str_replace(
258
			array(
259
				$thousands,
260
				$currency_sign,
261
				$currency_entity,
262
				html_entity_decode( $thousands ),
263
				html_entity_decode( $currency_sign ),
264
				html_entity_decode( $currency_entity ),
265
			), '', $value
266
		);
267
		// Convert decimal type for numeric type
268
		$check = str_replace( $dot, '.', $check );
269
		$check = trim( $check );
270
271
		$check = preg_replace( '/[0-9\.\-\s]/', '', $check );
272
273
		$label = pods_v( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
274
275
		if ( 0 < strlen( $check ) ) {
276
			return sprintf( __( '%s is not numeric', 'pods' ), $label );
277
		}
278
279
		return true;
280
281
	}
282
283
	/**
284
	 * {@inheritdoc}
285
	 */
286
	public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
287
288
		$format_args = $this->get_number_format_args( $options );
289
		$thousands   = $format_args['thousands'];
290
		$dot         = $format_args['dot'];
291
		$decimals    = $format_args['decimals'];
292
293
		$currency = 'usd';
294
295
		if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, - 1 ) ] ) ) {
296
			$currency = pods_v( static::$type . '_format_sign', $options );
297
		}
298
299
		$currency_sign   = static::$currencies[ $currency ]['sign'];
300
		$currency_entity = static::$currencies[ $currency ]['entity'];
301
302
		// Convert decimal type for numeric type
303
		$value = str_replace(
304
			array(
305
				$thousands,
306
				$currency_sign,
307
				$currency_entity,
308
				html_entity_decode( $thousands ),
309
				html_entity_decode( $currency_sign ),
310
				html_entity_decode( $currency_entity ),
311
			), '', $value
312
		);
313
		// Convert decimal type for numeric type
314
		$value = str_replace( $dot, '.', $value );
315
		$value = trim( $value );
316
317
		$value = preg_replace( '/[^0-9\.\-]/', '', $value );
318
319
		$value = number_format( (float) $value, $decimals, '.', '' );
320
321
		return $value;
322
323
	}
324
325
	/**
326
	 * {@inheritdoc}
327
	 */
328
	public function format( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
329
330
		if ( null === $value ) {
331
			// Don't enforce a default value here
332
			return null;
333
		}
334
335
		$format_args = $this->get_number_format_args( $options );
336
		$thousands   = $format_args['thousands'];
337
		$dot         = $format_args['dot'];
338
		$decimals    = $format_args['decimals'];
339
340
		if ( 'i18n' === pods_v( static::$type . '_format', $options ) ) {
341
			$value = number_format_i18n( (float) $value, $decimals );
342
		} else {
343
			$value = number_format( (float) $value, $decimals, $dot, $thousands );
344
		}
345
346
		// Additional output handling for decimals
347
		$decimal_handling = pods_v( static::$type . '_decimal_handling', $options, 'none' );
348
		if ( 'none' !== $decimal_handling ) {
349
			$value_parts = explode( $dot, $value );
350
			// Make sure decimals are empty.
351
			if ( isset( $value_parts[1] ) && ! (int) $value_parts[1] ) {
352
				if ( 'remove' === $decimal_handling ) {
353
					array_pop( $value_parts );
354
				} elseif ( 'dash' === $decimal_handling ) {
355
					array_pop( $value_parts );
356
					$value_parts[] = '-';
357
				}
358
				$value = implode( $dot, $value_parts );
359
			}
360
		}
361
362
		return $value;
363
364
	}
365
366
	/**
367
	 * Get the currencies and place them in the local property
368
	 *
369
	 * @since  2.6.8
370
	 * @return array
371
	 */
372
	public static function data_currencies() {
373
374
		// If it's already done, do not redo the filter
375
		if ( ! empty( static::$currencies ) ) {
376
			return static::$currencies;
377
		}
378
379
		$default_currencies = array(
380
			'aud'  => array(
381
				'label'  => 'AUD',
382
				'name'   => __( 'Australian Dollar', 'pods' ),
383
				'sign'   => '$',
384
				'entity' => '&#36;',
385
			),
386
			'brl'  => array(
387
				'label'  => 'BRL',
388
				'name'   => __( 'Brazilian Real', 'pods' ),
389
				'sign'   => 'R$',
390
				'entity' => 'R&#36;',
391
			),
392
			'cad'  => array(
393
				'label'  => 'CAD',
394
				'name'   => __( 'Canadian Dollar', 'pods' ),
395
				'sign'   => '$',
396
				'entity' => '&#36;',
397
			),
398
			'chf'  => array(
399
				'label'  => 'CHF',
400
				'name'   => __( 'Swiss Franc', 'pods' ),
401
				'sign'   => 'Fr',
402
				'entity' => 'Fr',
403
			),
404
			'cny'  => array(
405
				'label'  => 'CNY',
406
				'name'   => __( 'Chinese Yuan', 'pods' ),
407
				'sign'   => '¥',
408
				'entity' => '&yen;',
409
			),
410
			'cny2' => array(
411
				'label'  => 'CNY',
412
				'name'   => __( 'Chinese Yuan', 'pods' ),
413
				'sign'   => '元',
414
				'entity' => '&#20803;',
415
			),
416
			'czk'  => array(
417
				'label'  => 'CZK',
418
				'name'   => __( 'Czech Koruna', 'pods' ),
419
				'sign'   => 'Kč',
420
				'entity' => 'K&#x10D;',
421
			),
422
			'dkk'  => array(
423
				'label'  => 'DKK',
424
				'name'   => __( 'Danish Krone', 'pods' ),
425
				'sign'   => 'kr.',
426
				'entity' => 'kr.',
427
			),
428
			'euro' => array(
429
				'label'  => 'EUR',
430
				'name'   => __( 'Euro', 'pods' ),
431
				'sign'   => '€',
432
				'entity' => '&euro;',
433
			),
434
			'gbp'  => array(
435
				'label'  => 'GBP',
436
				'name'   => __( 'British Pound', 'pods' ),
437
				'sign'   => '£',
438
				'entity' => '&pound;',
439
			),
440
			'hkd'  => array(
441
				'label'  => 'HKD',
442
				'name'   => __( 'Hong Kong Dollar', 'pods' ),
443
				'sign'   => '$',
444
				'entity' => '&#36;',
445
			),
446
			'huf'  => array(
447
				'label'  => 'HUF',
448
				'name'   => __( 'Hungarian Forint', 'pods' ),
449
				'sign'   => 'Ft',
450
				'entity' => 'Ft',
451
			),
452
			'ils'  => array(
453
				'label'  => 'ILS',
454
				'name'   => __( 'Israeli New Sheqel', 'pods' ),
455
				'sign'   => '₪',
456
				'entity' => '&#x20AA;',
457
			),
458
			'jpy'  => array(
459
				'label'  => 'JPY',
460
				'name'   => __( 'Japanese Yen', 'pods' ),
461
				'sign'   => '¥',
462
				'entity' => '&yen;',
463
			),
464
			'krw'  => array(
465
				'label'  => 'KRW',
466
				'name'   => __( 'Korean Won', 'pods' ),
467
				'sign'   => '₩',
468
				'entity' => '&#8361;',
469
			),
470
			'myr'  => array(
471
				'label'  => 'MYR',
472
				'name'   => __( 'Malaysian Ringgit', 'pods' ),
473
				'sign'   => 'MR',
474
				'entity' => 'MR',
475
			),
476
			'mxn'  => array(
477
				'label'  => 'MXN',
478
				'name'   => __( 'Mexican Peso', 'pods' ),
479
				'sign'   => '$',
480
				'entity' => '&#36;',
481
			),
482
			'nok'  => array(
483
				'label'  => 'NOK',
484
				'name'   => __( 'Norwegian Krone', 'pods' ),
485
				'sign'   => 'kr',
486
				'entity' => 'kr',
487
			),
488
			'nzd'  => array(
489
				'label'  => 'NZD',
490
				'name'   => __( 'New Zealand Dollar', 'pods' ),
491
				'sign'   => '$',
492
				'entity' => '&#36;',
493
			),
494
			'php'  => array(
495
				'label'  => 'PHP',
496
				'name'   => __( 'Philippine Peso', 'pods' ),
497
				'sign'   => '₱',
498
				'entity' => '&#x20B1;',
499
			),
500
			'pln'  => array(
501
				'label'  => 'PLN',
502
				'name'   => __( 'Polish Złoty', 'pods' ),
503
				'sign'   => 'zł',
504
				'entity' => 'z&#x142;',
505
			),
506
			'rub'  => array(
507
				'label'  => 'RUB',
508
				'name'   => __( 'Russian Ruble', 'pods' ),
509
				'sign'   => '₽',
510
				'entity' => '&#8381;',
511
			),
512
			'sek'  => array(
513
				'label'  => 'SEK',
514
				'name'   => __( 'Swedish Krona', 'pods' ),
515
				'sign'   => 'kr',
516
				'entity' => 'kr',
517
			),
518
			'sgd'  => array(
519
				'label'  => 'SGD',
520
				'name'   => __( 'Singapore Dollar', 'pods' ),
521
				'sign'   => '$',
522
				'entity' => '&#36;',
523
			),
524
			'thb'  => array(
525
				'label'  => 'THB',
526
				'name'   => __( 'Thai Baht', 'pods' ),
527
				'sign'   => '฿',
528
				'entity' => '&#x0E3F;',
529
			),
530
			'trl'  => array(
531
				'label'  => 'TRL',
532
				'name'   => __( 'Turkish Lira', 'pods' ),
533
				'sign'   => '₺',
534
				'entity' => '&#8378;',
535
			),
536
			'twd'  => array(
537
				'label'  => 'TWD',
538
				'name'   => __( 'Taiwan New Dollar', 'pods' ),
539
				'sign'   => '$',
540
				'entity' => '&#36;',
541
			),
542
			'usd'  => array(
543
				'label'  => 'USD',
544
				'name'   => __( 'US Dollar', 'pods' ),
545
				'sign'   => '$',
546
				'entity' => '&#36;',
547
			),
548
			'vnd'  => array(
549
				'label'  => 'VND',
550
				'name'   => __( 'Vietnamese Dong', 'pods' ),
551
				'sign'   => '₫',
552
				'entity' => '&#8363;',
553
			),
554
			'zar'  => array(
555
				'label'  => 'ZAR',
556
				'name'   => __( 'South African Rand', 'pods' ),
557
				'sign'   => 'R',
558
				'entity' => 'R',
559
			),
560
			'inr'  => array(
561
				'label'  => 'INR',
562
				'name'   => __( 'Indian Rupee', 'pods' ),
563
				'sign'   => '₹',
564
				'entity' => '&#x20B9;',
565
			),
566
		);
567
568
		/**
569
		 * Add custom currencies
570
		 *
571
		 * @param  array $options {
572
		 *                        Required array of arrays.
573
		 *
574
		 * @type  array {
575
		 * @type  string $label   The label (example: USD).
576
		 * @type  string $name    The full name (example: US Dollar).
577
		 * @type  string $sign    The sign (example: $).
578
		 * @type  string $entity  The HTML entity (example: &#36;).
579
		 *     }
580
		 * }
581
		 * @return array
582
		 */
583
		static::$currencies = apply_filters( 'pods_form_ui_field_currency_currencies', $default_currencies );
584
585
		// Sort the currencies
586
		ksort( static::$currencies );
587
588
		// Backwards compatibility
589
		foreach ( static::$currencies as $key => $value ) {
590
			if ( is_string( $value ) ) {
591
				static::$currencies[ $key ] = array(
592
					'label'  => strtoupper( $key ),
593
					'name'   => strtoupper( $key ),
594
					'sign'   => $value,
595
					'entity' => $value,
596
				);
597
			} elseif ( is_array( $value ) ) {
598
				// Make sure all required values are set
599
				if ( empty( $value['label'] ) ) {
600
					$value['label'] = $key;
601
				}
602
				if ( empty( $value['name'] ) ) {
603
					$value['name'] = $key;
604
				}
605
				if ( empty( $value['sign'] ) ) {
606
					$value['sign'] = $key;
607
				}
608
				if ( empty( $value['entity'] ) ) {
609
					$value['entity'] = $key;
610
				}
611
			} else {
612
				// Invalid
613
				unset( static::$currencies[ $key ] );
614
			}//end if
615
		}//end foreach
616
617
		return static::$currencies;
618
	}
619
620
	/**
621
	 * Get the max allowed decimals.
622
	 * Overwrites the default value of Number field. 2 decimals instead of 0.
623
	 *
624
	 * @since 2.7
625
	 *
626
	 * @param array $options Field options.
627
	 *
628
	 * @return int
629
	 */
630
	public function get_max_decimals( $options ) {
631
632
		$length = (int) pods_v( static::$type . '_max_length', $options, 12, true );
633
634
		if ( $length < 1 || 64 < $length ) {
635
			$length = 64;
636
		}
637
638
		$decimals = (int) pods_v( static::$type . '_decimals', $options, 2 );
639
640
		if ( $decimals < 1 ) {
641
			$decimals = 0;
642
		} elseif ( 30 < $decimals ) {
643
			$decimals = 30;
644
		}
645
646
		if ( $length < $decimals ) {
647
			$decimals = $length;
648
		}
649
650
		return $decimals;
651
	}
652
}
653