Completed
Push — master ( d7245b...ea9fef )
by Stephanie
03:05
created

FrmAppHelper::admin_upgrade_link()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
	die( 'You are not allowed to call this page directly.' );
4
}
5
6
class FrmAppHelper {
7
	public static $db_version = 88; //version of the database we are moving to
8
	public static $pro_db_version = 37; //deprecated
9
	public static $font_version = 3;
10
11
	/**
12
	 * @since 2.0
13
	 */
14
	public static $plug_version = '3.04.01';
15
16
    /**
17
     * @since 1.07.02
18
     *
19
     * @param none
20
     * @return string The version of this plugin
21
     */
22
    public static function plugin_version() {
23
        return self::$plug_version;
24
    }
25
26
	public static function plugin_folder() {
27
		return basename( self::plugin_path() );
28
	}
29
30
	public static function plugin_path() {
31
		return dirname( dirname( dirname( __FILE__ ) ) );
32
	}
33
34
    public static function plugin_url() {
35
        //prevously FRM_URL constant
36
		return plugins_url( '', self::plugin_path() . '/formidable.php' );
37
    }
38
39
	public static function relative_plugin_url() {
40
		return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
41
	}
42
43
    /**
44
     * @return string Site URL
45
     */
46
    public static function site_url() {
47
        return site_url();
48
    }
49
50
    /**
51
     * Get the name of this site
52
     * Used for [sitename] shortcode
53
     *
54
     * @since 2.0
55
     * @return string
56
     */
57
	public static function site_name() {
58
		return get_option( 'blogname' );
59
	}
60
61
	public static function make_affiliate_url( $url ) {
62
		$affiliate_id = self::get_affiliate();
63
		if ( ! empty( $affiliate_id ) ) {
64
			$url = str_replace( array( 'http://', 'https://' ), '', $url );
65
			$url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
66
		}
67
		return $url;
68
	}
69
70
	public static function get_affiliate() {
71
		return absint( apply_filters( 'frm_affiliate_id', 0 ) );
72
	}
73
74
	/**
75
	 * @since 3.04.02
76
	 */
77
	public static function admin_upgrade_link( $medium, $page = '' ) {
78
		if ( empty( $page ) ) {
79
			$page = 'https://formidableforms.com/pricing-lite/';
80
		} else {
81
			$page = 'https://formidableforms.com/' . $page;
82
		}
83
		$query_args = array(
84
			'utm_source'   => 'WordPress',
85
			'utm_medium'   => $medium,
86
			'utm_campaign' => 'liteplugin',
87
		);
88
		return add_query_arg( $query_args, $page );
89
	}
90
91
    /**
92
     * Get the Formidable settings
93
     *
94
     * @since 2.0
95
     *
96
     * @param None
97
     * @return FrmSettings $frm_setings
98
     */
99
	public static function get_settings() {
100
		global $frm_settings;
101
		if ( empty( $frm_settings ) ) {
102
			$frm_settings = new FrmSettings();
103
		}
104
		return $frm_settings;
105
	}
106
107
	public static function get_menu_name() {
108
		$frm_settings = FrmAppHelper::get_settings();
109
		return $frm_settings->menu;
110
	}
111
112
	/**
113
	 * @since 2.02.04
114
	 */
115
	public static function ips_saved() {
116
		$frm_settings = self::get_settings();
117
		return ! $frm_settings->no_ips;
118
	}
119
120
	public static function pro_is_installed() {
121
		return apply_filters( 'frm_pro_installed', false );
122
	}
123
124
	public static function is_formidable_admin() {
125
		$page = self::simple_get( 'page', 'sanitize_title' );
126
		$is_formidable = strpos( $page, 'formidable' ) !== false;
127
		if ( empty( $page ) ) {
128
			global $pagenow;
129
			$post_type = self::simple_get( 'post_type', 'sanitize_title' );
130
			$is_formidable = ( $post_type == 'frm_display' );
131
			if ( empty( $post_type ) && $pagenow == 'post.php' ) {
132
				global $post;
133
				$is_formidable = ( $post && $post->post_type == 'frm_display' );
134
			}
135
		}
136
		return $is_formidable;
137
	}
138
139
    /**
140
     * Check for certain page in Formidable settings
141
     *
142
     * @since 2.0
143
     *
144
     * @param string $page The name of the page to check
145
     * @return boolean
146
     */
147
	public static function is_admin_page( $page = 'formidable' ) {
148
        global $pagenow;
149
		$get_page = self::simple_get( 'page', 'sanitize_title' );
150
        if ( $pagenow ) {
151
			// allow this to be true during ajax load i.e. ajax form builder loading
152
			return ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page;
153
        }
154
155
		return is_admin() && $get_page == $page;
156
    }
157
158
    /**
159
     * Check for the form preview page
160
     *
161
     * @since 2.0
162
     *
163
     * @param None
164
     * @return boolean
165
     */
166
    public static function is_preview_page() {
167
        global $pagenow;
168
		$action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
169
		return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
170
    }
171
172
    /**
173
     * Check for ajax except the form preview page
174
     *
175
     * @since 2.0
176
     *
177
     * @param None
178
     * @return boolean
179
     */
180
    public static function doing_ajax() {
181
        return self::wp_doing_ajax() && ! self::is_preview_page();
182
    }
183
184
	public static function js_suffix() {
185
		return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
186
	}
187
188
	/**
189
	 * Use the WP 4.7 wp_doing_ajax function
190
	 * @since 2.05.07
191
	 */
192
	public static function wp_doing_ajax() {
193
		if ( function_exists( 'wp_doing_ajax' ) ) {
194
			$doing_ajax = wp_doing_ajax();
195
		} else {
196
			$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
197
		}
198
		return $doing_ajax;
199
	}
200
201
	/**
202
	 * @since 2.0.8
203
	 */
204
	public static function prevent_caching() {
205
		global $frm_vars;
206
		return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
207
	}
208
209
    /**
210
     * Check if on an admin page
211
     *
212
     * @since 2.0
213
     *
214
     * @param None
215
     * @return boolean
216
     */
217
    public static function is_admin() {
218
        return is_admin() && ! self::wp_doing_ajax();
219
    }
220
221
    /**
222
     * Check if value contains blank value or empty array
223
     *
224
     * @since 2.0
225
     * @param mixed $value - value to check
226
	 * @param string
227
     * @return boolean
228
     */
229
    public static function is_empty_value( $value, $empty = '' ) {
230
        return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
231
    }
232
233
    public static function is_not_empty_value( $value, $empty = '' ) {
234
        return ! self::is_empty_value( $value, $empty );
235
    }
236
237
    /**
238
     * Get any value from the $_SERVER
239
     *
240
     * @since 2.0
241
     * @param string $value
242
     * @return string
243
     */
244
	public static function get_server_value( $value ) {
245
        return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
246
    }
247
248
    /**
249
     * Check for the IP address in several places
250
     * Used by [ip] shortcode
251
     *
252
     * @return string The IP address of the current user
253
     */
254
    public static function get_ip_address() {
255
		$ip = '';
256
		foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
257
            if ( ! isset( $_SERVER[ $key ] ) ) {
258
                continue;
259
            }
260
261
            foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
262
				$ip = trim( $ip ); // just to be safe
263
264
				if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
265
                    return sanitize_text_field( $ip );
266
                }
267
            }
268
        }
269
270
		return sanitize_text_field( $ip );
271
    }
272
273
    public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
274
		if ( strpos( $param, '[' ) ) {
275
			$params = explode( '[', $param );
276
            $param = $params[0];
277
        }
278
279
		if ( $src == 'get' ) {
280
            $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
281
            if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
282
                $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
283
            }
284
			self::sanitize_value( $sanitize, $value );
285
		} else {
286
			$value = self::get_simple_request(
287
				array(
288
					'type'     => $src,
289
					'param'    => $param,
290
					'default'  => $default,
291
					'sanitize' => $sanitize,
292
				)
293
			);
294
		}
