api = $api; } public function getConfig(): array { return [ 'title' => 'GeoIP Info', 'type' => 'system', ]; } /** * Register admin menu items. */ public function getAdminMenu(): array { return [ [ 'plugin' => 'GeoIPInfo', 'label' => 'GeoIP Info', 'label_key' => 'menu_label', 'route' => 'geoip-info', 'icon' => 'bi-globe2', ], ]; } /** * Register admin routes this plugin handles. */ public function getAdminRoutes(): array { return ['geoip-info']; } /** * Handle admin route — render the admin page. */ 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 '
'; } }