You are here

function _cdn_build_css_path in CDN 7.2

Same name and namespace in other branches
  1. 6.2 cdn.basic.css.inc \_cdn_build_css_path()

Near-identical to Changes: apply file_create_url() to every file!

See also

_drupal_build_css_path().

1 call to _cdn_build_css_path()
_cdn_build_css_cache in ./cdn.basic.css.inc
Near-identical to Changes:
1 string reference to '_cdn_build_css_path'
_cdn_build_css_cache in ./cdn.basic.css.inc
Near-identical to Changes:

File

./cdn.basic.css.inc, line 138
Overrides of Drupal's CSS aggregation system. Ensures that files referenced by CSS files are also served from the CDN, according to the CDN module's CSS aggregation rules.

Code

function _cdn_build_css_path($matches, $base = NULL) {
  $_base =& drupal_static(__FUNCTION__);

  // Store base path for preg_replace_callback.
  if (isset($base)) {
    $_base = $base;
  }

  // Prefix with base and remove '../' segments where possible.
  $url = $_base . $matches[1];
  $last = '';
  while ($url != $last) {
    $last = $url;
    $url = preg_replace('`(^|/)(?!\\.\\./)([^/]+)/\\.\\./`', '$1', $url);
  }
  $parsed_url = parse_url($url);
  $base_url = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
  $base_url .= isset($parsed_url['user']) ? $parsed_url['user'] : '';
  $base_url .= isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
  if (isset($parsed_url['user']) || isset($parsed_url['pass'])) {
    $base_url .= '@';
  }
  $base_url .= isset($parsed_url['host']) ? $parsed_url['host'] : '';
  $base_url .= isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
  $base_url .= isset($parsed_url['path']) ? $parsed_url['path'] : '';
  $query = isset($parsed_url['query']) ? $parsed_url['query'] : '';

  // In the case of certain URLs, we may have simply a '?' character without
  // further parameters. parse_url() misses this and leaves 'query' blank, so
  // need to this back in.
  // See http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax
  // for more information.
  if ($query != '' || strpos($url, $base_url . '?') === 0) {
    $query = '?' . $query;
  }
  $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
  return 'url(' . file_create_url($base_url) . $query . $fragment . ')';
}