jkcoding jkcoding - 1 year ago 71
PHP Question

oEmbed Featured Image (Large Thumbnail)

I found a plugin called oEmbed Featured Image that does absolutely everything I want except output the largest size.

The plugin's default YouTube output size is 480x360. I need to be able to use the full resolution size for at least YouTube/Vimeo.

I figured I can edit the function starting on line 68 in the plugin.

Here is what I've come up with:

public function oembed_dataparse( $return, $data, $url )

if ($yt = $data->provider_name == 'YouTube')
if(preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $data->thumbnail_url, $youtube_id))
$ytvideo_id = $youtube_id;
$max = get_headers($data->thumbnail_url);

if (substr($max[0], 9, 3) !== '404')
$data->thumbnail_url = 'http://img.youtube.com/vi/$ytvideo_id/maxresdefault.jpg';

if ($vm = $data->provider_name == 'Vimeo')
if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/", $data->thumbnail_url, $vimeo_id))
$vmvideo_id = $vimeo_id[3];
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vmvideo_id.php"));
$data->thumbnail_url = $hash[0]['thumbnail_large'];

if ( ! empty( $data->thumbnail_url ) && ! $this->_thumb_id ) {
//if ( in_array( @ $data->type, array( 'video' ) ) ) // Only set for video embeds
$this->set_thumb_by_url( $data->thumbnail_url, @ $data->title );

Answer Source

What you need to do is actually modify you youtube if statement to make it look at $url, not $data->thumbnail_url. That will cause your preg_match() to match correctly, and it will return the correct $yt_videoid for you to use.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download