PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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 +42 -221 6.35.4 View file →
@@ -13,11 +13,8 @@
13 13 public function __construct( $id = 0 ) {
14 14 $this->id = $id;
15 15 }
16 16
17 - /**
18 - * @return stdClass
19 - */
20 17 public function get_new() {
21 18 $this->id = 0;
22 19
23 20 $max_slug_value = 2147483647;
@@ -36,33 +33,20 @@
36 33
37 34 return (object) $style;
38 35 }
39 36
40 - /**
41 - * @param array $settings
42 - * @return int|WP_Error
43 - */
44 37 public function save( $settings ) {
45 38 return FrmDb::save_settings( $settings, 'frm_styles' );
46 39 }
47 40
48 - /**
49 - * @return void
50 - */
51 41 public function duplicate( $id ) {
52 - // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead.
42 + // duplicating is a pro feature
53 43 }
54 44
55 - /**
56 - * Handle save actions in the visual styler edit page.
57 - *
58 - * @param mixed $id
59 - * @return array<int|WP_Error>
60 - */
61 45 public function update( $id = 'default' ) {
62 46 $all_instances = $this->get_all();
63 47
64 - if ( ! $id ) {
48 + if ( empty( $id ) ) {
65 49 $new_style = (array) $this->get_new();
66 50 $all_instances[] = $new_style;
67 51 }
68 52
@@ -70,33 +54,30 @@
70 54
71 55 foreach ( $all_instances as $number => $new_instance ) {
72 56 $new_instance = (array) $new_instance;
73 57 $this->id = $new_instance['ID'];
58 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
59 + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
60 + $all_instances[ $number ] = $new_instance;
74 61
75 - if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
76 - // Don't continue if not saving this style.
62 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
63 + if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) {
64 + // this style was set to default, so remove default setting on previous default style
65 + $new_instance['menu_order'] = 0;
66 + $action_ids[] = $this->save( $new_instance );
67 + }
68 +
69 + // don't continue if not saving this style
77 70 continue;
78 71 }
79 72
80 - // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing.
81 - // Preserve the previous value in case Custom CSS has not been saved as a Global Setting yet.
82 - $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : '';
83 -
84 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
85 - if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) {
86 - // The nonce check happens in FrmStylesController::save_style before this is called.
87 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
88 - $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) );
89 - }
90 -
91 - $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
92 - $new_instance['post_content']['custom_css'] = $custom_css;
93 - unset( $custom_css );
94 -
73 + $new_instance['post_title'] = isset( $_POST['frm_style_setting']['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
74 + $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $this->sanitize_post_content( $this->unslash_post_content( $_POST['frm_style_setting']['post_content'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
95 75 $new_instance['post_type'] = FrmStylesController::$post_type;
96 76 $new_instance['post_status'] = 'publish';
77 + $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing
97 78
98 - if ( ! $id ) {
79 + if ( empty( $id ) ) {
99 80 $new_instance['post_name'] = $new_instance['post_title'];
100 81 }
101 82
102 83 $default_settings = $this->get_defaults();
@@ -107,21 +88,26 @@
107 88 }
108 89
109 90 if ( $this->is_color( $setting ) ) {
110 91 $color_val = $new_instance['post_content'][ $setting ];
111 - if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) {
112 - // Maybe sanitize if invalid rgba value is entered.
92 + if ( $color_val !== '' && 0 === strpos( $color_val, 'rgb' ) ) {
93 + // maybe sanitize if invalid rgba value is entered
113 94 $this->maybe_sanitize_rgba_value( $color_val );
114 95 }
115 96 $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val );
116 - } elseif ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ), true ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
97 + } elseif ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) )
98 + && ! isset( $new_instance['post_content'][ $setting ] )
99 + ) {
117 100 $new_instance['post_content'][ $setting ] = 0;
118 - } elseif ( $setting === 'font' ) {
101 + } elseif ( $setting == 'font' ) {
119 102 $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
120 103 }
121 104 }
122 105
106 + $all_instances[ $number ] = $new_instance;
107 +
123 108 $action_ids[] = $this->save( $new_instance );
109 +
124 110 }
125 111
126 112 $this->save_settings();
127 113
@@ -141,9 +127,8 @@
141 127 return;
142 128 }
143 129
144 130 $color_val = trim( $color_val );
145 - $color_val = ltrim( $color_val, '(' ); // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces.
146 131 $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' );
147 132 foreach ( $patterns as $pattern ) {
148 133 if ( preg_match( $pattern, $color_val ) === 1 ) {
149 134 return;
@@ -149,14 +134,13 @@
149 134 return;
150 135 }
151 136 }
152 137
153 - // Remove all leading ')' braces, then add one back. This way there's always a single brace.
154 - $color_val = rtrim( $color_val, ')' );
155 - $color_val .= ')';
138 + if ( substr( $color_val, -1 ) !== ')' ) {
139 + $color_val .= ')';
140 + }
156 141
157 142 $color_rgba = substr( $color_val, strpos( $color_val, '(' ) + 1, strlen( $color_val ) - strpos( $color_val, '(' ) - 2 );
158 - $color_rgba = trim( $color_rgba, '()' ); // Remove any excessive braces from the rgba like rgba((.
159 143 $length_of_color_codes = strpos( $color_val, '(' );
160 144 $new_color_values = array();
161 145
162 146 // replace empty values by 0 or 1 (if alpha position).
@@ -164,9 +148,9 @@
164 148 $new_value = null;
165 149 $value_is_empty_string = '' === trim( $value ) || '' === $value;
166 150
167 151 if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) {
168 - // Insert a value for r, g, or b.
152 + // insert a value for r, g, or b
169 153 if ( $value < 0 ) {
170 154 $new_value = 0;
171 155 } elseif ( $value > 255 ) {
172 156 $new_value = 255;
@@ -171,19 +155,15 @@
171 155 } elseif ( $value > 255 ) {
172 156 $new_value = 255;
173 157 } elseif ( $value_is_empty_string ) {
174 158 $new_value = 0;
175 - } else {
176 - $new_value = absint( $value );
177 159 }
178 160 } else {
179 - // Insert a value for alpha.
161 + // insert a value for alpha
180 162 if ( $value_is_empty_string ) {
181 163 $new_value = 4 === $length_of_color_codes ? 1 : 0;
182 164 } elseif ( $value > 1 || $value < 0 ) {
183 165 $new_value = 1;
184 - } else {
185 - $new_value = floatval( $value );
186 166 }
187 167 }
188 168
189 169 $new_color_values[] = null === $new_value ? $value : $new_value;
@@ -203,9 +183,8 @@
203 183 }
204 184
205 185 $new_color = implode( ',', $new_color_values );
206 186 $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 );
207 - $prefix = rtrim( $prefix, '(' ) . '('; // Limit the number of opening braces after rgb/rgba. There should only be one.
208 187 $new_color = $prefix . $new_color . ')';
209 188
210 189 $color_val = $new_color;
211 190 }
@@ -240,126 +219,23 @@
240 219 $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] );
241 220 } else {
242 221 $sanitized_settings[ $key ] = $defaults[ $key ];
243 222 }
244 -
245 - if ( 'custom_css' !== $key ) {
246 - $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] );
247 - }
248 223 }
249 224 return $sanitized_settings;
250 225 }
251 226
252 227 /**
253 - * Remove any characters that should not be used in CSS.
254 - *
255 - * @since 6.2.3
256 - *
257 - * @param string $setting
258 - * @return string
259 - */
260 - private function strip_invalid_characters( $setting ) {
261 - $characters_to_remove = array( '{', '}', ';', '[', ']' );
262 -
263 - // RGB is handled instead in self::maybe_sanitize_rgba_value.
264 - if ( 0 !== strpos( $setting, 'rgb' ) ) {
265 - $setting = $this->maybe_fix_braces( $setting, $characters_to_remove );
266 - }
267 -
268 - return str_replace( $characters_to_remove, '', $setting );
269 - }
270 -
271 - /**
272 - * @since 6.2.3
273 - *
274 - * @param string $setting
275 - * @param array $characters_to_remove
276 - * @return string
277 - */
278 - private function maybe_fix_braces( $setting, &$characters_to_remove ) {
279 - $number_of_opening_braces = substr_count( $setting, '(' );
280 - $number_of_closing_braces = substr_count( $setting, ')' );
281 -
282 - if ( $number_of_opening_braces === $number_of_closing_braces ) {
283 - return $this->trim_braces( $setting );
284 - }
285 -
286 - if ( $this->should_remove_every_brace( $setting ) ) {
287 - // Add to $characters_to_remove to remove when str_replace is called.
288 - array_push( $characters_to_remove, '(', ')' );
289 - return $setting;
290 - }
291 -
292 - return $this->trim_braces( $setting );
293 - }
294 -
295 - /**
296 - * @since 6.2.3
297 - *
298 - * @param string $input
299 - * @return string
300 - */
301 - private function trim_braces( $input ) {
302 - $output = $input;
303 - // Remove any ( from the start of the string as no CSS values expect at the first character.
304 - if ( $output ) {
305 - if ( in_array( $output[0], array( '(', ')' ), true ) ) {
306 - $output = ltrim( $output, '()' );
307 - }
308 - }
309 - // Remove extra braces from the end.
310 - if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) {
311 - $output = rtrim( $output, '()' );
312 - if ( false !== strpos( $output, '(' ) ) {
313 - $output .= ')';
314 - }
315 - }
316 - return $output;
317 - }
318 -
319 - /**
320 - * @since 6.2.3
321 - *
322 - * @param string $setting
323 - * @return bool
324 - */
325 - private function should_remove_every_brace( $setting ) {
326 - if ( 0 === strpos( trim( $setting, '()' ), 'calc' ) ) {
327 - // Support calc() sizes. We do not want to remove all braces when calc is used.
328 - return false;
329 - }
330 -
331 - // Matches hex values but also checks for unexpected ( and ).
332 - $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting );
333 - if ( $looks_like_a_hex_value ) {
334 - return true;
335 - }
336 -
337 - // Matches size values but also checks for unexpected ( and ).
338 - // This is case insensitive so it will catch PX, PT, etc, as well.
339 - $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting );
340 - if ( $looks_like_a_size ) {
341 - return true;
342 - }
343 -
344 - return false;
345 - }
346 -
347 - /**
348 228 * @since 3.01.01
349 - *
350 - * @param string $setting
351 - * @return bool
352 229 */
353 230 private function is_color( $setting ) {
354 231 $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
355 - return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors, true );
232 +
233 + return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors );
356 234 }
357 235
358 236 /**
359 237 * @since 3.01.01
360 - *
361 - * @return array
362 238 */
363 239 public function get_color_settings() {
364 240 $defaults = $this->get_defaults();
365 241 $settings = array_keys( $defaults );
@@ -367,11 +243,9 @@
367 243 return array_filter( $settings, array( $this, 'is_color' ) );
368 244 }
369 245
370 246 /**
371 - * Create static CSS file and update the CSS transient alternative.
372 - *
373 - * @return void
247 + * Create static css file
374 248 */
375 249 public function save_settings() {
376 250 $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
377 251 update_option( 'frm_last_style_update', gmdate( 'njGi' ) );
@@ -381,9 +255,10 @@
381 255 }
382 256
383 257 $this->clear_cache();
384 258
385 - $css = $this->get_css_content( $filename );
259 + $css = $this->get_css_content( $filename );
260 +
386 261 $create_file = new FrmCreateFile(
387 262 array(
388 263 'file_name' => FrmStylesController::get_file_name(),
389 264 'new_file_path' => FrmAppHelper::plugin_path() . '/css',
@@ -394,12 +269,8 @@
394 269 update_option( 'frmpro_css', $css, 'no' );
395 270 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
396 271 }
397 272
398 - /**
399 - * @param string $filename
400 - * @return string
401 - */
402 273 private function get_css_content( $filename ) {
403 274 $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
404 275
405 276 $saving = true;
@@ -405,9 +276,9 @@
405 276 $saving = true;
406 277 $frm_style = $this;
407 278
408 279 ob_start();
409 - include $filename;
280 + include( $filename );
410 281 $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
411 282 ob_end_clean();
412 283
413 284 return FrmStylesController::replace_relative_url( $css );
@@ -412,11 +283,8 @@
412 283
413 284 return FrmStylesController::replace_relative_url( $css );
414 285 }
415 286
416 - /**
417 - * @return void
418 - */
419 287 private function clear_cache() {
420 288 $default_post_atts = array(
421 289 'post_type' => FrmStylesController::$post_type,
422 290 'post_status' => 'publish',
@@ -429,26 +297,14 @@
429 297 FrmDb::cache_delete_group( 'frm_styles' );
430 298 FrmDb::delete_cache_and_transient( 'frmpro_css' );
431 299 }
432 300
433 - /**
434 - * Delete a style by its post ID.
435 - *
436 - * @param int $id
437 - * @return WP_Post|false|null
438 - */
439 301 public function destroy( $id ) {
440 - if ( $id === $this->get_default_style()->ID ) {
441 - return false;
442 - }
443 302 return wp_delete_post( $id );
444 303 }
445 304
446 - /**
447 - * @return WP_Post|stdClass
448 - */
449 305 public function get_one() {
450 - if ( 'default' === $this->id ) {
306 + if ( 'default' == $this->id ) {
451 307 $style = $this->get_default_style();
452 308 if ( $style ) {
453 309 $this->id = $style->ID;
454 310 } else {
@@ -474,14 +330,8 @@
474 330
475 331 return $style;
476 332 }
477 333
478 - /**
479 - * @param string $orderby
480 - * @param string $order
481 - * @param int $limit
482 - * @return array
483 - */
484 334 public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
485 335 $post_atts = array(
486 336 'post_type' => FrmStylesController::$post_type,
487 337 'post_status' => 'publish',
@@ -546,11 +396,8 @@
546 396
547 397 return $styles;
548 398 }
549 399
550 - /**
551 - * @param array|null $styles
552 - */
553 400 public function get_default_style( $styles = null ) {
554 401 if ( ! isset( $styles ) ) {
555 402 $styles = $this->get_all( 'menu_order', 'DESC', 1 );
556 403 }
@@ -561,12 +408,8 @@
561 408 }
562 409 }
563 410 }
564 411
565 - /**
566 - * @param mixed $settings
567 - * @return mixed
568 - */
569 412 public function override_defaults( $settings ) {
570 413 if ( ! is_array( $settings ) ) {
571 414 return $settings;
572 415 }
@@ -596,11 +439,8 @@
596 439
597 440 return apply_filters( 'frm_override_default_styles', $settings );
598 441 }
599 442
600 - /**
601 - * @return array
602 - */
603 443 public function get_defaults() {
604 444 $defaults = array(
605 445 'theme_css' => 'ui-lightness',
606 446 'theme_name' => 'UI Lightness',
@@ -732,9 +572,9 @@
732 572 'progress_active_bg_color' => '579AF6',
733 573 'progress_color' => '3f4b5b',
734 574 'progress_border_color' => 'E5E5E5',
735 575 'progress_border_size' => '2px',
736 - 'progress_size' => '24px',
576 + 'progress_size' => '30px',
737 577
738 578 'custom_css' => '',
739 579 );
740 580
@@ -740,22 +580,12 @@
740 580
741 581 return apply_filters( 'frm_default_style_settings', $defaults );
742 582 }
743 583
744 - /**
745 - * Get a name attribute value for a style setting input.
746 - *
747 - * @param string $field_name
748 - * @param string $post_field
749 - * @return string
750 - */
751 584 public function get_field_name( $field_name, $post_field = 'post_content' ) {
752 585 return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
753 586 }
754 587
755 - /**
756 - * @return array
757 - */
758 588 public static function get_bold_options() {
759 589 return array(
760 590 100 => 100,
761 591 200 => 200,
@@ -769,12 +599,9 @@
769 599 );
770 600 }
771 601
772 602 /**
773 - * Don't let imbalanced font families ruin the whole stylesheet.
774 - *
775 - * @param string $value
776 - * @return string
603 + * Don't let imbalanced font families ruin the whole stylesheet
777 604 */
778 605 public function force_balanced_quotation( $value ) {
779 606 $balanced_characters = array( '"', "'" );
780 607 foreach ( $balanced_characters as $char ) {
@@ -779,18 +606,12 @@
779 606 $balanced_characters = array( '"', "'" );
780 607 foreach ( $balanced_characters as $char ) {
781 608 $char_count = substr_count( $value, $char );
782 609 $is_balanced = $char_count % 2 == 0;
783 -
784 - if ( $is_balanced ) {
785 - continue;
786 - }
787 -
788 - if ( $value && $char === $value[ strlen( $value ) - 1 ] ) {
789 - $value = $char . $value;
790 - } else {
610 + if ( ! $is_balanced ) {
791 611 $value .= $char;
792 612 }
793 613 }
614 +
794 615 return $value;
795 616 }
796 617 }