PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Policy / CompliancePolicy.php
matomo / app / core / Policy Last commit date
Exceptions 6 months ago CnilPolicy.php 1 month ago CompliancePolicy.php 3 months ago PolicyManager.php 1 month ago
CompliancePolicy.php
160 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\Policy;
10
11 use Piwik\Piwik;
12 use Piwik\Plugin\Manager;
13 use Piwik\Settings\FieldConfig;
14 use Piwik\Settings\Interfaces\ConfigSettingInterface;
15 use Piwik\Settings\Interfaces\MeasurableSettingInterface;
16 use Piwik\Settings\Interfaces\SystemSettingInterface;
17 use Piwik\Settings\Interfaces\Traits\Getters\ConfigGetterTrait;
18 use Piwik\Settings\Interfaces\Traits\Setters\MeasurableSetterTrait;
19 use Piwik\Settings\Interfaces\Traits\Setters\SystemSetterTrait;
20 /**
21 * @implements SystemSettingInterface<bool>
22 * @implements MeasurableSettingInterface<bool>
23 */
24 abstract class CompliancePolicy implements SystemSettingInterface, MeasurableSettingInterface, ConfigSettingInterface
25 {
26 /**
27 * @use SystemSetterTrait<bool>
28 */
29 use SystemSetterTrait;
30 /**
31 * @use MeasurableSetterTrait<bool>
32 */
33 use MeasurableSetterTrait;
34 /**
35 * @use ConfigGetterTrait<bool>
36 */
37 use ConfigGetterTrait;
38 public static abstract function getName() : string;
39 public static abstract function getTitle() : string;
40 protected static abstract function generateDescription() : string;
41 protected static abstract function generateWarnings() : string;
42 public static function getDescription() : string
43 {
44 $description = static::generateDescription();
45 /**
46 * This event is triggered while the description of a compliance policy is
47 * being generated. The policy description can be modified via this event.
48 *
49 * @param string &$description of the policy.
50 */
51 Piwik::postEvent('CompliancePolicy.updatePolicyDescription', [&$description, static::class]);
52 $shouldShowWarnings = \true;
53 /**
54 * This event is triggered while the description of a compliance policy is
55 * being generated, and controls whether any warnings specific to the policy
56 * are displayed at the end of the description.
57 *
58 * @param bool &$shouldShowWarnings set to false if the warnings should be hidden
59 */
60 Piwik::postEvent('CompliancePolicy.shouldShowWarnings', [&$shouldShowWarnings, static::class]);
61 if ($shouldShowWarnings) {
62 $warnings = static::generateWarnings();
63 if (!empty($warnings)) {
64 $description .= '<br/>' . static::generateWarnings();
65 }
66 }
67 return $description;
68 }
69 /**
70 * @return array<array<string>> of [['title' => (string) 'TITLE', 'note' => (string) 'NOTE']]
71 */
72 public static abstract function getUnknownSettings() : array;
73 /**
74 * @return array<string, string>
75 */
76 public static function getDetails() : array
77 {
78 return ['id' => static::getName(), 'title' => static::getTitle(), 'description' => static::getDescription()];
79 }
80 protected static function getPluginManagerInstance() : Manager
81 {
82 return Manager::getInstance();
83 }
84 protected static function getSystemDefaultValue()
85 {
86 return \false;
87 }
88 protected static function getSystemName() : string
89 {
90 return preg_replace('/\\s+/', '', static::getName()) . '_policy_enabled';
91 }
92 protected static function getSystemType() : string
93 {
94 return FieldConfig::TYPE_BOOL;
95 }
96 protected static function getMeasurableDefaultValue()
97 {
98 return \false;
99 }
100 protected static function getMeasurableName() : string
101 {
102 return preg_replace('/\\s+/', '', static::getName()) . '_policy_enabled';
103 }
104 protected static function getMeasurableType() : string
105 {
106 return FieldConfig::TYPE_BOOL;
107 }
108 protected static function getConfigSection() : string
109 {
110 return Piwik::getPluginNameOfMatomoClass(static::class);
111 }
112 protected static function getConfigSettingName() : string
113 {
114 return static::getSystemName();
115 }
116 /**
117 * If the policy is active at the instance level,
118 * disabling the policy for a site will also disable it
119 * for the instance.
120 */
121 public static function setActiveStatus(?int $idSite, bool $isActive) : void
122 {
123 if (isset($idSite)) {
124 static::setMeasurableValue($idSite, $isActive);
125 if (static::getSystemValue() && !$isActive) {
126 static::setSystemValue($isActive);
127 }
128 } else {
129 static::setSystemValue($isActive);
130 }
131 /**
132 * This event is triggered when the status of a compliance policy changes, and
133 * is to be used to perform extra actions when a policy is activated/deactivated.
134 *
135 * The status of a policy cannot be changed via this event.
136 *
137 * @param bool $isActive Whether the policy is being activated or deactivated
138 * @param int|null $idSite
139 * @param class-string<CompliancePolicy> The compliance policy in question
140 */
141 Piwik::postEvent('CompliancePolicy.setActiveStatus', [$isActive, $idSite, static::class]);
142 }
143 /**
144 * If the policy is active at the instance level, then
145 * this function will return true for all sites.
146 */
147 public static function isActive(?int $idSite) : bool
148 {
149 $instanceLevel = static::getSystemValue();
150 if (!$instanceLevel && isset($idSite)) {
151 return static::getMeasurableValue($idSite);
152 }
153 return $instanceLevel;
154 }
155 public static function isConfigControlled()
156 {
157 return !is_null(static::getConfigValue());
158 }
159 }
160