PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.11.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.11.02
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmAppHelper.php

FrmAppHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 4.11.02, at classes/helpers/FrmAppHelper.php

2,932 lines 80.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 = 97; //version of the database we are moving to
8 public static $pro_db_version = 37; //deprecated
9 public static $font_version = 7;
10
11 /**
12 * @since 2.0
13 */
14 public static $plug_version = '4.11.02';
15
16 /**
17 * @since 1.07.02
18 *
19 * @param none
20 *
21 * @return string The version of this plugin
22 */
23 public static function plugin_version() {
24 return self::$plug_version;
25 }
26
27 public static function plugin_folder() {
28 return basename( self::plugin_path() );
29 }
30
31 public static function plugin_path() {
32 return dirname( dirname( dirname( __FILE__ ) ) );
33 }
34
35 public static function plugin_url() {
36 // Prevously FRM_URL constant.
37 return plugins_url( '', self::plugin_path() . '/formidable.php' );
38 }
39
40 public static function relative_plugin_url() {
41 return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
42 }
43
44 /**
45 * @return string Site URL
46 */
47 public static function site_url() {
48 return site_url();
49 }
50
51 /**
52 * Get the name of this site
53 * Used for [sitename] shortcode
54 *
55 * @since 2.0
56 * @return string
57 */
58 public static function site_name() {
59 return get_option( 'blogname' );
60 }
61
62 public static function make_affiliate_url( $url ) {
63 $affiliate_id = self::get_affiliate();
64 if ( ! empty( $affiliate_id ) ) {
65 $url = str_replace( array( 'http://', 'https://' ), '', $url );
66 $url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
67 }
68
69 return $url;
70 }
71
72 public static function get_affiliate() {
73 return absint( apply_filters( 'frm_affiliate_id', 0 ) );
74 }
75
76 /**
77 * @since 3.04.02
78 * @param array|string $args
79 * @param string $page
80 */
81 public static function admin_upgrade_link( $args, $page = '' ) {
82 if ( empty( $page ) ) {
83 $page = 'https://formidableforms.com/lite-upgrade/';
84 } else {
85 $page = str_replace( 'https://formidableforms.com/', '', $page );
86 $page = 'https://formidableforms.com/' . $page;
87 }
88
89 $anchor = '';
90 if ( is_array( $args ) ) {
91 $medium = $args['medium'];
92 if ( isset( $args['content'] ) ) {
93 $content = $args['content'];
94 }
95 if ( isset( $args['anchor'] ) ) {
96 $anchor = '#' . $args['anchor'];
97 }
98 } else {
99 $medium = $args;
100 }
101
102 $query_args = array(
103 'utm_source' => 'WordPress',
104 'utm_medium' => $medium,
105 'utm_campaign' => 'liteplugin',
106 );
107
108 if ( isset( $content ) ) {
109 $query_args['utm_content'] = $content;
110 }
111
112 if ( is_array( $args ) && isset( $args['param'] ) ) {
113 $query_args['f'] = $args['param'];
114 }
115
116 if ( is_array( $args ) && ! empty( $args['plan'] ) ) {
117 $query_args['plan'] = $args['plan'];
118 }
119
120 $link = add_query_arg( $query_args, $page ) . $anchor;
121 return self::make_affiliate_url( $link );
122 }
123
124 /**
125 * Get the Formidable settings
126 *
127 * @since 2.0
128 *
129 * @param array $args - May include the form id when values need translation.
130 * @return FrmSettings $frm_setings
131 */
132 public static function get_settings( $args = array() ) {
133 global $frm_settings;
134 if ( empty( $frm_settings ) ) {
135 $frm_settings = new FrmSettings( $args );
136 } elseif ( isset( $args['current_form'] ) ) {
137 // If the global has already been set, allow strings to be filtered.
138 $frm_settings->maybe_filter_for_form( $args );
139 }
140
141 return $frm_settings;
142 }
143
144 public static function get_menu_name() {
145 $frm_settings = self::get_settings();
146
147 return $frm_settings->menu;
148 }
149
150 /**
151 * @since 3.05
152 */
153 public static function svg_logo( $atts = array() ) {
154 $defaults = array(
155 'height' => 18,
156 'width' => 18,
157 'fill' => '#4d4d4d',
158 'orange' => '#f05a24',
159 );
160 $atts = array_merge( $defaults, $atts );
161
162 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'] ) . '">
163 <path fill="' . esc_attr( $atts['orange'] ) . '" d="M289.6 384h140v76h-140z"/>
164 <path fill="' . esc_attr( $atts['fill'] ) . '" d="M400.2 147h-200c-17 0-30.6 12.2-30.6 29.3V218h260v-71zM397.9 264H169.6v196h75V340H398a32.2 32.2 0 0 0 30.1-21.4 24.3 24.3 0 0 0 1.7-8.7V264zM299.8 601.4A300.3 300.3 0 0 1 0 300.7a299.8 299.8 0 1 1 511.9 212.6 297.4 297.4 0 0 1-212 88zm0-563A262 262 0 0 0 38.3 300.7a261.6 261.6 0 1 0 446.5-185.5 259.5 259.5 0 0 0-185-76.8z"/>
165 </svg>';
166 }
167
168 /**
169 * @since 4.0
170 */
171 public static function show_logo( $atts = array() ) {
172 echo self::kses( self::svg_logo( $atts ), 'all' ); // WPCS: XSS ok.
173 }
174
175 /**
176 * @since 4.03.02
177 */
178 public static function show_header_logo() {
179 $icon = self::svg_logo(
180 array(
181 'height' => 35,
182 'width' => 35,
183 )
184 );
185
186 $new_icon = apply_filters( 'frm_icon', $icon, true );
187 if ( $new_icon !== $icon ) {
188 if ( strpos( $new_icon, '<svg' ) === 0 ) {
189 $icon = str_replace( 'viewBox="0 0 20', 'width="30" height="35" style="color:#929699" viewBox="0 0 20', $new_icon );
190 } else {
191 // Show nothing if it isn't an SVG.
192 $icon = '<div style="height:39px"></div>';
193 }
194 }
195 echo self::kses( $icon, 'all' ); // WPCS: XSS ok.
196 }
197
198 /**
199 * @since 2.02.04
200 */
201 public static function ips_saved() {
202 $frm_settings = self::get_settings();
203
204 return ! $frm_settings->no_ips;
205 }
206
207 public static function pro_is_installed() {
208 return apply_filters( 'frm_pro_installed', false );
209 }
210
211 /**
212 * @since 4.06.02
213 */
214 public static function pro_is_connected() {
215 global $frm_vars;
216 return self::pro_is_installed() && $frm_vars['pro_is_authorized'];
217 }
218
219 /**
220 * @since 4.06
221 */
222 public static function is_form_builder_page() {
223 $action = self::simple_get( 'frm_action', 'sanitize_title' );
224 return self::is_admin_page( 'formidable' ) && ( $action === 'edit' || $action === 'settings' || $action === 'duplicate' );
225 }
226
227 public static function is_formidable_admin() {
228 $page = self::simple_get( 'page', 'sanitize_title' );
229 $is_formidable = strpos( $page, 'formidable' ) !== false;
230 if ( empty( $page ) ) {
231 $is_formidable = self::is_view_builder_page();
232 }
233
234 return $is_formidable;
235 }
236
237 /**
238 * Check for certain page in Formidable settings
239 *
240 * @since 2.0
241 *
242 * @param string $page The name of the page to check
243 *
244 * @return boolean
245 */
246 public static function is_admin_page( $page = 'formidable' ) {
247 global $pagenow;
248 $get_page = self::simple_get( 'page', 'sanitize_title' );
249 if ( $pagenow ) {
250 // allow this to be true during ajax load i.e. ajax form builder loading
251 $is_page = ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page;
252 if ( $is_page ) {
253 return true;
254 }
255 }
256
257 return is_admin() && $get_page == $page;
258 }
259
260 /**
261 * If the current page is for editing or creating a view.
262 * Returns false for the views listing page.
263 *
264 * @since 4.0
265 */
266 public static function is_view_builder_page() {
267 global $pagenow;
268
269 if ( $pagenow !== 'post.php' && $pagenow !== 'post-new.php' && $pagenow !== 'edit.php' ) {
270 return false;
271 }
272
273 $post_type = self::simple_get( 'post_type', 'sanitize_title' );
274
275 if ( empty( $post_type ) ) {
276 $post_id = self::simple_get( 'post', 'absint' );
277 $post = get_post( $post_id );
278 $post_type = $post ? $post->post_type : '';
279 }
280
281 return $post_type === 'frm_display';
282 }
283
284 /**
285 * Check for the form preview page
286 *
287 * @since 2.0
288 *
289 * @param None
290 *
291 * @return boolean
292 */
293 public static function is_preview_page() {
294 global $pagenow;
295 $action = self::simple_get( 'action', 'sanitize_title' );
296
297 return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
298 }
299
300 /**
301 * Check for ajax except the form preview page
302 *
303 * @since 2.0
304 *
305 * @param None
306 *
307 * @return boolean
308 */
309 public static function doing_ajax() {
310 return wp_doing_ajax() && ! self::is_preview_page();
311 }
312
313 public static function js_suffix() {
314 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
315 }
316
317 /**
318 * @since 2.0.8
319 */
320 public static function prevent_caching() {
321 global $frm_vars;
322
323 return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
324 }
325
326 /**
327 * Check if on an admin page
328 *
329 * @since 2.0
330 *
331 * @param None
332 *
333 * @return boolean
334 */
335 public static function is_admin() {
336 return is_admin() && ! wp_doing_ajax();
337 }
338
339 /**
340 * Check if value contains blank value or empty array
341 *
342 * @since 2.0
343 *
344 * @param mixed $value - value to check
345 * @param string
346 *
347 * @return boolean
348 */
349 public static function is_empty_value( $value, $empty = '' ) {
350 return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
351 }
352
353 public static function is_not_empty_value( $value, $empty = '' ) {
354 return ! self::is_empty_value( $value, $empty );
355 }
356
357 /**
358 * Get any value from the $_SERVER
359 *
360 * @since 2.0
361 *
362 * @param string $value
363 *
364 * @return string
365 */
366 public static function get_server_value( $value ) {
367 return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( wp_unslash( $_SERVER[ $value ] ) ) : '';
368 }
369
370 /**
371 * Check for the IP address in several places
372 * Used by [ip] shortcode
373 *
374 * @return string The IP address of the current user
375 */
376 public static function get_ip_address() {
377 $ip_options = array(
378 'HTTP_CLIENT_IP',
379 'HTTP_CF_CONNECTING_IP',
380 'HTTP_X_FORWARDED_FOR',
381 'HTTP_X_FORWARDED',
382 'HTTP_X_CLUSTER_CLIENT_IP',
383 'HTTP_X_REAL_IP',
384 'HTTP_FORWARDED_FOR',
385 'HTTP_FORWARDED',
386 'REMOTE_ADDR',
387 );
388 $ip = '';
389 foreach ( $ip_options as $key ) {
390 if ( ! isset( $_SERVER[ $key ] ) ) {
391 continue;
392 }
393
394 $key = self::get_server_value( $key );
395 foreach ( explode( ',', $key ) as $ip ) {
396 $ip = trim( $ip ); // just to be safe.
397
398 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
399 return sanitize_text_field( $ip );
400 }
401 }
402 }
403
404 return sanitize_text_field( $ip );
405 }
406
407 public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
408 if ( strpos( $param, '[' ) ) {
409 $params = explode( '[', $param );
410 $param = $params[0];
411 }
412
413 if ( $src == 'get' ) {
414 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
415 $value = isset( $_POST[ $param ] ) ? wp_unslash( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? wp_unslash( $_GET[ $param ] ) : $default );
416 if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
417 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
418 $value = htmlspecialchars_decode( wp_unslash( $_GET[ $param ] ) );
419 }
420 self::sanitize_value( $sanitize, $value );
421 } else {
422 $value = self::get_simple_request(
423 array(
424 'type' => $src,
425 'param' => $param,
426 'default' => $default,
427 'sanitize' => $sanitize,
428 )
429 );
430 }
431
432 if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
433 foreach ( $params as $k => $p ) {
434 if ( ! $k || ! is_array( $value ) ) {
435 continue;
436 }
437
438 $p = trim( $p, ']' );
439 $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
440 }
441 }
442
443 return $value;
444 }
445
446 public static function get_post_param( $param, $default = '', $sanitize = '', $serialized = false ) {
447 return self::get_simple_request(
448 array(
449 'type' => 'post',
450 'param' => $param,
451 'default' => $default,
452 'sanitize' => $sanitize,
453 'serialized' => $serialized,
454 )
455 );
456 }
457
458 /**
459 * @since 2.0
460 *
461 * @param string $param
462 * @param string $sanitize
463 * @param string $default
464 *
465 * @return string|array
466 */
467 public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
468 return self::get_simple_request(
469 array(
470 'type' => 'get',
471 'param' => $param,
472 'default' => $default,
473 'sanitize' => $sanitize,
474 )
475 );
476 }
477
478 /**
479 * Get a GET/POST/REQUEST value and sanitize it
480 *
481 * @since 2.0.6
482 *
483 * @param array $args
484 *
485 * @return string|array
486 */
487 public static function get_simple_request( $args ) {
488 $defaults = array(
489 'param' => '',
490 'default' => '',
491 'type' => 'get',
492 'sanitize' => 'sanitize_text_field',
493 'serialized' => false,
494 );
495 $args = wp_parse_args( $args, $defaults );
496
497 $value = $args['default'];
498 if ( $args['type'] == 'get' ) {
499 if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
500 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
501 $value = wp_unslash( $_GET[ $args['param'] ] );
502 }
503 } elseif ( $args['type'] == 'post' ) {
504 if ( isset( $_POST[ $args['param'] ] ) ) {
505 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
506 $value = wp_unslash( $_POST[ $args['param'] ] );
507 if ( $args['serialized'] === true && is_serialized_string( $value ) && is_serialized( $value ) ) {
508 self::unserialize_or_decode( $value );
509 }
510 }
511 } else {
512 if ( isset( $_REQUEST[ $args['param'] ] ) ) {
513 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
514 $value = wp_unslash( $_REQUEST[ $args['param'] ] );
515 }
516 }
517
518 self::sanitize_value( $args['sanitize'], $value );
519
520 return $value;
521 }
522
523 /**
524 * Preserve backslashes in a value, but make sure value doesn't get compounding slashes
525 *
526 * @since 2.0.8
527 *
528 * @param string $value
529 *
530 * @return string $value
531 */
532 public static function preserve_backslashes( $value ) {
533 // If backslashes have already been added, don't add them again
534 if ( strpos( $value, '\\\\' ) === false ) {
535 $value = addslashes( $value );
536 }
537
538 return $value;
539 }
540
541 public static function sanitize_value( $sanitize, &$value ) {
542 if ( ! empty( $sanitize ) ) {
543 if ( is_array( $value ) ) {
544 $temp_values = $value;
545 foreach ( $temp_values as $k => $v ) {
546 self::sanitize_value( $sanitize, $value[ $k ] );
547 }
548 } else {
549 $value = call_user_func( $sanitize, $value );
550 }
551 }
552 }
553
554 public static function sanitize_request( $sanitize_method, &$values ) {
555 $temp_values = $values;
556 foreach ( $temp_values as $k => $val ) {
557 if ( isset( $sanitize_method[ $k ] ) ) {
558 $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
559 }
560 }
561 }
562
563 /**
564 * @since 4.0.04
565 */
566 public static function sanitize_with_html( &$value ) {
567 self::sanitize_value( 'wp_kses_post', $value );
568 self::decode_specialchars( $value );
569 }
570
571 /**
572 * Do wp_specialchars_decode to get back '&' that wp_kses_post might have turned to '&amp;'
573 * this MUST be done, else we'll be back to the '& entity' problem.
574 *
575 * @since 4.0.04
576 */
577 public static function decode_specialchars( &$value ) {
578 if ( is_array( $value ) ) {
579 $temp_values = $value;
580 foreach ( $temp_values as $k => $v ) {
581 self::decode_specialchars( $value[ $k ] );
582 }
583 } else {
584 self::decode_amp( $value );
585 }
586 }
587
588 /**
589 * The wp_specialchars_decode function changes too much.
590 * This will leave HTML as is, but still convert &.
591 * Adapted from wp_specialchars_decode().
592 *
593 * @since 4.03.01
594 *
595 * @param string $string The string to prep.
596 */
597 private static function decode_amp( &$string ) {
598 // Don't bother if there are no entities - saves a lot of processing
599 if ( empty( $string ) || strpos( $string, '&' ) === false ) {
600 return;
601 }
602
603 $translation = array(
604 '&quot;' => '"',
605 '&#034;' => '"',
606 '&#x22;' => '"',
607 '&lt; ' => '< ', // The space preserves the HTML.
608 '&#060; ' => '< ', // The space preserves the HTML.
609 '&gt;' => '>',
610 '&#062;' => '>',
611 '&amp;' => '&',
612 '&#038;' => '&',
613 '&#x26;' => '&',
614 );
615
616 $translation_preg = array(
617 '/&#0*34;/' => '&#034;',
618 '/&#x0*22;/i' => '&#x22;',
619 '/&#0*60;/' => '&#060;',
620 '/&#0*62;/' => '&#062;',
621 '/&#0*38;/' => '&#038;',
622 '/&#x0*26;/i' => '&#x26;',
623 );
624
625 // Remove zero padding on numeric entities
626 $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );
627
628 // Replace characters according to translation table
629 $string = strtr( $string, $translation );
630 }
631
632 /**
633 * Sanitize the value, and allow some HTML
634 *
635 * @since 2.0
636 *
637 * @param string $value
638 * @param array|string $allowed 'all' for everything included as defaults
639 *
640 * @return string
641 */
642 public static function kses( $value, $allowed = array() ) {
643 $allowed_html = self::allowed_html( $allowed );
644
645 return wp_kses( $value, $allowed_html );
646 }
647
648 /**
649 * @since 2.05.03
650 */
651 private static function allowed_html( $allowed ) {
652 $html = self::safe_html();
653 $allowed_html = array();
654 if ( $allowed == 'all' ) {
655 $allowed_html = $html;
656 } elseif ( ! empty( $allowed ) ) {
657 foreach ( (array) $allowed as $a ) {
658 $allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
659 }
660 }
661
662 return apply_filters( 'frm_striphtml_allowed_tags', $allowed_html );
663 }
664
665 /**
666 * @since 2.05.03
667 */
668 private static function safe_html() {
669 $allow_class = array(
670 'class' => true,
671 'id' => true,
672 );
673
674 return array(
675 'a' => array(
676 'class' => true,
677 'href' => true,
678 'id' => true,
679 'rel' => true,
680 'target' => true,
681 'title' => true,
682 ),
683 'abbr' => array(
684 'title' => true,
685 ),
686 'aside' => $allow_class,
687 'b' => array(),
688 'blockquote' => array(
689 'cite' => true,
690 ),
691 'br' => array(),
692 'cite' => array(
693 'title' => true,
694 ),
695 'code' => array(),
696 'defs' => array(),
697 'del' => array(
698 'datetime' => true,
699 'title' => true,
700 ),
701 'dd' => array(),
702 'div' => array(
703 'class' => true,
704 'id' => true,
705 'title' => true,
706 'style' => true,
707 ),
708 'dl' => array(),
709 'dt' => array(),
710 'em' => array(),
711 'h1' => $allow_class,
712 'h2' => $allow_class,
713 'h3' => $allow_class,
714 'h4' => $allow_class,
715 'h5' => $allow_class,
716 'h6' => $allow_class,
717 'i' => array(
718 'class' => true,
719 'id' => true,
720 'icon' => true,
721 'style' => true,
722 ),
723 'img' => array(
724 'alt' => true,
725 'class' => true,
726 'height' => true,
727 'id' => true,
728 'src' => true,
729 'width' => true,
730 ),
731 'li' => $allow_class,
732 'ol' => $allow_class,
733 'p' => $allow_class,
734 'path' => array(
735 'd' => true,
736 'fill' => true,
737 ),
738 'pre' => array(),
739 'q' => array(
740 'cite' => true,
741 'title' => true,
742 ),
743 'rect' => array(
744 'class' => true,
745 'fill' => true,
746 'height' => true,
747 'width' => true,
748 'x' => true,
749 'y' => true,
750 'rx' => true,
751 'stroke' => true,
752 'stroke-opacity' => true,
753 'stroke-width' => true,
754 ),
755 'section' => $allow_class,
756 'span' => array(
757 'class' => true,
758 'id' => true,
759 'title' => true,
760 'style' => true,
761 ),
762 'strike' => array(),
763 'strong' => array(),
764 'symbol' => array(
765 'class' => true,
766 'id' => true,
767 'viewbox' => true,
768 ),
769 'svg' => array(
770 'class' => true,
771 'id' => true,
772 'xmlns' => true,
773 'viewbox' => true,
774 'width' => true,
775 'height' => true,
776 'style' => true,
777 'fill' => true,
778 ),
779 'use' => array(
780 'href' => true,
781 'xlink:href' => true,
782 ),
783 'ul' => $allow_class,
784 );
785 }
786
787 /**
788 * Used when switching the action for a bulk action
789 *
790 * @since 2.0
791 */
792 public static function remove_get_action() {
793 if ( ! isset( $_GET ) ) {
794 return;
795 }
796
797 $action_name = isset( $_GET['action'] ) ? 'action' : ( isset( $_GET['action2'] ) ? 'action2' : '' );
798 if ( empty( $action_name ) ) {
799 return;
800 }
801
802 $new_action = self::get_param( $action_name, '', 'get', 'sanitize_text_field' );
803 if ( ! empty( $new_action ) ) {
804 $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) );
805 }
806 }
807
808 /**
809 * Check the WP query for a parameter
810 *
811 * @since 2.0
812 * @return string|array
813 */
814 public static function get_query_var( $value, $param ) {
815 if ( $value != '' ) {
816 return $value;
817 }
818
819 global $wp_query;
820 if ( isset( $wp_query->query_vars[ $param ] ) ) {
821 $value = $wp_query->query_vars[ $param ];
822 }
823
824 return $value;
825 }
826
827 /**
828 * Try to show the SVG if possible. Otherwise, use the font icon.
829 *
830 * @since 4.0.02
831 * @param string $class
832 * @param array $atts
833 */
834 public static function icon_by_class( $class, $atts = array() ) {
835 $echo = ! isset( $atts['echo'] ) || $atts['echo'];
836 if ( isset( $atts['echo'] ) ) {
837 unset( $atts['echo'] );
838 }
839
840 $html_atts = self::array_to_html_params( $atts );
841
842 $icon = trim( str_replace( array( 'frm_icon_font', 'frmfont ' ), '', $class ) );
843 if ( $icon === $class ) {
844 $icon = '<i class="' . esc_attr( $class ) . '"' . $html_atts . '></i>';
845 } else {
846 $class = strpos( $icon, ' ' ) === false ? '' : ' ' . $icon;
847 if ( strpos( $icon, ' ' ) ) {
848 $icon = explode( ' ', $icon );
849 $icon = reset( $icon );
850 }
851 $icon = '<svg class="frmsvg' . esc_attr( $class ) . '"' . $html_atts . '>
852 <use xlink:href="#' . esc_attr( $icon ) . '" />
853 </svg>';
854 }
855
856 if ( $echo ) {
857 echo $icon; // WPCS: XSS ok.
858 } else {
859 return $icon;
860 }
861 }
862
863 /**
864 * Include svg images.
865 *
866 * @since 4.0.02
867 */
868 public static function include_svg() {
869 include_once( self::plugin_path() . '/images/icons.svg' );
870 }
871
872 /**
873 * Convert an associative array to HTML values.
874 *
875 * @since 4.0.02
876 * @param array $atts
877 * @return string
878 */
879 public static function array_to_html_params( $atts ) {
880 $html = '';
881 if ( ! empty( $atts ) ) {
882 foreach ( $atts as $key => $value ) {
883 $html .= ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
884 }
885 }
886 return $html;
887 }
888
889 /**
890 * @since 3.0
891 */
892 public static function get_admin_header( $atts ) {
893 $has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) );
894 if ( ! isset( $atts['close'] ) || empty( $atts['close'] ) ) {
895 $atts['close'] = admin_url( 'admin.php?page=formidable' );
896 }
897 if ( ! isset( $atts['import_link'] ) ) {
898 $atts['import_link'] = false;
899 }
900
901 include( self::plugin_path() . '/classes/views/shared/admin-header.php' );
902 }
903
904 /**
905 * @since 3.0
906 * @param array $atts
907 */
908 public static function add_new_item_link( $atts ) {
909 if ( ! empty( $atts['new_link'] ) ) {
910 ?>
911 <a href="<?php echo esc_url( $atts['new_link'] ); ?>" class="button button-primary frm-button-primary frm-with-plus">
912 <?php self::icon_by_class( 'frmfont frm_plus_icon frm_svg15' ); ?>
913 <?php esc_html_e( 'Add New', 'formidable' ); ?>
914 </a>
915 <?php
916 } elseif ( ! empty( $atts['trigger_new_form_modal'] ) ) {
917 ?>
918 <a href="#" class="button button-primary frm-button-primary frm-with-plus frm-trigger-new-form-modal">
919 <?php
920 self::icon_by_class( 'frmfont frm_plus_icon frm_svg15' );
921 esc_html_e( 'Add New', 'formidable' );
922 ?>
923 </a>
924 <?php
925 } elseif ( isset( $atts['link_hook'] ) ) {
926 do_action( $atts['link_hook']['hook'], $atts['link_hook']['param'] );
927 }
928 }
929
930 /**
931 * @since 3.06
932 */
933 public static function show_search_box( $atts ) {
934 $defaults = array(
935 'placeholder' => '',
936 'tosearch' => '',
937 'text' => __( 'Search', 'formidable' ),
938 'input_id' => '',
939 );
940 $atts = array_merge( $defaults, $atts );
941
942 if ( $atts['input_id'] === 'template' && empty( $atts['tosearch'] ) ) {
943 $atts['tosearch'] = 'frm-card';
944 }
945
946 $class = 'frm-search-input';
947 if ( ! empty( $atts['tosearch'] ) ) {
948 $class .= ' frm-auto-search';
949 }
950
951 $input_id = $atts['input_id'] . '-search-input';
952
953 ?>
954 <p class="frm-search">
955 <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>">
956 <?php echo esc_html( $atts['text'] ); ?>:
957 </label>
958 <span class="frmfont frm_search_icon"></span>
959 <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s"
960 value="<?php _admin_search_query(); ?>" placeholder="<?php echo esc_attr( $atts['placeholder'] ); ?>"
961 class="<?php echo esc_attr( $class ); ?>" data-tosearch="<?php echo esc_attr( $atts['tosearch'] ); ?>"
962 <?php if ( ! empty( $atts['tosearch'] ) ) { ?>
963 autocomplete="off"
964 <?php } ?>
965 />
966 <?php
967 if ( empty( $atts['tosearch'] ) ) {
968 submit_button( $atts['text'], 'button-secondary', '', false, array( 'id' => 'search-submit' ) );
969 }
970 ?>
971 </p>
972 <?php
973 }
974
975 /**
976 * @param string $type
977 */
978 public static function trigger_hook_load( $type, $object = null ) {
979 // Only load the form hooks once.
980 $hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
981 if ( ! $hooks_loaded ) {
982 do_action( 'frm_load_' . $type . '_hooks' );
983 }
984 }
985
986 /**
987 * Save all front-end js scripts into a single file
988 *
989 * @since 3.0
990 */
991 public static function save_combined_js() {
992 $file_atts = apply_filters(
993 'frm_js_location',
994 array(
995 'file_name' => 'frm.min.js',
996 'new_file_path' => self::plugin_path() . '/js',
997 )
998 );
999 $new_file = new FrmCreateFile( $file_atts );
1000
1001 $files = array(
1002 self::plugin_path() . '/js/jquery/jquery.placeholder.min.js',
1003 self::plugin_path() . '/js/formidable.min.js',
1004 );
1005 $files = apply_filters( 'frm_combined_js_files', $files );
1006 $new_file->combine_files( $files );
1007 }
1008
1009 /**
1010 * Check a value from a shortcode to see if true or false.
1011 * True when value is 1, true, 'true', 'yes'
1012 *
1013 * @since 1.07.10
1014 *
1015 * @param string $value The value to compare
1016 *
1017 * @return boolean True or False
1018 */
1019 public static function is_true( $value ) {
1020 return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
1021 }
1022
1023 /**
1024 * Gets all post from a specific post type.
1025 *
1026 * @since 4.10.01 Add `$post_type` argument.
1027 *
1028 * @param string $post_type Post type to query. Default is `page`.
1029 * @return WP_Post[]
1030 */
1031 public static function get_pages( $post_type = 'page' ) {
1032 $query = array(
1033 'post_type' => $post_type,
1034 'post_status' => array( 'publish', 'private' ),
1035 'numberposts' => - 1,
1036 'orderby' => 'title',
1037 'order' => 'ASC',
1038 );
1039
1040 return get_posts( $query );
1041 }
1042
1043 /**
1044 * Renders an autocomplete page selection or a regular dropdown depending on
1045 * the total page count
1046 *
1047 * @since 4.03.06
1048 * @since 4.10.01 Added `post_type` and `autocomplete_placeholder` to the arguments array.
1049 *
1050 * @param array $args Selection arguments.
1051 */
1052 public static function maybe_autocomplete_pages_options( $args ) {
1053 $args = self::preformat_selection_args( $args );
1054
1055 $pages_count = wp_count_posts( $args['post_type'] );
1056
1057 if ( $pages_count->publish <= 50 ) {
1058 self::wp_pages_dropdown( $args );
1059 return;
1060 }
1061
1062 wp_enqueue_script( 'jquery-ui-autocomplete' );
1063
1064 $selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' );
1065 $title = '';
1066
1067 if ( $selected ) {
1068 $title = get_the_title( $selected );
1069 }
1070
1071 ?>
1072 <input type="text" class="frm-page-search"
1073 data-post-type="<?php echo esc_attr( $args['post_type'] ); ?>"
1074 placeholder="<?php echo esc_attr( $args['autocomplete_placeholder'] ); ?>"
1075 value="<?php echo esc_attr( $title ); ?>" />
1076 <input type="hidden" name="<?php echo esc_attr( $args['field_name'] ); ?>"
1077 class="frm_autocomplete_value_input"
1078 value="<?php echo esc_attr( $selected ); ?>" />
1079 <?php
1080 }
1081
1082 /**
1083 * @param array $args
1084 * @param string $page_id Deprecated.
1085 * @param boolean $truncate Deprecated.
1086 */
1087 public static function wp_pages_dropdown( $args = array(), $page_id = '', $truncate = false ) {
1088 self::prep_page_dropdown_params( $page_id, $truncate, $args );
1089
1090 $pages = self::get_pages( $args['post_type'] );
1091 $selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' );
1092
1093 ?>
1094 <select name="<?php echo esc_attr( $args['field_name'] ); ?>" id="<?php echo esc_attr( $args['field_name'] ); ?>" class="frm-pages-dropdown">
1095 <option value=""><?php echo esc_html( $args['placeholder'] ); ?></option>
1096 <?php foreach ( $pages as $page ) { ?>
1097 <option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ); ?>>
1098 <?php echo esc_html( $args['truncate'] ? self::truncate( $page->post_title, $args['truncate'] ) : $page->post_title ); ?>
1099 </option>
1100 <?php } ?>
1101 </select>
1102 <?php
1103 }
1104
1105 /**
1106 * Fill in missing parameters passed to wp_pages_dropdown().
1107 * This is for reverse compatibility with switching 3 params to 1.
1108 *
1109 * @since 4.03.06
1110 */
1111 private static function prep_page_dropdown_params( $page_id, $truncate, &$args ) {
1112 if ( ! is_array( $args ) ) {
1113 $args = array(
1114 'field_name' => $args,
1115 'page_id' => $page_id,
1116 'truncate' => $truncate,
1117 );
1118 }
1119
1120 $args = self::preformat_selection_args( $args );
1121 }
1122
1123 /**
1124 * Filter to format args for page dropdown or autocomplete
1125 *
1126 * @since 4.03.06
1127 * @since 4.10.01 Added `post_type` and `autocomplete_placeholder` to the arguments array.
1128 */
1129 private static function preformat_selection_args( $args ) {
1130 $defaults = array(
1131 'truncate' => false,
1132 'placeholder' => ' ',
1133 'field_name' => '',
1134 'page_id' => '',
1135 'post_type' => 'page',
1136 'autocomplete_placeholder' => __( 'Select a Page', 'formidable' ),
1137 );
1138
1139 return array_merge( $defaults, $args );
1140 }
1141
1142 public static function post_edit_link( $post_id ) {
1143 $post = get_post( $post_id );
1144 if ( $post ) {
1145 $post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
1146 $post_url = self::maybe_full_screen_link( $post_url );
1147
1148 return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
1149 }
1150
1151 return '';
1152 }
1153
1154 /**
1155 * Hide the WordPress menus on some pages.
1156 *
1157 * @since 4.0
1158 */
1159 public static function is_full_screen() {
1160 $full_builder = self::is_form_builder_page();
1161 $styler = self::is_admin_page( 'formidable-styles' ) || self::is_admin_page( 'formidable-styles2' );
1162 $full_entries = self::simple_get( 'frm-full', 'absint' );
1163
1164 return $full_builder || $full_entries || $styler || self::is_view_builder_page();
1165 }
1166
1167 /**
1168 * @since 4.0
1169 */
1170 public static function maybe_full_screen_link( $link ) {
1171 $is_full = self::simple_get( 'frm-full', 'absint' );
1172 if ( $is_full && ! empty( $link ) && $link !== '#' ) {
1173 $link .= '&frm-full=1';
1174 }
1175 return $link;
1176 }
1177
1178 /**
1179 * @param string $field_name
1180 * @param string|array $capability
1181 * @param string $multiple 'single' and 'multiple'
1182 */
1183 public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
1184 ?>
1185 <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>"
1186 <?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?>
1187 class="frm_multiselect">
1188 <?php self::roles_options( $capability ); ?>
1189 </select>
1190 <?php
1191 }
1192
1193 /**
1194 * @since 4.07
1195 * @param array|string $selected
1196 * @param string $current
1197 */
1198 private static function selected( $selected, $current ) {
1199 if ( is_callable( 'FrmProAppHelper::selected' ) ) {
1200 FrmProAppHelper::selected( $selected, $current );
1201 } else {
1202 selected( in_array( $current, (array) $selected, true ) );
1203 }
1204 }
1205
1206 /**
1207 * @param string|array $capability
1208 */
1209 public static function roles_options( $capability ) {
1210 global $frm_vars;
1211 if ( isset( $frm_vars['editable_roles'] ) ) {
1212 $editable_roles = $frm_vars['editable_roles'];
1213 } else {
1214 $editable_roles = get_editable_roles();
1215 $frm_vars['editable_roles'] = $editable_roles;
1216 }
1217
1218 foreach ( $editable_roles as $role => $details ) {
1219 $name = translate_user_role( $details['name'] );
1220 ?>
1221 <option value="<?php echo esc_attr( $role ); ?>" <?php self::selected( $capability, $role ); ?>><?php echo esc_attr( $name ); ?> </option>
1222 <?php
1223 unset( $role, $details );
1224 }
1225 }
1226
1227 public static function frm_capabilities( $type = 'auto' ) {
1228 $cap = array(
1229 'frm_view_forms' => __( 'View Forms', 'formidable' ),
1230 'frm_edit_forms' => __( 'Add and Edit Forms', 'formidable' ),
1231 'frm_delete_forms' => __( 'Delete Forms', 'formidable' ),
1232 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ),
1233 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ),
1234 'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ),
1235 );
1236
1237 if ( ! self::pro_is_installed() && 'pro' != $type ) {
1238 return $cap;
1239 }
1240
1241 $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
1242 $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
1243 $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
1244 $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
1245
1246 return $cap;
1247 }
1248
1249 /**
1250 * Call the WordPress current_user_can but also validate empty strings as true for any logged in user
1251 *
1252 * @since 4.06.03
1253 *
1254 * @param string $role
1255 *
1256 * @return bool
1257 */
1258 public static function current_user_can( $role ) {
1259 if ( $role === '-1' ) {
1260 return false;
1261 }
1262
1263 if ( $role === 'loggedout' ) {
1264 return ! is_user_logged_in();
1265 }
1266
1267 if ( $role === 'loggedin' || ! $role ) {
1268 return is_user_logged_in();
1269 }
1270
1271 if ( $role == 1 ) {
1272 $role = 'administrator';
1273 }
1274
1275 if ( ! is_user_logged_in() ) {
1276 return false;
1277 }
1278
1279 return current_user_can( $role );
1280 }
1281
1282 /**
1283 * @param string|array $needed_role
1284 * @return bool
1285 */
1286 public static function user_has_permission( $needed_role ) {
1287 if ( is_array( $needed_role ) ) {
1288 foreach ( $needed_role as $role ) {
1289 if ( self::current_user_can( $role ) ) {
1290 return true;
1291 }
1292 }
1293
1294 return false;
1295 }
1296
1297 $can = self::current_user_can( $needed_role );
1298
1299 if ( $can || in_array( $needed_role, array( '-1', 'loggedout' ) ) ) {
1300 return $can;
1301 }
1302
1303 $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
1304 foreach ( $roles as $role ) {
1305 if ( current_user_can( $role ) ) {
1306 return true;
1307 }
1308 if ( $role == $needed_role ) {
1309 break;
1310 }
1311 }
1312
1313 return false;
1314 }
1315
1316 /**
1317 * Make sure administrators can see Formidable menu
1318 *
1319 * @since 2.0
1320 */
1321 public static function maybe_add_permissions() {
1322 self::force_capability( 'frm_view_entries' );
1323
1324 if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
1325 return;
1326 }
1327
1328 $user_id = get_current_user_id();
1329 $user = new WP_User( $user_id );
1330 $frm_roles = self::frm_capabilities();
1331 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
1332 $user->add_cap( $frm_role );
1333 unset( $frm_role, $frm_role_description );
1334 }
1335 }
1336
1337 /**
1338 * Make sure admins have permission to see the menu items
1339 *
1340 * @since 2.0.6
1341 */
1342 public static function force_capability( $cap = 'frm_change_settings' ) {
1343 if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
1344 $role = get_role( 'administrator' );
1345 $frm_roles = self::frm_capabilities();
1346 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
1347 $role->add_cap( $frm_role );
1348 }
1349 }
1350 }
1351
1352 /**
1353 * Check if the user has permision for action.
1354 * Return permission message and stop the action if no permission
1355 *
1356 * @since 2.0
1357 *
1358 * @param string $permission
1359 */
1360 public static function permission_check( $permission, $show_message = 'show' ) {
1361 $permission_error = self::permission_nonce_error( $permission );
1362 if ( $permission_error !== false ) {
1363 if ( 'hide' == $show_message ) {
1364 $permission_error = '';
1365 }
1366 wp_die( esc_html( $permission_error ) );
1367 }
1368 }
1369
1370 /**
1371 * Check user permission and nonce
1372 *
1373 * @since 2.0
1374 *
1375 * @param string $permission
1376 *
1377 * @return false|string The permission message or false if allowed
1378 */
1379 public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
1380 if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
1381 $frm_settings = self::get_settings();
1382
1383 return $frm_settings->admin_permission;
1384 }
1385
1386 $error = false;
1387 if ( empty( $nonce_name ) ) {
1388 return $error;
1389 }
1390
1391 $nonce_value = ( $_REQUEST && isset( $_REQUEST[ $nonce_name ] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $nonce_name ] ) ) : '';
1392 if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $nonce_value, $nonce ) ) ) {
1393 $frm_settings = self::get_settings();
1394 $error = $frm_settings->admin_permission;
1395 }
1396
1397 return $error;
1398 }
1399
1400 public static function checked( $values, $current ) {
1401 if ( self::check_selected( $values, $current ) ) {
1402 echo ' checked="checked"';
1403 }
1404 }
1405
1406 public static function check_selected( $values, $current ) {
1407 $values = self::recursive_function_map( $values, 'trim' );
1408 $values = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
1409 $current = htmlspecialchars_decode( trim( $current ) );
1410
1411 return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
1412 }
1413
1414 public static function recursive_function_map( $value, $function ) {
1415 if ( is_array( $value ) ) {
1416 $original_function = $function;
1417 if ( count( $value ) ) {
1418 $function = explode( ', ', FrmDb::prepare_array_values( $value, $function ) );
1419 } else {
1420 $function = array( $function );
1421 }
1422 if ( ! self::is_assoc( $value ) ) {
1423 $value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
1424 } else {
1425 foreach ( $value as $k => $v ) {
1426 if ( ! is_array( $v ) ) {
1427 $value[ $k ] = call_user_func( $original_function, $v );
1428 }
1429 }
1430 }
1431 } else {
1432 $value = call_user_func( $function, $value );
1433 }
1434
1435 return $value;
1436 }
1437
1438 public static function is_assoc( $array ) {
1439 return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
1440 }
1441
1442 /**
1443 * Flatten a multi-dimensional array
1444 */
1445 public static function array_flatten( $array, $keys = 'keep' ) {
1446 $return = array();
1447 foreach ( $array as $key => $value ) {
1448 if ( is_array( $value ) ) {
1449 $return = array_merge( $return, self::array_flatten( $value, $keys ) );
1450 } else {
1451 if ( $keys == 'keep' ) {
1452 $return[ $key ] = $value;
1453 } else {
1454 $return[] = $value;
1455 }
1456 }
1457 }
1458
1459 return $return;
1460 }
1461
1462 public static function esc_textarea( $text, $is_rich_text = false ) {
1463 $safe_text = str_replace( '&quot;', '"', $text );
1464 if ( ! $is_rich_text ) {
1465 $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
1466 }
1467 $safe_text = str_replace( '&amp; ', '& ', $safe_text );
1468
1469 return apply_filters( 'esc_textarea', $safe_text, $text );
1470 }
1471
1472 /**
1473 * Add auto paragraphs to text areas
1474 *
1475 * @since 2.0
1476 */
1477 public static function use_wpautop( $content ) {
1478 if ( apply_filters( 'frm_use_wpautop', true ) && ! is_array( $content ) ) {
1479 $content = wpautop( str_replace( '<br>', '<br />', $content ) );
1480 }
1481
1482 return $content;
1483 }
1484
1485 public static function replace_quotes( $val ) {
1486 // Replace double quotes.
1487 $val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
1488
1489 // Replace single quotes.
1490 $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
1491
1492 return $val;
1493 }
1494
1495 /**
1496 * @since 2.0
1497 * @return string The base Google APIS url for the current version of jQuery UI
1498 */
1499 public static function jquery_ui_base_url() {
1500 $url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
1501 $url = apply_filters( 'frm_jquery_ui_base_url', $url );
1502
1503 return $url;
1504 }
1505
1506 /**
1507 * @param string $handle
1508 */
1509 public static function script_version( $handle, $default = 0 ) {
1510 global $wp_scripts;
1511 if ( ! $wp_scripts ) {
1512 return $default;
1513 }
1514
1515 $ver = $default;
1516 if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
1517 return $ver;
1518 }
1519
1520 $query = $wp_scripts->registered[ $handle ];
1521 if ( is_object( $query ) && ! empty( $query->ver ) ) {
1522 $ver = $query->ver;
1523 }
1524
1525 return $ver;
1526 }
1527
1528 public static function js_redirect( $url ) {
1529 return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
1530 }
1531
1532 public static function get_user_id_param( $user_id ) {
1533 if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
1534 return $user_id;
1535 }
1536
1537 $user_id = sanitize_text_field( $user_id );
1538 if ( $user_id == 'current' ) {
1539 $user_id = get_current_user_id();
1540 } else {
1541 if ( is_email( $user_id ) ) {
1542 $user = get_user_by( 'email', $user_id );
1543 } else {
1544 $user = get_user_by( 'login', $user_id );
1545 }
1546
1547 if ( $user ) {
1548 $user_id = $user->ID;
1549 }
1550 unset( $user );
1551 }
1552
1553 return $user_id;
1554 }
1555
1556 public static function get_file_contents( $filename, $atts = array() ) {
1557 if ( ! is_file( $filename ) ) {
1558 return false;
1559 }
1560
1561 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
1562 ob_start();
1563 include( $filename );
1564 $contents = ob_get_contents();
1565 ob_end_clean();
1566
1567 return $contents;
1568 }
1569
1570 /**
1571 * @param string $name
1572 * @param string $table_name
1573 * @param string $column
1574 * @param int $id
1575 * @param int $num_chars
1576 */
1577 public static function get_unique_key( $name, $table_name, $column, $id = 0, $num_chars = 5 ) {
1578 $key = '';
1579 if ( $name ) {
1580 $key = sanitize_key( $name );
1581 $key = self::maybe_clear_long_key( $key, $column );
1582 }
1583
1584 if ( ! $key ) {
1585 $key = self::generate_new_key( $num_chars );
1586 }
1587
1588 $key = self::prevent_numeric_and_reserved_keys( $key );
1589
1590 $key_check = FrmDb::get_var(
1591 $table_name,
1592 array(
1593 $column => $key,
1594 'ID !' => $id,
1595 ),
1596 $column
1597 );
1598
1599 if ( $key_check || is_numeric( $key_check ) ) {
1600 // Create a unique field id if it has already been used.
1601 $key = $key . substr( md5( microtime() . rand() ), 0, 10 );
1602 }
1603
1604 return $key;
1605 }
1606
1607 /**
1608 * Possibly reset a key to avoid conflicts with column size limits.
1609 *
1610 * @param string $key
1611 * @param string $column
1612 * @return string either the original key value, or an empty string if the key was too long.
1613 */
1614 private static function maybe_clear_long_key( $key, $column ) {
1615 if ( 'field_key' === $column && strlen( $key ) >= 70 ) {
1616 $key = '';
1617 }
1618 return $key;
1619 }
1620
1621 /**
1622 * @param int $num_chars
1623 * @return string
1624 */
1625 private static function generate_new_key( $num_chars ) {
1626 $max_slug_value = pow( 36, $num_chars );
1627 $min_slug_value = 37; // we want to have at least 2 characters in the slug
1628 return base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
1629 }
1630
1631 /**
1632 * @param string $key
1633 * @return string
1634 */
1635 private static function prevent_numeric_and_reserved_keys( $key ) {
1636 if ( is_numeric( $key ) ) {
1637 $key .= 'a';
1638 } else {
1639 $not_allowed = array(
1640 'id',
1641 'key',
1642 'created-at',
1643 'detaillink',
1644 'editlink',
1645 'siteurl',
1646 'evenodd',
1647 );
1648 if ( in_array( $key, $not_allowed, true ) ) {
1649 $key .= 'a';
1650 }
1651 }
1652 return $key;
1653 }
1654
1655 /**
1656 * Editing a Form or Entry
1657 *
1658 * @param string $table
1659 *
1660 * @return bool|array
1661 */
1662 public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
1663 if ( ! $record ) {
1664 return false;
1665 }
1666
1667 if ( empty( $post_values ) ) {
1668 $post_values = wp_unslash( $_POST );
1669 }
1670
1671 $values = array(
1672 'id' => $record->id,
1673 'fields' => array(),
1674 );
1675
1676 foreach ( array( 'name', 'description' ) as $var ) {
1677 $default_val = isset( $record->{$var} ) ? $record->{$var} : '';
1678 $values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
1679 unset( $var, $default_val );
1680 }
1681
1682 $values['description'] = self::use_wpautop( $values['description'] );
1683
1684 self::fill_form_opts( $record, $table, $post_values, $values );
1685
1686 self::prepare_field_arrays( $fields, $record, $values, array_merge( $args, compact( 'default', 'post_values' ) ) );
1687
1688 if ( $table == 'entries' ) {
1689 $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1690 } elseif ( $table == 'forms' ) {
1691 $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1692 }
1693
1694 return $values;
1695 }
1696
1697 private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
1698 if ( ! empty( $fields ) ) {
1699 foreach ( (array) $fields as $field ) {
1700 if ( ! self::is_admin_page() ) {
1701 // Don't prep default values on the form settings page.
1702 $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
1703 }
1704 $args['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
1705 self::fill_field_defaults( $field, $record, $values, $args );
1706 }
1707 }
1708 }
1709
1710 private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1711 $post_values = $args['post_values'];
1712
1713 if ( $args['default'] ) {
1714 $meta_value = $field->default_value;
1715 } else {
1716 if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1717 if ( ! isset( $field->field_options['custom_field'] ) ) {
1718 $field->field_options['custom_field'] = '';
1719 }
1720 $meta_value = FrmProEntryMetaHelper::get_post_value(
1721 $record->post_id,
1722 $field->field_options['post_field'],
1723 $field->field_options['custom_field'],
1724 array(
1725 'truncate' => false,
1726 'type' => $field->type,
1727 'form_id' => $field->form_id,
1728 'field' => $field,
1729 )
1730 );
1731 } else {
1732 $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1733 }
1734 }
1735
1736 $field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1737 if ( isset( $post_values['item_meta'][ $field->id ] ) ) {
1738 $new_value = $post_values['item_meta'][ $field->id ];
1739 self::unserialize_or_decode( $new_value );
1740 } else {
1741 $new_value = $meta_value;
1742 }
1743
1744 $field_array = self::start_field_array( $field );
1745 $field_array['value'] = $new_value;
1746 $field_array['type'] = apply_filters( 'frm_field_type', $field_type, $field, $new_value );
1747 $field_array['parent_form_id'] = $args['parent_form_id'];
1748
1749 $args['field_type'] = $field_type;
1750
1751 FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
1752
1753 if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1754 $field_array['unique_msg'] = '';
1755 }
1756
1757 $field_array = array_merge( (array) $field->field_options, $field_array );
1758
1759 $values['fields'][ $field->id ] = $field_array;
1760 }
1761
1762 /**
1763 * @since 3.0
1764 *
1765 * @param object $field
1766 *
1767 * @return array
1768 */
1769 public static function start_field_array( $field ) {
1770 return array(
1771 'id' => $field->id,
1772 'default_value' => $field->default_value,
1773 'name' => $field->name,
1774 'description' => $field->description,
1775 'options' => $field->options,
1776 'required' => $field->required,
1777 'field_key' => $field->field_key,
1778 'field_order' => $field->field_order,
1779 'form_id' => $field->form_id,
1780 );
1781 }
1782
1783 /**
1784 * @param string $table
1785 */
1786 private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1787 if ( $table == 'entries' ) {
1788 $form = $record->form_id;
1789 FrmForm::maybe_get_form( $form );
1790 } else {
1791 $form = $record;
1792 }
1793
1794 if ( ! $form ) {
1795 return;
1796 }
1797
1798 $values['form_name'] = isset( $record->form_id ) ? $form->name : '';
1799 $values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1800
1801 if ( ! is_array( $form->options ) ) {
1802 return;
1803 }
1804
1805 foreach ( $form->options as $opt => $value ) {
1806 if ( isset( $post_values[ $opt ] ) ) {
1807 $values[ $opt ] = $post_values[ $opt ];
1808 self::unserialize_or_decode( $values[ $opt ] );
1809 } else {
1810 $values[ $opt ] = $value;
1811 }
1812 }
1813
1814 self::fill_form_defaults( $post_values, $values );
1815 }
1816
1817 /**
1818 * Set to POST value or default
1819 */
1820 private static function fill_form_defaults( $post_values, array &$values ) {
1821 $form_defaults = FrmFormsHelper::get_default_opts();
1822
1823 foreach ( $form_defaults as $opt => $default ) {
1824 if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1825 $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1826 }
1827
1828 unset( $opt, $default );
1829 }
1830
1831 if ( ! isset( $values['custom_style'] ) ) {
1832 $values['custom_style'] = self::custom_style_value( $post_values );
1833 }
1834
1835 foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1836 if ( ! isset( $values[ $h . '_html' ] ) ) {
1837 $values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1838 }
1839 unset( $h );
1840 }
1841 }
1842
1843 /**
1844 * @since 2.2.10
1845 *
1846 * @param array $post_values
1847 *
1848 * @return boolean|int
1849 */
1850 public static function custom_style_value( $post_values ) {
1851 if ( ! empty( $post_values ) && isset( $post_values['options']['custom_style'] ) ) {
1852 $custom_style = absint( $post_values['options']['custom_style'] );
1853 } else {
1854 $frm_settings = self::get_settings();
1855 $custom_style = ( $frm_settings->load_style != 'none' );
1856 }
1857
1858 return $custom_style;
1859 }
1860
1861 public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1862 if ( is_array( $str ) ) {
1863 return '';
1864 }
1865
1866 $length = (int) $length;
1867 $str = wp_strip_all_tags( $str );
1868 $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1869
1870 if ( $length == 0 ) {
1871 return '';
1872 } elseif ( $length <= 10 ) {
1873 $sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1874
1875 return $sub . ( ( $length < $original_len ) ? $continue : '' );
1876 }
1877
1878 $sub = '';
1879 $len = 0;
1880
1881 $words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1882
1883 foreach ( $words as $word ) {
1884 $part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1885 $total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1886 if ( $total_len > $length && substr_count( $sub, ' ' ) ) {
1887 break;
1888 }
1889
1890 $sub .= $part;
1891 $len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1892
1893 if ( substr_count( $sub, ' ' ) > $minword && $total_len >= $length ) {
1894 break;
1895 }
1896
1897 unset( $total_len, $word );
1898 }
1899
1900 return $sub . ( ( $len < $original_len ) ? $continue : '' );
1901 }
1902
1903 public static function mb_function( $function_names, $args ) {
1904 $mb_function_name = $function_names[0];
1905 $function_name = $function_names[1];
1906 if ( function_exists( $mb_function_name ) ) {
1907 $function_name = $mb_function_name;
1908 }
1909
1910 return call_user_func_array( $function_name, $args );
1911 }
1912
1913 public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1914 if ( empty( $date ) ) {
1915 return $date;
1916 }
1917
1918 if ( empty( $date_format ) ) {
1919 $date_format = get_option( 'date_format' );
1920 }
1921
1922 if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1923 $frmpro_settings = new FrmProSettings();
1924 $date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1925 }
1926
1927 $formatted = self::get_localized_date( $date_format, $date );
1928
1929 $do_time = ( gmdate( 'H:i:s', strtotime( $date ) ) != '00:00:00' );
1930 if ( $do_time ) {
1931 $formatted .= self::add_time_to_date( $time_format, $date );
1932 }
1933
1934 return $formatted;
1935 }
1936
1937 private static function add_time_to_date( $time_format, $date ) {
1938 if ( empty( $time_format ) ) {
1939 $time_format = get_option( 'time_format' );
1940 }
1941
1942 $trimmed_format = trim( $time_format );
1943 $time = '';
1944 if ( $time_format && ! empty( $trimmed_format ) ) {
1945 $time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
1946 }
1947
1948 return $time;
1949 }
1950
1951 /**
1952 * @since 2.0.8
1953 */
1954 public static function get_localized_date( $date_format, $date ) {
1955 $date = get_date_from_gmt( $date );
1956
1957 return date_i18n( $date_format, strtotime( $date ) );
1958 }
1959
1960 /**
1961 * Gets the time ago in words
1962 *
1963 * @param int $from in seconds
1964 * @param int|string $to in seconds
1965 *
1966 * @return string $time_ago
1967 */
1968 public static function human_time_diff( $from, $to = '', $levels = 1 ) {
1969 if ( empty( $to ) ) {
1970 $now = new DateTime();
1971 } else {
1972 $now = new DateTime( '@' . $to );
1973 }
1974 $ago = new DateTime( '@' . $from );
1975
1976 // Get the time difference
1977 $diff_object = $now->diff( $ago );
1978 $diff = get_object_vars( $diff_object );
1979
1980 // Add week amount and update day amount
1981 $diff['w'] = floor( $diff['d'] / 7 );
1982 $diff['d'] -= $diff['w'] * 7;
1983
1984 $time_strings = self::get_time_strings();
1985
1986 if ( ! is_numeric( $levels ) ) {
1987 // Show time in specified unit.
1988 $levels = self::get_unit( $levels );
1989 if ( isset( $time_strings[ $levels ] ) ) {
1990 $diff = array(
1991 $levels => self::time_format( $levels, $diff ),
1992 );
1993 $time_strings = array(
1994 $levels => $time_strings[ $levels ],
1995 );
1996 }
1997 $levels = 1;
1998 }
1999
2000 foreach ( $time_strings as $k => $v ) {
2001 if ( isset( $diff[ $k ] ) && $diff[ $k ] ) {
2002 $time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
2003 } elseif ( isset( $diff[ $k ] ) && count( $time_strings ) === 1 ) {
2004 // Account for 0.
2005 $time_strings[ $k ] = $diff[ $k ] . ' ' . $v[1];
2006 } else {
2007 unset( $time_strings[ $k ] );
2008 }
2009 }
2010
2011 $levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
2012 $time_strings = array_slice( $time_strings, 0, absint( $levels_deep ) );
2013 $time_ago_string = implode( ' ', $time_strings );
2014
2015 return $time_ago_string;
2016 }
2017
2018 /**
2019 * @since 4.05.01
2020 */
2021 private static function time_format( $unit, $diff ) {
2022 $return = array(
2023 'y' => 'y',
2024 'd' => 'days',
2025 );
2026 if ( isset( $return[ $unit ] ) ) {
2027 return $diff[ $return[ $unit ] ];
2028 }
2029
2030 $total = $diff['days'] * self::convert_time( 'd', $unit );
2031
2032 $times = array( 'h', 'i', 's' );
2033
2034 foreach ( $times as $time ) {
2035 if ( ! isset( $diff[ $time ] ) ) {
2036 continue;
2037 }
2038
2039 $total += $diff[ $time ] * self::convert_time( $time, $unit );
2040 }
2041
2042 return floor( $total );
2043 }
2044
2045 /**
2046 * @since 4.05.01
2047 */
2048 private static function convert_time( $from, $to ) {
2049 $convert = array(
2050 's' => 1,
2051 'i' => MINUTE_IN_SECONDS,
2052 'h' => HOUR_IN_SECONDS,
2053 'd' => DAY_IN_SECONDS,
2054 'w' => WEEK_IN_SECONDS,
2055 'm' => DAY_IN_SECONDS * 30.42,
2056 'y' => DAY_IN_SECONDS * 365.25,
2057 );
2058
2059 return $convert[ $from ] / $convert[ $to ];
2060 }
2061
2062 /**
2063 * @since 4.05.01
2064 */
2065 private static function get_unit( $unit ) {
2066 $units = self::get_time_strings();
2067 if ( isset( $units[ $unit ] ) || is_numeric( $unit ) ) {
2068 return $unit;
2069 }
2070
2071 foreach ( $units as $u => $strings ) {
2072 if ( in_array( $unit, $strings ) ) {
2073 return $u;
2074 }
2075 }
2076 return 1;
2077 }
2078
2079 /**
2080 * Get the translatable time strings. The untranslated version is a failsafe
2081 * in case langauges are changing for the unit set in the shortcode.
2082 *
2083 * @since 2.0.20
2084 * @return array
2085 */
2086 private static function get_time_strings() {
2087 return array(
2088 'y' => array(
2089 __( 'year', 'formidable' ),
2090 __( 'years', 'formidable' ),
2091 'year',
2092 ),
2093 'm' => array(
2094 __( 'month', 'formidable' ),
2095 __( 'months', 'formidable' ),
2096 'month',
2097 ),
2098 'w' => array(
2099 __( 'week', 'formidable' ),
2100 __( 'weeks', 'formidable' ),
2101 'week',
2102 ),
2103 'd' => array(
2104 __( 'day', 'formidable' ),
2105 __( 'days', 'formidable' ),
2106 'day',
2107 ),
2108 'h' => array(
2109 __( 'hour', 'formidable' ),
2110 __( 'hours', 'formidable' ),
2111 'hour',
2112 ),
2113 'i' => array(
2114 __( 'minute', 'formidable' ),
2115 __( 'minutes', 'formidable' ),
2116 'minute',
2117 ),
2118 's' => array(
2119 __( 'second', 'formidable' ),
2120 __( 'seconds', 'formidable' ),
2121 'second',
2122 ),
2123 );
2124 }
2125
2126 // Pagination Methods.
2127
2128 /**
2129 * @param integer $current_p
2130 */
2131 public static function get_last_record_num( $r_count, $current_p, $p_size ) {
2132 return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
2133 }
2134
2135 /**
2136 * @param integer $current_p
2137 */
2138 public static function get_first_record_num( $r_count, $current_p, $p_size ) {
2139 if ( $current_p == 1 ) {
2140 return 1;
2141 } else {
2142 return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
2143 }
2144 }
2145
2146 /**
2147 * @return array
2148 */
2149 public static function json_to_array( $json_vars ) {
2150 $vars = array();
2151 foreach ( $json_vars as $jv ) {
2152 $jv_name = explode( '[', $jv['name'] );
2153 $last = count( $jv_name ) - 1;
2154 foreach ( $jv_name as $p => $n ) {
2155 $name = trim( $n, ']' );
2156 if ( ! isset( $l1 ) ) {
2157 $l1 = $name;
2158 }
2159
2160 if ( ! isset( $l2 ) ) {
2161 $l2 = $name;
2162 }
2163
2164 if ( ! isset( $l3 ) ) {
2165 $l3 = $name;
2166 }
2167
2168 $this_val = ( $p == $last ) ? $jv['value'] : array();
2169
2170 switch ( $p ) {
2171 case 0:
2172 $l1 = $name;
2173 self::add_value_to_array( $name, $l1, $this_val, $vars );
2174 break;
2175
2176 case 1:
2177 $l2 = $name;
2178 self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
2179 break;
2180
2181 case 2:
2182 $l3 = $name;
2183 self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
2184 break;
2185
2186 case 3:
2187 $l4 = $name;
2188 self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
2189 }
2190
2191 unset( $this_val, $n );
2192 }
2193
2194 unset( $last, $jv );
2195 }
2196
2197 return $vars;
2198 }
2199
2200 /**
2201 * @param string $name
2202 * @param string $l1
2203 */
2204 public static function add_value_to_array( $name, $l1, $val, &$vars ) {
2205 if ( $name == '' ) {
2206 $vars[] = $val;
2207 } elseif ( ! isset( $vars[ $l1 ] ) ) {
2208 $vars[ $l1 ] = $val;
2209 }
2210 }
2211
2212 public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
2213 $tooltips = array(
2214 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ),
2215 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [admin_email] is the address set in WP General Settings.', 'formidable' ),
2216 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
2217 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
2218 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
2219 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <john@example.com> or john@example.com.', 'formidable' ),
2220 /* translators: %1$s: Form name, %2$s: Date */
2221 '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() ) ),
2222 );
2223
2224 if ( ! isset( $tooltips[ $name ] ) ) {
2225 return;
2226 }
2227
2228 if ( 'open' == $class ) {
2229 echo ' frm_help"';
2230 } else {
2231 echo ' class="frm_help"';
2232 }
2233
2234 echo ' title="' . esc_attr( $tooltips[ $name ] );
2235
2236 if ( 'open' != $class ) {
2237 echo '"';
2238 }
2239 }
2240
2241 /**
2242 * Add the current_page class to that page in the form nav
2243 */
2244 public static function select_current_page( $page, $current_page, $action = array() ) {
2245 if ( $current_page != $page ) {
2246 return;
2247 }
2248
2249 $frm_action = self::simple_get( 'frm_action', 'sanitize_title' );
2250 if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
2251 echo ' class="current_page"';
2252 }
2253 }
2254
2255 /**
2256 * Prepare and json_encode post content
2257 *
2258 * @since 2.0
2259 *
2260 * @param array $post_content
2261 *
2262 * @return string $post_content ( json encoded array )
2263 */
2264 public static function prepare_and_encode( $post_content ) {
2265 // Loop through array to strip slashes and add only the needed ones.
2266 foreach ( $post_content as $key => $val ) {
2267 // Replace problematic characters (like &quot;)
2268 if ( is_string( $val ) ) {
2269 $val = str_replace( '&quot;', '"', $val );
2270 }
2271
2272 self::prepare_action_slashes( $val, $key, $post_content );
2273 unset( $key, $val );
2274 }
2275
2276 // json_encode the array.
2277 $post_content = json_encode( $post_content );
2278
2279 // Add extra slashes for \r\n since WP strips them.
2280 $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
2281
2282 // allow for &quot
2283 $post_content = str_replace( '&quot;', '\\"', $post_content );
2284
2285 return $post_content;
2286 }
2287
2288 private static function prepare_action_slashes( $val, $key, &$post_content ) {
2289 if ( ! isset( $post_content[ $key ] ) ) {
2290 return;
2291 }
2292
2293 if ( is_array( $val ) ) {
2294 foreach ( $val as $k1 => $v1 ) {
2295 self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
2296 unset( $k1, $v1 );
2297 }
2298 } else {
2299 // Strip all slashes so everything is the same, no matter where the value is coming from
2300 $val = stripslashes( $val );
2301
2302 // Add backslashes before double quotes and forward slashes only
2303 $post_content[ $key ] = addcslashes( $val, '"\\/' );
2304 }
2305 }
2306
2307 /**
2308 * Check for either json or serilized data. This is temporary while transitioning
2309 * all data to json.
2310 *
2311 * @since 4.02.03
2312 */
2313 public static function unserialize_or_decode( &$value ) {
2314 if ( is_array( $value ) ) {
2315 return;
2316 }
2317
2318 if ( is_serialized( $value ) ) {
2319 $value = maybe_unserialize( $value );
2320 } else {
2321 $value = self::maybe_json_decode( $value, false );
2322 }
2323 }
2324
2325 /**
2326 * Decode a JSON string.
2327 * Do not switch shortcodes like [24] to array unless intentional ie XML values.
2328 */
2329 public static function maybe_json_decode( $string, $single_to_array = true ) {
2330 if ( is_array( $string ) ) {
2331 return $string;
2332 }
2333
2334 $new_string = json_decode( $string, true );
2335 if ( function_exists( 'json_last_error' ) ) {
2336 // php 5.3+
2337 $single_value = false;
2338 if ( ! $single_to_array ) {
2339 $single_value = is_array( $new_string ) && count( $new_string ) === 1 && isset( $new_string[0] );
2340 }
2341 if ( json_last_error() == JSON_ERROR_NONE && is_array( $new_string ) && ! $single_value ) {
2342 $string = $new_string;
2343 }
2344 }
2345
2346 return $string;
2347 }
2348
2349 /**
2350 * Reformat the json serialized array in name => value array.
2351 *
2352 * @since 4.02.03
2353 */
2354 public static function format_form_data( &$form ) {
2355 $formatted = array();
2356
2357 foreach ( $form as $input ) {
2358 if ( ! isset( $input['name'] ) ) {
2359 continue;
2360 }
2361 $key = $input['name'];
2362 if ( isset( $formatted[ $key ] ) ) {
2363 if ( is_array( $formatted[ $key ] ) ) {
2364 $formatted[ $key ][] = $input['value'];
2365 } else {
2366 $formatted[ $key ] = array( $formatted[ $key ], $input['value'] );
2367 }
2368 } else {
2369 $formatted[ $key ] = $input['value'];
2370 }
2371 }
2372
2373 parse_str( http_build_query( $formatted ), $form );
2374 }
2375
2376 /**
2377 * @since 4.02.03
2378 */
2379 public static function maybe_json_encode( $value ) {
2380 if ( is_array( $value ) ) {
2381 $value = wp_json_encode( $value );
2382 }
2383 return $value;
2384 }
2385
2386 /**
2387 * @since 1.07.10
2388 *
2389 * @param string $post_type The name of the post type that may need to be highlighted
2390 * echo The javascript to open and highlight the Formidable menu
2391 */
2392 public static function maybe_highlight_menu( $post_type ) {
2393 global $post;
2394
2395 if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
2396 return;
2397 }
2398
2399 if ( is_object( $post ) && $post->post_type != $post_type ) {
2400 return;
2401 }
2402
2403 self::load_admin_wide_js();
2404 echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
2405 }
2406
2407 /**
2408 * Load the JS file on non-Formidable pages in the admin area
2409 *
2410 * @since 2.0
2411 */
2412 public static function load_admin_wide_js( $load = true ) {
2413 $version = self::plugin_version();
2414 wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
2415
2416 $global_strings = array(
2417 'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
2418 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
2419 'url' => self::plugin_url(),
2420 'app_url' => 'https://formidableforms.com/',
2421 'loading' => __( 'Loading&hellip;', 'formidable' ),
2422 'nonce' => wp_create_nonce( 'frm_ajax' ),
2423 );
2424 wp_localize_script( 'formidable_admin_global', 'frmGlobal', $global_strings );
2425
2426 if ( $load ) {
2427 wp_enqueue_script( 'formidable_admin_global' );
2428 }
2429 }
2430
2431 /**
2432 * @since 2.0.9
2433 */
2434 public static function load_font_style() {
2435 wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
2436 }
2437
2438 /**
2439 * @param string $location
2440 */
2441 public static function localize_script( $location ) {
2442 global $wp_scripts;
2443
2444 $ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
2445 $ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
2446
2447 $script_strings = array(
2448 'ajax_url' => $ajax_url,
2449 'images_url' => self::plugin_url() . '/images',
2450 'loading' => __( 'Loading&hellip;', 'formidable' ),
2451 'remove' => __( 'Remove', 'formidable' ),
2452 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
2453 'nonce' => wp_create_nonce( 'frm_ajax' ),
2454 'id' => __( 'ID', 'formidable' ),
2455 'no_results' => __( 'No results match', 'formidable' ),
2456 'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
2457 'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
2458 'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
2459 );
2460
2461 $data = $wp_scripts->get_data( 'formidable', 'data' );
2462 if ( empty( $data ) ) {
2463 wp_localize_script( 'formidable', 'frm_js', $script_strings );
2464 }
2465
2466 if ( $location == 'admin' ) {
2467 $frm_settings = self::get_settings();
2468 $admin_script_strings = array(
2469 'desc' => __( '(Click to add description)', 'formidable' ),
2470 'blank' => __( '(Blank)', 'formidable' ),
2471 'no_label' => __( '(no label)', 'formidable' ),
2472 'saving' => esc_attr( __( 'Saving', 'formidable' ) ),
2473 'saved' => esc_attr( __( 'Saved', 'formidable' ) ),
2474 'ok' => __( 'OK', 'formidable' ),
2475 'cancel' => __( 'Cancel', 'formidable' ),
2476 'default_label' => __( 'Default', 'formidable' ),
2477 'clear_default' => __( 'Clear default value when typing', 'formidable' ),
2478 'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
2479 'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
2480 'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
2481 'caution' => __( 'Heads up', 'formidable' ),
2482 'confirm' => __( 'Are you sure?', 'formidable' ),
2483 'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
2484 'conf_delete_sec' => __( 'All fields inside this Section will be deleted along with their data. Are you sure you want to delete this group of fields?', 'formidable' ),
2485 'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
2486 'default_unique' => $frm_settings->unique_msg,
2487 'default_conf' => __( 'The entered values do not match', 'formidable' ),
2488 'enter_email' => __( 'Enter Email', 'formidable' ),
2489 'confirm_email' => __( 'Confirm Email', 'formidable' ),
2490 'conditional_text' => __( 'Conditional content here', 'formidable' ),
2491 'new_option' => __( 'New Option', 'formidable' ),
2492 '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' ),
2493 'enter_password' => __( 'Enter Password', 'formidable' ),
2494 'confirm_password' => __( 'Confirm Password', 'formidable' ),
2495 'import_complete' => __( 'Import Complete', 'formidable' ),
2496 'updating' => __( 'Please wait while your site updates.', 'formidable' ),
2497 'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
2498 'private_label' => __( 'Private', 'formidable' ),
2499 'jquery_ui_url' => self::jquery_ui_base_url(),
2500 'pro_url' => is_callable( 'FrmProAppHelper::plugin_url' ) ? FrmProAppHelper::plugin_url() : '',
2501 'no_licenses' => __( 'No new licenses were found', 'formidable' ),
2502 'unmatched_parens' => __( 'This calculation has at least one unmatched ( ) { } [ ].', 'formidable' ),
2503 'view_shortcodes' => __( 'This calculation may have shortcodes that work in Views but not forms.', 'formidable' ),
2504 'text_shortcodes' => __( 'This calculation may have shortcodes that work in text calculations but not numeric calculations.', 'formidable' ),
2505 'only_one_action' => __( 'This form action is limited to one per form. Please edit the existing form action.', 'formidable' ),
2506 'unsafe_params' => FrmFormsHelper::reserved_words(),
2507 /* Translators: %s is the name of a Detail Page Slug that is a reserved word.*/
2508 'slug_is_reserved' => sprintf( __( 'The Detail Page Slug "%s" is reserved by WordPress. This may cause problems. Is this intentional?', 'formidable' ), '****' ),
2509 /* Translators: %s is the name of a parameter that is a reserved word. More than one word could be listed here, though that would not be common. */
2510 'param_is_reserved' => sprintf( __( 'The parameter "%s" is reserved by WordPress. This may cause problems when included in the URL. Is this intentional? ', 'formidable' ), '****' ),
2511 'reserved_words' => __( 'See the list of reserved words in WordPress.', 'formidable' ),
2512 'repeat_limit_min' => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
2513 'checkbox_limit' => __( 'Please select a limit between 0 and 200.', 'formidable' ),
2514 'install' => __( 'Install', 'formidable' ),
2515 'active' => __( 'Active', 'formidable' ),
2516 'select_a_field' => __( 'Select a Field', 'formidable' ),
2517 'no_items_found' => __( 'No items found.', 'formidable' ),
2518 );
2519 $admin_script_strings = apply_filters( 'frm_admin_script_strings', $admin_script_strings );
2520
2521 $data = $wp_scripts->get_data( 'formidable_admin', 'data' );
2522 if ( empty( $data ) ) {
2523 wp_localize_script( 'formidable_admin', 'frm_admin_js', $admin_script_strings );
2524 }
2525 }
2526 }
2527
2528 /**
2529 * Echo the message on the plugins listing page
2530 *
2531 * @since 1.07.10
2532 *
2533 * @param float $min_version The version the add-on requires
2534 */
2535 public static function min_version_notice( $min_version ) {
2536 $frm_version = self::plugin_version();
2537
2538 // Check if Formidable meets minimum requirements.
2539 if ( version_compare( $frm_version, $min_version, '>=' ) ) {
2540 return;
2541 }
2542
2543 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
2544 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">' .
2545 esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
2546 '</div></td></tr>';
2547 }
2548
2549 /**
2550 * If Pro is far outdated, show a message.
2551 *
2552 * @since 4.0.01
2553 */
2554 public static function min_pro_version_notice( $min_version ) {
2555 if ( ! self::is_formidable_admin() ) {
2556 // Don't show admin-wide.
2557 return;
2558 }
2559
2560 self::php_version_notice();
2561
2562 $is_pro = self::pro_is_installed() && class_exists( 'FrmProDb' );
2563 if ( ! $is_pro || self::meets_min_pro_version( $min_version ) ) {
2564 return;
2565 }
2566
2567 $pro_version = FrmProDb::$plug_version;
2568 $expired = FrmAddonsController::is_license_expired();
2569 ?>
2570 <div class="error frm_previous_install">
2571 <?php
2572 esc_html_e( 'You are running a version of Formidable Forms that may not be compatible with your version of Formidable Forms Pro.', 'formidable' );
2573 if ( empty( $expired ) ) {
2574 echo ' Please <a href="' . esc_url( admin_url( 'plugins.php?s=formidable%20forms%20pro' ) ) . '">update now</a>.';
2575 } else {
2576 echo '<br/>Please <a href="https://formidableforms.com/account/downloads/?utm_source=WordPress&utm_medium=outdated">renew now</a> to get the latest version.';
2577 }
2578 ?>
2579 </div>
2580 <?php
2581 }
2582
2583 /**
2584 * If Pro is installed, check the version number.
2585 *
2586 * @since 4.0.01
2587 */
2588 public static function meets_min_pro_version( $min_version ) {
2589 return ! class_exists( 'FrmProDb' ) || version_compare( FrmProDb::$plug_version, $min_version, '>=' );
2590 }
2591
2592 /**
2593 * Show a message if the browser or PHP version is below the recommendations.
2594 *
2595 * @since 4.0.02
2596 */
2597 private static function php_version_notice() {
2598 $message = array();
2599 if ( version_compare( phpversion(), '5.6', '<' ) ) {
2600 $message[] = __( 'The version of PHP on your server is too low. If this is not corrected, you may see issues with Formidable Forms. Please contact your web host and ask to be updated to PHP 7.0+.', 'formidable' );
2601 }
2602
2603 $browser = self::get_server_value( 'HTTP_USER_AGENT' );
2604 $is_ie = strpos( $browser, 'MSIE' ) !== false;
2605 if ( $is_ie ) {
2606 $message[] = __( 'You are using an outdated browser that is not compatible with Formidable Forms. Please update to a more current browser (we recommend Chrome).', 'formidable' );
2607 }
2608
2609 foreach ( $message as $m ) {
2610 ?>
2611 <div class="error frm_previous_install">
2612 <?php echo esc_html( $m ); ?>
2613 </div>
2614 <?php
2615 }
2616 }
2617
2618 public static function locales( $type = 'date' ) {
2619 $locales = array(
2620 'en' => __( 'English', 'formidable' ),
2621 'af' => __( 'Afrikaans', 'formidable' ),
2622 'sq' => __( 'Albanian', 'formidable' ),
2623 'ar' => __( 'Arabic', 'formidable' ),
2624 'hy' => __( 'Armenian', 'formidable' ),
2625 'az' => __( 'Azerbaijani', 'formidable' ),
2626 'eu' => __( 'Basque', 'formidable' ),
2627 'bs' => __( 'Bosnian', 'formidable' ),
2628 'bg' => __( 'Bulgarian', 'formidable' ),
2629 'ca' => __( 'Catalan', 'formidable' ),
2630 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
2631 'zh-CN' => __( 'Chinese Simplified', 'formidable' ),
2632 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
2633 'hr' => __( 'Croatian', 'formidable' ),
2634 'cs' => __( 'Czech', 'formidable' ),
2635 'da' => __( 'Danish', 'formidable' ),
2636 'nl' => __( 'Dutch', 'formidable' ),
2637 'en-GB' => __( 'English/UK', 'formidable' ),
2638 'eo' => __( 'Esperanto', 'formidable' ),
2639 'et' => __( 'Estonian', 'formidable' ),
2640 'fo' => __( 'Faroese', 'formidable' ),
2641 'fa' => __( 'Farsi/Persian', 'formidable' ),
2642 'fil' => __( 'Filipino', 'formidable' ),
2643 'fi' => __( 'Finnish', 'formidable' ),
2644 'fr' => __( 'French', 'formidable' ),
2645 'fr-CA' => __( 'French/Canadian', 'formidable' ),
2646 'fr-CH' => __( 'French/Swiss', 'formidable' ),
2647 'de' => __( 'German', 'formidable' ),
2648 'de-AT' => __( 'German/Austria', 'formidable' ),
2649 'de-CH' => __( 'German/Switzerland', 'formidable' ),
2650 'el' => __( 'Greek', 'formidable' ),
2651 'he' => __( 'Hebrew', 'formidable' ),
2652 'iw' => __( 'Hebrew', 'formidable' ),
2653 'hi' => __( 'Hindi', 'formidable' ),
2654 'hu' => __( 'Hungarian', 'formidable' ),
2655 'is' => __( 'Icelandic', 'formidable' ),
2656 'id' => __( 'Indonesian', 'formidable' ),
2657 'it' => __( 'Italian', 'formidable' ),
2658 'ja' => __( 'Japanese', 'formidable' ),
2659 'ko' => __( 'Korean', 'formidable' ),
2660 'lv' => __( 'Latvian', 'formidable' ),
2661 'lt' => __( 'Lithuanian', 'formidable' ),
2662 'ms' => __( 'Malaysian', 'formidable' ),
2663 'no' => __( 'Norwegian', 'formidable' ),
2664 'pl' => __( 'Polish', 'formidable' ),
2665 'pt' => __( 'Portuguese', 'formidable' ),
2666 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
2667 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ),
2668 'ro' => __( 'Romanian', 'formidable' ),
2669 'ru' => __( 'Russian', 'formidable' ),
2670 'sr' => __( 'Serbian', 'formidable' ),
2671 'sr-SR' => __( 'Serbian', 'formidable' ),
2672 'sk' => __( 'Slovak', 'formidable' ),
2673 'sl' => __( 'Slovenian', 'formidable' ),
2674 'es' => __( 'Spanish', 'formidable' ),
2675 'es-419' => __( 'Spanish/Latin America', 'formidable' ),
2676 'sv' => __( 'Swedish', 'formidable' ),
2677 'ta' => __( 'Tamil', 'formidable' ),
2678 'th' => __( 'Thai', 'formidable' ),
2679 'tr' => __( 'Turkish', 'formidable' ),
2680 'uk' => __( 'Ukranian', 'formidable' ),
2681 'vi' => __( 'Vietnamese', 'formidable' ),
2682 );
2683
2684 if ( $type === 'captcha' ) {
2685 // remove the languages unavailable for the captcha
2686 $unset = array( 'af', 'sq', 'hy', 'az', 'eu', 'bs', 'zh-HK', 'eo', 'et', 'fo', 'fr-CH', 'he', 'is', 'ms', 'sr-SR', 'ta' );
2687 } else {
2688 // remove the languages unavailable for the datepicker
2689 $unset = array( 'fil', 'fr-CA', 'de-AT', 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', 'es-419' );
2690 }
2691
2692 $locales = array_diff_key( $locales, array_flip( $unset ) );
2693 $locales = apply_filters( 'frm_locales', $locales );
2694
2695 return $locales;
2696 }
2697
2698 /**
2699 * Output HTML containing reference text for accessibility
2700 */
2701 public static function multiselect_accessibility() {
2702 include_once self::plugin_path() . '/classes/views/frm-forms/multiselect-accessibility.php';
2703 }
2704
2705 /**
2706 * @since 4.07
2707 * @deprecated 4.09.01
2708 */
2709 public static function renewal_message() {
2710 if ( is_callable( 'FrmProAddonsController::renewal_message' ) ) {
2711 FrmProAddonsController::renewal_message();
2712 return;
2713 }
2714
2715 if ( ! FrmAddonsController::is_license_expired() ) {
2716 return;
2717 }
2718
2719 ?>
2720 <div class="frm_error_style" style="text-align:left">
2721 <?php self::icon_by_class( 'frmfont frm_alert_icon' ); ?>
2722 &nbsp;
2723 <?php esc_html_e( 'Your account has expired', 'formidable' ); ?>
2724 <div style="float:right">
2725 <a href="<?php echo esc_url( self::admin_upgrade_link( 'form-expired', 'account/downloads/' ) ); ?>">
2726 <?php esc_html_e( 'Renew Now', 'formidable' ); ?>
2727 </a>
2728 </div>
2729 </div>
2730 <?php
2731 }
2732
2733 /**
2734 * @since 4.08
2735 * @deprecated 4.09.01
2736 */
2737 public static function expiring_message() {
2738 _deprecated_function( __METHOD__, '4.09.01', 'FrmProAddonsController::expiring_message' );
2739 if ( is_callable( 'FrmProAddonsController::expiring_message' ) ) {
2740 FrmProAddonsController::expiring_message();
2741 }
2742 }
2743
2744 /**
2745 * Use the WP 4.7 wp_doing_ajax function
2746 *
2747 * @since 2.05.07
2748 * @deprecated 4.04.04
2749 */
2750 public static function wp_doing_ajax() {
2751 _deprecated_function( __METHOD__, '4.04.04', 'wp_doing_ajax' );
2752 return wp_doing_ajax();
2753 }
2754
2755 /**
2756 * @deprecated 4.0
2757 */
2758 public static function insert_opt_html( $args ) {
2759 _deprecated_function( __METHOD__, '4.0', 'FrmFormsHelper::insert_opt_html' );
2760 FrmFormsHelper::insert_opt_html( $args );
2761 }
2762
2763 /**
2764 * Used to filter shortcode in text widgets
2765 *
2766 * @deprecated 2.5.4
2767 * @codeCoverageIgnore
2768 */
2769 public static function widget_text_filter_callback( $matches ) {
2770 return FrmDeprecated::widget_text_filter_callback( $matches );
2771 }
2772
2773 /**
2774 * @deprecated 3.01
2775 * @codeCoverageIgnore
2776 */
2777 public static function sanitize_array( &$values ) {
2778 FrmDeprecated::sanitize_array( $values );
2779 }
2780
2781 /**
2782 * @param array $settings
2783 * @param string $group
2784 *
2785 * @since 2.0.6
2786 * @deprecated 2.05.06
2787 * @codeCoverageIgnore
2788 */
2789 public static function save_settings( $settings, $group ) {
2790 return FrmDeprecated::save_settings( $settings, $group );
2791 }
2792
2793 /**
2794 * @since 2.0.4
2795 * @deprecated 2.05.06
2796 * @codeCoverageIgnore
2797 */
2798 public static function save_json_post( $settings ) {
2799 return FrmDeprecated::save_json_post( $settings );
2800 }
2801
2802 /**
2803 * @since 2.0
2804 * @deprecated 2.05.06
2805 * @codeCoverageIgnore
2806 *
2807 * @param string $cache_key The unique name for this cache
2808 * @param string $group The name of the cache group
2809 * @param string $query If blank, don't run a db call
2810 * @param string $type The wpdb function to use with this query
2811 *
2812 * @return mixed $results The cache or query results
2813 */
2814 public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
2815 return FrmDeprecated::check_cache( $cache_key, $group, $query, $type, $time );
2816 }
2817
2818 /**
2819 * @deprecated 2.05.06
2820 * @codeCoverageIgnore
2821 */
2822 public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
2823 return FrmDeprecated::set_cache( $cache_key, $results, $group, $time );
2824 }
2825
2826 /**
2827 * @deprecated 2.05.06
2828 * @codeCoverageIgnore
2829 */
2830 public static function add_key_to_group_cache( $key, $group ) {
2831 FrmDeprecated::add_key_to_group_cache( $key, $group );
2832 }
2833
2834 /**
2835 * @deprecated 2.05.06
2836 * @codeCoverageIgnore
2837 */
2838 public static function get_group_cached_keys( $group ) {
2839 return FrmDeprecated::get_group_cached_keys( $group );
2840 }
2841
2842 /**
2843 * @since 2.0
2844 * @deprecated 2.05.06
2845 * @codeCoverageIgnore
2846 * @return mixed The cached value or false
2847 */
2848 public static function check_cache_and_transient( $cache_key ) {
2849 return FrmDeprecated::check_cache( $cache_key );
2850 }
2851
2852 /**
2853 * @since 2.0
2854 * @deprecated 2.05.06
2855 * @codeCoverageIgnore
2856 *
2857 * @param string $cache_key
2858 */
2859 public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
2860 FrmDeprecated::delete_cache_and_transient( $cache_key, $group );
2861 }
2862
2863 /**
2864 * @since 2.0
2865 * @deprecated 2.05.06
2866 * @codeCoverageIgnore
2867 *
2868 * @param string $group The name of the cache group
2869 */
2870 public static function cache_delete_group( $group ) {
2871 FrmDeprecated::cache_delete_group( $group );
2872 }
2873
2874 /**
2875 * @since 1.07.10
2876 * @deprecated 2.05.06
2877 * @codeCoverageIgnore
2878 *
2879 * @param string $term The value to escape
2880 *
2881 * @return string The escaped value
2882 */
2883 public static function esc_like( $term ) {
2884 return FrmDeprecated::esc_like( $term );
2885 }
2886
2887 /**
2888 * @param string $order_query
2889 *
2890 * @deprecated 2.05.06
2891 * @codeCoverageIgnore
2892 */
2893 public static function esc_order( $order_query ) {
2894 return FrmDeprecated::esc_order( $order_query );
2895 }
2896
2897 /**
2898 * @deprecated 2.05.06
2899 * @codeCoverageIgnore
2900 */
2901 public static function esc_order_by( &$order_by ) {
2902 FrmDeprecated::esc_order_by( $order_by );
2903 }
2904
2905 /**
2906 * @param string $limit
2907 *
2908 * @deprecated 2.05.06
2909 * @codeCoverageIgnore
2910 */
2911 public static function esc_limit( $limit ) {
2912 return FrmDeprecated::esc_limit( $limit );
2913 }
2914
2915 /**
2916 * @since 2.0
2917 * @deprecated 2.05.06
2918 * @codeCoverageIgnore
2919 */
2920 public static function prepare_array_values( $array, $type = '%s' ) {
2921 return FrmDeprecated::prepare_array_values( $array, $type );
2922 }
2923
2924 /**
2925 * @deprecated 2.05.06
2926 * @codeCoverageIgnore
2927 */
2928 public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
2929 return FrmDeprecated::prepend_and_or_where( $starts_with, $where );
2930 }
2931 }
2932