wordpress

show youtube vedio by width,heigh

/********************************************************************
show any video (control width/height)
********************************************************************/
define(“YOUTUBE_WIDTH”, 310); // default width
define(“YOUTUBE_HEIGHT”, 250); // default height
define(“YOUTUBE_REGEXP”, “/\]+)\]/”);
define(“YOUTUBE_TARGET”, “<object width=\”###WIDTH###\” height=\”###HEIGHT###\”><param name=\”movie\” value=\”http://www.youtube.com/v/###URL###?fs=1&amp;hl=en_US\”></param><param name=\”allowFullScreen\” value=\”true\”></param><param name=\”allowscriptaccess\” value=\”always\”></param><embed src=\”http://www.youtube.com/v/###URL###?fs=1&amp;hl=en_US\” type=\”application/x-shockwave-flash\” allowscriptaccess=\”always\” allowfullscreen=\”true\” width=\”###WIDTH###\” height=\”###HEIGHT###\”></embed></object>”);

function youtube_plugin_callback($match)
{     //    print $match;
$tag_parts = explode(” “, rtrim($match[0], “]”));
$output = YOUTUBE_TARGET;

$output = str_replace(“###URL###”, $tag_parts[1], $output);
if (count($tag_parts) > 2) {
if ($tag_parts[2] == 0) {
$output = str_replace(“###WIDTH###”, YOUTUBE_WIDTH, $output);
} else {
$output = str_replace(“###WIDTH###”, $tag_parts[2], $output);
}
if ($tag_parts[3] == 0) {
$output = str_replace(“###HEIGHT###”, YOUTUBE_HEIGHT, $output);
} else {
$output = str_replace(“###HEIGHT###”, $tag_parts[3], $output);
}
} else {
$output = str_replace(“###WIDTH###”, YOUTUBE_WIDTH, $output);
$output = str_replace(“###HEIGHT###”, YOUTUBE_HEIGHT, $output);
}
return ($output);
}

function youtube_plugin($content)
{
return (preg_replace_callback(YOUTUBE_REGEXP, ‘youtube_plugin_callback’, $content));
}

function show_video() {
global $sources;
query_posts( ‘cat=37&posts_per_page=1&orderby=date&order=Desc’ );
if( have_posts() ) {
while( have_posts() ) {
the_post();
print the_title();
//get_the_content();
$filtered_content = str_replace(‘<p>’,”,get_the_content());
$filtered_content = str_replace(‘</p>’,”,$filtered_content);
//print $filtered_content;
print youtube_plugin($filtered_content);
}}wp_reset_query();
}

Advertisements