PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.0-dev3
Elementor Website Builder – more than just a page builder v3.19.0-dev3
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.19.0-dev3, at includes/widgets/image-gallery.php

424 lines 10.2 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 get_upsale_data() {
76 return [
77 'description' => esc_html__( 'Use interesting masonry layouts and other overlay features with Elementor\'s Pro Gallery widget.', 'elementor' ),
78 'upgrade_url' => 'https://go.elementor.com/go-pro-basic-gallery-widget/',
79 ];
80 }
81
82 /**
83 * Register image gallery widget controls.
84 *
85 * Adds different input fields to allow the user to change and customize the widget settings.
86 *
87 * @since 3.1.0
88 * @access protected
89 */
90 protected function register_controls() {
91 $this->start_controls_section(
92 'section_gallery',
93 [
94 'label' => esc_html__( 'Image Gallery', 'elementor' ),
95 ]
96 );
97
98 $this->add_control(
99 'wp_gallery',
100 [
101 'label' => esc_html__( 'Add Images', 'elementor' ),
102 'type' => Controls_Manager::GALLERY,
103 'show_label' => false,
104 'dynamic' => [
105 'active' => true,
106 ],
107 ]
108 );
109
110 $this->add_group_control(
111 Group_Control_Image_Size::get_type(),
112 [
113 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
114 'exclude' => [ 'custom' ],
115 'separator' => 'none',
116 ]
117 );
118
119 $gallery_columns = range( 1, 10 );
120 $gallery_columns = array_combine( $gallery_columns, $gallery_columns );
121
122 $this->add_control(
123 'gallery_columns',
124 [
125 'label' => esc_html__( 'Columns', 'elementor' ),
126 'type' => Controls_Manager::SELECT,
127 'default' => 4,
128 'options' => $gallery_columns,
129 ]
130 );
131
132 $this->add_control(
133 'gallery_display_caption',
134 [
135 'label' => esc_html__( 'Caption', 'elementor' ),
136 'type' => Controls_Manager::SELECT,
137 'default' => '',
138 'options' => [
139 'none' => esc_html__( 'None', 'elementor' ),
140 '' => esc_html__( 'Attachment Caption', 'elementor' ),
141 ],
142 'selectors' => [
143 '{{WRAPPER}} .gallery-item .gallery-caption' => 'display: {{VALUE}};',
144 ],
145 ]
146 );
147
148 $this->add_control(
149 'gallery_link',
150 [
151 'label' => esc_html__( 'Link', 'elementor' ),
152 'type' => Controls_Manager::SELECT,
153 'default' => 'file',
154 'options' => [
155 'file' => esc_html__( 'Media File', 'elementor' ),
156 'attachment' => esc_html__( 'Attachment Page', 'elementor' ),
157 'none' => esc_html__( 'None', 'elementor' ),
158 ],
159 ]
160 );
161
162 $this->add_control(
163 'open_lightbox',
164 [
165 'label' => esc_html__( 'Lightbox', 'elementor' ),
166 'type' => Controls_Manager::SELECT,
167 'description' => sprintf(
168 /* translators: 1: Link open tag, 2: Link close tag. */
169 esc_html__( 'Manage your site’s lightbox settings in the %1$sLightbox panel%2$s.', 'elementor' ),
170 '<a href="javascript: $e.run( \'panel/global/open\' ).then( () => $e.route( \'panel/global/settings-lightbox\' ) )">',
171 '</a>'
172 ),
173 'default' => 'default',
174 'options' => [
175 'default' => esc_html__( 'Default', 'elementor' ),
176 'yes' => esc_html__( 'Yes', 'elementor' ),
177 'no' => esc_html__( 'No', 'elementor' ),
178 ],
179 'condition' => [
180 'gallery_link' => 'file',
181 ],
182 ]
183 );
184
185 $this->add_control(
186 'gallery_rand',
187 [
188 'label' => esc_html__( 'Order By', 'elementor' ),
189 'type' => Controls_Manager::SELECT,
190 'options' => [
191 '' => esc_html__( 'Default', 'elementor' ),
192 'rand' => esc_html__( 'Random', 'elementor' ),
193 ],
194 'default' => '',
195 ]
196 );
197
198 $this->end_controls_section();
199
200 $this->start_controls_section(
201 'section_gallery_images',
202 [
203 'label' => esc_html__( 'Images', 'elementor' ),
204 'tab' => Controls_Manager::TAB_STYLE,
205 ]
206 );
207
208 $this->add_control(
209 'image_spacing',
210 [
211 'label' => esc_html__( 'Spacing', 'elementor' ),
212 'type' => Controls_Manager::SELECT,
213 'options' => [
214 '' => esc_html__( 'Default', 'elementor' ),
215 'custom' => esc_html__( 'Custom', 'elementor' ),
216 ],
217 'prefix_class' => 'gallery-spacing-',
218 'default' => '',
219 ]
220 );
221
222 $columns_margin = is_rtl() ? '0 0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}};' : '0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}} 0;';
223 $columns_padding = is_rtl() ? '0 0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}};' : '0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}} 0;';
224
225 $this->add_control(
226 'image_spacing_custom',
227 [
228 'label' => esc_html__( 'Custom Spacing', 'elementor' ),
229 'type' => Controls_Manager::SLIDER,
230 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
231 'range' => [
232 'px' => [
233 'max' => 100,
234 ],
235 'em' => [
236 'max' => 10,
237 ],
238 'rem' => [
239 'max' => 10,
240 ],
241 ],
242 'default' => [
243 'size' => 15,
244 ],
245 'selectors' => [
246 '{{WRAPPER}} .gallery-item' => 'padding:' . $columns_padding,
247 '{{WRAPPER}} .gallery' => 'margin: ' . $columns_margin,
248 ],
249 'condition' => [
250 'image_spacing' => 'custom',
251 ],
252 ]
253 );
254
255 $this->add_group_control(
256 Group_Control_Border::get_type(),
257 [
258 'name' => 'image_border',
259 'selector' => '{{WRAPPER}} .gallery-item img',
260 'separator' => 'before',
261 ]
262 );
263
264 $this->add_responsive_control(
265 'image_border_radius',
266 [
267 'label' => esc_html__( 'Border Radius', 'elementor' ),
268 'type' => Controls_Manager::DIMENSIONS,
269 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
270 'selectors' => [
271 '{{WRAPPER}} .gallery-item img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
272 ],
273 ]
274 );
275
276 $this->end_controls_section();
277
278 $this->start_controls_section(
279 'section_caption',
280 [
281 'label' => esc_html__( 'Caption', 'elementor' ),
282 'tab' => Controls_Manager::TAB_STYLE,
283 'condition' => [
284 'gallery_display_caption' => '',
285 ],
286 ]
287 );
288
289 $this->add_responsive_control(
290 'align',
291 [
292 'label' => esc_html__( 'Alignment', 'elementor' ),
293 'type' => Controls_Manager::CHOOSE,
294 'options' => [
295 'left' => [
296 'title' => esc_html__( 'Left', 'elementor' ),
297 'icon' => 'eicon-text-align-left',
298 ],
299 'center' => [
300 'title' => esc_html__( 'Center', 'elementor' ),
301 'icon' => 'eicon-text-align-center',
302 ],
303 'right' => [
304 'title' => esc_html__( 'Right', 'elementor' ),
305 'icon' => 'eicon-text-align-right',
306 ],
307 'justify' => [
308 'title' => esc_html__( 'Justified', 'elementor' ),
309 'icon' => 'eicon-text-align-justify',
310 ],
311 ],
312 'default' => 'center',
313 'selectors' => [
314 '{{WRAPPER}} .gallery-item .gallery-caption' => 'text-align: {{VALUE}};',
315 ],
316 'condition' => [
317 'gallery_display_caption' => '',
318 ],
319 ]
320 );
321
322 $this->add_control(
323 'text_color',
324 [
325 'label' => esc_html__( 'Text Color', 'elementor' ),
326 'type' => Controls_Manager::COLOR,
327 'default' => '',
328 'selectors' => [
329 '{{WRAPPER}} .gallery-item .gallery-caption' => 'color: {{VALUE}};',
330 ],
331 'condition' => [
332 'gallery_display_caption' => '',
333 ],
334 ]
335 );
336
337 $this->add_group_control(
338 Group_Control_Typography::get_type(),
339 [
340 'name' => 'typography',
341 'global' => [
342 'default' => Global_Typography::TYPOGRAPHY_ACCENT,
343 ],
344 'selector' => '{{WRAPPER}} .gallery-item .gallery-caption',
345 'condition' => [
346 'gallery_display_caption' => '',
347 ],
348 ]
349 );
350
351 $this->add_group_control(
352 Group_Control_Text_Shadow::get_type(),
353 [
354 'name' => 'caption_shadow',
355 'selector' => '{{WRAPPER}} .gallery-item .gallery-caption',
356 'condition' => [
357 'gallery_display_caption' => '',
358 ],
359 ]
360 );
361
362 $this->add_responsive_control(
363 'caption_space',
364 [
365 'label' => esc_html__( 'Spacing', 'elementor' ),
366 'type' => Controls_Manager::SLIDER,
367 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
368 'selectors' => [
369 '{{WRAPPER}} .gallery-item .gallery-caption' => 'margin-block-start: {{SIZE}}{{UNIT}};',
370 ],
371 'condition' => [
372 'gallery_display_caption' => '',
373 ],
374 ]
375 );
376
377 $this->end_controls_section();
378 }
379
380 /**
381 * Render image gallery widget output on the frontend.
382 *
383 * Written in PHP and used to generate the final HTML.
384 *
385 * @since 1.0.0
386 * @access protected
387 */
388 protected function render() {
389 $settings = $this->get_settings_for_display();
390
391 if ( ! $settings['wp_gallery'] ) {
392 return;
393 }
394
395 $ids = wp_list_pluck( $settings['wp_gallery'], 'id' );
396
397 $this->add_render_attribute( 'shortcode', 'ids', implode( ',', $ids ) );
398 $this->add_render_attribute( 'shortcode', 'size', $settings['thumbnail_size'] );
399
400 if ( $settings['gallery_columns'] ) {
401 $this->add_render_attribute( 'shortcode', 'columns', $settings['gallery_columns'] );
402 }
403
404 if ( $settings['gallery_link'] ) {
405 $this->add_render_attribute( 'shortcode', 'link', $settings['gallery_link'] );
406 }
407
408 if ( ! empty( $settings['gallery_rand'] ) ) {
409 $this->add_render_attribute( 'shortcode', 'orderby', $settings['gallery_rand'] );
410 }
411 ?>
412 <div class="elementor-image-gallery">
413 <?php
414 add_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ], 10, 2 );
415
416 echo do_shortcode( '[gallery ' . $this->get_render_attribute_string( 'shortcode' ) . ']' );
417
418 remove_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ] );
419 ?>
420 </div>
421 <?php
422 }
423 }
424