';
list($lat, $lon) = split(',', get_post_meta($post_ID, '_geo_location', true));
$output .= '
' . __('Latitude:', 'Geo') . ' ';
$output .= '
' . __('Longitude:', 'Geo') . ' ';
$output .= '
' . __('Preset:', 'Geo') . ' --choose one-- ';
foreach($geolocations as $geolocation => $coords)
{
$output .= ")#ims', '\\1' . $output, $content, 1);
}
function admin_head($not_used)
/**
* Outputs support javascript to admin console and prepares the databse.
*
* Long description for the Function.
*
* @param $not_used Description
*/
{
Geo::prepare_database();
if(strstr($_SERVER['REQUEST_URI'], 'post.php'))
{
echo '
';
}
}
function update_post($id)
/**
* Updates the geo info for a post when the post is updated.
*
* Long description for the Function.
*
* @param $id Description
*/
{
delete_post_meta($id, '_geo_location');
add_post_meta($id, '_geo_location', $_POST['geo_lat'] . ',' . $_POST['geo_lon']);
echo "{$id}
";
//die(''.print_r($_POST,1).' '. "{$id}\n" . get_post_meta($id, '_geo_location', true));
}
function wp_head($not_used)
/**
* Outputs the geo info as meta tags in the blog head.
*
* Long description for the Function.
*
* @param $not_used Description
*/
{
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(is_single() && ($lat != '') && ($lon != ''))
{
$title = convert_chars(strip_tags(get_bloginfo("name")))." - ".$wp_query->post->post_title;
}
else if(get_settings('use_default_geourl'))
{
// send the default here
$title = convert_chars(strip_tags(get_bloginfo("name")));
$lat = get_settings('default_geourl_lat');
$lon = get_settings('default_geourl_lon');
}
else
{
return;
}
echo " \n";
echo " \n";
echo " \n";
}
function logErrors($msg)
/**
* Simple error logging function for debugging.
*
* Long description for the Function.
*
* @return bool Always true
* @param $msg Description
*/
{
$fp = fopen("../asy.log","a+");
fwrite($fp, "\n\n".date("Y-m-d H:i:s - ").$msg);
fclose($fp);
return true;
}
function admin_menu($not_used)
/**
* Adds the Geo Info menu to the Options tab in the admin menu.
*
* Long description for the Function.
*
* @param $not_used Description
*/
{
add_options_page(__('Geo Location Manager', 'Geo'), __('Geo Info', 'Geo'), 5, basename(__FILE__), array('Geo', 'options_page_geo'));
//add_submenu_page('index.php', __('Geo Location Manager', 'Geo'), __('Geo Info', 'Geo'), 5, basename(__FILE__), array('Geo', 'options_page_geo'));
}
} // End class geo
// Note the array as the second parameter for calling static methods on our nice, safe object namespace
// For instance, array('Geo', 'edit_form_advanced') calls Geo::edit_form_advanced()
add_action('edit_form_advanced', array('Geo', 'edit_form_advanced'));
add_action('admin_head', array('Geo', 'admin_head'));
add_action('wp_head', array('Geo', 'wp_head'));
add_action('save_post', array('Geo', 'update_post'));
//add_action('edit_post', array('Geo', 'update_post'));
//add_action('publish_post', array('Geo', 'update_post'));
add_action('admin_menu', array('Geo', 'admin_menu'));
function pingGeoURL($blog_ID)
/**
* Pings geourl.org with blog page ID.
*
* Long description for the Function.
*
* @param $blog_ID Description
*/
{
$ourUrl = get_settings('home') ."/index.php?p=".$blog_ID;
$host="geourl.org";
$path="/ping/?p=".$ourUrl;
getRemoteFile($host,$path);
}
function get_Lat()
/**
* Returns the latitude setting for a post.
*
* Long description for the Function.
*
* @return string Description
*/
{
global $post;
list($lat, $lon) = split(',', get_post_meta($post->ID, '_geo_location', true));
if ($lat != '') {
return trim($lat);
} else if(get_settings('use_default_geourl')) {
return trim(get_settings('default_geourl_lat'));
}
return '';
}
function get_Lon()
/**
* Returns the longitude setting for a post.
*
* Long description for the Function.
*
* @return string Description
*/
{
global $post;
list($lat, $lon) = split(',', get_post_meta($post->ID, '_geo_location', true));
if ($lon != '') {
return trim($lon);
} else if(get_settings('use_default_geourl')) {
return trim(get_settings('default_geourl_lon'));
}
return '';
}
function the_Lat()
/**
* Outputs the latitude for a post.
*
* Long description for the Function.
*
* @return string Description
*/
{
if(get_settings('use_geo_positions')) {
if(get_Lat() > 0) {
echo "".get_Lat()."N";
} else {
echo "".get_Lat()."S";
}
}
}
function the_Lon()
/**
* Outputs the longitude for a post.
*
* Long description for the Function.
*
* @return string Description
*/
{
global $id, $postdata;
if(get_settings('use_geo_positions')) {
if(get_Lon() < 0) {
$temp = get_Lon() * -1;
echo "".$temp."W";
} else {
echo "".get_Lon()."E";
}
}
}
function geo_PopUpScript()
/**
* Outputs the popup javascript used by the dropdown popup-er.
*
* Long description for the Function.
*
* @return string Description
*/
{
echo "
";
}
function geo_urls($lat = '', $lon = '')
/**
* Returns an array of named URLs for the llat and lon specified.
*
* Long description for the Function.
*
* @return array Description
*/
{
$lat = $lat == ''? get_Lat() : $lat;
$lon = $lon == ''? get_Lon() : $lon;
$title = get_place_name($lat, $lon);
$ary = array (
'AcmeMap' => array("http://www.acme.com/mapper?lat={$lat}&long={$lon}&scale=11&theme=Image&width=3&height=2&dot=Yes", __('Acme Mapper', 'Geo')),
'GeoURL' => array("http://geourl.org/near/?lat={$lat}&lon={$lon}&dist=500", __('GeoURLs near here', 'Geo')),
'GeoCache' => array("http://www.geocaching.com/seek/nearest.aspx?origin_lat={$lat}&origin_long={$lon}&dist=5", __('Geocaches near here', 'Geo')),
'MapQuest' => array("http://www.mapquest.com/maps/map.adp?latlongtype=decimal&latitude={$lat}&longitude={$lon}", __('Mapquest map of this spot', 'Geo')),
'SideBit' => array("http://www.sidebit.com/ProjectGeoURLMap.php?lat={$lat}&lon={$lon}", __('SideBit URL Map of this spot', 'Geo')),
'DegreeConfluence' => array("http://confluence.org/confluence.php?lat={$lat}&lon={$lon}", __('Confluence.org near here', 'Geo')),
'TopoZone' => array("http://www.topozone.com/map.asp?lat={$lat}&lon={$lon}", __('Topozone near here', 'Geo')),
'FindU' => array("http://www.findu.com/cgi-bin/near.cgi?lat={$lat}&lon={$lon}&scale=100000&zoom=50&type=1&icon=0&&scriptfile=http://mapserver.maptech.com/api/espn/index.cfm", __('FindU near here', 'Geo')),
'MapTech' => array("http://mapserver.maptech.com/api/espn/index.cfm?lat={$lat}&lon={$lon}", __('Maptech near here', 'Geo')),
//'GoogleMaps' => array("http://maps.google.com/maps?ll={$lat}%2C{$lon}&spn=0.015839,0.032747&hl=en", __('Google Maps', 'Geo')),
'GoogleMaps' => array("http://maps.google.com/maps?q={$lat}+{$lon}+({$title})&hl=en", __('Google Maps', 'Geo')),
);
return $ary;
}
function geo_UrlPopNav()
/**
* Creates a dropdown popup-er for viewing geo sites for a post's lat/long.
*
* Long description for the Function.
*
*/
{
$sites = geo_urls();
echo ''."\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";
}
}
?>