function video_youtube_v_validate in Video 6.2
Same name and namespace in other branches
- 5 types/video_youtube/video_youtube.module \video_youtube_v_validate()
- 6 types/video_youtube/video_youtube.module \video_youtube_v_validate()
implementation of hook_v_validate
File
- types/
video_youtube/ video_youtube.module, line 144 - Enable Youtube support for video module.
Code
function video_youtube_v_validate($node) {
if (!preg_match("/^http:\\/\\/([a-z]{2,3}\\.)?youtube\\.com\\/watch\\?v=/", $node->vidfile)) {
form_set_error('vidfile', t('The Youtube Video URL field must be similar to <em>http://youtube.com/watch?v=IICWFx7sKmw</em>, <em>http://www.youtube.com/watch?v=IICWFx7sKmw</em> or <em>http://it.youtube.com/watch?v=IICWFx7sKmw</em>'));
}
else {
if (variable_get('video_youtube_validation', false)) {
// we have a good URL. Let's check that the video is available on Youtube and that it is embeddable.
// the approach used here is to return errors only if Youtube explicitely says "an error has occurred"
$id = _video_youtube_get_id($node->vidfile);
//test
//$video_entry = _video_apiclient_youtube_video_entry($id);
// jlampton changed the youtube validation url
//$response = _video_apiclient_youtube_request('gdata.youtube.com/feeds/api/videos', array('video_id' => $id));
// if(isset($response['ERROR'])) {
// form_set_error('vidfile', t('The Youtube Video URL validation has failed for some reason. Please check the URL and try again.<br />If the error persists please contact %site_name administrators.', array('%site_name' => variable_get('site_name', 'Drupal'))));
// if(isset($response['ERROR']['DESCRIPTION'][0])) {
// drupal_set_message(t('The Youtube validation service reported the following error: %error', array('%error'=>$response['ERROR']['DESCRIPTION'][0])), 'error');
// }
// }
// else if(isset($response['VIDEO_DETAILS']['EMBED_STATUS'][0])
// && $response['VIDEO_DETAILS']['EMBED_STATUS'][0] != 'ok') {
// // embedding has been disabled. we let the video pass but we warn the user
// drupal_set_message(t('The video authors have disabled embedding on Youtube. This means that this video will only be playable directly on Youtube.'));
// }
// else { // if youtube did not explicetely said "an error has occurred" we accept the video
// ;
// }
}
}
}