PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.1
Easy Elements for Elementor – Addons & Website Templates v1.3.1
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.3.1, at widgets/gallery/gallery.php

499 lines 17.7 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_item_style',
190 [
191 'label' => esc_html__('Items', '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->end_controls_section();
213
214 $this->start_controls_section(
215 'section_image_style',
216 [
217 'label' => esc_html__('Images', 'easy-elements'),
218 'tab' => Controls_Manager::TAB_STYLE,
219 ]
220 );
221
222 $this->add_responsive_control(
223 'image_height',
224 [
225 'label' => esc_html__( 'Height', 'easy-elements' ),
226 'type' => \Elementor\Controls_Manager::SLIDER,
227 'size_units' => [ 'px', '%' ],
228 'range' => [
229 'px' => [ 'min' => 50, 'max' => 1000, 'step' => 1 ],
230 '%' => [ 'min' => 10, 'max' => 100, 'step' => 1 ],
231 ],
232 'selectors' => [
233 '{{WRAPPER}} .eel-gallery-item img' => 'height: {{SIZE}}{{UNIT}}; object-fit: cover; width: 100%;',
234 ],
235 ]
236 );
237
238
239 $this->add_group_control(
240 \Elementor\Group_Control_Border::get_type(),
241 [
242 'name' => 'image_border',
243 'label' => esc_html__( 'Border', 'easy-elements' ),
244 'selector' => '{{WRAPPER}} .eel-gallery-item img',
245 ]
246 );
247
248 $this->add_responsive_control(
249 'image_border_radius',
250 [
251 'label' => esc_html__( 'Border Radius', 'easy-elements' ),
252 'type' => Controls_Manager::DIMENSIONS,
253 'size_units' => [ 'px', '%' ],
254 'selectors' => [
255 '{{WRAPPER}} .eel-gallery-item img, {{WRAPPER}} .eel-gallery-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
256 ],
257 ]
258 );
259
260 $this->end_controls_section();
261
262 $this->start_controls_section(
263 'section_caption_style',
264 [
265 'label' => esc_html__('Caption', 'easy-elements'),
266 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
267 'condition' => [
268 'show_caption' => 'yes',
269 ],
270 ]
271 );
272
273 // Caption Color
274 $this->add_control(
275 'caption_color',
276 [
277 'label' => esc_html__('Color', 'easy-elements'),
278 'type' => \Elementor\Controls_Manager::COLOR,
279 'selectors' => [
280 '{{WRAPPER}} .eel-gallery-caption' => 'color: {{VALUE}};',
281 ],
282 ]
283 );
284
285 // Caption Background Color
286 $this->add_control(
287 'caption_bg_color',
288 [
289 'label' => esc_html__('Background Color', 'easy-elements'),
290 'type' => \Elementor\Controls_Manager::COLOR,
291 'selectors' => [
292 '{{WRAPPER}} .eel-gallery-caption' => 'background-color: {{VALUE}};',
293 ],
294 ]
295 );
296
297 // Caption Typography
298 $this->add_group_control(
299 \Elementor\Group_Control_Typography::get_type(),
300 [
301 'name' => 'caption_typography',
302 'label' => esc_html__('Typography', 'easy-elements'),
303 'selector' => '{{WRAPPER}} .eel-gallery-caption',
304 ]
305 );
306
307 $this->end_controls_section();
308
309
310 $this->start_controls_section(
311 'section_hover_overlay_style',
312 [
313 'label' => esc_html__('Hover Overlay', 'easy-elements'),
314 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
315 'condition' => [
316 'hover_style!' => 'default',
317 ],
318 ]
319 );
320 $this->add_control(
321 'hover_overlay_color',
322 [
323 'label' => esc_html__( 'Hover Overlay Color', 'easy-elements' ),
324 'type' => \Elementor\Controls_Manager::COLOR,
325 'default' => 'rgba(0,0,0,0.6)',
326 'selectors' => [
327 '{{WRAPPER}} .eel-hover-content' => 'background-color: {{VALUE}};',
328 ],
329 ]
330 );
331 $this->end_controls_section();
332
333 $this->start_controls_section(
334 'section_hover_icon_style',
335 [
336 'label' => esc_html__('Hover Icon', 'easy-elements'),
337 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
338 'condition' => [
339 'hover_style' => 'icon',
340 ],
341 ]
342 );
343 $this->add_responsive_control(
344 'hover_icon_size',
345 [
346 'label' => esc_html__( 'Icon Size', 'easy-elements' ),
347 'type' => \Elementor\Controls_Manager::SLIDER,
348 'size_units' => [ 'px' ],
349 'range' => [
350 'px' => [ 'min' => 10, 'max' => 100 ],
351 ],
352 'default' => [ 'size' => 16 ],
353 'selectors' => [
354 '{{WRAPPER}} .eel-hover-icon i' => 'font-size: {{SIZE}}{{UNIT}};',
355 '{{WRAPPER}} .eel-hover-icon svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
356 ],
357 ]
358 );
359
360 $this->add_control(
361 'hover_icon_color',
362 [
363 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
364 'type' => \Elementor\Controls_Manager::COLOR,
365 'default' => '#ffffff',
366 'selectors' => [
367 '{{WRAPPER}} .eel-hover-icon i, {{WRAPPER}} .eel-hover-icon svg, {{WRAPPER}} .eel-hover-icon svg path' => 'color: {{VALUE}}; fill: {{VALUE}};',
368 ],
369 ]
370 );
371 $this->end_controls_section();
372
373 $this->start_controls_section(
374 'section_hover_text_style',
375 [
376 'label' => esc_html__('Hover Text', 'easy-elements'),
377 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
378 'condition' => [
379 'hover_style' => 'text',
380 ],
381 ]
382 );
383
384 // Color
385 $this->add_control(
386 'hover_text_color',
387 [
388 'label' => esc_html__('Color', 'easy-elements'),
389 'type' => \Elementor\Controls_Manager::COLOR,
390 'selectors' => [
391 '{{WRAPPER}} .eel-hover-text span' => 'color: {{VALUE}};',
392 ],
393 ]
394 );
395
396 // Typography
397 $this->add_group_control(
398 \Elementor\Group_Control_Typography::get_type(),
399 [
400 'name' => 'hover_text_color_typography',
401 'label' => esc_html__('Typography', 'easy-elements'),
402 'selector' => '{{WRAPPER}} .eel-hover-text span',
403 ]
404 );
405
406 $this->end_controls_section();
407 }
408
409 protected function render() {
410 $settings = $this->get_settings_for_display();
411 $images = $settings['gallery_images'];
412
413 if ( empty( $images ) ) {
414 echo '<p>' . esc_html__( 'Please select images to display the gallery.', 'easy-elements' ) . '</p>';
415 return;
416 }
417
418 // Order images
419 $order_by = $settings['order_by'];
420 if ( $order_by === 'rand' ) {
421 shuffle( $images );
422 } elseif ( $order_by !== 'menu_order' ) {
423 usort( $images, function( $a, $b ) use ( $order_by ) {
424 $a_post = get_post( $a['id'] );
425 $b_post = get_post( $b['id'] );
426 if ( ! $a_post || ! $b_post ) return 0;
427 return strcmp( strtolower( $a_post->$order_by ), strtolower( $b_post->$order_by ) );
428 });
429 }
430
431 $popup_enabled = isset( $settings['enable_popup'] ) && $settings['enable_popup'] === 'yes';
432 $popup_class = $popup_enabled ? 'eel-popup-enabled' : '';
433
434 echo '<div class="eel-gallery-grid ' . esc_attr( $popup_class ) . '">';
435
436 foreach ( $images as $index => $image ) {
437 $image_url = \Elementor\Group_Control_Image_Size::get_attachment_image_src( $image['id'], 'thumbnail', $settings ) ?: $image['url'];
438 $full_image = wp_get_attachment_image_url( $image['id'], 'full' );
439 $caption = '';
440
441 if ( isset($settings['show_caption']) && $settings['show_caption'] === 'yes' ) {
442 if ( $settings['caption_source'] === 'media' ) {
443 $caption = wp_get_attachment_caption( $image['id'] );
444 } elseif ( $settings['caption_source'] === 'title' ) {
445 $caption = get_the_title( $image['id'] );
446 }
447 }
448
449 echo '<div class="eel-gallery-item">';
450
451 if ( $popup_enabled ) {
452 echo '<a href="' . esc_url( $full_image ) . '" class="eel-popup-link" data-index="' . esc_attr( $index ) . '" data-elementor-open-lightbox="no">';
453 } else {
454 echo '<a href="' . esc_url( $image['url'] ) . '" target="_blank" rel="noopener" data-elementor-open-lightbox="no">';
455 }
456
457 // === Image ===
458 echo '<div class="eel-gallery-image-wrap">';
459 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">';
460
461 // === Hover Content ===
462 if ( $settings['hover_style'] === 'text' && ! empty( $settings['hover_text'] ) ) {
463 echo '<div class="eel-hover-content eel-hover-text">';
464 echo '<span>' . esc_html( $settings['hover_text'] ) . '</span>';
465 echo '</div>';
466 } elseif ( $settings['hover_style'] === 'icon' && ! empty( $settings['hover_icon']['value'] ) ) {
467 echo '<div class="eel-hover-content eel-hover-icon">';
468 \Elementor\Icons_Manager::render_icon( $settings['hover_icon'], [ 'aria-hidden' => 'true' ] );
469 echo '</div>';
470 }
471
472 echo '</div>'; // .eel-gallery-image-wrap
473 echo '</a>';
474
475 // === Caption ===
476 if ( ! empty( $caption ) ) {
477 echo '<div class="eel-gallery-caption">' . esc_html( $caption ) . '</div>';
478 }
479
480 echo '</div>'; // .eel-gallery-item
481 }
482
483 echo '</div>'; // .eel-gallery-grid
484
485 // === Lightbox ===
486 if ( $popup_enabled ) :
487 ?>
488 <div class="eel-lightbox-gallery">
489 <span class="eel-close">&times;</span>
490 <img class="eel-lightbox-image" src="" alt="">
491 <button class="eel-prev">&#10094;</button>
492 <button class="eel-next">&#10095;</button>
493 </div>
494 <?php
495 endif;
496 }
497
498
499 }