Completed
Push — master ( f39a7a...20a4a2 )
by Stephanie
02:28
created

FrmAppHelper::fill_field_defaults()   C

Complexity

Conditions 11
Paths 32

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
nc 32
nop 4
dl 0
loc 51
rs 6.9224
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
	die( 'You are not allowed to call this page directly.' );
4
}
5
6
class FrmAppHelper {
7
	public static $db_version = 97; //version of the database we are moving to
8
	public static $pro_db_version = 37; //deprecated
9
	public static $font_version = 7;
10
11
	/**
12
	 * @since 2.0
13
	 */
14
	public static $plug_version = '4.03.05';
15
16
	/**
17
	 * @since 1.07.02
18
	 *
19
	 * @param none
20
	 *
21
	 * @return string The version of this plugin
22
	 */
23
	public static function plugin_version() {
24
		return self::$plug_version;
25
	}
26
27
	public static function plugin_folder() {
28
		return basename( self::plugin_path() );
29
	}
30
31
	public static function plugin_path() {
32
		return dirname( dirname( dirname( __FILE__ ) ) );
33
	}
34
35
	public static function plugin_url() {
36
		// Prevously FRM_URL constant.
37
		return plugins_url( '', self::plugin_path() . '/formidable.php' );
38
	}
39
40
	public static function relative_plugin_url() {
41
		return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
42
	}
43
44
	/**
45
	 * @return string Site URL
46
	 */
47
	public static function site_url() {
48
		return site_url();
49
	}
50
51
	/**
52
	 * Get the name of this site
53
	 * Used for [sitename] shortcode
54
	 *
55
	 * @since 2.0
56
	 * @return string
57
	 */
58
	public static function site_name() {
59
		return get_option( 'blogname' );
60
	}
61
62
	public static function make_affiliate_url( $url ) {
63
		$affiliate_id = self::get_affiliate();
64
		if ( ! empty( $affiliate_id ) ) {
65
			$url = str_replace( array( 'http://', 'https://' ), '', $url );
66
			$url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
67
		}
68
69
		return $url;
70
	}
71
72
	public static function get_affiliate() {
73
		return absint( apply_filters( 'frm_affiliate_id', 0 ) );
74
	}
75
76
	/**
77
	 * @since 3.04.02
78
	 * @param array|string $args
79
	 * @param string       $page
80
	 */
81
	public static function admin_upgrade_link( $args, $page = '' ) {
82
		if ( empty( $page ) ) {
83
			$page = 'https://formidableforms.com/lite-upgrade/';
84
		} else {
85
			$page = 'https://formidableforms.com/' . $page;
86
		}
87
88
		$anchor = '';
89
		if ( is_array( $args ) ) {
90
			$medium  = $args['medium'];
91
			$content = $args['content'];
92
			if ( isset( $args['anchor'] ) ) {
93
				$anchor = '#' . $args['anchor'];
94
			}
95
		} else {
96
			$medium = $args;
97
		}
98
99
		$query_args = array(
100
			'utm_source'   => 'WordPress',
101
			'utm_medium'   => $medium,
102
			'utm_campaign' => 'liteplugin',
103
		);
104
105
		if ( isset( $content ) ) {
106
			$query_args['utm_content'] = $content;
107
		}
108
109
		if ( is_array( $args ) && isset( $args['param'] ) ) {
110
			$query_args['f'] = $args['param'];
111
		}
112
113
		$link = add_query_arg( $query_args, $page ) . $anchor;
114
		return self::make_affiliate_url( $link );
115
	}
116
117
	/**
118
	 * Get the Formidable settings
119
	 *
120
	 * @since 2.0
121
	 *
122
	 * @param array $args - May include the form id when values need translation.
123
	 * @return FrmSettings $frm_setings
124
	 */
125
	public static function get_settings( $args = array() ) {
126
		global $frm_settings;
127
		if ( empty( $frm_settings ) ) {
128
			$frm_settings = new FrmSettings( $args );
129
		} elseif ( isset( $args['current_form'] ) ) {
130
			// If the global has already been set, allow strings to be filtered.
131
			$frm_settings->maybe_filter_for_form( $args );
132
		}
133
134
		return $frm_settings;
135
	}
136
137
	public static function get_menu_name() {
138
		$frm_settings = self::get_settings();
139
140
		return $frm_settings->menu;
141
	}
142
143
	/**
144
	 * @since 3.05
145
	 */
146
	public static function svg_logo( $atts = array() ) {
147
		$defaults = array(
148
			'height' => 18,
149
			'width'  => 18,
150
			'fill'   => '#4d4d4d',
151
			'orange' => '#f05a24',
152
		);
153
		$atts     = array_merge( $defaults, $atts );
154
155
		return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 599.68 601.37" width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '">
156
			<path fill="' . esc_attr( $atts['orange'] ) . '" d="M289.6 384h140v76h-140z"/>
157
			<path fill="' . esc_attr( $atts['fill'] ) . '" d="M400.2 147h-200c-17 0-30.6 12.2-30.6 29.3V218h260v-71zM397.9 264H169.6v196h75V340H398a32.2 32.2 0 0 0 30.1-21.4 24.3 24.3 0 0 0 1.7-8.7V264zM299.8 601.4A300.3 300.3 0 0 1 0 300.7a299.8 299.8 0 1 1 511.9 212.6 297.4 297.4 0 0 1-212 88zm0-563A262 262 0 0 0 38.3 300.7a261.6 261.6 0 1 0 446.5-185.5 259.5 259.5 0 0 0-185-76.8z"/>
158
		</svg>';
159
	}
160
161
	/**
162
	 * @since 4.0
163
	 */
164
	public static function show_logo( $atts = array() ) {
165
		echo self::kses( self::svg_logo( $atts ), 'all' ); // WPCS: XSS ok.
166
	}
167
168
	/**
169
	 * @since 4.03.02
170
	 */
171
	public static function show_header_logo() {
172
		$icon = self::svg_logo(
173
			array(
174
				'height' => 35,
175
				'width'  => 35,
176
			)
177
		);
178
179
		$new_icon = apply_filters( 'frm_icon', $icon, true );
180
		if ( $new_icon !== $icon ) {
181
			if ( strpos( $new_icon, '<svg' ) === 0 ) {
182
				$icon = str_replace( 'viewBox="0 0 20', 'width="30" height="35" style="color:#929699" viewBox="0 0 20', $new_icon );
183
			} else {
184
				// Show nothing if it isn't an SVG.
185
				$icon = '<div style="height:39px"></div>';
186
			}
187
		}
188
		echo self::kses( $icon, 'all' ); // WPCS: XSS ok.
189
	}
190
191
	/**
192
	 * @since 2.02.04
193
	 */
194
	public static function ips_saved() {
195
		$frm_settings = self::get_settings();
196
197
		return ! $frm_settings->no_ips;
198
	}
199
200
	public static function pro_is_installed() {
201
		return apply_filters( 'frm_pro_installed', false );
202
	}
203
204
	public static function is_formidable_admin() {
205
		$page          = self::simple_get( 'page', 'sanitize_title' );
206
		$is_formidable = strpos( $page, 'formidable' ) !== false;
207
		if ( empty( $page ) ) {
208
			global $pagenow;
209
			$post_type     = self::simple_get( 'post_type', 'sanitize_title' );
210
			$is_formidable = ( $post_type == 'frm_display' );
211
			if ( empty( $post_type ) && $pagenow == 'post.php' ) {
212
				global $post;
213
				$is_formidable = ( $post && $post->post_type == 'frm_display' );
214
			}
215
		}
216
217
		return $is_formidable;
218
	}
219
220
	/**
221
	 * Check for certain page in Formidable settings
222
	 *
223
	 * @since 2.0
224
	 *
225
	 * @param string $page The name of the page to check
226
	 *
227
	 * @return boolean
228
	 */
229
	public static function is_admin_page( $page = 'formidable' ) {
230
		global $pagenow;
231
		$get_page = self::simple_get( 'page', 'sanitize_title' );
232
		if ( $pagenow ) {
233
			// allow this to be true during ajax load i.e. ajax form builder loading
234
			return ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page;
235
		}
236
237
		return is_admin() && $get_page == $page;
238
	}
239
240
	/**
241
	 * If the current page is for editing or creating a view.
242
	 * Returns false for the views listing page.
243
	 *
244
	 * @since 4.0
245
	 */
246
	public static function is_view_builder_page() {
247
		global $pagenow;
248
249
		if ( $pagenow !== 'post.php' && $pagenow !== 'post-new.php' ) {
250
			return false;
251
		}
252
253
		$post_type = self::simple_get( 'post_type', 'sanitize_title' );
254
255
		if ( empty( $post_type ) ) {
256
			$post_id = self::simple_get( 'post', 'absint' );
257
			$post    = get_post( $post_id );
258
			if ( ! empty( $post ) ) {
259
				$post_type = $post->post_type;
260
			}
261
		}
262
263
		return $post_type === 'frm_display';
264
	}
265
266
	/**
267
	 * Check for the form preview page
268
	 *
269
	 * @since 2.0
270
	 *
271
	 * @param None
272
	 *
273
	 * @return boolean
274
	 */
275
	public static function is_preview_page() {
276
		global $pagenow;
277
		$action = self::simple_get( 'action', 'sanitize_title' );
278
279
		return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
280
	}
281
282
	/**
283
	 * Check for ajax except the form preview page
284
	 *
285
	 * @since 2.0
286
	 *
287
	 * @param None
288
	 *
289
	 * @return boolean
290
	 */
291
	public static function doing_ajax() {
292
		return self::wp_doing_ajax() && ! self::is_preview_page();
293
	}
294
295
	public static function js_suffix() {
296
		return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
297
	}
298
299
	/**
300
	 * Use the WP 4.7 wp_doing_ajax function
301
	 *
302
	 * @since 2.05.07
303
	 */
304
	public static function wp_doing_ajax() {
305
		if ( function_exists( 'wp_doing_ajax' ) ) {
306
			$doing_ajax = wp_doing_ajax();
307
		} else {
308
			$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
309
		}
310
311
		return $doing_ajax;
312
	}
313
314
	/**
315
	 * @since 2.0.8
316
	 */
317
	public static function prevent_caching() {
318
		global $frm_vars;
319
320
		return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
321
	}
322
323
	/**
324
	 * Check if on an admin page
325
	 *
326
	 * @since 2.0
327
	 *
328
	 * @param None
329
	 *
330
	 * @return boolean
331
	 */
332
	public static function is_admin() {
333
		return is_admin() && ! self::wp_doing_ajax();
334
	}
335
336
	/**
337
	 * Check if value contains blank value or empty array
338
	 *
339
	 * @since 2.0
340
	 *
341
	 * @param mixed $value - value to check
342
	 * @param string
343
	 *
344
	 * @return boolean
345
	 */
346
	public static function is_empty_value( $value, $empty = '' ) {
347
		return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
348
	}
349
350
	public static function is_not_empty_value( $value, $empty = '' ) {
351
		return ! self::is_empty_value( $value, $empty );
352
	}
353
354
	/**
355
	 * Get any value from the $_SERVER
356
	 *
357
	 * @since 2.0
358
	 *
359
	 * @param string $value
360
	 *
361
	 * @return string
362
	 */
363
	public static function get_server_value( $value ) {
364
		return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( wp_unslash( $_SERVER[ $value ] ) ) : '';
365
	}
366
367
	/**
368
	 * Check for the IP address in several places
369
	 * Used by [ip] shortcode
370
	 *
371
	 * @return string The IP address of the current user
372
	 */
373
	public static function get_ip_address() {
374
		$ip_options = array(
375
			'HTTP_CLIENT_IP',
376
			'HTTP_CF_CONNECTING_IP',
377
			'HTTP_X_FORWARDED_FOR',
378
			'HTTP_X_FORWARDED',
379
			'HTTP_X_CLUSTER_CLIENT_IP',
380
			'HTTP_X_REAL_IP',
381
			'HTTP_FORWARDED_FOR',
382
			'HTTP_FORWARDED',
383
			'REMOTE_ADDR',
384
		);
385
		$ip = '';
386
		foreach ( $ip_options as $key ) {
387
			if ( ! isset( $_SERVER[ $key ] ) ) {
388
				continue;
389
			}
390
391
			$key = self::get_server_value( $key );
392
			foreach ( explode( ',', $key ) as $ip ) {
393
				$ip = trim( $ip ); // just to be safe.
394
395
				if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
396
					return sanitize_text_field( $ip );
397
				}
398
			}
399
		}
400
401
		return sanitize_text_field( $ip );
402
	}
