diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-03-15 01:24:36 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-03-15 01:24:36 +0300 |
commit | 6395855aa7f3813cc7f413a18d31505ea26ba32a (patch) | |
tree | 2a3157954dd3c29cc024bf7093df53b63be94dd6 /core/AssetManager/UIAssetMerger/StylesheetUIAssetMerger.php | |
parent | d7c932710e690d87ea62c3ec94ae65fa5bd05b05 (diff) |
Support multiple plugin paths (#14051)
* do not hard code plugins directory
* remove method that is not needed for now
* use plugins directory in more places
* some work on supporting multiple plugin directories
* use more unique name
* couple fixes
* and another fix
* sort plugins
* adjust languagesmanager
* adjust more usages
* Update Manager.php
* adding a plugin to test
* more tests
* make sure plugin resources can be located in custom directory
* adding more tests
* rewrite image paths
* handle more cases
* add tests
* make sure to load plugin
* trying to fix test
* trying it this way
* load plugin
* fix ui test?
* testing if tests succeed this way
* another test
* load custom dir plugin
* load plugin in ui fixture
* change the update statement
* remove update script
* delete column
* fix ui test
* make it work for tests
* fix some tests
* Fix merge.
Diffstat (limited to 'core/AssetManager/UIAssetMerger/StylesheetUIAssetMerger.php')
-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; |