api = $api; } public function getConfig(): array { return [ 'title' => 'Statistics', 'viewable' => false, 'type' => 'system', ]; } public function getAdminMenu(): array { $config = $this->getPluginConfig(); $requiredRoles = $config['required_roles'] ?? ['bi-manager', 'site-admin', 'admin']; return [ [ 'plugin' => 'Statistics', 'route' => 'statistics', 'label' => 'Statistieken', 'label_key' => 'menu_label', 'icon' => 'bi-bar-chart', 'section' => 'general', 'permission' => 'statistics', 'required_roles' => $requiredRoles, ], ]; } /** * Get this plugin's runtime config (defaults + overrides). */ private function getPluginConfig(): array { $pluginDir = dirname(__DIR__); $pluginJsonFile = $pluginDir . '/plugin.json'; $configJsonFile = $pluginDir . '/config.json'; $defaults = []; if (file_exists($pluginJsonFile)) { $pluginJson = json_decode(file_get_contents($pluginJsonFile), true) ?? []; foreach ($pluginJson['settings'] ?? [] as $setting) { if (isset($setting['key'])) { $defaults[$setting['key']] = $setting['default'] ?? null; } } } $overrides = []; if (file_exists($configJsonFile)) { $overrides = json_decode(file_get_contents($configJsonFile), true) ?? []; } return array_merge($defaults, $overrides); } public function handleAdminRoute(string $action): ?string { // System plugin: translations resolve against the admin language. $t = $this->api ? $this->api->getPluginTranslations('Statistics') : []; $tr = function (string $key) use ($t): string { return $t[$key] ?? $key; }; $analytics = $this->getAnalytics(); if ($analytics === null) { return '
= htmlspecialchars($tr('no_data')) ?>
| = htmlspecialchars($tr('col_country')) ?> | = htmlspecialchars($tr('col_views')) ?> |
|---|---|
| = GeoIP::getCountryFlagEmoji($country) ?> = htmlspecialchars(GeoIP::getCountryName($country)) ?> | = number_format($count, 0, ',', '.') ?> |
= htmlspecialchars($tr('no_data')) ?>
| = htmlspecialchars($tr('col_page')) ?> | = htmlspecialchars($tr('col_views')) ?> |
|---|---|
| = htmlspecialchars($page) ?> | = number_format($count, 0, ',', '.') ?> |