403
404
	public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
405
		if ( strpos( $param, '[' ) ) {
406
			$params = explode( '[', $param );
407
			$param  = $params[0];
408
		}
409
410
		if ( $src == 'get' ) {
411
			// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
412
			$value = isset( $_POST[ $param ] ) ? wp_unslash( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? wp_unslash( $_GET[ $param ] ) : $default );
413
			if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
414
				// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
415
				$value = htmlspecialchars_decode( wp_unslash( $_GET[ $param ] ) );
416
			}
417
			self::sanitize_value( $sanitize, $value );
418
		} else {
419
			$value = self::get_simple_request(
420
				array(
421
					'type'     => $src,
422
					'param'    => $param,
423
					'default'  => $default,
424
					'sanitize' => $sanitize,
425
				)
426
			);
427
		}
428
429
		if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
430
			foreach ( $params as $k => $p ) {
431
				if ( ! $k || ! is_array( $value ) ) {
432
					continue;
433
				}
434
435
				$p     = trim( $p, ']' );
436
				$value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
437
			}
438
		}
439
440
		return $value;
441
	}
442
443 View Code Duplication
	public static function get_post_param( $param, $default = '', $sanitize = '', $serialized = false ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
444
		return self::get_simple_request(
445
			array(
446
				'type'     => 'post',
447
				'param'    => $param,
448
				'default'  => $default,
449
				'sanitize' => $sanitize,
450
				'serialized' => $serialized,
451
			)
452
		);
453
	}
454
455
	/**
456
	 * @since 2.0
457
	 *
458
	 * @param string $param
459
	 * @param string $sanitize
460
	 * @param string $default
461
	 *
462
	 * @return string|array
463
	 */
464 View Code Duplication
	public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
465
		return self::get_simple_request(
466
			array(
467
				'type'     => 'get',
468
				'param'    => $param,
469
				'default'  => $default,
470
				'sanitize' => $sanitize,
471
			)
472
		);
473
	}
474
475
	/**
476
	 * Get a GET/POST/REQUEST value and sanitize it
477
	 *
478
	 * @since 2.0.6
479
	 *
480
	 * @param array $args
481
	 *
482
	 * @return string|array
483
	 */
484
	public static function get_simple_request( $args ) {
485
		$defaults = array(
486
			'param'    => '',
487
			'default'  => '',
488
			'type'     => 'get',
489
			'sanitize' => 'sanitize_text_field',
490
			'serialized' => false,
491
		);
492
		$args     = wp_parse_args( $args, $defaults );
493
494
		$value = $args['default'];
495
		if ( $args['type'] == 'get' ) {
496 View Code Duplication
			if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
497
				// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
498
				$value = wp_unslash( $_GET[ $args['param'] ] );
499
			}
500
		} elseif ( $args['type'] == 'post' ) {
501
			if ( isset( $_POST[ $args['param'] ] ) ) {
502
				// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
503
				$value = wp_unslash( $_POST[ $args['param'] ] );
504
				if ( $args['serialized'] === true && is_serialized_string( $value ) && is_serialized( $value ) ) {
505
					self::unserialize_or_decode( $value );
506
				}
507
			}
508 View Code Duplication
		} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
509
			if ( isset( $_REQUEST[ $args['param'] ] ) ) {
510
				// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
511
				$value = wp_unslash( $_REQUEST[ $args['param'] ] );
512
			}
513
		}
514
515
		self::sanitize_value( $args['sanitize'], $value );
516
517
		return $value;
518
	}
519
520
	/**
521
	 * Preserve backslashes in a value, but make sure value doesn't get compounding slashes
522
	 *
523
	 * @since 2.0.8
524
	 *
525
	 * @param string $value
526
	 *
527
	 * @return string $value
528
	 */
529
	public static function preserve_backslashes( $value ) {
530
		// If backslashes have already been added, don't add them again
531
		if ( strpos( $value, '\\\\' ) === false ) {
532
			$value = addslashes( $value );
533
		}
534
535
		return $value;
536
	}
537
538
	public static function sanitize_value( $sanitize, &$value ) {
539
		if ( ! empty( $sanitize ) ) {
540
			if ( is_array( $value ) ) {
541
				$temp_values = $value;
542
				foreach ( $temp_values as $k => $v ) {
543
					self::sanitize_value( $sanitize, $value[ $k ] );
544
				}
545
			} else {
546
				$value = call_user_func( $sanitize, $value );
547
			}
548
		}
549
	}
550
551
	public static function sanitize_request( $sanitize_method, &$values ) {
552
		$temp_values = $values;
553
		foreach ( $temp_values as $k => $val ) {
554
			if ( isset( $sanitize_method[ $k ] ) ) {
555
				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
556
			}
557
		}
558
	}
559
560
	/**
561
	 * @since 4.0.04
562
	 */
563
	public static function sanitize_with_html( &$value ) {
564
		self::sanitize_value( 'wp_kses_post', $value );
565
		self::decode_specialchars( $value );
566
	}
567
568
	/**
569
	 * Do wp_specialchars_decode to get back '&' that wp_kses_post might have turned to '&amp;'
570
	 * this MUST be done, else we'll be back to the '& entity' problem.
571
	 *
572
	 * @since 4.0.04
573
	 */
574
	public static function decode_specialchars( &$value ) {
575
		if ( is_array( $value ) ) {
576
			$temp_values = $value;
577
			foreach ( $temp_values as $k => $v ) {
578
				self::decode_specialchars( $value[ $k ] );
579
			}
580
		} else {
581
			self::decode_amp( $value );
582
		}
583
	}
584
585
	/**
586
	 * The wp_specialchars_decode function changes too much.
587
	 * This will leave HTML as is, but still convert &.
588
	 * Adapted from wp_specialchars_decode().
589
	 *
590
	 * @since 4.03.01
591
	 *
592
	 * @param string $string The string to prep.
593
	 */
594
	private static function decode_amp( &$string ) {
595
		// Don't bother if there are no entities - saves a lot of processing
596
		if ( empty( $string ) || strpos( $string, '&' ) === false ) {
597
			return;
598
		}
599
600
		$translation = array(
601
			'&quot;'  => '"',
602
			'&#034;'  => '"',
603
			'&#x22;'  => '"',
604
			'&lt; '   => '< ', // The space preserves the HTML.
605
			'&#060; ' => '< ', // The space preserves the HTML.
606
			'&gt;'    => '>',
607
			'&#062;'  => '>',
608
			'&amp;'   => '&',
609
			'&#038;'  => '&',
610
			'&#x26;'  => '&',
611
		);
612
613
		$translation_preg = array(
614
			'/&#0*34;/'   => '&#034;',
615
			'/&#x0*22;/i' => '&#x22;',
616
			'/&#0*60;/'   => '&#060;',
617
			'/&#0*62;/'   => '&#062;',
618
			'/&#0*38;/'   => '&#038;',
619
			'/&#x0*26;/i' => '&#x26;',
620
		);
621
622
		// Remove zero padding on numeric entities
623
		$string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );
624
625
		// Replace characters according to translation table
626
		$string = strtr( $string, $translation );
627
	}
628
629
	/**
630
	 * Sanitize the value, and allow some HTML
631
	 *
632
	 * @since 2.0
633
	 *
634
	 * @param string $value
635
	 * @param array|string $allowed 'all' for everything included as defaults
636
	 *
637
	 * @return string
638
	 */
639
	public static function kses( $value, $allowed = array() ) {
640
		$allowed_html = self::allowed_html( $allowed );
641
642
		return wp_kses( $value, $allowed_html );
643
	}
644
645
	/**
646
	 * @since 2.05.03
647
	 */
648
	private static function allowed_html( $allowed ) {
649
		$html         = self::safe_html();
650
		$allowed_html = array();
651
		if ( $allowed == 'all' ) {
652
			$allowed_html = $html;
653
		} elseif ( ! empty( $allowed ) ) {
654
			foreach ( (array) $allowed as $a ) {
655
				$allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
656
			}
657
		}
658
659
		return apply_filters( 'frm_striphtml_allowed_tags', $allowed_html );
660
	}
661
662
	/**
663
	 * @since 2.05.03
664
	 */
665
	private static function safe_html() {
666
		$allow_class = array(
667
			'class' => true,
668
			'id'    => true,
669
		);
670
671
		return array(
672
			'a'          => array(
673
				'class'  => true,
674
				'href'   => true,
675
				'id'     => true,
676
				'rel'    => true,
677
				'target' => true,
678
				'title'  => true,
679
			),
680
			'abbr'       => array(
681
				'title' => true,
682
			),
683
			'aside'      => $allow_class,
684
			'b'          => array(),
685
			'blockquote' => array(
686
				'cite' => true,
687
			),
688
			'br'         => array(),
689
			'cite'       => array(
690
				'title' => true,
691
			),
692
			'code'       => array(),
693
			'defs'       => array(),
694
			'del'        => array(
695
				'datetime' => true,
696
				'title'    => true,
697
			),
698
			'dd'         => array(),
699
			'div'        => array(
700
				'class' => true,
701
				'id'    => true,
702
				'title' => true,
703
				'style' => true,
704
			),
705
			'dl'         => array(),
706
			'dt'         => array(),
707
			'em'         => array(),
708
			'h1'         => $allow_class,
709
			'h2'         => $allow_class,
710
			'h3'         => $allow_class,
711
			'h4'         => $allow_class,
712
			'h5'         => $allow_class,
713
			'h6'         => $allow_class,
714
			'i'          => array(
715
				'class' => true,
716
				'id'    => true,
717
				'icon'  => true,
718
				'style' => true,
719
			),
720
			'img'        => array(
721
				'alt'    => true,
722
				'class'  => true,
723
				'height' => true,
724
				'id'     => true,
725
				'src'    => true,
726
				'width'  => true,
727
			),
728
			'li'         => $allow_class,
729
			'ol'         => $allow_class,
730
			'p'          => $allow_class,
731
			'path'       => array(
732
				'd'    => true,
733
				'fill' => true,
734
			),
735
			'pre'        => array(),
736
			'q'          => array(
737
				'cite'  => true,
738
				'title' => true,
739
			),
740
			'rect'       => array(
741
				'class'  => true,
742
				'fill'   => true,
743
				'height' => true,
744
				'width'  => true,
745
				'x'      => true,
746
				'y'      => true,
747
			),
748
			'section'    => $allow_class,
749
			'span'       => array(
750
				'class' => true,
751
				'id'    => true,
752
				'title' => true,
753
				'style' => true,
754
			),
755
			'strike'     => array(),
756
			'strong'     => array(),
757
			'symbol'     => array(
758
				'class'   => true,
759
				'id'      => true,
760
				'viewbox' => true,
761
			),
762
			'svg'        => array(
763
				'class'   => true,
764
				'id'      => true,
765
				'xmlns'   => true,
766
				'viewbox' => true,
767
				'width'   => true,
768
				'height'  => true,
769
				'style'   => true,
770
			),
771
			'use'        => array(
772
				'href'   => true,
773
				'xlink:href' => true,
774
			),
775
			'ul'         => $allow_class,
776
		);
777
	}
