array( 304, 169 ), 'krakow' => array( 257, 310 ), 'wroclaw' => array( 129, 242 ), 'gdansk' => array( 200, 32 ), 'poznan' => array( 124, 158 ), 'katowice' => array( 217, 298 ), 'lodz' => array( 237, 201 ), 'lublin' => array( 373, 233 ), 'bialystok' => array( 399, 111 ), 'szczecin' => array( 40, 92 ), 'rzeszow' => array( 348, 311 ), 'bydgoszcz' => array( 171, 112 ), 'olsztyn' => array( 281, 69 ), 'kielce' => array( 288, 258 ), 'opole' => array( 168, 271 ), 'zielona gora' => array( 61, 188 ), 'radom' => array( 311, 224 ), 'torun' => array( 198, 119 ), 'czestochowa' => array( 221, 262 ), 'gliwice' => array( 201, 296 ), 'sosnowiec' => array( 221, 296 ), 'gdynia' => array( 195, 21 ), 'plock' => array( 247, 149 ), 'tarnow' => array( 304, 313 ), 'legnica' => array( 90, 236 ), 'grudziadz' => array( 205, 88 ), 'slupsk' => array( 129, 25 ), 'koszalin' => array( 91, 42 ), 'elblag' => array( 233, 44 ), 'siedlce' => array( 361, 173 ), 'nowy sacz' => array( 291, 339 ), 'piotrkow trybunalski' => array( 247, 224 ), 'zamosc' => array( 403, 268 ), 'przemysl' => array( 382, 329 ), 'wloclawek' => array( 219, 142 ), 'skierniewice' => array( 267, 188 ), 'gorzow wie' => array( 87, 210 ), 'gorzow wielkopolski' => array( 87, 210 ), 'rumia' => array( 192, 28 ), 'sopot' => array( 197, 27 ), 'bydgoszc' => array( 171, 112 ), 'rzszow' => array( 348, 311 ), ); public function get_name() { return 'carei-map'; } public function get_title() { return 'Carei Map'; } public function get_icon() { return 'eicon-google-maps'; } public function get_categories() { return array( 'general' ); } public function get_style_depends() { return array( 'carei-reservation-css' ); } public function get_script_depends() { return array( 'carei-reservation-js' ); } protected function register_controls() {} /** * Normalize city name: lowercase, strip Polish diacritics. */ private static function normalize_city( $name ) { $map = array( 'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', 'ż' => 'z', 'Ą' => 'a', 'Ć' => 'c', 'Ę' => 'e', 'Ł' => 'l', 'Ń' => 'n', 'Ó' => 'o', 'Ś' => 's', 'Ź' => 'z', 'Ż' => 'z', ); $name = mb_strtolower( trim( $name ), 'UTF-8' ); return strtr( $name, $map ); } /** * Truncated / misspelled names from Softra API → correct full city names. */ const NAME_FIXES = array( 'BYDGOSZC' => 'BYDGOSZCZ', 'GORZÓW WIE' => 'GORZÓW WIELKOPOLSKI', 'RZSZÓW' => 'RZESZÓW', 'SK-KAM' => '', ); /** * Clean branch name: handle D(Dworzec)/L suffixes, fix truncated names, skip codes. * Returns array: [ 'name' => cleaned name, 'dworzec' => bool ] */ private static function clean_branch_name( $raw ) { $name = trim( $raw ); $is_dworzec = (bool) preg_match( '/\s+D$/u', $name ); $name = preg_replace( '/\s+[DL]$/u', '', $name ); if ( isset( self::NAME_FIXES[ $name ] ) ) { $name = self::NAME_FIXES[ $name ]; } if ( empty( $name ) || preg_match( '/^[A-Z]{2,4}-[A-Z]{2,4}$/u', $name ) ) { return array( 'name' => '', 'dworzec' => false ); } return array( 'name' => $name, 'dworzec' => $is_dworzec ); } /** * Build branch data with coordinates for JS. */ private function get_branch_pins() { $api = Carei_Softra_API::get_instance(); if ( null === $api ) { return array(); } $branches = $api->get_branches_cached(); if ( is_wp_error( $branches ) || ! is_array( $branches ) ) { return array(); } $pins = array(); $seen_cities = array(); foreach ( $branches as $b ) { $raw_name = isset( $b['name'] ) ? $b['name'] : ''; $cleaned = self::clean_branch_name( $raw_name ); $city = $cleaned['name']; if ( empty( $city ) ) { continue; } $norm = self::normalize_city( $city ); if ( isset( $seen_cities[ $norm ] ) ) { continue; } $seen_cities[ $norm ] = true; $coords = isset( self::CITY_COORDS[ $norm ] ) ? self::CITY_COORDS[ $norm ] : null; if ( ! $coords ) { continue; } $display_city = mb_convert_case( $city, MB_CASE_TITLE, 'UTF-8' ); // Build address from API fields: "ul. Street\nZipCode City" $street = isset( $b['street'] ) ? trim( $b['street'] ) : ''; $zip = isset( $b['zipCode'] ) ? trim( (string) $b['zipCode'] ) : ''; $api_city = isset( $b['city'] ) ? trim( $b['city'] ) : ''; $api_city_title = mb_convert_case( $api_city, MB_CASE_TITLE, 'UTF-8' ); $address_lines = array( 'Oddział ' . $display_city ); if ( $street ) { $street_lower = mb_strtolower( $street, 'UTF-8' ); $has_prefix = preg_match( '/^(ul\.|al\.|pl\.|os\.)/u', $street_lower ); $address_lines[] = $has_prefix ? $street : 'ul. ' . $street; } $zip_city = trim( $zip . ' ' . $api_city_title ); if ( $zip_city ) { $address_lines[] = $zip_city; } $pins[] = array( 'city' => $display_city, 'x' => $coords[0], 'y' => $coords[1], 'address' => implode( "\n", $address_lines ), ); } return $pins; } protected function render() { $pins = $this->get_branch_pins(); $pins_json = wp_json_encode( $pins ); ?>