-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.php
166 lines (146 loc) · 5.58 KB
/
Plugin.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* Matomo Analytics - Powerful web analytics platform allowing website users to own their data and respect their clients' privacy.
*
* @package Winter
* @author Helmut Kaufmann
*/
namespace Mercator\Matomo;
use Backend;
use BackendAuth;
use Event;
use System\Classes\PluginBase;
use Mercator\Matomo\Models\Settings;
use Mercator\Matomo\Components\MatomoTrackerAPI;
use Yaml;
/**
* Matomo Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'Matomo',
'description' => "Powerful web analytics platform allowing website users to own their data and respect their clients' privacy.",
'author' => 'Helmut Kaufmann',
'icon' => 'icon-line-chart'
];
}
/**
* Register method, called when the plugin is first registered.
*
* @return void
*/
public function register()
{
}
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot() {
$settings = Settings::instance();
//
// Compile list of available Matomo reports
// and make them available as settings
//
$availableReports = Yaml::parseFile(plugins_path(). "/mercator/matomo/reports.yaml");
$matomoReports="";
foreach($availableReports as $acronym => $details) {
$matomoReports .= "<p class='help-block'><b>" . $details['t'] . "</b><br> ";
$matomoReports .= (array_key_exists("d", $details) && ($details["d"] != "") ? $details['d'] : "<em>Sorry, no description available.</em>");
$matomoReports .= "</p>";
// $matomoReports .= ("<p>" . $details['t'] . "</b><br>". (array_key_exists("d", $details) ? $details['d'] : "") . "</p>");
};
$matomoReports .= "";
$settings->mercator_matomo_reports = $matomoReports;
//
// Provide Matomo settings for use in template
//
switch (substr(Settings::get('server'), 0, 5)) {
case "https":
$settings->matomoServerHTTPS = "https";
$settings->matomoServer = (parse_url(Settings::get('server'), PHP_URL_HOST) ? parse_url(Settings::get('server'), PHP_URL_HOST) : "Matomo server not defined");
break;
case "http:":
$settings->matomoServerHTTPS = "http";
$settings->matomoServer = (parse_url(Settings::get('server'), PHP_URL_HOST) ? parse_url(Settings::get('server'), PHP_URL_HOST) : "Matomo server not defined");
break;
default:
$settings->matomoServerHTTPS = "https";
$settings->matomoServer = (Settings::get('server') ? Settings::get('server') : "Matomo server not defined");
}
$settings->matomoAuthorization = Settings::get('authorization');
$settings->matomoSite = Settings::get('site');
//
// Provide teh current list of tracking errors
// The CoreHomeAdmin report does currently not work, so just provide an error message for teh time being
//
//
$settings->errors = "Be back in the future - this feature has not yet been implemented.";
}
/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents() {
//
// Only expose the Matomo Tracking API if it is needed
//
if (Settings::get("phpTracking", false))
return [
'Mercator\Matomo\Components\Matomo' => 'Matomo',
'Mercator\Matomo\Components\MatomoTrackerAPI' => 'MatomoTrackingAPI',
];
else
return [
'Mercator\Matomo\Components\Matomo' => 'Matomo',
];
}
/**
* Registers any back-end permissions used by this plugin.
*
* @return array
*/
public function registerPermissions() {
return ['mercator.matomo.configuration' => ['tab' => 'Matomo Analytics', 'label' => 'Manage configuration', ],
'mercator.matomo.dashboard' => ['tab' => 'Matomo Analytics', 'label' => 'Manage dashbaord', ]
];
}
public function registerSettings() {
return ['settings' => ['label' => 'Matomo', 'description' => "Powerful web analytics platform allowing website users to own their data and respect their clients' privacy.",
'category' => 'mercator', 'icon' => 'icon-line-chart', 'class' => 'Mercator\Matomo\Models\Settings', 'order' => 500, 'keywords' => 'Helmut Kaufmann Mercator Matomo Analytics',
'homepage' => 'https://github.com/helmutkaufmann/wn-matomo-plugin', 'permissions' => ['mercator.matomo.configuration']]];
}
/**
* Registers back-end navigation items for this plugin.
*
* @return array
*/
public function registerNavigation() {
return [];
}
public function registerReportWidgets() {
$user = BackendAuth::getUser();
$settings = Settings::instance();
if ($user->hasAccess('mercator.matomo.dashboard') && $settings::get('dashboard') && $settings::get('matomoUsed'))
return [ 'Mercator\Matomo\ReportWidgets\Individual' => [
'label' => 'Matomo Widget',
'context' => 'dashboard'
],
'Mercator\Matomo\ReportWidgets\Dashboard' => [
'label' => 'Matomo Dashboard',
'context' => 'dashboard'
]];
else
return [];
}
}