diff options
author | Thomas ZILLIOX <thomas@zilliox.me> | 2013-08-09 22:34:32 +0400 |
---|---|---|
committer | Thomas ZILLIOX <thomas@zilliox.me> | 2013-08-09 22:34:32 +0400 |
commit | 9b3305306f7db26e05341d589b365307dd2b99d2 (patch) | |
tree | 700b89e2cd0ce72bc2a1c91cd40417c1497563ab /core/AssetManager.php | |
parent | 71c7d9838ff389b9d19114c6a4d8b011a11462c0 (diff) | |
parent | 302ddbfd3aad22f5da3ab1a3fc78dad7bba1d9ac (diff) |
Merge with master
Diffstat (limited to 'core/AssetManager.php')
-rw-r--r-- | core/AssetManager.php | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/core/AssetManager.php b/core/AssetManager.php index eca2e76ef8..79f81fafe1 100644 --- a/core/AssetManager.php +++ b/core/AssetManager.php @@ -152,8 +152,8 @@ class AssetManager $mergedContent = $firstLineCompileHash . "\n" - . "/* Piwik CSS file is compiled with Less. You may be interested in writing a custom Theme for Piwik! */\n" - . $mergedContent; + . "/* Piwik CSS file is compiled with Less. You may be interested in writing a custom Theme for Piwik! */\n" + . $mergedContent; self::writeAssetToFile($mergedContent, self::MERGED_CSS_FILE); } @@ -169,7 +169,7 @@ class AssetManager /* * Rewrite css url directives - * - assumes these are all relative paths + * - rewrites relative paths * - rewrite windows directory separator \\ to / */ protected static function rewriteCssPathsDirectives($relativePath, $content) @@ -179,15 +179,21 @@ class AssetManager $rootDirectoryLength = self::countDirectoriesInPathToRoot(); } + $baseDirectory = dirname($relativePath); $content = preg_replace_callback( "/(url\(['\"]?)([^'\")]*)/", - create_function( - '$matches', - "return \$matches[1] . str_replace('\\\\', '/', substr(realpath(PIWIK_DOCUMENT_ROOT . '/' . \$matches[2]), $rootDirectoryLength));" - ), + function ($matches) use ($rootDirectoryLength, $baseDirectory) { + $absolutePath = substr(realpath(PIWIK_DOCUMENT_ROOT . "/$baseDirectory/" . $matches[2]), $rootDirectoryLength); + $rewritten = str_replace('\\', '/', $absolutePath); + + if (is_file($rewritten)) { // only rewrite the URL if transforming it points to a valid file + return $matches[1] . $rewritten; + } else { + return $matches[1] . $matches[2]; + } + }, $content ); - return $content; } |