コード例 #1
0
/**
 * Updates marker address.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @global object $wpdb WordPress Database object.
 *
 * @param string $prefix Identifier used as a prefix for field name
 */
function geodir_location_update_marker_address($prefix = '')
{
    global $pagenow, $wpdb;
    if (is_page() && geodir_is_page('add-listing') || is_admin() && ($pagenow == 'post.php' || isset($_REQUEST['post_type']))) {
        $country_option = get_option('geodir_enable_country');
        $region_option = get_option('geodir_enable_region');
        $city_option = get_option('geodir_enable_city');
        $default_country = '';
        $default_region = '';
        $default_city = '';
        if (isset($_SESSION['gd_multi_location'])) {
            if (isset($_SESSION['gd_city']) && $_SESSION['gd_city'] != '') {
                $location = geodir_get_locations('city', $_SESSION['gd_city']);
            } elseif (isset($_SESSION['gd_region']) && $_SESSION['gd_region'] != '') {
                $location = geodir_get_locations('region', $_SESSION['gd_region']);
            } elseif (isset($_SESSION['gd_country']) && $_SESSION['gd_country'] != '') {
                $location = geodir_get_locations('country', $_SESSION['gd_country']);
            }
            if (isset($location) && $location) {
                $location = end($location);
            }
            $default_city = isset($location->city) ? $location->city : '';
            $default_region = isset($location->region) ? $location->region : '';
            $default_country = isset($location->country) ? $location->country : '';
        }
        $location = geodir_get_default_location();
        if (empty($default_city)) {
            $default_city = isset($location->city) ? $location->city : '';
        }
        if (empty($default_region)) {
            $default_region = isset($location->region) ? $location->region : '';
        }
        if (empty($default_country)) {
            $default_country = isset($location->country) ? $location->country : '';
        }
        $default_lat = apply_filters('geodir_default_latitude', $location->city_latitude, true);
        $default_lng = apply_filters('geodir_default_longitude', $location->city_longitude, true);
        $selected_countries = array();
        if (get_option('geodir_selected_countries')) {
            $selected_countries = get_option('geodir_selected_countries');
        }
        $selected_regions = array();
        if (get_option('geodir_selected_regions')) {
            $selected_regions = get_option('geodir_selected_regions');
        }
        $selected_cities = array();
        if (get_option('geodir_selected_cities')) {
            $selected_cities = get_option('geodir_selected_cities');
        }
        ?>
		
		var error = false;
		
		<?php 
        if ($country_option == 'default') {
            $countries_ISO2 = $wpdb->get_var($wpdb->prepare("SELECT ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country=%s", $default_country));
            ?>
			            
			if('<?php 
            echo $countries_ISO2;
            ?>
' != getCountryISO && error == false){
				
				alert('<?php 
            printf(__('Please choose any address of the (%s) country only.', GEODIRECTORY_TEXTDOMAIN), $default_country);
            ?>
');

				error = true;
			} <?php 
        } elseif ($country_option == 'selected') {
            if (is_array($selected_countries) && !empty($selected_countries)) {
                $selected_countries_string = implode(',', $selected_countries);
                if (count($selected_countries) > 1) {
                    $selected_countries_string = sprintf(__('Please choose any address of the (%s) countries only.', GEODIRECTORY_TEXTDOMAIN), implode(',', $selected_countries));
                } else {
                    $selected_countries_string = sprintf(__('Please choose any address of the (%s) country only.', GEODIRECTORY_TEXTDOMAIN), implode(',', $selected_countries));
                }
            } else {
                $selected_countries_string = __('No countries available.', GEODIRECTORY_TEXTDOMAIN);
            }
            $countriesP = implode(',', array_fill(0, count($selected_countries), '%s'));
            $countries_ISO2 = $wpdb->get_results($wpdb->prepare("SELECT ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country IN ({$countriesP})", $selected_countries));
            $cISO_arr = array();
            foreach ($countries_ISO2 as $cIOS2) {
                $cISO_arr[] = $cIOS2->ISO2;
            }
            ?>
			
			var country_array = <?php 
            echo json_encode($cISO_arr);
            ?>
;
			
			//country_array = jQuery.map(country_array, String.toLowerCase);
			
			if(jQuery.inArray( getCountryISO, country_array ) == -1 && error == false){
				
				alert('<?php 
            echo $selected_countries_string;
            ?>
');
				
				error = true;
				
			}	<?php 
        }
        ?>
		if(getCountry && getCity && error == false){
		
		jQuery.post( "<?php 
        echo admin_url() . 'admin-ajax.php?action=geodir_locationajax_action&location_ajax_action=set_region_on_map';
        ?>
", { country: getCountry, state: getState, city: getCity })
		.done(function( data ) {
			
			if(jQuery.trim(data) != '')
				getState = data;
			
			<?php 
        if ($region_option == 'default') {
            ?>
			
			if('<?php 
            echo mb_strtolower(esc_attr($default_region));
            ?>
' != getState.toLowerCase() && error == false){
				
				alert('<?php 
            printf(__('Please choose any address of the (%s) region only.', GEODIRECTORY_TEXTDOMAIN), $default_region);
            ?>
');
				
				error = true;
			}<?php 
        } elseif ($region_option == 'selected') {
            $selected_regions_string = '';
            if (is_array($selected_regions) && !empty($selected_regions)) {
                $selected_regions_string = implode(',', $selected_regions);
                if (count($selected_regions) > 1) {
                    $selected_regions_string = sprintf(__('Please choose any address of the (%s) regions only.', GEODIRECTORY_TEXTDOMAIN), implode(',', $selected_regions));
                } else {
                    $selected_regions_string = sprintf(__('Please choose any address of the (%s) region only.', GEODIRECTORY_TEXTDOMAIN), implode(',', $selected_regions));
                }
            }
            ?>
			
			var region_array = <?php 
            echo json_encode($selected_regions);
            ?>
;
			
			region_array = jQuery.map(region_array, String.toLowerCase);
			
			if(jQuery.inArray( getState.toLowerCase(), region_array ) == -1 && error == false && region_array.length > 0){
				
				alert('<?php 
            echo $selected_regions_string;
            ?>
');
				
				error = true;
				
			}	<?php 
        }
        if ($city_option == 'default') {
            ?>
			
			if('<?php 
            echo mb_strtolower(esc_attr($default_city));
            ?>
' != getCity.toLowerCase() && error == false){
				
				alert('<?php 
            printf(__('Please choose any address of the (%s) city only.', GEODIRECTORY_TEXTDOMAIN), $default_city);
            ?>
');
				
				error = true;
			}<?php 
        } elseif ($city_option == 'selected') {
            $selected_cities_string = '';
            if (is_array($selected_cities) && !empty($selected_cities)) {
                $selected_cities_string = implode(',', $selected_cities);
                if (count($selected_cities) > 1) {
                    $selected_cities_string = sprintf(__('Please choose any address of the (%s) cities only.', GEODIRECTORY_TEXTDOMAIN), implode(',', $selected_cities));
                } else {
                    $selected_cities_string = sprintf(__('Please choose any address of the (%s) city only.', GEODIRECTORY_TEXTDOMAIN), implode(',', $selected_cities));
                }
            }
            ?>
			
			var city_array = <?php 
            echo json_encode($selected_cities);
            ?>
;
			
			city_array = jQuery.map(city_array, String.toLowerCase);
			
			if(jQuery.inArray( getCity.toLowerCase(), city_array ) == -1 && error == false && city_array.length > 0){
				
				alert('<?php 
            echo $selected_cities_string;
            ?>
');
				
				error = true;
				
			}	<?php 
        }
        ?>
			});
			
	}
			
			if(error == false){
				if((jQuery.trim(old_country) != jQuery.trim(getCountry))){
					
					jQuery('#<?php 
        echo $prefix . 'region';
        ?>
 option').remove();
					
					if(jQuery("#<?php 
        echo $prefix . 'region';
        ?>
 option:contains('"+getState+"')").length == 0){
							jQuery("#<?php 
        echo $prefix . 'region';
        ?>
").append('<option value="'+getState+'">'+getState+'</option>');
					}
					
					jQuery('#<?php 
        echo $prefix . 'region';
        ?>
 option[value="'+getState+'"]').attr("selected",true);
					jQuery("#<?php 
        echo $prefix . 'region';
        ?>
").trigger("chosen:updated");
					
					jQuery('#<?php 
        echo $prefix . 'city';
        ?>
 option').remove();
					
					if(jQuery("#<?php 
        echo $prefix . 'city';
        ?>
 option:contains('"+getCity+"')").length == 0){
						jQuery("#<?php 
        echo $prefix . 'city';
        ?>
").append('<option value="'+getCity+'">'+getCity+'</option>');
					}
					
					jQuery('#<?php 
        echo $prefix . 'city';
        ?>
 option[value="'+getCity+'"]').attr("selected",true);
					jQuery("#<?php 
        echo $prefix . 'city';
        ?>
").trigger("chosen:updated");
					
				}
				
				
				if(jQuery.trim(old_region) != jQuery.trim(getState)){
					
					jQuery('#<?php 
        echo $prefix . 'city';
        ?>
 option').remove();
					
					if(jQuery("#<?php 
        echo $prefix . 'city';
        ?>
 option:contains('"+getCity+"')").length == 0){
						jQuery("#<?php 
        echo $prefix . 'city';
        ?>
").append('<option value="'+getCity+'">'+getCity+'</option>');
					}
					
					jQuery('#<?php 
        echo $prefix . 'city';
        ?>
 option[value="'+getCity+'"]').attr("selected",true);
					jQuery("#<?php 
        echo $prefix . 'city';
        ?>
").trigger("chosen:updated");
					
				}
				
				
				if (getCountry){
				
					jQuery('#<?php 
        echo $prefix . 'country';
        ?>
 option[value="'+getCountry+'"]').attr("selected",true);
					jQuery("#<?php 
        echo $prefix . 'country';
        ?>
").trigger("chosen:updated");
		
				}
				
                
			   if(getZip){
			   		if(getCountryISO=='SK'){geodir_region_fix(getCountryISO,getZip,'<?php 
        echo $prefix;
        ?>
');
					} 
			   }
			   
				if (getState){
				
					if(jQuery("#<?php 
        echo $prefix . 'region';
        ?>
 option:contains('"+getState+"')").length == 0){
						jQuery("#<?php 
        echo $prefix . 'region';
        ?>
").append('<option value="'+getState+'">'+getState+'</option>');
					}
				
					jQuery('#<?php 
        echo $prefix . 'region';
        ?>
 option[value="'+getState+'"]').attr("selected",true);
					jQuery("#<?php 
        echo $prefix . 'region';
        ?>
").trigger("chosen:updated");
				
				}
				
				if (getCity){
				
				if(jQuery("#<?php 
        echo $prefix . 'city';
        ?>
 option:contains('"+getCity+"')").length == 0){
					jQuery("#<?php 
        echo $prefix . 'city';
        ?>
").append('<option value="'+getCity+'">'+getCity+'</option>');
				}
				
				jQuery('#<?php 
        echo $prefix . 'city';
        ?>
 option[value="'+getCity+'"]').attr("selected",true);
				jQuery("#<?php 
        echo $prefix . 'city';
        ?>
").trigger("chosen:updated");
				
				jQuery('select.geodir_location_add_listing_chosen').each(function(){
					
					if(jQuery(this).attr('id') == '<?php 
        echo $prefix . 'city';
        ?>
'){
						jQuery(this).change();	
					}
					
				});
					
			}	
			
			}else{
		
				geodir_set_map_default_location('<?php 
        echo $prefix . 'map';
        ?>
', '<?php 
        echo $default_lat;
        ?>
', '<?php 
        echo $default_lng;
        ?>
');
			
				return false;
				
			}
			
		
		
		if(error){
		
		geodir_set_map_default_location('<?php 
        echo $prefix . 'map';
        ?>
', '<?php 
        echo $default_lat;
        ?>
', '<?php 
        echo $default_lng;
        ?>
');
	
		return false;
		
	}
	
	
	<?php 
    }
    if (isset($_REQUEST['add_hood']) && $_REQUEST['add_hood'] != '') {
        ?>
		if (getCity){
			if(jQuery('input[id="hood_name"]').attr('id')){
				
				//jQuery("#hood_name").val(getCity);
			
			}
		}
	<?php 
    } elseif (get_option('location_neighbourhoods') && (is_page() && get_query_var('page_id') == get_option('geodir_add_listing_page')) || is_admin() && ($pagenow == 'post.php' || isset($_REQUEST['post_type']))) {
        ?>
		//geodir_get_neighbourhood_dl(getCity);
		<?php 
    }
}
コード例 #2
0
/**
 * Get actual location name.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @param $type
 * @param $term
 * @param bool $translated
 * @return null|string|void
 */
function get_actual_location_name($type, $term, $translated = false)
{
    if ($type == '' || $term == '') {
        return NULL;
    }
    $row = geodir_get_locations($type, $term);
    $value = !empty($row) && !empty($row[0]) && isset($row[0]->{$type}) ? $row[0]->{$type} : '';
    if ($translated) {
        $value = __($value, GEODIRECTORY_TEXTDOMAIN);
    }
    return $value;
}