Newer
Older
<?php
/**
* Piwik - free/libre analytics platform
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
use Piwik\Menu\MenuAdmin;
use Piwik\Menu\MenuTop;
use Piwik\Notification\Manager as NotificationManager;
use Piwik\Tracker\TrackerConfig;
use Piwik\Url;
use Piwik\Version;
use Piwik\View;
use Piwik\ProxyHttp;
* Base class of plugin controllers that provide administrative functionality.
* See {@link Controller} to learn more about Piwik controllers.
abstract class ControllerAdmin extends Controller
private static function notifyWhenTrackingStatisticsDisabled()
{
$statsEnabled = PiwikConfig::getInstance()->Tracker['record_statistics'];
if ($statsEnabled == "0") {
$notification = new Notification(Piwik::translate('General_StatisticsAreNotRecorded'));
$notification->context = Notification::CONTEXT_INFO;
Notification\Manager::notify('ControllerAdmin_StatsAreNotRecorded', $notification);
}
}
private static function notifyAnyInvalidPlugin()
{
$missingPlugins = \Piwik\Plugin\Manager::getInstance()->getMissingPlugins();
Thomas Steur
a validé
if (empty($missingPlugins)) {
return;
}
Thomas Steur
a validé
if (!Piwik::hasUserSuperUserAccess()) {
Thomas Steur
a validé
$pluginsLink = Url::getCurrentQueryStringWithParametersModified(array(
'module' => 'CorePluginsAdmin', 'action' => 'plugins'
));
Thomas Steur
a validé
$invalidPluginsWarning = Piwik::translate('CoreAdminHome_InvalidPluginsWarning', array(
self::getPiwikVersion(),
'<strong>' . implode('</strong>, <strong>', $missingPlugins) . '</strong>'))
. Piwik::translate('CoreAdminHome_InvalidPluginsYouCanUninstall', array(
'<a href="' . $pluginsLink . '"/>',
'</a>'
));
$notification = new Notification($invalidPluginsWarning);
$notification->raw = true;
$notification->context = Notification::CONTEXT_WARNING;
Thomas Steur
a validé
$notification->title = Piwik::translate('General_Warning');
Notification\Manager::notify('ControllerAdmin_InvalidPluginsWarning', $notification);
}
* Calls {@link setBasicVariablesView()} and {@link setBasicVariablesAdminView()}
* @param View $view
*/
protected function setBasicVariablesView($view)
{
parent::setBasicVariablesView($view);
self::setBasicVariablesAdminView($view);
}
private static function notifyIfURLIsNotSecure()
{
$isURLSecure = ProxyHttp::isHttps();
if ($isURLSecure) {
return;
}
if (!Piwik::hasUserSuperUserAccess()) {
return;
}
if(Url::isLocalHost(Url::getCurrentHost())) {
return;
}
$message = Piwik::translate('General_CurrentlyUsingUnsecureHttp');
$message .= " ";
$message .= Piwik::translate('General_ReadThisToLearnMore',
array('<a rel="noreferrer" target="_blank" href="https://piwik.org/faq/how-to/faq_91/">', '</a>')
);
$notification = new Notification($message);
$notification->context = Notification::CONTEXT_WARNING;
$notification->raw = true;
Notification\Manager::notify('ControllerAdmin_HttpIsUsed', $notification);
}
public static function displayWarningIfConfigFileNotWritable()
$isConfigFileWritable = PiwikConfig::getInstance()->isFileWritable();
if (!$isConfigFileWritable) {
$exception = PiwikConfig::getInstance()->getConfigNotWritableException();
$message = $exception->getMessage();
$notification = new Notification($message);
$notification->raw = true;
$notification->context = Notification::CONTEXT_WARNING;
Notification\Manager::notify('ControllerAdmin_ConfigNotWriteable', $notification);
}
Thomas Steur
a validé
private static function notifyIfEAcceleratorIsUsed()
{
$isEacceleratorUsed = ini_get('eaccelerator.enable');
if (empty($isEacceleratorUsed)) {
return;
}
$message = sprintf("You are using the PHP accelerator & optimizer eAccelerator which is known to be not compatible with Piwik.
We have disabled eAccelerator, which might affect the performance of Piwik.
Read the %srelated ticket%s for more information and how to fix this problem.",
'<a rel="noreferrer" target="_blank" href="https://github.com/piwik/piwik/issues/4439">', '</a>');
Thomas Steur
a validé
$notification = new Notification($message);
$notification->context = Notification::CONTEXT_WARNING;
$notification->raw = true;
Notification\Manager::notify('ControllerAdmin_EacceleratorIsUsed', $notification);
}
private static function notifyWhenPhpVersionIsEOL()
{
$deprecatedMajorPhpVersion = null;
if(self::isPhpVersion53()) {
$deprecatedMajorPhpVersion = '5.3';
} elseif(self::isPhpVersion54()) {
$deprecatedMajorPhpVersion = '5.4';
}
$notifyPhpIsEOL = Piwik::hasUserSuperUserAccess() && $deprecatedMajorPhpVersion;
if (!$notifyPhpIsEOL) {
return;
Thomas Steur
a validé
}
mattab
a validé
$nextRequiredMinimumPHP = '5.5';
$message = Piwik::translate('General_WarningPiwikWillStopSupportingPHPVersion', array($deprecatedMajorPhpVersion, $nextRequiredMinimumPHP))
. Piwik::translate('General_WarningPhpVersionXIsTooOld', $deprecatedMajorPhpVersion);
$notification = new Notification($message);
$notification->title = Piwik::translate('General_Warning');
$notification->priority = Notification::PRIORITY_LOW;
$notification->context = Notification::CONTEXT_WARNING;
$notification->type = Notification::TYPE_TRANSIENT;
$notification->flags = Notification::FLAG_NO_CLEAR;
mattab
a validé
NotificationManager::notify('DeprecatedPHPVersionCheck', $notification);
Thomas Steur
a validé
}
private static function notifyWhenDebugOnDemandIsEnabled($trackerSetting)
{
if (!Development::isEnabled()
&& Piwik::hasUserSuperUserAccess() &&
TrackerConfig::getConfigValue($trackerSetting)) {
$message = Piwik::translate('General_WarningDebugOnDemandEnabled');
$message = sprintf($message, '"' . $trackerSetting . '"', '"[Tracker] ' . $trackerSetting . '"', '"0"',
$notification = new Notification($message);
$notification->title = Piwik::translate('General_Warning');
$notification->priority = Notification::PRIORITY_LOW;
$notification->context = Notification::CONTEXT_WARNING;
$notification->type = Notification::TYPE_TRANSIENT;
$notification->flags = Notification::FLAG_NO_CLEAR;
NotificationManager::notify('Tracker' . $trackerSetting, $notification);
* Assigns view properties that would be useful to views that render admin pages.
* - **statisticsNotRecorded** - Set to true if the `[Tracker] record_statistics` INI
* config is `0`. If not `0`, this variable will not be defined.
* - **topMenu** - The result of `MenuTop::getInstance()->getMenu()`.
* - **enableFrames** - The value of the `[General] enable_framed_pages` INI config option. If
* true, {@link Piwik\View::setXFrameOptions()} is called on the view.
* - **isSuperUser** - Whether the current user is a superuser or not.
* - **usingOldGeoIPPlugin** - Whether this Piwik install is currently using the old GeoIP
* plugin or not.
* - **invalidPluginsWarning** - Set if some of the plugins to load (determined by INI configuration)
* are invalid or missing.
* - **phpVersion** - The current PHP version.
* - **phpIsNewEnough** - Whether the current PHP version is new enough to run Piwik.
* - **adminMenu** - The result of `MenuAdmin::getInstance()->getMenu()`.
* @param View $view
* @api
*/
public static function setBasicVariablesAdminView(View $view)
self::notifyWhenTrackingStatisticsDisabled();
Thomas Steur
a validé
self::notifyIfEAcceleratorIsUsed();
self::notifyIfURLIsNotSecure();
$view->topMenu = MenuTop::getInstance()->getMenu();
$view->userMenu = MenuUser::getInstance()->getMenu();
$view->isDataPurgeSettingsEnabled = self::isDataPurgeSettingsEnabled();
Thomas Steur
a validé
$enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings'];
$view->enableFrames = $enableFrames;
if (!$enableFrames) {
$view->setXFrameOptions('sameorigin');
}
Thomas Steur
a validé
$view->isSuperUser = Piwik::hasUserSuperUserAccess();
self::notifyAnyInvalidPlugin();
diosmosis
a validé
self::checkPhpVersion($view);
self::notifyWhenPhpVersionIsEOL();
self::notifyWhenDebugOnDemandIsEnabled('debug');
self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand');
Thomas Steur
a validé
$adminMenu = MenuAdmin::getInstance()->getMenu();
$view->adminMenu = $adminMenu;
Thomas Steur
a validé
$notifications = $view->notifications;
Thomas Steur
a validé
Thomas Steur
a validé
if (empty($notifications)) {
$view->notifications = NotificationManager::getAllNotificationsToDisplay();
NotificationManager::cancelAllNonPersistent();
}
diosmosis
a validé
}
public static function isDataPurgeSettingsEnabled()
{
return (bool) Config::getInstance()->General['enable_delete_old_data_settings_admin'];
}
{
return "Piwik " . Version::VERSION;
}
diosmosis
a validé
/**
* Check if the current PHP version is >= 5.3. If not, a warning is displayed
* to the user.
*/
private static function checkPhpVersion($view)
{
$view->phpVersion = PHP_VERSION;
$view->phpIsNewEnough = version_compare($view->phpVersion, '5.3.0', '>=');
Thomas Steur
a validé
private static function isPhpVersion53()
{
return strpos(PHP_VERSION, '5.3') === 0;
}
mattab
a validé
private static function isPhpVersion54()
{
return strpos(PHP_VERSION, '5.4') === 0;
}