/** * @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 } }