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

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