778
779
	/**
780
	 * Used when switching the action for a bulk action
781
	 *
782
	 * @since 2.0
783
	 */
784
	public static function remove_get_action() {
785
		if ( ! isset( $_GET ) ) {
786
			return;
787
		}
788
789
		$action_name = isset( $_GET['action'] ) ? 'action' : ( isset( $_GET['action2'] ) ? 'action2' : '' );
790
		if ( empty( $action_name ) ) {
791
			return;
792
		}
793
794
		$new_action = self::get_param( $action_name, '', 'get', 'sanitize_text_field' );
795
		if ( ! empty( $new_action ) ) {
796
			$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) );
797
		}
798
	}
799
800
	/**
801
	 * Check the WP query for a parameter
802
	 *
803
	 * @since 2.0
804
	 * @return string|array
805
	 */
806
	public static function get_query_var( $value, $param ) {
807
		if ( $value != '' ) {
808
			return $value;
809
		}
810
811
		global $wp_query;
812
		if ( isset( $wp_query->query_vars[ $param ] ) ) {
813
			$value = $wp_query->query_vars[ $param ];
814
		}
815
816
		return $value;
817
	}
818
819
	/**
820
	 * Try to show the SVG if possible. Otherwise, use the font icon.
821
	 *
822
	 * @since 4.0.02
823
	 * @param string $class
824
	 * @param array  $atts
825
	 */
826
	public static function icon_by_class( $class, $atts = array() ) {
827
		$echo = ! isset( $atts['echo'] ) || $atts['echo'];
828
		if ( isset( $atts['echo'] ) ) {
829
			unset( $atts['echo'] );
830
		}
831
832
		$html_atts = self::array_to_html_params( $atts );
833
834
		$icon = trim( str_replace( array( 'frm_icon_font', 'frmfont ' ), '', $class ) );
835
		if ( $icon === $class ) {
836
			$icon = '<i class="' . esc_attr( $class ) . '"' . $html_atts . '></i>';
837
		} else {
838
			$class = strpos( $icon, ' ' ) === false ? '' : ' ' . $icon;
839
			if ( strpos( $icon, ' ' ) ) {
840
				$icon = explode( ' ', $icon );
841
				$icon = reset( $icon );
842
			}
843
			$icon  = '<svg class="frmsvg' . esc_attr( $class ) . '"' . $html_atts . '>
844
				<use xlink:href="#' . esc_attr( $icon ) . '" />
845
			</svg>';
846
		}
847
848
		if ( $echo ) {
849
			echo $icon; // WPCS: XSS ok.
850
		} else {
851
			return $icon;
852
		}
853
	}
854
855
	/**
856
	 * Include svg images.
857
	 *
858
	 * @since 4.0.02
859
	 */
860
	public static function include_svg() {
861
		include_once( self::plugin_path() . '/images/icons.svg' );
862
	}
863
864
	/**
865
	 * Convert an associative array to HTML values.
866
	 *
867
	 * @since 4.0.02
868
	 * @param array $atts
869
	 * @return string
870
	 */
871
	public static function array_to_html_params( $atts ) {
872
		$html = '';
873
		if ( ! empty( $atts ) ) {
874
			foreach ( $atts as $key => $value ) {
875
				$html .= ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
876
			}
877
		}
878
		return $html;
879
	}
880
881
	/**
882
	 * @since 3.0
883
	 */
884
	public static function get_admin_header( $atts ) {
885
		$has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) );
886
		if ( ! isset( $atts['close'] ) || empty( $atts['close'] ) ) {
887
			$atts['close'] = admin_url( 'admin.php?page=formidable' );
888
		}
889
890
		include( self::plugin_path() . '/classes/views/shared/admin-header.php' );
891
	}
892
893
	/**
894
	 * @since 3.0
895
	 */
896
	public static function add_new_item_link( $atts ) {
897
		if ( isset( $atts['new_link'] ) && ! empty( $atts['new_link'] ) ) { ?>
898
			<a href="<?php echo esc_url( $atts['new_link'] ); ?>" class="button button-primary frm-button-primary frm-with-plus">
899
				<?php self::icon_by_class( 'frmfont frm_plus_icon frm_svg15' ); ?>
900
				<?php esc_html_e( 'Add New', 'formidable' ); ?>
901
			</a>
902
			<?php
903
		} elseif ( isset( $atts['link_hook'] ) ) {
904
			do_action( $atts['link_hook']['hook'], $atts['link_hook']['param'] );
905
		}
906
	}
907
908
	/**
909
	 * @since 3.06
910
	 */
911
	public static function show_search_box( $atts ) {
912
		$defaults = array(
913
			'placeholder' => '',
914
			'tosearch'    => '',
915
			'text'        => __( 'Search', 'formidable' ),
916
			'input_id'    => '',
917
		);
918
		$atts = array_merge( $defaults, $atts );
919
920
		if ( $atts['input_id'] === 'template' && empty( $atts['tosearch'] ) ) {
921
			$atts['tosearch'] = 'frm-card';
922
		}
923
924
		$class = 'frm-search-input';
925
		if ( ! empty( $atts['tosearch'] ) ) {
926
			$class .= ' frm-auto-search';
927
		}
928
929
		$input_id = $atts['input_id'] . '-search-input';
930
931
		?>
932
		<p class="frm-search">
933
			<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>">
934
				<?php echo esc_html( $atts['text'] ); ?>:
935
			</label>
936
			<span class="frmfont frm_search_icon"></span>
937
			<input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s"
938
				value="<?php _admin_search_query(); ?>" placeholder="<?php echo esc_attr( $atts['placeholder'] ); ?>"
939
				class="<?php echo esc_attr( $class ); ?>" data-tosearch="<?php echo esc_attr( $atts['tosearch'] ); ?>"
940
				<?php if ( ! empty( $atts['tosearch'] ) ) { ?>
941
				autocomplete="off"
942
				<?php } ?>
943
				/>
944
			<?php
945
			if ( empty( $atts['tosearch'] ) ) {
946
				submit_button( $atts['text'], 'button-secondary', '', false, array( 'id' => 'search-submit' ) );
947
			}
948
			?>
949
		</p>
950
		<?php
951
	}
952
953
	/**
954
	 * @param string $type
955
	 */
956
	public static function trigger_hook_load( $type, $object = null ) {
957
		// Only load the form hooks once.
958
		$hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
959
		if ( ! $hooks_loaded ) {
960
			do_action( 'frm_load_' . $type . '_hooks' );
961
		}
962
	}
963
964
	/**
965
	 * Save all front-end js scripts into a single file
966
	 *
967
	 * @since 3.0
968
	 */
969
	public static function save_combined_js() {
970
		$file_atts = apply_filters(
971
			'frm_js_location',
972
			array(
973
				'file_name'     => 'frm.min.js',
974
				'new_file_path' => self::plugin_path() . '/js',
975
			)
976
		);
977
		$new_file  = new FrmCreateFile( $file_atts );
978
979
		$files = array(
980
			self::plugin_path() . '/js/jquery/jquery.placeholder.min.js',
981
			self::plugin_path() . '/js/formidable.min.js',
982
		);
983
		$files = apply_filters( 'frm_combined_js_files', $files );
984
		$new_file->combine_files( $files );
985
	}
986
987
	/**
988
	 * Check a value from a shortcode to see if true or false.
989
	 * True when value is 1, true, 'true', 'yes'
990
	 *
991
	 * @since 1.07.10
992
	 *
993
	 * @param string $value The value to compare
994
	 *
995
	 * @return boolean True or False
996
	 */
997
	public static function is_true( $value ) {
998
		return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
999
	}
1000
1001
	public static function get_pages() {
1002
		$query = array(
1003
			'post_type'   => 'page',
1004
			'post_status' => array( 'publish', 'private' ),
1005
			'numberposts' => - 1,
1006
			'orderby'     => 'title',
1007
			'order'       => 'ASC',
1008
		);
1009
1010
		return get_posts( $query );
1011
	}
1012
1013
	/**
1014
	 * Renders an autocomplete page selection or a regular dropdown depending on
1015
	 * the total page count
1016
	 *
1017
	 * @since 4.03.06
1018
	 */
1019
	public static function maybe_autocomplete_pages_options( $args ) {
1020
		$args = self::preformat_selection_args( $args );
1021
1022
		$pages_count = wp_count_posts( 'page' );
1023
1024
		if ( $pages_count->publish <= 50 ) {
1025
			self::wp_pages_dropdown( $args );
1026
			return;
1027
		}
1028
1029
		wp_enqueue_script( 'jquery-ui-autocomplete' );
1030
1031
		$selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' );
0 ignored issues
show
Security Bug introduced by
It seems like $args['page_id'] can also be of type false; however, FrmAppHelper::get_post_param() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
1032
		$title = '';
1033
1034
		if ( $selected ) {
1035
			$title = get_the_title( $selected );
1036
		}
1037
1038
		?>
1039
		<input type="text" class="frm-page-search"
1040
			placeholder="<?php esc_html_e( 'Select a Page', 'formidable' ); ?>"
1041
			value="<?php echo esc_attr( $title ); ?>" />
1042
		<input type="hidden" name="<?php echo esc_attr( $args['field_name'] ); ?>"
1043
			value="<?php echo esc_attr( $selected ); ?>" />
1044
		<?php
1045
	}
1046
1047
	/**
1048
	 * @param array   $args
1049
	 * @param string  $page_id Deprecated.
1050
	 * @param boolean $truncate Deprecated.
1051
	 */
