Test Failed
Push — master ( e5595a...a8f18e )
by
unknown
08:36
created
geodirectory-functions/comments_functions.php 1 patch
Indentation   +446 added lines, -446 removed lines patch added patch discarded remove patch
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function geodir_comment_meta_row_action($a)
33 33
 {
34
-    global $comment;
34
+	global $comment;
35 35
 
36
-    $rating = geodir_get_commentoverall($comment->comment_ID);
37
-    if ($rating != 0) {
38
-        echo geodir_get_rating_stars($rating, $comment->comment_ID);
39
-    }
40
-    return $a;
36
+	$rating = geodir_get_commentoverall($comment->comment_ID);
37
+	if ($rating != 0) {
38
+		echo geodir_get_rating_stars($rating, $comment->comment_ID);
39
+	}
40
+	return $a;
41 41
 }
42 42
 
43 43
 add_action('add_meta_boxes_comment', 'geodir_comment_add_meta_box');
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
  */
53 53
 function geodir_comment_add_meta_box($comment)
54 54
 {
55
-    add_meta_box('gd-comment-rating', __('Comment Rating', 'geodirectory'), 'geodir_comment_rating_meta', 'comment', 'normal', 'high');
55
+	add_meta_box('gd-comment-rating', __('Comment Rating', 'geodirectory'), 'geodir_comment_rating_meta', 'comment', 'normal', 'high');
56 56
 }
57 57
 
58 58
 /**
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
  * @param object $comment The comment object.
67 67
  */
