public function MediaInternetFileHandler::claim in D7 Media 7.2
Same name and namespace in other branches
- 7.4 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::claim()
- 7 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::claim()
- 7.3 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::claim()
Determines if this handler should claim the item.
Parameters
string $embed_code: A string of user-submitted embed code.
Return value
boolean Pass TRUE to claim the item.
Overrides MediaInternetBaseHandler::claim
File
- modules/
media_internet/ includes/ MediaInternetFileHandler.inc, line 46 - Definition of MediaInternetFileHandler.
Class
- MediaInternetFileHandler
- A class for managing the addition of Internet files.
Code
public function claim($embedCode) {
// Claim only valid URLs using a supported scheme.
if (!valid_url($embedCode, TRUE) || !in_array(file_uri_scheme($embedCode), variable_get('media_fromurl_supported_schemes', array(
'http',
'https',
'ftp',
'smb',
'ftps',
)))) {
return FALSE;
}
// This handler is intended for regular files, so don't claim URLs
// containing query strings or fragments.
if (preg_match('/[\\?\\#]/', $embedCode)) {
return FALSE;
}
// Since this handler copies the remote file to the local web server, do not
// claim a URL with an extension disallowed for media uploads.
$regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote(variable_get('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm'))) . ')$/i';
if (!preg_match($regex, basename($embedCode))) {
return FALSE;
}
return TRUE;
}