PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
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
Config 5 months ago Db 3 weeks ago Handler 2 years ago Visit 3 weeks ago Action.php 3 weeks ago ActionPageview.php 2 years ago BotRequest.php 4 months ago BotRequestProcessor.php 2 months ago Cache.php 3 weeks ago Db.php 3 weeks ago Failures.php 8 months ago FingerprintSalt.php 3 weeks ago GoalManager.php 3 weeks ago Handler.php 2 years ago IgnoreCookie.php 1 year ago LogTable.php 3 weeks ago Model.php 3 weeks ago PageUrl.php 3 weeks ago Request.php 3 weeks ago RequestHandlerTrait.php 5 months ago RequestProcessor.php 2 months ago RequestSet.php 8 months ago Response.php 4 months ago ScheduledTasksRunner.php 1 year ago Settings.php 3 weeks ago TableLogAction.php 3 weeks ago TrackerCodeGenerator.php 3 weeks ago TrackerConfig.php 2 months ago Visit.php 3 weeks ago VisitExcluded.php 3 weeks ago VisitInterface.php 4 months ago Visitor.php 2 months ago VisitorNotFoundInDb.php 2 months ago VisitorRecognizer.php 3 weeks ago
RequestSet.php
168 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\Request\AuthenticationToken;
12 use Piwik\Container\StaticContainer;
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(
46 #[\SensitiveParameter]
47 $tokenAuth)
48 {
49 $this->tokenAuth = $tokenAuth;
50 }
51 public function getNumberOfRequests()
52 {
53 if (is_array($this->requests)) {
54 return count($this->requests);
55 }
56 return 0;
57 }
58 public function getRequests()
59 {
60 if (!$this->areRequestsInitialized()) {
61 return array();
62 }
63 return $this->requests;
64 }
65 public function getTokenAuth()
66 {
67 if (!is_null($this->tokenAuth)) {
68 return $this->tokenAuth;
69 }
70 return StaticContainer::get(AuthenticationToken::class)->getAuthToken();
71 }
72 private function areRequestsInitialized()
73 {
74 return !is_null($this->requests);
75 }
76 public function initRequestsAndTokenAuth()
77 {
78 if ($this->areRequestsInitialized()) {
79 return;
80 }
81 /**
82 * Triggered when detecting tracking requests. A plugin can use this event to set
83 * requests that should be tracked by calling the {@link RequestSet::setRequests()} method.
84 * For example the BulkTracking plugin uses this event to detect tracking requests and auth token based on
85 * a sent JSON instead of default $_GET+$_POST. It would allow you for example to track requests based on
86 * XML or you could import tracking requests stored in a file.
87 *
88 * @param \Piwik\Tracker\RequestSet &$requestSet Call {@link setRequests()} to initialize requests and
89 * {@link setTokenAuth()} to set a detected auth token.
90 *
91 * @ignore This event is not public yet as the RequestSet API is not really stable yet
92 */
93 Piwik::postEvent('Tracker.initRequestSet', array($this));
94 if (!$this->areRequestsInitialized()) {
95 $this->requests = array();
96 if (!empty($_GET) || !empty($_POST)) {
97 $this->setRequests(array($_GET + $_POST));
98 }
99 }
100 }
101 public function hasRequests()
102 {
103 return !empty($this->requests);
104 }
105 protected function getAllSiteIdsWithinRequest()
106 {
107 if (empty($this->requests)) {
108 return array();
109 }
110 $siteIds = array();
111 foreach ($this->requests as $request) {
112 $siteIds[] = (int) $request->getIdSite();
113 }
114 return array_values(array_unique($siteIds));
115 }
116 public function getState()
117 {
118 $requests = array('requests' => array(), 'env' => $this->getEnvironment(), 'tokenAuth' => $this->getTokenAuth(), 'time' => time());
119 foreach ($this->getRequests() as $request) {
120 $requests['requests'][] = $request->getRawParams();
121 }
122 return $requests;
123 }
124 public function restoreState($state)
125 {
126 $backupEnv = $this->getCurrentEnvironment();
127 $this->setEnvironment($state['env']);
128 $this->setTokenAuth($state['tokenAuth']);
129 $this->restoreEnvironment();
130 $this->setRequests($state['requests']);
131 foreach ($this->getRequests() as $request) {
132 $request->setCurrentTimestamp($state['time']);
133 }
134 $this->resetEnvironment($backupEnv);
135 }
136 public function rememberEnvironment()
137 {
138 $this->setEnvironment($this->getEnvironment());
139 }
140 public function setEnvironment($env)
141 {
142 $this->env = $env;
143 }
144 protected function getEnvironment()
145 {
146 if (!empty($this->env)) {
147 return $this->env;
148 }
149 return $this->getCurrentEnvironment();
150 }
151 public function restoreEnvironment()
152 {
153 if (empty($this->env)) {
154 return;
155 }
156 $this->resetEnvironment($this->env);
157 }
158 private function resetEnvironment($env)
159 {
160 $_SERVER = $env['server'];
161 $_COOKIE = isset($env['cookie']) ? $env['cookie'] : array();
162 }
163 private function getCurrentEnvironment()
164 {
165 return array('server' => $_SERVER, 'cookie' => $_COOKIE);
166 }
167 }
168