Advertisement
Guest User

sasa

a guest
Jan 27th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. function get_youtube_kod($post_id=null) {
  2.     // Get the post ID if none is provided
  3.     if($post_id==null OR $post_id=='') $post_id = get_the_ID();
  4.    
  5.         // Gets the post's content
  6.         $post_array = get_post($post_id);
  7.         $markup = $post_array->post_content;
  8.    
  9.         // Checks for a standard YouTube embed
  10.         preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
  11.    
  12.         // Checks for any YouTube URL
  13.         if(!isset($matches[1])) {
  14.             preg_match('#http://w?w?w?.?youtube.com/watch\?v=([A-Za-z0-9\-_]+)#s', $markup, $matches);
  15.         }
  16.        
  17.         // If no standard YouTube embed is found, checks for one embedded with JR_embed
  18.         if(!isset($matches[1])) {
  19.             preg_match('#\[yt url=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
  20.         }
  21.        
  22.         if(!isset($matches[1])) {
  23.                 preg_match('#\[yt url=([A-Za-z0-9\-_]+)[^>]*]#s', $markup, $matches);
  24.         }
  25.        
  26.         // If we've found a YouTube video ID, create the thumbnail URL
  27.         if(isset($matches[1])) {
  28.             $youtube_kod = $matches[1];
  29.  
  30.         }
  31.  
  32. };
  33.  
  34. function youtube_kodic ($post_id=null) {
  35.      echo $youtube_kod;
  36. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement