| @@ -3,35 +3,14 @@ | ||
| 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 | |
| @@ -41,11 +20,10 @@ | ||
| 41 | 20 | public function get_new() { |
| 42 | 21 | $this->id = 0; |
| 43 | 22 | |
| 44 | 23 | $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 ); | |
| 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 ); | |
| 48 | 26 | |
| 49 | 27 | $style = array( |
| 50 | 28 | 'post_type' => FrmStylesController::$post_type, |
| 51 | 29 | 'ID' => '', |
| @@ -60,9 +38,8 @@ | ||
| 60 | 38 | } |
| 61 | 39 | |
| 62 | 40 | /** |
| 63 | 41 | * @param array $settings |
| 64 | - * | |
| 65 | 42 | * @return int|WP_Error |
| 66 | 43 | */ |
| 67 | 44 | public function save( $settings ) { |
| 68 | 45 | return FrmDb::save_settings( $settings, 'frm_styles' ); |
| @@ -68,10 +45,8 @@ | ||
| 68 | 45 | return FrmDb::save_settings( $settings, 'frm_styles' ); |
| 69 | 46 | } |
| 70 | 47 | |
| 71 | 48 | /** |
| 72 | - * @param int|string $id The id of the stylesheet or 'default'. | |
| 73 | - * | |
| 74 | 49 | * @return void |
| 75 | 50 | */ |
| 76 | 51 | public function duplicate( $id ) { |
| 77 | 52 | // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead. |
| @@ -80,14 +55,12 @@ | ||
| 80 | 55 | /** |
| 81 | 56 | * Handle save actions in the visual styler edit page. |
| 82 | 57 | * |
| 83 | 58 | * @param mixed $id |
| 84 | - * | |
| 85 | 59 | * @return array<int|WP_Error> |
| 86 | 60 | */ |
| 87 | 61 | public function update( $id = 'default' ) { |
| 88 | - $all_instances = $this->get_all(); | |
| 89 | - $css_scope_helper = new FrmCssScopeHelper(); | |
| 62 | + $all_instances = $this->get_all(); | |
| 90 | 63 | |
| 91 | 64 | if ( ! $id ) { |
| 92 | 65 | $new_style = (array) $this->get_new(); |
| 93 | 66 | $all_instances[] = $new_style; |
| @@ -94,9 +67,9 @@ | ||
| 94 | 67 | } |
| 95 | 68 | |
| 96 | 69 | $action_ids = array(); |
| 97 | 70 | |
| 98 | - foreach ( $all_instances as $new_instance ) { | |
| 71 | + foreach ( $all_instances as $number => $new_instance ) { | |
| 99 | 72 | $new_instance = (array) $new_instance; |
| 100 | 73 | $this->id = $new_instance['ID']; |
| 101 | 74 | |
| 102 | 75 | if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -105,9 +78,9 @@ | ||
| 105 | 78 | } |
| 106 | 79 | |
| 107 | 80 | // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing. |
| 108 | 81 | // 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'] ?? ''; | |
| 82 | + $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : ''; | |
| 110 | 83 | |
| 111 | 84 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 112 | 85 | if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) { |
| 113 | 86 | // The nonce check happens in FrmStylesController::save_style before this is called. |
| @@ -118,16 +91,11 @@ | ||
| 118 | 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 |
| 119 | 92 | $new_instance['post_content']['custom_css'] = $custom_css; |
| 120 | 93 | unset( $custom_css ); |
| 121 | 94 | |
| 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 | - } | |
| 95 | + $new_instance['post_type'] = FrmStylesController::$post_type; | |
| 96 | + $new_instance['post_status'] = 'publish'; | |
| 126 | 97 | |
| 127 | - $new_instance['post_type'] = FrmStylesController::$post_type; | |
| 128 | - $new_instance['post_status'] = 'publish'; | |
| 129 | - | |
| 130 | 98 | if ( ! $id ) { |
| 131 | 99 | $new_instance['post_name'] = $new_instance['post_title']; |
| 132 | 100 | } |
| 133 | 101 | |
| @@ -139,9 +107,8 @@ | ||
| 139 | 107 | } |
| 140 | 108 | |
| 141 | 109 | if ( $this->is_color( $setting ) ) { |
| 142 | 110 | $color_val = $new_instance['post_content'][ $setting ]; |
| 143 | - | |
| 144 | 111 | if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) { |
| 145 | 112 | // Maybe sanitize if invalid rgba value is entered. |
| 146 | 113 | $this->maybe_sanitize_rgba_value( $color_val ); |
| 147 | 114 | } |
| @@ -152,12 +119,10 @@ | ||
| 152 | 119 | $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] ); |
| 153 | 120 | } |
| 154 | 121 | } |
| 155 | 122 | |
| 156 | - $new_instance['post_content'] = FrmStylesHelper::update_base_font_size( $new_instance['post_content'], $this->get_defaults() ); | |
| 157 | - | |
| 158 | 123 | $action_ids[] = $this->save( $new_instance ); |
| 159 | - }//end foreach | |
| 124 | + } | |
| 160 | 125 | |
| 161 | 126 | $this->save_settings(); |
| 162 | 127 | |
| 163 | 128 | return $action_ids; |
| @@ -167,10 +132,9 @@ | ||
| 167 | 132 | * Sanitize custom color values and convert it to valid one filling missing values. |
| 168 | 133 | * |
| 169 | 134 | * @since 5.3.2 |
| 170 | 135 | * |
| 171 | - * @param string $color_val The color value, by reference. | |
| 172 | - * | |
| 136 | + * @param string $color_val, The color value, by reference. | |
| 173 | 137 | * @return void |
| 174 | 138 | */ |
| 175 | 139 | private function maybe_sanitize_rgba_value( &$color_val ) { |
| 176 | 140 | if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) { |
| @@ -177,12 +141,10 @@ | ||
| 177 | 141 | return; |
| 178 | 142 | } |
| 179 | 143 | |
| 180 | 144 | $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, '(' ); | |
| 145 | + $color_val = ltrim( $color_val, '(' ); // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces. | |
| 183 | 146 | $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' ); |
| 184 | - | |
| 185 | 147 | foreach ( $patterns as $pattern ) { |
| 186 | 148 | if ( preg_match( $pattern, $color_val ) === 1 ) { |
| 187 | 149 | return; |
| 188 | 150 | } |
| @@ -191,11 +153,10 @@ | ||
| 191 | 153 | // Remove all leading ')' braces, then add one back. This way there's always a single brace. |
| 192 | 154 | $color_val = rtrim( $color_val, ')' ); |
| 193 | 155 | $color_val .= ')'; |
| 194 | 156 | |
| 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, '()' ); | |
| 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((. | |
| 198 | 159 | $length_of_color_codes = strpos( $color_val, '(' ); |
| 199 | 160 | $new_color_values = array(); |
| 200 | 161 | |
| 201 | 162 | // replace empty values by 0 or 1 (if alpha position). |
| @@ -222,16 +183,15 @@ | ||
| 222 | 183 | $new_value = 1; |
| 223 | 184 | } else { |
| 224 | 185 | $new_value = floatval( $value ); |
| 225 | 186 | } |
| 226 | - }//end if | |
| 187 | + } | |
| 227 | 188 | |
| 228 | - $new_color_values[] = $new_value; | |
| 229 | - }//end foreach | |
| 189 | + $new_color_values[] = null === $new_value ? $value : $new_value; | |
| 190 | + } | |
| 230 | 191 | |
| 231 | 192 | // add more 0s and 1 (if alpha position) if needed. |
| 232 | 193 | $missing_values = $length_of_color_codes - count( $new_color_values ); |
| 233 | - | |
| 234 | 194 | if ( $missing_values > 1 ) { |
| 235 | 195 | $insert_values = array_fill( 0, $missing_values - 1, 0 ); |
| 236 | 196 | $last_value = 4 === $length_of_color_codes ? 1 : 0; |
| 237 | 197 | array_push( $insert_values, $last_value ); |
| @@ -237,9 +197,8 @@ | ||
| 237 | 197 | array_push( $insert_values, $last_value ); |
| 238 | 198 | } elseif ( $missing_values === 1 ) { |
| 239 | 199 | $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 ); |
| 240 | 200 | } |
| 241 | - | |
| 242 | 201 | if ( ! empty( $insert_values ) ) { |
| 243 | 202 | $new_color_values = array_merge( $new_color_values, $insert_values ); |
| 244 | 203 | } |
| 245 | 204 | |
| @@ -244,10 +203,9 @@ | ||
| 244 | 203 | } |
| 245 | 204 | |
| 246 | 205 | $new_color = implode( ',', $new_color_values ); |
| 247 | 206 | $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, '(' ) . '('; | |
| 207 | + $prefix = rtrim( $prefix, '(' ) . '('; // Limit the number of opening braces after rgb/rgba. There should only be one. | |
| 250 | 208 | $new_color = $prefix . $new_color . ')'; |
| 251 | 209 | |
| 252 | 210 | $color_val = $new_color; |
| 253 | 211 | } |
| @@ -252,12 +210,26 @@ | ||
| 252 | 210 | $color_val = $new_color; |
| 253 | 211 | } |
| 254 | 212 | |
| 255 | 213 | /** |
| 214 | + * Unslash everything in post_content but custom_css | |
| 215 | + * | |
| 256 | 216 | * @since 5.0.13 |
| 257 | 217 | * |
| 258 | 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 | |
| 259 | 230 | * |
| 231 | + * @param array $settings | |
| 260 | 232 | * @return array |
| 261 | 233 | */ |
| 262 | 234 | public function sanitize_post_content( $settings ) { |
| 263 | 235 | $defaults = $this->get_defaults(); |
| @@ -262,9 +234,8 @@ | ||
| 262 | 234 | public function sanitize_post_content( $settings ) { |
| 263 | 235 | $defaults = $this->get_defaults(); |
| 264 | 236 | $valid_keys = array_keys( $defaults ); |
| 265 | 237 | $sanitized_settings = array(); |
| 266 | - | |
| 267 | 238 | foreach ( $valid_keys as $key ) { |
| 268 | 239 | if ( isset( $settings[ $key ] ) ) { |
| 269 | 240 | $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] ); |
| 270 | 241 | } else { |
| @@ -269,123 +240,16 @@ | ||
| 269 | 240 | $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] ); |
| 270 | 241 | } else { |
| 271 | 242 | $sanitized_settings[ $key ] = $defaults[ $key ]; |
| 272 | 243 | } |
| 273 | - | |
| 274 | - if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) { | |
| 275 | - $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] ); | |
| 276 | - } | |
| 277 | 244 | } |
| 278 | 245 | return $sanitized_settings; |
| 279 | 246 | } |
| 280 | 247 | |
| 281 | 248 | /** |
| 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 | 249 | * @since 3.01.01 |
| 385 | 250 | * |
| 386 | 251 | * @param string $setting |
| 387 | - * | |
| 388 | 252 | * @return bool |
| 389 | 253 | */ |
| 390 | 254 | private function is_color( $setting ) { |
| 391 | 255 | $extra_colors = array( 'error_bg', 'error_border', 'error_text' ); |
| @@ -433,9 +297,8 @@ | ||
| 433 | 297 | } |
| 434 | 298 | |
| 435 | 299 | /** |
| 436 | 300 | * @param string $filename |
| 437 | - * | |
| 438 | 301 | * @return string |
| 439 | 302 | */ |
| 440 | 303 | private function get_css_content( $filename ) { |
| 441 | 304 | $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; |
| @@ -471,10 +334,9 @@ | ||
| 471 | 334 | /** |
| 472 | 335 | * Delete a style by its post ID. |
| 473 | 336 | * |
| 474 | 337 | * @param int $id |
| 475 | - * | |
| 476 | - * @return false|WP_Post|null | |
| 338 | + * @return WP_Post|false|null | |
| 477 | 339 | */ |
| 478 | 340 | public function destroy( $id ) { |
| 479 | 341 | if ( $id === $this->get_default_style()->ID ) { |
| 480 | 342 | return false; |
| @@ -482,14 +344,13 @@ | ||
| 482 | 344 | return wp_delete_post( $id ); |
| 483 | 345 | } |
| 484 | 346 | |
| 485 | 347 | /** |
| 486 | - * @return stdClass|WP_Post | |
| 348 | + * @return WP_Post|stdClass | |
| 487 | 349 | */ |
| 488 | 350 | public function get_one() { |
| 489 | 351 | if ( 'default' === $this->id ) { |
| 490 | 352 | $style = $this->get_default_style(); |
| 491 | - | |
| 492 | 353 | if ( $style ) { |
| 493 | 354 | $this->id = $style->ID; |
| 494 | 355 | } else { |
| 495 | 356 | $this->id = 0; |
| @@ -518,9 +379,8 @@ | ||
| 518 | 379 | /** |
| 519 | 380 | * @param string $orderby |
| 520 | 381 | * @param string $order |
| 521 | 382 | * @param int $limit |
| 522 | - * | |
| 523 | 383 | * @return array |
| 524 | 384 | */ |
| 525 | 385 | public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { |
| 526 | 386 | $post_atts = array( |
| @@ -557,12 +417,10 @@ | ||
| 557 | 417 | $default_values = $this->get_defaults(); |
| 558 | 418 | $default_style = false; |
| 559 | 419 | |
| 560 | 420 | $styles = array(); |
| 561 | - | |
| 562 | 421 | foreach ( $temp_styles as $style ) { |
| 563 | 422 | $this->id = $style->ID; |
| 564 | - | |
| 565 | 423 | if ( $style->menu_order ) { |
| 566 | 424 | if ( $default_style ) { |
| 567 | 425 | // only return one default |
| 568 | 426 | $style->menu_order = 0; |
| @@ -578,9 +436,9 @@ | ||
| 578 | 436 | $style->post_content = $this->override_defaults( $style->post_content ); |
| 579 | 437 | $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
| 580 | 438 | |
| 581 | 439 | $styles[ $style->ID ] = $style; |
| 582 | - }//end foreach | |
| 440 | + } | |
| 583 | 441 | |
| 584 | 442 | if ( ! $default_style ) { |
| 585 | 443 | $default_style = reset( $styles ); |
| 586 | 444 | |
| @@ -591,10 +449,8 @@ | ||
| 591 | 449 | } |
| 592 | 450 | |
| 593 | 451 | /** |
| 594 | 452 | * @param array|null $styles |
| 595 | - * | |
| 596 | - * @return object|null | |
| 597 | 453 | */ |
| 598 | 454 | public function get_default_style( $styles = null ) { |
| 599 | 455 | if ( ! isset( $styles ) ) { |
| 600 | 456 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
| @@ -608,9 +464,8 @@ | ||
| 608 | 464 | } |
| 609 | 465 | |
| 610 | 466 | /** |
| 611 | 467 | * @param mixed $settings |
| 612 | - * | |
| 613 | 468 | * @return mixed |
| 614 | 469 | */ |
| 615 | 470 | public function override_defaults( $settings ) { |
| 616 | 471 | if ( ! is_array( $settings ) ) { |
| @@ -616,9 +471,9 @@ | ||
| 616 | 471 | if ( ! is_array( $settings ) ) { |
| 617 | 472 | return $settings; |
| 618 | 473 | } |
| 619 | 474 | |
| 620 | - $settings['line_height'] = ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] === 'auto' ? 'normal' : $settings['field_height']; | |
| 475 | + $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height']; | |
| 621 | 476 | |
| 622 | 477 | if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) { |
| 623 | 478 | $settings['form_desc_size'] = $settings['description_font_size']; |
| 624 | 479 | $settings['form_desc_color'] = $settings['description_color']; |
| @@ -647,147 +502,142 @@ | ||
| 647 | 502 | * @return array |
| 648 | 503 | */ |
| 649 | 504 | public function get_defaults() { |
| 650 | 505 | $defaults = array( |
| 651 | - 'theme_css' => 'ui-lightness', | |
| 652 | - 'theme_name' => 'UI Lightness', | |
| 506 | + 'theme_css' => 'ui-lightness', | |
| 507 | + 'theme_name' => 'UI Lightness', | |
| 653 | 508 | |
| 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' => '', | |
| 509 | + 'center_form' => '', | |
| 510 | + 'form_width' => '100%', | |
| 511 | + 'form_align' => 'left', | |
| 512 | + 'direction' => is_rtl() ? 'rtl' : 'ltr', | |
| 513 | + 'fieldset' => '0px', | |
| 514 | + 'fieldset_color' => '000000', | |
| 515 | + 'fieldset_padding' => '0 0 15px 0', | |
| 516 | + 'fieldset_bg_color' => '', | |
| 662 | 517 | |
| 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', | |
| 518 | + 'title_size' => '40px', | |
| 519 | + 'title_color' => '444444', | |
| 520 | + 'title_margin_top' => '10px', | |
| 521 | + 'title_margin_bottom' => '60px', | |
| 522 | + 'form_desc_size' => '14px', | |
| 523 | + 'form_desc_color' => '666666', | |
| 524 | + 'form_desc_margin_top' => '10px', | |
| 525 | + 'form_desc_margin_bottom' => '25px', | |
| 526 | + 'form_desc_padding' => '0', | |
| 672 | 527 | |
| 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', | |
| 528 | + 'font' => '', | |
| 529 | + 'font_size' => '15px', | |
| 530 | + 'label_color' => '3f4b5b', | |
| 531 | + 'weight' => 'normal', | |
| 532 | + 'position' => 'none', | |
| 533 | + 'align' => 'left', | |
| 534 | + 'width' => '150px', | |
| 535 | + 'required_color' => 'B94A48', | |
| 536 | + 'required_weight' => 'bold', | |
| 537 | + 'label_padding' => '0 0 3px 0', | |
| 683 | 538 | |
| 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', | |
| 539 | + 'description_font_size' => '12px', | |
| 540 | + 'description_color' => '666666', | |
| 541 | + 'description_weight' => 'normal', | |
| 542 | + 'description_style' => 'normal', | |
| 543 | + 'description_align' => 'left', | |
| 544 | + 'description_margin' => '0', | |
| 690 | 545 | |
| 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', | |
| 546 | + 'field_font_size' => '14px', | |
| 547 | + 'field_height' => '32px', | |
| 548 | + 'line_height' => 'normal', | |
| 549 | + 'field_width' => '100%', | |
| 550 | + 'auto_width' => false, | |
| 551 | + 'field_pad' => '6px 10px', | |
| 552 | + 'field_margin' => '20px', | |
| 553 | + 'field_weight' => 'normal', | |
| 554 | + 'text_color' => '555555', | |
| 555 | + //'border_color_hv' => 'cccccc', | |
| 556 | + 'border_color' => 'BFC3C8', | |
| 557 | + 'field_border_width' => '1px', | |
| 558 | + 'field_border_style' => 'solid', | |
| 704 | 559 | |
| 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', | |
| 560 | + 'bg_color' => 'ffffff', | |
| 561 | + //'bg_color_hv' => 'ffffff', | |
| 562 | + 'remove_box_shadow' => '', | |
| 563 | + 'bg_color_active' => 'ffffff', | |
| 564 | + 'border_color_active' => '66afe9', | |
| 565 | + 'remove_box_shadow_active' => '', | |
| 566 | + 'text_color_error' => '444444', | |
| 567 | + 'bg_color_error' => 'ffffff', | |
| 568 | + 'border_color_error' => 'B94A48', | |
| 569 | + 'border_width_error' => '1px', | |
| 570 | + 'border_style_error' => 'solid', | |
| 571 | + 'bg_color_disabled' => 'ffffff', | |
| 572 | + 'border_color_disabled' => 'E5E5E5', | |
| 573 | + 'text_color_disabled' => 'A1A1A1', | |
| 719 | 574 | |
| 720 | - 'radio_align' => 'block', | |
| 721 | - 'check_align' => 'block', | |
| 722 | - 'check_font_size' => '14px', | |
| 723 | - 'check_label_color' => '1D2939', | |
| 724 | - 'check_weight' => 'normal', | |
| 575 | + 'radio_align' => 'block', | |
| 576 | + 'check_align' => 'block', | |
| 577 | + 'check_font_size' => '13px', | |
| 578 | + 'check_label_color' => '444444', | |
| 579 | + 'check_weight' => 'normal', | |
| 725 | 580 | |
| 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', | |
| 581 | + 'section_font_size' => '18px', | |
| 582 | + 'section_color' => '444444', | |
| 583 | + 'section_weight' => 'bold', | |
| 584 | + 'section_pad' => '15px 0 3px 0', | |
| 585 | + 'section_mar_top' => '15px', | |
| 586 | + 'section_mar_bottom' => '30px', | |
| 587 | + 'section_bg_color' => '', | |
| 588 | + 'section_border_color' => 'e8e8e8', | |
| 589 | + 'section_border_width' => '2px', | |
| 590 | + 'section_border_style' => 'solid', | |
| 591 | + 'section_border_loc' => '-top', | |
| 592 | + 'collapse_icon' => '6', | |
| 593 | + 'collapse_pos' => 'after', | |
| 594 | + 'repeat_icon' => '1', | |
| 595 | + 'repeat_icon_color' => 'ffffff', | |
| 741 | 596 | |
| 742 | 597 | 'submit_style' => false, |
| 743 | - 'submit_font_size' => '14px', | |
| 598 | + 'submit_font_size' => '15px', | |
| 744 | 599 | 'submit_width' => 'auto', |
| 745 | 600 | 'submit_height' => 'auto', |
| 746 | - 'submit_bg_color' => '4199FD', | |
| 747 | - 'submit_border_color' => '4199FD', | |
| 601 | + 'submit_bg_color' => '579AF6', | |
| 602 | + 'submit_border_color' => '579AF6', | |
| 748 | 603 | 'submit_border_width' => '1px', |
| 749 | 604 | 'submit_text_color' => 'ffffff', |
| 750 | 605 | 'submit_weight' => 'normal', |
| 751 | - 'submit_border_radius' => '8px', | |
| 606 | + 'submit_border_radius' => '4px', | |
| 752 | 607 | 'submit_bg_img' => '', |
| 753 | 608 | 'submit_margin' => '10px', |
| 754 | - 'submit_padding' => '8px 16px', | |
| 609 | + 'submit_padding' => '10px 20px', | |
| 755 | 610 | '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', | |
| 611 | + 'submit_hover_bg_color' => 'efefef', | |
| 612 | + 'submit_hover_color' => '444444', | |
| 613 | + 'submit_hover_border_color' => 'cccccc', | |
| 614 | + 'submit_active_bg_color' => 'efefef', | |
| 615 | + 'submit_active_color' => '444444', | |
| 616 | + 'submit_active_border_color' => 'cccccc', | |
| 762 | 617 | |
| 763 | - 'border_radius' => '8px', | |
| 764 | - 'error_bg' => 'FEE4E2', | |
| 765 | - 'error_border' => 'F5B8AA', | |
| 766 | - 'error_text' => 'F04438', | |
| 767 | - 'error_font_size' => '14px', | |
| 618 | + 'border_radius' => '4px', | |
| 619 | + 'error_bg' => 'F2DEDE', | |
| 620 | + 'error_border' => 'EBCCD1', | |
| 621 | + 'error_text' => 'B94A48', | |
| 622 | + 'error_font_size' => '14px', | |
| 768 | 623 | |
| 769 | - 'success_bg_color' => 'DFF0D8', | |
| 770 | - 'success_border_color' => 'D6E9C6', | |
| 771 | - 'success_text_color' => '468847', | |
| 772 | - 'success_font_size' => '14px', | |
| 624 | + 'success_bg_color' => 'DFF0D8', | |
| 625 | + 'success_border_color' => 'D6E9C6', | |
| 626 | + 'success_text_color' => '468847', | |
| 627 | + 'success_font_size' => '14px', | |
| 773 | 628 | |
| 774 | - 'important_style' => false, | |
| 629 | + 'important_style' => false, | |
| 775 | 630 | |
| 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', | |
| 631 | + 'progress_bg_color' => 'eaeaea', | |
| 632 | + 'progress_active_color' => 'ffffff', | |
| 633 | + 'progress_active_bg_color' => '579AF6', | |
| 634 | + 'progress_color' => '3f4b5b', | |
| 635 | + 'progress_border_color' => 'E5E5E5', | |
| 636 | + 'progress_border_size' => '2px', | |
| 637 | + 'progress_size' => '24px', | |
| 787 | 638 | |
| 788 | - 'enable_style_custom_css' => false, | |
| 789 | - 'single_style_custom_css' => '', | |
| 639 | + 'custom_css' => '', | |
| 790 | 640 | ); |
| 791 | 641 | |
| 792 | 642 | return apply_filters( 'frm_default_style_settings', $defaults ); |
| 793 | 643 | } |
| @@ -796,9 +646,8 @@ | ||
| 796 | 646 | * Get a name attribute value for a style setting input. |
| 797 | 647 | * |
| 798 | 648 | * @param string $field_name |
| 799 | 649 | * @param string $post_field |
| 800 | - * | |
| 801 | 650 | * @return string |
| 802 | 651 | */ |
| 803 | 652 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 804 | 653 | return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']'; |
| @@ -808,61 +657,35 @@ | ||
| 808 | 657 | * @return array |
| 809 | 658 | */ |
| 810 | 659 | public static function get_bold_options() { |
| 811 | 660 | 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' ), | |
| 661 | + 100 => 100, | |
| 662 | + 200 => 200, | |
| 663 | + 300 => 300, | |
| 664 | + 'normal' => __( 'normal', 'formidable' ), | |
| 665 | + 500 => 500, | |
| 666 | + 600 => 600, | |
| 667 | + 'bold' => __( 'bold', 'formidable' ), | |
| 668 | + 800 => 800, | |
| 669 | + 900 => 900, | |
| 821 | 670 | ); |
| 822 | 671 | } |
| 823 | 672 | |
| 824 | 673 | /** |
| 825 | - * Don't let imbalanced font families ruin the whole stylesheet. | |
| 674 | + * Don't let imbalanced font families ruin the whole stylesheet | |
| 826 | 675 | * |
| 827 | 676 | * @param string $value |
| 828 | - * | |
| 829 | 677 | * @return string |
| 830 | 678 | */ |
| 831 | 679 | public function force_balanced_quotation( $value ) { |
| 832 | 680 | $balanced_characters = array( '"', "'" ); |
| 833 | - | |
| 834 | 681 | foreach ( $balanced_characters as $char ) { |
| 835 | 682 | $char_count = substr_count( $value, $char ); |
| 836 | 683 | $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 { | |
| 684 | + if ( ! $is_balanced ) { | |
| 845 | 685 | $value .= $char; |
| 846 | 686 | } |
| 847 | 687 | } |
| 688 | + | |
| 848 | 689 | 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 | 690 | } |
| 868 | 691 | } |