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