function _cdn_basic_farfuture_parse_raw_mapping in CDN 7.2
Same name and namespace in other branches
- 6.2 cdn.basic.farfuture.inc \_cdn_basic_farfuture_parse_raw_mapping()
Parse the raw (textual) mapping into a lookup table, where the key is the file extension and the value is a list of CDN URLs that serve the file.
Parameters
$mapping_raw: A raw (textual) mapping.
Return value
The corresponding mapping lookup table.
4 calls to _cdn_basic_farfuture_parse_raw_mapping()
- CDNOriginPullFarFutureTestCase::assertUFIMapping in tests/
cdn.test - Assert a UFI mapping (and optionally set a mapping).
- CDNOriginPullFarFutureTestCase::assertUFIMethod in tests/
cdn.test - Assert a UFI method. Must be run after a UFI mapping is asserted (and set) by assertUFIMapping().
- CDNOriginPullFarFutureTestCase::testUFIMapping in tests/
cdn.test - cdn_basic_farfuture_get_identifier in ./
cdn.basic.farfuture.inc - Get the UFI (Unique File Identifier) for the file at a path.
File
- ./
cdn.basic.farfuture.inc, line 288 - Far Future expiration setting for basic mode.
Code
function _cdn_basic_farfuture_parse_raw_mapping($mapping_raw) {
$mapping = array();
if (!empty($mapping_raw)) {
$lines = preg_split("/[\n\r]+/", $mapping_raw, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
// Parse this line. It may or may not limit the CDN URL to a list of
// file extensions.
$parts = explode('|', $line);
$directories = explode(':', $parts[0]);
$specificity = 0;
// There may be 2 or 3 parts:
// - part 1: directories
// - part 2: file extensions (optional)
// - part 3: unique file identifier method
if (count($parts) == 2) {
$extensions = array(
'*',
);
// Use the asterisk as a wildcard.
$ufi_method = drupal_strtolower(trim($parts[1]));
}
elseif (count($parts) == 3) {
// Convert to lower case, remove periods, whitespace and split on ' '.
$extensions = explode(' ', trim(str_replace('.', '', drupal_strtolower($parts[1]))));
$ufi_method = drupal_strtolower(trim($parts[2]));
}
// Create the mapping lookup table.
foreach ($directories as $directory) {
$directory_specificity = 10 * count(explode('/', $directory));
foreach ($extensions as $extension) {
$extension_specificity = $extension == '*' ? 0 : 1;
$mapping[$directory][$extension] = array(
'ufi method' => $ufi_method,
'specificity' => $directory_specificity + $extension_specificity,
);
}
}
}
}
return $mapping;
}