68 68
 function geodir_comment_rating_meta($comment) {
69
-    $post_type = get_post_type($comment->comment_post_ID);
69
+	$post_type = get_post_type($comment->comment_post_ID);
70 70
 	if (in_array($post_type, (array)geodir_get_posttypes()) && (int)$comment->comment_parent == 0 && !(!empty($post_type) && geodir_cpt_has_rating_disabled($post_type))) {
71 71
 		$rating = geodir_get_commentoverall($comment->comment_ID);
72 72
 		
@@ -106,24 +106,24 @@  discard block
 block discarded – undo
106 106
  * @global object $post The post object.
107 107
  */
108 108
 function geodir_comment_rating_fields() {
109
-    global $post;
109
+	global $post;
110 110
 
111
-    $post_types = geodir_get_posttypes();
111
+	$post_types = geodir_get_posttypes();
112 112
 
113
-    if (!empty($post->post_type) && in_array($post->post_type, $post_types) && !(!empty($post->post_type) && geodir_cpt_has_rating_disabled($post->post_type))) {
114
-        $star_texts = array();
115
-        $star_texts[] = __('Terrible', 'geodirectory');
116
-        $star_texts[] = __('Poor', 'geodirectory');
117
-        $star_texts[] = __('Average', 'geodirectory');
118
-        $star_texts[] = __('Very Good', 'geodirectory');
119
-        $star_texts[] = __('Excellent', 'geodirectory');
113
+	if (!empty($post->post_type) && in_array($post->post_type, $post_types) && !(!empty($post->post_type) && geodir_cpt_has_rating_disabled($post->post_type))) {
114
+		$star_texts = array();
115
+		$star_texts[] = __('Terrible', 'geodirectory');
116
+		$star_texts[] = __('Poor', 'geodirectory');
117
+		$star_texts[] = __('Average', 'geodirectory');
118
+		$star_texts[] = __('Very Good', 'geodirectory');
119
+		$star_texts[] = __('Excellent', 'geodirectory');
120 120
         
121
-        $gd_rating_html = apply_filters('gd_rating_form_html', '<div class="gd_rating" data-average="0" data-id="5"></div>', $star_texts);
122
-        echo $gd_rating_html;
123
-        ?>
121
+		$gd_rating_html = apply_filters('gd_rating_form_html', '<div class="gd_rating" data-average="0" data-id="5"></div>', $star_texts);
122
+		echo $gd_rating_html;
123
+		?>
124 124
         <input type="hidden" id="geodir_overallrating" name="geodir_overallrating" value="0"/>
125 125
         <?php
126
-    }
126
+	}
127 127
 }
128 128
 
129 129
 add_filter('comment_reply_link', 'geodir_comment_replaylink');
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
 function geodir_comment_replaylink($link)
139 139
 {
140 140
 
141
-    $link = '<div class="gd_comment_replaylink">' . $link . '</div>';
141
+	$link = '<div class="gd_comment_replaylink">' . $link . '</div>';
142 142
 
143
-    return $link;
143
+	return $link;
144 144
 }
145 145
 
146 146
 add_filter('cancel_comment_reply_link', 'geodir_cancle_replaylink');
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 function geodir_cancle_replaylink($link)
156 156
 {
157 157
 
158
-    $link = '<span class="gd-cancel-replaylink">' . $link . '</span>';
158
+	$link = '<span class="gd-cancel-replaylink">' . $link . '</span>';
159 159
 
160
-    return $link;
160
+	return $link;
161 161
 }
162 162
 
163 163
 add_action('comment_post', 'geodir_save_rating');
@@ -173,32 +173,32 @@  discard block
 block discarded – undo
173 173
  */
174 174
 function geodir_save_rating($comment = 0)
175 175
 {
176
-    global $wpdb, $user_ID, $plugin_prefix;
176
+	global $wpdb, $user_ID, $plugin_prefix;
177 177
 
178
-    $comment_info = get_comment($comment);
178
+	$comment_info = get_comment($comment);
179 179
 
180
-    $post_id = $comment_info->comment_post_ID;
181
-    $status = $comment_info->comment_approved;
182
-    $rating_ip = getenv("REMOTE_ADDR");
180
+	$post_id = $comment_info->comment_post_ID;
181
+	$status = $comment_info->comment_approved;
182
+	$rating_ip = getenv("REMOTE_ADDR");
183 183
 	
184
-    $post = geodir_get_post_info($post_id);
185
-    if (empty($post)) {
186
-        return;
187
-    }
188
-
189
-    if ($post->post_status == 'publish') {
190
-        $post_status = '1';
191
-    } else {
192
-        $post_status = '0';
193
-    }
184
+	$post = geodir_get_post_info($post_id);
185
+	if (empty($post)) {
186
+		return;
187
+	}
188
+
189
+	if ($post->post_status == 'publish') {
190
+		$post_status = '1';
191
+	} else {
192
+		$post_status = '0';
193
+	}
194 194
 	
195
-    if (isset($_REQUEST['geodir_overallrating'])) {
196
-        $overall_rating = $_REQUEST['geodir_overallrating'];
195
+	if (isset($_REQUEST['geodir_overallrating'])) {
196
+		$overall_rating = $_REQUEST['geodir_overallrating'];
197 197
         
198 198
 		if (isset($comment_info->comment_parent) && (int)$comment_info->comment_parent == 0) {
199
-            $overall_rating = $overall_rating > 0 ? $overall_rating : '0';
199
+			$overall_rating = $overall_rating > 0 ? $overall_rating : '0';
200 200
 
201
-            $sqlqry = $wpdb->prepare("INSERT INTO " . GEODIR_REVIEW_TABLE . " SET
201
+			$sqlqry = $wpdb->prepare("INSERT INTO " . GEODIR_REVIEW_TABLE . " SET
202 202
 					post_id		= %d,
203 203
 					post_type = %s,
204 204
 					post_title	= %s,
@@ -216,35 +216,35 @@  discard block
 block discarded – undo
216 216
 					post_latitude	= %s,
217 217
 					comment_content	= %s 
218 218
 					",
219
-                array($post_id, $post->post_type, $post->post_title, $user_ID, $comment, $rating_ip, $overall_rating, $status, $post_status, date_i18n('Y-m-d H:i:s', current_time('timestamp')), $post->post_city, $post->post_region, $post->post_country, $post->post_latitude, $post->post_longitude, $comment_info->comment_content)
220
-            );
221
-
222
-            $wpdb->query($sqlqry);
223
-
224
-            /**
225
-             * Called after saving the comment.
226
-             *
227
-             * @since 1.0.0
228
-             * @package GeoDirectory
229
-             * @param array $_REQUEST {
230
-             *    Attributes of the $_REQUEST variable.
231
-             *
232
-             *    @type string $geodir_overallrating Overall rating.
233
-             *    @type string $comment Comment text.
234
-             *    @type string $submit Submit button text.
235
-             *    @type string $comment_post_ID Comment post ID.
236
-             *    @type string $comment_parent Comment Parent ID.
237
-             *    @type string $_wp_unfiltered_html_comment Unfiltered html comment string.
238
-             *
239
-             * }
240
-             */
241
-            do_action('geodir_after_save_comment', $_REQUEST, 'Comment Your Post');
242
-
243
-            if ($status) {
244
-                geodir_update_postrating($post_id);
245
-            }
246
-        }
247
-    }
219
+				array($post_id, $post->post_type, $post->post_title, $user_ID, $comment, $rating_ip, $overall_rating, $status, $post_status, date_i18n('Y-m-d H:i:s', current_time('timestamp')), $post->post_city, $post->post_region, $post->post_country, $post->post_latitude, $post->post_longitude, $comment_info->comment_content)
220
+			);
221
+
222
+			$wpdb->query($sqlqry);
223
+
224
+			/**
225
+			 * Called after saving the comment.
226
+			 *
227
+			 * @since 1.0.0
228
+			 * @package GeoDirectory
229
+			 * @param array $_REQUEST {
230
+			 *    Attributes of the $_REQUEST variable.
231
+			 *
232
+			 *    @type string $geodir_overallrating Overall rating.
233
+			 *    @type string $comment Comment text.
234
+			 *    @type string $submit Submit button text.
235
+			 *    @type string $comment_post_ID Comment post ID.
236
+			 *    @type string $comment_parent Comment Parent ID.
237
+			 *    @type string $_wp_unfiltered_html_comment Unfiltered html comment string.
238
+			 *
239
+			 * }
240
+			 */
241
+			do_action('geodir_after_save_comment', $_REQUEST, 'Comment Your Post');
242
+
243
+			if ($status) {
244
+				geodir_update_postrating($post_id);
245
+			}
246
+		}
247
+	}
248 248
 }
249 249
 
250 250
 
@@ -262,51 +262,51 @@  discard block
 block discarded – undo
262 262
  */
263 263
 function geodir_update_rating_status_change($comment_id, $status)
264 264
 {
265
-    if ($status == 'delete') {
266
-        return;
267
-    }
268
-    global $wpdb, $plugin_prefix, $user_ID;
265
+	if ($status == 'delete') {
266
+		return;
267
+	}
268
+	global $wpdb, $plugin_prefix, $user_ID;
269 269
 
270
-    $comment_info = get_comment($comment_id);
270
+	$comment_info = get_comment($comment_id);
271 271
 
272
-    $post_id = isset($comment_info->comment_post_ID) ? $comment_info->comment_post_ID : '';
272
+	$post_id = isset($comment_info->comment_post_ID) ? $comment_info->comment_post_ID : '';
273 273
 
274
-    if (!empty($comment_info))
275
-        $status = $comment_info->comment_approved;
274
+	if (!empty($comment_info))
275
+		$status = $comment_info->comment_approved;
276 276
 
277
-    if ($status == 'approve' || $status == 1) {
278
-        $status = 1;
279
-    } else {
280
-        $status = 0;
281
-    }
277
+	if ($status == 'approve' || $status == 1) {
278
+		$status = 1;
279
+	} else {
280
+		$status = 0;
281
+	}
282 282
 
283
-    $comment_info_ID = isset($comment_info->comment_ID) ? $comment_info->comment_ID : '';
284
-    $old_rating = geodir_get_commentoverall($comment_info_ID);
283
+	$comment_info_ID = isset($comment_info->comment_ID) ? $comment_info->comment_ID : '';
284
+	$old_rating = geodir_get_commentoverall($comment_info_ID);
285 285
 
286
-    $post_type = get_post_type($post_id);
286
+	$post_type = get_post_type($post_id);
287 287
 
288
-    $detail_table = $plugin_prefix . $post_type . '_detail';
288
+	$detail_table = $plugin_prefix . $post_type . '_detail';
289 289
 
290
-    if ($comment_id) {
290
+	if ($comment_id) {
291 291
 
292
-        $overall_rating = $old_rating;
292
+		$overall_rating = $old_rating;
293 293
 
294
-        if (isset($old_rating)) {
294
+		if (isset($old_rating)) {
295 295
 
296
-            $sqlqry = $wpdb->prepare("UPDATE " . GEODIR_REVIEW_TABLE . " SET
296
+			$sqlqry = $wpdb->prepare("UPDATE " . GEODIR_REVIEW_TABLE . " SET
297 297
 						overall_rating = %f,
298 298
 						status		= %s,
299 299
 						comment_content = %s 
300 300
 						WHERE comment_id = %d ", array($overall_rating, $status, $comment_info->comment_content, $comment_id));
301 301
 
302
-            $wpdb->query($sqlqry);
302
+			$wpdb->query($sqlqry);
303 303
 
304
-            //update rating
305
-            geodir_update_postrating($post_id, $post_type);
304
+			//update rating
305
+			geodir_update_postrating($post_id, $post_type);
306 306
 
307
-        }
307
+		}
308 308
 
309
-    }
309
+	}
310 310
 
311 311
 }
312 312
 
@@ -325,41 +325,41 @@  discard block
 block discarded – undo
325 325
 function geodir_update_rating($comment_id = 0)
326 326
 {
327 327
 
328
-    global $wpdb, $plugin_prefix, $user_ID;
328
+	global $wpdb, $plugin_prefix, $user_ID;
329 329
 
330
-    $comment_info = get_comment($comment_id);
330
+	$comment_info = get_comment($comment_id);
331 331
 
332
-    $post_id = $comment_info->comment_post_ID;
333
-    $status = $comment_info->comment_approved;
334
-    $old_rating = geodir_get_commentoverall($comment_info->comment_ID);
332
+	$post_id = $comment_info->comment_post_ID;
333
+	$status = $comment_info->comment_approved;
334
+	$old_rating = geodir_get_commentoverall($comment_info->comment_ID);
335 335
 
336
-    $post_type = get_post_type($post_id);
336
+	$post_type = get_post_type($post_id);
337 337
 
338
-    $detail_table = $plugin_prefix . $post_type . '_detail';
338
+	$detail_table = $plugin_prefix . $post_type . '_detail';
339 339
 
340
-    if (isset($_REQUEST['geodir_overallrating'])) {
340
+	if (isset($_REQUEST['geodir_overallrating'])) {
341 341
 
342
-        $overall_rating = $_REQUEST['geodir_overallrating'];
342
+		$overall_rating = $_REQUEST['geodir_overallrating'];
343 343
 
344
-        if (isset($comment_info->comment_parent) && (int)$comment_info->comment_parent == 0) {
345
-            $overall_rating = $overall_rating > 0 ? $overall_rating : '0';
344
+		if (isset($comment_info->comment_parent) && (int)$comment_info->comment_parent == 0) {
345
+			$overall_rating = $overall_rating > 0 ? $overall_rating : '0';
346 346
 
347
-            if (isset($old_rating)) {
347
+			if (isset($old_rating)) {
348 348
 
349
-                $sqlqry = $wpdb->prepare("UPDATE " . GEODIR_REVIEW_TABLE . " SET
349
+				$sqlqry = $wpdb->prepare("UPDATE " . GEODIR_REVIEW_TABLE . " SET
350 350
 						overall_rating = %f,
351 351
 						status		= %s,
352 352
 						comment_content	= %s 
353 353
 						WHERE comment_id = %d ", array($overall_rating, $status, $comment_info->comment_content, $comment_id));
354 354
 
355
-                $wpdb->query($sqlqry);
355
+				$wpdb->query($sqlqry);
356 356
 
357
-                //update rating
358
-                geodir_update_postrating($post_id, $post_type);
357
+				//update rating
358
+				geodir_update_postrating($post_id, $post_type);
359 359
 
360
-            }
361
-        }
362
-    }
360
+			}
361
+		}
362
+	}
363 363
 
364 364
 
365 365
 }
@@ -375,19 +375,19 @@  discard block
 block discarded – undo
375 375
  */
376 376
 function geodir_comment_delete_comment($comment_id)
377 377
 {
378
-    global $wpdb;
378
+	global $wpdb;
379 379
 
380
-    $review_info = geodir_get_review($comment_id);
381
-    if ($review_info) {
382
-        geodir_update_postrating($review_info->post_id);
383
-    }
380
+	$review_info = geodir_get_review($comment_id);
381
+	if ($review_info) {
382
+		geodir_update_postrating($review_info->post_id);
383
+	}
384 384
 
385
-    $wpdb->query(
386
-        $wpdb->prepare(
387
-            "DELETE FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id=%d",
388
-            array($comment_id)
389
-        )
390
-    );
385
+	$wpdb->query(
386
+		$wpdb->prepare(
387
+			"DELETE FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id=%d",
388
+			array($comment_id)
389
+		)
390
+	);
391 391
 
392 392
 }
393 393
 
@@ -403,21 +403,21 @@  discard block
 block discarded – undo
403 403
  * @return string The comment content.
404 404
  */
405 405
 function geodir_wrap_comment_text($content, $comment = '') {
406
-    if (!empty($comment->comment_post_ID) && geodir_cpt_has_rating_disabled((int)$comment->comment_post_ID)) {
407
-        if (!is_admin()) {
408
-            return '<div class="description">' . $content . '</div>';
409
-        } else {
410
-            return $content;
411
-        }
412
-    } else {
413
-        $rating = 0;
414
-        if (!empty($comment))
415
-            $rating = geodir_get_commentoverall($comment->comment_ID);
416
-        if ($rating != 0 && !is_admin()) {
417
-            return '<div><div class="gd-rating-text">' . __('Overall Rating', 'geodirectory') . ': <div class="rating">' . $rating . '</div></div>' . geodir_get_rating_stars($rating, $comment->comment_ID) . '</div><div class="description">' . $content . '</div>';
418
-        } else
419
-            return $content;
420
-    }
406
+	if (!empty($comment->comment_post_ID) && geodir_cpt_has_rating_disabled((int)$comment->comment_post_ID)) {
407
+		if (!is_admin()) {
408
+			return '<div class="description">' . $content . '</div>';
409
+		} else {
410
+			return $content;
411
+		}
412
+	} else {
413
+		$rating = 0;
414
+		if (!empty($comment))
415
+			$rating = geodir_get_commentoverall($comment->comment_ID);
416
+		if ($rating != 0 && !is_admin()) {
417
+			return '<div><div class="gd-rating-text">' . __('Overall Rating', 'geodirectory') . ': <div class="rating">' . $rating . '</div></div>' . geodir_get_rating_stars($rating, $comment->comment_ID) . '</div><div class="description">' . $content . '</div>';
418
+		} else
419
+			return $content;
420
+	}
421 421
 }
422 422
 
423 423
 
@@ -434,41 +434,41 @@  discard block
 block discarded – undo
434 434
  */
435 435
 function geodir_update_postrating($post_id = 0, $post_type = '', $delete = false)
436 436
 {
437
-    global $wpdb, $plugin_prefix, $comment;
438
-    if (!$post_type) {
439
-        $post_type = get_post_type($post_id);
440
-    }
441
-    $detail_table = $plugin_prefix . $post_type . '_detail';
442
-    $post_newrating = geodir_get_post_rating($post_id, 1);
443
-    $post_newrating_count = geodir_get_review_count_total($post_id);
437
+	global $wpdb, $plugin_prefix, $comment;
438
+	if (!$post_type) {
439
+		$post_type = get_post_type($post_id);
440
+	}
441
+	$detail_table = $plugin_prefix . $post_type . '_detail';
442
+	$post_newrating = geodir_get_post_rating($post_id, 1);
443
+	$post_newrating_count = geodir_get_review_count_total($post_id);
444 444
 
445 445
 
446
-    //$post_newrating = ( (float)$post_oldrating - (float)$old_rating ) + (float)$overall_rating ;
446
+	//$post_newrating = ( (float)$post_oldrating - (float)$old_rating ) + (float)$overall_rating ;
447 447
 
448
-    if ($wpdb->get_var("SHOW TABLES LIKE '" . $detail_table . "'") == $detail_table) {
448
+	if ($wpdb->get_var("SHOW TABLES LIKE '" . $detail_table . "'") == $detail_table) {
449 449
 
450
-        $wpdb->query(
451
-            $wpdb->prepare(
452
-                "UPDATE " . $detail_table . " SET
450
+		$wpdb->query(
451
+			$wpdb->prepare(
452
+				"UPDATE " . $detail_table . " SET
453 453
 						overall_rating = %f,
454 454
 						rating_count = %f
455 455
 						where post_id = %d",
456
-                array($post_newrating, $post_newrating_count, $post_id)
457
-            )
458
-        );
459
-
460
-        update_post_meta($post_id, 'overall_rating', $post_newrating);
461
-        update_post_meta($post_id, 'rating_count', $post_newrating_count);
462
-    }
463
-    /**
464
-     * Called after Updating post overall rating and rating count.
465
-     *
466
-     * @since 1.0.0
467
-     * @since 1.4.3 Added `$post_id` param.
468
-     * @package GeoDirectory
469
-     * @param int $post_id The post ID.
470
-     */
471
-    do_action('geodir_update_postrating',$post_id);
456
+				array($post_newrating, $post_newrating_count, $post_id)
457
+			)
458
+		);
459
+
460
+		update_post_meta($post_id, 'overall_rating', $post_newrating);
461
+		update_post_meta($post_id, 'rating_count', $post_newrating_count);
462
+	}
463
+	/**
464
+	 * Called after Updating post overall rating and rating count.
465
+	 *
466
+	 * @since 1.0.0
467
+	 * @since 1.4.3 Added `$post_id` param.
468
+	 * @package GeoDirectory
469
+	 * @param int $post_id The post ID.
470
+	 */
471
+	do_action('geodir_update_postrating',$post_id);
472 472
 
473 473
 }
474 474
 
@@ -486,29 +486,29 @@  discard block
 block discarded – undo
486 486
  */
487 487
 function geodir_get_postoverall($post_id = 0)
488 488
 {
489
-    global $wpdb, $plugin_prefix;
489
+	global $wpdb, $plugin_prefix;
490 490
 
491
-    $post_type = get_post_type($post_id);
492
-    $detail_table = $plugin_prefix . $post_type . '_detail';
491
+	$post_type = get_post_type($post_id);
492
+	$detail_table = $plugin_prefix . $post_type . '_detail';
493 493
 
494
-    if ($wpdb->get_var("SHOW TABLES LIKE '" . $detail_table . "'") == $detail_table) {
494
+	if ($wpdb->get_var("SHOW TABLES LIKE '" . $detail_table . "'") == $detail_table) {
495 495
 
496
-        $post_ratings = $wpdb->get_var(
497
-            $wpdb->prepare(
498
-                "SELECT overall_rating FROM " . $detail_table . " WHERE post_id = %d",
499
-                array($post_id)
500
-            )
501
-        );
496
+		$post_ratings = $wpdb->get_var(
497
+			$wpdb->prepare(
498
+				"SELECT overall_rating FROM " . $detail_table . " WHERE post_id = %d",
499
+				array($post_id)
500
+			)
501
+		);
502 502
 
503 503
 
504
-    } else {
505
-        $post_ratings = get_post_meta($post_id, 'overall_rating');
506
-    }
504
+	} else {
505
+		$post_ratings = get_post_meta($post_id, 'overall_rating');
506
+	}
507 507
 
508
-    if ($post_ratings)
509
-        return $post_ratings;
510
-    else
511
-        return false;
508
+	if ($post_ratings)
509
+		return $post_ratings;
510
+	else
511
+		return false;
512 512
 }
513 513
 
514 514
 
@@ -525,19 +525,19 @@  discard block
 block discarded – undo
525 525
  */
526 526
 function geodir_get_review($comment_id = 0)
527 527
 {
528
-    global $wpdb;
529
-
530
-    $reatings = $wpdb->get_row(
531
-        $wpdb->prepare(
532
-            "SELECT * FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id = %d",
533
-            array($comment_id)
534
-        )
535
-    );
536
-
537
-    if (!empty($reatings))
538
-        return $reatings;
539
-    else
540
-        return false;
528
+	global $wpdb;
529
+
530
+	$reatings = $wpdb->get_row(
531
+		$wpdb->prepare(
532
+			"SELECT * FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id = %d",
533
+			array($comment_id)
534
+		)
535
+	);
536
+
537
+	if (!empty($reatings))
538
+		return $reatings;
539
+	else
540
+		return false;
541 541
 }
542 542
 
543 543
 /**
@@ -553,19 +553,19 @@  discard block
 block discarded – undo
553 553
  */
554 554
 function geodir_get_review_total($post_id = 0)
555 555
 {
556
-    global $wpdb;
557
-
558
-    $results = $wpdb->get_var(
559
-        $wpdb->prepare(
560
-            "SELECT SUM(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id = %d AND status=1 AND overall_rating>0",
561
-            array($post_id)
562
-        )
563
-    );
564
-
565
-    if (!empty($results))
566
-        return $results;
567
-    else
568
-        return false;
556
+	global $wpdb;
557
+
558
+	$results = $wpdb->get_var(
559
+		$wpdb->prepare(
560
+			"SELECT SUM(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id = %d AND status=1 AND overall_rating>0",
561
+			array($post_id)
562
+		)
563
+	);
564
+
565
+	if (!empty($results))
566
+		return $results;
567
+	else
568
+		return false;
569 569
 }
570 570
 
571 571
 /**
@@ -581,18 +581,18 @@  discard block
 block discarded – undo
581 581
  */
582 582
 function geodir_get_review_count_by_user_id($user_id = 0)
583 583
 {
584
-    global $wpdb;
585
-    $results = $wpdb->get_var(
586
-        $wpdb->prepare(
587
-            "SELECT COUNT(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE user_id = %d AND status=1 AND overall_rating>0",
588
-            array($user_id)
589
-        )
590
-    );
591
-
592
-    if (!empty($results))
593
-        return $results;
594
-    else
595
-        return false;
584
+	global $wpdb;
585
+	$results = $wpdb->get_var(
586
+		$wpdb->prepare(
587
+			"SELECT COUNT(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE user_id = %d AND status=1 AND overall_rating>0",
588
+			array($user_id)
589
+		)
590
+	);
591
+
592
+	if (!empty($results))
593
+		return $results;
594
+	else
595
+		return false;
596 596
 }
597 597
 
598 598
 /**
@@ -610,27 +610,27 @@  discard block
 block discarded – undo
610 610
  */
611 611
 function geodir_get_post_rating($post_id = 0, $force_query = 0)
612 612
 {
613
-    global $wpdb, $post;
614
-
615
-    if (isset($post->ID) && $post->ID == $post_id && !$force_query) {
616
-        if (isset($post->rating_count) && $post->rating_count > 0 && isset($post->overall_rating) && $post->overall_rating > 0) {
617
-            return $post->overall_rating;
618
-        } else {
619
-            return 0;
620
-        }
621
-    }
622
-
623
-    $results = $wpdb->get_var(
624
-        $wpdb->prepare(
625
-            "SELECT COALESCE(avg(overall_rating),0) FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id = %d AND status=1 AND overall_rating>0",
626
-            array($post_id)
627
-        )
628
-    );
629
-
630
-    if (!empty($results))
631
-        return $results;
632
-    else
633
-        return false;
613
+	global $wpdb, $post;
614
+
615
+	if (isset($post->ID) && $post->ID == $post_id && !$force_query) {
616
+		if (isset($post->rating_count) && $post->rating_count > 0 && isset($post->overall_rating) && $post->overall_rating > 0) {
617
+			return $post->overall_rating;
618
+		} else {
619
+			return 0;
620
+		}
621
+	}
622
+
623
+	$results = $wpdb->get_var(
624
+		$wpdb->prepare(
625
+			"SELECT COALESCE(avg(overall_rating),0) FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id = %d AND status=1 AND overall_rating>0",
626
+			array($post_id)
627
+		)
628
+	);
629
+
630
+	if (!empty($results))
631
+		return $results;
632
+	else
633
+		return false;
634 634
 }
635 635
 
636 636
 /**
@@ -646,19 +646,19 @@  discard block
 block discarded – undo
646 646
  */
647 647
 function geodir_get_review_count_total($post_id = 0)
648 648
 {
649
-    global $wpdb;
650
-
651
-    $results = $wpdb->get_var(
652
-        $wpdb->prepare(
653
-            "SELECT COUNT(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id = %d AND status=1 AND overall_rating>0",
654
-            array($post_id)
655
-        )
656
-    );
657
-
658
-    if (!empty($results))
659
-        return $results;
660
-    else
661
-        return false;
649
+	global $wpdb;
650
+
651
+	$results = $wpdb->get_var(
652
+		$wpdb->prepare(
653
+			"SELECT COUNT(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id = %d AND status=1 AND overall_rating>0",
654
+			array($post_id)
655
+		)
656
+	);
657
+
658
+	if (!empty($results))
659
+		return $results;
660
+	else
661
+		return false;
662 662
 }
663 663
 
664 664
 /**
@@ -675,20 +675,20 @@  discard block
 block discarded – undo
675 675
  */
676 676
 function geodir_get_comments_number($post_id = 0)
677 677
 {
678
-    global $wpdb;
678
+	global $wpdb;
679 679
 
680
-    $results = $wpdb->get_var(
681
-        $wpdb->prepare(
682
-            "SELECT COUNT(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id = %d AND status=1 AND overall_rating>0",
683
-            array($post_id)
684
-        )
685
-    );
680
+	$results = $wpdb->get_var(
681
+		$wpdb->prepare(
682
+			"SELECT COUNT(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id = %d AND status=1 AND overall_rating>0",
683
+			array($post_id)
684
+		)
685
+	);
686 686
 
687 687
 
688
-    if (!empty($results))
689
-        return $results;
690
-    else
691
-        return false;
688
+	if (!empty($results))
689
+		return $results;
690
+	else
691
+		return false;
692 692
 }
693 693
 
694 694
 /**
@@ -704,19 +704,19 @@  discard block
 block discarded – undo
704 704
  */
705 705
 function geodir_get_commentoverall($comment_id = 0)
706 706
 {
707
-    global $wpdb;
708
-
709
-    $reatings = $wpdb->get_var(
710
-        $wpdb->prepare(
711
-            "SELECT overall_rating FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id = %d",
712
-            array($comment_id)
713
-        )
714
-    );
715
-
716
-    if ($reatings)
717
-        return $reatings;
718
-    else
719
-        return false;
707
+	global $wpdb;
708
+
709
+	$reatings = $wpdb->get_var(
710
+		$wpdb->prepare(
711
+			"SELECT overall_rating FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id = %d",
712
+			array($comment_id)
713
+		)
714
+	);
715
+
716
+	if ($reatings)
717
+		return $reatings;
718
+	else
719
+		return false;
720 720
 }
721 721
 
722 722
 /**
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
  */
731 731
 function geodir_get_commentoverall_number($post_id = 0)
732 732
 {
733
-    return geodir_get_post_rating($post_id);
733
+	return geodir_get_post_rating($post_id);
734 734
 }
735 735
 
736 736
 
@@ -748,102 +748,102 @@  discard block
 block discarded – undo
748 748
  */
749 749
 function geodir_comment_template($comment_template)
750 750
 {
751
-    global $post;
751
+	global $post;
752 752
 
753
-    $post_types = geodir_get_posttypes();
753
+	$post_types = geodir_get_posttypes();
754 754
 
755
-    if (!(is_singular() && (have_comments() || (isset($post->comment_status) && 'open' == $post->comment_status)))) {
756
-        return;
757
-    }
758
-    if (in_array($post->post_type, $post_types)) { // assuming there is a post type called business
759
-        if (geodir_cpt_has_rating_disabled($post->post_type)) {
760
-            return $comment_template;
761
-        }
755
+	if (!(is_singular() && (have_comments() || (isset($post->comment_status) && 'open' == $post->comment_status)))) {
756
+		return;
757
+	}
758
+	if (in_array($post->post_type, $post_types)) { // assuming there is a post type called business
759
+		if (geodir_cpt_has_rating_disabled($post->post_type)) {
760
+			return $comment_template;
761
+		}
762 762
         
763
-        $template = locate_template(array("geodirectory/reviews.php")); // Use theme template if available
764
-        if (!$template) {
765
-            $template = dirname(__FILE__) . '/reviews.php';
766
-        }
767
-        return $template;
768
-    }
763
+		$template = locate_template(array("geodirectory/reviews.php")); // Use theme template if available
764
+		if (!$template) {
765
+			$template = dirname(__FILE__) . '/reviews.php';
766
+		}
767
+		return $template;
768
+	}
769 769
 }
770 770
 
771 771
 add_filter("comments_template", "geodir_comment_template");
772 772
 
773 773
 
774 774
 if (!function_exists('geodir_comment')) {
775
-    /**
776
-     * Comment HTML markup.
777
-     *
778
-     * @since 1.0.0
779
-     * @package GeoDirectory
780
-     * @global object $post The current post object.
781
-     * @param object $comment The comment object.
782
-     * @param string|array $args {
783
-     *     Optional. Formatting options.
784
-     *
785
-     *     @type object $walker            Instance of a Walker class to list comments. Default null.
786
-     *     @type int    $max_depth         The maximum comments depth. Default empty.
787
-     *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
788
-     *     @type string $callback          Callback function to use. Default null.
789
-     *     @type string $end-callback      Callback function to use at the end. Default null.
790
-     *     @type string $type              Type of comments to list.
791
-     *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
792
-     *     @type int    $page              Page ID to list comments for. Default empty.
793
-     *     @type int    $per_page          Number of comments to list per page. Default empty.
794
-     *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
795
-     *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
796
-     *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
797
-     *     @type string $format            How to format the comments list.
798
-     *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
799
-     *     @type bool   $short_ping        Whether to output short pings. Default false.
800
-     *     @type bool   $echo              Whether to echo the output or return it. Default true.
801
-     * }
802
-     * @param int $depth Depth of comment.
803
-     */
804
-    function geodir_comment($comment, $args, $depth)
805
-    {
806
-        $GLOBALS['comment'] = $comment;
807
-        switch ($comment->comment_type) :
808
-            case 'pingback' :
809
-            case 'trackback' :
810
-                // Display trackbacks differently than normal comments.
811
-                ?>
775
+	/**
776
+	 * Comment HTML markup.
777
+	 *
778
+	 * @since 1.0.0
779
+	 * @package GeoDirectory
780
+	 * @global object $post The current post object.
781
+	 * @param object $comment The comment object.
782
+	 * @param string|array $args {
783
+	 *     Optional. Formatting options.
784
+	 *
785
+	 *     @type object $walker            Instance of a Walker class to list comments. Default null.
786
+	 *     @type int    $max_depth         The maximum comments depth. Default empty.
787
+	 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
788
+	 *     @type string $callback          Callback function to use. Default null.
789
+	 *     @type string $end-callback      Callback function to use at the end. Default null.
790
+	 *     @type string $type              Type of comments to list.
791
+	 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
792
+	 *     @type int    $page              Page ID to list comments for. Default empty.
793
+	 *     @type int    $per_page          Number of comments to list per page. Default empty.
794
+	 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
795
+	 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
796
+	 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
797
+	 *     @type string $format            How to format the comments list.
798
+	 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
799
+	 *     @type bool   $short_ping        Whether to output short pings. Default false.
800
+	 *     @type bool   $echo              Whether to echo the output or return it. Default true.
801
+	 * }
802
+	 * @param int $depth Depth of comment.
803
+	 */
804
+	function geodir_comment($comment, $args, $depth)
805
+	{
806
+		$GLOBALS['comment'] = $comment;
807
+		switch ($comment->comment_type) :
808
+			case 'pingback' :
809
+			case 'trackback' :
810
+				// Display trackbacks differently than normal comments.
811
+				?>
812 812
                 <li <?php comment_class('geodir-comment'); ?> id="comment-<?php comment_ID(); ?>">
813 813
                 <p><?php _e('Pingback:', 'geodirectory'); ?> <?php comment_author_link(); ?> <?php edit_comment_link(__('(Edit)', 'geodirectory'), '<span class="edit-link">', '</span>'); ?></p>
814 814
                 <?php
815
-                break;
816
-            default :
817
-                // Proceed with normal comments.
818
-                global $post;
819
-                ?>
815
+				break;
816
+			default :
817
+				// Proceed with normal comments.
818
+				global $post;
819
+				?>
820 820
             <li <?php comment_class('geodir-comment'); ?> id="li-comment-<?php comment_ID(); ?>">
821 821
                 <article id="comment-<?php comment_ID(); ?>" class="comment">
822 822
                     <header class="comment-meta comment-author vcard">
823 823
                         <?php
824
-                        /**
825
-                         * Filter to modify comment avatar size
826
-                         *
827
-                         * You can use this filter to change comment avatar size.
828
-                         *
829
-                         * @since 1.0.0
830
-                         * @package GeoDirectory
831
-                         */
832
-                        $avatar_size = apply_filters('geodir_comment_avatar_size', 44);
833
-                        echo get_avatar($comment, $avatar_size);
834
-                        printf('<cite><b class="reviewer">%1$s</b> %2$s</cite>',
835
-                            get_comment_author_link(),
836
-                            // If current post author is also comment author, make it known visually.
837
-                            ($comment->user_id === $post->post_author) ? '<span>' . __('Post author', 'geodirectory') . '</span>' : ''
838
-                        );
839
-                        echo "<span class='item'><small><span class='fn'>$post->post_title</span></small></span>";
840
-                        printf('<a href="%1$s"><time datetime="%2$s" class="dtreviewed">%3$s<span class="value-title" title="%2$s"></span></time></a>',
841
-                            esc_url(get_comment_link($comment->comment_ID)),
842
-                            get_comment_time('c'),
843
-                            /* translators: 1: date, 2: time */
844
-                            sprintf(__('%1$s at %2$s', 'geodirectory'), get_comment_date(), get_comment_time())
845
-                        );
846
-                        ?>
824
+						/**
825
+						 * Filter to modify comment avatar size
826
+						 *
827
+						 * You can use this filter to change comment avatar size.
828
+						 *
829
+						 * @since 1.0.0
830
+						 * @package GeoDirectory
831
+						 */
832
+						$avatar_size = apply_filters('geodir_comment_avatar_size', 44);
833
+						echo get_avatar($comment, $avatar_size);
834
+						printf('<cite><b class="reviewer">%1$s</b> %2$s</cite>',
835
+							get_comment_author_link(),
836
+							// If current post author is also comment author, make it known visually.
837
+							($comment->user_id === $post->post_author) ? '<span>' . __('Post author', 'geodirectory') . '</span>' : ''
838
+						);
839
+						echo "<span class='item'><small><span class='fn'>$post->post_title</span></small></span>";
840
+						printf('<a href="%1$s"><time datetime="%2$s" class="dtreviewed">%3$s<span class="value-title" title="%2$s"></span></time></a>',
841
+							esc_url(get_comment_link($comment->comment_ID)),
842
+							get_comment_time('c'),
843
+							/* translators: 1: date, 2: time */
844
+							sprintf(__('%1$s at %2$s', 'geodirectory'), get_comment_date(), get_comment_time())
845
+						);
846
+						?>
847 847
                     </header>
848 848
                     <!-- .comment-meta -->
849 849
 
@@ -867,47 +867,47 @@  discard block
 block discarded – undo
867 867
                 </article>
868 868
                 <!-- #comment-## -->
869 869
                 <?php
870
-                break;
871
-        endswitch; // end comment_type check
872
-    }
870
+				break;
871
+		endswitch; // end comment_type check
872
+	}
873 873
 }
874 874
 
875 875
 
876 876
 add_filter('get_comments_number', 'geodir_fix_comment_count', 10, 2);
877 877
 if (!function_exists('geodir_fix_comment_count')) {
878
-    /**
879
-     * Fix comment count by not listing replies as reviews
880
-     *
881
-     * @since 1.0.0
882
-     * @package GeoDirectory
883
-     * @global object $post The current post object.
884
-     * @param int $count The comment count.
885
-     * @param int $post_id The post ID.
886
-     * @todo $post is unreachable since the function return the count before that variable.
887
-     * @return bool|null|string The comment count.
888
-     */
889
-    function geodir_fix_comment_count($count, $post_id)
890
-    {
891
-        if (!is_admin() || strpos($_SERVER['REQUEST_URI'], 'admin-ajax.php')) {
892
-            global $post;
893
-            $post_types = geodir_get_posttypes();
894
-
895
-            if (in_array(get_post_type($post_id), $post_types) && !geodir_cpt_has_rating_disabled((int)$post_id)) {
896
-                $review_count = geodir_get_review_count_total($post_id);
897
-                return $review_count;
898
-
899
-                if ($post && isset($post->rating_count)) {
900
-                    return $post->rating_count;
901
-                } else {
902
-                    return geodir_get_comments_number($post_id);
903
-                }
904
-            } else {
905
-                return $count;
906
-            }
907
-        } else {
908
-            return $count;
909
-        }
910
-    }
878
+	/**
879
+	 * Fix comment count by not listing replies as reviews
880
+	 *
881
+	 * @since 1.0.0
882
+	 * @package GeoDirectory
883
+	 * @global object $post The current post object.
884
+	 * @param int $count The comment count.
885
+	 * @param int $post_id The post ID.
886
+	 * @todo $post is unreachable since the function return the count before that variable.
887
+	 * @return bool|null|string The comment count.
888
+	 */
889
+	function geodir_fix_comment_count($count, $post_id)
890
+	{
891
+		if (!is_admin() || strpos($_SERVER['REQUEST_URI'], 'admin-ajax.php')) {
892
+			global $post;
893
+			$post_types = geodir_get_posttypes();
894
+
895
+			if (in_array(get_post_type($post_id), $post_types) && !geodir_cpt_has_rating_disabled((int)$post_id)) {
896
+				$review_count = geodir_get_review_count_total($post_id);
897
+				return $review_count;
898
+
899
+				if ($post && isset($post->rating_count)) {
900
+					return $post->rating_count;
901
+				} else {
902
+					return geodir_get_comments_number($post_id);
903
+				}
904
+			} else {
905
+				return $count;
906
+			}
907
+		} else {
908
+			return $count;
909
+		}
910
+	}
911 911
 }
912 912
 
913 913
 /**
@@ -925,14 +925,14 @@  discard block
 block discarded – undo
925 925
  */
926 926
 function geodir_get_rating_stars($rating, $post_id, $small = false)
927 927
 {
928
-    if (!empty($post_id) && geodir_cpt_has_rating_disabled((int)$post_id)) {
929
-        return NULL;
930
-    }
931
-    $a_rating = $rating / 5 * 100;
932
-
933
-    if ($small) {
934
-        $r_html = '<div class="rating"><div class="gd_rating_map" data-average="' . $rating . '" data-id="' . $post_id . '"><div class="geodir_RatingColor" ></div><div class="geodir_RatingAverage_small" style="width: ' . $a_rating . '%;"></div><div class="geodir_Star_small"></div></div></div>';
935
-    } else {
928
+	if (!empty($post_id) && geodir_cpt_has_rating_disabled((int)$post_id)) {
929
+		return NULL;
930
+	}
931
+	$a_rating = $rating / 5 * 100;
932
+
933
+	if ($small) {
934
+		$r_html = '<div class="rating"><div class="gd_rating_map" data-average="' . $rating . '" data-id="' . $post_id . '"><div class="geodir_RatingColor" ></div><div class="geodir_RatingAverage_small" style="width: ' . $a_rating . '%;"></div><div class="geodir_Star_small"></div></div></div>';
935
+	} else {
936 936
 		if (function_exists('geodir_reviewrating_draw_overall_rating')) {
937 937
 			// Show rating stars from review rating manager
938 938
 			$r_html = geodir_reviewrating_draw_overall_rating($rating);
@@ -949,8 +949,8 @@  discard block
 block discarded – undo
949 949
 			}
950 950
 			$r_html = '<div class="geodir-rating" style="' . $attach_style . '"><div class="gd_rating_show" data-average="' . $rating . '" data-id="' . $post_id . '"><div class="geodir_RatingAverage" style="width: ' . $a_rating . '%;"></div><div class="geodir_Star">' . $rating_img . $rating_img . $rating_img . $rating_img . $rating_img . '</div></div></div>';
951 951
 		}
952
-    }
953
-    return apply_filters('geodir_get_rating_stars_html', $r_html, $rating, 5);
952
+	}
953
+	return apply_filters('geodir_get_rating_stars_html', $r_html, $rating, 5);
954 954
 }
955 955
 
956 956
 /**
@@ -964,23 +964,23 @@  discard block
 block discarded – undo
964 964
 function geodir_is_reviews_show($pageview = '')
965 965
 {
966 966
 
967
-    $active_tabs = get_option('geodir_detail_page_tabs_excluded');
968
-
969
-    $is_display = true;
970
-    if (!empty($active_tabs) && in_array('reviews', $active_tabs))
971
-        $is_display = false;
972
-
973
-    /**
974
-     * Filter to change display value.
975
-     *
976
-     * You can use this filter to change the is_display value.
977
-     *
978
-     * @since 1.0.0
979
-     * @package GeoDirectory
980
-     * @param bool $is_display Display ratings when set to true.
981
-     * @param string $pageview The view template. Ex: listview, gridview etc.
982
-     */
983
-    return apply_filters('geodir_is_reviews_show', $is_display, $pageview);
967
+	$active_tabs = get_option('geodir_detail_page_tabs_excluded');
968
+
969
+	$is_display = true;
970
+	if (!empty($active_tabs) && in_array('reviews', $active_tabs))
971
+		$is_display = false;
972
+
973
+	/**
974
+	 * Filter to change display value.
975
+	 *
976
+	 * You can use this filter to change the is_display value.
977
+	 *
978
+	 * @since 1.0.0
979
+	 * @package GeoDirectory
980
+	 * @param bool $is_display Display ratings when set to true.
981
+	 * @param string $pageview The view template. Ex: listview, gridview etc.
982
+	 */
983
+	return apply_filters('geodir_is_reviews_show', $is_display, $pageview);
984 984
 }
985 985
 
986 986
 
@@ -988,9 +988,9 @@  discard block
 block discarded – undo
988 988
  * If Disqus plugin is active, do some fixes to show on blogs but no on GD post types
989 989
  */
990 990
 if(function_exists('dsq_can_replace')) {
991
-    remove_filter('comments_template', 'dsq_comments_template');
992
-    add_filter('comments_template', 'dsq_comments_template', 100);
993
-    add_filter('pre_option_disqus_active', 'geodir_option_disqus_active',10,1);
991
+	remove_filter('comments_template', 'dsq_comments_template');
992
+	add_filter('comments_template', 'dsq_comments_template', 100);
993
+	add_filter('pre_option_disqus_active', 'geodir_option_disqus_active',10,1);
994 994
 }
995 995
 
996 996
 
@@ -1004,14 +1004,14 @@  discard block
 block discarded – undo
1004 1004
  * @return string `1` if active `0` if disabled.
1005 1005
  */
1006 1006
 function geodir_option_disqus_active($disqus_active){
1007
-    global $post;
1008
-    $all_postypes = geodir_get_posttypes();
1007
+	global $post;
1008
+	$all_postypes = geodir_get_posttypes();
1009 1009
 
1010
-    if(isset($post->post_type) && is_array($all_postypes) && in_array($post->post_type,$all_postypes)){
1011
-        $disqus_active = '0';
1012
-    }
1010
+	if(isset($post->post_type) && is_array($all_postypes) && in_array($post->post_type,$all_postypes)){
1011
+		$disqus_active = '0';
1012
+	}
1013 1013
 
1014
-    return $disqus_active;
1014
+	return $disqus_active;
1015 1015
 }
1016 1016
 
1017 1017
 /**
@@ -1025,16 +1025,16 @@  discard block
 block discarded – undo
1025 1025
  * @return array Modified tabs array.
1026 1026
  */
1027 1027
 function geodir_detail_reviews_tab_title($tabs_arr) {
1028
-    if (defined('GEODIR_CP_VERSION')) {
1029
-        return $tabs_arr;
1030
-    }
1028
+	if (defined('GEODIR_CP_VERSION')) {
1029
+		return $tabs_arr;
1030
+	}
1031 1031
     
1032
-    $post_type = geodir_get_current_posttype();
1032
+	$post_type = geodir_get_current_posttype();
1033 1033
     
1034
-    if (!empty($tabs_arr) && !empty($tabs_arr['reviews']) && isset($tabs_arr['reviews']['heading_text']) && $post_type != '' && geodir_cpt_has_rating_disabled($post_type)) {
1035
-        $tabs_arr['reviews']['heading_text'] = __('Comments', 'geodirectory');
1036
-    }
1034
+	if (!empty($tabs_arr) && !empty($tabs_arr['reviews']) && isset($tabs_arr['reviews']['heading_text']) && $post_type != '' && geodir_cpt_has_rating_disabled($post_type)) {
1035
+		$tabs_arr['reviews']['heading_text'] = __('Comments', 'geodirectory');
1036
+	}
1037 1037
     
1038
-    return $tabs_arr;
1038
+	return $tabs_arr;
1039 1039
 }
1040 1040
 add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_reviews_tab_title', 1000, 1);
1041 1041
\ No newline at end of file
Please login to merge, or discard this patch.
geodirectory-functions/listing_filters.php 1 patch
Indentation   +528 added lines, -528 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
33 33
  */
34 34
 function geodir_modified_query($query)
35 35
 {
36
-    if ($query->is_main_query() && (
37
-            (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '')
38
-            || geodir_is_page('listing')
39
-            || geodir_is_page('author')
40
-            || geodir_is_page('search')
41
-            || geodir_is_page('detail'))
42
-    ) {
43
-
44
-        $query->set('is_geodir_loop', true);
45
-    }
36
+	if ($query->is_main_query() && (
37
+			(geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '')
38
+			|| geodir_is_page('listing')
39
+			|| geodir_is_page('author')
40
+			|| geodir_is_page('search')
41
+			|| geodir_is_page('detail'))
42
+	) {
43
+
44
+		$query->set('is_geodir_loop', true);
45
+	}
46 46
 
47
-    return $query;
47
+	return $query;
48 48
 }
49 49
 
50 50
 /**
@@ -67,81 +67,81 @@  discard block
 block discarded – undo
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
-        } //  Latatude
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
+		} //  Latatude
106 106
 
107
-        if (isset($_REQUEST['sgeo_lon'])) {
108
-            $mylon = (float)esc_attr($_REQUEST['sgeo_lon']);
109
-        } else {
110
-            $mylon = (float)geodir_get_current_city_lng();
111
-        } //  Distance
107
+		if (isset($_REQUEST['sgeo_lon'])) {
108
+			$mylon = (float)esc_attr($_REQUEST['sgeo_lon']);
109
+		} else {
110
+			$mylon = (float)geodir_get_current_city_lng();
111
+		} //  Distance
112 112
 
113
-        if (isset($_REQUEST['snear'])) {
114
-            $snear = trim(esc_attr($_REQUEST['snear']));
115
-        }
113
+		if (isset($_REQUEST['snear'])) {
114
+			$snear = trim(esc_attr($_REQUEST['snear']));
115
+		}
116 116
 
117
-        if (isset($_REQUEST['s'])) {
118
-            $s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s'])));
119
-        }
117
+		if (isset($_REQUEST['s'])) {
118
+			$s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s'])));
119
+		}
120 120
 
121
-        if ($snear == 'NEAR ME') {
122
-            $ip = $_SERVER['REMOTE_ADDR'];
123
-            $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip));
124
-            $mylat = stripslashes(ucfirst($addr_details[geoplugin_latitude]));
125
-            $mylon = stripslashes(ucfirst($addr_details[geoplugin_longitude]));
126
-        }
121
+		if ($snear == 'NEAR ME') {
122
+			$ip = $_SERVER['REMOTE_ADDR'];
123
+			$addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip));
124
+			$mylat = stripslashes(ucfirst($addr_details[geoplugin_latitude]));
125
+			$mylon = stripslashes(ucfirst($addr_details[geoplugin_longitude]));
126
+		}
127 127
 
128 128
 
129
-        if (strstr($s, ',')) {
130
-            $s_AA = str_replace(" ", "", $s);
131
-            $s_A = explode(",", $s_AA);
132
-            $s_A = implode('","', $s_A);
133
-            $s_A = '"' . $s_A . '"';
134
-        } else {
135
-            $s_A = '"' . $s . '"';
136
-        }
129
+		if (strstr($s, ',')) {
130
+			$s_AA = str_replace(" ", "", $s);
131
+			$s_A = explode(",", $s_AA);
132
+			$s_A = implode('","', $s_A);
133
+			$s_A = '"' . $s_A . '"';
134
+		} else {
135
+			$s_A = '"' . $s . '"';
136
+		}
137 137
 
138
-        if (strstr($s, ' ')) {
139
-            $s_SA = explode(" ", $s);
140
-        } else {
141
-            $s_SA = '';
142
-        }
138
+		if (strstr($s, ' ')) {
139
+			$s_SA = explode(" ", $s);
140
+		} else {
141
+			$s_SA = '';
142
+		}
143 143
 
144
-    endif;
144
+	endif;
145 145
 
146 146
 
147 147
 
@@ -162,56 +162,56 @@  discard block
 block discarded – undo
162 162
  */
163 163
 function geodir_listing_loop_filter($query)
164 164
 {
165
-    global $wp_query, $geodir_post_type, $table, $plugin_prefix, $table, $term;
165
+	global $wp_query, $geodir_post_type, $table, $plugin_prefix, $table, $term;
166 166
 
167
-    // fix wp_reset_query for popular post view widget
168
-    if (!geodir_is_geodir_page()) {
169
-        return;
170
-    }
167
+	// fix wp_reset_query for popular post view widget
168
+	if (!geodir_is_geodir_page()) {
169
+		return;
170
+	}
171 171
 
172
-    $geodir_post_type = geodir_get_current_posttype();
173
-
174
-    if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) {
175
-        $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy');
176
-
177
-        if (isset($wp_query->query[$taxonomies[0]])) {
178
-            $request_term = explode("/", $wp_query->query[$taxonomies[0]]);
179
-            $request_term = end($request_term);
180
-            if (!term_exists($request_term)) {
181
-                $args = array('number' => '1',);
182
-                $terms_arr = get_terms($taxonomies[0], $args);
183
-                foreach ($terms_arr as $location_term) {
184
-                    $term_arr = $location_term;
185
-                    $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term));
186
-                }
187
-                $wp_query->queried_object_id = 1;
188
-                $wp_query->queried_object = $term_arr;
189
-                //print_r($wp_query) ;
190
-            }
191
-        }
172
+	$geodir_post_type = geodir_get_current_posttype();
173
+
174
+	if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) {
175
+		$taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy');
176
+
177
+		if (isset($wp_query->query[$taxonomies[0]])) {
178
+			$request_term = explode("/", $wp_query->query[$taxonomies[0]]);
179
+			$request_term = end($request_term);
180
+			if (!term_exists($request_term)) {
181
+				$args = array('number' => '1',);
182
+				$terms_arr = get_terms($taxonomies[0], $args);
183
+				foreach ($terms_arr as $location_term) {
184
+					$term_arr = $location_term;
185
+					$term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term));
186
+				}
187
+				$wp_query->queried_object_id = 1;
188
+				$wp_query->queried_object = $term_arr;
189
+				//print_r($wp_query) ;
190
+			}
191
+		}
192 192
 
