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

406 lines 9.7 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_link',
134 [
135 'label' => esc_html__( 'Link', 'elementor' ),
136 'type' => Controls_Manager::SELECT,
137 'default' => 'file',
138 'options' => [
139 'file' => esc_html__( 'Media File', 'elementor' ),
140 'attachment' => esc_html__( 'Attachment Page', 'elementor' ),
141 'none' => esc_html__( 'None', 'elementor' ),
142 ],
143 ]
144 );
145
146 $this->add_control(
147 'open_lightbox',
148 [
149 'label' => esc_html__( 'Lightbox', 'elementor' ),
150 'type' => Controls_Manager::SELECT,
151 'description' => sprintf(
152 /* translators: 1: Link open tag, 2: Link close tag. */
153 esc_html__( 'Manage your site’s lightbox settings in the %1$sLightbox panel%2$s.', 'elementor' ),
154 '<a href="javascript: $e.run( \'panel/global/open\' ).then( () => $e.route( \'panel/global/settings-lightbox\' ) )">',
155 '</a>'
156 ),
157 'default' => 'default',
158 'options' => [
159 'default' => esc_html__( 'Default', 'elementor' ),
160 'yes' => esc_html__( 'Yes', 'elementor' ),
161 'no' => esc_html__( 'No', 'elementor' ),
162 ],
163 'condition' => [
164 'gallery_link' => 'file',
165 ],
166 ]
167 );
168
169 $this->add_control(
170 'gallery_rand',
171 [
172 'label' => esc_html__( 'Order By', 'elementor' ),
173 'type' => Controls_Manager::SELECT,
174 'options' => [
175 '' => esc_html__( 'Default', 'elementor' ),
176 'rand' => esc_html__( 'Random', 'elementor' ),
177 ],
178 'default' => '',
179 ]
180 );
181
182 $this->add_control(
183 'view',
184 [
185 'label' => esc_html__( 'View', 'elementor' ),
186 'type' => Controls_Manager::HIDDEN,
187 'default' => 'traditional',
188 ]
189 );
190
191 $this->end_controls_section();
192
193 $this->start_controls_section(
194 'section_gallery_images',
195 [
196 'label' => esc_html__( 'Images', 'elementor' ),
197 'tab' => Controls_Manager::TAB_STYLE,
198 ]
199 );
200
201 $this->add_control(
202 'image_spacing',
203 [
204 'label' => esc_html__( 'Spacing', 'elementor' ),
205 'type' => Controls_Manager::SELECT,
206 'options' => [
207 '' => esc_html__( 'Default', 'elementor' ),
208 'custom' => esc_html__( 'Custom', 'elementor' ),
209 ],
210 'prefix_class' => 'gallery-spacing-',
211 'default' => '',
212 ]
213 );
214
215 $columns_margin = is_rtl() ? '0 0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}};' : '0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}} 0;';
216 $columns_padding = is_rtl() ? '0 0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}};' : '0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}} 0;';
217
218 $this->add_control(
219 'image_spacing_custom',
220 [
221 'label' => esc_html__( 'Image Spacing', 'elementor' ),
222 'type' => Controls_Manager::SLIDER,
223 'show_label' => false,
224 'range' => [
225 'px' => [
226 'max' => 100,
227 ],
228 ],
229 'default' => [
230 'size' => 15,
231 ],
232 'selectors' => [
233 '{{WRAPPER}} .gallery-item' => 'padding:' . $columns_padding,
234 '{{WRAPPER}} .gallery' => 'margin: ' . $columns_margin,
235 ],
236 'condition' => [
237 'image_spacing' => 'custom',
238 ],
239 ]
240 );
241
242 $this->add_group_control(
243 Group_Control_Border::get_type(),
244 [
245 'name' => 'image_border',
246 'selector' => '{{WRAPPER}} .gallery-item img',
247 'separator' => 'before',
248 ]
249 );
250
251 $this->add_responsive_control(
252 'image_border_radius',
253 [
254 'label' => esc_html__( 'Border Radius', 'elementor' ),
255 'type' => Controls_Manager::DIMENSIONS,
256 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
257 'selectors' => [
258 '{{WRAPPER}} .gallery-item img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
259 ],
260 ]
261 );
262
263 $this->end_controls_section();
264
265 $this->start_controls_section(
266 'section_caption',
267 [
268 'label' => esc_html__( 'Caption', 'elementor' ),
269 'tab' => Controls_Manager::TAB_STYLE,
270 ]
271 );
272
273 $this->add_control(
274 'gallery_display_caption',
275 [
276 'label' => esc_html__( 'Display', 'elementor' ),
277 'type' => Controls_Manager::SELECT,
278 'default' => '',
279 'options' => [
280 '' => esc_html__( 'Show', 'elementor' ),
281 'none' => esc_html__( 'Hide', 'elementor' ),
282 ],
283 'selectors' => [
284 '{{WRAPPER}} .gallery-item .gallery-caption' => 'display: {{VALUE}};',
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 ]
357 );
358
359 $this->end_controls_section();
360 }
361
362 /**
363 * Render image gallery widget output on the frontend.
364 *
365 * Written in PHP and used to generate the final HTML.
366 *
367 * @since 1.0.0
368 * @access protected
369 */
370 protected function render() {
371 $settings = $this->get_settings_for_display();
372
373 if ( ! $settings['wp_gallery'] ) {
374 return;
375 }
376
377 $ids = wp_list_pluck( $settings['wp_gallery'], 'id' );
378
379 $this->add_render_attribute( 'shortcode', 'ids', implode( ',', $ids ) );
380 $this->add_render_attribute( 'shortcode', 'size', $settings['thumbnail_size'] );
381
382 if ( $settings['gallery_columns'] ) {
383 $this->add_render_attribute( 'shortcode', 'columns', $settings['gallery_columns'] );
384 }
385
386 if ( $settings['gallery_link'] ) {
387 $this->add_render_attribute( 'shortcode', 'link', $settings['gallery_link'] );
388 }
389
390 if ( ! empty( $settings['gallery_rand'] ) ) {
391 $this->add_render_attribute( 'shortcode', 'orderby', $settings['gallery_rand'] );
392 }
393 ?>
394 <div class="elementor-image-gallery">
395 <?php
396 add_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ], 10, 2 );
397
398 echo do_shortcode( '[gallery ' . $this->get_render_attribute_string( 'shortcode' ) . ']' );
399
400 remove_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ] );
401 ?>
402 </div>
403 <?php
404 }
405 }
406