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