193
-    }
194
-    if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) {
195
-
196
-        $table = $plugin_prefix . $geodir_post_type . '_detail';
197
-
198
-        add_filter('posts_fields', 'geodir_posts_fields', 1);
199
-        add_filter('posts_join', 'geodir_posts_join', 1);
200
-        geodir_post_where();
201
-        if (!is_admin())
202
-            add_filter('posts_orderby', 'geodir_posts_orderby', 1);
203
-
204
-        // advanced filter for popular post view widget
205
-        global $wp_query;
206
-        if (!is_admin()) {
207
-            if (!empty($wp_query->query['with_pics_only'])) {
208
-                add_filter('posts_join', 'geodir_filter_widget_join', 1000);
209
-            }
210
-            add_filter('posts_where', 'geodir_filter_widget_where', 1000);
211
-        }
193
+	}
194
+	if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) {
212 195
 
213
-    }
214
-    return $query;
196
+		$table = $plugin_prefix . $geodir_post_type . '_detail';
197
+
198
+		add_filter('posts_fields', 'geodir_posts_fields', 1);
199
+		add_filter('posts_join', 'geodir_posts_join', 1);
200
+		geodir_post_where();
201
+		if (!is_admin())
202
+			add_filter('posts_orderby', 'geodir_posts_orderby', 1);
203
+
204
+		// advanced filter for popular post view widget
205
+		global $wp_query;
206
+		if (!is_admin()) {
207
+			if (!empty($wp_query->query['with_pics_only'])) {
208
+				add_filter('posts_join', 'geodir_filter_widget_join', 1000);
209
+			}
210
+			add_filter('posts_where', 'geodir_filter_widget_where', 1000);
211
+		}
212
+
213
+	}
214
+	return $query;
215 215
 }
