Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Get Embed Code

By: a guest on Sep 22nd, 2010  |  syntax: PHP  |  size: 1.90 KB  |  views: 62  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Get Embed - gets embed Code from custom field - Use: lom_get_embed
  2. /*
  3. Parameters:
  4.         $key = Custom field key eg. "embed"
  5.         $width = Set width manually without using $type
  6.         $height = Set height manually without using $type
  7. */
  8. function lom_get_embed($key = 'embed', $width, $height, $class = 'video', $id = null) {
  9.   if(empty($id))
  10.     {
  11.     global $post;
  12.     $id = $post->ID;
  13.     }    
  14. $custom_field = get_post_meta($id, $key, true);
  15. if ($custom_field) :
  16.     $org_width = $width;
  17.     $org_height = $height;
  18.     // Get custom width and height
  19.     $custom_width = get_post_meta($id, 'width', true);
  20.     $custom_height = get_post_meta($id, 'height', true);    
  21.     // Set values: width="XXX", height="XXX"
  22.     if ( !$custom_width ) $width = 'width="'.$width.'"'; else $width = 'width="'.$custom_width.'"';
  23.     if ( !$custom_height ) $height = 'height="'.$height.'"'; else $height = 'height="'.$custom_height.'"';
  24.     $custom_field = stripslashes($custom_field);
  25.     $custom_field = preg_replace( '/width="([0-9]*)"/' , $width , $custom_field );
  26.     $custom_field = preg_replace( '/height="([0-9]*)"/' , $height , $custom_field );    
  27.     // Set values: width:XXXpx, height:XXXpx
  28.     if ( !$custom_width ) $width = 'width:'.$org_width.'px'; else $width = 'width:'.$custom_width.'px';
  29.     if ( !$custom_height ) $height = 'height:'.$org_height.'px'; else $height = 'height:'.$custom_height.'px';
  30.     $custom_field = stripslashes($custom_field);
  31.     $custom_field = preg_replace( '/width:([0-9]*)px/' , $width , $custom_field );
  32.     $custom_field = preg_replace( '/height:([0-9]*)px/' , $height , $custom_field );    
  33.         // Suckerfish menu hack
  34.         $custom_field = str_replace('<embed ','<param name="wmode" value="transparent"></param><embed wmode="transparent" ',$custom_field);
  35.         $output = '';
  36.     $output .= '<div class="'. $class .'">' . $custom_field . '</div>';
  37.     return $output;
  38. endif;
  39. }