Completed
Push — master ( 1ae166...02cc92 )
by Stephanie
04:26 queued 01:44
created

FrmAppHelper::get_server_value()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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