blob: c05f5dc5135aaa969fc2caafbb872219e263ae71 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\BulkTracking;
use Piwik\Plugins\BulkTracking\Tracker\Handler;
use Piwik\Plugins\BulkTracking\Tracker\Requests;
use Piwik\Tracker\RequestSet;
class BulkTracking extends \Piwik\Plugin
{
/**
* @var Requests
*/
private $requests;
/**
* @see Piwik\Plugin::registerEvents
*/
public function registerEvents()
{
return array(
'Tracker.newHandler' => 'setHandlerIfBulkRequest',
'Tracker.initRequestSet' => 'initRequestSet',
);
}
public function setRequests(Requests $requests)
{
$this->requests = $requests;
}
public function initRequestSet(RequestSet $requestSet)
{
if ($this->isUsingBulkRequest()) {
$bulk = $this->buildBulkRequests();
list($requests, $token) = $bulk->initRequestsAndTokenAuth($bulk->getRawBulkRequest());
if ($bulk->requiresAuthentication()) {
$bulk->authenticateRequests($requests);
}
if (!$requestSet->getTokenAuth()) {
$requestSet->setTokenAuth($token);
}
$requestSet->setRequests($requests);
}
}
public function setHandlerIfBulkRequest(&$handler)
{
if (!is_null($handler)) {
return;
}
if ($this->isUsingBulkRequest()) {
$handler = new Handler();
}
}
private function isUsingBulkRequest()
{
$requests = $this->buildBulkRequests();
$rawData = $requests->getRawBulkRequest();
return $requests->isUsingBulkRequest($rawData);
}
private function buildBulkRequests()
{
if (!is_null($this->requests)) {
return $this->requests;
}
return new Requests();
}
}
|