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 +280 -590 6.43.06.06 View file →
@@ -1,9 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 -
6 2 class FrmStyle {
7 3 public $number = false; // Unique ID number of the current instance.
8 4 public $id = 0; // the id of the post
9 5
@@ -10,380 +6,134 @@
10 6 /**
11 7 * @param int|string $id The id of the stylsheet or 'default'
12 8 */
13 9 public function __construct( $id = 0 ) {
14 - $this->id = $id;
15 - }
10 + $this->id = $id;
11 + }
16 12
17 - /**
18 - * @return stdClass
19 - */
20 - public function get_new() {
13 + public function get_new() {
21 14 $this->id = 0;
22 15
23 - $max_slug_value = 2147483647;
24 - $min_slug_value = 37; // we want to have at least 2 characters in the slug
25 - $key = base_convert( rand( $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 );
26 19
27 - $style = array(
28 - 'post_type' => FrmStylesController::$post_type,
29 - 'ID' => '',
30 - 'post_title' => __( 'New Style', 'formidable' ),
31 - 'post_name' => $key,
32 - 'post_content' => $this->get_defaults(),
33 - 'menu_order' => '',
34 - 'post_status' => 'publish',
35 - );
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 + );
36 29
37 - return (object) $style;
38 - }
30 + return (object) $style;
31 + }
39 32
40 - /**
41 - * @param array $settings
42 - * @return int|WP_Error
43 - */
44 33 public function save( $settings ) {
45 34 return FrmDb::save_settings( $settings, 'frm_styles' );
46 - }
35 + }
47 36
48 - /**
49 - * @return void
50 - */
51 37 public function duplicate( $id ) {
52 - // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead.
53 - }
38 + // duplicating is a pro feature
39 + }
54 40
55 - /**
56 - * Handle save actions in the visual styler edit page.
57 - *
58 - * @param mixed $id
59 - * @return array<int|WP_Error>
60 - */
61 - public function update( $id = 'default' ) {
62 - $all_instances = $this->get_all();
41 + public function update( $id = 'default' ) {
42 + $all_instances = $this->get_all();
63 43
64 - if ( ! $id ) {
65 - $new_style = (array) $this->get_new();
66 - $all_instances[] = $new_style;
67 - }
44 + if ( empty( $id ) ) {
45 + $new_style = (array) $this->get_new();
46 + $all_instances[] = $new_style;
47 + }
68 48
69 - $action_ids = array();
49 + $action_ids = array();
70 50
71 - foreach ( $all_instances as $number => $new_instance ) {
72 - $new_instance = (array) $new_instance;
73 - $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;
74 56
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.
77 - continue;
78 - }
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 + }
79 62
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'] : '';
63 + // don't continue if not saving this style
64 + continue;
65 + }
83 66
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 - }
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;
90 72
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 );
73 + if ( empty( $id ) ) {
74 + $new_instance['post_name'] = $new_instance['post_title'];
75 + }
94 76
95 - $new_instance['post_type'] = FrmStylesController::$post_type;
96 - $new_instance['post_status'] = 'publish';
77 + $default_settings = $this->get_defaults();
97 78
98 - if ( ! $id ) {
99 - $new_instance['post_name'] = $new_instance['post_title'];
100 - }
101 -
102 - $default_settings = $this->get_defaults();
103 -
104 - foreach ( $default_settings as $setting => $default ) {
79 + foreach ( $default_settings as $setting => $default ) {
105 80 if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
106 81 $new_instance['post_content'][ $setting ] = $default;
107 82 }
108 83
109 84 if ( $this->is_color( $setting ) ) {
110 - $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.
113 - $this->maybe_sanitize_rgba_value( $color_val );
114 - }
115 - $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 ] ) ) {
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 ] ) ) {
117 87 $new_instance['post_content'][ $setting ] = 0;
118 - } elseif ( $setting === 'font' ) {
119 - $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
120 - }
121 - }
88 + } else if ( $setting == 'font' ) {
89 + $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
90 + }
91 + }
122 92
93 + $all_instances[ $number ] = $new_instance;
94 +
123 95 $action_ids[] = $this->save( $new_instance );
124 - }
125 96
126 - $this->save_settings();
97 + }
127 98
128 - return $action_ids;
129 - }
99 + $this->save_settings();
130 100
131 - /**
132 - * Sanitize custom color values and convert it to valid one filling missing values.
133 - *
134 - * @since 5.3.2
135 - *
136 - * @param string $color_val, The color value, by reference.
137 - * @return void
138 - */
139 - private function maybe_sanitize_rgba_value( &$color_val ) {
140 - if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) {
141 - return;
142 - }
101 + return $action_ids;
102 + }
143 103
144 - $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 - $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' );
147 - foreach ( $patterns as $pattern ) {
148 - if ( preg_match( $pattern, $color_val ) === 1 ) {
149 - return;
150 - }
151 - }
152 -
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 .= ')';
156 -
157 - $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 - $length_of_color_codes = strpos( $color_val, '(' );
160 - $new_color_values = array();
161 -
162 - // replace empty values by 0 or 1 (if alpha position).
163 - foreach ( explode( ',', $color_rgba ) as $index => $value ) {
164 - $new_value = null;
165 - $value_is_empty_string = '' === trim( $value ) || '' === $value;
166 -
167 - if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) {
168 - // Insert a value for r, g, or b.
169 - if ( $value < 0 ) {
170 - $new_value = 0;
171 - } elseif ( $value > 255 ) {
172 - $new_value = 255;
173 - } elseif ( $value_is_empty_string ) {
174 - $new_value = 0;
175 - } else {
176 - $new_value = absint( $value );
177 - }
178 - } else {
179 - // Insert a value for alpha.
180 - if ( $value_is_empty_string ) {
181 - $new_value = 4 === $length_of_color_codes ? 1 : 0;
182 - } elseif ( $value > 1 || $value < 0 ) {
183 - $new_value = 1;
184 - } else {
185 - $new_value = floatval( $value );
186 - }
187 - }
188 -
189 - $new_color_values[] = null === $new_value ? $value : $new_value;
190 - }
191 -
192 - // add more 0s and 1 (if alpha position) if needed.
193 - $missing_values = $length_of_color_codes - count( $new_color_values );
194 - if ( $missing_values > 1 ) {
195 - $insert_values = array_fill( 0, $missing_values - 1, 0 );
196 - $last_value = 4 === $length_of_color_codes ? 1 : 0;
197 - array_push( $insert_values, $last_value );
198 - } elseif ( $missing_values === 1 ) {
199 - $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 );
200 - }
201 - if ( ! empty( $insert_values ) ) {
202 - $new_color_values = array_merge( $new_color_values, $insert_values );
203 - }
204 -
205 - $new_color = implode( ',', $new_color_values );
206 - $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 - $new_color = $prefix . $new_color . ')';
209 -
210 - $color_val = $new_color;
211 - }
212 -
213 104 /**
214 - * Unslash everything in post_content but custom_css
215 - *
216 - * @since 5.0.13
217 - *
218 - * @param array $settings
219 - * @return array
220 - */
221 - private function unslash_post_content( $settings ) {
222 - $custom_css = isset( $settings['custom_css'] ) ? $settings['custom_css'] : '';
223 - $settings = wp_unslash( $settings );
224 - $settings['custom_css'] = $custom_css;
225 - return $settings;
226 - }
227 -
228 - /**
229 - * @since 5.0.13
230 - *
231 - * @param array $settings
232 - * @return array
233 - */
234 - public function sanitize_post_content( $settings ) {
235 - $defaults = $this->get_defaults();
236 - $valid_keys = array_keys( $defaults );
237 - $sanitized_settings = array();
238 - foreach ( $valid_keys as $key ) {
239 - if ( isset( $settings[ $key ] ) ) {
240 - $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] );
241 - } else {
242 - $sanitized_settings[ $key ] = $defaults[ $key ];
243 - }
244 -
245 - if ( 'custom_css' !== $key ) {
246 - $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] );
247 - }
248 - }
249 - return $sanitized_settings;
250 - }
251 -
252 - /**
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 105 * @since 3.01.01
349 - *
350 - * @param string $setting
351 - * @return bool
352 106 */
353 107 private function is_color( $setting ) {
354 108 $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
355 - return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors, true );
109 + return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors );
356 110 }
357 111
358 112 /**
359 113 * @since 3.01.01
360 - *
361 - * @return array
362 114 */
363 115 public function get_color_settings() {
364 116 $defaults = $this->get_defaults();
365 117 $settings = array_keys( $defaults );
366 -
367 118 return array_filter( $settings, array( $this, 'is_color' ) );
368 119 }
369 120
370 - /**
371 - * Create static CSS file and update the CSS transient alternative.
372 - *
373 - * @return void
374 - */
121 + /**
122 + * Create static css file
123 + */
375 124 public function save_settings() {
376 125 $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
377 - update_option( 'frm_last_style_update', gmdate( 'njGi' ) );
126 + update_option( 'frm_last_style_update', date( 'njGi' ) );
378 127
379 128 if ( ! is_file( $filename ) ) {
380 - return;
381 - }
129 + return;
130 + }
382 131
383 132 $this->clear_cache();
384 133
385 - $css = $this->get_css_content( $filename );
134 + $css = $this->get_css_content( $filename );
135 +
386 136 $create_file = new FrmCreateFile(
387 137 array(
388 138 'file_name' => FrmStylesController::get_file_name(),
389 139 'new_file_path' => FrmAppHelper::plugin_path() . '/css',
@@ -394,29 +144,22 @@
394 144 update_option( 'frmpro_css', $css, 'no' );
395 145 set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
396 146 }
397 147
398 - /**
399 - * @param string $filename
400 - * @return string
401 - */
402 148 private function get_css_content( $filename ) {
403 149 $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
404 150
405 - $saving = true;
151 + $saving = true;
406 152 $frm_style = $this;
407 153
408 - ob_start();
409 - include $filename;
154 + ob_start();
155 + include( $filename );
410 156 $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
411 - ob_end_clean();
157 + ob_end_clean();
412 158
413 - return FrmStylesController::replace_relative_url( $css );
159 + return $css;
414 160 }
415 161
416 - /**
417 - * @return void
418 - */
419 162 private function clear_cache() {
420 163 $default_post_atts = array(
421 164 'post_type' => FrmStylesController::$post_type,
422 165 'post_status' => 'publish',
@@ -424,111 +167,92 @@
424 167 'orderby' => 'title',
425 168 'order' => 'ASC',
426 169 );
427 170
428 - FrmDb::delete_cache_and_transient( json_encode( $default_post_atts ), 'frm_styles' );
171 + FrmDb::delete_cache_and_transient( serialize( $default_post_atts ), 'frm_styles' );
429 172 FrmDb::cache_delete_group( 'frm_styles' );
430 173 FrmDb::delete_cache_and_transient( 'frmpro_css' );
431 174 }
432 175
433 - /**
434 - * Delete a style by its post ID.
435 - *
436 - * @param int $id
437 - * @return WP_Post|false|null
438 - */
439 176 public function destroy( $id ) {
440 - if ( $id === $this->get_default_style()->ID ) {
441 - return false;
442 - }
443 177 return wp_delete_post( $id );
444 - }
178 + }
445 179
446 - /**
447 - * @return WP_Post|stdClass
448 - */
449 - public function get_one() {
450 - if ( 'default' === $this->id ) {
451 - $style = $this->get_default_style();
452 - if ( $style ) {
453 - $this->id = $style->ID;
454 - } else {
455 - $this->id = 0;
456 - }
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 + }
457 190
458 - return $style;
459 - }
460 -
461 191 $style = get_post( $this->id );
462 192
463 - if ( ! $style ) {
464 - return $style;
465 - }
193 + if ( ! $style ) {
194 + return $style;
195 + }
466 196
467 197 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
468 198
469 - $default_values = $this->get_defaults();
199 + $default_values = $this->get_defaults();
470 200
471 201 // fill default values
472 202 $style->post_content = $this->override_defaults( $style->post_content );
473 203 $style->post_content = wp_parse_args( $style->post_content, $default_values );
474 204
475 - return $style;
476 - }
205 + return $style;
206 + }
477 207
478 - /**
479 - * @param string $orderby
480 - * @param string $order
481 - * @param int $limit
482 - * @return array
483 - */
484 - public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
485 - $post_atts = array(
208 + public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
209 + $post_atts = array(
486 210 'post_type' => FrmStylesController::$post_type,
487 211 'post_status' => 'publish',
488 212 'numberposts' => $limit,
489 213 'orderby' => $orderby,
490 214 'order' => $order,
491 - );
215 + );
492 216
493 - $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' );
494 218
495 219 if ( empty( $temp_styles ) ) {
496 - global $wpdb;
497 - // make sure there wasn't a conflict with the query
498 - $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' );
499 223 $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
500 224
501 225 if ( empty( $temp_styles ) ) {
502 - // create a new style if there are none
503 - $new = $this->get_new();
226 + // create a new style if there are none
227 + $new = $this->get_new();
504 228 $new->post_title = __( 'Formidable Style', 'formidable' );
505 - $new->post_name = $new->post_title;
506 - $new->menu_order = 1;
507 - $new = $this->save( (array) $new );
229 + $new->post_name = $new->post_title;
230 + $new->menu_order = 1;
231 + $new = $this->save( (array) $new );
508 232 $this->update( 'default' );
509 233
510 - $post_atts['include'] = $new;
234 + $post_atts['include'] = $new;
511 235
512 - $temp_styles = get_posts( $post_atts );
513 - }
514 - }
236 + $temp_styles = get_posts( $post_atts );
237 + }
238 + }
515 239
516 - $default_values = $this->get_defaults();
517 - $default_style = false;
240 + $default_values = $this->get_defaults();
241 + $default_style = false;
518 242
519 - $styles = array();
520 - foreach ( $temp_styles as $style ) {
521 - $this->id = $style->ID;
522 - if ( $style->menu_order ) {
523 - if ( $default_style ) {
524 - // only return one default
525 - $style->menu_order = 0;
526 - } else {
527 - // check for a default style
528 - $default_style = $style->ID;
529 - }
530 - }
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 + }
531 255
532 256 $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
533 257
534 258 // fill default values
@@ -535,260 +259,226 @@
535 259 $style->post_content = $this->override_defaults( $style->post_content );
536 260 $style->post_content = wp_parse_args( $style->post_content, $default_values );
537 261
538 262 $styles[ $style->ID ] = $style;
539 - }
263 + }
540 264
541 - if ( ! $default_style ) {
265 + if ( ! $default_style ) {
542 266 $default_style = reset( $styles );
543 -
544 267 $styles[ $default_style->ID ]->menu_order = 1;
545 - }
268 + }
546 269
547 - return $styles;
548 - }
270 + return $styles;
271 + }
549 272
550 - /**
551 - * @param array|null $styles
552 - */
553 273 public function get_default_style( $styles = null ) {
554 274 if ( ! isset( $styles ) ) {
555 275 $styles = $this->get_all( 'menu_order', 'DESC', 1 );
556 - }
276 + }
557 277
558 - foreach ( $styles as $style ) {
559 - if ( $style->menu_order ) {
560 - return $style;
561 - }
562 - }
563 - }
278 + foreach ( $styles as $style ) {
279 + if ( $style->menu_order ) {
280 + return $style;
281 + }
282 + }
283 + }
564 284
565 - /**
566 - * @param mixed $settings
567 - * @return mixed
568 - */
569 285 public function override_defaults( $settings ) {
570 286 if ( ! is_array( $settings ) ) {
571 - return $settings;
572 - }
287 + return $settings;
288 + }
573 289
574 290 $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
575 291
576 292 if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
577 - $settings['form_desc_size'] = $settings['description_font_size'];
578 - $settings['form_desc_color'] = $settings['description_color'];
579 - $settings['title_color'] = $settings['label_color'];
580 - }
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 + }
581 297
582 298 if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) {
583 - $settings['section_color'] = $settings['label_color'];
584 - $settings['section_border_color'] = $settings['border_color'];
585 - }
299 + $settings['section_color'] = $settings['label_color'];
300 + $settings['section_border_color'] = $settings['border_color'];
301 + }
586 302
587 303 if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
588 - $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
589 - $settings['submit_hover_color'] = $settings['submit_text_color'];
590 - $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'];
591 307
592 - $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
593 - $settings['submit_active_color'] = $settings['submit_text_color'];
594 - $settings['submit_active_border_color'] = $settings['submit_border_color'];
595 - }
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 + }
596 312
597 - return apply_filters( 'frm_override_default_styles', $settings );
313 + return apply_filters( 'frm_override_default_styles', $settings );
598 314 }
599 315
600 - /**
601 - * @return array
602 - */
603 316 public function get_defaults() {
604 317 $defaults = array(
605 - 'theme_css' => 'ui-lightness',
606 - 'theme_name' => 'UI Lightness',
318 + 'theme_css' => 'ui-lightness',
319 + 'theme_name' => 'UI Lightness',
607 320
608 321 'center_form' => '',
609 - 'form_width' => '100%',
610 - 'form_align' => 'left',
611 - 'direction' => is_rtl() ? 'rtl' : 'ltr',
612 - 'fieldset' => '0px',
613 - 'fieldset_color' => '000000',
614 - 'fieldset_padding' => '0 0 15px 0',
615 - 'fieldset_bg_color' => '',
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' => '',
616 329
617 - 'title_size' => '40px',
618 - 'title_color' => '444444',
619 - 'title_margin_top' => '10px',
620 - 'title_margin_bottom' => '60px',
621 - 'form_desc_size' => '14px',
622 - 'form_desc_color' => '666666',
623 - 'form_desc_margin_top' => '10px',
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',
624 337 'form_desc_margin_bottom' => '25px',
625 - 'form_desc_padding' => '0',
626 338
627 - 'font' => '',
628 - 'font_size' => '15px',
629 - 'label_color' => '3f4b5b',
630 - 'weight' => 'normal',
631 - 'position' => 'none',
632 - 'align' => 'left',
633 - 'width' => '150px',
634 - 'required_color' => 'B94A48',
635 - 'required_weight' => 'bold',
636 - 'label_padding' => '0 0 3px 0',
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',
637 349
638 - 'description_font_size' => '12px',
639 - 'description_color' => '666666',
640 - 'description_weight' => 'normal',
641 - 'description_style' => 'normal',
642 - 'description_align' => 'left',
643 - 'description_margin' => '0',
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',
644 356
645 - 'field_font_size' => '14px',
646 - 'field_height' => '32px',
647 - 'line_height' => 'normal',
648 - 'field_width' => '100%',
649 - 'auto_width' => false,
650 - 'field_pad' => '6px 10px',
651 - 'field_margin' => '20px',
652 - 'field_weight' => 'normal',
653 - 'text_color' => '555555',
654 - //'border_color_hv' => 'cccccc',
655 - 'border_color' => 'BFC3C8',
656 - 'field_border_width' => '1px',
657 - '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',
658 370
659 - 'bg_color' => 'ffffff',
660 - //'bg_color_hv' => 'ffffff',
661 - 'remove_box_shadow' => '',
662 - 'bg_color_active' => 'ffffff',
663 - 'border_color_active' => '66afe9',
371 + 'bg_color' => 'ffffff',
372 + //'bg_color_hv' => 'ffffff',
373 + 'remove_box_shadow' => '',
374 + 'bg_color_active' => 'ffffff',
375 + 'border_color_active' => '66afe9',
664 376 'remove_box_shadow_active' => '',
665 - 'text_color_error' => '444444',
666 - 'bg_color_error' => 'ffffff',
667 - 'border_color_error' => 'B94A48',
668 - 'border_width_error' => '1px',
669 - 'border_style_error' => 'solid',
670 - 'bg_color_disabled' => 'ffffff',
671 - 'border_color_disabled' => 'E5E5E5',
672 - 'text_color_disabled' => 'A1A1A1',
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',
673 385
674 - 'radio_align' => 'block',
675 - 'check_align' => 'block',
676 - 'check_font_size' => '13px',
677 - 'check_label_color' => '444444',
678 - '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',
679 391
680 - 'section_font_size' => '18px',
681 - 'section_color' => '444444',
682 - 'section_weight' => 'bold',
683 - 'section_pad' => '15px 0 3px 0',
684 - 'section_mar_top' => '15px',
685 - 'section_mar_bottom' => '30px',
686 - 'section_bg_color' => '',
687 - 'section_border_color' => 'e8e8e8',
688 - 'section_border_width' => '2px',
689 - 'section_border_style' => 'solid',
690 - 'section_border_loc' => '-top',
691 - 'collapse_icon' => '6',
692 - 'collapse_pos' => 'after',
693 - 'repeat_icon' => '1',
694 - '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',
695 406
696 - 'submit_style' => false,
697 - 'submit_font_size' => '15px',
698 - 'submit_width' => 'auto',
699 - 'submit_height' => 'auto',
700 - 'submit_bg_color' => '579AF6',
701 - 'submit_border_color' => '579AF6',
702 - 'submit_border_width' => '1px',
703 - 'submit_text_color' => 'ffffff',
704 - 'submit_weight' => 'normal',
705 - 'submit_border_radius' => '4px',
706 - 'submit_bg_img' => '',
707 - 'submit_margin' => '10px',
708 - 'submit_padding' => '10px 20px',
709 - 'submit_shadow_color' => 'eeeeee',
710 - 'submit_hover_bg_color' => 'efefef',
711 - 'submit_hover_color' => '444444',
712 - 'submit_hover_border_color' => 'cccccc',
713 - 'submit_active_bg_color' => 'efefef',
714 - 'submit_active_color' => '444444',
715 - 'submit_active_border_color' => 'cccccc',
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',
716 427
717 - 'border_radius' => '4px',
718 - 'error_bg' => 'F2DEDE',
719 - 'error_border' => 'EBCCD1',
720 - 'error_text' => 'B94A48',
721 - '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',
722 433
723 - 'success_bg_color' => 'DFF0D8',
724 - 'success_border_color' => 'D6E9C6',
725 - 'success_text_color' => '468847',
726 - 'success_font_size' => '14px',
434 + 'success_bg_color' => 'DFF0D8',
435 + 'success_border_color' => 'D6E9C6',
436 + 'success_text_color' => '468847',
437 + 'success_font_size' => '14px',
727 438
728 - 'important_style' => false,
439 + 'important_style' => false,
729 440
730 - 'progress_bg_color' => 'eaeaea',
731 - 'progress_active_color' => 'ffffff',
732 - 'progress_active_bg_color' => '579AF6',
733 - 'progress_color' => '3f4b5b',
734 - 'progress_border_color' => 'E5E5E5',
735 - 'progress_border_size' => '2px',
736 - 'progress_size' => '24px',
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',
737 448
738 - 'custom_css' => '',
449 + 'custom_css' => '',
739 450 );
740 -
741 451 return apply_filters( 'frm_default_style_settings', $defaults );
742 - }
452 + }
743 453
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 454 public function get_field_name( $field_name, $post_field = 'post_content' ) {
752 455 return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
753 456 }
754 457
755 - /**
756 - * @return array
757 - */
758 458 public static function get_bold_options() {
759 459 return array(
760 - 100 => 100,
761 - 200 => 200,
762 - 300 => 300,
460 + 100 => 100,
461 + 200 => 200,
462 + 300 => 300,
763 463 'normal' => __( 'normal', 'formidable' ),
764 - 500 => 500,
765 - 600 => 600,
766 - 'bold' => __( 'bold', 'formidable' ),
767 - 800 => 800,
768 - 900 => 900,
464 + 500 => 500,
465 + 600 => 600,
466 + 'bold' => __( 'bold', 'formidable' ),
467 + 800 => 800,
468 + 900 => 900,
769 469 );
770 470 }
771 471
772 472 /**
773 - * Don't let imbalanced font families ruin the whole stylesheet.
774 - *
775 - * @param string $value
776 - * @return string
473 + * Don't let imbalanced font families ruin the whole stylesheet
777 474 */
778 475 public function force_balanced_quotation( $value ) {
779 476 $balanced_characters = array( '"', "'" );
780 477 foreach ( $balanced_characters as $char ) {
781 - $char_count = substr_count( $value, $char );
478 + $char_count = substr_count( $value, $char );
782 479 $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 {
480 + if ( ! $is_balanced ) {
791 481 $value .= $char;
792 482 }
793 483 }
794 484 return $value;