Completed
Push — master ( 46b435...c317c9 )
by Stephanie
02:52
created

FrmAppHelper::is_true()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 = 88; //version of the database we are moving to
8
	public static $pro_db_version = 37; //deprecated
9
	public static $font_version = 3;
10
11
	/**
12
	 * @since 2.0
13
	 */
14
	public static $plug_version = '3.04.03';
15
16
    /**
17
     * @since 1.07.02
18
     *
19
     * @param none
20
     * @return string The version of this plugin
21
     */
22
    public static function plugin_version() {
23
        return self::$plug_version;
24
    }
25
26
	public static function plugin_folder() {
27
		return basename( self::plugin_path() );
28
	}
29
30
	public static function plugin_path() {
31
		return dirname( dirname( dirname( __FILE__ ) ) );
32
	}
33
34
    public static function plugin_url() {
35
        //prevously FRM_URL constant
36
		return plugins_url( '', self::plugin_path() . '/formidable.php' );
37
    }
38
39
	public static function relative_plugin_url() {
40
		return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
41
	}
42
43
    /**
44
     * @return string Site URL
45
     */
46
    public static function site_url() {
47
        return site_url();
48
    }
49
50
    /**
51
     * Get the name of this site
52
     * Used for [sitename] shortcode
53
     *
54
     * @since 2.0
55
     * @return string
56
     */
57
	public static function site_name() {
58
		return get_option( 'blogname' );
59
	}
60
61
	public static function make_affiliate_url( $url ) {
62
		$affiliate_id = self::get_affiliate();
63
		if ( ! empty( $affiliate_id ) ) {
64
			$url = str_replace( array( 'http://', 'https://' ), '', $url );
65
			$url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
66
		}
67
		return $url;
68
	}
69
70
	public static function get_affiliate() {
71
		return absint( apply_filters( 'frm_affiliate_id', 0 ) );
72
	}
73
74
	/**
75
	 * @since 3.04.02
76
	 */
77
	public static function admin_upgrade_link( $medium, $page = '' ) {
78
		if ( empty( $page ) ) {
79
			$page = 'https://formidableforms.com/pricing-lite/';
80
		} else {
81
			$page = 'https://formidableforms.com/' . $page;
82
		}
83
		$query_args = array(
84
			'utm_source'   => 'WordPress',
85
			'utm_medium'   => $medium,
86
			'utm_campaign' => 'liteplugin',
87
		);
88
		return add_query_arg( $query_args, $page );
89
	}
90
91
    /**
92
     * Get the Formidable settings
93
     *
94
     * @since 2.0
95
     *
96
     * @param None
97
     * @return FrmSettings $frm_setings
98
     */
99
	public static function get_settings() {
100
		global $frm_settings;
101
		if ( empty( $frm_settings ) ) {
102
			$frm_settings = new FrmSettings();
103
		}
104
		return $frm_settings;
105
	}
106
107
	public static function get_menu_name() {
108
		$frm_settings = FrmAppHelper::get_settings();
109
		return $frm_settings->menu;
110
	}
111
112
	/**
113
	 * @since 3.04.04
114
	 */
115
	public static function svg_logo( $atts = array() ) {
116
		$defaults = array(
117
			'height' => 18,
118
			'width'  => 18,
119
			'fill'   => '#4d4d4d',
120
			'orange' => '#f05a24',
121
		);
122
		$atts = array_merge( $defaults, $atts );
123
		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'] ) . '">
124
				<defs />
125
				<rect fill="' . esc_attr( $atts['orange'] ) . '" x="289.64" y="383.96" width="140" height="76" />
126
				<path fill="' . esc_attr( $atts['fill'] ) . '" d="M400.21,147H200.12c-17,0-30.48,12.2-30.48,29.31V218h260V147Z" />
127
				<path fill="' . esc_attr( $atts['fill'] ) . '" d="M397.86,264H169.64V460h75V340H397.86A32.22,32.22,0,0,0,428,318.56a24.29,24.29,0,0,0,1.66-8.69V264Z" />
128
				<path fill="' . esc_attr( $atts['fill'] ) . '" d="M299.84,601.37A300.26,300.26,0,0,1,0,300.68,299.84,299.84,0,1,1,511.85,513.3,297.44,297.44,0,0,1,299.84,601.37Zm0-563A261.94,261.94,0,0,0,38.26,300.68,261.58,261.58,0,1,0,484.8,115.2,259.47,259.47,0,0,0,299.84,38.37Z" />
129
			</svg>';
130
	}
131
132
	/**
133
	 * @since 2.02.04
134
	 */
135
	public static function ips_saved() {
136
		$frm_settings = self::get_settings();
137
		return ! $frm_settings->no_ips;
138
	}
139
140
	public static function pro_is_installed() {
141
		return apply_filters( 'frm_pro_installed', false );
142
	}
143
144
	public static function is_formidable_admin() {
145
		$page = self::simple_get( 'page', 'sanitize_title' );
146
		$is_formidable = strpos( $page, 'formidable' ) !== false;
147
		if ( empty( $page ) ) {
148
			global $pagenow;
149
			$post_type = self::simple_get( 'post_type', 'sanitize_title' );
150
			$is_formidable = ( $post_type == 'frm_display' );
151
			if ( empty( $post_type ) && $pagenow == 'post.php' ) {
152
				global $post;
153
				$is_formidable = ( $post && $post->post_type == 'frm_display' );
154
			}
155
		}
156
		return $is_formidable;
157
	}
158
159
    /**
160
     * Check for certain page in Formidable settings
161
     *
162
     * @since 2.0
163
     *
164
     * @param string $page The name of the page to check
165
     * @return boolean
166
     */
167
	public static function is_admin_page( $page = 'formidable' ) {
168
        global $pagenow;
169
		$get_page = self::simple_get( 'page', 'sanitize_title' );
170
        if ( $pagenow ) {
171
			// allow this to be true during ajax load i.e. ajax form builder loading
172
			return ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page;
173
        }
174
175
		return is_admin() && $get_page == $page;
176
    }
177
178
    /**
179
     * Check for the form preview page
180
     *
181
     * @since 2.0
182
     *
183
     * @param None
184
     * @return boolean
185
     */
186
    public static function is_preview_page() {
187
        global $pagenow;
188
		$action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
189
		return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
190
    }
191
192
    /**
193
     * Check for ajax except the form preview page
194
     *
195
     * @since 2.0
196
     *
197
     * @param None
198
     * @return boolean
199
     */
200
    public static function doing_ajax() {
201
        return self::wp_doing_ajax() && ! self::is_preview_page();
202
    }
203
204
	public static function js_suffix() {
205
		return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
206
	}
207
208
	/**
209
	 * Use the WP 4.7 wp_doing_ajax function
210
	 * @since 2.05.07
211
	 */
212
	public static function wp_doing_ajax() {
213
		if ( function_exists( 'wp_doing_ajax' ) ) {
214
			$doing_ajax = wp_doing_ajax();
215
		} else {
216
			$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
217
		}
218
		return $doing_ajax;
219
	}
220
221
	/**
222
	 * @since 2.0.8
223
	 */
224
	public static function prevent_caching() {
225
		global $frm_vars;
226
		return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
227
	}
228
229
    /**
230
     * Check if on an admin page
231
     *
232
     * @since 2.0
233
     *
234
     * @param None
235
     * @return boolean
236
     */
237
    public static function is_admin() {
238
        return is_admin() && ! self::wp_doing_ajax();
239
    }
240
241
    /**
242
     * Check if value contains blank value or empty array
243
     *
244
     * @since 2.0
245
     * @param mixed $value - value to check
246
	 * @param string
247
     * @return boolean
248
     */
249
    public static function is_empty_value( $value, $empty = '' ) {
250
        return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
251
    }
252
253
    public static function is_not_empty_value( $value, $empty = '' ) {
254
        return ! self::is_empty_value( $value, $empty );
255
    }
256
257
    /**
258
     * Get any value from the $_SERVER
259
     *
260
     * @since 2.0
261
     * @param string $value
262
     * @return string
263
     */
264
	public static function get_server_value( $value ) {
265
        return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
266
    }
267
268
    /**
269
     * Check for the IP address in several places
270
     * Used by [ip] shortcode
271
     *
272
     * @return string The IP address of the current user
273
     */
274
    public static function get_ip_address() {
275
		$ip = '';
276
		foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
277
            if ( ! isset( $_SERVER[ $key ] ) ) {
278
                continue;
279
            }
280
281
            foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
282
				$ip = trim( $ip ); // just to be safe
283
284
				if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
285
                    return sanitize_text_field( $ip );
286
                }
287
            }
288
        }
289
290
		return sanitize_text_field( $ip );
291
    }
292
293
    public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
294
		if ( strpos( $param, '[' ) ) {
295
			$params = explode( '[', $param );
296
            $param = $params[0];
297
        }
298
299
		if ( $src == 'get' ) {
300
            $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
301
            if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
302
                $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
303
            }
304
			self::sanitize_value( $sanitize, $value );
305
		} else {
306
			$value = self::get_simple_request(
307
				array(
308
					'type'     => $src,
309
					'param'    => $param,
310
					'default'  => $default,
311
					'sanitize' => $sanitize,
312
				)
313
			);
314
		}
315
316
		if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
317
			foreach ( $params as $k => $p ) {
318
				if ( ! $k || ! is_array( $value ) ) {
319
					continue;
320
				}
321
322
				$p = trim( $p, ']' );
323
				$value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
324
			}
325
		}
326
327
        return $value;
328
    }
329
330 View Code Duplication
	public static function get_post_param( $param, $default = '', $sanitize = '' ) {
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...
331
		return self::get_simple_request(
332
			array(
333
				'type'     => 'post',
334
				'param'    => $param,
335
				'default'  => $default,
336
				'sanitize' => $sanitize,
337
			)
338
		);
339
	}
340
341
	/**
342
	 * @since 2.0
343
	 *
344
	 * @param string $param
345
	 * @param string $sanitize
346
	 * @param string $default
347
	 * @return string|array
348
	 */
349 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...
350
		return self::get_simple_request(
351
			array(
352
				'type'     => 'get',
353
				'param'    => $param,
354
				'default'  => $default,
355
				'sanitize' => $sanitize,
356
			)
357
		);
358
	}
359
360
	/**
361
	 * Get a GET/POST/REQUEST value and sanitize it
362
	 *
363
	 * @since 2.0.6
364
	 * @param array $args
365
	 * @return string|array
366
	 */
367
	public static function get_simple_request( $args ) {
368
		$defaults = array(
369
			'param'    => '',
370
			'default'  => '',
371
			'type'     => 'get',
372
			'sanitize' => 'sanitize_text_field',
373
		);
374
		$args = wp_parse_args( $args, $defaults );
375
376
		$value = $args['default'];
377
		if ( $args['type'] == 'get' ) {
378
			if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
379
				$value = $_GET[ $args['param'] ];
380
			}
381
		} else if ( $args['type'] == 'post' ) {
382
			if ( isset( $_POST[ $args['param'] ] ) ) {
383
				$value = stripslashes_deep( maybe_unserialize( $_POST[ $args['param'] ] ) );
384
			}
385
		} else {
386
			if ( isset( $_REQUEST[ $args['param'] ] ) ) {
387
				$value = $_REQUEST[ $args['param'] ];
388
			}
389
		}
390
391
		self::sanitize_value( $args['sanitize'], $value );
392
		return $value;
393
	}
394
395
	/**
396
	* Preserve backslashes in a value, but make sure value doesn't get compounding slashes
397
	*
398
	* @since 2.0.8
399
	* @param string $value
400
	* @return string $value
401
	*/
402
	public static function preserve_backslashes( $value ) {
403
		// If backslashes have already been added, don't add them again
404
		if ( strpos( $value, '\\\\' ) === false ) {
405
			$value = addslashes( $value );
406
		}
407
		return $value;
408
	}
409
410
	public static function sanitize_value( $sanitize, &$value ) {
411
		if ( ! empty( $sanitize ) ) {
412
			if ( is_array( $value ) ) {
413
				$temp_values = $value;
414
				foreach ( $temp_values as $k => $v ) {
415
					FrmAppHelper::sanitize_value( $sanitize, $value[ $k ] );
416
				}
417
			} else {
418
				$value = call_user_func( $sanitize, $value );
419
			}
420
		}
421
	}
422
423
    public static function sanitize_request( $sanitize_method, &$values ) {
424
        $temp_values = $values;
425
        foreach ( $temp_values as $k => $val ) {
426
            if ( isset( $sanitize_method[ $k ] ) ) {
427
				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
428
            }
429
        }
430
    }
431
432
	/**
433
	 * Sanitize the value, and allow some HTML
434
	 * @since 2.0
435
	 * @param string $value
436
	 * @param array|string $allowed 'all' for everything included as defaults
437
	 * @return string
438
	 */
439
	public static function kses( $value, $allowed = array() ) {
440
		$allowed_html = self::allowed_html( $allowed );
441
442
		return wp_kses( $value, $allowed_html );
443
	}
444
445
	/**
446
	 * @since 2.05.03
447
	 */
448
	private static function allowed_html( $allowed ) {
449
		$html = self::safe_html();
450
		$allowed_html = array();
451
		if ( $allowed == 'all' ) {
452
			$allowed_html = $html;
453
		} elseif ( ! empty( $allowed ) ) {
454
			foreach ( (array) $allowed as $a ) {
455
				$allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
456
			}
457
		}
458
459
		return apply_filters( 'frm_striphtml_allowed_tags', $allowed_html );
460
	}
461
462
	/**
463
	 * @since 2.05.03
464
	 */
465
	private static function safe_html() {
466
		$allow_class = array(
467
			'class' => array(),
468
			'id'    => array(),
469
		);
470
471
		return array(
472
			'a' => array(
473
				'class' => array(),
474
				'href'  => array(),
475
				'id'    => array(),
476
				'rel'   => array(),
477
				'target' => array(),
478
				'title' => array(),
479
			),
480
			'abbr' => array(
481
				'title' => array(),
482
			),
483
			'aside' => $allow_class,
484
			'b' => array(),
485
			'blockquote' => array(
486
				'cite'  => array(),
487
			),
488
			'br'   => array(),
489
			'cite' => array(
490
				'title' => array(),
491
			),
492
			'code' => array(),
493
			'del'  => array(
494
				'datetime' => array(),
495
				'title' => array(),
496
			),
497
			'dd'  => array(),
498
			'div' => array(
499
				'class' => array(),
500
				'id'    => array(),
501
				'title' => array(),
502
				'style' => array(),
503
			),
504
			'dl'  => array(),
505
			'dt'  => array(),
506
			'em'  => array(),
507
			'h1'  => $allow_class,
508
			'h2'  => $allow_class,
509
			'h3'  => $allow_class,
510
			'h4'  => $allow_class,
511
			'h5'  => $allow_class,
512
			'h6'  => $allow_class,
513
			'i'   => array(
514
				'class' => array(),
515
				'id'    => array(),
516
				'icon'  => array(),
517
			),
518
			'img' => array(
519
				'alt'    => array(),
520
				'class'  => array(),
521
				'height' => array(),
522
				'id'     => array(),
523
				'src'    => array(),
524
				'width'  => array(),
525
			),
526
			'li'  => $allow_class,
527
			'ol'  => $allow_class,
528
			'p'   => $allow_class,
529
			'pre' => array(),
530
			'q'   => array(
531
				'cite' => array(),
532
				'title' => array(),
533
			),
534
			'section' => $allow_class,
535
			'span' => array(
536
				'class' => array(),
537
				'id'    => array(),
538
				'title' => array(),
539
				'style' => array(),
540
			),
541
			'strike' => array(),
542
			'strong' => array(),
543
			'ul' => $allow_class,
544
		);
545
	}
546
547
    /**
548
     * Used when switching the action for a bulk action
549
     * @since 2.0
550
     */
