Skip to content

Commit 77844f7

Browse files
committed
Change API requests type, GET → POST. Closes #52
1 parent 7cb4632 commit 77844f7

File tree

164 files changed

+25271
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+25271
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.DS_Store
33
node_modules
44
package-lock.json
5+
composer.lock

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@
1818
}
1919
],
2020
"require": {
21-
"getkirby/composer-installer": "^1.1"
21+
"getkirby/composer-installer": "^1.1",
22+
"guzzlehttp/guzzle": "^7.9"
2223
},
2324
"extra": {
2425
"installer-name": "matomo"
2526
},
26-
"minimum-stability": "beta"
27+
"minimum-stability": "beta",
28+
"config": {
29+
"allow-plugins": {
30+
"getkirby/composer-installer": true
31+
}
32+
}
2733
}

index.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
@include_once __DIR__ . '/vendor/autoload.php';
34
require_once __DIR__ . '/lib/matomo.php';
45

56
Kirby::plugin('sylvainjule/matomo', array(

lib/matomo.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public static function allowed() {
3232
/* Matomo API calls
3333
---------------------------------*/
3434

35-
protected $url = null;
36-
protected $id = null;
37-
protected $token = null;
35+
protected $url = null;
36+
protected $id = null;
37+
protected $token = null;
38+
protected $client = null;
3839
protected $requestParams = [];
40+
3941
protected $methodsMap = array (
4042
'referrerType' => 'Referrers.getReferrerType',
4143
'websites' => 'Referrers.getWebsites',
@@ -46,9 +48,12 @@ public static function allowed() {
4648
);
4749

4850
public function __construct() {
49-
$this->url = option('sylvainjule.matomo.url');
50-
$this->id = option('sylvainjule.matomo.id');
51-
$this->token = is_callable($this->token) ? $this->token() : option('sylvainjule.matomo.token');
51+
$this->url = option('sylvainjule.matomo.url');
52+
$this->id = option('sylvainjule.matomo.id');
53+
$this->token = is_callable($this->token) ? $this->token() : option('sylvainjule.matomo.token');
54+
$this->client = new GuzzleHttp\Client();
55+
56+
$this->requestParams['token_auth'] = $this->token;
5257
if (option('sylvainjule.matomo.basicAuth') !== null) {
5358
$this->requestParams['basicAuth'] = option('sylvainjule.matomo.basicAuth');
5459
}
@@ -60,9 +65,8 @@ public function apiWidget($widget, $method, $period, $date, $limit, $lang) {
6065
$url .= "&idSite=". $this->id ."&period=". $period ."&date=" . $date;
6166
$url .= "&format=JSON&language=". $lang;
6267
$url .= $limit ? "&filter_limit=" . $limit : '';
63-
$url .= "&token_auth=". $this->token;
6468

65-
$content = Remote::get($url, $this->requestParams)->json();
69+
$content = $this->sendRequest($url);
6670
return $content;
6771
}
6872

@@ -72,7 +76,7 @@ public function apiBulkWidgets($widgets, $period, $date, $limit, $lang) {
7276
$url = $this->url;
7377

7478
$url .= "?module=API&method=API.getBulkRequest";
75-
$url .= "&token_auth=". $this->token ."&format=JSON";
79+
$url .= "&format=JSON";
7680

7781
$i = 0;
7882
foreach($widgets as $widget) {
@@ -81,27 +85,27 @@ public function apiBulkWidgets($widgets, $period, $date, $limit, $lang) {
8185
$i++;
8286
}
8387

84-
$content = Remote::get($url, $this->requestParams)->json();
88+
$content = $this->sendRequest($url);
8589
return $content;
8690
}
8791

8892
public function apiChart($method, $period, $date) {
8993
$url = $this->url;
9094
$url .= "?module=API&method=". $method;
9195
$url .= "&idSite=". $this->id ."&period=". $period ."&date=" . $date;
92-
$url .= "&format=JSON&token_auth=". $this->token;
96+
$url .= "&format=JSON";
9397

94-
$content = Remote::get($url, $this->requestParams)->json();
98+
$content = $this->sendRequest($url);
9599
return $content;
96100
}
97101

98102
public function apiOverview($method, $period, $date) {
99103
$url = $this->url;
100104
$url .= "?module=API&method=". $method;
101105
$url .= "&idSite=". $this->id ."&period=". $period ."&date=" . $date;
102-
$url .= "&format=JSON&token_auth=". $this->token;
106+
$url .= "&format=JSON";
103107

104-
$content = Remote::get($url, $this->requestParams)->json();
108+
$content = $this->sendRequest($url);
105109
return $content;
106110
}
107111

@@ -111,17 +115,17 @@ public function apiRealtime() {
111115

112116
$url .= "?module=API&method=" . $method;
113117
$url .= "&idSite=". $this->id ."&lastMinutes=3";
114-
$url .= "&format=JSON&token_auth=". $this->token;
118+
$url .= "&format=JSON";
115119

116-
$content = Remote::get($url, $this->requestParams)->json();
120+
$content = $this->sendRequest($url);
117121
return $content;
118122
}
119123

120124
public function apiBulkSummary() {
121125
$url = $this->url;
122126

123127
$url .= "?module=API&method=API.getBulkRequest";
124-
$url .= "&token_auth=". $this->token ."&format=JSON";
128+
$url .= "&format=JSON";
125129

126130
$url .= "&urls[0]=";
127131
$url .= urlencode("method=VisitsSummary.getVisits&idSite=". $this->id ."&period=day&date=today");
@@ -135,20 +139,21 @@ public function apiBulkSummary() {
135139
$url .= "&urls[3]=";
136140
$url .= urlencode("method=VisitsSummary.getVisits&idSite=". $this->id ."&period=year&date=today");
137141

138-
$content = Remote::get($url, $this->requestParams)->json();
142+
$content = $this->sendRequest($url);
139143
return $content;
140144
}
141145

142146
public function apiPageMetrics($period, $uri, $lang) {
143147
$url = $this->url;
144148
$url .= "?module=API&method=Actions.getPageUrls";
145149
$url .= "&idSite=". $this->id ."&period=". $period ."&date=today";
146-
$url .= "&format=JSON&token_auth=". $this->token;
150+
$url .= "&format=JSON";
147151
$url .= '&flat=1';
148152
$url .= $lang['multilang'] ? '&expanded=1' : '';
149153

150-
$content = Remote::get($url, $this->requestParams)->json();
154+
$content = $this->sendRequest($url);
151155
$content = $this->filterPageMetrics($content, $uri, $lang);
156+
152157
return $content;
153158
}
154159

@@ -300,4 +305,10 @@ public function multiplyArraysByKey($arr1, $arr2) {
300305
return $total;
301306
}
302307

308+
private function sendRequest($url) {
309+
$response = $this->client->request('POST', $url, ['form_params' => $this->requestParams]);
310+
$response = json_decode($response->getBody()->getContents(), true);
311+
return $response;
312+
}
313+
303314
}

vendor/autoload.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
if (PHP_VERSION_ID < 50600) {
6+
if (!headers_sent()) {
7+
header('HTTP/1.1 500 Internal Server Error');
8+
}
9+
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
10+
if (!ini_get('display_errors')) {
11+
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
12+
fwrite(STDERR, $err);
13+
} elseif (!headers_sent()) {
14+
echo $err;
15+
}
16+
}
17+
trigger_error(
18+
$err,
19+
E_USER_ERROR
20+
);
21+
}
22+
23+
require_once __DIR__ . '/composer/autoload_real.php';
24+
25+
return ComposerAutoloaderInit953a1b7003c34ab2e5a9e730590b37e9::getLoader();

0 commit comments

Comments
 (0)