diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-09-22 23:28:15 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-09-22 23:28:15 +0300 |
commit | 6db4698f572d6500d461e5d2fca565dcf1e12932 (patch) | |
tree | e013946270baf2a7d003b2d0ecd48e6b2ce64f41 | |
parent | cb97621911bed774b9f0c3a7d52d4cb0db38ee89 (diff) |
When loading a template url from a custom plugin directory, prefix the relative directory (#14717)
* When loading a template url from a custom plugin directory, prefix the relative directory
* detect relative dir partially
* replace the initial plugins part as well
* only print info for activated plugins
* Update _jsGlobalVariables.twig
* remove duplicate endif
* Update http404check.js
-rw-r--r-- | core/Plugin/Controller.php | 5 | ||||
-rw-r--r-- | core/Plugin/Manager.php | 10 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/http404check.js | 18 | ||||
-rw-r--r-- | plugins/Morpheus/templates/_jsGlobalVariables.twig | 3 |
4 files changed, 35 insertions, 1 deletions
diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php index 9b4f8dbf2c..1568b3145d 100644 --- a/core/Plugin/Controller.php +++ b/core/Plugin/Controller.php @@ -35,6 +35,7 @@ use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\SettingsPiwik; use Piwik\Site; use Piwik\Url; +use Piwik\Plugin; use Piwik\View; use Piwik\View\ViewInterface; use Piwik\ViewDataTable\Factory as ViewDataTableFactory; @@ -748,6 +749,9 @@ abstract class Controller $view->setXFrameOptions('sameorigin'); } + $pluginManager = Plugin\Manager::getInstance(); + $view->relativePluginWebDirs = (object) $pluginManager->getWebRootDirectoriesForCustomPluginDirs(); + self::setHostValidationVariablesView($view); } @@ -1063,3 +1067,4 @@ abstract class Controller } } } + diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php index e6872ef5a6..b47ffc0983 100644 --- a/core/Plugin/Manager.php +++ b/core/Plugin/Manager.php @@ -55,6 +55,7 @@ class Manager protected $doLoadPlugins = true; protected static $pluginsToPathCache = array(); + protected static $pluginsToWebRootDirCache = array(); private $pluginsLoadedAndActivated; @@ -409,6 +410,11 @@ class Manager return $dirs; } + public function getWebRootDirectoriesForCustomPluginDirs() + { + return array_intersect_key(self::$pluginsToWebRootDirCache, array_flip($this->pluginsToLoad)); + } + /** * Returns the path to all plugins directories. Each plugins directory may contain several plugins. * All paths have a trailing slash '/'. @@ -465,10 +471,11 @@ class Manager return self::$pluginsToPathCache[$pluginName]; } - foreach (self::getPluginsDirectories() as $dir) { + foreach (self::getAlternativeWebRootDirectories() as $dir => $relative) { $path = $dir . $pluginName; if (is_dir($path)) { self::$pluginsToPathCache[$pluginName] = self::getPluginRealPath($path); + self::$pluginsToWebRootDirCache[$pluginName] = $relative; return $path; } } @@ -1640,3 +1647,4 @@ class Manager } } } + diff --git a/plugins/CoreHome/angularjs/http404check.js b/plugins/CoreHome/angularjs/http404check.js index 2bafa893c9..b18b7be669 100644 --- a/plugins/CoreHome/angularjs/http404check.js +++ b/plugins/CoreHome/angularjs/http404check.js @@ -15,6 +15,23 @@ } return { + 'request': function(config) { + if ('object' === typeof piwik.relativePluginWebDirs + && config && config.url && config.url.indexOf('plugins/') === 0 + && config.url.indexOf('.html') > 0 + && config.url.indexOf('/angularjs/') > 0) { + + var urlParts = config.url.split('/'); + if (urlParts && urlParts.length > 2 && urlParts[1]) { + var pluginName = urlParts[1]; + if (pluginName && pluginName in piwik.relativePluginWebDirs && piwik.relativePluginWebDirs[pluginName]) { + urlParts[0] = piwik.relativePluginWebDirs[pluginName]; + config.url = urlParts.join('/'); + } + } + } + return config; + }, 'responseError': function(rejection) { if (rejection && @@ -54,3 +71,4 @@ })(); + diff --git a/plugins/Morpheus/templates/_jsGlobalVariables.twig b/plugins/Morpheus/templates/_jsGlobalVariables.twig index 36c03f0eb2..7f127d5b2c 100644 --- a/plugins/Morpheus/templates/_jsGlobalVariables.twig +++ b/plugins/Morpheus/templates/_jsGlobalVariables.twig @@ -16,6 +16,8 @@ symbolDecimal: "{{ 'Intl_NumberSymbolDecimal'|translate }}" }; + piwik.relativePluginWebDirs = {{ relativePluginWebDirs|json_encode|raw }} + {% if userLogin %}piwik.userLogin = "{{ userLogin|e('js')}}";{% endif %} {% if idSite is defined %}piwik.idSite = "{{ idSite }}";{% endif %} @@ -57,3 +59,4 @@ piwik.shouldPropagateTokenAuth = {{ shouldPropagateTokenAuth|json_encode|raw }}; {{ postEvent("Template.jsGlobalVariables") }} </script> + |