PluginProbe
Elementor Website Builder – more than just a page builder / 3.23.0-dev3
Elementor Website Builder – more than just a page builder v3.23.0-dev3
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 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / core / base / traits / shared-widget-controls-trait.php

shared-widget-controls-trait.php in Elementor Website Builder – more than just a page builder 3.23.0-dev3, at core/base/traits/shared-widget-controls-trait.php

297 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Core\Base\Traits;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Modules\FloatingButtons\Control\Hover_Animation_Floating_Buttons;
7 use Elementor\Plugin;
8 use Elementor\Shapes;
9 use Elementor\Utils;
10
11 trait Shared_Widget_Controls_Trait {
12
13 protected $border_width_range = [
14 'min' => 0,
15 'max' => 10,
16 'step' => 1,
17 ];
18
19 protected function add_html_tag_control( string $name, string $default = 'h2' ): void {
20 $this->add_control(
21 $name,
22 [
23 'label' => esc_html__( 'HTML Tag', 'elementor' ),
24 'type' => Controls_Manager::SELECT,
25 'options' => [
26 'h1' => 'H1',
27 'h2' => 'H2',
28 'h3' => 'H3',
29 'h4' => 'H4',
30 'h5' => 'H5',
31 'h6' => 'H6',
32 'div' => 'div',
33 'span' => 'span',
34 'p' => 'p',
35 ],
36 'default' => $default,
37 ]
38 );
39 }
40
41 /**
42 * Remove any child arrays where all properties are empty
43 */
44 protected function clean_array(
45 $input_array = []
46 ) {
47 $output_array = array_filter( $input_array, function( $sub_array ) {
48 // Use array_filter on the sub array
49 $filtered_sub_array = array_filter( $sub_array, function( $val ) {
50 // Filter out empty or null values
51 return ! is_null( $val ) && '' !== $val;
52 } );
53 // A non-empty result means the sub array contains some non-empty value(s)
54 return ! empty( $filtered_sub_array );
55 } );
56 return $output_array;
57 }
58
59 protected function get_link_attributes(
60 $link = [],
61 $other_attributes = []
62 ) {
63 $url_attrs = [];
64 $rel_string = '';
65
66 if ( ! empty( $link['url'] ) ) {
67 $url_attrs['href'] = esc_url( $link['url'] );
68 }
69
70 if ( ! empty( $link['is_external'] ) ) {
71 $url_attrs['target'] = '_blank';
72 $rel_string .= 'noopener ';
73 }
74
75 if ( ! empty( $link['nofollow'] ) ) {
76 $rel_string .= 'nofollow ';
77 }
78
79 if ( ! empty( $rel_string ) ) {
80 $url_attrs['rel'] = $rel_string;
81 }
82
83 /**
84 * Note - we deliberately merge $other_attributes second
85 * to allow overriding default attributes values such as a more formatted href
86 */
87 $url_combined_attrs = array_merge(
88 $url_attrs,
89 $other_attributes,
90 Utils::parse_custom_attributes( $link['custom_attributes'] ?? '' ),
91 );
92
93 return $url_combined_attrs;
94 }
95
96 protected function add_icons_per_row_control(
97 string $name = 'icons_per_row',
98 $options = [
99 '2' => '2',
100 '3' => '3',
101 ],
102 string $default = '3',
103 $label = '',
104 $selector_custom_property = '--e-link-in-bio-icon-columns'
105 ): void {
106 if ( ! $label ) {
107 $label = esc_html__( 'Icons Per Row', 'elementor' );
108 }
109 $this->add_control(
110 $name,
111 [
112 'label' => $label,
113 'type' => Controls_Manager::SELECT,
114 'options' => $options,
115 'default' => $default,
116 'selectors' => [
117 '{{WRAPPER}} .e-link-in-bio' => $selector_custom_property . ': {{VALUE}};',
118 ],
119 ]
120 );
121 }
122
123 protected function add_slider_control(
124 string $name,
125 array $args = []
126 ): void {
127 $default_args = [
128 'type' => Controls_Manager::SLIDER,
129 'default' => [
130 'unit' => 'px',
131 ],
132 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
133 'range' => [
134 'px' => [
135 'min' => 0,
136 'max' => 100,
137 'step' => 1,
138 ],
139 ],
140 ];
141
142 $this->add_control(
143 $name,
144 array_merge_recursive( $default_args, $args )
145 );
146 }
147
148 protected function add_borders_control(
149 string $prefix,
150 array $show_border_args = [],
151 array $border_width_args = [],
152 array $border_color_args = []
153 ): void {
154 $show_border = [
155 'label' => esc_html__( 'Border', 'elementor' ),
156 'type' => Controls_Manager::SWITCHER,
157 'label_on' => esc_html__( 'Yes', 'elementor' ),
158 'label_off' => esc_html__( 'No', 'elementor' ),
159 'return_value' => 'yes',
160 'default' => '',
161 ];
162
163 $this->add_control(
164 $prefix . '_show_border',
165 array_merge( $show_border, $show_border_args )
166 );
167
168 $condition = [
169 $prefix . '_show_border' => 'yes',
170 ];
171
172 if ( isset( $border_width_args['condition'] ) ) {
173 $condition = array_merge( $condition, $border_width_args['condition'] );
174 unset( $border_width_args['condition'] );
175 }
176
177 $border_width = [
178 'label' => esc_html__( 'Border Width', 'elementor' ) . ' (px)',
179 'type' => Controls_Manager::SLIDER,
180 'size_units' => [ 'px' ],
181 'range' => [
182 'px' => $this->border_width_range,
183 ],
184 'condition' => $condition,
185 'default' => [
186 'unit' => 'px',
187 'size' => 1,
188 ],
189 ];
190
191 $this->add_responsive_control(
192 $prefix . '_border_width',
193 array_merge( $border_width, $border_width_args ),
194 );
195
196 $condition = [
197 $prefix . '_show_border' => 'yes',
198 ];
199
200 if ( isset( $border_color_args['condition'] ) ) {
201 $condition = array_merge( $condition, $border_color_args['condition'] );
202 unset( $border_color_args['condition'] );
203 }
204
205 $border_color = [
206 'label' => esc_html__( 'Border Color', 'elementor' ),
207 'type' => Controls_Manager::COLOR,
208 'condition' => $condition,
209 'default' => '#000000',
210 ];
211
212 $this->add_control(
213 $prefix . '_border_color',
214 array_merge( $border_color, $border_color_args )
215 );
216 }
217
218 protected function get_shape_divider( $side = 'bottom' ) {
219 $settings = $this->settings;
220 $base_setting_key = "identity_section_style_cover_divider_$side";
221 $file_name = $settings[ $base_setting_key ];
222
223 if ( empty( $file_name ) ) {
224 return [];
225 }
226
227 $negative = ! empty( $settings[ $base_setting_key . '_negative' ] );
228 $shape_path = Shapes::get_shape_path( $file_name, $negative );
229
230 if ( ! is_file( $shape_path ) || ! is_readable( $shape_path ) ) {
231 return [];
232 }
233
234 return [
235 'negative' => $negative,
236 'svg' => Utils::file_get_contents( $shape_path ),
237 ];
238 }
239
240 protected function print_shape_divider( $side = 'bottom' ) {
241 $shape_divider = $this->get_shape_divider( $side );
242
243 if ( empty( $shape_divider ) ) {
244 return;
245 }
246 ?>
247 <div
248 class="elementor-shape elementor-shape-<?php echo esc_attr( $side ); ?>"
249 data-negative="<?php
250 echo esc_attr( $shape_divider['negative'] ? 'true' : 'false' );
251 ?>"
252 >
253 <?php
254 // PHPCS - The file content is being read from a strict file path structure.
255 echo $shape_divider['svg']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
256 ?>
257 </div>
258 <?php
259 }
260
261 protected function get_configured_breakpoints( $add_desktop = 'true' ) {
262 $active_devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] );
263 $active_breakpoint_instances = Plugin::$instance->breakpoints->get_active_breakpoints();
264
265 $devices_options = [];
266
267 foreach ( $active_devices as $device_key ) {
268 $device_label = 'desktop' === $device_key ? esc_html__( 'Desktop', 'elementor' ) : $active_breakpoint_instances[ $device_key ]->get_label();
269 $devices_options[ $device_key ] = $device_label;
270 }
271
272 return [
273 'active_devices' => $active_devices,
274 'devices_options' => $devices_options,
275 ];
276 }
277
278 protected function add_hover_animation_control(
279 string $name,
280 array $args = []
281 ): void {
282
283 $this->add_control(
284 $name,
285 array_merge(
286 [
287 'label' => esc_html__( 'Hover Animation', 'elementor' ),
288 'type' => Hover_Animation_Floating_Buttons::TYPE,
289 'frontend_available' => true,
290 'default' => 'grow',
291 ],
292 $args
293 )
294 );
295 }
296 }
297