Completed
Push — master ( 9e736e...81fa44 )
by Stephanie
02:35
created

FrmAppHelper::add_value_to_array()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 4
dl 0
loc 7
rs 9.4285
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.05';
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 defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
157
    }
158
159
	/**
160
	 * @since 2.0.8
161
	 */
162
	public static function prevent_caching() {
163
		global $frm_vars;
164
		return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
165
	}
166
167
    /**
168
     * Check if on an admin page
169
     *
170
     * @since 2.0
171
     *
172
     * @param None
173
     * @return boolean
174
     */
175
    public static function is_admin() {
176
        return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
177
    }
178
179
    /**
180
     * Check if value contains blank value or empty array
181
     *
182
     * @since 2.0
183
     * @param mixed $value - value to check
184
	 * @param string
185
     * @return boolean
186
     */
187
    public static function is_empty_value( $value, $empty = '' ) {
188
        return ( is_array( $value ) && empty( $value ) ) || $value == $empty;
189
    }
190
191
    public static function is_not_empty_value( $value, $empty = '' ) {
192
        return ! self::is_empty_value( $value, $empty );
193
    }
194
195
    /**
196
     * Get any value from the $_SERVER
197
     *
198
     * @since 2.0
199
     * @param string $value
200
     * @return string
201
     */
202
	public static function get_server_value( $value ) {
203
        return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
204
    }
205
206
    /**
207
     * Check for the IP address in several places
208
     * Used by [ip] shortcode
209
     *
210
     * @return string The IP address of the current user
211
     */
212
    public static function get_ip_address() {
213
		$ip = '';
214
        foreach ( array(
215
            'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
216
            'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
217
        ) as $key ) {
218
            if ( ! isset( $_SERVER[ $key ] ) ) {
219
                continue;
220
            }
221
222
            foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
223
                $ip = trim($ip); // just to be safe
224
225
                if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
226
                    return $ip;
227
                }
228
            }
229
        }
230
231
		return sanitize_text_field( $ip );
232
    }
233
234
    public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
235
        if ( strpos($param, '[') ) {
236
            $params = explode('[', $param);
237
            $param = $params[0];
238
        }
239
240
		if ( $src == 'get' ) {
241
            $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
242
            if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
243
                $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
244
            }
245
			self::sanitize_value( $sanitize, $value );
246
		} else {
247
            $value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
248
        }
249
250
		if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
251
            foreach ( $params as $k => $p ) {
252
                if ( ! $k || ! is_array($value) ) {
253
                    continue;
254
                }
255
256
                $p = trim($p, ']');
257
                $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
258
            }
259
        }
260
261
        return $value;
262
    }
