You are here

function cdn_file_url in CDN 5

Given a file path relative to the Drupal root directory, get the URL of the corresponding file on the CDN, or the normal URL if the corresponding file does not (yet) exist on the CDN.

Parameters

$file_path: A file path relative to the Drupal root directory.

$files_synced: (optional) An array of synced files, with the keys the source file paths and the values the file paths on the CDN. This parameter is used by the cdn_update_file() function for example. In normal usage, you should not need it.

Return value

The URL to the file on the CDN, if available, otherwise the normal URL.

1 call to cdn_file_url()
cdn_file_server in ./cdn.inc
Implementation of hook_file_server().

File

./cdn.inc, line 60
Basic functions for CDN integration and synchronization.

Code

function cdn_file_url($file_path, $files_synced = array()) {
  $files_synced = !empty($files_synced) ? $files_synced : variable_get('cdn_files_synced', array());
  $file_path = cdn_clean_filepath($file_path);
  return in_array($file_path, array_keys($files_synced)) ? variable_get('cdn_url', 'yourcdn.com/') . $files_synced[$file_path] : FALSE;
}