PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
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 / ViewDataTable / Request.php
matomo / app / core / ViewDataTable Last commit date
Config.php 6 years ago Factory.php 6 years ago Manager.php 6 years ago Request.php 6 years ago RequestConfig.php 6 years ago
Request.php
153 lines
1 <?php
2 /**
3 * Piwik - 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
10 namespace Piwik\ViewDataTable;
11
12 use Piwik\API\Request as ApiRequest;
13 use Piwik\Common;
14 use Piwik\DataTable;
15 use Piwik\Period;
16
17 class Request
18 {
19 /**
20 * @var null|\Piwik\ViewDataTable\RequestConfig
21 */
22 public $requestConfig;
23
24 public function __construct($requestConfig)
25 {
26 $this->requestConfig = $requestConfig;
27 }
28
29 /**
30 * Function called by the ViewDataTable objects in order to fetch data from the API.
31 * The function init() must have been called before, so that the object knows which API module and action to call.
32 * It builds the API request string and uses Request to call the API.
33 * The requested DataTable object is stored in $this->dataTable.
34 */
35 public function loadDataTableFromAPI($extraParams = [])
36 {
37 // we build the request (URL) to call the API
38 $requestArray = $this->getRequestArray();
39 $requestArray = array_merge($extraParams, $requestArray);
40
41 // we make the request to the API
42 $request = new ApiRequest($requestArray);
43
44 // and get the DataTable structure
45 $dataTable = $request->process();
46
47 return $dataTable;
48 }
49
50 /**
51 * @return array URL to call the API, eg. "method=Referrers.getKeywords&period=day&date=yesterday"...
52 */
53 public function getRequestArray()
54 {
55 // we prepare the array to give to the API Request
56 // we setup the method and format variable
57 // - we request the method to call to get this specific DataTable
58 // - the format = original specifies that we want to get the original DataTable structure itself, not rendered
59 $requestArray = array(
60 'method' => $this->requestConfig->apiMethodToRequestDataTable,
61 'format' => 'original'
62 );
63
64 $toSetEventually = array_merge(array(
65 'filter_limit',
66 'keep_totals_row',
67 'keep_summary_row',
68 'filter_sort_column',
69 'filter_sort_order',
70 'filter_excludelowpop',
71 'filter_excludelowpop_value',
72 'filter_column',
73 'filter_pattern',
74 'flat',
75 'totals',
76 'expanded',
77 'pivotBy',
78 'pivotByColumn',
79 'pivotByColumnLimit',
80 ), $this->requestConfig->getExtraParametersToSet());
81
82 foreach ($toSetEventually as $varToSet) {
83 $value = $this->getDefaultOrCurrent($varToSet);
84 if (false !== $value) {
85 $requestArray[$varToSet] = $value;
86 }
87 }
88
89 $segment = ApiRequest::getRawSegmentFromRequest();
90 if (!empty($segment)) {
91 $requestArray['segment'] = $segment;
92 }
93
94 if (ApiRequest::shouldLoadExpanded()) {
95 $requestArray['expanded'] = 1;
96 }
97
98 $requestArray = array_merge($requestArray, $this->requestConfig->request_parameters_to_modify);
99
100 if (!empty($requestArray['filter_limit'])
101 && $requestArray['filter_limit'] === 0
102 ) {
103 unset($requestArray['filter_limit']);
104 }
105
106 if ($this->requestConfig->disable_generic_filters) {
107 $requestArray['disable_generic_filters'] = '1';
108 }
109
110 if ($this->requestConfig->disable_queued_filters) {
111 $requestArray['disable_queued_filters'] = 1;
112 }
113
114 if (!empty($requestArray['compareSegments'])) {
115 $requestArray['compareSegments'] = Common::unsanitizeInputValues($requestArray['compareSegments']);
116 }
117
118 return $requestArray;
119 }
120
121 /**
122 * Returns, for a given parameter, the value of this parameter in the REQUEST array.
123 * If not set, returns the default value for this parameter @see getDefault()
124 *
125 * @param string $nameVar
126 * @return string|mixed Value of this parameter
127 */
128 protected function getDefaultOrCurrent($nameVar)
129 {
130 if (isset($_GET[$nameVar])) {
131 return Common::sanitizeInputValue($_GET[$nameVar]);
132 }
133
134 return $this->getDefault($nameVar);
135 }
136
137 /**
138 * Returns the default value for a given parameter.
139 * For example, these default values can be set using the disable* methods.
140 *
141 * @param string $nameVar
142 * @return mixed
143 */
144 protected function getDefault($nameVar)
145 {
146 if (isset($this->requestConfig->$nameVar)) {
147 return $this->requestConfig->$nameVar;
148 }
149
150 return false;
151 }
152 }
153