PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.2.8
Easy Elements for Elementor – Addons & Website Templates v1.2.8
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / gallery / gallery.php

gallery.php in Easy Elements for Elementor – Addons & Website Templates 1.2.8, at widgets/gallery/gallery.php

501 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Widgets;
3 use Elementor\Controls_Manager;
4 use Elementor\Group_Control_Image_Size;
5 use Elementor\Utils;
6
7 defined( 'ABSPATH' ) || die();
8
9 class Easyel__Gallery_Widget extends \Elementor\Widget_Base {
10
11 public function get_name() {
12 return 'eel-gallery';
13 }
14
15 public function get_title() {
16 return esc_html__( 'Simple Gallery', 'easy-elements' );
17 }
18
19 public function get_icon() {
20 return 'easyicon easyelIcon-marquee-logo';
21 }
22
23 public function get_categories() {
24 return [ 'easyelements_category_pro' ];
25 }
26
27 public function get_keywords() {
28 return [ 'gallery', 'image', 'photo', 'portfolio' ];
29 }
30
31 public function get_style_depends() {
32
33 return [ 'eel-gallery' ];
34 }
35
36 public function get_script_depends() {
37
38 return [ 'eel-gallery' ];
39 }
40
41 protected function register_controls() {
42
43 // Gallery Images
44 $this->start_controls_section(
45 'section_gallery',
46 [
47 'label' => esc_html__( 'Gallery Images', 'easy-elements' ),
48 'tab' => Controls_Manager::TAB_CONTENT,
49 ]
50 );
51
52 $this->add_control(
53 'gallery_images',
54 [
55 'label' => esc_html__( 'Add Images', 'easy-elements' ),
56 'type' => Controls_Manager::GALLERY,
57 'default' => [],
58 ]
59 );
60
61 $this->add_responsive_control(
62 'columns',
63 [
64 'label' => esc_html__( 'Columns', 'easy-elements' ),
65 'type' => Controls_Manager::SELECT,
66 'default' => '4',
67 'options' => [
68 '1' => esc_html__( '1 Column', 'easy-elements' ),
69 '2' => esc_html__( '2 Columns', 'easy-elements' ),
70 '3' => esc_html__( '3 Columns', 'easy-elements' ),
71 '4' => esc_html__( '4 Columns', 'easy-elements' ),
72 '5' => esc_html__( '5 Columns', 'easy-elements' ),
73 ],
74 'selectors' => [
75 '{{WRAPPER}} .eel-gallery-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
76 ],
77 ]
78 );
79
80 $this->add_group_control(
81 Group_Control_Image_Size::get_type(),
82 [
83 'name' => 'thumbnail',
84 'default' => 'large',
85 'separator' => 'none',
86 ]
87 );
88
89 $this->add_control(
90 'show_caption',
91 [
92 'label' => esc_html__( 'Show Caption', 'easy-elements' ),
93 'type' => Controls_Manager::SWITCHER,
94 'label_on' => esc_html__( 'Show', 'easy-elements' ),
95 'label_off' => esc_html__( 'Hide', 'easy-elements' ),
96 'default' => 'yes',
97 ]
98 );
99
100 $this->add_control(
101 'caption_source',
102 [
103 'label' => esc_html__( 'Caption Source', 'easy-elements' ),
104 'type' => Controls_Manager::SELECT,
105 'default' => 'media',
106 'options' => [
107 'media' => esc_html__( 'Media Library Caption', 'easy-elements' ),
108 'title' => esc_html__( 'Image Title', 'easy-elements' ),
109 'none' => esc_html__( 'None', 'easy-elements' ),
110 ],
111 'condition' => [
112 'show_caption' => 'yes',
113 ],
114 ]
115 );
116
117 $this->add_control(
118 'enable_popup',
119 [
120 'label' => esc_html__( 'Enable Lightbox', 'easy-elements' ),
121 'type' => Controls_Manager::SWITCHER,
122 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
123 'label_off' => esc_html__( 'No', 'easy-elements' ),
124 'default' => 'yes',
125 ]
126 );
127
128 $this->add_control(
129 'order_by',
130 [
131 'label' => esc_html__( 'Order By', 'easy-elements' ),
132 'type' => Controls_Manager::SELECT,
133 'default' => 'menu_order',
134 'options' => [
135 'menu_order' => esc_html__( 'Default', 'easy-elements' ),
136 'title' => esc_html__( 'Title', 'easy-elements' ),
137 'id' => esc_html__( 'ID', 'easy-elements' ),
138 'date' => esc_html__( 'Date', 'easy-elements' ),
139 'rand' => esc_html__( 'Random', 'easy-elements' ),
140 ],
141 ]
142 );
143
144 $this->add_control(
145 'hover_style',
146 [
147 'label' => esc_html__( 'On Hover', 'easy-elements' ),
148 'type' => Controls_Manager::SELECT,
149 'default' => 'default',
150 'options' => [
151 'default' => esc_html__( 'Default', 'easy-elements' ),
152 'icon' => esc_html__( 'Icon', 'easy-elements' ),
153 'text' => esc_html__( 'Text', 'easy-elements' ),
154 ],
155 ]
156 );
157
158 $this->add_control(
159 'hover_text',
160 [
161 'label' => esc_html__( 'Hover Text', 'easy-elements' ),
162 'type' => \Elementor\Controls_Manager::TEXT,
163 'default' => esc_html__( 'View', 'easy-elements' ),
164 'placeholder' => esc_html__( 'Enter hover text', 'easy-elements' ),
165 'condition' => [
166 'hover_style' => 'text',
167 ],
168 ]
169 );
170
171 $this->add_control(
172 'hover_icon',
173 [
174 'label' => esc_html__( 'Hover Icon', 'easy-elements' ),
175 'type' => \Elementor\Controls_Manager::ICONS,
176 'default' => [
177 'value' => 'fas fa-plus',
178 'library' => 'fa-solid',
179 ],
180 'condition' => [
181 'hover_style' => 'icon',
182 ],
183 ]
184 );
185
186 $this->end_controls_section();
187
188 $this->start_controls_section(
189 'section_image_style',
190 [
191 'label' => esc_html__('Images', 'easy-elements'),
192 'tab' => Controls_Manager::TAB_STYLE,
193 ]
194 );
195
196 $this->add_responsive_control(
197 'image_gap',
198 [
199 'label' => esc_html__( 'Gap', 'easy-elements' ),
200 'type' => Controls_Manager::SLIDER,
201 'size_units' => [ 'px', '%' ],
202 'range' => [
203 'px' => [ 'min' => 0, 'max' => 100 ],
204 ],
205 'default' => [ 'size' => 10 ],
206 'selectors' => [
207 '{{WRAPPER}} .eel-gallery-grid' => 'gap: {{SIZE}}{{UNIT}};',
208 ],
209 ]
210 );
211
212 $this->add_responsive_control(
213 'image_height',
214 [
215 'label' => esc_html__( 'Height', 'easy-elements' ),
216 'type' => \Elementor\Controls_Manager::SLIDER,
217 'size_units' => [ 'px', '%' ],
218 'range' => [
219 'px' => [ 'min' => 50, 'max' => 1000, 'step' => 1 ],
220 '%' => [ 'min' => 10, 'max' => 100, 'step' => 1 ],
221 ],
222 'selectors' => [
223 '{{WRAPPER}} .eel-gallery-item img' => 'height: {{SIZE}}{{UNIT}}; object-fit: cover; width: 100%;',
224 ],
225 ]
226 );
227
228
229 $this->add_group_control(
230 \Elementor\Group_Control_Border::get_type(),
231 [
232 'name' => 'image_border',
233 'label' => esc_html__( 'Border', 'easy-elements' ),
234 'selector' => '{{WRAPPER}} .eel-gallery-item img',
235 ]
236 );
237
238 $this->add_responsive_control(
239 'image_border_radius',
240 [
241 'label' => esc_html__( 'Border Radius', 'easy-elements' ),
242 'type' => Controls_Manager::DIMENSIONS,
243 'size_units' => [ 'px', '%' ],
244 'selectors' => [
245 '{{WRAPPER}} .eel-gallery-item img, {{WRAPPER}} .eel-gallery-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
246 ],
247 ]
248 );
249
250 $this->add_responsive_control(
251 'image_border_padding',
252 [
253 'label' => esc_html__( 'Padding', 'easy-elements' ),
254 'type' => Controls_Manager::DIMENSIONS,
255 'size_units' => [ 'px', '%' ],
256 'selectors' => [
257 '{{WRAPPER}} .eel-gallery-item img' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
258 ],
259 ]
260 );
261
262 $this->end_controls_section();
263
264 $this->start_controls_section(
265 'section_caption_style',
266 [
267 'label' => esc_html__('Caption', 'easy-elements'),
268 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
269 'condition' => [
270 'show_caption' => 'yes',
271 ],
272 ]
273 );
274
275 // Caption Color
276 $this->add_control(
277 'caption_color',
278 [
279 'label' => esc_html__('Color', 'easy-elements'),
280 'type' => \Elementor\Controls_Manager::COLOR,
281 'selectors' => [
282 '{{WRAPPER}} .eel-gallery-caption' => 'color: {{VALUE}};',
283 ],
284 ]
285 );
286
287 // Caption Background Color
288 $this->add_control(
289 'caption_bg_color',
290 [
291 'label' => esc_html__('Background Color', 'easy-elements'),
292 'type' => \Elementor\Controls_Manager::COLOR,
293 'selectors' => [
294 '{{WRAPPER}} .eel-gallery-caption' => 'background-color: {{VALUE}};',
295 ],
296 ]
297 );
298
299 // Caption Typography
300 $this->add_group_control(
301 \Elementor\Group_Control_Typography::get_type(),
302 [
303 'name' => 'caption_typography',
304 'label' => esc_html__('Typography', 'easy-elements'),
305 'selector' => '{{WRAPPER}} .eel-gallery-caption',
306 ]
307 );
308
309 $this->end_controls_section();
310
311
312 $this->start_controls_section(
313 'section_hover_overlay_style',
314 [
315 'label' => esc_html__('Hover Overlay', 'easy-elements'),
316 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
317 'condition' => [
318 'hover_style!' => 'default',
319 ],
320 ]
321 );
322 $this->add_control(
323 'hover_overlay_color',
324 [
325 'label' => esc_html__( 'Hover Overlay Color', 'easy-elements' ),
326 'type' => \Elementor\Controls_Manager::COLOR,
327 'default' => 'rgba(0,0,0,0.6)',
328 'selectors' => [
329 '{{WRAPPER}} .eel-hover-content' => 'background-color: {{VALUE}};',
330 ],
331 ]
332 );
333 $this->end_controls_section();
334
335 $this->start_controls_section(
336 'section_hover_icon_style',
337 [
338 'label' => esc_html__('Hover Icon', 'easy-elements'),
339 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
340 'condition' => [
341 'hover_style' => 'icon',
342 ],
343 ]
344 );
345 $this->add_responsive_control(
346 'hover_icon_size',
347 [
348 'label' => esc_html__( 'Icon Size', 'easy-elements' ),
349 'type' => \Elementor\Controls_Manager::SLIDER,
350 'size_units' => [ 'px' ],
351 'range' => [
352 'px' => [ 'min' => 10, 'max' => 100 ],
353 ],
354 'default' => [ 'size' => 16 ],
355 'selectors' => [
356 '{{WRAPPER}} .eel-hover-icon i' => 'font-size: {{SIZE}}{{UNIT}};',
357 '{{WRAPPER}} .eel-hover-icon svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
358 ],
359 ]
360 );
361
362 $this->add_control(
363 'hover_icon_color',
364 [
365 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
366 'type' => \Elementor\Controls_Manager::COLOR,
367 'default' => '#ffffff',
368 'selectors' => [
369 '{{WRAPPER}} .eel-hover-icon i, {{WRAPPER}} .eel-hover-icon svg, {{WRAPPER}} .eel-hover-icon svg path' => 'color: {{VALUE}}; fill: {{VALUE}};',
370 ],
371 ]
372 );
373 $this->end_controls_section();
374
375 $this->start_controls_section(
376 'section_hover_text_style',
377 [
378 'label' => esc_html__('Hover Text', 'easy-elements'),
379 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
380 'condition' => [
381 'hover_style' => 'text',
382 ],
383 ]
384 );
385
386 // Color
387 $this->add_control(
388 'hover_text_color',
389 [
390 'label' => esc_html__('Color', 'easy-elements'),
391 'type' => \Elementor\Controls_Manager::COLOR,
392 'selectors' => [
393 '{{WRAPPER}} .eel-hover-text span' => 'color: {{VALUE}};',
394 ],
395 ]
396 );
397
398 // Typography
399 $this->add_group_control(
400 \Elementor\Group_Control_Typography::get_type(),
401 [
402 'name' => 'hover_text_color_typography',
403 'label' => esc_html__('Typography', 'easy-elements'),
404 'selector' => '{{WRAPPER}} .eel-hover-text span',
405 ]
406 );
407
408 $this->end_controls_section();
409 }
410
411 protected function render() {
412 $settings = $this->get_settings_for_display();
413 $images = $settings['gallery_images'];
414
415 if ( empty( $images ) ) {
416 echo '<p>' . esc_html__( 'Please select images to display the gallery.', 'easy-elements' ) . '</p>';
417 return;
418 }
419
420 // Order images
421 $order_by = $settings['order_by'];
422 if ( $order_by === 'rand' ) {
423 shuffle( $images );
424 } elseif ( $order_by !== 'menu_order' ) {
425 usort( $images, function( $a, $b ) use ( $order_by ) {
426 $a_post = get_post( $a['id'] );
427 $b_post = get_post( $b['id'] );
428 if ( ! $a_post || ! $b_post ) return 0;
429 return strcmp( strtolower( $a_post->$order_by ), strtolower( $b_post->$order_by ) );
430 });
431 }
432
433 $popup_enabled = isset( $settings['enable_popup'] ) && $settings['enable_popup'] === 'yes';
434 $popup_class = $popup_enabled ? 'eel-popup-enabled' : '';
435
436 echo '<div class="eel-gallery-grid ' . esc_attr( $popup_class ) . '">';
437
438 foreach ( $images as $index => $image ) {
439 $image_url = \Elementor\Group_Control_Image_Size::get_attachment_image_src( $image['id'], 'thumbnail', $settings ) ?: $image['url'];
440 $full_image = wp_get_attachment_image_url( $image['id'], 'full' );
441 $caption = '';
442
443 if ( isset($settings['show_caption']) && $settings['show_caption'] === 'yes' ) {
444 if ( $settings['caption_source'] === 'media' ) {
445 $caption = wp_get_attachment_caption( $image['id'] );
446 } elseif ( $settings['caption_source'] === 'title' ) {
447 $caption = get_the_title( $image['id'] );
448 }
449 }
450
451 echo '<div class="eel-gallery-item">';
452
453 if ( $popup_enabled ) {
454 echo '<a href="' . esc_url( $full_image ) . '" class="eel-popup-link" data-index="' . esc_attr( $index ) . '" data-elementor-open-lightbox="no">';
455 } else {
456 echo '<a href="' . esc_url( $image['url'] ) . '" target="_blank" rel="noopener" data-elementor-open-lightbox="no">';
457 }
458
459 // === Image ===
460 echo '<div class="eel-gallery-image-wrap">';
461 echo '<img src="' . esc_url( $image_url ) . '" alt="' . esc_attr( get_post_meta( $image['id'], '_wp_attachment_image_alt', true ) ) . '" data-elementor-open-lightbox="no">';
462
463 // === Hover Content ===
464 if ( $settings['hover_style'] === 'text' && ! empty( $settings['hover_text'] ) ) {
465 echo '<div class="eel-hover-content eel-hover-text">';
466 echo '<span>' . esc_html( $settings['hover_text'] ) . '</span>';
467 echo '</div>';
468 } elseif ( $settings['hover_style'] === 'icon' && ! empty( $settings['hover_icon']['value'] ) ) {
469 echo '<div class="eel-hover-content eel-hover-icon">';
470 \Elementor\Icons_Manager::render_icon( $settings['hover_icon'], [ 'aria-hidden' => 'true' ] );
471 echo '</div>';
472 }
473
474 echo '</div>'; // .eel-gallery-image-wrap
475 echo '</a>';
476
477 // === Caption ===
478 if ( ! empty( $caption ) ) {
479 echo '<div class="eel-gallery-caption">' . esc_html( $caption ) . '</div>';
480 }
481
482 echo '</div>'; // .eel-gallery-item
483 }
484
485 echo '</div>'; // .eel-gallery-grid
486
487 // === Lightbox ===
488 if ( $popup_enabled ) :
489 ?>
490 <div class="eel-lightbox">
491 <span class="eel-close">&times;</span>
492 <img class="eel-lightbox-image" src="" alt="">
493 <button class="eel-prev">&#10094;</button>
494 <button class="eel-next">&#10095;</button>
495 </div>
496 <?php
497 endif;
498 }
499
500
501 } ?>