PluginProbe
Elementor Website Builder – more than just a page builder / 3.33.0-beta1
Elementor Website Builder – more than just a page builder v3.33.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 +98 -32 4.3.3 → 3.33.0-beta1 View file →
@@ -2,25 +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\Module as Atomic_Widgets_Module;
11 -use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer;
10 +use Elementor\Modules\AtomicWidgets\PropTypes\Image_Src_Prop_Type;
12 11 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
13 -use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
14 -use Elementor\Modules\AtomicWidgets\PropTypes\Icon_Prop_Type;
15 12 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
16 13 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
17 14 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
18 -use Elementor\Modules\AtomicWidgets\PropTypes\Svg_Src_Prop_Type;
19 -use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type;
20 15 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
21 16 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
22 -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
17 +use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
18 +use Elementor\Utils;
23 19
24 20 if ( ! defined( 'ABSPATH' ) ) {
25 21 exit; // Exit if accessed directly.
26 22 }
@@ -25,17 +21,13 @@
25 21 exit; // Exit if accessed directly.
26 22 }
27 23
28 24 class Atomic_Svg extends Atomic_Widget_Base {
29 - use Has_Template;
30 -
31 25 const BASE_STYLE_KEY = 'base';
32 26 const DEFAULT_SVG = 'images/default-svg.svg';
33 27 const DEFAULT_SVG_PATH = ELEMENTOR_ASSETS_PATH . self::DEFAULT_SVG;
34 28 const DEFAULT_SVG_URL = ELEMENTOR_ASSETS_URL . self::DEFAULT_SVG;
35 29
36 - public static $widget_description = 'Display an SVG image with customizable styles and link options.';
37 -
38 30 public static function get_element_type(): string {
39 31 return 'e-svg';
40 32 }
41 33
@@ -43,9 +35,9 @@
43 35 return esc_html__( 'SVG', 'elementor' );
44 36 }
45 37
46 38 public function get_keywords() {
47 - return [ 'ato', 'atom', 'atoms', 'atomic', 'svg', 'icon', 'vector' ];
39 + return [ 'ato', 'atom', 'atoms', 'atomic' ];
48 40 }
49 41
50 42 public function get_icon() {
51 43 return 'eicon-svg';
@@ -50,20 +42,14 @@
50 42 public function get_icon() {
51 43 return 'eicon-svg';
52 44 }
53 45
54 - public static function get_computed_html_tag( array $settings ): string {
55 - return Html_Tag_Computer::compute( $settings, 'div' );
56 - }
57 -
58 46 protected static function define_props_schema(): array {
59 47 return [
60 48 'classes' => Classes_Prop_Type::make()->default( [] ),
61 - 'svg' => Union_Prop_Type::create_from(
62 - Svg_Src_Prop_Type::make()->default_url( static::DEFAULT_SVG_URL )
63 - )->add_prop_type( Icon_Prop_Type::make() ),
49 + 'svg' => Image_Src_Prop_Type::make()->default_url( static::DEFAULT_SVG_URL ),
64 50 'link' => Link_Prop_Type::make(),
65 - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
51 + 'attributes' => Attributes_Prop_Type::make(),
66 52 ];
67 53 }
68 54
69 55 protected function define_atomic_controls(): array {
@@ -69,13 +55,11 @@
69 55 protected function define_atomic_controls(): array {
70 56 return [
71 57 Section::make()
72 58 ->set_label( esc_html__( 'Content', 'elementor' ) )
73 - ->set_id( 'content' )
74 59 ->set_items( [
75 60 Svg_Control::bind_to( 'svg' )
76 - ->set_label( __( 'SVG', 'elementor' ) )
77 - ->set_show_icon_library( Atomic_Widgets_Module::is_svg_library_active() ),
61 + ->set_label( __( 'SVG', 'elementor' ) ),
78 62 ] ),
79 63 Section::make()
80 64 ->set_label( __( 'Settings', 'elementor' ) )
81 65 ->set_id( 'settings' )
@@ -112,14 +96,96 @@
112 96 ),
113 97 ];
114 98 }
115 99
116 - protected function get_templates(): array {
117 - return [
118 - 'elementor/elements/atomic-svg' => __DIR__ . '/atomic-svg.html.twig',
119 - ];
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 + $this->add_svg_style( $svg, 'width: 100%; height: 100%; overflow: unset;' );
117 +
118 + $svg_html = ( new Svg_Sanitizer() )->sanitize( $svg->get_updated_html() );
119 +
120 + $classes = array_filter( array_merge(
121 + [ self::BASE_STYLE_KEY => $this->get_base_styles_dictionary()[ self::BASE_STYLE_KEY ] ],
122 + $settings['classes']
123 + ) );
124 +
125 + $classes_string = implode( ' ', $classes );
126 +
127 + $cssid_attribute = ! empty( $settings['_cssid'] ) ? 'id="' . esc_attr( $settings['_cssid'] ) . '"' : '';
128 +
129 + $all_attributes = trim( $cssid_attribute . ' ' . $settings['attributes'] );
130 +
131 + if ( isset( $settings['link'] ) && ! empty( $settings['link']['href'] ) ) {
132 + $svg_html = sprintf(
133 + '<a href="%s" target="%s" class="%s" %s>%s</a>',
134 + $settings['link']['href'],
135 + esc_attr( $settings['link']['target'] ),
136 + esc_attr( $classes_string ),
137 + $all_attributes,
138 + $svg_html
139 + );
140 + } else {
141 + $svg_html = sprintf( '<div class="%s" %s>%s</div>', esc_attr( $classes_string ), $all_attributes, $svg_html );
142 + }
143 +
144 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
145 + echo $svg_html;
120 146 }
121 147
122 - public function render_markdown(): string {
123 - return '';
148 + private function get_svg_content( $settings ) {
149 + if ( isset( $settings['svg']['id'] ) ) {
150 + $content = Utils::file_get_contents(
151 + get_attached_file( $settings['svg']['id'] )
152 + );
153 +
154 + if ( $content ) {
155 + return $content;
156 + }
157 + }
158 +
159 + if (
160 + isset( $settings['svg']['url'] ) &&
161 + static::DEFAULT_SVG_URL !== $settings['svg']['url']
162 + ) {
163 + $content = wp_safe_remote_get(
164 + $settings['svg']['url']
165 + );
166 +
167 + if ( ! is_wp_error( $content ) ) {
168 + return $content['body'];
169 + }
170 + }
171 +
172 + $content = Utils::file_get_contents(
173 + static::DEFAULT_SVG_PATH
174 + );
175 +
176 + return $content ? $content : null;
177 + }
178 +
179 + private function add_svg_style( &$svg, $new_style ) {
180 + $svg_style = $svg->get_attribute( 'style' );
181 + $svg_style = trim( (string) $svg_style );
182 +
183 + if ( empty( $svg_style ) ) {
184 + $svg_style = $new_style;
185 + } else {
186 + $svg_style = rtrim( $svg_style, ';' ) . '; ' . $new_style;
187 + }
188 +
189 + $svg->set_attribute( 'style', $svg_style );
124 190 }
125 191 }