You are here

function custom_file_url_rewrite in CDN 6

File

./cdn.module, line 43
Implementation of the core hooks, defines, public and private functions.

Code

function custom_file_url_rewrite($path) {
  $status = variable_get(CDN_STATUS_VARIABLE, CDN_DISABLED);
  $mode = variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
  $stats = variable_get(CDN_STATS_VARIABLE, FALSE) && user_access(CDN_PERM_ACCESS_STATS);
  if ($stats) {
    require_once drupal_get_path('module', 'cdn') . '/cdn.stats.inc';
  }
  if ($status == CDN_ENABLED || $status == CDN_DEBUG && user_access(CDN_PERM_ACCESS_DEBUG)) {
    if ($stats) {
      $start = microtime();
    }

    // Depending on the mode, use a different function to get the URL.
    if ($mode == CDN_MODE_BASIC) {
      $cdn_url = cdn_basic_get_url($path);
      $server = FALSE;
    }
    else {
      list($cdn_url, $server) = cdn_advanced_get_url($path);
    }

    // If the user can access it, add this to the per-page statistics.
    if ($stats) {
      $end = microtime();
      _cdn_devel_page_stats($path, $cdn_url, $server, $end - $start);
    }
    return $cdn_url;
  }
  else {
    return FALSE;
  }
}