PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.13.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.13.3
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 3 years ago Handler 5 years ago TableLogAction 5 years ago Visit 5 years ago Action.php 4 years ago ActionPageview.php 5 years ago Cache.php 4 years ago Db.php 4 years ago Failures.php 4 years ago FingerprintSalt.php 4 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 3 years ago Request.php 3 years ago RequestProcessor.php 5 years ago RequestSet.php 4 years ago Response.php 4 years ago ScheduledTasksRunner.php 5 years ago Settings.php 3 years ago TableLogAction.php 5 years ago TrackerCodeGenerator.php 3 years ago TrackerConfig.php 3 years ago Visit.php 4 years ago VisitExcluded.php 3 years ago VisitInterface.php 5 years ago Visitor.php 5 years ago VisitorNotFoundInDb.php 5 years ago VisitorRecognizer.php 4 years ago
RequestSet.php
212 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 $this->requests[] = $request;
49 }
50 }
51
52 public function setTokenAuth($tokenAuth)
53 {
54 $this->tokenAuth = $tokenAuth;
55 }
56
57 public function getNumberOfRequests()
58 {
59 if (is_array($this->requests)) {
60 return count($this->requests);
61 }
62
63 return 0;
64 }
65
66 public function getRequests()
67 {
68 if (!$this->areRequestsInitialized()) {
69 return array();
70 }
71
72 return $this->requests;
73 }
74
75 public function getTokenAuth()
76 {
77 if (!is_null($this->tokenAuth)) {
78 return $this->tokenAuth;
79 }
80
81 return Common::getRequestVar('token_auth', false);
82 }
83
84 private function areRequestsInitialized()
85 {
86 return !is_null($this->requests);
87 }
88
89 public function initRequestsAndTokenAuth()
90 {
91 if ($this->areRequestsInitialized()) {
92 return;
93 }
94
95 /**
96 * Triggered when detecting tracking requests. A plugin can use this event to set
97 * requests that should be tracked by calling the {@link RequestSet::setRequests()} method.
98 * For example the BulkTracking plugin uses this event to detect tracking requests and auth token based on
99 * a sent JSON instead of default $_GET+$_POST. It would allow you for example to track requests based on
100 * XML or you could import tracking requests stored in a file.
101 *
102 * @param \Piwik\Tracker\RequestSet &$requestSet Call {@link setRequests()} to initialize requests and
103 * {@link setTokenAuth()} to set a detected auth token.
104 *
105 * @ignore This event is not public yet as the RequestSet API is not really stable yet
106 */
107 Piwik::postEvent('Tracker.initRequestSet', array($this));
108
109 if (!$this->areRequestsInitialized()) {
110 $this->requests = array();
111
112 if (!empty($_GET) || !empty($_POST)) {
113 $this->setRequests(array($_GET + $_POST));
114 }
115 }
116 }
117
118 public function hasRequests()
119 {
120 return !empty($this->requests);
121 }
122
123 protected function getAllSiteIdsWithinRequest()
124 {
125 if (empty($this->requests)) {
126 return array();
127 }
128
129 $siteIds = array();
130 foreach ($this->requests as $request) {
131 $siteIds[] = (int) $request->getIdSite();
132 }
133
134 return array_values(array_unique($siteIds));
135 }
136
137 public function getState()
138 {
139 $requests = array(
140 'requests' => array(),
141 'env' => $this->getEnvironment(),
142 'tokenAuth' => $this->getTokenAuth(),
143 'time' => time()
144 );
145
146 foreach ($this->getRequests() as $request) {
147 $requests['requests'][] = $request->getRawParams();
148 }
149
150 return $requests;
151 }
152
153 public function restoreState($state)
154 {
155 $backupEnv = $this->getCurrentEnvironment();
156
157 $this->setEnvironment($state['env']);
158 $this->setTokenAuth($state['tokenAuth']);
159
160 $this->restoreEnvironment();
161 $this->setRequests($state['requests']);
162
163 foreach ($this->getRequests() as $request) {
164 $request->setCurrentTimestamp($state['time']);
165 }
166
167 $this->resetEnvironment($backupEnv);
168 }
169
170 public function rememberEnvironment()
171 {
172 $this->setEnvironment($this->getEnvironment());
173 }
174
175 public function setEnvironment($env)
176 {
177 $this->env = $env;
178 }
179
180 protected function getEnvironment()
181 {
182 if (!empty($this->env)) {
183 return $this->env;
184 }
185
186 return $this->getCurrentEnvironment();
187 }
188
189 public function restoreEnvironment()
190 {
191 if (empty($this->env)) {
192 return;
193 }
194
195 $this->resetEnvironment($this->env);
196 }
197
198 private function resetEnvironment($env)
199 {
200 $_SERVER = $env['server'];
201 $_COOKIE = isset($env['cookie']) ? $env['cookie'] : array();
202 }
203
204 private function getCurrentEnvironment()
205 {
206 return array(
207 'server' => $_SERVER,
208 'cookie' => $_COOKIE
209 );
210 }
211 }
212