Advertisement
Guest User

av-helper-slideshow.php

a guest
May 7th, 2018
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.28 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. protected $config; //base config set on initialization
  15. protected $slides; //attachment posts for the current slider
  16. protected $slide_count = 0; //number of slides
  17. protected $id_array = array();
  18. function __construct($config)
  19. {
  20.  
  21. $this->config = array_merge(array(
  22. 'size' => 'featured',
  23. 'lightbox_size' => 'large',
  24. 'animation' => 'slide',
  25. 'ids' => '',
  26. 'video_counter' => 0,
  27. 'autoplay' => 'false',
  28. 'bg_slider' => 'false',
  29. 'slide_height' => '',
  30. 'handle' => '',
  31. 'interval' => 5,
  32. 'class' => "",
  33. 'css_id' => "",
  34. 'scroll_down' => "",
  35. 'control_layout'=> '',
  36. 'content' => array(),
  37. 'custom_markup' => '',
  38. 'perma_caption' => '',
  39. 'autoplay_stopper'=>'',
  40. 'image_attachment'=>'',
  41. 'min_height' =>'0px'
  42. ), $config);
  43.  
  44. $this->config = apply_filters('avf_slideshow_config', $this->config);
  45.  
  46. //check how large the slider is and change the classname accordingly
  47. global $_wp_additional_image_sizes;
  48. $width = 1500;
  49.  
  50. if(isset($_wp_additional_image_sizes[$this->config['size']]['width']))
  51. {
  52. $width = $_wp_additional_image_sizes[$this->config['size']]['width'];
  53. $height = $_wp_additional_image_sizes[$this->config['size']]['height'];
  54.  
  55. $this->config['default-height'] = (100/$width) * $height;
  56.  
  57. }
  58. else if($size = get_option( $this->config['size'].'_size_w' ))
  59. {
  60. $width = $size;
  61. }
  62.  
  63. if($width < 600)
  64. {
  65. $this->config['class'] .= " avia-small-width-slider";
  66. }
  67.  
  68. if($width < 305)
  69. {
  70. $this->config['class'] .= " avia-super-small-width-slider";
  71. }
  72.  
  73. //if we got subslides overwrite the id array
  74. if(!empty($config['content']))
  75. {
  76. $this->extract_subslides($config['content']);
  77. }
  78.  
  79. if("aviaTBautoplay_stopper" == $this->config['autoplay_stopper'])
  80. {
  81. $this->config['autoplay_stopper'] = true;
  82. }
  83. else
  84. {
  85. $this->config['autoplay_stopper'] = false;
  86. }
  87.  
  88. $this->set_slides($this->config['ids']);
  89. }
  90.  
  91. public function set_slides($ids)
  92. {
  93. if(empty($ids) && empty($this->config['video_counter'])) return;
  94.  
  95. $this->slides = get_posts(array(
  96. 'include' => $ids,
  97. 'post_status' => 'inherit',
  98. 'post_type' => 'attachment',
  99. 'post_mime_type' => 'image',
  100. 'order' => 'ASC',
  101. 'orderby' => 'post__in')
  102. );
  103.  
  104.  
  105.  
  106. //resort slides so the id of each slide matches the post id
  107. $new_slides = array();
  108. foreach($this->slides as $slide)
  109. {
  110. $new_slides[$slide->ID] = $slide;
  111. }
  112.  
  113. $slideshow_data = array();
  114. $slideshow_data['slides'] = $new_slides;
  115. $slideshow_data['id_array'] = explode(',',$this->config['ids']);
  116. $slideshow_data['slide_count'] = count(array_filter($slideshow_data['id_array'])) + $this->config['video_counter'];
  117.  
  118. $slideshow_data = apply_filters('avf_avia_builder_slideshow_filter', $slideshow_data);
  119.  
  120. $this->slides = $slideshow_data['slides'];
  121. $this->id_array = $slideshow_data['id_array'];
  122. $this->slide_count = $slideshow_data['slide_count'];
  123. }
  124.  
  125. public function set_size($size)
  126. {
  127. $this->config['size'] = $size;
  128. }
  129.  
  130. public function set_extra_class($class)
  131. {
  132. $this->config['class'] .= " ".$class;
  133. }
  134.  
  135.  
  136.  
  137. public function html()
  138. {
  139. $html = "";
  140. $counter = 0;
  141. $style = "";
  142. $extraClass = "";
  143. avia_slideshow::$slider++;
  144. if($this->slide_count == 0) return $html;
  145.  
  146. if(!empty($this->config['scroll_down']))
  147. {
  148. $html .= "<a href='#next-section' title='' class='scroll-down-link ".$this->config['control_layout']."' ". av_icon_string( 'scrolldown' ). "></a>";
  149. $extraClass .= "av-slider-scroll-down-active";
  150. }
  151.  
  152. if(!empty($this->config['control_layout'])) $extraClass .= " ".$this->config['control_layout'];
  153.  
  154. $style = "";
  155. $data = AviaHelper::create_data_string($this->config);
  156. $slide_html = empty($this->subslides) ? $this->default_slide() : $this->advanced_slide();
  157.  
  158. if(!empty($this->config['default-height']))
  159. {
  160. $style = "style='padding-bottom: ".$this->config['default-height']."%;'";
  161. $extraClass .= " av-default-height-applied";
  162. }
  163.  
  164.  
  165. $markup = avia_markup_helper(array('context' => 'image','echo'=>false, 'custom_markup'=>$this->config['custom_markup']));
  166.  
  167.  
  168.  
  169. $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>";
  170.  
  171.  
  172. $html .= "<ul class='avia-slideshow-inner' {$style}>";
  173.  
  174.  
  175. $html .= $slide_html;
  176. $html .= "</ul>";
  177.  
  178. if($this->slide_count > 1)
  179. {
  180. $html .= $this->slide_navigation_arrows();
  181. $html .= $this->slide_navigation_dots();
  182. }
  183.  
  184.  
  185. if(!empty($this->config['caption_override'])) $html .= $this->config['caption_override'];
  186.  
  187.  
  188. $html .= "</div>";
  189.  
  190.  
  191. return $html;
  192. }
  193.  
  194. //function that renders the usual slides. use when we didnt use sub-shorcodes to define the images but ids
  195. protected function default_slide()
  196. {
  197. $html = "";
  198. $counter = 0;
  199.  
  200. $markup_url = avia_markup_helper(array('context' => 'image_url','echo'=>false, 'custom_markup'=>$this->config['custom_markup']));
  201.  
  202. foreach($this->id_array as $id)
  203. {
  204. if(isset($this->slides[$id]))
  205. {
  206. $slide = $this->slides[$id];
  207.  
  208. $counter ++;
  209. $img = wp_get_attachment_image_src($slide->ID, $this->config['size']);
  210. $link = wp_get_attachment_image_src($slide->ID, $this->config['lightbox_size']);
  211. $caption = trim($slide->post_excerpt) ? '<div class="avia-caption capt-bottom capt-left"><div class="avia-inner-caption">'.wptexturize($slide->post_excerpt)."</div></div>": "";
  212.  
  213. $imgalt = get_post_meta($slide->ID, '_wp_attachment_image_alt', true);
  214. $imgalt = !empty($imgalt) ? esc_attr($imgalt) : '';
  215. $imgtitle = trim($slide->post_title) ? esc_attr($slide->post_title) : "";
  216. if($imgtitle == "-") $imgtitle = "";
  217. $imgdescription = trim($slide->post_content) ? esc_attr($slide->post_content) : "";
  218.  
  219.  
  220. $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')
  221.  
  222. $html .= "<li class='slide-{$counter} slide-id-".$slide->ID."'>";
  223. $html .= "<".$tags[0]." >{$caption}<img src='".$img[0]."' width='".$img[1]."' height='".$img[2]."' title='".$imgtitle."' alt='".$imgalt."' $markup_url /></ ".$tags[1]." >";
  224. $html .= "</li>";
  225. }
  226. else
  227. {
  228. $this->slide_count --;
  229. }
  230. }
  231.  
  232. return $html;
  233. }
  234.  
  235. //function that renders the slides. use when we did use sub-shorcodes to define the images
  236. protected function advanced_slide()
  237. {
  238. $html = "";
  239. $counter = 0;
  240. $this->ie8_fallback = "";
  241.  
  242. foreach($this->id_array as $key => $id)
  243. {
  244. $meta = array_merge( array( 'content' => $this->subslides[$key]['content'],
  245. 'title' =>'',
  246. 'link_apply' =>'',
  247. //direct link from image
  248. 'link' =>'',
  249. 'link_target' =>'',
  250. //button link 1
  251. 'button_label' =>'',
  252. 'button_color' =>'light',
  253. 'link1' =>'',
  254. 'link_target1' =>'',
  255. //button link 2
  256. 'button_label2' =>'',
  257. 'button_color2' =>'light',
  258. 'link2' =>'',
  259. 'link_target2' =>'',
  260.  
  261. 'position' =>'center center',
  262. 'caption_pos' =>'capt-bottom capt-left',
  263. 'video_cover' =>'',
  264. 'video_controls'=>'',
  265. 'video_mute' =>'',
  266. 'video_loop' =>'',
  267. 'video_format' =>'',
  268. 'video_autoplay'=>'',
  269. 'video_ratio' =>'16:9',
  270. 'video_mobile_disabled'=>'',
  271. 'video_mobile' =>'mobile-fallback-image',
  272. 'mobile_image' => '',
  273. 'fallback_link' => '',
  274. 'slide_type' =>'',
  275. 'custom_markup' => '',
  276. 'custom_title_size' => '',
  277. 'custom_content_size' => '',
  278. 'font_color' =>'',
  279. 'custom_title' => '',
  280. 'custom_content' => '',
  281. 'overlay_enable' => '',
  282. 'overlay_opacity' => '',
  283. 'overlay_color' => '',
  284. 'overlay_pattern' => '',
  285. 'overlay_custom_pattern' => '',
  286.  
  287.  
  288. ), $this->subslides[$key]['attr']);
  289.  
  290. //return $av_font_classes, $av_title_font_classes and $av_display_classes
  291. extract(AviaHelper::av_mobile_sizes($this->subslides[$key]['attr']));
  292. extract($meta);
  293.  
  294. if(isset($this->slides[$id]) || $slide_type == 'video')
  295. {
  296. $img = array('');
  297. $slide = "";
  298. $attachment_id = isset($this->slides[$id]) ? $id : false;
  299. $link = AviaHelper::get_url($link, $attachment_id);
  300. $extra_class = "";
  301. $linkdescription= "";
  302. $linkalt = "";
  303. $this->service = false;
  304. $slider_data = "";
  305. $stretch_height = false;
  306. $final_ratio = "";
  307. $viewport = 16/9;
  308.  
  309. $markup_url = avia_markup_helper(array('context' => 'image_url','echo'=>false, 'id'=>$attachment_id, 'custom_markup'=>$custom_markup));
  310.  
  311. if($slide_type == 'video')
  312. {
  313. $this->service = avia_slideshow_video_helper::which_video_service($video);
  314. $video = avia_slideshow_video_helper::set_video_slide($video, $this->service, $meta);
  315. $video_class = !empty( $video_controls ) ? " av-hide-video-controls" : "";
  316. $video_class .= !empty( $video_mute ) ? " av-mute-video" : "";
  317. $video_class .= !empty( $video_loop ) ? " av-loop-video" : "";
  318. $video_class .= !empty( $video_mobile ) ? " av-".$video_mobile : "";
  319.  
  320. $extra_class .= " av-video-slide ".$video_cover." av-video-service-".$this->service." ".$video_class;
  321. $slider_data .= " data-controls='{$video_controls}' data-mute='{$video_mute}' data-loop='{$video_loop}' data-disable-autoplay='{$video_autoplay}' ";
  322.  
  323. if($mobile_image){
  324. $fallback_img = wp_get_attachment_image_src($mobile_image, $this->config['size']);
  325. $slider_data .= " data-mobile-img='".$fallback_img[0]."'";
  326.  
  327. if($fallback_link){
  328. $slider_data .= " data-fallback-link='".$fallback_link."'";
  329. }
  330. }
  331.  
  332. //if we dont use a fullscreen slider pass the video ratio to the slider
  333. if($this->config['bg_slider'] != "true")
  334. {
  335. global $avia_config;
  336. //if we use the small slideshow only allow the "full" $video_format
  337. if($this->config['handle'] == 'av_slideshow') $video_format = "full";
  338.  
  339.  
  340. //calculate the viewport ratio
  341. if(!empty($avia_config['imgSize'][$this->config['size']]))
  342. {
  343. $viewport = $avia_config['imgSize'][$this->config['size']]['width'] / $avia_config['imgSize'][$this->config['size']]['height'];
  344. }
  345.  
  346.  
  347. //calculate the ratio when passed as a string (eg: 16:9, 4:3). fallback is 16:9
  348. $video_ratio = explode(':',trim($video_ratio));
  349. if(empty($video_ratio[0])) $video_ratio[0] = 16;
  350. if(empty($video_ratio[1])) $video_ratio[1] = 9;
  351. $final_ratio = ((int) $video_ratio[0] / (int) $video_ratio[1]);
  352.  
  353. switch($video_format)
  354. {
  355. case "":
  356. $final_ratio = $viewport;
  357. break;
  358. case "stretch":
  359. $final_ratio = $viewport;
  360. $stretch_height = ceil( $viewport / ($video_ratio[0]/$video_ratio[1]) * 100 );
  361. $stretch_pos = (($stretch_height - 100) / 2) * -1;
  362. $slider_data .= " data-video-height='{$stretch_height}'";
  363. $slider_data .= " data-video-toppos='{$stretch_pos}'";
  364. $extra_class .= " av-video-stretch";
  365. break;
  366. case "full":
  367. // do nothing and apply the entered ratio
  368. break;
  369. }
  370.  
  371. $slider_data .= " data-video-ratio='{$final_ratio}'";
  372. }
  373.  
  374. }
  375. else //img slide
  376. {
  377. $slide = $this->slides[$id];
  378. $linktitle = trim($slide->post_title) ? esc_attr($slide->post_title) : "";
  379. if($linktitle == "-") $linktitle = "";
  380. $linkdescription = (trim($slide->post_content) && empty($link)) ? "title='".esc_attr($slide->post_content)."'" : "";
  381. $linkalt = get_post_meta($slide->ID, '_wp_attachment_image_alt', true);
  382. $linkalt = !empty($linkalt) ? esc_attr($linkalt) : '';
  383. $img = wp_get_attachment_image_src($slide->ID, $this->config['size']);
  384. $video = "";
  385. }
  386.  
  387. if($this->slide_count === 1) $extra_class .= " av-single-slide";
  388.  
  389. $blank = (strpos($link_target, '_blank') !== false || $link_target == 'yes') ? ' target="_blank" ' : "";
  390. $blank .= strpos($link_target, 'nofollow') !== false ? ' rel="nofollow" ' : "";
  391. $tags = (!empty($link) && $link_apply == 'image') ? array("a href='{$link}'{$blank}",'a') : array('div','div');
  392. $caption = "";
  393. $button_html = "";
  394. $counter ++;
  395. $button_count = "";
  396. if(strpos($link_apply, 'button-two') !== false){$button_count = "avia-multi-slideshow-button";}
  397.  
  398.  
  399. //if we got a CTA button apply the link to the button istead of the slide
  400. if(strpos($link_apply, 'button') !== false)
  401. {
  402. $button_html .= $this->slideshow_cta_button($link1, $link_target1, $button_color, $button_label, $button_count);
  403. $tags = array('div','div');
  404. }
  405.  
  406. if(strpos($link_apply, 'button-two') !== false)
  407. {
  408. $button_count .= " avia-slideshow-button-2";
  409. $button_html .= $this->slideshow_cta_button($link2, $link_target2, $button_color2, $button_label2, $button_count);
  410. }
  411.  
  412.  
  413. //custom caption styles
  414.  
  415. $title_styling = !empty($custom_title_size) ? "font-size:{$custom_title_size}px; " : "";
  416. $content_styling = !empty($custom_content_size) ? "font-size:{$custom_content_size}px; " : "";
  417. $content_class = "";
  418.  
  419. if($font_color == "custom")
  420. {
  421. $title_styling .= !empty($custom_title) ? "color:{$custom_title}; " : "";
  422. $content_styling .= !empty($custom_content) ? "color:{$custom_content}; " : "";
  423. }
  424.  
  425. if($title_styling) $title_styling = " style='{$title_styling}'" ;
  426. if($content_styling)
  427. {
  428. $content_styling = " style='{$content_styling}'" ;
  429. $content_class = "av_inherit_color";
  430. }
  431.  
  432.  
  433.  
  434.  
  435. //check if we got a caption
  436. $markup_description = avia_markup_helper(array('context' => 'description','echo'=>false, 'id'=>$attachment_id, 'custom_markup'=>$custom_markup));
  437. $markup_name = avia_markup_helper(array('context' => 'name','echo'=>false, 'id'=>$attachment_id, 'custom_markup'=>$custom_markup));
  438. if(trim($title) != "") $title = "<h2 {$title_styling} class='avia-caption-title {$av_title_font_classes}' $markup_name>".trim(apply_filters('avf_slideshow_title', $title))."</h2>";
  439.  
  440. if(is_array($content)) $content = implode(' ',$content); //temp fix for trim() expects string warning until I can actually reproduce the problem
  441. 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>";
  442.  
  443. if(trim($title.$content.$button_html) != "")
  444. {
  445. if(trim($title) != "" && trim($button_html) != "" && trim($content) == "") $content = "<br/>";
  446.  
  447. if($this->config['handle'] == 'av_slideshow_full' || $this->config['handle'] == 'av_fullscreen')
  448. {
  449. $caption .= '<div class = "caption_fullwidth av-slideshow-caption '.$caption_pos.'">';
  450. $caption .= '<div class = "container caption_container">';
  451. $caption .= '<div class = "slideshow_caption">';
  452. $caption .= '<div class = "slideshow_inner_caption">';
  453. $caption .= '<div class = "slideshow_align_caption">';
  454. $caption .= $title;
  455. $caption .= $content;
  456. $caption .= $button_html;
  457. $caption .= '</div>';
  458. $caption .= '</div>';
  459. $caption .= '</div>';
  460. $caption .= '</div>';
  461. $caption .= '</div>';
  462. }
  463. else
  464. {
  465. $caption = '<div class="avia-caption av-slideshow-caption"><div class="avia-inner-caption">'.$title.$content."</div></div>";
  466. }
  467. }
  468.  
  469. if(!empty($this->config['perma_caption']) && empty($this->config['caption_override']))
  470. {
  471. $this->config['caption_override'] = $caption;
  472. }
  473.  
  474. if(!empty($this->config['caption_override'])) $caption = "";
  475.  
  476.  
  477. if(!empty($img[0]))
  478. {
  479. $slider_data .= $this->config['bg_slider'] == "true" ? "style='background-position:{$position};' data-img-url='".$img[0]."'" : "";
  480.  
  481. if($slider_data )
  482. {
  483. if(empty($this->ie8_fallback))
  484. {
  485. $this->ie8_fallback .= "<!--[if lte IE 8]>";
  486. $this->ie8_fallback .= "<style type='text/css'>";
  487. }
  488. $this->ie8_fallback .= "\n #{$this->config['css_id']} .slide-{$counter}{";
  489. $this->ie8_fallback .= "\n -ms-filter: \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$img[0]}', sizingMethod='scale')\"; ";
  490. $this->ie8_fallback .= "\n filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$img[0]}', sizingMethod='scale'); ";
  491. $this->ie8_fallback .= "\n } \n";
  492. }
  493. }
  494.  
  495.  
  496.  
  497.  
  498. // $img[0] = 'https://kriesi.at/themes/enfold-photography/files/2014/08/darkened_girl.jpg';
  499.  
  500.  
  501. $html .= "<li {$slider_data} class='{$extra_class} slide-{$counter} ' >";
  502. $html .= "<".$tags[0]." data-rel='slideshow-".avia_slideshow::$slider."' class='avia-slide-wrap' {$linkdescription} >{$caption}";
  503. if($this->config['bg_slider'] != "true" && empty($video))
  504. {
  505. $img_style = "";
  506. if(!empty($this->config['min_height']) && $this->config['min_height'] != "0px")
  507. {
  508. $percent = 100 / (100/$img[2] * (int) $this->config['min_height'] );
  509. $this->config['min_width'] = ceil(($img[1] / $percent)) . "px";
  510.  
  511. $img_style .= AviaHelper::style_string($this->config, 'min_height', 'min-height');
  512. $img_style .= AviaHelper::style_string($this->config, 'min_width', 'min-width');
  513. $img_style = AviaHelper::style_string($img_style);
  514. }
  515.  
  516.  
  517. $html .= "<img src='".$img[0]."' width='".$img[1]."' height='".$img[2]."' title='".$linktitle."' alt='".$linkalt."' $markup_url $img_style />";
  518. }
  519. $html .= $video;
  520. $html .= $this->create_overlay($meta);
  521. $html .= "</".$tags[1].">";
  522. $html .= "</li>";
  523.  
  524. if( $counter === 1 )
  525. {
  526. if(!empty($img[1]) && !empty($img[2]))
  527. {
  528. $this->config['default-height'] = (100/$img[1]) * $img[2];
  529. }
  530. }
  531.  
  532. }
  533. else
  534. {
  535. $this->slide_count --;
  536. }
  537. }
  538.  
  539. if(!empty($this->ie8_fallback))
  540. {
  541. $this->ie8_fallback .= "</style> <![endif]-->";
  542. add_action('wp_footer', array($this, 'add_ie8_fallback_to_footer'));
  543. }
  544.  
  545. return $html;
  546. }
  547.  
  548. public function add_ie8_fallback_to_footer()
  549. {
  550. // echo $this->ie8_fallback;
  551. }
  552.  
  553. protected function slideshow_cta_button($link, $link_target, $button_color, $button_label, $button_count)
  554. {
  555. $button_html = "";
  556. $blank = (strpos($link_target, '_blank') !== false || $link_target == 'yes') ? ' target="_blank" ' : "";
  557. $blank .= strpos($link_target, 'nofollow') !== false ? ' rel="nofollow" ' : "";
  558.  
  559. $link = AviaHelper::get_url($link);
  560.  
  561. $button_html .= "<a href='{$link}' {$blank} class='avia-slideshow-button avia-button avia-color-{$button_color} {$button_count}' data-duration='800' data-easing='easeInOutQuad'>";
  562. $button_html .= $button_label;
  563. $button_html .= "</a>";
  564. return $button_html;
  565. }
  566.  
  567.  
  568. protected function slide_navigation_arrows()
  569. {
  570. global $avia_config;
  571.  
  572. $html = "";
  573. $html .= "<div class='avia-slideshow-arrows avia-slideshow-controls'>";
  574. $html .= "<a href='#prev' class='prev-slide' ".av_icon_string('prev_big').">".__('Previous','avia_framework' )."</a>";
  575. $html .= "<a href='#next' class='next-slide' ".av_icon_string('next_big').">".__('Next','avia_framework' )."</a>";
  576. $html .= "</div>";
  577.  
  578. return $html;
  579. }
  580.  
  581. protected function slide_navigation_dots()
  582. {
  583. $html = "";
  584. $html .= "<div class='avia-slideshow-dots avia-slideshow-controls'>";
  585. $active = "active";
  586.  
  587. for($i = 1; $i <= $this->slide_count; $i++)
  588. {
  589. $html .= "<a href='#{$i}' class='goto-slide {$active}' >{$i}</a>";
  590. $active = "";
  591. }
  592.  
  593. $html .= "</div>";
  594.  
  595. return $html;
  596. }
  597.  
  598. protected function extract_subslides($slide_array)
  599. {
  600. $this->config['ids']= array();
  601. $this->subslides = array();
  602.  
  603. foreach($slide_array as $key => $slide)
  604. {
  605. $this->subslides[$key] = $slide;
  606. $this->config['ids'][] = $slide['attr']['id'];
  607.  
  608. if( empty($slide['attr']['id']) && !empty($slide['attr']['video']) && $slide['attr']['slide_type'] === 'video')
  609. {
  610. $this->config['video_counter'] ++ ;
  611. }
  612. }
  613.  
  614. $this->config['ids'] = implode(',',$this->config['ids'] );
  615.  
  616. unset($this->config['content']);
  617. }
  618.  
  619. protected function create_overlay($meta)
  620. {
  621. extract($meta);
  622.  
  623. /*check/create overlay*/
  624. $overlay = "";
  625. if(!empty($overlay_enable))
  626. {
  627. $overlay_src = "";
  628. $overlay = "opacity: {$overlay_opacity}; ";
  629. if(!empty($overlay_color)) $overlay .= "background-color: {$overlay_color}; ";
  630. if(!empty($overlay_pattern))
  631. {
  632. if($overlay_pattern == "custom")
  633. {
  634. $overlay_src = $overlay_custom_pattern;
  635. }
  636. else
  637. {
  638. $overlay_src = str_replace('{{AVIA_BASE_URL}}', AVIA_BASE_URL, $overlay_pattern);
  639. }
  640. }
  641.  
  642. if(!empty($overlay_src)) $overlay .= "background-image: url({$overlay_src}); background-repeat: repeat;";
  643. $overlay = "<div class='av-section-color-overlay' style='{$overlay}'></div>";
  644. }
  645.  
  646. return $overlay;
  647. }
  648.  
  649.  
  650.  
  651.  
  652. }
  653. }
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660. if ( !class_exists( 'avia_slideshow_video_helper' ) )
  661. {
  662. class avia_slideshow_video_helper
  663. {
  664. static function set_video_slide($video_url, $service = false, $meta = false)
  665. {
  666. $video = "";
  667. if(empty($service)) $service = self::which_video_service($video_url);
  668.  
  669. $uid = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
  670. $controls = empty($meta['video_controls']) ? 1 : 0;
  671. $atts = array();
  672. $atts['loop'] = empty($meta['video_loop']) ? 0 : 1;
  673. $atts['autoplay'] = empty($meta['video_autoplay']) ? 1 : 0;
  674.  
  675. echo '<pre>' . var_export($meta['video_autoplay'], true) . '</pre>';
  676.  
  677. switch( $service )
  678. {
  679. case "html5": $video = "<div class='av-click-overlay'></div>".avia_html5_video_embed($video_url, $image = "", $types = array('webm' => 'type="video/webm"', 'mp4' => 'type="video/mp4"', 'ogv' => 'type="video/ogg"'), $atts); break;
  680. case "iframe":$video = $video_url; break;
  681. case "youtube":
  682.  
  683. $explode_at = strpos($video_url, 'youtu.be/') !== false ? "/" : "v=";
  684. $video_url = explode($explode_at, trim($video_url));
  685. $video_url = end($video_url);
  686. $video_id = $video_url;
  687.  
  688. //if parameters are appended make sure to create the correct video id
  689. if (strpos($video_url,'?') !== false || strpos($video_url,'?') !== false)
  690. {
  691. preg_match('!(.+)[&?]!',$video_url, $video_id);
  692. $video_id = isset($video_id[1]) ? $video_id[1] : $video_id[0];
  693. }
  694.  
  695. $video_data = apply_filters( 'avf_youtube_video_data', array(
  696. 'autoplay' => 0,
  697. 'videoid' => $video_id,
  698. 'hd' => 1,
  699. 'rel' => 0,
  700. 'wmode' => 'opaque',
  701. 'playlist' => $uid,
  702. 'loop' => 0,
  703. 'version' => 3,
  704. 'autohide' => 1,
  705. 'color' => 'white',
  706. 'controls' => $controls,
  707. 'showinfo' => 0,
  708. 'iv_load_policy'=> 3
  709. ));
  710.  
  711. $data = AviaHelper::create_data_string($video_data);
  712.  
  713. $video = "<div class='av-click-overlay'></div><div class='mejs-mediaelement'><div height='1600' width='900' class='av_youtube_frame' id='{$uid}' {$data}></div></div>";
  714.  
  715. break;
  716. case "vimeo":
  717.  
  718. $color = ltrim( avia_get_option('colorset-main_color-primary'), '#');
  719. $autopause = empty($meta['video_section_bg']) ? 1 : 0; //pause if another vimeo video plays?
  720. $video_url = explode('/', trim($video_url));
  721. $video_url = end($video_url);
  722. $video_url = esc_url(add_query_arg(
  723. array(
  724. 'portrait' => 0,
  725. 'byline' => 0,
  726. 'title' => 0,
  727. 'badge' => 0,
  728. 'loop' => $attributes['loop'],
  729. 'autopause' => $autopause,
  730. 'api' => 1,
  731. 'rel' => 0,
  732. 'player_id' => $uid,
  733. 'color' => $color
  734. ),
  735. '//player.vimeo.com/video/'.$video_url
  736. ));
  737.  
  738. $video_url = apply_filters( 'avf_vimeo_video_url' , $video_url);
  739. $video = "<div class='av-click-overlay'></div><div class='mejs-mediaelement'><iframe src='{$video_url}' height='1600' width='900' frameborder='' class='av_vimeo_frame' id='{$uid}'></iframe></div>";
  740.  
  741. break;
  742. }
  743.  
  744.  
  745.  
  746. return $video;
  747.  
  748. }
  749.  
  750. //get the video service based on the url string fo the video
  751. static function which_video_service($video_url)
  752. {
  753. $service = "";
  754.  
  755. if(avia_backend_is_file($video_url, 'html5video'))
  756. {
  757. $service = "html5";
  758. }
  759. else if(strpos($video_url,'<iframe') !== false)
  760. {
  761. $service = "iframe";
  762. }
  763. else
  764. {
  765. if(strpos($video_url, 'youtube.com/watch') !== false || strpos($video_url, 'youtu.be/') !== false)
  766. {
  767. $service = "youtube";
  768. }
  769. else if(strpos($video_url, 'vimeo.com') !== false)
  770. {
  771. $service = "vimeo";
  772. }
  773. }
  774.  
  775. return $service;
  776. }
  777. }
  778. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement