You are here

function oembed_url_to_file in oEmbed 7

Same name and namespace in other branches
  1. 8 oembed.module \oembed_url_to_file()
  2. 7.0 oembed.module \oembed_url_to_file()

Return a file entity for a URL. Create the file if necessary.

Parameters

string $url: URL of oEmbed request.

boolean $create: Flag to create the file entity if it does not already exist.

Return value

\stdClass

4 calls to oembed_url_to_file()
hook_oembed_resolve_link in ./oembed.api.php
oEmbed filter replacement callback.
MediaInternetOEmbedHandler::getFileObject in ./MediaInternetOEmbedHandler.inc
Returns a file object which can be used for validation
OembedFileEntityTestCase::testOembedFileFormatters in ./oembed.test
Tests the oembed render element types.
OembedFileEntityTestCase::testOembedImageFileFormatters in ./oembed.test
Tests the oembed render element types.

File

./oembed.module, line 910
Core functionality for oEmbed

Code

function oembed_url_to_file($url, $create = FALSE) {
  $uri = 'oembed://' . drupal_encode_path($url);
  $file = file_uri_to_object($uri);
  $file->metadata = array();
  if (!isset($file->metadata['oembed'])) {
    $file->metadata['oembed'] = oembed_get_data($url);
  }

  // New URLs need to be validated before being saved.
  if ($create && !isset($file->fid)) {

    // Save the new file.
    file_save($file);
  }
  return $file;
}