@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | */ |
17 | 17 | function geodir_session_start() |
18 | 18 | { |
19 | - if (!session_id()) session_start(); |
|
20 | - global $geodir_add_location_url; |
|
19 | + if (!session_id()) session_start(); |
|
20 | + global $geodir_add_location_url; |
|
21 | 21 | |
22 | - $geodir_add_location_url = NULL; |
|
22 | + $geodir_add_location_url = NULL; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,18 +33,18 @@ discard block |
||
33 | 33 | */ |
34 | 34 | function geodir_modified_query($query) |
35 | 35 | { |
36 | - if ($query->is_main_query() && ( |
|
37 | - (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') |
|
38 | - || geodir_is_page('listing') |
|
39 | - || geodir_is_page('author') |
|
40 | - || geodir_is_page('search') |
|
41 | - || geodir_is_page('detail')) |
|
42 | - ) { |
|
43 | - |
|
44 | - $query->set('is_geodir_loop', true); |
|
45 | - } |
|
36 | + if ($query->is_main_query() && ( |
|
37 | + (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') |
|
38 | + || geodir_is_page('listing') |
|
39 | + || geodir_is_page('author') |
|
40 | + || geodir_is_page('search') |
|
41 | + || geodir_is_page('detail')) |
|
42 | + ) { |
|
43 | + |
|
44 | + $query->set('is_geodir_loop', true); |
|
45 | + } |
|
46 | 46 | |
47 | - return $query; |
|
47 | + return $query; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -67,81 +67,81 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function set_listing_request($query ) |
69 | 69 | { |
70 | - global $wp_query, $wpdb, $geodir_post_type, $table, $dist, $mylat, $mylon, $s, $snear, $s, $s_A, $s_SA; |
|
70 | + global $wp_query, $wpdb, $geodir_post_type, $table, $dist, $mylat, $mylon, $s, $snear, $s, $s_A, $s_SA; |
|
71 | 71 | |
72 | 72 | |
73 | - // fix woocommerce shop products filtered by language for GD + WPML + Woocommerce |
|
74 | - if (!geodir_is_geodir_page()) { |
|
75 | - return; |
|
76 | - } |
|
73 | + // fix woocommerce shop products filtered by language for GD + WPML + Woocommerce |
|
74 | + if (!geodir_is_geodir_page()) { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - /* remove all pre filters */ |
|
79 | - remove_all_filters('query'); |
|
80 | - remove_all_filters('posts_search'); |
|
81 | - remove_all_filters('posts_fields'); |
|
82 | - remove_all_filters('posts_join'); |
|
83 | - remove_all_filters('posts_orderby'); |
|
84 | - remove_all_filters('posts_where'); |
|
78 | + /* remove all pre filters */ |
|
79 | + remove_all_filters('query'); |
|
80 | + remove_all_filters('posts_search'); |
|
81 | + remove_all_filters('posts_fields'); |
|
82 | + remove_all_filters('posts_join'); |
|
83 | + remove_all_filters('posts_orderby'); |
|
84 | + remove_all_filters('posts_where'); |
|
85 | 85 | |
86 | 86 | |
87 | - if ((is_search() && isset($_REQUEST['geodir_search']) && $_REQUEST['geodir_search'] != '')): |
|
87 | + if ((is_search() && isset($_REQUEST['geodir_search']) && $_REQUEST['geodir_search'] != '')): |
|
88 | 88 | |
89 | - if (isset($_REQUEST['scat']) && $_REQUEST['scat'] == 'all') $_REQUEST['scat'] = ''; |
|
90 | - //if(isset($_REQUEST['s']) && $_REQUEST['s'] == '+') $_REQUEST['s'] = ''; |
|
89 | + if (isset($_REQUEST['scat']) && $_REQUEST['scat'] == 'all') $_REQUEST['scat'] = ''; |
|
90 | + //if(isset($_REQUEST['s']) && $_REQUEST['s'] == '+') $_REQUEST['s'] = ''; |
|
91 | 91 | |
92 | - if (isset($_REQUEST['sdist'])) { |
|
93 | - ($_REQUEST['sdist'] != '0' && $_REQUEST['sdist'] != '') ? $dist = esc_attr($_REQUEST['sdist']) : $dist = 25000; |
|
94 | - } elseif (get_option('geodir_search_dist') != '') { |
|
95 | - $dist = get_option('geodir_search_dist'); |
|
92 | + if (isset($_REQUEST['sdist'])) { |
|
93 | + ($_REQUEST['sdist'] != '0' && $_REQUEST['sdist'] != '') ? $dist = esc_attr($_REQUEST['sdist']) : $dist = 25000; |
|
94 | + } elseif (get_option('geodir_search_dist') != '') { |
|
95 | + $dist = get_option('geodir_search_dist'); |
|
96 | 96 | |
97 | - } else { |
|
98 | - $dist = 25000; |
|
99 | - } // Distance |
|
97 | + } else { |
|
98 | + $dist = 25000; |
|
99 | + } // Distance |
|
100 | 100 | |
101 | - if (isset($_REQUEST['sgeo_lat'])) { |
|
102 | - $mylat = (float)esc_attr($_REQUEST['sgeo_lat']); |
|
103 | - } else { |
|
104 | - $mylat = (float)geodir_get_current_city_lat(); |
|
105 | - } // Latitude |
|
101 | + if (isset($_REQUEST['sgeo_lat'])) { |
|
102 | + $mylat = (float)esc_attr($_REQUEST['sgeo_lat']); |
|
103 | + } else { |
|
104 | + $mylat = (float)geodir_get_current_city_lat(); |
|
105 | + } // Latitude |
|
106 | 106 | |
107 | - if (isset($_REQUEST['sgeo_lon'])) { |
|
108 | - $mylon = (float)esc_attr($_REQUEST['sgeo_lon']); |
|
109 | - } else { |
|
110 | - $mylon = (float)geodir_get_current_city_lng(); |
|
111 | - } // Distance |
|
107 | + if (isset($_REQUEST['sgeo_lon'])) { |
|
108 | + $mylon = (float)esc_attr($_REQUEST['sgeo_lon']); |
|
109 | + } else { |
|
110 | + $mylon = (float)geodir_get_current_city_lng(); |
|
111 | + } // Distance |
|
112 | 112 | |
113 | - if (isset($_REQUEST['snear'])) { |
|
114 | - $snear = trim(esc_attr($_REQUEST['snear'])); |
|
115 | - } |
|
113 | + if (isset($_REQUEST['snear'])) { |
|
114 | + $snear = trim(esc_attr($_REQUEST['snear'])); |
|
115 | + } |
|
116 | 116 | |
117 | - if (isset($_REQUEST['s'])) { |
|
118 | - $s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s']))); |
|
119 | - } |
|
117 | + if (isset($_REQUEST['s'])) { |
|
118 | + $s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s']))); |
|
119 | + } |
|
120 | 120 | |
121 | - if ($snear == 'NEAR ME') { |
|
122 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
123 | - $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip)); |
|
124 | - $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude])); |
|
125 | - $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude])); |
|
126 | - } |
|
121 | + if ($snear == 'NEAR ME') { |
|
122 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
123 | + $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip)); |
|
124 | + $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude])); |
|
125 | + $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude])); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | - if (strstr($s, ',')) { |
|
130 | - $s_AA = str_replace(" ", "", $s); |
|
131 | - $s_A = explode(",", $s_AA); |
|
132 | - $s_A = implode('","', $s_A); |
|
133 | - $s_A = '"' . $s_A . '"'; |
|
134 | - } else { |
|
135 | - $s_A = '"' . $s . '"'; |
|
136 | - } |
|
129 | + if (strstr($s, ',')) { |
|
130 | + $s_AA = str_replace(" ", "", $s); |
|
131 | + $s_A = explode(",", $s_AA); |
|
132 | + $s_A = implode('","', $s_A); |
|
133 | + $s_A = '"' . $s_A . '"'; |
|
134 | + } else { |
|
135 | + $s_A = '"' . $s . '"'; |
|
136 | + } |
|
137 | 137 | |
138 | - if (strstr($s, ' ')) { |
|
139 | - $s_SA = explode(" ", $s); |
|
140 | - } else { |
|
141 | - $s_SA = ''; |
|
142 | - } |
|
138 | + if (strstr($s, ' ')) { |
|
139 | + $s_SA = explode(" ", $s); |
|
140 | + } else { |
|
141 | + $s_SA = ''; |
|
142 | + } |
|
143 | 143 | |
144 | - endif; |
|
144 | + endif; |
|
145 | 145 | |
146 | 146 | |
147 | 147 | |
@@ -162,56 +162,56 @@ discard block |
||
162 | 162 | */ |
163 | 163 | function geodir_listing_loop_filter($query) |
164 | 164 | { |
165 | - global $wp_query, $geodir_post_type, $table, $plugin_prefix, $table, $term; |
|
165 | + global $wp_query, $geodir_post_type, $table, $plugin_prefix, $table, $term; |
|
166 | 166 | |
167 | - // fix wp_reset_query for popular post view widget |
|
168 | - if (!geodir_is_geodir_page()) { |
|
169 | - return; |
|
170 | - } |
|
167 | + // fix wp_reset_query for popular post view widget |
|
168 | + if (!geodir_is_geodir_page()) { |
|
169 | + return; |
|
170 | + } |
|
171 | 171 | |
172 | - $geodir_post_type = geodir_get_current_posttype(); |
|
173 | - |
|
174 | - if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) { |
|
175 | - $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
176 | - |
|
177 | - if (isset($wp_query->query[$taxonomies[0]])) { |
|
178 | - $request_term = explode("/", $wp_query->query[$taxonomies[0]]); |
|
179 | - $request_term = end($request_term); |
|
180 | - if (!term_exists($request_term)) { |
|
181 | - $args = array('number' => '1',); |
|
182 | - $terms_arr = get_terms($taxonomies[0], $args); |
|
183 | - foreach ($terms_arr as $location_term) { |
|
184 | - $term_arr = $location_term; |
|
185 | - $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term)); |
|
186 | - } |
|
187 | - $wp_query->queried_object_id = 1; |
|
188 | - $wp_query->queried_object = $term_arr; |
|
189 | - //print_r($wp_query) ; |
|
190 | - } |
|
191 | - } |
|
172 | + $geodir_post_type = geodir_get_current_posttype(); |
|
173 | + |
|
174 | + if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) { |
|
175 | + $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
176 | + |
|
177 | + if (isset($wp_query->query[$taxonomies[0]])) { |
|
178 | + $request_term = explode("/", $wp_query->query[$taxonomies[0]]); |
|
179 | + $request_term = end($request_term); |
|
180 | + if (!term_exists($request_term)) { |
|
181 | + $args = array('number' => '1',); |
|
182 | + $terms_arr = get_terms($taxonomies[0], $args); |
|
183 | + foreach ($terms_arr as $location_term) { |
|
184 | + $term_arr = $location_term; |
|
185 | + $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term)); |
|
186 | + } |
|
187 | + $wp_query->queried_object_id = 1; |
|
188 | + $wp_query->queried_object = $term_arr; |
|
189 | + //print_r($wp_query) ; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - } |
|
194 | - if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) { |
|
195 | - |
|
196 | - $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
197 | - |
|
198 | - add_filter('posts_fields', 'geodir_posts_fields', 1); |
|
199 | - add_filter('posts_join', 'geodir_posts_join', 1); |
|
200 | - geodir_post_where(); |
|
201 | - if (!is_admin()) |
|
202 | - add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
203 | - |
|
204 | - // advanced filter for popular post view widget |
|
205 | - global $wp_query; |
|
206 | - if (!is_admin()) { |
|
207 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
208 | - add_filter('posts_join', 'geodir_filter_widget_join', 1000); |
|
209 | - } |
|
210 | - add_filter('posts_where', 'geodir_filter_widget_where', 1000); |
|
211 | - } |
|
193 | + } |
|
194 | + if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) { |
|
212 | 195 | |
213 | - } |
|
214 | - return $query; |
|
196 | + $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
197 | + |
|
198 | + add_filter('posts_fields', 'geodir_posts_fields', 1); |
|
199 | + add_filter('posts_join', 'geodir_posts_join', 1); |
|
200 | + geodir_post_where(); |
|
201 | + if (!is_admin()) |
|
202 | + add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
203 | + |
|
204 | + // advanced filter for popular post view widget |
|
205 | + global $wp_query; |
|
206 | + if (!is_admin()) { |
|
207 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
208 | + add_filter('posts_join', 'geodir_filter_widget_join', 1000); |
|
209 | + } |
|
210 | + add_filter('posts_where', 'geodir_filter_widget_where', 1000); |
|
211 | + } |
|
212 | + |
|
213 | + } |
|
214 | + return $query; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | |
@@ -230,67 +230,67 @@ discard block |
||
230 | 230 | * @return string Modified fields query string. |
231 | 231 | */ |
232 | 232 | function geodir_posts_fields($fields) { |
233 | - global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; |
|
233 | + global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; |
|
234 | 234 | |
235 | - // Filter-Location-Manager to add location table. |
|
236 | - $fields .= ", " . $table . ".* "; |
|
235 | + // Filter-Location-Manager to add location table. |
|
236 | + $fields .= ", " . $table . ".* "; |
|
237 | 237 | |
238 | 238 | if ($snear != '' || $gd_session->get('all_near_me')) { |
239 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
239 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
240 | 240 | |
241 | 241 | if ($gd_session->get('all_near_me')) { |
242 | - $mylat = $gd_session->get('user_lat'); |
|
243 | - $mylon = $gd_session->get('user_lon'); |
|
244 | - } |
|
245 | - |
|
246 | - $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; |
|
247 | - } |
|
248 | - |
|
249 | - global $s; |
|
250 | - if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
251 | - $keywords = explode(" ", $s); |
|
252 | - |
|
253 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
254 | - foreach($keywords as $kkey=>$kword){ |
|
255 | - if(geodir_utf8_strlen($kword)<=$klimit){ |
|
256 | - unset($keywords[$kkey]); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
242 | + $mylat = $gd_session->get('user_lat'); |
|
243 | + $mylon = $gd_session->get('user_lon'); |
|
244 | + } |
|
260 | 245 | |
246 | + $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; |
|
247 | + } |
|
261 | 248 | |
262 | - if (count($keywords) > 1) { |
|
263 | - $parts = array( |
|
264 | - 'AND' => 'gd_alltitlematch_part', |
|
265 | - 'OR' => 'gd_titlematch_part' |
|
266 | - ); |
|
267 | - $gd_titlematch_part = ""; |
|
268 | - foreach ($parts as $key => $part) { |
|
269 | - $gd_titlematch_part .= " CASE WHEN "; |
|
270 | - $count = 0; |
|
271 | - foreach ($keywords as $keyword) { |
|
272 | - $keyword = trim($keyword); |
|
273 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
249 | + global $s; |
|
250 | + if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
251 | + $keywords = explode(" ", $s); |
|
252 | + |
|
253 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
254 | + foreach($keywords as $kkey=>$kword){ |
|
255 | + if(geodir_utf8_strlen($kword)<=$klimit){ |
|
256 | + unset($keywords[$kkey]); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + if (count($keywords) > 1) { |
|
263 | + $parts = array( |
|
264 | + 'AND' => 'gd_alltitlematch_part', |
|
265 | + 'OR' => 'gd_titlematch_part' |
|
266 | + ); |
|
267 | + $gd_titlematch_part = ""; |
|
268 | + foreach ($parts as $key => $part) { |
|
269 | + $gd_titlematch_part .= " CASE WHEN "; |
|
270 | + $count = 0; |
|
271 | + foreach ($keywords as $keyword) { |
|
272 | + $keyword = trim($keyword); |
|
273 | + $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
274 | 274 | $count++; |
275 | - if ($count < count($keywords)) { |
|
276 | - // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; |
|
275 | + if ($count < count($keywords)) { |
|
276 | + // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; |
|
277 | 277 | $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) " . $key . " "; |
278 | - } else { |
|
279 | - //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; |
|
278 | + } else { |
|
279 | + //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; |
|
280 | 280 | $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) "; |
281 | - } |
|
282 | - } |
|
283 | - $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; |
|
284 | - } |
|
285 | - } else { |
|
286 | - $gd_titlematch_part = ""; |
|
287 | - } |
|
288 | - $s = stripslashes_deep( $s ); |
|
289 | - $s = wp_specialchars_decode($s,ENT_QUOTES); |
|
281 | + } |
|
282 | + } |
|
283 | + $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; |
|
284 | + } |
|
285 | + } else { |
|
286 | + $gd_titlematch_part = ""; |
|
287 | + } |
|
288 | + $s = stripslashes_deep( $s ); |
|
289 | + $s = wp_specialchars_decode($s,ENT_QUOTES); |
|
290 | 290 | $fields .= $wpdb->prepare(", CASE WHEN " . $table . ".is_featured='1' THEN 1 ELSE 0 END AS gd_featured, CASE WHEN " . $wpdb->posts . ".post_title LIKE %s THEN 1 ELSE 0 END AS gd_exacttitle," . $gd_titlematch_part . " CASE WHEN ( " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s ) THEN 1 ELSE 0 END AS gd_titlematch, CASE WHEN ( " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s ) THEN 1 ELSE 0 END AS gd_content", array($s, $s, $s . '%', '% ' . $s . '%', $s, $s . ' %', '% ' . $s . ' %', '% ' . $s)); |
291 | - } |
|
291 | + } |
|
292 | 292 | |
293 | - return $fields; |
|
293 | + return $fields; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | |
@@ -307,26 +307,26 @@ discard block |
||
307 | 307 | */ |
308 | 308 | function geodir_posts_join($join) |
309 | 309 | { |
310 | - global $wpdb, $geodir_post_type, $table, $table_prefix, $plugin_prefix; |
|
310 | + global $wpdb, $geodir_post_type, $table, $table_prefix, $plugin_prefix; |
|
311 | 311 | |
312 | - ########### WPML ########### |
|
312 | + ########### WPML ########### |
|
313 | 313 | |
314 | - if ( geodir_wpml_is_post_type_translated( $geodir_post_type ) ) { |
|
315 | - global $sitepress; |
|
316 | - $lang_code = ICL_LANGUAGE_CODE; |
|
317 | - $default_lang_code = $sitepress->get_default_language(); |
|
318 | - if ($lang_code) { |
|
319 | - $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID"; |
|
320 | - } |
|
314 | + if ( geodir_wpml_is_post_type_translated( $geodir_post_type ) ) { |
|
315 | + global $sitepress; |
|
316 | + $lang_code = ICL_LANGUAGE_CODE; |
|
317 | + $default_lang_code = $sitepress->get_default_language(); |
|
318 | + if ($lang_code) { |
|
319 | + $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID"; |
|
320 | + } |
|
321 | 321 | |
322 | - } |
|
323 | - ########### WPML ########### |
|
322 | + } |
|
323 | + ########### WPML ########### |
|
324 | 324 | |
325 | - $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID) "; |
|
326 | - //===old code start |
|
327 | - //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id) " ;//===old code end |
|
325 | + $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID) "; |
|
326 | + //===old code start |
|
327 | + //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id) " ;//===old code end |
|
328 | 328 | |
329 | - return $join; |
|
329 | + return $join; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | |
@@ -344,15 +344,15 @@ discard block |
||
344 | 344 | */ |
345 | 345 | function geodir_posts_orderby($orderby) |
346 | 346 | { |
347 | - global $wpdb, $wp_query, $geodir_post_type, $table, $plugin_prefix, $snear, $default_sort; |
|
347 | + global $wpdb, $wp_query, $geodir_post_type, $table, $plugin_prefix, $snear, $default_sort; |
|
348 | 348 | |
349 | - $sort_by = ''; |
|
350 | - $orderby = ' '; |
|
349 | + $sort_by = ''; |
|
350 | + $orderby = ' '; |
|
351 | 351 | |
352 | - if (get_query_var('order_by')) |
|
353 | - $sort_by = get_query_var('order_by'); |
|
352 | + if (get_query_var('order_by')) |
|
353 | + $sort_by = get_query_var('order_by'); |
|
354 | 354 | |
355 | - /*if(isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries){ |
|
355 | + /*if(isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries){ |
|
356 | 356 | $current_term = $wp_query->get_queried_object(); |
357 | 357 | } |
358 | 358 | |
@@ -366,133 +366,133 @@ discard block |
||
366 | 366 | }*/ |
367 | 367 | |
368 | 368 | |
369 | - if ($snear != '') { |
|
370 | - $orderby .= " distance,"; |
|
371 | - } |
|
369 | + if ($snear != '') { |
|
370 | + $orderby .= " distance,"; |
|
371 | + } |
|
372 | 372 | |
373 | - if (isset($_REQUEST['sort_by']) && $_REQUEST['sort_by'] != '' && is_main_query()) |
|
374 | - $sort_by = esc_attr($_REQUEST['sort_by']); |
|
373 | + if (isset($_REQUEST['sort_by']) && $_REQUEST['sort_by'] != '' && is_main_query()) |
|
374 | + $sort_by = esc_attr($_REQUEST['sort_by']); |
|
375 | 375 | |
376 | 376 | |
377 | - if ($sort_by == '') { |
|
378 | - $default_sort = geodir_get_posts_default_sort($geodir_post_type); |
|
379 | - if (!empty($default_sort)) |
|
380 | - $sort_by = $default_sort; |
|
381 | - } |
|
377 | + if ($sort_by == '') { |
|
378 | + $default_sort = geodir_get_posts_default_sort($geodir_post_type); |
|
379 | + if (!empty($default_sort)) |
|
380 | + $sort_by = $default_sort; |
|
381 | + } |
|
382 | 382 | |
383 | - /* |
|
383 | + /* |
|
384 | 384 | if search by term & no location then order always "relevance" |
385 | 385 | if search by location then order always "nearest" |
386 | 386 | */ |
387 | - if (is_main_query() && geodir_is_page('search')) { |
|
388 | - $search_term = get_query_var('s'); |
|
389 | - |
|
390 | - if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) { |
|
391 | - $sort_by = 'az'; |
|
392 | - } |
|
387 | + if (is_main_query() && geodir_is_page('search')) { |
|
388 | + $search_term = get_query_var('s'); |
|
393 | 389 | |
394 | - if ($snear != '' && $sort_by!='farthest') { |
|
395 | - $sort_by = 'nearest'; |
|
396 | - } |
|
397 | - } |
|
390 | + if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) { |
|
391 | + $sort_by = 'az'; |
|
392 | + } |
|
398 | 393 | |
399 | - switch ($sort_by): |
|
400 | - case 'newest': |
|
401 | - $orderby = "$wpdb->posts.post_date desc, "; |
|
402 | - break; |
|
403 | - case 'oldest': |
|
404 | - $orderby = "$wpdb->posts.post_date asc, "; |
|
405 | - break; |
|
406 | - case 'low_review': |
|
407 | - case 'rating_count_asc': |
|
408 | - $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, "; |
|
409 | - break; |
|
410 | - case 'high_review': |
|
411 | - case 'rating_count_desc': |
|
412 | - $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, "; |
|
413 | - break; |
|
414 | - case 'low_rating': |
|
415 | - $orderby = "( " . $table . ".overall_rating ) ASC, " . $table . ".rating_count ASC, "; |
|
416 | - break; |
|
417 | - case 'high_rating': |
|
418 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
419 | - break; |
|
420 | - case 'featured': |
|
421 | - $orderby = $table . ".is_featured asc, "; |
|
422 | - break; |
|
423 | - case 'nearest': |
|
424 | - $orderby = " distance asc, "; |
|
425 | - break; |
|
426 | - case 'farthest': |
|
427 | - $orderby = " distance desc, "; |
|
428 | - break; |
|
429 | - case 'random': |
|
430 | - $orderby = " rand(), "; |
|
431 | - break; |
|
432 | - case 'az': |
|
433 | - $orderby = "$wpdb->posts.post_title asc, "; |
|
434 | - break; |
|
435 | - // sort by rating |
|
436 | - case 'overall_rating_desc': |
|
437 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
438 | - break; |
|
439 | - case 'overall_rating_asc': |
|
440 | - $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, "; |
|
441 | - break; |
|
442 | - default: |
|
443 | - |
|
444 | - break; |
|
445 | - endswitch; |
|
446 | - |
|
447 | - if ($sort_by != '' && geodir_cpt_has_rating_disabled($geodir_post_type)) { |
|
448 | - if (in_array($sort_by, array('high_review', 'rating_count_desc', 'high_rating', 'overall_rating_desc'))) { |
|
449 | - $orderby = "$wpdb->posts.comment_count DESC, "; |
|
450 | - $sort_by = 'comment_count_desc'; |
|
451 | - } else if (in_array($sort_by, array('low_review', 'rating_count_asc', 'low_rating', 'overall_rating_asc'))) { |
|
452 | - $orderby = "$wpdb->posts.comment_count ASC, "; |
|
453 | - $sort_by = 'comment_count_asc'; |
|
454 | - } |
|
455 | - } |
|
394 | + if ($snear != '' && $sort_by!='farthest') { |
|
395 | + $sort_by = 'nearest'; |
|
396 | + } |
|
397 | + } |
|
456 | 398 | |
457 | - global $s; |
|
399 | + switch ($sort_by): |
|
400 | + case 'newest': |
|
401 | + $orderby = "$wpdb->posts.post_date desc, "; |
|
402 | + break; |
|
403 | + case 'oldest': |
|
404 | + $orderby = "$wpdb->posts.post_date asc, "; |
|
405 | + break; |
|
406 | + case 'low_review': |
|
407 | + case 'rating_count_asc': |
|
408 | + $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, "; |
|
409 | + break; |
|
410 | + case 'high_review': |
|
411 | + case 'rating_count_desc': |
|
412 | + $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, "; |
|
413 | + break; |
|
414 | + case 'low_rating': |
|
415 | + $orderby = "( " . $table . ".overall_rating ) ASC, " . $table . ".rating_count ASC, "; |
|
416 | + break; |
|
417 | + case 'high_rating': |
|
418 | + $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
419 | + break; |
|
420 | + case 'featured': |
|
421 | + $orderby = $table . ".is_featured asc, "; |
|
422 | + break; |
|
423 | + case 'nearest': |
|
424 | + $orderby = " distance asc, "; |
|
425 | + break; |
|
426 | + case 'farthest': |
|
427 | + $orderby = " distance desc, "; |
|
428 | + break; |
|
429 | + case 'random': |
|
430 | + $orderby = " rand(), "; |
|
431 | + break; |
|
432 | + case 'az': |
|
433 | + $orderby = "$wpdb->posts.post_title asc, "; |
|
434 | + break; |
|
435 | + // sort by rating |
|
436 | + case 'overall_rating_desc': |
|
437 | + $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
438 | + break; |
|
439 | + case 'overall_rating_asc': |
|
440 | + $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, "; |
|
441 | + break; |
|
442 | + default: |
|
443 | + |
|
444 | + break; |
|
445 | + endswitch; |
|
446 | + |
|
447 | + if ($sort_by != '' && geodir_cpt_has_rating_disabled($geodir_post_type)) { |
|
448 | + if (in_array($sort_by, array('high_review', 'rating_count_desc', 'high_rating', 'overall_rating_desc'))) { |
|
449 | + $orderby = "$wpdb->posts.comment_count DESC, "; |
|
450 | + $sort_by = 'comment_count_desc'; |
|
451 | + } else if (in_array($sort_by, array('low_review', 'rating_count_asc', 'low_rating', 'overall_rating_asc'))) { |
|
452 | + $orderby = "$wpdb->posts.comment_count ASC, "; |
|
453 | + $sort_by = 'comment_count_asc'; |
|
454 | + } |
|
455 | + } |
|
458 | 456 | |
459 | - if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
460 | - $keywords = explode(" ", $s); |
|
461 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
462 | - foreach($keywords as $kkey=>$kword){ |
|
463 | - if(geodir_utf8_strlen($kword)<=$klimit){ |
|
464 | - unset($keywords[$kkey]); |
|
465 | - } |
|
466 | - } |
|
467 | - } |
|
468 | - if ($sort_by == 'nearest' || $sort_by == 'farthest') { |
|
469 | - if (count($keywords) > 1) { |
|
470 | - $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, "; |
|
471 | - } else { |
|
472 | - $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
473 | - } |
|
474 | - } else { |
|
475 | - if (count($keywords) > 1) { |
|
476 | - $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, " . $orderby; |
|
477 | - } else { |
|
478 | - $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby; |
|
479 | - } |
|
480 | - } |
|
481 | - } |
|
457 | + global $s; |
|
458 | + |
|
459 | + if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
460 | + $keywords = explode(" ", $s); |
|
461 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
462 | + foreach($keywords as $kkey=>$kword){ |
|
463 | + if(geodir_utf8_strlen($kword)<=$klimit){ |
|
464 | + unset($keywords[$kkey]); |
|
465 | + } |
|
466 | + } |
|
467 | + } |
|
468 | + if ($sort_by == 'nearest' || $sort_by == 'farthest') { |
|
469 | + if (count($keywords) > 1) { |
|
470 | + $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, "; |
|
471 | + } else { |
|
472 | + $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
473 | + } |
|
474 | + } else { |
|
475 | + if (count($keywords) > 1) { |
|
476 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, " . $orderby; |
|
477 | + } else { |
|
478 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby; |
|
479 | + } |
|
480 | + } |
|
481 | + } |
|
482 | 482 | |
483 | - /** |
|
484 | - * Filter order by SQL. |
|
485 | - * |
|
486 | - * @since 1.0.0 |
|
487 | - * @param string $orderby The orderby query string. |
|
488 | - * @param string $sort_by Sortby query string. |
|
489 | - * @param string $table Listing table name. |
|
490 | - */ |
|
491 | - $orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table); |
|
483 | + /** |
|
484 | + * Filter order by SQL. |
|
485 | + * |
|
486 | + * @since 1.0.0 |
|
487 | + * @param string $orderby The orderby query string. |
|
488 | + * @param string $sort_by Sortby query string. |
|
489 | + * @param string $table Listing table name. |
|
490 | + */ |
|
491 | + $orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table); |
|
492 | 492 | |
493 | - $orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title "; |
|
493 | + $orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title "; |
|
494 | 494 | |
495 | - return $orderby; |
|
495 | + return $orderby; |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | |
@@ -510,53 +510,53 @@ discard block |
||
510 | 510 | function geodir_posts_order_by_custom_sort($orderby, $sort_by, $table) |
511 | 511 | { |
512 | 512 | |
513 | - global $wpdb; |
|
513 | + global $wpdb; |
|
514 | 514 | |
515 | - if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' || $_REQUEST['s']==' ') ) )) { |
|
515 | + if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' || $_REQUEST['s']==' ') ) )) { |
|
516 | 516 | |
517 | - $sort_array = explode('_', $sort_by); |
|
517 | + $sort_array = explode('_', $sort_by); |
|
518 | 518 | |
519 | - $sort_by_count = count($sort_array); |
|
519 | + $sort_by_count = count($sort_array); |
|
520 | 520 | |
521 | - $order = $sort_array[$sort_by_count - 1]; |
|
521 | + $order = $sort_array[$sort_by_count - 1]; |
|
522 | 522 | |
523 | - if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) { |
|
523 | + if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) { |
|
524 | 524 | |
525 | - $sort_by = str_replace('_' . $order, '', $sort_by); |
|
525 | + $sort_by = str_replace('_' . $order, '', $sort_by); |
|
526 | 526 | |
527 | - switch ($sort_by): |
|
527 | + switch ($sort_by): |
|
528 | 528 | |
529 | - case 'post_date': |
|
530 | - case 'comment_count': |
|
529 | + case 'post_date': |
|
530 | + case 'comment_count': |
|
531 | 531 | |
532 | - $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", "; |
|
533 | - break; |
|
532 | + $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", "; |
|
533 | + break; |
|
534 | 534 | |
535 | - case 'distance': |
|
536 | - $orderby = $sort_by . " " . $order . ", "; |
|
537 | - break; |
|
535 | + case 'distance': |
|
536 | + $orderby = $sort_by . " " . $order . ", "; |
|
537 | + break; |
|
538 | 538 | |
539 | 539 | |
540 | - // sort by rating |
|
541 | - case 'overall_rating': |
|
542 | - $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
540 | + // sort by rating |
|
541 | + case 'overall_rating': |
|
542 | + $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
543 | 543 | |
544 | - break; |
|
544 | + break; |
|
545 | 545 | |
546 | 546 | |
547 | - default: |
|
548 | - if (geodir_column_exist($table, $sort_by)) { |
|
547 | + default: |
|
548 | + if (geodir_column_exist($table, $sort_by)) { |
|
549 | 549 | $orderby = $table . "." . $sort_by . " " . $order . ", "; |
550 | 550 | } |
551 | - break; |
|
551 | + break; |
|
552 | 552 | |
553 | - endswitch; |
|
553 | + endswitch; |
|
554 | 554 | |
555 | - } |
|
555 | + } |
|
556 | 556 | |
557 | - } |
|
557 | + } |
|
558 | 558 | |
559 | - return $orderby; |
|
559 | + return $orderby; |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
@@ -571,34 +571,34 @@ discard block |
||
571 | 571 | { |
572 | 572 | |
573 | 573 | |
574 | - global $wpdb, $geodir_post_type, $table, $s, $snear; |
|
574 | + global $wpdb, $geodir_post_type, $table, $s, $snear; |
|
575 | 575 | |
576 | - if (!is_admin()) { |
|
576 | + if (!is_admin()) { |
|
577 | 577 | |
578 | - if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { |
|
579 | - add_filter('posts_where', 'geodir_edit_listing_where', 1); |
|
578 | + if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { |
|
579 | + add_filter('posts_where', 'geodir_edit_listing_where', 1); |
|
580 | 580 | |
581 | - } elseif ((is_search() && $_REQUEST['geodir_search'])) { |
|
581 | + } elseif ((is_search() && $_REQUEST['geodir_search'])) { |
|
582 | 582 | |
583 | - add_filter('posts_where', 'searching_filter_where', 1); |
|
583 | + add_filter('posts_where', 'searching_filter_where', 1); |
|
584 | 584 | |
585 | - if ($snear != '') |
|
586 | - add_filter('posts_where', 'searching_filter_where', 1); |
|
585 | + if ($snear != '') |
|
586 | + add_filter('posts_where', 'searching_filter_where', 1); |
|
587 | 587 | |
588 | - add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
588 | + add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
589 | 589 | |
590 | - } elseif (geodir_is_page('author')) { |
|
590 | + } elseif (geodir_is_page('author')) { |
|
591 | 591 | |
592 | - add_filter('posts_where', 'author_filter_where', 1); |
|
592 | + add_filter('posts_where', 'author_filter_where', 1); |
|
593 | 593 | |
594 | - } |
|
594 | + } |
|
595 | 595 | |
596 | - //if (!geodir_is_page('detail')) |
|
597 | - add_filter('posts_where', 'geodir_default_where', 1);/**/ |
|
596 | + //if (!geodir_is_page('detail')) |
|
597 | + add_filter('posts_where', 'geodir_default_where', 1);/**/ |
|
598 | 598 | |
599 | - //add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts |
|
599 | + //add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts |
|
600 | 600 | |
601 | - } |
|
601 | + } |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -613,13 +613,13 @@ discard block |
||
613 | 613 | */ |
614 | 614 | function geodir_preview_post_cap($allcaps, $caps, $args) |
615 | 615 | { |
616 | - $user_id = get_current_user_id(); |
|
617 | - if ($user_id && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != '' && isset($_REQUEST['p']) && $_REQUEST['p'] != '' && $args[0] == 'edit_post' && $_REQUEST['p'] == $args[2]) { |
|
616 | + $user_id = get_current_user_id(); |
|
617 | + if ($user_id && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != '' && isset($_REQUEST['p']) && $_REQUEST['p'] != '' && $args[0] == 'edit_post' && $_REQUEST['p'] == $args[2]) { |
|
618 | 618 | |
619 | - $allcaps['edit_posts'] = true; |
|
620 | - } |
|
621 | - //print_r($allcaps); |
|
622 | - return $allcaps; |
|
619 | + $allcaps['edit_posts'] = true; |
|
620 | + } |
|
621 | + //print_r($allcaps); |
|
622 | + return $allcaps; |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | |
@@ -634,9 +634,9 @@ discard block |
||
634 | 634 | */ |
635 | 635 | function geodir_edit_listing_where($where) |
636 | 636 | { |
637 | - global $wpdb; |
|
638 | - $where = $wpdb->prepare(" AND $wpdb->posts.ID = %d ", $_REQUEST['pid']); |
|
639 | - return $where; |
|
637 | + global $wpdb; |
|
638 | + $where = $wpdb->prepare(" AND $wpdb->posts.ID = %d ", $_REQUEST['pid']); |
|
639 | + return $where; |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | |
@@ -653,29 +653,29 @@ discard block |
||
653 | 653 | */ |
654 | 654 | function geodir_default_where($where) |
655 | 655 | { |
656 | - global $wp_query, $wpdb; |
|
657 | - |
|
658 | - //print_r($wp_query); |
|
659 | - ########### WPML ########### |
|
660 | - |
|
661 | - if (geodir_is_wpml()) { |
|
662 | - global $sitepress, $table_prefix; |
|
663 | - $lang_code = ICL_LANGUAGE_CODE; |
|
664 | - $default_lang_code = $sitepress->get_default_language(); |
|
665 | - $q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
|
666 | - //echo '##########'.$q_post_type; |
|
667 | - if ($lang_code && $q_post_type && geodir_wpml_is_post_type_translated($q_post_type)) { |
|
668 | - $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') "; |
|
669 | - //$where .= " AND icl_t.language_code = '$lang_code' "; |
|
670 | - } |
|
656 | + global $wp_query, $wpdb; |
|
671 | 657 | |
672 | - } |
|
673 | - ########### WPML ########### |
|
658 | + //print_r($wp_query); |
|
659 | + ########### WPML ########### |
|
660 | + |
|
661 | + if (geodir_is_wpml()) { |
|
662 | + global $sitepress, $table_prefix; |
|
663 | + $lang_code = ICL_LANGUAGE_CODE; |
|
664 | + $default_lang_code = $sitepress->get_default_language(); |
|
665 | + $q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
|
666 | + //echo '##########'.$q_post_type; |
|
667 | + if ($lang_code && $q_post_type && geodir_wpml_is_post_type_translated($q_post_type)) { |
|
668 | + $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') "; |
|
669 | + //$where .= " AND icl_t.language_code = '$lang_code' "; |
|
670 | + } |
|
674 | 671 | |
672 | + } |
|
673 | + ########### WPML ########### |
|
675 | 674 | |
676 | - return $where = str_replace("0 = 1", "1=1", $where); |
|
677 | 675 | |
678 | - /* ====== old code start === |
|
676 | + return $where = str_replace("0 = 1", "1=1", $where); |
|
677 | + |
|
678 | + /* ====== old code start === |
|
679 | 679 | $where = str_replace("0 = 1", "1=1", $where); |
680 | 680 | $country = get_query_var('gd_country'); |
681 | 681 | $region = get_query_var('gd_region'); |
@@ -716,92 +716,92 @@ discard block |
||
716 | 716 | * @return string Modified where query string. |
717 | 717 | */ |
718 | 718 | function searching_filter_where($where) { |
719 | - global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s_A, $s_SA, $search_term, $gd_session; |
|
719 | + global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s_A, $s_SA, $search_term, $gd_session; |
|
720 | 720 | |
721 | - $search_term = 'OR'; |
|
722 | - $search_term = 'AND'; |
|
723 | - $geodir_custom_search = ''; |
|
724 | - $category_search_range = ''; |
|
721 | + $search_term = 'OR'; |
|
722 | + $search_term = 'AND'; |
|
723 | + $geodir_custom_search = ''; |
|
724 | + $category_search_range = ''; |
|
725 | 725 | |
726 | - if (is_single() && get_query_var('post_type')) { |
|
726 | + if (is_single() && get_query_var('post_type')) { |
|
727 | 727 | return $where; |
728 | 728 | } |
729 | 729 | |
730 | - if (is_tax()) { |
|
730 | + if (is_tax()) { |
|
731 | 731 | return $where; |
732 | 732 | } |
733 | 733 | |
734 | 734 | $s = trim($s); |
735 | - $s = wp_specialchars_decode($s ,ENT_QUOTES); |
|
736 | - $s_A = wp_specialchars_decode($s_A ,ENT_QUOTES); |
|
737 | - |
|
738 | - $where = ''; |
|
739 | - $better_search_terms = ''; |
|
740 | - if (isset($_REQUEST['stype'])) |
|
741 | - $post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype'])); |
|
742 | - else |
|
743 | - $post_types = 'gd_place'; |
|
744 | - |
|
745 | - if ($s != '') { |
|
746 | - $keywords = explode(" ", $s); |
|
747 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
748 | - foreach($keywords as $kkey=>$kword){ |
|
749 | - if(geodir_utf8_strlen($kword)<=$klimit){ |
|
750 | - unset($keywords[$kkey]); |
|
751 | - } |
|
752 | - } |
|
753 | - } |
|
735 | + $s = wp_specialchars_decode($s ,ENT_QUOTES); |
|
736 | + $s_A = wp_specialchars_decode($s_A ,ENT_QUOTES); |
|
754 | 737 | |
755 | - if (!empty($keywords)) { |
|
756 | - foreach ($keywords as $keyword) { |
|
757 | - $keyword = trim($keyword); |
|
758 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
759 | - if ($keyword != '') { |
|
760 | - /** |
|
761 | - * Filter the search query keywords SQL. |
|
762 | - * |
|
763 | - * @since 1.5.9 |
|
764 | - * @package GeoDirectory |
|
765 | - * @param string $better_search_terms The query values, default: `' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )'`. |
|
766 | - * @param array $keywords The array of keywords for the query. |
|
767 | - * @param string $keyword The single keyword being searched. |
|
768 | - */ |
|
738 | + $where = ''; |
|
739 | + $better_search_terms = ''; |
|
740 | + if (isset($_REQUEST['stype'])) |
|
741 | + $post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype'])); |
|
742 | + else |
|
743 | + $post_types = 'gd_place'; |
|
744 | + |
|
745 | + if ($s != '') { |
|
746 | + $keywords = explode(" ", $s); |
|
747 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
748 | + foreach($keywords as $kkey=>$kword){ |
|
749 | + if(geodir_utf8_strlen($kword)<=$klimit){ |
|
750 | + unset($keywords[$kkey]); |
|
751 | + } |
|
752 | + } |
|
753 | + } |
|
754 | + |
|
755 | + if (!empty($keywords)) { |
|
756 | + foreach ($keywords as $keyword) { |
|
757 | + $keyword = trim($keyword); |
|
758 | + $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
759 | + if ($keyword != '') { |
|
760 | + /** |
|
761 | + * Filter the search query keywords SQL. |
|
762 | + * |
|
763 | + * @since 1.5.9 |
|
764 | + * @package GeoDirectory |
|
765 | + * @param string $better_search_terms The query values, default: `' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )'`. |
|
766 | + * @param array $keywords The array of keywords for the query. |
|
767 | + * @param string $keyword The single keyword being searched. |
|
768 | + */ |
|
769 | 769 | $better_search_terms .= apply_filters("geodir_search_better_search_terms",' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )',$keywords,$keyword); |
770 | - } |
|
771 | - } |
|
772 | - } |
|
773 | - } |
|
770 | + } |
|
771 | + } |
|
772 | + } |
|
773 | + } |
|
774 | 774 | |
775 | - /* get taxonomy */ |
|
776 | - $taxonomies = geodir_get_taxonomies($post_types, true); |
|
777 | - if($taxonomies) { |
|
778 | - $taxonomies = implode("','", $taxonomies); |
|
779 | - $taxonomies = "'" . $taxonomies . "'"; |
|
780 | - }else{$taxonomies='';} |
|
775 | + /* get taxonomy */ |
|
776 | + $taxonomies = geodir_get_taxonomies($post_types, true); |
|
777 | + if($taxonomies) { |
|
778 | + $taxonomies = implode("','", $taxonomies); |
|
779 | + $taxonomies = "'" . $taxonomies . "'"; |
|
780 | + }else{$taxonomies='';} |
|
781 | 781 | |
782 | - $content_where = $terms_where = ''; |
|
782 | + $content_where = $terms_where = ''; |
|
783 | 783 | if ($s != '') { |
784 | - /** |
|
785 | - * Filter the search query content where values. |
|
786 | - * |
|
787 | - * @since 1.5.0 |
|
788 | - * @package GeoDirectory |
|
789 | - * @param string $content_where The query values, default: `" OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") ") "`. |
|
790 | - */ |
|
784 | + /** |
|
785 | + * Filter the search query content where values. |
|
786 | + * |
|
787 | + * @since 1.5.0 |
|
788 | + * @package GeoDirectory |
|
789 | + * @param string $content_where The query values, default: `" OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") ") "`. |
|
790 | + */ |
|
791 | 791 | $content_where = apply_filters("geodir_search_content_where"," OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") "); |
792 | - /** |
|
793 | - * Filter the search query term values. |
|
794 | - * |
|
795 | - * @since 1.5.0 |
|
796 | - * @package GeoDirectory |
|
797 | - * @param string $terms_where The separator, default: `" AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "`. |
|
798 | - */ |
|
799 | - $terms_where = apply_filters("geodir_search_terms_where"," AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "); |
|
792 | + /** |
|
793 | + * Filter the search query term values. |
|
794 | + * |
|
795 | + * @since 1.5.0 |
|
796 | + * @package GeoDirectory |
|
797 | + * @param string $terms_where The separator, default: `" AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "`. |
|
798 | + */ |
|
799 | + $terms_where = apply_filters("geodir_search_terms_where"," AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | |
803 | - // get term sql |
|
804 | - $term_sql = "SELECT $wpdb->term_taxonomy.term_id, $wpdb->terms.name, $wpdb->term_taxonomy.taxonomy |
|
803 | + // get term sql |
|
804 | + $term_sql = "SELECT $wpdb->term_taxonomy.term_id, $wpdb->terms.name, $wpdb->term_taxonomy.taxonomy |
|
805 | 805 | FROM $wpdb->term_taxonomy, $wpdb->terms, $wpdb->term_relationships |
806 | 806 | WHERE $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id |
807 | 807 | AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id |
@@ -809,45 +809,45 @@ discard block |
||
809 | 809 | $terms_where |
810 | 810 | GROUP BY $wpdb->term_taxonomy.term_id"; |
811 | 811 | |
812 | - $term_results = $wpdb->get_results($term_sql); |
|
813 | - $term_ids = array(); |
|
814 | - $terms_sql = ''; |
|
815 | - |
|
816 | - if(!empty($term_results)){ |
|
817 | - foreach($term_results as $term_id){ |
|
818 | - $term_ids[] = $term_id; |
|
819 | - } |
|
820 | - if (!empty($term_ids)) { |
|
821 | - foreach($term_ids as $term){ |
|
822 | - if ($term->taxonomy == $post_types.'_tags') { |
|
823 | - $terms_sql .= $wpdb->prepare(" OR FIND_IN_SET(%s , " . $table . ".post_tags) ", $term->name); |
|
824 | - } else { |
|
825 | - $terms_sql .= " OR FIND_IN_SET($term->term_id , " . $table . "." . $post_types . "category) "; |
|
826 | - } |
|
827 | - } |
|
828 | - } |
|
829 | - } |
|
812 | + $term_results = $wpdb->get_results($term_sql); |
|
813 | + $term_ids = array(); |
|
814 | + $terms_sql = ''; |
|
815 | + |
|
816 | + if(!empty($term_results)){ |
|
817 | + foreach($term_results as $term_id){ |
|
818 | + $term_ids[] = $term_id; |
|
819 | + } |
|
820 | + if (!empty($term_ids)) { |
|
821 | + foreach($term_ids as $term){ |
|
822 | + if ($term->taxonomy == $post_types.'_tags') { |
|
823 | + $terms_sql .= $wpdb->prepare(" OR FIND_IN_SET(%s , " . $table . ".post_tags) ", $term->name); |
|
824 | + } else { |
|
825 | + $terms_sql .= " OR FIND_IN_SET($term->term_id , " . $table . "." . $post_types . "category) "; |
|
826 | + } |
|
827 | + } |
|
828 | + } |
|
829 | + } |
|
830 | 830 | |
831 | 831 | |
832 | - if ($snear != '') { |
|
832 | + if ($snear != '') { |
|
833 | 833 | |
834 | 834 | |
835 | - if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) { |
|
836 | - $dist = $gd_session->get('near_me_range'); |
|
837 | - } |
|
838 | - $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69); |
|
839 | - $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69); |
|
840 | - $lat1 = $mylat - ($dist / 69); |
|
841 | - $lat2 = $mylat + ($dist / 69); |
|
835 | + if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) { |
|
836 | + $dist = $gd_session->get('near_me_range'); |
|
837 | + } |
|
838 | + $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69); |
|
839 | + $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69); |
|
840 | + $lat1 = $mylat - ($dist / 69); |
|
841 | + $lat2 = $mylat + ($dist / 69); |
|
842 | 842 | |
843 | - $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : ''; |
|
844 | - $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : ''; |
|
845 | - $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : ''; |
|
846 | - $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : ''; |
|
843 | + $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : ''; |
|
844 | + $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : ''; |
|
845 | + $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : ''; |
|
846 | + $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : ''; |
|
847 | 847 | |
848 | 848 | |
849 | 849 | |
850 | - $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
850 | + $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
851 | 851 | $content_where |
852 | 852 | $terms_sql |
853 | 853 | ) |
@@ -856,35 +856,35 @@ discard block |
||
856 | 856 | AND ( " . $table . ".post_latitude between $rlat1 and $rlat2 ) |
857 | 857 | AND ( " . $table . ".post_longitude between $rlon1 and $rlon2 ) "; |
858 | 858 | |
859 | - if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') { |
|
860 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
861 | - $where .= " AND CONVERT((" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) ))),DECIMAL(64,4)) <= " . $dist; |
|
862 | - } |
|
859 | + if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') { |
|
860 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
861 | + $where .= " AND CONVERT((" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) ))),DECIMAL(64,4)) <= " . $dist; |
|
862 | + } |
|
863 | 863 | |
864 | - } else { |
|
864 | + } else { |
|
865 | 865 | |
866 | 866 | |
867 | 867 | |
868 | - $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
868 | + $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
869 | 869 | $content_where |
870 | 870 | $terms_sql |
871 | 871 | ) |
872 | 872 | |
873 | 873 | AND $wpdb->posts.post_type in ('$post_types') |
874 | 874 | AND ($wpdb->posts.post_status = 'publish') "; |
875 | - } |
|
875 | + } |
|
876 | 876 | |
877 | 877 | ########### WPML ########### |
878 | - if ( geodir_wpml_is_post_type_translated( $post_types ) ) { |
|
878 | + if ( geodir_wpml_is_post_type_translated( $post_types ) ) { |
|
879 | 879 | $lang_code = ICL_LANGUAGE_CODE; |
880 | 880 | |
881 | 881 | if ($lang_code && $post_types) { |
882 | - $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') "; |
|
883 | - } |
|
884 | - } |
|
885 | - ########### WPML ########### |
|
882 | + $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') "; |
|
883 | + } |
|
884 | + } |
|
885 | + ########### WPML ########### |
|
886 | 886 | |
887 | - return $where; |
|
887 | + return $where; |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | |
@@ -899,45 +899,45 @@ discard block |
||
899 | 899 | * @return string Modified where query string. |
900 | 900 | */ |
901 | 901 | function author_filter_where($where) { |
902 | - global $wpdb, $geodir_post_type, $table, $curr; |
|
902 | + global $wpdb, $geodir_post_type, $table, $curr; |
|
903 | 903 | |
904 | - $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); |
|
905 | - $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
904 | + $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); |
|
905 | + $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
906 | 906 | |
907 | - if (isset($_REQUEST['stype'])) { |
|
908 | - $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']); |
|
909 | - } else { |
|
910 | - $where = " AND $wpdb->posts.post_type IN ('gd_place') "; |
|
911 | - } |
|
907 | + if (isset($_REQUEST['stype'])) { |
|
908 | + $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']); |
|
909 | + } else { |
|
910 | + $where = " AND $wpdb->posts.post_type IN ('gd_place') "; |
|
911 | + } |
|
912 | 912 | |
913 | - if ($user_id > 0) { |
|
914 | - if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') { |
|
915 | - $user_fav_posts = get_user_meta($user_id, 'gd_user_favourite_post', true); |
|
916 | - $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1'; |
|
917 | - $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')"; |
|
918 | - } else |
|
919 | - $where .= " AND $wpdb->posts.post_author = $user_id"; |
|
920 | - |
|
921 | - if ($user_id == (int)get_current_user_id()) { |
|
922 | - $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') "; |
|
923 | - } else { |
|
924 | - $where .= " AND $wpdb->posts.post_status = 'publish' "; |
|
925 | - } |
|
926 | - } else { |
|
927 | - $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' "; |
|
928 | - } |
|
913 | + if ($user_id > 0) { |
|
914 | + if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') { |
|
915 | + $user_fav_posts = get_user_meta($user_id, 'gd_user_favourite_post', true); |
|
916 | + $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1'; |
|
917 | + $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')"; |
|
918 | + } else |
|
919 | + $where .= " AND $wpdb->posts.post_author = $user_id"; |
|
920 | + |
|
921 | + if ($user_id == (int)get_current_user_id()) { |
|
922 | + $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') "; |
|
923 | + } else { |
|
924 | + $where .= " AND $wpdb->posts.post_status = 'publish' "; |
|
925 | + } |
|
926 | + } else { |
|
927 | + $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' "; |
|
928 | + } |
|
929 | 929 | |
930 | - ########### WPML ########### |
|
931 | - if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) { |
|
932 | - $lang_code = ICL_LANGUAGE_CODE; |
|
933 | - if ($lang_code) { |
|
934 | - $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
935 | - } |
|
930 | + ########### WPML ########### |
|
931 | + if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) { |
|
932 | + $lang_code = ICL_LANGUAGE_CODE; |
|
933 | + if ($lang_code) { |
|
934 | + $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
935 | + } |
|
936 | 936 | |
937 | - } |
|
938 | - ########### WPML ########### |
|
937 | + } |
|
938 | + ########### WPML ########### |
|
939 | 939 | |
940 | - return $where; |
|
940 | + return $where; |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | /** |
@@ -952,11 +952,11 @@ discard block |
||
952 | 952 | */ |
953 | 953 | function geodir_filter_widget_join($join) |
954 | 954 | { |
955 | - global $wp_query, $table; |
|
956 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
957 | - $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
958 | - } |
|
959 | - return $join; |
|
955 | + global $wp_query, $table; |
|
956 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
957 | + $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
958 | + } |
|
959 | + return $join; |
|
960 | 960 | } |
961 | 961 | |
962 | 962 | /** |
@@ -971,43 +971,43 @@ discard block |
||
971 | 971 | */ |
972 | 972 | function geodir_filter_widget_where($where) |
973 | 973 | { |
974 | - global $wp_query, $table; |
|
975 | - if (!empty($wp_query->query['show_featured_only'])) { |
|
976 | - $where .= " AND " . $table . ".is_featured = '1'"; |
|
977 | - } |
|
978 | - if (!empty($wp_query->query['show_special_only'])) { |
|
979 | - $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
980 | - } |
|
981 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
982 | - $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
983 | - } |
|
984 | - if (!empty($wp_query->query['with_videos_only'])) { |
|
985 | - $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
986 | - } |
|
987 | - return $where; |
|
974 | + global $wp_query, $table; |
|
975 | + if (!empty($wp_query->query['show_featured_only'])) { |
|
976 | + $where .= " AND " . $table . ".is_featured = '1'"; |
|
977 | + } |
|
978 | + if (!empty($wp_query->query['show_special_only'])) { |
|
979 | + $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
980 | + } |
|
981 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
982 | + $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
983 | + } |
|
984 | + if (!empty($wp_query->query['with_videos_only'])) { |
|
985 | + $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
986 | + } |
|
987 | + return $where; |
|
988 | 988 | } |
989 | 989 | |
990 | 990 | |
991 | 991 | function geodir_related_posts_fields($fields) { |
992 | - global $wp_query, $wpdb, $table, $post; |
|
992 | + global $wp_query, $wpdb, $table, $post; |
|
993 | 993 | |
994 | - $fields .= ", " . $table . ".* "; |
|
994 | + $fields .= ", " . $table . ".* "; |
|
995 | 995 | |
996 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
996 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
997 | 997 | |
998 | - $mylat = $post->post_latitude; |
|
999 | - $mylon = $post->post_longitude; |
|
998 | + $mylat = $post->post_latitude; |
|
999 | + $mylon = $post->post_longitude; |
|
1000 | 1000 | |
1001 | - $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; |
|
1002 | - return $fields; |
|
1001 | + $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; |
|
1002 | + return $fields; |
|
1003 | 1003 | } |
1004 | 1004 | function geodir_related_posts_fields_filter($query) { |
1005 | - if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
1006 | - && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
|
1007 | - && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
|
1008 | - ) { |
|
1009 | - add_filter('posts_fields', 'geodir_related_posts_fields', 1); |
|
1010 | - } |
|
1005 | + if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
1006 | + && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
|
1007 | + && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
|
1008 | + ) { |
|
1009 | + add_filter('posts_fields', 'geodir_related_posts_fields', 1); |
|
1010 | + } |
|
1011 | 1011 | } |
1012 | 1012 | add_action('pre_get_posts', 'geodir_related_posts_fields_filter', 1); |
1013 | 1013 | |
@@ -1022,30 +1022,30 @@ discard block |
||
1022 | 1022 | * @return string|null If field exists in table returns order by clause else returns empty. |
1023 | 1023 | */ |
1024 | 1024 | function geodir_prepare_custom_sorting( $sorting, $table ) { |
1025 | - $orderby = ''; |
|
1025 | + $orderby = ''; |
|
1026 | 1026 | |
1027 | - if ( empty( $sorting ) || empty( $table ) ) { |
|
1028 | - return $orderby; |
|
1029 | - } |
|
1027 | + if ( empty( $sorting ) || empty( $table ) ) { |
|
1028 | + return $orderby; |
|
1029 | + } |
|
1030 | 1030 | |
1031 | - if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) { |
|
1032 | - $sorting_array = explode( '_', $sorting ); |
|
1031 | + if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) { |
|
1032 | + $sorting_array = explode( '_', $sorting ); |
|
1033 | 1033 | |
1034 | - if ( ( $count = count( $sorting_array ) ) > 1 ) { |
|
1035 | - $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
1036 | - array_pop( $sorting_array ); |
|
1034 | + if ( ( $count = count( $sorting_array ) ) > 1 ) { |
|
1035 | + $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
1036 | + array_pop( $sorting_array ); |
|
1037 | 1037 | |
1038 | - if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) { |
|
1039 | - $sort_by = implode( '_', $sorting_array ); |
|
1038 | + if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) { |
|
1039 | + $sort_by = implode( '_', $sorting_array ); |
|
1040 | 1040 | |
1041 | - if ( geodir_column_exist( $table, $sort_by ) ) { |
|
1042 | - $orderby = $table . "." . $sort_by . " " . $order; |
|
1043 | - } |
|
1044 | - } |
|
1045 | - } |
|
1046 | - } |
|
1041 | + if ( geodir_column_exist( $table, $sort_by ) ) { |
|
1042 | + $orderby = $table . "." . $sort_by . " " . $order; |
|
1043 | + } |
|
1044 | + } |
|
1045 | + } |
|
1046 | + } |
|
1047 | 1047 | |
1048 | - return $orderby; |
|
1048 | + return $orderby; |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | /** |
@@ -1065,21 +1065,21 @@ discard block |
||
1065 | 1065 | * @return string Modified fields SQL. |
1066 | 1066 | */ |
1067 | 1067 | function geodir_search_widget_location_filter_fields( $fields, $table, $post_type ) { |
1068 | - global $wpdb, $gd_query_args_widgets, $snear, $gd_session; |
|
1068 | + global $wpdb, $gd_query_args_widgets, $snear, $gd_session; |
|
1069 | 1069 | |
1070 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1071 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1070 | + if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1071 | + $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1072 | 1072 | |
1073 | - if ( $location_allowed && strpos( strtolower( $fields ), ' as distance ' ) === false && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1074 | - $latitude = sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
1075 | - $longitude = sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
1076 | - $radius = geodir_getDistanceRadius( get_option( 'geodir_search_dist_1' ) ); |
|
1073 | + if ( $location_allowed && strpos( strtolower( $fields ), ' as distance ' ) === false && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1074 | + $latitude = sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
1075 | + $longitude = sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
1076 | + $radius = geodir_getDistanceRadius( get_option( 'geodir_search_dist_1' ) ); |
|
1077 | 1077 | |
1078 | - $fields .= $wpdb->prepare( ", (" . $radius . " * 2 * ASIN(SQRT(POWER(SIN((ABS(%s) - ABS(" . $table . ".post_latitude)) * PI() / 180 / 2), 2) + COS(ABS(%s) * PI() / 180) * COS(ABS(" . $table . ".post_latitude) * PI() / 180) * POWER(SIN((%s - " . $table . ".post_longitude) * PI() / 180 / 2), 2)))) AS distance ", $latitude, $latitude, $longitude ); |
|
1079 | - } |
|
1080 | - } |
|
1078 | + $fields .= $wpdb->prepare( ", (" . $radius . " * 2 * ASIN(SQRT(POWER(SIN((ABS(%s) - ABS(" . $table . ".post_latitude)) * PI() / 180 / 2), 2) + COS(ABS(%s) * PI() / 180) * COS(ABS(" . $table . ".post_latitude) * PI() / 180) * POWER(SIN((%s - " . $table . ".post_longitude) * PI() / 180 / 2), 2)))) AS distance ", $latitude, $latitude, $longitude ); |
|
1079 | + } |
|
1080 | + } |
|
1081 | 1081 | |
1082 | - return $fields; |
|
1082 | + return $fields; |
|
1083 | 1083 | } |
1084 | 1084 | |
1085 | 1085 | /** |
@@ -1098,15 +1098,15 @@ discard block |
||
1098 | 1098 | * @return string Modified fields SQL. |
1099 | 1099 | */ |
1100 | 1100 | function geodir_search_widget_location_filter_orderby( $orderby, $table, $post_type ) { |
1101 | - global $gd_query_args_widgets, $snear, $gd_session; |
|
1101 | + global $gd_query_args_widgets, $snear, $gd_session; |
|
1102 | 1102 | |
1103 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1104 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1103 | + if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1104 | + $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1105 | 1105 | |
1106 | - if ( $location_allowed && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1107 | - $orderby = "distance ASC, " . $orderby; |
|
1108 | - } |
|
1109 | - } |
|
1106 | + if ( $location_allowed && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1107 | + $orderby = "distance ASC, " . $orderby; |
|
1108 | + } |
|
1109 | + } |
|
1110 | 1110 | |
1111 | - return $orderby; |
|
1111 | + return $orderby; |
|
1112 | 1112 | } |
1113 | 1113 | \ No newline at end of file |