551
	public static function remove_get_action() {
552
		if ( ! isset( $_GET ) ) {
553
			return;
554
		}
555
556
        $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
557
        if ( ! empty( $new_action ) ) {
558
			$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
559
        }
560
    }
561
562
    /**
563
     * Check the WP query for a parameter
564
     *
565
     * @since 2.0
566
     * @return string|array
567
     */
568
    public static function get_query_var( $value, $param ) {
569
        if ( $value != '' ) {
570
            return $value;
571
        }
572
573
        global $wp_query;
574
        if ( isset( $wp_query->query_vars[ $param ] ) ) {
575
            $value = $wp_query->query_vars[ $param ];
576
        }
577
578
        return $value;
579
    }
580
581
	/**
582
	 * @since 3.0
583
	 */
584
	public static function get_admin_header( $atts ) {
585
		$has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) );
586
		include( self::plugin_path() . '/classes/views/shared/admin-header.php' );
587
	}
588
589
	/**
590
	 * @since 3.0
591
	 */
592
	public static function add_new_item_link( $atts ) {
593
		if ( isset( $atts['new_link'] ) && ! empty( $atts['new_link'] ) ) { ?>
594
			<a href="<?php echo esc_url( $atts['new_link'] ) ?>" class="add-new-h2 frm_animate_bg"><?php esc_html_e( 'Add New', 'formidable' ); ?></a>
595
		<?php
596
		} elseif ( isset( $atts['link_hook'] ) ) {
597
			do_action( $atts['link_hook']['hook'], $atts['link_hook']['param'] );
598
		}
599
	}
600
601
    /**
602
     * @param string $type
603
     */
604
    public static function trigger_hook_load( $type, $object = null ) {
605
        // only load the form hooks once
606
		$hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
607
        if ( ! $hooks_loaded ) {
608
			do_action( 'frm_load_' . $type . '_hooks' );
609
        }
610
    }
611
612
	/**
613
	 * Save all front-end js scripts into a single file
614
	 *
615
	 * @since 3.0
616
	 */
617
	public static function save_combined_js() {
618
		$file_atts = apply_filters(
619
			'frm_js_location',
620
			array(
621
				'file_name' => 'frm.min.js',
622
				'new_file_path' => FrmAppHelper::plugin_path() . '/js',
623
			)
624
		);
625
		$new_file = new FrmCreateFile( $file_atts );
626
627
		$files = array(
628
			FrmAppHelper::plugin_path() . '/js/jquery/jquery.placeholder.min.js',
629
			FrmAppHelper::plugin_path() . '/js/formidable.min.js',
630
		);
631
		$files = apply_filters( 'frm_combined_js_files', $files );
632
		$new_file->combine_files( $files );
633
	}
634
635
    /**
636
     * Check a value from a shortcode to see if true or false.
637
     * True when value is 1, true, 'true', 'yes'
638
     *
639
     * @since 1.07.10
640
     *
641
     * @param string $value The value to compare
642
     * @return boolean True or False
643
     */
644
	public static function is_true( $value ) {
645
        return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
646
    }
647
648
	public static function get_pages() {
649
		$query = array(
650
			'post_type'   => 'page',
651
			'post_status' => array( 'publish', 'private' ),
652
			'numberposts' => -1,
0 ignored issues
show
introduced by
Disabling pagination is prohibited in VIP context, do not set numberposts to -1 ever.
Loading history...
653
			'orderby'     => 'title',
654
			'order'       => 'ASC',
655
		);
656
		return get_posts( $query );
657
	}
658
659
    public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
660
        $pages = self::get_pages();
661
		$selected = self::get_post_param( $field_name, $page_id, 'absint' );
662
    ?>
663
		<select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" class="frm-pages-dropdown">
664
            <option value=""> </option>
665
            <?php foreach ( $pages as $page ) { ?>
666
				<option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ); ?>>
667
					<?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?>
668
				</option>
669
            <?php } ?>
670
        </select>
671
    <?php
672
    }
673
674
	public static function post_edit_link( $post_id ) {
675
		$post = get_post( $post_id );
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
676
        if ( $post ) {
677
			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
678
			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
679
        }
680
        return '';
681
    }
682
683
	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
684
		?>
685
		<select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" <?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?> class="frm_multiselect">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
686
			<?php self::roles_options( $capability ); ?>
687
		</select>
688
		<?php
689
	}
690
691
	public static function roles_options( $capability ) {
692
        global $frm_vars;
693
		if ( isset( $frm_vars['editable_roles'] ) ) {
694
            $editable_roles = $frm_vars['editable_roles'];
695
        } else {
696
            $editable_roles = get_editable_roles();
697
            $frm_vars['editable_roles'] = $editable_roles;
698
        }
699
700
        foreach ( $editable_roles as $role => $details ) {
701
			$name = translate_user_role( $details['name'] );
702
			?>
703
		<option value="<?php echo esc_attr( $role ); ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ); ?> </option>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'in_array'
Loading history...
704
<?php
705
			unset( $role, $details );
706
        }
707
    }
708
709
	public static function frm_capabilities( $type = 'auto' ) {
710
        $cap = array(
711
            'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
712
            'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
713
            'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
714
            'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
715
            'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
716
            'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
717
        );
718
719
		if ( ! self::pro_is_installed() && 'pro' != $type ) {
720
            return $cap;
721
        }
722
723
        $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
724
        $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
725
        $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
726
        $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
727
728
        return $cap;
729
    }
730
731
	public static function user_has_permission( $needed_role ) {
732
        if ( $needed_role == '-1' ) {
733
            return false;
734
		}
735
736
        // $needed_role will be equal to blank if "Logged-in users" is selected
737
        if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
738
            return true;
739
        }
740
741
        $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
742
        foreach ( $roles as $role ) {
743
			if ( current_user_can( $role ) ) {
744
        		return true;
745
			}
746
        	if ( $role == $needed_role ) {
747
        		break;
748
			}
749
        }
750
        return false;
751
    }
752
753
    /**
754
     * Make sure administrators can see Formidable menu
755
     *
756
     * @since 2.0
757
     */
758
    public static function maybe_add_permissions() {
759
		self::force_capability( 'frm_view_entries' );
760
761
		if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
762
			return;
763
		}
764
765
		$user_id = get_current_user_id();
766
		$user = new WP_User( $user_id );
767
        $frm_roles = self::frm_capabilities();
768
        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
769
			$user->add_cap( $frm_role );
770
			unset( $frm_role, $frm_role_description );
771
        }
772
    }
773
774
	/**
775
	 * Make sure admins have permission to see the menu items
776
	 * @since 2.0.6
777
	 */
778
	public static function force_capability( $cap = 'frm_change_settings' ) {
779
		if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
780
			$role = get_role( 'administrator' );
781
			$frm_roles = self::frm_capabilities();
782
			foreach ( $frm_roles as $frm_role => $frm_role_description ) {
783
				$role->add_cap( $frm_role );
784
			}
785
		}
786
	}
787
788
    /**
789
     * Check if the user has permision for action.
790
     * Return permission message and stop the action if no permission
791
     * @since 2.0
792
     * @param string $permission
793
     */
794
	public static function permission_check( $permission, $show_message = 'show' ) {
795
		$permission_error = self::permission_nonce_error( $permission );
796
        if ( $permission_error !== false ) {
797
            if ( 'hide' == $show_message ) {
798
                $permission_error = '';
799
            }
800
			wp_die( esc_html( $permission_error ) );
801
        }
802
    }
803
804
    /**
805
     * Check user permission and nonce
806
     * @since 2.0
807
     * @param string $permission
808
     * @return false|string The permission message or false if allowed
809
     */
810
	public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
811
		if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
812
			$frm_settings = self::get_settings();
813
			return $frm_settings->admin_permission;
814
		}
815
816
		$error = false;
817
		if ( empty( $nonce_name ) ) {
818
            return $error;
819
        }
820
821
        if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
822
            $frm_settings = self::get_settings();
823
            $error = $frm_settings->admin_permission;
824
        }