1052
	public static function wp_pages_dropdown( $args = array(), $page_id = '', $truncate = false ) {
1053
		self::prep_page_dropdown_params( $page_id, $truncate, $args );
1054
1055
		$pages    = self::get_pages();
1056
		$selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' );
1057
1058
		?>
1059
		<select name="<?php echo esc_attr( $args['field_name'] ); ?>" id="<?php echo esc_attr( $args['field_name'] ); ?>" class="frm-pages-dropdown">
1060
			<option value=""><?php echo esc_html( $args['placeholder'] ); ?></option>
1061
			<?php foreach ( $pages as $page ) { ?>
1062
				<option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ); ?>>
1063
					<?php echo esc_html( $args['truncate'] ? self::truncate( $page->post_title, $args['truncate'] ) : $page->post_title ); ?>
1064
				</option>
1065
			<?php } ?>
1066
		</select>
1067
		<?php
1068
	}
1069
1070
	/**
1071
	 * Fill in missing parameters passed to wp_pages_dropdown().
1072
	 * This is for reverse compatibility with switching 3 params to 1.
1073
	 *
1074
	 * @since 4.03.06
1075
	 */
1076
	private static function prep_page_dropdown_params( $page_id, $truncate, &$args ) {
1077
		if ( ! is_array( $args ) ) {
1078
			$args = array(
1079
				'field_name' => $args,
1080
				'page_id'    => $page_id,
1081
				'truncate'   => $truncate,
1082
			);
1083
		}
1084
1085
		$args = self::preformat_selection_args( $args );
1086
	}
1087
1088
	/**
1089
	 * Filter to format args for page dropdown or autocomplete
1090
	 *
1091
	 * @since 4.03.06
1092
	 */
1093
	private static function preformat_selection_args( $args ) {
1094
		$defaults = array(
1095
			'truncate'    => false,
1096
			'placeholder' => ' ',
1097
			'field_name'  => '',
1098
			'page_id'     => '',
1099
		);
1100
1101
		return array_merge( $defaults, $args );
1102
	}
1103
1104
	public static function post_edit_link( $post_id ) {
1105
		$post = get_post( $post_id );
1106
		if ( $post ) {
1107
			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
1108
			$post_url = self::maybe_full_screen_link( $post_url );
1109
1110
			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
1111
		}
1112
1113
		return '';
1114
	}
1115
1116
	/**
1117
	 * Hide the WordPress menus on some pages.
1118
	 *
1119
	 * @since 4.0
1120
	 */
1121
	public static function is_full_screen() {
1122
		$action       = self::simple_get( 'frm_action', 'sanitize_title' );
1123
		$full_builder = self::is_admin_page( 'formidable' ) && ( $action === 'edit' || $action === 'settings' || $action === 'duplicate' );
1124
		$styler       = self::is_admin_page( 'formidable-styles' );
1125
		$full_entries = self::simple_get( 'frm-full', 'absint' );
1126
1127
		return $full_builder || $full_entries || $styler || self::is_view_builder_page();
1128
	}
1129
1130
	/**
1131
	 * @since 4.0
1132
	 */
1133
	public static function maybe_full_screen_link( $link ) {
1134
		$is_full = self::simple_get( 'frm-full', 'absint' );
1135
		if ( $is_full && ! empty( $link ) && $link !== '#' ) {
1136
			$link .= '&frm-full=1';
1137
		}
1138
		return $link;
1139
	}
1140
1141
	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
1142
		?>
1143
		<select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>"
1144
			<?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?>
1145
			class="frm_multiselect">
1146
			<?php self::roles_options( $capability ); ?>
1147
		</select>
1148
		<?php
1149
	}
1150
1151
	public static function roles_options( $capability ) {
1152
		global $frm_vars;
1153
		if ( isset( $frm_vars['editable_roles'] ) ) {
1154
			$editable_roles = $frm_vars['editable_roles'];
1155
		} else {
1156
			$editable_roles             = get_editable_roles();
1157
			$frm_vars['editable_roles'] = $editable_roles;
1158
		}
1159
1160
		foreach ( $editable_roles as $role => $details ) {
1161
			$name = translate_user_role( $details['name'] );
1162
			?>
1163
			<option value="<?php echo esc_attr( $role ); ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ); ?> </option>
1164
			<?php
1165
			unset( $role, $details );
1166
		}
1167
	}
1168
1169
	public static function frm_capabilities( $type = 'auto' ) {
1170
		$cap = array(
1171
			'frm_view_forms'      => __( 'View Forms and Templates', 'formidable' ),
1172
			'frm_edit_forms'      => __( 'Add/Edit Forms and Templates', 'formidable' ),
1173
			'frm_delete_forms'    => __( 'Delete Forms and Templates', 'formidable' ),
1174
			'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ),
1175
			'frm_view_entries'    => __( 'View Entries from Admin Area', 'formidable' ),
1176
			'frm_delete_entries'  => __( 'Delete Entries from Admin Area', 'formidable' ),
1177
		);
1178
1179
		if ( ! self::pro_is_installed() && 'pro' != $type ) {
1180
			return $cap;
1181
		}
1182
1183
		$cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
1184
		$cap['frm_edit_entries']   = __( 'Edit Entries from Admin Area', 'formidable' );
1185
		$cap['frm_view_reports']   = __( 'View Reports', 'formidable' );
1186
		$cap['frm_edit_displays']  = __( 'Add/Edit Views', 'formidable' );
1187
1188
		return $cap;
1189
	}
1190
1191
	public static function user_has_permission( $needed_role ) {
1192
		if ( $needed_role == '-1' ) {
1193
			return false;
1194
		}
1195
1196
		// $needed_role will be equal to blank if "Logged-in users" is selected.
1197
		if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
1198
			return true;
1199
		}
1200
1201
		$roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
1202
		foreach ( $roles as $role ) {
1203
			if ( current_user_can( $role ) ) {
1204
				return true;
1205
			}
1206
			if ( $role == $needed_role ) {
1207
				break;
1208
			}
1209
		}
1210
1211
		return false;
1212
	}
1213
1214
	/**
1215
	 * Make sure administrators can see Formidable menu
1216
	 *
1217
	 * @since 2.0
1218
	 */
1219
	public static function maybe_add_permissions() {
1220
		self::force_capability( 'frm_view_entries' );
1221
1222
		if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
1223
			return;
1224
		}
1225
1226
		$user_id   = get_current_user_id();
1227
		$user      = new WP_User( $user_id );
1228
		$frm_roles = self::frm_capabilities();
1229
		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
1230
			$user->add_cap( $frm_role );
1231
			unset( $frm_role, $frm_role_description );
1232
		}
1233
	}
1234
1235
	/**
1236
	 * Make sure admins have permission to see the menu items
1237
	 *
1238
	 * @since 2.0.6
1239
	 */
1240
	public static function force_capability( $cap = 'frm_change_settings' ) {
1241
		if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
1242
			$role      = get_role( 'administrator' );
1243
			$frm_roles = self::frm_capabilities();
1244
			foreach ( $frm_roles as $frm_role => $frm_role_description ) {
1245
				$role->add_cap( $frm_role );
1246
			}
1247
		}
1248
	}
1249
1250
	/**
1251
	 * Check if the user has permision for action.
1252
	 * Return permission message and stop the action if no permission
1253
	 *
1254
	 * @since 2.0
1255
	 *
1256
	 * @param string $permission
1257
	 */
1258
	public static function permission_check( $permission, $show_message = 'show' ) {
1259
		$permission_error = self::permission_nonce_error( $permission );
1260
		if ( $permission_error !== false ) {
1261
			if ( 'hide' == $show_message ) {
1262
				$permission_error = '';
1263
			}
1264
			wp_die( esc_html( $permission_error ) );
1265
		}
1266
	}
1267
1268
	/**
1269
	 * Check user permission and nonce
1270
	 *
1271
	 * @since 2.0
1272
	 *
1273
	 * @param string $permission
1274
	 *
1275
	 * @return false|string The permission message or false if allowed
1276
	 */
1277
	public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
1278
		if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
1279
			$frm_settings = self::get_settings();
1280
1281
			return $frm_settings->admin_permission;
1282
		}
1283
1284
		$error = false;
1285
		if ( empty( $nonce_name ) ) {
1286
			return $error;
1287
		}
1288
1289
		$nonce_value = ( $_REQUEST && isset( $_REQUEST[ $nonce_name ] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $nonce_name ] ) ) : '';
1290
		if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $nonce_value, $nonce ) ) ) {
1291
			$frm_settings = self::get_settings();
1292
			$error        = $frm_settings->admin_permission;
1293
		}
1294
1295
		return $error;
1296
	}
1297
1298
	public static function checked( $values, $current ) {
1299
		if ( self::check_selected( $values, $current ) ) {
1300
			echo ' checked="checked"';
1301
		}
1302
	}
1303
1304
	public static function check_selected( $values, $current ) {
1305
		$values  = self::recursive_function_map( $values, 'trim' );
1306
		$values  = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
1307
		$current = htmlspecialchars_decode( trim( $current ) );
1308
1309
		return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
1310
	}
1311
1312
	public static function recursive_function_map( $value, $function ) {
1313
		if ( is_array( $value ) ) {
1314
			$original_function = $function;
1315
			if ( count( $value ) ) {
1316
				$function = explode( ', ', FrmDb::prepare_array_values( $value, $function ) );
1317
			} else {
1318
				$function = array( $function );
1319
			}
1320
			if ( ! self::is_assoc( $value ) ) {
1321
				$value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
1322
			} else {
1323
				foreach ( $value as $k => $v ) {
1324
					if ( ! is_array( $v ) ) {
1325
						$value[ $k ] = call_user_func( $original_function, $v );
1326
					}
1327
				}
1328
			}
1329
		} else {
1330
			$value = call_user_func( $function, $value );
1331
		}
1332
1333
		return $value;
1334
	}
1335
1336
	public static function is_assoc( $array ) {
1337
		return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
1338
	}
1339
1340
	/**
1341
	 * Flatten a multi-dimensional array
1342
	 */
1343
	public static function array_flatten( $array, $keys = 'keep' ) {
1344
		$return = array();
1345
		foreach ( $array as $key => $value ) {
1346
			if ( is_array( $value ) ) {
1347
				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
1348
			} else {
1349
				if ( $keys == 'keep' ) {
1350
					$return[ $key ] = $value;
1351
				} else {
1352
					$return[] = $value;
1353
				}
1354
			}
1355
		}
1356
1357
		return $return;
1358
	}
1359
1360
	public static function esc_textarea( $text, $is_rich_text = false ) {
1361
		$safe_text = str_replace( '&quot;', '"', $text );
1362
		if ( ! $is_rich_text ) {
1363
			$safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
1364
		}
1365
		$safe_text = str_replace( '&amp; ', '& ', $safe_text );
1366
1367
		return apply_filters( 'esc_textarea', $safe_text, $text );
1368
	}
1369
1370
	/**
1371
	 * Add auto paragraphs to text areas
1372
	 *
1373
	 * @since 2.0
1374
	 */
1375
	public static function use_wpautop( $content ) {
1376
		if ( apply_filters( 'frm_use_wpautop', true ) && ! is_array( $content ) ) {
1377
			$content = wpautop( str_replace( '<br>', '<br />', $content ) );
1378
		}
1379
1380
		return $content;
1381
	}