295
296
		if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
297
			foreach ( $params as $k => $p ) {
298
				if ( ! $k || ! is_array( $value ) ) {
299
					continue;
300
				}
301
302
				$p = trim( $p, ']' );
303
				$value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
304
			}
305
		}
306
307
        return $value;
308
    }
309
310 View Code Duplication
	public static function get_post_param( $param, $default = '', $sanitize = '' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
311
		return self::get_simple_request(
312
			array(
313
				'type'     => 'post',
314
				'param'    => $param,
315
				'default'  => $default,
316
				'sanitize' => $sanitize,
317
			)
318
		);
319
	}
320
321
	/**
322
	 * @since 2.0
323
	 *
324
	 * @param string $param
325
	 * @param string $sanitize
326
	 * @param string $default
327
	 * @return string|array
328
	 */
329 View Code Duplication
	public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
330
		return self::get_simple_request(
331
			array(
332
				'type'     => 'get',
333
				'param'    => $param,
334
				'default'  => $default,
335
				'sanitize' => $sanitize,
336
			)
337
		);
338
	}
339
340
	/**
341
	 * Get a GET/POST/REQUEST value and sanitize it
342
	 *
343
	 * @since 2.0.6
344
	 * @param array $args
345
	 * @return string|array
346
	 */
347
	public static function get_simple_request( $args ) {
348
		$defaults = array(
349
			'param'    => '',
350
			'default'  => '',
351
			'type'     => 'get',
352
			'sanitize' => 'sanitize_text_field',
353
		);
354
		$args = wp_parse_args( $args, $defaults );
355
356
		$value = $args['default'];
357
		if ( $args['type'] == 'get' ) {
358
			if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
359
				$value = $_GET[ $args['param'] ];
360
			}
361
		} else if ( $args['type'] == 'post' ) {
362
			if ( isset( $_POST[ $args['param'] ] ) ) {
363
				$value = stripslashes_deep( maybe_unserialize( $_POST[ $args['param'] ] ) );
364
			}
365
		} else {
366
			if ( isset( $_REQUEST[ $args['param'] ] ) ) {
367
				$value = $_REQUEST[ $args['param'] ];
368
			}
369
		}
370
371
		self::sanitize_value( $args['sanitize'], $value );
372
		return $value;
373
	}
374
375
	/**
376
	* Preserve backslashes in a value, but make sure value doesn't get compounding slashes
377
	*
378
	* @since 2.0.8
379
	* @param string $value
380
	* @return string $value
381
	*/
382
	public static function preserve_backslashes( $value ) {
383
		// If backslashes have already been added, don't add them again
384
		if ( strpos( $value, '\\\\' ) === false ) {
385
			$value = addslashes( $value );
386
		}
387
		return $value;
388
	}
389
390
	public static function sanitize_value( $sanitize, &$value ) {
391
		if ( ! empty( $sanitize ) ) {
392
			if ( is_array( $value ) ) {
393
				$temp_values = $value;
394
				foreach ( $temp_values as $k => $v ) {
395
					FrmAppHelper::sanitize_value( $sanitize, $value[ $k ] );
396
				}
397
			} else {
398
				$value = call_user_func( $sanitize, $value );
399
			}
400
		}
401
	}
402
403
    public static function sanitize_request( $sanitize_method, &$values ) {
404
        $temp_values = $values;
405
        foreach ( $temp_values as $k => $val ) {
406
            if ( isset( $sanitize_method[ $k ] ) ) {
407
				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
408
            }
409
        }
410
    }
411
412
	/**
413
	 * @deprecated 3.01
414
	 * @codeCoverageIgnore
415
	 */
416
	public static function sanitize_array( &$values ) {
417
		_deprecated_function( __METHOD__, '3.01', 'FrmAppHelper::sanitize_value' );
418
		self::sanitize_value( 'wp_kses_post', $values );
419
	}
420
421
	/**
422
	 * Sanitize the value, and allow some HTML
423
	 * @since 2.0
424
	 * @param string $value
425
	 * @param array|string $allowed 'all' for everything included as defaults
426
	 * @return string
427
	 */
428
	public static function kses( $value, $allowed = array() ) {
429
		$allowed_html = self::allowed_html( $allowed );
430
431
		return wp_kses( $value, $allowed_html );
432
	}
433
434
	/**
435
	 * @since 2.05.03
436
	 */
437
	private static function allowed_html( $allowed ) {
438
		$html = self::safe_html();
439
		$allowed_html = array();
440
		if ( $allowed == 'all' ) {
441
			$allowed_html = $html;
442
		} elseif ( ! empty( $allowed ) ) {
443
			foreach ( (array) $allowed as $a ) {
444
				$allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
445
			}
446
		}
447
448
		return apply_filters( 'frm_striphtml_allowed_tags', $allowed_html );
449
	}
450
451
	/**
452
	 * @since 2.05.03
453
	 */
454
	private static function safe_html() {
455
		$allow_class = array(
456
			'class' => array(),
457
			'id'    => array(),
458
		);
459
460
		return array(
461
			'a' => array(
462
				'class' => array(),
463
				'href'  => array(),
464
				'id'    => array(),
465
				'rel'   => array(),
466
				'target' => array(),
467
				'title' => array(),
468
			),
469
			'abbr' => array(
470
				'title' => array(),
471
			),
472
			'aside' => $allow_class,
473
			'b' => array(),
474
			'blockquote' => array(
475
				'cite'  => array(),
476
			),
477
			'br'   => array(),
478
			'cite' => array(
479
				'title' => array(),
480
			),
481
			'code' => array(),
482
			'del'  => array(
483
				'datetime' => array(),
484
				'title' => array(),
485
			),
486
			'dd'  => array(),
487
			'div' => array(
488
				'class' => array(),
489
				'id'    => array(),
490
				'title' => array(),
491
				'style' => array(),
492
			),
493
			'dl'  => array(),
494
			'dt'  => array(),
495
			'em'  => array(),
496
			'h1'  => $allow_class,
497
			'h2'  => $allow_class,
498
			'h3'  => $allow_class,
499
			'h4'  => $allow_class,
500
			'h5'  => $allow_class,
501
			'h6'  => $allow_class,
502
			'i'   => array(
503
				'class' => array(),
504
				'id'    => array(),
505
				'icon'  => array(),
506
			),
507
			'img' => array(
508
				'alt'    => array(),
509
				'class'  => array(),
510
				'height' => array(),
511
				'id'     => array(),
512
				'src'    => array(),
513
				'width'  => array(),
514
			),
515
			'li'  => $allow_class,
516
			'ol'  => $allow_class,
517
			'p'   => $allow_class,
518
			'pre' => array(),
519
			'q'   => array(
520
				'cite' => array(),
521
				'title' => array(),
522
			),
523
			'section' => $allow_class,
524
			'span' => array(
525
				'class' => array(),
526
				'id'    => array(),
527
				'title' => array(),
528
				'style' => array(),
529
			),
530
			'strike' => array(),
531
			'strong' => array(),
532
			'ul' => $allow_class,
533
		);
534
	}
535
536
    /**
537
     * Used when switching the action for a bulk action
538
     * @since 2.0
539
     */
540
	public static function remove_get_action() {
541
		if ( ! isset( $_GET ) ) {
542
			return;
543
		}
544
545
        $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
546
        if ( ! empty( $new_action ) ) {
547
			$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
548
        }
549
    }
550
551
    /**
552
     * Check the WP query for a parameter
553
     *
554
     * @since 2.0
555
     * @return string|array
556
     */
557
    public static function get_query_var( $value, $param ) {
558
        if ( $value != '' ) {
559
            return $value;
560
        }
561
562
        global $wp_query;
563
        if ( isset( $wp_query->query_vars[ $param ] ) ) {
564
            $value = $wp_query->query_vars[ $param ];
565
        }
566
567
        return $value;
568
    }
569
570
	/**
571
	 * @since 3.0
572
	 */
