From: Steve Sutton Date: Thu, 4 May 2017 17:32:22 +0000 (-0400) Subject: Filter start for lat lon to DMS X-Git-Tag: v2.9.16^2~13^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=bf295309a9433d4064e0db657aa31f157edc1ad6;p=WP-Plugins%2Fglm-member-db.git Filter start for lat lon to DMS adding a filter for lat lon to DMS --- diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 7c73c172..f11f018e 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -433,14 +433,14 @@ add_filter('glm_getListForSearch', function( $field,$cat_parent = false, $forAct }, 10, 3); -// Getting the current admin theme colors as set by Wordpress. -// This will be useful for styling our menu when we figure out how best to use +// Getting the current admin theme colors as set by Wordpress. +// This will be useful for styling our menu when we figure out how best to use // the available data. -// +// //$admin_colors; //add_action('admin_head', function(){global $_wp_admin_css_colors; $admin_colors = $_wp_admin_css_colors;}); //$admin_colors[get_user_option('admin_color')]['colors']; - + function get_member_id_by_name( $name = null ) { if ( $name ) { @@ -454,3 +454,78 @@ function get_member_id_by_name( $name = null ) return $memberId; } } +add_filter( 'glm-member-lat-lon-dms', function( $d, $LatLon, $type, $precision ){ + $sign = +1; + if ($d < 0) { + $sign = -1; + } + + switch ($LatLon) { + case 'Lat': + // Is it N or S? + $dir = 'N'; + if ($d < 0) { + $dir = 'S'; + } + + $deg_size = 2; + $dir_opts = array('1' => 'N', '-1' => 'S'); + break; + case 'Lon': + // Is it E or W? + $dir = 'E'; + if ($d < 0) { + $dir = 'W'; + } + + $deg_size = 3; + $dir_opts = array('1' => 'E', '-1' => 'W'); + break; + } + $d = abs($d); + $deg = 0; + $min = 0; + $sec = 0; + $format = "%s %0" . $deg_size . "." . $precision . "f°"; + + if ($type == 'D') { + $deg = $d; + } elseif ($type == 'DM' || $type == 'DMS') { + $deg = (int) $d; + $d = ($d - $deg) * 60; + $min = $d; + $format = "%s %02d° %02.".$precision."f'"; + if ($type == 'DMS') { + $min = (int) $d; + $sec = ($d - $min) * 60; + $format = "%s %0".$deg_size."d° %02d' %02.".$precision."f\""; + } + } + + // Setup possible direction selection + $dir_select = array( + array( + 'value' => 1, + 'name' => $dir_opts[1], + 'default' => ($sign == 1) + ), + array( + 'value' => - 1, + 'name' => $dir_opts[-1], + 'default' => ($sign == - 1) + ) + ); + + return array( + 'text' => $dms = sprintf($format, $dir, $deg, $min, $sec), + 'd_only' => ($sign * ($deg + ($min + $sec / 60) / 60)), + 'dir' => $sign, + 'dir_list' => $dir_select, + 'deg' => $deg, + 'min' => $min, + 'sec' => $sec, + ); +}, +10, +4 +);