263
264
	public static function get_post_param( $param, $default = '', $sanitize = '' ) {
265
		return self::get_simple_request( array( 'type' => 'post', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
266
	}
267
268
	/**
269
	 * @since 2.0
270
	 *
271
	 * @param string $param
272
	 * @param string $sanitize
273
	 * @param string $default
274
	 * @return string|array
275
	 */
276
	public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
277
		return self::get_simple_request( array( 'type' => 'get', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
278
    }
279
280
	/**
281
	 * Get a GET/POST/REQUEST value and sanitize it
282
	 *
283
	 * @since 2.0.6
284
	 * @param array $args
285
	 * @return string|array
286
	 */
287
	public static function get_simple_request( $args ) {
288
		$defaults = array(
289
			'param' => '', 'default' => '',
290
			'type' => 'get', 'sanitize' => 'sanitize_text_field',
291
		);
292
		$args = wp_parse_args( $args, $defaults );
293
294
		$value = $args['default'];
295
		if ( $args['type'] == 'get' ) {
296
			if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
297
				$value = $_GET[ $args['param'] ];
298
			}
299
		} else if ( $args['type'] == 'post' ) {
300
			if ( isset( $_POST[ $args['param'] ] ) ) {
301
				$value = stripslashes_deep( maybe_unserialize( $_POST[ $args['param'] ] ) );
302
			}
303
		} else {
304
			if ( isset( $_REQUEST[ $args['param'] ] ) ) {
305
				$value = $_REQUEST[ $args['param'] ];
306
			}
307
		}
308
309
		self::sanitize_value( $args['sanitize'], $value );
310
		return $value;
311
	}
312
313
	/**
314
	* Preserve backslashes in a value, but make sure value doesn't get compounding slashes
315
	*
316
	* @since 2.0.8
317
	* @param string $value
318
	* @return string $value
319
	*/
320
	public static function preserve_backslashes( $value ) {
321
		// If backslashes have already been added, don't add them again
322
		if ( strpos( $value, '\\\\' ) === false ) {
323
			$value = addslashes( $value );
324
		}
325
		return $value;
326
	}
327
328
	public static function sanitize_value( $sanitize, &$value ) {
329
		if ( ! empty( $sanitize ) ) {
330
			if ( is_array( $value ) ) {
331
				$temp_values = $value;
332
				foreach ( $temp_values as $k => $v ) {
333
					FrmAppHelper::sanitize_value( $sanitize, $value[ $k ] );
334
				}
335
			} else {
336
				$value = call_user_func( $sanitize, $value );
337
			}
338
		}
339
	}
340
341
    public static function sanitize_request( $sanitize_method, &$values ) {
342
        $temp_values = $values;
343
        foreach ( $temp_values as $k => $val ) {
344
            if ( isset( $sanitize_method[ $k ] ) ) {
345
				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
346
            }
347
        }
348
    }
349
350
	public static function sanitize_array( &$values ) {
351
		$temp_values = $values;
352
		foreach ( $temp_values as $k => $val ) {
353
			$values[ $k ] = wp_kses_post( $val );
354
		}
355
	}
356
357
	/**
358
	 * Sanitize the value, and allow some HTML
359
	 * @since 2.0
360
	 * @param string $value
361
	 * @param array|string $allowed 'all' for everything included as defaults
362
	 * @return string
363
	 */
364
	public static function kses( $value, $allowed = array() ) {
365
		$allowed_html = self::allowed_html( $allowed );
366
367
		return wp_kses( $value, $allowed_html );
368
	}
369
370
	/**
371
	 * @since 2.05.03
372
	 */
373
	private static function allowed_html( $allowed ) {
374
		$html = self::safe_html();
375
		$allowed_html = array();
376
		if ( $allowed == 'all' ) {
377
			$allowed_html = $html;
378
		} else {
379
			foreach ( $allowed as $a ) {
380
				$allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
381
			}
382
		}
383
384
		return apply_filters( 'frm_striphtml_allowed_tags', $allowed_html );
385
	}
386
387
	/**
388
	 * @since 2.05.03
389
	 */
390
	private static function safe_html() {
391
		return array(
392
			'a' => array(
393
				'class' => array(),
394
				'href'  => array(),
395
				'id'    => array(),
396
				'rel'   => array(),
397
				'title' => array(),
398
			),
399
			'abbr' => array(
400
				'title' => array(),
401
			),
402
			'b' => array(),
403
			'blockquote' => array(
404
				'cite'  => array(),
405
			),
406
			'br'   => array(),
407
			'cite' => array(
408
				'title' => array(),
409
			),
410
			'code' => array(),
411
			'del'  => array(
412
				'datetime' => array(),
413
				'title' => array(),
414
			),
415
			'dd'  => array(),
416
			'div' => array(
417
				'class' => array(),
418
				'id'    => array(),
419
				'title' => array(),
420
				'style' => array(),
421
			),
422
			'dl'  => array(),
423
			'dt'  => array(),
424
			'em'  => array(),
425
			'h1'  => array(),
426
			'h2'  => array(),
427
			'h3'  => array(),
428
			'h4'  => array(),
429
			'h5'  => array(),
430
			'h6'  => array(),
431
			'i'   => array(),
432
			'img' => array(
433
				'alt'    => array(),
434
				'class'  => array(),
435
				'height' => array(),
436
				'id'     => array(),
437
				'src'    => array(),
438
				'width'  => array(),
439
			),
440
			'li' => array(
441
				'class' => array(),
442
				'id'    => array(),
443
			),
444
			'ol' => array(
445
				'class' => array(),
446
				'id'    => array(),
447
			),
448
			'p'   => array(
449
				'class' => array(),
450
				'id'    => array(),
451
			),
452
			'pre' => array(),
453
			'q'   => array(
454
				'cite' => array(),
455
				'title' => array(),
456
			),
457
			'span' => array(
458
				'class' => array(),
459
				'id'    => array(),
460
				'title' => array(),
461
				'style' => array(),
462
			),
463
			'strike' => array(),
464
			'strong' => array(),
465
			'ul' => array(
466
				'class' => array(),
467
				'id'    => array(),
468
			),
469
		);
470
	}
471
472
    /**
473
     * Used when switching the action for a bulk action
474
     * @since 2.0
475
     */
476
    public static function remove_get_action() {
477
        if ( ! isset($_GET) ) {
478
            return;
479
        }
480
481
        $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
482
        if ( ! empty( $new_action ) ) {
483
			$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
484
        }
485
    }
486
487
    /**
488
     * Check the WP query for a parameter
489
     *
490
     * @since 2.0
491
     * @return string|array
492
     */
493
    public static function get_query_var( $value, $param ) {
494
        if ( $value != '' ) {
495
            return $value;
496
        }
497
498
        global $wp_query;
499
        if ( isset( $wp_query->query_vars[ $param ] ) ) {
500
            $value = $wp_query->query_vars[ $param ];
501
        }
502
503
        return $value;
504
    }
505
506
    /**
507
     * @param string $type
508
     */
509
    public static function trigger_hook_load( $type, $object = null ) {
510
        // only load the form hooks once
511
		$hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
512
        if ( ! $hooks_loaded ) {
513
			do_action( 'frm_load_' . $type . '_hooks' );
514
        }
515
    }
516
517
    /**
518
     * Check a value from a shortcode to see if true or false.
519
     * True when value is 1, true, 'true', 'yes'
520
     *
521
     * @since 1.07.10
522
     *
523
     * @param string $value The value to compare
524
     * @return boolean True or False
525
     */
526
	public static function is_true( $value ) {
527
        return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
528
    }
529
530
    /**
531
     * Used to filter shortcode in text widgets
532
     */
533
    public static function widget_text_filter_callback( $matches ) {
534
		_deprecated_function( __METHOD__, '2.5.4' );
535
        return do_shortcode( $matches[0] );
536
    }
537
538
    public static function get_pages() {
539
		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...
540
    }
541
542
    public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
543
        $pages = self::get_pages();
544
		$selected = self::get_post_param( $field_name, $page_id, 'absint' );
545
    ?>
546
        <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown">
547
            <option value=""> </option>
548
            <?php foreach ( $pages as $page ) { ?>
549
				<option value="<?php echo esc_attr($page->ID); ?>" <?php selected( $selected, $page->ID ) ?>>
550
					<?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?>
551
				</option>
552
            <?php } ?>
553
        </select>
554
    <?php
555
    }
556
557
	public static function post_edit_link( $post_id ) {
558
        $post = get_post($post_id);
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
559
        if ( $post ) {
560
			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
561
			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
562
        }
563
        return '';
564
    }
565
566
	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
567
    ?>
568
        <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php
569
            echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
570
            ?> class="frm_multiselect">
571
            <?php self::roles_options($capability); ?>
572
        </select>
573
    <?php
574
    }
575
576
	public static function roles_options( $capability ) {
577
        global $frm_vars;
578
        if ( isset($frm_vars['editable_roles']) ) {
579
            $editable_roles = $frm_vars['editable_roles'];
580
        } else {
581
            $editable_roles = get_editable_roles();
582
            $frm_vars['editable_roles'] = $editable_roles;
583
        }
584
585
        foreach ( $editable_roles as $role => $details ) {
586
            $name = translate_user_role($details['name'] ); ?>
587
        <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...
588
<?php
589
            unset($role, $details);
590
        }
591
    }
592
593
	public static function frm_capabilities( $type = 'auto' ) {
594
        $cap = array(
595
            'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
596
            'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
597
            'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
598
            'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
599
            'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
600
            'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
601
        );
602
603
		if ( ! self::pro_is_installed() && 'pro' != $type ) {
604
            return $cap;
605
        }
606
607
        $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
608
        $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
609
        $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
610
        $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
611
612
        return $cap;
613
    }
614
615
	public static function user_has_permission( $needed_role ) {
616
        if ( $needed_role == '-1' ) {
617
            return false;
618
		}
619
620
        // $needed_role will be equal to blank if "Logged-in users" is selected
621
        if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
622
            return true;
623
        }
624
625
        $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
626
        foreach ( $roles as $role ) {
627
			if ( current_user_can( $role ) ) {
628
        		return true;
629
			}
630
        	if ( $role == $needed_role ) {
631
        		break;
632
			}
633
        }
634
        return false;
635
    }
636
637
    /**
638
     * Make sure administrators can see Formidable menu
639
     *
640
     * @since 2.0
641
     */
