PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
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 6 years ago API.php 6 years ago AggregatedMetric.php 6 years ago ArchivedMetric.php 6 years ago Archiver.php 6 years ago Categories.php 6 years ago ComponentFactory.php 6 years ago ComputedMetric.php 6 years ago ConsoleCommand.php 6 years ago Controller.php 6 years ago ControllerAdmin.php 6 years ago Dependency.php 6 years ago LogTablesProvider.php 6 years ago Manager.php 6 years ago Menu.php 6 years ago MetadataLoader.php 6 years ago Metric.php 6 years ago PluginException.php 6 years ago ProcessedMetric.php 6 years ago ReleaseChannels.php 6 years ago Report.php 6 years ago ReportsProvider.php 6 years ago RequestProcessors.php 6 years ago Segment.php 6 years ago SettingsProvider.php 6 years ago Tasks.php 6 years ago ThemeStyles.php 6 years ago ViewDataTable.php 6 years ago Visualization.php 6 years ago WidgetsProvider.php 6 years ago
ControllerAdmin.php
364 lines
1 <?php
2 /**
3 * Piwik - 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 }
226
227 private static function notifyWhenPhpVersionIsEOL()
228 {
229 if (defined('PIWIK_TEST_MODE')) { // to avoid changing every admin UI test
230 return;
231 }
232
233 $notifyPhpIsEOL = Piwik::hasUserSuperUserAccess() && ! self::isPhpVersionAtLeast71();
234 if (!$notifyPhpIsEOL) {
235 return;
236 }
237
238 $deprecatedMajorPhpVersion = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
239 $message = Piwik::translate('General_WarningPiwikWillStopSupportingPHPVersion', array($deprecatedMajorPhpVersion, self::getNextRequiredMinimumPHP()))
240 . "<br/> "
241 . Piwik::translate('General_WarningPhpVersionXIsTooOld', $deprecatedMajorPhpVersion);
242
243 $notification = new Notification($message);
244 $notification->raw = true;
245 $notification->title = Piwik::translate('General_Warning');
246 $notification->priority = Notification::PRIORITY_LOW;
247 $notification->context = Notification::CONTEXT_WARNING;
248 $notification->type = Notification::TYPE_TRANSIENT;
249 $notification->flags = Notification::FLAG_NO_CLEAR;
250 NotificationManager::notify('PHP71VersionCheck', $notification);
251 }
252
253 private static function notifyWhenDebugOnDemandIsEnabled($trackerSetting)
254 {
255 if (!Development::isEnabled()
256 && Piwik::hasUserSuperUserAccess() &&
257 TrackerConfig::getConfigValue($trackerSetting)) {
258
259 $message = Piwik::translate('General_WarningDebugOnDemandEnabled');
260 $message = sprintf($message, '"' . $trackerSetting . '"', '"[Tracker] ' . $trackerSetting . '"', '"0"',
261 '"config/config.ini.php"');
262 $notification = new Notification($message);
263 $notification->title = Piwik::translate('General_Warning');
264 $notification->priority = Notification::PRIORITY_LOW;
265 $notification->context = Notification::CONTEXT_WARNING;
266 $notification->type = Notification::TYPE_TRANSIENT;
267 $notification->flags = Notification::FLAG_NO_CLEAR;
268 NotificationManager::notify('Tracker' . $trackerSetting, $notification);
269 }
270 }
271
272 /**
273 * Assigns view properties that would be useful to views that render admin pages.
274 *
275 * Assigns the following variables:
276 *
277 * - **statisticsNotRecorded** - Set to true if the `[Tracker] record_statistics` INI
278 * config is `0`. If not `0`, this variable will not be defined.
279 * - **topMenu** - The result of `MenuTop::getInstance()->getMenu()`.
280 * - **enableFrames** - The value of the `[General] enable_framed_pages` INI config option. If
281 * true, {@link Piwik\View::setXFrameOptions()} is called on the view.
282 * - **isSuperUser** - Whether the current user is a superuser or not.
283 * - **usingOldGeoIPPlugin** - Whether this Piwik install is currently using the old GeoIP
284 * plugin or not.
285 * - **invalidPluginsWarning** - Set if some of the plugins to load (determined by INI configuration)
286 * are invalid or missing.
287 * - **phpVersion** - The current PHP version.
288 * - **phpIsNewEnough** - Whether the current PHP version is new enough to run Piwik.
289 * - **adminMenu** - The result of `MenuAdmin::getInstance()->getMenu()`.
290 *
291 * @param View $view
292 * @api
293 */
294 public static function setBasicVariablesAdminView(View $view)
295 {
296 self::notifyWhenTrackingStatisticsDisabled();
297 self::notifyIfEAcceleratorIsUsed();
298 self::notifyIfURLIsNotSecure();
299
300 $view->topMenu = MenuTop::getInstance()->getMenu();
301
302 $view->isDataPurgeSettingsEnabled = self::isDataPurgeSettingsEnabled();
303 $enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings'];
304 $view->enableFrames = $enableFrames;
305
306 if (!$enableFrames) {
307 $view->setXFrameOptions('sameorigin');
308 }
309
310 $view->isSuperUser = Piwik::hasUserSuperUserAccess();
311
312 self::notifyAnyInvalidLicense();
313 self::notifyAnyInvalidPlugin();
314 self::notifyWhenPhpVersionIsEOL();
315 self::notifyWhenPhpVersionIsNotCompatibleWithNextMajorPiwik();
316 self::notifyWhenDebugOnDemandIsEnabled('debug');
317 self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand');
318
319 /**
320 * Posted when rendering an admin page and notifications about any warnings or errors should be triggered.
321 * You can use it for example when you have a plugin that needs to be configured in order to work and the
322 * plugin has not been configured yet. It can be also used to cancel / remove other notifications by calling
323 * eg `Notification\Manager::cancel($notificationId)`.
324 *
325 * **Example**
326 *
327 * public function onTriggerAdminNotifications(Piwik\Widget\WidgetsList $list)
328 * {
329 * if ($pluginFooIsNotConfigured) {
330 * $notification = new Notification('The plugin foo has not been configured yet');
331 * $notification->context = Notification::CONTEXT_WARNING;
332 * Notification\Manager::notify('fooNotConfigured', $notification);
333 * }
334 * }
335 *
336 */
337 Piwik::postEvent('Controller.triggerAdminNotifications');
338
339 $view->adminMenu = MenuAdmin::getInstance()->getMenu();
340
341 $notifications = $view->notifications;
342
343 if (empty($notifications)) {
344 $view->notifications = NotificationManager::getAllNotificationsToDisplay();
345 NotificationManager::cancelAllNonPersistent();
346 }
347 }
348
349 public static function isDataPurgeSettingsEnabled()
350 {
351 return (bool) Config::getInstance()->General['enable_delete_old_data_settings_admin'];
352 }
353
354 protected static function getPiwikVersion()
355 {
356 return "Matomo " . Version::VERSION;
357 }
358
359 private static function isPhpVersionAtLeast71()
360 {
361 return version_compare(PHP_VERSION, '7.1', '>=');
362 }
363 }
364