216 216
 
217 217
 
@@ -230,67 +230,67 @@  discard block
 block discarded – undo
230 230
  * @return string Modified fields query string.
231 231
  */
232 232
 function geodir_posts_fields($fields) {
233
-    global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session;
233
+	global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session;
234 234
 
235
-    // Filter-Location-Manager to add location table.
236
-    $fields .= ", " . $table . ".* ";
235
+	// Filter-Location-Manager to add location table.
236
+	$fields .= ", " . $table . ".* ";
237 237
 
238 238
 	if ($snear != '' || $gd_session->get('all_near_me')) {
239
-        $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
239
+		$DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
240 240
 
241 241
 		if ($gd_session->get('all_near_me')) {
242
-            $mylat = $gd_session->get('user_lat');
243
-            $mylon = $gd_session->get('user_lon');
244
-        }
245
-
246
-        $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance ";
247
-    }
248
-
249
-    global $s;
250
-    if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
251
-        $keywords = explode(" ", $s);
252
-
253
-        if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
254
-            foreach($keywords as $kkey=>$kword){
255
-                if(mb_strlen($kword, 'UTF-8')<=$klimit){
256
-                    unset($keywords[$kkey]);
257
-                }
258
-            }
259
-        }
242
+			$mylat = $gd_session->get('user_lat');
243
+			$mylon = $gd_session->get('user_lon');
244
+		}
260 245
 
