PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 +193 -547 6.295.0 View file →
@@ -3,49 +3,24 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmStyle {
7 + public $number = false; // Unique ID number of the current instance.
8 + public $id = 0; // the id of the post
7 9
8 10 /**
9 - * The meta name of default template style.
10 - *
11 - * @since 6.14
12 - *
13 - * @var string
11 + * @param int|string $id The id of the stylsheet or 'default'
14 12 */
15 - private $default_template_style_meta_name = 'frm_style_default';
16 -
17 - /**
18 - * Unique ID number of the current instance.
19 - *
20 - * @var int
21 - */
22 - public $number = false;
23 -
24 - /**
25 - * The id of the post.
26 - *
27 - * @var int|string
28 - */
29 - public $id = 0;
30 -
31 - /**
32 - * @param int|string $id The id of the stylesheet or 'default'.
33 - */
34 13 public function __construct( $id = 0 ) {
35 14 $this->id = $id;
36 15 }
37 16
38 - /**
39 - * @return stdClass
40 - */
41 17 public function get_new() {
42 18 $this->id = 0;
43 19
44 20 $max_slug_value = 2147483647;
45 - // We want to have at least 2 characters in the slug.
46 - $min_slug_value = 37;
47 - $key = base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 );
21 + $min_slug_value = 37; // we want to have at least 2 characters in the slug
22 + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
48 23
49 24 $style = array(
50 25 'post_type' => FrmStylesController::$post_type,
51 26 'ID' => '',
@@ -58,77 +33,52 @@
58 33
59 34 return (object) $style;
60 35 }
61 36
62 - /**
63 - * @param array $settings
64 - *
65 - * @return int|WP_Error
66 - */
67 37 public function save( $settings ) {
68 38 return FrmDb::save_settings( $settings, 'frm_styles' );
69 39 }
70 40
71 - /**
72 - * @param int|string $id The id of the stylesheet or 'default'.
73 - *
74 - * @return void
75 - */
76 41 public function duplicate( $id ) {
77 - // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead.
42 + // duplicating is a pro feature
78 43 }
79 44
80 - /**
81 - * Handle save actions in the visual styler edit page.
82 - *
83 - * @param mixed $id
84 - *
85 - * @return array<int|WP_Error>
86 - */
87 45 public function update( $id = 'default' ) {
88 - $all_instances = $this->get_all();
89 - $css_scope_helper = new FrmCssScopeHelper();
46 + $all_instances = $this->get_all();
90 47
91 - if ( ! $id ) {
92 - $all_instances[] = (array) $this->get_new();
48 + if ( empty( $id ) ) {
49 + $new_style = (array) $this->get_new();
50 + $all_instances[] = $new_style;
93 51 }
94 52
95 53 $action_ids = array();
96 54
97 - foreach ( $all_instances as $new_instance ) {
55 + foreach ( $all_instances as $number => $new_instance ) {
98 56 $new_instance = (array) $new_instance;
99 57 $this->id = $new_instance['ID'];
100 -
101 - // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
102 58 if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
103 - // Don't continue if not saving this style.
104 - continue;
105 - }
59 + $all_instances[ $number ] = $new_instance;
106 60
107 - // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing.
108 - // 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'] ?? '';
61 + if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) {
62 + // this style was set to default, so remove default setting on previous default style
63 + $new_instance['menu_order'] = 0;
64 + $action_ids[] = $this->save( $new_instance );
65 + }
110 66
111 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
112 - if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) {
113 - // The nonce check happens in FrmStylesController::save_style before this is called.
114 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
115 - $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) );
67 + // don't continue if not saving this style
68 + continue;
116 69 }
117 70
118 - $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, SlevomatCodingStandard.Files.LineLength.LineTooLong
119 - $new_instance['post_content']['custom_css'] = $custom_css;
120 - unset( $custom_css );
71 + $new_instance['post_title'] = isset( $_POST['frm_style_setting']['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) ) : '';
121 72
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 - }
73 + // Don't wp_unslash yet since it removes backslashes.
74 + $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $_POST['frm_style_setting']['post_content'] : ''; // WPCS: sanitization ok.
75 + FrmAppHelper::sanitize_value( 'sanitize_textarea_field', $new_instance['post_content'] );
76 + $new_instance['post_type'] = FrmStylesController::$post_type;
77 + $new_instance['post_status'] = 'publish';
78 + $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0;
126 79
127 - $new_instance['post_type'] = FrmStylesController::$post_type;
128 - $new_instance['post_status'] = 'publish';
129 -
130 - if ( ! $id ) {
80 + if ( empty( $id ) ) {
131 81 $new_instance['post_name'] = $new_instance['post_title'];
132 82 }
133 83
134 84 $default_settings = $this->get_defaults();
@@ -138,259 +88,40 @@
138 88 $new_instance['post_content'][ $setting ] = $default;
139 89 }
140 90
141 91 if ( $this->is_color( $setting ) ) {
142 - $color_val = $new_instance['post_content'][ $setting ];
143 -
144 - if ( $color_val !== '' && str_contains( $color_val, 'rgb' ) ) {
145 - // Maybe sanitize if invalid rgba value is entered.
146 - $this->maybe_sanitize_rgba_value( $color_val );
147 - }
148 - $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val );
149 - } elseif ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ), true ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
92 + $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
93 + } elseif ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) )
94 + && ! isset( $new_instance['post_content'][ $setting ] )
95 + ) {
150 96 $new_instance['post_content'][ $setting ] = 0;
151 - } elseif ( $setting === 'font' ) {
97 + } elseif ( $setting == 'font' ) {
152 98 $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
153 99 }
154 100 }
155 101
156 - $new_instance['post_content'] = FrmStylesHelper::update_base_font_size( $new_instance['post_content'], $this->get_defaults() );
157 - $action_ids[] = $this->save( $new_instance );
158 - }//end foreach
102 + $all_instances[ $number ] = $new_instance;
159 103
160 - $this->save_settings();
104 + $action_ids[] = $this->save( $new_instance );
161 105
162 - return $action_ids;
163 - }
164 -
165 - /**
166 - * Sanitize custom color values and convert it to valid one filling missing values.
167 - *
168 - * @since 5.3.2
169 - *
170 - * @param string $color_val The color value, by reference.
171 - *
172 - * @return void
173 - */
174 - private function maybe_sanitize_rgba_value( &$color_val ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
175 - if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) {
176 - return;
177 106 }
178 107
179 - $color_val = trim( $color_val );
180 - // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces.
181 - $color_val = ltrim( $color_val, '(' );
182 - $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' );
108 + $this->save_settings();
183 109
184 - foreach ( $patterns as $pattern ) {
185 - if ( preg_match( $pattern, $color_val ) === 1 ) {
186 - return;
187 - }
188 - }
189 -
190 - // Remove all leading ')' braces, then add one back. This way there's always a single brace.
191 - $color_val = rtrim( $color_val, ')' );
192 - $color_val .= ')';
193 -
194 - $color_rgba = substr( $color_val, strpos( $color_val, '(' ) + 1, strlen( $color_val ) - strpos( $color_val, '(' ) - 2 );
195 - // Remove any excessive braces from the rgba like rgba((.
196 - $color_rgba = trim( $color_rgba, '()' );
197 - $length_of_color_codes = strpos( $color_val, '(' );
198 - $new_color_values = array();
199 -
200 - // replace empty values by 0 or 1 (if alpha position).
201 - foreach ( explode( ',', $color_rgba ) as $index => $value ) {
202 - $new_value = null;
203 - $value_is_empty_string = '' === trim( $value ) || '' === $value;
204 -
205 - if ( 3 === $length_of_color_codes || $index !== $length_of_color_codes - 1 ) {
206 - // Insert a value for r, g, or b.
207 - if ( $value < 0 ) {
208 - $new_value = 0;
209 - } elseif ( $value > 255 ) {
210 - $new_value = 255;
211 - } elseif ( $value_is_empty_string ) {
212 - $new_value = 0;
213 - } else {
214 - $new_value = absint( $value );
215 - }
216 - } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
217 - // Insert a value for alpha.
218 - if ( $value_is_empty_string ) {
219 - $new_value = 4 === $length_of_color_codes ? 1 : 0;
220 - } elseif ( $value > 1 || $value < 0 ) {
221 - $new_value = 1;
222 - } else {
223 - $new_value = floatval( $value );
224 - }
225 - }//end if
226 -
227 - $new_color_values[] = $new_value;
228 - }//end foreach
229 -
230 - // add more 0s and 1 (if alpha position) if needed.
231 - $missing_values = $length_of_color_codes - count( $new_color_values );
232 -
233 - if ( $missing_values > 1 ) {
234 - $insert_values = array_fill( 0, $missing_values - 1, 0 );
235 - $last_value = 4 === $length_of_color_codes ? 1 : 0;
236 - array_push( $insert_values, $last_value );
237 - } elseif ( $missing_values === 1 ) {
238 - $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 );
239 - }
240 -
241 - if ( ! empty( $insert_values ) ) {
242 - $new_color_values = array_merge( $new_color_values, $insert_values );
243 - }
244 -
245 - $new_color = implode( ',', $new_color_values );
246 - $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 );
247 - // Limit the number of opening braces after rgb/rgba. There should only be one.
248 - $prefix = rtrim( $prefix, '(' ) . '(';
249 - $new_color = $prefix . $new_color . ')';
250 - $color_val = $new_color;
110 + return $action_ids;
251 111 }
252 112
253 113 /**
254 - * @since 5.0.13
255 - *
256 - * @param array $settings
257 - *
258 - * @return array
259 - */
260 - public function sanitize_post_content( $settings ) {
261 - $defaults = $this->get_defaults();
262 - $valid_keys = array_keys( $defaults );
263 - $sanitized_settings = array();
264 -
265 - foreach ( $valid_keys as $key ) {
266 - $sanitized_settings[ $key ] = isset( $settings[ $key ] ) ? sanitize_textarea_field( $settings[ $key ] ) : $defaults[ $key ];
267 -
268 - if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) {
269 - $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] );
270 - }
271 - }
272 -
273 - return $sanitized_settings;
274 - }
275 -
276 - /**
277 - * Remove any characters that should not be used in CSS.
278 - *
279 - * @since 6.2.3
280 - *
281 - * @param string $setting
282 - *
283 - * @return string
284 - */
285 - private function strip_invalid_characters( $setting ) {
286 - $characters_to_remove = array( '{', '}', ';', '[', ']' );
287 -
288 - // RGB is handled instead in self::maybe_sanitize_rgba_value.
289 - if ( ! str_starts_with( $setting, 'rgb' ) ) {
290 - $setting = $this->maybe_fix_braces( $setting, $characters_to_remove );
291 - }
292 -
293 - return str_replace( $characters_to_remove, '', $setting );
294 - }
295 -
296 - /**
297 - * @since 6.2.3
298 - *
299 - * @param string $setting
300 - * @param array $characters_to_remove
301 - *
302 - * @return string
303 - */
304 - private function maybe_fix_braces( $setting, &$characters_to_remove ) {
305 - $number_of_opening_braces = substr_count( $setting, '(' );
306 - $number_of_closing_braces = substr_count( $setting, ')' );
307 -
308 - if ( $number_of_opening_braces === $number_of_closing_braces ) {
309 - return $this->trim_braces( $setting );
310 - }
311 -
312 - if ( $this->should_remove_every_brace( $setting ) ) {
313 - // Add to $characters_to_remove to remove when str_replace is called.
314 - array_push( $characters_to_remove, '(', ')' );
315 - return $setting;
316 - }
317 -
318 - return $this->trim_braces( $setting );
319 - }
320 -
321 - /**
322 - * @since 6.2.3
323 - *
324 - * @param string $input
325 - *
326 - * @return string
327 - */
328 - private function trim_braces( $input ) {
329 - $output = $input;
330 -
331 - // Remove any ( from the start of the string as no CSS values expect at the first character.
332 - if ( $output && in_array( $output[0], array( '(', ')' ), true ) ) {
333 - $output = ltrim( $output, '()' );
334 - }
335 -
336 - // Remove extra braces from the end.
337 - if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) {
338 - $output = rtrim( $output, '()' );
339 -
340 - if ( str_contains( $output, '(' ) ) {
341 - $output .= ')';
342 - }
343 - }
344 -
345 - return $output;
346 - }
347 -
348 - /**
349 - * @since 6.2.3
350 - *
351 - * @param string $setting
352 - *
353 - * @return bool
354 - */
355 - private function should_remove_every_brace( $setting ) {
356 - if ( str_starts_with( trim( $setting, '()' ), 'calc' ) ) {
357 - // Support calc() sizes. We do not want to remove all braces when calc is used.
358 - return false;
359 - }
360 -
361 - // Matches hex values but also checks for unexpected ( and ).
362 - $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting );
363 -
364 - if ( $looks_like_a_hex_value ) {
365 - return true;
366 - }
367 -
368 - // Matches size values but also checks for unexpected ( and ).
369 - // This is case insensitive so it will catch PX, PT, etc, as well.
370 - $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting );
371 - return (bool) $looks_like_a_size;
372 - }
373 -
374 - /**
375 114 * @since 3.01.01
376 - *
377 - * @param string $setting
378 - *
379 - * @return bool
380 115 */
381 116 private function is_color( $setting ) {
382 - if ( str_contains( $setting, 'color' ) ) {
383 - return true;
384 - }
117 + $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
385 118
386 - return in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ), true );
119 + return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors );
387 120 }
388 121
389 122 /**
390 123 * @since 3.01.01
391 - *
392 - * @return array
393 124 */
394 125 public function get_color_settings() {
395 126 $defaults = $this->get_defaults();
396 127 $settings = array_keys( $defaults );
@@ -398,11 +129,9 @@
398 129 return array_filter( $settings, array( $this, 'is_color' ) );
399 130 }
400 131
401 132 /**
402 - * Create static CSS file and update the CSS transient alternative.
403 - *
404 - * @return void
133 + * Create static css file
405 134 */
406 135 public function save_settings() {
407 136 $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
408 137 update_option( 'frm_last_style_update', gmdate( 'njGi' ) );
@@ -412,9 +141,10 @@
412 141 }
413 142
414 143 $this->clear_cache();
415 144
416 - $css = $this->get_css_content( $filename );
145 + $css = $this->get_css_content( $filename );
146 +
417 147 $create_file = new FrmCreateFile(
418 148 array(
419 149 'file_name' => FrmStylesController::get_file_name(),
420 150 'new_file_path' => FrmAppHelper::plugin_path() . '/css',
@@ -421,32 +151,26 @@
421 151 )
422 152 );
423 153 $create_file->create_file( $css );
424 154
425 - update_option( 'frmpro_css', $css, false );
155 + update_option( 'frmpro_css', $css, 'no' );
426 156 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
427 157 }
428 158
429 - /**
430 - * @param string $filename
431 - *
432 - * @return string
433 - */
434 159 private function get_css_content( $filename ) {
435 - $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
160 + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
161 +
436 162 $saving = true;
437 163 $frm_style = $this;
438 164
439 165 ob_start();
440 - include $filename;
441 - $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_clean() ) );
166 + include( $filename );
167 + $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
168 + ob_end_clean();
442 169
443 170 return FrmStylesController::replace_relative_url( $css );
444 171 }
445 172
446 - /**
447 - * @return void
448 - */
449 173 private function clear_cache() {
450 174 $default_post_atts = array(
451 175 'post_type' => FrmStylesController::$post_type,
452 176 'post_status' => 'publish',
@@ -459,31 +183,21 @@
459 183 FrmDb::cache_delete_group( 'frm_styles' );
460 184 FrmDb::delete_cache_and_transient( 'frmpro_css' );
461 185 }
462 186
463 - /**
464 - * Delete a style by its post ID.
465 - *
466 - * @param int $id
467 - *
468 - * @return false|WP_Post|null
469 - */
470 187 public function destroy( $id ) {
471 - if ( $id === $this->get_default_style()->ID ) {
472 - return false;
473 - }
474 188 return wp_delete_post( $id );
475 189 }
476 190
477 - /**
478 - * @return stdClass|WP_Post
479 - */
480 191 public function get_one() {
481 - if ( 'default' === $this->id ) {
192 + if ( 'default' == $this->id ) {
482 193 $style = $this->get_default_style();
194 + if ( $style ) {
195 + $this->id = $style->ID;
196 + } else {
197 + $this->id = 0;
198 + }
483 199
484 - $this->id = $style ? $style->ID : 0;
485 -
486 200 return $style;
487 201 }
488 202
489 203 $style = get_post( $this->id );
@@ -495,9 +209,9 @@
495 209 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
496 210
497 211 $default_values = $this->get_defaults();
498 212
499 - // Fill default values
213 + // fill default values
500 214 $style->post_content = $this->override_defaults( $style->post_content );
501 215 $style->post_content = wp_parse_args( $style->post_content, $default_values );
502 216
503 217 return $style;
@@ -502,15 +216,8 @@
502 216
503 217 return $style;
504 218 }
505 219
506 - /**
507 - * @param string $orderby
508 - * @param string $order
509 - * @param int $limit
510 - *
511 - * @return array
512 - */
513 220 public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
514 221 $post_atts = array(
515 222 'post_type' => FrmStylesController::$post_type,
516 223 'post_status' => 'publish',
@@ -520,16 +227,16 @@
520 227 );
521 228
522 229 $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
523 230
524 - if ( ! $temp_styles ) {
231 + if ( empty( $temp_styles ) ) {
525 232 global $wpdb;
526 - // Make sure there wasn't a conflict with the query
527 - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
233 + // make sure there wasn't a conflict with the query
234 + $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
528 235 $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
529 236
530 - if ( ! $temp_styles ) {
531 - // Create a new style if there are none
237 + if ( empty( $temp_styles ) ) {
238 + // create a new style if there are none
532 239 $new = $this->get_new();
533 240 $new->post_title = __( 'Formidable Style', 'formidable' );
534 241 $new->post_name = $new->post_title;
535 242 $new->menu_order = 1;
@@ -536,25 +243,25 @@
536 243 $new = $this->save( (array) $new );
537 244 $this->update( 'default' );
538 245
539 246 $post_atts['include'] = $new;
540 - $temp_styles = get_posts( $post_atts );
247 +
248 + $temp_styles = get_posts( $post_atts );
541 249 }
542 250 }
543 251
544 252 $default_values = $this->get_defaults();
545 253 $default_style = false;
546 - $styles = array();
547 254
255 + $styles = array();
548 256 foreach ( $temp_styles as $style ) {
549 257 $this->id = $style->ID;
550 -
551 258 if ( $style->menu_order ) {
552 259 if ( $default_style ) {
553 - // Only return one default
260 + // only return one default
554 261 $style->menu_order = 0;
555 262 } else {
556 - // Check for a default style
263 + // check for a default style
557 264 $default_style = $style->ID;
558 265 }
559 266 }
560 267
@@ -559,17 +266,18 @@
559 266 }
560 267
561 268 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
562 269
563 - // Fill default values
270 + // fill default values
564 271 $style->post_content = $this->override_defaults( $style->post_content );
565 272 $style->post_content = wp_parse_args( $style->post_content, $default_values );
566 273
567 274 $styles[ $style->ID ] = $style;
568 - }//end foreach
275 + }
569 276
570 277 if ( ! $default_style ) {
571 - $default_style = reset( $styles );
278 + $default_style = reset( $styles );
279 +
572 280 $styles[ $default_style->ID ]->menu_order = 1;
573 281 }
574 282
575 283 return $styles;
@@ -574,13 +282,8 @@
574 282
575 283 return $styles;
576 284 }
577 285
578 - /**
579 - * @param array|null $styles
580 - *
581 - * @return object|null
582 - */
583 286 public function get_default_style( $styles = null ) {
584 287 if ( ! isset( $styles ) ) {
585 288 $styles = $this->get_all( 'menu_order', 'DESC', 1 );
586 289 }
@@ -589,23 +292,16 @@
589 292 if ( $style->menu_order ) {
590 293 return $style;
591 294 }
592 295 }
593 -
594 - return null;
595 296 }
596 297
597 - /**
598 - * @param mixed $settings
599 - *
600 - * @return mixed
601 - */
602 298 public function override_defaults( $settings ) {
603 299 if ( ! is_array( $settings ) ) {
604 300 return $settings;
605 301 }
606 302
607 - $settings['line_height'] = ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] === 'auto' ? 'normal' : $settings['field_height']; // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong
303 + $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
608 304
609 305 if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
610 306 $settings['form_desc_size'] = $settings['description_font_size'];
611 307 $settings['form_desc_color'] = $settings['description_color'];
@@ -629,229 +325,179 @@
629 325
630 326 return apply_filters( 'frm_override_default_styles', $settings );
631 327 }
632 328
633 - /**
634 - * @return array
635 - */
636 329 public function get_defaults() {
637 330 $defaults = array(
638 - 'theme_css' => 'ui-lightness',
639 - 'theme_name' => 'UI Lightness',
331 + 'theme_css' => 'ui-lightness',
332 + 'theme_name' => 'UI Lightness',
640 333
641 - 'center_form' => '',
642 - 'form_width' => '100%',
643 - 'form_align' => 'left',
644 - 'direction' => is_rtl() ? 'rtl' : 'ltr',
645 - 'fieldset' => '0px',
646 - 'fieldset_color' => '000000',
647 - 'fieldset_padding' => '0px 0px 15px 0px',
648 - 'fieldset_bg_color' => '',
334 + 'center_form' => '',
335 + 'form_width' => '100%',
336 + 'form_align' => 'left',
337 + 'direction' => is_rtl() ? 'rtl' : 'ltr',
338 + 'fieldset' => '0px',
339 + 'fieldset_color' => '000000',
340 + 'fieldset_padding' => '0 0 15px 0',
341 + 'fieldset_bg_color' => '',
649 342
650 - 'title_size' => '40px',
651 - 'title_color' => '444444',
652 - 'title_margin_top' => '10px',
653 - 'title_margin_bottom' => '60px',
654 - 'form_desc_size' => '14px',
655 - 'form_desc_color' => '98A2B3',
656 - 'form_desc_margin_top' => '10px',
657 - 'form_desc_margin_bottom' => '25px',
658 - 'form_desc_padding' => '0px',
343 + 'title_size' => '40px',
344 + 'title_color' => '444444',
345 + 'title_margin_top' => '10px',
346 + 'title_margin_bottom' => '60px',
347 + 'form_desc_size' => '14px',
348 + 'form_desc_color' => '666666',
349 + 'form_desc_margin_top' => '10px',
350 + 'form_desc_margin_bottom' => '25px',
351 + 'form_desc_padding' => '0',
659 352
660 - 'font' => '',
661 - 'font_size' => '15px',
662 - 'label_color' => '344054',
663 - 'weight' => 'normal',
664 - 'position' => 'none',
665 - 'align' => 'left',
666 - 'width' => '150px',
667 - 'required_color' => 'F04438',
668 - 'required_weight' => 'bold',
669 - 'label_padding' => '0px 0px 5px 0px',
353 + 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
354 + 'font_size' => '15px',
355 + 'label_color' => '3f4b5b',
356 + 'weight' => 'normal',
357 + 'position' => 'none',
358 + 'align' => 'left',
359 + 'width' => '150px',
360 + 'required_color' => 'B94A48',
361 + 'required_weight' => 'bold',
362 + 'label_padding' => '0 0 3px 0',
670 363
671 - 'description_font_size' => '12px',
672 - 'description_color' => '667085',
673 - 'description_weight' => 'normal',
674 - 'description_style' => 'normal',
675 - 'description_align' => 'left',
676 - 'description_margin' => '0px',
364 + 'description_font_size' => '12px',
365 + 'description_color' => '666666',
366 + 'description_weight' => 'normal',
367 + 'description_style' => 'normal',
368 + 'description_align' => 'left',
369 + 'description_margin' => '0',
677 370
678 - 'field_font_size' => '14px',
679 - 'field_height' => '36px',
680 - 'line_height' => 'normal',
681 - 'field_width' => '100%',
682 - 'auto_width' => false,
683 - 'field_pad' => '8px 12px',
684 - 'field_margin' => '20px',
685 - 'field_weight' => 'normal',
686 - 'text_color' => '1D2939',
687 - // 'border_color_hv' => 'cccccc',
688 - 'border_color' => 'D0D5DD',
689 - 'field_border_width' => '1px',
690 - 'field_border_style' => 'solid',
371 + 'field_font_size' => '14px',
372 + 'field_height' => '32px',
373 + 'line_height' => 'normal',
374 + 'field_width' => '100%',
375 + 'auto_width' => false,
376 + 'field_pad' => '6px 10px',
377 + 'field_margin' => '20px',
378 + 'field_weight' => 'normal',
379 + 'text_color' => '555555',
380 + //'border_color_hv' => 'cccccc',
381 + 'border_color' => 'BFC3C8',
382 + 'field_border_width' => '1px',
383 + 'field_border_style' => 'solid',
691 384
692 - 'bg_color' => 'ffffff',
693 - // 'bg_color_hv' => 'ffffff',
694 - 'remove_box_shadow' => '',
695 - 'bg_color_active' => 'ffffff',
696 - 'border_color_active' => '4199FD',
697 - 'remove_box_shadow_active' => '',
698 - 'text_color_error' => '444444',
699 - 'bg_color_error' => 'ffffff',
700 - 'border_color_error' => 'F04438',
701 - 'border_width_error' => '1px',
702 - 'border_style_error' => 'solid',
703 - 'bg_color_disabled' => 'F9FAFB',
704 - 'border_color_disabled' => 'D0D5DD',
705 - 'text_color_disabled' => '667085',
385 + 'bg_color' => 'ffffff',
386 + //'bg_color_hv' => 'ffffff',
387 + 'remove_box_shadow' => '',
388 + 'bg_color_active' => 'ffffff',
389 + 'border_color_active' => '66afe9',
390 + 'remove_box_shadow_active' => '',
391 + 'text_color_error' => '444444',
392 + 'bg_color_error' => 'ffffff',
393 + 'border_color_error' => 'B94A48',
394 + 'border_width_error' => '1px',
395 + 'border_style_error' => 'solid',
396 + 'bg_color_disabled' => 'ffffff',
397 + 'border_color_disabled' => 'E5E5E5',
398 + 'text_color_disabled' => 'A1A1A1',
706 399
707 - 'radio_align' => 'block',
708 - 'check_align' => 'block',
709 - 'check_font_size' => '14px',
710 - 'check_label_color' => '1D2939',
711 - 'check_weight' => 'normal',
400 + 'radio_align' => 'block',
401 + 'check_align' => 'block',
402 + 'check_font_size' => '13px',
403 + 'check_label_color' => '444444',
404 + 'check_weight' => 'normal',
712 405
713 - 'section_font_size' => '18px',
714 - 'section_color' => '344054',
715 - 'section_weight' => 'bold',
716 - 'section_pad' => '32px 0px 3px 0px',
717 - 'section_mar_top' => '30px',
718 - 'section_mar_bottom' => '30px',
719 - 'section_bg_color' => '',
720 - 'section_border_color' => 'EAECF0',
721 - 'section_border_width' => '1px',
722 - 'section_border_style' => 'solid',
723 - 'section_border_loc' => '-top',
724 - 'collapse_icon' => '6',
725 - 'collapse_pos' => 'after',
726 - 'repeat_icon' => '1',
727 - 'repeat_icon_color' => 'ffffff',
406 + 'section_font_size' => '18px',
407 + 'section_color' => '444444',
408 + 'section_weight' => 'bold',
409 + 'section_pad' => '15px 0 3px 0',
410 + 'section_mar_top' => '15px',
411 + 'section_mar_bottom' => '30px',
412 + 'section_bg_color' => '',
413 + 'section_border_color' => 'e8e8e8',
414 + 'section_border_width' => '2px',
415 + 'section_border_style' => 'solid',
416 + 'section_border_loc' => '-top',
417 + 'collapse_icon' => '6',
418 + 'collapse_pos' => 'after',
419 + 'repeat_icon' => '1',
420 + 'repeat_icon_color' => 'ffffff',
728 421
729 422 'submit_style' => false,
730 - 'submit_font_size' => '14px',
423 + 'submit_font_size' => '15px',
731 424 'submit_width' => 'auto',
732 425 'submit_height' => 'auto',
733 - 'submit_bg_color' => '4199FD',
734 - 'submit_border_color' => '4199FD',
426 + 'submit_bg_color' => '579AF6',
427 + 'submit_border_color' => '579AF6',
735 428 'submit_border_width' => '1px',
736 429 'submit_text_color' => 'ffffff',
737 430 'submit_weight' => 'normal',
738 - 'submit_border_radius' => '8px',
431 + 'submit_border_radius' => '4px',
739 432 'submit_bg_img' => '',
740 433 'submit_margin' => '10px',
741 - 'submit_padding' => '8px 16px',
434 + 'submit_padding' => '10px 20px',
742 435 'submit_shadow_color' => 'eeeeee',
743 - 'submit_hover_bg_color' => '3680D3',
744 - 'submit_hover_color' => 'ffffff',
745 - 'submit_hover_border_color' => '3680D3',
746 - 'submit_active_bg_color' => '3680D3',
747 - 'submit_active_color' => 'ffffff',
748 - 'submit_active_border_color' => '3680D3',
436 + 'submit_hover_bg_color' => 'efefef',
437 + 'submit_hover_color' => '444444',
438 + 'submit_hover_border_color' => 'cccccc',
439 + 'submit_active_bg_color' => 'efefef',
440 + 'submit_active_color' => '444444',
441 + 'submit_active_border_color' => 'cccccc',
749 442
750 - 'border_radius' => '8px',
751 - 'error_bg' => 'FEE4E2',
752 - 'error_border' => 'F5B8AA',
753 - 'error_text' => 'F04438',
754 - 'error_font_size' => '14px',
443 + 'border_radius' => '4px',
444 + 'error_bg' => 'F2DEDE',
445 + 'error_border' => 'EBCCD1',
446 + 'error_text' => 'B94A48',
447 + 'error_font_size' => '14px',
755 448
756 - 'success_bg_color' => 'DFF0D8',
757 - 'success_border_color' => 'D6E9C6',
758 - 'success_text_color' => '468847',
759 - 'success_font_size' => '14px',
449 + 'success_bg_color' => 'DFF0D8',
450 + 'success_border_color' => 'D6E9C6',
451 + 'success_text_color' => '468847',
452 + 'success_font_size' => '14px',
760 453
761 - 'important_style' => false,
454 + 'important_style' => false,
762 455
763 - 'progress_bg_color' => 'EAECF0',
764 - 'progress_color' => '1D2939',
765 - 'progress_active_bg_color' => '4199FD',
766 - 'progress_active_color' => 'ffffff',
767 - 'progress_border_color' => 'EAECF0',
768 - 'progress_border_size' => '1px',
769 - 'progress_size' => '30px',
770 - 'custom_css' => '',
771 - 'use_base_font_size' => false,
772 - 'base_font_size' => '15px',
773 - 'field_shape_type' => 'rounded-corner',
456 + 'progress_bg_color' => 'eaeaea',
457 + 'progress_active_color' => 'ffffff',
458 + 'progress_active_bg_color' => '579AF6',
459 + 'progress_color' => '3f4b5b',
460 + 'progress_border_color' => 'E5E5E5',
461 + 'progress_border_size' => '2px',
462 + 'progress_size' => '30px',
774 463
775 - 'enable_style_custom_css' => false,
776 - 'single_style_custom_css' => '',
464 + 'custom_css' => '',
777 465 );
778 466
779 467 return apply_filters( 'frm_default_style_settings', $defaults );
780 468 }
781 469
782 - /**
783 - * Get a name attribute value for a style setting input.
784 - *
785 - * @param string $field_name
786 - * @param string $post_field
787 - *
788 - * @return string
789 - */
790 470 public function get_field_name( $field_name, $post_field = 'post_content' ) {
791 - return 'frm_style_setting' . ( $post_field ? '[' . $post_field . ']' : '' ) . '[' . $field_name . ']';
471 + return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
792 472 }
793 473
794 - /**
795 - * @return array
796 - */
797 474 public static function get_bold_options() {
798 475 return array(
799 - 100 => __( 'Thin', 'formidable' ),
800 - 200 => __( 'Extra Light', 'formidable' ),
801 - 300 => __( 'Light', 'formidable' ),
802 - 'normal' => __( 'Regular', 'formidable' ),
803 - 500 => __( 'Medium', 'formidable' ),
804 - 600 => __( 'Semi Bold', 'formidable' ),
805 - 'bold' => __( 'Bold', 'formidable' ),
806 - 800 => __( 'Extra Bold', 'formidable' ),
807 - 900 => __( 'Black', 'formidable' ),
476 + 100 => 100,
477 + 200 => 200,
478 + 300 => 300,
479 + 'normal' => __( 'normal', 'formidable' ),
480 + 500 => 500,
481 + 600 => 600,
482 + 'bold' => __( 'bold', 'formidable' ),
483 + 800 => 800,
484 + 900 => 900,
808 485 );
809 486 }
810 487
811 488 /**
812 - * Don't let imbalanced font families ruin the whole stylesheet.
813 - *
814 - * @param string $value
815 - *
816 - * @return string
489 + * Don't let imbalanced font families ruin the whole stylesheet
817 490 */
818 491 public function force_balanced_quotation( $value ) {
819 492 $balanced_characters = array( '"', "'" );
820 -
821 493 foreach ( $balanced_characters as $char ) {
822 494 $char_count = substr_count( $value, $char );
823 - $is_balanced = $char_count % 2 === 0;
824 -
825 - if ( $is_balanced ) {
826 - continue;
827 - }
828 -
829 - if ( $value && $char === $value[ strlen( $value ) - 1 ] ) {
830 - $value = $char . $value;
831 - } else {
495 + $is_balanced = $char_count % 2 == 0;
496 + if ( ! $is_balanced ) {
832 497 $value .= $char;
833 498 }
834 499 }
835 500
836 501 return $value;
837 - }
838 -
839 - /**
840 - * Get the default template style
841 - *
842 - * @since 6.14
843 - *
844 - * @param int|string $style_id The post type "frm_styles" ID.
845 - *
846 - * @return string The json encoded template data
847 - */
848 - public function get_default_template_style( $style_id ) {
849 - $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true );
850 -
851 - if ( ! $default_template ) {
852 - return FrmAppHelper::prepare_and_encode( $this->get_defaults() );
853 - }
854 -
855 - return $default_template;
856 502 }
857 503 }