/** * Outputs the widget with the selected settings * * @since 3.0.0 */ public function widget($args, $instance) { extract($instance); $sgm_options = get_option('SGMoptions'); // get options defined in admin page $sgm_options = wp_parse_args($sgm_options, Simple_Google_Map::$default_options); if (!$lat) { $lat = '0'; } if (!$lng) { $lng = '0'; } if (!$zoom) { $zoom = $sgm_options['zoom']; } // 1-19 if (!$type) { $type = $sgm_options['type']; } // ROADMAP, SATELLITE, HYBRID, TERRAIN if (!$icon) { $icon = $sgm_options['icon']; } if (!$content) { $content = $sgm_options['content']; } if (!$directionsto) { $directions_to = ''; } else { $directions_to = $directionsto; } $content = Simple_Google_Map::strip_last_chars(htmlspecialchars_decode($content), array('<br>', '<br/>', '<br />')); $directions_form = ''; if ($directions_to) { $directions_form = '<form method="get" action="//maps.google.com/maps"><input type="hidden" name="daddr" value="' . $directions_to . '" /><input type="text" class="text" name="saddr" /><input type="submit" class="submit" value="Directions" /></form>'; } $marker = "var marker = new google.maps.Marker({\n\t\t\tposition: latlng,\n\t\t\tmap: map,\n\t\t\ttitle: '',"; if ($icon) { $icon = "var image = {\n\t\t\t\turl: '{$icon}',\n\t\t\t};"; $marker .= "\n" . 'icon: image,' . "\n"; } $marker .= '});'; $infowindow_arr = array($content, $directions_form); $infowindow_content = implode('<br>', array_filter($infowindow_arr)); extract($args); echo $before_widget; if ($instance['title']) { echo $before_title . $instance['title'] . $after_title; } $map = '<script type="text/javascript">'; $map .= "function makeMap() {\n\t\t\t\tvar latlng = new google.maps.LatLng({$lat}, {$lng});\n\t\t\t\tvar myOptions = {\n\t\t\t\t\tzoom: {$zoom},\n\t\t\t\t\tcenter: latlng,\n\t\t\t\t\tmapTypeControl: true,\n\t\t\t\t\tmapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},\n\t\t\t\t\tnavigationControl: true,\n\t\t\t\t\tnavigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},\n\t\t\t\t\tmapTypeId: google.maps.MapTypeId.{$type}\n\t\t\t\t};\n\t\t\t\tvar map = new google.maps.Map(document.getElementById('SGM'), myOptions);\n\t\t\t\tvar contentstring = '<div class=\"infoWindow\">{$infowindow_content}</div>';\n\t\t\t\tvar infowindow = new google.maps.InfoWindow({\n\t\t\t\t\tcontent: contentstring\n\t\t\t\t});\n\t\t\t\t{$icon}\n\t\t\t\t{$marker}\n\t\t\t\tgoogle.maps.event.addListener(marker, 'click', function() {\n\t\t\t\t infowindow.open(map,marker);\n\t\t\t\t});\n\t\t\t}\n\t\t\twindow.onload = makeMap;"; $map .= '</script>'; $map .= '<div id="SGM"></div>'; echo $map; echo $after_widget; }
/** * Output CSS into header * * @since 3.0.0 */ public function map($atts) { $sgm_options = get_option('SGMoptions'); // get options defined in admin page $sgm_options = wp_parse_args($sgm_options, Simple_Google_Map::$default_options); $lat = isset($atts['lat']) ? $atts['lat'] : '0'; $lng = isset($atts['lng']) ? $atts['lng'] : '0'; $zoom = isset($atts['zoom']) ? $atts['zoom'] : $sgm_options['zoom']; $type = isset($atts['type']) ? strtoupper($atts['type']) : $sgm_options['type']; $content = isset($atts['content']) ? $atts['content'] : $sgm_options['content']; $directions_to = isset($atts['directionsto']) ? $atts['directionsto'] : ''; $icon = isset($atts['icon']) ? esc_url($atts['icon'], array('http', 'https')) : $sgm_options['icon']; $content = Simple_Google_Map::strip_last_chars(htmlspecialchars_decode($content), array('<br>', '<br/>', '<br />')); $directions_form = ''; if ($directions_to) { $directions_form = '<form method="get" action="//maps.google.com/maps"><input type="hidden" name="daddr" value="' . $directions_to . '" /><input type="text" class="text" name="saddr" /><input type="submit" class="submit" value="Directions" /></form>'; } $marker = "var marker = new google.maps.Marker({\n\t\t\tposition: latlng,\n\t\t\tmap: map,\n\t\t\ttitle: '',"; if ($icon) { $icon = "var image = {\n\t\t\t\turl: '{$icon}',\n\t\t\t};"; $marker .= "\n" . 'icon: image,' . "\n"; } $marker .= '});'; $infowindow_arr = array($content, $directions_form); $infowindow_content = implode('<br>', array_filter($infowindow_arr)); $map = '<script type="text/javascript">'; $map .= "function makeMap() {\n\t\t\t\tvar latlng = new google.maps.LatLng({$lat}, {$lng});\n\t\t\t\tvar myOptions = {\n\t\t\t\t\tzoom: {$zoom},\n\t\t\t\t\tcenter: latlng,\n\t\t\t\t\tmapTypeControl: true,\n\t\t\t\t\tmapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},\n\t\t\t\t\tnavigationControl: true,\n\t\t\t\t\tnavigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},\n\t\t\t\t\tmapTypeId: google.maps.MapTypeId.{$type}\n\t\t\t\t};\n\t\t\t\tvar map = new google.maps.Map(document.getElementById('SGM'), myOptions);\n\t\t\t\tvar contentstring = '<div class=\"infoWindow\">{$infowindow_content}</div>';\n\t\t\t\tvar infowindow = new google.maps.InfoWindow({\n\t\t\t\t\tcontent: contentstring\n\t\t\t\t});\n\t\t\t\t{$icon}\n\t\t\t\t{$marker}\n\t\t\t\tgoogle.maps.event.addListener(marker, 'click', function() {\n\t\t\t\t infowindow.open(map,marker);\n\t\t\t\t});\n\t\t\t};\n\t\t\twindow.onload = makeMap;"; $map .= '</script>'; $map .= '<div id="SGM"></div>'; return $map; }