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