642
    public static function maybe_add_permissions() {
643
		self::force_capability( 'frm_view_entries' );
644
645
        if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
646
            return;
647
        }
648
649
		$user_id = get_current_user_id();
650
		$user = new WP_User( $user_id );
651
        $frm_roles = self::frm_capabilities();
652
        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
653
			$user->add_cap( $frm_role );
654
            unset($frm_role, $frm_role_description);
655
        }
656
    }
657
658
	/**
659
	 * Make sure admins have permission to see the menu items
660
	 * @since 2.0.6
661
	 */
662
	public static function force_capability( $cap = 'frm_change_settings' ) {
663
		if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
664
			$role = get_role( 'administrator' );
665
			$frm_roles = self::frm_capabilities();
666
			foreach ( $frm_roles as $frm_role => $frm_role_description ) {
667
				$role->add_cap( $frm_role );
668
			}
669
		}
670
	}
671
672
    /**
673
     * Check if the user has permision for action.
674
     * Return permission message and stop the action if no permission
675
     * @since 2.0
676
     * @param string $permission
677
     */
678
	public static function permission_check( $permission, $show_message = 'show' ) {
679
        $permission_error = self::permission_nonce_error($permission);
680
        if ( $permission_error !== false ) {
681
            if ( 'hide' == $show_message ) {
682
                $permission_error = '';
683
            }
684
            wp_die($permission_error);
685
        }
686
    }
687
688
    /**
689
     * Check user permission and nonce
690
     * @since 2.0
691
     * @param string $permission
692
     * @return false|string The permission message or false if allowed
693
     */
694
	public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
695
		if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
696
			$frm_settings = self::get_settings();
697
			return $frm_settings->admin_permission;
698
		}
699
700
		$error = false;
701
        if ( empty($nonce_name) ) {
702
            return $error;
703
        }
704
705
        if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
706
            $frm_settings = self::get_settings();
707
            $error = $frm_settings->admin_permission;
708
        }
709
710
        return $error;
711
    }
712
713
    public static function checked( $values, $current ) {
714
		if ( self::check_selected( $values, $current ) ) {
715
            echo ' checked="checked"';
716
		}
717
    }
718
719
	public static function check_selected( $values, $current ) {
720
		$values = self::recursive_function_map( $values, 'trim' );
721
		$values = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
722
		$current = htmlspecialchars_decode( trim( $current ) );
723
724
		return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
725
	}
726
727
    /**
728
    * Check if current field option is an "other" option
729
    *
730
    * @since 2.0
731
    *
732
    * @param string $opt_key
733
    * @return boolean Returns true if current field option is an "Other" option
734
    */
735
    public static function is_other_opt( $opt_key ) {
736
        _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' );
737
        return FrmFieldsHelper::is_other_opt( $opt_key );
738
    }
739
740
    /**
741
    * Get value that belongs in "Other" text box
742
    *
743
    * @since 2.0
744
    *
745
    * @param string $opt_key
746
    * @param array $field
747
    * @return string $other_val
748
    */
749
    public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) {
750
		_deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::get_other_val' );
751
		return FrmFieldsHelper::get_other_val( compact( 'opt_key', 'field', 'parent', 'pointer' ) );
752
    }
753
754
    /**
755
    * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
756
    * Intended for front-end use
757
    *
758
    * @since 2.0
759
    *
760
    * @param array $field
761
    * @param boolean $other_opt
762
    * @param string $checked
763
    * @param array $args should include opt_key and field name
764
    * @return string $other_val
765
    */
766
    public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) {
767
		_deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::prepare_other_input' );
768
		$args['field'] = $field;
769
		return FrmFieldsHelper::prepare_other_input( $args, $other_opt, $checked );
770
    }
771
772
	public static function recursive_function_map( $value, $function ) {
773
		if ( is_array( $value ) ) {
774
			$original_function = $function;
775
			if ( count( $value ) ) {
776
				$function = explode( ', ', self::prepare_array_values( $value, $function ) );
0 ignored issues
show
Deprecated Code introduced by
The method FrmAppHelper::prepare_array_values() has been deprecated with message: 2.06

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

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

Loading history...
777
			} else {
778
				$function = array( $function );
779
			}
780
			if ( ! self::is_assoc( $value ) ) {
781
				$value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
782
			} else {
783
				foreach ( $value as $k => $v ) {
784
					if ( ! is_array( $v ) ) {
785
						$value[ $k ] = call_user_func( $original_function, $v );
786
					}
787
				}
788
			}
789
		} else {
790
			$value = call_user_func( $function, $value );
791
		}
792
793
		return $value;
794
	}
795
796
	public static function is_assoc( $array ) {
797
		return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
798
	}
799
800
    /**
801
     * Flatten a multi-dimensional array
802
     */
803
	public static function array_flatten( $array, $keys = 'keep' ) {
804
        $return = array();
805
        foreach ( $array as $key => $value ) {
806
            if ( is_array($value) ) {
807
				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
808
            } else {
809
				if ( $keys == 'keep' ) {
810
					$return[ $key ] = $value;
811
				} else {
812
					$return[] = $value;
813
				}
814
            }
815
        }
816
        return $return;
817
    }
818
819
	public static function esc_textarea( $text, $is_rich_text = false ) {
820
		$safe_text = str_replace( '&quot;', '"', $text );
821
		if ( ! $is_rich_text ) {
822
			$safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
823
		}
824
		$safe_text = str_replace( '&amp;', '&', $safe_text );
825
		return apply_filters( 'esc_textarea', $safe_text, $text );
826
	}
827
828
    /**
829
     * Add auto paragraphs to text areas
830
     * @since 2.0
831
     */
832
	public static function use_wpautop( $content ) {
833
        if ( apply_filters('frm_use_wpautop', true) ) {
834
            $content = wpautop(str_replace( '<br>', '<br />', $content));
835
        }
836
        return $content;
837
    }
838
839
	public static function replace_quotes( $val ) {
840
        //Replace double quotes
841
		$val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
842
        //Replace single quotes
843
        $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
844
        return $val;
845
    }
846
847
    /**
848
     * @since 2.0
849
     * @return string The base Google APIS url for the current version of jQuery UI
850
     */
851
    public static function jquery_ui_base_url() {
852
		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
853
        $url = apply_filters('frm_jquery_ui_base_url', $url);
854
        return $url;
855
    }
856
857
    /**
858
     * @param string $handle
859
     */
860
	public static function script_version( $handle, $default = 0 ) {
861
		global $wp_scripts;
862
		if ( ! $wp_scripts ) {
863
			return $default;
864
		}
865
866
		$ver = $default;
867
		if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
868
			return $ver;
869
		}
