function oembed_validate_response in oEmbed 8
Same name and namespace in other branches
- 7 oembed.module \oembed_validate_response()
- 7.0 oembed.module \oembed_validate_response()
Validates oEmbed responses.
4 calls to oembed_validate_response()
- OembedEndpointTestCase::testOembedEndpoint in modules/
oembedprovider/ oembedprovider.test - OembedProviderTestCase::testOembedProviders in modules/
oembedprovider/ oembedprovider.test - oembed_field_attach_validate in ./
oembed.filter.inc - Implements hook_field_attach_validate().
- oembed_file_validator_type in ./
oembed.module - Checks that the oEmbed response has required standard properties for its type.
File
- ./
oembed.module, line 448 - Core functionality for oEmbed
Code
function oembed_validate_response($embed) {
$errors = array();
if (!$embed) {
$errors[] = t('Unable to fetch oEmbed data or it is not a valid URL.');
}
else {
if (empty($embed['version']) || empty($embed['type']) || intval($embed['version']) != 1) {
$errors[] = t('oEmbed data for is invalid.');
}
}
// Validate that response has required properties for its type.
$message = t('oEmbed response is missing required properties for @type.', array(
'@type' => $embed['type'],
));
// Video, rich and photo all must have width and height.
// This validation causes lots of legitimate responses to be rejected. To retain access
// to Twitter, Scribd and others, we allow responses that do not have height and width.
if (in_array($embed['type'], array(
'video',
'rich',
'photo',
))) {
if (!isset($embed['width']) || empty($embed['width']) || (!isset($embed['height']) || empty($embed['height']))) {
//$errors[] = $message;
}
}
// Video and rich type must have html content.
if (in_array($embed['type'], array(
'video',
'rich',
))) {
if (!isset($embed['html']) || empty($embed['html'])) {
$errors[] = $message;
}
}
// Image type must have a URL.
if ($embed['type'] == 'photo') {
if (!isset($embed['url']) || empty($embed['url'])) {
$errors[] = $message;
}
}
return $errors;
}