PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16.1.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16.1.2
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
← All changes | classes/helpers/FrmStylesHelper.php +7 -212 6.266.16.1.2 View file →
@@ -4,14 +4,10 @@
4 4 }
5 5
6 6 class FrmStylesHelper {
7 7
8 - /**
9 - * @return array
10 - */
11 8 public static function get_upload_base() {
12 9 $uploads = wp_upload_dir();
13 -
14 10 if ( is_ssl() && ! preg_match( '/^https:\/\/.*\..*$/', $uploads['baseurl'] ) ) {
15 11 $uploads['baseurl'] = str_replace( 'http://', 'https://', $uploads['baseurl'] );
16 12 }
17 13
@@ -21,10 +17,8 @@
21 17 /**
22 18 * Called from the admin header.
23 19 *
24 20 * @since 4.0
25 - *
26 - * @return void
27 21 */
28 22 public static function save_button() {
29 23 ?>
30 24 <input type="submit" name="submit" class="button button-primary frm-button-primary" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" />
@@ -32,10 +26,8 @@
32 26 }
33 27
34 28 /**
35 29 * @since 2.05
36 - *
37 - * @return array
38 30 */
39 31 public static function get_css_label_positions() {
40 32 return array(
41 33 'none' => __( 'top', 'formidable' ),
@@ -74,11 +66,8 @@
74 66 */
75 67 return apply_filters( 'frm_single_label_positions', $label_positions, $field );
76 68 }
77 69
78 - /**
79 - * @return array
80 - */
81 70 public static function minus_icons() {
82 71 return array(
83 72 0 => array(
84 73 '-' => '62e',
@@ -102,11 +91,8 @@
102 91 ),
103 92 );
104 93 }
105 94
106 - /**
107 - * @return array
108 - */
109 95 public static function arrow_icons() {
110 96 $minus_icons = self::minus_icons();
111 97
112 98 return array(
@@ -147,13 +133,8 @@
147 133 }
148 134
149 135 /**
150 136 * @since 2.0
151 - *
152 - * @param int|string $key Icon key.
153 - * @param string $icon Icon state, `+` or `-`.
154 - * @param string $type Icon type, such as `arrow`.
155 - *
156 137 * @return string The class for this icon.
157 138 */
158 139 public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
159 140 if ( 'arrow' === $type && is_numeric( $key ) ) {
@@ -175,9 +156,8 @@
175 156
176 157 if ( $key ) {
177 158 $class .= $key;
178 159 }
179 -
180 160 $class .= '_icon';
181 161
182 162 return $class;
183 163 }
@@ -185,9 +165,8 @@
185 165 /**
186 166 * @param WP_Post $style
187 167 * @param FrmStyle $frm_style
188 168 * @param string $type
189 - *
190 169 * @return void
191 170 */
192 171 public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
193 172 $function_name = $type . '_icons';
@@ -228,9 +207,8 @@
228 207 *
229 208 * @since 2.0
230 209 *
231 210 * @param string $color Color setting value. This could be hex or rgb.
232 - *
233 211 * @return string RGB value without the rgb() wrapper.
234 212 */
235 213 public static function hex2rgb( $color ) {
236 214 if ( 0 === strpos( $color, 'rgb' ) ) {
@@ -246,15 +224,13 @@
246 224 *
247 225 * @since 6.8.3
248 226 *
249 227 * @param string $rgb RGB value including the rgb() or rgba() wrapper.
250 - *
251 228 * @return array<string> including three numeric values for R, G, and B.
252 229 */
253 230 private static function get_rgb_array_from_rgb( $rgb ) {
254 231 $rgb = str_replace( array( 'rgb(', 'rgba(', ')' ), '', $rgb );
255 232 $rgb = explode( ',', $rgb );
256 -
257 233 if ( 4 === count( $rgb ) ) {
258 234 // Drop the alpha. The function is expected to only return r,g,b with no alpha.
259 235 array_pop( $rgb );
260 236 }
@@ -266,9 +242,8 @@
266 242 *
267 243 * @since 6.8.3
268 244 *
269 245 * @param string $hex A hex color string.
270 - *
271 246 * @return array<string> Including three numeric values for R, G, and B.
272 247 */
273 248 private static function get_rgb_array_from_hex( $hex ) {
274 249 $hex = str_replace( '#', '', $hex );
@@ -277,13 +252,8 @@
277 252 }
278 253
279 254 /**
280 255 * @since 4.0
281 - *
282 - * @param string $hex Hex color string.
283 - * @param float|int|string $a Alpha channel value.
284 - *
285 - * @return string
286 256 */
287 257 public static function hex2rgba( $hex, $a ) {
288 258 $rgb = self::hex2rgb( $hex );
289 259
@@ -293,9 +263,8 @@
293 263 /**
294 264 * @since 6.0
295 265 *
296 266 * @param string $rgba Color setting value. This could be hex or rgb.
297 - *
298 267 * @return string Hex color value.
299 268 */
300 269 private static function rgb_to_hex( $rgba ) {
301 270 if ( strpos( $rgba, '#' ) === 0 ) {
@@ -309,9 +278,8 @@
309 278 /**
310 279 * @since 6.8
311 280 *
312 281 * @param string $hsl
313 - *
314 282 * @return string|null Null if it fails to parse the HSL string.
315 283 */
316 284 private static function hsl_to_hex( $hsl ) {
317 285 // Convert hsla to hsl.
@@ -370,13 +338,10 @@
370 338 }
371 339
372 340 /**
373 341 * @since 2.3
374 - *
375 342 * @param string $hex string The original color in hex format #ffffff.
376 343 * @param int $steps integer Should be between -255 and 255. Negative = darker, positive = lighter.
377 - *
378 - * @return string
379 344 */
380 345 public static function adjust_brightness( $hex, $steps ) {
381 346 $steps = max( - 255, min( 255, $steps ) );
382 347
@@ -413,9 +378,8 @@
413 378 /**
414 379 * @since 6.0
415 380 *
416 381 * @param string $color
417 - *
418 382 * @return int
419 383 */
420 384 public static function get_color_brightness( $color ) {
421 385 if ( 0 === strpos( $color, 'rgb' ) ) {
@@ -423,14 +387,12 @@
423 387 }
424 388
425 389 if ( 0 === strpos( $color, 'hsl' ) ) {
426 390 $hsl_to_hex = self::hsl_to_hex( $color );
427 -
428 391 if ( is_null( $hsl_to_hex ) ) {
429 392 // Fallback if we cannot convert the HSL value.
430 393 return 0;
431 394 }
432 -
433 395 $color = $hsl_to_hex;
434 396 }
435 397
436 398 self::fill_hex( $color );
@@ -447,10 +409,8 @@
447 409 * Change a 3 character hex color to a 6 character one.
448 410 *
449 411 * @since 6.0
450 412 *
451 - * @param string $color Color value, passed by reference.
452 - *
453 413 * @return void
454 414 */
455 415 private static function fill_hex( &$color ) {
456 416 if ( 3 === strlen( $color ) ) {
@@ -459,12 +419,8 @@
459 419 }
460 420
461 421 /**
462 422 * @since 4.05.02
463 - *
464 - * @param array $vars CSS variable keys.
465 - *
466 - * @return array
467 423 */
468 424 public static function get_css_vars( $vars = array() ) {
469 425 $vars = apply_filters( 'frm_css_vars', $vars );
470 426 return array_unique( $vars );
@@ -471,128 +427,31 @@
471 427 }
472 428
473 429 /**
474 430 * @since 4.05.02
475 - *
476 - * @param array $settings Style settings.
477 - * @param array $defaults Default style settings.
478 - * @param array $vars CSS variable keys to output.
479 - *
480 - * @return void
481 431 */
482 432 public static function output_vars( $settings, $defaults = array(), $vars = array() ) {
483 433 if ( empty( $vars ) ) {
484 434 $vars = self::get_css_vars( array_keys( $settings ) );
485 435 }
486 -
487 - $remove = array( 'remove_box_shadow', 'remove_box_shadow_active', 'theme_css', 'theme_name', 'theme_selector', 'important_style', 'submit_style', 'collapse_icon', 'center_form', 'custom_css', 'style_class', 'submit_bg_img', 'change_margin', 'repeat_icon', 'use_base_font_size', 'field_shape_type' );
436 + $remove = array( 'remove_box_shadow', 'remove_box_shadow_active', 'theme_css', 'theme_name', 'theme_selector', 'important_style', 'submit_style', 'collapse_icon', 'center_form', 'custom_css', 'style_class', 'submit_bg_img', 'change_margin', 'repeat_icon' );
488 437 $vars = array_diff( $vars, $remove );
489 438
490 439 foreach ( $vars as $var ) {
491 - if ( ! isset( $settings[ $var ] ) || ! self::css_key_is_valid( $var ) ) {
440 + if ( ! isset( $settings[ $var ] ) ) {
492 441 continue;
493 442 }
494 -
495 443 if ( ! isset( $defaults[ $var ] ) ) {
496 444 $defaults[ $var ] = '';
497 445 }
498 -
499 - $prepared_value = '';
500 -
501 - if ( self::should_add_css_var( $settings, $defaults, $var, $prepared_value ) ) {
502 - echo '--' . esc_html( self::clean_var_name( str_replace( '_', '-', $var ) ) ) . ':' . $prepared_value . ';'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
446 + $show = empty( $defaults ) || ( $settings[ $var ] !== '' && $settings[ $var ] !== $defaults[ $var ] );
447 + if ( $show ) {
448 + echo '--' . esc_html( str_replace( '_', '-', $var ) ) . ':' . self::css_var_prepare_value( $settings, $var ) . ';'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
503 449 }
504 450 }
505 451 }
506 452
507 453 /**
508 - * Check if a CSS variable setting is not blank, doesn't match the default, and doesn't include invalid substrings.
509 - *
510 - * @since 6.24
511 - *
512 - * @param array $settings Array of setting values.
513 - * @param array $defaults Array of default values.
514 - * @param string $var The setting key name.
515 - * @param string $prepared_value The value from calling css_var_prepare_value. This is set by reference so it can be used after this function is called.
516 - *
517 - * @return bool True if the CSS value should be printed.
518 - */
519 - private static function should_add_css_var( $settings, $defaults, $var, &$prepared_value ) {
520 - $prepared_value = self::css_var_prepare_value( $settings, $var );
521 -
522 - if ( $prepared_value === '' ) {
523 - return false;
524 - }
525 -
526 - if ( $defaults && $defaults[ $var ] === $prepared_value ) {
527 - return false;
528 - }
529 -
530 - return self::css_value_is_valid( $prepared_value );
531 - }
532 -
533 - /**
534 - * Prevent invalid CSS keys from getting added to the generated CSS.
535 - *
536 - * @since 6.20
537 - *
538 - * @param string $key
539 - *
540 - * @return bool
541 - */
542 - private static function css_key_is_valid( $key ) {
543 - // Any key that is abnormally large is not valid.
544 - // Any key that contains a '{' is not valid.
545 - return strlen( $key ) < 100 && false === strpos( $key, '{' );
546 - }
547 -
548 - /**
549 - * Confirm a CSS value is valid.
550 - * If it appears to contain JavaScript, it will not be added.
551 - *
552 - * @since 6.20
553 - *
554 - * @param string $var
555 - *
556 - * @return bool
557 - */
558 - private static function css_value_is_valid( $var ) {
559 - if ( is_numeric( $var ) ) {
560 - return true;
561 - }
562 -
563 - // None of these substrings should be present in any CSS value.
564 - $invalid_substrings = array(
565 - 'function(',
566 - ';userAgent',
567 - ';stopPropagation',
568 - '{const',
569 - 'window[',
570 - 'navigator[',
571 - 'Array;',
572 - );
573 -
574 - foreach ( $invalid_substrings as $substring ) {
575 - if ( strpos( $var, $substring ) !== false ) {
576 - return false;
577 - }
578 - }
579 -
580 - return true;
581 - }
582 -
583 - /**
584 - * Remove anything that isn't used as a CSS variable name.
585 - *
586 - * @param string $var_name
587 - *
588 - * @return string
589 - */
590 - private static function clean_var_name( $var_name ) {
591 - return preg_replace( '/[^a-zA-Z0-9_-]/', '', $var_name );
592 - }
593 -
594 - /**
595 454 * Prepare the value for a CSS variable.
596 455 *
597 456 * @since 6.14
598 457 *
@@ -603,12 +462,8 @@
603 462 */
604 463 private static function css_var_prepare_value( $settings, $key ) {
605 464 $value = $settings[ $key ];
606 465
607 - if ( ! is_string( $value ) && ! is_numeric( $value ) ) {
608 - return '';
609 - }
610 -
611 466 switch ( $key ) {
612 467 case 'font':
613 468 return safecss_filter_attr( $value );
614 469
@@ -637,9 +492,9 @@
637 492 }
638 493 break;
639 494 }//end switch
640 495
641 - return esc_html( $value );
496 + return esc_html( $settings[ $key ] );
642 497 }
643 498
644 499 /**
645 500 * @since 2.3
@@ -644,20 +499,17 @@
644 499 /**
645 500 * @since 2.3
646 501 *
647 502 * @param WP_Post $style
648 - *
649 503 * @return array
650 504 */
651 505 public static function get_settings_for_output( $style ) {
652 506 if ( self::previewing_style() ) {
653 507 $frm_style = new FrmStyle();
654 -
655 508 if ( isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
656 509
657 510 // Sanitizing is done later.
658 511 $posted = wp_unslash( $_POST['frm_style_setting'] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
659 -
660 512 if ( ! is_array( $posted ) ) {
661 513 $posted = json_decode( $posted, true );
662 514 FrmAppHelper::format_form_data( $posted );
663 515 $settings = $frm_style->sanitize_post_content( $posted['frm_style_setting']['post_content'] );
@@ -675,9 +527,8 @@
675 527
676 528 FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings );
677 529
678 530 $settings['style_class'] = '';
679 -
680 531 if ( ! empty( $style_name ) ) {
681 532 $settings['style_class'] = $style_name . '.';
682 533 }
683 534 } else {
@@ -689,9 +540,8 @@
689 540 $settings['font'] = stripslashes( $settings['font'] );
690 541 $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] );
691 542
692 543 $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' );
693 -
694 544 foreach ( $checkbox_opts as $opt ) {
695 545 if ( ! isset( $settings[ $opt ] ) ) {
696 546 $settings[ $opt ] = 0;
697 547 }
@@ -716,9 +566,8 @@
716 566 *
717 567 * @since 6.14
718 568 *
719 569 * @param array $settings An array of css style.
720 - * @param array $defaults Default style settings.
721 570 *
722 571 * @return array
723 572 */
724 573 public static function update_base_font_size( $settings, $defaults ) {
@@ -724,11 +573,10 @@
724 573 public static function update_base_font_size( $settings, $defaults ) {
725 574 if ( empty( $settings['base_font_size'] ) || empty( $settings['use_base_font_size'] ) || 'false' === $settings['use_base_font_size'] ) {
726 575 return $settings;
727 576 }
728 -
729 577 $base_font_size = (int) $settings['base_font_size'];
730 - $font_size = $defaults['font_size'];
578 + $font_size = $settings['font_size'];
731 579 $font_sizes_to_update = array(
732 580 'font_size',
733 581 'field_font_size',
734 582 'check_font_size',
@@ -758,12 +606,8 @@
758 606 * Get style font size scale value.
759 607 *
760 608 * @since 6.14
761 609 *
762 - * @param string $key Setting key.
763 - * @param int|string $value Base font size value.
764 - * @param array $defaults Default style settings.
765 - *
766 610 * @return float
767 611 */
768 612 private static function get_base_font_size_scale( $key, $value, $defaults ) {
769 613 if ( empty( $defaults[ $key ] ) || ! is_numeric( (int) $defaults[ $key ] ) || ! is_numeric( (int) $value ) || 0 === (int) $value ) {
@@ -774,22 +618,15 @@
774 618 }
775 619
776 620 /**
777 621 * @since 2.3
778 - *
779 - * @param array $settings Style settings, passed by reference.
780 - * @param bool $allow_transparent Whether transparent colors are allowed.
781 - *
782 - * @return void
783 622 */
784 623 public static function prepare_color_output( &$settings, $allow_transparent = true ) {
785 624 $colors = self::allow_color_override();
786 -
787 625 foreach ( $colors as $css => $opts ) {
788 626 if ( $css === 'transparent' && ! $allow_transparent ) {
789 627 $css = '';
790 628 }
791 -
792 629 foreach ( $opts as $opt ) {
793 630 self::get_color_output( $css, $settings[ $opt ] );
794 631 }
795 632 }
@@ -829,17 +666,11 @@
829 666 }
830 667
831 668 /**
832 669 * @since 2.3
833 - *
834 - * @param string $default Default color value.
835 - * @param string $color Color value, passed by reference.
836 - *
837 - * @return void
838 670 */
839 671 private static function get_color_output( $default, &$color ) {
840 672 $color = trim( $color );
841 -
842 673 if ( empty( $color ) ) {
843 674 $color = $default;
844 675 } elseif ( false !== strpos( $color, 'rgb(' ) ) {
845 676 $color = str_replace( 'rgb(', 'rgba(', $color );
@@ -855,9 +686,8 @@
855 686 *
856 687 * @since 6.8
857 688 *
858 689 * @param string $color
859 - *
860 690 * @return bool
861 691 */
862 692 private static function is_hex( $color ) {
863 693 $non_hex_substrings = array(
@@ -880,17 +710,12 @@
880 710 * If left/right label is over a certain size,
881 711 * adjust the field description margin at a different screen size
882 712 *
883 713 * @since 2.3
884 - *
885 - * @param string $width Label width value.
886 - *
887 - * @return false|string
888 714 */
889 715 private static function description_margin_for_screensize( $width ) {
890 716 $temp_label_width = str_replace( 'px', '', $width );
891 717 $change_margin = false;
892 -
893 718 if ( $temp_label_width >= 230 ) {
894 719 $change_margin = '800px';
895 720 } elseif ( $width >= 215 ) {
896 721 $change_margin = '700px';
@@ -917,9 +742,8 @@
917 742 *
918 743 * @since 6.0
919 744 *
920 745 * @param int|string $form_id
921 - *
922 746 * @return string
923 747 */
924 748 public static function get_list_url( $form_id ) {
925 749 return admin_url( 'admin.php?page=formidable-styles&form=' . absint( $form_id ) );
@@ -931,9 +755,8 @@
931 755 * @since 6.14
932 756 *
933 757 * @param stdClass|WP_Post $style
934 758 * @param int $form_id
935 - *
936 759 * @return array
937 760 */
938 761 public static function get_style_options_back_button_args( $style, $form_id ) {
939 762 if ( self::is_advanced_settings() ) {
@@ -980,9 +803,8 @@
980 803 * @since 6.0
981 804 *
982 805 * @param int|string $style_id
983 806 * @param bool $is_default
984 - *
985 807 * @return int
986 808 */
987 809 public static function get_form_count_for_style( $style_id, $is_default ) {
988 810 $serialized = serialize( array( 'custom_style' => (string) $style_id ) );
@@ -1013,9 +835,8 @@
1013 835 * @since 6.0
1014 836 *
1015 837 * @param int|string $style_id
1016 838 * @param mixed $conversational_style_id
1017 - *
1018 839 * @return int
1019 840 */
1020 841 private static function get_default_style_count( $style_id, $conversational_style_id ) {
1021 842 $substrings = array_map(
@@ -1082,18 +903,15 @@
1082 903 *
1083 904 * @since 6.14
1084 905 *
1085 906 * @param array $settings
1086 - *
1087 907 * @return false|string Return image url or false.
1088 908 */
1089 909 public static function get_submit_image_bg_url( $settings ) {
1090 910 $background_image = $settings['submit_bg_img'];
1091 -
1092 911 if ( empty( $background_image ) ) {
1093 912 return false;
1094 913 }
1095 -
1096 914 // Handle the case where the submit_bg_img is a full URL string. If the settings were saved with the older styler version prior to 6.14, the submit_bg_img will be a full URL string.
1097 915 if ( ! is_numeric( $background_image ) ) {
1098 916 return $background_image;
1099 917 }
@@ -1099,9 +917,8 @@
1099 917 }
1100 918
1101 919 return wp_get_attachment_url( (int) $background_image );
1102 920 }
1103 -
1104 921 /**
1105 922 * Determines if the chosen JavaScript library should be used.
1106 923 *
1107 924 * @since 6.13
@@ -1115,28 +932,6 @@
1115 932
1116 933 return is_callable( 'FrmProAppHelper::use_chosen_js' )
1117 934 ? FrmProAppHelper::use_chosen_js()
1118 935 : true;
1119 - }
1120 -
1121 - /**
1122 - * Returns the bottom part from a margin/padding value.
1123 - *
1124 - * @since 6.17
1125 - *
1126 - * @param string $value The margin/padding value.
1127 - *
1128 - * @return string
1129 - */
1130 - public static function get_bottom_value( $value ) {
1131 - if ( ! $value ) {
1132 - return $value;
1133 - }
1134 -
1135 - $parts = explode( ' ', $value );
1136 -
1137 - if ( count( $parts ) < 3 ) {
1138 - return $parts[0];
1139 - }
1140 - return $parts[2];
1141 936 }
1142 937 }