573
	public static function get_admin_header( $atts ) {
574
		$has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) );
575
		include( self::plugin_path() . '/classes/views/shared/admin-header.php' );
576
	}
577
578
	/**
579
	 * @since 3.0
580
	 */
581
	public static function add_new_item_link( $atts ) {
582
		if ( isset( $atts['new_link'] ) && ! empty( $atts['new_link'] ) ) { ?>
583
			<a href="<?php echo esc_url( $atts['new_link'] ) ?>" class="add-new-h2 frm_animate_bg"><?php esc_html_e( 'Add New', 'formidable' ); ?></a>
584
		<?php
585
		} elseif ( isset( $atts['link_hook'] ) ) {
586
			do_action( $atts['link_hook']['hook'], $atts['link_hook']['param'] );
587
		}
588
	}
589
590
    /**
591
     * @param string $type
592
     */
593
    public static function trigger_hook_load( $type, $object = null ) {
594
        // only load the form hooks once
595
		$hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
596
        if ( ! $hooks_loaded ) {
597
			do_action( 'frm_load_' . $type . '_hooks' );
598
        }
599
    }
600
601
	/**
602
	 * Save all front-end js scripts into a single file
603
	 *
604
	 * @since 3.0
605
	 */
606
	public static function save_combined_js() {
607
		$file_atts = apply_filters(
608
			'frm_js_location',
609
			array(
610
				'file_name' => 'frm.min.js',
611
				'new_file_path' => FrmAppHelper::plugin_path() . '/js',
612
			)
613
		);
614
		$new_file = new FrmCreateFile( $file_atts );
615
616
		$files = array(
617
			FrmAppHelper::plugin_path() . '/js/jquery/jquery.placeholder.min.js',
618
			FrmAppHelper::plugin_path() . '/js/formidable.min.js',
619
		);
620
		$files = apply_filters( 'frm_combined_js_files', $files );
621
		$new_file->combine_files( $files );
622
	}
623
624
    /**
625
     * Check a value from a shortcode to see if true or false.
626
     * True when value is 1, true, 'true', 'yes'
627
     *
628
     * @since 1.07.10
629
     *
630
     * @param string $value The value to compare
631
     * @return boolean True or False
632
     */
633
	public static function is_true( $value ) {
634
        return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
635
    }
636
637
    /**
638
     * Used to filter shortcode in text widgets
639
	 *
640
	 * @deprecated 2.5.4
641
	 * @codeCoverageIgnore
642
     */
643
    public static function widget_text_filter_callback( $matches ) {
644
		_deprecated_function( __METHOD__, '2.5.4' );
645
        return do_shortcode( $matches[0] );
646
    }
647
648
	public static function get_pages() {
649
		$query = array(
650
			'post_type'   => 'page',
651
			'post_status' => array( 'publish', 'private' ),
652
			'numberposts' => -1,
0 ignored issues
show
introduced by
Disabling pagination is prohibited in VIP context, do not set numberposts to -1 ever.
Loading history...
653
			'orderby'     => 'title',
654
			'order'       => 'ASC',
655
		);
656
		return get_posts( $query );
657
	}
658
659
    public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
660
        $pages = self::get_pages();
661
		$selected = self::get_post_param( $field_name, $page_id, 'absint' );
662
    ?>
663
		<select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" class="frm-pages-dropdown">
664
            <option value=""> </option>
665
            <?php foreach ( $pages as $page ) { ?>
666
				<option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ); ?>>
667
					<?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?>
668
				</option>
669
            <?php } ?>
670
        </select>
671
    <?php
672
    }
673
674
	public static function post_edit_link( $post_id ) {
675
		$post = get_post( $post_id );
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
676
        if ( $post ) {
677
			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
678
			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
679
        }
680
        return '';
681
    }
682
683
	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
684
		?>
685
		<select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" <?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?> class="frm_multiselect">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
686
			<?php self::roles_options( $capability ); ?>
687
		</select>
688
		<?php
689
	}
690
691
	public static function roles_options( $capability ) {
692
        global $frm_vars;
693
		if ( isset( $frm_vars['editable_roles'] ) ) {
694
            $editable_roles = $frm_vars['editable_roles'];
695
        } else {
696
            $editable_roles = get_editable_roles();
697
            $frm_vars['editable_roles'] = $editable_roles;
698
        }
699
700
        foreach ( $editable_roles as $role => $details ) {
701
			$name = translate_user_role( $details['name'] );
702
			?>
703
		<option value="<?php echo esc_attr( $role ); ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ); ?> </option>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'in_array'
Loading history...
704
<?php
705
			unset( $role, $details );
706
        }
707
    }
708
709
	public static function frm_capabilities( $type = 'auto' ) {
710
        $cap = array(
711
            'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
712
            'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
713
            'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
714
            'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
715
            'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
716
            'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
717
        );
718
719
		if ( ! self::pro_is_installed() && 'pro' != $type ) {
720
            return $cap;
721
        }
722
723
        $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
724
        $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
725
        $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
726
        $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
727
728
        return $cap;
729
    }
730
731
	public static function user_has_permission( $needed_role ) {
732
        if ( $needed_role == '-1' ) {
733
            return false;
734
		}
735
736
        // $needed_role will be equal to blank if "Logged-in users" is selected
737
        if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
738
            return true;
739
        }
740
741
        $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
742
        foreach ( $roles as $role ) {
743
			if ( current_user_can( $role ) ) {
744
        		return true;
745
			}
746
        	if ( $role == $needed_role ) {
747
        		break;
748
			}
749
        }
750
        return false;
751
    }
752
753
    /**
754
     * Make sure administrators can see Formidable menu
755
     *
756
     * @since 2.0
757
     */
758
    public static function maybe_add_permissions() {
759
		self::force_capability( 'frm_view_entries' );
760
761
		if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
762
			return;
763
		}
764
765
		$user_id = get_current_user_id();
766
		$user = new WP_User( $user_id );
767
        $frm_roles = self::frm_capabilities();
768
        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
769
			$user->add_cap( $frm_role );
770
			unset( $frm_role, $frm_role_description );
771
        }
772
    }
773
774
	/**
775
	 * Make sure admins have permission to see the menu items
776
	 * @since 2.0.6
777
	 */
778
	public static function force_capability( $cap = 'frm_change_settings' ) {
779
		if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
780
			$role = get_role( 'administrator' );
781
			$frm_roles = self::frm_capabilities();
782
			foreach ( $frm_roles as $frm_role => $frm_role_description ) {
783
				$role->add_cap( $frm_role );
784
			}
785
		}
786
	}
787
788
    /**
789
     * Check if the user has permision for action.
790
     * Return permission message and stop the action if no permission
791
     * @since 2.0
792
     * @param string $permission
793
     */
794
	public static function permission_check( $permission, $show_message = 'show' ) {
795
		$permission_error = self::permission_nonce_error( $permission );
796
        if ( $permission_error !== false ) {
797
            if ( 'hide' == $show_message ) {
798
                $permission_error = '';
799
            }
800
			wp_die( esc_html( $permission_error ) );
801
        }
802
    }
803
804
    /**
805
     * Check user permission and nonce
806
     * @since 2.0
807
     * @param string $permission
808
     * @return false|string The permission message or false if allowed
809
     */
810
	public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
811
		if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
812
			$frm_settings = self::get_settings();
813
			return $frm_settings->admin_permission;
814
		}
815
816
		$error = false;
817
		if ( empty( $nonce_name ) ) {
818
            return $error;
819
        }
820
821
        if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
822
            $frm_settings = self::get_settings();
823
            $error = $frm_settings->admin_permission;
824
        }
825
826
        return $error;
827
    }
828
829
    public static function checked( $values, $current ) {
830
		if ( self::check_selected( $values, $current ) ) {
831
            echo ' checked="checked"';
832
		}
833
    }
