· 5 years ago · Jul 23, 2020, 09:14 AM
1<?php
2/**
3 * Helper for slideshows
4 *
5 */
6if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
7
8
9if ( ! class_exists( 'avia_slideshow' ) )
10{
11 class avia_slideshow
12 {
13 static $slider = 0; //slider count for the current page
14
15 /**
16 * base config set on initialization
17 *
18 * @var array
19 */
20 protected $config;
21
22 /**
23 * attachment posts for the current slider
24 *
25 * @var array
26 */
27 protected $slides;
28
29 /**
30 * number of slides
31 *
32 * @var int
33 */
34 protected $slide_count;
35
36 /**
37 *
38 * @var array
39 */
40 protected $id_array;
41
42
43 /**
44 *
45 * @var boolean
46 */
47 protected $need_conditional_load;
48
49
50 /**
51 *
52 * @param array $config
53 */
54 public function __construct( array $config )
55 {
56 $this->slides = array();
57 $this->slide_count = 0;
58 $this->id_array = array();
59 $this->need_conditional_load = false;
60
61 $this->config = array_merge( array(
62 'size' => 'featured',
63 'lightbox_size' => 'large',
64 'animation' => 'slide',
65 'transition_speed' => '', // in ms - empty for default
66 'conditional_play' => '',
67 'ids' => '',
68 'video_counter' => 0,
69 'autoplay' => 'false',
70 'bg_slider' => 'false',
71 'slide_height' => '',
72 'handle' => '',
73 'interval' => 5,
74 'class' => '',
75 'el_id' => '',
76 'css_id' => '',
77 'scroll_down' => '',
78 'control_layout' => '',
79 'content' => array(),
80 'custom_markup' => '',
81 'perma_caption' => '',
82 'autoplay_stopper' => '',
83 'image_attachment' => '',
84 'min_height' => '0px'
85
86 ), $config );
87
88 /**
89 *
90 * @param array $this->config
91 * @return array
92 */
93 $this->config = apply_filters( 'avf_slideshow_config', $this->config );
94
95 // reset to use default setting
96 if( empty( $this->config['transition_speed'] ) || ! is_numeric( $this->config['transition_speed'] ) )
97 {
98 unset( $this->config['transition_speed'] );
99 }
100
101 //check how large the slider is and change the classname accordingly
102 global $_wp_additional_image_sizes;
103 $width = 1500;
104
105 if( isset( $_wp_additional_image_sizes[ $this->config['size'] ]['width'] ) )
106 {
107 $width = $_wp_additional_image_sizes[ $this->config['size'] ]['width'];
108 $height = $_wp_additional_image_sizes[ $this->config['size'] ]['height'];
109
110 /**
111 * Avoid notices in case user manipulated image settings to 0
112 */
113 $height = is_numeric( $height ) && $height > 0 ? $height : get_option( 'medium_size_h', 300 );
114 $width = is_numeric( $width ) && $width > 0 ? $width : get_option( 'medium_size_w', $height );
115
116 $this->config['default-height'] = ( 100 / $width ) * $height;
117
118 }
119 else if( $size = get_option( $this->config['size'] . '_size_w' ) )
120 {
121 $width = $size;
122 }
123
124 if( $width < 600 )
125 {
126 $this->config['class'] .= ' avia-small-width-slider';
127 }
128
129 if( $width < 305 )
130 {
131 $this->config['class'] .= ' avia-super-small-width-slider';
132 }
133
134 //if we got subslides overwrite the id array
135 if( ! empty( $config['content'] ) )
136 {
137 $this->extract_subslides( $config['content'] );
138 }
139
140 if( 'aviaTBautoplay_stopper' == $this->config['autoplay_stopper'] )
141 {
142 $this->config['autoplay_stopper'] = true;
143 }
144 else
145 {
146 $this->config['autoplay_stopper'] = false;
147 }
148
149 $this->set_slides( $this->config['ids'] );
150 }
151
152 /**
153 * @since 4.4
154 */
155 public function __destruct()
156 {
157 unset( $this->config );
158 unset( $this->slides );
159 unset( $this->id_array );
160 }
161
162
163 /**
164 *
165 * @param string $ids
166 * @return void
167 */
168 public function set_slides( $ids )
169 {
170 $ids = trim( $ids );
171
172 if( empty( $ids ) && empty( $this->config['video_counter'] ) )
173 {
174 return;
175 }
176
177 /**
178 * video slides have no id and return empty string - avoid an unnecessary db query if only video slides
179 */
180 $post_ids = explode( ',', $ids );
181 $post_ids = array_unique( $post_ids );
182 if( ( 1 == count( $post_ids ) ) && empty( $post_ids[0] ) )
183 {
184 $post_ids = '';
185 }
186 else
187 {
188 $post_ids = implode( ',', $post_ids );
189 }
190
191 if( ! empty( $post_ids ) )
192 {
193 $this->slides = get_posts( array(
194 'include' => $ids,
195 'post_status' => 'inherit',
196 'post_type' => 'attachment',
197 'post_mime_type' => 'image',
198 'order' => 'ASC',
199 'orderby' => 'post__in'
200 )
201 );
202 }
203 else
204 {
205 $this->slides = array();
206 }
207
208 //resort slides so the id of each slide matches the post id
209 $new_slides = array();
210 foreach( $this->slides as $slide )
211 {
212 $new_slides[ $slide->ID ] = $slide;
213 }
214
215 $slideshow_data = array();
216 $slideshow_data['slides'] = $new_slides;
217 $slideshow_data['id_array'] = explode( ',', $this->config['ids'] );
218 $slideshow_data['slide_count'] = count( array_filter( $slideshow_data['id_array'] ) ) + $this->config['video_counter'];
219
220 $slideshow_data = apply_filters( 'avf_avia_builder_slideshow_filter', $slideshow_data, $this );
221
222 $this->slides = $slideshow_data['slides'];
223 $this->id_array = $slideshow_data['id_array'];
224 $this->slide_count = $slideshow_data['slide_count'];
225 }
226
227 /**
228 *
229 * @param string $size
230 */
231 public function set_size( $size )
232 {
233 $this->config['size'] = $size;
234 }
235
236
237 /**
238 *
239 * @param string $class
240 */
241 public function set_extra_class( $class )
242 {
243 $this->config['class'] .= ' ' . $class;
244 }
245
246
247 /**
248 *
249 * @return string
250 */
251 public function html()
252 {
253 $html = '';
254 $counter = 0;
255 $style = '';
256 $extraClass = '';
257 $cond_play_class = '';
258 avia_slideshow::$slider++;
259
260 if( $this->slide_count == 0 )
261 {
262 return $html;
263 }
264
265 if( ! empty( $this->config['scroll_down'] ) )
266 {
267 $html .= "<a href='#next-section' title='' class='scroll-down-link " . $this->config['control_layout'] . "' " . av_icon_string( 'scrolldown' ) . "></a>";
268 $extraClass .= 'av-slider-scroll-down-active';
269 }
270
271 if( ! empty( $this->config['control_layout'] ) )
272 {
273 $extraClass .= ' ' . $this->config['control_layout'];
274 }
275
276 if( ! empty( $this->config['conditional_play'] ) && $this->need_conditional_load )
277 {
278 $cond_play_class = 'av-show-video-on-click';
279 }
280
281 $style = '';
282 $data = AviaHelper::create_data_string( $this->config );
283 $slide_html = empty( $this->subslides ) ? $this->default_slide() : $this->advanced_slide();
284
285 if( ! empty( $this->config['default-height'] ) )
286 {
287 $style = "style='padding-bottom: {$this->config['default-height']}%;'";
288 $extraClass .= ' av-default-height-applied';
289 }
290
291 $markup = avia_markup_helper( array( 'context' => 'image', 'echo' => false, 'custom_markup' => $this->config['custom_markup'] ) );
292
293
294 $html .= "<div {$this->config['el_id']} {$data} class='avia-slideshow avia-slideshow-" . avia_slideshow::$slider . " {$extraClass} avia-slideshow-{$this->config['size']} {$this->config['handle']} {$this->config['class']} avia-{$this->config['animation']}-slider ' {$markup}>";
295
296 $html .= "<ul class='avia-slideshow-inner {$cond_play_class}' {$style} >";
297 $html .= $slide_html;
298 $html .= '</ul>';
299
300 if( $this->slide_count > 1 )
301 {
302 $html .= $this->slide_navigation_arrows();
303 $html .= $this->slide_navigation_dots();
304 }
305
306
307 if( ! empty( $this->config['caption_override'] ) )
308 {
309 $html .= $this->config['caption_override'];
310 }
311
312 $html .= '</div>';
313
314 return $html;
315 }
316
317 //function that renders the usual slides. use when we didnt use sub-shorcodes to define the images but ids
318 protected function default_slide()
319 {
320 $html = '';
321 $counter = 0;
322
323 $markup_url = avia_markup_helper( array( 'context' => 'image_url', 'echo' => false, 'custom_markup' => $this->config['custom_markup'] ) );
324
325 foreach( $this->id_array as $id )
326 {
327 if( isset( $this->slides[ $id ] ) )
328 {
329 $slide = $this->slides[ $id ];
330
331 $counter ++;
332 $img = wp_get_attachment_image_src( $slide->ID, $this->config['size'] );
333 $link = wp_get_attachment_image_src( $slide->ID, $this->config['lightbox_size'] );
334 $caption = trim($slide->post_excerpt) ? '<div class="avia-caption capt-bottom capt-left"><div class="avia-inner-caption">' . wptexturize( $slide->post_excerpt ) . "</div></div>": '';
335
336 $imgalt = get_post_meta( $slide->ID, '_wp_attachment_image_alt', true );
337 $imgalt = ! empty( $imgalt ) ? esc_attr( $imgalt ) : '';
338 $imgtitle = trim( $slide->post_title ) ? esc_attr( $slide->post_title ) : '';
339 if( $imgtitle == '-' )
340 {
341 $imgtitle = '';
342 }
343 $imgdescription = trim( $slide->post_content ) ? esc_attr( $slide->post_content ) : '';
344
345
346 $tags = apply_filters( 'avf_slideshow_link_tags', array( "a href='" . $link[0] . "' title='" . $imgdescription . "'", 'a' ) ); // can be filtered and for example be replaced by array('div','div')
347
348 $img_tag = "<img src='{$img[0]}' width='{$img[1]}' height='{$img[2]}' title='{$imgtitle}' alt='{$imgalt}' {$markup_url} />";
349 $img_tag = Av_Responsive_Images()->make_image_responsive( $img_tag, $slide->ID );
350
351 $html .= "<li class='slide-{$counter} slide-id-{$slide->ID}'>";
352 $html .= "<{$tags[0]}>{$caption}{$img_tag}</{$tags[1]}>";
353 $html .= '</li>';
354 }
355 else
356 {
357 $this->slide_count --;
358 }
359 }
360
361 return $html;
362 }
363
364 //function that renders the slides. use when we did use sub-shorcodes to define the images
365 protected function advanced_slide()
366 {
367 $html = '';
368 $counter = 0;
369 $this->ie8_fallback = '';
370
371 foreach( $this->id_array as $key => $id )
372 {
373 $dev_tags = aviaShortcodeTemplate::set_frontend_developer_heading_tag( $this->subslides[ $key ]['attr'] );
374
375 $meta = array_merge( array( 'content' => $this->subslides[$key]['content'],
376 'title' => '',
377 'link_apply' => '',
378 //direct link from image
379 'link' => '',
380 'link_target' => '',
381 //button link 1
382 'button_label' => '',
383 'button_color' => 'light',
384 'link1' => '',
385 'link_target1' => '',
386 //button link 2
387 'button_label2' => '',
388 'button_color2' => 'light',
389 'link2' => '',
390 'link_target2' => '',
391
392 'position' => 'center center',
393 'caption_pos' => 'capt-bottom capt-left',
394 'video_cover' => '',
395 'video_controls' => '',
396 'video_mute' => '',
397 'video_loop' => '',
398 'video_format' => '',
399 'video_autoplay' => '',
400 'video_ratio' => '16:9',
401 'video_mobile_disabled' => '',
402 'video_mobile' => 'mobile-fallback-image',
403 'mobile_image' => '',
404 'fallback_link' => '',
405 'slide_type' =>'',
406 'custom_markup' => '',
407 'custom_title_size' => '',
408 'custom_content_size' => '',
409 'font_color' => '',
410 'custom_title' => '',
411 'custom_content' => '',
412 'overlay_enable' => '',
413 'overlay_opacity' => '',
414 'overlay_color' => '',
415 'overlay_pattern' => '',
416 'overlay_custom_pattern' => '',
417 'preload' => $this->need_conditional_load ? 'none' : ''
418
419 ), $this->subslides[ $key ]['attr'] );
420
421 // Autoplay videos must be muted to work on several browsers (e.g. FF, Chrome)
422 if( empty( $meta['video_autoplay'] ) )
423 {
424 $meta['video_mute'] = 'aviaTBaviaTBvideo_mute';
425 }
426
427 //return $av_font_classes, $av_title_font_classes and $av_display_classes
428 extract( AviaHelper::av_mobile_sizes( $this->subslides[ $key ]['attr'] ) );
429 extract( $meta );
430
431 if( isset( $this->slides[ $id ] ) || $slide_type == 'video' )
432 {
433 $img = array( '' );
434 $slide = '';
435 $attachment_id = isset( $this->slides[ $id ] ) ? $id : false;
436 $link = AviaHelper::get_url( $link, $attachment_id );
437 $extra_class = '';
438 $linkdescription= '';
439 $linkalt = '';
440 $this->service = false;
441 $slider_data = '';
442 $stretch_height = false;
443 $final_ratio = '';
444 $viewport = 16/9;
445
446 $fallback_img_style = '';
447 $fallback_img_class = '';
448
449
450 $markup_url = avia_markup_helper( array( 'context' => 'image_url', 'echo' => false, 'id' => $attachment_id, 'custom_markup' => $custom_markup ) );
451
452 if( $slide_type == 'video' )
453 {
454 $this->service = avia_slideshow_video_helper::which_video_service( $video );
455 $video = avia_slideshow_video_helper::set_video_slide( $video, $this->service, $meta , $this->config );
456 $video_class = ! empty( $video_controls ) ? ' av-hide-video-controls' : '';
457 $video_class .= ! empty( $video_mute ) ? ' av-mute-video' : '';
458 $video_class .= ! empty( $video_loop ) ? ' av-loop-video' : '';
459 $video_class .= ! empty( $video_mobile ) ? ' av-' . $video_mobile : '';
460
461 $extra_class .= " av-video-slide ".$video_cover." av-video-service-".$this->service." ".$video_class;
462 $slider_data .= " data-controls='{$video_controls}' data-mute='{$video_mute}' data-loop='{$video_loop}' data-disable-autoplay='{$video_autoplay}' ";
463
464 if( $mobile_image )
465 {
466 $fallback_img = wp_get_attachment_image_src( $mobile_image, $this->config['size'] );
467 $fallback_img_style = "style='background-image:url(\"{$fallback_img[0]}\");'";
468
469 $slider_data .= " data-mobile-img='" . $fallback_img[0] . "'";
470
471 if( $fallback_link )
472 {
473 $slider_data .= " data-fallback-link='" . $fallback_link . "'";
474 }
475 }
476
477 //if we dont use a fullscreen slider pass the video ratio to the slider
478 if( $this->config['bg_slider'] != 'true' )
479 {
480 global $avia_config;
481
482 //if we use the small slideshow only allow the 'full' $video_format
483 if( $this->config['handle'] == 'av_slideshow' )
484 {
485 $video_format = 'full';
486 }
487
488 //calculate the viewport ratio
489 if( ! empty( $avia_config['imgSize'][ $this->config['size'] ] ) )
490 {
491 $viewport = $avia_config['imgSize'][ $this->config['size'] ]['width'] / $avia_config['imgSize'][ $this->config['size'] ]['height'];
492 }
493
494
495 //calculate the ratio when passed as a string (eg: 16:9, 4:3). fallback is 16:9
496 $video_ratio = explode( ':', trim( $video_ratio ) );
497 if( empty( $video_ratio[0] ) )
498 {
499 $video_ratio[0] = 16;
500 }
501 if( empty( $video_ratio[1] ) )
502 {
503 $video_ratio[1] = 9;
504 }
505
506 $final_ratio = ( (int) $video_ratio[0] / (int) $video_ratio[1] );
507
508 switch( $video_format )
509 {
510 case '':
511 $final_ratio = $viewport;
512 break;
513 case 'stretch':
514 $final_ratio = $viewport;
515 $stretch_height = ceil( $viewport / ( $video_ratio[0] / $video_ratio[1] ) * 100 );
516 $stretch_pos = ( ( $stretch_height - 100 ) / 2 ) * -1;
517 $slider_data .= " data-video-height='{$stretch_height}'";
518 $slider_data .= " data-video-toppos='{$stretch_pos}'";
519 $extra_class .= ' av-video-stretch';
520 break;
521 case 'full':
522 // do nothing and apply the entered ratio
523 break;
524 }
525
526 $slider_data .= " data-video-ratio='{$final_ratio}'";
527 }
528
529 }
530 else //img slide
531 {
532 $slide = $this->slides[ $id ];
533 $linktitle = trim( $slide->post_title ) ? esc_attr( $slide->post_title ) : '';
534 if($linktitle == '-') $linktitle = '';
535 $linkdescription = ( trim( $slide->post_content ) && empty( $link ) ) ? "title='" . esc_attr( $slide->post_content ) . "'" : '';
536 $linkalt = get_post_meta( $slide->ID, '_wp_attachment_image_alt', true );
537 $linkalt = ! empty( $linkalt ) ? esc_attr( $linkalt ) : '';
538 $img = wp_get_attachment_image_src( $slide->ID, $this->config['size'] );
539 $video = '';
540 }
541
542 if( $this->slide_count === 1 )
543 {
544 $extra_class .= ' av-single-slide';
545 }
546
547 $blank = AviaHelper::get_link_target( $link_target );
548
549 $tags = ( ! empty( $link ) && $link_apply == 'image' ) ? array( "a href='{$link}'{$blank}", 'a' ) : array( 'div', 'div' );
550 $caption = '';
551 $button_html = '';
552 $counter ++;
553 $button_count = '';
554 if( strpos( $link_apply, 'button-two' ) !== false )
555 {
556 $button_count = 'avia-multi-slideshow-button';
557 }
558
559
560 //if we got a CTA button apply the link to the button istead of the slide
561 if( strpos( $link_apply, 'button' ) !== false )
562 {
563 $button_html .= $this->slideshow_cta_button( $link1, $link_target1, $button_color, $button_label, $button_count );
564 $tags = array( 'div', 'div' );
565 }
566
567 if( strpos( $link_apply, 'button-two' ) !== false )
568 {
569 $button_count .= ' avia-slideshow-button-2';
570 $button_html .= $this->slideshow_cta_button( $link2, $link_target2, $button_color2, $button_label2, $button_count );
571 }
572
573
574 //custom caption styles
575 $title_styling = ! empty( $custom_title_size ) ? "font-size:{$custom_title_size}px; " : '';
576 $content_styling = ! empty( $custom_content_size ) ? "font-size:{$custom_content_size}px; " : '';
577 $content_class = '';
578
579 if( $font_color == 'custom' )
580 {
581 $title_styling .= ! empty( $custom_title ) ? "color:{$custom_title}; " : '';
582 $content_styling .= ! empty( $custom_content ) ? "color:{$custom_content}; " : '';
583 }
584
585 if( $title_styling )
586 {
587 $title_styling = " style='{$title_styling}'" ;
588 }
589
590 if( $content_styling )
591 {
592 $content_styling = " style='{$content_styling}'" ;
593 $content_class = 'av_inherit_color';
594 }
595
596 //check if we got a caption
597 $markup_description = avia_markup_helper( array( 'context' => 'description', 'echo' => false, 'id' => $attachment_id, 'custom_markup' => $custom_markup ) );
598 $markup_name = avia_markup_helper( array( 'context' => 'name', 'echo' => false, 'id' => $attachment_id, 'custom_markup' => $custom_markup ) );
599
600 if( trim( $title ) != '' )
601 {
602
603 $default_heading = ! empty( $dev_tags['heading_tag'] ) ? $dev_tags['heading_tag'] : 'h2';
604 $args = array(
605 'heading' => $default_heading,
606 'extra_class' => $dev_tags['heading_class']
607 );
608
609 $extra_args = array( $this, $key );
610
611 /**
612 * @since 4.5.5
613 * @return array
614 */
615 $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
616
617 $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
618 $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : $dev_tags['heading_class'];
619
620 $title = "<{$heading} {$title_styling} class='avia-caption-title {$css} {$av_title_font_classes}' $markup_name>" . trim( apply_filters( 'avf_slideshow_title', $title ) ) . "</{$heading}>";
621 }
622
623 if( is_array( $content ) )
624 {
625 $content = implode( ' ', $content ); //temp fix for trim() expects string warning until I can actually reproduce the problem
626 }
627
628 if( trim($content ) != '' )
629 {
630 $content = "<div class='avia-caption-content {$av_font_classes} {$content_class}' {$markup_description} {$content_styling}>" . ShortcodeHelper::avia_apply_autop( ShortcodeHelper::avia_remove_autop( trim( $content ) ) ) . '</div>';
631 }
632
633 if( trim( $title . $content . $button_html ) != '' )
634 {
635 if( trim( $title ) != '' && trim( $button_html ) != '' && trim( $content ) == '')
636 {
637 $content = '<br/>';
638 }
639
640 if( $this->config['handle'] == 'av_slideshow_full' || $this->config['handle'] == 'av_fullscreen' )
641 {
642 $caption .= '<div class = "caption_fullwidth av-slideshow-caption ' . $caption_pos . '">';
643 $caption .= '<div class = "container caption_container">';
644 $caption .= '<div class = "slideshow_caption">';
645 $caption .= '<div class = "slideshow_inner_caption">';
646 $caption .= '<div class = "slideshow_align_caption">';
647 $caption .= $title;
648 $caption .= $content;
649 $caption .= $button_html;
650 $caption .= '</div>';
651 $caption .= '</div>';
652 $caption .= '</div>';
653 $caption .= '</div>';
654 $caption .= '</div>';
655 }
656 else
657 {
658 $caption = '<div class="avia-caption av-slideshow-caption"><div class="avia-inner-caption">' . $title.$content . '</div></div>';
659 }
660 }
661
662 if( ! empty( $this->config['perma_caption'] ) && empty( $this->config['caption_override'] ) )
663 {
664 $this->config['caption_override'] = $caption;
665 }
666
667 if( ! empty( $this->config['caption_override'] ) )
668 {
669 $caption = '';
670 }
671
672 if( ! empty( $img[0] ) )
673 {
674 $slider_data .= $this->config['bg_slider'] == 'true' ? "style='background-position:{$position};' data-img-url='{$img[0]}'" : '';
675
676 if( $slider_data )
677 {
678 if( empty( $this->ie8_fallback ) )
679 {
680 $this->ie8_fallback .= "<!--[if lte IE 8]>";
681 $this->ie8_fallback .= "<style type='text/css'>";
682 }
683 $this->ie8_fallback .= "\n #{$this->config['css_id']} .slide-{$counter}{";
684 $this->ie8_fallback .= "\n -ms-filter: \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$img[0]}', sizingMethod='scale')\"; ";
685 $this->ie8_fallback .= "\n filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$img[0]}', sizingMethod='scale'); ";
686 $this->ie8_fallback .= "\n } \n";
687 }
688 }
689
690
691
692
693 // $img[0] = 'https://kriesi.at/themes/enfold-photography/files/2014/08/darkened_girl.jpg';
694
695
696 $html .= "<li {$slider_data} class='{$extra_class} slide-{$counter} ' >";
697 $html .= "<{$tags[0]} data-rel='slideshow-" . avia_slideshow::$slider . "' class='avia-slide-wrap {$fallback_img_class}' {$fallback_img_style} {$linkdescription} >{$caption}";
698
699 if( $this->config['bg_slider'] != 'true' && empty( $video ) )
700 {
701 $img_style = '';
702 if( ! empty( $this->config['min_height'] ) && $this->config['min_height'] != '0px' )
703 {
704 $percent = 100 / ( 100 / $img[2] * (int) $this->config['min_height'] );
705 $this->config['min_width'] = ceil( ( $img[1] / $percent ) ) . 'px';
706
707 $img_style .= AviaHelper::style_string( $this->config, 'min_height', 'min-height' );
708 $img_style .= AviaHelper::style_string( $this->config, 'min_width', 'min-width' );
709 $img_style = AviaHelper::style_string( $img_style );
710 }
711
712 $img_tag = "<img src='{$img[0]}' width='{$img[1]}' height='{$img[2]}' title='{$linktitle}' alt='{$linkalt}' {$markup_url} {$img_style} />";
713 $img_tag = Av_Responsive_Images()->make_image_responsive( $img_tag, $slide->ID );
714
715 $html .= $img_tag;
716 }
717
718 $html .= $video;
719 $html .= $this->create_overlay( $meta );
720 $html .= $this->create_click_to_play_overlay();
721
722
723
724 $html .= '</'.$tags[1].'>';
725 $html .= '</li>';
726
727 if( $counter === 1 )
728 {
729 if( ! empty( $img[1] ) && ! empty( $img[2] ) )
730 {
731 $this->config['default-height'] = ( 100 / $img[1] ) * $img[2];
732 }
733 }
734
735 }
736 else
737 {
738 $this->slide_count --;
739 }
740 }
741
742 if( ! empty( $this->ie8_fallback ) )
743 {
744 $this->ie8_fallback .= '</style> <![endif]-->';
745 add_action( 'wp_footer', array( $this, 'add_ie8_fallback_to_footer' ) );
746 }
747
748 return $html;
749 }
750
751 public function add_ie8_fallback_to_footer()
752 {
753 // echo $this->ie8_fallback;
754 }
755
756 protected function slideshow_cta_button($link, $link_target, $button_color, $button_label, $button_count)
757 {
758 $button_html = '';
759
760 $link = AviaHelper::get_url( $link );
761 $blank = AviaHelper::get_link_target( $link_target );
762
763 $button_html .= "<a href='{$link}' {$blank} class='avia-slideshow-button avia-button avia-color-{$button_color} {$button_count}' data-duration='800' data-easing='easeInOutQuad'>";
764 $button_html .= $button_label;
765 $button_html .= '</a>';
766 return $button_html;
767 }
768
769
770 protected function slide_navigation_arrows()
771 {
772 global $avia_config;
773
774 $html = '';
775 $html .= "<div class='avia-slideshow-arrows avia-slideshow-controls'>";
776 $html .= "<a href='#prev' class='prev-slide' " . av_icon_string('prev_big') . ">" . __( 'Previous', 'avia_framework' ) . "</a>";
777 $html .= "<a href='#next' class='next-slide' " . av_icon_string('next_big') . ">" . __( 'Next', 'avia_framework' ) . "</a>";
778 $html .= '</div>';
779
780 return $html;
781 }
782
783 protected function slide_navigation_dots()
784 {
785 $html = '';
786 $html .= "<div class='avia-slideshow-dots avia-slideshow-controls'>";
787 $active = 'active';
788
789 for( $i = 1; $i <= $this->slide_count; $i++ )
790 {
791 $html .= "<a href='#{$i}' class='goto-slide {$active}' >{$i}</a>";
792 $active = '';
793 }
794
795 $html .= '</div>';
796
797 return $html;
798 }
799
800 /**
801 *
802 * @param array $slide_array
803 */
804 protected function extract_subslides( array $slide_array )
805 {
806 $this->config['ids']= array();
807 $this->subslides = array();
808
809 foreach( $slide_array as $key => $slide )
810 {
811 $this->subslides[$key] = $slide;
812 $this->config['ids'][] = $slide['attr']['id'];
813
814 if( empty( $slide['attr']['id'] ) && ! empty( $slide['attr']['video'] ) && $slide['attr']['slide_type'] === 'video' )
815 {
816 $this->config['video_counter'] ++ ;
817 if( avia_slideshow_video_helper::is_extern_service( $slide['attr']['video'] ) )
818 {
819 $this->need_conditional_load = true;
820 }
821 else
822 {
823 if( ! $this->need_conditional_load )
824 {
825 /**
826 * Allow to change default behaviour to lazy load all video files
827 *
828 * @since 4.4
829 */
830 $this->need_conditional_load = apply_filters( 'avf_video_slide_conditional_load_html5', true, $slide_array, $this );
831 }
832 }
833 }
834 }
835
836 $this->config['ids'] = implode( ',', $this->config['ids'] );
837 unset( $this->config['content'] );
838 }
839
840 /**
841 *
842 * @param array $meta
843 * @return string
844 */
845 protected function create_overlay( array $meta )
846 {
847 extract($meta);
848
849 /*check/create overlay*/
850 $overlay = '';
851 if( ! empty( $overlay_enable ) )
852 {
853 $overlay_src = '';
854 $overlay = "opacity: {$overlay_opacity}; ";
855 if( ! empty( $overlay_color ) )
856 {
857 $overlay .= "background-color: {$overlay_color}; ";
858 }
859
860 if( ! empty( $overlay_pattern ) )
861 {
862 if( $overlay_pattern == 'custom' )
863 {
864 $overlay_src = $overlay_custom_pattern;
865 }
866 else
867 {
868 $overlay_src = str_replace('{{AVIA_BASE_URL}}', AVIA_BASE_URL, $overlay_pattern );
869 }
870 }
871
872 if( ! empty( $overlay_src ) )
873 {
874 $overlay .= "background-image: url({$overlay_src}); background-repeat: repeat;";
875 }
876
877 $overlay = "<div class='av-section-color-overlay' style='{$overlay}'></div>";
878 }
879
880 return $overlay;
881 }
882
883 /**
884 * Returns an overlay div if we need late loading of videos
885 *
886 * @since 4.4
887 * @return string
888 */
889 protected function create_click_to_play_overlay()
890 {
891 if( ! $this->need_conditional_load )
892 {
893 return '';
894 }
895
896
897 $overlay = "<div class='av-click-to-play-overlay'>";
898 $overlay .= '<div class="avia_playpause_icon">';
899 $overlay .= '</div>';
900 $overlay .= '</div>';
901
902 return $overlay;
903 }
904
905 }
906}
907
908
909if( ! class_exists( 'avia_slideshow_video_helper' ) )
910{
911 class avia_slideshow_video_helper
912 {
913
914 /**
915 * Define extern services that need to be confirmed by user
916 *
917 * @var array
918 */
919 static protected $extern_services = array( 'youtube', 'vimeo' );
920
921
922 static function set_video_slide( $video_url, $service = false, $meta = false, $config = false )
923 {
924 $video = '';
925 $origin_url = $video_url;
926
927 if( empty( $service ) )
928 {
929 $service = self::which_video_service( $video_url );
930 }
931
932 $uid = 'player_' . get_the_ID() . '_' . mt_rand() . '_' . mt_rand();
933 $controls = empty( $meta['video_controls'] ) ? 1 : 0;
934 $atts = array();
935 $atts['loop'] = empty( $meta['video_loop'] ) ? 0 : 1;
936 $atts['autoplay'] = empty( $meta['video_autoplay'] ) ? 1 : 0;
937 $atts['muted'] = empty( $meta['video_mute'] ) ? 0 : 1;
938
939 //was previously only used for mobile,now for everything
940 $fallback_img = ! empty( $meta['mobile_image'] ) ? $meta['mobile_image'] : '';
941
942 if( is_numeric( $fallback_img ) )
943 {
944 $fallback_img = wp_get_attachment_image_src( $fallback_img, $config['size'] );
945 $fallback_img = ( is_array( $fallback_img ) ) ? $fallback_img[0] : '';
946 }
947
948 switch( $service )
949 {
950 case 'html5':
951 $types = array( 'webm' => 'type="video/webm"', 'mp4' => 'type="video/mp4"', 'ogv' => 'type="video/ogg"' );
952 $video = "<div class='av-click-overlay'></div>" . avia_html5_video_embed( $video_url, $fallback_img, $types, $atts );
953 break;
954
955 case 'iframe':
956 $video = $video_url;
957 break;
958
959 case 'youtube':
960
961 $explode_at = strpos( $video_url, 'youtu.be/' ) !== false ? '/' : 'v=';
962 $video_url = explode( $explode_at, trim( $video_url ) );
963 $video_url = end( $video_url );
964 $video_id = $video_url;
965
966 //if parameters are appended make sure to create the correct video id
967 if( strpos( $video_url, '?' ) !== false || strpos( $video_url, '?' ) !== false )
968 {
969 preg_match( '!(.+)[&?]!', $video_url, $video_id );
970 $video_id = isset( $video_id[1] ) ? $video_id[1] : $video_id[0];
971 }
972
973 $video_data = apply_filters( 'avf_youtube_video_data', array(
974 'autoplay' => 0,
975 'videoid' => $video_id,
976 'hd' => 1,
977 'rel' => 0,
978 'wmode' => 'opaque',
979 'playlist' => $uid,
980 'loop' => 0,
981 'version' => 3,
982 'autohide' => 1,
983 'color' => 'white',
984 'controls' => $controls,
985 'showinfo' => 0,
986 'iv_load_policy'=> 3
987 ));
988
989 $data = AviaHelper::create_data_string( $video_data );
990
991 $video = "<div class='av-click-overlay'></div><div class='mejs-mediaelement'><div height='1600' width='900' class='av_youtube_frame' id='{$uid}' {$data} data-original_url='{$origin_url}' ></div></div>";
992
993 break;
994 case 'vimeo':
995
996 $color = ltrim( avia_get_option('colorset-main_color-primary'), '#');
997 $autopause = empty( $meta['video_section_bg'] ) ? 1 : 0; //pause if another vimeo video plays?
998 $video_url = explode( '/', trim( $video_url ) );
999 $video_url = end( $video_url );
1000 $video_url = esc_url( add_query_arg(
1001 array(
1002 'portrait' => 0,
1003 'byline' => 0,
1004 'title' => 0,
1005 'badge' => 0,
1006 'loop' => $atts['loop'],
1007 'autopause' => $autopause,
1008 'api' => 1,
1009 'rel' => 0,
1010 'player_id' => $uid,
1011 'color' => $color
1012 ),
1013 '//player.vimeo.com/video/' . $video_url
1014 ));
1015
1016 $video_url = apply_filters( 'avf_vimeo_video_url' , $video_url );
1017 $video = "<div class='av-click-overlay'></div><div class='mejs-mediaelement'><div data-src='{$video_url}' data-original_url='{$origin_url}' height='1600' width='900' class='av_vimeo_frame' id='{$uid}'></div></div>";
1018
1019 break;
1020 }
1021
1022 return $video;
1023
1024 }
1025
1026 //get the video service based on the url string fo the video
1027 static function which_video_service( $video_url )
1028 {
1029 $service = '';
1030
1031 if( avia_backend_is_file( $video_url, 'html5video' ) )
1032 {
1033 $service = 'html5';
1034 }
1035 else if( strpos($video_url, '<iframe' ) !== false )
1036 {
1037 $service = 'iframe';
1038 }
1039 else
1040 {
1041 if( strpos( $video_url, 'youtube.com/watch' ) !== false || strpos( $video_url, 'youtu.be/' ) !== false )
1042 {
1043 $service = 'youtube';
1044 }
1045 else if( strpos( $video_url, 'vimeo.com' ) !== false )
1046 {
1047 $service = 'vimeo';
1048 }
1049 }
1050
1051 return $service;
1052 }
1053
1054 /**
1055 * Checks, if teh video
1056 * @since 4.4
1057 * @param string $video_url
1058 * @return boolean
1059 */
1060 static public function is_extern_service( $video_url )
1061 {
1062 $ervice = avia_slideshow_video_helper::which_video_service( $video_url );
1063
1064 return in_array( $ervice, avia_slideshow_video_helper::$extern_services );
1065 }
1066 }
1067}