PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24
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/models/FrmStyle.php +7 -52 6.266.24 View file →
@@ -8,9 +8,8 @@
8 8 /**
9 9 * The meta name of default template style.
10 10 *
11 11 * @since 6.14
12 - *
13 12 * @var string
14 13 */
15 14 private $default_template_style_meta_name = 'frm_style_default';
16 15
@@ -43,9 +42,9 @@
43 42
44 43 $max_slug_value = 2147483647;
45 44 // We want to have at least 2 characters in the slug.
46 45 $min_slug_value = 37;
47 - $key = base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 );
46 + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
48 47
49 48 $style = array(
50 49 'post_type' => FrmStylesController::$post_type,
51 50 'ID' => '',
@@ -60,9 +59,8 @@
60 59 }
61 60
62 61 /**
63 62 * @param array $settings
64 - *
65 63 * @return int|WP_Error
66 64 */
67 65 public function save( $settings ) {
68 66 return FrmDb::save_settings( $settings, 'frm_styles' );
@@ -68,10 +66,8 @@
68 66 return FrmDb::save_settings( $settings, 'frm_styles' );
69 67 }
70 68
71 69 /**
72 - * @param int|string $id The id of the stylesheet or 'default'.
73 - *
74 70 * @return void
75 71 */
76 72 public function duplicate( $id ) {
77 73 // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead.
@@ -80,14 +76,12 @@
80 76 /**
81 77 * Handle save actions in the visual styler edit page.
82 78 *
83 79 * @param mixed $id
84 - *
85 80 * @return array<int|WP_Error>
86 81 */
87 82 public function update( $id = 'default' ) {
88 - $all_instances = $this->get_all();
89 - $css_scope_helper = new FrmCssScopeHelper();
83 + $all_instances = $this->get_all();
90 84
91 85 if ( ! $id ) {
92 86 $new_style = (array) $this->get_new();
93 87 $all_instances[] = $new_style;
@@ -105,9 +99,9 @@
105 99 }
106 100
107 101 // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing.
108 102 // Preserve the previous value in case Custom CSS has not been saved as a Global Setting yet.
109 - $custom_css = $new_instance['post_content']['custom_css'] ?? '';
103 + $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : '';
110 104
111 105 // phpcs:ignore WordPress.Security.NonceVerification.Missing
112 106 if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) {
113 107 // The nonce check happens in FrmStylesController::save_style before this is called.
@@ -118,13 +112,8 @@
118 112 $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $this->sanitize_post_content( wp_unslash( $_POST['frm_style_setting']['post_content'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
119 113 $new_instance['post_content']['custom_css'] = $custom_css;
120 114 unset( $custom_css );
121 115
122 - if ( ! empty( $new_instance['post_content']['single_style_custom_css'] ) ) {
123 - $css_scope = 'frm_style_' . $new_instance['post_name'];
124 - $new_instance['post_content']['single_style_custom_css'] = $css_scope_helper->nest( $new_instance['post_content']['single_style_custom_css'], $css_scope );
125 - }
126 -
127 116 $new_instance['post_type'] = FrmStylesController::$post_type;
128 117 $new_instance['post_status'] = 'publish';
129 118
130 119 if ( ! $id ) {
@@ -139,9 +128,8 @@
139 128 }
140 129
141 130 if ( $this->is_color( $setting ) ) {
142 131 $color_val = $new_instance['post_content'][ $setting ];
143 -
144 132 if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) {
145 133 // Maybe sanitize if invalid rgba value is entered.
146 134 $this->maybe_sanitize_rgba_value( $color_val );
147 135 }
@@ -168,9 +156,8 @@
168 156 *
169 157 * @since 5.3.2
170 158 *
171 159 * @param string $color_val The color value, by reference.
172 - *
173 160 * @return void
174 161 */
175 162 private function maybe_sanitize_rgba_value( &$color_val ) {
176 163 if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) {
@@ -180,9 +167,8 @@
180 167 $color_val = trim( $color_val );
181 168 // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces.
182 169 $color_val = ltrim( $color_val, '(' );
183 170 $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' );
184 -
185 171 foreach ( $patterns as $pattern ) {
186 172 if ( preg_match( $pattern, $color_val ) === 1 ) {
187 173 return;
188 174 }
@@ -224,14 +210,13 @@
224 210 $new_value = floatval( $value );
225 211 }
226 212 }//end if
227 213
228 - $new_color_values[] = $new_value;
214 + $new_color_values[] = null === $new_value ? $value : $new_value;
229 215 }//end foreach
230 216
231 217 // add more 0s and 1 (if alpha position) if needed.
232 218 $missing_values = $length_of_color_codes - count( $new_color_values );
233 -
234 219 if ( $missing_values > 1 ) {
235 220 $insert_values = array_fill( 0, $missing_values - 1, 0 );
236 221 $last_value = 4 === $length_of_color_codes ? 1 : 0;
237 222 array_push( $insert_values, $last_value );
@@ -237,9 +222,8 @@
237 222 array_push( $insert_values, $last_value );
238 223 } elseif ( $missing_values === 1 ) {
239 224 $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 );
240 225 }
241 -
242 226 if ( ! empty( $insert_values ) ) {
243 227 $new_color_values = array_merge( $new_color_values, $insert_values );
244 228 }
245 229
@@ -255,9 +239,8 @@
255 239 /**
256 240 * @since 5.0.13
257 241 *
258 242 * @param array $settings
259 - *
260 243 * @return array
261 244 */
262 245 public function sanitize_post_content( $settings ) {
263 246 $defaults = $this->get_defaults();
@@ -262,9 +245,8 @@
262 245 public function sanitize_post_content( $settings ) {
263 246 $defaults = $this->get_defaults();
264 247 $valid_keys = array_keys( $defaults );
265 248 $sanitized_settings = array();
266 -
267 249 foreach ( $valid_keys as $key ) {
268 250 if ( isset( $settings[ $key ] ) ) {
269 251 $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] );
270 252 } else {
@@ -270,9 +252,9 @@
270 252 } else {
271 253 $sanitized_settings[ $key ] = $defaults[ $key ];
272 254 }
273 255
274 - if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) {
256 + if ( 'custom_css' !== $key ) {
275 257 $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] );
276 258 }
277 259 }
278 260 return $sanitized_settings;
@@ -283,9 +265,8 @@
283 265 *
284 266 * @since 6.2.3
285 267 *
286 268 * @param string $setting
287 - *
288 269 * @return string
289 270 */
290 271 private function strip_invalid_characters( $setting ) {
291 272 $characters_to_remove = array( '{', '}', ';', '[', ']' );
@@ -302,9 +283,8 @@
302 283 * @since 6.2.3
303 284 *
304 285 * @param string $setting
305 286 * @param array $characters_to_remove
306 - *
307 287 * @return string
308 288 */
309 289 private function maybe_fix_braces( $setting, &$characters_to_remove ) {
310 290 $number_of_opening_braces = substr_count( $setting, '(' );
@@ -326,23 +306,19 @@
326 306 /**
327 307 * @since 6.2.3
328 308 *
329 309 * @param string $input
330 - *
331 310 * @return string
332 311 */
333 312 private function trim_braces( $input ) {
334 313 $output = $input;
335 -
336 314 // Remove any ( from the start of the string as no CSS values expect at the first character.
337 315 if ( $output && in_array( $output[0], array( '(', ')' ), true ) ) {
338 316 $output = ltrim( $output, '()' );
339 317 }
340 -
341 318 // Remove extra braces from the end.
342 319 if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) {
343 320 $output = rtrim( $output, '()' );
344 -
345 321 if ( false !== strpos( $output, '(' ) ) {
346 322 $output .= ')';
347 323 }
348 324 }
@@ -352,9 +328,8 @@
352 328 /**
353 329 * @since 6.2.3
354 330 *
355 331 * @param string $setting
356 - *
357 332 * @return bool
358 333 */
359 334 private function should_remove_every_brace( $setting ) {
360 335 if ( 0 === strpos( trim( $setting, '()' ), 'calc' ) ) {
@@ -363,9 +338,8 @@
363 338 }
364 339
365 340 // Matches hex values but also checks for unexpected ( and ).
366 341 $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting );
367 -
368 342 if ( $looks_like_a_hex_value ) {
369 343 return true;
370 344 }
371 345
@@ -371,9 +345,8 @@
371 345
372 346 // Matches size values but also checks for unexpected ( and ).
373 347 // This is case insensitive so it will catch PX, PT, etc, as well.
374 348 $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting );
375 -
376 349 if ( $looks_like_a_size ) {
377 350 return true;
378 351 }
379 352
@@ -383,9 +356,8 @@
383 356 /**
384 357 * @since 3.01.01
385 358 *
386 359 * @param string $setting
387 - *
388 360 * @return bool
389 361 */
390 362 private function is_color( $setting ) {
391 363 $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
@@ -433,9 +405,8 @@
433 405 }
434 406
435 407 /**
436 408 * @param string $filename
437 - *
438 409 * @return string
439 410 */
440 411 private function get_css_content( $filename ) {
441 412 $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
@@ -471,9 +442,8 @@
471 442 /**
472 443 * Delete a style by its post ID.
473 444 *
474 445 * @param int $id
475 - *
476 446 * @return false|WP_Post|null
477 447 */
478 448 public function destroy( $id ) {
479 449 if ( $id === $this->get_default_style()->ID ) {
@@ -487,9 +457,8 @@
487 457 */
488 458 public function get_one() {
489 459 if ( 'default' === $this->id ) {
490 460 $style = $this->get_default_style();
491 -
492 461 if ( $style ) {
493 462 $this->id = $style->ID;
494 463 } else {
495 464 $this->id = 0;
@@ -518,9 +487,8 @@
518 487 /**
519 488 * @param string $orderby
520 489 * @param string $order
521 490 * @param int $limit
522 - *
523 491 * @return array
524 492 */
525 493 public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
526 494 $post_atts = array(
@@ -557,12 +525,10 @@
557 525 $default_values = $this->get_defaults();
558 526 $default_style = false;
559 527
560 528 $styles = array();
561 -
562 529 foreach ( $temp_styles as $style ) {
563 530 $this->id = $style->ID;
564 -
565 531 if ( $style->menu_order ) {
566 532 if ( $default_style ) {
567 533 // only return one default
568 534 $style->menu_order = 0;
@@ -578,9 +544,9 @@
578 544 $style->post_content = $this->override_defaults( $style->post_content );
579 545 $style->post_content = wp_parse_args( $style->post_content, $default_values );
580 546
581 547 $styles[ $style->ID ] = $style;
582 - }//end foreach
548 + }
583 549
584 550 if ( ! $default_style ) {
585 551 $default_style = reset( $styles );
586 552
@@ -591,10 +557,8 @@
591 557 }
592 558
593 559 /**
594 560 * @param array|null $styles
595 - *
596 - * @return object|null
597 561 */
598 562 public function get_default_style( $styles = null ) {
599 563 if ( ! isset( $styles ) ) {
600 564 $styles = $this->get_all( 'menu_order', 'DESC', 1 );
@@ -608,9 +572,8 @@
608 572 }
609 573
610 574 /**
611 575 * @param mixed $settings
612 - *
613 576 * @return mixed
614 577 */
615 578 public function override_defaults( $settings ) {
616 579 if ( ! is_array( $settings ) ) {
@@ -783,11 +746,8 @@
783 746 'custom_css' => '',
784 747 'use_base_font_size' => false,
785 748 'base_font_size' => '15px',
786 749 'field_shape_type' => 'rounded-corner',
787 -
788 - 'enable_style_custom_css' => false,
789 - 'single_style_custom_css' => '',
790 750 );
791 751
792 752 return apply_filters( 'frm_default_style_settings', $defaults );
793 753 }
@@ -796,9 +756,8 @@
796 756 * Get a name attribute value for a style setting input.
797 757 *
798 758 * @param string $field_name
799 759 * @param string $post_field
800 - *
801 760 * @return string
802 761 */
803 762 public function get_field_name( $field_name, $post_field = 'post_content' ) {
804 763 return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
@@ -824,14 +783,12 @@
824 783 /**
825 784 * Don't let imbalanced font families ruin the whole stylesheet.
826 785 *
827 786 * @param string $value
828 - *
829 787 * @return string
830 788 */
831 789 public function force_balanced_quotation( $value ) {
832 790 $balanced_characters = array( '"', "'" );
833 -
834 791 foreach ( $balanced_characters as $char ) {
835 792 $char_count = substr_count( $value, $char );
836 793 $is_balanced = $char_count % 2 == 0;
837 794
@@ -851,16 +808,14 @@
851 808 /**
852 809 * Get the default template style
853 810 *
854 811 * @since 6.14
812 + * @param int $style_id The post type "frm_styles" ID.
855 813 *
856 - * @param int|string $style_id The post type "frm_styles" ID.
857 - *
858 814 * @return string The json encoded template data
859 815 */
860 816 public function get_default_template_style( $style_id ) {
861 817 $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true );
862 -
863 818 if ( empty( $default_template ) ) {
864 819 return FrmAppHelper::prepare_and_encode( $this->get_defaults() );
865 820 }
866 821 return $default_template;