825
826
        return $error;
827
    }
828
829
    public static function checked( $values, $current ) {
830
		if ( self::check_selected( $values, $current ) ) {
831
            echo ' checked="checked"';
832
		}
833
    }
834
835
	public static function check_selected( $values, $current ) {
836
		$values = self::recursive_function_map( $values, 'trim' );
837
		$values = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
838
		$current = htmlspecialchars_decode( trim( $current ) );
839
840
		return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
841
	}
842
843
	public static function recursive_function_map( $value, $function ) {
844
		if ( is_array( $value ) ) {
845
			$original_function = $function;
846
			if ( count( $value ) ) {
847
				$function = explode( ', ', FrmDb::prepare_array_values( $value, $function ) );
848
			} else {
849
				$function = array( $function );
850
			}
851
			if ( ! self::is_assoc( $value ) ) {
852
				$value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
853
			} else {
854
				foreach ( $value as $k => $v ) {
855
					if ( ! is_array( $v ) ) {
856
						$value[ $k ] = call_user_func( $original_function, $v );
857
					}
858
				}
859
			}
860
		} else {
861
			$value = call_user_func( $function, $value );
862
		}
863
864
		return $value;
865
	}
866
867
	public static function is_assoc( $array ) {
868
		return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
869
	}
870
871
    /**
872
     * Flatten a multi-dimensional array
873
     */
874
	public static function array_flatten( $array, $keys = 'keep' ) {
875
        $return = array();
876
        foreach ( $array as $key => $value ) {
877
			if ( is_array( $value ) ) {
878
				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
879
            } else {
880
				if ( $keys == 'keep' ) {
881
					$return[ $key ] = $value;
882
				} else {
883
					$return[] = $value;
884
				}
885
            }
886
        }
887
        return $return;
888
    }
889
890
	public static function esc_textarea( $text, $is_rich_text = false ) {
891
		$safe_text = str_replace( '&quot;', '"', $text );
892
		if ( ! $is_rich_text ) {
893
			$safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
894
		}
895
		$safe_text = str_replace( '&amp;', '&', $safe_text );
896
		return apply_filters( 'esc_textarea', $safe_text, $text );
897
	}
898
899
    /**
900
     * Add auto paragraphs to text areas
901
     * @since 2.0
902
     */
903
	public static function use_wpautop( $content ) {
904
		if ( apply_filters( 'frm_use_wpautop', true ) ) {
905
			$content = wpautop( str_replace( '<br>', '<br />', $content ) );
906
		}
907
		return $content;
908
	}
909
910
	public static function replace_quotes( $val ) {
911
        //Replace double quotes
912
		$val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
913
        //Replace single quotes
914
        $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
915
        return $val;
916
    }
917
918
    /**
919
     * @since 2.0
920
     * @return string The base Google APIS url for the current version of jQuery UI
921
     */
922
    public static function jquery_ui_base_url() {
923
		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
924
		$url = apply_filters( 'frm_jquery_ui_base_url', $url );
925
        return $url;
926
    }
927
928
    /**
929
     * @param string $handle
930
     */
931
	public static function script_version( $handle, $default = 0 ) {
932
		global $wp_scripts;
933
		if ( ! $wp_scripts ) {
934
			return $default;
935
		}
936
937
		$ver = $default;
938
		if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
939
			return $ver;
940
		}
941
942
		$query = $wp_scripts->registered[ $handle ];
943
		if ( is_object( $query ) && ! empty( $query->ver ) ) {
944
			$ver = $query->ver;
945
		}
946
947
		return $ver;
948
	}
949
950
	public static function js_redirect( $url ) {
951
		return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
952
    }
953
954
	public static function get_user_id_param( $user_id ) {
955
		if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
956
            return $user_id;
957
        }
958
959
		$user_id = sanitize_text_field( $user_id );
960
		if ( $user_id == 'current' ) {
961
			$user_id = get_current_user_id();
962
		} else {
963
			if ( is_email( $user_id ) ) {
964
				$user = get_user_by( 'email', $user_id );
965
			} else {
966
				$user = get_user_by( 'login', $user_id );
967
			}
968
969
            if ( $user ) {
970
                $user_id = $user->ID;
971
            }
972
			unset( $user );
973
        }
974
975
        return $user_id;
976
    }
977
978
	public static function get_file_contents( $filename, $atts = array() ) {
979
		if ( ! is_file( $filename ) ) {
980
			return false;
981
		}
982
983
		extract( $atts );
0 ignored issues
show
introduced by
extract() usage is highly discouraged, due to the complexity and unintended issues it might cause.
Loading history...
984
		ob_start();
985
		include( $filename );
986
		$contents = ob_get_contents();
987
		ob_end_clean();
988
		return $contents;
989
	}
990
991
    /**
992
     * @param string $table_name
993
     * @param string $column
994
	 * @param int $id
995
	 * @param int $num_chars
996
     */
997
    public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
998
        $key = '';
999
1000
        if ( ! empty( $name ) ) {
1001
			$key = sanitize_key( $name );
1002
        }
1003
1004
		if ( empty( $key ) ) {
1005
			$max_slug_value = pow( 36, $num_chars );
1006
            $min_slug_value = 37; // we want to have at least 2 characters in the slug
1007
			$key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
1008
        }
1009
1010
		if ( is_numeric( $key ) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
1011
			$key = $key . 'a';
1012
        }
1013
1014
		$key_check = FrmDb::get_var(
1015
			$table_name,
1016
			array(
1017
				$column => $key,
1018
				'ID !'  => $id,
1019
			),
1020
			$column
1021
		);
1022
1023
		if ( $key_check || is_numeric( $key_check ) ) {
1024
            $suffix = 2;
1025
			do {
1026
				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
1027
				$key_check = FrmDb::get_var(
1028
					$table_name,
1029
					array(
1030
						$column => $alt_post_name,
1031
						'ID !'  => $id,
1032
					),
1033
					$column
1034
				);
1035
				$suffix++;
1036
			} while ( $key_check || is_numeric( $key_check ) );
1037
			$key = $alt_post_name;
1038
        }
1039
        return $key;
1040
    }
1041
1042
    /**
1043
     * Editing a Form or Entry
1044
     * @param string $table
1045
     * @return bool|array
1046
     */
1047
    public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
1048
        if ( ! $record ) {
1049
            return false;
1050
        }
1051
1052
		if ( empty( $post_values ) ) {
1053
			$post_values = stripslashes_deep( $_POST );
1054
		}
1055
1056
		$values = array(
1057
			'id' => $record->id,
1058
			'fields' => array(),
1059
		);
1060
1061
		foreach ( array( 'name', 'description' ) as $var ) {
1062
			$default_val = isset( $record->{$var} ) ? $record->{$var} : '';
1063
			$values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
1064
			unset( $var, $default_val );
1065
		}
1066
1067
		$values['description'] = self::use_wpautop( $values['description'] );
1068
1069
		self::fill_form_opts( $record, $table, $post_values, $values );
1070
1071
		self::prepare_field_arrays( $fields, $record, $values, array_merge( $args, compact( 'default', 'post_values' ) ) );
1072
1073
        if ( $table == 'entries' ) {
1074
            $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1075
        } else if ( $table == 'forms' ) {
1076
            $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1077
        }
1078
1079
        return $values;
1080
    }
1081
1082
	private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
1083
		if ( ! empty( $fields ) ) {
1084
			foreach ( (array) $fields as $field ) {
1085
				$field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
1086
				$args['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
1087
				self::fill_field_defaults( $field, $record, $values, $args );
1088
			}
1089
		}
1090
	}
1091
1092
	private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1093
        $post_values = $args['post_values'];
1094
1095
        if ( $args['default'] ) {
1096
            $meta_value = $field->default_value;
1097
        } else {
1098
			if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1099
				if ( ! isset( $field->field_options['custom_field'] ) ) {
1100
                    $field->field_options['custom_field'] = '';
1101
                }
1102
				$meta_value = FrmProEntryMetaHelper::get_post_value(
1103
					$record->post_id,
1104
					$field->field_options['post_field'],
1105
					$field->field_options['custom_field'],
1106
					array(
1107
						'truncate' => false,
1108
						'type' => $field->type,
1109
						'form_id' => $field->form_id,
1110
						'field' => $field,
1111
					)
1112
				);
1113
            } else {
1114
				$meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1115
            }