834
835
	public static function check_selected( $values, $current ) {
836
		$values = self::recursive_function_map( $values, 'trim' );
837
		$values = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
838
		$current = htmlspecialchars_decode( trim( $current ) );
839
840
		return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
841
	}
842
843
	public static function recursive_function_map( $value, $function ) {
844
		if ( is_array( $value ) ) {
845
			$original_function = $function;
846
			if ( count( $value ) ) {
847
				$function = explode( ', ', FrmDb::prepare_array_values( $value, $function ) );
848
			} else {
849
				$function = array( $function );
850
			}
851
			if ( ! self::is_assoc( $value ) ) {
852
				$value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
853
			} else {
854
				foreach ( $value as $k => $v ) {
855
					if ( ! is_array( $v ) ) {
856
						$value[ $k ] = call_user_func( $original_function, $v );
857
					}
858
				}
859
			}
860
		} else {
861
			$value = call_user_func( $function, $value );
862
		}
863
864
		return $value;
865
	}
866
867
	public static function is_assoc( $array ) {
868
		return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
869
	}
870
871
    /**
872
     * Flatten a multi-dimensional array
873
     */
874
	public static function array_flatten( $array, $keys = 'keep' ) {
875
        $return = array();
876
        foreach ( $array as $key => $value ) {
877
			if ( is_array( $value ) ) {
878
				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
879
            } else {
880
				if ( $keys == 'keep' ) {
881
					$return[ $key ] = $value;
882
				} else {
883
					$return[] = $value;
884
				}
885
            }
886
        }
887
        return $return;
888
    }
889
890
	public static function esc_textarea( $text, $is_rich_text = false ) {
891
		$safe_text = str_replace( '&quot;', '"', $text );
892
		if ( ! $is_rich_text ) {
893
			$safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
894
		}
895
		$safe_text = str_replace( '&amp;', '&', $safe_text );
896
		return apply_filters( 'esc_textarea', $safe_text, $text );
897
	}
898
899
    /**
900
     * Add auto paragraphs to text areas
901
     * @since 2.0
902
     */
903
	public static function use_wpautop( $content ) {
904
		if ( apply_filters( 'frm_use_wpautop', true ) ) {
905
			$content = wpautop( str_replace( '<br>', '<br />', $content ) );
906
		}
907
		return $content;
908
	}
909
910
	public static function replace_quotes( $val ) {
911
        //Replace double quotes
912
		$val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
913
        //Replace single quotes
914
        $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
915
        return $val;
916
    }
917
918
    /**
919
     * @since 2.0
920
     * @return string The base Google APIS url for the current version of jQuery UI
921
     */
922
    public static function jquery_ui_base_url() {
923
		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
924
		$url = apply_filters( 'frm_jquery_ui_base_url', $url );
925
        return $url;
926
    }
927
928
    /**
929
     * @param string $handle
930
     */
931
	public static function script_version( $handle, $default = 0 ) {
932
		global $wp_scripts;
933
		if ( ! $wp_scripts ) {
934
			return $default;
935
		}
936
937
		$ver = $default;
938
		if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
939
			return $ver;
940
		}
941
942
		$query = $wp_scripts->registered[ $handle ];
943
		if ( is_object( $query ) && ! empty( $query->ver ) ) {
944
			$ver = $query->ver;
945
		}
946
947
		return $ver;
948
	}
949
950
	public static function js_redirect( $url ) {
951
		return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
952
    }
953
954
	public static function get_user_id_param( $user_id ) {
955
		if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
956
            return $user_id;
957
        }
958
959
		$user_id = sanitize_text_field( $user_id );
960
		if ( $user_id == 'current' ) {
961
			$user_id = get_current_user_id();
962
		} else {
963
			if ( is_email( $user_id ) ) {
964
				$user = get_user_by( 'email', $user_id );
965
			} else {
966
				$user = get_user_by( 'login', $user_id );
967
			}
968
969
            if ( $user ) {
970
                $user_id = $user->ID;
971
            }
972
			unset( $user );
973
        }
974
975
        return $user_id;
976
    }
977
978
	public static function get_file_contents( $filename, $atts = array() ) {
979
		if ( ! is_file( $filename ) ) {
980
			return false;
981
		}
982
983
		extract( $atts );
0 ignored issues
show
introduced by
extract() usage is highly discouraged, due to the complexity and unintended issues it might cause.
Loading history...
984
		ob_start();
985
		include( $filename );
986
		$contents = ob_get_contents();
987
		ob_end_clean();
988
		return $contents;
989
	}
990
991
    /**
992
     * @param string $table_name
993
     * @param string $column
994
	 * @param int $id
995
	 * @param int $num_chars
996
     */
997
    public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
998
        $key = '';
999
1000
        if ( ! empty( $name ) ) {
1001
			$key = sanitize_key( $name );
1002
        }
1003
1004
		if ( empty( $key ) ) {
1005
			$max_slug_value = pow( 36, $num_chars );
1006
            $min_slug_value = 37; // we want to have at least 2 characters in the slug
1007
			$key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
1008
        }
1009
1010
		if ( is_numeric( $key ) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
1011
			$key = $key . 'a';
1012
        }
1013
1014
		$key_check = FrmDb::get_var(
1015
			$table_name,
1016
			array(
1017
				$column => $key,
1018
				'ID !'  => $id,
1019
			),
1020
			$column
1021
		);
1022
1023
		if ( $key_check || is_numeric( $key_check ) ) {
1024
            $suffix = 2;
1025
			do {
1026
				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
1027
				$key_check = FrmDb::get_var(
1028
					$table_name,
1029
					array(
1030
						$column => $alt_post_name,
1031
						'ID !'  => $id,
1032
					),
1033
					$column
1034
				);
1035
				$suffix++;
1036
			} while ( $key_check || is_numeric( $key_check ) );
1037
			$key = $alt_post_name;
1038
        }
1039
        return $key;
1040
    }
1041
1042
    /**
1043
     * Editing a Form or Entry
1044
     * @param string $table
1045
     * @return bool|array
1046
     */
1047
    public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
1048
        if ( ! $record ) {
1049
            return false;
1050
        }
1051
1052
		if ( empty( $post_values ) ) {
1053
			$post_values = stripslashes_deep( $_POST );
1054
		}
1055
1056
		$values = array(
1057
			'id' => $record->id,
1058
			'fields' => array(),
1059
		);
1060
1061
		foreach ( array( 'name', 'description' ) as $var ) {
1062
			$default_val = isset( $record->{$var} ) ? $record->{$var} : '';
1063
			$values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
1064
			unset( $var, $default_val );
1065
		}
1066
1067
		$values['description'] = self::use_wpautop( $values['description'] );
1068
1069
		self::fill_form_opts( $record, $table, $post_values, $values );
1070
1071
		self::prepare_field_arrays( $fields, $record, $values, array_merge( $args, compact( 'default', 'post_values' ) ) );
1072
1073
        if ( $table == 'entries' ) {
1074
            $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1075
        } else if ( $table == 'forms' ) {
1076
            $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1077
        }
1078
1079
        return $values;
1080
    }
1081
1082
	private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
1083
		if ( ! empty( $fields ) ) {
1084
			foreach ( (array) $fields as $field ) {
1085
				$field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
1086
				$args['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
1087
				self::fill_field_defaults( $field, $record, $values, $args );
1088
			}
1089
		}
1090
	}
1091
1092
	private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1093
        $post_values = $args['post_values'];
1094
1095
        if ( $args['default'] ) {
1096
            $meta_value = $field->default_value;
1097
        } else {
1098
			if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1099
				if ( ! isset( $field->field_options['custom_field'] ) ) {
1100
                    $field->field_options['custom_field'] = '';
1101
                }
1102
				$meta_value = FrmProEntryMetaHelper::get_post_value(
1103
					$record->post_id,
1104
					$field->field_options['post_field'],
1105
					$field->field_options['custom_field'],
1106
					array(
1107
						'truncate' => false,
1108
						'type' => $field->type,
1109
						'form_id' => $field->form_id,
1110
						'field' => $field,
1111
					)
1112
				);
1113
            } else {
1114
				$meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1115
            }
