| @@ -4,14 +4,10 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmStylesHelper { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * @return array | |
| 10 | - */ | |
| 11 | 8 | public static function get_upload_base() { |
| 12 | 9 | $uploads = wp_upload_dir(); |
| 13 | - | |
| 14 | 10 | if ( is_ssl() && ! preg_match( '/^https:\/\/.*\..*$/', $uploads['baseurl'] ) ) { |
| 15 | 11 | $uploads['baseurl'] = str_replace( 'http://', 'https://', $uploads['baseurl'] ); |
| 16 | 12 | } |
| 17 | 13 | |
| @@ -21,10 +17,8 @@ | ||
| 21 | 17 | /** |
| 22 | 18 | * Called from the admin header. |
| 23 | 19 | * |
| 24 | 20 | * @since 4.0 |
| 25 | - * | |
| 26 | - * @return void | |
| 27 | 21 | */ |
| 28 | 22 | public static function save_button() { |
| 29 | 23 | ?> |
| 30 | 24 | <input type="submit" name="submit" class="button button-primary frm-button-primary" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" /> |
| @@ -32,10 +26,8 @@ | ||
| 32 | 26 | } |
| 33 | 27 | |
| 34 | 28 | /** |
| 35 | 29 | * @since 2.05 |
| 36 | - * | |
| 37 | - * @return array | |
| 38 | 30 | */ |
| 39 | 31 | public static function get_css_label_positions() { |
| 40 | 32 | return array( |
| 41 | 33 | 'none' => __( 'top', 'formidable' ), |
| @@ -74,11 +66,8 @@ | ||
| 74 | 66 | */ |
| 75 | 67 | return apply_filters( 'frm_single_label_positions', $label_positions, $field ); |
| 76 | 68 | } |
| 77 | 69 | |
| 78 | - /** | |
| 79 | - * @return array | |
| 80 | - */ | |
| 81 | 70 | public static function minus_icons() { |
| 82 | 71 | return array( |
| 83 | 72 | 0 => array( |
| 84 | 73 | '-' => '62e', |
| @@ -102,11 +91,8 @@ | ||
| 102 | 91 | ), |
| 103 | 92 | ); |
| 104 | 93 | } |
| 105 | 94 | |
| 106 | - /** | |
| 107 | - * @return array | |
| 108 | - */ | |
| 109 | 95 | public static function arrow_icons() { |
| 110 | 96 | $minus_icons = self::minus_icons(); |
| 111 | 97 | |
| 112 | 98 | return array( |
| @@ -147,13 +133,8 @@ | ||
| 147 | 133 | } |
| 148 | 134 | |
| 149 | 135 | /** |
| 150 | 136 | * @since 2.0 |
| 151 | - * | |
| 152 | - * @param int|string $key Icon key. | |
| 153 | - * @param string $icon Icon state, `+` or `-`. | |
| 154 | - * @param string $type Icon type, such as `arrow`. | |
| 155 | - * | |
| 156 | 137 | * @return string The class for this icon. |
| 157 | 138 | */ |
| 158 | 139 | public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) { |
| 159 | 140 | if ( 'arrow' === $type && is_numeric( $key ) ) { |
| @@ -175,9 +156,8 @@ | ||
| 175 | 156 | |
| 176 | 157 | if ( $key ) { |
| 177 | 158 | $class .= $key; |
| 178 | 159 | } |
| 179 | - | |
| 180 | 160 | $class .= '_icon'; |
| 181 | 161 | |
| 182 | 162 | return $class; |
| 183 | 163 | } |
| @@ -185,9 +165,8 @@ | ||
| 185 | 165 | /** |
| 186 | 166 | * @param WP_Post $style |
| 187 | 167 | * @param FrmStyle $frm_style |
| 188 | 168 | * @param string $type |
| 189 | - * | |
| 190 | 169 | * @return void |
| 191 | 170 | */ |
| 192 | 171 | public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) { |
| 193 | 172 | $function_name = $type . '_icons'; |
| @@ -228,9 +207,8 @@ | ||
| 228 | 207 | * |
| 229 | 208 | * @since 2.0 |
| 230 | 209 | * |
| 231 | 210 | * @param string $color Color setting value. This could be hex or rgb. |
| 232 | - * | |
| 233 | 211 | * @return string RGB value without the rgb() wrapper. |
| 234 | 212 | */ |
| 235 | 213 | public static function hex2rgb( $color ) { |
| 236 | 214 | if ( 0 === strpos( $color, 'rgb' ) ) { |
| @@ -246,15 +224,13 @@ | ||
| 246 | 224 | * |
| 247 | 225 | * @since 6.8.3 |
| 248 | 226 | * |
| 249 | 227 | * @param string $rgb RGB value including the rgb() or rgba() wrapper. |
| 250 | - * | |
| 251 | 228 | * @return array<string> including three numeric values for R, G, and B. |
| 252 | 229 | */ |
| 253 | 230 | private static function get_rgb_array_from_rgb( $rgb ) { |
| 254 | 231 | $rgb = str_replace( array( 'rgb(', 'rgba(', ')' ), '', $rgb ); |
| 255 | 232 | $rgb = explode( ',', $rgb ); |
| 256 | - | |
| 257 | 233 | if ( 4 === count( $rgb ) ) { |
| 258 | 234 | // Drop the alpha. The function is expected to only return r,g,b with no alpha. |
| 259 | 235 | array_pop( $rgb ); |
| 260 | 236 | } |
| @@ -266,9 +242,8 @@ | ||
| 266 | 242 | * |
| 267 | 243 | * @since 6.8.3 |
| 268 | 244 | * |
| 269 | 245 | * @param string $hex A hex color string. |
| 270 | - * | |
| 271 | 246 | * @return array<string> Including three numeric values for R, G, and B. |
| 272 | 247 | */ |
| 273 | 248 | private static function get_rgb_array_from_hex( $hex ) { |
| 274 | 249 | $hex = str_replace( '#', '', $hex ); |
| @@ -277,13 +252,8 @@ | ||
| 277 | 252 | } |
| 278 | 253 | |
| 279 | 254 | /** |
| 280 | 255 | * @since 4.0 |
| 281 | - * | |
| 282 | - * @param string $hex Hex color string. | |
| 283 | - * @param float|int|string $a Alpha channel value. | |
| 284 | - * | |
| 285 | - * @return string | |
| 286 | 256 | */ |
| 287 | 257 | public static function hex2rgba( $hex, $a ) { |
| 288 | 258 | $rgb = self::hex2rgb( $hex ); |
| 289 | 259 | |
| @@ -293,9 +263,8 @@ | ||
| 293 | 263 | /** |
| 294 | 264 | * @since 6.0 |
| 295 | 265 | * |
| 296 | 266 | * @param string $rgba Color setting value. This could be hex or rgb. |
| 297 | - * | |
| 298 | 267 | * @return string Hex color value. |
| 299 | 268 | */ |
| 300 | 269 | private static function rgb_to_hex( $rgba ) { |
| 301 | 270 | if ( strpos( $rgba, '#' ) === 0 ) { |
| @@ -309,9 +278,8 @@ | ||
| 309 | 278 | /** |
| 310 | 279 | * @since 6.8 |
| 311 | 280 | * |
| 312 | 281 | * @param string $hsl |
| 313 | - * | |
| 314 | 282 | * @return string|null Null if it fails to parse the HSL string. |
| 315 | 283 | */ |
| 316 | 284 | private static function hsl_to_hex( $hsl ) { |
| 317 | 285 | // Convert hsla to hsl. |
| @@ -370,13 +338,10 @@ | ||
| 370 | 338 | } |
| 371 | 339 | |
| 372 | 340 | /** |
| 373 | 341 | * @since 2.3 |
| 374 | - * | |
| 375 | 342 | * @param string $hex string The original color in hex format #ffffff. |
| 376 | 343 | * @param int $steps integer Should be between -255 and 255. Negative = darker, positive = lighter. |
| 377 | - * | |
| 378 | - * @return string | |
| 379 | 344 | */ |
| 380 | 345 | public static function adjust_brightness( $hex, $steps ) { |
| 381 | 346 | $steps = max( - 255, min( 255, $steps ) ); |
| 382 | 347 | |
| @@ -413,9 +378,8 @@ | ||
| 413 | 378 | /** |
| 414 | 379 | * @since 6.0 |
| 415 | 380 | * |
| 416 | 381 | * @param string $color |
| 417 | - * | |
| 418 | 382 | * @return int |
| 419 | 383 | */ |
| 420 | 384 | public static function get_color_brightness( $color ) { |
| 421 | 385 | if ( 0 === strpos( $color, 'rgb' ) ) { |
| @@ -423,14 +387,12 @@ | ||
| 423 | 387 | } |
| 424 | 388 | |
| 425 | 389 | if ( 0 === strpos( $color, 'hsl' ) ) { |
| 426 | 390 | $hsl_to_hex = self::hsl_to_hex( $color ); |
| 427 | - | |
| 428 | 391 | if ( is_null( $hsl_to_hex ) ) { |
| 429 | 392 | // Fallback if we cannot convert the HSL value. |
| 430 | 393 | return 0; |
| 431 | 394 | } |
| 432 | - | |
| 433 | 395 | $color = $hsl_to_hex; |
| 434 | 396 | } |
| 435 | 397 | |
| 436 | 398 | self::fill_hex( $color ); |
| @@ -447,10 +409,8 @@ | ||
| 447 | 409 | * Change a 3 character hex color to a 6 character one. |
| 448 | 410 | * |
| 449 | 411 | * @since 6.0 |
| 450 | 412 | * |
| 451 | - * @param string $color Color value, passed by reference. | |
| 452 | - * | |
| 453 | 413 | * @return void |
| 454 | 414 | */ |
| 455 | 415 | private static function fill_hex( &$color ) { |
| 456 | 416 | if ( 3 === strlen( $color ) ) { |
| @@ -459,12 +419,8 @@ | ||
| 459 | 419 | } |
| 460 | 420 | |
| 461 | 421 | /** |
| 462 | 422 | * @since 4.05.02 |
| 463 | - * | |
| 464 | - * @param array $vars CSS variable keys. | |
| 465 | - * | |
| 466 | - * @return array | |
| 467 | 423 | */ |
| 468 | 424 | public static function get_css_vars( $vars = array() ) { |
| 469 | 425 | $vars = apply_filters( 'frm_css_vars', $vars ); |
| 470 | 426 | return array_unique( $vars ); |
| @@ -471,221 +427,43 @@ | ||
| 471 | 427 | } |
| 472 | 428 | |
| 473 | 429 | /** |
| 474 | 430 | * @since 4.05.02 |
| 475 | - * | |
| 476 | - * @param array $settings Style settings. | |
| 477 | - * @param array $defaults Default style settings. | |
| 478 | - * @param array $vars CSS variable keys to output. | |
| 479 | - * | |
| 480 | - * @return void | |
| 481 | 431 | */ |
| 482 | 432 | public static function output_vars( $settings, $defaults = array(), $vars = array() ) { |
| 483 | 433 | if ( empty( $vars ) ) { |
| 484 | 434 | $vars = self::get_css_vars( array_keys( $settings ) ); |
| 485 | 435 | } |
| 436 | + $remove = array( 'remove_box_shadow', 'remove_box_shadow_active', 'theme_css', 'theme_name', 'theme_selector', 'important_style', 'submit_style', 'collapse_icon', 'center_form', 'custom_css', 'style_class', 'submit_bg_img', 'change_margin', 'repeat_icon' ); | |
| 437 | + $vars = array_diff( $vars, $remove ); | |
| 486 | 438 | |
| 487 | - $vars = array_diff( $vars, self::get_style_keys_to_remove_from_output_vars() ); | |
| 488 | - | |
| 489 | 439 | foreach ( $vars as $var ) { |
| 490 | - if ( ! isset( $settings[ $var ] ) || ! self::css_key_is_valid( $var ) ) { | |
| 440 | + if ( ! isset( $settings[ $var ] ) ) { | |
| 491 | 441 | continue; |
| 492 | 442 | } |
| 493 | - | |
| 494 | 443 | if ( ! isset( $defaults[ $var ] ) ) { |
| 495 | 444 | $defaults[ $var ] = ''; |
| 496 | 445 | } |
| 497 | - | |
| 498 | - $prepared_value = ''; | |
| 499 | - | |
| 500 | - if ( self::should_add_css_var( $settings, $defaults, $var, $prepared_value ) ) { | |
| 501 | - echo '--' . esc_html( self::clean_var_name( str_replace( '_', '-', $var ) ) ) . ':' . $prepared_value . ';'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 446 | + $show = empty( $defaults ) || ( $settings[ $var ] !== '' && $settings[ $var ] !== $defaults[ $var ] ); | |
| 447 | + if ( $show ) { | |
| 448 | + echo '--' . esc_html( str_replace( '_', '-', $var ) ) . ':' . ( $var === 'font' ? FrmAppHelper::kses( $settings[ $var ] ) : esc_html( $settings[ $var ] ) ) . ';'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 502 | 449 | } |
| 503 | 450 | } |
| 504 | 451 | } |
| 505 | 452 | |
| 506 | 453 | /** |
| 507 | - * None of these style settings are used as CSS variables, so we want to exclude them to keep the CSS output clean. | |
| 508 | - * | |
| 509 | - * @since 6.26.1 | |
| 510 | - * | |
| 511 | - * @return array<string> | |
| 512 | - */ | |
| 513 | - private static function get_style_keys_to_remove_from_output_vars() { | |
| 514 | - return array( | |
| 515 | - 'remove_box_shadow', | |
| 516 | - 'remove_box_shadow_active', | |
| 517 | - 'theme_css', | |
| 518 | - 'theme_name', | |
| 519 | - 'theme_selector', | |
| 520 | - 'important_style', | |
| 521 | - 'submit_style', | |
| 522 | - 'collapse_icon', | |
| 523 | - 'center_form', | |
| 524 | - 'custom_css', | |
| 525 | - 'style_class', | |
| 526 | - 'submit_bg_img', | |
| 527 | - 'change_margin', | |
| 528 | - 'repeat_icon', | |
| 529 | - 'use_base_font_size', | |
| 530 | - 'field_shape_type', | |
| 531 | - 'bg_image_id', | |
| 532 | - ); | |
| 533 | - } | |
| 534 | - | |
| 535 | - /** | |
| 536 | - * Check if a CSS variable setting is not blank, doesn't match the default, and doesn't include invalid substrings. | |
| 537 | - * | |
| 538 | - * @since 6.24 | |
| 539 | - * | |
| 540 | - * @param array $settings Array of setting values. | |
| 541 | - * @param array $defaults Array of default values. | |
| 542 | - * @param string $var The setting key name. | |
| 543 | - * @param string $prepared_value The value from calling css_var_prepare_value. This is set by reference so it can be used after this function is called. | |
| 544 | - * | |
| 545 | - * @return bool True if the CSS value should be printed. | |
| 546 | - */ | |
| 547 | - private static function should_add_css_var( $settings, $defaults, $var, &$prepared_value ) { | |
| 548 | - $prepared_value = self::css_var_prepare_value( $settings, $var ); | |
| 549 | - | |
| 550 | - if ( $prepared_value === '' ) { | |
| 551 | - return false; | |
| 552 | - } | |
| 553 | - | |
| 554 | - if ( $defaults && $defaults[ $var ] === $prepared_value ) { | |
| 555 | - return false; | |
| 556 | - } | |
| 557 | - | |
| 558 | - return self::css_value_is_valid( $prepared_value ); | |
| 559 | - } | |
| 560 | - | |
| 561 | - /** | |
| 562 | - * Prevent invalid CSS keys from getting added to the generated CSS. | |
| 563 | - * | |
| 564 | - * @since 6.20 | |
| 565 | - * | |
| 566 | - * @param string $key | |
| 567 | - * | |
| 568 | - * @return bool | |
| 569 | - */ | |
| 570 | - private static function css_key_is_valid( $key ) { | |
| 571 | - // Any key that is abnormally large is not valid. | |
| 572 | - // Any key that contains a '{' is not valid. | |
| 573 | - return strlen( $key ) < 100 && false === strpos( $key, '{' ); | |
| 574 | - } | |
| 575 | - | |
| 576 | - /** | |
| 577 | - * Confirm a CSS value is valid. | |
| 578 | - * If it appears to contain JavaScript, it will not be added. | |
| 579 | - * | |
| 580 | - * @since 6.20 | |
| 581 | - * | |
| 582 | - * @param string $var | |
| 583 | - * | |
| 584 | - * @return bool | |
| 585 | - */ | |
| 586 | - private static function css_value_is_valid( $var ) { | |
| 587 | - if ( is_numeric( $var ) ) { | |
| 588 | - return true; | |
| 589 | - } | |
| 590 | - | |
| 591 | - // None of these substrings should be present in any CSS value. | |
| 592 | - $invalid_substrings = array( | |
| 593 | - 'function(', | |
| 594 | - ';userAgent', | |
| 595 | - ';stopPropagation', | |
| 596 | - '{const', | |
| 597 | - 'window[', | |
| 598 | - 'navigator[', | |
| 599 | - 'Array;', | |
| 600 | - ); | |
| 601 | - | |
| 602 | - foreach ( $invalid_substrings as $substring ) { | |
| 603 | - if ( strpos( $var, $substring ) !== false ) { | |
| 604 | - return false; | |
| 605 | - } | |
| 606 | - } | |
| 607 | - | |
| 608 | - return true; | |
| 609 | - } | |
| 610 | - | |
| 611 | - /** | |
| 612 | - * Remove anything that isn't used as a CSS variable name. | |
| 613 | - * | |
| 614 | - * @param string $var_name | |
| 615 | - * | |
| 616 | - * @return string | |
| 617 | - */ | |
| 618 | - private static function clean_var_name( $var_name ) { | |
| 619 | - return preg_replace( '/[^a-zA-Z0-9_-]/', '', $var_name ); | |
| 620 | - } | |
| 621 | - | |
| 622 | - /** | |
| 623 | - * Prepare the value for a CSS variable. | |
| 624 | - * | |
| 625 | - * @since 6.14 | |
| 626 | - * | |
| 627 | - * @param array $settings An array of css style. | |
| 628 | - * @param string $key | |
| 629 | - * | |
| 630 | - * @return string | |
| 631 | - */ | |
| 632 | - private static function css_var_prepare_value( $settings, $key ) { | |
| 633 | - $value = $settings[ $key ]; | |
| 634 | - | |
| 635 | - if ( ! is_string( $value ) && ! is_numeric( $value ) ) { | |
| 636 | - return ''; | |
| 637 | - } | |
| 638 | - | |
| 639 | - switch ( $key ) { | |
| 640 | - case 'font': | |
| 641 | - return safecss_filter_attr( $value ); | |
| 642 | - | |
| 643 | - case 'border_width_error': | |
| 644 | - case 'field_border_width': | |
| 645 | - if ( ! empty( $settings['field_shape_type'] ) && 'underline' === $settings['field_shape_type'] ) { | |
| 646 | - return safecss_filter_attr( '0px 0px ' . $value . ' 0px' ); | |
| 647 | - } | |
| 648 | - break; | |
| 649 | - | |
| 650 | - case 'box_shadow': | |
| 651 | - if ( ! empty( $settings['field_shape_type'] ) && 'underline' === $settings['field_shape_type'] ) { | |
| 652 | - return safecss_filter_attr( 'none' ); | |
| 653 | - } | |
| 654 | - break; | |
| 655 | - | |
| 656 | - case 'border_radius': | |
| 657 | - if ( ! empty( $settings['field_shape_type'] ) ) { | |
| 658 | - switch ( $settings['field_shape_type'] ) { | |
| 659 | - case 'underline': | |
| 660 | - case 'regular': | |
| 661 | - return safecss_filter_attr( '0px' ); | |
| 662 | - case 'circle': | |
| 663 | - return safecss_filter_attr( '30px' ); | |
| 664 | - } | |
| 665 | - } | |
| 666 | - break; | |
| 667 | - }//end switch | |
| 668 | - | |
| 669 | - return esc_html( $value ); | |
| 670 | - } | |
| 671 | - | |
| 672 | - /** | |
| 673 | 454 | * @since 2.3 |
| 674 | 455 | * |
| 675 | 456 | * @param WP_Post $style |
| 676 | - * | |
| 677 | 457 | * @return array |
| 678 | 458 | */ |
| 679 | 459 | public static function get_settings_for_output( $style ) { |
| 680 | 460 | if ( self::previewing_style() ) { |
| 681 | 461 | $frm_style = new FrmStyle(); |
| 682 | - | |
| 683 | 462 | if ( isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 684 | 463 | |
| 685 | 464 | // Sanitizing is done later. |
| 686 | 465 | $posted = wp_unslash( $_POST['frm_style_setting'] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing |
| 687 | - | |
| 688 | 466 | if ( ! is_array( $posted ) ) { |
| 689 | 467 | $posted = json_decode( $posted, true ); |
| 690 | 468 | FrmAppHelper::format_form_data( $posted ); |
| 691 | 469 | $settings = $frm_style->sanitize_post_content( $posted['frm_style_setting']['post_content'] ); |
| @@ -698,14 +476,11 @@ | ||
| 698 | 476 | $settings = $frm_style->sanitize_post_content( wp_unslash( $_GET ) ); |
| 699 | 477 | $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' ); |
| 700 | 478 | } |
| 701 | 479 | |
| 702 | - $settings = self::update_base_font_size( $settings, $frm_style->get_defaults() ); | |
| 703 | - | |
| 704 | 480 | FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings ); |
| 705 | 481 | |
| 706 | 482 | $settings['style_class'] = ''; |
| 707 | - | |
| 708 | 483 | if ( ! empty( $style_name ) ) { |
| 709 | 484 | $settings['style_class'] = $style_name . '.'; |
| 710 | 485 | } |
| 711 | 486 | } else { |
| @@ -717,9 +492,8 @@ | ||
| 717 | 492 | $settings['font'] = stripslashes( $settings['font'] ); |
| 718 | 493 | $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] ); |
| 719 | 494 | |
| 720 | 495 | $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' ); |
| 721 | - | |
| 722 | 496 | foreach ( $checkbox_opts as $opt ) { |
| 723 | 497 | if ( ! isset( $settings[ $opt ] ) ) { |
| 724 | 498 | $settings[ $opt ] = 0; |
| 725 | 499 | } |
| @@ -739,85 +513,16 @@ | ||
| 739 | 513 | return $settings; |
| 740 | 514 | } |
| 741 | 515 | |
| 742 | 516 | /** |
| 743 | - * Update the "Base Font Size" value from "Quick Settings across multiple settings values". | |
| 744 | - * | |
| 745 | - * @since 6.14 | |
| 746 | - * | |
| 747 | - * @param array $settings An array of css style. | |
| 748 | - * @param array $defaults Default style settings. | |
| 749 | - * | |
| 750 | - * @return array | |
| 751 | - */ | |
| 752 | - public static function update_base_font_size( $settings, $defaults ) { | |
| 753 | - if ( empty( $settings['base_font_size'] ) || empty( $settings['use_base_font_size'] ) || 'false' === $settings['use_base_font_size'] ) { | |
| 754 | - return $settings; | |
| 755 | - } | |
| 756 | - | |
| 757 | - $base_font_size = (int) $settings['base_font_size']; | |
| 758 | - $font_size = $defaults['font_size']; | |
| 759 | - $font_sizes_to_update = array( | |
| 760 | - 'font_size', | |
| 761 | - 'field_font_size', | |
| 762 | - 'check_font_size', | |
| 763 | - 'title_size', | |
| 764 | - 'form_desc_size', | |
| 765 | - 'description_font_size', | |
| 766 | - 'section_font_size', | |
| 767 | - 'submit_font_size', | |
| 768 | - 'success_font_size', | |
| 769 | - 'error_font_size', | |
| 770 | - 'progress_size', | |
| 771 | - ); | |
| 772 | - | |
| 773 | - array_map( | |
| 774 | - function ( $key ) use ( $defaults, $font_size, $base_font_size, &$settings ) { | |
| 775 | - if ( isset( $settings[ $key ] ) ) { | |
| 776 | - $settings[ $key ] = round( self::get_base_font_size_scale( $key, $font_size, $defaults ) * $base_font_size ) . 'px'; | |
| 777 | - } | |
| 778 | - }, | |
| 779 | - $font_sizes_to_update | |
| 780 | - ); | |
| 781 | - | |
| 782 | - return $settings; | |
| 783 | - } | |
| 784 | - | |
| 785 | - /** | |
| 786 | - * Get style font size scale value. | |
| 787 | - * | |
| 788 | - * @since 6.14 | |
| 789 | - * | |
| 790 | - * @param string $key Setting key. | |
| 791 | - * @param int|string $value Base font size value. | |
| 792 | - * @param array $defaults Default style settings. | |
| 793 | - * | |
| 794 | - * @return float | |
| 795 | - */ | |
| 796 | - private static function get_base_font_size_scale( $key, $value, $defaults ) { | |
| 797 | - if ( empty( $defaults[ $key ] ) || ! is_numeric( (int) $defaults[ $key ] ) || ! is_numeric( (int) $value ) || 0 === (int) $value ) { | |
| 798 | - return 1; | |
| 799 | - } | |
| 800 | - | |
| 801 | - return round( (int) $defaults[ $key ] / (int) $value, 2 ); | |
| 802 | - } | |
| 803 | - | |
| 804 | - /** | |
| 805 | 517 | * @since 2.3 |
| 806 | - * | |
| 807 | - * @param array $settings Style settings, passed by reference. | |
| 808 | - * @param bool $allow_transparent Whether transparent colors are allowed. | |
| 809 | - * | |
| 810 | - * @return void | |
| 811 | 518 | */ |
| 812 | 519 | public static function prepare_color_output( &$settings, $allow_transparent = true ) { |
| 813 | 520 | $colors = self::allow_color_override(); |
| 814 | - | |
| 815 | 521 | foreach ( $colors as $css => $opts ) { |
| 816 | 522 | if ( $css === 'transparent' && ! $allow_transparent ) { |
| 817 | 523 | $css = ''; |
| 818 | 524 | } |
| 819 | - | |
| 820 | 525 | foreach ( $opts as $opt ) { |
| 821 | 526 | self::get_color_output( $css, $settings[ $opt ] ); |
| 822 | 527 | } |
| 823 | 528 | } |
| @@ -857,17 +562,11 @@ | ||
| 857 | 562 | } |
| 858 | 563 | |
| 859 | 564 | /** |
| 860 | 565 | * @since 2.3 |
| 861 | - * | |
| 862 | - * @param string $default Default color value. | |
| 863 | - * @param string $color Color value, passed by reference. | |
| 864 | - * | |
| 865 | - * @return void | |
| 866 | 566 | */ |
| 867 | 567 | private static function get_color_output( $default, &$color ) { |
| 868 | 568 | $color = trim( $color ); |
| 869 | - | |
| 870 | 569 | if ( empty( $color ) ) { |
| 871 | 570 | $color = $default; |
| 872 | 571 | } elseif ( false !== strpos( $color, 'rgb(' ) ) { |
| 873 | 572 | $color = str_replace( 'rgb(', 'rgba(', $color ); |
| @@ -883,9 +582,8 @@ | ||
| 883 | 582 | * |
| 884 | 583 | * @since 6.8 |
| 885 | 584 | * |
| 886 | 585 | * @param string $color |
| 887 | - * | |
| 888 | 586 | * @return bool |
| 889 | 587 | */ |
| 890 | 588 | private static function is_hex( $color ) { |
| 891 | 589 | $non_hex_substrings = array( |
| @@ -908,17 +606,12 @@ | ||
| 908 | 606 | * If left/right label is over a certain size, |
| 909 | 607 | * adjust the field description margin at a different screen size |
| 910 | 608 | * |
| 911 | 609 | * @since 2.3 |
| 912 | - * | |
| 913 | - * @param string $width Label width value. | |
| 914 | - * | |
| 915 | - * @return false|string | |
| 916 | 610 | */ |
| 917 | 611 | private static function description_margin_for_screensize( $width ) { |
| 918 | 612 | $temp_label_width = str_replace( 'px', '', $width ); |
| 919 | 613 | $change_margin = false; |
| 920 | - | |
| 921 | 614 | if ( $temp_label_width >= 230 ) { |
| 922 | 615 | $change_margin = '800px'; |
| 923 | 616 | } elseif ( $width >= 215 ) { |
| 924 | 617 | $change_margin = '700px'; |
| @@ -945,9 +638,8 @@ | ||
| 945 | 638 | * |
| 946 | 639 | * @since 6.0 |
| 947 | 640 | * |
| 948 | 641 | * @param int|string $form_id |
| 949 | - * | |
| 950 | 642 | * @return string |
| 951 | 643 | */ |
| 952 | 644 | public static function get_list_url( $form_id ) { |
| 953 | 645 | return admin_url( 'admin.php?page=formidable-styles&form=' . absint( $form_id ) ); |
| @@ -953,45 +645,19 @@ | ||
| 953 | 645 | return admin_url( 'admin.php?page=formidable-styles&form=' . absint( $form_id ) ); |
| 954 | 646 | } |
| 955 | 647 | |
| 956 | 648 | /** |
| 957 | - * Get the back button args from Style settings. | |
| 958 | - * | |
| 959 | - * @since 6.14 | |
| 960 | - * | |
| 961 | - * @param stdClass|WP_Post $style | |
| 962 | - * @param int $form_id | |
| 963 | - * | |
| 964 | - * @return array | |
| 965 | - */ | |
| 966 | - public static function get_style_options_back_button_args( $style, $form_id ) { | |
| 967 | - if ( self::is_advanced_settings() ) { | |
| 968 | - return array( | |
| 969 | - 'title' => __( 'Quick Settings', 'formidable' ), | |
| 970 | - 'id' => 'frm_style_back_to_quick_settings', | |
| 971 | - ); | |
| 972 | - } | |
| 973 | - return array( | |
| 974 | - 'href' => self::get_list_url( $form_id ), | |
| 975 | - 'title' => $style->post_title, | |
| 976 | - ); | |
| 977 | - } | |
| 978 | - | |
| 979 | - /** | |
| 980 | 649 | * Get a link to edit a target style post object in the visual styler. |
| 981 | 650 | * |
| 982 | 651 | * @param stdClass|WP_Post $style |
| 983 | 652 | * @param int|string $form_id Used for the back button and preview form target. |
| 984 | - * @param string $section The url param section. | |
| 985 | - * | |
| 986 | 653 | * @return string |
| 987 | 654 | */ |
| 988 | - public static function get_edit_url( $style, $form_id = 0, $section = '' ) { | |
| 655 | + public static function get_edit_url( $style, $form_id = 0 ) { | |
| 989 | 656 | $query_args = array( |
| 990 | 657 | 'page' => 'formidable-styles', |
| 991 | 658 | 'frm_action' => 'edit', |
| 992 | 659 | 'id' => $style->ID, |
| 993 | - 'section' => $section, | |
| 994 | 660 | ); |
| 995 | 661 | |
| 996 | 662 | if ( $form_id ) { |
| 997 | 663 | // We include &form_id for the back button to know where to point to. |
| @@ -1008,9 +674,8 @@ | ||
| 1008 | 674 | * @since 6.0 |
| 1009 | 675 | * |
| 1010 | 676 | * @param int|string $style_id |
| 1011 | 677 | * @param bool $is_default |
| 1012 | - * | |
| 1013 | 678 | * @return int |
| 1014 | 679 | */ |
| 1015 | 680 | public static function get_form_count_for_style( $style_id, $is_default ) { |
| 1016 | 681 | $serialized = serialize( array( 'custom_style' => (string) $style_id ) ); |
| @@ -1041,9 +706,8 @@ | ||
| 1041 | 706 | * @since 6.0 |
| 1042 | 707 | * |
| 1043 | 708 | * @param int|string $style_id |
| 1044 | 709 | * @param mixed $conversational_style_id |
| 1045 | - * | |
| 1046 | 710 | * @return int |
| 1047 | 711 | */ |
| 1048 | 712 | private static function get_default_style_count( $style_id, $conversational_style_id ) { |
| 1049 | 713 | $substrings = array_map( |
| @@ -1075,62 +739,8 @@ | ||
| 1075 | 739 | return FrmDb::get_count( 'frm_forms', $where ); |
| 1076 | 740 | } |
| 1077 | 741 | |
| 1078 | 742 | /** |
| 1079 | - * Check if the current page is the advanced settings page. | |
| 1080 | - * | |
| 1081 | - * @since 6.14 | |
| 1082 | - * | |
| 1083 | - * @return bool True if is advanced settings, false otherwise. | |
| 1084 | - */ | |
| 1085 | - public static function is_advanced_settings() { | |
| 1086 | - return FrmAppHelper::get_param( 'section' ) === 'advanced-settings' && FrmAppHelper::get_param( 'page' ) === 'formidable-styles'; | |
| 1087 | - } | |
| 1088 | - | |
| 1089 | - /** | |
| 1090 | - * Get wrapper classname for style editor sections. | |
| 1091 | - * | |
| 1092 | - * @since 6.16 | |
| 1093 | - * | |
| 1094 | - * @param string $section_type | |
| 1095 | - * | |
| 1096 | - * @return string The style editor wrapper classname. | |
| 1097 | - */ | |
| 1098 | - public static function style_editor_get_wrapper_classname( $section_type ) { | |
| 1099 | - $is_quick_settings = ( 'quick-settings' === $section_type ); | |
| 1100 | - $classname = 'frm-style-editor-form'; | |
| 1101 | - $classname .= ( ! self::is_advanced_settings() xor $is_quick_settings ) ? ' frm_hidden' : ''; | |
| 1102 | - $classname .= FrmAppHelper::pro_is_installed() ? ' frm-pro' : ''; | |
| 1103 | - | |
| 1104 | - return $classname; | |
| 1105 | - } | |
| 1106 | - | |
| 1107 | - /** | |
| 1108 | - * Retrieve the background image URL of the submit button. | |
| 1109 | - * It may be either a full URL string (used in versions prior to 6.14) or a numeric attachment ID (introduced in version 6.14). | |
| 1110 | - * | |
| 1111 | - * @since 6.14 | |
| 1112 | - * | |
| 1113 | - * @param array $settings | |
| 1114 | - * | |
| 1115 | - * @return false|string Return image url or false. | |
| 1116 | - */ | |
| 1117 | - public static function get_submit_image_bg_url( $settings ) { | |
| 1118 | - $background_image = $settings['submit_bg_img']; | |
| 1119 | - | |
| 1120 | - if ( empty( $background_image ) ) { | |
| 1121 | - return false; | |
| 1122 | - } | |
| 1123 | - | |
| 1124 | - // Handle the case where the submit_bg_img is a full URL string. If the settings were saved with the older styler version prior to 6.14, the submit_bg_img will be a full URL string. | |
| 1125 | - if ( ! is_numeric( $background_image ) ) { | |
| 1126 | - return $background_image; | |
| 1127 | - } | |
| 1128 | - | |
| 1129 | - return wp_get_attachment_url( (int) $background_image ); | |
| 1130 | - } | |
| 1131 | - | |
| 1132 | - /** | |
| 1133 | 743 | * Determines if the chosen JavaScript library should be used. |
| 1134 | 744 | * |
| 1135 | 745 | * @since 6.13 |
| 1136 | 746 | * |
| @@ -1146,25 +756,12 @@ | ||
| 1146 | 756 | : true; |
| 1147 | 757 | } |
| 1148 | 758 | |
| 1149 | 759 | /** |
| 1150 | - * Returns the bottom part from a margin/padding value. | |
| 1151 | - * | |
| 1152 | - * @since 6.17 | |
| 1153 | - * | |
| 1154 | - * @param string $value The margin/padding value. | |
| 1155 | - * | |
| 1156 | - * @return string | |
| 760 | + * @since 5.5.1 | |
| 761 | + * @deprecated 6.10 | |
| 762 | + * @return void | |
| 1157 | 763 | */ |
| 1158 | - public static function get_bottom_value( $value ) { | |
| 1159 | - if ( ! $value ) { | |
| 1160 | - return $value; | |
| 1161 | - } | |
| 1162 | - | |
| 1163 | - $parts = explode( ' ', $value ); | |
| 1164 | - | |
| 1165 | - if ( count( $parts ) < 3 ) { | |
| 1166 | - return $parts[0]; | |
| 1167 | - } | |
| 1168 | - return $parts[2]; | |
| 764 | + public static function maybe_include_font_icon_css() { | |
| 765 | + _deprecated_function( __METHOD__, '6.10' ); | |
| 1169 | 766 | } |
| 1170 | 767 | } |