1116
        }
1117
1118
		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1119
        $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1120
1121
		$field_array = self::start_field_array( $field );
1122
		$field_array['value'] = $new_value;
1123
		$field_array['type']  = apply_filters( 'frm_field_type', $field_type, $field, $new_value );
1124
		$field_array['parent_form_id'] = $args['parent_form_id'];
1125
1126
        $args['field_type'] = $field_type;
1127
1128
		FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
1129
1130
		if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1131
            $field_array['unique_msg'] = '';
1132
        }
1133
1134
        $field_array = array_merge( $field->field_options, $field_array );
1135
1136
        $values['fields'][ $field->id ] = $field_array;
1137
    }
1138
1139
	/**
1140
	 * @since 3.0
1141
	 * @param object $field
1142
	 * @return array
1143
	 */
1144
	public static function start_field_array( $field ) {
1145
		return array(
1146
			'id'            => $field->id,
1147
			'default_value' => $field->default_value,
1148
			'name'          => $field->name,
1149
			'description'   => $field->description,
1150
			'options'       => $field->options,
1151
			'required'      => $field->required,
1152
			'field_key'     => $field->field_key,
1153
			'field_order'   => $field->field_order,
1154
			'form_id'       => $field->form_id,
1155
		);
1156
	}
1157
1158
    /**
1159
     * @param string $table
1160
     */
1161
	private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1162
        if ( $table == 'entries' ) {
1163
            $form = $record->form_id;
1164
			FrmForm::maybe_get_form( $form );
1165
        } else {
1166
            $form = $record;
1167
        }
1168
1169
        if ( ! $form ) {
1170
            return;
1171
        }
1172
1173
		$values['form_name'] = isset( $record->form_id ) ? $form->name : '';
1174
		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1175
1176
		if ( ! is_array( $form->options ) ) {
1177
			return;
1178
		}
1179
1180
        foreach ( $form->options as $opt => $value ) {
1181
            $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1182
        }
1183
1184
		self::fill_form_defaults( $post_values, $values );
1185
    }
1186
1187
    /**
1188
     * Set to POST value or default
1189
     */
1190
	private static function fill_form_defaults( $post_values, array &$values ) {
1191
        $form_defaults = FrmFormsHelper::get_default_opts();
1192
1193
        foreach ( $form_defaults as $opt => $default ) {
1194
            if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1195
				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1196
            }
1197
1198
			unset( $opt, $default );
1199
        }
1200
1201
		if ( ! isset( $values['custom_style'] ) ) {
1202
			$values['custom_style'] = self::custom_style_value( $post_values );
1203
		}
1204
1205
		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1206
			if ( ! isset( $values[ $h . '_html' ] ) ) {
1207
				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1208
            }
1209
			unset( $h );
1210
        }
1211
    }
1212
1213
	/**
1214
	 * @since 2.2.10
1215
	 * @param array $post_values
1216
	 * @return boolean|int
1217
	 */
1218
	public static function custom_style_value( $post_values ) {
1219
		if ( ! empty( $post_values ) && isset( $post_values['options']['custom_style'] ) ) {
1220
			$custom_style = absint( $post_values['options']['custom_style'] );
1221
		} else {
1222
			$frm_settings = FrmAppHelper::get_settings();
1223
			$custom_style = ( $frm_settings->load_style != 'none' );
1224
		}
1225
		return $custom_style;
1226
	}
1227
1228
	public static function insert_opt_html( $args ) {
1229
		$class = '';
1230
		$possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' );
1231
		if ( $possible_email_field ) {
1232
			$class .= 'show_frm_not_email_to';
1233
		}
1234
    ?>
1235
<li>
1236
	<a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['id'] ); ?>" >[<?php echo esc_attr( $args['id'] ); ?>]</a>
1237
	<a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['key'] ); ?>" >[<?php echo esc_attr( self::truncate( $args['key'], 10 ) ); ?>]</a>
1238
	<a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['id'] ); ?>" ><?php echo esc_attr( self::truncate( $args['name'], 60 ) ); ?></a>
1239
</li>
1240
    <?php
1241
    }
1242
1243
	public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1244
        if ( is_array( $str ) ) {
1245
            return '';
1246
		}
1247
1248
        $length = (int) $length;
1249
		$str = wp_strip_all_tags( $str );
1250
		$original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1251
1252
		if ( $length == 0 ) {
1253
            return '';
1254
        } else if ( $length <= 10 ) {
1255
			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1256
			return $sub . ( ( $length < $original_len ) ? $continue : '' );
1257
        }
1258
1259
        $sub = '';
1260
        $len = 0;
1261
1262
		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1263
1264
		foreach ( $words as $word ) {
1265
			$part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1266
			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1267
			if ( $total_len > $length && str_word_count( $sub ) ) {
1268
                break;
1269
            }
1270
1271
            $sub .= $part;
1272
			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1273
1274
			if ( str_word_count( $sub ) > $minword && $total_len >= $length ) {
1275
                break;
1276
            }
1277
1278
			unset( $total_len, $word );
1279
        }
1280
1281
		return $sub . ( ( $len < $original_len ) ? $continue : '' );
1282
    }
1283
1284
	public static function mb_function( $function_names, $args ) {
1285
		$mb_function_name = $function_names[0];
1286
		$function_name = $function_names[1];
1287
		if ( function_exists( $mb_function_name ) ) {
1288
			$function_name = $mb_function_name;
1289
		}
1290
		return call_user_func_array( $function_name, $args );
1291
	}
1292
1293
	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1294
		if ( empty( $date ) ) {
1295
            return $date;
1296
        }
1297
1298
		if ( empty( $date_format ) ) {
1299
			$date_format = get_option( 'date_format' );
1300
		}
1301
1302
		if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1303
            $frmpro_settings = new FrmProSettings();
1304
			$date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1305
        }
1306
1307
		$formatted = self::get_localized_date( $date_format, $date );
1308
1309
		$do_time = ( date( 'H:i:s', strtotime( $date ) ) != '00:00:00' );
1310
		if ( $do_time ) {
1311
			$formatted .= self::add_time_to_date( $time_format, $date );
1312
		}
1313
1314
        return $formatted;
1315
    }
1316
1317
	private static function add_time_to_date( $time_format, $date ) {
1318
		if ( empty( $time_format ) ) {
1319
			$time_format = get_option( 'time_format' );
1320
		}
1321
1322
		$trimmed_format = trim( $time_format );
1323
		$time = '';
1324
		if ( $time_format && ! empty( $trimmed_format ) ) {
1325
			$time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
1326
		}
1327
1328
		return $time;
1329
	}
1330
1331
	/**
1332
	 * @since 2.0.8
1333
	 */
1334
	public static function get_localized_date( $date_format, $date ) {
1335
		$date = get_date_from_gmt( $date );
1336
		return date_i18n( $date_format, strtotime( $date ) );
1337
	}
1338
1339
	/**
1340
	 * Gets the time ago in words
1341
	 *
1342
	 * @param int $from in seconds
1343
	 * @param int|string $to in seconds
1344
	 * @return string $time_ago
1345
	 */
1346
	public static function human_time_diff( $from, $to = '', $levels = 1 ) {
1347
		if ( empty( $to ) ) {
1348
			$now = new DateTime;
1349
		} else {
1350
			$now = new DateTime( '@' . $to );
1351
		}
1352
		$ago = new DateTime( '@' . $from );
1353
1354
		// Get the time difference
1355
		$diff_object = $now->diff( $ago );
1356
		$diff = get_object_vars( $diff_object );
1357
1358
		// Add week amount and update day amount
1359
		$diff['w'] = floor( $diff['d'] / 7 );
1360
		$diff['d'] -= $diff['w'] * 7;
1361
1362
		$time_strings = self::get_time_strings();
1363
1364
		foreach ( $time_strings as $k => $v ) {
1365
			if ( $diff[ $k ] ) {
1366
				$time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
1367
			} else {
1368
				unset( $time_strings[ $k ] );
1369
			}
1370
		}
1371
1372
		$levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
1373
		$time_strings = array_slice( $time_strings, 0, $levels_deep );
1374
		$time_ago_string = $time_strings ? implode( ' ', $time_strings ) : '0 ' . __( 'seconds', 'formidable' );
1375
1376
		return $time_ago_string;
1377
	}
