/** * The Content * Output Map placeholders in the content area if set to automatically. * * @param string $content HTML content. * @return string HTML content. */ function the_content($content = '') { global $wpgeo, $post, $wpdb; $new_content = ''; if ($wpgeo->show_maps() && !is_feed()) { $wp_geo_options = get_option('wp_geo_options'); $maptype = empty($wp_geo_options['google_map_type']) ? 'G_NORMAL_MAP' : $wp_geo_options['google_map_type']; $mapzoom = $wp_geo_options['default_map_zoom']; $coord = get_wpgeo_post_coord($post->ID); $title = get_wpgeo_title($post->ID); $marker = get_post_meta($post->ID, WPGEO_MARKER_META, true); $settings = WPGeo::get_post_map_settings($post->ID); $mymaptype = $maptype; if (isset($settings['type']) && !empty($settings['type'])) { $mymaptype = $settings['type']; } $mymapzoom = $mapzoom; if (isset($settings['zoom']) && is_numeric($settings['zoom'])) { $mymapzoom = $settings['zoom']; } // Need a map? if ($coord->is_valid_coord()) { $map = new WPGeo_Map($post->ID); // Add point $marker_large = empty($marker) ? 'large' : $marker; $icon = apply_filters('wpgeo_marker_icon', $marker_large, $post, 'post'); $map->add_point($coord, array('icon' => $icon, 'title' => $title, 'link' => get_permalink($post->ID))); $map->setMapZoom($mymapzoom); $map->setMapType($mymaptype); if (!empty($settings['centre'])) { $centre = explode(',', $settings['centre']); if (is_array($centre) && count($centre) == 2) { $map->setMapCentre($centre[0], $centre[1]); } else { $map->setMapCentre($coord->latitude(), $coord->longitude()); } } else { $map->setMapCentre($coord->latitude(), $coord->longitude()); } $map_types = $this->control_type_option_strings($wp_geo_options); foreach ($map_types as $map_type) { $map->addMapType($map_type); } if ($wp_geo_options['show_map_scale'] == 'Y') { $map->showMapScale(true); } if ($wp_geo_options['show_map_overview'] == 'Y') { $map->showMapOverview(true); } if ($wp_geo_options['show_streetview_control'] == 'Y') { $map->show_streetview_control(true); } $map->setMapControl($wp_geo_options['default_map_control']); $wpgeo->maps->add_map($map); $new_content .= $map->get_map_html(array('classes' => array('wp_geo_map'), 'styles' => array('width' => $wp_geo_options['default_map_width'], 'height' => $wp_geo_options['default_map_height']))); $new_content = apply_filters('wpgeo_the_content_map', $new_content); } // Add map to content $show_post_map = apply_filters('wpgeo_show_post_map', $wp_geo_options['show_post_map'], $post->ID); // Show at top/bottom of post if ($show_post_map == 'TOP') { $content = $new_content . $content; } elseif ($show_post_map == 'BOTTOM') { $content = $content . $new_content; } } return $content; }
/** * @method WP Head * @description Outputs HTML and JavaScript to the header. */ function wp_head() { global $wpgeo; $js_map_inits = ''; $js_marker_inits = ''; $this->meta_tags(); // WP Geo Default Settings $wp_geo_options = get_option('wp_geo_options'); $controltypes = array(); if ($wp_geo_options['show_map_type_normal'] == 'Y') { $controltypes[] = 'G_NORMAL_MAP'; } if ($wp_geo_options['show_map_type_satellite'] == 'Y') { $controltypes[] = 'G_SATELLITE_MAP'; } if ($wp_geo_options['show_map_type_hybrid'] == 'Y') { $controltypes[] = 'G_HYBRID_MAP'; } if ($wp_geo_options['show_map_type_physical'] == 'Y') { $controltypes[] = 'G_PHYSICAL_MAP'; } echo ' <script type="text/javascript"> //<![CDATA[ // WP Geo default settings var wpgeo_w = \'' . $wp_geo_options['default_map_width'] . '\'; var wpgeo_h = \'' . $wp_geo_options['default_map_height'] . '\'; var wpgeo_type = \'' . $wp_geo_options['google_map_type'] . '\'; var wpgeo_zoom = ' . $wp_geo_options['default_map_zoom'] . '; var wpgeo_controls = \'' . $wp_geo_options['default_map_control'] . '\'; var wpgeo_controltypes = \'' . implode(",", $controltypes) . '\'; var wpgeo_scale = \'' . $wp_geo_options['show_map_scale'] . '\'; var wpgeo_overview = \'' . $wp_geo_options['show_map_overview'] . '\'; //]]> </script> '; // CSS echo '<link rel="stylesheet" href="' . WPGEO_URL . 'css/wp-geo.css" type="text/css" />'; if ($wpgeo->show_maps() || $wpgeo->widget_is_active()) { global $posts; $this->markers->wp_head(); $wp_geo_options = get_option('wp_geo_options'); $maptype = empty($wp_geo_options['google_map_type']) ? 'G_NORMAL_MAP' : $wp_geo_options['google_map_type']; $mapzoom = $wp_geo_options['default_map_zoom']; // Coords to show on map? $coords = array(); for ($i = 0; $i < count($posts); $i++) { $post = $posts[$i]; $latitude = get_post_meta($post->ID, WPGEO_LATITUDE_META, true); $longitude = get_post_meta($post->ID, WPGEO_LONGITUDE_META, true); $title = get_wpgeo_title($post->ID); $marker = get_post_meta($post->ID, WPGEO_MARKER_META, true); $settings = get_post_meta($post->ID, WPGEO_MAP_SETTINGS_META, true); $mymaptype = $maptype; if (isset($settings['type']) && !empty($settings['type'])) { $mymaptype = $settings['type']; } $mymapzoom = $mapzoom; if (isset($settings['zoom']) && is_numeric($settings['zoom'])) { $mymapzoom = $settings['zoom']; } if (is_numeric($latitude) && is_numeric($longitude)) { $push = array('id' => $post->ID, 'latitude' => $latitude, 'longitude' => $longitude, 'title' => $title, 'link' => get_permalink($post->ID), 'post' => $post); array_push($coords, $push); // ----------- Start - Create maps for visible posts and pages ----------- $map = new WPGeo_Map($post->ID); // Create map // Add point $marker_large = empty($marker) ? 'large' : $marker; $icon = apply_filters('wpgeo_marker_icon', $marker_large, $post, 'post'); $map->addPoint($latitude, $longitude, $icon, $title, get_permalink($post->ID)); $map->setMapZoom($mymapzoom); // Set zoom $map->setMapType($mymaptype); // Set map type if (!empty($settings['centre'])) { $centre = explode(',', $settings['centre']); if (is_array($centre) && count($centre) == 2) { $map->setMapCentre($centre[0], $centre[1]); } else { $map->setMapCentre($latitude, $longitude); } } else { $map->setMapCentre($latitude, $longitude); } if ($wp_geo_options['show_map_type_physical'] == 'Y') { $map->addMapType('G_PHYSICAL_MAP'); } // Show PHYSICAL map? if ($wp_geo_options['show_map_type_normal'] == 'Y') { $map->addMapType('G_NORMAL_MAP'); } // Show NORMAL map? if ($wp_geo_options['show_map_type_satellite'] == 'Y') { $map->addMapType('G_SATELLITE_MAP'); } // Show SATELLITE map? if ($wp_geo_options['show_map_type_hybrid'] == 'Y') { $map->addMapType('G_HYBRID_MAP'); } // Show HYBRID map? if ($wp_geo_options['show_map_scale'] == 'Y') { $map->showMapScale(true); } // Show map scale if ($wp_geo_options['show_map_overview'] == 'Y') { $map->showMapOverview(true); } // Show map overview $map->setMapControl($wp_geo_options['default_map_control']); // Set map control array_push($this->maps, $map); // Add map to maps array // ----------- End - Create maps for visible posts and pages ----------- } } // Need a map? if (count($coords) > 0) { // ----------- Start - Create map for visible posts and pages ----------- $map = new WPGeo_Map('visible'); $map->show_polyline = true; // Add points for ($j = 0; $j < count($coords); $j++) { $marker_small = empty($marker) ? 'small' : $marker; $icon = apply_filters('wpgeo_marker_icon', $marker_small, $coords[$j]['post'], 'multiple'); $map->addPoint($coords[$j]['latitude'], $coords[$j]['longitude'], $icon, $coords[$j]['title'], $coords[$j]['link']); } $map->setMapZoom($mapzoom); // Set zoom $map->setMapType($maptype); // Set map type if ($wp_geo_options['show_map_type_physical'] == 'Y') { // Show PHYSICAL map? $map->addMapType('G_PHYSICAL_MAP'); } if ($wp_geo_options['show_map_type_normal'] == 'Y') { // Show NORMAL map? $map->addMapType('G_NORMAL_MAP'); } if ($wp_geo_options['show_map_type_satellite'] == 'Y') { // Show SATELLITE map? $map->addMapType('G_SATELLITE_MAP'); } if ($wp_geo_options['show_map_type_hybrid'] == 'Y') { // Show HYBRID map? $map->addMapType('G_HYBRID_MAP'); } if ($wp_geo_options['show_map_scale'] == 'Y') { $map->showMapScale(true); } // Show map scale if ($wp_geo_options['show_map_overview'] == 'Y') { $map->showMapOverview(true); } // Show map overview $map->setMapControl($wp_geo_options['default_map_control']); // Set map control array_push($this->maps, $map); // Add map to maps array // ----------- End - Create map for visible posts and pages ----------- $google_maps_api_key = $wpgeo->get_google_api_key(); $zoom = $wp_geo_options['default_map_zoom']; // Loop through maps to get Javascript $js_map_writes = ''; foreach ($this->maps as $map) { $js_map_writes .= $map->renderMapJS(); } // Script $wpgeo->includeGoogleMapsJavaScriptAPI(); $html_content = ' <script type="text/javascript"> //<![CDATA[ var map = null; ' . $js_map_inits . ' var marker = null; ' . $js_marker_inits . ' function init_wp_geo_map() { if (GBrowserIsCompatible()) { ' . $js_map_writes . ' } } if (document.all&&window.attachEvent) { // IE-Win window.attachEvent("onload", function () { init_wp_geo_map(); }); window.attachEvent("onunload", GUnload); } else if (window.addEventListener) { // Others window.addEventListener("load", function () { init_wp_geo_map(); }, false); window.addEventListener("unload", GUnload, false); } //]]> </script>'; echo $html_content; } // Check if plugin head needed // Check for Google API key // Write Javascripts and CSS } }