870
871
		$query = $wp_scripts->registered[ $handle ];
872
		if ( is_object( $query ) && ! empty( $query->ver ) ) {
873
			$ver = $query->ver;
874
		}
875
876
		return $ver;
877
	}
878
879
	public static function js_redirect( $url ) {
880
		return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
881
    }
882
883
	public static function get_user_id_param( $user_id ) {
884
        if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
885
            return $user_id;
886
        }
887
888
		$user_id = sanitize_text_field( $user_id );
889
		if ( $user_id == 'current' ) {
890
			$user_id = get_current_user_id();
891
		} else {
892
            if ( is_email($user_id) ) {
893
                $user = get_user_by('email', $user_id);
894
            } else {
895
                $user = get_user_by('login', $user_id);
896
            }
897
898
            if ( $user ) {
899
                $user_id = $user->ID;
900
            }
901
            unset($user);
902
        }
903
904
        return $user_id;
905
    }
906
907
	public static function get_file_contents( $filename, $atts = array() ) {
908
        if ( ! is_file($filename) ) {
909
            return false;
910
        }
911
912
        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...
913
        ob_start();
914
        include($filename);
915
        $contents = ob_get_contents();
916
        ob_end_clean();
917
        return $contents;
918
    }
919
920
    /**
921
     * @param string $table_name
922
     * @param string $column
923
	 * @param int $id
924
	 * @param int $num_chars
925
     */
926
    public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
927
        $key = '';
928
929
        if ( ! empty( $name ) ) {
930
            $key = sanitize_key($name);
931
        }
932
933
		if ( empty( $key ) ) {
934
            $max_slug_value = pow(36, $num_chars);
935
            $min_slug_value = 37; // we want to have at least 2 characters in the slug
936
            $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
937
        }
938
939
		if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
940
			$key = $key . 'a';
941
        }
942
943
		$key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column );
944
945
        if ( $key_check || is_numeric($key_check) ) {
946
            $suffix = 2;
947
			do {
948
				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
949
				$key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column );
950
				$suffix++;
951
			} while ( $key_check || is_numeric( $key_check ) );
952
			$key = $alt_post_name;
953
        }
954
        return $key;
955
    }
956
957
    /**
958
     * Editing a Form or Entry
959
     * @param string $table
960
     * @return bool|array
961
     */
962
    public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
963
        if ( ! $record ) {
964
            return false;
965
        }
966
967
        if ( empty($post_values) ) {
968
            $post_values = stripslashes_deep($_POST);
969
        }
970
971
		$values = array( 'id' => $record->id, 'fields' => array() );
972
973
		foreach ( array( 'name', 'description' ) as $var ) {
974
            $default_val = isset($record->{$var}) ? $record->{$var} : '';
975
			$values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
976
            unset($var, $default_val);
977
        }
978
979
        $values['description'] = self::use_wpautop($values['description']);
980
        $frm_settings = self::get_settings();
981
        $is_form_builder = self::is_admin_page('formidable' );
982
983
        foreach ( (array) $fields as $field ) {
984
            // Make sure to filter default values (for placeholder text), but not on the form builder page
985
            if ( ! $is_form_builder ) {
986
                $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
987
            }
988
			$parent_form_id = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
989
			self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings', 'parent_form_id' ) );
990
        }
991
992
        self::fill_form_opts($record, $table, $post_values, $values);
993
994
        if ( $table == 'entries' ) {
995
            $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
996
        } else if ( $table == 'forms' ) {
997
            $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
998
        }
999
1000
        return $values;
1001
    }
1002
1003
	private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1004
        $post_values = $args['post_values'];
1005
1006
        if ( $args['default'] ) {
1007
            $meta_value = $field->default_value;
1008
        } else {
1009
            if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
1010
                if ( ! isset($field->field_options['custom_field']) ) {
1011
                    $field->field_options['custom_field'] = '';
1012
                }
1013
				$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 ) );
1014
            } else {
1015
				$meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1016
            }
1017
        }
1018
1019
		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1020
        $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1021
1022
        $field_array = array(
1023
            'id'            => $field->id,
1024
            'value'         => $new_value,
1025
            'default_value' => $field->default_value,
1026
            'name'          => $field->name,
1027
            'description'   => $field->description,
1028
            'type'          => apply_filters('frm_field_type', $field_type, $field, $new_value),
1029
            'options'       => $field->options,
1030
            'required'      => $field->required,
1031
            'field_key'     => $field->field_key,
1032
            'field_order'   => $field->field_order,
1033
            'form_id'       => $field->form_id,
1034
			'parent_form_id' => $args['parent_form_id'],
1035
        );
1036
1037
        $args['field_type'] = $field_type;
1038
        self::fill_field_opts($field, $field_array, $args);
1039
		// Track the original field's type
1040
		$field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
1041
1042
        $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() );
1043
1044
        if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
1045
            $field_array['unique_msg'] = '';
1046
        }
1047
1048
        $field_array = array_merge( $field->field_options, $field_array );
1049
1050
        $values['fields'][ $field->id ] = $field_array;
1051
    }
1052
1053
	private static function fill_field_opts( $field, array &$field_array, $args ) {
1054
        $post_values = $args['post_values'];
1055
        $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
1056
1057
        foreach ( $opt_defaults as $opt => $default_opt ) {
1058
			$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 );
1059
            if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
1060
                $field_array[ $opt ] = $args['frm_settings']->blank_msg;
1061
            } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
1062
                if ( $args['field_type'] == 'captcha' ) {
1063
                    $field_array[ $opt ] = $args['frm_settings']->re_msg;
1064
                } else {
1065
                    $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1066
                }
1067
            }
1068
        }
1069
1070
        if ( $field_array['custom_html'] == '' ) {
1071
            $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
1072
        }
1073
    }
1074
1075
    /**
1076
     * @param string $table
1077
     */
1078
	private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1079
        if ( $table == 'entries' ) {
1080
            $form = $record->form_id;
1081
			FrmForm::maybe_get_form( $form );
1082
        } else {
1083
            $form = $record;
1084
        }
1085
1086
        if ( ! $form ) {
1087
            return;
1088
        }
1089
1090
        $values['form_name'] = isset($record->form_id) ? $form->name : '';
1091
		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1092
1093
        if ( ! is_array($form->options) ) {
1094
            return;
1095
        }
1096
1097
        foreach ( $form->options as $opt => $value ) {
1098
            $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1099
        }
1100
1101
        self::fill_form_defaults($post_values, $values);
