Chunk.php
3 months ago
JScriptUIAssetFetcher.php
2 years ago
PluginUmdAssetFetcher.php
2 months ago
StaticUIAssetFetcher.php
2 years ago
StylesheetUIAssetFetcher.php
2 years ago
StylesheetUIAssetFetcher.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\AssetManager\UIAssetFetcher; |
| 10 | |
| 11 | use Piwik\AssetManager\UIAssetFetcher; |
| 12 | use Piwik\Piwik; |
| 13 | class StylesheetUIAssetFetcher extends UIAssetFetcher |
| 14 | { |
| 15 | protected function getPriorityOrder() |
| 16 | { |
| 17 | $theme = $this->getTheme(); |
| 18 | $themeName = $theme->getThemeName(); |
| 19 | $order = array( |
| 20 | 'plugins/Morpheus/stylesheets/base/bootstrap.css', |
| 21 | 'plugins/Morpheus/stylesheets/base/icons.css', |
| 22 | 'node_modules/', |
| 23 | 'libs/', |
| 24 | 'plugins/CoreHome/stylesheets/color_manager.css', |
| 25 | // must be before other Piwik stylesheets |
| 26 | 'plugins/Morpheus/stylesheets/base.less', |
| 27 | ); |
| 28 | if ($themeName === 'Morpheus') { |
| 29 | $order[] = 'plugins\\/((?!Morpheus).)*\\/'; |
| 30 | } else { |
| 31 | $order[] = sprintf('plugins\\/((?!(Morpheus)|(%s)).)*\\/', $themeName); |
| 32 | } |
| 33 | $order = array_merge($order, array('plugins/Dashboard/stylesheets/dashboard.less', 'tests/')); |
| 34 | return $order; |
| 35 | } |
| 36 | protected function retrieveFileLocations() |
| 37 | { |
| 38 | /** |
| 39 | * Triggered when gathering the list of all stylesheets (CSS and LESS) needed by |
| 40 | * Piwik and its plugins. |
| 41 | * |
| 42 | * Plugins that have stylesheets should use this event to make those stylesheets |
| 43 | * load. |
| 44 | * |
| 45 | * Stylesheets should be placed within a **stylesheets** subdirectory in your plugin's |
| 46 | * root directory. |
| 47 | * |
| 48 | * **Example** |
| 49 | * |
| 50 | * public function getStylesheetFiles(&$stylesheets) |
| 51 | * { |
| 52 | * $stylesheets[] = "plugins/MyPlugin/stylesheets/myfile.less"; |
| 53 | * $stylesheets[] = "plugins/MyPlugin/stylesheets/myotherfile.css"; |
| 54 | * } |
| 55 | * |
| 56 | * @param string[] &$stylesheets The list of stylesheet paths. |
| 57 | */ |
| 58 | Piwik::postEvent('AssetManager.getStylesheetFiles', array(&$this->fileLocations)); |
| 59 | $this->addUmdCssFilesIfDetected($this->plugins); |
| 60 | $this->addThemeFiles(); |
| 61 | $this->mapBowerComponentFilesForBC($this->fileLocations); |
| 62 | } |
| 63 | protected function addThemeFiles() |
| 64 | { |
| 65 | $theme = $this->getTheme(); |
| 66 | if (!$theme) { |
| 67 | return; |
| 68 | } |
| 69 | $themeStylesheet = $theme->getStylesheet(); |
| 70 | if ($themeStylesheet) { |
| 71 | $this->fileLocations[] = $themeStylesheet; |
| 72 | } |
| 73 | } |
| 74 | private function addUmdCssFilesIfDetected(array $plugins) |
| 75 | { |
| 76 | foreach ($plugins as $plugin) { |
| 77 | $css = "plugins/{$plugin}/vue/dist/{$plugin}.css"; |
| 78 | if (is_file(PIWIK_INCLUDE_PATH . '/' . $css)) { |
| 79 | $this->fileLocations[] = $css; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 |