function cdn_basic_get_servers in CDN 7.2
Same name and namespace in other branches
- 6.2 cdn.basic.inc \cdn_basic_get_servers()
Gets the servers on which a file is available when basic mode is enabled.
Parameters
$path: The path to get the servers for.
1 call to cdn_basic_get_servers()
- cdn_file_url_alter in ./
cdn.module - Implements hook_file_url_alter().
File
- ./
cdn.basic.inc, line 18 - Logic for basic mode ("Origin Pull mode" in the UI).
Code
function cdn_basic_get_servers($path) {
static $mapping;
$servers = array();
// We only need to parse the textual CDN mapping once into a lookup table.
if (!isset($mapping)) {
$mapping = _cdn_basic_parse_raw_mapping(cdn_basic_get_mapping());
}
// Parse the file extension from the given path; convert it to lower case.
$file_extension = drupal_strtolower(pathinfo($path, PATHINFO_EXTENSION));
// Based on the file extension, determine which key should be used to find
// the CDN URLs in the mapping lookup table, if any.
if (array_key_exists($file_extension, $mapping)) {
$key = $file_extension;
}
elseif (array_key_exists('*', $mapping)) {
$key = '*';
}
else {
$key = NULL;
}
// If there is a key to look up the CDN URLs in the mapping lookup table,
// then build the list of servers.
if (isset($key)) {
$base_path = base_path();
foreach ($mapping[$key] as $cdn_url) {
$servers[] = array(
'server' => $cdn_url,
'url' => $cdn_url . $base_path . $path,
);
}
}
return $servers;
}