1102
    }
1103
1104
    /**
1105
     * Set to POST value or default
1106
     */
1107
	private static function fill_form_defaults( $post_values, array &$values ) {
1108
        $form_defaults = FrmFormsHelper::get_default_opts();
1109
1110
        foreach ( $form_defaults as $opt => $default ) {
1111
            if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1112
				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1113
            }
1114
1115
            unset($opt, $defaut);
1116
        }
1117
1118
		if ( ! isset( $values['custom_style'] ) ) {
1119
			$values['custom_style'] = self::custom_style_value( $post_values );
1120
		}
1121
1122
		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1123
			if ( ! isset( $values[ $h . '_html' ] ) ) {
1124
				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1125
            }
1126
            unset($h);
1127
        }
1128
    }
1129
1130
	/**
1131
	 * @since 2.2.10
1132
	 * @param array $post_values
1133
	 * @return boolean|int
1134
	 */
1135
	public static function custom_style_value( $post_values ) {
1136
		if ( ! empty( $post_values ) && isset( $post_values['options']['custom_style'] ) ) {
1137
			$custom_style = absint( $post_values['options']['custom_style'] );
1138
		} else {
1139
			$frm_settings = FrmAppHelper::get_settings();
1140
			$custom_style = ( $frm_settings->load_style != 'none' );
1141
		}
1142
		return $custom_style;
1143
	}
1144
1145
	public static function get_meta_value( $field_id, $entry ) {
1146
		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryMeta::get_meta_value' );
1147
		return FrmEntryMeta::get_meta_value( $entry, $field_id );
1148
	}
1149
1150
	public static function insert_opt_html( $args ) {
1151
        $class = '';
1152
        if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
1153
            $class .= 'show_frm_not_email_to';
1154
        }
1155
    ?>
1156
<li>
1157
    <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>
1158
    <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>
1159
    <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>
1160
</li>
1161
    <?php
1162
    }
1163
1164
	public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1165
        if ( is_array( $str ) ) {
1166
            return '';
1167
		}
1168
1169
        $length = (int) $length;
1170
		$str = wp_strip_all_tags( $str );
1171
		$original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1172
1173
		if ( $length == 0 ) {
1174
            return '';
1175
        } else if ( $length <= 10 ) {
1176
			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1177
            return $sub . (($length < $original_len) ? $continue : '');
1178
        }
1179
1180
        $sub = '';
1181
        $len = 0;
1182
1183
		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1184
1185
		foreach ( $words as $word ) {
1186
            $part = (($sub != '') ? ' ' : '') . $word;
1187
			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1188
            if ( $total_len > $length && str_word_count($sub) ) {
1189
                break;
1190
            }
1191
1192
            $sub .= $part;
1193
			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1194
1195
            if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1196
                break;
1197
            }
1198
1199
            unset($total_len, $word);
1200
        }
1201
1202
        return $sub . (($len < $original_len) ? $continue : '');
1203
    }
1204
1205
	public static function mb_function( $function_names, $args ) {
1206
		$mb_function_name = $function_names[0];
1207
		$function_name = $function_names[1];
1208
		if ( function_exists( $mb_function_name ) ) {
1209
			$function_name = $mb_function_name;
1210
		}
1211
		return call_user_func_array( $function_name, $args );
1212
	}
1213
1214
	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1215
        if ( empty($date) ) {
1216
            return $date;
1217
        }
1218
1219
        if ( empty($date_format) ) {
1220
            $date_format = get_option('date_format');
1221
        }
1222
1223
        if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1224
            $frmpro_settings = new FrmProSettings();
1225
            $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1226
        }
1227
1228
		$formatted = self::get_localized_date( $date_format, $date );
1229
1230
		$do_time = ( date( 'H:i:s', strtotime( $date ) ) != '00:00:00' );
1231
		if ( $do_time ) {
1232
			$formatted .= self::add_time_to_date( $time_format, $date );
1233
		}
1234
1235
        return $formatted;
1236
    }
1237
1238
	private static function add_time_to_date( $time_format, $date ) {
1239
		if ( empty( $time_format ) ) {
1240
			$time_format = get_option('time_format');
1241
		}
1242
1243
		$trimmed_format = trim( $time_format );
1244
		$time = '';
1245
		if ( $time_format && ! empty( $trimmed_format ) ) {
1246
			$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...
1247
		}
1248
1249
		return $time;
1250
	}
1251
1252
	/**
1253
	 * @since 2.0.8
1254
	 */
1255
	public static function get_localized_date( $date_format, $date ) {
1256
		$date = get_date_from_gmt( $date );
1257
		return date_i18n( $date_format, strtotime( $date ) );
1258
	}
1259
1260
	/**
1261
	 * Gets the time ago in words
1262
	 *
1263
	 * @param int $from in seconds
1264
	 * @param int|string $to in seconds
1265
	 * @return string $time_ago
1266
	 */
1267
	public static function human_time_diff( $from, $to = '', $levels = 1 ) {
1268
		if ( empty( $to ) ) {
1269
			$now = new DateTime;
1270
		} else {
1271
			$now = new DateTime( '@' . $to );
1272
		}
1273
		$ago = new DateTime( '@' . $from );
1274
1275
		// Get the time difference
1276
		$diff_object = $now->diff( $ago );
1277
		$diff = get_object_vars( $diff_object );
1278
1279
		// Add week amount and update day amount
1280
		$diff['w'] = floor( $diff['d'] / 7 );
1281
		$diff['d'] -= $diff['w'] * 7;
1282
1283
		$time_strings = self::get_time_strings();
1284
1285
		foreach ( $time_strings as $k => $v ) {
1286
			if ( $diff[ $k ] ) {
1287
				$time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
1288
			} else {
1289
				unset( $time_strings[ $k ] );
1290
			}
1291
		}
1292
1293
		$levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
1294
		$time_strings = array_slice( $time_strings, 0, $levels_deep );
1295
		$time_ago_string = $time_strings ? implode( ' ', $time_strings ) : '0 ' . __( 'seconds', 'formidable' );
1296
1297
		return $time_ago_string;
1298
	}
1299
1300
	/**
1301
	 * Get the translatable time strings
1302
	 *
1303
	 * @since 2.0.20
1304
	 * @return array
1305
	 */
1306
	private static function get_time_strings() {
1307
		return array(
1308
			'y' => array( __( 'year', 'formidable' ), __( 'years', 'formidable' ) ),
1309
			'm' => array( __( 'month', 'formidable' ), __( 'months', 'formidable' ) ),
1310
			'w' => array( __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ),
1311
			'd' => array( __( 'day', 'formidable' ), __( 'days', 'formidable' ) ),
1312
			'h' => array( __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ),
1313
			'i' => array( __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ),
1314
			's' => array( __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) ),
1315
		);
