get_options(); if ( !empty( $options['enable_permalinks'] ) ) { $args += array( 'publicly_queryable' => true, 'exclude_from_search' => false, 'rewrite' => array( 'slug' => $options['permalink_slug'] ), ); } $args += array( 'public' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => false, 'query_var' => 'sm-location', 'register_meta_box_cb' => array( &$this, 'location_meta_cb' ), 'supports' => array(), 'labels' => array( 'name' => 'Locations', 'singular_name' => 'Location', 'add_new_item' => 'Add New Location', 'edit_item' => 'Edit Location', 'new_item' => 'New Location', 'view_item' => 'View Locations', 'search_items' => 'Search Locations', 'not_found' => 'No Locations found', 'not_found_in_trash' => 'No Locations found in trash', ) ); // Register it register_post_type( 'sm-location', $args ); } // Register custom taxonomies for locations function register_location_taxonomies() { global $simple_map; $options = $simple_map->get_options(); foreach ( $options['taxonomies'] as $taxonomy => $tax_info ) { $this->register_location_taxonomy( $taxonomy, $tax_info ); } } // Register custom taxonomy for locations function register_location_taxonomy( $taxonomy, $tax_info ) { if ( taxonomy_exists( $taxonomy ) ) { return; } $tax_info += array( 'singular' => $taxonomy, 'plural' => $taxonomy, 'hierarchical' => false, ); $args = array( 'labels' => array( 'name' => 'Location ' . $tax_info['plural'], 'singular_name' => 'Location ' . $tax_info['singular'], 'search_items' => 'Search ' . $tax_info['plural'], 'popular_items' => 'Popular ' . $tax_info['plural'], 'all_items' => 'All ' . $tax_info['plural'], 'parent_item' => 'Parent ' . $tax_info['singular'], 'parent_item_colon' => 'Parent ' . $tax_info['singular'] . ':', 'edit_item' => 'Edit ' . $tax_info['singular'], 'update_item' => 'Update ' . $tax_info['singular'], 'add_new_item' => 'Add New ' . $tax_info['singular'], 'new_item_name' => 'New ' . $tax_info['singular'] . ' Name', 'separate_items_with_commas' => 'Separate ' . strtolower( $tax_info['plural'] ) . ' with commas', 'add_or_remove_items' => 'Add or remove ' . strtolower( $tax_info['plural'] ), 'choose_from_most_used' => 'Choose from the most used ' . strtolower( $tax_info['plural'] ), ), 'hierarchical' => $tax_info['hierarchical'], 'rewrite' => false, 'show_tagcloud' => false ); register_taxonomy( $taxonomy, 'sm-location', $args ); } // Add call back for meta box function location_meta_cb(){ add_meta_box( 'sm-location-premium-support', __( 'Premium Support', 'SimpleMap' ), array( &$this, 'premium_support' ), 'sm-location', 'side', 'high' ); add_meta_box( 'sm-geo-location', __( 'Geographic Location', 'SimpleMap' ), array( &$this, 'geo_location' ), 'sm-location', 'normal' ); add_meta_box( 'sm-additional-information', __( 'Additional Information', 'SimpleMap' ), array( &$this, 'additional_information' ), 'sm-location', 'normal' ); add_meta_box( 'sm-location-drag-drop', __( 'Drag and Drop Location', 'SimpleMap' ), array( &$this, 'location_drag_drop' ), 'sm-location', 'side' ); } // Add premium support box function premium_support() { global $simplemap_ps, $current_user; wp_get_current_user(); $status_key = md5( 'ft_premium_support_' . $simplemap_ps->product_id . '_' . sanitize_title_with_dashes( $simplemap_ps->site_url ) . '_' . sanitize_title_with_dashes( $simplemap_ps->server_url ) ) ; $sso_key = md5( 'ft_premium_sso_' . $current_user->ID . '_' . $simplemap_ps->product_id . '_' . sanitize_title_with_dashes( $simplemap_ps->site_url ) . '_' . sanitize_title_with_dashes( $simplemap_ps->server_url ) ); // Set status from transient if not set via global if ( '' == $simplemap_ps->ps_status && '' != get_transient( $status_key ) ) $simplemap_ps->ps_status = get_transient( $status_key ); // Set sso key from transient if not set via global if ( '' == $simplemap_ps->sso_status && '' != get_transient( $sso_key ) ) $simplemap_ps->sso_status = get_transient( $sso_key ); //echo "
";print_r( $simplemap_ps );echo ""; if ( ! url_has_ftps_for_item( $simplemap_ps ) ) : ?>
", "SimpleMap" ); ?>
http://', 'SimpleMap'); ?> |
|
/> |
Drag the marker to fine tune your location's placement on the map
id ) return; wp_enqueue_script( 'sm-drag-drop-location-js', site_url() . '/?sm-drag-drop-location-js=' . $post->ID, array( 'jquery' ) ); } // Javascript for add / edit location page function location_add_edit_js() { global $current_screen, $simple_map; $options = $simple_map->get_options(); if ( !isset( $_GET['sm-drag-drop-location-js'] ) ) return; $postid = (int) $_GET['sm-drag-drop-location-js']; $drag_drop_lat = get_post_meta( $postid, 'location_lat', true ) ? get_post_meta( $postid, 'location_lat', true ) : '40.730885'; $drag_drop_lng = get_post_meta( $postid, 'location_lng', true ) ? get_post_meta( $postid, 'location_lng', true ) : '-73.997383'; $drag_drop_zoom = ( $drag_drop_lat == '40.730885' ) ? 2 : 17; header( "Content-type: application/x-javascript" ); /* if ( '' == $options['api_key'] ) { die( "alert( '" . esc_js( __( "You will need to enter your API key in general options before your addresses will be coded properly.", 'SimpleMap' ) ) . "');" ); } */ ?> var map; var geocoder; var address; var marker; var place; function location_add_edit_js_init() { var latlng = new google.maps.LatLng( , ); var myOptions = { zoom: , center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map( document.getElementById( "dragdrop_map_canvas" ), myOptions ); marker = new google.maps.Marker({ position: latlng, map: map, draggable: true, animation: google.maps.Animation.DROP }); google.maps.event.addListener( map, 'click', dragDropGetAddress ); google.maps.event.addListener( marker, 'dragend', dragDropGetAddressTest ); geocoder = new google.maps.Geocoder(); jQuery( '#js-geo-encode-msg' ).removeClass( 'hidden' ); // Do geocode var geo_address = ''; geocoder.geocode( { 'address': geo_address }, function( results, status ) { if ( status == google.maps.GeocoderStatus.OK ) { var latlng = results[0].geometry.location; jQuery( "#location_lat" ).attr( 'value', latlng.lat() ); jQuery( "#location_lng" ).attr( 'value', latlng.lng() ); var smdata = { action: 'ajax_save_lat_lng', sm_id: , sm_lat: latlng.lat(), sm_lng: latlng.lng() }; jQuery.post( ajaxurl, smdata, function( response ) { jQuery( '#sm_js_update_lat_lng_result' ).html( response ); }); // Set drag/drop map to new location map.setCenter( latlng ); map.setZoom( ); marker = new google.maps.Marker({ map: map, position: latlng, draggable: true, animation: google.maps.Animation.DROP }); jQuery( '#js-geo-encode-msg' ).removeClass( 'hidden' ); } else { alert("Geocode was not successful for the following reason: " + status); } }); } function dragDropGetAddressTest() { var latlng = marker.getPosition(); geocoder.geocode( { 'latLng': latlng }, dragDropShowAddress ); } function dragDropGetAddress( event ) { if ( event.latlng != null ) { geocoder.geocode( { 'latLng': event.latlng }, dragDropShowAddress ); } } function dragDropShowAddress( results, status ) { marker.setMap(null); if ( status != google.maps.GeocoderStatus.OK ) { alert("Geocoder failed due to: " + status); map.addOverlay(marker); } else { var latlng = results[0].geometry.location; marker = new google.maps.Marker({ map: map, position: latlng, draggable: true, animation: google.maps.Animation.DROP }); dragDropUpdateFormFields( latlng ); place = results[0]; google.maps.event.addListener( marker, 'dragend', dragDropGetAddressTest ); } } jQuery(document).ready(function(){ location_add_edit_js_init(); }); function dragDropUpdateFormFields( latlng ) { jQuery( "#location_lat" ).attr( 'value', latlng.lat() ); jQuery( "#location_lng" ).attr( 'value', latlng.lng() ); jQuery( "#latlng_dontforget" ).hide(); jQuery( "#latlng_updated" ).fadeIn(); } function dragDropUpdateAddress() { var newAddress = {}; for ( var i = 0; i < place.address_components.length; i++ ) { var component = place.address_components[i]; newAddress[component.types[0]] = component.short_name; } var newStreet = ''; var newCity = ''; var newState = ''; var newZip = ''; var newCountry = ''; if ( newAddress.street_number ) { newStreet += newAddress.street_number; } if ( newAddress.route ) { if ( newStreet != '' ) { newStreet += ' '; } newStreet += newAddress.route; } if ( newAddress.locality ) { newCity += newAddress.locality; } if ( newAddress.administrative_area_level_1 ) { newState += newAddress.administrative_area_level_1; } if ( newAddress.postal_code ) { newZip += newAddress.postal_code; } if ( newAddress.country ) { newCountry += newAddress.country; } /* if ( place.AddressDetails.Country.AdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare != null ) newStreet = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName; else if ( place.AddressDetails.Country.AdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.Locality != null && place.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare != null ) newStreet = place.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName; if ( place.AddressDetails.Country.AdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName != null ) newCity = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName; else if ( place.AddressDetails.Country.AdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.Locality != null && place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName != null ) newCity = place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName; if ( place.AddressDetails.Country.AdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName != null ) newState = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName; if ( place.AddressDetails.Country.AdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber != null ) newZip = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber; if ( place.AddressDetails.Country.AdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.Locality != null && place.AddressDetails.Country.AdministrativeArea.Locality.PostalCode != null && place.AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber != null ) newZip = place.AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber; if ( place.AddressDetails.Country != null && place.AddressDetails.Country.CountryNameCode != null ) newCountry = place.AddressDetails.Country.CountryNameCode; oldStreet = jQuery("#location_address").attr( 'value' ); oldCity = jQuery("#location_address").attr( 'value' ); oldState = jQuery("#location_address").attr( 'value' ); oldZip = jQuery("#location_address").attr( 'value' ); oldCountry = jQuery("#location_address").attr( 'value' ); */ jQuery("#location_address").attr( 'value', newStreet ); jQuery("#location_city").attr( 'value', newCity ); jQuery("#location_state").attr( 'value', newState ); jQuery("#location_zip").attr( 'value', newZip ); jQuery("#location_country").val( newCountry ); } id || 'sm-location' != $current_screen->post_type ) return; $options = $simple_map->get_options(); $post_object = get_post( $post ); //$api_key = ( isset( $options['api_key'] ) && !empty( $options['api_key'] ) ) ? $options['api_key'] : ''; // Grab old data $location_address = get_post_meta( $post, 'location_address', true ) ? get_post_meta( $post, 'location_address', true ) : ' '; $location_address2 = get_post_meta( $post, 'location_address2', true ) ? get_post_meta( $post, 'location_address2', true ) : ' '; $location_city = get_post_meta( $post, 'location_city', true ) ? get_post_meta( $post, 'location_city', true ) : ' '; $location_state = get_post_meta( $post, 'location_state', true ) ? get_post_meta( $post, 'location_state', true ) : $options['default_state']; $location_zip = get_post_meta( $post, 'location_zip', true ) ? get_post_meta( $post, 'location_zip', true ) : ' '; $location_country = get_post_meta( $post, 'location_country', true ) ? get_post_meta( $post, 'location_country', true ) : $options['default_country']; $location_lat = get_post_meta( $post, 'location_lat', true ) ? get_post_meta( $post, 'location_lat', true ) : ' '; $location_lng = get_post_meta( $post, 'location_lng', true ) ? get_post_meta( $post, 'location_lng', true ) : ' '; $location_phone = get_post_meta( $post, 'location_phone', true ) ? get_post_meta( $post, 'location_phone', true ) : ' '; $location_fax = get_post_meta( $post, 'location_fax', true ) ? get_post_meta( $post, 'location_fax', true ) : ' '; $location_url = get_post_meta( $post, 'location_url', true ) ? get_post_meta( $post, 'location_url', true ) : ' '; $location_email = get_post_meta( $post, 'location_email', true ) ? get_post_meta( $post, 'location_email', true ) : ' '; $location_special = get_post_meta( $post, 'location_special', true ) ? get_post_meta( $post, 'location_special', true ) : ' '; // If adding new field that has a default (like state and country above), you must modify the update section below accordingly! // Grab new data $new_address = isset( $_POST['location_address'] ) ? $_POST['location_address'] : ''; $new_address2 = isset( $_POST['location_address2'] ) ? $_POST['location_address2'] : ''; $new_city = isset( $_POST['location_city'] ) ? $_POST['location_city'] : ''; $new_state = isset( $_POST['location_state'] ) ? $_POST['location_state'] : ''; $new_zip = isset( $_POST['location_zip'] ) ? $_POST['location_zip'] : ''; $new_country = isset( $_POST['location_country'] ) ? $_POST['location_country'] : ''; $new_lat = isset( $_POST['location_lat'] ) ? $_POST['location_lat'] : ''; $new_lng = isset( $_POST['location_lng'] ) ? $_POST['location_lng'] : ''; $new_phone = isset( $_POST['location_phone'] ) ? $_POST['location_phone'] : ''; $new_fax = isset( $_POST['location_fax'] ) ? $_POST['location_fax'] : ''; $new_url = isset( $_POST['location_url'] ) ? $_POST['location_url'] : ''; $new_email = isset( $_POST['location_email'] ) ? $_POST['location_email'] : ''; $new_special = isset( $_POST['location_special'] ) ? $_POST['location_special'] : ''; // Update if ( $location_address != $new_address ) update_post_meta( $post, 'location_address', $new_address ); if ( $location_address2 != $new_address2 ) update_post_meta( $post, 'location_address2', $new_address2 ); if ( $location_city != $new_city ) update_post_meta( $post, 'location_city', $new_city ); if ( $location_state != $new_state || ( $new_state == $options['default_state'] && ! get_post_meta( $post, 'location_state', true ) ) ) update_post_meta( $post, 'location_state', $new_state ); if ( $location_zip != $new_zip ) update_post_meta( $post, 'location_zip', $new_zip ); if ( $location_country != $new_country || ( $new_country == $options['default_country'] && ! get_post_meta( $post, 'location_country', true ) ) ) update_post_meta( $post, 'location_country', $new_country ); if ( $location_lat != $new_lat ) update_post_meta( $post, 'location_lat', $new_lat ); if ( $location_lng != $new_lng ) update_post_meta( $post, 'location_lng', $new_lng ); if ( $location_phone != $new_phone ) update_post_meta( $post, 'location_phone', $new_phone ); if ( $location_fax != $new_fax ) update_post_meta( $post, 'location_fax', $new_fax ); if ( $location_url != $new_url ) update_post_meta( $post, 'location_url', $new_url ); if ( $location_email != $new_email ) update_post_meta( $post, 'location_email', $new_email ); if ( $location_special != $new_special ) update_post_meta( $post, 'location_special', $new_special ); // Lets not geocode on auto-draft if ( 'auto-draft' == $post_object->post_status ) return; /* * Geocode here under the following conditions * If address, city, state, or zip have changed * If lat or lng is empty */ $updated_address = get_post_meta( $post, 'location_address', true ); $updated_city = get_post_meta( $post, 'location_city', true ); $updated_state = get_post_meta( $post, 'location_state', true ); $updated_zip = get_post_meta( $post, 'location_zip', true ); $updated_country = get_post_meta( $post, 'location_country', true ); $updated_lat = get_post_meta( $post, 'location_lat', true ); $updated_lng = get_post_meta( $post, 'location_lng', true ); if ( $location_address != $updated_address || $location_city != $updated_city || $location_state != $updated_state || $location_zip != $updated_zip || $location_country != $updated_country || '' == $updated_lat || '' == $updated_lng ) { $geocode_result = $simple_map->geocode_location( $updated_address, $updated_city, $updated_state, $updated_zip, $updated_country, '' ); if ( $geocode_result && isset( $geocode_result['status'] ) && $geocode_result['status'] == 'OK' ) { if ( isset( $geocode_result['lat'] ) && isset( $geocode_result['lng'] ) ) { update_post_meta( $post, 'location_lat', $geocode_result['lat'] ); update_post_meta( $post, 'location_lng', $geocode_result['lng'] ); } } else if ( $geocode_result && isset( $geocode_result['status'] ) ) { // Parse response switch( $geocode_result['status'] ) { case 620 : case 'OVER_QUERY_LIMIT' : update_post_meta( $post, 'sm-needs-js-geocode', 'true' ); } } } } // Filter the main query run at top of edit.php function limit_edit_query( $query ) { global $current_screen, $wpdb; if ( is_object( $current_screen ) && 'edit-sm-location' == $current_screen->id ) { $sql = 'SELECT ID FROM `' . $wpdb->posts . '` WHERE post_type = "sm-location" AND post_status = "publish" LIMIT 10000'; if ( 10000 == count( $wpdb->get_results( $sql ) ) ) { $query->query_vars['posts_per_page'] = $query->query_vars['posts_per_archive_page'] = 1000; add_action( 'in_admin_footer', array( &$this, 'print_excessive_locations_message' ) ); } } return $query; } // Prints the excessive locations message function print_excessive_locations_message() { ?>Warning: You have more than 10,000 locations in your database. We have limited the list here to 1,000. You may use the search field to access locations beyond the first 1,000.', 'SimpleMap' ); ?>