You are here

public function MediaInternetFileHandler::claim in D7 Media 7

Same name and namespace in other branches
  1. 7.4 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::claim()
  2. 7.2 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::claim()
  3. 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 44
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), media_variable_get('fromurl_supported_schemes'))) {
    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(media_variable_get('file_extensions'))) . ')$/i';
  if (!preg_match($regex, basename($embedCode))) {
    return FALSE;
  }
  return TRUE;
}