/** * Get location array using arguments. * * @since 1.0.0 * @package GeoDirectory_Location_Manager * * @global object $wpdb WordPress Database object. * * @param null|array $args { * Attributes of args. * * @type string $what What do you want to query. Possible values: city, region, country. Default: 'city'. * @type string $city_val City value. * @type string $region_val Region value. * @type string $country_val Country value. * @type string $country_non_restricted Non restricted countries. * @type string $region_non_restricted Non restricted regions. * @type string $city_non_restricted Non restricted cities. * @type bool $filter_by_non_restricted Filter by non restricted?. * @type string $compare_operator Comparison operator. * @type string $country_column_name Country column name. * @type string $region_column_name Region column name. * @type string $city_column_name City column name. * @type bool $location_link_part Location link part. * @type string $order_by Order by value. * @type string $no_of_records No of records to return. * @type string $spage Current page number. * @type array $format { * Attributes of format. * * @type string $type Type. Default: 'list'. * @type string $container_wrapper Container wrapper. Default: 'ul'. * @type string $container_wrapper_attr Container wrapper attr. * @type string $item_wrapper Item wrapper. Default: 'li'. * @type string $item_wrapper_attr Item wrapper attr. * * } * * } * @param bool $switcher Todo: describe this part. * @return array|mixed|string */ function geodir_get_location_array($args = null, $switcher = false) { global $wpdb; $defaults = array('what' => 'city', 'city_val' => '', 'region_val' => '', 'country_val' => '', 'country_non_restricted' => '', 'region_non_restricted' => '', 'city_non_restricted' => '', 'filter_by_non_restricted' => true, 'compare_operator' => 'like', 'country_column_name' => 'country', 'region_column_name' => 'region', 'city_column_name' => 'city', 'location_link_part' => true, 'order_by' => 'asc', 'no_of_records' => '', 'spage' => '', 'format' => array('type' => 'list', 'container_wrapper' => 'ul', 'container_wrapper_attr' => '', 'item_wrapper' => 'li', 'item_wrapper_attr' => '')); $location_args = wp_parse_args($args, $defaults); $search_query = ''; $location_link_column = ''; $location_default = geodir_get_default_location(); if ($location_args['filter_by_non_restricted']) { // Non restricted countries if ($location_args['country_non_restricted'] == '') { if (get_option('geodir_enable_country') == 'default') { $country_non_retsricted = isset($location_default->country) ? $location_default->country : ''; $location_args['country_non_restricted'] = $country_non_retsricted; } else { if (get_option('geodir_enable_country') == 'selected') { $country_non_retsricted = get_option('geodir_selected_countries'); if (!empty($country_non_retsricted) && is_array($country_non_retsricted)) { $country_non_retsricted = implode(',', $country_non_retsricted); } $location_args['country_non_restricted'] = $country_non_retsricted; } } $location_args['country_non_restricted'] = geodir_parse_location_list($location_args['country_non_restricted']); } //Non restricted Regions if ($location_args['region_non_restricted'] == '') { if (get_option('geodir_enable_region') == 'default') { $regoin_non_restricted = isset($location_default->region) ? $location_default->region : ''; $location_args['region_non_restricted'] = $regoin_non_restricted; } else { if (get_option('geodir_enable_region') == 'selected') { $regoin_non_restricted = get_option('geodir_selected_regions'); if (!empty($regoin_non_restricted) && is_array($regoin_non_restricted)) { $regoin_non_restricted = implode(',', $regoin_non_restricted); } $location_args['region_non_restricted'] = $regoin_non_restricted; } } $location_args['region_non_restricted'] = geodir_parse_location_list($location_args['region_non_restricted']); } //Non restricted cities if ($location_args['city_non_restricted'] == '') { if (get_option('geodir_enable_city') == 'default') { $city_non_retsricted = isset($location_default->city) ? $location_default->city : ''; $location_args['city_non_restricted'] = $city_non_retsricted; } else { if (get_option('geodir_enable_city') == 'selected') { $city_non_restricted = get_option('geodir_selected_cities'); if (!empty($city_non_restricted) && is_array($city_non_restricted)) { $city_non_restricted = implode(',', $city_non_restricted); } $location_args['city_non_restricted'] = $city_non_restricted; } } $location_args['city_non_restricted'] = geodir_parse_location_list($location_args['city_non_restricted']); } } if ($location_args['what'] == '') { $location_args['what'] = 'city'; } if ($location_args['location_link_part']) { switch ($location_args['what']) { case 'country': if (get_option('permalink_structure') != '') { $location_link_column = ", CONCAT_WS('/', country_slug) AS location_link "; } else { $location_link_column = ", CONCAT_WS('&gd_country=', '', country_slug) AS location_link "; } break; case 'region': if (get_option('permalink_structure') != '') { $location_link_column = ", CONCAT_WS('/', country_slug, region_slug) AS location_link "; } else { $location_link_column = ", CONCAT_WS('&', CONCAT('&gd_country=', country_slug), CONCAT('gd_region=', region_slug) ) AS location_link "; } break; case 'city': if (get_option('permalink_structure') != '') { $location_link_column = ", CONCAT_WS('/', country_slug, region_slug, city_slug) AS location_link "; } else { $location_link_column = ", CONCAT_WS('&', CONCAT('&gd_country=', country_slug), CONCAT('gd_region=', region_slug) ,CONCAT('gd_city=' , city_slug)) AS location_link "; } /*else { if ( get_option('permalink_structure') != '' ) $location_link_column = " , city_slug as location_link "; else $location_link_column = " , CONCAT_WS('&gd_city=', '',city_slug) as location_link "; }*/ break; /*default: if(get_option('geodir_show_location_url')=='all') { if ( get_option('permalink_structure') != '' ) $location_link_column = " , CONCAT_WS('/', country_slug, region_slug, city_slug) as location_link "; else $location_link_column = " , CONCAT_WS('&', CONCAT('&gd_country=' ,country_slug) ,CONCAT('gd_region=' , region_slug) ,CONCAT('gd_city=' , city_slug)) as location_link "; } else { if ( get_option('permalink_structure') != '' ) $location_link_column = " , city_slug as location_link "; else $location_link_column = " , CONCAT_WS('&gd_city=', '',city_slug) as location_link "; } break;*/ } } switch ($location_args['compare_operator']) { case 'like': if (isset($location_args['country_val']) && $location_args['country_val'] != '') { //$search_query .= " AND lower(".$location_args['country_column_name'].") like '". mb_strtolower( $location_args['country_val'] )."%' "; $countries_search_sql = geodir_countries_search_sql($location_args['country_val']); $countries_search_sql = $countries_search_sql != '' ? " OR FIND_IN_SET(country, '" . $countries_search_sql . "')" : ''; $translated_country_val = sanitize_title(trim(wp_unslash($location_args['country_val']))); $search_query .= " AND ( lower(" . $location_args['country_column_name'] . ") like '%" . mb_strtolower($location_args['country_val']) . "%' OR lower(country_slug) LIKE '" . $translated_country_val . "%' " . $countries_search_sql . " ) "; } if (isset($location_args['region_val']) && $location_args['region_val'] != '') { $search_query .= " AND lower(" . $location_args['region_column_name'] . ") like '%" . mb_strtolower($location_args['region_val']) . "%' "; } if (isset($location_args['city_val']) && $location_args['city_val'] != '') { $search_query .= " AND lower(" . $location_args['city_column_name'] . ") like '%" . mb_strtolower($location_args['city_val']) . "%' "; } break; case 'in': if (isset($location_args['country_val']) && $location_args['country_val'] != '') { $location_args['country_val'] = geodir_parse_location_list($location_args['country_val']); $search_query .= " AND lower(" . $location_args['country_column_name'] . ") in({$location_args['country_val']}) "; } if (isset($location_args['region_val']) && $location_args['region_val'] != '') { $location_args['region_val'] = geodir_parse_location_list($location_args['region_val']); $search_query .= " AND lower(" . $location_args['region_column_name'] . ") in({$location_args['region_val']}) "; } if (isset($location_args['city_val']) && $location_args['city_val'] != '') { $location_args['city_val'] = geodir_parse_location_list($location_args['city_val']); $search_query .= " AND lower(" . $location_args['city_column_name'] . ") in({$location_args['city_val']}) "; } break; default: if (isset($location_args['country_val']) && $location_args['country_val'] != '') { //$search_query .= " AND lower(".$location_args['country_column_name'].") = '". mb_strtolower($location_args['country_val'])."' "; $countries_search_sql = geodir_countries_search_sql($location_args['country_val']); $countries_search_sql = $countries_search_sql != '' ? " OR FIND_IN_SET(country, '" . $countries_search_sql . "')" : ''; $translated_country_val = sanitize_title(trim(wp_unslash($location_args['country_val']))); $search_query .= " AND ( lower(" . $location_args['country_column_name'] . ") = '" . mb_strtolower($location_args['country_val']) . "' OR lower(country_slug) LIKE '" . $translated_country_val . "%' " . $countries_search_sql . " ) "; } if (isset($location_args['region_val']) && $location_args['region_val'] != '') { $search_query .= " AND lower(" . $location_args['region_column_name'] . ") = '" . mb_strtolower($location_args['region_val']) . "' "; } if (isset($location_args['city_val']) && $location_args['city_val'] != '') { $search_query .= " AND lower(" . $location_args['city_column_name'] . ") = '" . mb_strtolower($location_args['city_val']) . "' "; } break; } // end of switch if ($location_args['country_non_restricted'] != '') { $search_query .= " AND LOWER(country) IN ({$location_args['country_non_restricted']}) "; } if ($location_args['region_non_restricted'] != '') { if ($location_args['what'] == 'region' || $location_args['what'] == 'city') { $search_query .= " AND LOWER(region) IN ({$location_args['region_non_restricted']}) "; } } if ($location_args['city_non_restricted'] != '') { if ($location_args['what'] == 'city') { $search_query .= " AND LOWER(city) IN ({$location_args['city_non_restricted']}) "; } } //page if ($location_args['no_of_records']) { $spage = $location_args['no_of_records'] * $location_args['spage']; } else { $spage = "0"; } // limit $limit = $location_args['no_of_records'] != '' ? ' LIMIT ' . $spage . ', ' . (int) $location_args['no_of_records'] . ' ' : ''; // display all locations with same name also $search_field = $location_args['what']; if ($switcher) { $select = $search_field . $location_link_column; $group_by = $search_field; $order_by = $search_field; if ($search_field == 'city') { $select .= ', country, region, city, country_slug, region_slug, city_slug'; $group_by = 'country, region, city'; $order_by = 'city, region, country'; } else { if ($search_field == 'region') { $select .= ', country, region, country_slug, region_slug'; $group_by = 'country, region'; $order_by = 'region, country'; } else { if ($search_field == 'country') { $select .= ', country, country_slug'; $group_by = 'country'; $order_by = 'country'; } } } $main_location_query = "SELECT " . $select . " FROM " . POST_LOCATION_TABLE . " WHERE 1=1 " . $search_query . " GROUP BY " . $group_by . " ORDER BY " . $order_by . " " . $location_args['order_by'] . " " . $limit; } else { $main_location_query = "SELECT {$location_args['what']} {$location_link_column} FROM " . POST_LOCATION_TABLE . " WHERE 1=1 " . $search_query . " GROUP BY {$location_args['what']} ORDER BY {$location_args['what']} {$location_args['order_by']} {$limit}"; } $locations = $wpdb->get_results($main_location_query); if ($switcher && !empty($locations)) { $new_locations = array(); foreach ($locations as $location) { //print_r($location); //echo '###'.$search_field; $new_location = $location; $label = $location->{$search_field}; if (($search_field == 'city' || $search_field == 'region') && (int) geodir_location_check_duplicate($search_field, $label) > 1) { if ($search_field == 'city') { $label .= ', ' . $location->region; } else { if ($search_field == 'region') { $country_iso2 = geodir_location_get_iso2($location->country); $country_iso2 = $country_iso2 != '' ? $country_iso2 : $location->country; $label .= $country_iso2 != '' ? ', ' . $country_iso2 : ''; } } } $new_location->title = $location->{$search_field}; $new_location->{$search_field} = $label; $new_location->label = $label; $new_locations[] = $new_location; } $locations = $new_locations; } $location_as_formated_list = ""; if (!empty($location_args['format'])) { if ($location_args['format']['type'] == 'array') { return $locations; } elseif ($location_args['format']['type'] == 'jason') { return json_encode($locations); } else { $base_location_link = geodir_get_location_link('base'); $container_wrapper = ''; $container_wrapper_attr = ''; $item_wrapper = ''; $item_wrapper_attr = ''; if (isset($location_args['format']['container_wrapper']) && !empty($location_args['format']['container_wrapper'])) { $container_wrapper = $location_args['format']['container_wrapper']; } if (isset($location_args['format']['container_wrapper_attr']) && !empty($location_args['format']['container_wrapper_attr'])) { $container_wrapper_attr = $location_args['format']['container_wrapper_attr']; } if (isset($location_args['format']['item_wrapper']) && !empty($location_args['format']['item_wrapper'])) { $item_wrapper = $location_args['format']['item_wrapper']; } if (isset($location_args['format']['item_wrapper_attr']) && !empty($location_args['format']['item_wrapper_attr'])) { $item_wrapper_attr = $location_args['format']['item_wrapper_attr']; } if (!empty($container_wrapper)) { $location_as_formated_list = "<" . $container_wrapper . " " . $container_wrapper_attr . " >"; } if (!empty($locations)) { foreach ($locations as $location) { if (!empty($item_wrapper)) { $location_as_formated_list .= "<" . $item_wrapper . " " . $item_wrapper_attr . " >"; } if (isset($location->location_link)) { $location_as_formated_list .= "<a href='" . geodir_location_permalink_url($base_location_link . $location->location_link) . "' ><i class='fa fa-caret-right'></i> "; } $location_as_formated_list .= $location->{$location_args}['what']; if (isset($location->location_link)) { $location_as_formated_list .= "</a>"; } if (!empty($item_wrapper)) { $location_as_formated_list .= "</" . $item_wrapper . ">"; } } } return $location_as_formated_list; } } return $locations; }
/** * Redirect url after sharing location. * * @since 1.0.0 * @package GeoDirectory_Location_Manager * * @global object $wp_query WordPress Query object. * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * * @param string $redirect_url Old redirect url * @return bool|null|string Filtered redirect url. */ 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 = (double) stripslashes(ucfirst($_REQUEST['lat'])); $mylon = (double) 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; } }
/** * * @global object $wpdb WordPress Database object. * * @param null $args * @return string */ function geodir_location_tab_switcher($args = null) { $switcher = !empty($args) && isset($args['addSearchTermOnNorecord']) ? true : false; if (get_option('geodir_enable_country') != 'default' || get_option('geodir_enable_region') != 'default' || get_option('geodir_enable_city') != 'default') { $defaults = array('echo' => true, 'addSearchTermOnNorecord' => 0, 'autoredirect' => false); $args = wp_parse_args($args, $defaults); global $wpdb; // Options $echo = $args['echo']; $addSearchTermOnNorecord = $args['addSearchTermOnNorecord']; $autoredirect = $args['autoredirect']; $output = ''; $selected = ''; $location_list = ''; $country_div = ''; $region_div = ''; $city_div = ''; $onchange = ''; $what_is_current_location = geodir_what_is_current_location(); $what_is_current_location_div = $what_is_current_location . '_div'; if ($what_is_current_location != '') { ${$what_is_current_location_div} = 'gd-tab-active'; } else { $what_is_current_location = apply_filters('geodir_location_switcher_default_tab', 'city'); $what_is_current_location_div = $what_is_current_location . '_div'; ${$what_is_current_location_div} = 'gd-tab-active'; } $location_value = ''; if ($autoredirect === '0') { } else { $location_value = geodir_get_location_link('base'); $onchange = ' onchange="window.location.href=this.value" '; $autoredirect = '1'; } $base_location = geodir_get_location_link('base'); $current_location_array = array(); $selected = ''; $country_val = ''; $region_val = ''; $city_val = ''; $country_val = geodir_get_current_location(array('what' => 'country', 'echo' => false)); $region_val = geodir_get_current_location(array('what' => 'region', 'echo' => false)); $city_val = geodir_get_current_location(array('what' => 'city', 'echo' => false)); $item_set_selected = false; $output .= '<div class="geodir_location_tab_container" >'; $output .= '<dl class="geodir_location_tabs_head">'; if (get_option('geodir_enable_country') != 'default') { $output .= '<dd data-location="country" class="geodir_location_tabs ' . $country_div . '" ><a href="javascript:void(0)">' . __('Country', GEODIRLOCATION_TEXTDOMAIN) . '</a></dd>'; } if (get_option('geodir_enable_region') != 'default') { $output .= '<dd data-location="region" class="geodir_location_tabs ' . $region_div . '" ><a href="javascript:void(0)">' . __('Region', GEODIRLOCATION_TEXTDOMAIN) . '</a></dd>'; } if (get_option('geodir_enable_city') != 'default') { $output .= '<dd data-location="city" class="geodir_location_tabs ' . $city_div . ' " ><a href="javascript:void(0)">' . __('City', GEODIRLOCATION_TEXTDOMAIN) . '</a></dd>'; } $output .= '</dl>'; $output .= '<input type="hidden" class="selected_location" value="city" /><div style="clear:both;"></div>'; $output .= '<div class="geodir_location_sugestion">'; $output .= '<select class="geodir_location_switcher_chosen" name="gd_location" data-placeholder="' . __('Please wait..…', GEODIRLOCATION_TEXTDOMAIN) . '" data-addSearchTermOnNorecord="' . $addSearchTermOnNorecord . '" data-autoredirect="' . $autoredirect . '" ' . $onchange . ' data-showeverywhere="1" >'; $location_switcher_list_mode = get_option('geodir_location_switcher_list_mode'); if (empty($location_switcher_list_mode)) { $location_switcher_list_mode = 'drill'; } if ($location_switcher_list_mode == 'drill') { $args = array('what' => $what_is_current_location, 'country_val' => strtolower($what_is_current_location) == 'region' || strtolower($what_is_current_location) == 'city' ? $country_val : '', 'region_val' => strtolower($what_is_current_location) == 'city' ? $region_val : '', 'echo' => false, 'no_of_records' => '5', 'format' => array('type' => 'array')); } else { $args = array('what' => $what_is_current_location, 'echo' => false, 'no_of_records' => '5', 'format' => array('type' => 'array')); } if ($what_is_current_location == 'country' && $country_val != '') { $args_current_location = array('what' => $what_is_current_location, 'country_val' => $country_val, 'compare_operator' => '=', 'no_of_records' => '1', 'echo' => false, 'format' => array('type' => 'array')); $current_location_array = geodir_get_location_array($args_current_location, $switcher); } if ($what_is_current_location == 'region' && $region_val != '') { $args_current_location = array('what' => $what_is_current_location, 'country_val' => $country_val, 'region_val' => $region_val, 'compare_operator' => '=', 'no_of_records' => '1', 'echo' => false, 'format' => array('type' => 'array')); $current_location_array = geodir_get_location_array($args_current_location, $switcher); } if ($what_is_current_location == 'city' && $city_val != '') { $args_current_location = array('what' => $what_is_current_location, 'country_val' => $country_val, 'region_val' => $region_val, 'city_val' => $city_val, 'compare_operator' => '=', 'no_of_records' => '1', 'echo' => false, 'format' => array('type' => 'array')); $current_location_array = geodir_get_location_array($args_current_location, $switcher); } $location_array = geodir_get_location_array($args, $switcher); // get country val in case of country search to get selected option if (get_option('geodir_everywhere_in_' . $what_is_current_location . '_dropdown')) { $output .= '<option value="' . $base_location . '">' . __('Everywhere', GEODIRLOCATION_TEXTDOMAIN) . '</option>'; } $selected = ''; if (!empty($location_array)) { foreach ($location_array as $locations) { $selected = ''; $with_parent = isset($locations->label) ? true : false; switch ($what_is_current_location) { case 'country': if (strtolower($country_val) == strtolower($locations->country)) { $selected = 'selected="selected"'; } $locations->country = __($locations->country, GEODIRECTORY_TEXTDOMAIN); break; case 'region': $country_iso2 = geodir_location_get_iso2($country_val); $country_iso2 = $country_iso2 != '' ? $country_iso2 : $country_val; $with_parent = $with_parent && strtolower($region_val . ', ' . $country_iso2) == strtolower($locations->label) ? true : false; if (strtolower($region_val) == strtolower($locations->region) || $with_parent) { $selected = 'selected="selected"'; } break; case 'city': $with_parent = $with_parent && strtolower($city_val . ', ' . $region_val) == strtolower($locations->label) ? true : false; if (strtolower($city_val) == strtolower($locations->city) || $with_parent) { $selected = 'selected="selected"'; } break; } $output .= '<option value="' . geodir_location_permalink_url($base_location . $locations->location_link) . '" ' . $selected . '>' . ucwords($locations->{$what_is_current_location}) . '</option>'; if (!$item_set_selected && $selected != '') { $item_set_selected = true; } } } if (!empty($current_location_array) && !$item_set_selected) { foreach ($current_location_array as $current_location) { $selected = ''; $with_parent = isset($current_location->label) ? true : false; switch ($what_is_current_location) { case 'country': if (strtolower($country_val) == strtolower($current_location->country)) { $selected = 'selected="selected"'; } $current_location->country = __($current_location->country, GEODIRECTORY_TEXTDOMAIN); break; case 'region': $country_iso2 = geodir_location_get_iso2($country_val); $country_iso2 = $country_iso2 != '' ? $country_iso2 : $country_val; $with_parent = $with_parent && strtolower($region_val . ', ' . $country_iso2) == strtolower($current_location->label) ? true : false; if (strtolower($region_val) == strtolower($current_location->region) || $with_parent) { $selected = 'selected="selected"'; } break; case 'city': $with_parent = $with_parent && strtolower($city_val . ', ' . $region_val) == strtolower($current_location->label) ? true : false; if (strtolower($city_val) == strtolower($current_location->city) || $with_parent) { $selected = 'selected="selected"'; } break; } $output .= '<option value="' . geodir_location_permalink_url($base_location . $current_location->location_link) . '" ' . $selected . '>' . ucwords($current_location->{$what_is_current_location}) . '</option>'; } } $output .= '</select>'; $output .= "</div>"; $output .= '</div>'; if ($echo) { echo $output; } else { return $output; } } }