1316
	}
1317
1318
    // Pagination Methods
1319
1320
    /**
1321
     * @param integer $current_p
1322
     */
1323
	public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1324
		return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1325
	}
1326
1327
    /**
1328
     * @param integer $current_p
1329
     */
1330
    public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1331
        if ( $current_p == 1 ) {
1332
            return 1;
1333
        } else {
1334
            return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1335
        }
1336
    }
1337
1338
	/**
1339
	 * @return array
1340
	 */
1341
	public static function json_to_array( $json_vars ) {
1342
        $vars = array();
1343
        foreach ( $json_vars as $jv ) {
1344
            $jv_name = explode('[', $jv['name']);
1345
            $last = count($jv_name) - 1;
1346
            foreach ( $jv_name as $p => $n ) {
1347
                $name = trim($n, ']');
1348
                if ( ! isset($l1) ) {
1349
                    $l1 = $name;
1350
                }
1351
1352
                if ( ! isset($l2) ) {
1353
                    $l2 = $name;
1354
                }
1355
1356
                if ( ! isset($l3) ) {
1357
                    $l3 = $name;
1358
                }
1359
1360
                $this_val = ( $p == $last ) ? $jv['value'] : array();
1361
1362
                switch ( $p ) {
1363
                    case 0:
1364
                        $l1 = $name;
1365
                        self::add_value_to_array( $name, $l1, $this_val, $vars );
1366
                    break;
1367
1368
                    case 1:
1369
                        $l2 = $name;
1370
                        self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1371
                    break;
1372
1373 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...
1374
                        $l3 = $name;
1375
                        self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1376
                    break;
1377
1378 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...
1379
                        $l4 = $name;
1380
                        self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1381
                    break;
1382
                }
1383
1384
                unset($this_val, $n);
1385
            }
1386
1387
            unset($last, $jv);
1388
        }
1389
1390
        return $vars;
1391
    }
1392
1393
    /**
1394
     * @param string $name
1395
     * @param string $l1
1396
     */
1397
    public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1398
        if ( $name == '' ) {
1399
            $vars[] = $val;
1400
        } else if ( ! isset( $vars[ $l1 ] ) ) {
1401
            $vars[ $l1 ] = $val;
1402
        }
1403
    }
1404
1405
	public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1406
        $tooltips = array(
1407
            'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1408
            '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' ),
1409
            'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1410
            'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1411
            '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' ),
1412
            'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1413
            '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() ) ),
1414
        );
1415
1416
        if ( ! isset( $tooltips[ $name ] ) ) {
1417
            return;
1418
        }
1419
1420
        if ( 'open' == $class ) {
1421
            echo ' frm_help"';
1422
        } else {
1423
            echo ' class="frm_help"';
1424
        }
1425
1426
		echo ' title="' . esc_attr( $tooltips[ $name ] );
1427
1428
        if ( 'open' != $class ) {
1429
            echo '"';
1430
        }
1431
    }
1432
1433
	/**
1434
	 * Add the current_page class to that page in the form nav
1435
	 */
1436
	public static function select_current_page( $page, $current_page, $action = array() ) {
1437
		if ( $current_page != $page ) {
1438
			return;
1439
		}
1440
1441
		$frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
1442
		if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
1443
			echo ' class="current_page"';
1444
		}
1445
	}
1446
1447
    /**
1448
     * Prepare and json_encode post content
1449
     *
1450
     * @since 2.0
1451
     *
1452
     * @param array $post_content
1453
     * @return string $post_content ( json encoded array )
1454
     */
1455
    public static function prepare_and_encode( $post_content ) {
1456
        //Loop through array to strip slashes and add only the needed ones
1457
		foreach ( $post_content as $key => $val ) {
1458
			// Replace problematic characters (like &quot;)
1459
			$val = str_replace( '&quot;', '"', $val );
1460
1461
			self::prepare_action_slashes( $val, $key, $post_content );
1462
            unset( $key, $val );
1463
        }
1464
1465
        // json_encode the array
1466
        $post_content = json_encode( $post_content );
1467
1468
	    // add extra slashes for \r\n since WP strips them
1469
		$post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1470
1471
        // allow for &quot
1472
	    $post_content = str_replace( '&quot;', '\\"', $post_content );
1473
1474
        return $post_content;
1475
    }
1476
1477
	private static function prepare_action_slashes( $val, $key, &$post_content ) {
1478
		if ( ! isset( $post_content[ $key ] ) ) {
1479
			return;
1480
		}
1481
1482
		if ( is_array( $val ) ) {
1483
			foreach ( $val as $k1 => $v1 ) {
1484
				self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
1485
				unset( $k1, $v1 );
1486
			}
1487
		} else {
1488
			// Strip all slashes so everything is the same, no matter where the value is coming from
1489
			$val = stripslashes( $val );
1490
1491
			// Add backslashes before double quotes and forward slashes only
1492
			$post_content[ $key ] = addcslashes( $val, '"\\/' );
1493
		}
1494
	}
1495
1496
	public static function maybe_json_decode( $string ) {
1497
        if ( is_array($string) ) {
1498
            return $string;
1499
        }
1500
1501
        $new_string = json_decode($string, true);
1502
        if ( function_exists('json_last_error') ) {
1503
			// php 5.3+
1504
            if ( json_last_error() == JSON_ERROR_NONE ) {
1505
                $string = $new_string;
1506
            }
1507
        } else if ( isset($new_string) ) {
1508
			// php < 5.3 fallback
1509
            $string = $new_string;
1510
        }
1511
        return $string;
1512
    }
1513
1514
    /**
1515
     * @since 1.07.10
1516
     *
1517
     * @param string $post_type The name of the post type that may need to be highlighted
1518
     * echo The javascript to open and highlight the Formidable menu
1519
     */
1520
	public static function maybe_highlight_menu( $post_type ) {
1521
        global $post;
1522
1523
        if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1524
            return;
1525
        }
1526
1527
        if ( is_object($post) && $post->post_type != $post_type ) {
1528
            return;
1529
        }
1530
1531
        self::load_admin_wide_js();
1532
        echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1533
    }
1534
1535
    /**
1536
     * Load the JS file on non-Formidable pages in the admin area
1537
     * @since 2.0
1538
     */
