-
Notifications
You must be signed in to change notification settings - Fork 59
/
Configuration.php
116 lines (91 loc) · 2.84 KB
/
Configuration.php
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
114
115
116
<?php
/**
* Matomo - 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\TagManager;
use Piwik\Config;
class Configuration
{
public static $DEFAULT_DISABLED_TAGS = [];
public static $DEFAULT_DISABLED_TRIGGERS = [];
public static $DEFAULT_DISABLED_VARIABLES = [];
public const KEY_DISABLED_TAGS = 'disable_tags';
public const KEY_DISABLED_TRIGGERS = 'disable_triggers';
public const KEY_DISABLED_VARIABLES = 'disable_variables';
public function install()
{
$config = $this->getConfig();
if (empty($config->TagManager)) {
$config->TagManager = array();
}
$tagManager = $config->TagManager;
$values = array(
self::KEY_DISABLED_TAGS => self::$DEFAULT_DISABLED_TAGS,
self::KEY_DISABLED_TRIGGERS => self::$DEFAULT_DISABLED_TRIGGERS,
self::KEY_DISABLED_VARIABLES => self::$DEFAULT_DISABLED_VARIABLES,
);
foreach ($values as $key => $default) {
// we make sure to set a value only if none has been configured yet, eg in common config.
if (empty($tagManager[$key])) {
$tagManager[$key] = $default;
}
}
$config->TagManager = $tagManager;
$config->forceSave();
}
public function uninstall()
{
$config = $this->getConfig();
$config->TagManager = array();
$config->forceSave();
}
/**
* @return array
*/
public function getDisabledTags()
{
$disabled = $this->getConfigValue(self::KEY_DISABLED_TAGS, self::$DEFAULT_DISABLED_TAGS);
if (!is_array($disabled) || empty($disabled)) {
$disabled = array();
}
return array_values(array_unique($disabled));
}
/**
* @return array
*/
public function getDisabledTriggers()
{
$disabled = $this->getConfigValue(self::KEY_DISABLED_TRIGGERS, self::$DEFAULT_DISABLED_TRIGGERS);
if (!is_array($disabled) || empty($disabled)) {
$disabled = array();
}
return $disabled;
}
/**
* @return array
*/
public function getDisabledVariables()
{
$disabled = $this->getConfigValue(self::KEY_DISABLED_VARIABLES, self::$DEFAULT_DISABLED_VARIABLES);
if (!is_array($disabled) || empty($disabled)) {
$disabled = array();
}
return array_values(array_unique($disabled));
}
private function getConfig()
{
return Config::getInstance();
}
private function getConfigValue($name, $default)
{
$config = $this->getConfig();
$tagManager = $config->TagManager;
if (isset($tagManager[$name])) {
return $tagManager[$name];
}
return $default;
}
}