Created
April 4, 2013 14:12
-
-
Save wimleers/5310684 to your computer and use it in GitHub Desktop.
Moves file_create_url() calls from once per aggregated CSS file (which is very wrong) to once per actual referenced file (which is right).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git d | |
includes/common.inc | 16 +++++----------- | |
1 file changed, 5 insertions(+), 11 deletions(-) | |
diff --git a/includes/common.inc b/includes/common.inc | |
index 27fa190..7324b00 100644 | |
--- a/includes/common.inc | |
+++ b/includes/common.inc | |
@@ -3562,17 +3562,10 @@ function drupal_build_css_cache($css) { | |
if ($stylesheet['type'] == 'file') { | |
$contents = drupal_load_stylesheet($stylesheet['data'], TRUE); | |
- // Build the base URL of this CSS file: start with the full URL. | |
- $css_base_url = file_create_url($stylesheet['data']); | |
- // Move to the parent. | |
- $css_base_url = substr($css_base_url, 0, strrpos($css_base_url, '/')); | |
- // Simplify to a relative URL if the stylesheet URL starts with the | |
- // base URL of the website. | |
- if (substr($css_base_url, 0, strlen($GLOBALS['base_root'])) == $GLOBALS['base_root']) { | |
- $css_base_url = substr($css_base_url, strlen($GLOBALS['base_root'])); | |
- } | |
- | |
+ // Get the parent directory of this file, relative to the Drupal root. | |
+ $css_base_url = drupal_substr($stylesheet['data'], 0, strrpos($stylesheet['data'], '/')); | |
_drupal_build_css_path(NULL, $css_base_url . '/'); | |
+ | |
// Anchor all paths in the CSS with its base URL, ignoring external and absolute paths. | |
$data .= preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\s*\)/i', '_drupal_build_css_path', $contents); | |
} | |
@@ -3629,7 +3622,8 @@ function _drupal_build_css_path($matches, $base = NULL) { | |
$last = $path; | |
$path = preg_replace('`(^|/)(?!\.\./)([^/]+)/\.\./`', '$1', $path); | |
} | |
- return 'url(' . $path . ')'; | |
+ | |
+ return 'url(' . file_create_url($path) . ')'; | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment