You are here

function cdn_basic_farfuture_get_ufi_method in CDN 6.2

Same name and namespace in other branches
  1. 7.2 cdn.basic.farfuture.inc \cdn_basic_farfuture_get_ufi_method()

Get the UFI method for the file at a path.

Parameters

$path: The path to get UFI method for the file at the given path.

$mapping: The UFI mapping to use.

1 call to cdn_basic_farfuture_get_ufi_method()
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 184
Far Future expiration setting for basic mode.

Code

function cdn_basic_farfuture_get_ufi_method($path, $mapping) {

  // Determine which UFI method should be used. Note that we keep on trying to
  // find another method until the end: the order of rules matters!
  // However, specificity also matters. The directory pattern "foo/bar/*"
  // should *always* override the less specific pattern "foo/*".
  $ufi_method = FALSE;
  $current_specificity = 0;
  foreach (array_keys($mapping) as $directory) {
    if (drupal_match_path($path, $directory)) {

      // 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.
      $extension = NULL;
      if (array_key_exists($file_extension, $mapping[$directory])) {
        $extension = $file_extension;
      }
      elseif (array_key_exists('*', $mapping[$directory])) {
        $extension = '*';
      }

      // If a matching extension was found, assign the corresponding UFI method.
      if (isset($extension)) {
        $specificity = $mapping[$directory][$extension]['specificity'];
        if ($specificity > $current_specificity) {
          $ufi_method = $mapping[$directory][$extension]['ufi method'];
          $current_specificity = $specificity;
        }
      }
    }
  }

  // Fall back to the default UFI method in case no UFI method is defined by
  // the user.
  if ($ufi_method === FALSE) {
    $ufi_method = CDN_BASIC_FARFUTURE_UNIQUE_IDENTIFIER_DEFAULT;
  }
  return $ufi_method;
}