$value ) {
if ( '' === $value ) {
$args[ $key ] = $defaults[ $key ];
}
}
return $args;
}
/**
* Function to apply attributes to HTML tags.
* Devs can override attributes in a child theme by using the correct slug
*
* @param string $slug Slug to refer to the HTML tag.
* @param array $attributes Attributes for HTML tag.
* @return string
*/
public static function attributes( $slug, $attributes = [] ) {
$out = '';
$attr = apply_filters( "fusion_attr_{$slug}", $attributes );
if ( empty( $attr ) ) {
$attr['class'] = $slug;
}
foreach ( $attr as $name => $value ) {
if ( empty( $value ) ) {
$out .= ' ' . esc_html( $name );
} else {
$out .= ' ' . esc_html( $name ) . '="' . esc_attr( $value ) . '"';
}
}
return trim( $out );
}
/**
* JS API render method.
*
* @access public
* @since 5.6
* @return string The needed map data.
*/
public function use_js_api() {
extract( self::$args );
$html = '';
if ( $address ) {
$addresses = explode( '|', $address );
$infobox_content = ( ! in_array( $map_style, [ 'default', 'theme' ], true ) ) ? html_entity_decode( $infobox_content ) : '';
$infobox_content_array = ( $infobox_content ) ? explode( '|', $infobox_content ) : '';
$icon_array = ( $icon && 'default' !== $infobox ) ? explode( '|', $icon ) : '';
if ( ! empty( $addresses ) ) {
self::$args['address'] = $addresses;
}
$num_of_addresses = count( $addresses );
if ( $icon && false === strpos( $icon, '|' ) && 'default' !== $infobox ) {
for ( $i = 0; $i < $num_of_addresses; $i++ ) {
$icon_array[ $i ] = $icon;
}
}
if ( 'theme' === $map_style ) {
$map_style = 'custom';
$icon = 'theme';
$animation = 'yes';
$infobox = 'custom';
$color_obj = Fusion_Color::new_color( Avada()->settings->get( 'primary_color' ) );
$infobox_background_color = 'rgba(' . $color_obj->red . ', ' . $color_obj->green . ', ' . $color_obj->blue . ', 0.8)';
$overlay_color = $color_obj->color;
$brightness_level = $color_obj->brightness['level'];
$infobox_text_color = ( $brightness_level > 140 ) ? '#fff' : '#747474';
} elseif ( 'custom' === $map_style ) {
$overlay_color = Avada()->settings->get( 'map_overlay_color' );
$color_obj = Fusion_Color::new_color( $overlay_color );
if ( 0 === $color_obj->alpha ) {
$overlay_color = '';
} elseif ( 1 > $color_obj->alpha ) {
$overlay_color = $color_obj->get_new( 'lightness', $color_obj->lightness + absint( 100 * ( 1 - $color_obj->alpha ) ) )->to_css( 'hex' );
}
}
if ( 'theme' === $icon && 'custom' === $map_style ) {
for ( $i = 0; $i < $num_of_addresses; $i++ ) {
$icon_array[ $i ] = Avada::$template_dir_url . '/assets/images/avada_map_marker.png';
}
}
if ( wp_script_is( 'google-maps-api', 'registered' ) ) {
wp_print_scripts( 'google-maps-api' );
if ( wp_script_is( 'google-maps-infobox', 'registered' ) ) {
wp_print_scripts( 'google-maps-infobox' );
}
}
foreach ( self::$args['address'] as $add ) {
$add = trim( $add );
$add_arr = explode( "\n", $add );
$add_arr = array_filter( $add_arr, 'trim' );
$add = implode( '
', $add_arr );
$add = str_replace( "\r", '', $add );
$add = str_replace( "\n", '', $add );
$coordinates[]['address'] = $add;
}
if ( ! is_array( $coordinates ) ) {
return;
}
for ( $i = 0; $i < $num_of_addresses; $i++ ) {
if ( 0 === strpos( self::$args['address'][ $i ], 'latlng=' ) ) {
self::$args['address'][ $i ] = $coordinates[ $i ]['address'];
}
}
if ( is_array( $infobox_content_array ) && ! empty( $infobox_content_array ) ) {
for ( $i = 0; $i < $num_of_addresses; $i++ ) {
if ( ! array_key_exists( $i, $infobox_content_array ) ) {
$infobox_content_array[ $i ] = self::$args['address'][ $i ];
}
}
self::$args['infobox_content'] = $infobox_content_array;
} else {
self::$args['infobox_content'] = self::$args['address'];
}
$cached_addresses = get_option( 'fusion_map_addresses' );
foreach ( self::$args['address'] as $key => $address ) {
$json_addresses[] = [
'address' => $address,
'infobox_content' => self::$args['infobox_content'][ $key ],
];
if ( isset( $icon_array ) && is_array( $icon_array ) ) {
$json_addresses[ $key ]['marker'] = $icon_array[ $key ];
}
if ( false !== strpos( $address, strtolower( 'latlng=' ) ) ) {
$json_addresses[ $key ]['address'] = str_replace( 'latlng=', '', $address );
$lat_lng = explode( ',', $json_addresses[ $key ]['address'] );
$json_addresses[ $key ]['coordinates'] = true;
$json_addresses[ $key ]['latitude'] = $lat_lng[0];
$json_addresses[ $key ]['longitude'] = $lat_lng[1];
$json_addresses[ $key ]['cache'] = false;
if ( false !== strpos( self::$args['infobox_content'][ $key ], strtolower( 'latlng=' ) ) ) {
$json_addresses[ $key ]['infobox_content'] = '';
}
if ( isset( $cached_addresses[ trim( $json_addresses[ $key ]['latitude'] . ',' . $json_addresses[ $key ]['longitude'] ) ] ) ) {
$json_addresses[ $key ]['geocoded_address'] = $cached_addresses[ trim( $json_addresses[ $key ]['latitude'] . ',' . $json_addresses[ $key ]['longitude'] ) ]['address'];
$json_addresses[ $key ]['cache'] = true;
}
} else {
$json_addresses[ $key ]['coordinates'] = false;
$json_addresses[ $key ]['cache'] = false;
if ( isset( $cached_addresses[ trim( $json_addresses[ $key ]['address'] ) ] ) ) {
$json_addresses[ $key ]['latitude'] = $cached_addresses[ trim( $json_addresses[ $key ]['address'] ) ]['latitude'];
$json_addresses[ $key ]['longitude'] = $cached_addresses[ trim( $json_addresses[ $key ]['address'] ) ]['longitude'];
$json_addresses[ $key ]['cache'] = true;
}
}
}
$json_addresses = wp_json_encode( $json_addresses );
$map_id = uniqid( 'fusion_map_' ); // Generate a unique ID for this map.
$this->map_id = $map_id;
ob_start(); ?>