Completed
Push — master ( 755208...807d29 )
by Stephanie
03:27
created

FrmAppHelper::esc_order_by()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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