' . __('Options updated.', 'Geo') . '

'; } if(isset($_POST['Submit']) || isset($_POST['Add'])) { $geolocations = get_settings('geo_locations'); foreach($geolocations as $name => $coords) { $geolocations[$name] = "{$_POST['lat'][$name]},{$_POST['lon'][$name]}"; } if(isset($_POST['new_location']) && ($_POST['new_location'] != '')) { $geolocations[$_POST['new_location']] = "{$_POST['new_lat']},{$_POST['new_lon']}"; } update_option('geo_locations', $geolocations); echo '

' . __('Locations updated.', 'Geo') . '

'; } else { Geo::add_options(); } $use_geo_positions = get_settings('use_geo_positions'); $use_default_geourl = get_settings('use_default_geourl'); $default_geourl_lat = get_settings('default_geourl_lat'); $default_geourl_lon = get_settings('default_geourl_lon'); $ck_use_geo_positions = $use_geo_positions == 1 ? ' checked="checked"' : ''; $ck_use_default_geourl[intval($use_default_geourl)] = ' checked="checked"'; $geolocations = get_settings('geo_locations'); if(!is_array($geolocations)) $geolocations = array(); //Page Presentation echo '

' . __('Geographic Location Manager', 'Geo') . '

' . __('Geographic Tracking Features', 'Geo') . ': Enable
' . __('When no location is specified', 'Geo') . ':
'; echo '

' . __('Preset Locations', 'Geo') . '

'; foreach($geolocations as $name => $coords) { list($lat, $lon) = split(',', $coords); $alternate = $alternate == ''? ' class="alternate"' : ''; echo ""; echo ""; echo ""; echo ""; echo " "; echo ""; } echo '
'.__('Location Name', 'Geo').' '.__('Latitude', 'Geo').' '.__('Longitude', 'Geo').' '.__('Action', 'Geo').'
{$name}Delete · Map
'.__('New Location', 'Geo').':
 
