File: RequestProcessor.php

package info (click to toggle)
matomo 5.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,068 kB
  • sloc: php: 289,425; xml: 127,249; javascript: 112,130; python: 202; sh: 178; makefile: 20; sql: 10
file content (47 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\IntranetMeasurable\Tracker;

use Piwik\Container\StaticContainer;
use Piwik\Exception\UnexpectedWebsiteFoundException;
use Piwik\Plugins\IntranetMeasurable\Type;
use Piwik\Tracker\Cache;
use Piwik\Tracker\Request;

class RequestProcessor extends \Piwik\Tracker\RequestProcessor
{
    private $didEnableSetting = false;
    private $settingName = 'ini.Tracker.trust_visitors_cookies';

    public function manipulateRequest(Request $request)
    {
        try {
            $site = Cache::getCacheWebsiteAttributes($request->getIdSite());
        } catch (UnexpectedWebsiteFoundException $e) {
            return;
        }
        $isIntranetSite = !empty($site['type']) && $site['type'] === Type::ID;

        if ($isIntranetSite && !StaticContainer::get($this->settingName)) {
            $this->setTrustCookiesSetting(1);
            $this->didEnableSetting = true;
        } elseif ($this->didEnableSetting) {
            // we reset it in case of bulk tracking with different sites etc
            $this->setTrustCookiesSetting(0);
            $this->didEnableSetting = false;
        }
    }

    private function setTrustCookiesSetting($value)
    {
        StaticContainer::get('Piwik\Tracker\VisitorRecognizer')->setTrustCookiesOnly($value);
        StaticContainer::getContainer()->set($this->settingName, $value);
    }
}