/* Place these these into your functions.php file
Retrive Video Thumbnails */
function video_image($url){
$domain = parse_url($url);
// Test if the link is for youtube
if($domain['host'] == 'www.youtube.com' || $domain['host'] == 'youtube.com'){
$array = explode("&", $domain['query']);
return "http://img.youtube.com/vi/".substr($array[0], 2)."/0.jpg"; // Returns the largest Thumbnail
// Test if the link is for the shortened youtube share link
} else if($domain['host'] == 'www.youtu.be' || $domain['host'] == 'youtu.be'){
$array = ltrim($domain['path'],'/');
return "http://img.youtube.com/vi/". $array ."/0.jpg"; // Returns the largest Thumbnail
// Test if the link is for vimeo
} else if($domain['host'] == 'www.vimeo.com' || $domain['host'] == 'vimeo.com'){
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/".substr($domain['path'], 1).".php"));
return $hash[0]["thumbnail_medium"]; // Returns the medium Thumbnail
}
}
/* Retrieve Video Embed Code */
/* Instead of returning the full embed code, you could just return the video ID and place that in the necessary location. Useful if you need to have your embeds vary in size across your site */
function video_embed($url){
$domain = parse_url($url);
// Test if the link is for youtube
if($domain['host'] == 'www.youtube.com' || $domain['host'] == 'youtube.com'){
$array = explode("&", $domain['query']);
return '<iframe src="http://www.youtube.com/embed/' . substr($array[0], 2) . '?wmode=transparent" width="100%" height="100%" frameborder="0" allowfullscreen></iframe>'; // Returns the youtube iframe embed code
// Test if the link is for the shortened youtube share link
} else if($domain['host'] == 'www.youtu.be' || $domain['host'] == 'youtu.be'){
$array = ltrim($domain['path'],'/');
return '<iframe src="http://www.youtube.com/embed/' . $array . '?wmode=transparent" width="100%" height="100%" frameborder="0" allowfullscreen></iframe>'; // Returns the youtube iframe embed code
// Test if the link is for vimeo
} else if($domain['host'] == 'www.vimeo.com' || $domain['host'] == 'vimeo.com'){
$hash = substr($domain['path'], 1);
return '<iframe src="http://player.vimeo.com/video/' . $hash . '?title=0&byline=0&portrait=0" width="100%" height="100%" frameborder="0" webkitAllowFullScreen allowfullscreen></iframe>'; // Returns the vimeo iframe embed code
}
}
And Usage:
echo video_embed($data['url from the database']);
echo video_image($data['url from the database']);
add_to_head('<script src="http://jwpsrv.com/library/7zlM1FqoEeOclyIACqoGtw.js"></script>');
add_to_head('<script src="https://ssl.jwpsrv.com/library/7zlM1FqoEeOclyIACqoGtw.js"></script>');
add_to_head('<script src="https://jwpsrv.com/library/7zlM1FqoEeOclyIACqoGtw.js"></script>');
Category Forum
Official releases [Infusions]Labels
None yet
Statistics
0 participants
Notifications
You are not receiving notifications from this thread.
Related Questions