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