PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.6.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.6.0
5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Tracker / RequestSet.php
matomo / app / core / Tracker Last commit date
Db 4 years ago Handler 5 years ago TableLogAction 5 years ago Visit 5 years ago Action.php 5 years ago ActionPageview.php 5 years ago Cache.php 5 years ago Db.php 4 years ago Failures.php 4 years ago FingerprintSalt.php 6 years ago GoalManager.php 4 years ago Handler.php 5 years ago IgnoreCookie.php 4 years ago LogTable.php 5 years ago Model.php 5 years ago PageUrl.php 4 years ago Request.php 4 years ago RequestProcessor.php 5 years ago RequestSet.php 4 years ago Response.php 4 years ago ScheduledTasksRunner.php 5 years ago Settings.php 5 years ago TableLogAction.php 5 years ago TrackerCodeGenerator.php 4 years ago TrackerConfig.php 4 years ago Visit.php 4 years ago VisitExcluded.php 5 years ago VisitInterface.php 5 years ago Visitor.php 5 years ago VisitorNotFoundInDb.php 5 years ago VisitorRecognizer.php 4 years ago
RequestSet.php
213 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9 namespace Piwik\Tracker;
10
11 use Piwik\Common;
12 use Piwik\Piwik;
13
14 class RequestSet
15 {
16 /**
17 * The set of visits to track.
18 *
19 * @var Request[]
20 */
21 private $requests = null;
22
23 /**
24 * The token auth supplied with a bulk visits POST.
25 *
26 * @var string
27 */
28 private $tokenAuth = null;
29
30 private $env = array();
31
32 public function setRequests($requests)
33 {
34 $this->requests = array();
35
36 if (empty($requests)|| !is_array($requests)) {
37 return;
38 }
39
40 foreach ($requests as $request) {
41 if (empty($request) && !is_array($request)) {
42 continue;
43 }
44
45 if (!$request instanceof Request) {
46 $request = new Request($request, $this->getTokenAuth());
47 }
48
49 $this->requests[] = $request;
50 }
51 }
52
53 public function setTokenAuth($tokenAuth)
54 {
55 $this->tokenAuth = $tokenAuth;
56 }
57
58 public function getNumberOfRequests()
59 {
60 if (is_array($this->requests)) {
61 return count($this->requests);
62 }
63
64 return 0;
65 }
66
67 public function getRequests()
68 {
69 if (!$this->areRequestsInitialized()) {
70 return array();
71 }
72
73 return $this->requests;
74 }
75
76 public function getTokenAuth()
77 {
78 if (!is_null($this->tokenAuth)) {
79 return $this->tokenAuth;
80 }
81
82 return Common::getRequestVar('token_auth', false);
83 }
84
85 private function areRequestsInitialized()
86 {
87 return !is_null($this->requests);
88 }
89
90 public function initRequestsAndTokenAuth()
91 {
92 if ($this->areRequestsInitialized()) {
93 return;
94 }
95
96 /**
97 * Triggered when detecting tracking requests. A plugin can use this event to set
98 * requests that should be tracked by calling the {@link RequestSet::setRequests()} method.
99 * For example the BulkTracking plugin uses this event to detect tracking requests and auth token based on
100 * a sent JSON instead of default $_GET+$_POST. It would allow you for example to track requests based on
101 * XML or you could import tracking requests stored in a file.
102 *
103 * @param \Piwik\Tracker\RequestSet &$requestSet Call {@link setRequests()} to initialize requests and
104 * {@link setTokenAuth()} to set a detected auth token.
105 *
106 * @ignore This event is not public yet as the RequestSet API is not really stable yet
107 */
108 Piwik::postEvent('Tracker.initRequestSet', array($this));
109
110 if (!$this->areRequestsInitialized()) {
111 $this->requests = array();
112
113 if (!empty($_GET) || !empty($_POST)) {
114 $this->setRequests(array($_GET + $_POST));
115 }
116 }
117 }
118
119 public function hasRequests()
120 {
121 return !empty($this->requests);
122 }
123
124 protected function getAllSiteIdsWithinRequest()
125 {
126 if (empty($this->requests)) {
127 return array();
128 }
129
130 $siteIds = array();
131 foreach ($this->requests as $request) {
132 $siteIds[] = (int) $request->getIdSite();
133 }
134
135 return array_values(array_unique($siteIds));
136 }
137
138 public function getState()
139 {
140 $requests = array(
141 'requests' => array(),
142 'env' => $this->getEnvironment(),
143 'tokenAuth' => $this->getTokenAuth(),
144 'time' => time()
145 );
146
147 foreach ($this->getRequests() as $request) {
148 $requests['requests'][] = $request->getRawParams();
149 }
150
151 return $requests;
152 }
153
154 public function restoreState($state)
155 {
156 $backupEnv = $this->getCurrentEnvironment();
157
158 $this->setEnvironment($state['env']);
159 $this->setTokenAuth($state['tokenAuth']);
160
161 $this->restoreEnvironment();
162 $this->setRequests($state['requests']);
163
164 foreach ($this->getRequests() as $request) {
165 $request->setCurrentTimestamp($state['time']);
166 }
167
168 $this->resetEnvironment($backupEnv);
169 }
170
171 public function rememberEnvironment()
172 {
173 $this->setEnvironment($this->getEnvironment());
174 }
175
176 public function setEnvironment($env)
177 {
178 $this->env = $env;
179 }
180
181 protected function getEnvironment()
182 {
183 if (!empty($this->env)) {
184 return $this->env;
185 }
186
187 return $this->getCurrentEnvironment();
188 }
189
190 public function restoreEnvironment()
191 {
192 if (empty($this->env)) {
193 return;
194 }
195
196 $this->resetEnvironment($this->env);
197 }
198
199 private function resetEnvironment($env)
200 {
201 $_SERVER = $env['server'];
202 $_COOKIE = isset($env['cookie']) ? $env['cookie'] : array();
203 }
204
205 private function getCurrentEnvironment()
206 {
207 return array(
208 'server' => $_SERVER,
209 'cookie' => $_COOKIE
210 );
211 }
212 }
213