1382
1383
	public static function replace_quotes( $val ) {
1384
		// Replace double quotes.
1385
		$val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
1386
1387
		// Replace single quotes.
1388
		$val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
1389
1390
		return $val;
1391
	}
1392
1393
	/**
1394
	 * @since 2.0
1395
	 * @return string The base Google APIS url for the current version of jQuery UI
1396
	 */
1397
	public static function jquery_ui_base_url() {
1398
		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
1399
		$url = apply_filters( 'frm_jquery_ui_base_url', $url );
1400
1401
		return $url;
1402
	}
1403
1404
	/**
1405
	 * @param string $handle
1406
	 */
1407
	public static function script_version( $handle, $default = 0 ) {
1408
		global $wp_scripts;
1409
		if ( ! $wp_scripts ) {
1410
			return $default;
1411
		}
1412
1413
		$ver = $default;
1414
		if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
1415
			return $ver;
1416
		}
1417
1418
		$query = $wp_scripts->registered[ $handle ];
1419
		if ( is_object( $query ) && ! empty( $query->ver ) ) {
1420
			$ver = $query->ver;
1421
		}
1422
1423
		return $ver;
1424
	}
1425
1426
	public static function js_redirect( $url ) {
1427
		return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
1428
	}
1429
1430
	public static function get_user_id_param( $user_id ) {
1431
		if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
1432
			return $user_id;
1433
		}
1434
1435
		$user_id = sanitize_text_field( $user_id );
1436
		if ( $user_id == 'current' ) {
1437
			$user_id = get_current_user_id();
1438
		} else {
1439
			if ( is_email( $user_id ) ) {
1440
				$user = get_user_by( 'email', $user_id );
1441
			} else {
1442
				$user = get_user_by( 'login', $user_id );
1443
			}
1444
1445
			if ( $user ) {
1446
				$user_id = $user->ID;
1447
			}
1448
			unset( $user );
1449
		}
1450
1451
		return $user_id;
1452
	}
1453
1454
	public static function get_file_contents( $filename, $atts = array() ) {
1455
		if ( ! is_file( $filename ) ) {
1456
			return false;
1457
		}
1458
1459
		extract( $atts );
1460
		ob_start();
1461
		include( $filename );
1462
		$contents = ob_get_contents();
1463
		ob_end_clean();
1464
1465
		return $contents;
1466
	}
1467
1468
	/**
1469
	 * @param string $table_name
1470
	 * @param string $column
1471
	 * @param int $id
1472
	 * @param int $num_chars
1473
	 */
1474
	public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
1475
		$key = '';
1476
1477
		if ( ! empty( $name ) ) {
1478
			$key = sanitize_key( $name );
1479
		}
1480
1481
		if ( empty( $key ) ) {
1482
			$max_slug_value = pow( 36, $num_chars );
1483
			$min_slug_value = 37; // we want to have at least 2 characters in the slug
1484
			$key            = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
1485
		}
1486
1487
		$not_allowed = array(
1488
			'id',
1489
			'key',
1490
			'created-at',
1491
			'detaillink',
1492
			'editlink',
1493
			'siteurl',
1494
			'evenodd',
1495
		);
1496
1497
		if ( is_numeric( $key ) || in_array( $key, $not_allowed ) ) {
1498
			$key = $key . 'a';
1499
		}
1500
1501
		$key_check = FrmDb::get_var(
1502
			$table_name,
1503
			array(
1504
				$column => $key,
1505
				'ID !'  => $id,
1506
			),
1507
			$column
1508
		);
1509
1510
		if ( $key_check || is_numeric( $key_check ) ) {
1511
			$suffix = 2;
1512
			do {
1513
				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
1514
				$key_check     = FrmDb::get_var(
1515
					$table_name,
1516
					array(
1517
						$column => $alt_post_name,
1518
						'ID !'  => $id,
1519
					),
1520
					$column
1521
				);
1522
				$suffix ++;
1523
			} while ( $key_check || is_numeric( $key_check ) );
1524
			$key = $alt_post_name;
1525
		}
1526
1527
		return $key;
1528
	}
1529
1530
	/**
1531
	 * Editing a Form or Entry
1532
	 *
1533
	 * @param string $table
1534
	 *
1535
	 * @return bool|array
1536
	 */
1537
	public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
1538
		if ( ! $record ) {
1539
			return false;
1540
		}
1541
1542
		if ( empty( $post_values ) ) {
1543
			$post_values = wp_unslash( $_POST );
1544
		}
1545
1546
		$values = array(
1547
			'id'     => $record->id,
1548
			'fields' => array(),
1549
		);
1550
1551
		foreach ( array( 'name', 'description' ) as $var ) {
1552
			$default_val    = isset( $record->{$var} ) ? $record->{$var} : '';
1553
			$values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
1554
			unset( $var, $default_val );
1555
		}
1556
1557
		$values['description'] = self::use_wpautop( $values['description'] );
1558
1559
		self::fill_form_opts( $record, $table, $post_values, $values );
1560
1561
		self::prepare_field_arrays( $fields, $record, $values, array_merge( $args, compact( 'default', 'post_values' ) ) );
1562
1563
		if ( $table == 'entries' ) {
1564
			$values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1565
		} elseif ( $table == 'forms' ) {
1566
			$values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1567
		}
1568
1569
		return $values;
1570
	}
1571
1572
	private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
1573
		if ( ! empty( $fields ) ) {
1574
			foreach ( (array) $fields as $field ) {
1575
				$field->default_value   = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
1576
				$args['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
1577
				self::fill_field_defaults( $field, $record, $values, $args );
1578
			}
1579
		}
1580
	}
1581
1582
	private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1583
		$post_values = $args['post_values'];
1584
1585
		if ( $args['default'] ) {
1586
			$meta_value = $field->default_value;
1587
		} else {
1588
			if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1589
				if ( ! isset( $field->field_options['custom_field'] ) ) {
1590
					$field->field_options['custom_field'] = '';
1591
				}
1592
				$meta_value = FrmProEntryMetaHelper::get_post_value(
1593
					$record->post_id,
1594
					$field->field_options['post_field'],
1595
					$field->field_options['custom_field'],
1596
					array(
1597
						'truncate' => false,
1598
						'type'     => $field->type,
1599
						'form_id'  => $field->form_id,
1600
						'field'    => $field,
1601
					)
1602
				);
1603
			} else {
1604
				$meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1605
			}
1606
		}
1607
1608
		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1609
		if ( isset( $post_values['item_meta'][ $field->id ] ) ) {
1610
			$new_value = $post_values['item_meta'][ $field->id ];
1611
			self::unserialize_or_decode( $new_value );
1612
		} else {
1613
			$new_value = $meta_value;
1614
		}
1615
1616
		$field_array                   = self::start_field_array( $field );
1617
		$field_array['value']          = $new_value;
1618
		$field_array['type']           = apply_filters( 'frm_field_type', $field_type, $field, $new_value );
1619
		$field_array['parent_form_id'] = $args['parent_form_id'];
1620
1621
		$args['field_type'] = $field_type;
1622
1623
		FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
1624
1625
		if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1626
			$field_array['unique_msg'] = '';
1627
		}
1628
1629
		$field_array = array_merge( $field->field_options, $field_array );
1630
1631
		$values['fields'][ $field->id ] = $field_array;
1632
	}
1633
1634
	/**
1635
	 * @since 3.0
1636
	 *
1637
	 * @param object $field
1638
	 *
1639
	 * @return array
1640
	 */
1641
	public static function start_field_array( $field ) {
1642
		return array(
1643
			'id'            => $field->id,
1644
			'default_value' => $field->default_value,
1645
			'name'          => $field->name,
1646
			'description'   => $field->description,
1647
			'options'       => $field->options,
1648
			'required'      => $field->required,
1649
			'field_key'     => $field->field_key,
1650
			'field_order'   => $field->field_order,
1651
			'form_id'       => $field->form_id,
1652
		);
1653
	}
1654
1655
	/**
1656
	 * @param string $table
1657
	 */
1658
	private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1659
		if ( $table == 'entries' ) {
1660
			$form = $record->form_id;
1661
			FrmForm::maybe_get_form( $form );
1662
		} else {
1663
			$form = $record;
1664
		}
1665
1666
		if ( ! $form ) {
1667
			return;
1668
		}
1669
1670
		$values['form_name']      = isset( $record->form_id ) ? $form->name : '';
1671
		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1672
1673
		if ( ! is_array( $form->options ) ) {
1674
			return;
1675
		}
1676
1677
		foreach ( $form->options as $opt => $value ) {
1678
			if ( isset( $post_values[ $opt ] ) ) {
1679
				$values[ $opt ] = $post_values[ $opt ];
1680
				self::unserialize_or_decode( $values[ $opt ] );
1681
			} else {
1682
				$values[ $opt ] = $value;
1683
			}
1684
		}
1685
1686
		self::fill_form_defaults( $post_values, $values );
1687
	}
1688
1689
	/**
1690
	 * Set to POST value or default
1691
	 */
1692
	private static function fill_form_defaults( $post_values, array &$values ) {
1693
		$form_defaults = FrmFormsHelper::get_default_opts();
1694
1695
		foreach ( $form_defaults as $opt => $default ) {
1696
			if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1697
				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1698
			}
1699
1700
			unset( $opt, $default );
1701
		}
1702
1703
		if ( ! isset( $values['custom_style'] ) ) {
1704
			$values['custom_style'] = self::custom_style_value( $post_values );
1705
		}
1706
1707
		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1708
			if ( ! isset( $values[ $h . '_html' ] ) ) {
1709
				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1710
			}
1711
			unset( $h );
1712
		}
1713
	}
1714
1715
	/**
1716
	 * @since 2.2.10
1717
	 *
1718
	 * @param array $post_values
1719
	 *
1720
	 * @return boolean|int
1721
	 */
1722
	public static function custom_style_value( $post_values ) {
1723
		if ( ! empty( $post_values ) && isset( $post_values['options']['custom_style'] ) ) {
1724
			$custom_style = absint( $post_values['options']['custom_style'] );
1725
		} else {
1726
			$frm_settings = self::get_settings();
1727
			$custom_style = ( $frm_settings->load_style != 'none' );
1728
		}
1729
1730
		return $custom_style;
1731
	}
1732
1733
	public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1734
		if ( is_array( $str ) ) {
1735
			return '';
1736
		}
1737
1738
		$length       = (int) $length;
1739
		$str          = wp_strip_all_tags( $str );
1740
		$original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1741
1742
		if ( $length == 0 ) {
1743
			return '';
1744
		} elseif ( $length <= 10 ) {
1745
			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1746
1747
			return $sub . ( ( $length < $original_len ) ? $continue : '' );
1748
		}
1749
1750
		$sub = '';
1751
		$len = 0;
1752
1753
		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1754
1755
		foreach ( $words as $word ) {
1756
			$part      = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1757
			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1758
			if ( $total_len > $length && substr_count( $sub, ' ' ) ) {
1759
				break;
1760
			}
1761
1762
			$sub .= $part;
1763
			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1764
1765
			if ( substr_count( $sub, ' ' ) > $minword && $total_len >= $length ) {
1766
				break;
1767
			}
1768
1769
			unset( $total_len, $word );
1770
		}
