PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 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.8 All 37 releases
wpdirectorykit / elementor-elements / views / wdk-listing-slider.php

wdk-listing-slider.php in WP Directory Kit 1.5.9, at elementor-elements/views/wdk-listing-slider.php

339 lines 20.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The template for Element Listing Images Slider.
5 * This is the template that elementor element slider, carousel
6 *
7 */
8
9 if (! defined('ABSPATH')) {
10 exit; // Exit if accessed directly.
11 }
12 ?>
13 <div class="wdk-element" id="wdk_el_<?php echo esc_html($id_element); ?>">
14 <div class="wdk-listing-slider">
15 <?php
16 // Organize images into tabs: gallery, plans, custom fields
17 $tabs = [];
18
19 // Gallery Tab
20 $tabs['gallery'] = [];
21 foreach ($images as $key => $image) {
22 $type = 'gallery';
23 if (strpos($key, '__') !== FALSE) {
24 $type = substr($key, 0, strpos($key, '__'));
25 }
26 if ($type === 'gallery') {
27 $tabs['gallery'][$key] = $image;
28 }
29 }
30
31 // Plans tab if exists
32 if (!empty($plans_exists)) {
33 $tabs['plans'] = [];
34 foreach ($images as $key => $image) {
35 $type = 'gallery';
36 if (strpos($key, '__') !== FALSE) {
37 $type = substr($key, 0, strpos($key, '__'));
38 }
39 if ($type === 'plans') {
40 $tabs['plans'][$key] = $image;
41 }
42 }
43 }
44
45 // Custom fields (images_fields) tabs if exists
46 if (!empty($images_fields)) {
47 foreach ($images_fields as $field_id => $field_images) {
48 $tabs[$field_id] = [];
49 foreach ($images as $key => $image) {
50 $field_images_id = 'gallery';
51 if (strpos($key, '__') !== FALSE) {
52 $field_images_id = substr($key, 0, strpos($key, '__'));
53 }
54 if ($field_images_id == $field_id) {
55 $tabs[$field_id][$key] = $image;
56 }
57 }
58 }
59 }
60 // Only make tabs if we have images for them
61 $tab_keys = array_filter(array_keys($tabs), function($tab_key) use ($tabs) {
62 return !empty($tabs[$tab_key]);
63 });
64 ?>
65
66 <?php if (count($images) > 0): ?>
67 <?php if (count($tab_keys) > 1): ?>
68 <div class="elementor-section elementor-section-boxed">
69 <div class="elementor-container">
70 <div class="wdk-listing-slider--tabs">
71 <?php foreach ($tab_keys as $tab_key): ?>
72 <a data-tab="<?php echo esc_attr($tab_key); ?>" href="#" class="wdk-listing-slider--tabs--btn <?php echo $tab_key === 'gallery' ? 'active' : ''; ?>">
73 <?php
74 if ($tab_key === 'gallery') {
75 echo esc_html__('Gallery', 'wpdirectorykit');
76 } elseif ($tab_key === 'plans') {
77 echo esc_html__('Plans', 'wpdirectorykit');
78 } else {
79 echo esc_html(wdk_field_label($tab_key));
80 }
81 ?>
82 </a>
83 <?php endforeach; ?>
84 </div>
85 </div>
86 </div>
87 <?php endif; ?>
88
89 <div class="wdk-listing-slider--content-tabs">
90 <?php foreach ($tab_keys as $tab_key): ?>
91 <div class="wdk-listing-slider--tab-pane<?php if ($tab_key === 'gallery') echo ' active'; ?>" id="wdk_list_slider_tab_<?php echo esc_attr($tab_key); ?>">
92 <div class="<?php if ($settings['popup_enable'] == 'yes'): ?> wdk_js_gallery <?php endif; ?> wdk_listing_slider_box <?php echo esc_attr($settings['layout_carousel_animation_style']) . '_animation'; ?> <?php echo esc_attr(join(' ', [$settings['styles_carousel_dots_position_style'], $settings['styles_carousel_arrows_position_style'], $settings['styles_carousel_arrows_position'], $settings['styles_carousel_arrows_position_style']])); ?>">
93 <div class="wdk_listing_slider_ini" id="wdk_slider_<?php echo esc_attr($tab_key); ?>">
94 <?php foreach ($tabs[$tab_key] as $key => $image): ?>
95 <?php
96 $type = $tab_key;
97 ?>
98 <?php if (
99 is_string($image) && (
100 filter_var($image, FILTER_VALIDATE_URL) ||
101 preg_match('/^www\./i', $image)
102 )
103 ): ?>
104 <div class="wdk-col" data-type="<?php echo esc_attr($type); ?>">
105 <div class="wdk-listing-image-card">
106 <?php if (strpos($image, 'vimeo.com') !== FALSE): ?>
107 <div class="wdk-listing-image wdk-listing-video-embed<?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height<?php endif; ?>">
108 <?php
109 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.I18n.NonSingularStringLiteralText
110 echo wp_oembed_get($image, array("width" => "800", "height" => "450")); ?>
111 </div>
112 <?php elseif (strpos($image, 'watch?v=') !== FALSE): ?>
113 <?php $embed_code = substr($image, strpos($image, 'watch?v=') + 8); ?>
114 <div class="wdk-listing-image wdk-listing-video-embed<?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height<?php endif; ?>">
115 <?php
116 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.I18n.NonSingularStringLiteralText
117 echo wp_oembed_get('https://www.youtube.com/watch?v=' . $embed_code, array("width" => "800", "height" => "455")); ?>
118 </div>
119 <?php elseif (strpos($image, 'youtube.com/shorts/') !== FALSE): ?>
120 <?php $embed_code = substr($image, strpos($image, 'shorts') + 7); ?>
121 <div class="wdk-listing-image wdk-listing-video-embed<?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height<?php endif; ?>">
122 <?php
123 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.I18n.NonSingularStringLiteralText
124 echo wp_oembed_get('https://www.youtube.com/watch?v=' . $embed_code, array("width" => "800", "height" => "455")); ?>
125 </div>
126 <?php elseif (strpos($image, 'youtu.be/') !== FALSE): ?>
127 <?php $embed_code = substr($image, strpos($image, 'youtu.be/') + 9); ?>
128 <div class="wdk-listing-image wdk-listing-video-embed<?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height<?php endif; ?>">
129 <?php
130 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.I18n.NonSingularStringLiteralText
131 echo wp_oembed_get('https://www.youtube.com/watch?v=' . $embed_code, array("width" => "800", "height" => "455")); ?>
132 </div>
133 <?php elseif (filter_var($image, FILTER_VALIDATE_URL) !== FALSE && preg_match('/\.(mp4|flv|wmw|ogv|webm|ogg)$/i', $image)): ?>
134 <video
135 src="<?php echo esc_url($image); ?>"
136 controls
137 class="wdk-listing-image <?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height<?php endif; ?>"
138 <?php if (wmvc_show_data('auto_start_video', $settings, false) == 'yes'): ?> autoplay loop<?php endif; ?>
139 >
140 </video>
141 <?php else: ?>
142 <iframe
143 src="<?php echo esc_url($image); ?>" width="100%" frameborder="0" allowfullscreen
144 class="wdk-listing-image <?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height <?php endif; ?>"></iframe>
145 <?php endif; ?>
146 </div>
147 </div>
148 <?php elseif (!wmvc_show_data('wdk_listing_video_disabled', $settings, false) && wdk_file_extension_type(wmvc_show_data('src', $image)) == 'video'): ?>
149 <div class="wdk-col" data-type="<?php echo esc_attr($type); ?>">
150 <div class="wdk-listing-image-card">
151 <video controls loop <?php if (wmvc_show_data('auto_start_video', $settings, false) == 'yes'): ?> autoplay <?php endif; ?> src="<?php echo esc_url(wmvc_show_data('src', $image)); ?>" alt="<?php echo esc_attr(wmvc_show_data('alt', $image)); ?>" class="wdk-listing-image <?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height <?php endif; ?>"></video>
152
153 </div>
154 </div>
155 <?php elseif (wdk_file_extension_type(wmvc_show_data('src', $image)) == 'image'): ?>
156 <div class="wdk-col" data-type="<?php echo esc_attr($type); ?>">
157 <div class="wdk-listing-image-card">
158 <img
159 src="<?php echo esc_url(wmvc_show_data('src', $image)); ?>"
160 class="wdk-listing-image<?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height<?php endif; ?>"
161 alt="<?php echo esc_attr(wmvc_show_data('alt', $image)); ?>">
162 </div>
163 </div>
164 <?php endif; ?>
165 <?php endforeach; ?>
166
167 <?php if (!empty($tabs[$tab_key]) && wmvc_show_data('layout_carousel_columns', $settings, 1) < wmvc_count($tabs[$tab_key])): ?>
168 </div>
169 <div class="wdk-listing-slider_arrows">
170 <a title="<?php echo esc_attr__('prev slider', 'wpdirectorykit'); ?>" href="#" class="wdk-slider-prev wdk-listing-slider_arrow">
171 <?php \Elementor\Icons_Manager::render_icon($settings['styles_carousel_arrows_icon_left'], ['aria-hidden' => 'true']); ?>
172 </a>
173 <a title="<?php echo esc_attr__('next slider', 'wpdirectorykit'); ?>" href="#" class="wdk-slider-next wdk-listing-slider_arrow">
174 <?php \Elementor\Icons_Manager::render_icon($settings['styles_carousel_arrows_icon_right'], ['aria-hidden' => 'true']); ?>
175 </a>
176 </div>
177 <?php else: ?>
178 </div>
179 <?php endif; ?>
180 </div>
181 <?php
182 // Thumbs
183 if (count($tabs[$tab_key]) > 1): ?>
184 <div class="banner-thumbs-con elementor-section elementor-section-boxed">
185 <div class="elementor-container">
186 <div class="banner-thumbs" id="banner_thumbs_<?php echo esc_attr($tab_key); ?>">
187 <?php foreach ($tabs[$tab_key] as $key => $image): ?>
188 <?php
189 $type = $tab_key;
190 ?>
191 <?php if (
192 is_string($image) && (
193 filter_var($image, FILTER_VALIDATE_URL) ||
194 preg_match('/^www\./i', $image)
195 )
196 ): ?>
197
198 <?php elseif (!wmvc_show_data('wdk_listing_video_disabled', $settings, false) && wdk_file_extension_type(wmvc_show_data('src', $image)) == 'video'): ?>
199 <div class="banner-thumb" data-type="<?php echo esc_attr($type); ?>">
200 <video src="<?php echo esc_url(wmvc_show_data('src', $image)); ?>" alt="<?php echo esc_attr(wmvc_show_data('alt', $image)); ?>" class="wdk-listing-image <?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height <?php endif; ?>"></video>
201 </div>
202 <?php elseif (wdk_file_extension_type(wmvc_show_data('src', $image)) == 'image'): ?>
203 <div class="banner-thumb" data-type="<?php echo esc_attr($type); ?>">
204 <img src="<?php echo esc_url(wmvc_show_data('src', $image)); ?>" class="wdk-listing-image <?php if ($settings['enable_fixed_height'] != 'yes'): ?> auto_height <?php endif; ?>" alt="<?php echo esc_attr(wmvc_show_data('alt', $image)); ?>">
205 </div>
206 <?php endif; ?>
207 <?php endforeach; ?>
208 </div><!--banner-thumbs end-->
209 </div>
210 </div>
211 <?php endif; ?>
212 </div>
213 <?php endforeach; ?>
214 </div> <!-- .wdk-listing-slider--content-tabs -->
215 <?php endif; ?>
216 </div>
217 </div>
218 <script>
219 jQuery(document).ready(function($){
220 function initTabSlider(tab_key) {
221 var sliderSelector = '#wdk_el_<?php echo esc_html($id_element); ?> #wdk_slider_' + tab_key;
222 var thumbsSelector = '#wdk_el_<?php echo esc_html($id_element); ?> #banner_thumbs_' + tab_key;
223
224 // destroy before re-init
225 if ($(sliderSelector).hasClass('slick-initialized')) {
226 $(sliderSelector).slick('unslick');
227 }
228 if ($(thumbsSelector).length && $(thumbsSelector).hasClass('slick-initialized')) {
229 $(thumbsSelector).slick('unslick');
230 }
231
232 $(sliderSelector).slick({
233 <?php if (!empty($images) && wmvc_show_data('layout_carousel_columns', $settings, 1) < wmvc_count($images)): ?>
234 dots: true,
235 arrows: true,
236 <?php else: ?>
237 dots: false,
238 arrows: false,
239 <?php endif; ?>
240 slidesToShow: <?php echo esc_js(wmvc_show_data('layout_carousel_columns', $settings, 1)); ?>,
241 slidesToScroll: <?php echo esc_js(wmvc_show_data('layout_carousel_columns', $settings, 1)); ?>,
242 <?php if (!empty(wmvc_show_data('layout_carousel_is_infinite', $settings))): ?>
243 infinite: <?php echo esc_js(wmvc_show_data('layout_carousel_is_infinite', $settings, 'true')); ?>,
244 <?php endif; ?>
245 <?php if (!empty(wmvc_show_data('layout_carousel_is_autoplay', $settings))): ?>
246 autoplay: <?php echo esc_js(wmvc_show_data('layout_carousel_is_autoplay', $settings, 'false')); ?>,
247 <?php endif; ?>
248 nextArrow: $('#wdk_el_<?php echo esc_html($id_element); ?> #wdk_list_slider_tab_'+tab_key+' .wdk-listing-slider_arrows .wdk-slider-next'),
249 prevArrow: $('#wdk_el_<?php echo esc_html($id_element); ?> #wdk_list_slider_tab_'+tab_key+' .wdk-listing-slider_arrows .wdk-slider-prev'),
250 customPaging: function(slider, i) {
251 return '<span class="wdk_lr_dot"><?php \Elementor\Icons_Manager::render_icon($settings['styles_carousel_dots_icon'], ['aria-hidden' => 'true']); ?></span>';
252 },
253 responsive: [{
254 breakpoint: 600,
255 settings: {
256 slidesToShow: 1,
257 slidesToScroll: 1
258 }
259 }],
260 asNavFor: thumbsSelector.length ? thumbsSelector : null
261 });
262
263 if ($(thumbsSelector).length) {
264 $(thumbsSelector).slick({
265 slidesToShow: <?php echo (!empty(trim(wmvc_show_data('styles_thmbn_nav_columns', $settings, '4')))) ? esc_js(wmvc_show_data('styles_thmbn_nav_columns', $settings, '4')) : 4; ?>,
266 slidesToScroll: 1,
267 asNavFor: sliderSelector,
268 dots: false,
269 centerMode: false,
270 arrows: false,
271 focusOnSelect: true,
272 responsive: [{
273 breakpoint: 991,
274 settings: {
275 slidesToShow: <?php echo (!empty(trim(wmvc_show_data('styles_thmbn_nav_columns_tablet', $settings, '3')))) ? esc_js(wmvc_show_data('styles_thmbn_nav_columns_tablet', $settings, '3')) : 3; ?>,
276 }
277 },
278 {
279 breakpoint: 768,
280 settings: {
281 slidesToShow: <?php echo (!empty(trim(wmvc_show_data('styles_thmbn_nav_columns_mobile', $settings, '2')))) ? esc_js(wmvc_show_data('styles_thmbn_nav_columns_mobile', $settings, '2')) : 2; ?>,
282 }
283 },
284 ]
285 });
286 }
287
288 // Sync thumb highlight after change
289 $(sliderSelector).on('afterChange', function(event, slick, currentSlide) {
290 if ($(thumbsSelector).length) {
291 $(thumbsSelector).find('.slick-slide').removeClass('is-active');
292 $(thumbsSelector).find('.slick-slide[data-slick-index="' + currentSlide + '"]').addClass('is-active');
293 }
294 });
295
296 $(sliderSelector).on('reInit afterChange', function(event, slick, currentSlide) {
297 var visibleSlides = $(sliderSelector).find('.slick-slide:not(.slick-cloned):visible').length;
298 if (visibleSlides <= 1) {
299 $('#wdk_el_<?php echo esc_html($id_element); ?> #wdk_list_slider_tab_'+tab_key+' .slick-arrow').hide();
300 } else {
301 $('#wdk_el_<?php echo esc_html($id_element); ?> #wdk_list_slider_tab_'+tab_key+' .slick-arrow').show();
302 }
303 });
304 }
305
306 // On load: initialize all tabs, show only active
307 $('.wdk-listing-slider--tab-pane').hide();
308 $('.wdk-listing-slider--tab-pane.active').show();
309
310 // Initialize the visible slider only, or all if you like
311 var firstTab = $('.wdk-listing-slider--tab-pane.active').attr('id');
312 if (firstTab) {
313 var firstTabKey = firstTab.replace('wdk_list_slider_tab_', '');
314 initTabSlider(firstTabKey);
315 }
316
317 // Change tabs event
318 $(document).on('click', '.wdk-listing-slider--tabs--btn', function(e){
319 e.preventDefault();
320 var $this = $(this);
321 var tabKey = $this.data('tab');
322 $('.wdk-listing-slider--tabs--btn').removeClass('active');
323 $this.addClass('active');
324 $('.wdk-listing-slider--tab-pane').removeClass('active').hide();
325 $('#wdk_list_slider_tab_'+tabKey).addClass('active').show();
326
327 // destroy all others
328 $('.wdk_listing_slider_ini.slick-initialized').not('#wdk_slider_'+tabKey).each(function(){
329 $(this).slick('unslick');
330 });
331 $('.banner-thumbs.slick-initialized').not('#banner_thumbs_'+tabKey).each(function(){
332 $(this).slick('unslick');
333 });
334
335 // init for this tab if not already initialized
336 initTabSlider(tabKey);
337 });
338 });
339 </script>