246
+		$fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance ";
247
+	}
261 248
 
262
-        if (count($keywords) > 1) {
263
-            $parts = array(
264
-                'AND' => 'gd_alltitlematch_part',
265
-                'OR' => 'gd_titlematch_part'
266
-            );
267
-            $gd_titlematch_part = "";
268
-            foreach ($parts as $key => $part) {
269
-                $gd_titlematch_part .= " CASE WHEN ";
270
-                $count = 0;
271
-                foreach ($keywords as $keyword) {
272
-                    $keyword = trim($keyword);
273
-                    $keyword  = wp_specialchars_decode($keyword ,ENT_QUOTES);
249
+	global $s;
250
+	if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
251
+		$keywords = explode(" ", $s);
252
+
253
+		if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
254
+			foreach($keywords as $kkey=>$kword){
255
+				if(mb_strlen($kword, 'UTF-8')<=$klimit){
256
+					unset($keywords[$kkey]);
257
+				}
258
+			}
259
+		}
260
+
261
+
262
+		if (count($keywords) > 1) {
263
+			$parts = array(
264
+				'AND' => 'gd_alltitlematch_part',
265
+				'OR' => 'gd_titlematch_part'
266
+			);
267
+			$gd_titlematch_part = "";
268
+			foreach ($parts as $key => $part) {
269
+				$gd_titlematch_part .= " CASE WHEN ";
270
+				$count = 0;
271
+				foreach ($keywords as $keyword) {
272
+					$keyword = trim($keyword);
273
+					$keyword  = wp_specialchars_decode($keyword ,ENT_QUOTES);
274 274
 					$count++;
275
-                    if ($count < count($keywords)) {
276
-                       // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " ";
275
+					if ($count < count($keywords)) {
276
+					   // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " ";
277 277
 						$gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) " . $key . " ";
278
-                    } else {
279
-                        //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' ";
278
+					} else {
279
+						//$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' ";
280 280
 						$gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) ";
281
-                    }
282
-                }
283
-                $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ",";
284
-            }
285
-        } else {
286
-            $gd_titlematch_part = "";
287
-        }
288
-        $s = stripslashes_deep( $s );
289
-        $s = wp_specialchars_decode($s,ENT_QUOTES);
281
+					}
282
+				}
283
+				$gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ",";
284
+			}
285
+		} else {
286
+			$gd_titlematch_part = "";
287
+		}
288
+		$s = stripslashes_deep( $s );
289
+		$s = wp_specialchars_decode($s,ENT_QUOTES);
290 290
 		$fields .= $wpdb->prepare(", CASE WHEN " . $table . ".is_featured='1' THEN 1 ELSE 0 END AS gd_featured, CASE WHEN " . $wpdb->posts . ".post_title LIKE %s THEN 1 ELSE 0 END AS gd_exacttitle," . $gd_titlematch_part . " CASE WHEN ( " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s ) THEN 1 ELSE 0 END AS gd_titlematch, CASE WHEN ( " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s ) THEN 1 ELSE 0 END AS gd_content", array($s, $s, $s . '%', '% ' . $s . '%', $s, $s . ' %', '% ' . $s . ' %', '% ' . $s));
