Advertisement
Guest User

Untitled

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