Advertisement
manchumahara

allinonevideoembed

Aug 19th, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.76 KB | None | 0 0
  1. //function to parse a video url
  2.  
  3. function eyeconnect_getvideoinfo($vid_link)
  4. {
  5.   // youtube get video id
  6.   if (strpos($vid_link, 'youtube'))
  7.   {
  8.     // regular links
  9.     if (preg_match('/(?<=v\=)([\w\d-_]+)/', $vid_link, $matches))
  10.       return array('host_name' => 'youtube', 'original_key' => $matches[0],'vid_link' => $vid_link);
  11.     // ajax hash tag links
  12.     else if (preg_match('#([\d\w-_]+)$#i', $vid_link, $matches))
  13.       return array('host_name' => 'youtube', 'original_key' => $matches[0],'vid_link' => $vid_link);
  14.     else
  15.       return FALSE;
  16.   }
  17.   // vimeo get video id
  18.   elseif (strpos($vid_link, 'vimeo'))
  19.   {
  20.     if (preg_match('#(?<=/)([\d]+)#', $vid_link, $matches))
  21.       return array('host_name' => 'vimeo', 'original_key' => $matches[0],'vid_link' => $vid_link);
  22.     else
  23.       return FALSE;
  24.   }
  25.   // dailymotion.com get video id
  26.   elseif (strpos($vid_link, 'dailymotion'))
  27.   {
  28.     /*
  29.     if (preg_match('#(?<=/)([\d]+)#', $vid_link, $matches))
  30.       return array('host_name' => 'dailymotion', 'original_key' => $matches[0]);
  31.     else
  32.       return FALSE;
  33.     */
  34.     $id = strtok(basename($vid_link), '_');
  35.     if($id != '')
  36.         return array('host_name' => 'dailymotion', 'original_key' => $id, 'vid_link' => $vid_link);
  37.     else
  38.       return FALSE;
  39.   }
  40.   else
  41.     return FALSE;
  42. }
  43.  
  44.  
  45. //using the function
  46.  
  47. if($videourl != ''){
  48.                     $videoinfo = eyeconnect_getvideoinfo($videourl);
  49.                     //var_dump($videoinfo);
  50.                     if(is_array($videoinfo)){ //if valid video links
  51.                         $hostname = $videoinfo['host_name'];
  52.                         $videoid  = $videoinfo['original_key'];
  53.                         if($hostname == 'youtube'){
  54.                             //$string = 'http://www.youtube.com/watch?v=A7izsd5IXq8&playnext=1&list=PL6753173C0F0BE9ED';
  55.                             $url = parse_url($videourl);
  56.                             parse_str($url['query'],$q);
  57.                             $list = $q['list'];
  58.                             //var_dump($list);
  59.                             if($list != ''){
  60.                                 $list = substr($list, 2);
  61.                                 //echo '<iframe src="http://www.youtube.com/embed/p/ID" width="100%" height="500" frameborder="0"></iframe>';
  62.                                 echo '<iframe width="520" height="320" src="http://www.youtube.com/p/'.$list.'?fs=1&version=3&autoplay=1" frameborder="0" allowfullscreen></iframe>';
  63.                             }
  64.                             else{
  65.                                 echo '<iframe width="520" height="320" src="http://www.youtube.com/v/'.$videoid.'&autoplay=1" frameborder="0" allowfullscreen></iframe>';
  66.                             }
  67.                            
  68.                         }
  69.                         else if($hostname == 'vimeo')
  70.                         {
  71.                             //echo '<iframe src="http://player.vimeo.com/video/'.$videoid.'?title=0&amp;byline=0&amp;portrait=0" width="520" height="320" frameborder="0"></iframe>';
  72.                             echo '<object width="520" height="320"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='.$videoid.'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='.$videoid.'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="520" height="320"></embed></object>';
  73.                         }
  74.                         else if($hostname == 'dailymotion')
  75.                         {
  76.                             $custom = get_post_custom($id);
  77.                             $videourl2 = $custom["videourl2"][0];
  78.                             if($videourl2 != ''){
  79.                                 $videourl2 = basename($videourl2);
  80.                                 echo '<iframe marginwidth="0" marginheight="0" width="520" height="500" frameborder="0" scrolling="no" src="http://www.dailymotion.com/videozap/playlist/'.$videourl2.'?position=bottom&auto=1"></iframe>';
  81.                             }
  82.                             else{
  83.                                 echo '<iframe frameborder="0" width="520" height="320" src="http://www.dailymotion.com/embed/video/'.$videoid.'?width=328"></iframe>';
  84.                             }
  85.                         }                                                
  86.                     }                    
  87.                 }//end if video url found in meta box
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement