You are here

function emfield_request_header in Embedded Media Field 6.2

Same name and namespace in other branches
  1. 5 emfield.module \emfield_request_header()
  2. 6.3 deprecated/emfield-deprecated.inc \emfield_request_header()
  3. 6 emfield.module \emfield_request_header()

Get the HTTP Header of media, for mime-type and length.

Parameters

$provider: The string of the third party provider, such as 'youtube' or 'flickr'. @param $url The url for the media. @param $cached (Optional) If TRUE, the result of this xml request will be cached. good to play nice with the third party folks so they don't stop providing service to your site... @return The header results, returned as an array.

File

./emfield.module, line 488
Embedded Media Field is a CCK-based framework for 3rd party media files.

Code

function emfield_request_header($provider, $url, $cached = TRUE, $return_errors = TRUE) {

  // if it's cacheable, try to load a cached value
  if ($cached && ($cache = cache_get('emfield:request-header:' . $url, 'cache_emfield_xml'))) {
    return $cache->data;
  }
  $result = _emfield_http_request_header($url);
  if (!empty($result->error)) {
    if ($return_errors) {
      return $result;
    }
    emfield_set_error(t("Could not connect to @provider: HTTP error @error.", array(
      '@error' => $result->code,
      '@provider' => $provider,
    )));
    return array();
  }

  // Cache the result.
  cache_set('emfield:request-header:' . $url, $result, 'cache_emfield_xml', time() + variable_get('emfield_cache_duration', 3600));
  return $result;
}