PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.0-beta1
Elementor Website Builder – more than just a page builder v3.34.0-beta1
4.3.4 4.3.3 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 All 457 releases
← All changes | modules/atomic-widgets/elements/atomic-svg/atomic-svg.php +115 -19 4.2.0-dev2 → 3.34.0-beta1 View file →
@@ -2,21 +2,21 @@
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\Image_Src_Prop_Type;
10 11 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
11 -use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
12 12 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
13 -use Elementor\Modules\AtomicWidgets\PropTypes\Svg_Src_Prop_Type;
14 13 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
15 14 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
16 15 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
17 16 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
18 -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
17 +use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
18 +use Elementor\Utils;
19 19
20 20 if ( ! defined( 'ABSPATH' ) ) {
21 21 exit; // Exit if accessed directly.
22 22 }
@@ -21,17 +21,13 @@
21 21 exit; // Exit if accessed directly.
22 22 }
23 23
24 24 class Atomic_Svg extends Atomic_Widget_Base {
25 - use Has_Template;
26 -
27 25 const BASE_STYLE_KEY = 'base';
28 26 const DEFAULT_SVG = 'images/default-svg.svg';
29 27 const DEFAULT_SVG_PATH = ELEMENTOR_ASSETS_PATH . self::DEFAULT_SVG;
30 28 const DEFAULT_SVG_URL = ELEMENTOR_ASSETS_URL . self::DEFAULT_SVG;
31 29
32 - public static $widget_description = 'Display an SVG image with customizable styles and link options.';
33 -
34 30 public static function get_element_type(): string {
35 31 return 'e-svg';
36 32 }
37 33
@@ -49,11 +45,11 @@
49 45
50 46 protected static function define_props_schema(): array {
51 47 return [
52 48 'classes' => Classes_Prop_Type::make()->default( [] ),
53 - 'svg' => Svg_Src_Prop_Type::make()->default_url( static::DEFAULT_SVG_URL ),
49 + 'svg' => Image_Src_Prop_Type::make()->default_url( static::DEFAULT_SVG_URL ),
54 50 'link' => Link_Prop_Type::make(),
55 - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
51 + 'attributes' => Attributes_Prop_Type::make(),
56 52 ];
57 53 }
58 54
59 55 protected function define_atomic_controls(): array {
@@ -59,9 +55,8 @@
59 55 protected function define_atomic_controls(): array {
60 56 return [
61 57 Section::make()
62 58 ->set_label( esc_html__( 'Content', 'elementor' ) )
63 - ->set_id( 'content' )
64 59 ->set_items( [
65 60 Svg_Control::bind_to( 'svg' )
66 61 ->set_label( __( 'SVG', 'elementor' ) ),
67 62 ] ),
@@ -101,14 +96,115 @@
101 96 ),
102 97 ];
103 98 }
104 99
105 - protected function get_templates(): array {
106 - return [
107 - 'elementor/elements/atomic-svg' => __DIR__ . '/atomic-svg.html.twig',
108 - ];
100 + protected function render() {
101 + $settings = $this->get_atomic_settings();
102 +
103 + $svg = $this->get_svg_content( $settings );
104 +
105 + if ( ! $svg ) {
106 + return;
107 + }
108 +
109 + $svg = new \WP_HTML_Tag_Processor( $svg );
110 +
111 + if ( ! $svg->next_tag( 'svg' ) ) {
112 + return;
113 + }
114 +
115 + $svg->set_attribute( 'fill', 'currentColor' );
116 + $svg->set_attribute( 'data-interaction-id', $this->get_id() );
117 +
118 + $interaction_ids = $this->get_interactions_ids();
119 + if ( ! empty( $interaction_ids ) ) {
120 + $svg->set_attribute( 'data-interactions', wp_json_encode( $interaction_ids ) );
121 + }
122 +
123 + $this->add_svg_style( $svg, 'width: 100%; height: 100%; overflow: unset;' );
124 +
125 + $svg_html = ( new Svg_Sanitizer() )->sanitize( $svg->get_updated_html() );
126 +
127 + $classes = array_filter( array_merge(
128 + [ self::BASE_STYLE_KEY => $this->get_base_styles_dictionary()[ self::BASE_STYLE_KEY ] ],
129 + $settings['classes']
130 + ) );
131 +
132 + $classes_string = implode( ' ', $classes );
133 +
134 + $cssid_attribute = ! empty( $settings['_cssid'] ) ? 'id="' . esc_attr( $settings['_cssid'] ) . '"' : '';
135 +
136 + $all_attributes = trim( $cssid_attribute . ' ' . $settings['attributes'] );
137 +
138 + $data_attributes_string = '';
139 +
140 + if ( ! empty( $interaction_ids ) ) {
141 + $data_attributes_string = sprintf(
142 + 'data-interaction-id="%s" data-interactions="%s"',
143 + esc_attr( $this->get_id() ),
144 + esc_attr( wp_json_encode( $interaction_ids ) )
145 + );
146 + }
147 +
148 + $attributes_string = trim( $data_attributes_string . ' ' . $all_attributes );
149 +
150 + if ( isset( $settings['link'] ) && ! empty( $settings['link']['href'] ) ) {
151 + $svg_html = sprintf(
152 + '<a href="%s" target="%s" class="%s" %s>%s</a>',
153 + $settings['link']['href'],
154 + esc_attr( $settings['link']['target'] ),
155 + esc_attr( $classes_string ),
156 + $attributes_string,
157 + $svg_html
158 + );
159 + } else {
160 + $svg_html = sprintf( '<div class="%s" %s>%s</div>', esc_attr( $classes_string ), $attributes_string, $svg_html );
161 + }
162 +
163 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
164 + echo $svg_html;
109 165 }
110 166
111 - public function render_markdown(): string {
112 - return '';
167 + private function get_svg_content( $settings ) {
168 + if ( isset( $settings['svg']['id'] ) ) {
169 + $content = Utils::file_get_contents(
170 + get_attached_file( $settings['svg']['id'] )
171 + );
172 +
173 + if ( $content ) {
174 + return $content;
175 + }
176 + }
177 +
178 + if (
179 + isset( $settings['svg']['url'] ) &&
180 + static::DEFAULT_SVG_URL !== $settings['svg']['url']
181 + ) {
182 + $content = wp_safe_remote_get(
183 + $settings['svg']['url']
184 + );
185 +
186 + if ( ! is_wp_error( $content ) ) {
187 + return $content['body'];
188 + }
189 + }
190 +
191 + $content = Utils::file_get_contents(
192 + static::DEFAULT_SVG_PATH
193 + );
194 +
195 + return $content ? $content : null;
196 + }
197 +
198 + private function add_svg_style( &$svg, $new_style ) {
199 + $svg_style = $svg->get_attribute( 'style' );
200 + $svg_style = trim( (string) $svg_style );
201 +
202 + if ( empty( $svg_style ) ) {
203 + $svg_style = $new_style;
204 + } else {
205 + $svg_style = rtrim( $svg_style, ';' ) . '; ' . $new_style;
206 + }
207 +
208 + $svg->set_attribute( 'style', $svg_style );
113 209 }
114 210 }