*/ private const COUNTRY_MAP = [ 'AR' => 'Argentina', 'AU' => 'Australia', 'AT' => 'Austrian', 'BE' => 'Belgian', 'BR' => 'Brazil', 'CA' => 'Canada', 'CL' => 'Chile', 'CN' => 'China', 'CO' => 'Colombian', 'CZ' => 'Czech', 'DK' => 'Denmark', 'FI' => 'Finland', 'FR' => 'French', 'DE' => 'German', 'GR' => 'Greece', 'HU' => 'Hungarian', 'IN' => 'India', 'IE' => 'Ireland', 'IT' => 'Italian', 'JP' => 'Japan', 'MX' => 'Mexico', 'NL' => 'Dutch', 'NZ' => 'NewZealand', 'NO' => 'Norwegian', 'PL' => 'Polish', 'PT' => 'Portugal', 'RO' => 'Romania', 'RU' => 'Russia', 'ZA' => 'SouthAfrica', 'KR' => 'SouthKorea', 'ES' => 'Spain', 'SE' => 'Swedish', 'CH' => 'Swiss', 'TW' => 'Taiwan', 'TR' => 'Turkey', 'GB' => 'UK', 'US' => 'US', ]; /** * Human-readable country names keyed by code. * * @var array */ private const COUNTRY_NAMES = [ 'AR' => 'Argentina', 'AU' => 'Australia', 'AT' => 'Austria', 'BE' => 'Belgium', 'BR' => 'Brazil', 'CA' => 'Canada', 'CL' => 'Chile', 'CN' => 'China', 'CO' => 'Colombia', 'CZ' => 'Czech Republic', 'DK' => 'Denmark', 'FI' => 'Finland', 'FR' => 'France', 'DE' => 'Germany', 'GR' => 'Greece', 'HU' => 'Hungary', 'IN' => 'India', 'IE' => 'Ireland', 'IT' => 'Italy', 'JP' => 'Japan', 'MX' => 'Mexico', 'NL' => 'Netherlands', 'NZ' => 'New Zealand', 'NO' => 'Norway', 'PL' => 'Poland', 'PT' => 'Portugal', 'RO' => 'Romania', 'RU' => 'Russia', 'ZA' => 'South Africa', 'KR' => 'South Korea', 'ES' => 'Spain', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'TW' => 'Taiwan', 'TR' => 'Turkey', 'GB' => 'United Kingdom', 'US' => 'United States', ]; public function get_id(): string { return 'thunderbird'; } public function get_label(): string { return __( 'Thunderbird (Community Holidays)', 'agenticdaisy-calendar' ); } /** * @return array */ public function get_countries(): array { return self::COUNTRY_NAMES; } public function fetch_holidays( string $country_code, int $year ): string { $prefix = self::COUNTRY_MAP[ $country_code ] ?? null; if ( $prefix === null ) { throw new \RuntimeException( // translators: %s is the country code. sprintf( esc_html__( 'Unsupported country code for Thunderbird: %s', 'agenticdaisy-calendar' ), esc_html( $country_code ) ) ); } $url = sprintf( self::URL_TEMPLATE, $prefix ); $response = wp_remote_get( $url, [ 'timeout' => 15, ] ); if ( is_wp_error( $response ) ) { throw new \RuntimeException( esc_html( $response->get_error_message() ) ); } $code = wp_remote_retrieve_response_code( $response ); if ( 200 !== $code ) { throw new \RuntimeException( // translators: 1: HTTP status code, 2: country code. sprintf( esc_html__( 'Thunderbird returned HTTP %1$d for %2$s', 'agenticdaisy-calendar' ), (int) $code, esc_html( $country_code ) ) ); } $body = wp_remote_retrieve_body( $response ); if ( empty( $body ) ) { throw new \RuntimeException( esc_html__( 'Empty response from Thunderbird', 'agenticdaisy-calendar' ) ); } return $body; } }