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
@ -14,37 +14,35 @@ use Piwik\Tracker\Request;
/**
* Excludes visits where user agent's request contains either:
*
*
* - X-Do-Not-Track header (used by AdBlockPlus and NoScript)
* - DNT header (used by Mozilla)
*
*
* Note: visits from Internet Explorer and other browsers that have DoNoTrack enabled by default will be tracked anyway.
*/
class DoNotTrackHeaderChecker
{
/**
* @param Config $config
*/
public function __construct($config = null)
{
$this->config = $config ?: new Config();
}
/**
* Checks for DoNotTrack headers and if found, sets `$exclude` to `true`.
*/
public function checkHeaderInTracker(&$exclude)
{
if (!$this->isActive()
|| $exclude
) {
if ($exclude) {
Common::printDebug("Visit is already excluded, no need to check DoNotTrack support.");
return;
}
if ((isset($_SERVER['HTTP_X_DO_NOT_TRACK']) && $_SERVER['HTTP_X_DO_NOT_TRACK'] === '1')
|| (isset($_SERVER['HTTP_DNT']) && substr($_SERVER['HTTP_DNT'], 0, 1) === '1')
) {
$request = new Request($_REQUEST);
$ua = $request->getUserAgent();
if (strpos($ua, 'MSIE 10') !== false
|| strpos($ua, 'Trident/7') !== false) {
Common::printDebug("INTERNET EXPLORER 10 and 11 enable DoNotTrack by default; so Piwik ignores DNT for all IE10 + IE11 browsers...");
return;
}
$exclude = $this->isDoNotTrackFound();
$exclude = true;
Common::printDebug("DoNotTrack found.");
if($exclude) {
$trackingCookie = IgnoreCookie::getTrackingCookie();
$trackingCookie->delete();
@ -56,22 +54,47 @@ class DoNotTrackHeaderChecker
}
}
/**
* @return bool
*/
public function isDoNotTrackFound()
{
if (!$this->isActive()) {
Common::printDebug("DoNotTrack support is not enabled, skip check");
return false;
}
if (!$this->isHeaderDntFound()) {
Common::printDebug("DoNotTrack header not found");
return false;
}
$request = new Request($_REQUEST);
$userAgent = $request->getUserAgent();
if ($this->isUserAgentWithDoNotTrackAlwaysEnabled($userAgent)) {
Common::printDebug("INTERNET EXPLORER enable DoNotTrack by default; so Piwik ignores DNT IE browsers...");
return false;
}
Common::printDebug("DoNotTrack header found!");
return true;
}
/**
* Deactivates DoNotTrack header checking. This function will not be called by the Tracker.
*/
public static function deactivate()
public function deactivate()
{
$config = new Config();
$config->doNotTrackEnabled = false;
$this->config->doNotTrackEnabled = false;
}
/**
* Activates DoNotTrack header checking. This function will not be called by the Tracker.
*/
public static function activate()
public function activate()
{
$config = new Config();
$config->doNotTrackEnabled = true;
$this->config->doNotTrackEnabled = true;
}
/**
@ -79,9 +102,53 @@ class DoNotTrackHeaderChecker
*
* @return bool
*/
public static function isActive()
public function isActive()
{
$config = new Config();
return $config->doNotTrackEnabled;
return $this->config->doNotTrackEnabled;
}
/**
* @return bool
*/
protected function isHeaderDntFound()
{
return (isset($_SERVER['HTTP_X_DO_NOT_TRACK']) && $_SERVER['HTTP_X_DO_NOT_TRACK'] === '1')
|| (isset($_SERVER['HTTP_DNT']) && substr($_SERVER['HTTP_DNT'], 0, 1) === '1');
}
/**
*
* @param $userAgent
* @return bool
*/
protected function isUserAgentWithDoNotTrackAlwaysEnabled($userAgent)
{
$browsersWithDnt = $this->getBrowsersWithDNTAlwaysEnabled();
foreach($browsersWithDnt as $userAgentBrowserFragment) {
if (stripos($userAgent, $userAgentBrowserFragment) !== false) {
return true;
}
}
return false;
}
/**
* Some browsers have DNT enabled by default. For those we will ignore DNT and always track those users.
*
* @return array
*/
protected function getBrowsersWithDNTAlwaysEnabled()
{
return array(
// IE
'MSIE',
'Trident',
// Maxthon
'Maxthon',
// Epiphany - https://github.com/piwik/piwik/issues/8682
'Epiphany',
);
}
}