示例#1
0
文件: feeds.php 项目: bangjojo/wp
 /**
  * GeoRSS Item
  * Adds geo RSS nodes to the feed item.
  */
 function georss_item()
 {
     global $wpgeo, $post;
     if ($wpgeo->show_maps()) {
         $coord = get_wpgeo_post_coord($post->ID);
         if ($coord->is_valid_coord()) {
             echo '<georss:point>' . esc_html($coord->get_delimited(' ')) . '</georss:point>';
             echo '<geo:lat>' . esc_html($coord->latitude()) . '</geo:lat>';
             echo '<geo:long>' . esc_html($coord->longitude()) . '</geo:long>';
         }
     }
 }
示例#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;
     }
 }
示例#3
0
文件: admin.php 项目: hbuisman/WP-Geo
    /**
     * WP Geo Location Inner Custom Box
     */
    function wpgeo_location_inner_custom_box()
    {
        global $wpgeo, $post;
        $wp_geo_options = get_option('wp_geo_options');
        $search = '';
        $coord = get_wpgeo_post_coord($post->ID);
        $title = get_post_meta($post->ID, WPGEO_TITLE_META, true);
        $marker = get_post_meta($post->ID, WPGEO_MARKER_META, true);
        $settings = WPGeo::get_post_map_settings($post->ID);
        $wpgeo_map_settings_zoom = '';
        $wpgeo_map_settings_type = '';
        $wpgeo_map_settings_centre = '';
        $wpgeo_map_settings_zoom_checked = '';
        $wpgeo_map_settings_type_checked = '';
        $wpgeo_map_settings_centre_checked = '';
        $markers_menu = array('selected' => $marker, 'echo' => 0, 'name' => 'wp_geo_marker', 'show_option_none' => '(' . __('Use Default', 'wp-geo') . ')', 'option_none_value' => '');
        if (!empty($settings['zoom'])) {
            $wpgeo_map_settings_zoom = $settings['zoom'];
            $wpgeo_map_settings_zoom_checked = checked(true, true, false);
        } elseif ($wp_geo_options['save_post_zoom'] == 'Y') {
            $wpgeo_map_settings_zoom = $wp_geo_options['save_post_zoom'];
            $wpgeo_map_settings_zoom_checked = checked(true, true, false);
        }
        if (!empty($settings['type'])) {
            $wpgeo_map_settings_type = $settings['type'];
            $wpgeo_map_settings_type_checked = checked(true, true, false);
        } elseif ($wp_geo_options['save_post_map_type'] == 'Y') {
            $wpgeo_map_settings_type = $wp_geo_options['save_post_map_type'];
            $wpgeo_map_settings_type_checked = checked(true, true, false);
        }
        if (!empty($settings['centre'])) {
            $wpgeo_map_settings_centre = $settings['centre'];
            $wpgeo_map_settings_centre_checked = checked(true, true, false);
        } elseif ($wp_geo_options['save_post_centre_point'] == 'Y') {
            $wpgeo_map_settings_centre = $wp_geo_options['save_post_centre_point'];
            $wpgeo_map_settings_centre_checked = checked(true, true, false);
        }
        $map_html = $this->map->get_map_html(array('classes' => array('wp_geo_map', 'wpgeo_map_admin_post'), 'styles' => array('width' => '100%', 'height' => 300, 'padding' => '0px', 'margin' => '0px'), 'content' => __('Loading Google map, please wait...', 'wp-geo')));
        // Use nonce for verification
        echo '<input type="hidden" name="wpgeo_location_noncename" id="wpgeo_location_noncename" value="' . wp_create_nonce('wpgeo_edit_post') . '" />';
        // The actual fields for data entry
        echo '<table cellpadding="3" cellspacing="5" class="form-table">
			<tr>
				<td colspan="2">' . $map_html . '</td>
			</tr>
			<tr>
				<th scope="row">' . esc_html__('Search for location', 'wp-geo') . '</th>
				<td><input name="wp_geo_search" type="text" size="45" id="wp_geo_search" value="' . esc_attr($search) . '" placeholder="' . esc_attr__('e.g. town, postcode or address', 'wp-geo') . '" />
					<input type="hidden" name="wp_geo_base_country_code" id="wp_geo_base_country_code" value="' . esc_attr(apply_filters('wpgeo_base_country_code', '')) . '" />
					<span class="submit"><input type="button" id="wp_geo_search_button" class="button" name="wp_geo_search_button" value="' . esc_attr__('Search', 'wp-geo') . '" /></span></td>
			</tr>
			<tr>
				<th scope="row">' . esc_html__('Co-ordinates', 'wp-geo') . '</th>
				<td><input name="wp_geo_latitude" type="text" size="25" id="wp_geo_latitude" value="' . esc_attr($coord->latitude()) . '" placeholder="' . esc_attr__('Latitude', 'wp-geo') . '" />,
					<input name="wp_geo_longitude" type="text" size="25" id="wp_geo_longitude" value="' . esc_attr($coord->longitude()) . '" placeholder="' . esc_attr__('Longitude', 'wp-geo') . '" /><br />
					<a href="#" class="button button-small wpgeo-clear-location-fields">' . esc_html__('clear location', 'wp-geo') . '</a> <a href="#" class="button button-small wpgeo-centre-location">' . esc_html__('centre location', 'wp-geo') . '</a>
				</td>
			</tr>
			<tr>
				<th scope="row">' . esc_html__('Marker Title', 'wp-geo') . ' <small>(' . esc_html__('optional', 'wp-geo') . ')</small></th>
				<td><input name="wp_geo_title" type="text" size="25" style="width:100%;" id="wp_geo_title" value="' . esc_attr($title) . '" /></td>
			</tr>
			<tr>
				<th scope="row">' . esc_html__('Marker Image', 'wp-geo') . '</th>
				<td>' . $wpgeo->markers->dropdown_markers($markers_menu) . '</td>
			</tr>
			<tr>
				<th scope="row">' . esc_html__('Map Settings', 'wp-geo') . '</th>
				<td>
					<label for="wpgeo_map_settings_zoom"><input type="checkbox" name="wpgeo_map_settings_zoom" id="wpgeo_map_settings_zoom" value="' . esc_attr($wpgeo_map_settings_zoom) . '" ' . $wpgeo_map_settings_zoom_checked . ' /> ' . esc_html__('Save custom map zoom for this post', 'wp-geo') . '</label><br />
					<label for="wpgeo_map_settings_type"><input type="checkbox" name="wpgeo_map_settings_type" id="wpgeo_map_settings_type" value="' . esc_attr($wpgeo_map_settings_type) . '" ' . $wpgeo_map_settings_type_checked . ' /> ' . esc_html__('Save custom map type for this post', 'wp-geo') . '</label><br />
					<label for="wpgeo_map_settings_centre"><input type="checkbox" name="wpgeo_map_settings_centre" id="wpgeo_map_settings_centre" value="' . esc_attr($wpgeo_map_settings_centre) . '" ' . $wpgeo_map_settings_centre_checked . ' /> ' . esc_html__('Save map centre point for this post', 'wp-geo') . '</label>
				</td>
			</tr>
			' . apply_filters('wpgeo_edit_post_map_fields', '', $post->ID) . '
		</table>';
    }
