| @@ -8,9 +8,8 @@ | ||
| 8 | 8 | use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 9 | 9 | use Elementor\Core\Files\Base as Base_File; |
| 10 | 10 | use Elementor\Core\DynamicTags\Manager; |
| 11 | 11 | use Elementor\Core\DynamicTags\Tag; |
| 12 | -use Elementor\Core\Frontend\Performance; | |
| 13 | 12 | use Elementor\Core\Kits\Documents\Tabs\Global_Typography; |
| 14 | 13 | use Elementor\Plugin; |
| 15 | 14 | use Elementor\Stylesheet; |
| 16 | 15 | use Elementor\Icons_Manager; |
| @@ -64,10 +63,8 @@ | ||
| 64 | 63 | private $icons_fonts = []; |
| 65 | 64 | |
| 66 | 65 | private $dynamic_elements_ids = []; |
| 67 | 66 | |
| 68 | - private $preserved_dynamic_style_values = []; | |
| 69 | - | |
| 70 | 67 | /** |
| 71 | 68 | * Stylesheet object. |
| 72 | 69 | * |
| 73 | 70 | * Holds the CSS file stylesheet instance. |
| @@ -214,17 +211,8 @@ | ||
| 214 | 211 | if ( self::CSS_STATUS_EMPTY === $meta['status'] ) { |
| 215 | 212 | return; |
| 216 | 213 | } |
| 217 | 214 | |
| 218 | - /** | |
| 219 | - * Enqueue CSS file. | |
| 220 | - * | |
| 221 | - * Fires before enqueuing a CSS file. | |
| 222 | - * | |
| 223 | - * @param Base $this The current CSS file. | |
| 224 | - */ | |
| 225 | - do_action( 'elementor/css-file/before_enqueue', $this ); | |
| 226 | - | |
| 227 | 215 | // First time after clear cache and etc. |
| 228 | 216 | if ( '' === $meta['status'] || $this->is_update_required() ) { |
| 229 | 217 | $this->update(); |
| 230 | 218 | |
| @@ -234,14 +222,14 @@ | ||
| 234 | 222 | if ( self::CSS_STATUS_INLINE === $meta['status'] ) { |
| 235 | 223 | $dep = $this->get_inline_dependency(); |
| 236 | 224 | // If the dependency has already been printed ( like a template in footer ) |
| 237 | 225 | if ( wp_styles()->query( $dep, 'done' ) ) { |
| 238 | - printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 226 | + printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // XSS ok. | |
| 239 | 227 | } else { |
| 240 | 228 | wp_add_inline_style( $dep, $meta['css'] ); |
| 241 | 229 | } |
| 242 | 230 | } elseif ( self::CSS_STATUS_FILE === $meta['status'] ) { // Re-check if it's not empty after CSS update. |
| 243 | - wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_enqueue_dependencies(), null ); | |
| 231 | + wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_enqueue_dependencies(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 244 | 232 | } |
| 245 | 233 | |
| 246 | 234 | // Handle fonts. |
| 247 | 235 | if ( ! empty( $meta['fonts'] ) ) { |
| @@ -273,17 +261,8 @@ | ||
| 273 | 261 | * |
| 274 | 262 | * @param Base $this The current CSS file. |
| 275 | 263 | */ |
| 276 | 264 | do_action( "elementor/css-file/{$name}/enqueue", $this ); |
| 277 | - | |
| 278 | - /** | |
| 279 | - * Enqueue CSS file. | |
| 280 | - * | |
| 281 | - * Fires after enqueuing a CSS file. | |
| 282 | - * | |
| 283 | - * @param Base $this The current CSS file. | |
| 284 | - */ | |
| 285 | - do_action( 'elementor/css-file/after_enqueue', $this ); | |
| 286 | 265 | } |
| 287 | 266 | |
| 288 | 267 | /** |
| 289 | 268 | * Print CSS. |
| @@ -294,9 +273,9 @@ | ||
| 294 | 273 | * @since 1.9.4 |
| 295 | 274 | * @access public |
| 296 | 275 | */ |
| 297 | 276 | public function print_css() { |
| 298 | - echo '<style>' . $this->get_content() . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 277 | + echo '<style>' . $this->get_content() . '</style>'; // XSS ok. | |
| 299 | 278 | Plugin::$instance->frontend->print_fonts_links(); |
| 300 | 279 | } |
| 301 | 280 | |
| 302 | 281 | /** |
| @@ -347,10 +326,8 @@ | ||
| 347 | 326 | } |
| 348 | 327 | |
| 349 | 328 | $stylesheet = $this->get_stylesheet(); |
| 350 | 329 | |
| 351 | - $control = apply_filters( 'elementor/files/css/selectors', $control, $value ?? [], $this ); | |
| 352 | - | |
| 353 | 330 | foreach ( $control['selectors'] as $selector => $css_property ) { |
| 354 | 331 | $output_css_property = ''; |
| 355 | 332 | |
| 356 | 333 | if ( $global_key ) { |
| @@ -360,19 +337,13 @@ | ||
| 360 | 337 | $output_css_property = preg_replace( '/(:)[^;]+(;?)/', '$1' . $selector_global_value . '$2', $css_property ); |
| 361 | 338 | } |
| 362 | 339 | } else { |
| 363 | 340 | try { |
| 364 | - if ( $this->unit_has_custom_selector( $control, $value ) ) { | |
| 365 | - $css_property = $control['unit_selectors_dictionary'][ $value['unit'] ]; | |
| 366 | - } | |
| 367 | - | |
| 368 | 341 | $output_css_property = preg_replace_callback( '/{{(?:([^.}]+)\.)?([^}| ]*)(?: *\|\| *(?:([^.}]+)\.)?([^}| ]*) *)*}}/', function( $matches ) use ( $control, $value_callback, $controls_stack, $value, $css_property ) { |
| 369 | 342 | $external_control_missing = $matches[1] && ! isset( $controls_stack[ $matches[1] ] ); |
| 370 | 343 | |
| 371 | 344 | $parsed_value = ''; |
| 372 | 345 | |
| 373 | - $value = apply_filters( 'elementor/files/css/property', $value, $css_property, $matches, $control ); | |
| 374 | - | |
| 375 | 346 | if ( ! $external_control_missing ) { |
| 376 | 347 | $parsed_value = $this->parse_property_placeholder( $control, $value, $controls_stack, $value_callback, $matches[2], $matches[1] ); |
| 377 | 348 | } |
| 378 | 349 | |
| @@ -401,12 +372,8 @@ | ||
| 401 | 372 | throw new \Exception(); |
| 402 | 373 | } |
| 403 | 374 | } |
| 404 | 375 | |
| 405 | - if ( '__EMPTY__' === $parsed_value ) { | |
| 406 | - $parsed_value = ''; | |
| 407 | - } | |
| 408 | - | |
| 409 | 376 | return $parsed_value; |
| 410 | 377 | }, $css_property ); |
| 411 | 378 | } catch ( \Exception $e ) { |
| 412 | 379 | return; |
| @@ -456,12 +423,8 @@ | ||
| 456 | 423 | $stylesheet->add_rules( $parsed_selector, $output_css_property, $query ); |
| 457 | 424 | } |
| 458 | 425 | } |
| 459 | 426 | |
| 460 | - protected function unit_has_custom_selector( $control, $value ) { | |
| 461 | - return isset( $control['unit_selectors_dictionary'] ) && isset( $control['unit_selectors_dictionary'][ $value['unit'] ] ); | |
| 462 | - } | |
| 463 | - | |
| 464 | 427 | /** |
| 465 | 428 | * @param array $control |
| 466 | 429 | * @param mixed $value |
| 467 | 430 | * @param array $controls_stack |
| @@ -472,17 +435,10 @@ | ||
| 472 | 435 | * @return string |
| 473 | 436 | */ |
| 474 | 437 | public function parse_property_placeholder( array $control, $value, array $controls_stack, $value_callback, $placeholder, $parser_control_name = null ) { |
| 475 | 438 | if ( $parser_control_name ) { |
| 476 | - // If both the processed control and the control name found in the placeholder are responsive | |
| 477 | - if ( ! empty( $control['responsive'] ) && ! empty( $controls_stack[ $parser_control_name ]['responsive'] ) ) { | |
| 478 | - $device_suffix = Controls_Manager::get_responsive_control_device_suffix( $control ); | |
| 439 | + $control = $controls_stack[ $parser_control_name ]; | |
| 479 | 440 | |
| 480 | - $control = $controls_stack[ $parser_control_name . $device_suffix ] ?? $controls_stack[ $parser_control_name ]; | |
| 481 | - } else { | |
| 482 | - $control = $controls_stack[ $parser_control_name ]; | |
| 483 | - } | |
| 484 | - | |
| 485 | 441 | $value = call_user_func( $value_callback, $control ); |
| 486 | 442 | } |
| 487 | 443 | |
| 488 | 444 | // If the control value is empty, check for global default. `0` (integer, string) are falsy but are valid values. |
| @@ -490,9 +446,9 @@ | ||
| 490 | 446 | $value = $this->get_control_global_default_value( $control ); |
| 491 | 447 | } |
| 492 | 448 | |
| 493 | 449 | if ( Controls_Manager::FONT === $control['type'] ) { |
| 494 | - $this->add_font( $value ); | |
| 450 | + $this->fonts[] = $value; | |
| 495 | 451 | } |
| 496 | 452 | |
| 497 | 453 | /** @var Base_Data_Control $control_obj */ |
| 498 | 454 | $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); |
| @@ -548,9 +504,9 @@ | ||
| 548 | 504 | * @param array $placeholders Placeholders. |
| 549 | 505 | * @param array $replacements Replacements. |
| 550 | 506 | * @param array $all_controls All controls. |
| 551 | 507 | */ |
| 552 | - public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, ?array $all_controls = null ) { | |
| 508 | + public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, array $all_controls = null ) { | |
| 553 | 509 | if ( ! $all_controls ) { |
| 554 | 510 | $all_controls = $controls_stack->get_controls(); |
| 555 | 511 | } |
| 556 | 512 | |
| @@ -572,13 +528,8 @@ | ||
| 572 | 528 | if ( ! empty( $parsed_dynamic_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ) ) { |
| 573 | 529 | // Dynamic CSS should not be added to the CSS files. |
| 574 | 530 | // Instead it's handled by \Elementor\Core\DynamicTags\Dynamic_CSS |
| 575 | 531 | // and printed in a style tag. |
| 576 | - $should_preserve_value = isset( $control['control_type'] ) && 'content' === $control['control_type']; | |
| 577 | - if ( $should_preserve_value ) { | |
| 578 | - $this->preserved_dynamic_style_values[ $control['name'] ] = $parsed_dynamic_settings[ $control['name'] ]; | |
| 579 | - } | |
| 580 | - | |
| 581 | 532 | unset( $parsed_dynamic_settings[ $control['name'] ] ); |
| 582 | 533 | |
| 583 | 534 | $this->dynamic_elements_ids[] = $controls_stack->get_id(); |
| 584 | 535 | |
| @@ -677,10 +628,8 @@ | ||
| 677 | 628 | * @since 1.2.0 |
| 678 | 629 | * @access protected |
| 679 | 630 | */ |
| 680 | 631 | protected function parse_content() { |
| 681 | - Performance::set_use_style_controls( true ); | |
| 682 | - | |
| 683 | 632 | $initial_responsive_controls_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); |
| 684 | 633 | |
| 685 | 634 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $this->get_responsive_control_duplication_mode() ); |
| 686 | 635 | |
| @@ -702,10 +651,8 @@ | ||
| 702 | 651 | do_action( "elementor/css-file/{$name}/parse", $this ); |
| 703 | 652 | |
| 704 | 653 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode ); |
| 705 | 654 | |
| 706 | - Performance::set_use_style_controls( false ); | |
| 707 | - | |
| 708 | 655 | return $this->get_stylesheet()->__toString(); |
| 709 | 656 | } |
| 710 | 657 | |
| 711 | 658 | /** |
| @@ -786,11 +733,9 @@ | ||
| 786 | 733 | // When the control itself has no global value, but it refers to another control global value |
| 787 | 734 | return $this->get_selector_global_value( $control, $values['__globals__'][ $control['name'] ] ); |
| 788 | 735 | } |
| 789 | 736 | |
| 790 | - $value = isset( $values[ $control['name'] ] ) | |
| 791 | - ? $values[ $control['name'] ] | |
| 792 | - : $this->preserved_dynamic_style_values[ $control['name'] ] ?? null; | |
| 737 | + $value = $values[ $control['name'] ]; | |
| 793 | 738 | |
| 794 | 739 | if ( isset( $control['selectors_dictionary'][ $value ] ) ) { |
| 795 | 740 | $value = $control['selectors_dictionary'][ $value ]; |
| 796 | 741 | } |
| @@ -907,9 +852,9 @@ | ||
| 907 | 852 | if ( $control['groupPrefix'] . 'font_family' === $control['name'] ) { |
| 908 | 853 | $default_generic_fonts = Plugin::$instance->kits_manager->get_current_settings( 'default_generic_fonts' ); |
| 909 | 854 | |
| 910 | 855 | if ( $default_generic_fonts ) { |
| 911 | - $value .= ", $default_generic_fonts"; | |
| 856 | + $value .= ", $default_generic_fonts"; | |
| 912 | 857 | } |
| 913 | 858 | } |
| 914 | 859 | } else { |
| 915 | 860 | $value = "var( --e-global-$control[type]-$id )"; |
| @@ -917,9 +862,9 @@ | ||
| 917 | 862 | |
| 918 | 863 | return $value; |
| 919 | 864 | } |
| 920 | 865 | |
| 921 | - final protected function get_active_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) { | |
| 866 | + final protected function get_active_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { | |
| 922 | 867 | if ( ! $controls ) { |
| 923 | 868 | $controls = $controls_stack->get_controls(); |
| 924 | 869 | } |
| 925 | 870 | |
| @@ -934,9 +879,9 @@ | ||
| 934 | 879 | $active_controls = array_reduce( |
| 935 | 880 | array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls_stack, $controls, $settings ) { |
| 936 | 881 | $control = $controls[ $control_key ]; |
| 937 | 882 | |
| 938 | - if ( $controls_stack->is_control_visible( $control, $settings, $controls ) ) { | |
| 883 | + if ( $controls_stack->is_control_visible( $control, $settings ) ) { | |
| 939 | 884 | $active_controls[ $control_key ] = $control; |
| 940 | 885 | } |
| 941 | 886 | |
| 942 | 887 | return $active_controls; |
| @@ -945,9 +890,9 @@ | ||
| 945 | 890 | |
| 946 | 891 | return $active_controls; |
| 947 | 892 | } |
| 948 | 893 | |
| 949 | - final public function get_style_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) { | |
| 894 | + final public function get_style_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { | |
| 950 | 895 | $controls = $this->get_active_controls( $controls_stack, $controls, $settings ); |
| 951 | 896 | |
| 952 | 897 | $style_controls = []; |
| 953 | 898 | |
| @@ -1024,12 +969,6 @@ | ||
| 1024 | 969 | |
| 1025 | 970 | $globals = $controls_stack->get_settings( '__globals__' ); |
| 1026 | 971 | |
| 1027 | 972 | return ! empty( $globals[ $control_global_key ] ); |
| 1028 | - } | |
| 1029 | - | |
| 1030 | - public function add_font( $font ) { | |
| 1031 | - if ( ! in_array( $font, $this->fonts, true ) ) { | |
| 1032 | - $this->fonts[] = $font; | |
| 1033 | - } | |
| 1034 | 973 | } |
| 1035 | 974 | } |