1378
1379
	/**
1380
	 * Get the translatable time strings
1381
	 *
1382
	 * @since 2.0.20
1383
	 * @return array
1384
	 */
1385
	private static function get_time_strings() {
1386
		return array(
1387
			'y' => array( __( 'year', 'formidable' ), __( 'years', 'formidable' ) ),
1388
			'm' => array( __( 'month', 'formidable' ), __( 'months', 'formidable' ) ),
1389
			'w' => array( __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ),
1390
			'd' => array( __( 'day', 'formidable' ), __( 'days', 'formidable' ) ),
1391
			'h' => array( __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ),
1392
			'i' => array( __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ),
1393
			's' => array( __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) ),
1394
		);
1395
	}
1396
1397
    // Pagination Methods
1398
1399
    /**
1400
     * @param integer $current_p
1401
     */
1402
	public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1403
		return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1404
	}
1405
1406
    /**
1407
     * @param integer $current_p
1408
     */
1409
    public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1410
        if ( $current_p == 1 ) {
1411
            return 1;
1412
        } else {
1413
            return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1414
        }
1415
    }
1416
1417
	/**
1418
	 * @return array
1419
	 */
1420
	public static function json_to_array( $json_vars ) {
1421
        $vars = array();
1422
        foreach ( $json_vars as $jv ) {
1423
			$jv_name = explode( '[', $jv['name'] );
1424
			$last = count( $jv_name ) - 1;
1425
			foreach ( $jv_name as $p => $n ) {
1426
				$name = trim( $n, ']' );
1427
				if ( ! isset( $l1 ) ) {
1428
					$l1 = $name;
1429
				}
1430
1431
				if ( ! isset( $l2 ) ) {
1432
					$l2 = $name;
1433
				}
1434
1435
				if ( ! isset( $l3 ) ) {
1436
					$l3 = $name;
1437
				}
1438
1439
                $this_val = ( $p == $last ) ? $jv['value'] : array();
1440
1441
                switch ( $p ) {
1442
                    case 0:
1443
                        $l1 = $name;
1444
                        self::add_value_to_array( $name, $l1, $this_val, $vars );
1445
						break;
1446
1447
                    case 1:
1448
                        $l2 = $name;
1449
                        self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1450
						break;
1451
1452 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...
1453
                        $l3 = $name;
1454
                        self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1455
						break;
1456
1457 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...
1458
                        $l4 = $name;
1459
                        self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1460
                }
1461
1462
				unset( $this_val, $n );
1463
            }
1464
1465
			unset( $last, $jv );
1466
        }
1467
1468
        return $vars;
1469
    }
1470
1471
    /**
1472
     * @param string $name
1473
     * @param string $l1
1474
     */
1475
    public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1476
        if ( $name == '' ) {
1477
            $vars[] = $val;
1478
        } else if ( ! isset( $vars[ $l1 ] ) ) {
1479
            $vars[ $l1 ] = $val;
1480
        }
1481
    }
1482
1483
	public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1484
        $tooltips = array(
1485
            'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1486
            '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' ),
1487
            'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1488
            'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1489
            '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' ),
1490
            'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1491
            '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() ) ),
1492
        );
1493
1494
        if ( ! isset( $tooltips[ $name ] ) ) {
1495
            return;
1496
        }
1497
1498
        if ( 'open' == $class ) {
1499
            echo ' frm_help"';
1500
        } else {
1501
            echo ' class="frm_help"';
1502
        }
1503
1504
		echo ' title="' . esc_attr( $tooltips[ $name ] );
1505
1506
        if ( 'open' != $class ) {
1507
            echo '"';
1508
        }
1509
    }
1510
1511
	/**
1512
	 * Add the current_page class to that page in the form nav
1513
	 */
1514
	public static function select_current_page( $page, $current_page, $action = array() ) {
1515
		if ( $current_page != $page ) {
1516
			return;
1517
		}
1518
1519
		$frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
1520
		if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
1521
			echo ' class="current_page"';
1522
		}
1523
	}
1524
1525
    /**
1526
     * Prepare and json_encode post content
1527
     *
1528
     * @since 2.0
1529
     *
1530
     * @param array $post_content
1531
     * @return string $post_content ( json encoded array )
1532
     */
1533
    public static function prepare_and_encode( $post_content ) {
1534
        //Loop through array to strip slashes and add only the needed ones
1535
		foreach ( $post_content as $key => $val ) {
1536
			// Replace problematic characters (like &quot;)
1537
			$val = str_replace( '&quot;', '"', $val );
1538
1539
			self::prepare_action_slashes( $val, $key, $post_content );
1540
            unset( $key, $val );
1541
        }
1542
1543
        // json_encode the array
1544
        $post_content = json_encode( $post_content );
1545
1546
	    // add extra slashes for \r\n since WP strips them
1547
		$post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1548
1549
        // allow for &quot
1550
	    $post_content = str_replace( '&quot;', '\\"', $post_content );
1551
1552
        return $post_content;
1553
    }
1554
1555
	private static function prepare_action_slashes( $val, $key, &$post_content ) {
1556
		if ( ! isset( $post_content[ $key ] ) ) {
1557
			return;
1558
		}
1559
1560
		if ( is_array( $val ) ) {
1561
			foreach ( $val as $k1 => $v1 ) {
1562
				self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
1563
				unset( $k1, $v1 );
1564
			}
1565
		} else {
1566
			// Strip all slashes so everything is the same, no matter where the value is coming from
1567
			$val = stripslashes( $val );
1568
1569
			// Add backslashes before double quotes and forward slashes only
1570
			$post_content[ $key ] = addcslashes( $val, '"\\/' );
1571
		}
1572
	}
1573
1574
	public static function maybe_json_decode( $string ) {
1575
		if ( is_array( $string ) ) {
1576
            return $string;
1577
        }
1578
1579
		$new_string = json_decode( $string, true );
1580
		if ( function_exists( 'json_last_error' ) ) {
1581
			// php 5.3+
1582
            if ( json_last_error() == JSON_ERROR_NONE ) {
1583
                $string = $new_string;
1584
            }
1585
		} elseif ( isset( $new_string ) ) {
1586
			// php < 5.3 fallback
1587
            $string = $new_string;
1588
        }
1589
        return $string;
1590
    }
1591
1592
    /**
1593
     * @since 1.07.10
1594
     *
1595
     * @param string $post_type The name of the post type that may need to be highlighted
1596
     * echo The javascript to open and highlight the Formidable menu
1597
     */
1598
	public static function maybe_highlight_menu( $post_type ) {
1599
        global $post;
1600
1601
		if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
1602
            return;
1603
        }
1604
1605
		if ( is_object( $post ) && $post->post_type != $post_type ) {
1606
            return;
1607
        }
1608
1609
        self::load_admin_wide_js();
1610
        echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1611
    }
1612
1613
    /**
1614
     * Load the JS file on non-Formidable pages in the admin area
1615
     * @since 2.0
1616
     */
1617
	public static function load_admin_wide_js( $load = true ) {
1618
        $version = FrmAppHelper::plugin_version();
1619
		wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1620
1621
		$global_strings = array(
1622
			'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1623
            'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1624
			'url'          => FrmAppHelper::plugin_url(),
1625
			'loading'      => __( 'Loading&hellip;' ),
1626
			'nonce'        => wp_create_nonce( 'frm_ajax' ),
1627
		);
1628
		wp_localize_script( 'formidable_admin_global', 'frmGlobal', $global_strings );
1629
1630
		if ( $load ) {
1631
			wp_enqueue_script( 'formidable_admin_global' );
1632
		}
1633
    }