示例#4
0
文件: wp-geo.php 项目: bangjojo/wp
 /**
  * Get WP Geo Posts
  *
  * @todo Use same parameters as query_posts by default.
  *
  * @param array $args Arguments.
  * @return array Points.
  */
 function get_wpgeo_posts($args = null)
 {
     global $customFields;
     $default_args = array('numberposts' => 5);
     $arguments = wp_parse_args($args, $default_args);
     extract($arguments, EXTR_SKIP);
     $customFields = "'" . WPGEO_LONGITUDE_META . "', '" . WPGEO_LATITUDE_META . "'";
     $custom_posts = new WP_Query();
     add_filter('posts_join', array($this->wpgeo_query, 'get_custom_field_posts_join'));
     add_filter('posts_groupby', array($this->wpgeo_query, 'get_custom_field_posts_group'));
     $custom_posts->query('showposts=' . $numberposts);
     remove_filter('posts_join', array($this->wpgeo_query, 'get_custom_field_posts_join'));
     remove_filter('posts_groupby', array($this->wpgeo_query, 'get_custom_field_posts_group'));
     $points = array();
     while ($custom_posts->have_posts()) {
         $custom_posts->the_post();
         $id = get_the_ID();
         $coord = get_wpgeo_post_coord($id);
         if ($coord->is_valid_coord()) {
             $points[] = array('id' => $id, 'lat' => $coord->latitude(), 'long' => $coord->longitude());
         }
     }
     return $points;
 }
示例#5
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));
}