api = $api; } /** * Geeft de plugin-configuratie terug. * * @since 2.6.5 * @return array Plugin-configuratie met title en type. */ public function getConfig(): array { return [ 'title' => 'GeoIP Info', 'type' => 'system', ]; } /** * Geeft de admin-menu-items voor deze plugin terug. * * @since 2.6.5 * @return array> Lijst met admin-menu-item configuraties. */ public function getAdminMenu(): array { return [ [ 'plugin' => 'GeoIPInfo', 'label' => 'GeoIP Info', 'label_key' => 'menu_label', 'route' => 'geoip-info', 'icon' => 'bi-globe2', ], ]; } /** * Geeft de admin-routes terug die deze plugin afhandelt. * * @since 2.6.5 * @return array Lijst met admin-route namen. */ public function getAdminRoutes(): array { return ['geoip-info']; } /** * Verwerkt een admin-route en toont de GeoIP-info-pagina. * * Bepaalt het IP-adres van de bezoeker en toont het land en de vlag. * * @since 2.6.5 * @param string $route De af te handelen admin-route. * @return void */ public function handleAdminRoute(string $route): void { $ip = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1'; $geoip = new GeoIP(); $countryCode = $geoip->lookupCountry($ip); $country = GeoIP::getCountryName($countryCode); $flag = GeoIP::getCountryFlagEmoji($countryCode); $t = $this->api ? $this->api->getPluginTranslations('GeoIPInfo') : []; $tr = function (string $key) use ($t): string { return $t[$key] ?? $key; }; echo '

' . htmlspecialchars($tr('page_title')) . '

'; echo '
'; echo ''; echo ''; echo ''; echo '
' . htmlspecialchars($tr('ip_address')) . '' . htmlspecialchars($ip) . '
' . htmlspecialchars($tr('country')) . '' . $flag . ' ' . htmlspecialchars($country) . '
'; echo '
'; } }