function video_embed_field_handle_youtube in Video Embed Field 7.2
Same name and namespace in other branches
- 7 video_embed_field.module \video_embed_field_handle_youtube()
Handler for Youtube videos.
Parameters
string $url: The video URL.
array $settings: The settings array.
Return value
array The video iframe render array.
1 string reference to 'video_embed_field_handle_youtube'
File
- ./
video_embed_field.handlers.inc, line 166 - Provide some handlers for video embed field Other modules can implement the hook_video_embed_handler_info to provide more handlers.
Code
function video_embed_field_handle_youtube($url, $settings) {
$output = array();
if (preg_match('/#t=((?P<min>\\d+)m)?((?P<sec>\\d+)s)?((?P<tinsec>\\d+))?/', $url, $matches)) {
if (isset($matches['tinsec'])) {
$settings['start'] = $matches['tinsec'];
// url already in form #t=125 for 2 minutes and 5 seconds
}
else {
// url in form #t=2m5s or with other useless data, this is why we still keep adding the default data..
// give it some default data in case there is no #t=...
$matches += array(
"min" => 0,
"sec" => 0,
);
if ($time = $matches["min"] * 60 + $matches["sec"]) {
$settings['start'] = $time;
}
}
}
$id = _video_embed_field_get_youtube_id($url);
if (!$id) {
// We can't decode the URL - just return the URL as a link.
$output['#markup'] = l($url, $url);
return $output;
}
// Add class to variable to avoid adding it to URL param string.
$class = $settings['class'];
unset($settings['class']);
// Construct the embed code.
$settings['wmode'] = 'opaque';
$settings_str = urlencode(_video_embed_code_get_settings_str($settings));
$output['#markup'] = '<iframe class="' . check_plain($class) . '" width="' . check_plain($settings['width']) . '" height="' . check_plain($settings['height']) . '" src="//www.youtube.com/embed/' . $id . '?' . $settings_str . '" frameborder="0" allowfullscreen></iframe>';
return $output;
}