| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Plugin; |
|
|
| use Piwik\CacheId; |
| use Piwik\Container\StaticContainer; |
| use Piwik\Plugin; |
| use Piwik\Cache as PiwikCache; |
| use Piwik\Settings\Measurable\MeasurableSettings; |
| use Piwik\Settings\Plugin\UserSettings; |
| use Piwik\Settings\Plugin\SystemSettings; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class SettingsProvider |
| { |
| |
| |
| |
| private $pluginManager; |
|
|
| public function __construct(Plugin\Manager $pluginManager) |
| { |
| $this->pluginManager = $pluginManager; |
| } |
|
|
| |
| |
| |
| public function getSystemSettings(string $pluginName): ?SystemSettings |
| { |
| $plugin = $this->getLoadedAndActivated($pluginName); |
|
|
| if ($plugin) { |
| $settings = $plugin->findComponent('SystemSettings', 'Piwik\\Settings\\Plugin\\SystemSettings'); |
|
|
| if ($settings) { |
| return StaticContainer::get($settings); |
| } |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| public function getUserSettings(string $pluginName): ?UserSettings |
| { |
| $plugin = $this->getLoadedAndActivated($pluginName); |
|
|
| if ($plugin) { |
| $settings = $plugin->findComponent('UserSettings', 'Piwik\\Settings\\Plugin\\UserSettings'); |
|
|
| if ($settings) { |
| return StaticContainer::get($settings); |
| } |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getAllSystemSettings(): array |
| { |
| $cacheId = CacheId::languageAware('AllSystemSettings'); |
| $cache = PiwikCache::getTransientCache(); |
|
|
| if (!$cache->contains($cacheId)) { |
| $pluginNames = $this->pluginManager->getActivatedPlugins(); |
| $byPluginName = array(); |
|
|
| foreach ($pluginNames as $plugin) { |
| $component = $this->getSystemSettings($plugin); |
|
|
| if (!empty($component)) { |
| $byPluginName[$plugin] = $component; |
| } |
| } |
|
|
| $cache->save($cacheId, $byPluginName); |
| } |
|
|
| return $cache->fetch($cacheId); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getAllUserSettings(): array |
| { |
| $cacheId = CacheId::languageAware('AllUserSettings'); |
| $cache = PiwikCache::getTransientCache(); |
|
|
| if (!$cache->contains($cacheId)) { |
| $pluginNames = $this->pluginManager->getActivatedPlugins(); |
| $byPluginName = array(); |
|
|
| foreach ($pluginNames as $plugin) { |
| $component = $this->getUserSettings($plugin); |
|
|
| if (!empty($component)) { |
| $byPluginName[$plugin] = $component; |
| } |
| } |
|
|
| $cache->save($cacheId, $byPluginName); |
| } |
|
|
| return $cache->fetch($cacheId); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getMeasurableSettings($pluginName, $idSite, $idType = null) |
| { |
| $plugin = $this->getLoadedAndActivated($pluginName); |
|
|
| if ($plugin) { |
| $component = $plugin->findComponent('MeasurableSettings', 'Piwik\\Settings\\Measurable\\MeasurableSettings'); |
|
|
| if ($component) { |
| return StaticContainer::getContainer()->make($component, [ |
| 'idSite' => $idSite, |
| 'idMeasurableType' => $idType, |
| ]); |
| } |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getAllMeasurableSettings($idSite, $idMeasurableType = null) |
| { |
| $pluginNames = $this->pluginManager->getActivatedPlugins(); |
| $byPluginName = array(); |
|
|
| foreach ($pluginNames as $plugin) { |
| $component = $this->getMeasurableSettings($plugin, $idSite, $idMeasurableType); |
|
|
| if (!empty($component)) { |
| $byPluginName[$plugin] = $component; |
| } |
| } |
|
|
| return $byPluginName; |
| } |
|
|
| private function getLoadedAndActivated(string $pluginName): ?Plugin |
| { |
| if (!$this->pluginManager->isPluginLoaded($pluginName)) { |
| return null; |
| } |
|
|
| try { |
| if (!$this->pluginManager->isPluginActivated($pluginName)) { |
| return null; |
| } |
|
|
| $plugin = $this->pluginManager->getLoadedPlugin($pluginName); |
| } catch (\Exception $e) { |
| |
| return null; |
| } |
|
|
| return $plugin; |
| } |
| } |
|
|