1.20.x common.inc _backdrop_build_css_path($matches, $base = NULL)

Prefixes all paths within a CSS file for backdrop_build_css_cache().

File

includes/common.inc, line 4101
Common functions that many Backdrop modules will need to reference.

Code

function _backdrop_build_css_path($matches, $base = NULL) {
  $_base = &backdrop_static(__FUNCTION__);
  // Store base path for preg_replace_callback.
  if (isset($base)) {
    $_base = $base;
  }

  // Prefix with base and remove '../' segments where possible.
  if (is_array($matches)) {
    $path = $_base . $matches[1];
  }
  else {
    $path = $_base;
  }
  $last = '';
  while ($path != $last) {
    $last = $path;
    $path = preg_replace('`(^|/)(?!\.\./)([^/]+)/\.\./`', '$1', $path);
  }
  return 'url(' . $path . ')';
}