PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.1.4
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.1.4
5.12.0 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 / Plugin / ControllerAdmin.php
matomo / app / core / Plugin Last commit date
ConsoleCommand 2 years ago Dimension 2 years ago API.php 2 years ago AggregatedMetric.php 2 years ago ArchivedMetric.php 2 years ago Archiver.php 2 years ago Categories.php 2 years ago ComponentFactory.php 2 years ago ComputedMetric.php 2 years ago ConsoleCommand.php 2 years ago Controller.php 2 years ago ControllerAdmin.php 2 years ago Dependency.php 2 years ago LogTablesProvider.php 2 years ago Manager.php 2 years ago Menu.php 2 years ago MetadataLoader.php 2 years ago Metric.php 2 years ago PluginException.php 2 years ago ProcessedMetric.php 2 years ago ReleaseChannels.php 2 years ago Report.php 2 years ago ReportsProvider.php 2 years ago RequestProcessors.php 2 years ago Segment.php 2 years ago SettingsProvider.php 2 years ago Tasks.php 2 years ago ThemeStyles.php 2 years ago ViewDataTable.php 2 years ago Visualization.php 2 years ago WidgetsProvider.php 2 years ago
ControllerAdmin.php
342 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\Plugin;
10
11 use Piwik\Config as PiwikConfig;
12 use Piwik\Config;
13 use Piwik\Container\StaticContainer;
14 use Piwik\Date;
15 use Piwik\Development;
16 use Piwik\Menu\MenuAdmin;
17 use Piwik\Menu\MenuTop;
18 use Piwik\Notification;
19 use Piwik\Notification\Manager as NotificationManager;
20 use Piwik\Piwik;
21 use Piwik\Plugins\Marketplace\Marketplace;
22 use Piwik\Tracker\TrackerConfig;
23 use Piwik\Url;
24 use Piwik\Version;
25 use Piwik\View;
26 use Piwik\ProxyHttp;
27 use Piwik\SettingsPiwik;
28 /**
29 * Base class of plugin controllers that provide administrative functionality.
30 *
31 * See {@link Controller} to learn more about Piwik controllers.
32 *
33 */
34 abstract class ControllerAdmin extends \Piwik\Plugin\Controller
35 {
36 private static function notifyWhenTrackingStatisticsDisabled()
37 {
38 $statsEnabled = PiwikConfig::getInstance()->Tracker['record_statistics'];
39 if ($statsEnabled == "0") {
40 $notification = new Notification(Piwik::translate('General_StatisticsAreNotRecorded'));
41 $notification->context = Notification::CONTEXT_INFO;
42 Notification\Manager::notify('ControllerAdmin_StatsAreNotRecorded', $notification);
43 }
44 }
45 private static function notifyAnyInvalidLicense()
46 {
47 if (!Marketplace::isMarketplaceEnabled()) {
48 return;
49 }
50 if (Piwik::isUserIsAnonymous()) {
51 return;
52 }
53 if (!Piwik::isUserHasSomeAdminAccess()) {
54 return;
55 }
56 if (Development::isEnabled()) {
57 return;
58 }
59 $expired = StaticContainer::get('Piwik\\Plugins\\Marketplace\\Plugins\\InvalidLicenses');
60 $messageLicenseMissing = $expired->getMessageNoLicense();
61 if (!empty($messageLicenseMissing)) {
62 $notification = new Notification($messageLicenseMissing);
63 $notification->raw = true;
64 $notification->context = Notification::CONTEXT_ERROR;
65 $notification->title = Piwik::translate('Marketplace_LicenseMissing');
66 Notification\Manager::notify('ControllerAdmin_LicenseMissingWarning', $notification);
67 }
68 $messageExceeded = $expired->getMessageExceededLicenses();
69 if (!empty($messageExceeded)) {
70 $notification = new Notification($messageExceeded);
71 $notification->raw = true;
72 $notification->context = Notification::CONTEXT_WARNING;
73 $notification->title = Piwik::translate('Marketplace_LicenseExceeded');
74 Notification\Manager::notify('ControllerAdmin_LicenseExceededWarning', $notification);
75 }
76 $messageExpired = $expired->getMessageExpiredLicenses();
77 if (!empty($messageExpired)) {
78 $notification = new Notification($messageExpired);
79 $notification->raw = true;
80 $notification->context = Notification::CONTEXT_WARNING;
81 $notification->title = Piwik::translate('Marketplace_LicenseExpired');
82 Notification\Manager::notify('ControllerAdmin_LicenseExpiredWarning', $notification);
83 }
84 }
85 private static function notifyAnyInvalidPlugin()
86 {
87 if (!Piwik::hasUserSuperUserAccess()) {
88 return;
89 }
90 $missingPlugins = \Piwik\Plugin\Manager::getInstance()->getMissingPlugins();
91 if (empty($missingPlugins)) {
92 return;
93 }
94 $pluginsLink = Url::getCurrentQueryStringWithParametersModified(['module' => 'CorePluginsAdmin', 'action' => 'plugins']);
95 $invalidPluginsWarning = Piwik::translate('CoreAdminHome_InvalidPluginsWarning', [self::getPiwikVersion(), '<strong>' . implode('</strong>,&nbsp;<wbr><strong>', $missingPlugins) . '</strong>']) . "<br/>" . Piwik::translate('CoreAdminHome_InvalidPluginsYouCanUninstall', ['<a href="' . $pluginsLink . '"/>', '</a>']);
96 $notification = new Notification($invalidPluginsWarning);
97 $notification->raw = true;
98 $notification->context = Notification::CONTEXT_WARNING;
99 $notification->title = Piwik::translate('General_Warning');
100 Notification\Manager::notify('ControllerAdmin_InvalidPluginsWarning', $notification);
101 }
102 /**
103 * Calls {@link setBasicVariablesView()} and {@link setBasicVariablesAdminView()}
104 * using the supplied view.
105 *
106 * @param View $view
107 * @param string $viewType If 'admin', the admin variables are set as well as basic ones.
108 */
109 protected function setBasicVariablesViewAs($view, $viewType = 'admin')
110 {
111 $this->setBasicVariablesNoneAdminView($view);
112 if ($viewType === 'admin') {
113 self::setBasicVariablesAdminView($view);
114 }
115 }
116 private static function notifyIfURLIsNotSecure()
117 {
118 $isURLSecure = ProxyHttp::isHttps();
119 if ($isURLSecure) {
120 return;
121 }
122 if (!Piwik::hasUserSuperUserAccess()) {
123 return;
124 }
125 if (Url::isLocalHost(Url::getCurrentHost())) {
126 return;
127 }
128 if (Development::isEnabled()) {
129 return;
130 }
131 $message = Piwik::translate('General_CurrentlyUsingUnsecureHttp');
132 $message .= " ";
133 $message .= Piwik::translate('General_ReadThisToLearnMore', ['<a rel="noreferrer noopener" target="_blank" href="' . Url::addCampaignParametersToMatomoLink('https://matomo.org/faq/how-to/faq_91/">'), '</a>']);
134 $notification = new Notification($message);
135 $notification->context = Notification::CONTEXT_WARNING;
136 $notification->raw = true;
137 Notification\Manager::notify('ControllerAdmin_HttpIsUsed', $notification);
138 }
139 private static function notifyIfDevelopmentModeOnButNotInstalledThroughGit()
140 {
141 if (!Piwik::hasUserSuperUserAccess()) {
142 return;
143 }
144 if (!Development::isEnabled()) {
145 return;
146 }
147 if (SettingsPiwik::isGitDeployment()) {
148 return;
149 }
150 $message = Piwik::translate('General_WarningDevelopmentModeOnButNotGitInstalled');
151 $notification = new Notification($message);
152 $notification->context = Notification::CONTEXT_WARNING;
153 $notification->raw = true;
154 $notification->flags = Notification::FLAG_CLEAR;
155 Notification\Manager::notify('ControllerAdmin_DevelopmentModeOn', $notification);
156 }
157 /**
158 * @ignore
159 */
160 public static function displayWarningIfConfigFileNotWritable()
161 {
162 $isConfigFileWritable = PiwikConfig::getInstance()->isFileWritable();
163 if (!$isConfigFileWritable) {
164 $exception = PiwikConfig::getInstance()->getConfigNotWritableException();
165 $message = $exception->getMessage();
166 $notification = new Notification($message);
167 $notification->raw = true;
168 $notification->context = Notification::CONTEXT_WARNING;
169 Notification\Manager::notify('ControllerAdmin_ConfigNotWriteable', $notification);
170 }
171 }
172 private static function notifyIfEAcceleratorIsUsed()
173 {
174 $isEacceleratorUsed = ini_get('eaccelerator.enable');
175 if (empty($isEacceleratorUsed)) {
176 return;
177 }
178 $message = sprintf("You are using the PHP accelerator & optimizer eAccelerator which is known to be not compatible with Matomo.\n We have disabled eAccelerator, which might affect the performance of Matomo.\n Read the %srelated ticket%s for more information and how to fix this problem.", '<a rel="noreferrer noopener" target="_blank" href="https://github.com/matomo-org/matomo/issues/4439">', '</a>');
179 $notification = new Notification($message);
180 $notification->context = Notification::CONTEXT_WARNING;
181 $notification->raw = true;
182 Notification\Manager::notify('ControllerAdmin_EacceleratorIsUsed', $notification);
183 }
184 /**
185 * PHP Version required by the next major Matomo version
186 * @return string
187 */
188 private static function getNextRequiredMinimumPHP()
189 {
190 return '7.2';
191 }
192 private static function isUsingPhpVersionCompatibleWithNextPiwik()
193 {
194 return version_compare(PHP_VERSION, self::getNextRequiredMinimumPHP(), '>=');
195 }
196 private static function notifyWhenPhpVersionIsNotCompatibleWithNextMajorPiwik()
197 {
198 if (self::isUsingPhpVersionCompatibleWithNextPiwik()) {
199 return;
200 }
201 $youMustUpgradePHP = Piwik::translate('General_YouMustUpgradePhpVersionToReceiveLatestPiwik');
202 $message = Piwik::translate('General_PiwikCannotBeUpgradedBecausePhpIsTooOld') . ' ' . sprintf(Piwik::translate('General_PleaseUpgradeYourPhpVersionSoYourPiwikDataStaysSecure'), self::getNextRequiredMinimumPHP());
203 $notification = new Notification($message);
204 $notification->title = $youMustUpgradePHP;
205 $notification->priority = Notification::PRIORITY_LOW;
206 $notification->context = Notification::CONTEXT_WARNING;
207 $notification->type = Notification::TYPE_TRANSIENT;
208 $notification->flags = Notification::FLAG_NO_CLEAR;
209 NotificationManager::notify('PHPVersionTooOldForNewestPiwikCheck', $notification);
210 }
211 private static function notifyWhenPhpVersionIsEOL()
212 {
213 if (defined('PIWIK_TEST_MODE')) {
214 // to avoid changing every admin UI test
215 return;
216 }
217 $notifyPhpIsEOL = Piwik::hasUserSuperUserAccess() && self::isPhpVersionEOL();
218 if (!$notifyPhpIsEOL) {
219 return;
220 }
221 $deprecatedMajorPhpVersion = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
222 $message = '';
223 if (version_compare(PHP_VERSION, self::getNextRequiredMinimumPHP(), '<')) {
224 $message = Piwik::translate('General_WarningPiwikWillStopSupportingPHPVersion', [$deprecatedMajorPhpVersion, self::getNextRequiredMinimumPHP()]) . '<br/>';
225 }
226 $message .= Piwik::translate('General_WarningPhpVersionXIsTooOld', $deprecatedMajorPhpVersion);
227 $notification = new Notification($message);
228 $notification->raw = true;
229 $notification->title = Piwik::translate('General_Warning');
230 $notification->priority = Notification::PRIORITY_LOW;
231 $notification->context = Notification::CONTEXT_WARNING;
232 $notification->type = Notification::TYPE_TRANSIENT;
233 $notification->flags = Notification::FLAG_NO_CLEAR;
234 NotificationManager::notify('PHPVersionCheck', $notification);
235 }
236 private static function notifyWhenDebugOnDemandIsEnabled($trackerSetting)
237 {
238 if (!Development::isEnabled() && Piwik::hasUserSuperUserAccess() && TrackerConfig::getConfigValue($trackerSetting)) {
239 $message = Piwik::translate('General_WarningDebugOnDemandEnabled');
240 $message = sprintf($message, '"' . $trackerSetting . '"', '"[Tracker] ' . $trackerSetting . '"', '"0"', '"config/config.ini.php"');
241 $notification = new Notification($message);
242 $notification->title = Piwik::translate('General_Warning');
243 $notification->priority = Notification::PRIORITY_LOW;
244 $notification->context = Notification::CONTEXT_WARNING;
245 $notification->type = Notification::TYPE_TRANSIENT;
246 $notification->flags = Notification::FLAG_NO_CLEAR;
247 NotificationManager::notify('Tracker' . $trackerSetting, $notification);
248 }
249 }
250 /**
251 * Assigns view properties that would be useful to views that render admin pages.
252 *
253 * Assigns the following variables:
254 *
255 * - **statisticsNotRecorded** - Set to true if the `[Tracker] record_statistics` INI
256 * config is `0`. If not `0`, this variable will not be defined.
257 * - **topMenu** - The result of `MenuTop::getInstance()->getMenu()`.
258 * - **enableFrames** - The value of the `[General] enable_framed_pages` INI config option. If
259 * true, {@link Piwik\View::setXFrameOptions()} is called on the view.
260 * - **isSuperUser** - Whether the current user is a superuser or not.
261 * - **usingOldGeoIPPlugin** - Whether this Piwik install is currently using the old GeoIP
262 * plugin or not.
263 * - **invalidPluginsWarning** - Set if some of the plugins to load (determined by INI configuration)
264 * are invalid or missing.
265 * - **phpVersion** - The current PHP version.
266 * - **phpIsNewEnough** - Whether the current PHP version is new enough to run Piwik.
267 * - **adminMenu** - The result of `MenuAdmin::getInstance()->getMenu()`.
268 *
269 * @param View $view
270 * @api
271 */
272 public static function setBasicVariablesAdminView(View $view)
273 {
274 self::notifyWhenTrackingStatisticsDisabled();
275 self::notifyIfEAcceleratorIsUsed();
276 self::notifyIfURLIsNotSecure();
277 self::notifyIfDevelopmentModeOnButNotInstalledThroughGit();
278 $view->topMenu = MenuTop::getInstance()->getMenu();
279 $view->isDataPurgeSettingsEnabled = self::isDataPurgeSettingsEnabled();
280 $enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings'];
281 $view->enableFrames = $enableFrames;
282 if (!$enableFrames) {
283 $view->setXFrameOptions('sameorigin');
284 }
285 $view->isSuperUser = Piwik::hasUserSuperUserAccess();
286 self::notifyAnyInvalidLicense();
287 self::notifyAnyInvalidPlugin();
288 self::notifyWhenPhpVersionIsEOL();
289 self::notifyWhenPhpVersionIsNotCompatibleWithNextMajorPiwik();
290 self::notifyWhenDebugOnDemandIsEnabled('debug');
291 self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand');
292 /**
293 * Posted when rendering an admin page and notifications about any warnings or errors should be triggered.
294 * You can use it for example when you have a plugin that needs to be configured in order to work and the
295 * plugin has not been configured yet. It can be also used to cancel / remove other notifications by calling
296 * eg `Notification\Manager::cancel($notificationId)`.
297 *
298 * **Example**
299 *
300 * public function onTriggerAdminNotifications(Piwik\Widget\WidgetsList $list)
301 * {
302 * if ($pluginFooIsNotConfigured) {
303 * $notification = new Notification('The plugin foo has not been configured yet');
304 * $notification->context = Notification::CONTEXT_WARNING;
305 * Notification\Manager::notify('fooNotConfigured', $notification);
306 * }
307 * }
308 *
309 */
310 Piwik::postEvent('Controller.triggerAdminNotifications');
311 $view->adminMenu = MenuAdmin::getInstance()->getMenu();
312 $notifications = $view->notifications;
313 if (empty($notifications)) {
314 $view->notifications = NotificationManager::getAllNotificationsToDisplay();
315 NotificationManager::cancelAllNonPersistent();
316 }
317 }
318 public static function isDataPurgeSettingsEnabled()
319 {
320 return (bool) Config::getInstance()->General['enable_delete_old_data_settings_admin'];
321 }
322 protected static function getPiwikVersion()
323 {
324 return "Matomo " . Version::VERSION;
325 }
326 private static function isPhpVersionEOL()
327 {
328 $phpEOL = '7.3';
329 // End of security update for certain PHP versions as of https://www.php.net/supported-versions.php
330 if (Date::today()->isLater(Date::factory('2022-11-28'))) {
331 $phpEOL = '7.4';
332 }
333 if (Date::today()->isLater(Date::factory('2023-11-26'))) {
334 $phpEOL = '8.0';
335 }
336 if (Date::today()->isLater(Date::factory('2024-11-25'))) {
337 $phpEOL = '8.1';
338 }
339 return version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, $phpEOL, '<=');
340 }
341 }
342