ce 1.2.0 * @access protected * * @return string Name of the stylesheet. */ protected function get_inline_dependency() { return ''; } /** * Is update required. * * Whether the CSS requires an update. When there are new schemes or settings * updates. * * @since 1.2.0 * @access protected * * @return bool True if the CSS requires an update, False otherwise. */ protected function is_update_required() { return false; } /** * Parse CSS. * * Parsing the CSS file. * * @since 1.2.0 * @access protected */ protected function parse_content() { do_action( 'elementor/css_file/parse_content', $this ); $initial_responsive_controls_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $this->get_responsive_control_duplication_mode() ); $this->render_css(); $name = $this->get_name(); /** * Parse CSS file. * * Fires when CSS file is parsed on Elementor. * * The dynamic portion of the hook name, `$name`, refers to the CSS file name. * * @since 2.0.0 * * @param Base $this The current CSS file. */ do_action( "elementor/css-file/{$name}/parse", $this ); Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode ); return $this->get_stylesheet()->__toString(); } /** * Add control style rules. * * Register new style rules for the control. * * @since 1.6.0 * @access private * * @param array $control The control. * @param array $values Values array. * @param array $controls The controls stack. * @param array $placeholders Placeholders. * @param array $replacements Replacements. */ protected function add_control_style_rules( array $control, array $values, array $controls, array $placeholders, array $replacements ) { $this->add_control_rules( $control, $controls, function( $control ) use ( $values ) { return $this->get_style_control_value( $control, $values ); }, $placeholders, $replacements, $values ); } /** * Get Control Global Default Value * * If the control has a global default value, and the corresponding global default setting is enabled, this method * fetches and returns the global default value. Otherwise, it returns null. * * @since 3.7.0 * @access private * * @param $control * @return string|null */ private function get_control_global_default_value( $control ) { if ( empty( $control['global']['default'] ) ) { return null; } // If the control value is empty, and the control has a global default set, fetch the global value and use it. $global_enabled = false; if ( 'color' === $control['type'] ) { $global_enabled = Plugin::$instance->kits_manager->is_custom_colors_enabled(); } elseif ( isset( $control['groupType'] ) && 'typography' === $control['groupType'] ) { $global_enabled = Plugin::$instance->kits_manager->is_custom_typography_enabled(); } $value = null; // Only apply the global default if Global Colors are enabled. if ( $global_enabled ) { $value = $this->get_selector_global_value( $control, $control['global']['default'] ); } return $value; } /** * Get style control value. * * Retrieve the value of the style control for any give control and values. * * It will retrieve the control name and return the style value. * * @since 1.6.0 * @access private * * @param array $control The control. * @param array $values Values array. * * @return mixed Style control value. */ private function get_style_control_value( array $control, array $values ) { if ( ! empty( $values['__globals__'][ $control['name'] ] ) ) { // When the control itself has no global value, but it refers to another control global value return $this->get_selector_global_value( $control, $values['__globals__'][ $control['name'] ] ); } $value = $values[ $control['name'] ]; if ( isset( $control['selectors_dictionary'][ $value ] ) ) { $value = $control['selectors_dictionary'][ $value ]; } if ( ! is_numeric( $value ) && ! is_float( $value ) && empty( $value ) ) { return null; } return $value; } /** * Init stylesheet. * * Initialize CSS file stylesheet by creating a new `Stylesheet` object and register new * breakpoints for the stylesheet. * * @since 1.2.0 * @access private */ private function init_stylesheet() { $this->stylesheet_obj = new Stylesheet(); $active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints(); foreach ( $active_breakpoints as $breakpoint_name => $breakpoint ) { $this->stylesheet_obj->add_device( $breakpoint_name, $breakpoint->get_value() ); } } /** * Add repeater control style rules. * * Register new style rules for the repeater control. * * @since 2.0.0 * @access private * * @param Controls_Stack $controls_stack The control stack. * @param array $repeater_control The repeater control. * @param array $repeater_values Repeater values array. * @param array $placeholders Placeholders. * @param array $replacements Replacements. */ protected function add_repeater_control_style_rules( Controls_Stack $controls_stack, array $repeater_control, array $repeater_values, array $placeholders, array $replacements ) { $placeholders = array_merge( $placeholders, [ '{{CURRENT_ITEM}}' ] ); foreach ( $repeater_control['style_fields'] as $index => $item ) { $this->add_controls_stack_style_rules( $controls_stack, $item, $repeater_values[ $index ], $placeholders, array_merge( $replacements, [ '.elementor-repeater-item-' . $repeater_values[ $index ]['_id'] ] ), $repeater_control['fields'] ); } } /** * Add dynamic control style rules. * * Register new style rules for the dynamic control. * * @since 2.0.0 * @access private * * @param array $control The control. * @param string $value The value. */ protected function add_dynamic_control_style_rules( array $control, $value ) { Plugin::$instance->dynamic_tags->parse_tags_text( $value, $control, function( $id, $name, $settings ) { $tag = Plugin::$instance->dynamic_tags->create_tag( $id, $name, $settings ); if ( ! $tag instanceof Tag ) { return; } $this->add_controls_stack_style_rules( $tag, $this->get_style_controls( $tag ), $tag->get_active_settings(), [ '{{WRAPPER}}' ], [ '#elementor-tag-' . $id ] ); } ); } private function get_selector_global_value( $control, $global_key ) { $data = Plugin::$instance->data_manager_v2->run( $global_key ); if ( empty( $data['value'] ) ) { return null; } $global_args = explode( '?id=', $global_key ); $id = $global_args[1]; if ( ! empty( $control['groupType'] ) ) { $strings_to_replace = [ $control['groupPrefix'] ]; $active_breakpoint_keys = array_keys( Plugin::$instance->breakpoints->get_active_breakpoints() ); foreach ( $active_breakpoint_keys as $breakpoint ) { $strings_to_replace[] = '_' . $breakpoint; } $property_name = str_replace( $strings_to_replace, '', $control['name'] ); // TODO: This check won't retrieve the proper answer for array values (multiple controls). if ( empty( $data['value'][ Global_Typography::TYPOGRAPHY_GROUP_PREFIX . $property_name ] ) ) { return null; } $property_name = str_replace( '_', '-', $property_name ); $value = "var( --e-global-$control[groupType]-$id-$property_name )"; if ( $control['groupPrefix'] . 'font_family' === $control['name'] ) { $default_generic_fonts = Plugin::$instance->kits_manager->get_current_settings( 'default_generic_fonts' ); if ( $default_generic_fonts ) { $value .= ", $default_generic_fonts"; } } } else { $value = "var( --e-global-$control[type]-$id )"; } return $value; } final protected function get_active_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { if ( ! $controls ) { $controls = $controls_stack->get_controls(); } if ( ! $settings ) { $settings = $controls_stack->get_controls_settings(); } if ( $this->is_global_parsing_supported() ) { $settings = $this->parse_global_settings( $settings, $controls ); } $active_controls = array_reduce( array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls_stack, $controls, $settings ) { $control = $controls[ $control_key ]; if ( $controls_stack->is_control_visible( $control, $settings ) ) { $active_controls[ $control_key ] = $control; } return $active_controls; }, [] ); return $active_controls; } final public function get_style_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { $controls = $this->get_active_controls( $controls_stack, $controls, $settings ); $style_controls = []; foreach ( $controls as $control_name => $control ) { $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); if ( ! $control_obj instanceof Base_Data_Control ) { continue; } $control = array_merge( $control_obj->get_settings(), $control ); if ( $control_obj instanceof Control_Repeater ) { $style_fields = []; foreach ( $controls_stack->get_settings( $control_name ) as $item ) { $style_fields[] = $this->get_style_controls( $controls_stack, $control['fields'], $item ); } $control['style_fields'] = $style_fields; } if ( ! empty( $control['selectors'] ) || ! empty( $control['dynamic'] ) || $this->is_global_control( $controls_stack, $control_name, $controls ) || ! empty( $control['style_fields'] ) ) { $style_controls[ $control_name ] = $control; } } return $style_controls; } private function parse_global_settings( array $settings, array $controls ) { foreach ( $controls as $control ) { $control_name = $control['name']; $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); if ( ! $control_obj instanceof Base_Data_Control ) { continue; } if ( $control_obj instanceof Control_Repeater ) { foreach ( $settings[ $control_name ] as & $field ) { $field = $this->parse_global_settings( $field, $control['fields'] ); } continue; } if ( empty( $control['global']['active'] ) ) { continue; } if ( empty( $settings['__globals__'][ $control_name ] ) ) { continue; } $settings[ $control_name ] = 'global'; } return $settings; } private function is_global_control( Controls_Stack $controls_stack, $control_name, $controls ) { $control = $controls[ $control_name ]; $control_global_key = $control_name; if ( ! empty( $control['groupType'] ) ) { $control_global_key = $control['groupPrefix'] . $control['groupType']; } if ( empty( $controls[ $control_global_key ]['global']['active'] ) ) { return false; } $globals = $controls_stack->get_settings( '__globals__' ); return ! empty( $globals[ $control_global_key ] ); } }