*/ public static function get_all(): array { $dir = MAPFIELD_SPOTS_PATH . self::DIR; $markers = array(); foreach ( glob( $dir . '*.svg' ) ?: array() as $file ) { $id = basename( $file, '.svg' ); $markers[ $id ] = array( 'id' => $id, 'label' => self::label_from_filename( $id ), 'url' => MAPFIELD_SPOTS_URL . self::DIR . basename( $file ), 'path' => $file, ); } ksort( $markers ); return $markers; } // Falls back to the first available marker (then '') if the requested // id's file was deleted after a Map Type was configured to use it. public static function get_svg_markup( string $id ): string { $markers = self::get_all(); if ( isset( $markers[ $id ] ) ) { $svg = file_get_contents( $markers[ $id ]['path'] ); return $svg ?: ''; } $first = reset( $markers ); return $first ? ( file_get_contents( $first['path'] ) ?: '' ) : ''; } /** * Resolves a Map Type's `map` config into a marker descriptor, whether * a library SVG or a custom image. A custom image renders as a plain * `` (not recoloured like `.st0` SVGs) since it's the site owner's * own photo/logo and should keep its real colours; the recolouring step * in buildMarkerElement() already leaves non-.st0 markup alone. * * Custom-image resolution itself is PRO (mapfield_spots_resolve_custom_marker, * hooked by Mapfield_Spots_Pro\Customization) — this plugin only knows the * CUSTOM_ID sentinel exists; no empty filter result just falls through * to the library below. * * @param array $map_config A Map Type's own $config['map'] sub-array. * @return array{markup: string, url: string, is_custom: bool} */ public static function resolve( array $map_config ): array { $marker_id = $map_config['marker'] ?? ''; if ( self::CUSTOM_ID === $marker_id ) { $custom = apply_filters( 'mapfield_spots_resolve_custom_marker', null, $map_config ); if ( $custom ) { return $custom; } } $markers = self::get_all(); $entry = $markers[ $marker_id ] ?? reset( $markers ); return array( 'markup' => self::get_svg_markup( $marker_id ), 'url' => $entry['url'] ?? '', 'is_custom' => false, ); } public static function default_id(): string { $markers = self::get_all(); if ( isset( $markers[ self::DEFAULT_ID ] ) ) { return self::DEFAULT_ID; } $first = array_key_first( $markers ); return $first ?: ''; } private static function label_from_filename( string $id ): string { return ucwords( str_replace( array( '-', '_' ), ' ', $id ) ); } }