1116
        }
1117
1118
		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1119
        $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1120
1121
		$field_array = self::start_field_array( $field );
1122
		$field_array['value'] = $new_value;
1123
		$field_array['type']  = apply_filters( 'frm_field_type', $field_type, $field, $new_value );
1124
		$field_array['parent_form_id'] = $args['parent_form_id'];
1125
1126
        $args['field_type'] = $field_type;
1127
1128
		FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
1129
1130
		if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1131
            $field_array['unique_msg'] = '';
1132
        }
1133
1134
        $field_array = array_merge( $field->field_options, $field_array );
1135
1136
        $values['fields'][ $field->id ] = $field_array;
1137
    }
1138
1139
	/**
1140
	 * @since 3.0
1141
	 * @param object $field
1142
	 * @return array
1143
	 */
1144
	public static function start_field_array( $field ) {
1145
		return array(
1146
			'id'            => $field->id,
1147
			'default_value' => $field->default_value,
1148
			'name'          => $field->name,
1149
			'description'   => $field->description,
1150
			'options'       => $field->options,
1151
			'required'      => $field->required,
1152
			'field_key'     => $field->field_key,
1153
			'field_order'   => $field->field_order,
1154
			'form_id'       => $field->form_id,
1155
		);
1156
	}
1157
1158
    /**
1159
     * @param string $table
1160
     */
1161
	private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1162
        if ( $table == 'entries' ) {
1163
            $form = $record->form_id;
1164
			FrmForm::maybe_get_form( $form );
1165
        } else {
1166
            $form = $record;
1167
        }
1168
1169
        if ( ! $form ) {
1170
            return;
1171
        }
1172
1173
		$values['form_name'] = isset( $record->form_id ) ? $form->name : '';
1174
		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1175
1176
		if ( ! is_array( $form->options ) ) {
1177
			return;
1178
		}
1179
1180
        foreach ( $form->options as $opt => $value ) {
1181
            $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1182
        }
1183
1184
		self::fill_form_defaults( $post_values, $values );
1185
    }
1186
1187
    /**
1188
     * Set to POST value or default
1189
     */
1190
	private static function fill_form_defaults( $post_values, array &$values ) {
1191
        $form_defaults = FrmFormsHelper::get_default_opts();
1192
1193
        foreach ( $form_defaults as $opt => $default ) {
1194
            if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1195
				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1196
            }
1197
1198
			unset( $opt, $default );
1199
        }
1200
1201
		if ( ! isset( $values['custom_style'] ) ) {
1202
			$values['custom_style'] = self::custom_style_value( $post_values );
1203
		}
1204
1205
		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1206
			if ( ! isset( $values[ $h . '_html' ] ) ) {
1207
				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1208
            }
1209
			unset( $h );
1210
        }
1211
    }
1212
1213
	/**
1214
	 * @since 2.2.10
1215
	 * @param array $post_values
1216
	 * @return boolean|int
1217
	 */
1218
	public static function custom_style_value( $post_values ) {
1219
		if ( ! empty( $post_values ) && isset( $post_values['options']['custom_style'] ) ) {
1220
			$custom_style = absint( $post_values['options']['custom_style'] );
1221
		} else {
1222
			$frm_settings = FrmAppHelper::get_settings();
1223
			$custom_style = ( $frm_settings->load_style != 'none' );
1224
		}
1225
		return $custom_style;
1226
	}
1227
1228
	public static function insert_opt_html( $args ) {
1229
		$class = '';
1230
		$possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' );
1231
		if ( $possible_email_field ) {
1232
			$class .= 'show_frm_not_email_to';
1233
		}
1234
    ?>
1235
<li>
1236
	<a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['id'] ); ?>" >[<?php echo esc_attr( $args['id'] ); ?>]</a>
1237
	<a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['key'] ); ?>" >[<?php echo esc_attr( self::truncate( $args['key'], 10 ) ); ?>]</a>
1238
	<a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['id'] ); ?>" ><?php echo esc_attr( self::truncate( $args['name'], 60 ) ); ?></a>
1239
</li>
1240
    <?php
1241
    }
1242
1243
	public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1244
        if ( is_array( $str ) ) {
1245
            return '';
1246
		}
1247
1248
        $length = (int) $length;
1249
		$str = wp_strip_all_tags( $str );
1250
		$original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1251
1252
		if ( $length == 0 ) {
1253
            return '';
1254
        } else if ( $length <= 10 ) {
1255
			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1256
			return $sub . ( ( $length < $original_len ) ? $continue : '' );
1257
        }
1258
1259
        $sub = '';
1260
        $len = 0;
1261
1262
		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1263
1264
		foreach ( $words as $word ) {
1265
			$part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1266
			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1267
			if ( $total_len > $length && str_word_count( $sub ) ) {
1268
                break;
1269
            }
1270
1271
            $sub .= $part;
1272
			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1273
1274
			if ( str_word_count( $sub ) > $minword && $total_len >= $length ) {
1275
                break;
1276
            }
1277
1278
			unset( $total_len, $word );
1279
        }
1280
1281
		return $sub . ( ( $len < $original_len ) ? $continue : '' );
1282
    }
1283
1284
	public static function mb_function( $function_names, $args ) {
1285
		$mb_function_name = $function_names[0];
1286
		$function_name = $function_names[1];
1287
		if ( function_exists( $mb_function_name ) ) {
1288
			$function_name = $mb_function_name;
1289
		}
1290
		return call_user_func_array( $function_name, $args );
1291
	}
1292
1293
	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1294
		if ( empty( $date ) ) {
1295
            return $date;
1296
        }
1297
1298
		if ( empty( $date_format ) ) {
1299
			$date_format = get_option( 'date_format' );
1300
		}
1301
1302
		if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1303
            $frmpro_settings = new FrmProSettings();
1304
			$date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1305
        }
1306
1307
		$formatted = self::get_localized_date( $date_format, $date );
1308
1309
		$do_time = ( date( 'H:i:s', strtotime( $date ) ) != '00:00:00' );
1310
		if ( $do_time ) {
1311
			$formatted .= self::add_time_to_date( $time_format, $date );
1312
		}
1313
1314
        return $formatted;
1315
    }
1316
1317
	private static function add_time_to_date( $time_format, $date ) {
1318
		if ( empty( $time_format ) ) {
1319
			$time_format = get_option( 'time_format' );
1320
		}
1321
1322
		$trimmed_format = trim( $time_format );
1323
		$time = '';
1324
		if ( $time_format && ! empty( $trimmed_format ) ) {
1325
			$time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
1326
		}
1327
1328
		return $time;
1329
	}
1330
1331
	/**
1332
	 * @since 2.0.8
1333
	 */
1334
	public static function get_localized_date( $date_format, $date ) {
1335
		$date = get_date_from_gmt( $date );
1336
		return date_i18n( $date_format, strtotime( $date ) );
1337
	}
1338
1339
	/**
1340
	 * Gets the time ago in words
1341
	 *
1342
	 * @param int $from in seconds
1343
	 * @param int|string $to in seconds
1344
	 * @return string $time_ago
1345
	 */
1346
	public static function human_time_diff( $from, $to = '', $levels = 1 ) {
1347
		if ( empty( $to ) ) {
1348
			$now = new DateTime;
1349
		} else {
1350
			$now = new DateTime( '@' . $to );
1351
		}
1352
		$ago = new DateTime( '@' . $from );
1353
1354
		// Get the time difference
1355
		$diff_object = $now->diff( $ago );
1356
		$diff = get_object_vars( $diff_object );
1357
1358
		// Add week amount and update day amount
1359
		$diff['w'] = floor( $diff['d'] / 7 );
1360
		$diff['d'] -= $diff['w'] * 7;
1361
1362
		$time_strings = self::get_time_strings();
1363
1364
		foreach ( $time_strings as $k => $v ) {
1365
			if ( $diff[ $k ] ) {
1366
				$time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
1367
			} else {
1368
				unset( $time_strings[ $k ] );
1369
			}
1370
		}
1371
1372
		$levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
1373
		$time_strings = array_slice( $time_strings, 0, $levels_deep );
1374
		$time_ago_string = $time_strings ? implode( ' ', $time_strings ) : '0 ' . __( 'seconds', 'formidable' );
1375
1376
		return $time_ago_string;
1377
	}
