Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * Add widget map
  *
  * @param array $args Args.
  * @return string Output.
  */
 function add_widget_map($args = null)
 {
     global $wpgeo, $post;
     $wp_geo_options = get_option('wp_geo_options');
     $current_post = $post->ID;
     $html_js = '';
     $markers_js = '';
     $polyline_js = '';
     $markers_js_3 = '';
     $polyline_js_3 = '';
     $args = wp_parse_args($args, array('width' => '100%', 'height' => 150, 'maptype' => empty($wp_geo_options['google_map_type']) ? 'G_NORMAL_MAP' : $wp_geo_options['google_map_type'], 'show_polylines' => false, 'zoom' => $wp_geo_options['default_map_zoom'], 'id' => 'widget_map', 'posts' => null));
     if (!$args['posts']) {
         return $html_js;
     }
     // Create Map
     $map = new WPGeo_Map($args['id']);
     $map->set_size($args['width'], $args['height']);
     $map->set_map_centre(new WPGeo_Coord(0, 0));
     $map->set_map_zoom($args['zoom']);
     $map->set_map_type($args['maptype']);
     // If Google API Key...
     if ($wpgeo->checkGoogleAPIKey()) {
         // Add points (from posts) to map
         $count = 0;
         foreach ($args['posts'] as $geo_post) {
             $coord = get_wpgeo_post_coord($geo_post->ID);
             if ($coord->is_valid_coord()) {
                 $count++;
                 if (count($count) == 1) {
                     $map->set_map_centre($coord);
                 }
                 $map->add_point($coord, array('icon' => apply_filters('wpgeo_marker_icon', 'small', $geo_post, 'widget'), 'title' => get_wpgeo_title($geo_post->ID), 'link' => apply_filters('wpgeo_marker_link', get_permalink($geo_post), $geo_post), 'post' => $geo_post));
             }
         }
         // Only show map widget if there are coords to show
         if (count($map->points) > 0) {
             // Add polylines (to connect points) to map
             if ($args['show_polylines']) {
                 $polyline = new WPGeo_Polyline(array('color' => $wp_geo_options['polyline_colour']));
                 foreach ($map->points as $point) {
                     $polyline->add_coord($point->get_coord());
                 }
                 $map->add_polyline($polyline);
             }
             $html_js .= $map->get_map_html(array('classes' => array('wp_geo_map')));
         }
         $wpgeo->maps->add_map($map);
         return $html_js;
     }
 }
Beispiel #3
0
/**
 * Get WP Geo Post Static Map
 * Gets the HTML for a static post map.
 *
 * @param   int    $post_id  (optional) Post ID.
 * @param   array  $query    (optional) Parameters.
 * @return  string           HTML.
 */
function get_wpgeo_post_static_map($post_id = 0, $query = null)
{
    global $post, $wpgeo;
    $post_id = absint($post_id);
    $post_id = $post_id > 0 ? $post_id : $post->ID;
    // Show Map?
    if (!$post_id || is_feed() || !$wpgeo->show_maps() || !$wpgeo->checkGoogleAPIKey()) {
        return '';
    }
    $coord = get_wpgeo_post_coord($post_id);
    if (!$coord->is_valid_coord()) {
        return '';
    }
    // Fetch wp geo options & post settings
    $wp_geo_options = get_option('wp_geo_options');
    $settings = WPGeo::get_post_map_settings($post_id);
    // Options
    $options = wp_parse_args($query, array('width' => trim($wp_geo_options['default_map_width'], 'px'), 'height' => trim($wp_geo_options['default_map_height'], 'px'), 'maptype' => $wp_geo_options['google_map_type'], 'zoom' => $wp_geo_options['default_map_zoom']));
    // Can't do percentage sizes so abort
    if (strpos($options['width'], '%') !== false || strpos($options['height'], '%') !== false) {
        return '';
    }
    // Map Options
    $zoom = isset($settings['zoom']) && is_numeric($settings['zoom']) ? $settings['zoom'] : $options['zoom'];
    $map_type = !empty($settings['type']) ? $settings['type'] : $options['maptype'];
    $center_coord = new WPGeo_Coord($coord->latitude(), $coord->longitude());
    if (!empty($settings['centre'])) {
        $center = explode(',', $settings['centre']);
        $maybe_center_coord = new WPGeo_Coord($center[0], $center[1]);
        if ($maybe_center_coord->is_valid_coord()) {
            $center_coord = $maybe_center_coord;
        }
    }
    // Map
    $map = new WPGeo_Map();
    $map->set_map_centre($center_coord);
    $map->set_map_zoom($zoom);
    $map->set_map_type($map_type);
    $map->set_size($options['width'], $options['height']);
    $map->add_point($coord);
    $url = $wpgeo->api->static_map_url($map);
    return sprintf('<img id="wp_geo_static_map_%s" src="%s" class="wp_geo_static_map" />', $post_id, esc_url($url));
}