1539
	public static function load_admin_wide_js( $load = true ) {
1540
        $version = FrmAppHelper::plugin_version();
1541
		wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1542
1543
        wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
1544
			'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1545
            'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1546
			'url'          => FrmAppHelper::plugin_url(),
1547
			'loading'      => __( 'Loading&hellip;' ),
1548
			'nonce'        => wp_create_nonce( 'frm_ajax' ),
1549
        ) );
1550
1551
		if ( $load ) {
1552
			wp_enqueue_script( 'formidable_admin_global' );
1553
		}
1554
    }
1555
1556
	/**
1557
	 * @since 2.0.9
1558
	 */
1559
	public static function load_font_style() {
1560
		wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
1561
	}
1562
1563
    /**
1564
     * @param string $location
1565
     */
1566
	public static function localize_script( $location ) {
1567
		$ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
1568
		$ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
1569
1570
		wp_localize_script( 'formidable', 'frm_js', array(
1571
			'ajax_url'  => $ajax_url,
1572
			'images_url' => self::plugin_url() . '/images',
1573
			'loading'   => __( 'Loading&hellip;' ),
1574
			'remove'    => __( 'Remove', 'formidable' ),
1575
			'offset'    => apply_filters( 'frm_scroll_offset', 4 ),
1576
			'nonce'     => wp_create_nonce( 'frm_ajax' ),
1577
			'id'        => __( 'ID', 'formidable' ),
1578
			'no_results' => __( 'No results match', 'formidable' ),
1579
			'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
1580
			'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
1581
		) );
1582
1583
		if ( $location == 'admin' ) {
1584
			$frm_settings = self::get_settings();
1585
			wp_localize_script( 'formidable_admin', 'frm_admin_js', array(
1586
				'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' ),
1587
				'desc'              => __( '(Click to add description)', 'formidable' ),
1588
				'blank'             => __( '(Blank)', 'formidable' ),
1589
				'no_label'          => __( '(no label)', 'formidable' ),
1590
				'saving'            => esc_attr( __( 'Saving', 'formidable' ) ),
1591
				'saved'             => esc_attr( __( 'Saved', 'formidable' ) ),
1592
				'ok'                => __( 'OK' ),
1593
				'cancel'            => __( 'Cancel', 'formidable' ),
1594
				'default'           => __( 'Default', 'formidable' ),
1595
				'clear_default'     => __( 'Clear default value when typing', 'formidable' ),
1596
				'no_clear_default'  => __( 'Do not clear default value when typing', 'formidable' ),
1597
				'valid_default'     => __( 'Default value will pass form validation', 'formidable' ),
1598
				'no_valid_default'  => __( 'Default value will NOT pass form validation', 'formidable' ),
1599
				'confirm'           => __( 'Are you sure?', 'formidable' ),
1600
				'conf_delete'       => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
1601
				'conf_delete_sec'   => __( 'WARNING: This will delete all fields inside of the section as well.', 'formidable' ),
1602
				'conf_no_repeat'    => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
1603
				'default_unique'    => $frm_settings->unique_msg,
1604
				'default_conf'      => __( 'The entered values do not match', 'formidable' ),
1605
				'enter_email'       => __( 'Enter Email', 'formidable' ),
1606
				'confirm_email'     => __( 'Confirm Email', 'formidable' ),
1607
				'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' ),
1608
				'enter_password'    => __( 'Enter Password', 'formidable' ),
1609
				'confirm_password'  => __( 'Confirm Password', 'formidable' ),
1610
				'import_complete'   => __( 'Import Complete', 'formidable' ),
1611
				'updating'          => __( 'Please wait while your site updates.', 'formidable' ),
1612
				'no_save_warning'   => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
1613
				'private'           => __( 'Private' ),
1614
				'jquery_ui_url'     => self::jquery_ui_base_url(),
1615
				'no_licenses'       => __( 'No new licenses were found', 'formidable' ),
1616
				'repeat_limit_min'  => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
1617
			) );
1618
		}
1619
	}
1620
1621
    /**
1622
	 * echo the message on the plugins listing page
1623
     * @since 1.07.10
1624
     *
1625
     * @param float $min_version The version the add-on requires
1626
     */
