PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.0-dev4
Elementor Website Builder – more than just a page builder v3.26.0-dev4
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 4.0.7 All 451 releases
elementor / includes / widgets / image-gallery.php

image-gallery.php in Elementor Website Builder – more than just a page builder 3.26.0-dev4, at includes/widgets/image-gallery.php

459 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor image gallery widget.
12 *
13 * Elementor widget that displays a set of images in an aligned grid.
14 *
15 * @since 1.0.0
16 */
17 class Widget_Image_Gallery extends Widget_Base {
18
19 /**
20 * Get widget name.
21 *
22 * Retrieve image gallery widget name.
23 *
24 * @since 1.0.0
25 * @access public
26 *
27 * @return string Widget name.
28 */
29 public function get_name() {
30 return 'image-gallery';
31 }
32
33 /**
34 * Get widget title.
35 *
36 * Retrieve image gallery widget title.
37 *
38 * @since 1.0.0
39 * @access public
40 *
41 * @return string Widget title.
42 */
43 public function get_title() {
44 return esc_html__( 'Basic Gallery', 'elementor' );
45 }
46
47 /**
48 * Get widget icon.
49 *
50 * Retrieve image gallery widget icon.
51 *
52 * @since 1.0.0
53 * @access public
54 *
55 * @return string Widget icon.
56 */
57 public function get_icon() {
58 return 'eicon-gallery-grid';
59 }
60
61 /**
62 * Get widget keywords.
63 *
64 * Retrieve the list of keywords the widget belongs to.
65 *
66 * @since 2.1.0
67 * @access public
68 *
69 * @return array Widget keywords.
70 */
71 public function get_keywords() {
72 return [ 'image', 'photo', 'visual', 'gallery' ];
73 }
74
75 protected function is_dynamic_content(): bool {
76 return false;
77 }
78
79 /**
80 * Get style dependencies.
81 *
82 * Retrieve the list of style dependencies the widget requires.
83 *
84 * @since 3.24.0
85 * @access public
86 *
87 * @return array Widget style dependencies.
88 */
89 public function get_style_depends(): array {
90 return [ 'widget-image-gallery' ];
91 }
92
93 /**
94 * Get widget upsale data.
95 *
96 * Retrieve the widget promotion data.
97 *
98 * @since 3.18.0
99 * @access protected
100 *
101 * @return array Widget promotion data.
102 */
103 protected function get_upsale_data() {
104 return [
105 'condition' => ! Utils::has_pro(),
106 'image' => esc_url( ELEMENTOR_ASSETS_URL . 'images/go-pro.svg' ),
107 'image_alt' => esc_attr__( 'Upgrade', 'elementor' ),
108 'description' => esc_html__( 'Use interesting masonry layouts and other overlay features with Elementor\'s Pro Gallery widget.', 'elementor' ),
109 'upgrade_url' => esc_url( 'https://go.elementor.com/go-pro-basic-gallery-widget/' ),
110 'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ),
111 ];
112 }
113
114 public function has_widget_inner_wrapper(): bool {
115 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
116 }
117
118 /**
119 * Register image gallery widget controls.
120 *
121 * Adds different input fields to allow the user to change and customize the widget settings.
122 *
123 * @since 3.1.0
124 * @access protected
125 */
126 protected function register_controls() {
127 $this->start_controls_section(
128 'section_gallery',
129 [
130 'label' => esc_html__( 'Basic Gallery', 'elementor' ),
131 ]
132 );
133
134 $this->add_control(
135 'wp_gallery',
136 [
137 'label' => esc_html__( 'Add Images', 'elementor' ),
138 'type' => Controls_Manager::GALLERY,
139 'show_label' => false,
140 'dynamic' => [
141 'active' => true,
142 ],
143 ]
144 );
145
146 $this->add_group_control(
147 Group_Control_Image_Size::get_type(),
148 [
149 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
150 'exclude' => [ 'custom' ],
151 ]
152 );
153
154 $gallery_columns = range( 1, 10 );
155 $gallery_columns = array_combine( $gallery_columns, $gallery_columns );
156
157 $this->add_control(
158 'gallery_columns',
159 [
160 'label' => esc_html__( 'Columns', 'elementor' ),
161 'type' => Controls_Manager::SELECT,
162 'default' => 4,
163 'options' => $gallery_columns,
164 ]
165 );
166
167 $this->add_control(
168 'gallery_display_caption',
169 [
170 'label' => esc_html__( 'Caption', 'elementor' ),
171 'type' => Controls_Manager::SELECT,
172 'default' => '',
173 'options' => [
174 'none' => esc_html__( 'None', 'elementor' ),
175 '' => esc_html__( 'Attachment Caption', 'elementor' ),
176 ],
177 'selectors' => [
178 '{{WRAPPER}} .gallery-item .gallery-caption' => 'display: {{VALUE}};',
179 ],
180 ]
181 );
182
183 $this->add_control(
184 'gallery_link',
185 [
186 'label' => esc_html__( 'Link', 'elementor' ),
187 'type' => Controls_Manager::SELECT,
188 'default' => 'file',
189 'options' => [
190 'file' => esc_html__( 'Media File', 'elementor' ),
191 'attachment' => esc_html__( 'Attachment Page', 'elementor' ),
192 'none' => esc_html__( 'None', 'elementor' ),
193 ],
194 ]
195 );
196
197 $this->add_control(
198 'open_lightbox',
199 [
200 'label' => esc_html__( 'Lightbox', 'elementor' ),
201 'type' => Controls_Manager::SELECT,
202 'description' => sprintf(
203 /* translators: 1: Link open tag, 2: Link close tag. */
204 esc_html__( 'Manage your site’s lightbox settings in the %1$sLightbox panel%2$s.', 'elementor' ),
205 '<a href="javascript: $e.run( \'panel/global/open\' ).then( () => $e.route( \'panel/global/settings-lightbox\' ) )">',
206 '</a>'
207 ),
208 'default' => 'default',
209 'options' => [
210 'default' => esc_html__( 'Default', 'elementor' ),
211 'yes' => esc_html__( 'Yes', 'elementor' ),
212 'no' => esc_html__( 'No', 'elementor' ),
213 ],
214 'condition' => [
215 'gallery_link' => 'file',
216 ],
217 ]
218 );
219
220 $this->add_control(
221 'gallery_rand',
222 [
223 'label' => esc_html__( 'Order By', 'elementor' ),
224 'type' => Controls_Manager::SELECT,
225 'options' => [
226 '' => esc_html__( 'Default', 'elementor' ),
227 'rand' => esc_html__( 'Random', 'elementor' ),
228 ],
229 'default' => '',
230 ]
231 );
232
233 $this->end_controls_section();
234
235 $this->start_controls_section(
236 'section_gallery_images',
237 [
238 'label' => esc_html__( 'Images', 'elementor' ),
239 'tab' => Controls_Manager::TAB_STYLE,
240 ]
241 );
242
243 $this->add_control(
244 'image_spacing',
245 [
246 'label' => esc_html__( 'Spacing', 'elementor' ),
247 'type' => Controls_Manager::SELECT,
248 'options' => [
249 '' => esc_html__( 'Default', 'elementor' ),
250 'custom' => esc_html__( 'Custom', 'elementor' ),
251 ],
252 'prefix_class' => 'gallery-spacing-',
253 'default' => '',
254 ]
255 );
256
257 $columns_margin = is_rtl() ? '0 0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}};' : '0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}} 0;';
258 $columns_padding = is_rtl() ? '0 0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}};' : '0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}} 0;';
259
260 $this->add_control(
261 'image_spacing_custom',
262 [
263 'label' => esc_html__( 'Custom Spacing', 'elementor' ),
264 'type' => Controls_Manager::SLIDER,
265 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
266 'range' => [
267 'px' => [
268 'max' => 100,
269 ],
270 'em' => [
271 'max' => 10,
272 ],
273 'rem' => [
274 'max' => 10,
275 ],
276 ],
277 'default' => [
278 'size' => 15,
279 ],
280 'selectors' => [
281 '{{WRAPPER}} .gallery-item' => 'padding:' . $columns_padding,
282 '{{WRAPPER}} .gallery' => 'margin: ' . $columns_margin,
283 ],
284 'condition' => [
285 'image_spacing' => 'custom',
286 ],
287 ]
288 );
289
290 $this->add_group_control(
291 Group_Control_Border::get_type(),
292 [
293 'name' => 'image_border',
294 'selector' => '{{WRAPPER}} .gallery-item img',
295 'separator' => 'before',
296 ]
297 );
298
299 $this->add_responsive_control(
300 'image_border_radius',
301 [
302 'label' => esc_html__( 'Border Radius', 'elementor' ),
303 'type' => Controls_Manager::DIMENSIONS,
304 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
305 'selectors' => [
306 '{{WRAPPER}} .gallery-item img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
307 ],
308 ]
309 );
310
311 $this->end_controls_section();
312
313 $this->start_controls_section(
314 'section_caption',
315 [
316 'label' => esc_html__( 'Caption', 'elementor' ),
317 'tab' => Controls_Manager::TAB_STYLE,
318 'condition' => [
319 'gallery_display_caption' => '',
320 ],
321 ]
322 );
323
324 $this->add_responsive_control(
325 'align',
326 [
327 'label' => esc_html__( 'Alignment', 'elementor' ),
328 'type' => Controls_Manager::CHOOSE,
329 'options' => [
330 'left' => [
331 'title' => esc_html__( 'Left', 'elementor' ),
332 'icon' => 'eicon-text-align-left',
333 ],
334 'center' => [
335 'title' => esc_html__( 'Center', 'elementor' ),
336 'icon' => 'eicon-text-align-center',
337 ],
338 'right' => [
339 'title' => esc_html__( 'Right', 'elementor' ),
340 'icon' => 'eicon-text-align-right',
341 ],
342 'justify' => [
343 'title' => esc_html__( 'Justified', 'elementor' ),
344 'icon' => 'eicon-text-align-justify',
345 ],
346 ],
347 'default' => 'center',
348 'selectors' => [
349 '{{WRAPPER}} .gallery-item .gallery-caption' => 'text-align: {{VALUE}};',
350 ],
351 'condition' => [
352 'gallery_display_caption' => '',
353 ],
354 ]
355 );
356
357 $this->add_control(
358 'text_color',
359 [
360 'label' => esc_html__( 'Text Color', 'elementor' ),
361 'type' => Controls_Manager::COLOR,
362 'default' => '',
363 'selectors' => [
364 '{{WRAPPER}} .gallery-item .gallery-caption' => 'color: {{VALUE}};',
365 ],
366 'condition' => [
367 'gallery_display_caption' => '',
368 ],
369 ]
370 );
371
372 $this->add_group_control(
373 Group_Control_Typography::get_type(),
374 [
375 'name' => 'typography',
376 'global' => [
377 'default' => Global_Typography::TYPOGRAPHY_ACCENT,
378 ],
379 'selector' => '{{WRAPPER}} .gallery-item .gallery-caption',
380 'condition' => [
381 'gallery_display_caption' => '',
382 ],
383 ]
384 );
385
386 $this->add_group_control(
387 Group_Control_Text_Shadow::get_type(),
388 [
389 'name' => 'caption_shadow',
390 'selector' => '{{WRAPPER}} .gallery-item .gallery-caption',
391 'condition' => [
392 'gallery_display_caption' => '',
393 ],
394 ]
395 );
396
397 $this->add_responsive_control(
398 'caption_space',
399 [
400 'label' => esc_html__( 'Spacing', 'elementor' ),
401 'type' => Controls_Manager::SLIDER,
402 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
403 'selectors' => [
404 '{{WRAPPER}} .gallery-item .gallery-caption' => 'margin-block-start: {{SIZE}}{{UNIT}};',
405 ],
406 'condition' => [
407 'gallery_display_caption' => '',
408 ],
409 ]
410 );
411
412 $this->end_controls_section();
413 }
414
415 /**
416 * Render image gallery widget output on the frontend.
417 *
418 * Written in PHP and used to generate the final HTML.
419 *
420 * @since 1.0.0
421 * @access protected
422 */
423 protected function render() {
424 $settings = $this->get_settings_for_display();
425
426 if ( ! $settings['wp_gallery'] ) {
427 return;
428 }
429
430 $ids = wp_list_pluck( $settings['wp_gallery'], 'id' );
431
432 $this->add_render_attribute( 'shortcode', 'ids', implode( ',', $ids ) );
433 $this->add_render_attribute( 'shortcode', 'size', $settings['thumbnail_size'] );
434
435 if ( $settings['gallery_columns'] ) {
436 $this->add_render_attribute( 'shortcode', 'columns', $settings['gallery_columns'] );
437 }
438
439 if ( $settings['gallery_link'] ) {
440 $this->add_render_attribute( 'shortcode', 'link', $settings['gallery_link'] );
441 }
442
443 if ( ! empty( $settings['gallery_rand'] ) ) {
444 $this->add_render_attribute( 'shortcode', 'orderby', $settings['gallery_rand'] );
445 }
446 ?>
447 <div class="elementor-image-gallery">
448 <?php
449 add_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ], 10, 2 );
450
451 echo do_shortcode( '[gallery ' . $this->get_render_attribute_string( 'shortcode' ) . ']' );
452
453 remove_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ] );
454 ?>
455 </div>
456 <?php
457 }
458 }
459