'; ?>
»" />
get_var("SELECT count(post_id) FROM {$wpdb->postmeta} WHERE meta_key = '_geo_location'") == 0) { // Put empty geo markers on any one post to mark plugin as installed $one_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} LIMIT 1;"); add_post_meta($one_post_id, '_geo_location', ''); // Is there a WP 1.2-remnant geo field pair? $fieldrow = $wpdb->get_row("SELECT * FROM {$wpdb->posts} LIMIT 1", ARRAY_A); $fields = array_keys($fieldrow); if(in_array('post_lat', $fields)) { if($latlon_posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE not isnull(post_lat) OR not isnull(post_lon);")) { foreach($latlon_posts as $post) { add_post_meta($post->ID, '_geo_location', $post->post_lat . ',' . $post->post_lon); } } } Geo::add_options(); } } return true; } function add_options() /** * Adds the options required for geo info * * Long description for the Function. * */ { add_option('use_geo_positions', 0); add_option('use_default_geourl', 0); add_option('default_geourl_lat', 0); add_option('default_geourl_lon', 0); add_option('geo_locations', array()); } function edit_form_advanced($not_used) /** * Queues the output buffer for displaying the Geo interface on the post * editing form * * Long description for the Function. * * @param $not_used Description */ { ob_start(array('Geo', 'advanced_buffer')); } function advanced_buffer($content) /** * Displays the Geo interface on the post editing form * * Long description for the Function. * * @param $content Description */ { global $post_ID; $geolocations = get_settings('geo_locations'); $output = '

' . __('Location', 'Geo') . '

'; list($lat, $lon) = split(',', get_post_meta($post_ID, '_geo_location', true)); $output .= '   '; $output .= '   '; $output .= '
'."\n"; } function longitude_invalid() /** * Validates the longitude value of the current post. * * Long description for the Function. * * @return boolean True if longitude is out of range. */ { if (get_Lon() == null) return true; if (get_Lon() > 360) return true; if (get_Lon() < -360) return true; } function get_geo_url($index, $lat = '', $lon = '') /** * Returns a URL for the indexed geo site at the given coordinates. * * Long description for the Function. * * @param $index The associative index of the URL array to return. * @param $lat Optional latitude for the URL, if not specified then the current is used. * @param $lon Optional longitude for the URL, if not specified then the current is used. * * @return string The URL of the requested site. */ { $lat = $lat == ''? get_Lat() : $lat; $lon = $lon == ''? get_Lon() : $lon; $urls = geo_urls($lat, $lon); return $urls[$index][0]; } function the_AcmeMap_Url() /** * Outputs a URL to the AcmeMap site for the current geo coordinates. * * Long description for the Function. * */ { /* // Shouldn't this function work if a coordinate is set? // Can't we correct an invalid longitude? if (!get_settings('use_geo_positions')) return; if (longitude_invalid()) return; */ echo get_geo_url('AcmeMap'); } function the_GeoURL_Url() /** * Outputs a URL to the GeoURL site for the current geo coordinates. * * Long description for the Function. * */ { echo get_geo_url('GeoURL'); } function the_GeoCache_Url() /** * Outputs a URL to the GeoCaching site for the current geo coordinates. * * Long description for the Function. * */ { echo get_geo_url('GeoCache'); } function the_MapQuest_Url() /** * Outputs a URL to the MapQuest site for the current geo coordinates. * * Long description for the Function. * */ { echo get_geo_url('MapQuest'); } function the_SideBit_Url() /** * Outputs a URL to the SideBit site for the current geo coordinates. * * Long description for the Function. * */ { echo get_geo_url('SideBit'); } function the_DegreeConfluence_Url() /** * Outputs a URL to the DegreeConfluence site for the current geo coordinates. * * Long description for the Function. * */ { echo get_geo_url('DegreeConfluence'); } function the_TopoZone_Url() /** * Outputs a URL to the TopoZone site for the current geo coordinates. * * Long description for the Function. * */ { echo get_geo_url('TopoZone'); } function the_FindU_Url() /** * Outputs a URL to the FindU site for the current geo coordinates. * * Long description for the Function. * */ { echo get_geo_url('FindU'); } function the_MapTech_Url() /** * Outputs a URL to the MapTech site for the current geo coordinates. * * Long description for the Function. * */ { echo get_geo_url('MapTech'); } function the_GoogleMap_Url() { /** * Outputs a URL to Google Maps for the current geo coordinates. * * Long description for the Function. * */ echo get_geo_url('GoogleMaps'); } function geo_distance($lat1, $lon1, $lat2, $lon2, $unit = 'm' ) /** * Returns the distance between two geo coordinates. * * Long description for the Function. * * @param $lat1 The latitude of the first coordinate * @param $lon1 The longitude of the first coordinate * @param $lat2 The latitude of the second coordinate * @param $lon2 The longitude of the second coordinate * @param $unit 'm' for miles, 'k' for kilometers, 'n' for nautical miles. * * @return float The distance between the to coordinates. */ { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "k") { return ($miles * 1.609344); } else if ($unit == "n") { return ($miles * 0.8684); } else { return $miles; } } function pretty_degrees($decimal_degrees) { $deg = floor($decimal_degrees); $decimal_degrees = ($decimal_degrees - $deg) * 60; $min = floor($decimal_degrees); $decimal_degrees = ($decimal_degrees - $min) * 60; $sec = $decimal_degrees; return "{$deg}° {$min}' {$sec}\""; } function get_place_name($lat = 'x', $lon = 'x') { global $post; if($lat=='x' || $lon=='x') { list($lat, $lon) = split(',', get_post_meta($post->ID, '_geo_location', true)); if ($lat == '') { $lat = get_settings('default_geourl_lat'); $lon = get_settings('default_geourl_lon'); } } $geolocations = get_settings('geo_locations'); foreach($geolocations as $geolocation => $coords) { if($coords == "{$lat},{$lon}") return $geolocation; } return ''; } function the_location($format = '%1$s at %2$s, %3$s', $defaultlocation = 'Unnamed location', $service='GoogleMaps') { global $post; list($lat, $lon) = split(',', get_post_meta($post->ID, '_geo_location', true)); if ($lat == '') { $lat = get_settings('default_geourl_lat'); $lon = get_settings('default_geourl_lon'); } $place = get_place_name($lat, $lon); if($place == '') $place = $defaultlocation; if($lat > 0) { $outlat = pretty_degrees($lat)."N"; } else { $outlat = pretty_degrees($lat)."S"; } if($lon < 0) { $temp = get_Lon() * -1; $outlon = pretty_degrees($temp)."W"; } else { $outlon = pretty_degrees($lon)."E"; } echo sprintf($format, $place, $outlat, $outlon, get_geo_url($service, $lat, $lon)); } function get_the_rss_geotags() /** * Returns the tags with geo information for inclusion in RSS 2.0 feeds. * * Include a call to this function inside the tag to add tags with geo information if available. * To keep the feed valid add these namespace declarations to the tag: * xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" * xmlns:icbm="http://postneo.com/icbm" * xmlns:geourl="http://geourl.org/rss/module/" */ { global $wp_query; if(!get_settings('use_geo_positions')) return; list($lat, $lon) = split(',', get_post_meta($wp_query->post->ID, '_geo_location', true)); if ($lat == '' || $lon == '') { if (get_settings('use_default_geourl')){ // send the default here $lat = get_settings('default_geourl_lat'); $lon = get_settings('default_geourl_lon'); } } if ($lat != '' && $lon != '') { echo "$lat$lon\n" . "$lat$lon\n" . "$lon$lat\n"; } } ?>