PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-dev2
Elementor Website Builder – more than just a page builder v3.28.0-dev2
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
← All changes | modules/atomic-widgets/elements/atomic-svg/atomic-svg.php +54 -52 4.1.0-beta3 → 3.28.0-dev2 View file →
@@ -2,21 +2,18 @@
2 2 namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Svg;
3 3
4 4 use Elementor\Modules\AtomicWidgets\Controls\Section;
5 5 use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
6 +use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
7 +use Elementor\Modules\AtomicWidgets\Elements\Atomic_Widget_Base;
8 +use Elementor\Core\Utils\Svg\Svg_Sanitizer;
6 9 use Elementor\Modules\AtomicWidgets\Controls\Types\Svg_Control;
7 -use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
8 -use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base;
9 -use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template;
10 -use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
11 -use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
10 +use Elementor\Modules\AtomicWidgets\PropTypes\Image_Src_Prop_Type;
11 +
12 12 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
13 -use Elementor\Modules\AtomicWidgets\PropTypes\Svg_Src_Prop_Type;
14 -use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
15 13 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
16 14 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
17 15 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
18 -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
19 16
20 17 if ( ! defined( 'ABSPATH' ) ) {
21 18 exit; // Exit if accessed directly.
22 19 }
@@ -21,29 +18,20 @@
21 18 exit; // Exit if accessed directly.
22 19 }
23 20
24 21 class Atomic_Svg extends Atomic_Widget_Base {
25 - use Has_Template;
26 -
27 22 const BASE_STYLE_KEY = 'base';
28 - const DEFAULT_SVG = 'images/default-svg.svg';
29 - const DEFAULT_SVG_PATH = ELEMENTOR_ASSETS_PATH . self::DEFAULT_SVG;
30 - const DEFAULT_SVG_URL = ELEMENTOR_ASSETS_URL . self::DEFAULT_SVG;
23 + const DEFAULT_SIZE = 'full';
24 + const DEFAULT_SVG_PATH = ELEMENTOR_ASSETS_URL . 'images/a-default-svg.svg';
31 25
32 - public static $widget_description = 'Display an SVG image with customizable styles and link options.';
33 -
34 26 public static function get_element_type(): string {
35 - return 'e-svg';
27 + return 'a-svg';
36 28 }
37 29
38 30 public function get_title() {
39 - return esc_html__( 'SVG', 'elementor' );
31 + return esc_html__( 'Atomic SVG', 'elementor' );
40 32 }
41 33
42 - public function get_keywords() {
43 - return [ 'ato', 'atom', 'atoms', 'atomic' ];
44 - }
45 -
46 34 public function get_icon() {
47 35 return 'eicon-svg';
48 36 }
49 37
@@ -49,11 +37,10 @@
49 37
50 38 protected static function define_props_schema(): array {
51 39 return [
52 40 'classes' => Classes_Prop_Type::make()->default( [] ),
53 - 'svg' => Svg_Src_Prop_Type::make()->default_url( static::DEFAULT_SVG_URL ),
41 + 'svg' => Image_Src_Prop_Type::make()->default_url( self::DEFAULT_SVG_PATH ),
54 42 'link' => Link_Prop_Type::make(),
55 - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
56 43 ];
57 44 }
58 45
59 46 protected function define_atomic_controls(): array {
@@ -60,54 +47,69 @@
60 47 return [
61 48 Section::make()
62 49 ->set_label( esc_html__( 'Content', 'elementor' ) )
63 50 ->set_items( [
64 - Svg_Control::bind_to( 'svg' )
65 - ->set_label( __( 'SVG', 'elementor' ) ),
51 + Svg_Control::bind_to( 'svg' ),
52 + Link_Control::bind_to( 'link' )
53 + ->set_placeholder( __( 'Paste URL or type', 'elementor' ) ),
66 54 ] ),
67 - Section::make()
68 - ->set_label( __( 'Settings', 'elementor' ) )
69 - ->set_id( 'settings' )
70 - ->set_items( $this->get_settings_controls() ),
71 55 ];
72 56 }
73 57
74 - protected function get_settings_controls(): array {
75 - return [
76 - Link_Control::bind_to( 'link' )
77 - ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
78 - ->set_label( __( 'Link', 'elementor' ) ),
79 - Text_Control::bind_to( '_cssid' )
80 - ->set_label( __( 'ID', 'elementor' ) )
81 - ->set_meta( $this->get_css_id_control_meta() ),
82 - ];
83 - }
84 -
85 58 protected function define_base_styles(): array {
86 - $display_value = String_Prop_Type::generate( 'inline-block' );
87 -
88 - $size = Size_Prop_Type::generate( [
59 + $width = Size_Prop_Type::generate( [
89 60 'size' => 65,
90 61 'unit' => 'px',
91 62 ] );
63 + $height = Size_Prop_Type::generate( [
64 + 'size' => 65,
65 + 'unit' => 'px',
66 + ] );
92 67
93 68 return [
94 69 self::BASE_STYLE_KEY => Style_Definition::make()
95 70 ->add_variant(
96 71 Style_Variant::make()
97 - ->add_prop( 'display', $display_value )
98 - ->add_prop( 'width', $size )
99 - ->add_prop( 'height', $size )
72 + ->add_prop( 'width', $width )
73 + ->add_prop( 'height', $height )
100 74 ),
101 75 ];
102 76 }
103 77
104 - protected function get_templates(): array {
105 - return [
106 - 'elementor/elements/atomic-svg' => __DIR__ . '/atomic-svg.html.twig',
107 - ];
78 + protected function render() {
79 + $settings = $this->get_atomic_settings();
80 + $svg_url = isset( $settings['svg']['url'] ) ? $settings['svg']['url'] : null;
81 +
82 + if ( ! $svg_url && isset( $settings['svg']['id'] ) ) {
83 + $attachment = wp_get_attachment_image_src( $settings['svg']['id'], self::DEFAULT_SIZE );
84 + $svg_url = isset( $attachment[0] ) ? $attachment[0] : null;
85 + }
86 +
87 + $svg = file_get_contents( $svg_url );
88 + $svg = $svg ? new \WP_HTML_Tag_Processor( $svg ) : null;
89 +
90 + if ( $svg && $svg->next_tag( 'svg' ) ) {
91 + $this->set_svg_attributes( $svg, $settings );
92 + }
93 +
94 + if ( $svg ) {
95 + $svg_html = ( new Svg_Sanitizer() )->sanitize( $svg->get_updated_html() );
96 + }
97 +
98 + $svg_html = $svg_html ?? file_get_contents( self::DEFAULT_SVG_PATH );
99 +
100 + if ( isset( $settings['link'] ) && ! empty( $settings['link']['href'] ) ) {
101 + $svg_html = sprintf( '<a href="%s" target="%s"> %s </a>', esc_url( $settings['link']['href'] ), esc_attr( $settings['link']['target'] ), $svg_html );
102 + }
103 +
104 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
105 + echo $svg_html;
108 106 }
109 107
110 - public function render_markdown(): string {
111 - return '';
108 + private function set_svg_attributes( \WP_HTML_Tag_Processor $svg, $settings ) {
109 + $svg->set_attribute( 'fill', 'currentColor' );
110 + $string_classes = implode( ' ', $settings['classes'] );
111 + $svg->add_class( $string_classes );
112 + $base_styles = $this->get_base_styles_dictionary()[ self::BASE_STYLE_KEY ];
113 + $svg->add_class( $base_styles );
112 114 }
113 115 }