1771
1772
		return $sub . ( ( $len < $original_len ) ? $continue : '' );
1773
	}
1774
1775
	public static function mb_function( $function_names, $args ) {
1776
		$mb_function_name = $function_names[0];
1777
		$function_name    = $function_names[1];
1778
		if ( function_exists( $mb_function_name ) ) {
1779
			$function_name = $mb_function_name;
1780
		}
1781
1782
		return call_user_func_array( $function_name, $args );
1783
	}
1784
1785
	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1786
		if ( empty( $date ) ) {
1787
			return $date;
1788
		}
1789
1790
		if ( empty( $date_format ) ) {
1791
			$date_format = get_option( 'date_format' );
1792
		}
1793
1794
		if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1795
			$frmpro_settings = new FrmProSettings();
1796
			$date            = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1797
		}
1798
1799
		$formatted = self::get_localized_date( $date_format, $date );
1800
1801
		$do_time = ( gmdate( 'H:i:s', strtotime( $date ) ) != '00:00:00' );
1802
		if ( $do_time ) {
1803
			$formatted .= self::add_time_to_date( $time_format, $date );
1804
		}
1805
1806
		return $formatted;
1807
	}
1808
1809
	private static function add_time_to_date( $time_format, $date ) {
1810
		if ( empty( $time_format ) ) {
1811
			$time_format = get_option( 'time_format' );
1812
		}
1813
1814
		$trimmed_format = trim( $time_format );
1815
		$time           = '';
1816
		if ( $time_format && ! empty( $trimmed_format ) ) {
1817
			$time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
1818
		}
1819
1820
		return $time;
1821
	}
1822
1823
	/**
1824
	 * @since 2.0.8
1825
	 */
1826
	public static function get_localized_date( $date_format, $date ) {
1827
		$date = get_date_from_gmt( $date );
1828
1829
		return date_i18n( $date_format, strtotime( $date ) );
1830
	}
1831
1832
	/**
1833
	 * Gets the time ago in words
1834
	 *
1835
	 * @param int $from in seconds
1836
	 * @param int|string $to in seconds
1837
	 *
1838
	 * @return string $time_ago
1839
	 */
1840
	public static function human_time_diff( $from, $to = '', $levels = 1 ) {
1841
		if ( empty( $to ) ) {
1842
			$now = new DateTime();
1843
		} else {
1844
			$now = new DateTime( '@' . $to );
1845
		}
1846
		$ago = new DateTime( '@' . $from );
1847
1848
		// Get the time difference
1849
		$diff_object = $now->diff( $ago );
1850
		$diff        = get_object_vars( $diff_object );
1851
1852
		// Add week amount and update day amount
1853
		$diff['w'] = floor( $diff['d'] / 7 );
1854
		$diff['d'] -= $diff['w'] * 7;
1855
1856
		$time_strings = self::get_time_strings();
1857
1858
		foreach ( $time_strings as $k => $v ) {
1859
			if ( $diff[ $k ] ) {
1860
				$time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
1861
			} else {
1862
				unset( $time_strings[ $k ] );
1863
			}
1864
		}
1865
1866
		$levels_deep     = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
1867
		$time_strings    = array_slice( $time_strings, 0, $levels_deep );
1868
		$time_ago_string = $time_strings ? implode( ' ', $time_strings ) : '0 ' . __( 'seconds', 'formidable' );
1869
1870
		return $time_ago_string;
1871
	}
1872
1873
	/**
1874
	 * Get the translatable time strings
1875
	 *
1876
	 * @since 2.0.20
1877
	 * @return array
1878
	 */
1879
	private static function get_time_strings() {
1880
		return array(
1881
			'y' => array( __( 'year', 'formidable' ), __( 'years', 'formidable' ) ),
1882
			'm' => array( __( 'month', 'formidable' ), __( 'months', 'formidable' ) ),
1883
			'w' => array( __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ),
1884
			'd' => array( __( 'day', 'formidable' ), __( 'days', 'formidable' ) ),
1885
			'h' => array( __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ),
1886
			'i' => array( __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ),
1887
			's' => array( __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) ),
1888
		);
1889
	}
1890
1891
	// Pagination Methods.
1892
1893
	/**
1894
	 * @param integer $current_p
1895
	 */
1896
	public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1897
		return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1898
	}
1899
1900
	/**
1901
	 * @param integer $current_p
1902
	 */
1903
	public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1904
		if ( $current_p == 1 ) {
1905
			return 1;
1906
		} else {
1907
			return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1908
		}
1909
	}
1910
1911
	/**
1912
	 * @return array
1913
	 */
1914
	public static function json_to_array( $json_vars ) {
1915
		$vars = array();
1916
		foreach ( $json_vars as $jv ) {
1917
			$jv_name = explode( '[', $jv['name'] );
1918
			$last    = count( $jv_name ) - 1;
1919
			foreach ( $jv_name as $p => $n ) {
1920
				$name = trim( $n, ']' );
1921
				if ( ! isset( $l1 ) ) {
1922
					$l1 = $name;
1923
				}
1924
1925
				if ( ! isset( $l2 ) ) {
1926
					$l2 = $name;
1927
				}
1928
1929
				if ( ! isset( $l3 ) ) {
1930
					$l3 = $name;
1931
				}
1932
1933
				$this_val = ( $p == $last ) ? $jv['value'] : array();
1934
1935
				switch ( $p ) {
1936
					case 0:
1937
						$l1 = $name;
1938
						self::add_value_to_array( $name, $l1, $this_val, $vars );
1939
						break;
1940
1941
					case 1:
1942
						$l2 = $name;
1943
						self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1944
						break;
1945
1946 View Code Duplication
					case 2:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1947
						$l3 = $name;
1948
						self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1949
						break;
1950
1951 View Code Duplication
					case 3:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1952
						$l4 = $name;
1953
						self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1954
				}
1955
1956
				unset( $this_val, $n );
1957
			}
1958
1959
			unset( $last, $jv );
1960
		}
1961
1962
		return $vars;
1963
	}
1964
1965
	/**
1966
	 * @param string $name
1967
	 * @param string $l1
1968
	 */
1969
	public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1970
		if ( $name == '' ) {
1971
			$vars[] = $val;
1972
		} elseif ( ! isset( $vars[ $l1 ] ) ) {
1973
			$vars[ $l1 ] = $val;
1974
		}
1975
	}
1976
1977
	public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1978
		$tooltips = array(
1979
			'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1980
			'email_to'      => __( 'Add one or more recipient addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].  [admin_email] is the address set in WP General Settings.', 'formidable' ),
1981
			'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1982
			'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1983
			'reply_to'      => __( 'If you would like a different reply to address than the "from" address, add a single address here.  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1984
			'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1985
			/* translators: %1$s: Form name, %2$s: Date */
1986
			'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1987
		);
1988
1989
		if ( ! isset( $tooltips[ $name ] ) ) {
1990
			return;
1991
		}
1992
1993
		if ( 'open' == $class ) {
1994
			echo ' frm_help"';
1995
		} else {
1996
			echo ' class="frm_help"';
1997
		}
1998
1999
		echo ' title="' . esc_attr( $tooltips[ $name ] );
2000
2001
		if ( 'open' != $class ) {
2002
			echo '"';
2003
		}
2004
	}
2005
2006
	/**
2007
	 * Add the current_page class to that page in the form nav
2008
	 */
2009
	public static function select_current_page( $page, $current_page, $action = array() ) {
2010
		if ( $current_page != $page ) {
2011
			return;
2012
		}
2013
2014
		$frm_action = self::simple_get( 'frm_action', 'sanitize_title' );
2015
		if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
2016
			echo ' class="current_page"';
2017
		}
2018
	}
2019
2020
	/**
2021
	 * Prepare and json_encode post content
2022
	 *
2023
	 * @since 2.0
2024
	 *
2025
	 * @param array $post_content
2026
	 *
2027
	 * @return string $post_content ( json encoded array )
2028
	 */
2029
	public static function prepare_and_encode( $post_content ) {
2030
		// Loop through array to strip slashes and add only the needed ones.
2031
		foreach ( $post_content as $key => $val ) {
2032
			// Replace problematic characters (like &quot;)
2033
			$val = str_replace( '&quot;', '"', $val );
2034
2035
			self::prepare_action_slashes( $val, $key, $post_content );
2036
			unset( $key, $val );
2037
		}
2038
2039
		// json_encode the array.
2040
		$post_content = json_encode( $post_content );
2041
2042
		// Add extra slashes for \r\n since WP strips them.
2043
		$post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
2044
2045
		// allow for &quot
2046
		$post_content = str_replace( '&quot;', '\\"', $post_content );
2047
2048
		return $post_content;
2049
	}
2050
2051
	private static function prepare_action_slashes( $val, $key, &$post_content ) {
2052
		if ( ! isset( $post_content[ $key ] ) ) {
2053
			return;
2054
		}
2055
2056
		if ( is_array( $val ) ) {
2057
			foreach ( $val as $k1 => $v1 ) {
2058
				self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
2059
				unset( $k1, $v1 );
2060
			}
2061
		} else {
2062
			// Strip all slashes so everything is the same, no matter where the value is coming from
2063
			$val = stripslashes( $val );
2064
2065
			// Add backslashes before double quotes and forward slashes only
2066
			$post_content[ $key ] = addcslashes( $val, '"\\/' );
2067
		}
2068
	}
2069
2070
	/**
2071
	 * Check for either json or serilized data. This is temporary while transitioning
2072
	 * all data to json.
2073
	 *
2074
	 * @since 4.02.03
2075
	 */
2076
	public static function unserialize_or_decode( &$value ) {
2077
		if ( is_array( $value ) ) {
2078
			return;
2079
		}
2080
2081
		if ( is_serialized( $value ) ) {
2082
			$value = maybe_unserialize( $value );
2083
		} else {
2084
			$value = self::maybe_json_decode( $value, false );
2085
		}
2086
	}
2087
2088
	/**
2089
	 * Decode a JSON string.
2090
	 * Do not switch shortcodes like [24] to array unless intentional ie XML values.
2091
	 */
2092
	public static function maybe_json_decode( $string, $single_to_array = true ) {
2093
		if ( is_array( $string ) ) {
2094
			return $string;
2095
		}
2096
2097
		$new_string = json_decode( $string, true );
2098
		if ( function_exists( 'json_last_error' ) ) {
2099
			// php 5.3+
2100
			$single_value = false;
2101
			if ( ! $single_to_array ) {
2102
				$single_value = is_array( $new_string ) && count( $new_string ) === 1 && isset( $new_string[0] );
2103
			}
2104
			if ( json_last_error() == JSON_ERROR_NONE && is_array( $new_string ) && ! $single_value ) {
2105
				$string = $new_string;
2106
			}
2107
		}
2108
2109
		return $string;
2110
	}
2111
2112
	/**
2113
	 * Reformat the json serialized array in name => value array.
2114
	 *
2115
	 * @since 4.02.03
2116
	 */
