UIAsset
1 year ago
UIAssetFetcher
1 month ago
UIAssetMerger
1 month ago
UIAsset.php
2 years ago
UIAssetCacheBuster.php
6 months ago
UIAssetCatalog.php
5 months ago
UIAssetCatalogSorter.php
2 years ago
UIAssetFetcher.php
1 year ago
UIAssetMerger.php
1 year ago
UIAssetMinifier.php
1 year ago
UIAssetCacheBuster.php
61 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 | * @method static \Piwik\AssetManager\UIAssetCacheBuster getInstance() |
| 10 | */ |
| 11 | namespace Piwik\AssetManager; |
| 12 | |
| 13 | use Piwik\Plugin\Manager; |
| 14 | use Piwik\Singleton; |
| 15 | use Piwik\Version; |
| 16 | class UIAssetCacheBuster extends Singleton |
| 17 | { |
| 18 | /** |
| 19 | * Cache buster based on |
| 20 | * - Piwik version |
| 21 | * - Loaded plugins (name and version) |
| 22 | * - Super user salt |
| 23 | * - Latest |
| 24 | * |
| 25 | * @param string[] $pluginNames |
| 26 | * @return string |
| 27 | */ |
| 28 | public function piwikVersionBasedCacheBuster($pluginNames = \false) |
| 29 | { |
| 30 | static $cachedCacheBuster = null; |
| 31 | if (empty($cachedCacheBuster) || $pluginNames !== \false) { |
| 32 | $masterFile = PIWIK_INCLUDE_PATH . '/.git/refs/heads/master'; |
| 33 | $currentGitHash = file_exists($masterFile) ? @file_get_contents($masterFile) : ''; |
| 34 | $manager = Manager::getInstance(); |
| 35 | $plugins = !$pluginNames ? $manager->getActivatedPlugins() : $pluginNames; |
| 36 | sort($plugins); |
| 37 | $pluginsInfo = ''; |
| 38 | foreach ($plugins as $pluginName) { |
| 39 | if ($manager->isPluginLoaded($pluginName)) { |
| 40 | $plugin = $manager->getLoadedPlugin($pluginName); |
| 41 | $pluginsInfo .= $plugin->getPluginName() . $plugin->getVersion() . ','; |
| 42 | } |
| 43 | } |
| 44 | $cacheBuster = md5($pluginsInfo . \PHP_VERSION . Version::VERSION . trim($currentGitHash ?: '')); |
| 45 | if ($pluginNames !== \false) { |
| 46 | return $cacheBuster; |
| 47 | } |
| 48 | $cachedCacheBuster = $cacheBuster; |
| 49 | } |
| 50 | return $cachedCacheBuster; |
| 51 | } |
| 52 | /** |
| 53 | * @param string $content |
| 54 | * @return string |
| 55 | */ |
| 56 | public function md5BasedCacheBuster($content) |
| 57 | { |
| 58 | return md5($content); |
| 59 | } |
| 60 | } |
| 61 |