Guest User

avia_slideshow_video_helper

a guest
Apr 26th, 2018
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.65 KB | None | 0 0
  1. if ( !class_exists( 'avia_slideshow_video_helper' ) )
  2. {
  3.     class avia_slideshow_video_helper
  4.     {
  5.         static function set_video_slide($video_url, $service = false, $meta = false)
  6.         {
  7.             $video = "";
  8.             if(empty($service)) $service = self::which_video_service($video_url);
  9.            
  10.             $uid        = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
  11.             $controls   = empty($meta['video_controls']) ? 1 : 0;
  12.             $loop       = empty($meta['video_loop']) ? 0 : 1;
  13.             $autoplay   = empty($meta['video_autoplay']) ? true : false;
  14.            
  15.             switch( $service )
  16.             {
  17.                 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"'), $autoplay); break;
  18.                 case "iframe":$video = $video_url; break;
  19.                 case "youtube":
  20.                    
  21.                     $explode_at = strpos($video_url, 'youtu.be/') !== false ? "/" : "v=";
  22.                     $video_url  = explode($explode_at, trim($video_url));
  23.                     $video_url  = end($video_url);
  24.                     $video_id   = $video_url;
  25.                    
  26.                     //if parameters are appended make sure to create the correct video id
  27.                     if (strpos($video_url,'?') !== false || strpos($video_url,'?') !== false)
  28.                     {
  29.                         preg_match('!(.+)[&?]!',$video_url, $video_id);
  30.                         $video_id = isset($video_id[1]) ? $video_id[1] : $video_id[0];
  31.                     }
  32.                    
  33.                     $video_data = apply_filters( 'avf_youtube_video_data', array(
  34.                             'autoplay'      => 0,
  35.                             'videoid'       => $video_id,
  36.                             'hd'            => 1,
  37.                             'rel'           => 0,
  38.                             'wmode'         => 'opaque',
  39.                             'playlist'      => $uid,
  40.                             'loop'          => 0,
  41.                             'version'       => 3,
  42.                             'autohide'      => 1,
  43.                             'color'         => 'white',
  44.                             'controls'      => $controls,
  45.                             'showinfo'      => 0,
  46.                             'iv_load_policy'=> 3
  47.                         ));
  48.                        
  49.                     $data = AviaHelper::create_data_string($video_data);
  50.                
  51.                     $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>";
  52.                    
  53.                 break;
  54.                 case "vimeo":
  55.            
  56.                     $color      = ltrim( avia_get_option('colorset-main_color-primary'), '#');             
  57.                     $autopause  = empty($meta['video_section_bg']) ? 1 : 0; //pause if another vimeo video plays?
  58.                     $video_url  = explode('/', trim($video_url));
  59.                     $video_url  = end($video_url);
  60.                     $video_url  = esc_url(add_query_arg(
  61.                         array(
  62.                             'portrait'  => 0,
  63.                             'byline'    => 0,
  64.                             'title'     => 0,
  65.                             'badge'     => 0,
  66.                             'loop'      => $loop,
  67.                             'autopause' => $autopause,
  68.                             'api'       => 1,
  69.                             'rel'       => 0,
  70.                             'player_id' => $uid,
  71.                             'color'     => $color
  72.                         ),
  73.                     '//player.vimeo.com/video/'.$video_url
  74.                     ));
  75.                    
  76.                     $video_url = apply_filters( 'avf_vimeo_video_url' , $video_url);
  77.                     $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>";
  78.                    
  79.                 break;
  80.             }
  81.            
  82.            
  83.            
  84.             return $video;
  85.            
  86.         }
  87.        
  88.         //get the video service based on the url string fo the video
  89.         static function which_video_service($video_url)
  90.         {
  91.             $service = "";
  92.            
  93.             if(avia_backend_is_file($video_url, 'html5video'))
  94.             {
  95.                 $service = "html5";
  96.             }
  97.             else if(strpos($video_url,'<iframe') !== false)
  98.             {
  99.                 $service = "iframe";
  100.             }
  101.             else
  102.             {
  103.                 if(strpos($video_url, 'youtube.com/watch') !== false || strpos($video_url, 'youtu.be/') !== false)
  104.                 {
  105.                     $service = "youtube";
  106.                 }
  107.                 else if(strpos($video_url, 'vimeo.com') !== false)
  108.                 {
  109.                     $service = "vimeo";
  110.                 }
  111.             }
  112.            
  113.             return $service;
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment