@@ -9,10 +9,10 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function geodir_get_current_city_lat() |
| 11 | 11 | {
|
| 12 | - $location = geodir_get_default_location(); |
|
| 13 | - $lat = isset($location_result->city_latitude) ? $location_result->city_latitude : '39.952484'; |
|
| 12 | + $location = geodir_get_default_location(); |
|
| 13 | + $lat = isset($location_result->city_latitude) ? $location_result->city_latitude : '39.952484'; |
|
| 14 | 14 | |
| 15 | - return $lat; |
|
| 15 | + return $lat; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function geodir_get_current_city_lng() |
| 27 | 27 | {
|
| 28 | - $location = geodir_get_default_location(); |
|
| 29 | - $lng = isset($location_result->city_longitude) ? $location_result->city_longitude : '-75.163786'; |
|
| 30 | - return $lng; |
|
| 28 | + $location = geodir_get_default_location(); |
|
| 29 | + $lng = isset($location_result->city_longitude) ? $location_result->city_longitude : '-75.163786'; |
|
| 30 | + return $lng; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -40,15 +40,15 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function geodir_get_default_location() |
| 42 | 42 | {
|
| 43 | - /** |
|
| 44 | - * Filter the default location. |
|
| 45 | - * |
|
| 46 | - * @since 1.0.0 |
|
| 47 | - * @package GeoDirectory |
|
| 48 | - * |
|
| 49 | - * @param string $location_result The default location object. |
|
| 50 | - */ |
|
| 51 | - return $location_result = apply_filters('geodir_get_default_location', get_option('geodir_default_location'));
|
|
| 43 | + /** |
|
| 44 | + * Filter the default location. |
|
| 45 | + * |
|
| 46 | + * @since 1.0.0 |
|
| 47 | + * @package GeoDirectory |
|
| 48 | + * |
|
| 49 | + * @param string $location_result The default location object. |
|
| 50 | + */ |
|
| 51 | + return $location_result = apply_filters('geodir_get_default_location', get_option('geodir_default_location'));
|
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function geodir_is_default_location_set() |
| 62 | 62 | {
|
| 63 | - $default_location = geodir_get_default_location(); |
|
| 64 | - if (!empty($default_location)) |
|
| 65 | - return true; |
|
| 66 | - else |
|
| 67 | - return false; |
|
| 63 | + $default_location = geodir_get_default_location(); |
|
| 64 | + if (!empty($default_location)) |
|
| 65 | + return true; |
|
| 66 | + else |
|
| 67 | + return false; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -78,15 +78,15 @@ discard block |
||
| 78 | 78 | function create_location_slug($location_string) |
| 79 | 79 | {
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Filter the location slug. |
|
| 83 | - * |
|
| 84 | - * @since 1.0.0 |
|
| 85 | - * @package GeoDirectory |
|
| 86 | - * |
|
| 87 | - * @param string $location_string Sanitized location string. |
|
| 88 | - */ |
|
| 89 | - return urldecode(apply_filters('geodir_location_slug_check', sanitize_title($location_string)));
|
|
| 81 | + /** |
|
| 82 | + * Filter the location slug. |
|
| 83 | + * |
|
| 84 | + * @since 1.0.0 |
|
| 85 | + * @package GeoDirectory |
|
| 86 | + * |
|
| 87 | + * @param string $location_string Sanitized location string. |
|
| 88 | + */ |
|
| 89 | + return urldecode(apply_filters('geodir_location_slug_check', sanitize_title($location_string)));
|
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | function geodir_get_location($id = '') |
| 102 | 102 | {
|
| 103 | - /** |
|
| 104 | - * Filter the location information. |
|
| 105 | - * |
|
| 106 | - * @since 1.0.0 |
|
| 107 | - * @package GeoDirectory |
|
| 108 | - * |
|
| 109 | - * @param string $id The location ID. |
|
| 110 | - */ |
|
| 111 | - return $location_result = apply_filters('geodir_get_location_by_id', get_option('geodir_default_location'), $id);
|
|
| 103 | + /** |
|
| 104 | + * Filter the location information. |
|
| 105 | + * |
|
| 106 | + * @since 1.0.0 |
|
| 107 | + * @package GeoDirectory |
|
| 108 | + * |
|
| 109 | + * @param string $id The location ID. |
|
| 110 | + */ |
|
| 111 | + return $location_result = apply_filters('geodir_get_location_by_id', get_option('geodir_default_location'), $id);
|
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -122,28 +122,28 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | function geodir_get_country_dl($post_country = '', $prefix = '') |
| 124 | 124 | {
|
| 125 | - global $wpdb; |
|
| 125 | + global $wpdb; |
|
| 126 | 126 | |
| 127 | - $rows = $wpdb->get_results("SELECT Country,ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " ORDER BY Country ASC");
|
|
| 127 | + $rows = $wpdb->get_results("SELECT Country,ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " ORDER BY Country ASC");
|
|
| 128 | 128 | |
| 129 | - $ISO2 = array(); |
|
| 130 | - $countries = array(); |
|
| 129 | + $ISO2 = array(); |
|
| 130 | + $countries = array(); |
|
| 131 | 131 | |
| 132 | - foreach ($rows as $row) {
|
|
| 133 | - $ISO2[$row->Country] = $row->ISO2; |
|
| 134 | - $countries[$row->Country] = __($row->Country, 'geodirectory'); |
|
| 135 | - } |
|
| 132 | + foreach ($rows as $row) {
|
|
| 133 | + $ISO2[$row->Country] = $row->ISO2; |
|
| 134 | + $countries[$row->Country] = __($row->Country, 'geodirectory'); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - asort($countries); |
|
| 137 | + asort($countries); |
|
| 138 | 138 | |
| 139 | - $out_put = '<option ' . selected('', $post_country, false) . ' value="">' . __('Select Country', 'geodirectory') . '</option>';
|
|
| 140 | - foreach ($countries as $country => $name) {
|
|
| 141 | - $ccode = $ISO2[$country]; |
|
| 139 | + $out_put = '<option ' . selected('', $post_country, false) . ' value="">' . __('Select Country', 'geodirectory') . '</option>';
|
|
| 140 | + foreach ($countries as $country => $name) {
|
|
| 141 | + $ccode = $ISO2[$country]; |
|
| 142 | 142 | |
| 143 | - $out_put .= '<option ' . selected($post_country, $country, false) . ' value="' . esc_attr($country) . '" data-country_code="' . $ccode . '">' . $name . '</option>'; |
|
| 144 | - } |
|
| 143 | + $out_put .= '<option ' . selected($post_country, $country, false) . ' value="' . esc_attr($country) . '" data-country_code="' . $ccode . '">' . $name . '</option>'; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - echo $out_put; |
|
| 146 | + echo $out_put; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
@@ -158,40 +158,40 @@ discard block |
||
| 158 | 158 | function geodir_location_form_submit() |
| 159 | 159 | {
|
| 160 | 160 | |
| 161 | - global $wpdb, $plugin_prefix; |
|
| 162 | - if (isset($_REQUEST['add_location'])) {
|
|
| 161 | + global $wpdb, $plugin_prefix; |
|
| 162 | + if (isset($_REQUEST['add_location'])) {
|
|
| 163 | 163 | |
| 164 | - $location_info = array( |
|
| 165 | - 'city' => $_REQUEST['city'], |
|
| 166 | - 'region' => $_REQUEST['region'], |
|
| 167 | - 'country' => $_REQUEST['country'], |
|
| 168 | - 'geo_lat' => $_REQUEST['latitude'], |
|
| 169 | - 'geo_lng' => $_REQUEST['longitude'], |
|
| 170 | - 'is_default' => $_REQUEST['is_default'], |
|
| 171 | - 'update_city' => $_REQUEST['update_city'] |
|
| 172 | - ); |
|
| 164 | + $location_info = array( |
|
| 165 | + 'city' => $_REQUEST['city'], |
|
| 166 | + 'region' => $_REQUEST['region'], |
|
| 167 | + 'country' => $_REQUEST['country'], |
|
| 168 | + 'geo_lat' => $_REQUEST['latitude'], |
|
| 169 | + 'geo_lng' => $_REQUEST['longitude'], |
|
| 170 | + 'is_default' => $_REQUEST['is_default'], |
|
| 171 | + 'update_city' => $_REQUEST['update_city'] |
|
| 172 | + ); |
|
| 173 | 173 | |
| 174 | - $old_location = geodir_get_default_location(); |
|
| 174 | + $old_location = geodir_get_default_location(); |
|
| 175 | 175 | |
| 176 | - $locationid = geodir_add_new_location($location_info); |
|
| 176 | + $locationid = geodir_add_new_location($location_info); |
|
| 177 | 177 | |
| 178 | - $default_location = geodir_get_location($locationid); |
|
| 178 | + $default_location = geodir_get_location($locationid); |
|
| 179 | 179 | |
| 180 | - //UPDATE AND DELETE LISTING |
|
| 181 | - $posttype = geodir_get_posttypes(); |
|
| 182 | - if (isset($_REQUEST['listing_action']) && $_REQUEST['listing_action'] == 'delete') {
|
|
| 180 | + //UPDATE AND DELETE LISTING |
|
| 181 | + $posttype = geodir_get_posttypes(); |
|
| 182 | + if (isset($_REQUEST['listing_action']) && $_REQUEST['listing_action'] == 'delete') {
|
|
| 183 | 183 | |
| 184 | - foreach ($posttype as $posttypeobj) {
|
|
| 185 | - $post_locations = '[' . $default_location->city_slug . '],[' . $default_location->region_slug . '],[' . $default_location->country_slug . ']'; // set all overall post location |
|
| 184 | + foreach ($posttype as $posttypeobj) {
|
|
| 185 | + $post_locations = '[' . $default_location->city_slug . '],[' . $default_location->region_slug . '],[' . $default_location->country_slug . ']'; // set all overall post location |
|
| 186 | 186 | |
| 187 | - $sql = $wpdb->prepare( |
|
| 188 | - "UPDATE " . $plugin_prefix . $posttypeobj . "_detail SET post_city=%s, post_region=%s, post_country=%s, post_locations=%s WHERE post_location_id=%d AND ( post_city!=%s OR post_region!=%s OR post_country!=%s OR post_locations!=%s OR post_locations IS NULL)", |
|
| 189 | - array($_REQUEST['city'], $_REQUEST['region'], $_REQUEST['country'], $post_locations, $locationid, $_REQUEST['city'], $_REQUEST['region'], $_REQUEST['country'], $post_locations) |
|
| 190 | - ); |
|
| 191 | - $wpdb->query($sql); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 187 | + $sql = $wpdb->prepare( |
|
| 188 | + "UPDATE " . $plugin_prefix . $posttypeobj . "_detail SET post_city=%s, post_region=%s, post_country=%s, post_locations=%s WHERE post_location_id=%d AND ( post_city!=%s OR post_region!=%s OR post_country!=%s OR post_locations!=%s OR post_locations IS NULL)", |
|
| 189 | + array($_REQUEST['city'], $_REQUEST['region'], $_REQUEST['country'], $post_locations, $locationid, $_REQUEST['city'], $_REQUEST['region'], $_REQUEST['country'], $post_locations) |
|
| 190 | + ); |
|
| 191 | + $wpdb->query($sql); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -214,39 +214,39 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | function geodir_add_new_location($location_info = array()) |
| 216 | 216 | {
|
| 217 | - global $wpdb; |
|
| 218 | - |
|
| 219 | - if (!empty($location_info)) {
|
|
| 220 | - |
|
| 221 | - $location_city = ($location_info['city'] != '') ? $location_info['city'] : 'all'; |
|
| 222 | - $location_region = ($location_info['region'] != '') ? $location_info['region'] : 'all'; |
|
| 223 | - $location_country = ($location_info['country'] != '') ? $location_info['country'] : 'all'; |
|
| 224 | - $location_lat = ($location_info['geo_lat'] != '') ? $location_info['geo_lat'] : ''; |
|
| 225 | - $location_lng = ($location_info['geo_lng'] != '') ? $location_info['geo_lng'] : ''; |
|
| 226 | - $is_default = isset($location_info['is_default']) ? $location_info['is_default'] : ''; |
|
| 227 | - $country_slug = create_location_slug(__($location_country, 'geodirectory')); |
|
| 228 | - $region_slug = create_location_slug($location_region); |
|
| 229 | - $city_slug = create_location_slug($location_city); |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Filter add new location data. |
|
| 233 | - * |
|
| 234 | - * @since 1.0.0 |
|
| 235 | - */ |
|
| 236 | - $geodir_location = (object)apply_filters('geodir_add_new_location', array('location_id' => 0,
|
|
| 237 | - 'country' => $location_country, |
|
| 238 | - 'region' => $location_region, |
|
| 239 | - 'city' => $location_city, |
|
| 240 | - 'country_slug' => $country_slug, |
|
| 241 | - 'region_slug' => $region_slug, |
|
| 242 | - 'city_slug' => $city_slug, |
|
| 243 | - 'city_latitude' => $location_lat, |
|
| 244 | - 'city_longitude' => $location_lng, |
|
| 245 | - 'is_default' => $is_default |
|
| 246 | - )); |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /* // Not allowed to create country in DB : 2016-12-09 |
|
| 217 | + global $wpdb; |
|
| 218 | + |
|
| 219 | + if (!empty($location_info)) {
|
|
| 220 | + |
|
| 221 | + $location_city = ($location_info['city'] != '') ? $location_info['city'] : 'all'; |
|
| 222 | + $location_region = ($location_info['region'] != '') ? $location_info['region'] : 'all'; |
|
| 223 | + $location_country = ($location_info['country'] != '') ? $location_info['country'] : 'all'; |
|
| 224 | + $location_lat = ($location_info['geo_lat'] != '') ? $location_info['geo_lat'] : ''; |
|
| 225 | + $location_lng = ($location_info['geo_lng'] != '') ? $location_info['geo_lng'] : ''; |
|
| 226 | + $is_default = isset($location_info['is_default']) ? $location_info['is_default'] : ''; |
|
| 227 | + $country_slug = create_location_slug(__($location_country, 'geodirectory')); |
|
| 228 | + $region_slug = create_location_slug($location_region); |
|
| 229 | + $city_slug = create_location_slug($location_city); |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Filter add new location data. |
|
| 233 | + * |
|
| 234 | + * @since 1.0.0 |
|
| 235 | + */ |
|
| 236 | + $geodir_location = (object)apply_filters('geodir_add_new_location', array('location_id' => 0,
|
|
| 237 | + 'country' => $location_country, |
|
| 238 | + 'region' => $location_region, |
|
| 239 | + 'city' => $location_city, |
|
| 240 | + 'country_slug' => $country_slug, |
|
| 241 | + 'region_slug' => $region_slug, |
|
| 242 | + 'city_slug' => $city_slug, |
|
| 243 | + 'city_latitude' => $location_lat, |
|
| 244 | + 'city_longitude' => $location_lng, |
|
| 245 | + 'is_default' => $is_default |
|
| 246 | + )); |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /* // Not allowed to create country in DB : 2016-12-09 |
|
| 250 | 250 | if ($geodir_location->country) {
|
| 251 | 251 | |
| 252 | 252 | $get_country = $wpdb->get_var($wpdb->prepare("SELECT Country FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country=%s", array($geodir_location->country)));
|
@@ -260,14 +260,14 @@ discard block |
||
| 260 | 260 | } |
| 261 | 261 | */ |
| 262 | 262 | |
| 263 | - if ($geodir_location->is_default) |
|
| 264 | - update_option('geodir_default_location', $geodir_location);
|
|
| 263 | + if ($geodir_location->is_default) |
|
| 264 | + update_option('geodir_default_location', $geodir_location);
|
|
| 265 | 265 | |
| 266 | - return $geodir_location->location_id; |
|
| 266 | + return $geodir_location->location_id; |
|
| 267 | 267 | |
| 268 | - } else {
|
|
| 269 | - return false; |
|
| 270 | - } |
|
| 268 | + } else {
|
|
| 269 | + return false; |
|
| 270 | + } |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | function geodir_random_float($min = 0, $max = 1) |
| 283 | 283 | {
|
| 284 | - return $min + mt_rand() / mt_getrandmax() * ($max - $min); |
|
| 284 | + return $min + mt_rand() / mt_getrandmax() * ($max - $min); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -295,22 +295,22 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | function geodir_get_address_by_lat_lan($lat, $lng) |
| 297 | 297 | {
|
| 298 | - $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . trim($lat) . ',' . trim($lng) ; |
|
| 299 | - |
|
| 300 | - $ch = curl_init(); |
|
| 301 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
| 302 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 303 | - curl_setopt($ch, CURLOPT_PROXYPORT, 3128); |
|
| 304 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 305 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 306 | - $response = curl_exec($ch); |
|
| 307 | - curl_close($ch); |
|
| 308 | - $data = json_decode($response); |
|
| 309 | - $status = $data->status; |
|
| 310 | - if ($status == "OK") {
|
|
| 311 | - return $data->results[0]->address_components; |
|
| 312 | - } else |
|
| 313 | - return false; |
|
| 298 | + $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . trim($lat) . ',' . trim($lng) ; |
|
| 299 | + |
|
| 300 | + $ch = curl_init(); |
|
| 301 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 302 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 303 | + curl_setopt($ch, CURLOPT_PROXYPORT, 3128); |
|
| 304 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 305 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 306 | + $response = curl_exec($ch); |
|
| 307 | + curl_close($ch); |
|
| 308 | + $data = json_decode($response); |
|
| 309 | + $status = $data->status; |
|
| 310 | + if ($status == "OK") {
|
|
| 311 | + return $data->results[0]->address_components; |
|
| 312 | + } else |
|
| 313 | + return false; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -327,70 +327,70 @@ discard block |
||
| 327 | 327 | */ |
| 328 | 328 | function geodir_get_current_location_terms($location_array_from = 'session', $gd_post_type = '') |
| 329 | 329 | {
|
| 330 | - global $wp, $gd_session; |
|
| 331 | - $location_array = array(); |
|
| 332 | - if ($location_array_from == 'session') {
|
|
| 333 | - if ($gd_session->get('gd_country') == 'me' || $gd_session->get('gd_region') == 'me' || $gd_session->get('gd_city') == 'me') {
|
|
| 334 | - return $location_array; |
|
| 335 | - } |
|
| 330 | + global $wp, $gd_session; |
|
| 331 | + $location_array = array(); |
|
| 332 | + if ($location_array_from == 'session') {
|
|
| 333 | + if ($gd_session->get('gd_country') == 'me' || $gd_session->get('gd_region') == 'me' || $gd_session->get('gd_city') == 'me') {
|
|
| 334 | + return $location_array; |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - $country = $gd_session->get('gd_country');
|
|
| 338 | - if ($country != '' && $country) |
|
| 339 | - $location_array['gd_country'] = urldecode($country); |
|
| 337 | + $country = $gd_session->get('gd_country');
|
|
| 338 | + if ($country != '' && $country) |
|
| 339 | + $location_array['gd_country'] = urldecode($country); |
|
| 340 | 340 | |
| 341 | - $region = $gd_session->get('gd_region');
|
|
| 342 | - if ($region != '' && $region) |
|
| 343 | - $location_array['gd_region'] = urldecode($region); |
|
| 341 | + $region = $gd_session->get('gd_region');
|
|
| 342 | + if ($region != '' && $region) |
|
| 343 | + $location_array['gd_region'] = urldecode($region); |
|
| 344 | 344 | |
| 345 | - $city = $gd_session->get('gd_city');
|
|
| 346 | - if ($city != '' && $city) |
|
| 347 | - $location_array['gd_city'] = urldecode($city); |
|
| 348 | - } else {
|
|
| 349 | - if ((isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] == 'me') || (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] == 'me') || (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] == 'me')) {
|
|
| 350 | - return $location_array; |
|
| 351 | - } |
|
| 345 | + $city = $gd_session->get('gd_city');
|
|
| 346 | + if ($city != '' && $city) |
|
| 347 | + $location_array['gd_city'] = urldecode($city); |
|
| 348 | + } else {
|
|
| 349 | + if ((isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] == 'me') || (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] == 'me') || (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] == 'me')) {
|
|
| 350 | + return $location_array; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - $country = (isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] != '') ? $wp->query_vars['gd_country'] : ''; |
|
| 353 | + $country = (isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] != '') ? $wp->query_vars['gd_country'] : ''; |
|
| 354 | 354 | |
| 355 | - $region = (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] != '') ? $wp->query_vars['gd_region'] : ''; |
|
| 355 | + $region = (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] != '') ? $wp->query_vars['gd_region'] : ''; |
|
| 356 | 356 | |
| 357 | - $city = (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] != '') ? $wp->query_vars['gd_city'] : ''; |
|
| 357 | + $city = (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] != '') ? $wp->query_vars['gd_city'] : ''; |
|
| 358 | 358 | |
| 359 | - if ($country != '') |
|
| 360 | - $location_array['gd_country'] = urldecode($country); |
|
| 359 | + if ($country != '') |
|
| 360 | + $location_array['gd_country'] = urldecode($country); |
|
| 361 | 361 | |
| 362 | - if ($region != '') |
|
| 363 | - $location_array['gd_region'] = urldecode($region); |
|
| 362 | + if ($region != '') |
|
| 363 | + $location_array['gd_region'] = urldecode($region); |
|
| 364 | 364 | |
| 365 | - if ($city != '') |
|
| 366 | - $location_array['gd_city'] = urldecode($city); |
|
| 365 | + if ($city != '') |
|
| 366 | + $location_array['gd_city'] = urldecode($city); |
|
| 367 | 367 | |
| 368 | 368 | // Fix category link in ajax popular category widget on change post type |
| 369 | 369 | if (empty($location_array) && defined('DOING_AJAX') && DOING_AJAX) {
|
| 370 | 370 | $location_array = geodir_get_current_location_terms('session');
|
| 371 | 371 | } |
| 372 | - } |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | 374 | /** |
| 375 | 375 | * Filter the location terms. |
| 376 | 376 | * |
| 377 | 377 | * @since 1.4.6 |
| 378 | - * @package GeoDirectory |
|
| 378 | + * @package GeoDirectory |
|
| 379 | + * |
|
| 380 | + * @param array $location_array {
|
|
| 381 | + * Attributes of the location_array. |
|
| 382 | + * |
|
| 383 | + * @type string $gd_country The country slug. |
|
| 384 | + * @type string $gd_region The region slug. |
|
| 385 | + * @type string $gd_city The city slug. |
|
| 379 | 386 | * |
| 380 | - * @param array $location_array {
|
|
| 381 | - * Attributes of the location_array. |
|
| 382 | - * |
|
| 383 | - * @type string $gd_country The country slug. |
|
| 384 | - * @type string $gd_region The region slug. |
|
| 385 | - * @type string $gd_city The city slug. |
|
| 386 | - * |
|
| 387 | - * } |
|
| 387 | + * } |
|
| 388 | 388 | * @param string $location_array_from Source type of location terms. Default session. |
| 389 | 389 | * @param string $gd_post_type WP post type. |
| 390 | 390 | */ |
| 391 | 391 | $location_array = apply_filters( 'geodir_current_location_terms', $location_array, $location_array_from, $gd_post_type ); |
| 392 | 392 | |
| 393 | - return $location_array; |
|
| 393 | + return $location_array; |
|
| 394 | 394 | |
| 395 | 395 | } |
| 396 | 396 | |
@@ -403,24 +403,24 @@ discard block |
||
| 403 | 403 | * @return bool|string |
| 404 | 404 | */ |
| 405 | 405 | function geodir_get_location_link($which_location = 'current') {
|
| 406 | - $location_link = get_permalink(geodir_location_page_id()); |
|
| 407 | - |
|
| 408 | - if ($which_location == 'base') {
|
|
| 409 | - return $location_link; |
|
| 410 | - } else {
|
|
| 411 | - $location_terms = geodir_get_current_location_terms(); |
|
| 412 | - |
|
| 413 | - if (!empty($location_terms)) {
|
|
| 414 | - if (get_option('permalink_structure') != '') {
|
|
| 415 | - $location_terms = implode("/", $location_terms);
|
|
| 416 | - $location_terms = rtrim($location_terms, '/'); |
|
| 417 | - $location_link .= $location_terms; |
|
| 418 | - } else {
|
|
| 419 | - $location_link = geodir_getlink($location_link, $location_terms); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - return $location_link; |
|
| 406 | + $location_link = get_permalink(geodir_location_page_id()); |
|
| 407 | + |
|
| 408 | + if ($which_location == 'base') {
|
|
| 409 | + return $location_link; |
|
| 410 | + } else {
|
|
| 411 | + $location_terms = geodir_get_current_location_terms(); |
|
| 412 | + |
|
| 413 | + if (!empty($location_terms)) {
|
|
| 414 | + if (get_option('permalink_structure') != '') {
|
|
| 415 | + $location_terms = implode("/", $location_terms);
|
|
| 416 | + $location_terms = rtrim($location_terms, '/'); |
|
| 417 | + $location_link .= $location_terms; |
|
| 418 | + } else {
|
|
| 419 | + $location_link = geodir_getlink($location_link, $location_terms); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + return $location_link; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -433,34 +433,34 @@ discard block |
||
| 433 | 433 | * @return array|bool Returns address on success. |
| 434 | 434 | */ |
| 435 | 435 | function geodir_get_osm_address_by_lat_lan($lat, $lng) {
|
| 436 | - $url = is_ssl() ? 'https:' : 'http:'; |
|
| 437 | - $url .= '//nominatim.openstreetmap.org/reverse?format=json&lat=' . trim($lat) . '&lon=' . trim($lng) . '&zoom=16&addressdetails=1&email=' . get_option('admin_email');
|
|
| 438 | - |
|
| 439 | - $ch = curl_init(); |
|
| 440 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
| 441 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 442 | - curl_setopt($ch, CURLOPT_PROXYPORT, 3128); |
|
| 443 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 444 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 445 | - $response = curl_exec($ch); |
|
| 446 | - curl_close($ch); |
|
| 447 | - $data = json_decode($response); |
|
| 436 | + $url = is_ssl() ? 'https:' : 'http:'; |
|
| 437 | + $url .= '//nominatim.openstreetmap.org/reverse?format=json&lat=' . trim($lat) . '&lon=' . trim($lng) . '&zoom=16&addressdetails=1&email=' . get_option('admin_email');
|
|
| 438 | + |
|
| 439 | + $ch = curl_init(); |
|
| 440 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 441 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 442 | + curl_setopt($ch, CURLOPT_PROXYPORT, 3128); |
|
| 443 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 444 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 445 | + $response = curl_exec($ch); |
|
| 446 | + curl_close($ch); |
|
| 447 | + $data = json_decode($response); |
|
| 448 | 448 | |
| 449 | - if (!empty($data) && !empty($data->address)) {
|
|
| 450 | - $address_fields = array('public_building', 'house', 'house_number', 'bakery', 'footway', 'street', 'road', 'village', 'attraction', 'pedestrian', 'neighbourhood', 'suburb');
|
|
| 451 | - $formatted_address = (array)$data->address; |
|
| 449 | + if (!empty($data) && !empty($data->address)) {
|
|
| 450 | + $address_fields = array('public_building', 'house', 'house_number', 'bakery', 'footway', 'street', 'road', 'village', 'attraction', 'pedestrian', 'neighbourhood', 'suburb');
|
|
| 451 | + $formatted_address = (array)$data->address; |
|
| 452 | 452 | |
| 453 | - foreach ( $data->address as $key => $value ) {
|
|
| 454 | - if (!in_array($key, $address_fields)) {
|
|
| 455 | - unset($formatted_address[$key]); |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - $data->formatted_address = !empty($formatted_address) ? implode(', ', $formatted_address) : '';
|
|
| 453 | + foreach ( $data->address as $key => $value ) {
|
|
| 454 | + if (!in_array($key, $address_fields)) {
|
|
| 455 | + unset($formatted_address[$key]); |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + $data->formatted_address = !empty($formatted_address) ? implode(', ', $formatted_address) : '';
|
|
| 459 | 459 | |
| 460 | - return $data; |
|
| 461 | - } else {
|
|
| 462 | - return false; |
|
| 463 | - } |
|
| 460 | + return $data; |
|
| 461 | + } else {
|
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -472,47 +472,47 @@ discard block |
||
| 472 | 472 | * @return string Returns the country. |
| 473 | 473 | */ |
| 474 | 474 | function geodir_get_normal_country($country) {
|
| 475 | - global $wpdb; |
|
| 476 | - if ($result = geodir_get_country_by_name($country)) {
|
|
| 477 | - return $result; |
|
| 478 | - } |
|
| 475 | + global $wpdb; |
|
| 476 | + if ($result = geodir_get_country_by_name($country)) {
|
|
| 477 | + return $result; |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - if (defined('POST_LOCATION_TABLE')) {
|
|
| 481 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT country FROM " . POST_LOCATION_TABLE . " WHERE country NOT LIKE %s ORDER BY location_id ASC", $country));
|
|
| 482 | - if (!empty($rows)) {
|
|
| 483 | - foreach ($rows as $row) {
|
|
| 484 | - $translated = __($row->country, 'geodirectory'); |
|
| 485 | - if (geodir_strtolower($translated) == geodir_strtolower($country) && $result = geodir_get_country_by_name($row->country)) {
|
|
| 486 | - return $result; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - } |
|
| 480 | + if (defined('POST_LOCATION_TABLE')) {
|
|
| 481 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT country FROM " . POST_LOCATION_TABLE . " WHERE country NOT LIKE %s ORDER BY location_id ASC", $country));
|
|
| 482 | + if (!empty($rows)) {
|
|
| 483 | + foreach ($rows as $row) {
|
|
| 484 | + $translated = __($row->country, 'geodirectory'); |
|
| 485 | + if (geodir_strtolower($translated) == geodir_strtolower($country) && $result = geodir_get_country_by_name($row->country)) {
|
|
| 486 | + return $result; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | 490 | |
| 491 | - $rows = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT country FROM " . POST_LOCATION_TABLE . " WHERE country_slug LIKE %s AND country NOT LIKE %s ORDER BY location_id", $country, $country ) ); |
|
| 492 | - if (!empty($rows)) {
|
|
| 493 | - foreach ($rows as $row) {
|
|
| 494 | - $translated = __($row->country, 'geodirectory'); |
|
| 495 | - if (geodir_strtolower($translated) == geodir_strtolower($country) && $result = geodir_get_country_by_name($row->country)) {
|
|
| 496 | - return $result; |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - } |
|
| 491 | + $rows = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT country FROM " . POST_LOCATION_TABLE . " WHERE country_slug LIKE %s AND country NOT LIKE %s ORDER BY location_id", $country, $country ) ); |
|
| 492 | + if (!empty($rows)) {
|
|
| 493 | + foreach ($rows as $row) {
|
|
| 494 | + $translated = __($row->country, 'geodirectory'); |
|
| 495 | + if (geodir_strtolower($translated) == geodir_strtolower($country) && $result = geodir_get_country_by_name($row->country)) {
|
|
| 496 | + return $result; |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | 501 | |
| 502 | - $default_location = geodir_get_default_location(); |
|
| 503 | - if (!empty($default_location->country) && $result = geodir_get_country_by_name($default_location->country)) {
|
|
| 504 | - return $result; |
|
| 505 | - } |
|
| 502 | + $default_location = geodir_get_default_location(); |
|
| 503 | + if (!empty($default_location->country) && $result = geodir_get_country_by_name($default_location->country)) {
|
|
| 504 | + return $result; |
|
| 505 | + } |
|
| 506 | 506 | |
| 507 | - if (!empty($default_location->country_slug) && $result = geodir_get_country_by_name($default_location->country_slug)) {
|
|
| 508 | - return $result; |
|
| 509 | - } |
|
| 507 | + if (!empty($default_location->country_slug) && $result = geodir_get_country_by_name($default_location->country_slug)) {
|
|
| 508 | + return $result; |
|
| 509 | + } |
|
| 510 | 510 | |
| 511 | - if (!empty($default_location->country_ISO2) && $result = geodir_get_country_by_name($default_location->country_ISO2, true)) {
|
|
| 512 | - return $result; |
|
| 513 | - } |
|
| 511 | + if (!empty($default_location->country_ISO2) && $result = geodir_get_country_by_name($default_location->country_ISO2, true)) {
|
|
| 512 | + return $result; |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - return $country; |
|
| 515 | + return $country; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -524,16 +524,16 @@ discard block |
||
| 524 | 524 | * @return string Country ISO2 code. |
| 525 | 525 | */ |
| 526 | 526 | function geodir_get_country_iso2($country) {
|
| 527 | - global $wpdb; |
|
| 527 | + global $wpdb; |
|
| 528 | 528 | |
| 529 | - if ($result = $wpdb->get_var($wpdb->prepare("SELECT ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country LIKE %s", $country))) {
|
|
| 530 | - return $result; |
|
| 531 | - } |
|
| 532 | - if ($result = $wpdb->get_var($wpdb->prepare("SELECT ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country LIKE %s", geodir_get_normal_country($country)))) {
|
|
| 533 | - return $result; |
|
| 534 | - } |
|
| 529 | + if ($result = $wpdb->get_var($wpdb->prepare("SELECT ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country LIKE %s", $country))) {
|
|
| 530 | + return $result; |
|
| 531 | + } |
|
| 532 | + if ($result = $wpdb->get_var($wpdb->prepare("SELECT ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country LIKE %s", geodir_get_normal_country($country)))) {
|
|
| 533 | + return $result; |
|
| 534 | + } |
|
| 535 | 535 | |
| 536 | - return $country; |
|
| 536 | + return $country; |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | /** |
@@ -546,14 +546,14 @@ discard block |
||
| 546 | 546 | * @return string|null Country ISO2 code. |
| 547 | 547 | */ |
| 548 | 548 | function geodir_get_country_by_name($country, $iso2 = false) {
|
| 549 | - global $wpdb; |
|
| 549 | + global $wpdb; |
|
| 550 | 550 | |
| 551 | - if ($result = $wpdb->get_var($wpdb->prepare("SELECT Country FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country LIKE %s", $country))) {
|
|
| 552 | - return $result; |
|
| 553 | - } |
|
| 554 | - if ($iso2 && $result = $wpdb->get_var($wpdb->prepare("SELECT Country FROM " . GEODIR_COUNTRIES_TABLE . " WHERE ISO2 LIKE %s", $country))) {
|
|
| 555 | - return $result; |
|
| 556 | - } |
|
| 551 | + if ($result = $wpdb->get_var($wpdb->prepare("SELECT Country FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country LIKE %s", $country))) {
|
|
| 552 | + return $result; |
|
| 553 | + } |
|
| 554 | + if ($iso2 && $result = $wpdb->get_var($wpdb->prepare("SELECT Country FROM " . GEODIR_COUNTRIES_TABLE . " WHERE ISO2 LIKE %s", $country))) {
|
|
| 555 | + return $result; |
|
| 556 | + } |
|
| 557 | 557 | |
| 558 | - return NULL; |
|
| 558 | + return NULL; |
|
| 559 | 559 | } |
| 560 | 560 | \ No newline at end of file |