1634
1635
	/**
1636
	 * @since 2.0.9
1637
	 */
1638
	public static function load_font_style() {
1639
		wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
1640
	}
1641
1642
    /**
1643
     * @param string $location
1644
     */
1645
	public static function localize_script( $location ) {
1646
		$ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
1647
		$ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
1648
1649
		$script_strings = array(
1650
			'ajax_url'  => $ajax_url,
1651
			'images_url' => self::plugin_url() . '/images',
1652
			'loading'   => __( 'Loading&hellip;' ),
1653
			'remove'    => __( 'Remove', 'formidable' ),
1654
			'offset'    => apply_filters( 'frm_scroll_offset', 4 ),
1655
			'nonce'     => wp_create_nonce( 'frm_ajax' ),
1656
			'id'        => __( 'ID', 'formidable' ),
1657
			'no_results' => __( 'No results match', 'formidable' ),
1658
			'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
1659
			'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
1660
			'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
1661
		);
1662
		wp_localize_script( 'formidable', 'frm_js', $script_strings );
1663
1664
		if ( $location == 'admin' ) {
1665
			$frm_settings = self::get_settings();
1666
			$admin_script_strings = array(
1667
				'confirm_uninstall' => __( 'Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable' ),
1668
				'desc'              => __( '(Click to add description)', 'formidable' ),
1669
				'blank'             => __( '(Blank)', 'formidable' ),
1670
				'no_label'          => __( '(no label)', 'formidable' ),
1671
				'saving'            => esc_attr( __( 'Saving', 'formidable' ) ),
1672
				'saved'             => esc_attr( __( 'Saved', 'formidable' ) ),
1673
				'ok'                => __( 'OK' ),
1674
				'cancel'            => __( 'Cancel', 'formidable' ),
1675
				'default'           => __( 'Default', 'formidable' ),
1676
				'clear_default'     => __( 'Clear default value when typing', 'formidable' ),
1677
				'no_clear_default'  => __( 'Do not clear default value when typing', 'formidable' ),
1678
				'valid_default'     => __( 'Default value will pass form validation', 'formidable' ),
1679
				'no_valid_default'  => __( 'Default value will NOT pass form validation', 'formidable' ),
1680
				'confirm'           => __( 'Are you sure?', 'formidable' ),
1681
				'conf_delete'       => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
1682
				'conf_delete_sec'   => __( 'WARNING: This will delete all fields inside of the section as well.', 'formidable' ),
1683
				'conf_no_repeat'    => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
1684
				'default_unique'    => $frm_settings->unique_msg,
1685
				'default_conf'      => __( 'The entered values do not match', 'formidable' ),
1686
				'enter_email'       => __( 'Enter Email', 'formidable' ),
1687
				'confirm_email'     => __( 'Confirm Email', 'formidable' ),
1688
				'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' ),
1689
				'enter_password'    => __( 'Enter Password', 'formidable' ),
1690
				'confirm_password'  => __( 'Confirm Password', 'formidable' ),
1691
				'import_complete'   => __( 'Import Complete', 'formidable' ),
1692
				'updating'          => __( 'Please wait while your site updates.', 'formidable' ),
1693
				'no_save_warning'   => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
1694
				'private'           => __( 'Private' ),
1695
				'jquery_ui_url'     => self::jquery_ui_base_url(),
1696
				'pro_url'           => is_callable( 'FrmProAppHelper::plugin_url' ) ? FrmProAppHelper::plugin_url() : '',
1697
				'no_licenses'       => __( 'No new licenses were found', 'formidable' ),
1698
				'unmatched_parens'  => __( 'This calculation has at least one unmatched ( ) { } [ ].', 'formidable' ),
1699
				'view_shortcodes'   => __( 'This calculation may have shortcodes that work in Views but not forms.', 'formidable' ),
1700
				'text_shortcodes'   => __( 'This calculation may have shortcodes that work in text calculations but not numeric calculations.', 'formidable' ),
1701
				'repeat_limit_min'  => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
1702
				'installing'        => __( 'Installing', 'formidable' ),
1703
				'install'           => __( 'Install', 'formidable' ),
1704
				'active'            => __( 'Active', 'formidable' ),
1705
			);
1706
			wp_localize_script( 'formidable_admin', 'frm_admin_js', $admin_script_strings );
1707
		}
1708
	}
1709
1710
    /**
1711
	 * echo the message on the plugins listing page
1712
     * @since 1.07.10
1713
     *
1714
     * @param float $min_version The version the add-on requires
1715
     */
1716
	public static function min_version_notice( $min_version ) {
1717
        $frm_version = self::plugin_version();
1718
1719
        // check if Formidable meets minimum requirements
1720
		if ( version_compare( $frm_version, $min_version, '>=' ) ) {
1721
            return;
1722
        }
1723
1724
		$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1725
		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">' .
1726
        esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1727
        '</div></td></tr>';
1728
    }