291
-    }
291
+	}
292 292
 
293
-    return $fields;
293
+	return $fields;
294 294
 }
295 295
 
296 296
 
@@ -307,26 +307,26 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function geodir_posts_join($join)
309 309
 {
310
-    global $wpdb, $geodir_post_type, $table, $table_prefix, $plugin_prefix;
310
+	global $wpdb, $geodir_post_type, $table, $table_prefix, $plugin_prefix;
311 311
 
312
-    ########### WPML ###########
312
+	########### WPML ###########
313 313
 
314
-    if (function_exists('icl_object_id')) {
315
-        global $sitepress;
316
-        $lang_code = ICL_LANGUAGE_CODE;
317
-        $default_lang_code = $sitepress->get_default_language();
318
-        if ($lang_code) {
319
-            $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID";
320
-        }
314
+	if (function_exists('icl_object_id')) {
315
+		global $sitepress;
316
+		$lang_code = ICL_LANGUAGE_CODE;
317
+		$default_lang_code = $sitepress->get_default_language();
318
+		if ($lang_code) {
319
+			$join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID";
320
+		}
321 321
 
322
-    }
323
-    ########### WPML ###########
322
+	}
323
+	########### WPML ###########
324 324
 
325
-    $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID)  ";
326
-    //===old code start
327
-    //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id)  " ;//===old code end
325
+	$join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID)  ";
326
+	//===old code start
327
+	//$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id)  " ;//===old code end
328 328
 
329
-    return $join;
329
+	return $join;
330 330
 }
331 331
 
332 332
 
@@ -344,15 +344,15 @@  discard block
 block discarded – undo
344 344
  */
345 345
 function geodir_posts_orderby($orderby)
346 346
 {
347
-    global $wpdb, $wp_query, $geodir_post_type, $table, $plugin_prefix, $snear, $default_sort;
347
+	global $wpdb, $wp_query, $geodir_post_type, $table, $plugin_prefix, $snear, $default_sort;
348 348
 
349
-    $sort_by = '';
350
-    $orderby = ' ';
349
+	$sort_by = '';
350
+	$orderby = ' ';
351 351
 
352
-    if (get_query_var('order_by'))
353
-        $sort_by = get_query_var('order_by');
352
+	if (get_query_var('order_by'))
353
+		$sort_by = get_query_var('order_by');
354 354
 
355
-    /*if(isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries){
355
+	/*if(isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries){
356 356
         $current_term = $wp_query->get_queried_object();
357 357
     }
358 358
 
@@ -366,133 +366,133 @@  discard block
 block discarded – undo
366 366
     }*/
367 367
 
368 368
 
369
-    if ($snear != '') {
370
-        $orderby .= " distance,";
371
-    }
369
+	if ($snear != '') {
370
+		$orderby .= " distance,";
371
+	}
372 372
 
373
-    if (isset($_REQUEST['sort_by']) && $_REQUEST['sort_by'] != '' && is_main_query())
374
-        $sort_by = esc_attr($_REQUEST['sort_by']);
373
+	if (isset($_REQUEST['sort_by']) && $_REQUEST['sort_by'] != '' && is_main_query())
374
+		$sort_by = esc_attr($_REQUEST['sort_by']);
375 375
 
376 376
 
377
-    if ($sort_by == '') {
378
-        $default_sort = geodir_get_posts_default_sort($geodir_post_type);
379
-        if (!empty($default_sort))
380
-            $sort_by = $default_sort;
381
-    }
377
+	if ($sort_by == '') {
378
+		$default_sort = geodir_get_posts_default_sort($geodir_post_type);
379
+		if (!empty($default_sort))
380
+			$sort_by = $default_sort;
381
+	}
382 382
 
383
-    /*
383
+	/*
384 384
     if search by term & no location then order always "relevance"
385 385
     if search by location then order always "nearest"
386 386
     */
387
-    if (is_main_query() && geodir_is_page('search')) {
388
-        $search_term = get_query_var('s');
387
+	if (is_main_query() && geodir_is_page('search')) {
388
+		$search_term = get_query_var('s');
389 389
 
390
-        if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) {
391
-            $sort_by = 'az';
392
-        }
390
+		if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) {
391
+			$sort_by = 'az';
392
+		}
393 393
 
394
-        if ($snear != '' &&  $sort_by!='farthest') {
395
-            $sort_by = 'nearest';
396
-        }
397
-    }
398
-
399
-    switch ($sort_by):
400
-        case 'newest':
401
-            $orderby = "$wpdb->posts.post_date desc, ";
402
-            break;
403
-        case 'oldest':
404
-            $orderby = "$wpdb->posts.post_date asc, ";
405
-            break;
406
-        case 'low_review':
407
-        case 'rating_count_asc':
408
-            $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, ";
409
-            break;
410
-        case 'high_review':
411
-        case 'rating_count_desc':
412
-            $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, ";
413
-            break;
414
-        case 'low_rating':
415
-            $orderby = "( " . $table . ".overall_rating  ) ASC, " . $table . ".rating_count ASC,  ";
416
-            break;
417
-        case 'high_rating':
418
-            $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, ";
419
-            break;
420
-        case 'featured':
421
-            $orderby = $table . ".is_featured asc, ";
422
-            break;
423
-        case 'nearest':
424
-            $orderby = " distance asc, ";
425
-            break;
426
-        case 'farthest':
427
-            $orderby = " distance desc, ";
428
-            break;
429
-        case 'random':
430
-            $orderby = " rand(), ";
431
-            break;
432
-        case 'az':
433
-            $orderby = "$wpdb->posts.post_title asc, ";
434
-            break;
435
-        // sort by rating
436
-        case 'overall_rating_desc':
437
-            $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, ";
438
-            break;
439
-        case 'overall_rating_asc':
440
-            $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, ";
441
-            break;
442
-        default:
443
-
444
-            break;
445
-    endswitch;
446
-
447
-    if ($sort_by != '' && geodir_cpt_has_rating_disabled($geodir_post_type)) {
448
-        if (in_array($sort_by, array('high_review', 'rating_count_desc', 'high_rating', 'overall_rating_desc'))) {
449
-            $orderby = "$wpdb->posts.comment_count DESC, ";
450
-            $sort_by = 'comment_count_desc';
451
-        } else if (in_array($sort_by, array('low_review', 'rating_count_asc', 'low_rating', 'overall_rating_asc'))) {
452
-            $orderby = "$wpdb->posts.comment_count ASC, ";
453
-            $sort_by = 'comment_count_asc';
454
-        }
455
-    }
394
+		if ($snear != '' &&  $sort_by!='farthest') {
395
+			$sort_by = 'nearest';
396
+		}
397
+	}
456 398
 
457
-    global $s;
399
+	switch ($sort_by):
400
+		case 'newest':
401
+			$orderby = "$wpdb->posts.post_date desc, ";
402
+			break;
403
+		case 'oldest':
404
+			$orderby = "$wpdb->posts.post_date asc, ";
405
+			break;
406
+		case 'low_review':
407
+		case 'rating_count_asc':
408
+			$orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, ";
409
+			break;
410
+		case 'high_review':
411
+		case 'rating_count_desc':
412
+			$orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, ";
413
+			break;
414
+		case 'low_rating':
415
+			$orderby = "( " . $table . ".overall_rating  ) ASC, " . $table . ".rating_count ASC,  ";
416
+			break;
417
+		case 'high_rating':
418
+			$orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, ";
419
+			break;
420
+		case 'featured':
421
+			$orderby = $table . ".is_featured asc, ";
422
+			break;
423
+		case 'nearest':
424
+			$orderby = " distance asc, ";
425
+			break;
426
+		case 'farthest':
427
+			$orderby = " distance desc, ";
428
+			break;
429
+		case 'random':
430
+			$orderby = " rand(), ";
431
+			break;
432
+		case 'az':
433
+			$orderby = "$wpdb->posts.post_title asc, ";
434
+			break;
435
+		// sort by rating
436
+		case 'overall_rating_desc':
437
+			$orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, ";
438
+			break;
439
+		case 'overall_rating_asc':
440
+			$orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, ";
441
+			break;
442
+		default:
443
+
444
+			break;
445
+	endswitch;
446
+
447
+	if ($sort_by != '' && geodir_cpt_has_rating_disabled($geodir_post_type)) {
448
+		if (in_array($sort_by, array('high_review', 'rating_count_desc', 'high_rating', 'overall_rating_desc'))) {
449
+			$orderby = "$wpdb->posts.comment_count DESC, ";
450
+			$sort_by = 'comment_count_desc';
451
+		} else if (in_array($sort_by, array('low_review', 'rating_count_asc', 'low_rating', 'overall_rating_asc'))) {
452
+			$orderby = "$wpdb->posts.comment_count ASC, ";
453
+			$sort_by = 'comment_count_asc';
454
+		}
455
+	}
458 456
 
459
-    if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
460
-        $keywords = explode(" ", $s);
461
-        if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
462
-            foreach($keywords as $kkey=>$kword){
463
-                if(mb_strlen($kword, 'UTF-8')<=$klimit){
464
-                    unset($keywords[$kkey]);
465
-                }
466
-            }
467
-        }
468
-        if ($sort_by == 'nearest' || $sort_by == 'farthest') {
469
-            if (count($keywords) > 1) {
470
-                $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, ";
471
-            } else {
472
-                $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, ";
473
-            }
474
-        } else {
475
-            if (count($keywords) > 1) {
476
-                $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, " . $orderby;
477
-            } else {
478
-                $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby;
479
-            }
480
-        }
481
-    }
457
+	global $s;
458
+
459
+	if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') {
460
+		$keywords = explode(" ", $s);
461
+		if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
462
+			foreach($keywords as $kkey=>$kword){
463
+				if(mb_strlen($kword, 'UTF-8')<=$klimit){
464
+					unset($keywords[$kkey]);
465
+				}
466
+			}
467
+		}
468
+		if ($sort_by == 'nearest' || $sort_by == 'farthest') {
469
+			if (count($keywords) > 1) {
470
+				$orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, ";
471
+			} else {
472
+				$orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, ";
473
+			}
474
+		} else {
475
+			if (count($keywords) > 1) {
476
+				$orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, " . $orderby;
477
+			} else {
478
+				$orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby;
479
+			}
480
+		}
481
+	}
482 482
 
