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

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