1378
1379
	/**
1380
	 * Get the translatable time strings
1381
	 *
1382
	 * @since 2.0.20
1383
	 * @return array
1384
	 */
1385
	private static function get_time_strings() {
1386
		return array(
1387
			'y' => array( __( 'year', 'formidable' ), __( 'years', 'formidable' ) ),
1388
			'm' => array( __( 'month', 'formidable' ), __( 'months', 'formidable' ) ),
1389
			'w' => array( __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ),
1390
			'd' => array( __( 'day', 'formidable' ), __( 'days', 'formidable' ) ),
1391
			'h' => array( __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ),
1392
			'i' => array( __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ),
1393
			's' => array( __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) ),
1394
		);
1395
	}
1396
1397
    // Pagination Methods
1398
1399
    /**
1400
     * @param integer $current_p
1401
     */
1402
	public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1403
		return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1404
	}
1405
1406
    /**
1407
     * @param integer $current_p
1408
     */
1409
    public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1410
        if ( $current_p == 1 ) {
1411
            return 1;
1412
        } else {
1413
            return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1414
        }
1415
    }
1416
1417
	/**
1418
	 * @return array
1419
	 */
1420
	public static function json_to_array( $json_vars ) {
1421
        $vars = array();
1422
        foreach ( $json_vars as $jv ) {
1423
			$jv_name = explode( '[', $jv['name'] );
1424
			$last = count( $jv_name ) - 1;
1425
			foreach ( $jv_name as $p => $n ) {
1426
				$name = trim( $n, ']' );
1427
				if ( ! isset( $l1 ) ) {
1428
					$l1 = $name;
1429
				}
1430
1431
				if ( ! isset( $l2 ) ) {
1432
					$l2 = $name;
1433
				}
1434
1435
				if ( ! isset( $l3 ) ) {
1436
					$l3 = $name;
1437
				}
1438
1439
                $this_val = ( $p == $last ) ? $jv['value'] : array();
1440
1441
                switch ( $p ) {
1442
                    case 0:
1443
                        $l1 = $name;
1444
                        self::add_value_to_array( $name, $l1, $this_val, $vars );
1445
						break;
1446
1447
                    case 1:
1448
                        $l2 = $name;
1449
                        self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1450
						break;
1451
1452 View Code Duplication
                    case 2:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

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

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

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

Loading history...
1458
                        $l4 = $name;
1459
                        self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1460
                }
1461
1462
				unset( $this_val, $n );
1463
            }
1464
1465
			unset( $last, $jv );
1466
        }
1467
1468
        return $vars;
1469
    }
1470
1471
    /**
1472
     * @param string $name
1473
     * @param string $l1
1474
     */
1475
    public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1476
        if ( $name == '' ) {
1477
            $vars[] = $val;
1478
        } else if ( ! isset( $vars[ $l1 ] ) ) {
1479
            $vars[ $l1 ] = $val;
1480
        }
1481
    }
1482
1483
	public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1484
        $tooltips = array(
1485
            'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1486
            'email_to'      => __( 'Add one or more recipient addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].  [admin_email] is the address set in WP General Settings.', 'formidable' ),
1487
            'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1488
            'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1489
            'reply_to'      => __( 'If you would like a different reply to address than the "from" address, add a single address here.  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1490
            'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1491
            'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1492
        );
1493
1494
        if ( ! isset( $tooltips[ $name ] ) ) {
1495
            return;
1496
        }
1497
1498
        if ( 'open' == $class ) {
1499
            echo ' frm_help"';
1500
        } else {
1501
            echo ' class="frm_help"';
1502
        }
1503
1504
		echo ' title="' . esc_attr( $tooltips[ $name ] );
1505
1506
        if ( 'open' != $class ) {
1507
            echo '"';
1508
        }
1509
    }
1510
1511
	/**
1512
	 * Add the current_page class to that page in the form nav
1513
	 */
1514
	public static function select_current_page( $page, $current_page, $action = array() ) {
1515
		if ( $current_page != $page ) {
1516
			return;
1517
		}
1518
1519
		$frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
1520
		if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
1521
			echo ' class="current_page"';
1522
		}
1523
	}
1524
1525
    /**
1526
     * Prepare and json_encode post content
1527
     *
1528
     * @since 2.0
1529
     *
1530
     * @param array $post_content
1531
     * @return string $post_content ( json encoded array )
1532
     */
1533
    public static function prepare_and_encode( $post_content ) {
1534
        //Loop through array to strip slashes and add only the needed ones
1535
		foreach ( $post_content as $key => $val ) {
1536
			// Replace problematic characters (like &quot;)
1537
			$val = str_replace( '&quot;', '"', $val );
1538
1539
			self::prepare_action_slashes( $val, $key, $post_content );
1540
            unset( $key, $val );
1541
        }
1542
1543
        // json_encode the array
1544
        $post_content = json_encode( $post_content );
1545
1546
	    // add extra slashes for \r\n since WP strips them
1547
		$post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1548
1549
        // allow for &quot
1550
	    $post_content = str_replace( '&quot;', '\\"', $post_content );
1551
1552
        return $post_content;
1553
    }
1554
1555
	private static function prepare_action_slashes( $val, $key, &$post_content ) {
1556
		if ( ! isset( $post_content[ $key ] ) ) {
1557
			return;
1558
		}
1559
1560
		if ( is_array( $val ) ) {
1561
			foreach ( $val as $k1 => $v1 ) {
1562
				self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
1563
				unset( $k1, $v1 );
1564
			}
1565
		} else {
1566
			// Strip all slashes so everything is the same, no matter where the value is coming from
1567
			$val = stripslashes( $val );
1568
1569
			// Add backslashes before double quotes and forward slashes only
1570
			$post_content[ $key ] = addcslashes( $val, '"\\/' );
1571
		}
1572
	}
1573
1574
	public static function maybe_json_decode( $string ) {
1575
		if ( is_array( $string ) ) {
1576
            return $string;
1577
        }
1578
1579
		$new_string = json_decode( $string, true );
1580
		if ( function_exists( 'json_last_error' ) ) {
1581
			// php 5.3+
1582
            if ( json_last_error() == JSON_ERROR_NONE ) {
1583
                $string = $new_string;
1584
            }
1585
		} elseif ( isset( $new_string ) ) {
1586
			// php < 5.3 fallback
1587
            $string = $new_string;
1588
        }
1589
        return $string;
1590
    }
1591
1592
    /**
1593
     * @since 1.07.10
1594
     *
1595
     * @param string $post_type The name of the post type that may need to be highlighted
1596
     * echo The javascript to open and highlight the Formidable menu
1597
     */
1598
	public static function maybe_highlight_menu( $post_type ) {
1599
        global $post;
1600
1601
		if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
1602
            return;
1603
        }
1604
1605
		if ( is_object( $post ) && $post->post_type != $post_type ) {
1606
            return;
1607
        }
1608
1609
        self::load_admin_wide_js();
1610
        echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1611
    }
1612
1613
    /**
1614
     * Load the JS file on non-Formidable pages in the admin area
1615
     * @since 2.0
1616
     */
1617
	public static function load_admin_wide_js( $load = true ) {
1618
        $version = FrmAppHelper::plugin_version();
1619
		wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1620
1621
		$global_strings = array(
1622
			'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1623
            'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1624
			'url'          => FrmAppHelper::plugin_url(),
1625
			'loading'      => __( 'Loading&hellip;' ),
1626
			'nonce'        => wp_create_nonce( 'frm_ajax' ),
1627
		);
1628
		wp_localize_script( 'formidable_admin_global', 'frmGlobal', $global_strings );
1629
1630
		if ( $load ) {
1631
			wp_enqueue_script( 'formidable_admin_global' );
1632
		}
1633
    }
