update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* Piwik - Open source web analytics
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
@ -10,25 +10,27 @@ namespace Piwik\Plugin;
use Piwik\Config as PiwikConfig;
use Piwik\Config;
use Piwik\Development;
use Piwik\Menu\MenuAdmin;
use Piwik\Menu\MenuTop;
use Piwik\Menu\MenuUser;
use Piwik\Notification;
use Piwik\Notification\Manager as NotificationManager;
use Piwik\Piwik;
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 $isEacceleratorUsed = false;
private static function notifyWhenTrackingStatisticsDisabled()
{
$statsEnabled = PiwikConfig::getInstance()->Tracker['record_statistics'];
@ -42,6 +44,7 @@ abstract class ControllerAdmin extends Controller
private static function notifyAnyInvalidPlugin()
{
$missingPlugins = \Piwik\Plugin\Manager::getInstance()->getMissingPlugins();
if (empty($missingPlugins)) {
return;
}
@ -49,12 +52,15 @@ abstract class ControllerAdmin extends Controller
if (!Piwik::hasUserSuperUserAccess()) {
return;
}
$pluginsLink = Url::getCurrentQueryStringWithParametersModified(array(
'module' => 'CorePluginsAdmin', 'action' => 'plugins'
));
$invalidPluginsWarning = Piwik::translate('CoreAdminHome_InvalidPluginsWarning', array(
self::getPiwikVersion(),
'<strong>' . implode('</strong>,&nbsp;<strong>', $missingPlugins) . '</strong>'))
. "<br/>"
. Piwik::translate('CoreAdminHome_InvalidPluginsYouCanUninstall', array(
'<a href="' . $pluginsLink . '"/>',
'</a>'
@ -63,7 +69,7 @@ abstract class ControllerAdmin extends Controller
$notification = new Notification($invalidPluginsWarning);
$notification->raw = true;
$notification->context = Notification::CONTEXT_WARNING;
$notification->title = Piwik::translate('General_Warning') . ':';
$notification->title = Piwik::translate('General_Warning');
Notification\Manager::notify('ControllerAdmin_InvalidPluginsWarning', $notification);
}
@ -81,10 +87,40 @@ abstract class ControllerAdmin extends Controller
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);
}
/**
* @ignore
*/
static public function displayWarningIfConfigFileNotWritable()
public static function displayWarningIfConfigFileNotWritable()
{
$isConfigFileWritable = PiwikConfig::getInstance()->isFileWritable();
@ -99,36 +135,69 @@ abstract class ControllerAdmin extends Controller
}
}
/**
* See http://dev.piwik.org/trac/ticket/4439#comment:8 and https://github.com/eaccelerator/eaccelerator/issues/12
*
* Eaccelerator does not support closures and is known to be not comptabile with Piwik. Therefore we are disabling
* it automatically. At this point it looks like Eaccelerator is no longer under development and the bug has not
* been fixed within a year.
*/
public static function disableEacceleratorIfEnabled()
{
$isEacceleratorUsed = ini_get('eaccelerator.enable');
if (!empty($isEacceleratorUsed)) {
self::$isEacceleratorUsed = true;
@ini_set('eaccelerator.enable', 0);
}
}
private static function notifyIfEAcceleratorIsUsed()
{
if (self::$isEacceleratorUsed) {
$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 target="_blank" href="http://dev.piwik.org/trac/ticket/4439">', '</a>');
$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>');
$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;
}
$nextRequiredMinimumPHP = '5.5';
$message = Piwik::translate('General_WarningPiwikWillStopSupportingPHPVersion', array($deprecatedMajorPhpVersion, $nextRequiredMinimumPHP))
. "\n "
. 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;
NotificationManager::notify('DeprecatedPHPVersionCheck', $notification);
}
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"',
'"config/config.ini.php"');
$notification = new Notification($message);
$notification->title = Piwik::translate('General_Warning');
$notification->priority = Notification::PRIORITY_LOW;
$notification->context = Notification::CONTEXT_WARNING;
$notification->raw = true;
Notification\Manager::notify('ControllerAdmin_EacceleratorIsUsed', $notification);
$notification->type = Notification::TYPE_TRANSIENT;
$notification->flags = Notification::FLAG_NO_CLEAR;
NotificationManager::notify('Tracker' . $trackerSetting, $notification);
}
}
@ -140,7 +209,6 @@ abstract class ControllerAdmin extends Controller
* - **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()`.
* - **currentAdminMenuName** - The currently selected admin menu name.
* - **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.
@ -155,17 +223,20 @@ abstract class ControllerAdmin extends Controller
* @param View $view
* @api
*/
static public function setBasicVariablesAdminView(View $view)
public static function setBasicVariablesAdminView(View $view)
{
self::notifyWhenTrackingStatisticsDisabled();
self::notifyIfEAcceleratorIsUsed();
self::notifyIfURLIsNotSecure();
$view->topMenu = MenuTop::getInstance()->getMenu();
$view->currentAdminMenuName = MenuAdmin::getInstance()->getCurrentAdminMenuName();
$view->topMenu = MenuTop::getInstance()->getMenu();
$view->userMenu = MenuUser::getInstance()->getMenu();
$view->isDataPurgeSettingsEnabled = self::isDataPurgeSettingsEnabled();
$view->enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings'];
if (!$view->enableFrames) {
$enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings'];
$view->enableFrames = $enableFrames;
if (!$enableFrames) {
$view->setXFrameOptions('sameorigin');
}
@ -175,19 +246,27 @@ abstract class ControllerAdmin extends Controller
self::checkPhpVersion($view);
self::notifyWhenPhpVersionIsEOL();
self::notifyWhenDebugOnDemandIsEnabled('debug');
self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand');
$adminMenu = MenuAdmin::getInstance()->getMenu();
$view->adminMenu = $adminMenu;
$view->notifications = NotificationManager::getAllNotificationsToDisplay();
NotificationManager::cancelAllNonPersistent();
$notifications = $view->notifications;
if (empty($notifications)) {
$view->notifications = NotificationManager::getAllNotificationsToDisplay();
NotificationManager::cancelAllNonPersistent();
}
}
static public function isDataPurgeSettingsEnabled()
public static function isDataPurgeSettingsEnabled()
{
return (bool) Config::getInstance()->General['enable_delete_old_data_settings_admin'];
}
static protected function getPiwikVersion()
protected static function getPiwikVersion()
{
return "Piwik " . Version::VERSION;
}
@ -202,12 +281,13 @@ abstract class ControllerAdmin extends Controller
$view->phpIsNewEnough = version_compare($view->phpVersion, '5.3.0', '>=');
}
protected function getDefaultWebsiteId()
private static function isPhpVersion53()
{
$sitesId = \Piwik\Plugins\SitesManager\API::getInstance()->getSitesIdWithAdminAccess();
if (!empty($sitesId)) {
return $sitesId[0];
}
return parent::getDefaultWebsiteId();
return strpos(PHP_VERSION, '5.3') === 0;
}
private static function isPhpVersion54()
{
return strpos(PHP_VERSION, '5.4') === 0;
}
}