This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpiwik.php
109 lines (86 loc) · 2.36 KB
/
piwik.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
$kirby->set('widget', 'piwik', __DIR__ . '/widgets/piwik');
$kirby->set('tag', 'piwikOptOut', array(
'attr' => array(
'width',
'height'
),
'html' => function ($tag) {
loadTranslation();
if (!c::get('ka.piwik.tracking', false)) {
return (c::get('debug', false)) ? l::get('ka.piwik.pluginDisabled') : '';
}
if (!c::get('ka.piwik.url') || !c::get('ka.piwik.id')) {
return l::get('ka.piwik.missingConfig');
}
$width = $tag->attr('width');
$height = $tag->attr('height');
if (empty($width)) {
$width = '100%';
}
if (empty($height)) {
$height = '150px';
}
$data = array(
'url' => c::get('ka.piwik.url'),
'id' => c::get('ka.piwik.id'),
'lang' => site()->language(),
'width' => $width,
'height' => $height
);
return tpl::load(__DIR__ . DS . 'templates/optOut.php', $data);
}
));
$kirby->set('tag', 'piwikAjaxOptOut', array(
'attr' => array(),
'html' => function ($tag) {
loadTranslation();
if (!c::get('ka.piwik.tracking', false)) {
return (c::get('debug', false)) ? l::get('ka.piwik.pluginDisabled') : '';
}
if (!c::get('ka.piwik.url') || !c::get('ka.piwik.id')) {
return l::get('ka.piwik.missingConfig');
}
$data = array(
'url' => c::get('ka.piwik.url')
);
if (isset($_SERVER["HTTP_DNT"])) {
return l::get('ka.piwik.doNotTrack');
} else {
return tpl::load(__DIR__ . DS . 'templates/ajaxOptOut.php', $data);
}
}
));
function piwik()
{
// check if enabled and config is valid
if (!c::get('ka.piwik.tracking', false) || !c::get('ka.piwik.url') || !c::get('ka.piwik.id')) {
return '';
}
// check if user is logged in
if (!c::get('ka.piwik.trackingIfLoggedIn', true) && site()->user()) {
return '';
}
$data = array(
'url' => c::get('ka.piwik.url'),
'id' => c::get('ka.piwik.id')
);
// Return template HTML
return tpl::load(__DIR__ . DS . 'templates/tracking.php', $data);
}
function loadTranslation()
{
if (defined('KIRBY')) {
$site = kirby()->site();
$code = $site->multilang() ? $site->language()->code() : c::get('ka.piwik.language', 'de');
try {
include_once __DIR__ . DS . 'languages' . DS . $code . '.php';
} catch (ErrorException $e) {
try {
include_once __DIR__ . DS . 'languages' . DS . 'de' . '.php';
} catch (ErrorException $e) {
throw new Exception("Uniform does not have a translation for the language '$code'.");
}
}
}
}