Ejemplo n.º 1
0
    /**
     * Map Scripts Init
     * Output Javascripts to display maps in admin.
     *
     * @param object $coord WPGeo_Coord.
     * @param int $zoom Zoom.
     * @param bool $panel_open Admin panel open?
     * @param bool $hide_marker Hide marker?
     * @return string HTML content.
     */
    function mapScriptsInit($coord, $zoom = 5, $panel_open = false, $hide_marker = false)
    {
        global $wpgeo, $post;
        $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'];
        // Centre on London
        if (!$coord->is_valid_coord()) {
            $coord = new WPGeo_Coord($wp_geo_options['default_map_latitude'], $wp_geo_options['default_map_longitude']);
            $zoom = $wp_geo_options['default_map_zoom'];
            $panel_open = true;
            $hide_marker = true;
        }
        $map_center_coord = new WPGeo_Coord($coord->latitude(), $coord->longitude());
        if (isset($post) && is_numeric($post->ID) && $post->ID > 0) {
            $settings = WPGeo::get_post_map_settings($post->ID);
            if (isset($settings['zoom']) && is_numeric($settings['zoom'])) {
                $zoom = $settings['zoom'];
            }
            if (!empty($settings['type'])) {
                $maptype = $settings['type'];
            }
            if (!empty($settings['centre'])) {
                $map_center = explode(',', $settings['centre']);
                if (count($map_center) == 2) {
                    $new_mapcentre_coord = new WPGeo_Coord($map_center[0], $map_center[1]);
                    if ($new_mapcentre_coord->is_valid_coord()) {
                        $map_center_coord = $new_mapcentre_coord;
                    }
                }
            }
        }
        // Vars
        $panel_open = !$hide_marker || $panel_open ? '.removeClass("closed")' : '';
        $wpgeo_admin_vars = array('api' => $this->get_api_string(), 'map_dom_id' => $this->admin->map->get_dom_id(), 'map' => null, 'marker' => null, 'zoom' => intval($zoom), 'mapCentreX' => $map_center_coord->latitude(), 'mapCentreY' => $map_center_coord->longitude(), 'latitude' => $coord->latitude(), 'longitude' => $coord->longitude(), 'hideMarker' => absint($hide_marker));
        // Script
        // @todo Maps API needs changing
        return '
			<script type="text/javascript">
			var WPGeo_Admin = ' . json_encode($wpgeo_admin_vars) . ';
			WPGeo_Admin.mapType = ' . $this->api_string($maptype, 'maptype') . ';
			
			jQuery(document).ready(function($) {
				$("#wpgeo_location")' . $panel_open . '.bind("WPGeo_adminPostMapReady", function(e){
					' . apply_filters('wpgeo_map_js_preoverlays', '', 'WPGeo_Admin.map') . '
				});
			});
			</script>
			';
    }
Ejemplo n.º 2
0
 /**
  * WP Geo Location Save post data
  * When the post is saved, saves our custom data.
  *
  * @todo Use update_post_meta() where appropriate, rather than always adding/deleting.
  *
  * @param int $post_id Post ID.
  */
 function wpgeo_location_save_postdata($post_id)
 {
     global $wpgeo;
     if (!$wpgeo->checkGoogleAPIKey()) {
         return;
     }
     // Verify this came from the our screen and with proper authorization,
     // because save_post can be triggered at other times
     if (!isset($_POST['wpgeo_location_noncename']) || !wp_verify_nonce($_POST['wpgeo_location_noncename'], plugin_basename('wpgeo_edit_post'))) {
         return $post_id;
     }
     // Authenticate user
     if ('page' == $_POST['post_type']) {
         if (!current_user_can('edit_page', $post_id)) {
             return $post_id;
         }
     } elseif ('post' == $_POST['post_type']) {
         if (!current_user_can('edit_post', $post_id)) {
             return $post_id;
         }
     } elseif (function_exists('get_post_type_object')) {
         $post_type = get_post_type_object($_POST['post_type']);
         // @todo Should this be "edit_" . $post_type->capability_type
         if (!current_user_can($post_type->cap->edit_post, $post_id)) {
             return $post_id;
         }
     }
     $mydata = array();
     // Find and save the location data
     if (isset($_POST['wp_geo_latitude']) && isset($_POST['wp_geo_longitude'])) {
         // Only delete post meta if isset (to avoid deletion in bulk/quick edit mode)
         delete_post_meta($post_id, WPGEO_LATITUDE_META);
         delete_post_meta($post_id, WPGEO_LONGITUDE_META);
         $coord = new WPGeo_Coord($_POST['wp_geo_latitude'], $_POST['wp_geo_longitude']);
         if ($coord->is_valid_coord()) {
             add_post_meta($post_id, WPGEO_LATITUDE_META, $coord->latitude());
             add_post_meta($post_id, WPGEO_LONGITUDE_META, $coord->longitude());
             $mydata[WPGEO_LATITUDE_META] = $coord->latitude();
             $mydata[WPGEO_LONGITUDE_META] = $coord->longitude();
         }
     }
     // Find and save the title data
     if (isset($_POST['wp_geo_title'])) {
         delete_post_meta($post_id, WPGEO_TITLE_META);
         if (!empty($_POST['wp_geo_title'])) {
             add_post_meta($post_id, WPGEO_TITLE_META, $_POST['wp_geo_title']);
             $mydata[WPGEO_TITLE_META] = $_POST['wp_geo_title'];
         }
     }
     // Find and save the marker data
     if (isset($_POST['wp_geo_marker'])) {
         if (!empty($_POST['wp_geo_marker'])) {
             update_post_meta($post_id, WPGEO_MARKER_META, $_POST['wp_geo_marker']);
             $mydata[WPGEO_MARKER_META] = $_POST['wp_geo_marker'];
         } else {
             delete_post_meta($post_id, WPGEO_MARKER_META);
         }
     }
     // Find and save the settings data
     delete_post_meta($post_id, WPGEO_MAP_SETTINGS_META);
     $settings = array();
     if (isset($_POST['wpgeo_map_settings_zoom']) && !empty($_POST['wpgeo_map_settings_zoom'])) {
         $settings['zoom'] = $_POST['wpgeo_map_settings_zoom'];
     }
     if (isset($_POST['wpgeo_map_settings_type']) && !empty($_POST['wpgeo_map_settings_type'])) {
         $settings['type'] = $wpgeo->decode_api_string($_POST['wpgeo_map_settings_type'], 'maptype');
     }
     if (isset($_POST['wpgeo_map_settings_centre']) && !empty($_POST['wpgeo_map_settings_centre'])) {
         $settings['centre'] = $_POST['wpgeo_map_settings_centre'];
     }
     add_post_meta($post_id, WPGEO_MAP_SETTINGS_META, $settings);
     $mydata[WPGEO_MAP_SETTINGS_META] = $settings;
     return $mydata;
 }