2117
	public static function format_form_data( &$form ) {
2118
		$formatted = array();
2119
2120
		foreach ( $form as $input ) {
2121
			if ( ! isset( $input['name'] ) ) {
2122
				continue;
2123
			}
2124
			$key = $input['name'];
2125
			if ( isset( $formatted[ $key ] ) ) {
2126
				if ( is_array( $formatted[ $key ] ) ) {
2127
					$formatted[ $key ][] = $input['value'];
2128
				} else {
2129
					$formatted[ $key ] = array( $formatted[ $key ], $input['value'] );
2130
				}
2131
			} else {
2132
				$formatted[ $key ] = $input['value'];
2133
			}
2134
		}
2135
2136
		parse_str( http_build_query( $formatted ), $form );
2137
	}
2138
2139
	/**
2140
	 * @since 4.02.03
2141
	 */
2142
	public static function maybe_json_encode( $value ) {
2143
		if ( is_array( $value ) ) {
2144
			$value = wp_json_encode( $value );
2145
		}
2146
		return $value;
2147
	}
2148
2149
	/**
2150
	 * @since 1.07.10
2151
	 *
2152
	 * @param string $post_type The name of the post type that may need to be highlighted
2153
	 * echo The javascript to open and highlight the Formidable menu
2154
	 */
2155
	public static function maybe_highlight_menu( $post_type ) {
2156
		global $post;
2157
2158
		if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
2159
			return;
2160
		}
2161
2162
		if ( is_object( $post ) && $post->post_type != $post_type ) {
2163
			return;
2164
		}
2165
2166
		self::load_admin_wide_js();
2167
		echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
2168
	}
2169
2170
	/**
2171
	 * Load the JS file on non-Formidable pages in the admin area
2172
	 *
2173
	 * @since 2.0
2174
	 */
2175
	public static function load_admin_wide_js( $load = true ) {
2176
		$version = self::plugin_version();
2177
		wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
2178
2179
		$global_strings = array(
2180
			'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
2181
			'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
2182
			'url'          => self::plugin_url(),
2183
			'app_url'      => 'https://formidableforms.com/',
2184
			'loading'      => __( 'Loading&hellip;', 'formidable' ),
2185
			'nonce'        => wp_create_nonce( 'frm_ajax' ),
2186
		);
2187
		wp_localize_script( 'formidable_admin_global', 'frmGlobal', $global_strings );
2188
2189
		if ( $load ) {
2190
			wp_enqueue_script( 'formidable_admin_global' );
2191
		}
2192
	}
2193
2194
	/**
2195
	 * @since 2.0.9
2196
	 */
2197
	public static function load_font_style() {
2198
		wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
2199
	}
2200
2201
	/**
2202
	 * @param string $location
2203
	 */
2204
	public static function localize_script( $location ) {
2205
		$ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
2206
		$ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
2207
2208
		$script_strings = array(
2209
			'ajax_url'     => $ajax_url,
2210
			'images_url'   => self::plugin_url() . '/images',
2211
			'loading'      => __( 'Loading&hellip;', 'formidable' ),
2212
			'remove'       => __( 'Remove', 'formidable' ),
2213
			'offset'       => apply_filters( 'frm_scroll_offset', 4 ),
2214
			'nonce'        => wp_create_nonce( 'frm_ajax' ),
2215
			'id'           => __( 'ID', 'formidable' ),
2216
			'no_results'   => __( 'No results match', 'formidable' ),
2217
			'file_spam'    => __( 'That file looks like Spam.', 'formidable' ),
2218
			'calc_error'   => __( 'There is an error in the calculation in the field with key', 'formidable' ),
2219
			'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
2220
		);
2221
		wp_localize_script( 'formidable', 'frm_js', $script_strings );
2222
2223
		if ( $location == 'admin' ) {
2224
			$frm_settings         = self::get_settings();
2225
			$admin_script_strings = array(
2226
				'desc'              => __( '(Click to add description)', 'formidable' ),
2227
				'blank'             => __( '(Blank)', 'formidable' ),
2228
				'no_label'          => __( '(no label)', 'formidable' ),
2229
				'saving'            => esc_attr( __( 'Saving', 'formidable' ) ),
2230
				'saved'             => esc_attr( __( 'Saved', 'formidable' ) ),
2231
				'ok'                => __( 'OK', 'formidable' ),
2232
				'cancel'            => __( 'Cancel', 'formidable' ),
2233
				'default'           => __( 'Default', 'formidable' ),
2234
				'clear_default'     => __( 'Clear default value when typing', 'formidable' ),
2235
				'no_clear_default'  => __( 'Do not clear default value when typing', 'formidable' ),
2236
				'valid_default'     => __( 'Default value will pass form validation', 'formidable' ),
2237
				'no_valid_default'  => __( 'Default value will NOT pass form validation', 'formidable' ),
2238
				'confirm'           => __( 'Are you sure?', 'formidable' ),
2239
				'conf_delete'       => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
2240
				'conf_delete_sec'   => __( 'WARNING: This will delete all fields inside of the section as well.', 'formidable' ),
2241
				'conf_no_repeat'    => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
2242
				'default_unique'    => $frm_settings->unique_msg,
2243
				'default_conf'      => __( 'The entered values do not match', 'formidable' ),
2244
				'enter_email'       => __( 'Enter Email', 'formidable' ),
2245
				'confirm_email'     => __( 'Confirm Email', 'formidable' ),
2246
				'conditional_text'  => __( 'Conditional content here', 'formidable' ),
2247
				'new_option'        => __( 'New Option', 'formidable' ),
2248
				'css_invalid_size'  => __( 'In certain browsers (e.g. Firefox) text will not display correctly if the field height is too small relative to the field padding and text size. Please increase your field height or decrease your field padding.', 'formidable' ),
2249
				'enter_password'    => __( 'Enter Password', 'formidable' ),
2250
				'confirm_password'  => __( 'Confirm Password', 'formidable' ),
2251
				'import_complete'   => __( 'Import Complete', 'formidable' ),
2252
				'updating'          => __( 'Please wait while your site updates.', 'formidable' ),
2253
				'no_save_warning'   => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
2254
				'private'           => __( 'Private', 'formidable' ),
2255
				'jquery_ui_url'     => self::jquery_ui_base_url(),
2256
				'pro_url'           => is_callable( 'FrmProAppHelper::plugin_url' ) ? FrmProAppHelper::plugin_url() : '',
2257
				'no_licenses'       => __( 'No new licenses were found', 'formidable' ),
2258
				'unmatched_parens'  => __( 'This calculation has at least one unmatched ( ) { } [ ].', 'formidable' ),
2259
				'view_shortcodes'   => __( 'This calculation may have shortcodes that work in Views but not forms.', 'formidable' ),
2260
				'text_shortcodes'   => __( 'This calculation may have shortcodes that work in text calculations but not numeric calculations.', 'formidable' ),
2261
				'repeat_limit_min'  => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
2262
				'checkbox_limit'    => __( 'Please select a limit between 0 and 200.', 'formidable' ),
2263
				'install'           => __( 'Install', 'formidable' ),
2264
				'active'            => __( 'Active', 'formidable' ),
2265
				'no_items_found'    => __( 'No items found.', 'formidable' ),
2266
			);
2267
			wp_localize_script( 'formidable_admin', 'frm_admin_js', $admin_script_strings );
2268
		}
2269
	}
2270
2271
	/**
2272
	 * Echo the message on the plugins listing page
2273
	 *
2274
	 * @since 1.07.10
2275
	 *
2276
	 * @param float $min_version The version the add-on requires
2277
	 */
2278
	public static function min_version_notice( $min_version ) {
2279
		$frm_version = self::plugin_version();
2280
2281
		// Check if Formidable meets minimum requirements.
2282
		if ( version_compare( $frm_version, $min_version, '>=' ) ) {
2283
			return;
2284
		}
2285
2286
		$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
2287
		echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' .
2288
			esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
2289
			'</div></td></tr>';
2290
	}
2291
2292
	/**
2293
	 * If Pro is far outdated, show a message.
2294
	 *
2295
	 * @since 4.0.01
2296
	 */
2297
	public static function min_pro_version_notice( $min_version ) {
2298
		if ( ! self::is_formidable_admin() ) {
2299
			// Don't show admin-wide.
2300
			return;
2301
		}
2302
2303
		self::php_version_notice();
2304
2305
		$is_pro = self::pro_is_installed() && class_exists( 'FrmProDb' );
2306
		if ( ! $is_pro || self::meets_min_pro_version( $min_version ) ) {
2307
			return;
2308
		}
2309
2310
		$pro_version = FrmProDb::$plug_version;
0 ignored issues
show
Unused Code introduced by
$pro_version is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2311
		$expired = FrmAddonsController::is_license_expired();
2312
		?>
2313
		<div class="error frm_previous_install">
2314
			<?php
2315
			esc_html_e( 'You are running a version of Formidable Forms that may not be compatible with your version of Formidable Forms Pro.', 'formidable' );
2316
			if ( empty( $expired ) ) {
2317
				echo ' Please <a href="' . esc_url( admin_url( 'plugins.php?s=formidable%20forms%20pro' ) ) . '">update now</a>.';
2318
			} else {
2319
				echo '<br/>Please <a href="https://formidableforms.com/account/downloads/?utm_source=WordPress&utm_medium=outdated">renew now</a> to get the latest Pro version or <a href="https://downloads.wordpress.org/plugin/formidable.<?php echo esc_attr( $pro_version ); ?>.zip">download the previous Lite version</a> to revert.';
2320
			}
2321
			?>
2322
		</div>
2323
		<?php
2324
	}
2325
2326
	/**
2327
	 * If Pro is installed, check the version number.
2328
	 *
2329
	 * @since 4.0.01
2330
	 */
2331
	public static function meets_min_pro_version( $min_version ) {
2332
		return ! class_exists( 'FrmProDb' ) || version_compare( FrmProDb::$plug_version, $min_version, '>=' );
2333
	}
2334
2335
	/**
2336
	 * Show a message if the browser or PHP version is below the recommendations.
2337
	 *
2338
	 * @since 4.0.02
2339
	 */
2340
	private static function php_version_notice() {
2341
		$message = array();
2342
		if ( version_compare( phpversion(), '5.6', '<' ) ) {
2343
			$message[] = __( 'The version of PHP on your server is too low. If this is not corrected, you may see issues with Formidable Forms. Please contact your web host and ask to be updated to PHP 7.0+.', 'formidable' );
2344
		}
2345
2346
		$browser = self::get_server_value( 'HTTP_USER_AGENT' );
2347
		$is_ie   = strpos( $browser, 'MSIE' ) !== false;
2348
		if ( $is_ie ) {
2349
			$message[] = __( 'You are using an outdated browser that is not compatible with Formidable Forms. Please update to a more current browser (we recommend Chrome).', 'formidable' );
2350
		}
2351
2352
		foreach ( $message as $m ) {
2353
			?>
2354
			<div class="error frm_previous_install">
2355
				<?php echo esc_html( $m ); ?>
2356
			</div>
2357
			<?php
2358
		}
2359
	}
2360
2361
	public static function locales( $type = 'date' ) {
2362
		$locales = array(
2363
			'en'     => __( 'English', 'formidable' ),
2364
			'af'     => __( 'Afrikaans', 'formidable' ),
2365
			'sq'     => __( 'Albanian', 'formidable' ),
2366
			'ar'     => __( 'Arabic', 'formidable' ),
2367
			'hy'     => __( 'Armenian', 'formidable' ),
2368
			'az'     => __( 'Azerbaijani', 'formidable' ),
2369
			'eu'     => __( 'Basque', 'formidable' ),
2370
			'bs'     => __( 'Bosnian', 'formidable' ),
2371
			'bg'     => __( 'Bulgarian', 'formidable' ),
2372
			'ca'     => __( 'Catalan', 'formidable' ),
2373
			'zh-HK'  => __( 'Chinese Hong Kong', 'formidable' ),
2374
			'zh-CN'  => __( 'Chinese Simplified', 'formidable' ),
2375
			'zh-TW'  => __( 'Chinese Traditional', 'formidable' ),
2376
			'hr'     => __( 'Croatian', 'formidable' ),
2377
			'cs'     => __( 'Czech', 'formidable' ),
2378
			'da'     => __( 'Danish', 'formidable' ),
2379
			'nl'     => __( 'Dutch', 'formidable' ),
2380
			'en-GB'  => __( 'English/UK', 'formidable' ),
2381
			'eo'     => __( 'Esperanto', 'formidable' ),
2382
			'et'     => __( 'Estonian', 'formidable' ),
2383
			'fo'     => __( 'Faroese', 'formidable' ),
2384
			'fa'     => __( 'Farsi/Persian', 'formidable' ),
2385
			'fil'    => __( 'Filipino', 'formidable' ),
2386
			'fi'     => __( 'Finnish', 'formidable' ),
2387
			'fr'     => __( 'French', 'formidable' ),
2388
			'fr-CA'  => __( 'French/Canadian', 'formidable' ),
2389
			'fr-CH'  => __( 'French/Swiss', 'formidable' ),
2390
			'de'     => __( 'German', 'formidable' ),
2391
			'de-AT'  => __( 'German/Austria', 'formidable' ),
2392
			'de-CH'  => __( 'German/Switzerland', 'formidable' ),
2393
			'el'     => __( 'Greek', 'formidable' ),
2394
			'he'     => __( 'Hebrew', 'formidable' ),
2395
			'iw'     => __( 'Hebrew', 'formidable' ),
2396
			'hi'     => __( 'Hindi', 'formidable' ),
2397
			'hu'     => __( 'Hungarian', 'formidable' ),
2398
			'is'     => __( 'Icelandic', 'formidable' ),
2399
			'id'     => __( 'Indonesian', 'formidable' ),
2400
			'it'     => __( 'Italian', 'formidable' ),
2401
			'ja'     => __( 'Japanese', 'formidable' ),
2402
			'ko'     => __( 'Korean', 'formidable' ),
2403
			'lv'     => __( 'Latvian', 'formidable' ),
2404
			'lt'     => __( 'Lithuanian', 'formidable' ),
2405
			'ms'     => __( 'Malaysian', 'formidable' ),
2406
			'no'     => __( 'Norwegian', 'formidable' ),
2407
			'pl'     => __( 'Polish', 'formidable' ),
2408
			'pt'     => __( 'Portuguese', 'formidable' ),
2409
			'pt-BR'  => __( 'Portuguese/Brazilian', 'formidable' ),
2410
			'pt-PT'  => __( 'Portuguese/Portugal', 'formidable' ),
2411
			'ro'     => __( 'Romanian', 'formidable' ),
2412
			'ru'     => __( 'Russian', 'formidable' ),
2413
			'sr'     => __( 'Serbian', 'formidable' ),
2414
			'sr-SR'  => __( 'Serbian', 'formidable' ),
2415
			'sk'     => __( 'Slovak', 'formidable' ),
2416
			'sl'     => __( 'Slovenian', 'formidable' ),
2417
			'es'     => __( 'Spanish', 'formidable' ),
2418
			'es-419' => __( 'Spanish/Latin America', 'formidable' ),
2419
			'sv'     => __( 'Swedish', 'formidable' ),
2420
			'ta'     => __( 'Tamil', 'formidable' ),
2421
			'th'     => __( 'Thai', 'formidable' ),
2422
			'tu'     => __( 'Turkish', 'formidable' ),
2423
			'tr'     => __( 'Turkish', 'formidable' ),
2424
			'uk'     => __( 'Ukranian', 'formidable' ),
2425
			'vi'     => __( 'Vietnamese', 'formidable' ),
2426
		);
2427
2428
		if ( $type === 'captcha' ) {
2429
			// remove the languages unavailable for the captcha
2430
			$unset = array( 'af', 'sq', 'hy', 'az', 'eu', 'bs', 'zh-HK', 'eo', 'et', 'fo', 'fr-CH', 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu' );
2431
		} else {
2432
			// remove the languages unavailable for the datepicker
2433
			$unset = array( 'fil', 'fr-CA', 'de-AT', 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', 'es-419', 'tr' );
2434
		}
2435
2436
		$locales = array_diff_key( $locales, array_flip( $unset ) );
2437
		$locales = apply_filters( 'frm_locales', $locales );
2438
2439
		return $locales;
2440
	}
2441
2442
	/**
2443
	 * @deprecated 4.0
2444
	 */
2445
	public static function insert_opt_html( $args ) {
2446
		_deprecated_function( __METHOD__, '4.0', 'FrmFormsHelper::insert_opt_html' );
2447
		FrmFormsHelper::insert_opt_html( $args );
2448
	}
2449
2450
	/**
2451
	 * Used to filter shortcode in text widgets
2452
	 *
2453
	 * @deprecated 2.5.4
2454
	 * @codeCoverageIgnore
2455
	 */
2456
	public static function widget_text_filter_callback( $matches ) {
2457
		return FrmDeprecated::widget_text_filter_callback( $matches );
2458
	}
2459
2460
	/**
2461
	 * @deprecated 3.01
2462
	 * @codeCoverageIgnore
2463
	 */
2464
	public static function sanitize_array( &$values ) {
2465
		FrmDeprecated::sanitize_array( $values );
2466
	}
2467
2468
	/**
2469
	 * @param array $settings
2470
	 * @param string $group
2471
	 *
2472
	 * @since 2.0.6
2473
	 * @deprecated 2.05.06
2474
	 * @codeCoverageIgnore
2475
	 */
2476
	public static function save_settings( $settings, $group ) {
2477
		return FrmDeprecated::save_settings( $settings, $group );
2478
	}
2479
2480
	/**
2481
	 * @since 2.0.4
2482
	 * @deprecated 2.05.06
2483
	 * @codeCoverageIgnore
2484
	 */
2485
	public static function save_json_post( $settings ) {
2486
		return FrmDeprecated::save_json_post( $settings );
2487
	}
2488
2489
	/**
2490
	 * @since 2.0
2491
	 * @deprecated 2.05.06
2492
	 * @codeCoverageIgnore
2493
	 *
2494
	 * @param string $cache_key The unique name for this cache
2495
	 * @param string $group The name of the cache group
2496
	 * @param string $query If blank, don't run a db call
2497
	 * @param string $type The wpdb function to use with this query
2498
	 *
2499
	 * @return mixed $results The cache or query results
2500
	 */
2501
	public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
2502
		return FrmDeprecated::check_cache( $cache_key, $group, $query, $type, $time );
2503
	}
2504
2505
	/**
2506
	 * @deprecated 2.05.06
2507
	 * @codeCoverageIgnore
2508
	 */
2509
	public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
2510
		return FrmDeprecated::set_cache( $cache_key, $results, $group, $time );
2511
	}
2512
2513
	/**
2514
	 * @deprecated 2.05.06
2515
	 * @codeCoverageIgnore
2516
	 */
2517
	public static function add_key_to_group_cache( $key, $group ) {
2518
		FrmDeprecated::add_key_to_group_cache( $key, $group );
2519
	}
2520
2521
	/**
2522
	 * @deprecated 2.05.06
2523
	 * @codeCoverageIgnore
2524
	 */
2525
	public static function get_group_cached_keys( $group ) {
2526
		return FrmDeprecated::get_group_cached_keys( $group );
2527
	}
2528
2529
	/**
2530
	 * @since 2.0
2531
	 * @deprecated 2.05.06
2532
	 * @codeCoverageIgnore
2533
	 * @return mixed The cached value or false
2534
	 */
2535
	public static function check_cache_and_transient( $cache_key ) {
2536
		return FrmDeprecated::check_cache( $cache_key );
2537
	}
2538
2539
	/**
2540
	 * @since 2.0
2541
	 * @deprecated 2.05.06
2542
	 * @codeCoverageIgnore
2543
	 *
2544
	 * @param string $cache_key
2545
	 */
2546
	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
2547
		FrmDeprecated::delete_cache_and_transient( $cache_key, $group );
2548
	}
2549
2550
	/**
2551
	 * @since 2.0
2552
	 * @deprecated 2.05.06
2553
	 * @codeCoverageIgnore
2554
	 *
2555
	 * @param string $group The name of the cache group
2556
	 */
2557
	public static function cache_delete_group( $group ) {
2558
		FrmDeprecated::cache_delete_group( $group );
2559
	}
2560
2561
	/**
2562
	 * @since 1.07.10
2563
	 * @deprecated 2.05.06
2564
	 * @codeCoverageIgnore
2565
	 *
2566
	 * @param string $term The value to escape
2567
	 *
2568
	 * @return string The escaped value
2569
	 */
2570
	public static function esc_like( $term ) {
2571
		return FrmDeprecated::esc_like( $term );
2572
	}
2573
2574
	/**
2575
	 * @param string $order_query
2576
	 *
2577
	 * @deprecated 2.05.06
2578
	 * @codeCoverageIgnore
2579
	 */
2580
	public static function esc_order( $order_query ) {
2581
		return FrmDeprecated::esc_order( $order_query );
2582
	}
2583
2584
	/**
2585
	 * @deprecated 2.05.06
2586
	 * @codeCoverageIgnore
2587
	 */
2588
	public static function esc_order_by( &$order_by ) {
2589
		FrmDeprecated::esc_order_by( $order_by );
2590
	}
2591
2592
	/**
2593
	 * @param string $limit
2594
	 *
2595
	 * @deprecated 2.05.06
2596
	 * @codeCoverageIgnore
2597
	 */
2598
	public static function esc_limit( $limit ) {
2599
		return FrmDeprecated::esc_limit( $limit );
2600
	}
2601
2602
	/**
2603
	 * @since 2.0
2604
	 * @deprecated 2.05.06
2605
	 * @codeCoverageIgnore
2606
	 */
2607
	public static function prepare_array_values( $array, $type = '%s' ) {
2608
		return FrmDeprecated::prepare_array_values( $array, $type );
2609
	}
2610
2611
	/**
2612
	 * @deprecated 2.05.06
2613
	 * @codeCoverageIgnore
2614
	 */
2615
	public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
2616
		return FrmDeprecated::prepend_and_or_where( $starts_with, $where );
2617
	}
2618
}
2619