Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/AssetManager')
-rw-r--r--core/AssetManager/UIAsset/OnDiskUIAsset.php19
-rw-r--r--core/AssetManager/UIAssetFetcher.php33
-rw-r--r--core/AssetManager/UIAssetMerger/StylesheetUIAssetMerger.php36
3 files changed, 82 insertions, 6 deletions
diff --git a/core/AssetManager/UIAsset/OnDiskUIAsset.php b/core/AssetManager/UIAsset/OnDiskUIAsset.php
index cbd702a691..48557480e0 100644
--- a/core/AssetManager/UIAsset/OnDiskUIAsset.php
+++ b/core/AssetManager/UIAsset/OnDiskUIAsset.php
@@ -10,6 +10,7 @@ namespace Piwik\AssetManager\UIAsset;
use Exception;
use Piwik\AssetManager\UIAsset;
+use Piwik\Common;
use Piwik\Filesystem;
class OnDiskUIAsset extends UIAsset
@@ -25,13 +26,26 @@ class OnDiskUIAsset extends UIAsset
private $relativeLocation;
/**
+ * @var string
+ */
+ private $relativeRootDir;
+
+ /**
* @param string $baseDirectory
* @param string $fileLocation
*/
- public function __construct($baseDirectory, $fileLocation)
+ public function __construct($baseDirectory, $fileLocation, $relativeRootDir = '')
{
$this->baseDirectory = $baseDirectory;
$this->relativeLocation = $fileLocation;
+
+ if (!empty($relativeRootDir)
+ && is_string($relativeRootDir)
+ && !Common::stringEndsWith($relativeRootDir, '/')) {
+ $relativeRootDir .= '/';
+ }
+
+ $this->relativeRootDir = $relativeRootDir;
}
public function getAbsoluteLocation()
@@ -41,6 +55,9 @@ class OnDiskUIAsset extends UIAsset
public function getRelativeLocation()
{
+ if (isset($this->relativeRootDir)) {
+ return $this->relativeRootDir . $this->relativeLocation;
+ }
return $this->relativeLocation;
}
diff --git a/core/AssetManager/UIAssetFetcher.php b/core/AssetManager/UIAssetFetcher.php
index 0b8e9b3a55..c9086b0e71 100644
--- a/core/AssetManager/UIAssetFetcher.php
+++ b/core/AssetManager/UIAssetFetcher.php
@@ -9,6 +9,7 @@
namespace Piwik\AssetManager;
use Piwik\AssetManager\UIAsset\OnDiskUIAsset;
+use Piwik\Plugin\Manager;
use Piwik\Theme;
abstract class UIAssetFetcher
@@ -89,9 +90,39 @@ abstract class UIAssetFetcher
private function populateCatalog()
{
+ $pluginBaseDir = Manager::getPluginsDirectory();
+ $pluginWebDirectories = Manager::getAlternativeWebRootDirectories();
+ $matomoRootDir = $this->getBaseDirectory();
+
foreach ($this->fileLocations as $fileLocation) {
+ $fileAbsolute = $matomoRootDir . '/' . $fileLocation;
+
$newUIAsset = new OnDiskUIAsset($this->getBaseDirectory(), $fileLocation);
- $this->catalog->addUIAsset($newUIAsset);
+ if ($newUIAsset->exists()) {
+ $this->catalog->addUIAsset($newUIAsset);
+ continue;
+ }
+
+ $found = false;
+
+ if (strpos($fileAbsolute, $pluginBaseDir) === 0) {
+ // we iterate over all custom plugin directories only for plugin files, not libs files (not needed there)
+ foreach ($pluginWebDirectories as $pluginDirectory => $relative) {
+ $fileTest = str_replace($pluginBaseDir, $pluginDirectory, $fileAbsolute);
+ $newFileRelative = str_replace($pluginDirectory, '', $fileTest);
+ $testAsset = new OnDiskUIAsset($pluginDirectory, $newFileRelative, $relative);
+ if ($testAsset->exists()) {
+ $this->catalog->addUIAsset($testAsset);
+ $found = true;
+ break;
+ }
+ }
+ }
+
+ if (!$found) {
+ // we add it anyway so it'll trigger an error about the missing file
+ $this->catalog->addUIAsset($newUIAsset);
+ }
}
}
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;