PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.12.1 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 2 years ago Handler 2 years ago Visit 2 years ago Action.php 2 years ago ActionPageview.php 2 years ago Cache.php 2 years ago Db.php 2 years ago Failures.php 2 years ago FingerprintSalt.php 2 years ago GoalManager.php 2 years ago Handler.php 2 years ago IgnoreCookie.php 2 years ago LogTable.php 2 years ago Model.php 2 years ago PageUrl.php 2 years ago Request.php 2 years ago RequestProcessor.php 2 years ago RequestSet.php 2 years ago Response.php 2 years ago ScheduledTasksRunner.php 2 years ago Settings.php 2 years ago TableLogAction.php 2 years ago TrackerCodeGenerator.php 2 years ago TrackerConfig.php 2 years ago Visit.php 2 years ago VisitExcluded.php 2 years ago VisitInterface.php 2 years ago Visitor.php 2 years ago VisitorNotFoundInDb.php 2 years ago VisitorRecognizer.php 2 years ago
RequestSet.php
166 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\Tracker;
11
12 use Piwik\Common;
13 use Piwik\Piwik;
14 class RequestSet
15 {
16 /**
17 * The set of visits to track.
18 *
19 * @var Request[]
20 */
21 private $requests = null;
22 /**
23 * The token auth supplied with a bulk visits POST.
24 *
25 * @var string
26 */
27 private $tokenAuth = null;
28 private $env = array();
29 public function setRequests($requests)
30 {
31 $this->requests = array();
32 if (empty($requests) || !is_array($requests)) {
33 return;
34 }
35 foreach ($requests as $request) {
36 if (empty($request) && !is_array($request)) {
37 continue;
38 }
39 if (!$request instanceof \Piwik\Tracker\Request) {
40 $request = new \Piwik\Tracker\Request($request, $this->getTokenAuth());
41 }
42 $this->requests[] = $request;
43 }
44 }
45 public function setTokenAuth($tokenAuth)
46 {
47 $this->tokenAuth = $tokenAuth;
48 }
49 public function getNumberOfRequests()
50 {
51 if (is_array($this->requests)) {
52 return count($this->requests);
53 }
54 return 0;
55 }
56 public function getRequests()
57 {
58 if (!$this->areRequestsInitialized()) {
59 return array();
60 }
61 return $this->requests;
62 }
63 public function getTokenAuth()
64 {
65 if (!is_null($this->tokenAuth)) {
66 return $this->tokenAuth;
67 }
68 return Common::getRequestVar('token_auth', false);
69 }
70 private function areRequestsInitialized()
71 {
72 return !is_null($this->requests);
73 }
74 public function initRequestsAndTokenAuth()
75 {
76 if ($this->areRequestsInitialized()) {
77 return;
78 }
79 /**
80 * Triggered when detecting tracking requests. A plugin can use this event to set
81 * requests that should be tracked by calling the {@link RequestSet::setRequests()} method.
82 * For example the BulkTracking plugin uses this event to detect tracking requests and auth token based on
83 * a sent JSON instead of default $_GET+$_POST. It would allow you for example to track requests based on
84 * XML or you could import tracking requests stored in a file.
85 *
86 * @param \Piwik\Tracker\RequestSet &$requestSet Call {@link setRequests()} to initialize requests and
87 * {@link setTokenAuth()} to set a detected auth token.
88 *
89 * @ignore This event is not public yet as the RequestSet API is not really stable yet
90 */
91 Piwik::postEvent('Tracker.initRequestSet', array($this));
92 if (!$this->areRequestsInitialized()) {
93 $this->requests = array();
94 if (!empty($_GET) || !empty($_POST)) {
95 $this->setRequests(array($_GET + $_POST));
96 }
97 }
98 }
99 public function hasRequests()
100 {
101 return !empty($this->requests);
102 }
103 protected function getAllSiteIdsWithinRequest()
104 {
105 if (empty($this->requests)) {
106 return array();
107 }
108 $siteIds = array();
109 foreach ($this->requests as $request) {
110 $siteIds[] = (int) $request->getIdSite();
111 }
112 return array_values(array_unique($siteIds));
113 }
114 public function getState()
115 {
116 $requests = array('requests' => array(), 'env' => $this->getEnvironment(), 'tokenAuth' => $this->getTokenAuth(), 'time' => time());
117 foreach ($this->getRequests() as $request) {
118 $requests['requests'][] = $request->getRawParams();
119 }
120 return $requests;
121 }
122 public function restoreState($state)
123 {
124 $backupEnv = $this->getCurrentEnvironment();
125 $this->setEnvironment($state['env']);
126 $this->setTokenAuth($state['tokenAuth']);
127 $this->restoreEnvironment();
128 $this->setRequests($state['requests']);
129 foreach ($this->getRequests() as $request) {
130 $request->setCurrentTimestamp($state['time']);
131 }
132 $this->resetEnvironment($backupEnv);
133 }
134 public function rememberEnvironment()
135 {
136 $this->setEnvironment($this->getEnvironment());
137 }
138 public function setEnvironment($env)
139 {
140 $this->env = $env;
141 }
142 protected function getEnvironment()
143 {
144 if (!empty($this->env)) {
145 return $this->env;
146 }
147 return $this->getCurrentEnvironment();
148 }
149 public function restoreEnvironment()
150 {
151 if (empty($this->env)) {
152 return;
153 }
154 $this->resetEnvironment($this->env);
155 }
156 private function resetEnvironment($env)
157 {
158 $_SERVER = $env['server'];
159 $_COOKIE = isset($env['cookie']) ? $env['cookie'] : array();
160 }
161 private function getCurrentEnvironment()
162 {
163 return array('server' => $_SERVER, 'cookie' => $_COOKIE);
164 }
165 }
166