blob: b7254c1ced6653d74d88fe80ddad330aa5cd689f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CorePluginsAdmin;
use Piwik\Piwik;
use Piwik\Plugin\SettingsProvider;
use Exception;
/**
* API for plugin CorePluginsAdmin
*
* @method static \Piwik\Plugins\CorePluginsAdmin\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* @var SettingsMetadata
*/
private $settingsMetadata;
/**
* @var SettingsProvider
*/
private $settingsProvider;
public function __construct(SettingsProvider $settingsProvider, SettingsMetadata $settingsMetadata)
{
$this->settingsProvider = $settingsProvider;
$this->settingsMetadata = $settingsMetadata;
}
/**
* @internal
* @param array $settingValues Format: array('PluginName' => array(array('name' => 'SettingName1', 'value' => 'SettingValue1), ..))
* @throws Exception
*/
public function setSystemSettings($settingValues)
{
Piwik::checkUserHasSuperUserAccess();
$pluginsSettings = $this->settingsProvider->getAllSystemSettings();
$this->settingsMetadata->setPluginSettings($pluginsSettings, $settingValues);
try {
foreach ($pluginsSettings as $pluginSetting) {
if (!empty($settingValues[$pluginSetting->getPluginName()])) {
$pluginSetting->save();
}
}
} catch (Exception $e) {
throw new Exception(Piwik::translate('CoreAdminHome_PluginSettingsSaveFailed'));
}
}
/**
* @internal
* @param array $settingValues Format: array('PluginName' => array(array('name' => 'SettingName1', 'value' => 'SettingValue1), ..))
* @throws Exception
*/
public function setUserSettings($settingValues)
{
Piwik::checkUserIsNotAnonymous();
$pluginsSettings = $this->settingsProvider->getAllUserSettings();
$this->settingsMetadata->setPluginSettings($pluginsSettings, $settingValues);
try {
foreach ($pluginsSettings as $pluginSetting) {
if (!empty($settingValues[$pluginSetting->getPluginName()])) {
$pluginSetting->save();
}
}
} catch (Exception $e) {
throw new Exception(Piwik::translate('CoreAdminHome_PluginSettingsSaveFailed'));
}
}
/**
* @internal
* @return array
* @throws \Piwik\NoAccessException
*/
public function getSystemSettings()
{
Piwik::checkUserHasSuperUserAccess();
$systemSettings = $this->settingsProvider->getAllSystemSettings();
return $this->settingsMetadata->formatSettings($systemSettings);
}
/**
* @internal
* @return array
* @throws \Piwik\NoAccessException
*/
public function getUserSettings()
{
Piwik::checkUserIsNotAnonymous();
$userSettings = $this->settingsProvider->getAllUserSettings();
return $this->settingsMetadata->formatSettings($userSettings);
}
}
|