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