483
-    /**
484
-     * Filter order by SQL.
485
-     *
486
-     * @since 1.0.0
487
-     * @param string $orderby The orderby query string.
488
-     * @param string $sort_by Sortby query string.
489
-     * @param string $table Listing table name.
490
-     */
491
-    $orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table);
483
+	/**
484
+	 * Filter order by SQL.
485
+	 *
486
+	 * @since 1.0.0
487
+	 * @param string $orderby The orderby query string.
488
+	 * @param string $sort_by Sortby query string.
489
+	 * @param string $table Listing table name.
490
+	 */
491
+	$orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table);
492 492
 
493
-    $orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title ";
493
+	$orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title ";
494 494
 
495
-    return $orderby;
495
+	return $orderby;
496 496
 }
497 497
 
498 498
 
@@ -510,53 +510,53 @@  discard block
 block discarded – undo
510 510
 function geodir_posts_order_by_custom_sort($orderby, $sort_by, $table)
511 511
 {
512 512
 
513
-    global $wpdb;
513
+	global $wpdb;
514 514
 
515
-    if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' ||  $_REQUEST['s']==' ') ) )) {
515
+	if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' ||  $_REQUEST['s']==' ') ) )) {
516 516
 
517
-        $sort_array = explode('_', $sort_by);
517
+		$sort_array = explode('_', $sort_by);
518 518
 
519
-        $sort_by_count = count($sort_array);
519
+		$sort_by_count = count($sort_array);
520 520
 
521
-        $order = $sort_array[$sort_by_count - 1];
521
+		$order = $sort_array[$sort_by_count - 1];
522 522
 
523
-        if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) {
523
+		if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) {
524 524
 
525
-            $sort_by = str_replace('_' . $order, '', $sort_by);
525
+			$sort_by = str_replace('_' . $order, '', $sort_by);
526 526
 
527
-            switch ($sort_by):
527
+			switch ($sort_by):
528 528
 
529
-                case 'post_date':
530
-                case 'comment_count':
529
+				case 'post_date':
530
+				case 'comment_count':
531 531
 
532
-                    $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", ";
533
-                    break;
532
+					$orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", ";
533
+					break;
534 534
 
535
-                case 'distance':
536
-                    $orderby = $sort_by . " " . $order . ", ";
537
-                    break;
535
+				case 'distance':
536
+					$orderby = $sort_by . " " . $order . ", ";
537
+					break;
538 538
 
539 539
 
540
-                // sort by rating
541
-                case 'overall_rating':
542
-                    $orderby = " " . $table . "." . $sort_by . "  " . $order . ", " . $table . ".rating_count " . $order . ", ";
540
+				// sort by rating
541
+				case 'overall_rating':
542
+					$orderby = " " . $table . "." . $sort_by . "  " . $order . ", " . $table . ".rating_count " . $order . ", ";
543 543
 
544
-                    break;
544
+					break;
545 545
 
546 546
 
547
-                default:
548
-                    if (geodir_column_exist($table, $sort_by)) {
547
+				default:
548
+					if (geodir_column_exist($table, $sort_by)) {
549 549
 						$orderby = $table . "." . $sort_by . " " . $order . ", ";
550 550
 					}
551
-                    break;
551
+					break;
552 552
 
553
-            endswitch;
553
+			endswitch;
554 554
 
555
-        }
555
+		}
556 556
 
557
-    }
557
+	}
558 558
 
559
-    return $orderby;
559
+	return $orderby;
560 560
 }
561 561
 
562 562
 /**
@@ -571,34 +571,34 @@  discard block
 block discarded – undo
571 571
 {
572 572
 
573 573
 
574
-    global $wpdb, $geodir_post_type, $table, $s, $snear;
574
+	global $wpdb, $geodir_post_type, $table, $s, $snear;
575 575
 
576
-    if (!is_admin()) {
576
+	if (!is_admin()) {
577 577
 
578
-        if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
579
-            add_filter('posts_where', 'geodir_edit_listing_where', 1);
578
+		if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
579
+			add_filter('posts_where', 'geodir_edit_listing_where', 1);
580 580
 
581
-        } elseif ((is_search() && $_REQUEST['geodir_search'])) {
581
+		} elseif ((is_search() && $_REQUEST['geodir_search'])) {
582 582
 
583
-            add_filter('posts_where', 'searching_filter_where', 1);
583
+			add_filter('posts_where', 'searching_filter_where', 1);
584 584
 
585
-            if ($snear != '')
586
-                add_filter('posts_where', 'searching_filter_where', 1);
585
+			if ($snear != '')
586
+				add_filter('posts_where', 'searching_filter_where', 1);
587 587
 
588
-            add_filter('posts_orderby', 'geodir_posts_orderby', 1);
588
+			add_filter('posts_orderby', 'geodir_posts_orderby', 1);
589 589
 
590
-        } elseif (geodir_is_page('author')) {
590
+		} elseif (geodir_is_page('author')) {
591 591
 
592
-            add_filter('posts_where', 'author_filter_where', 1);
592
+			add_filter('posts_where', 'author_filter_where', 1);
593 593
 
594
-        }
594
+		}
595 595
 
596
-        //if (!geodir_is_page('detail'))
597
-            add_filter('posts_where', 'geodir_default_where', 1);/**/
596
+		//if (!geodir_is_page('detail'))
597
+			add_filter('posts_where', 'geodir_default_where', 1);/**/
598 598
 
599
-        //add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts
599
+		//add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts
600 600
 
601
-    }
601
+	}
602 602
 }
603 603
 
604 604
 /**
@@ -613,13 +613,13 @@  discard block
 block discarded – undo
613 613
  */
614 614
 function geodir_preview_post_cap($allcaps, $caps, $args)
615 615
 {
616
-    $user_id = get_current_user_id();
617
-    if ($user_id && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != '' && isset($_REQUEST['p']) && $_REQUEST['p'] != '' && $args[0] == 'edit_post' && $_REQUEST['p'] == $args[2]) {
616
+	$user_id = get_current_user_id();
617
+	if ($user_id && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != '' && isset($_REQUEST['p']) && $_REQUEST['p'] != '' && $args[0] == 'edit_post' && $_REQUEST['p'] == $args[2]) {
618 618
 
619
-        $allcaps['edit_posts'] = true;
620
-    }
621
-    //print_r($allcaps);
622
-    return $allcaps;
619
+		$allcaps['edit_posts'] = true;
620
+	}
621
+	//print_r($allcaps);
622
+	return $allcaps;
623 623
 }
624 624
 
625 625
 
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
  */
635 635
 function geodir_edit_listing_where($where)
636 636
 {
637
-    global $wpdb;
638
-    $where = $wpdb->prepare(" AND $wpdb->posts.ID = %d ", $_REQUEST['pid']);
639
-    return $where;
637
+	global $wpdb;
638
+	$where = $wpdb->prepare(" AND $wpdb->posts.ID = %d ", $_REQUEST['pid']);
639
+	return $where;
640 640
 }
641 641
 
642 642
 
@@ -653,29 +653,29 @@  discard block
 block discarded – undo
653 653
  */
654 654
 function geodir_default_where($where)
655 655
 {
656
-    global $wp_query, $wpdb;
657
-
658
-    //print_r($wp_query);
659
-    ########### WPML ###########
660
-
661
-    if (function_exists('icl_object_id')) {
662
-        global $sitepress, $table_prefix;
663
-        $lang_code = ICL_LANGUAGE_CODE;
664
-        $default_lang_code = $sitepress->get_default_language();
665
-        $q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : '';
666
-        //echo '##########'.$q_post_type;
667
-        if ($lang_code && $q_post_type) {
668
-            $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') ";
669
-            //$where .= " AND icl_t.language_code = '$lang_code' ";
670
-        }
656
+	global $wp_query, $wpdb;
671 657
 
672
-    }
673
-    ########### WPML ###########
658
+	//print_r($wp_query);
659
+	########### WPML ###########
660
+
661
+	if (function_exists('icl_object_id')) {
662
+		global $sitepress, $table_prefix;
663
+		$lang_code = ICL_LANGUAGE_CODE;
664
+		$default_lang_code = $sitepress->get_default_language();
665
+		$q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : '';
666
+		//echo '##########'.$q_post_type;
667
+		if ($lang_code && $q_post_type) {
668
+			$where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') ";
669
+			//$where .= " AND icl_t.language_code = '$lang_code' ";
670
+		}
671
+
672
+	}
673
+	########### WPML ###########
674 674
 
675 675
 
676
-    return $where = str_replace("0 = 1", "1=1", $where);
676
+	return $where = str_replace("0 = 1", "1=1", $where);
677 677
 
678
-    /* ====== old code start ===
678
+	/* ====== old code start ===
679 679
     $where = str_replace("0 = 1", "1=1", $where);
680 680
     $country = get_query_var('gd_country');
681 681
     $region = get_query_var('gd_region');
@@ -716,108 +716,108 @@  discard block
 block discarded – undo
716 716
  * @return string Modified where query string.
717 717
  */
718 718
 function searching_filter_where($where) {
719
-    global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s_A, $s_SA, $search_term, $gd_session;
719
+	global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s_A, $s_SA, $search_term, $gd_session;
720 720
 
721
-    $search_term = 'OR';
722
-    $search_term = 'AND';
723
-    $geodir_custom_search = '';
724
-    $category_search_range = '';
721
+	$search_term = 'OR';
722
+	$search_term = 'AND';
723
+	$geodir_custom_search = '';
724
+	$category_search_range = '';
725 725
 
726
-    if (is_single() && get_query_var('post_type')) {
726
+	if (is_single() && get_query_var('post_type')) {
727 727
 		return $where;
728 728
 	}
729 729
 
730
-    if (is_tax()) {
730
+	if (is_tax()) {
731 731
 		return $where;
732 732
 	}
733 733
 
734 734
 	$s = trim($s);
735
-    $s  = wp_specialchars_decode($s ,ENT_QUOTES);
736
-    $s_A = wp_specialchars_decode($s_A ,ENT_QUOTES);
737
-
738
-    $where = '';
739
-    $better_search_terms = '';
740
-    if (isset($_REQUEST['stype']))
741
-        $post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype']));
742
-    else
743
-        $post_types = 'gd_place';
744
-
745
-    if ($s != '') {
746
-        $keywords = explode(" ", $s);
747
-        if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
748
-            foreach($keywords as $kkey=>$kword){
749
-                if(mb_strlen($kword, 'UTF-8')<=$klimit){
750
-                    unset($keywords[$kkey]);
751
-                }
752
-            }
753
-        }
735
+	$s  = wp_specialchars_decode($s ,ENT_QUOTES);
736
+	$s_A = wp_specialchars_decode($s_A ,ENT_QUOTES);
754 737
 
755
-        if (!empty($keywords)) {
756
-            foreach ($keywords as $keyword) {
757
-                $keyword = trim($keyword);
758
-                $keyword  = wp_specialchars_decode($keyword ,ENT_QUOTES);
759
-                if ($keyword != '') {
760
-                    /**
761
-                     * Filter the search query keywords SQL.
762
-                     *
763
-                     * @since 1.5.9
764
-                     * @package GeoDirectory
765
-                     * @param string $better_search_terms The query values, default: `' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )'`.
766
-                     * @param array $keywords The array of keywords for the query.
767
-                     * @param string $keyword The single keyword being searched.
768
-                     */
738
+	$where = '';
739
+	$better_search_terms = '';
740
+	if (isset($_REQUEST['stype']))
741
+		$post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype']));
742
+	else
743
+		$post_types = 'gd_place';
744
+
745
+	if ($s != '') {
746
+		$keywords = explode(" ", $s);
747
+		if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){
748
+			foreach($keywords as $kkey=>$kword){
749
+				if(mb_strlen($kword, 'UTF-8')<=$klimit){
750
+					unset($keywords[$kkey]);
751
+				}
752
+			}
753
+		}
754
+
755
+		if (!empty($keywords)) {
756
+			foreach ($keywords as $keyword) {
757
+				$keyword = trim($keyword);
758
+				$keyword  = wp_specialchars_decode($keyword ,ENT_QUOTES);
759
+				if ($keyword != '') {
760
+					/**
761
+					 * Filter the search query keywords SQL.
762
+					 *
763
+					 * @since 1.5.9
764
+					 * @package GeoDirectory
765
+					 * @param string $better_search_terms The query values, default: `' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )'`.
766
+					 * @param array $keywords The array of keywords for the query.
767
+					 * @param string $keyword The single keyword being searched.
768
+					 */
769 769
 					$better_search_terms .= apply_filters("geodir_search_better_search_terms",' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )',$keywords,$keyword);
770
-                }
771
-            }
772
-        }
773
-    }
770
+				}
771
+			}
772
+		}
773
+	}
774 774
 
775
-    /* get taxonomy */
776
-    $taxonomies = geodir_get_taxonomies($post_types, true);
777
-    if($taxonomies) {
778
-        $taxonomies = implode("','", $taxonomies);
779
-        $taxonomies = "'" . $taxonomies . "'";
780
-    }else{$taxonomies='';}
775
+	/* get taxonomy */
776
+	$taxonomies = geodir_get_taxonomies($post_types, true);
777
+	if($taxonomies) {
778
+		$taxonomies = implode("','", $taxonomies);
779
+		$taxonomies = "'" . $taxonomies . "'";
780
+	}else{$taxonomies='';}
781 781
 
782
-    $content_where = $terms_where = '';
782
+	$content_where = $terms_where = '';
783 783
 	if ($s != '') {
784
-        /**
785
-         * Filter the search query content where values.
786
-         *
787
-         * @since 1.5.0
788
-         * @package GeoDirectory
789
-         * @param string $content_where The query values, default: `" OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") ") "`.
790
-         */
784
+		/**
785
+		 * Filter the search query content where values.
786
+		 *
787
+		 * @since 1.5.0
788
+		 * @package GeoDirectory
789
+		 * @param string $content_where The query values, default: `" OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") ") "`.
790
+		 */
791 791
 		$content_where = apply_filters("geodir_search_content_where"," OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") ");
792
-        /**
793
-         * Filter the search query term values.
794
-         *
795
-         * @since 1.5.0
796
-         * @package GeoDirectory
797
-         * @param string $terms_where The separator, default: `" AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "`.
798
-         */
799
-        $terms_where = apply_filters("geodir_search_terms_where"," AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) ");
792
+		/**
793
+		 * Filter the search query term values.
794
+		 *
795
+		 * @since 1.5.0
796
+		 * @package GeoDirectory
797
+		 * @param string $terms_where The separator, default: `" AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "`.
798
+		 */
799
+		$terms_where = apply_filters("geodir_search_terms_where"," AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) ");
800 800
 	}
801 801
 
802
-    if ($snear != '') {
802
+	if ($snear != '') {
803 803
 
804 804
 
805
-        if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) {
806
-            $dist = $gd_session->get('near_me_range');
807
-        }
808
-        $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69);
809
-        $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69);
810
-        $lat1 = $mylat - ($dist / 69);
811
-        $lat2 = $mylat + ($dist / 69);
805
+		if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) {
806
+			$dist = $gd_session->get('near_me_range');
807
+		}
808
+		$lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69);
809
+		$lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69);
810
+		$lat1 = $mylat - ($dist / 69);
811
+		$lat2 = $mylat + ($dist / 69);
812 812
 