1627
	public static function min_version_notice( $min_version ) {
1628
        $frm_version = self::plugin_version();
1629
1630
        // check if Formidable meets minimum requirements
1631
        if ( version_compare($frm_version, $min_version, '>=') ) {
1632
            return;
1633
        }
1634
1635
        $wp_list_table = _get_list_table('WP_Plugins_List_Table');
1636
		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">' .
1637
        __( '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...
1638
        '</div></td></tr>';
1639
    }
1640
1641
    public static function locales( $type = 'date' ) {
1642
        $locales = array(
1643
            'en' => __( 'English', 'formidable' ),    '' => __( 'English/Western', 'formidable' ),
1644
            'af' => __( 'Afrikaans', 'formidable' ),  'sq' => __( 'Albanian', 'formidable' ),
1645
            'ar' => __( 'Arabic', 'formidable' ),     'hy' => __( 'Armenian', 'formidable' ),
1646
            'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
1647
            'bs' => __( 'Bosnian', 'formidable' ),    'bg' => __( 'Bulgarian', 'formidable' ),
1648
            'ca' => __( 'Catalan', 'formidable' ),    'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1649
            'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1650
            'hr' => __( 'Croatian', 'formidable' ),   'cs' => __( 'Czech', 'formidable' ),
1651
            'da' => __( 'Danish', 'formidable' ),     'nl' => __( 'Dutch', 'formidable' ),
1652
            'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
1653
            'et' => __( 'Estonian', 'formidable' ),   'fo' => __( 'Faroese', 'formidable' ),
1654
            'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
1655
            'fi' => __( 'Finnish', 'formidable' ),    'fr' => __( 'French', 'formidable' ),
1656
            'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1657
            'de' => __( 'German', 'formidable' ),     'de-AT' => __( 'German/Austria', 'formidable' ),
1658
            'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
1659
            'he' => __( 'Hebrew', 'formidable' ),     'iw' => __( 'Hebrew', 'formidable' ),
1660
            'hi' => __( 'Hindi', 'formidable' ),      'hu' => __( 'Hungarian', 'formidable' ),
1661
            'is' => __( 'Icelandic', 'formidable' ),  'id' => __( 'Indonesian', 'formidable' ),
1662
            'it' => __( 'Italian', 'formidable' ),    'ja' => __( 'Japanese', 'formidable' ),
1663
            'ko' => __( 'Korean', 'formidable' ),     'lv' => __( 'Latvian', 'formidable' ),
1664
            'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
1665
            'no' => __( 'Norwegian', 'formidable' ),  'pl' => __( 'Polish', 'formidable' ),
1666
            'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1667
            'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
1668
            'ru' => __( 'Russian', 'formidable' ),    'sr' => __( 'Serbian', 'formidable' ),
1669
            'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
1670
            'sl' => __( 'Slovenian', 'formidable' ),  'es' => __( 'Spanish', 'formidable' ),
1671
            'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
1672
            'ta' => __( 'Tamil', 'formidable' ),      'th' => __( 'Thai', 'formidable' ),
1673
            'tu' => __( 'Turkish', 'formidable' ),    'tr' => __( 'Turkish', 'formidable' ),
1674
            'uk' => __( 'Ukranian', 'formidable' ),   'vi' => __( 'Vietnamese', 'formidable' ),
1675
        );
1676
1677
        if ( $type == 'captcha' ) {
1678
            // remove the languages unavailable for the captcha
1679
            $unset = array(
1680
                '', 'af', 'sq', 'hy', 'az', 'eu', 'bs',
1681
                'zh-HK', 'eo', 'et', 'fo', 'fr-CH',
1682
                'he', 'is', 'ms', 'sr-SR', 'ta', 'tu',
1683
            );
1684
        } else {
1685
            // remove the languages unavailable for the datepicker
1686
            $unset = array(
1687
                'en', 'fil', 'fr-CA', 'de-AT', 'de-AT',
1688
                'de-CH', 'iw', 'hi', 'pt', 'pt-PT',
1689
                'es-419', 'tr',
1690
            );
1691
        }
1692
1693
        $locales = array_diff_key($locales, array_flip($unset));
1694
        $locales = apply_filters('frm_locales', $locales);
1695
1696
        return $locales;
1697
    }
1698
1699
	/**
1700
	 * Prepare and save settings in styles and actions
1701
	 *
1702
	 * @param array $settings
1703
	 * @param string $group
1704
	 *
1705
	 * @since 2.0.6
1706
	 * @deprecated 2.06
1707
	 */
1708
	public static function save_settings( $settings, $group ) {
1709
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1710
		return FrmDb::save_settings( $settings, $group );
1711
	}
1712
1713
	/**
1714
	 * Since actions are JSON encoded, we don't want any filters messing with it.
1715
	 * Remove the filters and then add them back in case any posts or views are
1716
	 * also being imported.
1717
	 *
1718
	 * Used when saving form actions and styles
1719
	 *
1720
	 * @since 2.0.4
1721
	 * @deprecated 2.06
1722
	 */
1723
	public static function save_json_post( $settings ) {
1724
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1725
		return FrmDb::save_json_post( $settings );
1726
	}
1727
1728
    /**
1729
     * Check cache before fetching values and saving to cache
1730
     *
1731
     * @since 2.0
1732
	 * @deprecated 2.06
1733
     *
1734
     * @param string $cache_key The unique name for this cache
1735
     * @param string $group The name of the cache group
1736
     * @param string $query If blank, don't run a db call
1737
     * @param string $type The wpdb function to use with this query
1738
     * @return mixed $results The cache or query results
1739
     */
1740
    public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
1741
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1742
		return FrmDb::check_cache( $cache_key, $group, $query, $type, $time );
1743
	}
1744
1745
	/**
1746
	 * @deprecated 2.06
1747
	 */
1748
	public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
1749
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1750
		FrmDb::set_cache( $cache_key, $results, $group, $time );
1751
	}
1752
1753
	/**
1754
	 * Keep track of the keys cached in each group so they can be deleted
1755
	 * in Redis and Memcache
1756
	 * @deprecated 2.06
1757
	 */
1758
	public static function add_key_to_group_cache( $key, $group ) {
1759
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1760
		FrmDb::add_key_to_group_cache( $key, $group );
1761
	}
1762
1763
	public static function get_group_cached_keys( $group ) {
1764
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1765
		return FrmDb::get_group_cached_keys( $group );
1766
	}
1767
1768
    /**
1769
     * @since 2.0
1770
	 * @deprecated 2.06
1771
     * @return mixed The cached value or false
1772
     */
1773
	public static function check_cache_and_transient( $cache_key ) {
1774
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1775
        return FrmDb::check_cache_and_transient( $cache_key );
1776
    }
1777
1778
    /**
1779
     * @since 2.0
1780
	 * @deprecated 2.06
1781
     * @param string $cache_key
1782
     */
1783
	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
1784
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1785
		FrmDb::delete_cache_and_transient( $cache_key, $group );
1786
	}
1787
1788
    /**
1789
     * @since 2.0
1790
	 * @deprecated 2.06
1791
     *
1792
     * @param string $group The name of the cache group
1793
     */
1794
	public static function cache_delete_group( $group ) {
1795
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1796
		FrmDb::cache_delete_group( $group );
1797
	}
1798
1799
	/**
1800
	 * Added for < WP 4.0 compatability
1801
	 *
1802
	 * @since 1.07.10
1803
	 * @deprecated 2.06
1804
	 *
1805
	 * @param string $term The value to escape
1806
	 * @return string The escaped value
1807
	 */
1808
	public static function esc_like( $term ) {
1809
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1810
		return FrmDb::esc_like( $term );
1811
	}
1812
1813
	/**
1814
	 * @param string $order_query
1815
	 * @deprecated 2.06
1816
	 */
1817
	public static function esc_order( $order_query ) {
1818
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1819
		return FrmDb::esc_order( $order_query );
1820
	}
1821
1822
	/**
1823
	 * Make sure this is ordering by either ASC or DESC
1824
	 * @deprecated 2.06
1825
	 */
1826
	public static function esc_order_by( &$order_by ) {
1827
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1828
		FrmDb::esc_order_by( $order_by );
1829
	}
1830
1831
	/**
1832
	 * @param string $limit
1833
	 * @deprecated 2.06
1834
	 */
1835
	public static function esc_limit( $limit ) {
1836
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1837
		return FrmDb::esc_limit( $limit );
1838
	}
1839
1840
	/**
1841
	 * Get an array of values ready to go through $wpdb->prepare
1842
	 * @since 2.0
1843
	 * @deprecated 2.06
1844
	 */
1845
	public static function prepare_array_values( $array, $type = '%s' ) {
1846
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1847
		return FrmDb::prepare_array_values( $array, $type );
1848
	}
1849
1850
	/**
1851
	 * @deprecated 2.06
1852
	 */
1853
	public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
1854
		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1855
		return FrmDb::prepend_and_or_where( $starts_with, $where );
1856
	}
1857
}
1858