1634
1635
	/**
1636
	 * @since 2.0.9
1637
	 */
1638
	public static function load_font_style() {
1639
		wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
1640
	}
1641
1642
    /**
1643
     * @param string $location
1644
     */
1645
	public static function localize_script( $location ) {
1646
		$ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
1647
		$ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
1648
1649
		$script_strings = array(
1650
			'ajax_url'  => $ajax_url,
1651
			'images_url' => self::plugin_url() . '/images',
1652
			'loading'   => __( 'Loading&hellip;' ),
1653
			'remove'    => __( 'Remove', 'formidable' ),
1654
			'offset'    => apply_filters( 'frm_scroll_offset', 4 ),
1655
			'nonce'     => wp_create_nonce( 'frm_ajax' ),
1656
			'id'        => __( 'ID', 'formidable' ),
1657
			'no_results' => __( 'No results match', 'formidable' ),
1658
			'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
1659
			'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
1660
			'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
1661
		);
1662
		wp_localize_script( 'formidable', 'frm_js', $script_strings );
1663
1664
		if ( $location == 'admin' ) {
1665
			$frm_settings = self::get_settings();
1666
			$admin_script_strings = array(
1667
				'confirm_uninstall' => __( 'Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable' ),
1668
				'desc'              => __( '(Click to add description)', 'formidable' ),
1669
				'blank'             => __( '(Blank)', 'formidable' ),
1670
				'no_label'          => __( '(no label)', 'formidable' ),
1671
				'saving'            => esc_attr( __( 'Saving', 'formidable' ) ),
1672
				'saved'             => esc_attr( __( 'Saved', 'formidable' ) ),
1673
				'ok'                => __( 'OK' ),
1674
				'cancel'            => __( 'Cancel', 'formidable' ),
1675
				'default'           => __( 'Default', 'formidable' ),
1676
				'clear_default'     => __( 'Clear default value when typing', 'formidable' ),
1677
				'no_clear_default'  => __( 'Do not clear default value when typing', 'formidable' ),
1678
				'valid_default'     => __( 'Default value will pass form validation', 'formidable' ),
1679
				'no_valid_default'  => __( 'Default value will NOT pass form validation', 'formidable' ),
1680
				'confirm'           => __( 'Are you sure?', 'formidable' ),
1681
				'conf_delete'       => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
1682
				'conf_delete_sec'   => __( 'WARNING: This will delete all fields inside of the section as well.', 'formidable' ),
1683
				'conf_no_repeat'    => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
1684
				'default_unique'    => $frm_settings->unique_msg,
1685
				'default_conf'      => __( 'The entered values do not match', 'formidable' ),
1686
				'enter_email'       => __( 'Enter Email', 'formidable' ),
1687
				'confirm_email'     => __( 'Confirm Email', 'formidable' ),
1688
				'css_invalid_size'  => __( 'In certain browsers (e.g. Firefox) text will not display correctly if the field height is too small relative to the field padding and text size. Please increase your field height or decrease your field padding.', 'formidable' ),
1689
				'enter_password'    => __( 'Enter Password', 'formidable' ),
1690
				'confirm_password'  => __( 'Confirm Password', 'formidable' ),
1691
				'import_complete'   => __( 'Import Complete', 'formidable' ),
1692
				'updating'          => __( 'Please wait while your site updates.', 'formidable' ),
1693
				'no_save_warning'   => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
1694
				'private'           => __( 'Private' ),
1695
				'jquery_ui_url'     => self::jquery_ui_base_url(),
1696
				'pro_url'           => is_callable( 'FrmProAppHelper::plugin_url' ) ? FrmProAppHelper::plugin_url() : '',
1697
				'no_licenses'       => __( 'No new licenses were found', 'formidable' ),
1698
				'unmatched_parens'  => __( 'This calculation has at least one unmatched ( ) { } [ ].', 'formidable' ),
1699
				'view_shortcodes'   => __( 'This calculation may have shortcodes that work in Views but not forms.', 'formidable' ),
1700
				'text_shortcodes'   => __( 'This calculation may have shortcodes that work in text calculations but not numeric calculations.', 'formidable' ),
1701
				'repeat_limit_min'  => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
1702
			);
1703
			wp_localize_script( 'formidable_admin', 'frm_admin_js', $admin_script_strings );
1704
		}
1705
	}
1706
1707
    /**
1708
	 * echo the message on the plugins listing page
1709
     * @since 1.07.10
1710
     *
1711
     * @param float $min_version The version the add-on requires
1712
     */
1713
	public static function min_version_notice( $min_version ) {
1714
        $frm_version = self::plugin_version();
1715
1716
        // check if Formidable meets minimum requirements
1717
		if ( version_compare( $frm_version, $min_version, '>=' ) ) {
1718
            return;
1719
        }
1720
1721
		$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1722
		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">' .
1723
        esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1724
        '</div></td></tr>';
1725
    }
