@@ -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(); |
|
192 | 173 | |
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 | - } |
|
174 | + if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) { |
|
175 | + $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
212 | 176 | |
213 | - } |
|
214 | - return $query; |
|
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 | + |
|
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 | + } |
|
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 | - } |
|
242 | + $mylat = $gd_session->get('user_lat'); |
|
243 | + $mylon = $gd_session->get('user_lon'); |
|
244 | + } |
|
245 | 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 | - } |
|
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 | 248 | |
249 | - global $s; |
|
250 | - if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
251 | - $keywords = explode(" ", $s); |
|
249 | + global $s; |
|
250 | + if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
251 | + $keywords = explode(" ", $s); |
|
252 | 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 | - } |
|
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 | 260 | |
261 | 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); |
|
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 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,'%>' . $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'); |
|
387 | + if (is_main_query() && geodir_is_page('search')) { |
|
388 | + $search_term = get_query_var('s'); |
|
389 | 389 | |
390 | - if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) { |
|
391 | - $sort_by = 'az'; |
|
392 | - } |
|
390 | + if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) { |
|
391 | + $sort_by = 'az'; |
|
392 | + } |
|
393 | 393 | |
394 | - if ($snear != '' && $sort_by!='farthest') { |
|
395 | - $sort_by = 'nearest'; |
|
396 | - } |
|
397 | - } |
|
394 | + if ($snear != '' && $sort_by!='farthest') { |
|
395 | + $sort_by = 'nearest'; |
|
396 | + } |
|
397 | + } |
|
398 | 398 | |
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 | - } |
|
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 | + } |
|
456 | 456 | |
457 | - global $s; |
|
457 | + global $s; |
|
458 | 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 | - } |
|
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,78 +510,78 @@ 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': |
|
540 | + // sort by rating |
|
541 | + case 'overall_rating': |
|
542 | 542 | |
543 | - $use_bayesian = apply_filters('gd_use_bayesian',true,$table); |
|
544 | - $avg_rating = 0; |
|
545 | - if($use_bayesian){ |
|
546 | - $avg_num_votes = get_transient( 'gd_avg_num_votes_'.$table ); |
|
547 | - if(!$avg_num_votes){ |
|
548 | - $avg_num_votes = $wpdb->get_var("SELECT SUM(rating_count) FROM $table"); |
|
549 | - if($avg_num_votes){ |
|
543 | + $use_bayesian = apply_filters('gd_use_bayesian',true,$table); |
|
544 | + $avg_rating = 0; |
|
545 | + if($use_bayesian){ |
|
546 | + $avg_num_votes = get_transient( 'gd_avg_num_votes_'.$table ); |
|
547 | + if(!$avg_num_votes){ |
|
548 | + $avg_num_votes = $wpdb->get_var("SELECT SUM(rating_count) FROM $table"); |
|
549 | + if($avg_num_votes){ |
|
550 | 550 | |
551 | - $avg_rating = get_transient( 'gd_avg_rating_'.$table ); |
|
552 | - if(!$avg_rating){ |
|
553 | - $avg_rating = $wpdb->get_var("SELECT SUM(overall_rating) FROM $table")/$avg_num_votes; |
|
554 | - } |
|
555 | - set_transient( 'gd_avg_num_votes_'.$table, $avg_num_votes, 12 * HOUR_IN_SECONDS ); |
|
556 | - set_transient( 'gd_avg_rating_'.$table, $avg_rating , 12 * HOUR_IN_SECONDS ); |
|
557 | - } |
|
558 | - } |
|
551 | + $avg_rating = get_transient( 'gd_avg_rating_'.$table ); |
|
552 | + if(!$avg_rating){ |
|
553 | + $avg_rating = $wpdb->get_var("SELECT SUM(overall_rating) FROM $table")/$avg_num_votes; |
|
554 | + } |
|
555 | + set_transient( 'gd_avg_num_votes_'.$table, $avg_num_votes, 12 * HOUR_IN_SECONDS ); |
|
556 | + set_transient( 'gd_avg_rating_'.$table, $avg_rating , 12 * HOUR_IN_SECONDS ); |
|
557 | + } |
|
558 | + } |
|
559 | 559 | |
560 | - if(!$avg_num_votes){ $avg_num_votes = 0;} |
|
560 | + if(!$avg_num_votes){ $avg_num_votes = 0;} |
|
561 | 561 | |
562 | - $orderby = " (( $avg_num_votes * $avg_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating )) / ( $avg_num_votes + " . $table . ".rating_count ) $order , "; |
|
562 | + $orderby = " (( $avg_num_votes * $avg_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating )) / ( $avg_num_votes + " . $table . ".rating_count ) $order , "; |
|
563 | 563 | |
564 | - //$orderby = " ( " . $table . ".rating_count * " . $table . ".overall_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating ) / ( " . $table . ".rating_count + " . $table . ".rating_count ) $order , "; // seems to work mostly with no extra overheads |
|
565 | - }else{ |
|
566 | - $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
567 | - } |
|
564 | + //$orderby = " ( " . $table . ".rating_count * " . $table . ".overall_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating ) / ( " . $table . ".rating_count + " . $table . ".rating_count ) $order , "; // seems to work mostly with no extra overheads |
|
565 | + }else{ |
|
566 | + $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
567 | + } |
|
568 | 568 | |
569 | - break; |
|
569 | + break; |
|
570 | 570 | |
571 | 571 | |
572 | - default: |
|
573 | - if (geodir_column_exist($table, $sort_by)) { |
|
572 | + default: |
|
573 | + if (geodir_column_exist($table, $sort_by)) { |
|
574 | 574 | $orderby = $table . "." . $sort_by . " " . $order . ", "; |
575 | 575 | } |
576 | - break; |
|
576 | + break; |
|
577 | 577 | |
578 | - endswitch; |
|
578 | + endswitch; |
|
579 | 579 | |
580 | - } |
|
580 | + } |
|
581 | 581 | |
582 | - } |
|
582 | + } |
|
583 | 583 | |
584 | - return $orderby; |
|
584 | + return $orderby; |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -596,35 +596,35 @@ discard block |
||
596 | 596 | { |
597 | 597 | |
598 | 598 | |
599 | - global $wpdb, $geodir_post_type, $table, $s, $snear; |
|
599 | + global $wpdb, $geodir_post_type, $table, $s, $snear; |
|
600 | 600 | |
601 | - if (!is_admin()) { |
|
601 | + if (!is_admin()) { |
|
602 | 602 | |
603 | - if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { |
|
604 | - add_filter('posts_where', 'geodir_edit_listing_where', 1); |
|
603 | + if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { |
|
604 | + add_filter('posts_where', 'geodir_edit_listing_where', 1); |
|
605 | 605 | |
606 | - } elseif ((is_search() && $_REQUEST['geodir_search'])) { |
|
606 | + } elseif ((is_search() && $_REQUEST['geodir_search'])) { |
|
607 | 607 | |
608 | - add_filter('posts_where', 'searching_filter_where', 1); |
|
608 | + add_filter('posts_where', 'searching_filter_where', 1); |
|
609 | 609 | |
610 | - if ($snear != '') |
|
611 | - add_filter('posts_where', 'searching_filter_where', 1); |
|
610 | + if ($snear != '') |
|
611 | + add_filter('posts_where', 'searching_filter_where', 1); |
|
612 | 612 | |
613 | - add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
613 | + add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
614 | 614 | add_filter( 'posts_where', 'geodir_posts_having', 10000, 2 ); // make sure its the last WHERE param |
615 | 615 | |
616 | - } elseif (geodir_is_page('author')) { |
|
616 | + } elseif (geodir_is_page('author')) { |
|
617 | 617 | |
618 | - add_filter('posts_where', 'author_filter_where', 1); |
|
618 | + add_filter('posts_where', 'author_filter_where', 1); |
|
619 | 619 | |
620 | - } |
|
620 | + } |
|
621 | 621 | |
622 | - //if (!geodir_is_page('detail')) |
|
623 | - add_filter('posts_where', 'geodir_default_where', 1);/**/ |
|
622 | + //if (!geodir_is_page('detail')) |
|
623 | + add_filter('posts_where', 'geodir_default_where', 1);/**/ |
|
624 | 624 | |
625 | - //add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts |
|
625 | + //add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts |
|
626 | 626 | |
627 | - } |
|
627 | + } |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -639,13 +639,13 @@ discard block |
||
639 | 639 | */ |
640 | 640 | function geodir_preview_post_cap($allcaps, $caps, $args) |
641 | 641 | { |
642 | - $user_id = get_current_user_id(); |
|
643 | - if ($user_id && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != '' && isset($_REQUEST['p']) && $_REQUEST['p'] != '' && $args[0] == 'edit_post' && $_REQUEST['p'] == $args[2]) { |
|
642 | + $user_id = get_current_user_id(); |
|
643 | + if ($user_id && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != '' && isset($_REQUEST['p']) && $_REQUEST['p'] != '' && $args[0] == 'edit_post' && $_REQUEST['p'] == $args[2]) { |
|
644 | 644 | |
645 | - $allcaps['edit_posts'] = true; |
|
646 | - } |
|
647 | - //print_r($allcaps); |
|
648 | - return $allcaps; |
|
645 | + $allcaps['edit_posts'] = true; |
|
646 | + } |
|
647 | + //print_r($allcaps); |
|
648 | + return $allcaps; |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | |
@@ -660,9 +660,9 @@ discard block |
||
660 | 660 | */ |
661 | 661 | function geodir_edit_listing_where($where) |
662 | 662 | { |
663 | - global $wpdb; |
|
664 | - $where = $wpdb->prepare(" AND $wpdb->posts.ID = %d ", $_REQUEST['pid']); |
|
665 | - return $where; |
|
663 | + global $wpdb; |
|
664 | + $where = $wpdb->prepare(" AND $wpdb->posts.ID = %d ", $_REQUEST['pid']); |
|
665 | + return $where; |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | |
@@ -679,29 +679,29 @@ discard block |
||
679 | 679 | */ |
680 | 680 | function geodir_default_where($where) |
681 | 681 | { |
682 | - global $wp_query, $wpdb; |
|
683 | - |
|
684 | - //print_r($wp_query); |
|
685 | - ########### WPML ########### |
|
686 | - |
|
687 | - if (geodir_is_wpml()) { |
|
688 | - global $sitepress, $table_prefix; |
|
689 | - $lang_code = ICL_LANGUAGE_CODE; |
|
690 | - $default_lang_code = $sitepress->get_default_language(); |
|
691 | - $q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
|
692 | - //echo '##########'.$q_post_type; |
|
693 | - if ($lang_code && $q_post_type && geodir_wpml_is_post_type_translated($q_post_type)) { |
|
694 | - $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') "; |
|
695 | - //$where .= " AND icl_t.language_code = '$lang_code' "; |
|
696 | - } |
|
682 | + global $wp_query, $wpdb; |
|
697 | 683 | |
698 | - } |
|
699 | - ########### WPML ########### |
|
684 | + //print_r($wp_query); |
|
685 | + ########### WPML ########### |
|
686 | + |
|
687 | + if (geodir_is_wpml()) { |
|
688 | + global $sitepress, $table_prefix; |
|
689 | + $lang_code = ICL_LANGUAGE_CODE; |
|
690 | + $default_lang_code = $sitepress->get_default_language(); |
|
691 | + $q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
|
692 | + //echo '##########'.$q_post_type; |
|
693 | + if ($lang_code && $q_post_type && geodir_wpml_is_post_type_translated($q_post_type)) { |
|
694 | + $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') "; |
|
695 | + //$where .= " AND icl_t.language_code = '$lang_code' "; |
|
696 | + } |
|
697 | + |
|
698 | + } |
|
699 | + ########### WPML ########### |
|
700 | 700 | |
701 | 701 | |
702 | - return $where = str_replace("0 = 1", "1=1", $where); |
|
702 | + return $where = str_replace("0 = 1", "1=1", $where); |
|
703 | 703 | |
704 | - /* ====== old code start === |
|
704 | + /* ====== old code start === |
|
705 | 705 | $where = str_replace("0 = 1", "1=1", $where); |
706 | 706 | $country = get_query_var('gd_country'); |
707 | 707 | $region = get_query_var('gd_region'); |
@@ -742,94 +742,94 @@ discard block |
||
742 | 742 | * @return string Modified where query string. |
743 | 743 | */ |
744 | 744 | function searching_filter_where($where) { |
745 | - global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s_A, $s_SA, $search_term, $gd_session; |
|
745 | + global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s_A, $s_SA, $search_term, $gd_session; |
|
746 | 746 | |
747 | - $search_term = 'OR'; |
|
748 | - $search_term = 'AND'; |
|
749 | - $geodir_custom_search = ''; |
|
750 | - $category_search_range = ''; |
|
747 | + $search_term = 'OR'; |
|
748 | + $search_term = 'AND'; |
|
749 | + $geodir_custom_search = ''; |
|
750 | + $category_search_range = ''; |
|
751 | 751 | |
752 | - if (is_single() && get_query_var('post_type')) { |
|
752 | + if (is_single() && get_query_var('post_type')) { |
|
753 | 753 | return $where; |
754 | 754 | } |
755 | 755 | |
756 | - if (is_tax()) { |
|
756 | + if (is_tax()) { |
|
757 | 757 | return $where; |
758 | 758 | } |
759 | 759 | |
760 | 760 | $s = trim($s); |
761 | - $s = wp_specialchars_decode($s ,ENT_QUOTES); |
|
762 | - $s_A = wp_specialchars_decode($s_A ,ENT_QUOTES); |
|
763 | - |
|
764 | - $where = ''; |
|
765 | - $better_search_terms = ''; |
|
766 | - if (isset($_REQUEST['stype'])) |
|
767 | - $post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype'])); |
|
768 | - else |
|
769 | - $post_types = 'gd_place'; |
|
770 | - |
|
771 | - if ($s != '') { |
|
772 | - $keywords = explode(" ", $s); |
|
773 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
774 | - foreach($keywords as $kkey=>$kword){ |
|
775 | - if(geodir_utf8_strlen($kword)<=$klimit){ |
|
776 | - unset($keywords[$kkey]); |
|
777 | - } |
|
778 | - } |
|
779 | - } |
|
761 | + $s = wp_specialchars_decode($s ,ENT_QUOTES); |
|
762 | + $s_A = wp_specialchars_decode($s_A ,ENT_QUOTES); |
|
763 | + |
|
764 | + $where = ''; |
|
765 | + $better_search_terms = ''; |
|
766 | + if (isset($_REQUEST['stype'])) |
|
767 | + $post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype'])); |
|
768 | + else |
|
769 | + $post_types = 'gd_place'; |
|
770 | + |
|
771 | + if ($s != '') { |
|
772 | + $keywords = explode(" ", $s); |
|
773 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
774 | + foreach($keywords as $kkey=>$kword){ |
|
775 | + if(geodir_utf8_strlen($kword)<=$klimit){ |
|
776 | + unset($keywords[$kkey]); |
|
777 | + } |
|
778 | + } |
|
779 | + } |
|
780 | 780 | |
781 | - if (!empty($keywords)) { |
|
782 | - foreach ($keywords as $keyword) { |
|
783 | - $keyword = trim($keyword); |
|
784 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
785 | - if ($keyword != '') { |
|
786 | - /** |
|
787 | - * Filter the search query keywords SQL. |
|
788 | - * |
|
789 | - * @since 1.5.9 |
|
790 | - * @package GeoDirectory |
|
791 | - * @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 . '%" )'`. |
|
792 | - * @param array $keywords The array of keywords for the query. |
|
793 | - * @param string $keyword The single keyword being searched. |
|
794 | - */ |
|
781 | + if (!empty($keywords)) { |
|
782 | + foreach ($keywords as $keyword) { |
|
783 | + $keyword = trim($keyword); |
|
784 | + $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
785 | + if ($keyword != '') { |
|
786 | + /** |
|
787 | + * Filter the search query keywords SQL. |
|
788 | + * |
|
789 | + * @since 1.5.9 |
|
790 | + * @package GeoDirectory |
|
791 | + * @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 . '%" )'`. |
|
792 | + * @param array $keywords The array of keywords for the query. |
|
793 | + * @param string $keyword The single keyword being searched. |
|
794 | + */ |
|
795 | 795 | $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); |
796 | - } |
|
797 | - } |
|
798 | - } |
|
799 | - } |
|
796 | + } |
|
797 | + } |
|
798 | + } |
|
799 | + } |
|
800 | 800 | |
801 | - /* get taxonomy */ |
|
802 | - $taxonomies = geodir_get_taxonomies($post_types, true); |
|
803 | - if($taxonomies) { |
|
804 | - $taxonomies = implode("','", $taxonomies); |
|
805 | - $taxonomies = "'" . $taxonomies . "'"; |
|
806 | - }else{$taxonomies='';} |
|
801 | + /* get taxonomy */ |
|
802 | + $taxonomies = geodir_get_taxonomies($post_types, true); |
|
803 | + if($taxonomies) { |
|
804 | + $taxonomies = implode("','", $taxonomies); |
|
805 | + $taxonomies = "'" . $taxonomies . "'"; |
|
806 | + }else{$taxonomies='';} |
|
807 | 807 | |
808 | - $content_where = $terms_where = ''; |
|
809 | - $terms_sql = ''; |
|
808 | + $content_where = $terms_where = ''; |
|
809 | + $terms_sql = ''; |
|
810 | 810 | if ($s != '') { |
811 | - /** |
|
812 | - * Filter the search query content where values. |
|
813 | - * |
|
814 | - * @since 1.5.0 |
|
815 | - * @package GeoDirectory |
|
816 | - * |
|
817 | - * @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%\") ") "`. |
|
818 | - */ |
|
819 | - $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%\") " ); |
|
820 | - /** |
|
821 | - * Filter the search query term values. |
|
822 | - * |
|
823 | - * @since 1.5.0 |
|
824 | - * @package GeoDirectory |
|
825 | - * |
|
826 | - * @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)) "`. |
|
827 | - */ |
|
828 | - $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)) " ); |
|
829 | - |
|
830 | - |
|
831 | - // get term sql |
|
832 | - $term_sql = "SELECT $wpdb->term_taxonomy.term_id, $wpdb->terms.name, $wpdb->term_taxonomy.taxonomy |
|
811 | + /** |
|
812 | + * Filter the search query content where values. |
|
813 | + * |
|
814 | + * @since 1.5.0 |
|
815 | + * @package GeoDirectory |
|
816 | + * |
|
817 | + * @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%\") ") "`. |
|
818 | + */ |
|
819 | + $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%\") " ); |
|
820 | + /** |
|
821 | + * Filter the search query term values. |
|
822 | + * |
|
823 | + * @since 1.5.0 |
|
824 | + * @package GeoDirectory |
|
825 | + * |
|
826 | + * @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)) "`. |
|
827 | + */ |
|
828 | + $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)) " ); |
|
829 | + |
|
830 | + |
|
831 | + // get term sql |
|
832 | + $term_sql = "SELECT $wpdb->term_taxonomy.term_id, $wpdb->terms.name, $wpdb->term_taxonomy.taxonomy |
|
833 | 833 | FROM $wpdb->term_taxonomy, $wpdb->terms, $wpdb->term_relationships |
834 | 834 | WHERE $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id |
835 | 835 | AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id |
@@ -837,46 +837,46 @@ discard block |
||
837 | 837 | $terms_where |
838 | 838 | GROUP BY $wpdb->term_taxonomy.term_id"; |
839 | 839 | |
840 | - $term_results = $wpdb->get_results( $term_sql ); |
|
841 | - $term_ids = array(); |
|
842 | - $terms_sql = ''; |
|
843 | - |
|
844 | - if ( ! empty( $term_results ) ) { |
|
845 | - foreach ( $term_results as $term_id ) { |
|
846 | - $term_ids[] = $term_id; |
|
847 | - } |
|
848 | - if ( ! empty( $term_ids ) ) { |
|
849 | - foreach ( $term_ids as $term ) { |
|
850 | - if ( $term->taxonomy == $post_types . '_tags' ) { |
|
851 | - $terms_sql .= $wpdb->prepare( " OR FIND_IN_SET(%s , " . $table . ".post_tags) ", $term->name ); |
|
852 | - } else { |
|
853 | - $terms_sql .= " OR FIND_IN_SET($term->term_id , " . $table . "." . $post_types . "category) "; |
|
854 | - } |
|
855 | - } |
|
856 | - } |
|
857 | - } |
|
840 | + $term_results = $wpdb->get_results( $term_sql ); |
|
841 | + $term_ids = array(); |
|
842 | + $terms_sql = ''; |
|
858 | 843 | |
859 | - } |
|
844 | + if ( ! empty( $term_results ) ) { |
|
845 | + foreach ( $term_results as $term_id ) { |
|
846 | + $term_ids[] = $term_id; |
|
847 | + } |
|
848 | + if ( ! empty( $term_ids ) ) { |
|
849 | + foreach ( $term_ids as $term ) { |
|
850 | + if ( $term->taxonomy == $post_types . '_tags' ) { |
|
851 | + $terms_sql .= $wpdb->prepare( " OR FIND_IN_SET(%s , " . $table . ".post_tags) ", $term->name ); |
|
852 | + } else { |
|
853 | + $terms_sql .= " OR FIND_IN_SET($term->term_id , " . $table . "." . $post_types . "category) "; |
|
854 | + } |
|
855 | + } |
|
856 | + } |
|
857 | + } |
|
860 | 858 | |
861 | - if ($snear != '') { |
|
859 | + } |
|
862 | 860 | |
861 | + if ($snear != '') { |
|
863 | 862 | |
864 | - if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) { |
|
865 | - $dist = $gd_session->get('near_me_range'); |
|
866 | - } |
|
867 | - $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69); |
|
868 | - $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69); |
|
869 | - $lat1 = $mylat - ($dist / 69); |
|
870 | - $lat2 = $mylat + ($dist / 69); |
|
871 | 863 | |
872 | - $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : ''; |
|
873 | - $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : ''; |
|
874 | - $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : ''; |
|
875 | - $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : ''; |
|
864 | + if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) { |
|
865 | + $dist = $gd_session->get('near_me_range'); |
|
866 | + } |
|
867 | + $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69); |
|
868 | + $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69); |
|
869 | + $lat1 = $mylat - ($dist / 69); |
|
870 | + $lat2 = $mylat + ($dist / 69); |
|
871 | + |
|
872 | + $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : ''; |
|
873 | + $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : ''; |
|
874 | + $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : ''; |
|
875 | + $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : ''; |
|
876 | 876 | |
877 | 877 | |
878 | 878 | $post_title_where = $s != "" ? "{$wpdb->posts}.post_title LIKE \"$s\"" : "1=1"; |
879 | - $where .= " AND ( ( $post_title_where $better_search_terms) |
|
879 | + $where .= " AND ( ( $post_title_where $better_search_terms) |
|
880 | 880 | $content_where |
881 | 881 | $terms_sql |
882 | 882 | ) |
@@ -885,35 +885,35 @@ discard block |
||
885 | 885 | AND ( " . $table . ".post_latitude between $rlat1 and $rlat2 ) |
886 | 886 | AND ( " . $table . ".post_longitude between $rlon1 and $rlon2 ) "; |
887 | 887 | |
888 | - if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') { |
|
889 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
890 | - $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; |
|
891 | - } |
|
888 | + if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') { |
|
889 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
890 | + $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; |
|
891 | + } |
|
892 | 892 | |
893 | - } else { |
|
893 | + } else { |
|
894 | 894 | |
895 | 895 | |
896 | - $post_title_where = $s != "" ? "{$wpdb->posts}.post_title LIKE \"$s\"" : "1=1"; |
|
897 | - $where .= " AND ( ( $post_title_where $better_search_terms) |
|
896 | + $post_title_where = $s != "" ? "{$wpdb->posts}.post_title LIKE \"$s\"" : "1=1"; |
|
897 | + $where .= " AND ( ( $post_title_where $better_search_terms) |
|
898 | 898 | $content_where |
899 | 899 | $terms_sql |
900 | 900 | ) |
901 | 901 | |
902 | 902 | AND $wpdb->posts.post_type in ('$post_types') |
903 | 903 | AND ($wpdb->posts.post_status = 'publish') "; |
904 | - } |
|
904 | + } |
|
905 | 905 | |
906 | 906 | ########### WPML ########### |
907 | - if ( geodir_wpml_is_post_type_translated( $post_types ) ) { |
|
907 | + if ( geodir_wpml_is_post_type_translated( $post_types ) ) { |
|
908 | 908 | $lang_code = ICL_LANGUAGE_CODE; |
909 | 909 | |
910 | 910 | if ($lang_code && $post_types) { |
911 | - $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') "; |
|
912 | - } |
|
913 | - } |
|
914 | - ########### WPML ########### |
|
911 | + $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') "; |
|
912 | + } |
|
913 | + } |
|
914 | + ########### WPML ########### |
|
915 | 915 | |
916 | - return $where; |
|
916 | + return $where; |
|
917 | 917 | } |
918 | 918 | |
919 | 919 | |
@@ -928,45 +928,45 @@ discard block |
||
928 | 928 | * @return string Modified where query string. |
929 | 929 | */ |
930 | 930 | function author_filter_where($where) { |
931 | - global $wpdb, $geodir_post_type, $table, $curr; |
|
931 | + global $wpdb, $geodir_post_type, $table, $curr; |
|
932 | 932 | |
933 | - $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); |
|
934 | - $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
933 | + $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); |
|
934 | + $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
935 | 935 | |
936 | - if (isset($_REQUEST['stype'])) { |
|
937 | - $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']); |
|
938 | - } else { |
|
939 | - $where = " AND $wpdb->posts.post_type IN ('gd_place') "; |
|
940 | - } |
|
936 | + if (isset($_REQUEST['stype'])) { |
|
937 | + $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']); |
|
938 | + } else { |
|
939 | + $where = " AND $wpdb->posts.post_type IN ('gd_place') "; |
|
940 | + } |
|
941 | 941 | |
942 | - if ($user_id > 0) { |
|
943 | - if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') { |
|
944 | - $user_fav_posts = geodir_get_user_favourites($user_id); |
|
945 | - $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1'; |
|
946 | - $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')"; |
|
947 | - } else |
|
948 | - $where .= " AND $wpdb->posts.post_author = $user_id"; |
|
949 | - |
|
950 | - if ($user_id == (int)get_current_user_id()) { |
|
951 | - $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') "; |
|
952 | - } else { |
|
953 | - $where .= " AND $wpdb->posts.post_status = 'publish' "; |
|
954 | - } |
|
955 | - } else { |
|
956 | - $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' "; |
|
957 | - } |
|
942 | + if ($user_id > 0) { |
|
943 | + if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') { |
|
944 | + $user_fav_posts = geodir_get_user_favourites($user_id); |
|
945 | + $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1'; |
|
946 | + $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')"; |
|
947 | + } else |
|
948 | + $where .= " AND $wpdb->posts.post_author = $user_id"; |
|
949 | + |
|
950 | + if ($user_id == (int)get_current_user_id()) { |
|
951 | + $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') "; |
|
952 | + } else { |
|
953 | + $where .= " AND $wpdb->posts.post_status = 'publish' "; |
|
954 | + } |
|
955 | + } else { |
|
956 | + $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' "; |
|
957 | + } |
|
958 | 958 | |
959 | - ########### WPML ########### |
|
960 | - if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) { |
|
961 | - $lang_code = ICL_LANGUAGE_CODE; |
|
962 | - if ($lang_code) { |
|
963 | - $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
964 | - } |
|
959 | + ########### WPML ########### |
|
960 | + if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) { |
|
961 | + $lang_code = ICL_LANGUAGE_CODE; |
|
962 | + if ($lang_code) { |
|
963 | + $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
964 | + } |
|
965 | 965 | |
966 | - } |
|
967 | - ########### WPML ########### |
|
966 | + } |
|
967 | + ########### WPML ########### |
|
968 | 968 | |
969 | - return $where; |
|
969 | + return $where; |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | /** |
@@ -981,11 +981,11 @@ discard block |
||
981 | 981 | */ |
982 | 982 | function geodir_filter_widget_join($join) |
983 | 983 | { |
984 | - global $wp_query, $table; |
|
985 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
986 | - $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
987 | - } |
|
988 | - return $join; |
|
984 | + global $wp_query, $table; |
|
985 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
986 | + $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
987 | + } |
|
988 | + return $join; |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | /** |
@@ -1000,43 +1000,43 @@ discard block |
||
1000 | 1000 | */ |
1001 | 1001 | function geodir_filter_widget_where($where) |
1002 | 1002 | { |
1003 | - global $wp_query, $table; |
|
1004 | - if (!empty($wp_query->query['show_featured_only'])) { |
|
1005 | - $where .= " AND " . $table . ".is_featured = '1'"; |
|
1006 | - } |
|
1007 | - if (!empty($wp_query->query['show_special_only'])) { |
|
1008 | - $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
1009 | - } |
|
1010 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
1011 | - $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
1012 | - } |
|
1013 | - if (!empty($wp_query->query['with_videos_only'])) { |
|
1014 | - $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
1015 | - } |
|
1016 | - return $where; |
|
1003 | + global $wp_query, $table; |
|
1004 | + if (!empty($wp_query->query['show_featured_only'])) { |
|
1005 | + $where .= " AND " . $table . ".is_featured = '1'"; |
|
1006 | + } |
|
1007 | + if (!empty($wp_query->query['show_special_only'])) { |
|
1008 | + $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
1009 | + } |
|
1010 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
1011 | + $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
1012 | + } |
|
1013 | + if (!empty($wp_query->query['with_videos_only'])) { |
|
1014 | + $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
1015 | + } |
|
1016 | + return $where; |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | |
1020 | 1020 | function geodir_related_posts_fields($fields) { |
1021 | - global $wp_query, $wpdb, $table, $post; |
|
1021 | + global $wp_query, $wpdb, $table, $post; |
|
1022 | 1022 | |
1023 | - $fields .= ", " . $table . ".* "; |
|
1023 | + $fields .= ", " . $table . ".* "; |
|
1024 | 1024 | |
1025 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
1025 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
1026 | 1026 | |
1027 | - $mylat = $post->post_latitude; |
|
1028 | - $mylon = $post->post_longitude; |
|
1027 | + $mylat = $post->post_latitude; |
|
1028 | + $mylon = $post->post_longitude; |
|
1029 | 1029 | |
1030 | - $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 "; |
|
1031 | - return $fields; |
|
1030 | + $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 "; |
|
1031 | + return $fields; |
|
1032 | 1032 | } |
1033 | 1033 | function geodir_related_posts_fields_filter($query) { |
1034 | - if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
1035 | - && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
|
1036 | - && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
|
1037 | - ) { |
|
1038 | - add_filter('posts_fields', 'geodir_related_posts_fields', 1); |
|
1039 | - } |
|
1034 | + if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
1035 | + && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
|
1036 | + && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
|
1037 | + ) { |
|
1038 | + add_filter('posts_fields', 'geodir_related_posts_fields', 1); |
|
1039 | + } |
|
1040 | 1040 | } |
1041 | 1041 | add_action('pre_get_posts', 'geodir_related_posts_fields_filter', 1); |
1042 | 1042 | |
@@ -1051,30 +1051,30 @@ discard block |
||
1051 | 1051 | * @return string|null If field exists in table returns order by clause else returns empty. |
1052 | 1052 | */ |
1053 | 1053 | function geodir_prepare_custom_sorting( $sorting, $table ) { |
1054 | - $orderby = ''; |
|
1054 | + $orderby = ''; |
|
1055 | 1055 | |
1056 | - if ( empty( $sorting ) || empty( $table ) ) { |
|
1057 | - return $orderby; |
|
1058 | - } |
|
1056 | + if ( empty( $sorting ) || empty( $table ) ) { |
|
1057 | + return $orderby; |
|
1058 | + } |
|
1059 | 1059 | |
1060 | - if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) { |
|
1061 | - $sorting_array = explode( '_', $sorting ); |
|
1060 | + if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) { |
|
1061 | + $sorting_array = explode( '_', $sorting ); |
|
1062 | 1062 | |
1063 | - if ( ( $count = count( $sorting_array ) ) > 1 ) { |
|
1064 | - $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
1065 | - array_pop( $sorting_array ); |
|
1063 | + if ( ( $count = count( $sorting_array ) ) > 1 ) { |
|
1064 | + $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
1065 | + array_pop( $sorting_array ); |
|
1066 | 1066 | |
1067 | - if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) { |
|
1068 | - $sort_by = implode( '_', $sorting_array ); |
|
1067 | + if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) { |
|
1068 | + $sort_by = implode( '_', $sorting_array ); |
|
1069 | 1069 | |
1070 | - if ( geodir_column_exist( $table, $sort_by ) ) { |
|
1071 | - $orderby = $table . "." . $sort_by . " " . $order; |
|
1072 | - } |
|
1073 | - } |
|
1074 | - } |
|
1075 | - } |
|
1070 | + if ( geodir_column_exist( $table, $sort_by ) ) { |
|
1071 | + $orderby = $table . "." . $sort_by . " " . $order; |
|
1072 | + } |
|
1073 | + } |
|
1074 | + } |
|
1075 | + } |
|
1076 | 1076 | |
1077 | - return $orderby; |
|
1077 | + return $orderby; |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | /** |
@@ -1094,21 +1094,21 @@ discard block |
||
1094 | 1094 | * @return string Modified fields SQL. |
1095 | 1095 | */ |
1096 | 1096 | function geodir_search_widget_location_filter_fields( $fields, $table, $post_type ) { |
1097 | - global $wpdb, $gd_query_args_widgets, $snear, $gd_session; |
|
1097 | + global $wpdb, $gd_query_args_widgets, $snear, $gd_session; |
|
1098 | 1098 | |
1099 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1100 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1099 | + if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1100 | + $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1101 | 1101 | |
1102 | - if ( $location_allowed && strpos( strtolower( $fields ), ' as distance ' ) === false && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1103 | - $latitude = sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
1104 | - $longitude = sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
1105 | - $radius = geodir_getDistanceRadius( get_option( 'geodir_search_dist_1' ) ); |
|
1102 | + if ( $location_allowed && strpos( strtolower( $fields ), ' as distance ' ) === false && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1103 | + $latitude = sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
1104 | + $longitude = sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
1105 | + $radius = geodir_getDistanceRadius( get_option( 'geodir_search_dist_1' ) ); |
|
1106 | 1106 | |
1107 | - $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 ); |
|
1108 | - } |
|
1109 | - } |
|
1107 | + $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 ); |
|
1108 | + } |
|
1109 | + } |
|
1110 | 1110 | |
1111 | - return $fields; |
|
1111 | + return $fields; |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | /** |
@@ -1127,17 +1127,17 @@ discard block |
||
1127 | 1127 | * @return string Modified fields SQL. |
1128 | 1128 | */ |
1129 | 1129 | function geodir_search_widget_location_filter_orderby( $orderby, $table, $post_type ) { |
1130 | - global $gd_query_args_widgets, $snear, $gd_session; |
|
1130 | + global $gd_query_args_widgets, $snear, $gd_session; |
|
1131 | 1131 | |
1132 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1133 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1132 | + if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1133 | + $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1134 | 1134 | |
1135 | - if ( $location_allowed && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1136 | - $orderby = "distance ASC, " . $orderby; |
|
1137 | - } |
|
1138 | - } |
|
1135 | + if ( $location_allowed && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1136 | + $orderby = "distance ASC, " . $orderby; |
|
1137 | + } |
|
1138 | + } |
|
1139 | 1139 | |
1140 | - return $orderby; |
|
1140 | + return $orderby; |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | /** |
@@ -1148,23 +1148,23 @@ discard block |
||
1148 | 1148 | * @return string Filtered url. |
1149 | 1149 | */ |
1150 | 1150 | function geodir_search_page_base_url() { |
1151 | - if ( function_exists( 'geodir_location_geo_home_link' ) ) { |
|
1152 | - remove_filter( 'home_url', 'geodir_location_geo_home_link', 100000 ); |
|
1153 | - } |
|
1151 | + if ( function_exists( 'geodir_location_geo_home_link' ) ) { |
|
1152 | + remove_filter( 'home_url', 'geodir_location_geo_home_link', 100000 ); |
|
1153 | + } |
|
1154 | 1154 | |
1155 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX && geodir_is_wpml() ) { |
|
1156 | - $url = icl_get_home_url(); |
|
1157 | - } else { |
|
1158 | - $url = get_home_url(); |
|
1159 | - } |
|
1155 | + if ( defined( 'DOING_AJAX' ) && DOING_AJAX && geodir_is_wpml() ) { |
|
1156 | + $url = icl_get_home_url(); |
|
1157 | + } else { |
|
1158 | + $url = get_home_url(); |
|
1159 | + } |
|
1160 | 1160 | |
1161 | - $url = trailingslashit( $url ); |
|
1161 | + $url = trailingslashit( $url ); |
|
1162 | 1162 | |
1163 | - if ( function_exists( 'geodir_location_geo_home_link' ) ) { |
|
1164 | - add_filter( 'home_url', 'geodir_location_geo_home_link', 100000, 2 ); |
|
1165 | - } |
|
1163 | + if ( function_exists( 'geodir_location_geo_home_link' ) ) { |
|
1164 | + add_filter( 'home_url', 'geodir_location_geo_home_link', 100000, 2 ); |
|
1165 | + } |
|
1166 | 1166 | |
1167 | - return apply_filters( 'geodir_search_page_base_url', $url ); |
|
1167 | + return apply_filters( 'geodir_search_page_base_url', $url ); |
|
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | /** |
@@ -1175,7 +1175,7 @@ discard block |
||
1175 | 1175 | function geodir_jetpack_fix_post_types_search(){ |
1176 | 1176 | if ( defined( 'JETPACK__VERSION' ) && ! empty( $_REQUEST['geodir_search'] ) ) { |
1177 | 1177 | add_filter( 'jetpack_search_should_handle_query', '__return_false', 999, 1 ); |
1178 | - } |
|
1178 | + } |
|
1179 | 1179 | } |
1180 | 1180 | add_action( 'plugins_loaded','geodir_jetpack_fix_post_types_search', 10 ); |
1181 | 1181 |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @global string $s_A Extra parameters. |
66 | 66 | * @global string $s_SA Extra parameters. |
67 | 67 | */ |
68 | -function set_listing_request($query ) |
|
68 | +function set_listing_request($query) |
|
69 | 69 | { |
70 | 70 | global $wp_query, $wpdb, $geodir_post_type, $table, $dist, $mylat, $mylon, $s, $snear, $s, $s_A, $s_SA; |
71 | 71 | |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | } // Distance |
100 | 100 | |
101 | 101 | if (isset($_REQUEST['sgeo_lat'])) { |
102 | - $mylat = (float)esc_attr($_REQUEST['sgeo_lat']); |
|
102 | + $mylat = (float) esc_attr($_REQUEST['sgeo_lat']); |
|
103 | 103 | } else { |
104 | - $mylat = (float)geodir_get_current_city_lat(); |
|
104 | + $mylat = (float) geodir_get_current_city_lat(); |
|
105 | 105 | } // Latitude |
106 | 106 | |
107 | 107 | if (isset($_REQUEST['sgeo_lon'])) { |
108 | - $mylon = (float)esc_attr($_REQUEST['sgeo_lon']); |
|
108 | + $mylon = (float) esc_attr($_REQUEST['sgeo_lon']); |
|
109 | 109 | } else { |
110 | - $mylon = (float)geodir_get_current_city_lng(); |
|
110 | + $mylon = (float) geodir_get_current_city_lng(); |
|
111 | 111 | } // Distance |
112 | 112 | |
113 | 113 | if (isset($_REQUEST['snear'])) { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | if ($snear == 'NEAR ME') { |
122 | 122 | $ip = $_SERVER['REMOTE_ADDR']; |
123 | - $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip)); |
|
123 | + $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip)); |
|
124 | 124 | $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude])); |
125 | 125 | $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude])); |
126 | 126 | } |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | $s_AA = str_replace(" ", "", $s); |
131 | 131 | $s_A = explode(",", $s_AA); |
132 | 132 | $s_A = implode('","', $s_A); |
133 | - $s_A = '"' . $s_A . '"'; |
|
133 | + $s_A = '"'.$s_A.'"'; |
|
134 | 134 | } else { |
135 | - $s_A = '"' . $s . '"'; |
|
135 | + $s_A = '"'.$s.'"'; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | if (strstr($s, ' ')) { |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | } |
194 | 194 | if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) { |
195 | 195 | |
196 | - $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
196 | + $table = $plugin_prefix.$geodir_post_type.'_detail'; |
|
197 | 197 | |
198 | 198 | add_filter('posts_fields', 'geodir_posts_fields', 1); |
199 | 199 | add_filter('posts_join', 'geodir_posts_join', 1); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; |
234 | 234 | |
235 | 235 | // Filter-Location-Manager to add location table. |
236 | - $fields .= ", " . $table . ".* "; |
|
236 | + $fields .= ", ".$table.".* "; |
|
237 | 237 | |
238 | 238 | if ($snear != '' || $gd_session->get('all_near_me')) { |
239 | 239 | $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
@@ -243,16 +243,16 @@ discard block |
||
243 | 243 | $mylon = $gd_session->get('user_lon'); |
244 | 244 | } |
245 | 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 "; |
|
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 | 247 | } |
248 | 248 | |
249 | 249 | global $s; |
250 | 250 | if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
251 | 251 | $keywords = explode(" ", $s); |
252 | 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){ |
|
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 | 256 | unset($keywords[$kkey]); |
257 | 257 | } |
258 | 258 | } |
@@ -270,24 +270,24 @@ discard block |
||
270 | 270 | $count = 0; |
271 | 271 | foreach ($keywords as $keyword) { |
272 | 272 | $keyword = trim($keyword); |
273 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
273 | + $keyword = wp_specialchars_decode($keyword, ENT_QUOTES); |
|
274 | 274 | $count++; |
275 | 275 | if ($count < count($keywords)) { |
276 | 276 | // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; |
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 . " "; |
|
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 | 278 | } else { |
279 | 279 | //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; |
280 | - $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) "; |
|
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 | 281 | } |
282 | 282 | } |
283 | - $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; |
|
283 | + $gd_titlematch_part .= "THEN 1 ELSE 0 END AS ".$part.","; |
|
284 | 284 | } |
285 | 285 | } else { |
286 | 286 | $gd_titlematch_part = ""; |
287 | 287 | } |
288 | - $s = stripslashes_deep( $s ); |
|
289 | - $s = wp_specialchars_decode($s,ENT_QUOTES); |
|
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 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,'%>' . $s . '%','% ' . $s . ',')); |
|
288 | + $s = stripslashes_deep($s); |
|
289 | + $s = wp_specialchars_decode($s, ENT_QUOTES); |
|
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 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, '%>'.$s.'%', '% '.$s.',')); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | return $fields; |
@@ -311,18 +311,18 @@ discard block |
||
311 | 311 | |
312 | 312 | ########### WPML ########### |
313 | 313 | |
314 | - if ( geodir_wpml_is_post_type_translated( $geodir_post_type ) ) { |
|
314 | + if (geodir_wpml_is_post_type_translated($geodir_post_type)) { |
|
315 | 315 | global $sitepress; |
316 | 316 | $lang_code = ICL_LANGUAGE_CODE; |
317 | 317 | $default_lang_code = $sitepress->get_default_language(); |
318 | 318 | if ($lang_code) { |
319 | - $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID"; |
|
319 | + $join .= "JOIN ".$table_prefix."icl_translations icl_t ON icl_t.element_id = ".$table_prefix."posts.ID"; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | } |
323 | 323 | ########### WPML ########### |
324 | 324 | |
325 | - $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID) "; |
|
325 | + $join .= " INNER JOIN ".$table." ON (".$table.".post_id = $wpdb->posts.ID) "; |
|
326 | 326 | //===old code start |
327 | 327 | //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id) " ;//===old code end |
328 | 328 | |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | $sort_by = 'az'; |
392 | 392 | } |
393 | 393 | |
394 | - if ($snear != '' && $sort_by!='farthest') { |
|
394 | + if ($snear != '' && $sort_by != 'farthest') { |
|
395 | 395 | $sort_by = 'nearest'; |
396 | 396 | } |
397 | 397 | } |
@@ -405,20 +405,20 @@ discard block |
||
405 | 405 | break; |
406 | 406 | case 'low_review': |
407 | 407 | case 'rating_count_asc': |
408 | - $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, "; |
|
408 | + $orderby = $table.".rating_count ASC, ".$table.".overall_rating ASC, "; |
|
409 | 409 | break; |
410 | 410 | case 'high_review': |
411 | 411 | case 'rating_count_desc': |
412 | - $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, "; |
|
412 | + $orderby = $table.".rating_count DESC, ".$table.".overall_rating DESC, "; |
|
413 | 413 | break; |
414 | 414 | case 'low_rating': |
415 | - $orderby = "( " . $table . ".overall_rating ) ASC, " . $table . ".rating_count ASC, "; |
|
415 | + $orderby = "( ".$table.".overall_rating ) ASC, ".$table.".rating_count ASC, "; |
|
416 | 416 | break; |
417 | 417 | case 'high_rating': |
418 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
418 | + $orderby = " ".$table.".overall_rating DESC, ".$table.".rating_count DESC, "; |
|
419 | 419 | break; |
420 | 420 | case 'featured': |
421 | - $orderby = $table . ".is_featured asc, "; |
|
421 | + $orderby = $table.".is_featured asc, "; |
|
422 | 422 | break; |
423 | 423 | case 'nearest': |
424 | 424 | $orderby = " distance asc, "; |
@@ -434,10 +434,10 @@ discard block |
||
434 | 434 | break; |
435 | 435 | // sort by rating |
436 | 436 | case 'overall_rating_desc': |
437 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
437 | + $orderby = " ".$table.".overall_rating DESC, ".$table.".rating_count DESC, "; |
|
438 | 438 | break; |
439 | 439 | case 'overall_rating_asc': |
440 | - $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, "; |
|
440 | + $orderby = " ".$table.".overall_rating ASC, ".$table.".rating_count ASC, "; |
|
441 | 441 | break; |
442 | 442 | default: |
443 | 443 | |
@@ -458,24 +458,24 @@ discard block |
||
458 | 458 | |
459 | 459 | if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
460 | 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){ |
|
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 | 464 | unset($keywords[$kkey]); |
465 | 465 | } |
466 | 466 | } |
467 | 467 | } |
468 | 468 | if ($sort_by == 'nearest' || $sort_by == 'farthest') { |
469 | 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, "; |
|
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 | 471 | } else { |
472 | - $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
472 | + $orderby = $orderby." ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
473 | 473 | } |
474 | 474 | } else { |
475 | 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; |
|
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 | 477 | } else { |
478 | - $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby; |
|
478 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, ".$orderby; |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | } |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | */ |
491 | 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 | 495 | return $orderby; |
496 | 496 | } |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | |
513 | 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 | 517 | $sort_array = explode('_', $sort_by); |
518 | 518 | |
@@ -522,48 +522,48 @@ discard block |
||
522 | 522 | |
523 | 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 | 527 | switch ($sort_by): |
528 | 528 | |
529 | 529 | case 'post_date': |
530 | 530 | case 'comment_count': |
531 | 531 | |
532 | - $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", "; |
|
532 | + $orderby = "$wpdb->posts.".$sort_by." ".$order.", ".$table.".overall_rating ".$order.", "; |
|
533 | 533 | break; |
534 | 534 | |
535 | 535 | case 'distance': |
536 | - $orderby = $sort_by . " " . $order . ", "; |
|
536 | + $orderby = $sort_by." ".$order.", "; |
|
537 | 537 | break; |
538 | 538 | |
539 | 539 | |
540 | 540 | // sort by rating |
541 | 541 | case 'overall_rating': |
542 | 542 | |
543 | - $use_bayesian = apply_filters('gd_use_bayesian',true,$table); |
|
543 | + $use_bayesian = apply_filters('gd_use_bayesian', true, $table); |
|
544 | 544 | $avg_rating = 0; |
545 | - if($use_bayesian){ |
|
546 | - $avg_num_votes = get_transient( 'gd_avg_num_votes_'.$table ); |
|
547 | - if(!$avg_num_votes){ |
|
545 | + if ($use_bayesian) { |
|
546 | + $avg_num_votes = get_transient('gd_avg_num_votes_'.$table); |
|
547 | + if (!$avg_num_votes) { |
|
548 | 548 | $avg_num_votes = $wpdb->get_var("SELECT SUM(rating_count) FROM $table"); |
549 | - if($avg_num_votes){ |
|
549 | + if ($avg_num_votes) { |
|
550 | 550 | |
551 | - $avg_rating = get_transient( 'gd_avg_rating_'.$table ); |
|
552 | - if(!$avg_rating){ |
|
553 | - $avg_rating = $wpdb->get_var("SELECT SUM(overall_rating) FROM $table")/$avg_num_votes; |
|
551 | + $avg_rating = get_transient('gd_avg_rating_'.$table); |
|
552 | + if (!$avg_rating) { |
|
553 | + $avg_rating = $wpdb->get_var("SELECT SUM(overall_rating) FROM $table") / $avg_num_votes; |
|
554 | 554 | } |
555 | - set_transient( 'gd_avg_num_votes_'.$table, $avg_num_votes, 12 * HOUR_IN_SECONDS ); |
|
556 | - set_transient( 'gd_avg_rating_'.$table, $avg_rating , 12 * HOUR_IN_SECONDS ); |
|
555 | + set_transient('gd_avg_num_votes_'.$table, $avg_num_votes, 12 * HOUR_IN_SECONDS); |
|
556 | + set_transient('gd_avg_rating_'.$table, $avg_rating, 12 * HOUR_IN_SECONDS); |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
560 | - if(!$avg_num_votes){ $avg_num_votes = 0;} |
|
560 | + if (!$avg_num_votes) { $avg_num_votes = 0; } |
|
561 | 561 | |
562 | - $orderby = " (( $avg_num_votes * $avg_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating )) / ( $avg_num_votes + " . $table . ".rating_count ) $order , "; |
|
562 | + $orderby = " (( $avg_num_votes * $avg_rating ) + (".$table.".rating_count * ".$table.".overall_rating )) / ( $avg_num_votes + ".$table.".rating_count ) $order , "; |
|
563 | 563 | |
564 | 564 | //$orderby = " ( " . $table . ".rating_count * " . $table . ".overall_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating ) / ( " . $table . ".rating_count + " . $table . ".rating_count ) $order , "; // seems to work mostly with no extra overheads |
565 | - }else{ |
|
566 | - $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
565 | + } else { |
|
566 | + $orderby = " ".$table.".".$sort_by." ".$order.", ".$table.".rating_count ".$order.", "; |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | break; |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | |
572 | 572 | default: |
573 | 573 | if (geodir_column_exist($table, $sort_by)) { |
574 | - $orderby = $table . "." . $sort_by . " " . $order . ", "; |
|
574 | + $orderby = $table.".".$sort_by." ".$order.", "; |
|
575 | 575 | } |
576 | 576 | break; |
577 | 577 | |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | add_filter('posts_where', 'searching_filter_where', 1); |
612 | 612 | |
613 | 613 | add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
614 | - add_filter( 'posts_where', 'geodir_posts_having', 10000, 2 ); // make sure its the last WHERE param |
|
614 | + add_filter('posts_where', 'geodir_posts_having', 10000, 2); // make sure its the last WHERE param |
|
615 | 615 | |
616 | 616 | } elseif (geodir_is_page('author')) { |
617 | 617 | |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | } |
621 | 621 | |
622 | 622 | //if (!geodir_is_page('detail')) |
623 | - add_filter('posts_where', 'geodir_default_where', 1);/**/ |
|
623 | + add_filter('posts_where', 'geodir_default_where', 1); /**/ |
|
624 | 624 | |
625 | 625 | //add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts |
626 | 626 | |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | $q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
692 | 692 | //echo '##########'.$q_post_type; |
693 | 693 | if ($lang_code && $q_post_type && geodir_wpml_is_post_type_translated($q_post_type)) { |
694 | - $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') "; |
|
694 | + $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_".$q_post_type."') "; |
|
695 | 695 | //$where .= " AND icl_t.language_code = '$lang_code' "; |
696 | 696 | } |
697 | 697 | |
@@ -758,8 +758,8 @@ discard block |
||
758 | 758 | } |
759 | 759 | |
760 | 760 | $s = trim($s); |
761 | - $s = wp_specialchars_decode($s ,ENT_QUOTES); |
|
762 | - $s_A = wp_specialchars_decode($s_A ,ENT_QUOTES); |
|
761 | + $s = wp_specialchars_decode($s, ENT_QUOTES); |
|
762 | + $s_A = wp_specialchars_decode($s_A, ENT_QUOTES); |
|
763 | 763 | |
764 | 764 | $where = ''; |
765 | 765 | $better_search_terms = ''; |
@@ -770,9 +770,9 @@ discard block |
||
770 | 770 | |
771 | 771 | if ($s != '') { |
772 | 772 | $keywords = explode(" ", $s); |
773 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
774 | - foreach($keywords as $kkey=>$kword){ |
|
775 | - if(geodir_utf8_strlen($kword)<=$klimit){ |
|
773 | + if (is_array($keywords) && $klimit = get_option('geodir_search_word_limit')) { |
|
774 | + foreach ($keywords as $kkey=>$kword) { |
|
775 | + if (geodir_utf8_strlen($kword) <= $klimit) { |
|
776 | 776 | unset($keywords[$kkey]); |
777 | 777 | } |
778 | 778 | } |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | if (!empty($keywords)) { |
782 | 782 | foreach ($keywords as $keyword) { |
783 | 783 | $keyword = trim($keyword); |
784 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
784 | + $keyword = wp_specialchars_decode($keyword, ENT_QUOTES); |
|
785 | 785 | if ($keyword != '') { |
786 | 786 | /** |
787 | 787 | * Filter the search query keywords SQL. |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | * @param array $keywords The array of keywords for the query. |
793 | 793 | * @param string $keyword The single keyword being searched. |
794 | 794 | */ |
795 | - $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); |
|
795 | + $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); |
|
796 | 796 | } |
797 | 797 | } |
798 | 798 | } |
@@ -800,13 +800,13 @@ discard block |
||
800 | 800 | |
801 | 801 | /* get taxonomy */ |
802 | 802 | $taxonomies = geodir_get_taxonomies($post_types, true); |
803 | - if($taxonomies) { |
|
803 | + if ($taxonomies) { |
|
804 | 804 | $taxonomies = implode("','", $taxonomies); |
805 | - $taxonomies = "'" . $taxonomies . "'"; |
|
806 | - }else{$taxonomies='';} |
|
805 | + $taxonomies = "'".$taxonomies."'"; |
|
806 | + } else {$taxonomies = ''; } |
|
807 | 807 | |
808 | 808 | $content_where = $terms_where = ''; |
809 | - $terms_sql = ''; |
|
809 | + $terms_sql = ''; |
|
810 | 810 | if ($s != '') { |
811 | 811 | /** |
812 | 812 | * Filter the search query content where values. |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | * |
817 | 817 | * @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%\") ") "`. |
818 | 818 | */ |
819 | - $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%\") " ); |
|
819 | + $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%\") "); |
|
820 | 820 | /** |
821 | 821 | * Filter the search query term values. |
822 | 822 | * |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | * |
826 | 826 | * @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)) "`. |
827 | 827 | */ |
828 | - $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)) " ); |
|
828 | + $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)) "); |
|
829 | 829 | |
830 | 830 | |
831 | 831 | // get term sql |
@@ -837,20 +837,20 @@ discard block |
||
837 | 837 | $terms_where |
838 | 838 | GROUP BY $wpdb->term_taxonomy.term_id"; |
839 | 839 | |
840 | - $term_results = $wpdb->get_results( $term_sql ); |
|
840 | + $term_results = $wpdb->get_results($term_sql); |
|
841 | 841 | $term_ids = array(); |
842 | 842 | $terms_sql = ''; |
843 | 843 | |
844 | - if ( ! empty( $term_results ) ) { |
|
845 | - foreach ( $term_results as $term_id ) { |
|
844 | + if (!empty($term_results)) { |
|
845 | + foreach ($term_results as $term_id) { |
|
846 | 846 | $term_ids[] = $term_id; |
847 | 847 | } |
848 | - if ( ! empty( $term_ids ) ) { |
|
849 | - foreach ( $term_ids as $term ) { |
|
850 | - if ( $term->taxonomy == $post_types . '_tags' ) { |
|
851 | - $terms_sql .= $wpdb->prepare( " OR FIND_IN_SET(%s , " . $table . ".post_tags) ", $term->name ); |
|
848 | + if (!empty($term_ids)) { |
|
849 | + foreach ($term_ids as $term) { |
|
850 | + if ($term->taxonomy == $post_types.'_tags') { |
|
851 | + $terms_sql .= $wpdb->prepare(" OR FIND_IN_SET(%s , ".$table.".post_tags) ", $term->name); |
|
852 | 852 | } else { |
853 | - $terms_sql .= " OR FIND_IN_SET($term->term_id , " . $table . "." . $post_types . "category) "; |
|
853 | + $terms_sql .= " OR FIND_IN_SET($term->term_id , ".$table.".".$post_types."category) "; |
|
854 | 854 | } |
855 | 855 | } |
856 | 856 | } |
@@ -882,12 +882,12 @@ discard block |
||
882 | 882 | ) |
883 | 883 | AND $wpdb->posts.post_type in ('{$post_types}') |
884 | 884 | AND ($wpdb->posts.post_status = 'publish') |
885 | - AND ( " . $table . ".post_latitude between $rlat1 and $rlat2 ) |
|
886 | - AND ( " . $table . ".post_longitude between $rlon1 and $rlon2 ) "; |
|
885 | + AND ( ".$table.".post_latitude between $rlat1 and $rlat2 ) |
|
886 | + AND ( ".$table.".post_longitude between $rlon1 and $rlon2 ) "; |
|
887 | 887 | |
888 | 888 | if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') { |
889 | 889 | $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
890 | - $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; |
|
890 | + $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; |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | } else { |
@@ -904,11 +904,11 @@ discard block |
||
904 | 904 | } |
905 | 905 | |
906 | 906 | ########### WPML ########### |
907 | - if ( geodir_wpml_is_post_type_translated( $post_types ) ) { |
|
907 | + if (geodir_wpml_is_post_type_translated($post_types)) { |
|
908 | 908 | $lang_code = ICL_LANGUAGE_CODE; |
909 | 909 | |
910 | 910 | if ($lang_code && $post_types) { |
911 | - $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') "; |
|
911 | + $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_".$post_types."') "; |
|
912 | 912 | } |
913 | 913 | } |
914 | 914 | ########### WPML ########### |
@@ -931,10 +931,10 @@ discard block |
||
931 | 931 | global $wpdb, $geodir_post_type, $table, $curr; |
932 | 932 | |
933 | 933 | $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); |
934 | - $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
934 | + $user_id = !empty($curauth->ID) ? (int) $curauth->ID : 0; |
|
935 | 935 | |
936 | 936 | if (isset($_REQUEST['stype'])) { |
937 | - $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']); |
|
937 | + $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ", $_REQUEST['stype']); |
|
938 | 938 | } else { |
939 | 939 | $where = " AND $wpdb->posts.post_type IN ('gd_place') "; |
940 | 940 | } |
@@ -947,7 +947,7 @@ discard block |
||
947 | 947 | } else |
948 | 948 | $where .= " AND $wpdb->posts.post_author = $user_id"; |
949 | 949 | |
950 | - if ($user_id == (int)get_current_user_id()) { |
|
950 | + if ($user_id == (int) get_current_user_id()) { |
|
951 | 951 | $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') "; |
952 | 952 | } else { |
953 | 953 | $where .= " AND $wpdb->posts.post_status = 'publish' "; |
@@ -960,7 +960,7 @@ discard block |
||
960 | 960 | if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) { |
961 | 961 | $lang_code = ICL_LANGUAGE_CODE; |
962 | 962 | if ($lang_code) { |
963 | - $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
963 | + $where .= " AND icl_t.language_code='".$lang_code."' "; |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | } |
@@ -983,7 +983,7 @@ discard block |
||
983 | 983 | { |
984 | 984 | global $wp_query, $table; |
985 | 985 | if (!empty($wp_query->query['with_pics_only'])) { |
986 | - $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
986 | + $join .= " LEFT JOIN ".GEODIR_ATTACHMENT_TABLE." ON ( ".GEODIR_ATTACHMENT_TABLE.".post_id=".$table.".post_id AND ".GEODIR_ATTACHMENT_TABLE.".mime_type LIKE '%image%' )"; |
|
987 | 987 | } |
988 | 988 | return $join; |
989 | 989 | } |
@@ -1002,16 +1002,16 @@ discard block |
||
1002 | 1002 | { |
1003 | 1003 | global $wp_query, $table; |
1004 | 1004 | if (!empty($wp_query->query['show_featured_only'])) { |
1005 | - $where .= " AND " . $table . ".is_featured = '1'"; |
|
1005 | + $where .= " AND ".$table.".is_featured = '1'"; |
|
1006 | 1006 | } |
1007 | 1007 | if (!empty($wp_query->query['show_special_only'])) { |
1008 | - $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
1008 | + $where .= " AND ( ".$table.".geodir_special_offers != '' AND ".$table.".geodir_special_offers IS NOT NULL )"; |
|
1009 | 1009 | } |
1010 | 1010 | if (!empty($wp_query->query['with_pics_only'])) { |
1011 | - $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
1011 | + $where .= " AND ".GEODIR_ATTACHMENT_TABLE.".ID IS NOT NULL GROUP BY ".$table.".post_id"; |
|
1012 | 1012 | } |
1013 | 1013 | if (!empty($wp_query->query['with_videos_only'])) { |
1014 | - $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
1014 | + $where .= " AND ( ".$table.".geodir_video != '' AND ".$table.".geodir_video IS NOT NULL )"; |
|
1015 | 1015 | } |
1016 | 1016 | return $where; |
1017 | 1017 | } |
@@ -1020,18 +1020,18 @@ discard block |
||
1020 | 1020 | function geodir_related_posts_fields($fields) { |
1021 | 1021 | global $wp_query, $wpdb, $table, $post; |
1022 | 1022 | |
1023 | - $fields .= ", " . $table . ".* "; |
|
1023 | + $fields .= ", ".$table.".* "; |
|
1024 | 1024 | |
1025 | 1025 | $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
1026 | 1026 | |
1027 | 1027 | $mylat = $post->post_latitude; |
1028 | 1028 | $mylon = $post->post_longitude; |
1029 | 1029 | |
1030 | - $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 "; |
|
1030 | + $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 "; |
|
1031 | 1031 | return $fields; |
1032 | 1032 | } |
1033 | 1033 | function geodir_related_posts_fields_filter($query) { |
1034 | - if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
1034 | + if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
1035 | 1035 | && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
1036 | 1036 | && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
1037 | 1037 | ) { |
@@ -1050,25 +1050,25 @@ discard block |
||
1050 | 1050 | * @param string $table Listing table name. |
1051 | 1051 | * @return string|null If field exists in table returns order by clause else returns empty. |
1052 | 1052 | */ |
1053 | -function geodir_prepare_custom_sorting( $sorting, $table ) { |
|
1053 | +function geodir_prepare_custom_sorting($sorting, $table) { |
|
1054 | 1054 | $orderby = ''; |
1055 | 1055 | |
1056 | - if ( empty( $sorting ) || empty( $table ) ) { |
|
1056 | + if (empty($sorting) || empty($table)) { |
|
1057 | 1057 | return $orderby; |
1058 | 1058 | } |
1059 | 1059 | |
1060 | - if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) { |
|
1061 | - $sorting_array = explode( '_', $sorting ); |
|
1060 | + if (strpos(strtoupper($sorting), '_ASC') !== false || strpos(strtoupper($sorting), '_DESC') !== false) { |
|
1061 | + $sorting_array = explode('_', $sorting); |
|
1062 | 1062 | |
1063 | - if ( ( $count = count( $sorting_array ) ) > 1 ) { |
|
1064 | - $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
1065 | - array_pop( $sorting_array ); |
|
1063 | + if (($count = count($sorting_array)) > 1) { |
|
1064 | + $order = !empty($sorting_array[$count - 1]) ? strtoupper($sorting_array[$count - 1]) : ''; |
|
1065 | + array_pop($sorting_array); |
|
1066 | 1066 | |
1067 | - if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) { |
|
1068 | - $sort_by = implode( '_', $sorting_array ); |
|
1067 | + if (!empty($sorting_array) && ($order == 'ASC' || $order == 'DESC')) { |
|
1068 | + $sort_by = implode('_', $sorting_array); |
|
1069 | 1069 | |
1070 | - if ( geodir_column_exist( $table, $sort_by ) ) { |
|
1071 | - $orderby = $table . "." . $sort_by . " " . $order; |
|
1070 | + if (geodir_column_exist($table, $sort_by)) { |
|
1071 | + $orderby = $table.".".$sort_by." ".$order; |
|
1072 | 1072 | } |
1073 | 1073 | } |
1074 | 1074 | } |
@@ -1093,18 +1093,18 @@ discard block |
||
1093 | 1093 | * |
1094 | 1094 | * @return string Modified fields SQL. |
1095 | 1095 | */ |
1096 | -function geodir_search_widget_location_filter_fields( $fields, $table, $post_type ) { |
|
1096 | +function geodir_search_widget_location_filter_fields($fields, $table, $post_type) { |
|
1097 | 1097 | global $wpdb, $gd_query_args_widgets, $snear, $gd_session; |
1098 | 1098 | |
1099 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1100 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1099 | + if (!empty($gd_query_args_widgets['gd_location']) && geodir_is_page('search') && !empty($_REQUEST['sgeo_lat']) && !empty($_REQUEST['sgeo_lon'])) { |
|
1100 | + $location_allowed = function_exists('geodir_cpt_no_location') && geodir_cpt_no_location($post_type) ? false : true; |
|
1101 | 1101 | |
1102 | - if ( $location_allowed && strpos( strtolower( $fields ), ' as distance ' ) === false && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1103 | - $latitude = sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
1104 | - $longitude = sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
1105 | - $radius = geodir_getDistanceRadius( get_option( 'geodir_search_dist_1' ) ); |
|
1102 | + if ($location_allowed && strpos(strtolower($fields), ' as distance ') === false && ($snear != '' || $gd_session->get('all_near_me'))) { |
|
1103 | + $latitude = sanitize_text_field($_REQUEST['sgeo_lat']); |
|
1104 | + $longitude = sanitize_text_field($_REQUEST['sgeo_lon']); |
|
1105 | + $radius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
1106 | 1106 | |
1107 | - $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 ); |
|
1107 | + $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); |
|
1108 | 1108 | } |
1109 | 1109 | } |
1110 | 1110 | |
@@ -1126,14 +1126,14 @@ discard block |
||
1126 | 1126 | * |
1127 | 1127 | * @return string Modified fields SQL. |
1128 | 1128 | */ |
1129 | -function geodir_search_widget_location_filter_orderby( $orderby, $table, $post_type ) { |
|
1129 | +function geodir_search_widget_location_filter_orderby($orderby, $table, $post_type) { |
|
1130 | 1130 | global $gd_query_args_widgets, $snear, $gd_session; |
1131 | 1131 | |
1132 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) { |
|
1133 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
1132 | + if (!empty($gd_query_args_widgets['gd_location']) && geodir_is_page('search') && !empty($_REQUEST['sgeo_lat']) && !empty($_REQUEST['sgeo_lon'])) { |
|
1133 | + $location_allowed = function_exists('geodir_cpt_no_location') && geodir_cpt_no_location($post_type) ? false : true; |
|
1134 | 1134 | |
1135 | - if ( $location_allowed && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1136 | - $orderby = "distance ASC, " . $orderby; |
|
1135 | + if ($location_allowed && ($snear != '' || $gd_session->get('all_near_me'))) { |
|
1136 | + $orderby = "distance ASC, ".$orderby; |
|
1137 | 1137 | } |
1138 | 1138 | } |
1139 | 1139 | |
@@ -1148,23 +1148,23 @@ discard block |
||
1148 | 1148 | * @return string Filtered url. |
1149 | 1149 | */ |
1150 | 1150 | function geodir_search_page_base_url() { |
1151 | - if ( function_exists( 'geodir_location_geo_home_link' ) ) { |
|
1152 | - remove_filter( 'home_url', 'geodir_location_geo_home_link', 100000 ); |
|
1151 | + if (function_exists('geodir_location_geo_home_link')) { |
|
1152 | + remove_filter('home_url', 'geodir_location_geo_home_link', 100000); |
|
1153 | 1153 | } |
1154 | 1154 | |
1155 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX && geodir_is_wpml() ) { |
|
1155 | + if (defined('DOING_AJAX') && DOING_AJAX && geodir_is_wpml()) { |
|
1156 | 1156 | $url = icl_get_home_url(); |
1157 | 1157 | } else { |
1158 | 1158 | $url = get_home_url(); |
1159 | 1159 | } |
1160 | 1160 | |
1161 | - $url = trailingslashit( $url ); |
|
1161 | + $url = trailingslashit($url); |
|
1162 | 1162 | |
1163 | - if ( function_exists( 'geodir_location_geo_home_link' ) ) { |
|
1164 | - add_filter( 'home_url', 'geodir_location_geo_home_link', 100000, 2 ); |
|
1163 | + if (function_exists('geodir_location_geo_home_link')) { |
|
1164 | + add_filter('home_url', 'geodir_location_geo_home_link', 100000, 2); |
|
1165 | 1165 | } |
1166 | 1166 | |
1167 | - return apply_filters( 'geodir_search_page_base_url', $url ); |
|
1167 | + return apply_filters('geodir_search_page_base_url', $url); |
|
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | /** |
@@ -1172,30 +1172,30 @@ discard block |
||
1172 | 1172 | * |
1173 | 1173 | * @since 1.6.31 |
1174 | 1174 | */ |
1175 | -function geodir_jetpack_fix_post_types_search(){ |
|
1176 | - if ( defined( 'JETPACK__VERSION' ) && ! empty( $_REQUEST['geodir_search'] ) ) { |
|
1177 | - add_filter( 'jetpack_search_should_handle_query', '__return_false', 999, 1 ); |
|
1175 | +function geodir_jetpack_fix_post_types_search() { |
|
1176 | + if (defined('JETPACK__VERSION') && !empty($_REQUEST['geodir_search'])) { |
|
1177 | + add_filter('jetpack_search_should_handle_query', '__return_false', 999, 1); |
|
1178 | 1178 | } |
1179 | 1179 | } |
1180 | -add_action( 'plugins_loaded','geodir_jetpack_fix_post_types_search', 10 ); |
|
1180 | +add_action('plugins_loaded', 'geodir_jetpack_fix_post_types_search', 10); |
|
1181 | 1181 | |
1182 | -function geodir_posts_having( $where, $query = array() ) { |
|
1182 | +function geodir_posts_having($where, $query = array()) { |
|
1183 | 1183 | global $wpdb, $gd_session, $geodir_post_type, $dist, $mylat, $mylon, $snear; |
1184 | 1184 | |
1185 | - if ( geodir_is_gd_main_query( $query ) ) { |
|
1186 | - $support_location = $geodir_post_type && function_exists( 'geodir_cpt_no_location' ) && ! geodir_cpt_no_location( $geodir_post_type ); |
|
1185 | + if (geodir_is_gd_main_query($query)) { |
|
1186 | + $support_location = $geodir_post_type && function_exists('geodir_cpt_no_location') && !geodir_cpt_no_location($geodir_post_type); |
|
1187 | 1187 | |
1188 | - if ( $support_location && $dist && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) { |
|
1189 | - if ( $gd_session->get( 'near_me_range' ) && ! isset( $_REQUEST['sdist'] ) ) { |
|
1190 | - $dist = $gd_session->get( 'near_me_range' ); |
|
1188 | + if ($support_location && $dist && ($snear != '' || $gd_session->get('all_near_me'))) { |
|
1189 | + if ($gd_session->get('near_me_range') && !isset($_REQUEST['sdist'])) { |
|
1190 | + $dist = $gd_session->get('near_me_range'); |
|
1191 | 1191 | |
1192 | - if ( get_option( 'geodir_search_dist_1' ) == 'km' ) { |
|
1192 | + if (get_option('geodir_search_dist_1') == 'km') { |
|
1193 | 1193 | $dist = $dist * 1.6093440001; |
1194 | 1194 | } |
1195 | 1195 | } |
1196 | 1196 | |
1197 | - if ( strpos( $where, ' HAVING ') === false ) { |
|
1198 | - $where .= $wpdb->prepare( " HAVING distance <= %f ", $dist ); |
|
1197 | + if (strpos($where, ' HAVING ') === false) { |
|
1198 | + $where .= $wpdb->prepare(" HAVING distance <= %f ", $dist); |
|
1199 | 1199 | } |
1200 | 1200 | } |
1201 | 1201 | } |
@@ -1203,12 +1203,12 @@ discard block |
||
1203 | 1203 | return $where; |
1204 | 1204 | } |
1205 | 1205 | |
1206 | -function geodir_is_gd_main_query( $query ){ |
|
1206 | +function geodir_is_gd_main_query($query) { |
|
1207 | 1207 | $is_main_query = false; |
1208 | 1208 | |
1209 | - if(isset($query->query->gd_is_geodir_page) && $query->query->gd_is_geodir_page) { |
|
1209 | + if (isset($query->query->gd_is_geodir_page) && $query->query->gd_is_geodir_page) { |
|
1210 | 1210 | $is_main_query = true; |
1211 | - }elseif(isset($query->query['gd_is_geodir_page']) && $query->query['gd_is_geodir_page']) { |
|
1211 | + }elseif (isset($query->query['gd_is_geodir_page']) && $query->query['gd_is_geodir_page']) { |
|
1212 | 1212 | $is_main_query = true; |
1213 | 1213 | } |
1214 | 1214 |