813
-        $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : '';
814
-        $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : '';
815
-        $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : '';
816
-        $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : '';
813
+		$rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : '';
814
+		$rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : '';
815
+		$rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : '';
816
+		$rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : '';
817 817
 
818 818
 
819 819
 
820
-	    $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms)
820
+		$where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms)
821 821
 			                    $content_where 
822 822
 								OR ($wpdb->posts.ID IN( 
823 823
 										SELECT $wpdb->term_relationships.object_id as post_id 
@@ -834,13 +834,13 @@  discard block
 block discarded – undo
834 834
 						AND ( " . $table . ".post_latitude between $rlat1 and $rlat2 )
835 835
 						AND ( " . $table . ".post_longitude between $rlon1 and $rlon2 ) ";
836 836
 
837
-        if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') {
838
-            $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
839
-            $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;
840
-        }
837
+		if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') {
838
+			$DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
839
+			$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;
840
+		}
841 841
 
842
-    } else {
843
-        $where .= " AND (	( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms)
842
+	} else {
843
+		$where .= " AND (	( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms)
844 844
                             $content_where  
845 845
 							OR ( $wpdb->posts.ID IN(	
846 846
 									SELECT $wpdb->term_relationships.object_id as post_id                     
@@ -854,19 +854,19 @@  discard block
 block discarded – undo
854 854
 					) 
855 855
 				AND $wpdb->posts.post_type in ('$post_types')
856 856
 				AND ($wpdb->posts.post_status = 'publish') ";
857
-    }
857
+	}
858 858
 
859 859
 	########### WPML ###########
860
-    if ( function_exists( 'icl_object_id' ) ) {
860
+	if ( function_exists( 'icl_object_id' ) ) {
861 861
 		$lang_code = ICL_LANGUAGE_CODE;
862 862
 
863 863
 		if ($lang_code && $post_types) {
864
-            $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') ";
865
-        }
866
-    }
867
-    ########### WPML ###########
864
+			$where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') ";
865
+		}
866
+	}
867
+	########### WPML ###########
868 868
 
869
-    return $where;
869
+	return $where;
870 870
 }
871 871
 
872 872
 
@@ -881,45 +881,45 @@  discard block
 block discarded – undo
881 881
  * @return string Modified where query string.
882 882
  */
883 883
 function author_filter_where($where) {
884
-    global $wpdb, $geodir_post_type, $table, $curr;
884
+	global $wpdb, $geodir_post_type, $table, $curr;
885 885
 
886
-    $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
887
-    $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0;
886
+	$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
887
+	$user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0;
888 888
 
889
-    if (isset($_REQUEST['stype'])) {
890
-        $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']);
891
-    } else {
892
-        $where = " AND $wpdb->posts.post_type IN ('gd_place') ";
893
-    }
889
+	if (isset($_REQUEST['stype'])) {
890
+		$where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']);
891
+	} else {
892
+		$where = " AND $wpdb->posts.post_type IN ('gd_place') ";
893
+	}
894 894
 
895
-    if ($user_id > 0) {
896
-        if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') {
897
-            $user_fav_posts = get_user_meta($user_id, 'gd_user_favourite_post', true);
898
-            $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1';
899
-            $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')";
900
-        } else
901
-            $where .= " AND $wpdb->posts.post_author = $user_id";
902
-
903
-        if ($user_id == (int)get_current_user_id()) {
904
-            $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') ";
905
-        } else {
906
-            $where .= " AND $wpdb->posts.post_status = 'publish' ";
907
-        }
908
-    } else {
909
-        $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' ";
910
-    }
895
+	if ($user_id > 0) {
896
+		if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') {
897
+			$user_fav_posts = get_user_meta($user_id, 'gd_user_favourite_post', true);
898
+			$user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1';
899
+			$where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')";
900
+		} else
901
+			$where .= " AND $wpdb->posts.post_author = $user_id";
902
+
903
+		if ($user_id == (int)get_current_user_id()) {
904
+			$where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') ";
905
+		} else {
906
+			$where .= " AND $wpdb->posts.post_status = 'publish' ";
907
+		}
908
+	} else {
909
+		$where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' ";
910
+	}
911 911
 
912
-    ########### WPML ###########
913
-    if (function_exists('icl_object_id')) {
914
-        $lang_code = ICL_LANGUAGE_CODE;
915
-        if ($lang_code) {
916
-            $where .= " AND icl_t.language_code='" . $lang_code . "' ";
917
-        }
912
+	########### WPML ###########
913
+	if (function_exists('icl_object_id')) {
914
+		$lang_code = ICL_LANGUAGE_CODE;
915
+		if ($lang_code) {
916
+			$where .= " AND icl_t.language_code='" . $lang_code . "' ";
917
+		}
918 918
 
919
-    }
920
-    ########### WPML ###########
919
+	}
920
+	########### WPML ###########
921 921
 
922
-    return $where;
922
+	return $where;
923 923
 }
924 924
 
925 925
 /**
@@ -934,11 +934,11 @@  discard block
 block discarded – undo
934 934
  */
935 935
 function geodir_filter_widget_join($join)
936 936
 {
937
-    global $wp_query, $table;
938
-    if (!empty($wp_query->query['with_pics_only'])) {
939
-        $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )";
940
-    }
941
-    return $join;
937
+	global $wp_query, $table;
938
+	if (!empty($wp_query->query['with_pics_only'])) {
939
+		$join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )";
940
+	}
941
+	return $join;
942 942
 }
943 943
 
944 944
 /**
@@ -953,42 +953,42 @@  discard block
 block discarded – undo
953 953
  */
954 954
 function geodir_filter_widget_where($where)
955 955
 {
956
-    global $wp_query, $table;
957
-    if (!empty($wp_query->query['show_featured_only'])) {
958
-        $where .= " AND " . $table . ".is_featured = '1'";
959
-    }
960
-    if (!empty($wp_query->query['show_special_only'])) {
961
-        $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )";
962
-    }
963
-    if (!empty($wp_query->query['with_pics_only'])) {
964
-        $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id";
965
-    }
966
-    if (!empty($wp_query->query['with_videos_only'])) {
967
-        $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )";
968
-    }
969
-    return $where;
956
+	global $wp_query, $table;
957
+	if (!empty($wp_query->query['show_featured_only'])) {
958
+		$where .= " AND " . $table . ".is_featured = '1'";
959
+	}
960
+	if (!empty($wp_query->query['show_special_only'])) {
961
+		$where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )";
962
+	}
963
+	if (!empty($wp_query->query['with_pics_only'])) {
964
+		$where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id";
965
+	}
966
+	if (!empty($wp_query->query['with_videos_only'])) {
967
+		$where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )";
968
+	}
969
+	return $where;
970 970
 }
971 971
 
972 972
 
973 973
 function geodir_related_posts_fields($fields) {
974
-    global $wp_query, $wpdb, $table, $post;
974
+	global $wp_query, $wpdb, $table, $post;
975 975
 
976
-    $fields .= ", " . $table . ".* ";
976
+	$fields .= ", " . $table . ".* ";
977 977
 
978
-    $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
978
+	$DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
979 979
 
980
-    $mylat = $post->post_latitude;
981
-    $mylon = $post->post_longitude;
980
+	$mylat = $post->post_latitude;
981
+	$mylon = $post->post_longitude;
982 982
 
983
-    $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 ";
984
-    return $fields;
983
+	$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 ";
984
+	return $fields;
985 985
 }
986 986
 function geodir_related_posts_fields_filter($query) {
987
-    if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']
988
-        && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest'
989
-        && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings']
990
-    ) {
991
-        add_filter('posts_fields', 'geodir_related_posts_fields', 1);
992
-    }
987
+	if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']
988
+		&& isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest'
989
+		&& isset($query->query_vars['related_listings']) && $query->query_vars['related_listings']
990
+	) {
991
+		add_filter('posts_fields', 'geodir_related_posts_fields', 1);
992
+	}
993 993
 }
994 994
 add_action('pre_get_posts', 'geodir_related_posts_fields_filter', 1);
995 995
\ No newline at end of file
Please login to merge, or discard this patch.