diff options
Diffstat (limited to 'core/AssetManager/UIAssetMerger')
-rw-r--r-- | core/AssetManager/UIAssetMerger/StylesheetUIAssetMerger.php | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/core/AssetManager/UIAssetMerger/StylesheetUIAssetMerger.php b/core/AssetManager/UIAssetMerger/StylesheetUIAssetMerger.php index a485a513c9..b3cebc8841 100644 --- a/core/AssetManager/UIAssetMerger/StylesheetUIAssetMerger.php +++ b/core/AssetManager/UIAssetMerger/StylesheetUIAssetMerger.php @@ -15,6 +15,7 @@ use Piwik\AssetManager\UIAssetMerger; use Piwik\Common; use Piwik\Exception\StylesheetLessCompileException; use Piwik\Piwik; +use Piwik\Plugin\Manager; class StylesheetUIAssetMerger extends UIAssetMerger { @@ -191,8 +192,9 @@ class StylesheetUIAssetMerger extends UIAssetMerger private function getCssPathsRewriter($uiAsset) { $baseDirectory = dirname($uiAsset->getRelativeLocation()); + $webDirs = Manager::getAlternativeWebRootDirectories(); - return function ($matches) use ($baseDirectory) { + return function ($matches) use ($baseDirectory, $webDirs) { $absolutePath = PIWIK_DOCUMENT_ROOT . "/$baseDirectory/" . $matches[2]; // Allow to import extension less file @@ -201,13 +203,39 @@ class StylesheetUIAssetMerger extends UIAssetMerger } // Prevent from rewriting full path - $absolutePath = realpath($absolutePath); - if ($absolutePath) { + $absolutePathReal = realpath($absolutePath); + if ($absolutePathReal) { $relativePath = $baseDirectory . "/" . $matches[2]; $relativePath = str_replace('\\', '/', $relativePath); $publicPath = $matches[1] . $relativePath; } else { - $publicPath = $matches[1] . $matches[2]; + foreach ($webDirs as $absPath => $relativePath) { + if (strpos($baseDirectory, $relativePath) === 0) { + if (strpos($matches[2], '.') === 0) { + // eg ../images/ok.png + $fileRelative = $baseDirectory . '/' . $matches[2]; + $fileAbsolute = $absPath . str_replace($relativePath, '', $fileRelative); + if (file_exists($fileAbsolute)) { + return $matches[1] . $fileRelative; + } + } elseif (strpos($matches[2], 'plugins/') === 0) { + // eg plugins/Foo/images/ok.png + $fileRelative = substr($matches[2], strlen('plugins/')); + $fileAbsolute = $absPath . $fileRelative; + if (file_exists($fileAbsolute)) { + return $matches[1] . $relativePath . $fileRelative; + } + } elseif ($matches[1] === '@import "') { + $fileRelative = $baseDirectory . '/' . $matches[2]; + $fileAbsolute = $absPath . str_replace($relativePath, '', $fileRelative); + if (file_exists($fileAbsolute)) { + return $matches[1] . $baseDirectory . '/' . $matches[2]; + } + } + } + } + + $publicPath = $matches[1] . $matches[2]; } return $publicPath; |