1729
1730
    public static function locales( $type = 'date' ) {
1731
		$locales = array(
1732
			'en' => __( 'English', 'formidable' ),
1733
			''   => __( 'English/Western', 'formidable' ),
1734
			'af' => __( 'Afrikaans', 'formidable' ),
1735
			'sq' => __( 'Albanian', 'formidable' ),
1736
			'ar' => __( 'Arabic', 'formidable' ),
1737
			'hy' => __( 'Armenian', 'formidable' ),
1738
			'az' => __( 'Azerbaijani', 'formidable' ),
1739
			'eu' => __( 'Basque', 'formidable' ),
1740
			'bs' => __( 'Bosnian', 'formidable' ),
1741
			'bg' => __( 'Bulgarian', 'formidable' ),
1742
			'ca' => __( 'Catalan', 'formidable' ),
1743
			'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1744
			'zh-CN' => __( 'Chinese Simplified', 'formidable' ),
1745
			'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1746
			'hr' => __( 'Croatian', 'formidable' ),
1747
			'cs' => __( 'Czech', 'formidable' ),
1748
			'da' => __( 'Danish', 'formidable' ),
1749
			'nl' => __( 'Dutch', 'formidable' ),
1750
			'en-GB' => __( 'English/UK', 'formidable' ),
1751
			'eo' => __( 'Esperanto', 'formidable' ),
1752
			'et' => __( 'Estonian', 'formidable' ),
1753
			'fo' => __( 'Faroese', 'formidable' ),
1754
			'fa' => __( 'Farsi/Persian', 'formidable' ),
1755
			'fil' => __( 'Filipino', 'formidable' ),
1756
			'fi' => __( 'Finnish', 'formidable' ),
1757
			'fr' => __( 'French', 'formidable' ),
1758
			'fr-CA' => __( 'French/Canadian', 'formidable' ),
1759
			'fr-CH' => __( 'French/Swiss', 'formidable' ),
1760
			'de' => __( 'German', 'formidable' ),
1761
			'de-AT' => __( 'German/Austria', 'formidable' ),
1762
			'de-CH' => __( 'German/Switzerland', 'formidable' ),
1763
			'el' => __( 'Greek', 'formidable' ),
1764
			'he' => __( 'Hebrew', 'formidable' ),
1765
			'iw' => __( 'Hebrew', 'formidable' ),
1766
			'hi' => __( 'Hindi', 'formidable' ),
1767
			'hu' => __( 'Hungarian', 'formidable' ),
1768
			'is' => __( 'Icelandic', 'formidable' ),
1769
			'id' => __( 'Indonesian', 'formidable' ),
1770
			'it' => __( 'Italian', 'formidable' ),
1771
			'ja' => __( 'Japanese', 'formidable' ),
1772
			'ko' => __( 'Korean', 'formidable' ),
1773
			'lv' => __( 'Latvian', 'formidable' ),
1774
			'lt' => __( 'Lithuanian', 'formidable' ),
1775
			'ms' => __( 'Malaysian', 'formidable' ),
1776
			'no' => __( 'Norwegian', 'formidable' ),
1777
			'pl' => __( 'Polish', 'formidable' ),
1778
			'pt' => __( 'Portuguese', 'formidable' ),
1779
			'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1780
			'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ),
1781
			'ro' => __( 'Romanian', 'formidable' ),
1782
			'ru' => __( 'Russian', 'formidable' ),
1783
			'sr' => __( 'Serbian', 'formidable' ),
1784
			'sr-SR' => __( 'Serbian', 'formidable' ),
1785
			'sk' => __( 'Slovak', 'formidable' ),
1786
			'sl' => __( 'Slovenian', 'formidable' ),
1787
			'es' => __( 'Spanish', 'formidable' ),
1788
			'es-419' => __( 'Spanish/Latin America', 'formidable' ),
1789
			'sv' => __( 'Swedish', 'formidable' ),
1790
			'ta' => __( 'Tamil', 'formidable' ),
1791
			'th' => __( 'Thai', 'formidable' ),
1792
			'tu' => __( 'Turkish', 'formidable' ),
1793
			'tr' => __( 'Turkish', 'formidable' ),
1794
			'uk' => __( 'Ukranian', 'formidable' ),
1795
			'vi' => __( 'Vietnamese', 'formidable' ),
1796
		);
1797
1798
		if ( $type === 'captcha' ) {
1799
			// remove the languages unavailable for the captcha
1800
			$unset = array( '', 'af', 'sq', 'hy', 'az', 'eu', 'bs', 'zh-HK', 'eo', 'et', 'fo', 'fr-CH', 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu' );
1801
		} else {
1802
			// remove the languages unavailable for the datepicker
1803
			$unset = array( 'en', 'fil', 'fr-CA', 'de-AT', 'de-AT', 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', 'es-419', 'tr' );
1804
		}
1805
1806
		$locales = array_diff_key( $locales, array_flip( $unset ) );
1807
		$locales = apply_filters( 'frm_locales', $locales );
1808
1809
        return $locales;
1810
    }
1811
1812
	/**
1813
	 * Used to filter shortcode in text widgets
1814
	 *
1815
	 * @deprecated 2.5.4
1816
	 * @codeCoverageIgnore
1817
	 */
1818
	public static function widget_text_filter_callback( $matches ) {
1819
		return FrmDeprecated::widget_text_filter_callback( $matches );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::widget_text_filter_callback() has been deprecated with message: 2.5.4

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1820
	}
1821
1822
	/**
1823
	 * @deprecated 3.01
1824
	 * @codeCoverageIgnore
1825
	 */
1826
	public static function sanitize_array( &$values ) {
1827
		FrmDeprecated::sanitize_array( $values );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::sanitize_array() has been deprecated with message: 3.01

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1828
	}
1829
1830
	/**
1831
	 * @param array $settings
1832
	 * @param string $group
1833
	 *
1834
	 * @since 2.0.6
1835
	 * @deprecated 2.05.06
1836
	 * @codeCoverageIgnore
1837
	 */
1838
	public static function save_settings( $settings, $group ) {
1839
		return FrmDeprecated::save_settings( $settings, $group );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::save_settings() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1840
	}
1841
1842
	/**
1843
	 * @since 2.0.4
1844
	 * @deprecated 2.05.06
1845
	 * @codeCoverageIgnore
1846
	 */
1847
	public static function save_json_post( $settings ) {
1848
		return FrmDeprecated::save_json_post( $settings );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::save_json_post() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1849
	}
1850
1851
	/**
1852
	 * @since 2.0
1853
	 * @deprecated 2.05.06
1854
	 * @codeCoverageIgnore
1855
	 *
1856
	 * @param string $cache_key The unique name for this cache
1857
	 * @param string $group The name of the cache group
1858
	 * @param string $query If blank, don't run a db call
1859
	 * @param string $type The wpdb function to use with this query
1860
	 * @return mixed $results The cache or query results
1861
	 */
1862
	public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
1863
		return FrmDeprecated::check_cache( $cache_key, $group, $query, $type, $time );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::check_cache() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1864
	}
1865
1866
	/**
1867
	 * @deprecated 2.05.06
1868
	 * @codeCoverageIgnore
1869
	 */
1870
	public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
1871
		return FrmDeprecated::set_cache( $cache_key, $results, $group, $time );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::set_cache() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1872
	}
1873
1874
	/**
1875
	 * @deprecated 2.05.06
1876
	 * @codeCoverageIgnore
1877
	 */
1878
	public static function add_key_to_group_cache( $key, $group ) {
1879
		FrmDeprecated::add_key_to_group_cache( $key, $group );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::add_key_to_group_cache() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1880
	}
1881
1882
	/**
1883
	 * @deprecated 2.05.06
1884
	 * @codeCoverageIgnore
1885
	 */
1886
	public static function get_group_cached_keys( $group ) {
1887
		return FrmDeprecated::get_group_cached_keys( $group );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::get_group_cached_keys() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1888
	}
1889
1890
	/**
1891
	 * @since 2.0
1892
	 * @deprecated 2.05.06
1893
	 * @codeCoverageIgnore
1894
	 * @return mixed The cached value or false
1895
	 */
1896
	public static function check_cache_and_transient( $cache_key ) {
1897
		return FrmDeprecated::check_cache( $cache_key );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::check_cache() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1898
	}
1899
1900
	/**
1901
	 * @since 2.0
1902
	 * @deprecated 2.05.06
1903
	 * @codeCoverageIgnore
1904
	 * @param string $cache_key
1905
	 */
1906
	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
1907
		FrmDeprecated::delete_cache_and_transient( $cache_key, $group );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::delete_cache_and_transient() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1908
	}
1909
1910
	/**
1911
	 * @since 2.0
1912
	 * @deprecated 2.05.06
1913
	 * @codeCoverageIgnore
1914
	 *
1915
	 * @param string $group The name of the cache group
1916
	 */
1917
	public static function cache_delete_group( $group ) {
1918
		FrmDeprecated::cache_delete_group( $group );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::cache_delete_group() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1919
	}
1920
1921
	/**
1922
	 * @since 1.07.10
1923
	 * @deprecated 2.05.06
1924
	 * @codeCoverageIgnore
1925
	 *
1926
	 * @param string $term The value to escape
1927
	 * @return string The escaped value
1928
	 */
1929
	public static function esc_like( $term ) {
1930
		return FrmDeprecated::esc_like( $term );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::esc_like() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1931
	}
1932
1933
	/**
1934
	 * @param string $order_query
1935
	 * @deprecated 2.05.06
1936
	 * @codeCoverageIgnore
1937
	 */
1938
	public static function esc_order( $order_query ) {
1939
		return FrmDeprecated::esc_order( $order_query );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::esc_order() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1940
	}
1941
1942
	/**
1943
	 * @deprecated 2.05.06
1944
	 * @codeCoverageIgnore
1945
	 */
1946
	public static function esc_order_by( &$order_by ) {
1947
		FrmDeprecated::esc_order_by( $order_by );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::esc_order_by() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1948
	}
1949
1950
	/**
1951
	 * @param string $limit
1952
	 * @deprecated 2.05.06
1953
	 * @codeCoverageIgnore
1954
	 */
1955
	public static function esc_limit( $limit ) {
1956
		return FrmDeprecated::esc_limit( $limit );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::esc_limit() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1957
	}
1958
1959
	/**
1960
	 * @since 2.0
1961
	 * @deprecated 2.05.06
1962
	 * @codeCoverageIgnore
1963
	 */
1964
	public static function prepare_array_values( $array, $type = '%s' ) {
1965
		return FrmDeprecated::prepare_array_values( $array, $type );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::prepare_array_values() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1966
	}
1967
1968
	/**
1969
	 * @deprecated 2.05.06
1970
	 * @codeCoverageIgnore
1971
	 */
1972
	public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
1973
		return FrmDeprecated::prepend_and_or_where( $starts_with, $where );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::prepend_and_or_where() has been deprecated with message: 2.05.06

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1974
	}
1975
}
1976