Skip to content

Commit 500c384

Browse files
committed
Allow token from closure. Fixes #16
1 parent 33a92a2 commit 500c384

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/matomo.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static function allowed() {
1111
// if deactivated or missing option
1212
if(!option('sylvainjule.matomo.id') || !option('sylvainjule.matomo.url') || !option('sylvainjule.matomo.active')) {
1313
return false;
14-
}
14+
}
1515
// if debugging the plugin, return true before checking the blacklist / user status
1616
if(option('sylvainjule.matomo.debug')) {
1717
return true;
@@ -23,7 +23,7 @@ public static function allowed() {
2323
// if users tracking is disabled and an I'm logged in
2424
if(!option('sylvainjule.matomo.trackUsers') && kirby()->user()) {
2525
return false;
26-
}
26+
}
2727

2828
return true;
2929
}
@@ -47,7 +47,7 @@ public static function allowed() {
4747
public function __construct() {
4848
$this->url = option('sylvainjule.matomo.url');
4949
$this->id = option('sylvainjule.matomo.id');
50-
$this->token = option('sylvainjule.matomo.token');
50+
$this->token = is_callable($this->token) ? $this->token() : option('sylvainjule.matomo.token');
5151
}
5252

5353
public function apiWidget($widget, $method, $period, $date, $limit, $lang) {
@@ -171,7 +171,7 @@ public function filterPageMetrics($content, $uri, $lang) {
171171
$currentLang = $lang['current'];
172172
$defaultLang = $lang['default'];
173173
$isDefault = $currentLang == $defaultLang;
174-
174+
175175
// set the correct language and find the page
176176
if($multilang) $site->visit($site->homePage(), $currentLang);
177177
$page = $site->childrenAndDrafts()->find($uri);
@@ -198,7 +198,7 @@ public function filterPageMetrics($content, $uri, $lang) {
198198
// loop through all language
199199
foreach($kirby->languages() as $language) {
200200
if($language->code() == $currentLang) continue;
201-
201+
202202
$tempCode = $language->code();
203203
$tempDefault = $tempCode == $defaultLang;
204204
$tempUrl = $page->url($tempCode);
@@ -207,7 +207,7 @@ public function filterPageMetrics($content, $uri, $lang) {
207207

208208
$tempMetrics = $this->filterWithUri($content, $tempUri, $tempCode, $tempDefault);
209209
array_push($metrics, $tempMetrics);
210-
}
210+
}
211211

212212
// filter out empty languages
213213
$metrics = array_filter($metrics);
@@ -250,7 +250,7 @@ public function filterPageMetrics($content, $uri, $lang) {
250250
'current' => $current,
251251
'all' => $all,
252252
);
253-
253+
254254
}
255255
}
256256

@@ -264,7 +264,7 @@ public function filterWithUri($content, $uri, $lang, $isDefault) {
264264
});
265265
// if the array exists, make it the new $content
266266
if(count($langArray)) {
267-
$content = reset($langArray)['subtable'] ?? array();
267+
$content = reset($langArray)['subtable'] ?? array();
268268
}
269269
// if the array isn't found, but the language isn't the default one
270270
else {
@@ -323,4 +323,4 @@ public function multiplyArraysByKey($arr1, $arr2) {
323323
return $total;
324324
}
325325

326-
}
326+
}

0 commit comments

Comments
 (0)