Exemplo n.º 1
0
 public static function google_map($atts = null, $content = null)
 {
     $atts = shortcode_atts(array('geo_address' => '', 'lat_value' => '41.850033', 'lng_value' => '-87.6500523', 'zoom_value' => '4', 'scroll_wheel' => 'no', 'map_style' => 'blue-water', 'map_height' => '400', 'pan_control' => 'yes', 'zoom_control' => 'yes', 'map_draggable' => 'yes', 'map_marker' => '', 'custom_class' => ''), $atts, 'google_map');
     $random_id = rand();
     $lat_value = floatval($atts['lat_value']);
     $lng_value = floatval($atts['lng_value']);
     $zoom_value = floatval($atts['zoom_value']);
     $map_height = intval($atts['map_height']);
     $pan_control = (bool) ($atts['pan_control'] === 'yes') ? true : false;
     $zoom_control = (bool) ($atts['zoom_control'] === 'yes') ? true : false;
     $map_draggable = (bool) ($atts['map_draggable'] === 'yes') ? apply_filters('cherry_shortcodes_google_map_draggable', !wp_is_mobile(), $atts) : false;
     $scroll_wheel = (bool) ($atts['scroll_wheel'] === 'yes') ? true : false;
     $addr = sanitize_text_field($atts['geo_address']);
     $map_style = sanitize_text_field($atts['map_style']);
     $custom_class = sanitize_text_field($atts['custom_class']);
     $map_marker = sanitize_text_field($atts['map_marker']);
     $marker_desc = do_shortcode($content);
     $style = Cherry_Shortcodes_Tools::get_map_style_json($map_style);
     if ('' !== $addr) {
         $geo_position = Cherry_Shortcodes_Tools::google_geocoding($addr);
         $lat_value = floatval($geo_position['lat']);
         $lng_value = floatval($geo_position['lng']);
     }
     $map_marker_attachment_id = Cherry_Shortcodes_Tools::get_attachment_id_from_src($map_marker);
     if (isset($map_marker_attachment_id)) {
         $map_marker = wp_get_attachment_image_src($map_marker_attachment_id);
         $map_marker = json_encode($map_marker);
     } else {
         $map_marker = 'default';
     }
     $data_attr_line = '';
     $data_attr_line .= 'data-map-id="google-map-' . $random_id . '"';
     $data_attr_line .= 'data-lat-value="' . $lat_value . '"';
     $data_attr_line .= 'data-lng-value="' . $lng_value . '"';
     $data_attr_line .= 'data-zoom-value="' . $zoom_value . '"';
     $data_attr_line .= 'data-scroll-wheel="' . $scroll_wheel . '"';
     $data_attr_line .= 'data-pan-control="' . $pan_control . '"';
     $data_attr_line .= 'data-zoom-control="' . $zoom_control . '"';
     $data_attr_line .= 'data-map-draggable="' . $map_draggable . '"';
     $data_attr_line .= "data-map-marker='" . $map_marker . "'";
     $data_attr_line .= "data-map-style='" . $style . "'";
     $html = '<div class="google-map-container ' . $custom_class . '" style="height:' . $map_height . 'px;" ' . $data_attr_line . '>';
     $html .= '<div id="google-map-' . $random_id . '" class="google-map"></div>';
     $html .= '<div class="marker-desc">' . $marker_desc . '</div>';
     $html .= '</div>';
     cherry_query_asset('js', array('cherry-google-map', 'cherry-shortcodes-init'));
     return apply_filters('cherry_shortcodes_output', $html, $atts, 'google_map');
 }