Function Reference: geodir_location_manager_share_location

Summary

Redirect url after sharing location.

Global Values

$wp_query
(object) (required) WordPress Query object.

Default: None
$wpdb
(object) (required) WordPress Database object.

Default: None
$plugin_prefix
(string) (required) Geodirectory plugin table prefix.

Default: None

Package

GeoDirectory_Location_Manager

Parameters

$redirect_url
(string) (required) Old redirect url.

Default: None

Return Values

(bool|null|string)
  • Filtered redirect url.

Change Log

Since: 1.0.0

Source File

geodir_location_manager_share_location() is located in geodir_location_manager/geodir_location_hooks_actions.php [Line: 3119]

Source Code

function geodir_location_manager_share_location($redirect_url)
{
	global $wp_query,$plugin_prefix;

	
	if(isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax']=='share_location')
	{
		if(isset($_REQUEST['error']) && $_REQUEST['error'])
		{
			$_SESSION['gd_location_shared'] = true ;
			return ;
		}
		global $wpdb;
		
		// ask user to share his location only one time.
		$_SESSION['gd_location_shared'] = true ;
		
		$DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
		
		if(get_option('geodir_search_dist')!=''){$dist = get_option('geodir_search_dist');}else{ $dist = '25000';  }
		if(get_option('geodir_near_me_dist')!=''){$dist2 = get_option('geodir_near_me_dist');}else{ $dist2 = '200';  }
		
		if(isset($_REQUEST['lat']) && isset($_REQUEST['long']))
		{
			$mylat = (float)stripslashes(ucfirst($_REQUEST['lat']));
			$mylon = (float)stripslashes(ucfirst($_REQUEST['long']));
		}else
		{
			$ip = $_SERVER['REMOTE_ADDR'];
			$addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
			$mylat = stripslashes(ucfirst($addr_details['geoplugin_latitude']));
			$mylon = stripslashes(ucfirst($addr_details['geoplugin_longitude']));
		}
		
	$_SESSION['user_lat'] = $mylat;
	$_SESSION['user_lon'] = $mylon;
	$lon1 = $mylon- $dist2/abs(cos(deg2rad($mylat))*69); 
	$lon2 = $mylon+$dist2/abs(cos(deg2rad($mylat))*69);
	$lat1 = $mylat-($dist2/69);
	$lat2 = $mylat+($dist2/69);
	
	$rlon1 = is_numeric(min($lon1,$lon2)) ? min($lon1,$lon2) : '';
	$rlon2 = is_numeric(max($lon1,$lon2)) ? max($lon1,$lon2) : '';
	$rlat1 = is_numeric(min($lat1,$lat2)) ? min($lat1,$lat2) : '';
	$rlat2 = is_numeric(max($lat1,$lat2)) ? max($lat1,$lat2) : '';
		
		$near_location_info = $wpdb->get_results($wpdb->prepare("SELECT *,CONVERT((%s * 2 * ASIN(SQRT( POWER(SIN((%s - (".$plugin_prefix."gd_place_detail.post_latitude)) * pi()/180 / 2), 2) +COS(%s * pi()/180) * COS( (".$plugin_prefix."gd_place_detail.post_latitude) * pi()/180) *POWER(SIN((%s - ".$plugin_prefix."gd_place_detail.post_longitude) * pi()/180 / 2), 2) ))),UNSIGNED INTEGER) as distance FROM ".$plugin_prefix."gd_place_detail WHERE (".$plugin_prefix."gd_place_detail.post_latitude IS NOT NULL AND ".$plugin_prefix."gd_place_detail.post_latitude!='') AND ".$plugin_prefix."gd_place_detail.post_latitude between $rlat1 and $rlat2  AND ".$plugin_prefix."gd_place_detail.post_longitude between $rlon1 and $rlon2 ORDER BY distance ASC LIMIT 1",$DistanceRadius,$mylat,$mylat,$mylon));
	 
		if(!empty($near_location_info)){
			$redirect_url = geodir_get_location_link('base').'me';
			return ($redirect_url);die();
		}
		
		
		$location_info = $wpdb->get_results($wpdb->prepare("SELECT *,CONVERT((%s * 2 * ASIN(SQRT( POWER(SIN((%s - (".POST_LOCATION_TABLE.".city_latitude)) * pi()/180 / 2), 2) +COS(%s * pi()/180) * COS( (".POST_LOCATION_TABLE.".city_latitude) * pi()/180) *POWER(SIN((%s - ".POST_LOCATION_TABLE.".city_longitude) * pi()/180 / 2), 2) ))),UNSIGNED INTEGER) as distance FROM ".POST_LOCATION_TABLE." ORDER BY distance ASC LIMIT 1",$DistanceRadius,$mylat,$mylat,$mylon));
		
		if(!empty($location_info))
		{
			$location_info = end($location_info);
			$location_array = array();
			$location_array['gd_country'] = $location_info->country_slug;
			$location_array['gd_region'] = $location_info->region_slug;
			$location_array['gd_city'] = $location_info->city_slug;
			$base = rtrim(geodir_get_location_link('base') , '/');
			$redirect_url = $base .'/' .$location_info->country_slug. '/' . $location_info->region_slug. '/' .  $location_info->city_slug ;
			$redirect_url = geodir_location_permalink_url( $redirect_url );
		}
		else
		{
			$redirect_url = geodir_get_location_link('base');
		}
		
		return ($redirect_url);
		
		die;
	}
	
}