true, 'title' => true, 'data-src' => true, 'width' => true, 'height' => true, 'loading' => true, 'referrerpolicy' => true, 'allowfullscreen' => true, )); unset($allowed['iframe']['src']); return $allowed; } public static function register_block() { register_block_type(__DIR__ . '/blocks/store-map', array( 'api_version' => 3, 'title' => __('Rooster One Store Map', 'ai-eshop-optimizer'), 'description' => __("A single store's location map (OpenStreetMap, or Google Maps where a Google key is configured) plus a directions link. Auto-resolves on a store page, or set a location slug.", 'ai-eshop-optimizer'), 'category' => 'widgets', 'icon' => 'location', 'keywords' => array('map', 'location', 'directions', 'store', 'shop'), 'supports' => array('align' => array('wide')), 'attributes' => array( 'locationSlug' => array('type' => 'string', 'default' => ''), 'height' => array('type' => 'number', 'default' => 320), 'aspect' => array('type' => 'string', 'default' => ''), 'showDirections' => array('type' => 'boolean', 'default' => true), 'provider' => array('type' => 'string', 'default' => '', 'enum' => array('', 'osm', 'google')), ), 'uses_context' => array('postId'), 'render_callback' => array(__CLASS__, 'render'), )); } public static function shortcode($atts) { $atts = shortcode_atts(array('location' => '', 'height' => 320, 'aspect' => '', 'directions' => '1', 'provider' => ''), $atts, 'aieo_store_map'); return self::render(array( 'locationSlug' => (string) $atts['location'], 'height' => (int) $atts['height'], 'aspect' => (string) $atts['aspect'], 'showDirections' => !in_array((string) $atts['directions'], array('0', 'no', 'false', ''), true), 'provider' => sanitize_key((string) $atts['provider']), )); } public static function render($attrs, $content = '', $block = null) { if (!class_exists('AIEO_Google_Reviews_Helpers')) { return ''; } $attrs = wp_parse_args(is_array($attrs) ? $attrs : array(), array( 'locationSlug' => '', 'height' => 320, 'aspect' => '', 'showDirections' => true, 'provider' => '', )); $loc = AIEO_Google_Reviews_Helpers::resolve_single($attrs['locationSlug'], $block); if (!$loc) { return ''; } $query = self::map_query($loc); if ($query === '') { return ''; } $height = max(160, min(720, (int) $attrs['height'])); $aspect = preg_replace('/[^0-9.\/]/', '', (string) $attrs['aspect']); $frame_style = ($aspect !== '' && strpos($aspect, '/') !== false) ? '--aieo-store-map-aspect:' . $aspect . ';' : '--aieo-store-map-height:' . (int) $height . 'px;'; $provider = self::provider($attrs, $loc); $coords = self::coords($loc); $label = (string) ($loc['label'] ?? ''); $place = $label !== '' ? $label : __('store location', 'ai-eshop-optimizer'); if ('osm' === $provider) { $embed = $coords ? self::osm_embed_url($coords[0], $coords[1]) : ''; $larger = $coords ? 'https://www.openstreetmap.org/?mlat=' . $coords[0] . '&mlon=' . $coords[1] . '#map=17/' . $coords[0] . '/' . $coords[1] : 'https://www.openstreetmap.org/search?query=' . rawurlencode($query); } else { $embed = 'https://maps.google.com/maps?q=' . rawurlencode($query) . '&z=15&hl=' . rawurlencode((string) ($loc['language'] ?? 'el')) . '&output=embed'; $larger = ''; } $address = self::address_line($loc); $icon = function_exists('rooster_icon') && (!function_exists('rooster_has_icon') || rooster_has_icon('map-pin')) ? (string) rooster_icon('map-pin', array('width' => 24, 'height' => 24)) : ''; if ($embed !== '' && function_exists('wp_enqueue_script_module')) { wp_enqueue_script_module('aieo-store-map-view-script-module'); } $wrap = get_block_wrapper_attributes(array('class' => 'aieo-store-map aieo-store-map--' . $provider)); ob_start(); ?>
>
>

OpenStreetMap'), array('a' => array('href' => true, 'target' => true, 'rel' => true))); ?>

90 || abs($lng) > 180) { return null; } return array(round($lat, 6), round($lng, 6)); } public static function osm_embed_url($lat, $lng) { $bbox = implode(',', array(round($lng - 0.006, 6), round($lat - 0.0035, 6), round($lng + 0.006, 6), round($lat + 0.0035, 6))); return 'https://www.openstreetmap.org/export/embed.html?bbox=' . rawurlencode($bbox) . '&layer=mapnik&marker=' . rawurlencode($lat . ',' . $lng); } private static function address_line($loc) { $line = trim(implode(', ', array_filter(array( trim((string) ($loc['street'] ?? '')), trim(str_replace(' ', "\u{00A0}", trim((string) ($loc['postcode'] ?? ''))) . ' ' . trim((string) ($loc['locality'] ?? ''))), )))); return '' !== $line ? $line : trim((string) ($loc['address'] ?? '')); } private static function map_query($loc) { $lat = isset($loc['lat']) && $loc['lat'] !== null && $loc['lat'] !== '' ? (float) $loc['lat'] : null; $lng = isset($loc['lng']) && $loc['lng'] !== null && $loc['lng'] !== '' ? (float) $loc['lng'] : null; if ($lat !== null && $lng !== null && ($lat !== 0.0 || $lng !== 0.0)) { return $lat . ',' . $lng; } $addr = trim(implode(' ', array_filter(array( (string) ($loc['street'] ?? ''), (string) ($loc['postcode'] ?? ''), (string) ($loc['locality'] ?? ''), (string) ($loc['country'] ?? ''), )))); if ($addr !== '') { return $addr; } $a = trim((string) ($loc['address'] ?? '')); if ($a !== '') { return $a; } return trim((string) ($loc['label'] ?? '')); } private static function directions_url($loc) { $place_id = trim((string) ($loc['place_id'] ?? '')); if ($place_id !== '') { return 'https://www.google.com/maps/dir/?api=1&destination=' . rawurlencode(self::map_query($loc)) . '&destination_place_id=' . rawurlencode($place_id); } $q = self::map_query($loc); return $q !== '' ? 'https://www.google.com/maps/dir/?api=1&destination=' . rawurlencode($q) : ''; } private static function map_style() { if (wp_style_is('aieo-store-map', 'registered')) { wp_enqueue_style('aieo-store-map'); return; } $css = '.aieo-store-map{margin:0}' . '.aieo-store-map__frame{position:relative;width:100%;height:var(--aieo-store-map-height,auto);aspect-ratio:var(--aieo-store-map-aspect,auto);border-radius:14px;overflow:hidden;background:var(--wp--preset--color--subtle,#eceae6);border:1px solid var(--wp--preset--color--line,#e5e7eb)}' . '.aieo-store-map__map{position:absolute;inset:0;width:100%;height:100%;border:0;display:block}' . '.aieo-store-map__placeholder{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;padding:16px;width:100%;margin:0;border:0;border-radius:0;background:var(--wp--preset--color--subtle,#eceae6);color:var(--wp--preset--color--fg,#111827);font:inherit;text-align:center}' . 'button.aieo-store-map__placeholder{cursor:pointer}' . 'button.aieo-store-map__placeholder:focus-visible{outline:2px solid var(--wp--preset--color--accent,#2563eb);outline-offset:-4px}' . '.aieo-store-map__frame.is-loaded .aieo-store-map__placeholder{display:none}' . '.aieo-store-map__place{font-weight:600}' . '.aieo-store-map__address{color:var(--wp--preset--color--muted,#4b5563);font-size:.92rem}' . '.aieo-store-map__show{margin-top:6px;min-height:44px;display:inline-flex;align-items:center;padding:0 16px;border-radius:999px;border:1px solid var(--wp--preset--color--line,#d1d5db);background:var(--wp--preset--color--bg,#fff);font-weight:600}' . '.aieo-store-map__links{display:flex;flex-wrap:wrap;gap:8px 20px;margin:12px 0 0}' . '.aieo-store-map__links a{display:inline-flex;align-items:center;min-height:24px;font-size:.92rem;font-weight:600}' . '.aieo-store-map__credit{margin:6px 0 0;font-size:.8rem;color:var(--wp--preset--color--muted,#4b5563)}' . '.aieo-store-map__credit a{color:inherit}'; wp_register_style('aieo-store-map', false, array(), null); wp_add_inline_style('aieo-store-map', $css); wp_enqueue_style('aieo-store-map'); } }