Completed
Push — master ( 1466b8...74a3d9 )
by Stephanie
14s
created

FrmAppHelper::select_current_page()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

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

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

Loading history...
1887
	}
1888
1889
	/**
1890
	 * @param array $settings
1891
	 * @param string $group
1892
	 *
1893
	 * @since 2.0.6
1894
	 * @deprecated 2.05.06
1895
	 * @codeCoverageIgnore
1896
	 */
1897
	public static function save_settings( $settings, $group ) {
1898
		return FrmDeprecated::save_settings( $settings, $group );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::save_settings() has been deprecated with message: 2.05.06

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

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

Loading history...
1899
	}
1900
1901
	/**
1902
	 * @since 2.0.4
1903
	 * @deprecated 2.05.06
1904
	 * @codeCoverageIgnore
1905
	 */
1906
	public static function save_json_post( $settings ) {
1907
		return FrmDeprecated::save_json_post( $settings );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::save_json_post() has been deprecated with message: 2.05.06

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

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

Loading history...
1908
	}
1909
1910
	/**
1911
	 * @since 2.0
1912
	 * @deprecated 2.05.06
1913
	 * @codeCoverageIgnore
1914
	 *
1915
	 * @param string $cache_key The unique name for this cache
1916
	 * @param string $group The name of the cache group
1917
	 * @param string $query If blank, don't run a db call
1918
	 * @param string $type The wpdb function to use with this query
1919
	 * @return mixed $results The cache or query results
1920
	 */
1921
	public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
1922
		return FrmDeprecated::check_cache( $cache_key, $group, $query, $type, $time );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::check_cache() has been deprecated with message: 2.05.06

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

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

Loading history...
1923
	}
1924
1925
	/**
1926
	 * @deprecated 2.05.06
1927
	 * @codeCoverageIgnore
1928
	 */
1929
	public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
1930
		return FrmDeprecated::set_cache( $cache_key, $results, $group, $time );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::set_cache() has been deprecated with message: 2.05.06

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

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

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

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

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

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

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

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

Loading history...
1947
	}
1948
1949
	/**
1950
	 * @since 2.0
1951
	 * @deprecated 2.05.06
1952
	 * @codeCoverageIgnore
1953
	 * @return mixed The cached value or false
1954
	 */
1955
	public static function check_cache_and_transient( $cache_key ) {
1956
		return FrmDeprecated::check_cache( $cache_key );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::check_cache() has been deprecated with message: 2.05.06

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

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

Loading history...
1957
	}
1958
1959
	/**
1960
	 * @since 2.0
1961
	 * @deprecated 2.05.06
1962
	 * @codeCoverageIgnore
1963
	 * @param string $cache_key
1964
	 */
1965
	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
1966
		FrmDeprecated::delete_cache_and_transient( $cache_key, $group );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::delete_cache_and_transient() has been deprecated with message: 2.05.06

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

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

Loading history...
1967
	}
1968
1969
	/**
1970
	 * @since 2.0
1971
	 * @deprecated 2.05.06
1972
	 * @codeCoverageIgnore
1973
	 *
1974
	 * @param string $group The name of the cache group
1975
	 */
1976
	public static function cache_delete_group( $group ) {
1977
		FrmDeprecated::cache_delete_group( $group );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::cache_delete_group() has been deprecated with message: 2.05.06

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

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

Loading history...
1978
	}
1979
1980
	/**
1981
	 * @since 1.07.10
1982
	 * @deprecated 2.05.06
1983
	 * @codeCoverageIgnore
1984
	 *
1985
	 * @param string $term The value to escape
1986
	 * @return string The escaped value
1987
	 */
1988
	public static function esc_like( $term ) {
1989
		return FrmDeprecated::esc_like( $term );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::esc_like() has been deprecated with message: 2.05.06

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

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

Loading history...
1990
	}
1991
1992
	/**
1993
	 * @param string $order_query
1994
	 * @deprecated 2.05.06
1995
	 * @codeCoverageIgnore
1996
	 */
1997
	public static function esc_order( $order_query ) {
1998
		return FrmDeprecated::esc_order( $order_query );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::esc_order() has been deprecated with message: 2.05.06

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

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

Loading history...
1999
	}
2000
2001
	/**
2002
	 * @deprecated 2.05.06
2003
	 * @codeCoverageIgnore
2004
	 */
2005
	public static function esc_order_by( &$order_by ) {
2006
		FrmDeprecated::esc_order_by( $order_by );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::esc_order_by() has been deprecated with message: 2.05.06

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

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

Loading history...
2007
	}
2008
2009
	/**
2010
	 * @param string $limit
2011
	 * @deprecated 2.05.06
2012
	 * @codeCoverageIgnore
2013
	 */
2014
	public static function esc_limit( $limit ) {
2015
		return FrmDeprecated::esc_limit( $limit );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::esc_limit() has been deprecated with message: 2.05.06

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

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

Loading history...
2016
	}
2017
2018
	/**
2019
	 * @since 2.0
2020
	 * @deprecated 2.05.06
2021
	 * @codeCoverageIgnore
2022
	 */
2023
	public static function prepare_array_values( $array, $type = '%s' ) {
2024
		return FrmDeprecated::prepare_array_values( $array, $type );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::prepare_array_values() has been deprecated with message: 2.05.06

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

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

Loading history...
2025
	}
2026
2027
	/**
2028
	 * @deprecated 2.05.06
2029
	 * @codeCoverageIgnore
2030
	 */
2031
	public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
2032
		return FrmDeprecated::prepend_and_or_where( $starts_with, $where );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::prepend_and_or_where() has been deprecated with message: 2.05.06

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

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

Loading history...
2033
	}
2034
}
2035