Last active
August 29, 2015 14:22
-
-
Save mgsolipa/cbb3ad0ffa5e84553a5c to your computer and use it in GitHub Desktop.
Get the thumbnail of a given video from Youtube or Vimeo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... add this to your _skin.class.php ... | |
/** | |
* The following methods have been added in order to get the thumbnail of a given video | |
* | |
* In order to make this work, you should do the following: | |
* | |
* 1. Add these functions to the _skin.class.php file of your skin | |
* 2. Create a text custom field called "video_thumb" | |
* 3. Add a section of code in the posts.main.php file, just above the ITEM BLOCK section | |
* Warning: this method may vary depending on what version of b2evolution are you currently running | |
* | |
* $excerpt_before_text = '<div class="excerpt">'; | |
* | |
* if( $Item->video_thumb = $Item->get_custom_field_value( 'video_thumb' ) ) | |
* { | |
* if($thumb_url = $Skin->decode_tag($Item->video_thumb)) | |
* { | |
* $excerpt_before_text .= '<img src="'.$thumb_url.'" style="float: left;">'; | |
* } | |
* } | |
* | |
* // ---------------------- ITEM BLOCK INCLUDED HERE ------------------------ | |
* skin_include( '_item_block.inc.php', array( | |
* 'content_mode' => 'auto', // 'auto' will auto select depending on $disp-detail | |
* 'image_size' => 'fit-400x320', | |
* 'excerpt_before_text' => $excerpt_before_text, | |
* ) ); | |
* | |
*/ | |
static public function youtube_apicall( $video_id ) | |
{ | |
$data = new stdClass; | |
$data->thumb_url = "http://img.youtube.com/vi/" . $video_id . "/0.jpg"; | |
return $data; | |
} | |
static public function vimeo_apicall( $video_id ) | |
{ | |
$hash = unserialize(file_get_contents('http://vimeo.com/api/v2/video/'.$video_id.".php")); | |
$data = new stdClass; | |
$data->thumb_url = $hash[0]['thumbnail_medium']; | |
return $data; | |
} | |
function decode_tag( $tag ) | |
{ | |
$providers = array('youtube', 'vimeo'); | |
preg_match('#\[video:('.implode('|', $providers).'):(.+?)]#', $tag, $matches); | |
if( $data = call_user_func('self::'.$matches[1].'_apicall', $matches[2]) ) | |
{ | |
return $data->thumb_url; | |
} | |
else | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment