@@ -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,82 +67,82 @@ 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 | - $s = str_replace(array("%E2%80%99","’"),array("%27","'"),$s);
|
|
| 120 | - } |
|
| 117 | + if (isset($_REQUEST['s'])) {
|
|
| 118 | + $s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s']))); |
|
| 119 | + $s = str_replace(array("%E2%80%99","’"),array("%27","'"),$s);
|
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - if ($snear == 'NEAR ME') {
|
|
| 123 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 124 | - $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip));
|
|
| 125 | - $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude])); |
|
| 126 | - $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude])); |
|
| 127 | - } |
|
| 122 | + if ($snear == 'NEAR ME') {
|
|
| 123 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 124 | + $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip));
|
|
| 125 | + $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude])); |
|
| 126 | + $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude])); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | |
| 130 | - if (strstr($s, ',')) {
|
|
| 131 | - $s_AA = str_replace(" ", "", $s);
|
|
| 132 | - $s_A = explode(",", $s_AA);
|
|
| 133 | - $s_A = implode('","', $s_A);
|
|
| 134 | - $s_A = '"' . $s_A . '"'; |
|
| 135 | - } else {
|
|
| 136 | - $s_A = '"' . $s . '"'; |
|
| 137 | - } |
|
| 130 | + if (strstr($s, ',')) {
|
|
| 131 | + $s_AA = str_replace(" ", "", $s);
|
|
| 132 | + $s_A = explode(",", $s_AA);
|
|
| 133 | + $s_A = implode('","', $s_A);
|
|
| 134 | + $s_A = '"' . $s_A . '"'; |
|
| 135 | + } else {
|
|
| 136 | + $s_A = '"' . $s . '"'; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if (strstr($s, ' ')) {
|
|
| 140 | - $s_SA = explode(" ", $s);
|
|
| 141 | - } else {
|
|
| 142 | - $s_SA = ''; |
|
| 143 | - } |
|
| 139 | + if (strstr($s, ' ')) {
|
|
| 140 | + $s_SA = explode(" ", $s);
|
|
| 141 | + } else {
|
|
| 142 | + $s_SA = ''; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - endif; |
|
| 145 | + endif; |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | |
@@ -163,56 +163,56 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | function geodir_listing_loop_filter($query) |
| 165 | 165 | {
|
| 166 | - global $wp_query, $geodir_post_type, $table, $plugin_prefix, $table, $term; |
|
| 166 | + global $wp_query, $geodir_post_type, $table, $plugin_prefix, $table, $term; |
|
| 167 | 167 | |
| 168 | - // fix wp_reset_query for popular post view widget |
|
| 169 | - if (!geodir_is_geodir_page()) {
|
|
| 170 | - return; |
|
| 171 | - } |
|
| 168 | + // fix wp_reset_query for popular post view widget |
|
| 169 | + if (!geodir_is_geodir_page()) {
|
|
| 170 | + return; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - $geodir_post_type = geodir_get_current_posttype(); |
|
| 174 | - |
|
| 175 | - if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) {
|
|
| 176 | - $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
| 177 | - |
|
| 178 | - if (isset($wp_query->query[$taxonomies[0]])) {
|
|
| 179 | - $request_term = explode("/", $wp_query->query[$taxonomies[0]]);
|
|
| 180 | - $request_term = end($request_term); |
|
| 181 | - if (!term_exists($request_term)) {
|
|
| 182 | - $args = array('number' => '1',);
|
|
| 183 | - $terms_arr = get_terms($taxonomies[0], $args); |
|
| 184 | - foreach ($terms_arr as $location_term) {
|
|
| 185 | - $term_arr = $location_term; |
|
| 186 | - $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term));
|
|
| 187 | - } |
|
| 188 | - $wp_query->queried_object_id = 1; |
|
| 189 | - $wp_query->queried_object = $term_arr; |
|
| 190 | - //print_r($wp_query) ; |
|
| 191 | - } |
|
| 192 | - } |
|
| 173 | + $geodir_post_type = geodir_get_current_posttype(); |
|
| 174 | + |
|
| 175 | + if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) {
|
|
| 176 | + $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
| 177 | + |
|
| 178 | + if (isset($wp_query->query[$taxonomies[0]])) {
|
|
| 179 | + $request_term = explode("/", $wp_query->query[$taxonomies[0]]);
|
|
| 180 | + $request_term = end($request_term); |
|
| 181 | + if (!term_exists($request_term)) {
|
|
| 182 | + $args = array('number' => '1',);
|
|
| 183 | + $terms_arr = get_terms($taxonomies[0], $args); |
|
| 184 | + foreach ($terms_arr as $location_term) {
|
|
| 185 | + $term_arr = $location_term; |
|
| 186 | + $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term));
|
|
| 187 | + } |
|
| 188 | + $wp_query->queried_object_id = 1; |
|
| 189 | + $wp_query->queried_object = $term_arr; |
|
| 190 | + //print_r($wp_query) ; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - } |
|
| 195 | - if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) {
|
|
| 196 | - |
|
| 197 | - $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
| 198 | - |
|
| 199 | - add_filter('posts_fields', 'geodir_posts_fields', 1);
|
|
| 200 | - add_filter('posts_join', 'geodir_posts_join', 1);
|
|
| 201 | - geodir_post_where(); |
|
| 202 | - if (!is_admin()) |
|
| 203 | - add_filter('posts_orderby', 'geodir_posts_orderby', 1);
|
|
| 204 | - |
|
| 205 | - // advanced filter for popular post view widget |
|
| 206 | - global $wp_query; |
|
| 207 | - if (!is_admin()) {
|
|
| 208 | - if (!empty($wp_query->query['with_pics_only'])) {
|
|
| 209 | - add_filter('posts_join', 'geodir_filter_widget_join', 1000);
|
|
| 210 | - } |
|
| 211 | - add_filter('posts_where', 'geodir_filter_widget_where', 1000);
|
|
| 212 | - } |
|
| 194 | + } |
|
| 195 | + if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) {
|
|
| 213 | 196 | |
| 214 | - } |
|
| 215 | - return $query; |
|
| 197 | + $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
| 198 | + |
|
| 199 | + add_filter('posts_fields', 'geodir_posts_fields', 1);
|
|
| 200 | + add_filter('posts_join', 'geodir_posts_join', 1);
|
|
| 201 | + geodir_post_where(); |
|
| 202 | + if (!is_admin()) |
|
| 203 | + add_filter('posts_orderby', 'geodir_posts_orderby', 1);
|
|
| 204 | + |
|
| 205 | + // advanced filter for popular post view widget |
|
| 206 | + global $wp_query; |
|
| 207 | + if (!is_admin()) {
|
|
| 208 | + if (!empty($wp_query->query['with_pics_only'])) {
|
|
| 209 | + add_filter('posts_join', 'geodir_filter_widget_join', 1000);
|
|
| 210 | + } |
|
| 211 | + add_filter('posts_where', 'geodir_filter_widget_where', 1000);
|
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + } |
|
| 215 | + return $query; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -231,67 +231,67 @@ discard block |
||
| 231 | 231 | * @return string Modified fields query string. |
| 232 | 232 | */ |
| 233 | 233 | function geodir_posts_fields($fields) {
|
| 234 | - global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; |
|
| 234 | + global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; |
|
| 235 | 235 | |
| 236 | - // Filter-Location-Manager to add location table. |
|
| 237 | - $fields .= ", " . $table . ".* "; |
|
| 236 | + // Filter-Location-Manager to add location table. |
|
| 237 | + $fields .= ", " . $table . ".* "; |
|
| 238 | 238 | |
| 239 | 239 | if ($snear != '' || $gd_session->get('all_near_me')) {
|
| 240 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
|
| 240 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
|
| 241 | 241 | |
| 242 | 242 | if ($gd_session->get('all_near_me')) {
|
| 243 | - $mylat = $gd_session->get('user_lat');
|
|
| 244 | - $mylon = $gd_session->get('user_lon');
|
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $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 ";
|
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - global $s; |
|
| 251 | - if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
|
|
| 252 | - $keywords = explode(" ", $s);
|
|
| 253 | - |
|
| 254 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
|
|
| 255 | - foreach($keywords as $kkey=>$kword){
|
|
| 256 | - if(geodir_utf8_strlen($kword)<=$klimit){
|
|
| 257 | - unset($keywords[$kkey]); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } |
|
| 243 | + $mylat = $gd_session->get('user_lat');
|
|
| 244 | + $mylon = $gd_session->get('user_lon');
|
|
| 245 | + } |
|
| 261 | 246 | |
| 247 | + $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 ";
|
|
| 248 | + } |
|
| 262 | 249 | |
| 263 | - if (count($keywords) > 1) {
|
|
| 264 | - $parts = array( |
|
| 265 | - 'AND' => 'gd_alltitlematch_part', |
|
| 266 | - 'OR' => 'gd_titlematch_part' |
|
| 267 | - ); |
|
| 268 | - $gd_titlematch_part = ""; |
|
| 269 | - foreach ($parts as $key => $part) {
|
|
| 270 | - $gd_titlematch_part .= " CASE WHEN "; |
|
| 271 | - $count = 0; |
|
| 272 | - foreach ($keywords as $keyword) {
|
|
| 273 | - $keyword = trim($keyword); |
|
| 274 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
| 250 | + global $s; |
|
| 251 | + if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
|
|
| 252 | + $keywords = explode(" ", $s);
|
|
| 253 | + |
|
| 254 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
|
|
| 255 | + foreach($keywords as $kkey=>$kword){
|
|
| 256 | + if(geodir_utf8_strlen($kword)<=$klimit){
|
|
| 257 | + unset($keywords[$kkey]); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + if (count($keywords) > 1) {
|
|
| 264 | + $parts = array( |
|
| 265 | + 'AND' => 'gd_alltitlematch_part', |
|
| 266 | + 'OR' => 'gd_titlematch_part' |
|
| 267 | + ); |
|
| 268 | + $gd_titlematch_part = ""; |
|
| 269 | + foreach ($parts as $key => $part) {
|
|
| 270 | + $gd_titlematch_part .= " CASE WHEN "; |
|
| 271 | + $count = 0; |
|
| 272 | + foreach ($keywords as $keyword) {
|
|
| 273 | + $keyword = trim($keyword); |
|
| 274 | + $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
| 275 | 275 | $count++; |
| 276 | - if ($count < count($keywords)) {
|
|
| 277 | - // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; |
|
| 276 | + if ($count < count($keywords)) {
|
|
| 277 | + // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; |
|
| 278 | 278 | $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) " . $key . " "; |
| 279 | - } else {
|
|
| 280 | - //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; |
|
| 279 | + } else {
|
|
| 280 | + //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; |
|
| 281 | 281 | $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) "; |
| 282 | - } |
|
| 283 | - } |
|
| 284 | - $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; |
|
| 285 | - } |
|
| 286 | - } else {
|
|
| 287 | - $gd_titlematch_part = ""; |
|
| 288 | - } |
|
| 289 | - $s = stripslashes_deep( $s ); |
|
| 290 | - $s = wp_specialchars_decode($s,ENT_QUOTES); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; |
|
| 285 | + } |
|
| 286 | + } else {
|
|
| 287 | + $gd_titlematch_part = ""; |
|
| 288 | + } |
|
| 289 | + $s = stripslashes_deep( $s ); |
|
| 290 | + $s = wp_specialchars_decode($s,ENT_QUOTES); |
|
| 291 | 291 | $fields .= $wpdb->prepare(", CASE WHEN " . $table . ".is_featured='1' THEN 1 ELSE 0 END AS gd_featured, CASE WHEN " . $wpdb->posts . ".post_title LIKE %s THEN 1 ELSE 0 END AS gd_exacttitle," . $gd_titlematch_part . " CASE WHEN ( " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s ) THEN 1 ELSE 0 END AS gd_titlematch, CASE WHEN ( " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s ) THEN 1 ELSE 0 END AS gd_content", array($s, $s, $s . '%', '% ' . $s . '%', $s, $s . ' %', '% ' . $s . ' %', '% ' . $s));
|
| 292 | - } |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - return $fields; |
|
| 294 | + return $fields; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | |
@@ -308,26 +308,26 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | function geodir_posts_join($join) |
| 310 | 310 | {
|
| 311 | - global $wpdb, $geodir_post_type, $table, $table_prefix, $plugin_prefix; |
|
| 311 | + global $wpdb, $geodir_post_type, $table, $table_prefix, $plugin_prefix; |
|
| 312 | 312 | |
| 313 | - ########### WPML ########### |
|
| 313 | + ########### WPML ########### |
|
| 314 | 314 | |
| 315 | - if ( geodir_wpml_is_post_type_translated( $geodir_post_type ) ) {
|
|
| 316 | - global $sitepress; |
|
| 317 | - $lang_code = ICL_LANGUAGE_CODE; |
|
| 318 | - $default_lang_code = $sitepress->get_default_language(); |
|
| 319 | - if ($lang_code) {
|
|
| 320 | - $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID"; |
|
| 321 | - } |
|
| 315 | + if ( geodir_wpml_is_post_type_translated( $geodir_post_type ) ) {
|
|
| 316 | + global $sitepress; |
|
| 317 | + $lang_code = ICL_LANGUAGE_CODE; |
|
| 318 | + $default_lang_code = $sitepress->get_default_language(); |
|
| 319 | + if ($lang_code) {
|
|
| 320 | + $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID"; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - } |
|
| 324 | - ########### WPML ########### |
|
| 323 | + } |
|
| 324 | + ########### WPML ########### |
|
| 325 | 325 | |
| 326 | - $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID) ";
|
|
| 327 | - //===old code start |
|
| 328 | - //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id) " ;//===old code end
|
|
| 326 | + $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID) ";
|
|
| 327 | + //===old code start |
|
| 328 | + //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id) " ;//===old code end
|
|
| 329 | 329 | |
| 330 | - return $join; |
|
| 330 | + return $join; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
@@ -345,15 +345,15 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | function geodir_posts_orderby($orderby) |
| 347 | 347 | {
|
| 348 | - global $wpdb, $wp_query, $geodir_post_type, $table, $plugin_prefix, $snear, $default_sort; |
|
| 348 | + global $wpdb, $wp_query, $geodir_post_type, $table, $plugin_prefix, $snear, $default_sort; |
|
| 349 | 349 | |
| 350 | - $sort_by = ''; |
|
| 351 | - $orderby = ' '; |
|
| 350 | + $sort_by = ''; |
|
| 351 | + $orderby = ' '; |
|
| 352 | 352 | |
| 353 | - if (get_query_var('order_by'))
|
|
| 354 | - $sort_by = get_query_var('order_by');
|
|
| 353 | + if (get_query_var('order_by'))
|
|
| 354 | + $sort_by = get_query_var('order_by');
|
|
| 355 | 355 | |
| 356 | - /*if(isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries){
|
|
| 356 | + /*if(isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries){
|
|
| 357 | 357 | $current_term = $wp_query->get_queried_object(); |
| 358 | 358 | } |
| 359 | 359 | |
@@ -367,133 +367,133 @@ discard block |
||
| 367 | 367 | }*/ |
| 368 | 368 | |
| 369 | 369 | |
| 370 | - if ($snear != '') {
|
|
| 371 | - $orderby .= " distance,"; |
|
| 372 | - } |
|
| 370 | + if ($snear != '') {
|
|
| 371 | + $orderby .= " distance,"; |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - if (isset($_REQUEST['sort_by']) && $_REQUEST['sort_by'] != '' && is_main_query()) |
|
| 375 | - $sort_by = esc_attr($_REQUEST['sort_by']); |
|
| 374 | + if (isset($_REQUEST['sort_by']) && $_REQUEST['sort_by'] != '' && is_main_query()) |
|
| 375 | + $sort_by = esc_attr($_REQUEST['sort_by']); |
|
| 376 | 376 | |
| 377 | 377 | |
| 378 | - if ($sort_by == '') {
|
|
| 379 | - $default_sort = geodir_get_posts_default_sort($geodir_post_type); |
|
| 380 | - if (!empty($default_sort)) |
|
| 381 | - $sort_by = $default_sort; |
|
| 382 | - } |
|
| 378 | + if ($sort_by == '') {
|
|
| 379 | + $default_sort = geodir_get_posts_default_sort($geodir_post_type); |
|
| 380 | + if (!empty($default_sort)) |
|
| 381 | + $sort_by = $default_sort; |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | - /* |
|
| 384 | + /* |
|
| 385 | 385 | if search by term & no location then order always "relevance" |
| 386 | 386 | if search by location then order always "nearest" |
| 387 | 387 | */ |
| 388 | - if (is_main_query() && geodir_is_page('search')) {
|
|
| 389 | - $search_term = get_query_var('s');
|
|
| 388 | + if (is_main_query() && geodir_is_page('search')) {
|
|
| 389 | + $search_term = get_query_var('s');
|
|
| 390 | 390 | |
| 391 | - if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) {
|
|
| 392 | - $sort_by = 'az'; |
|
| 393 | - } |
|
| 391 | + if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) {
|
|
| 392 | + $sort_by = 'az'; |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - if ($snear != '' && $sort_by!='farthest') {
|
|
| 396 | - $sort_by = 'nearest'; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - switch ($sort_by): |
|
| 401 | - case 'newest': |
|
| 402 | - $orderby = "$wpdb->posts.post_date desc, "; |
|
| 403 | - break; |
|
| 404 | - case 'oldest': |
|
| 405 | - $orderby = "$wpdb->posts.post_date asc, "; |
|
| 406 | - break; |
|
| 407 | - case 'low_review': |
|
| 408 | - case 'rating_count_asc': |
|
| 409 | - $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, "; |
|
| 410 | - break; |
|
| 411 | - case 'high_review': |
|
| 412 | - case 'rating_count_desc': |
|
| 413 | - $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, "; |
|
| 414 | - break; |
|
| 415 | - case 'low_rating': |
|
| 416 | - $orderby = "( " . $table . ".overall_rating ) ASC, " . $table . ".rating_count ASC, "; |
|
| 417 | - break; |
|
| 418 | - case 'high_rating': |
|
| 419 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
| 420 | - break; |
|
| 421 | - case 'featured': |
|
| 422 | - $orderby = $table . ".is_featured asc, "; |
|
| 423 | - break; |
|
| 424 | - case 'nearest': |
|
| 425 | - $orderby = " distance asc, "; |
|
| 426 | - break; |
|
| 427 | - case 'farthest': |
|
| 428 | - $orderby = " distance desc, "; |
|
| 429 | - break; |
|
| 430 | - case 'random': |
|
| 431 | - $orderby = " rand(), "; |
|
| 432 | - break; |
|
| 433 | - case 'az': |
|
| 434 | - $orderby = "$wpdb->posts.post_title asc, "; |
|
| 435 | - break; |
|
| 436 | - // sort by rating |
|
| 437 | - case 'overall_rating_desc': |
|
| 438 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
| 439 | - break; |
|
| 440 | - case 'overall_rating_asc': |
|
| 441 | - $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, "; |
|
| 442 | - break; |
|
| 443 | - default: |
|
| 444 | - |
|
| 445 | - break; |
|
| 446 | - endswitch; |
|
| 447 | - |
|
| 448 | - if ($sort_by != '' && geodir_cpt_has_rating_disabled($geodir_post_type)) {
|
|
| 449 | - if (in_array($sort_by, array('high_review', 'rating_count_desc', 'high_rating', 'overall_rating_desc'))) {
|
|
| 450 | - $orderby = "$wpdb->posts.comment_count DESC, "; |
|
| 451 | - $sort_by = 'comment_count_desc'; |
|
| 452 | - } else if (in_array($sort_by, array('low_review', 'rating_count_asc', 'low_rating', 'overall_rating_asc'))) {
|
|
| 453 | - $orderby = "$wpdb->posts.comment_count ASC, "; |
|
| 454 | - $sort_by = 'comment_count_asc'; |
|
| 455 | - } |
|
| 456 | - } |
|
| 395 | + if ($snear != '' && $sort_by!='farthest') {
|
|
| 396 | + $sort_by = 'nearest'; |
|
| 397 | + } |
|
| 398 | + } |
|
| 457 | 399 | |
| 458 | - global $s; |
|
| 400 | + switch ($sort_by): |
|
| 401 | + case 'newest': |
|
| 402 | + $orderby = "$wpdb->posts.post_date desc, "; |
|
| 403 | + break; |
|
| 404 | + case 'oldest': |
|
| 405 | + $orderby = "$wpdb->posts.post_date asc, "; |
|
| 406 | + break; |
|
| 407 | + case 'low_review': |
|
| 408 | + case 'rating_count_asc': |
|
| 409 | + $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, "; |
|
| 410 | + break; |
|
| 411 | + case 'high_review': |
|
| 412 | + case 'rating_count_desc': |
|
| 413 | + $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, "; |
|
| 414 | + break; |
|
| 415 | + case 'low_rating': |
|
| 416 | + $orderby = "( " . $table . ".overall_rating ) ASC, " . $table . ".rating_count ASC, "; |
|
| 417 | + break; |
|
| 418 | + case 'high_rating': |
|
| 419 | + $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
| 420 | + break; |
|
| 421 | + case 'featured': |
|
| 422 | + $orderby = $table . ".is_featured asc, "; |
|
| 423 | + break; |
|
| 424 | + case 'nearest': |
|
| 425 | + $orderby = " distance asc, "; |
|
| 426 | + break; |
|
| 427 | + case 'farthest': |
|
| 428 | + $orderby = " distance desc, "; |
|
| 429 | + break; |
|
| 430 | + case 'random': |
|
| 431 | + $orderby = " rand(), "; |
|
| 432 | + break; |
|
| 433 | + case 'az': |
|
| 434 | + $orderby = "$wpdb->posts.post_title asc, "; |
|
| 435 | + break; |
|
| 436 | + // sort by rating |
|
| 437 | + case 'overall_rating_desc': |
|
| 438 | + $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
| 439 | + break; |
|
| 440 | + case 'overall_rating_asc': |
|
| 441 | + $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, "; |
|
| 442 | + break; |
|
| 443 | + default: |
|
| 444 | + |
|
| 445 | + break; |
|
| 446 | + endswitch; |
|
| 447 | + |
|
| 448 | + if ($sort_by != '' && geodir_cpt_has_rating_disabled($geodir_post_type)) {
|
|
| 449 | + if (in_array($sort_by, array('high_review', 'rating_count_desc', 'high_rating', 'overall_rating_desc'))) {
|
|
| 450 | + $orderby = "$wpdb->posts.comment_count DESC, "; |
|
| 451 | + $sort_by = 'comment_count_desc'; |
|
| 452 | + } else if (in_array($sort_by, array('low_review', 'rating_count_asc', 'low_rating', 'overall_rating_asc'))) {
|
|
| 453 | + $orderby = "$wpdb->posts.comment_count ASC, "; |
|
| 454 | + $sort_by = 'comment_count_asc'; |
|
| 455 | + } |
|
| 456 | + } |
|
| 459 | 457 | |
| 460 | - if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
|
|
| 461 | - $keywords = explode(" ", $s);
|
|
| 462 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
|
|
| 463 | - foreach($keywords as $kkey=>$kword){
|
|
| 464 | - if(geodir_utf8_strlen($kword)<=$klimit){
|
|
| 465 | - unset($keywords[$kkey]); |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - if ($sort_by == 'nearest' || $sort_by == 'farthest') {
|
|
| 470 | - if (count($keywords) > 1) {
|
|
| 471 | - $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, "; |
|
| 472 | - } else {
|
|
| 473 | - $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
| 474 | - } |
|
| 475 | - } else {
|
|
| 476 | - if (count($keywords) > 1) {
|
|
| 477 | - $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, " . $orderby; |
|
| 478 | - } else {
|
|
| 479 | - $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby; |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - } |
|
| 458 | + global $s; |
|
| 459 | + |
|
| 460 | + if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
|
|
| 461 | + $keywords = explode(" ", $s);
|
|
| 462 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
|
|
| 463 | + foreach($keywords as $kkey=>$kword){
|
|
| 464 | + if(geodir_utf8_strlen($kword)<=$klimit){
|
|
| 465 | + unset($keywords[$kkey]); |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + if ($sort_by == 'nearest' || $sort_by == 'farthest') {
|
|
| 470 | + if (count($keywords) > 1) {
|
|
| 471 | + $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, "; |
|
| 472 | + } else {
|
|
| 473 | + $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
| 474 | + } |
|
| 475 | + } else {
|
|
| 476 | + if (count($keywords) > 1) {
|
|
| 477 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, " . $orderby; |
|
| 478 | + } else {
|
|
| 479 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby; |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | - /** |
|
| 485 | - * Filter order by SQL. |
|
| 486 | - * |
|
| 487 | - * @since 1.0.0 |
|
| 488 | - * @param string $orderby The orderby query string. |
|
| 489 | - * @param string $sort_by Sortby query string. |
|
| 490 | - * @param string $table Listing table name. |
|
| 491 | - */ |
|
| 492 | - $orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table);
|
|
| 484 | + /** |
|
| 485 | + * Filter order by SQL. |
|
| 486 | + * |
|
| 487 | + * @since 1.0.0 |
|
| 488 | + * @param string $orderby The orderby query string. |
|
| 489 | + * @param string $sort_by Sortby query string. |
|
| 490 | + * @param string $table Listing table name. |
|
| 491 | + */ |
|
| 492 | + $orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table);
|
|
| 493 | 493 | |
| 494 | - $orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title "; |
|
| 494 | + $orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title "; |
|
| 495 | 495 | |
| 496 | - return $orderby; |
|
| 496 | + return $orderby; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | |
@@ -511,78 +511,78 @@ discard block |
||
| 511 | 511 | function geodir_posts_order_by_custom_sort($orderby, $sort_by, $table) |
| 512 | 512 | {
|
| 513 | 513 | |
| 514 | - global $wpdb; |
|
| 514 | + global $wpdb; |
|
| 515 | 515 | |
| 516 | - if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' || $_REQUEST['s']==' ') ) )) {
|
|
| 516 | + if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' || $_REQUEST['s']==' ') ) )) {
|
|
| 517 | 517 | |
| 518 | - $sort_array = explode('_', $sort_by);
|
|
| 518 | + $sort_array = explode('_', $sort_by);
|
|
| 519 | 519 | |
| 520 | - $sort_by_count = count($sort_array); |
|
| 520 | + $sort_by_count = count($sort_array); |
|
| 521 | 521 | |
| 522 | - $order = $sort_array[$sort_by_count - 1]; |
|
| 522 | + $order = $sort_array[$sort_by_count - 1]; |
|
| 523 | 523 | |
| 524 | - if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) {
|
|
| 524 | + if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) {
|
|
| 525 | 525 | |
| 526 | - $sort_by = str_replace('_' . $order, '', $sort_by);
|
|
| 526 | + $sort_by = str_replace('_' . $order, '', $sort_by);
|
|
| 527 | 527 | |
| 528 | - switch ($sort_by): |
|
| 528 | + switch ($sort_by): |
|
| 529 | 529 | |
| 530 | - case 'post_date': |
|
| 531 | - case 'comment_count': |
|
| 530 | + case 'post_date': |
|
| 531 | + case 'comment_count': |
|
| 532 | 532 | |
| 533 | - $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", "; |
|
| 534 | - break; |
|
| 533 | + $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", "; |
|
| 534 | + break; |
|
| 535 | 535 | |
| 536 | - case 'distance': |
|
| 537 | - $orderby = $sort_by . " " . $order . ", "; |
|
| 538 | - break; |
|
| 536 | + case 'distance': |
|
| 537 | + $orderby = $sort_by . " " . $order . ", "; |
|
| 538 | + break; |
|
| 539 | 539 | |
| 540 | 540 | |
| 541 | - // sort by rating |
|
| 542 | - case 'overall_rating': |
|
| 541 | + // sort by rating |
|
| 542 | + case 'overall_rating': |
|
| 543 | 543 | |
| 544 | - $use_bayesian = apply_filters('gd_use_bayesian',true,$table);
|
|
| 545 | - $avg_rating = 0; |
|
| 546 | - if($use_bayesian){
|
|
| 547 | - $avg_num_votes = get_transient( 'gd_avg_num_votes_'.$table ); |
|
| 548 | - if(!$avg_num_votes){
|
|
| 549 | - $avg_num_votes = $wpdb->get_var("SELECT SUM(rating_count) FROM $table");
|
|
| 550 | - if($avg_num_votes){
|
|
| 544 | + $use_bayesian = apply_filters('gd_use_bayesian',true,$table);
|
|
| 545 | + $avg_rating = 0; |
|
| 546 | + if($use_bayesian){
|
|
| 547 | + $avg_num_votes = get_transient( 'gd_avg_num_votes_'.$table ); |
|
| 548 | + if(!$avg_num_votes){
|
|
| 549 | + $avg_num_votes = $wpdb->get_var("SELECT SUM(rating_count) FROM $table");
|
|
| 550 | + if($avg_num_votes){
|
|
| 551 | 551 | |
| 552 | - $avg_rating = get_transient( 'gd_avg_rating_'.$table ); |
|
| 553 | - if(!$avg_rating){
|
|
| 554 | - $avg_rating = $wpdb->get_var("SELECT SUM(overall_rating) FROM $table")/$avg_num_votes;
|
|
| 555 | - } |
|
| 556 | - set_transient( 'gd_avg_num_votes_'.$table, $avg_num_votes, 12 * HOUR_IN_SECONDS ); |
|
| 557 | - set_transient( 'gd_avg_rating_'.$table, $avg_rating , 12 * HOUR_IN_SECONDS ); |
|
| 558 | - } |
|
| 559 | - } |
|
| 552 | + $avg_rating = get_transient( 'gd_avg_rating_'.$table ); |
|
| 553 | + if(!$avg_rating){
|
|
| 554 | + $avg_rating = $wpdb->get_var("SELECT SUM(overall_rating) FROM $table")/$avg_num_votes;
|
|
| 555 | + } |
|
| 556 | + set_transient( 'gd_avg_num_votes_'.$table, $avg_num_votes, 12 * HOUR_IN_SECONDS ); |
|
| 557 | + set_transient( 'gd_avg_rating_'.$table, $avg_rating , 12 * HOUR_IN_SECONDS ); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | - if(!$avg_num_votes){ $avg_num_votes = 0;}
|
|
| 561 | + if(!$avg_num_votes){ $avg_num_votes = 0;}
|
|
| 562 | 562 | |
| 563 | - $orderby = " (( $avg_num_votes * $avg_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating )) / ( $avg_num_votes + " . $table . ".rating_count ) $order , ";
|
|
| 563 | + $orderby = " (( $avg_num_votes * $avg_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating )) / ( $avg_num_votes + " . $table . ".rating_count ) $order , ";
|
|
| 564 | 564 | |
| 565 | - //$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
|
|
| 566 | - }else{
|
|
| 567 | - $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
| 568 | - } |
|
| 565 | + //$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
|
|
| 566 | + }else{
|
|
| 567 | + $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
| 568 | + } |
|
| 569 | 569 | |
| 570 | - break; |
|
| 570 | + break; |
|
| 571 | 571 | |
| 572 | 572 | |
| 573 | - default: |
|
| 574 | - if (geodir_column_exist($table, $sort_by)) {
|
|
| 573 | + default: |
|
| 574 | + if (geodir_column_exist($table, $sort_by)) {
|
|
| 575 | 575 | $orderby = $table . "." . $sort_by . " " . $order . ", "; |
| 576 | 576 | } |
| 577 | - break; |
|
| 577 | + break; |
|
| 578 | 578 | |
| 579 | - endswitch; |
|
| 579 | + endswitch; |
|
| 580 | 580 | |
| 581 | - } |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | - } |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | - return $orderby; |
|
| 585 | + return $orderby; |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -597,34 +597,34 @@ discard block |
||
| 597 | 597 | {
|
| 598 | 598 | |
| 599 | 599 | |
| 600 | - global $wpdb, $geodir_post_type, $table, $s, $snear; |
|
| 600 | + global $wpdb, $geodir_post_type, $table, $s, $snear; |
|
| 601 | 601 | |
| 602 | - if (!is_admin()) {
|
|
| 602 | + if (!is_admin()) {
|
|
| 603 | 603 | |
| 604 | - if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
|
|
| 605 | - add_filter('posts_where', 'geodir_edit_listing_where', 1);
|
|
| 604 | + if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
|
|
| 605 | + add_filter('posts_where', 'geodir_edit_listing_where', 1);
|
|
| 606 | 606 | |
| 607 | - } elseif ((is_search() && $_REQUEST['geodir_search'])) {
|
|
| 607 | + } elseif ((is_search() && $_REQUEST['geodir_search'])) {
|
|
| 608 | 608 | |
| 609 | - add_filter('posts_where', 'searching_filter_where', 1);
|
|
| 609 | + add_filter('posts_where', 'searching_filter_where', 1);
|
|
| 610 | 610 | |
| 611 | - if ($snear != '') |
|
| 612 | - add_filter('posts_where', 'searching_filter_where', 1);
|
|
| 611 | + if ($snear != '') |
|
| 612 | + add_filter('posts_where', 'searching_filter_where', 1);
|
|
| 613 | 613 | |
| 614 | - add_filter('posts_orderby', 'geodir_posts_orderby', 1);
|
|
| 614 | + add_filter('posts_orderby', 'geodir_posts_orderby', 1);
|
|
| 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 ########### |
|
| 700 | 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 | + } |
|
| 701 | 697 | |
| 702 | - return $where = str_replace("0 = 1", "1=1", $where);
|
|
| 698 | + } |
|
| 699 | + ########### WPML ########### |
|
| 700 | + |
|
| 701 | + |
|
| 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,92 +742,92 @@ 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'; |
|
| 780 | 770 | |
| 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 | - */ |
|
| 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 | + |
|
| 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 = ''; |
|
| 808 | + $content_where = $terms_where = ''; |
|
| 809 | 809 | if ($s != '') {
|
| 810 | - /** |
|
| 811 | - * Filter the search query content where values. |
|
| 812 | - * |
|
| 813 | - * @since 1.5.0 |
|
| 814 | - * @package GeoDirectory |
|
| 815 | - * @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%\") ") "`. |
|
| 816 | - */ |
|
| 810 | + /** |
|
| 811 | + * Filter the search query content where values. |
|
| 812 | + * |
|
| 813 | + * @since 1.5.0 |
|
| 814 | + * @package GeoDirectory |
|
| 815 | + * @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%\") ") "`. |
|
| 816 | + */ |
|
| 817 | 817 | $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%\") ");
|
| 818 | - /** |
|
| 819 | - * Filter the search query term values. |
|
| 820 | - * |
|
| 821 | - * @since 1.5.0 |
|
| 822 | - * @package GeoDirectory |
|
| 823 | - * @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)) "`. |
|
| 824 | - */ |
|
| 825 | - $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)) ");
|
|
| 818 | + /** |
|
| 819 | + * Filter the search query term values. |
|
| 820 | + * |
|
| 821 | + * @since 1.5.0 |
|
| 822 | + * @package GeoDirectory |
|
| 823 | + * @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)) "`. |
|
| 824 | + */ |
|
| 825 | + $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)) ");
|
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | |
| 829 | - // get term sql |
|
| 830 | - $term_sql = "SELECT $wpdb->term_taxonomy.term_id, $wpdb->terms.name, $wpdb->term_taxonomy.taxonomy |
|
| 829 | + // get term sql |
|
| 830 | + $term_sql = "SELECT $wpdb->term_taxonomy.term_id, $wpdb->terms.name, $wpdb->term_taxonomy.taxonomy |
|
| 831 | 831 | FROM $wpdb->term_taxonomy, $wpdb->terms, $wpdb->term_relationships |
| 832 | 832 | WHERE $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id |
| 833 | 833 | AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id |
@@ -835,45 +835,45 @@ discard block |
||
| 835 | 835 | $terms_where |
| 836 | 836 | GROUP BY $wpdb->term_taxonomy.term_id"; |
| 837 | 837 | |
| 838 | - $term_results = $wpdb->get_results($term_sql); |
|
| 839 | - $term_ids = array(); |
|
| 840 | - $terms_sql = ''; |
|
| 841 | - |
|
| 842 | - if(!empty($term_results)){
|
|
| 843 | - foreach($term_results as $term_id){
|
|
| 844 | - $term_ids[] = $term_id; |
|
| 845 | - } |
|
| 846 | - if (!empty($term_ids)) {
|
|
| 847 | - foreach($term_ids as $term){
|
|
| 848 | - if ($term->taxonomy == $post_types.'_tags') {
|
|
| 849 | - $terms_sql .= $wpdb->prepare(" OR FIND_IN_SET(%s , " . $table . ".post_tags) ", $term->name);
|
|
| 850 | - } else {
|
|
| 851 | - $terms_sql .= " OR FIND_IN_SET($term->term_id , " . $table . "." . $post_types . "category) "; |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - } |
|
| 838 | + $term_results = $wpdb->get_results($term_sql); |
|
| 839 | + $term_ids = array(); |
|
| 840 | + $terms_sql = ''; |
|
| 841 | + |
|
| 842 | + if(!empty($term_results)){
|
|
| 843 | + foreach($term_results as $term_id){
|
|
| 844 | + $term_ids[] = $term_id; |
|
| 845 | + } |
|
| 846 | + if (!empty($term_ids)) {
|
|
| 847 | + foreach($term_ids as $term){
|
|
| 848 | + if ($term->taxonomy == $post_types.'_tags') {
|
|
| 849 | + $terms_sql .= $wpdb->prepare(" OR FIND_IN_SET(%s , " . $table . ".post_tags) ", $term->name);
|
|
| 850 | + } else {
|
|
| 851 | + $terms_sql .= " OR FIND_IN_SET($term->term_id , " . $table . "." . $post_types . "category) "; |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | 856 | |
| 857 | 857 | |
| 858 | - if ($snear != '') {
|
|
| 858 | + if ($snear != '') {
|
|
| 859 | 859 | |
| 860 | 860 | |
| 861 | - if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) {
|
|
| 862 | - $dist = $gd_session->get('near_me_range');
|
|
| 863 | - } |
|
| 864 | - $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69); |
|
| 865 | - $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69); |
|
| 866 | - $lat1 = $mylat - ($dist / 69); |
|
| 867 | - $lat2 = $mylat + ($dist / 69); |
|
| 861 | + if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) {
|
|
| 862 | + $dist = $gd_session->get('near_me_range');
|
|
| 863 | + } |
|
| 864 | + $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69); |
|
| 865 | + $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69); |
|
| 866 | + $lat1 = $mylat - ($dist / 69); |
|
| 867 | + $lat2 = $mylat + ($dist / 69); |
|
| 868 | 868 | |
| 869 | - $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : ''; |
|
| 870 | - $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : ''; |
|
| 871 | - $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : ''; |
|
| 872 | - $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : ''; |
|
| 869 | + $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : ''; |
|
| 870 | + $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : ''; |
|
| 871 | + $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : ''; |
|
| 872 | + $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : ''; |
|
| 873 | 873 | |
| 874 | 874 | |
| 875 | 875 | |
| 876 | - $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
| 876 | + $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
| 877 | 877 | $content_where |
| 878 | 878 | $terms_sql |
| 879 | 879 | ) |
@@ -882,35 +882,35 @@ discard block |
||
| 882 | 882 | AND ( " . $table . ".post_latitude between $rlat1 and $rlat2 ) |
| 883 | 883 | AND ( " . $table . ".post_longitude between $rlon1 and $rlon2 ) "; |
| 884 | 884 | |
| 885 | - if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') {
|
|
| 886 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
|
| 887 | - $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;
|
|
| 888 | - } |
|
| 885 | + if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') {
|
|
| 886 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
|
| 887 | + $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;
|
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - } else {
|
|
| 890 | + } else {
|
|
| 891 | 891 | |
| 892 | 892 | |
| 893 | 893 | |
| 894 | - $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
| 894 | + $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
| 895 | 895 | $content_where |
| 896 | 896 | $terms_sql |
| 897 | 897 | ) |
| 898 | 898 | |
| 899 | 899 | AND $wpdb->posts.post_type in ('$post_types')
|
| 900 | 900 | AND ($wpdb->posts.post_status = 'publish') "; |
| 901 | - } |
|
| 901 | + } |
|
| 902 | 902 | |
| 903 | 903 | ########### WPML ########### |
| 904 | - if ( geodir_wpml_is_post_type_translated( $post_types ) ) {
|
|
| 904 | + if ( geodir_wpml_is_post_type_translated( $post_types ) ) {
|
|
| 905 | 905 | $lang_code = ICL_LANGUAGE_CODE; |
| 906 | 906 | |
| 907 | 907 | if ($lang_code && $post_types) {
|
| 908 | - $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') ";
|
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - ########### WPML ########### |
|
| 908 | + $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') ";
|
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + ########### WPML ########### |
|
| 912 | 912 | |
| 913 | - return $where; |
|
| 913 | + return $where; |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | |
@@ -925,45 +925,45 @@ discard block |
||
| 925 | 925 | * @return string Modified where query string. |
| 926 | 926 | */ |
| 927 | 927 | function author_filter_where($where) {
|
| 928 | - global $wpdb, $geodir_post_type, $table, $curr; |
|
| 928 | + global $wpdb, $geodir_post_type, $table, $curr; |
|
| 929 | 929 | |
| 930 | - $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
|
|
| 931 | - $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
| 930 | + $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
|
|
| 931 | + $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
| 932 | 932 | |
| 933 | - if (isset($_REQUEST['stype'])) {
|
|
| 934 | - $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']);
|
|
| 935 | - } else {
|
|
| 936 | - $where = " AND $wpdb->posts.post_type IN ('gd_place') ";
|
|
| 937 | - } |
|
| 933 | + if (isset($_REQUEST['stype'])) {
|
|
| 934 | + $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']);
|
|
| 935 | + } else {
|
|
| 936 | + $where = " AND $wpdb->posts.post_type IN ('gd_place') ";
|
|
| 937 | + } |
|
| 938 | 938 | |
| 939 | - if ($user_id > 0) {
|
|
| 940 | - if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') {
|
|
| 941 | - $user_fav_posts = geodir_get_user_favourites($user_id); |
|
| 942 | - $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1';
|
|
| 943 | - $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')";
|
|
| 944 | - } else |
|
| 945 | - $where .= " AND $wpdb->posts.post_author = $user_id"; |
|
| 946 | - |
|
| 947 | - if ($user_id == (int)get_current_user_id()) {
|
|
| 948 | - $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') ";
|
|
| 949 | - } else {
|
|
| 950 | - $where .= " AND $wpdb->posts.post_status = 'publish' "; |
|
| 951 | - } |
|
| 952 | - } else {
|
|
| 953 | - $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' "; |
|
| 954 | - } |
|
| 939 | + if ($user_id > 0) {
|
|
| 940 | + if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') {
|
|
| 941 | + $user_fav_posts = geodir_get_user_favourites($user_id); |
|
| 942 | + $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1';
|
|
| 943 | + $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')";
|
|
| 944 | + } else |
|
| 945 | + $where .= " AND $wpdb->posts.post_author = $user_id"; |
|
| 946 | + |
|
| 947 | + if ($user_id == (int)get_current_user_id()) {
|
|
| 948 | + $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') ";
|
|
| 949 | + } else {
|
|
| 950 | + $where .= " AND $wpdb->posts.post_status = 'publish' "; |
|
| 951 | + } |
|
| 952 | + } else {
|
|
| 953 | + $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' "; |
|
| 954 | + } |
|
| 955 | 955 | |
| 956 | - ########### WPML ########### |
|
| 957 | - if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) {
|
|
| 958 | - $lang_code = ICL_LANGUAGE_CODE; |
|
| 959 | - if ($lang_code) {
|
|
| 960 | - $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
| 961 | - } |
|
| 956 | + ########### WPML ########### |
|
| 957 | + if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) {
|
|
| 958 | + $lang_code = ICL_LANGUAGE_CODE; |
|
| 959 | + if ($lang_code) {
|
|
| 960 | + $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
| 961 | + } |
|
| 962 | 962 | |
| 963 | - } |
|
| 964 | - ########### WPML ########### |
|
| 963 | + } |
|
| 964 | + ########### WPML ########### |
|
| 965 | 965 | |
| 966 | - return $where; |
|
| 966 | + return $where; |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | /** |
@@ -978,11 +978,11 @@ discard block |
||
| 978 | 978 | */ |
| 979 | 979 | function geodir_filter_widget_join($join) |
| 980 | 980 | {
|
| 981 | - global $wp_query, $table; |
|
| 982 | - if (!empty($wp_query->query['with_pics_only'])) {
|
|
| 983 | - $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
| 984 | - } |
|
| 985 | - return $join; |
|
| 981 | + global $wp_query, $table; |
|
| 982 | + if (!empty($wp_query->query['with_pics_only'])) {
|
|
| 983 | + $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
| 984 | + } |
|
| 985 | + return $join; |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | 988 | /** |
@@ -997,43 +997,43 @@ discard block |
||
| 997 | 997 | */ |
| 998 | 998 | function geodir_filter_widget_where($where) |
| 999 | 999 | {
|
| 1000 | - global $wp_query, $table; |
|
| 1001 | - if (!empty($wp_query->query['show_featured_only'])) {
|
|
| 1002 | - $where .= " AND " . $table . ".is_featured = '1'"; |
|
| 1003 | - } |
|
| 1004 | - if (!empty($wp_query->query['show_special_only'])) {
|
|
| 1005 | - $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
| 1006 | - } |
|
| 1007 | - if (!empty($wp_query->query['with_pics_only'])) {
|
|
| 1008 | - $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
| 1009 | - } |
|
| 1010 | - if (!empty($wp_query->query['with_videos_only'])) {
|
|
| 1011 | - $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
| 1012 | - } |
|
| 1013 | - return $where; |
|
| 1000 | + global $wp_query, $table; |
|
| 1001 | + if (!empty($wp_query->query['show_featured_only'])) {
|
|
| 1002 | + $where .= " AND " . $table . ".is_featured = '1'"; |
|
| 1003 | + } |
|
| 1004 | + if (!empty($wp_query->query['show_special_only'])) {
|
|
| 1005 | + $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
| 1006 | + } |
|
| 1007 | + if (!empty($wp_query->query['with_pics_only'])) {
|
|
| 1008 | + $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
| 1009 | + } |
|
| 1010 | + if (!empty($wp_query->query['with_videos_only'])) {
|
|
| 1011 | + $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
| 1012 | + } |
|
| 1013 | + return $where; |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | |
| 1017 | 1017 | function geodir_related_posts_fields($fields) {
|
| 1018 | - global $wp_query, $wpdb, $table, $post; |
|
| 1018 | + global $wp_query, $wpdb, $table, $post; |
|
| 1019 | 1019 | |
| 1020 | - $fields .= ", " . $table . ".* "; |
|
| 1020 | + $fields .= ", " . $table . ".* "; |
|
| 1021 | 1021 | |
| 1022 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
|
| 1022 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
|
| 1023 | 1023 | |
| 1024 | - $mylat = $post->post_latitude; |
|
| 1025 | - $mylon = $post->post_longitude; |
|
| 1024 | + $mylat = $post->post_latitude; |
|
| 1025 | + $mylon = $post->post_longitude; |
|
| 1026 | 1026 | |
| 1027 | - $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 ";
|
|
| 1028 | - return $fields; |
|
| 1027 | + $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 ";
|
|
| 1028 | + return $fields; |
|
| 1029 | 1029 | } |
| 1030 | 1030 | function geodir_related_posts_fields_filter($query) {
|
| 1031 | - if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
| 1032 | - && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
|
| 1033 | - && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
|
| 1034 | - ) {
|
|
| 1035 | - add_filter('posts_fields', 'geodir_related_posts_fields', 1);
|
|
| 1036 | - } |
|
| 1031 | + if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
| 1032 | + && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
|
| 1033 | + && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
|
| 1034 | + ) {
|
|
| 1035 | + add_filter('posts_fields', 'geodir_related_posts_fields', 1);
|
|
| 1036 | + } |
|
| 1037 | 1037 | } |
| 1038 | 1038 | add_action('pre_get_posts', 'geodir_related_posts_fields_filter', 1);
|
| 1039 | 1039 | |
@@ -1048,30 +1048,30 @@ discard block |
||
| 1048 | 1048 | * @return string|null If field exists in table returns order by clause else returns empty. |
| 1049 | 1049 | */ |
| 1050 | 1050 | function geodir_prepare_custom_sorting( $sorting, $table ) {
|
| 1051 | - $orderby = ''; |
|
| 1051 | + $orderby = ''; |
|
| 1052 | 1052 | |
| 1053 | - if ( empty( $sorting ) || empty( $table ) ) {
|
|
| 1054 | - return $orderby; |
|
| 1055 | - } |
|
| 1053 | + if ( empty( $sorting ) || empty( $table ) ) {
|
|
| 1054 | + return $orderby; |
|
| 1055 | + } |
|
| 1056 | 1056 | |
| 1057 | - if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) {
|
|
| 1058 | - $sorting_array = explode( '_', $sorting ); |
|
| 1057 | + if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) {
|
|
| 1058 | + $sorting_array = explode( '_', $sorting ); |
|
| 1059 | 1059 | |
| 1060 | - if ( ( $count = count( $sorting_array ) ) > 1 ) {
|
|
| 1061 | - $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
| 1062 | - array_pop( $sorting_array ); |
|
| 1060 | + if ( ( $count = count( $sorting_array ) ) > 1 ) {
|
|
| 1061 | + $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
| 1062 | + array_pop( $sorting_array ); |
|
| 1063 | 1063 | |
| 1064 | - if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) {
|
|
| 1065 | - $sort_by = implode( '_', $sorting_array ); |
|
| 1064 | + if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) {
|
|
| 1065 | + $sort_by = implode( '_', $sorting_array ); |
|
| 1066 | 1066 | |
| 1067 | - if ( geodir_column_exist( $table, $sort_by ) ) {
|
|
| 1068 | - $orderby = $table . "." . $sort_by . " " . $order; |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - } |
|
| 1067 | + if ( geodir_column_exist( $table, $sort_by ) ) {
|
|
| 1068 | + $orderby = $table . "." . $sort_by . " " . $order; |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + } |
|
| 1073 | 1073 | |
| 1074 | - return $orderby; |
|
| 1074 | + return $orderby; |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | /** |
@@ -1091,21 +1091,21 @@ discard block |
||
| 1091 | 1091 | * @return string Modified fields SQL. |
| 1092 | 1092 | */ |
| 1093 | 1093 | function geodir_search_widget_location_filter_fields( $fields, $table, $post_type ) {
|
| 1094 | - global $wpdb, $gd_query_args_widgets, $snear, $gd_session; |
|
| 1094 | + global $wpdb, $gd_query_args_widgets, $snear, $gd_session; |
|
| 1095 | 1095 | |
| 1096 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) {
|
|
| 1097 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
| 1096 | + if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) {
|
|
| 1097 | + $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
| 1098 | 1098 | |
| 1099 | - if ( $location_allowed && strpos( strtolower( $fields ), ' as distance ' ) === false && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) {
|
|
| 1100 | - $latitude = sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
| 1101 | - $longitude = sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
| 1102 | - $radius = geodir_getDistanceRadius( get_option( 'geodir_search_dist_1' ) ); |
|
| 1099 | + if ( $location_allowed && strpos( strtolower( $fields ), ' as distance ' ) === false && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) {
|
|
| 1100 | + $latitude = sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
| 1101 | + $longitude = sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
| 1102 | + $radius = geodir_getDistanceRadius( get_option( 'geodir_search_dist_1' ) ); |
|
| 1103 | 1103 | |
| 1104 | - $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 );
|
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1104 | + $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 );
|
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | 1107 | |
| 1108 | - return $fields; |
|
| 1108 | + return $fields; |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | 1111 | /** |
@@ -1124,17 +1124,17 @@ discard block |
||
| 1124 | 1124 | * @return string Modified fields SQL. |
| 1125 | 1125 | */ |
| 1126 | 1126 | function geodir_search_widget_location_filter_orderby( $orderby, $table, $post_type ) {
|
| 1127 | - global $gd_query_args_widgets, $snear, $gd_session; |
|
| 1127 | + global $gd_query_args_widgets, $snear, $gd_session; |
|
| 1128 | 1128 | |
| 1129 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) {
|
|
| 1130 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
| 1129 | + if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) {
|
|
| 1130 | + $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
| 1131 | 1131 | |
| 1132 | - if ( $location_allowed && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) {
|
|
| 1133 | - $orderby = "distance ASC, " . $orderby; |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1132 | + if ( $location_allowed && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) {
|
|
| 1133 | + $orderby = "distance ASC, " . $orderby; |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | 1136 | |
| 1137 | - return $orderby; |
|
| 1137 | + return $orderby; |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | /** |
@@ -1145,23 +1145,23 @@ discard block |
||
| 1145 | 1145 | * @return string Filtered url. |
| 1146 | 1146 | */ |
| 1147 | 1147 | function geodir_search_page_base_url() {
|
| 1148 | - if ( function_exists( 'geodir_location_geo_home_link' ) ) {
|
|
| 1149 | - remove_filter( 'home_url', 'geodir_location_geo_home_link', 100000 ); |
|
| 1150 | - } |
|
| 1148 | + if ( function_exists( 'geodir_location_geo_home_link' ) ) {
|
|
| 1149 | + remove_filter( 'home_url', 'geodir_location_geo_home_link', 100000 ); |
|
| 1150 | + } |
|
| 1151 | 1151 | |
| 1152 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX && geodir_is_wpml() ) {
|
|
| 1153 | - $url = icl_get_home_url(); |
|
| 1154 | - } else {
|
|
| 1155 | - $url = get_home_url(); |
|
| 1156 | - } |
|
| 1152 | + if ( defined( 'DOING_AJAX' ) && DOING_AJAX && geodir_is_wpml() ) {
|
|
| 1153 | + $url = icl_get_home_url(); |
|
| 1154 | + } else {
|
|
| 1155 | + $url = get_home_url(); |
|
| 1156 | + } |
|
| 1157 | 1157 | |
| 1158 | - $url = trailingslashit( $url ); |
|
| 1158 | + $url = trailingslashit( $url ); |
|
| 1159 | 1159 | |
| 1160 | - if ( function_exists( 'geodir_location_geo_home_link' ) ) {
|
|
| 1161 | - add_filter( 'home_url', 'geodir_location_geo_home_link', 100000, 2 ); |
|
| 1162 | - } |
|
| 1160 | + if ( function_exists( 'geodir_location_geo_home_link' ) ) {
|
|
| 1161 | + add_filter( 'home_url', 'geodir_location_geo_home_link', 100000, 2 ); |
|
| 1162 | + } |
|
| 1163 | 1163 | |
| 1164 | - return apply_filters( 'geodir_search_page_base_url', $url ); |
|
| 1164 | + return apply_filters( 'geodir_search_page_base_url', $url ); |
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | /** |
@@ -1172,6 +1172,6 @@ discard block |
||
| 1172 | 1172 | function geodir_jetpack_fix_post_types_search(){
|
| 1173 | 1173 | if ( defined( 'JETPACK__VERSION' ) && ! empty( $_REQUEST['geodir_search'] ) ) {
|
| 1174 | 1174 | add_filter( 'jetpack_search_should_handle_query', '__return_false', 999, 1 ); |
| 1175 | - } |
|
| 1175 | + } |
|
| 1176 | 1176 | } |
| 1177 | 1177 | add_action( 'plugins_loaded','geodir_jetpack_fix_post_types_search', 10 ); |
| 1178 | 1178 | \ No newline at end of file |
@@ -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'])) {
|
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | if (isset($_REQUEST['s'])) {
|
| 118 | 118 | $s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s']))); |
| 119 | - $s = str_replace(array("%E2%80%99","’"),array("%27","'"),$s);
|
|
| 119 | + $s = str_replace(array("%E2%80%99", "’"), array("%27", "'"), $s);
|
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if ($snear == 'NEAR ME') {
|
| 123 | 123 | $ip = $_SERVER['REMOTE_ADDR']; |
| 124 | - $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip));
|
|
| 124 | + $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
|
|
| 125 | 125 | $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude])); |
| 126 | 126 | $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude])); |
| 127 | 127 | } |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | $s_AA = str_replace(" ", "", $s);
|
| 132 | 132 | $s_A = explode(",", $s_AA);
|
| 133 | 133 | $s_A = implode('","', $s_A);
|
| 134 | - $s_A = '"' . $s_A . '"'; |
|
| 134 | + $s_A = '"'.$s_A.'"'; |
|
| 135 | 135 | } else {
|
| 136 | - $s_A = '"' . $s . '"'; |
|
| 136 | + $s_A = '"'.$s.'"'; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | if (strstr($s, ' ')) {
|
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | } |
| 195 | 195 | if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) {
|
| 196 | 196 | |
| 197 | - $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
| 197 | + $table = $plugin_prefix.$geodir_post_type.'_detail'; |
|
| 198 | 198 | |
| 199 | 199 | add_filter('posts_fields', 'geodir_posts_fields', 1);
|
| 200 | 200 | add_filter('posts_join', 'geodir_posts_join', 1);
|
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; |
| 235 | 235 | |
| 236 | 236 | // Filter-Location-Manager to add location table. |
| 237 | - $fields .= ", " . $table . ".* "; |
|
| 237 | + $fields .= ", ".$table.".* "; |
|
| 238 | 238 | |
| 239 | 239 | if ($snear != '' || $gd_session->get('all_near_me')) {
|
| 240 | 240 | $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
@@ -244,16 +244,16 @@ discard block |
||
| 244 | 244 | $mylon = $gd_session->get('user_lon');
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - $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 | + $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 ";
|
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | global $s; |
| 251 | 251 | if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
|
| 252 | 252 | $keywords = explode(" ", $s);
|
| 253 | 253 | |
| 254 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
|
|
| 255 | - foreach($keywords as $kkey=>$kword){
|
|
| 256 | - if(geodir_utf8_strlen($kword)<=$klimit){
|
|
| 254 | + if (is_array($keywords) && $klimit = get_option('geodir_search_word_limit')) {
|
|
| 255 | + foreach ($keywords as $kkey=>$kword) {
|
|
| 256 | + if (geodir_utf8_strlen($kword) <= $klimit) {
|
|
| 257 | 257 | unset($keywords[$kkey]); |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -271,24 +271,24 @@ discard block |
||
| 271 | 271 | $count = 0; |
| 272 | 272 | foreach ($keywords as $keyword) {
|
| 273 | 273 | $keyword = trim($keyword); |
| 274 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
| 274 | + $keyword = wp_specialchars_decode($keyword, ENT_QUOTES); |
|
| 275 | 275 | $count++; |
| 276 | 276 | if ($count < count($keywords)) {
|
| 277 | 277 | // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; |
| 278 | - $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 | + $gd_titlematch_part .= "( ".$wpdb->posts.".post_title LIKE '".$keyword."' OR ".$wpdb->posts.".post_title LIKE '".$keyword."%%' OR ".$wpdb->posts.".post_title LIKE '%% ".$keyword."%%' ) ".$key." "; |
|
| 279 | 279 | } else {
|
| 280 | 280 | //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; |
| 281 | - $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) "; |
|
| 281 | + $gd_titlematch_part .= "( ".$wpdb->posts.".post_title LIKE '".$keyword."' OR ".$wpdb->posts.".post_title LIKE '".$keyword."%%' OR ".$wpdb->posts.".post_title LIKE '%% ".$keyword."%%' ) "; |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; |
|
| 284 | + $gd_titlematch_part .= "THEN 1 ELSE 0 END AS ".$part.","; |
|
| 285 | 285 | } |
| 286 | 286 | } else {
|
| 287 | 287 | $gd_titlematch_part = ""; |
| 288 | 288 | } |
| 289 | - $s = stripslashes_deep( $s ); |
|
| 290 | - $s = wp_specialchars_decode($s,ENT_QUOTES); |
|
| 291 | - $fields .= $wpdb->prepare(", CASE WHEN " . $table . ".is_featured='1' THEN 1 ELSE 0 END AS gd_featured, CASE WHEN " . $wpdb->posts . ".post_title LIKE %s THEN 1 ELSE 0 END AS gd_exacttitle," . $gd_titlematch_part . " CASE WHEN ( " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s ) THEN 1 ELSE 0 END AS gd_titlematch, CASE WHEN ( " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s ) THEN 1 ELSE 0 END AS gd_content", array($s, $s, $s . '%', '% ' . $s . '%', $s, $s . ' %', '% ' . $s . ' %', '% ' . $s));
|
|
| 289 | + $s = stripslashes_deep($s); |
|
| 290 | + $s = wp_specialchars_decode($s, ENT_QUOTES); |
|
| 291 | + $fields .= $wpdb->prepare(", CASE WHEN ".$table.".is_featured='1' THEN 1 ELSE 0 END AS gd_featured, CASE WHEN ".$wpdb->posts.".post_title LIKE %s THEN 1 ELSE 0 END AS gd_exacttitle,".$gd_titlematch_part." CASE WHEN ( ".$wpdb->posts.".post_title LIKE %s OR ".$wpdb->posts.".post_title LIKE %s OR ".$wpdb->posts.".post_title LIKE %s ) THEN 1 ELSE 0 END AS gd_titlematch, CASE WHEN ( ".$wpdb->posts.".post_content LIKE %s OR ".$wpdb->posts.".post_content LIKE %s OR ".$wpdb->posts.".post_content LIKE %s OR ".$wpdb->posts.".post_content LIKE %s ) THEN 1 ELSE 0 END AS gd_content", array($s, $s, $s.'%', '% '.$s.'%', $s, $s.' %', '% '.$s.' %', '% '.$s));
|
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | return $fields; |
@@ -312,18 +312,18 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | ########### WPML ########### |
| 314 | 314 | |
| 315 | - if ( geodir_wpml_is_post_type_translated( $geodir_post_type ) ) {
|
|
| 315 | + if (geodir_wpml_is_post_type_translated($geodir_post_type)) {
|
|
| 316 | 316 | global $sitepress; |
| 317 | 317 | $lang_code = ICL_LANGUAGE_CODE; |
| 318 | 318 | $default_lang_code = $sitepress->get_default_language(); |
| 319 | 319 | if ($lang_code) {
|
| 320 | - $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID"; |
|
| 320 | + $join .= "JOIN ".$table_prefix."icl_translations icl_t ON icl_t.element_id = ".$table_prefix."posts.ID"; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | } |
| 324 | 324 | ########### WPML ########### |
| 325 | 325 | |
| 326 | - $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID) ";
|
|
| 326 | + $join .= " INNER JOIN ".$table." ON (".$table.".post_id = $wpdb->posts.ID) ";
|
|
| 327 | 327 | //===old code start |
| 328 | 328 | //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id) " ;//===old code end
|
| 329 | 329 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | $sort_by = 'az'; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - if ($snear != '' && $sort_by!='farthest') {
|
|
| 395 | + if ($snear != '' && $sort_by != 'farthest') {
|
|
| 396 | 396 | $sort_by = 'nearest'; |
| 397 | 397 | } |
| 398 | 398 | } |
@@ -406,20 +406,20 @@ discard block |
||
| 406 | 406 | break; |
| 407 | 407 | case 'low_review': |
| 408 | 408 | case 'rating_count_asc': |
| 409 | - $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, "; |
|
| 409 | + $orderby = $table.".rating_count ASC, ".$table.".overall_rating ASC, "; |
|
| 410 | 410 | break; |
| 411 | 411 | case 'high_review': |
| 412 | 412 | case 'rating_count_desc': |
| 413 | - $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, "; |
|
| 413 | + $orderby = $table.".rating_count DESC, ".$table.".overall_rating DESC, "; |
|
| 414 | 414 | break; |
| 415 | 415 | case 'low_rating': |
| 416 | - $orderby = "( " . $table . ".overall_rating ) ASC, " . $table . ".rating_count ASC, "; |
|
| 416 | + $orderby = "( ".$table.".overall_rating ) ASC, ".$table.".rating_count ASC, "; |
|
| 417 | 417 | break; |
| 418 | 418 | case 'high_rating': |
| 419 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
| 419 | + $orderby = " ".$table.".overall_rating DESC, ".$table.".rating_count DESC, "; |
|
| 420 | 420 | break; |
| 421 | 421 | case 'featured': |
| 422 | - $orderby = $table . ".is_featured asc, "; |
|
| 422 | + $orderby = $table.".is_featured asc, "; |
|
| 423 | 423 | break; |
| 424 | 424 | case 'nearest': |
| 425 | 425 | $orderby = " distance asc, "; |
@@ -435,10 +435,10 @@ discard block |
||
| 435 | 435 | break; |
| 436 | 436 | // sort by rating |
| 437 | 437 | case 'overall_rating_desc': |
| 438 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
| 438 | + $orderby = " ".$table.".overall_rating DESC, ".$table.".rating_count DESC, "; |
|
| 439 | 439 | break; |
| 440 | 440 | case 'overall_rating_asc': |
| 441 | - $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, "; |
|
| 441 | + $orderby = " ".$table.".overall_rating ASC, ".$table.".rating_count ASC, "; |
|
| 442 | 442 | break; |
| 443 | 443 | default: |
| 444 | 444 | |
@@ -459,24 +459,24 @@ discard block |
||
| 459 | 459 | |
| 460 | 460 | if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
|
| 461 | 461 | $keywords = explode(" ", $s);
|
| 462 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
|
|
| 463 | - foreach($keywords as $kkey=>$kword){
|
|
| 464 | - if(geodir_utf8_strlen($kword)<=$klimit){
|
|
| 462 | + if (is_array($keywords) && $klimit = get_option('geodir_search_word_limit')) {
|
|
| 463 | + foreach ($keywords as $kkey=>$kword) {
|
|
| 464 | + if (geodir_utf8_strlen($kword) <= $klimit) {
|
|
| 465 | 465 | unset($keywords[$kkey]); |
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | if ($sort_by == 'nearest' || $sort_by == 'farthest') {
|
| 470 | 470 | if (count($keywords) > 1) {
|
| 471 | - $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 | + $orderby = $orderby." ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, "; |
|
| 472 | 472 | } else {
|
| 473 | - $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
| 473 | + $orderby = $orderby." ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
| 474 | 474 | } |
| 475 | 475 | } else {
|
| 476 | 476 | if (count($keywords) > 1) {
|
| 477 | - $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 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, ".$orderby; |
|
| 478 | 478 | } else {
|
| 479 | - $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby; |
|
| 479 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, ".$orderby; |
|
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | } |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | $orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table);
|
| 493 | 493 | |
| 494 | - $orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title "; |
|
| 494 | + $orderby .= $table.".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title "; |
|
| 495 | 495 | |
| 496 | 496 | return $orderby; |
| 497 | 497 | } |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | |
| 514 | 514 | global $wpdb; |
| 515 | 515 | |
| 516 | - if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' || $_REQUEST['s']==' ') ) )) {
|
|
| 516 | + if ($sort_by != '' && (!is_search() || (isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear'] == '' && ($_REQUEST['s'] == '' || $_REQUEST['s'] == ' ')))) {
|
|
| 517 | 517 | |
| 518 | 518 | $sort_array = explode('_', $sort_by);
|
| 519 | 519 | |
@@ -523,48 +523,48 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) {
|
| 525 | 525 | |
| 526 | - $sort_by = str_replace('_' . $order, '', $sort_by);
|
|
| 526 | + $sort_by = str_replace('_'.$order, '', $sort_by);
|
|
| 527 | 527 | |
| 528 | 528 | switch ($sort_by): |
| 529 | 529 | |
| 530 | 530 | case 'post_date': |
| 531 | 531 | case 'comment_count': |
| 532 | 532 | |
| 533 | - $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", "; |
|
| 533 | + $orderby = "$wpdb->posts.".$sort_by." ".$order.", ".$table.".overall_rating ".$order.", "; |
|
| 534 | 534 | break; |
| 535 | 535 | |
| 536 | 536 | case 'distance': |
| 537 | - $orderby = $sort_by . " " . $order . ", "; |
|
| 537 | + $orderby = $sort_by." ".$order.", "; |
|
| 538 | 538 | break; |
| 539 | 539 | |
| 540 | 540 | |
| 541 | 541 | // sort by rating |
| 542 | 542 | case 'overall_rating': |
| 543 | 543 | |
| 544 | - $use_bayesian = apply_filters('gd_use_bayesian',true,$table);
|
|
| 544 | + $use_bayesian = apply_filters('gd_use_bayesian', true, $table);
|
|
| 545 | 545 | $avg_rating = 0; |
| 546 | - if($use_bayesian){
|
|
| 547 | - $avg_num_votes = get_transient( 'gd_avg_num_votes_'.$table ); |
|
| 548 | - if(!$avg_num_votes){
|
|
| 546 | + if ($use_bayesian) {
|
|
| 547 | + $avg_num_votes = get_transient('gd_avg_num_votes_'.$table);
|
|
| 548 | + if (!$avg_num_votes) {
|
|
| 549 | 549 | $avg_num_votes = $wpdb->get_var("SELECT SUM(rating_count) FROM $table");
|
| 550 | - if($avg_num_votes){
|
|
| 550 | + if ($avg_num_votes) {
|
|
| 551 | 551 | |
| 552 | - $avg_rating = get_transient( 'gd_avg_rating_'.$table ); |
|
| 553 | - if(!$avg_rating){
|
|
| 554 | - $avg_rating = $wpdb->get_var("SELECT SUM(overall_rating) FROM $table")/$avg_num_votes;
|
|
| 552 | + $avg_rating = get_transient('gd_avg_rating_'.$table);
|
|
| 553 | + if (!$avg_rating) {
|
|
| 554 | + $avg_rating = $wpdb->get_var("SELECT SUM(overall_rating) FROM $table") / $avg_num_votes;
|
|
| 555 | 555 | } |
| 556 | - set_transient( 'gd_avg_num_votes_'.$table, $avg_num_votes, 12 * HOUR_IN_SECONDS ); |
|
| 557 | - set_transient( 'gd_avg_rating_'.$table, $avg_rating , 12 * HOUR_IN_SECONDS ); |
|
| 556 | + set_transient('gd_avg_num_votes_'.$table, $avg_num_votes, 12 * HOUR_IN_SECONDS);
|
|
| 557 | + set_transient('gd_avg_rating_'.$table, $avg_rating, 12 * HOUR_IN_SECONDS);
|
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - if(!$avg_num_votes){ $avg_num_votes = 0;}
|
|
| 561 | + if (!$avg_num_votes) { $avg_num_votes = 0; }
|
|
| 562 | 562 | |
| 563 | - $orderby = " (( $avg_num_votes * $avg_rating ) + (" . $table . ".rating_count * " . $table . ".overall_rating )) / ( $avg_num_votes + " . $table . ".rating_count ) $order , ";
|
|
| 563 | + $orderby = " (( $avg_num_votes * $avg_rating ) + (".$table.".rating_count * ".$table.".overall_rating )) / ( $avg_num_votes + ".$table.".rating_count ) $order , ";
|
|
| 564 | 564 | |
| 565 | 565 | //$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
|
| 566 | - }else{
|
|
| 567 | - $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
| 566 | + } else {
|
|
| 567 | + $orderby = " ".$table.".".$sort_by." ".$order.", ".$table.".rating_count ".$order.", "; |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | break; |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | |
| 573 | 573 | default: |
| 574 | 574 | if (geodir_column_exist($table, $sort_by)) {
|
| 575 | - $orderby = $table . "." . $sort_by . " " . $order . ", "; |
|
| 575 | + $orderby = $table.".".$sort_by." ".$order.", "; |
|
| 576 | 576 | } |
| 577 | 577 | break; |
| 578 | 578 | |
@@ -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,10 +800,10 @@ 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 | 809 | if ($s != '') {
|
@@ -814,7 +814,7 @@ discard block |
||
| 814 | 814 | * @package GeoDirectory |
| 815 | 815 | * @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%\") ") "`. |
| 816 | 816 | */ |
| 817 | - $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%\") ");
|
|
| 817 | + $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%\") ");
|
|
| 818 | 818 | /** |
| 819 | 819 | * Filter the search query term values. |
| 820 | 820 | * |
@@ -822,7 +822,7 @@ discard block |
||
| 822 | 822 | * @package GeoDirectory |
| 823 | 823 | * @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)) "`. |
| 824 | 824 | */ |
| 825 | - $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)) ");
|
|
| 825 | + $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)) ");
|
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | |
@@ -839,16 +839,16 @@ discard block |
||
| 839 | 839 | $term_ids = array(); |
| 840 | 840 | $terms_sql = ''; |
| 841 | 841 | |
| 842 | - if(!empty($term_results)){
|
|
| 843 | - foreach($term_results as $term_id){
|
|
| 842 | + if (!empty($term_results)) {
|
|
| 843 | + foreach ($term_results as $term_id) {
|
|
| 844 | 844 | $term_ids[] = $term_id; |
| 845 | 845 | } |
| 846 | 846 | if (!empty($term_ids)) {
|
| 847 | - foreach($term_ids as $term){
|
|
| 847 | + foreach ($term_ids as $term) {
|
|
| 848 | 848 | if ($term->taxonomy == $post_types.'_tags') {
|
| 849 | - $terms_sql .= $wpdb->prepare(" OR FIND_IN_SET(%s , " . $table . ".post_tags) ", $term->name);
|
|
| 849 | + $terms_sql .= $wpdb->prepare(" OR FIND_IN_SET(%s , ".$table.".post_tags) ", $term->name);
|
|
| 850 | 850 | } else {
|
| 851 | - $terms_sql .= " OR FIND_IN_SET($term->term_id , " . $table . "." . $post_types . "category) "; |
|
| 851 | + $terms_sql .= " OR FIND_IN_SET($term->term_id , ".$table.".".$post_types."category) "; |
|
| 852 | 852 | } |
| 853 | 853 | } |
| 854 | 854 | } |
@@ -879,12 +879,12 @@ discard block |
||
| 879 | 879 | ) |
| 880 | 880 | AND $wpdb->posts.post_type in ('{$post_types}')
|
| 881 | 881 | AND ($wpdb->posts.post_status = 'publish') |
| 882 | - AND ( " . $table . ".post_latitude between $rlat1 and $rlat2 ) |
|
| 883 | - AND ( " . $table . ".post_longitude between $rlon1 and $rlon2 ) "; |
|
| 882 | + AND ( ".$table.".post_latitude between $rlat1 and $rlat2 ) |
|
| 883 | + AND ( ".$table.".post_longitude between $rlon1 and $rlon2 ) "; |
|
| 884 | 884 | |
| 885 | 885 | if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') {
|
| 886 | 886 | $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
| 887 | - $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;
|
|
| 887 | + $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;
|
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | } else {
|
@@ -901,11 +901,11 @@ discard block |
||
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | ########### WPML ########### |
| 904 | - if ( geodir_wpml_is_post_type_translated( $post_types ) ) {
|
|
| 904 | + if (geodir_wpml_is_post_type_translated($post_types)) {
|
|
| 905 | 905 | $lang_code = ICL_LANGUAGE_CODE; |
| 906 | 906 | |
| 907 | 907 | if ($lang_code && $post_types) {
|
| 908 | - $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') ";
|
|
| 908 | + $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_".$post_types."') ";
|
|
| 909 | 909 | } |
| 910 | 910 | } |
| 911 | 911 | ########### WPML ########### |
@@ -928,10 +928,10 @@ discard block |
||
| 928 | 928 | global $wpdb, $geodir_post_type, $table, $curr; |
| 929 | 929 | |
| 930 | 930 | $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
|
| 931 | - $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
| 931 | + $user_id = !empty($curauth->ID) ? (int) $curauth->ID : 0; |
|
| 932 | 932 | |
| 933 | 933 | if (isset($_REQUEST['stype'])) {
|
| 934 | - $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']);
|
|
| 934 | + $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ", $_REQUEST['stype']);
|
|
| 935 | 935 | } else {
|
| 936 | 936 | $where = " AND $wpdb->posts.post_type IN ('gd_place') ";
|
| 937 | 937 | } |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | } else |
| 945 | 945 | $where .= " AND $wpdb->posts.post_author = $user_id"; |
| 946 | 946 | |
| 947 | - if ($user_id == (int)get_current_user_id()) {
|
|
| 947 | + if ($user_id == (int) get_current_user_id()) {
|
|
| 948 | 948 | $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') ";
|
| 949 | 949 | } else {
|
| 950 | 950 | $where .= " AND $wpdb->posts.post_status = 'publish' "; |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) {
|
| 958 | 958 | $lang_code = ICL_LANGUAGE_CODE; |
| 959 | 959 | if ($lang_code) {
|
| 960 | - $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
| 960 | + $where .= " AND icl_t.language_code='".$lang_code."' "; |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | } |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | {
|
| 981 | 981 | global $wp_query, $table; |
| 982 | 982 | if (!empty($wp_query->query['with_pics_only'])) {
|
| 983 | - $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
| 983 | + $join .= " LEFT JOIN ".GEODIR_ATTACHMENT_TABLE." ON ( ".GEODIR_ATTACHMENT_TABLE.".post_id=".$table.".post_id AND ".GEODIR_ATTACHMENT_TABLE.".mime_type LIKE '%image%' )"; |
|
| 984 | 984 | } |
| 985 | 985 | return $join; |
| 986 | 986 | } |
@@ -999,16 +999,16 @@ discard block |
||
| 999 | 999 | {
|
| 1000 | 1000 | global $wp_query, $table; |
| 1001 | 1001 | if (!empty($wp_query->query['show_featured_only'])) {
|
| 1002 | - $where .= " AND " . $table . ".is_featured = '1'"; |
|
| 1002 | + $where .= " AND ".$table.".is_featured = '1'"; |
|
| 1003 | 1003 | } |
| 1004 | 1004 | if (!empty($wp_query->query['show_special_only'])) {
|
| 1005 | - $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
| 1005 | + $where .= " AND ( ".$table.".geodir_special_offers != '' AND ".$table.".geodir_special_offers IS NOT NULL )"; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | if (!empty($wp_query->query['with_pics_only'])) {
|
| 1008 | - $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
| 1008 | + $where .= " AND ".GEODIR_ATTACHMENT_TABLE.".ID IS NOT NULL GROUP BY ".$table.".post_id"; |
|
| 1009 | 1009 | } |
| 1010 | 1010 | if (!empty($wp_query->query['with_videos_only'])) {
|
| 1011 | - $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
| 1011 | + $where .= " AND ( ".$table.".geodir_video != '' AND ".$table.".geodir_video IS NOT NULL )"; |
|
| 1012 | 1012 | } |
| 1013 | 1013 | return $where; |
| 1014 | 1014 | } |
@@ -1017,18 +1017,18 @@ discard block |
||
| 1017 | 1017 | function geodir_related_posts_fields($fields) {
|
| 1018 | 1018 | global $wp_query, $wpdb, $table, $post; |
| 1019 | 1019 | |
| 1020 | - $fields .= ", " . $table . ".* "; |
|
| 1020 | + $fields .= ", ".$table.".* "; |
|
| 1021 | 1021 | |
| 1022 | 1022 | $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
| 1023 | 1023 | |
| 1024 | 1024 | $mylat = $post->post_latitude; |
| 1025 | 1025 | $mylon = $post->post_longitude; |
| 1026 | 1026 | |
| 1027 | - $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 ";
|
|
| 1027 | + $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 ";
|
|
| 1028 | 1028 | return $fields; |
| 1029 | 1029 | } |
| 1030 | 1030 | function geodir_related_posts_fields_filter($query) {
|
| 1031 | - if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
| 1031 | + if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
| 1032 | 1032 | && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
| 1033 | 1033 | && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
| 1034 | 1034 | ) {
|
@@ -1047,25 +1047,25 @@ discard block |
||
| 1047 | 1047 | * @param string $table Listing table name. |
| 1048 | 1048 | * @return string|null If field exists in table returns order by clause else returns empty. |
| 1049 | 1049 | */ |
| 1050 | -function geodir_prepare_custom_sorting( $sorting, $table ) {
|
|
| 1050 | +function geodir_prepare_custom_sorting($sorting, $table) {
|
|
| 1051 | 1051 | $orderby = ''; |
| 1052 | 1052 | |
| 1053 | - if ( empty( $sorting ) || empty( $table ) ) {
|
|
| 1053 | + if (empty($sorting) || empty($table)) {
|
|
| 1054 | 1054 | return $orderby; |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | - if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) {
|
|
| 1058 | - $sorting_array = explode( '_', $sorting ); |
|
| 1057 | + if (strpos(strtoupper($sorting), '_ASC') !== false || strpos(strtoupper($sorting), '_DESC') !== false) {
|
|
| 1058 | + $sorting_array = explode('_', $sorting);
|
|
| 1059 | 1059 | |
| 1060 | - if ( ( $count = count( $sorting_array ) ) > 1 ) {
|
|
| 1061 | - $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
| 1062 | - array_pop( $sorting_array ); |
|
| 1060 | + if (($count = count($sorting_array)) > 1) {
|
|
| 1061 | + $order = !empty($sorting_array[$count - 1]) ? strtoupper($sorting_array[$count - 1]) : ''; |
|
| 1062 | + array_pop($sorting_array); |
|
| 1063 | 1063 | |
| 1064 | - if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) {
|
|
| 1065 | - $sort_by = implode( '_', $sorting_array ); |
|
| 1064 | + if (!empty($sorting_array) && ($order == 'ASC' || $order == 'DESC')) {
|
|
| 1065 | + $sort_by = implode('_', $sorting_array);
|
|
| 1066 | 1066 | |
| 1067 | - if ( geodir_column_exist( $table, $sort_by ) ) {
|
|
| 1068 | - $orderby = $table . "." . $sort_by . " " . $order; |
|
| 1067 | + if (geodir_column_exist($table, $sort_by)) {
|
|
| 1068 | + $orderby = $table.".".$sort_by." ".$order; |
|
| 1069 | 1069 | } |
| 1070 | 1070 | } |
| 1071 | 1071 | } |
@@ -1090,18 +1090,18 @@ discard block |
||
| 1090 | 1090 | * |
| 1091 | 1091 | * @return string Modified fields SQL. |
| 1092 | 1092 | */ |
| 1093 | -function geodir_search_widget_location_filter_fields( $fields, $table, $post_type ) {
|
|
| 1093 | +function geodir_search_widget_location_filter_fields($fields, $table, $post_type) {
|
|
| 1094 | 1094 | global $wpdb, $gd_query_args_widgets, $snear, $gd_session; |
| 1095 | 1095 | |
| 1096 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) {
|
|
| 1097 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
| 1096 | + if (!empty($gd_query_args_widgets['gd_location']) && geodir_is_page('search') && !empty($_REQUEST['sgeo_lat']) && !empty($_REQUEST['sgeo_lon'])) {
|
|
| 1097 | + $location_allowed = function_exists('geodir_cpt_no_location') && geodir_cpt_no_location($post_type) ? false : true;
|
|
| 1098 | 1098 | |
| 1099 | - if ( $location_allowed && strpos( strtolower( $fields ), ' as distance ' ) === false && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) {
|
|
| 1100 | - $latitude = sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
| 1101 | - $longitude = sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
| 1102 | - $radius = geodir_getDistanceRadius( get_option( 'geodir_search_dist_1' ) ); |
|
| 1099 | + if ($location_allowed && strpos(strtolower($fields), ' as distance ') === false && ($snear != '' || $gd_session->get('all_near_me'))) {
|
|
| 1100 | + $latitude = sanitize_text_field($_REQUEST['sgeo_lat']); |
|
| 1101 | + $longitude = sanitize_text_field($_REQUEST['sgeo_lon']); |
|
| 1102 | + $radius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
|
|
| 1103 | 1103 | |
| 1104 | - $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 );
|
|
| 1104 | + $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);
|
|
| 1105 | 1105 | } |
| 1106 | 1106 | } |
| 1107 | 1107 | |
@@ -1123,14 +1123,14 @@ discard block |
||
| 1123 | 1123 | * |
| 1124 | 1124 | * @return string Modified fields SQL. |
| 1125 | 1125 | */ |
| 1126 | -function geodir_search_widget_location_filter_orderby( $orderby, $table, $post_type ) {
|
|
| 1126 | +function geodir_search_widget_location_filter_orderby($orderby, $table, $post_type) {
|
|
| 1127 | 1127 | global $gd_query_args_widgets, $snear, $gd_session; |
| 1128 | 1128 | |
| 1129 | - if ( !empty( $gd_query_args_widgets['gd_location'] ) && geodir_is_page( 'search' ) && !empty( $_REQUEST['sgeo_lat'] ) && !empty( $_REQUEST['sgeo_lon'] ) ) {
|
|
| 1130 | - $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; |
|
| 1129 | + if (!empty($gd_query_args_widgets['gd_location']) && geodir_is_page('search') && !empty($_REQUEST['sgeo_lat']) && !empty($_REQUEST['sgeo_lon'])) {
|
|
| 1130 | + $location_allowed = function_exists('geodir_cpt_no_location') && geodir_cpt_no_location($post_type) ? false : true;
|
|
| 1131 | 1131 | |
| 1132 | - if ( $location_allowed && ( $snear != '' || $gd_session->get( 'all_near_me' ) ) ) {
|
|
| 1133 | - $orderby = "distance ASC, " . $orderby; |
|
| 1132 | + if ($location_allowed && ($snear != '' || $gd_session->get('all_near_me'))) {
|
|
| 1133 | + $orderby = "distance ASC, ".$orderby; |
|
| 1134 | 1134 | } |
| 1135 | 1135 | } |
| 1136 | 1136 | |
@@ -1145,23 +1145,23 @@ discard block |
||
| 1145 | 1145 | * @return string Filtered url. |
| 1146 | 1146 | */ |
| 1147 | 1147 | function geodir_search_page_base_url() {
|
| 1148 | - if ( function_exists( 'geodir_location_geo_home_link' ) ) {
|
|
| 1149 | - remove_filter( 'home_url', 'geodir_location_geo_home_link', 100000 ); |
|
| 1148 | + if (function_exists('geodir_location_geo_home_link')) {
|
|
| 1149 | + remove_filter('home_url', 'geodir_location_geo_home_link', 100000);
|
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX && geodir_is_wpml() ) {
|
|
| 1152 | + if (defined('DOING_AJAX') && DOING_AJAX && geodir_is_wpml()) {
|
|
| 1153 | 1153 | $url = icl_get_home_url(); |
| 1154 | 1154 | } else {
|
| 1155 | 1155 | $url = get_home_url(); |
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 1158 | - $url = trailingslashit( $url ); |
|
| 1158 | + $url = trailingslashit($url); |
|
| 1159 | 1159 | |
| 1160 | - if ( function_exists( 'geodir_location_geo_home_link' ) ) {
|
|
| 1161 | - add_filter( 'home_url', 'geodir_location_geo_home_link', 100000, 2 ); |
|
| 1160 | + if (function_exists('geodir_location_geo_home_link')) {
|
|
| 1161 | + add_filter('home_url', 'geodir_location_geo_home_link', 100000, 2);
|
|
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | - return apply_filters( 'geodir_search_page_base_url', $url ); |
|
| 1164 | + return apply_filters('geodir_search_page_base_url', $url);
|
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | /** |
@@ -1169,9 +1169,9 @@ discard block |
||
| 1169 | 1169 | * |
| 1170 | 1170 | * @since 1.6.31 |
| 1171 | 1171 | */ |
| 1172 | -function geodir_jetpack_fix_post_types_search(){
|
|
| 1173 | - if ( defined( 'JETPACK__VERSION' ) && ! empty( $_REQUEST['geodir_search'] ) ) {
|
|
| 1174 | - add_filter( 'jetpack_search_should_handle_query', '__return_false', 999, 1 ); |
|
| 1172 | +function geodir_jetpack_fix_post_types_search() {
|
|
| 1173 | + if (defined('JETPACK__VERSION') && !empty($_REQUEST['geodir_search'])) {
|
|
| 1174 | + add_filter('jetpack_search_should_handle_query', '__return_false', 999, 1);
|
|
| 1175 | 1175 | } |
| 1176 | 1176 | } |
| 1177 | -add_action( 'plugins_loaded','geodir_jetpack_fix_post_types_search', 10 ); |
|
| 1178 | 1177 | \ No newline at end of file |
| 1178 | +add_action('plugins_loaded', 'geodir_jetpack_fix_post_types_search', 10); |
|
| 1179 | 1179 | \ No newline at end of file |