1726
1727
    public static function locales( $type = 'date' ) {
1728
		$locales = array(
1729
			'en' => __( 'English', 'formidable' ),
1730
			''   => __( 'English/Western', 'formidable' ),
1731
			'af' => __( 'Afrikaans', 'formidable' ),
1732
			'sq' => __( 'Albanian', 'formidable' ),
1733
			'ar' => __( 'Arabic', 'formidable' ),
1734
			'hy' => __( 'Armenian', 'formidable' ),
1735
			'az' => __( 'Azerbaijani', 'formidable' ),
1736
			'eu' => __( 'Basque', 'formidable' ),
1737
			'bs' => __( 'Bosnian', 'formidable' ),
1738
			'bg' => __( 'Bulgarian', 'formidable' ),
1739
			'ca' => __( 'Catalan', 'formidable' ),
1740
			'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1741
			'zh-CN' => __( 'Chinese Simplified', 'formidable' ),
1742
			'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1743
			'hr' => __( 'Croatian', 'formidable' ),
1744
			'cs' => __( 'Czech', 'formidable' ),
1745
			'da' => __( 'Danish', 'formidable' ),
1746
			'nl' => __( 'Dutch', 'formidable' ),
1747
			'en-GB' => __( 'English/UK', 'formidable' ),
1748
			'eo' => __( 'Esperanto', 'formidable' ),
1749
			'et' => __( 'Estonian', 'formidable' ),
1750
			'fo' => __( 'Faroese', 'formidable' ),
1751
			'fa' => __( 'Farsi/Persian', 'formidable' ),
1752
			'fil' => __( 'Filipino', 'formidable' ),
1753
			'fi' => __( 'Finnish', 'formidable' ),
1754
			'fr' => __( 'French', 'formidable' ),
1755
			'fr-CA' => __( 'French/Canadian', 'formidable' ),
1756
			'fr-CH' => __( 'French/Swiss', 'formidable' ),
1757
			'de' => __( 'German', 'formidable' ),
1758
			'de-AT' => __( 'German/Austria', 'formidable' ),
1759
			'de-CH' => __( 'German/Switzerland', 'formidable' ),
1760
			'el' => __( 'Greek', 'formidable' ),
1761
			'he' => __( 'Hebrew', 'formidable' ),
1762
			'iw' => __( 'Hebrew', 'formidable' ),
1763
			'hi' => __( 'Hindi', 'formidable' ),
1764
			'hu' => __( 'Hungarian', 'formidable' ),
1765
			'is' => __( 'Icelandic', 'formidable' ),
1766
			'id' => __( 'Indonesian', 'formidable' ),
1767
			'it' => __( 'Italian', 'formidable' ),
1768
			'ja' => __( 'Japanese', 'formidable' ),
1769
			'ko' => __( 'Korean', 'formidable' ),
1770
			'lv' => __( 'Latvian', 'formidable' ),
1771
			'lt' => __( 'Lithuanian', 'formidable' ),
1772
			'ms' => __( 'Malaysian', 'formidable' ),
1773
			'no' => __( 'Norwegian', 'formidable' ),
1774
			'pl' => __( 'Polish', 'formidable' ),
1775
			'pt' => __( 'Portuguese', 'formidable' ),
1776
			'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1777
			'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ),
1778
			'ro' => __( 'Romanian', 'formidable' ),
1779
			'ru' => __( 'Russian', 'formidable' ),
1780
			'sr' => __( 'Serbian', 'formidable' ),
1781
			'sr-SR' => __( 'Serbian', 'formidable' ),
1782
			'sk' => __( 'Slovak', 'formidable' ),
1783
			'sl' => __( 'Slovenian', 'formidable' ),
1784
			'es' => __( 'Spanish', 'formidable' ),
1785
			'es-419' => __( 'Spanish/Latin America', 'formidable' ),
1786
			'sv' => __( 'Swedish', 'formidable' ),
1787
			'ta' => __( 'Tamil', 'formidable' ),
1788
			'th' => __( 'Thai', 'formidable' ),
1789
			'tu' => __( 'Turkish', 'formidable' ),
1790
			'tr' => __( 'Turkish', 'formidable' ),
1791
			'uk' => __( 'Ukranian', 'formidable' ),
1792
			'vi' => __( 'Vietnamese', 'formidable' ),
1793
		);
1794
1795
		if ( $type === 'captcha' ) {
1796
			// remove the languages unavailable for the captcha
1797
			$unset = array( '', 'af', 'sq', 'hy', 'az', 'eu', 'bs', 'zh-HK', 'eo', 'et', 'fo', 'fr-CH', 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu' );
1798
		} else {
1799
			// remove the languages unavailable for the datepicker
1800
			$unset = array( 'en', 'fil', 'fr-CA', 'de-AT', 'de-AT', 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', 'es-419', 'tr' );
1801
		}
1802
1803
		$locales = array_diff_key( $locales, array_flip( $unset ) );
1804
		$locales = apply_filters( 'frm_locales', $locales );
1805
1806
        return $locales;
1807
    }
1808
1809
	/**
1810
	 * Prepare and save settings in styles and actions
1811
	 *
1812
	 * @param array $settings
1813
	 * @param string $group
1814
	 *
1815
	 * @since 2.0.6
1816
	 * @deprecated 2.05.06
1817
	 * @codeCoverageIgnore
1818
	 */
1819
	public static function save_settings( $settings, $group ) {
1820
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1821
		return FrmDb::save_settings( $settings, $group );
1822
	}
1823
1824
	/**
1825
	 * Since actions are JSON encoded, we don't want any filters messing with it.
1826
	 * Remove the filters and then add them back in case any posts or views are
1827
	 * also being imported.
1828
	 *
1829
	 * Used when saving form actions and styles
1830
	 *
1831
	 * @since 2.0.4
1832
	 * @deprecated 2.05.06
1833
	 * @codeCoverageIgnore
1834
	 */
1835
	public static function save_json_post( $settings ) {
1836
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1837
		return FrmDb::save_json_post( $settings );
1838
	}
1839
1840
	/**
1841
	 * Check cache before fetching values and saving to cache
1842
	 *
1843
	 * @since 2.0
1844
	 * @deprecated 2.05.06
1845
	 * @codeCoverageIgnore
1846
	 *
1847
	 * @param string $cache_key The unique name for this cache
1848
	 * @param string $group The name of the cache group
1849
	 * @param string $query If blank, don't run a db call
1850
	 * @param string $type The wpdb function to use with this query
1851
	 * @return mixed $results The cache or query results
1852
	 */
1853
	public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
1854
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1855
		return FrmDb::check_cache( $cache_key, $group, $query, $type, $time );
1856
	}
1857
1858
	/**
1859
	 * @deprecated 2.05.06
1860
	 * @codeCoverageIgnore
1861
	 */
1862
	public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
1863
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1864
		FrmDb::set_cache( $cache_key, $results, $group, $time );
1865
	}
1866
1867
	/**
1868
	 * Keep track of the keys cached in each group so they can be deleted
1869
	 * in Redis and Memcache
1870
	 * @deprecated 2.05.06
1871
	 * @codeCoverageIgnore
1872
	 */
1873
	public static function add_key_to_group_cache( $key, $group ) {
1874
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1875
		FrmDb::add_key_to_group_cache( $key, $group );
1876
	}
1877
1878
	/**
1879
	 * @deprecated 2.05.06
1880
	 * @codeCoverageIgnore
1881
	 */
1882
	public static function get_group_cached_keys( $group ) {
1883
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1884
		return FrmDb::get_group_cached_keys( $group );
1885
	}
1886
1887
	/**
1888
	 * @since 2.0
1889
	 * @deprecated 2.05.06
1890
	 * @codeCoverageIgnore
1891
	 * @return mixed The cached value or false
1892
	 */
1893
	public static function check_cache_and_transient( $cache_key ) {
1894
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1895
		return FrmDb::check_cache( $cache_key );
1896
	}
1897
1898
	/**
1899
	 * @since 2.0
1900
	 * @deprecated 2.05.06
1901
	 * @codeCoverageIgnore
1902
	 * @param string $cache_key
1903
	 */
1904
	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
1905
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1906
		FrmDb::delete_cache_and_transient( $cache_key, $group );
1907
	}
1908
1909
	/**
1910
	 * @since 2.0
1911
	 * @deprecated 2.05.06
1912
	 * @codeCoverageIgnore
1913
	 *
1914
	 * @param string $group The name of the cache group
1915
	 */
1916
	public static function cache_delete_group( $group ) {
1917
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1918
		FrmDb::cache_delete_group( $group );
1919
	}
1920
1921
	/**
1922
	 * Added for < WP 4.0 compatability
1923
	 *
1924
	 * @since 1.07.10
1925
	 * @deprecated 2.05.06
1926
	 * @codeCoverageIgnore
1927
	 *
1928
	 * @param string $term The value to escape
1929
	 * @return string The escaped value
1930
	 */
1931
	public static function esc_like( $term ) {
1932
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1933
		return FrmDb::esc_like( $term );
1934
	}
1935
1936
	/**
1937
	 * @param string $order_query
1938
	 * @deprecated 2.05.06
1939
	 * @codeCoverageIgnore
1940
	 */
1941
	public static function esc_order( $order_query ) {
1942
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1943
		return FrmDb::esc_order( $order_query );
1944
	}
1945
1946
	/**
1947
	 * Make sure this is ordering by either ASC or DESC
1948
	 * @deprecated 2.05.06
1949
	 * @codeCoverageIgnore
1950
	 */
1951
	public static function esc_order_by( &$order_by ) {
1952
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1953
		FrmDb::esc_order_by( $order_by );
1954
	}
1955
1956
	/**
1957
	 * @param string $limit
1958
	 * @deprecated 2.05.06
1959
	 * @codeCoverageIgnore
1960
	 */
1961
	public static function esc_limit( $limit ) {
1962
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1963
		return FrmDb::esc_limit( $limit );
1964
	}
1965
1966
	/**
1967
	 * Get an array of values ready to go through $wpdb->prepare
1968
	 * @since 2.0
1969
	 * @deprecated 2.05.06
1970
	 * @codeCoverageIgnore
1971
	 */
1972
	public static function prepare_array_values( $array, $type = '%s' ) {
1973
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1974
		return FrmDb::prepare_array_values( $array, $type );
1975
	}
1976
1977
	/**
1978
	 * @deprecated 2.05.06
1979
	 * @codeCoverageIgnore
1980
	 */
1981
	public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
1982
		_deprecated_function( __METHOD__, '2.05.06', 'FrmDb::' . __FUNCTION__ );
1983
		return FrmDb::prepend_and_or_where( $starts_with, $where );
1984
	}
1985
}
1986