Test Failed
Pull Request — master (#314)
by Kiran
19:34
created

custom_functions.php ➔ geodir_is_wpml()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
ccs 0
cts 0
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Custom functions
4
 *
5
 * @since   1.0.0
6
 * @package GeoDirectory
7
 */
8
9
/**
10
 * Front end listing view template selection.
11
 *
12
 * This function adds a drop down in front end listing page for selecting view template. Ex: list view, 2 column grid
13
 * view, etc.
14
 *
15
 * @since   1.0.0
16
 * @package GeoDirectory
17
 *
18
 * @global object $gd_session GeoDirectory Session object.
19
 */
20 2
function geodir_list_view_select() {
21
	global $gd_session;
22
	?>
23
	<script type="text/javascript">
24
		function geodir_list_view_select(list) {
25
			//alert(listval);
26
			val = list.value;
27
			if (!val) {
28
				return;
29
			}
30
31
			var listSel = jQuery(list).parent().parent().next('.geodir_category_list_view');
32
			if (val != 1) {
33
				jQuery(listSel).children('li').addClass('geodir-gridview');
34
				jQuery(listSel).children('li').removeClass('geodir-listview');
35
			} else {
36
				jQuery(listSel).children('li').addClass('geodir-listview');
37
			}
38
39
			if (val == 1) {
40
				jQuery(listSel).children('li').removeClass('geodir-gridview gridview_onehalf gridview_onethird gridview_onefourth gridview_onefifth');
41
			}
42
			else if (val == 2) {
43
				jQuery(listSel).children('li').switchClass('gridview_onethird gridview_onefourth gridview_onefifth', 'gridview_onehalf', 600);
44
			}
45
			else if (val == 3) {
46
				jQuery(listSel).children('li').switchClass('gridview_onehalf gridview_onefourth gridview_onefifth', 'gridview_onethird', 600);
47
			}
48
			else if (val == 4) {
49
				jQuery(listSel).children('li').switchClass('gridview_onehalf gridview_onethird gridview_onefifth', 'gridview_onefourth', 600);
50
			}
51
			else if (val == 5) {
52
				jQuery(listSel).children('li').switchClass('gridview_onehalf gridview_onethird gridview_onefourth', 'gridview_onefifth', 600);
53
			}
54
55
			jQuery.post("<?php echo geodir_get_ajax_url();?>&gd_listing_view=" + val, function (data) {
56
				//alert(data );
57
			});
58
		}
59
	</script>
60
	<div class="geodir-list-view-select">
61
		<select name="gd_list_view" id="gd_list_view" onchange="geodir_list_view_select(this);">
62
			<?php $listing_view = (int) $gd_session->get( 'gd_listing_view' ); ?>
63
			<option value=""><?php _e( 'View:', 'geodirectory' ); ?></option>
64
			<option
65
				value="1" <?php selected( 1, $listing_view ); ?>><?php _e( 'View: List', 'geodirectory' ); ?></option>
66
			<option
67
				value="2" <?php selected( 2, $listing_view ); ?>><?php _e( 'View: Grid 2', 'geodirectory' ); ?></option>
68
			<option
69
				value="3" <?php selected( 3, $listing_view ); ?>><?php _e( 'View: Grid 3', 'geodirectory' ); ?></option>
70
			<option
71 2
				value="4" <?php selected( 4, $listing_view ); ?>><?php _e( 'View: Grid 4', 'geodirectory' ); ?></option>
72
			<option
73
				value="5" <?php selected( 5, $listing_view ); ?>><?php _e( 'View: Grid 5', 'geodirectory' ); ?></option>
74
		</select>
75
	</div>
76
	<?php
77
}
78
79
add_action( 'geodir_before_listing', 'geodir_list_view_select', 100 );
80
81
/**
82
 * Limit the listing excerpt.
83
 *
84
 * This function limits excerpt characters and display "read more" link.
85
 *
86
 * @since   1.0.0
87
 * @package GeoDirectory
88
 *
89 5
 * @param string|int $charlength The character length.
90 5
 *
91
 * @global object $post          The current post object.
92
 * @return string The modified excerpt.
93 5
 */
94
function geodir_max_excerpt( $charlength ) {
95 5
	global $post;
96 5
	if ( $charlength == '0' ) {
97
		return;
98 5
	}
99 5
	$out = '';
100 5
101 5
	$temp_post = $post;
102 5
	$excerpt   = get_the_excerpt();
103 5
104 5
	$charlength ++;
105 5
	$excerpt_more = function_exists( 'geodirf_excerpt_more' ) ? geodirf_excerpt_more( '' ) : geodir_excerpt_more( '' );
106 5
	if ( mb_strlen( $excerpt ) > $charlength ) {
107 5
		if ( mb_strlen( $excerpt_more ) > 0 && mb_strpos( $excerpt, $excerpt_more ) !== false ) {
108 5
			$excut = - ( mb_strlen( $excerpt_more ) );
109
			$subex = mb_substr( $excerpt, 0, $excut );
110
			if ( $charlength > 0 && mb_strlen( $subex ) > $charlength ) {
111
				$subex = mb_substr( $subex, 0, $charlength );
112
			}
113
			$out .= $subex;
114
		} else {
115
			$subex   = mb_substr( $excerpt, 0, $charlength - 5 );
116
			$exwords = explode( ' ', $subex );
117
			$excut   = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
118 5
			if ( $excut < 0 ) {
119
				$out .= mb_substr( $subex, 0, $excut );
120
			} else {
121
				$out .= $subex;
122
			}
123
		}
124 5
		$out .= ' <a class="excerpt-read-more" href="' . get_permalink() . '" title="' . get_the_title() . '">';
125 5
		/**
126
		 * Filter excerpt read more text.
127 5
		 *
128 1
		 * @since 1.0.0
129
		 */
130
		$out .= apply_filters( 'geodir_max_excerpt_end', __( 'Read more [...]', 'geodirectory' ) );
131
		$out .= '</a>';
132
133
	} else {
134
		if ( mb_strlen( $excerpt_more ) > 0 && mb_strpos( $excerpt, $excerpt_more ) !== false ) {
135
			$excut = - ( mb_strlen( $excerpt_more ) );
136
			$out .= mb_substr( $excerpt, 0, $excut );
137
			$out .= ' <a class="excerpt-read-more" href="' . get_permalink() . '" title="' . get_the_title() . '">';
138
			/**
139
			 * Filter excerpt read more text.
140 1
			 *
141
			 * @since 1.0.0
142
			 */
143 5
			$out .= apply_filters( 'geodir_max_excerpt_end', __( 'Read more [...]', 'geodirectory' ) );
144
			$out .= '</a>';
145 5
		} else {
146
			$out .= $excerpt;
147
		}
148
	}
149
	$post = $temp_post;
150
151
	return $out;
152
}
153
154
/**
155
 * Returns package information as an objects.
156
 *
157
 * @since   1.0.0
158
 * @package GeoDirectory
159
 *
160 22
 * @param array $package_info Package info array.
161 22
 * @param object|string $post The post object.
162 22
 * @param string $post_type   The post type.
163 22
 *
164 22
 * @return object Returns filtered package info as an object.
165 22
 */
166 22
function geodir_post_package_info( $package_info, $post = '', $post_type = '' ) {
167
	$package_info['pid']              = 0;
168
	$package_info['days']             = 0;
169
	$package_info['amount']           = 0;
170
	$package_info['is_featured']      = 0;
171
	$package_info['image_limit']      = '';
172
	$package_info['google_analytics'] = 1;
173
	$package_info['sendtofriend']     = 1;
174
175
	/**
176
	 * Filter listing package info.
177
	 *
178
	 * @since 1.0.0
179
	 *
180
	 * @param array $package_info  {
181
	 *                             Attributes of the package_info.
182
	 *
183
	 * @type int $pid              Package ID. Default 0.
184
	 * @type int $days             Package validity in Days. Default 0.
185
	 * @type int $amount           Package amount. Default 0.
186
	 * @type int $is_featured      Is this featured package? Default 0.
187 22
	 * @type string $image_limit   Image limit for this package. Default "".
188
	 * @type int $google_analytics Add analytics to this package. Default 1.
189
	 * @type int $sendtofriend     Send to friend. Default 1.
190
	 *
191
	 * }
192
	 * @param object|string $post  The post object.
193
	 * @param string $post_type    The post type.
194
	 */
195
	return (object) apply_filters( 'geodir_post_package_info', $package_info, $post, $post_type );
196
197
}
198
199
200
/**
201
 * Send enquiry to listing author
202
 *
203
 * This function let the user to send Enquiry to listing author. If listing author email not available, then admin
204
 * email will be used. Email content will be used WP Admin -> Geodirectory -> Notifications -> Other Emails -> Email
205
 * enquiry
206
 *
207
 * @since   1.0.0
208
 * @package GeoDirectory
209
 * @global object $wpdb    WordPress Database object.
210
 *
211
 * @param array $request   {
212
 *                         The submitted form fields as an array.
213
 *
214
 * @type string $sendact   Enquiry type. Default "send_inqury".
215 1
 * @type string $pid       Post ID.
216
 * @type string $inq_name  Sender name.
217
 * @type string $inq_email Sender mail.
218 1
 * @type string $inq_phone Sender phone.
219
 * @type string $inq_msg   Email message.
220 1
 *
221 1
 * }
222 1
 */
223 1
function geodir_send_inquiry( $request ) {
224 1
	global $wpdb;
225
226 1
	// strip slashes from text
227 1
	$request = ! empty( $request ) ? stripslashes_deep( $request ) : $request;
228
229 1
	$yourname      = $request['inq_name'];
230
	$youremail     = $request['inq_email'];
231 1
	$inq_phone     = $request['inq_phone'];
232 1
	$frnd_comments = $request['inq_msg'];
233 1
	$pid           = $request['pid'];
234 1
235 1
	$author_id  = '';
236
	$post_title = '';
237 1
238 1
	if ( $request['pid'] ) {
239 1
240
		$productinfosql = $wpdb->prepare(
241 1
			"select ID,post_author,post_title from $wpdb->posts where ID =%d",
242
			array( $request['pid'] )
243 1
		);
244 1
		$productinfo    = $wpdb->get_row( $productinfosql );
245 1
246
		$author_id  = $productinfo->post_author;
247 1
		$post_title = $productinfo->post_title;
248
	}
249
250
	$post_title = '<a href="' . get_permalink( $pid ) . '">' . $post_title . '</a>';
0 ignored issues
show
Unused Code introduced by
$post_title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
251
252
	$user_info = get_userdata( $author_id );
0 ignored issues
show
Unused Code introduced by
$user_info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
253
	$to_email  = geodir_get_post_meta( $pid, 'geodir_email', true );
254
	$to_name   = geodir_get_client_name( $author_id );
255
256
	if ( $to_email == '' ) {
257
		$to_email = get_option( 'admin_email' );
258
	}
259
260
	/**
261
	 * Called after the send enquiry var have been set but before the email has been sent.
262
	 *
263
	 * @since 1.0.0
264
	 *
265
	 * @param array $request   {
266
	 *                         The submitted form fields as an array.
267
	 *
268 1
	 * @type string $sendact   Enquiry type. Default "send_inqury".
269
	 * @type string $pid       Post ID.
270 1
	 * @type string $inq_name  Sender name.
271 1
	 * @type string $inq_email Sender mail.
272
	 * @type string $inq_phone Sender phone.
273
	 * @type string $inq_msg   Email message.
274
	 *
275
	 * }
276
	 * @param string $type     The form type, default: `Enquiry`.
277
	 */
278 1
	do_action( 'geodir_after_send_enquiry', $request, 'Enquiry' );
279
280
	$client_message = $frnd_comments;
281
	$client_message .= '<br>' . __( 'From :', 'geodirectory' ) . ' ' . $yourname . '<br>' . __( 'Phone :', 'geodirectory' ) . ' ' . $inq_phone . '<br>' . __( 'Email :', 'geodirectory' ) . ' ' . $youremail . '<br><br>' . __( 'Sent from', 'geodirectory' ) . ' - <b><a href="' . trailingslashit( home_url() ) . '">' . get_option( 'blogname' ) . '</a></b>.';
282
	/**
283
	 * Filter client message text.
284
	 *
285
	 * @since 1.0.0
286
	 *
287
	 * @param string $client_message Client message text.
288
	 */
289
	$client_message = apply_filters( 'geodir_inquiry_email_msg', $client_message );
290
291
	/**
292
	 * Called before the send enquiry email is sent.
293
	 *
294
	 * @since 1.0.0
295
	 *
296 1
	 * @param array $request   {
297 1
	 *                         The submitted form fields as an array.
298
	 *
299 1
	 * @type string $sendact   Enquiry type. Default "send_inqury".
300
	 * @type string $pid       Post ID.
301 1
	 * @type string $inq_name  Sender name.
302 1
	 * @type string $inq_email Sender mail.
303
	 * @type string $inq_phone Sender phone.
304
	 * @type string $inq_msg   Email message.
305
	 *
306
	 * }
307
	 */
308
	do_action( 'geodir_before_send_enquiry_email', $request );
309
	if ( $to_email ) {
310
		// strip slashes message
311
		$client_message = stripslashes_deep( $client_message );
312
313
		geodir_sendEmail( $youremail, $yourname, $to_email, $to_name, '', $client_message, $extra = '', 'send_enquiry', $request['pid'] );//To client email
314
	}
315
316
	/**
317
	 * Called after the send enquiry email is sent.
318
	 *
319
	 * @since 1.0.0
320 1
	 *
321 1
	 * @param array $request   {
322 1
	 *                         The submitted form fields as an array.
323 1
	 *
324 1
	 * @type string $sendact   Enquiry type. Default "send_inqury".
325
	 * @type string $pid       Post ID.
326
	 * @type string $inq_name  Sender name.
327
	 * @type string $inq_email Sender mail.
328
	 * @type string $inq_phone Sender phone.
329
	 * @type string $inq_msg   Email message.
330
	 *
331
	 * }
332
	 */
333 1
	do_action( 'geodir_after_send_enquiry_email', $request );
334 1
	$url = get_permalink( $pid );
335 1 View Code Duplication
	if ( strstr( $url, '?' ) ) {
336
		$url = $url . "&send_inquiry=success";
337 1
	} else {
338
		$url = $url . "?send_inquiry=success";
339
	}
340
	/**
341
	 * Filter redirect url after the send enquiry email is sent.
342
	 *
343
	 * @since 1.0.0
344
	 *
345
	 * @param string $url Redirect url.
346
	 */
347
	$url = apply_filters( 'geodir_send_enquiry_after_submit_redirect', $url );
348
	wp_redirect( $url );
349
	gd_die();
350
351
}
352
353
/**
354
 * Send Email to a friend.
355
 *
356
 * This function let the user to send Email to a friend.
357
 * Email content will be used WP Admin -> Geodirectory -> Notifications -> Other Emails -> Send to friend
358
 *
359
 * @since   1.0.0
360
 * @package GeoDirectory
361
 *
362
 * @param array $request       {
363
 *                             The submitted form fields as an array.
364 1
 *
365
 * @type string $sendact       Enquiry type. Default "email_frnd".
366
 * @type string $pid           Post ID.
367 1
 * @type string $to_name       Friend name.
368
 * @type string $to_email      Friend email.
369 1
 * @type string $yourname      Sender name.
370 1
 * @type string $youremail     Sender email.
371 1
 * @type string $frnd_subject  Email subject.
372 1
 * @type string $frnd_comments Email Message.
373 1
 *
374 1
 * }
375 1
 * @global object $wpdb        WordPress Database object.
376 1
 */
377 1
function geodir_send_friend( $request ) {
378 1
	global $wpdb;
379 1
380 1
	// strip slashes from text
381 1
	$request = ! empty( $request ) ? stripslashes_deep( $request ) : $request;
382 1
383 1
	$yourname      = $request['yourname'];
384 1
	$youremail     = $request['youremail'];
385 1
	$frnd_subject  = $request['frnd_subject'];
386
	$frnd_comments = $request['frnd_comments'];
387
	$pid           = $request['pid'];
388
	$to_email      = $request['to_email'];
389
	$to_name       = $request['to_name'];
390
	if ( $request['pid'] ) {
391
		$productinfosql = $wpdb->prepare(
392
			"select ID,post_title from $wpdb->posts where ID =%d",
393
			array( $request['pid'] )
394
		);
395
		$productinfo    = $wpdb->get_results( $productinfosql );
396
		foreach ( $productinfo as $productinfoObj ) {
397
			$post_title = $productinfoObj->post_title;
0 ignored issues
show
Unused Code introduced by
$post_title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
398
		}
399
	}
400
401
	/**
402
	 * Called before the send to friend email is sent.
403
	 *
404
	 * @since 1.0.0
405 1
	 *
406 1
	 * @param array $request       {
407
	 *                             The submitted form fields as an array.
408
	 *
409
	 * @type string $sendact       Enquiry type. Default "email_frnd".
410
	 * @type string $pid           Post ID.
411
	 * @type string $to_name       Friend name.
412
	 * @type string $to_email      Friend email.
413
	 * @type string $yourname      Sender name.
414
	 * @type string $youremail     Sender email.
415
	 * @type string $frnd_subject  Email subject.
416
	 * @type string $frnd_comments Email Message.
417
	 *
418
	 * }
419
	 */
420
	do_action( 'geodir_before_send_to_friend_email', $request );
421
	geodir_sendEmail( $youremail, $yourname, $to_email, $to_name, $frnd_subject, $frnd_comments, $extra = '', 'send_friend', $request['pid'] );//To client email
422
423
	/**
424
	 * Called after the send to friend email is sent.
425
	 *
426 1
	 * @since 1.0.0
427
	 *
428 1
	 * @param array $request       {
429 1
	 *                             The submitted form fields as an array.
430 1
	 *
431 1
	 * @type string $sendact       Enquiry type. Default "email_frnd".
432
	 * @type string $pid           Post ID.
433
	 * @type string $to_name       Friend name.
434
	 * @type string $to_email      Friend email.
435
	 * @type string $yourname      Sender name.
436
	 * @type string $youremail     Sender email.
437
	 * @type string $frnd_subject  Email subject.
438
	 * @type string $frnd_comments Email Message.
439
	 *
440 1
	 * }
441 1
	 */
442 1
	do_action( 'geodir_after_send_to_friend_email', $request );
443 1
444
	$url = get_permalink( $pid );
445 View Code Duplication
	if ( strstr( $url, '?' ) ) {
446
		$url = $url . "&sendtofrnd=success";
447
	} else {
448
		$url = $url . "?sendtofrnd=success";
449
	}
450
	/**
451
	 * Filter redirect url after the send to friend email is sent.
452
	 *
453
	 * @since 1.0.0
454
	 *
455
	 * @param string $url Redirect url.
456
	 */
457 2
	$url = apply_filters( 'geodir_send_to_friend_after_submit_redirect', $url );
458
	wp_redirect( $url );
459
	gd_die();
460 2
}
461
462
/**
463
 * Adds open div before the tab content.
464
 *
465
 * This function adds open div before the tab content like post information, post images, reviews etc.
466
 *
467
 * @since   1.0.0
468 2
 * @package GeoDirectory
469 1
 *
470 1
 * @param string $hash_key
471 2
 */
472
function geodir_before_tab_content( $hash_key ) {
473
	switch ( $hash_key ) {
474 2
		case 'post_info' :
475 1
			echo '<div class="geodir-company_info field-group">';
476 1
			break;
477
		case 'post_images' :
478 2
			/**
479
			 * Filter post gallery HTML id.
480
			 *
481
			 * @since 1.0.0
482
			 */
483
			echo ' <div id="' . apply_filters( 'geodir_post_gallery_id', 'geodir-post-gallery' ) . '" class="clearfix" >';
484
			break;
485
		case 'reviews' :
486
			echo '<div id="reviews-wrap" class="clearfix"> ';
487
			break;
488
		case 'post_video':
489
			echo ' <div id="post_video-wrap" class="clearfix">';
490
			break;
491
		case 'special_offers':
492 2
			echo '<div id="special_offers-wrap" class="clearfix">';
493
			break;
494
	}
495 2
}
496
497
/**
498 2
 * Adds closing div after the tab content.
499 1
 *
500 1
 * This function adds closing div after the tab content like post information, post images, reviews etc.
501 2
 *
502
 * @since   1.0.0
503
 * @package GeoDirectory
504 2
 *
505 1
 * @param string $hash_key
506 1
 */
507
function geodir_after_tab_content( $hash_key ) {
508 2
	switch ( $hash_key ) {
509
		case 'post_info' :
510
			echo '</div>';
511
			break;
512
		case 'post_images' :
513
			echo '</div>';
514
			break;
515
		case 'reviews' :
516
			echo '</div>';
517
			break;
518
		case 'post_video':
519
			echo '</div>';
520
			break;
521
		case 'special_offers':
522
			echo '</div>';
523
			break;
524
	}
525
}
526
527
528
/**
529
 * Returns default sorting order of a post type.
530
 *
531
 * @since   1.0.0
532
 * @package GeoDirectory
533
 *
534
 * @param string $post_type The post type.
535
 *
536
 * @global object $wpdb     WordPress Database object.
537
 * @return bool|null|string Returns default sort results, when the post type is valid. Otherwise returns false.
538
 */
539 View Code Duplication
function geodir_get_posts_default_sort( $post_type ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
540
541
	global $wpdb;
542
543
	if ( $post_type != '' ) {
544
545
		$all_postypes = geodir_get_posttypes();
546
547
		if ( ! in_array( $post_type, $all_postypes ) ) {
548
			return false;
549
		}
550
551
		$sort_field_info = $wpdb->get_var( $wpdb->prepare( "select default_order from " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " where	post_type= %s and is_active=%d and is_default=%d", array(
552 1
			$post_type,
553
			1,
554 1
			1
555 1
		) ) );
556
557 1
		if ( ! empty( $sort_field_info ) ) {
558 1
			return $sort_field_info;
559
		}
560 1
561
	}
562
563
}
564
565
566
/**
567
 * Returns sort options of a post type.
568 1
 *
569
 * @since   1.0.0
570
 * @package GeoDirectory
571
 *
572
 * @param string $post_type The post type.
573
 *
574
 * @global object $wpdb     WordPress Database object.
575
 * @return bool|mixed|void Returns sort results, when the post type is valid. Otherwise returns false.
576
 */
577 View Code Duplication
function geodir_get_sort_options( $post_type ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
578
	global $wpdb;
579
580
	if ( $post_type != '' ) {
581
		$all_postypes = geodir_get_posttypes();
582
583 2
		if ( ! in_array( $post_type, $all_postypes ) ) {
584
			return false;
585
		}
586
587
		$sort_field_info = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " WHERE post_type=%s AND is_active=%d AND (sort_asc=1 || sort_desc=1 || field_type='random') AND field_type != 'address' ORDER BY sort_order ASC", array(
588
			$post_type,
589
			1
590 2
		) ) );
591 1
592
		/**
593
		 * Filter post sort options.
594 1
		 *
595
		 * @since 1.0.0
596 1
		 *
597
		 * @param array $sort_field_info Unfiltered sort field array.
598 1
		 * @param string $post_type      Post type.
599
		 */
600 1
		return apply_filters( 'geodir_get_sort_options', $sort_field_info, $post_type );
601
	}
602
603 1
}
604
605 1
606
/**
607
 * Display list of sort options available in front end using dropdown.
608
 *
609
 * @since   1.0.0
610
 * @package GeoDirectory
611
 * @global object $wp_query WordPress Query object.
612
 */
613
function geodir_display_sort_options() {
614
	global $wp_query;
615
616
	/**
617
	 * On search pages there should be no sort options, sorting is done by search criteria.
618
	 *
619
	 * @since 1.4.4
620
	 */
621
	if ( is_search() ) {
622
		return;
623
	}
624
625
	$sort_by = '';
626
627
	if ( isset( $_REQUEST['sort_by'] ) ) {
628
		$sort_by = $_REQUEST['sort_by'];
629
	}
630
631
	$gd_post_type = geodir_get_current_posttype();
632
633
	$sort_options = geodir_get_sort_options( $gd_post_type );
634
635
636
	$sort_field_options = '';
637
638
	if ( ! empty( $sort_options ) ) {
639
		foreach ( $sort_options as $sort ) {
640
			$sort = stripslashes_deep( $sort ); // strip slashes
641
642 1
			$label = __( $sort->site_title, 'geodirectory' );
643
644
			if ( $sort->field_type == 'random' ) {
645
				$key = $sort->field_type;
646
				( $sort_by == $key || ( $sort->is_default == '1' && ! isset( $_REQUEST['sort_by'] ) ) ) ? $selected = 'selected="selected"' : $selected = '';
647
				$sort_field_options .= '<option ' . $selected . ' value="' . esc_url( add_query_arg( 'sort_by', $key ) ) . '">' . __( $label, 'geodirectory' ) . '</option>';
648
			}
649
650
			if ( $sort->htmlvar_name == 'comment_count' ) {
651
				$sort->htmlvar_name = 'rating_count';
652
			}
653
654 View Code Duplication
			if ( $sort->sort_asc ) {
655
				$key   = $sort->htmlvar_name . '_asc';
656
				$label = $sort->site_title;
657
				if ( $sort->asc_title ) {
658
					$label = $sort->asc_title;
659
				}
660
				( $sort_by == $key || ( $sort->is_default == '1' && $sort->default_order == $key && ! isset( $_REQUEST['sort_by'] ) ) ) ? $selected = 'selected="selected"' : $selected = '';
661
				$sort_field_options .= '<option ' . $selected . ' value="' . esc_url( add_query_arg( 'sort_by', $key ) ) . '">' . __( $label, 'geodirectory' ) . '</option>';
662 1
			}
663
664 View Code Duplication
			if ( $sort->sort_desc ) {
665
				$key   = $sort->htmlvar_name . '_desc';
666
				$label = $sort->site_title;
667
				if ( $sort->desc_title ) {
668
					$label = $sort->desc_title;
669
				}
670
				( $sort_by == $key || ( $sort->is_default == '1' && $sort->default_order == $key && ! isset( $_REQUEST['sort_by'] ) ) ) ? $selected = 'selected="selected"' : $selected = '';
671
				$sort_field_options .= '<option ' . $selected . ' value="' . esc_url( add_query_arg( 'sort_by', $key ) ) . '">' . __( $label, 'geodirectory' ) . '</option>';
672
			}
673
674
		}
675
	}
676
677
	if ( $sort_field_options != '' ) {
678
679
		?>
680 2
681 1
		<div class="geodir-tax-sort">
682 1
683 2
			<select name="sort_by" id="sort_by" onchange="javascript:window.location=this.value;">
684
685
				<option
686
					value="<?php echo esc_url( add_query_arg( 'sort_by', '' ) ); ?>" <?php if ( $sort_by == '' ) {
687
					echo 'selected="selected"';
688
				} ?>><?php _e( 'Sort By', 'geodirectory' ); ?></option><?php
689
690
				echo $sort_field_options; ?>
691
692
			</select>
693
694
		</div>
695
		<?php
696
697
	}
698
699
}
700 3
701 3
702 3
/**
703
 * Removes the section title
704 3
 *
705 3
 * Removes the section title "Posts sort options", if the custom field type is multiselect or textarea or taxonomy.
706 3
 * Can be found here. WP Admin -> Geodirectory -> Place settings -> Custom fields
707 3
 *
708 3
 * @since   1.0.0
709 3
 * @package GeoDirectory
710 3
 *
711 3
 * @param string $title      The section title.
712
 * @param string $field_type The field type.
713 3
 *
714 3
 * @return string Returns the section title.
715 3
 */
716 3
function geodir_advance_customfields_heading( $title, $field_type ) {
717
718 3
	if ( in_array( $field_type, array( 'multiselect', 'textarea', 'taxonomy' ) ) ) {
719 3
		$title = '';
720 3
	}
721 3
722 3
	return $title;
723 3
}
724
725 3
726 3
/**
727 3
 * Returns related listings of a listing.
728 3
 *
729 3
 * @since   1.0.0
730 3
 * @package GeoDirectory
731 3
 *
732
 * @param array $request            Related posts request array.
733 3
 *
734
 * @global object $wpdb             WordPress Database object.
735
 * @global object $post             The current post object.
736
 * @global string $gridview_columns The girdview style of the listings.
737
 * @global object $gd_session       GeoDirectory Session object.
738 3
 * @return string Returns related posts html.
739 2
 */
740 2
function geodir_related_posts_display( $request ) {
741 2
	if ( ! empty( $request ) ) {
742 3
		$before_title = ( isset( $request['before_title'] ) && ! empty( $request['before_title'] ) ) ? $request['before_title'] : '';
743 1
		$after_title  = ( isset( $request['after_title'] ) && ! empty( $request['after_title'] ) ) ? $request['after_title'] : '';
744 1
745 1
		$title               = ( isset( $request['title'] ) && ! empty( $request['title'] ) ) ? $request['title'] : __( 'Related Listings', 'geodirectory' );
746
		$post_number         = ( isset( $request['post_number'] ) && ! empty( $request['post_number'] ) ) ? $request['post_number'] : '5';
747 3
		$relate_to           = ( isset( $request['relate_to'] ) && ! empty( $request['relate_to'] ) ) ? $request['relate_to'] : 'category';
748
		$layout              = ( isset( $request['layout'] ) && ! empty( $request['layout'] ) ) ? $request['layout'] : 'gridview_onehalf';
749 3
		$add_location_filter = ( isset( $request['add_location_filter'] ) && ! empty( $request['add_location_filter'] ) ) ? $request['add_location_filter'] : '0';
750 3
		$listing_width       = ( isset( $request['listing_width'] ) && ! empty( $request['listing_width'] ) ) ? $request['listing_width'] : '';
751 3
		$list_sort           = ( isset( $request['list_sort'] ) && ! empty( $request['list_sort'] ) ) ? $request['list_sort'] : 'latest';
752
		$character_count     = ( isset( $request['character_count'] ) && ! empty( $request['character_count'] ) ) ? $request['character_count'] : '';
753 3
754
		global $wpdb, $post, $gd_session, $related_nearest, $related_parent_lat, $related_parent_lon;
755
		$related_parent_lat   = !empty($post->post_latitude) ? $post->post_latitude : '';
756
		$related_parent_lon   = !empty($post->post_longitude) ? $post->post_longitude : '';
757
		$arr_detail_page_tabs = geodir_detail_page_tabs_list();
758
759
		$related_listing_array = array();
760
		if ( get_option( 'geodir_add_related_listing_posttypes' ) ) {
761
			$related_listing_array = get_option( 'geodir_add_related_listing_posttypes' );
762 3
		}
763 3
		if ( isset($post->post_type) && in_array( $post->post_type, $related_listing_array ) ) {
764
			$arr_detail_page_tabs['related_listing']['is_display'] = true;
765 3
		}
766
767 3
		$is_display        = $arr_detail_page_tabs['related_listing']['is_display'];
768 3
		$origi_post        = $post;
769
		$post_type         = '';
770
		$post_id           = '';
771
		$category_taxonomy = '';
772 3
		$tax_field         = 'id';
773 3
		$category          = array();
774
775
		if ( isset( $_REQUEST['backandedit'] ) ) {
776
			$post      = (object) $gd_session->get( 'listing' );
777
			$post_type = $post->listing_type;
778
			if ( isset( $_REQUEST['pid'] ) && $_REQUEST['pid'] != '' ) {
779
				$post_id = $_REQUEST['pid'];
780
			}
781 View Code Duplication
		} elseif ( isset( $_REQUEST['pid'] ) && $_REQUEST['pid'] != '' ) {
782
			$post      = geodir_get_post_info( $_REQUEST['pid'] );
783
			$post_type = $post->post_type;
784
			$post_id   = $_REQUEST['pid'];
785
		} elseif ( isset( $post->post_type ) && $post->post_type != '' ) {
786
			$post_type = $post->post_type;
787
			$post_id   = $post->ID;
788
		}
789
790
		if ( $relate_to == 'category' ) {
791
792
			$category_taxonomy = $post_type . $relate_to;
793
			if ( isset( $post->{$category_taxonomy} ) && $post->{$category_taxonomy} != '' ) {
794
				$category = explode( ',', trim( $post->{$category_taxonomy}, ',' ) );
795
			}
796
797
		} elseif ( $relate_to == 'tags' ) {
798
799
			$category_taxonomy = $post_type . '_' . $relate_to;
800
			if ( $post->post_tags != '' ) {
801
				$category = explode( ',', trim( $post->post_tags, ',' ) );
802
			}
803
			$tax_field = 'name';
804
		}
805 3
806 3
		/* --- return false in invalid request --- */
807 3
		if ( empty( $category ) ) {
808 3
			return false;
809
		}
810
811 3
		$all_postypes = geodir_get_posttypes();
812 3
813 3
		if ( ! in_array( $post_type, $all_postypes ) ) {
814 3
			return false;
815
		}
816
817
		/* --- return false in invalid request --- */
818
819
		$location_url = '';
820
		if ( $add_location_filter != '0' ) {
821 3
			$location_url             = array();
822
			$geodir_show_location_url = get_option( 'geodir_show_location_url' );
823 2
824
			$gd_city = get_query_var( 'gd_city' );
825 2
826
			if ( $gd_city ) {
827
				$gd_country = get_query_var( 'gd_country' );
828
				$gd_region  = get_query_var( 'gd_region' );
829
			} else {
830
				$location = geodir_get_default_location();
831 2
832
				$gd_country = isset( $location->country_slug ) ? $location->country_slug : '';
833 3
				$gd_region  = isset( $location->region_slug ) ? $location->region_slug : '';
834 3
				$gd_city    = isset( $location->city_slug ) ? $location->city_slug : '';
835 3
			}
836 3
837 3
			if ( $geodir_show_location_url == 'all' ) {
838 3
				$location_url[] = $gd_country;
839 3
				$location_url[] = $gd_region;
840
			} else if ( $geodir_show_location_url == 'country_city' ) {
841 3
				$location_url[] = $gd_country;
842
			} else if ( $geodir_show_location_url == 'region_city' ) {
843 3
				$location_url[] = $gd_region;
844 3
			}
845
846 3
			$location_url[] = $gd_city;
847
848 3
			$location_url = implode( '/', $location_url );
849
		}
850
851 3
852
		if ( ! empty( $category ) ) {
853
			global $geodir_add_location_url;
854 3
			$geodir_add_location_url = '0';
855
			if ( $add_location_filter != '0' ) {
856 3
				$geodir_add_location_url = '1';
857 3
			}
858 3
			$viewall_url             = get_term_link( (int) $category[0], $post_type . $category_taxonomy );
859 3
			$geodir_add_location_url = null;
860 3
		}
861
		ob_start();
862
		?>
863 3
864
865 3
		<div class="geodir_locations geodir_location_listing">
866 3
867
			<?php
868
			if ( isset( $request['is_widget'] ) && $request['is_widget'] == '1' ) {
869
				/** geodir_before_title filter Documented in geodirectory_widgets.php */
870
				$before_title = isset( $before_title ) ? $before_title : apply_filters( 'geodir_before_title', '<h3 class="widget-title">' );
871
				/** geodir_after_title filter Documented in geodirectory_widgets.php */
872
				$after_title = isset( $after_title ) ? $after_title : apply_filters( 'geodir_after_title', '</h3>' );
873
				?>
874
				<div class="location_list_heading clearfix">
875
					<?php echo $before_title . $title . $after_title; ?>
876 3
				</div>
877
				<?php
878
			}
879
			$query_args = array(
880
				'posts_per_page'   => $post_number,
881
				'is_geodir_loop'   => true,
882
				'gd_location'      => ( $add_location_filter ) ? true : false,
883 3
				'post_type'        => $post_type,
884
				'order_by'         => $list_sort,
885 3
				'post__not_in'     => array( $post_id ),
886 3
				'excerpt_length'   => $character_count,
887 3
				'related_listings' => $is_display
888
			);
889
890
			$tax_query = array(
891
				'taxonomy' => $category_taxonomy,
892 3
				'field'    => $tax_field,
893
				'terms'    => $category
894
			);
895
896
			$query_args['tax_query'] = array( $tax_query );
897
898
			global $gridview_columns, $post;
899
900
			/**
901
			 * Filters related listing query args.
902
			 *
903
			 * @since 1.6.11
904
			 *
905
			 * @param array $query_args The query array.
906
			 * @param array $request Related posts request array.
907
			 */
908
			$query_args = apply_filters( 'geodir_related_posts_widget_query_args', $query_args, $request );
909
910
			query_posts( $query_args );
911
912 View Code Duplication
			if ( strstr( $layout, 'gridview' ) ) {
913
				$listing_view_exp = explode( '_', $layout );
914
				$gridview_columns = $layout;
915
				$layout           = $listing_view_exp[0];
916
			} else if ( $layout == 'list' ) {
917
				$gridview_columns = '';
918
			}
919
			$related_posts = true;
920
921
			$related_nearest = false;
922
			if ( $list_sort == 'nearest' ) {
923
				$related_nearest = true;
924
			}
925
926
927
			/**
928
			 * Filters related listing listview template.
929
			 *
930
			 * @since 1.0.0
931
			 */
932
			$template = apply_filters( "geodir_template_part-related-listing-listview", geodir_locate_template( 'listing-listview' ) );
933 7
934 7
			/**
935 7
			 * Includes related listing listview template.
936
			 *
937
			 * @since 1.0.0
938
			 */
939
			include( $template );
940
941
			wp_reset_query();
942 7
			$post            = $origi_post;
943
			$related_nearest = false;
944
			?>
945
946
		</div>
947
		<?php
948
		return $html = ob_get_clean();
0 ignored issues
show
Unused Code introduced by
$html is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
949
950
	}
951
952
}
953
954 8
955
//add_action('wp_footer', 'geodir_category_count_script', 10);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
956
/**
957
 * Adds the category post count javascript code
958
 *
959
 * @since       1.0.0
960
 * @package     GeoDirectory
961 8
 * @global string $geodir_post_category_str The geodirectory post category.
962
 * @depreciated No longer needed.
963
 */
964
function geodir_category_count_script() {
965
	global $geodir_post_category_str;
966
967
	if ( ! empty( $geodir_post_category_str ) ) {
968
		$geodir_post_category_str = serialize( $geodir_post_category_str );
969
	}
970
971
	$all_var['post_category_array'] = html_entity_decode( (string) $geodir_post_category_str, ENT_QUOTES, 'UTF-8' );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$all_var was never initialized. Although not strictly required by PHP, it is generally a good practice to add $all_var = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
972
	$script                         = "var post_category_array = " . json_encode( $all_var ) . ';';
973
	echo '<script>';
974
	echo $script;
975
	echo '</script>';
976
977
}
978 7
979
/**
980 7
 * Returns the default language of the map.
981 7
 *
982 7
 * @since   1.0.0
983
 * @package GeoDirectory
984
 * @return string Returns the default language.
985
 */
986
function geodir_get_map_default_language() {
987
	$geodir_default_map_language = get_option( 'geodir_default_map_language' );
988
	if ( empty( $geodir_default_map_language ) ) {
989
		$geodir_default_map_language = 'en';
990
	}
991
992
	/**
993
	 * Filter default map language.
994
	 *
995
	 * @since 1.0.0
996
	 *
997
	 * @param string $geodir_default_map_language Default map language.
998
	 */
999
	return apply_filters( 'geodir_default_map_language', $geodir_default_map_language );
1000
}
1001
1002
/**
1003
 * Returns the Google maps api key.
1004
 *
1005
 * @since   1.6.4
1006
 * @package GeoDirectory
1007
 * @return string Returns the api key.
1008
 */
1009
function geodir_get_map_api_key() {
1010
	$key = get_option( 'geodir_google_api_key' );
1011
1012
	/**
1013
	 * Filter Google maps api key.
1014
	 *
1015
	 * @since 1.6.4
1016
	 *
1017
	 * @param string $key Google maps api key.
1018
	 */
1019
	return apply_filters( 'geodir_google_api_key', $key );
1020
}
1021
1022
1023
/**
1024
 * Adds meta keywords and description for SEO.
1025
 *
1026
 * @since   1.0.0
1027
 * @since   1.5.4 Modified to replace %location% from meta when Yoast SEO plugin active.
1028
 * @package GeoDirectory
1029
 * @global object $wpdb             WordPress Database object.
1030
 * @global object $post             The current post object.
1031
 * @global object $wp_query         WordPress Query object.
1032
 * @global array $geodir_addon_list List of active GeoDirectory extensions.
1033
 */
1034
function geodir_add_meta_keywords() {
1035
	global $wp, $post, $wp_query, $wpdb, $geodir_addon_list;
1036
1037
	$is_geodir_page = geodir_is_geodir_page();
1038
	if ( ! $is_geodir_page ) {
1039
		return;
1040
	}// if non GD page, bail
1041
1042
	$use_gd_meta = true;
1043
	if ( class_exists( 'WPSEO_Frontend' ) || class_exists( 'All_in_One_SEO_Pack' ) ) {
1044
		$use_gd_meta = false;
1045
1046
		if ( geodir_is_page( 'search' ) ) {
1047
			$use_gd_meta = true;
1048
		}
1049
	}
1050
1051
	if ( ! $use_gd_meta ) {
1052
		return;
1053
	}// bail if Yoast Wordpress SEO or All_in_One_SEO_Pack active.
1054
1055
	$current_term = $wp_query->get_queried_object();
1056
1057
	$all_postypes = geodir_get_posttypes();
1058
1059
	$geodir_taxonomies = geodir_get_taxonomies( '', true );
1060
1061
	$meta_desc = '';
1062
	$meta_key  = '';
1063
	if ( isset( $current_term->ID ) && $current_term->ID == geodir_location_page_id() ) {
1064
		/**
1065
		 * Filter SEO meta location description.
1066
		 *
1067
		 * @since 1.0.0
1068
		 */
1069
		$meta_desc = apply_filters( 'geodir_seo_meta_location_description', '' );
1070
		$meta_desc .= '';
1071
	}
1072
	if ( have_posts() && is_single() OR is_page() ) {
1073
		while ( have_posts() ) {
1074
			the_post();
1075
1076
			if ( has_excerpt() ) {
1077
				$out_excerpt = strip_tags( strip_shortcodes( get_the_excerpt() ) );
1078
				if ( empty( $out_excerpt ) ) {
1079
					$out_excerpt = strip_tags( do_shortcode( get_the_excerpt() ) );
1080
				}
1081
				$out_excerpt = str_replace( array( "\r\n", "\r", "\n" ), "", $out_excerpt );
1082
			} else {
1083
				$out_excerpt = str_replace( array( "\r\n", "\r", "\n" ), "", $post->post_content );
1084
				$out_excerpt = strip_tags( strip_shortcodes( $out_excerpt ) );
1085
				if ( empty( $out_excerpt ) ) {
1086
					$out_excerpt = strip_tags( do_shortcode( $out_excerpt ) ); // parse short code from content
1087
				}
1088
				$out_excerpt = trim( wp_trim_words( $out_excerpt, 35, '' ), '.!?,;:-' );
1089
			}
1090
1091
			$meta_desc .= $out_excerpt;
1092
		}
1093
	} elseif ( ( is_category() || is_tag() ) && isset( $current_term->taxonomy ) && in_array( $current_term->taxonomy, $geodir_taxonomies ) ) {
1094
		if ( is_category() ) {
1095
			$meta_desc .= __( "Posts related to Category:", 'geodirectory' ) . " " . ucfirst( single_cat_title( "", false ) );
1096
		} elseif ( is_tag() ) {
1097
			$meta_desc .= __( "Posts related to Tag:", 'geodirectory' ) . " " . ucfirst( single_tag_title( "", false ) );
1098
		}
1099
	} elseif ( isset( $current_term->taxonomy ) && in_array( $current_term->taxonomy, $geodir_taxonomies ) ) {
1100
		$meta_desc .= isset( $current_term->description ) ? $current_term->description : '';
1101
	}
1102
1103
1104
	$geodir_post_type       = geodir_get_current_posttype();
1105
	$geodir_post_type_info  = get_post_type_object( $geodir_post_type );
1106
	$geodir_is_page_listing = geodir_is_page( 'listing' ) ? true : false;
1107
1108
	$category_taxonomy = geodir_get_taxonomies( $geodir_post_type );
1109
	$tag_taxonomy      = geodir_get_taxonomies( $geodir_post_type, true );
1110
1111
	$geodir_is_category = isset( $category_taxonomy[0] ) && get_query_var( $category_taxonomy[0] ) ? get_query_var( $category_taxonomy[0] ) : false;
1112
	$geodir_is_tag      = isset( $tag_taxonomy[0] ) && get_query_var( $tag_taxonomy[0] ) ? true : false;
1113
1114
	$geodir_is_search        = geodir_is_page( 'search' ) ? true : false;
1115
	$geodir_is_location      = geodir_is_page( 'location' ) ? true : false;
0 ignored issues
show
Unused Code introduced by
$geodir_is_location is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1116
	$geodir_location_manager = isset( $geodir_addon_list['geodir_location_manager'] ) && $geodir_addon_list['geodir_location_manager'] = 'yes' ? true : false;
1117
	$godir_location_terms    = geodir_get_current_location_terms( 'query_vars' );
1118
	$gd_city                 = $geodir_location_manager && isset( $godir_location_terms['gd_city'] ) ? $godir_location_terms['gd_city'] : null;
1119
	$gd_region               = $geodir_location_manager && isset( $godir_location_terms['gd_region'] ) ? $godir_location_terms['gd_region'] : null;
0 ignored issues
show
Unused Code introduced by
$gd_region is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1120
	$gd_country              = $geodir_location_manager && isset( $godir_location_terms['gd_country'] ) ? $godir_location_terms['gd_country'] : null;
0 ignored issues
show
Unused Code introduced by
$gd_country is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1121
	$replace_location        = __( 'Everywhere', 'geodirectory' );
1122
	$location_id             = null;
1123
	if ( $geodir_location_manager ) {
1124
		$sql           = $wpdb->prepare( "SELECT location_id FROM " . POST_LOCATION_TABLE . " WHERE city_slug=%s ORDER BY location_id ASC LIMIT 1", array( $gd_city ) );
1125
		$location_id   = (int) $wpdb->get_var( $sql );
1126
		$location_type = geodir_what_is_current_location();
1127
		if ( $location_type == 'city' ) {
1128
			$replace_location = geodir_get_current_location( array( 'what' => 'city', 'echo' => false ) );
1129
		} elseif ( $location_type == 'region' ) {
1130
			$replace_location = geodir_get_current_location( array( 'what' => 'region', 'echo' => false ) );
1131
		} elseif ( $location_type == 'country' ) {
1132
			$replace_location = geodir_get_current_location( array( 'what' => 'country', 'echo' => false ) );
1133
			$replace_location = __( $replace_location, 'geodirectory' );
1134
		}
1135
		$country          = get_query_var( 'gd_country' );
1136
		$region           = get_query_var( 'gd_region' );
1137
		$city             = get_query_var( 'gd_city' );
1138
		$current_location = '';
1139
		if ( $country != '' ) {
1140
			$current_location = get_actual_location_name( 'country', $country, true );
1141
		}
1142
		if ( $region != '' ) {
1143
			$current_location = get_actual_location_name( 'region', $region );
1144
		}
1145
		if ( $city != '' ) {
1146
			$current_location = get_actual_location_name( 'city', $city );
1147
		}
1148
		$replace_location = $current_location != '' ? $current_location : $replace_location;
1149
	}
1150
1151
	$geodir_meta_keys = '';
1152
	$geodir_meta_desc = '';
1153
	if ( $is_geodir_page && ! empty( $geodir_post_type_info ) ) {
1154
		if ( $geodir_is_page_listing || $geodir_is_search || geodir_is_page( 'add-listing' ) ) {
1155
			$geodir_meta_keys = isset( $geodir_post_type_info->seo['meta_keyword'] ) && $geodir_post_type_info->seo['meta_keyword'] != '' ? $geodir_post_type_info->seo['meta_keyword'] : $geodir_meta_keys;
1156
1157
			$geodir_meta_desc = isset( $geodir_post_type_info->description ) ? $geodir_post_type_info->description : $geodir_meta_desc;
1158
			$geodir_meta_desc = isset( $geodir_post_type_info->seo['meta_description'] ) && $geodir_post_type_info->seo['meta_description'] != '' ? $geodir_post_type_info->seo['meta_description'] : $geodir_meta_desc;
1159
1160
			if ( $geodir_is_category ) {
1161
				$category = $geodir_is_category ? get_term_by( 'slug', $geodir_is_category, $category_taxonomy[0] ) : null;
1162
				if ( isset( $category->term_id ) && ! empty( $category->term_id ) ) {
1163
					$category_id   = $category->term_id;
1164
					$category_desc = trim( $category->description ) != '' ? trim( $category->description ) : get_tax_meta( $category_id, 'ct_cat_top_desc', false, $geodir_post_type );
1165
					if ( $location_id ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $location_id of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
1166
						$option_name    = 'geodir_cat_loc_' . $geodir_post_type . '_' . $category_id;
1167
						$cat_loc_option = get_option( $option_name );
1168
1169
						$gd_cat_loc_default = ! empty( $cat_loc_option ) && isset( $cat_loc_option['gd_cat_loc_default'] ) && $cat_loc_option['gd_cat_loc_default'] > 0 ? true : false;
1170
						if ( ! $gd_cat_loc_default ) {
1171
							$option_name   = 'geodir_cat_loc_' . $geodir_post_type . '_' . $category_id . '_' . $location_id;
1172
							$option        = get_option( $option_name );
1173
							$category_desc = isset( $option['gd_cat_loc_desc'] ) && trim( $option['gd_cat_loc_desc'] ) != '' ? trim( $option['gd_cat_loc_desc'] ) : $category_desc;
1174
						}
1175
					}
1176
					$geodir_meta_desc = __( "Posts related to Category:", 'geodirectory' ) . " " . ucfirst( single_cat_title( "", false ) ) . '. ' . $category_desc;
0 ignored issues
show
Unused Code introduced by
$geodir_meta_desc is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1177
				}
1178
			} else if ( $geodir_is_tag ) {
1179
				$geodir_meta_desc = __( "Posts related to Tag:", 'geodirectory' ) . " " . ucfirst( single_tag_title( "", false ) ) . '. ' . $geodir_meta_desc;
0 ignored issues
show
Unused Code introduced by
$geodir_meta_desc is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1180
			}
1181
		}
1182
	}
1183
1184
1185
	$gd_page = '';
1186 View Code Duplication
	if ( geodir_is_page( 'home' ) ) {
1187
		$gd_page   = 'home';
1188
		$meta_desc = ( get_option( 'geodir_meta_desc_homepage' ) ) ? get_option( 'geodir_meta_desc_homepage' ) : $meta_desc;
1189
	} elseif ( geodir_is_page( 'detail' ) ) {
1190
		$gd_page   = 'detail';
1191
		$meta_desc = ( get_option( 'geodir_meta_desc_detail' ) ) ? get_option( 'geodir_meta_desc_detail' ) : $meta_desc;
1192
	} elseif ( geodir_is_page( 'pt' ) ) {
1193
		$gd_page   = 'pt';
1194
		$meta_desc = ( get_option( 'geodir_meta_desc_pt' ) ) ? get_option( 'geodir_meta_desc_pt' ) : $meta_desc;
1195
	} elseif ( geodir_is_page( 'listing' ) ) {
1196
		$gd_page   = 'listing';
1197
		$meta_desc = ( get_option( 'geodir_meta_desc_listing' ) ) ? get_option( 'geodir_meta_desc_listing' ) : $meta_desc;
1198
	} elseif ( geodir_is_page( 'location' ) ) {
1199
		$gd_page   = 'location';
1200
		$meta_desc = ( get_option( 'geodir_meta_desc_location' ) ) ? get_option( 'geodir_meta_desc_location' ) : $meta_desc;
1201
		$meta_desc = apply_filters( 'geodir_seo_meta_location_description', $meta_desc );
1202
1203
	} elseif ( geodir_is_page( 'search' ) ) {
1204
		$gd_page   = 'search';
1205
		$meta_desc = ( get_option( 'geodir_meta_desc_search' ) ) ? get_option( 'geodir_meta_desc_search' ) : $meta_desc;
1206
	} elseif ( geodir_is_page( 'add-listing' ) ) {
1207
		$gd_page   = 'add-listing';
1208
		$meta_desc = ( get_option( 'geodir_meta_desc_add-listing' ) ) ? get_option( 'geodir_meta_desc_add-listing' ) : $meta_desc;
1209
	} elseif ( geodir_is_page( 'author' ) ) {
1210
		$gd_page   = 'author';
1211
		$meta_desc = ( get_option( 'geodir_meta_desc_author' ) ) ? get_option( 'geodir_meta_desc_author' ) : $meta_desc;
1212
	} elseif ( geodir_is_page( 'login' ) ) {
1213
		$gd_page   = 'login';
1214
		$meta_desc = ( get_option( 'geodir_meta_desc_login' ) ) ? get_option( 'geodir_meta_desc_login' ) : $meta_desc;
1215
	} elseif ( geodir_is_page( 'listing-success' ) ) {
1216
		$gd_page   = 'listing-success';
1217
		$meta_desc = ( get_option( 'geodir_meta_desc_listing-success' ) ) ? get_option( 'geodir_meta_desc_listing-success' ) : $meta_desc;
1218
	}
1219
1220
1221
	if ( $meta_desc ) {
1222
		$meta_desc = stripslashes_deep( $meta_desc );
1223
		/**
1224
		 * Filter page description to replace variables.
1225
		 *
1226
		 * @since 1.5.4
1227
		 *
1228
		 * @param string $title   The page description including variables.
1229
		 * @param string $gd_page The GeoDirectory page type if any.
1230
		 */
1231
		$meta_desc = apply_filters( 'geodir_seo_meta_description_pre', __( $meta_desc, 'geodirectory' ), $gd_page, '' );
1232
1233
		/**
1234
		 * Filter SEO meta description.
1235
		 *
1236
		 * @since 1.0.0
1237
		 *
1238
		 * @param string $meta_desc Meta description content.
1239
		 */
1240
		echo apply_filters( 'geodir_seo_meta_description', '<meta name="description" content="' . $meta_desc . '" />', $meta_desc );
1241
	}
1242
1243
	// meta keywords
1244
	if ( isset( $post->post_type ) && in_array( $post->post_type, $all_postypes ) ) {
1245
		$place_tags = wp_get_post_terms( $post->ID, $post->post_type . '_tags', array( "fields" => "names" ) );
1246
		$place_cats = wp_get_post_terms( $post->ID, $post->post_type . 'category', array( "fields" => "names" ) );
1247
1248
		$meta_key .= implode( ", ", array_merge( (array) $place_cats, (array) $place_tags ) );
1249
	} else {
1250
		$posttags = get_the_tags();
1251
		if ( $posttags ) {
1252
			foreach ( $posttags as $tag ) {
1253
				$meta_key .= $tag->name . ' ';
1254
			}
1255
		} else {
1256
			$tags = get_tags( array( 'orderby' => 'count', 'order' => 'DESC' ) );
1257
			$xt   = 1;
1258
1259
			foreach ( $tags as $tag ) {
1260
				if ( $xt <= 20 ) {
1261
					$meta_key .= $tag->name . ", ";
1262
				}
1263
1264
				$xt ++;
1265
			}
1266
		}
1267
	}
1268
1269
	$meta_key         = $meta_key != '' ? rtrim( trim( $meta_key ), "," ) : $meta_key;
1270
	$geodir_meta_keys = $geodir_meta_keys != '' ? ( $meta_key != '' ? $meta_key . ', ' . $geodir_meta_keys : $geodir_meta_keys ) : $meta_key;
1271
	if ( $geodir_meta_keys != '' ) {
1272
		$geodir_meta_keys = strip_tags( $geodir_meta_keys );
1273
		$geodir_meta_keys = esc_html( $geodir_meta_keys );
1274
		$geodir_meta_keys = geodir_strtolower( $geodir_meta_keys );
1275
		$geodir_meta_keys = wp_html_excerpt( $geodir_meta_keys, 1000, '' );
1276
		$geodir_meta_keys = str_replace( '%location%', $replace_location, $geodir_meta_keys );
1277
1278
		$meta_key = rtrim( trim( $geodir_meta_keys ), "," );
1279
	}
1280
1281
	if ( $meta_key ) {
1282
		$meta_key = stripslashes_deep( $meta_key );
1283
		/**
1284
		 * Filter SEO meta keywords.
1285
		 *
1286
		 * @since 1.0.0
1287
		 *
1288 4
		 * @param string $meta_desc Meta keywords.
1289
		 */
1290
		echo apply_filters( 'geodir_seo_meta_keywords', '<meta name="keywords" content="' . $meta_key . '" />', $meta_key );
1291
	}
1292
1293
}
1294 4
1295 4
/**
1296 4
 * Returns list of options available for "Detail page tab settings"
1297 4
 *
1298
 * Options will be populated here. WP Admin -> Geodirectory -> Design -> Detail -> Detail page tab settings -> Exclude
1299 4
 * selected tabs from detail page
1300 4
 *
1301 4
 * @since   1.0.0
1302 4
 * @package GeoDirectory
1303 4
 * @return array eturns list of options available as an array.
1304
 */
1305 4
function geodir_detail_page_tabs_key_value_array() {
1306
	$geodir_detail_page_tabs_key_value_array = array();
1307 4
1308 4
	$geodir_detail_page_tabs_array = geodir_detail_page_tabs_array();
1309 4
1310 4
	foreach ( $geodir_detail_page_tabs_array as $key => $tabs_obj ) {
1311
		$geodir_detail_page_tabs_key_value_array[ $key ] = $tabs_obj['heading_text'];
1312 4
	}
1313
1314 4
	return $geodir_detail_page_tabs_key_value_array;
1315 4
}
1316 4
1317 4
/**
1318
 * Build and return the list of available tabs as an array.
1319 4
 *
1320
 * @since   1.0.0
1321 4
 * @package GeoDirectory
1322 4
 * @return mixed|array Tabs array.
1323 4
 */
1324 4
function geodir_detail_page_tabs_array() {
1325
1326 4
	$arr_tabs = array();
1327
	/**
1328 4
	 * Filter detail page tab display.
1329 4
	 *
1330 4
	 * @since 1.0.0
1331 4
	 */
1332
	$arr_tabs['post_profile'] = array(
1333 4
		'heading_text'  => __( 'Profile', 'geodirectory' ),
1334
		'is_active_tab' => true,
1335 4
		'is_display'    => apply_filters( 'geodir_detail_page_tab_is_display', true, 'post_profile' ),
1336 4
		'tab_content'   => ''
1337 4
	);
1338 4
	$arr_tabs['post_info']    = array(
1339
		'heading_text'  => __( 'More Info', 'geodirectory' ),
1340 4
		'is_active_tab' => false,
1341
		'is_display'    => apply_filters( 'geodir_detail_page_tab_is_display', true, 'post_info' ),
1342 4
		'tab_content'   => ''
1343 4
	);
1344 4
1345 4
	$arr_tabs['post_images'] = array(
1346
		'heading_text'  => __( 'Photo', 'geodirectory' ),
1347 4
		'is_active_tab' => false,
1348
		'is_display'    => apply_filters( 'geodir_detail_page_tab_is_display', true, 'post_images' ),
1349
		'tab_content'   => ''
1350
	);
1351
1352
	$arr_tabs['post_video'] = array(
1353
		'heading_text'  => __( 'Video', 'geodirectory' ),
1354 4
		'is_active_tab' => false,
1355
		'is_display'    => apply_filters( 'geodir_detail_page_tab_is_display', true, 'post_video' ),
1356
		'tab_content'   => ''
1357
	);
1358
1359
	$arr_tabs['special_offers'] = array(
1360
		'heading_text'  => __( 'Special Offers', 'geodirectory' ),
1361
		'is_active_tab' => false,
1362
		'is_display'    => apply_filters( 'geodir_detail_page_tab_is_display', true, 'special_offers' ),
1363
		'tab_content'   => ''
1364
	);
1365
1366
	$arr_tabs['post_map'] = array(
1367
		'heading_text'  => __( 'Map', 'geodirectory' ),
1368
		'is_active_tab' => false,
1369 4
		'is_display'    => apply_filters( 'geodir_detail_page_tab_is_display', true, 'post_map' ),
1370 4
		'tab_content'   => ''
1371 4
	);
1372 4
1373 4
	$arr_tabs['reviews'] = array(
1374 4
		'heading_text'  => __( 'Reviews', 'geodirectory' ),
1375 4
		'is_active_tab' => false,
1376 4
		'is_display'    => apply_filters( 'geodir_detail_page_tab_is_display', true, 'reviews' ),
1377 4
		'tab_content'   => 'review display'
1378
	);
1379
1380
	$arr_tabs['related_listing'] = array(
1381
		'heading_text'  => __( 'Related Listing', 'geodirectory' ),
1382
		'is_active_tab' => false,
1383
		'is_display'    => apply_filters( 'geodir_detail_page_tab_is_display', true, 'related_listing' ),
1384
		'tab_content'   => ''
1385
	);
1386
1387
	/**
1388
	 * Filter the tabs array.
1389
	 *
1390
	 * @since 1.0.0
1391
	 */
1392
	return apply_filters( 'geodir_detail_page_tab_list_extend', $arr_tabs );
1393
1394
1395 2
}
1396
1397 2
1398 2
/**
1399 2
 * Returns the list of tabs available as an array.
1400
 *
1401 2
 * @since   1.0.0
1402
 * @package GeoDirectory
1403
 * @return mixed|array Tabs array.
1404
 */
1405
function geodir_detail_page_tabs_list() {
1406 2
	$tabs_excluded = get_option( 'geodir_detail_page_tabs_excluded' );
1407
	$tabs_array    = geodir_detail_page_tabs_array();
1408 2
1409
	if ( ! empty( $tabs_excluded ) ) {
1410 2
		foreach ( $tabs_excluded as $tab ) {
1411 1
			if ( array_key_exists( $tab, $tabs_array ) ) {
1412 1
				unset( $tabs_array[ $tab ] );
1413 1
			}
1414 1
		}
1415 1
	}
1416
1417 1
	return $tabs_array;
1418 1
}
1419 1
1420
1421 1
/**
1422 1
 * The main function responsible for displaying tabs in frontend detail page.
1423 1
 *
1424 1
 * @since   1.0.0
1425 1
 * @package GeoDirectory
1426 1
 * @global object $post                      The current post object.
1427 1
 * @global array $post_images                List of images attached to the post.
1428 1
 * @global string $video                     The video embed content.
1429
 * @global string $special_offers            Special offers content.
1430 1
 * @global string $related_listing           Related listing html.
1431
 * @global string $geodir_post_detail_fields Detail field html.
1432
 */
1433 1
function geodir_show_detail_page_tabs() {
1434
	global $post, $post_images, $video, $special_offers, $related_listing, $geodir_post_detail_fields, $preview;
1435
1436 1
	$post_id            = ! empty( $post ) && isset( $post->ID ) ? (int) $post->ID : 0;
1437
	$request_post_id    = ! empty( $_REQUEST['p'] ) ? (int) $_REQUEST['p'] : 0;
1438 1
	$is_backend_preview = ( is_single() && ! empty( $_REQUEST['post_type'] ) && ! empty( $_REQUEST['preview'] ) && ! empty( $_REQUEST['p'] ) ) && is_super_admin() ? true : false; // skip if preview from backend
1439 1
1440 1
	if ( $is_backend_preview && ! $post_id > 0 && $request_post_id > 0 ) {
1441 1
		$post = geodir_get_post_info( $request_post_id );
1442 1
		setup_postdata( $post );
1443 1
	}
1444 1
1445 1
	$geodir_post_detail_fields = geodir_show_listing_info( 'moreinfo' );
1446 1
1447 1
1448
	if ( geodir_is_page( 'detail' ) ) {
1449 1
		$video                 = geodir_get_video( $post->ID );
1450 1
		$special_offers        = geodir_get_special_offers( $post->ID );
1451 1
		$related_listing_array = array();
1452 1
		if ( get_option( 'geodir_add_related_listing_posttypes' ) ) {
1453 1
			$related_listing_array = get_option( 'geodir_add_related_listing_posttypes' );
1454
		}
1455
1456 1
1457 1
		$excluded_tabs = get_option( 'geodir_detail_page_tabs_excluded' );
1458 1
		if ( ! $excluded_tabs ) {
1459 1
			$excluded_tabs = array();
1460 1
		}
1461 1
1462 1
		$related_listing = '';
1463 1
		if ( in_array( $post->post_type, $related_listing_array ) && ! in_array( 'related_listing', $excluded_tabs ) ) {
1464 1
			$request = array(
1465 1
				'post_number'         => get_option( 'geodir_related_post_count' ),
1466 2
				'relate_to'           => get_option( 'geodir_related_post_relate_to' ),
1467 1
				'layout'              => get_option( 'geodir_related_post_listing_view' ),
1468 1
				'add_location_filter' => get_option( 'geodir_related_post_location_filter' ),
1469
				'list_sort'           => get_option( 'geodir_related_post_sortby' ),
1470 1
				'character_count'     => get_option( 'geodir_related_post_excerpt' )
1471 1
			);
1472
1473 1
			if ( $post->post_type == 'gd_event' && defined( 'GDEVENTS_VERSION' ) ) {
1474 1
				$related_listing = geodir_get_detail_page_related_events( $request );
1475
			} else {
1476 1
				$related_listing = geodir_related_posts_display( $request );
1477 1
			}
1478
1479
		}
1480
1481
		$post_images = geodir_get_images( $post->ID, 'thumbnail' );
1482
		$thumb_image = '';
1483
		if ( ! empty( $post_images ) ) {
1484
			foreach ( $post_images as $image ) {
0 ignored issues
show
Bug introduced by
The expression $post_images of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
1485
				$caption = ( ! empty( $image->caption ) ) ? $image->caption : '';
1486
				$thumb_image .= '<a href="' . $image->src . '" title="' . $caption . '">';
1487 1
				$thumb_image .= geodir_show_image( $image, 'thumbnail', true, false );
1488 1
				$thumb_image .= '</a>';
1489 1
			}
1490 1
		}
1491 1
1492 1
		$map_args                    = array();
1493 1
		$map_args['map_canvas_name'] = 'detail_page_map_canvas';
1494
		$map_args['width']           = '600';
1495 1
		$map_args['height']          = '300';
1496 1
		if ( $post->post_mapzoom ) {
1497 1
			$map_args['zoom'] = '' . $post->post_mapzoom . '';
1498 1
		}
1499 1
		$map_args['autozoom']                 = false;
1500
		$map_args['scrollwheel']              = ( get_option( 'geodir_add_listing_mouse_scroll' ) ) ? 0 : 1;
1501
		$map_args['child_collapse']           = '0';
1502
		$map_args['enable_cat_filters']       = false;
1503 1
		$map_args['enable_text_search']       = false;
1504 1
		$map_args['enable_post_type_filters'] = false;
1505 1
		$map_args['enable_location_filters']  = false;
1506 1
		$map_args['enable_jason_on_load']     = true;
1507 1
		$map_args['enable_map_direction']     = true;
1508 1
		$map_args['map_class_name']           = 'geodir-map-detail-page';
1509 1
		$map_args['maptype']                  = ( ! empty( $post->post_mapview ) ) ? $post->post_mapview : 'ROADMAP';
1510 1
	} else if ( geodir_is_page( 'preview' ) ) {
1511 1
		$video          = isset( $post->geodir_video ) ? $post->geodir_video : '';
1512 1
		$special_offers = isset( $post->geodir_special_offers ) ? $post->geodir_special_offers : '';
1513 1
1514 1
		if ( isset( $post->post_images ) ) {
1515 1
			$post->post_images = trim( $post->post_images, "," );
1516 1
		}
1517 1
1518 1
		if ( isset( $post->post_images ) && ! empty( $post->post_images ) ) {
1519 1
			$post_images = explode( ",", $post->post_images );
1520 1
		}
1521
1522 2
		$thumb_image = '';
1523 2
		if ( ! empty( $post_images ) ) {
1524 2
			foreach ( $post_images as $image ) {
1525 2
				if ( $image != '' ) {
1526 2
					$thumb_image .= '<a href="' . $image . '">';
1527 2
					$thumb_image .= geodir_show_image( array( 'src' => $image ), 'thumbnail', true, false );
1528 2
					$thumb_image .= '</a>';
1529 2
				}
1530 2
			}
1531
		}
1532 2
1533 2
		global $map_jason;
1534 2
		$marker_json      = $post->marker_json != '' ? json_decode( $post->marker_json, true ) : array();
1535 2
		$marker_icon      = ( ! empty( $marker_json ) && ! empty( $marker_json['i'] ) ) ? $marker_json['i'] : '';
1536 2
		$icon_size        = geodir_get_marker_size( $marker_icon );
1537
		$marker_json['w'] = $icon_size['w'];
1538 2
		$marker_json['h'] = $icon_size['h'];
1539
		$map_jason[]      = json_encode( $marker_json );
1540
1541
		$address_latitude  = isset( $post->post_latitude ) ? $post->post_latitude : '';
1542
		$address_longitude = isset( $post->post_longitude ) ? $post->post_longitude : '';
1543
		$mapview           = isset( $post->post_mapview ) ? $post->post_mapview : '';
1544
		$mapzoom           = isset( $post->post_mapzoom ) ? $post->post_mapzoom : '';
1545
		if ( ! $mapzoom ) {
1546
			$mapzoom = 12;
1547 2
		}
1548
1549
		$map_args                             = array();
1550
		$map_args['map_canvas_name']          = 'preview_map_canvas';
1551
		$map_args['width']                    = '950';
1552
		$map_args['height']                   = '300';
1553
		$map_args['child_collapse']           = '0';
1554
		$map_args['maptype']                  = $mapview;
1555
		$map_args['autozoom']                 = false;
1556
		$map_args['zoom']                     = "$mapzoom";
1557
		$map_args['latitude']                 = $address_latitude;
1558 2
		$map_args['longitude']                = $address_longitude;
1559
		$map_args['enable_cat_filters']       = false;
1560
		$map_args['enable_text_search']       = false;
1561
		$map_args['enable_post_type_filters'] = false;
1562
		$map_args['enable_location_filters']  = false;
1563
		$map_args['enable_jason_on_load']     = true;
1564
		$map_args['enable_map_direction']     = true;
1565
		$map_args['map_class_name']           = 'geodir-map-preview-page';
1566
	}
1567
1568 2
	$arr_detail_page_tabs = geodir_detail_page_tabs_list();// get this sooner so we can get the active tab for the user
1569 2
1570
	$active_tab       = '';
1571 2
	$active_tab_name  = '';
1572
	$default_tab      = '';
1573
	$default_tab_name = '';
1574
	foreach ( $arr_detail_page_tabs as $tab_index => $tabs ) {
1575
		if ( isset( $tabs['is_active_tab'] ) && $tabs['is_active_tab'] && ! empty( $tabs['is_display'] ) && isset( $tabs['heading_text'] ) && $tabs['heading_text'] ) {
1576
			$active_tab      = $tab_index;
1577
			$active_tab_name = __( $tabs['heading_text'], 'geodirectory' );
1578
		}
1579 2
1580 2
		if ( $default_tab === '' && ! empty( $tabs['is_display'] ) && ! empty( $tabs['heading_text'] ) ) {
1581
			$default_tab      = $tab_index;
1582
			$default_tab_name = __( $tabs['heading_text'], 'geodirectory' );
1583
		}
1584
	}
1585
1586
	if ( $active_tab === '' && $default_tab !== '' ) { // Make first tab acs a active tab if not any tab is active.
1587
		if ( isset( $arr_detail_page_tabs[ $active_tab ] ) && isset( $arr_detail_page_tabs[ $active_tab ]['is_active_tab'] ) ) {
1588
			$arr_detail_page_tabs[ $active_tab ]['is_active_tab'] = false;
1589
		}
1590
1591
		$arr_detail_page_tabs[ $default_tab ]['is_active_tab'] = true;
1592
		$active_tab                                            = $default_tab;
0 ignored issues
show
Unused Code introduced by
$active_tab is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1593
		$active_tab_name                                       = $default_tab_name;
1594
	}
1595
	$tab_list = ( get_option( 'geodir_disable_tabs', false ) ) ? true : false;
1596
	?>
1597
	<div class="geodir-tabs" id="gd-tabs" style="position:relative;">
1598
		<?php if ( ! $tab_list ){ ?>
1599
		<div id="geodir-tab-mobile-menu">
1600
			<i class="fa fa-bars"></i>
1601
			<span class="geodir-mobile-active-tab"><?php echo $active_tab_name; ?></span>
1602
			<i class="fa fa-sort-desc"></i>
1603 2
		</div>
1604
		<dl class="geodir-tab-head">
1605
			<?php
1606
			}
1607
			/**
1608
			 * Called before the details page tab list headings, inside the `dl` tag.
1609
			 *
1610
			 * @since 1.0.0
1611
			 * @see   'geodir_after_tab_list'
1612
			 */
1613 2
			do_action( 'geodir_before_tab_list' ); ?>
1614
			<?php
1615
1616 2
			foreach ( $arr_detail_page_tabs as $tab_index => $detail_page_tab ) {
1617
				if ( $detail_page_tab['is_display'] ) {
1618
1619
					if ( ! $tab_list ) {
1620
						?>
1621
						<dt></dt> <!-- added to comply with validation -->
1622 2
						<dd <?php if ( $detail_page_tab['is_active_tab'] ){ ?>class="geodir-tab-active"<?php } ?> ><a
1623 2
								data-tab="#<?php echo $tab_index; ?>"
1624 1
								data-status="enable"><?php _e( $detail_page_tab['heading_text'], 'geodirectory' ); ?></a>
1625 1
						</dd>
1626
						<?php
1627 1
					}
1628
					ob_start() // start tab content buffering
1629
					?>
1630
					<li id="<?php echo $tab_index; ?>Tab">
1631
						<?php if ( $tab_list ) {
1632
							$tab_title = '<span class="gd-tab-list-title" ><a href="#' . $tab_index . '">' . __( $detail_page_tab['heading_text'], 'geodirectory' ) . '</a></span><hr />';
1633
							/**
1634
							 * Filter the tab list title html.
1635 2
							 *
1636 2
							 * @since 1.6.1
1637 2
							 *
1638
							 * @param string $tab_title      The html for the tab title.
1639
							 * @param string $tab_index      The tab index type.
1640 2
							 * @param array $detail_page_tab The array of values including title text.
1641
							 */
1642
							echo apply_filters( 'geodir_tab_list_title', $tab_title, $tab_index, $detail_page_tab );
1643 2
						} ?>
1644
						<div id="<?php echo $tab_index; ?>" class="hash-offset"></div>
1645
						<?php
1646
						/**
1647 2
						 * Called before the details tab content is output per tab.
1648 1
						 *
1649
						 * @since 1.0.0
1650 1
						 *
1651 2
						 * @param string $tab_index The tab name ID.
1652 2
						 */
1653 2
						do_action( 'geodir_before_tab_content', $tab_index );
1654 1
1655 1
						/**
1656 1
						 * Called before the details tab content is output per tab.
1657 1
						 *
1658 1
						 * Uses dynamic hook name: geodir_before_$tab_index_tab_content
1659 1
						 *
1660
						 * @since 1.0.0
1661
						 * @todo  do we need this if we have the hook above? 'geodir_before_tab_content'
1662
						 */
1663
						do_action( 'geodir_before_' . $tab_index . '_tab_content' );
1664
						/// write a code to generate content of each tab
1665
						switch ( $tab_index ) {
1666
							case 'post_profile':
1667
								/**
1668
								 * Called before the listing description content on the details page tab.
1669
								 *
1670
								 * @since 1.0.0
1671
								 */
1672
								do_action( 'geodir_before_description_on_listing_detail' );
1673 2
								if ( geodir_is_page( 'detail' ) ) {
1674
									the_content();
1675
								} else {
1676
									/** This action is documented in geodirectory_template_actions.php */
1677
									echo apply_filters( 'the_content', stripslashes( $post->post_desc ) );
1678
								}
1679
1680
								/**
1681
								 * Called after the listing description content on the details page tab.
1682
								 *
1683 2
								 * @since 1.0.0
1684
								 */
1685
								do_action( 'geodir_after_description_on_listing_detail' );
1686
								break;
1687
							case 'post_info':
1688
								echo $geodir_post_detail_fields;
1689
								break;
1690
							case 'post_images':
1691 2
								echo $thumb_image;
0 ignored issues
show
Bug introduced by
The variable $thumb_image does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1692 2
								break;
1693 2
							case 'post_video':
1694
								// some browsers hide $_POST data if used for embeds so we repalce with a placeholder
1695
								if ( $preview ) {
1696
									if ( $video ) {
1697
										echo "<span class='gd-video-embed-preview' ><p class='gd-video-preview-text'><i class=\"fa fa-video-camera\" aria-hidden=\"true\"></i><br />" . __( 'Video Preview Placeholder', 'geodirectory' ) . "</p></span>";
1698
									}
1699
								} else {
1700
1701 2
									// stop payment manager filtering content length
1702
									$filter_priority = has_filter( 'the_content', 'geodir_payments_the_content' );
1703
									if ( false !== $filter_priority ) {
1704
										remove_filter( 'the_content', 'geodir_payments_the_content', $filter_priority );
1705
									}
1706 2
1707 2
									/** This action is documented in geodirectory_template_actions.php */
1708 2
									echo apply_filters( 'the_content', stripslashes( $video ) );// we apply the_content filter so oembed works also;
1709 2
1710 2
									if ( false !== $filter_priority ) {
1711
										add_filter( 'the_content', 'geodir_payments_the_content', $filter_priority );
1712
									}
1713
								}
1714
								break;
1715
							case 'special_offers':
1716
								echo apply_filters( 'gd_special_offers_content', wpautop( stripslashes( $special_offers ) ) );
1717
1718
								break;
1719
							case 'post_map':
1720
								geodir_draw_map( $map_args );
0 ignored issues
show
Bug introduced by
The variable $map_args does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1721
								break;
1722
							case 'reviews':
1723
								comments_template();
1724
								break;
1725
							case 'related_listing':
1726
								echo $related_listing;
1727
								break;
1728
							default: {
1729
								if ( ( isset( $post->{$tab_index} ) || ( ! isset( $post->{$tab_index} ) && ( strpos( $tab_index, 'gd_tab_' ) !== false || $tab_index == 'link_business' ) ) ) && ! empty( $detail_page_tab['tab_content'] ) ) {
1730
									echo $detail_page_tab['tab_content'];
1731
								}
1732
							}
1733
								break;
1734
						}
1735
1736
						/**
1737
						 * Called after the details tab content is output per tab.
1738
						 *
1739
						 * @since 1.0.0
1740 2
						 */
1741 2
						do_action( 'geodir_after_tab_content', $tab_index );
1742
1743
						/**
1744
						 * Called after the details tab content is output per tab.
1745
						 *
1746
						 * Uses dynamic hook name: geodir_after_$tab_index_tab_content
1747
						 *
1748
						 * @since 1.0.0
1749
						 * @todo  do we need this if we have the hook above? 'geodir_after_tab_content'
1750
						 */
1751
						do_action( 'geodir_after_' . $tab_index . '_tab_content' );
1752
						?> </li>
1753
					<?php
1754
					/**
1755
					 * Filter the current tab content.
1756
					 *
1757
					 * @since 1.0.0
1758
					 */
1759
					$arr_detail_page_tabs[ $tab_index ]['tab_content'] = apply_filters( "geodir_modify_" . $detail_page_tab['tab_content'] . "_tab_content", ob_get_clean() );
1760
				} // end of if for is_display
1761
			}// end of foreach
1762
1763
			/**
1764
			 * Called after the details page tab list headings, inside the `dl` tag.
1765
			 *
1766
			 * @since 1.0.0
1767
			 * @see   'geodir_before_tab_list'
1768
			 */
1769
			do_action( 'geodir_after_tab_list' );
1770
			?>
1771
			<?php if ( ! $tab_list ){ ?></dl><?php } ?>
1772
		<ul class="geodir-tabs-content entry-content <?php if ( $tab_list ) { ?>geodir-tabs-list<?php } ?>"
1773
		    style="position:relative;">
1774
			<?php
1775
			foreach ( $arr_detail_page_tabs as $detail_page_tab ) {
1776
				if ( $detail_page_tab['is_display'] && ! empty( $detail_page_tab['tab_content'] ) ) {
1777
					echo $detail_page_tab['tab_content'];
1778
				}// end of if
1779
			}// end of foreach
1780
1781
			/**
1782
			 * Called after all the tab content is output in `li` tags, called before the closing `ul` tag.
1783
			 *
1784
			 * @since 1.0.0
1785
			 */
1786
			do_action( 'geodir_add_tab_content' ); ?>
1787
		</ul>
1788
		<!--gd-tabs-content ul end-->
1789
	</div>
1790
	<?php if ( ! $tab_list ) { ?>
1791
		<script>
1792
			if (window.location.hash && window.location.hash.indexOf('&') === -1 && jQuery(window.location.hash + 'Tab').length) {
1793
				hashVal = window.location.hash;
1794
			} else {
1795
				hashVal = jQuery('dl.geodir-tab-head dd.geodir-tab-active').find('a').attr('data-tab');
1796
			}
1797
			jQuery('dl.geodir-tab-head dd').each(function () {
1798
				//Get all tabs
1799
				var tabs = jQuery(this).children('dd');
1800
				var tab = '';
1801
				tab = jQuery(this).find('a').attr('data-tab');
1802
				if (hashVal != tab) {
1803
					jQuery(tab + 'Tab').hide();
1804
				}
1805
1806
			});
1807
		</script>
1808
		<?php
1809
	}
1810
}
1811
1812
/**
1813
 * Fixes image orientation.
1814
 *
1815
 * @since   1.0.0
1816
 * @package GeoDirectory
1817
 *
1818
 * @param array $file The image file.
1819
 *
1820
 * @return mixed Image file.
1821
 */
1822
function geodir_exif( $file ) {
1823
	if ( empty( $file ) || ! is_array( $file ) ) {
1824
		return $file;
1825
	}
1826
1827
	$file_path = ! empty( $file['tmp_name'] ) ? sanitize_text_field( $file['tmp_name'] ) : '';
1828
	if ( ! ( $file_path && file_exists( $file_path ) ) ) {
1829
		return $file;
1830
	}
1831
	$file['file'] = $file_path;
1832
1833
	if ( ! file_is_valid_image( $file_path ) ) {
1834
		return $file; // Bail if file is not an image.
1835
	}
1836
1837
	if ( ! function_exists( 'wp_get_image_editor' ) ) {
1838
		return $file;
1839
	}
1840
1841
	$mime_type = $file['type'];
1842
	$exif      = array();
1843
	if ( $mime_type == 'image/jpeg' && function_exists( 'exif_read_data' ) ) {
1844
		try {
1845
			$exif = exif_read_data( $file_path );
1846
		} catch ( Exception $e ) {
1847
			$exif = array();
1848
		}
1849
	}
1850
1851
	$rotate      = false;
1852
	$flip        = false;
1853
	$modify      = false;
1854
	$orientation = 0;
1855
	if ( ! empty( $exif ) && isset( $exif['Orientation'] ) ) {
1856
		switch ( (int) $exif['Orientation'] ) {
1857
			case 1:
1858
				// do nothing
1859
				break;
1860 View Code Duplication
			case 2:
1861
				$flip   = array( false, true );
1862
				$modify = true;
1863
				break;
1864
			case 3:
1865
				$orientation = - 180;
1866
				$rotate      = true;
1867
				$modify      = true;
1868
				break;
1869 View Code Duplication
			case 4:
1870
				$flip   = array( true, false );
1871
				$modify = true;
1872
				break;
1873 View Code Duplication
			case 5:
1874
				$orientation = - 90;
1875
				$rotate      = true;
1876
				$flip        = array( false, true );
1877
				$modify      = true;
1878
				break;
1879
			case 6:
1880
				$orientation = - 90;
1881
				$rotate      = true;
1882
				$modify      = true;
1883
				break;
1884 View Code Duplication
			case 7:
1885
				$orientation = - 270;
1886
				$rotate      = true;
1887
				$flip        = array( false, true );
1888
				$modify      = true;
1889
				break;
1890
			case 8:
1891
			case 9:
1892 2
				$orientation = - 270;
1893 2
				$rotate      = true;
1894 2
				$modify      = true;
1895
				break;
1896 2
			default:
1897 2
				$orientation = 0;
1898 2
				$rotate      = true;
1899 2
				$modify      = true;
1900
				break;
1901 2
		}
1902
	}
1903
1904
	$quality = null;
1905
	/**
1906
	 * Filter the image quality.
1907
	 *
1908
	 * @since 1.5.7
1909
	 *
1910
	 * @param int|null $quality Image Compression quality between 1-100% scale. Default null.
1911
	 * @param string $quality   Image mime type.
1912
	 */
1913
	$quality = apply_filters( 'geodir_image_upload_set_quality', $quality, $mime_type );
1914
	if ( $quality !== null ) {
1915 2
		$modify = true;
1916 2
	}
1917
1918 2
	if ( ! $modify ) {
1919
		return $file; // no change
1920 2
	}
1921
1922 2
	$image = wp_get_image_editor( $file_path );
1923
	if ( ! is_wp_error( $image ) ) {
1924 2
		if ( $rotate ) {
1925 2
			$image->rotate( $orientation );
1926 2
		}
1927
1928 2
		if ( ! empty( $flip ) ) {
1929 2
			$image->flip( $flip[0], $flip[1] );
1930 2
		}
1931
1932 2
		if ( $quality !== null ) {
1933
			$image->set_quality( (int) $quality );
1934 2
		}
1935 2
1936 2
		$result = $image->save( $file_path );
1937
		if ( ! is_wp_error( $result ) ) {
1938 2
			$file['file']     = $result['path'];
1939 2
			$file['tmp_name'] = $result['path'];
1940
		}
1941
	}
1942
1943
	// The image orientation is fixed, pass it back for further processing
1944
	return $file;
1945
}
1946
1947 2
/**
1948 2
 * Returns the recent reviews.
1949 2
 *
1950 2
 * @since   1.0.0
1951
 * @package GeoDirectory
1952 2
 *
1953 2
 * @global object $wpdb        WordPress Database object.
1954
 * @global object $gd_session  GeoDirectory Session object.
1955
 *
1956 2
 * @param int $g_size          Optional. Avatar size in pixels. Default 60.
1957
 * @param int $no_comments     Optional. Number of reviews you want to display. Default: 10.
1958
 * @param int $comment_lenth   Optional. Maximum number of characters you want to display. After that read more link
1959 2
 *                             will appear.
1960 2
 * @param bool $show_pass_post Optional. Not yet implemented.
1961 2
 *
1962
 * @return string Returns the recent reviews html.
1963
 */
1964
function geodir_get_recent_reviews( $g_size = 60, $no_comments = 10, $comment_lenth = 60, $show_pass_post = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $show_pass_post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1965 2
	global $wpdb, $tablecomments, $tableposts, $rating_table_name, $gd_session;
1966 2
	$tablecomments = $wpdb->comments;
1967 2
	$tableposts    = $wpdb->posts;
1968 2
1969 2
	$comments_echo  = '';
1970 2
	$city_filter    = '';
1971 2
	$region_filter  = '';
1972 2
	$country_filter = '';
1973 2
1974 2
	if ( $gd_session->get( 'gd_multi_location' ) ) {
1975 2
		if ( $gd_ses_country = $gd_session->get( 'gd_country' ) ) {
1976 2
			$country_filter = $wpdb->prepare( " AND r.post_country=%s ", str_replace( "-", " ", $gd_ses_country ) );
1977 2
		}
1978
1979
		if ( $gd_ses_region = $gd_session->get( 'gd_region' ) ) {
1980
			$region_filter = $wpdb->prepare( " AND r.post_region=%s ", str_replace( "-", " ", $gd_ses_region ) );
1981
		}
1982
1983 2
		if ( $gd_ses_city = $gd_session->get( 'gd_city' ) ) {
1984
			$city_filter = $wpdb->prepare( " AND r.post_city=%s ", str_replace( "-", " ", $gd_ses_city ) );
1985
		}
1986
	}
1987
1988
	$review_table = GEODIR_REVIEW_TABLE;
1989
	$request      = "SELECT r.id as ID, r.post_type, r.comment_id as comment_ID, r.post_date as comment_date,r.overall_rating, r.user_id, r.post_id FROM $review_table as r WHERE r.post_status = 1 AND r.status =1 AND r.overall_rating>=1 $country_filter $region_filter $city_filter ORDER BY r.post_date DESC, r.id DESC LIMIT $no_comments";
1990
1991
	$comments = $wpdb->get_results( $request );
1992
1993
	foreach ( $comments as $comment ) {
1994
		// Set the extra comment info needed.
1995
		$comment_extra = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID =$comment->comment_ID" );
1996
		//echo "SELECT * FROM $wpdb->comments WHERE comment_ID =$comment->comment_ID";
1997
		$comment->comment_content      = $comment_extra->comment_content;
1998
		$comment->comment_author       = $comment_extra->comment_author;
1999
		$comment->comment_author_email = $comment_extra->comment_author_email;
2000
2001
		$comment_id      = '';
0 ignored issues
show
Unused Code introduced by
$comment_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2002
		$comment_id      = $comment->comment_ID;
2003
		$comment_content = strip_tags( $comment->comment_content );
2004
2005 2
		$comment_content = preg_replace( '#(\\[img\\]).+(\\[\\/img\\])#', '', $comment_content );
2006
2007 2
		$permalink            = get_permalink( $comment->ID ) . "#comment-" . $comment->comment_ID;
0 ignored issues
show
Unused Code introduced by
$permalink is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2008 2
		$comment_author_email = $comment->comment_author_email;
0 ignored issues
show
Unused Code introduced by
$comment_author_email is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2009 2
		$comment_post_ID      = $comment->post_id;
2010 2
2011 2
		$na = true;
2012 2
		if ( function_exists( 'icl_object_id' ) && icl_object_id( $comment_post_ID, $comment->post_type, true ) ) {
2013 2
			$comment_post_ID2 = icl_object_id( $comment_post_ID, $comment->post_type, false );
2014 2
			if ( $comment_post_ID == $comment_post_ID2 ) {
2015
			} else {
2016 2
				$na = false;
2017
			}
2018 2
		}
2019 2
2020 2
		$post_title        = get_the_title( $comment_post_ID );
2021 2
		$permalink         = get_permalink( $comment_post_ID );
2022
		$comment_permalink = $permalink . "#comment-" . $comment->comment_ID;
2023 2
		$read_more         = '<a class="comment_excerpt" href="' . $comment_permalink . '">' . __( 'Read more', 'geodirectory' ) . '</a>';
2024
2025
		$comment_content_length = strlen( $comment_content );
2026
		if ( $comment_content_length > $comment_lenth ) {
2027
			$comment_excerpt = mb_substr( $comment_content, 0, $comment_lenth ) . '... ' . $read_more;
2028
		} else {
2029
			$comment_excerpt = $comment_content;
2030
		}
2031
2032
		if ( $comment->user_id ) {
2033
			$user_profile_url = get_author_posts_url( $comment->user_id );
2034
		} else {
2035
			$user_profile_url = '';
2036
		}
2037
2038
		if ( $comment_id && $na ) {
2039
			$comments_echo .= '<li class="clearfix">';
2040
			$comments_echo .= "<span class=\"li" . $comment_id . " geodir_reviewer_image\">";
2041
			if ( function_exists( 'get_avatar' ) ) {
2042
				if ( ! isset( $comment->comment_type ) ) {
2043
					if ( $user_profile_url ) {
2044
						$comments_echo .= '<a href="' . $user_profile_url . '">';
2045
					}
2046
					$comments_echo .= get_avatar( $comment->comment_author_email, $g_size, geodir_plugin_url() . '/geodirectory-assets/images/gravatar2.png' );
2047
					if ( $user_profile_url ) {
2048
						$comments_echo .= '</a>';
2049
					}
2050
				} elseif ( ( isset( $comment->comment_type ) && $comment->comment_type == 'trackback' ) || ( isset( $comment->comment_type ) && $comment->comment_type == 'pingback' ) ) {
2051
					if ( $user_profile_url ) {
2052
						$comments_echo .= '<a href="' . $user_profile_url . '">';
2053
					}
2054
					$comments_echo .= get_avatar( $comment->comment_author_url, $g_size, geodir_plugin_url() . '/geodirectory-assets/images/gravatar2.png' );
2055
				}
2056
			} elseif ( function_exists( 'gravatar' ) ) {
2057
				if ( $user_profile_url ) {
2058
					$comments_echo .= '<a href="' . $user_profile_url . '">';
2059
				}
2060
				$comments_echo .= "<img src=\"";
2061
				if ( '' == $comment->comment_type ) {
2062
					$comments_echo .= gravatar( $comment->comment_author_email, $g_size, geodir_plugin_url() . '/geodirectory-assets/images/gravatar2.png' );
2063
					if ( $user_profile_url ) {
2064
						$comments_echo .= '</a>';
2065
					}
2066
				} elseif ( ( 'trackback' == $comment->comment_type ) || ( 'pingback' == $comment->comment_type ) ) {
2067
					if ( $user_profile_url ) {
2068
						$comments_echo .= '<a href="' . $user_profile_url . '">';
2069
					}
2070
					$comments_echo .= gravatar( $comment->comment_author_url, $g_size, geodir_plugin_url() . '/geodirectory-assets/images/gravatar2.png' );
2071
					if ( $user_profile_url ) {
2072
						$comments_echo .= '</a>';
2073
					}
2074 2
				}
2075
				$comments_echo .= "\" alt=\"\" class=\"avatar\" />";
2076
			}
2077
2078
			$comments_echo .= "</span>\n";
2079
2080
			$comments_echo .= '<span class="geodir_reviewer_content">';
2081
			if ( $comment->user_id ) {
2082
				$comments_echo .= '<a href="' . get_author_posts_url( $comment->user_id ) . '">';
2083
			}
2084
			$comments_echo .= '<span class="geodir_reviewer_author">' . $comment->comment_author . '</span> ';
2085
			if ( $comment->user_id ) {
2086 2
				$comments_echo .= '</a>';
2087
			}
2088
			$comments_echo .= '<span class="geodir_reviewer_reviewed">' . __( 'reviewed', 'geodirectory' ) . '</span> ';
2089
			$comments_echo .= '<a href="' . $permalink . '" class="geodir_reviewer_title">' . $post_title . '</a>';
2090
			$comments_echo .= geodir_get_rating_stars( $comment->overall_rating, $comment_post_ID );
2091
			$comments_echo .= '<p class="geodir_reviewer_text">' . $comment_excerpt . '';
2092
			//echo preg_replace('#(\\[img\\]).+(\\[\\/img\\])#', '', $comment_excerpt);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2093
			$comments_echo .= '</p>';
2094 2
2095
			$comments_echo .= "</span>\n";
2096
			$comments_echo .= '</li>';
2097
		}
2098
	}
2099
2100
	return $comments_echo;
2101
}
2102
2103
/**
2104
 * Returns All post categories from all GD post types.
2105
 *
2106
 * @since   1.0.0
2107
 * @package GeoDirectory
2108
 * @return array Returns post categories as an array.
2109
 */
2110
function geodir_home_map_cats_key_value_array() {
2111
	$post_types = geodir_get_posttypes( 'object' );
2112
2113
	$return = array();
2114
	if ( ! empty( $post_types ) ) {
2115
		foreach ( $post_types as $key => $post_type ) {
0 ignored issues
show
Bug introduced by
The expression $post_types of type array|object|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
2116
			$cpt_name       = __( $post_type->labels->singular_name, 'geodirectory' );
2117
			$post_type_name = sprintf( __( '%s Categories', 'geodirectory' ), $cpt_name );
2118 2
			$taxonomies     = geodir_get_taxonomies( $key );
2119
			$cat_taxonomy   = ! empty( $taxonomies[0] ) ? $taxonomies[0] : null;
2120
			$cat_terms      = $cat_taxonomy ? get_terms( $cat_taxonomy ) : null;
2121
2122
			if ( ! empty( $cat_terms ) ) {
2123
				$return[ 'optgroup_start-' . $key ] = $post_type_name;
2124
2125
				foreach ( $cat_terms as $cat_term ) {
2126
					$return[ $key . '_' . $cat_term->term_id ] = $cat_term->name;
2127
				}
2128
2129
				$return[ 'optgroup_end-' . $key ] = $post_type_name;
2130 2
			}
2131
		}
2132
	}
2133
2134
	return $return;
2135
}
2136
2137
/**
2138
 * "Twitter tweet" button code.
2139
 *
2140
 * To display "Twitter tweet" button, you can call this function.
2141
 * @since   1.0.0
2142
 * @package GeoDirectory
2143
 */
2144
function geodir_twitter_tweet_button() {
2145
	if ( isset( $_GET['gde'] ) ) {
2146
		$link = '?url=' . urlencode( geodir_curPageURL() );
2147
	} else {
2148
		$link = '';
2149
	}
2150
	?>
2151
	<a href="http://twitter.com/share<?php echo $link; ?>"
2152
	   class="twitter-share-button"><?php _e( 'Tweet', 'geodirectory' ); ?></a>
2153 2
	<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
2154
	<?php
2155
}
2156 10
2157
/**
2158
 * "Facebook like" button code.
2159
 *
2160
 * To display "Facebook like" button, you can call this function.
2161
 *
2162
 * @since   1.0.0
2163
 * @package GeoDirectory
2164
 * @global object $post The current post object.
2165
 */
2166
function geodir_fb_like_button() {
2167
	global $post;
2168
	?>
2169 View Code Duplication
	<iframe <?php if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) ) {
2170
		echo 'allowtransparency="true"';
2171
	} ?> class="facebook"
2172
	     src="//www.facebook.com/plugins/like.php?href=<?php echo urlencode( get_permalink( $post->ID ) ); ?>&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light"
2173
	     style="border:none; overflow:hidden; width:100px; height:20px"></iframe>
2174 10
	<?php
2175 10
}
2176
2177
/**
2178
 * "Google Plus" share button code.
2179
 *
2180 9
 * To display "Google Plus" share button, you can call this function.
2181 9
 *
2182
 * @since   1.0.0
2183
 * @package GeoDirectory
2184
 */
2185 4
function geodir_google_plus_button() {
2186
	?>
2187 4
	<div id="plusone-div" class="g-plusone" data-size="medium"></div>
2188
	<script type="text/javascript">
2189 4
		(function () {
2190 2
			var po = document.createElement('script');
2191 2
			po.type = 'text/javascript';
2192
			po.async = true;
2193
			po.src = 'https://apis.google.com/js/platform.js';
2194
			var s = document.getElementsByTagName('script')[0];
2195
			s.parentNode.insertBefore(po, s);
2196 2
		})();
2197 4
	</script>
2198
	<?php
2199
}
2200
2201
2202
function geodir_listing_bounce_map_pin_on_hover() {
2203
	if ( get_option( 'geodir_listing_hover_bounce_map_pin', true ) ) {
2204
		?>
2205
		<script>
2206
			jQuery(function ($) {
2207
				if (typeof(animate_marker) == 'function') {
2208
					var groupTab = $("ul.geodir_category_list_view").children("li");
2209
					groupTab.hover(function () {
2210
						animate_marker('listing_map_canvas', String($(this).data("post-id")));
2211
					}, function () {
2212
						stop_marker_animation('listing_map_canvas', String($(this).data("post-id")));
2213
					});
2214
				} else {
2215
					window.animate_marker = function () {
2216
					};
2217
					window.stop_marker_animation = function () {
2218
					};
2219
				}
2220
			});
2221
		</script>
2222
		<?php
2223
	}
2224
}
2225
2226
add_action( 'geodir_after_listing_listview', 'geodir_listing_bounce_map_pin_on_hover', 10 );
2227
2228
add_action( 'geodir_after_favorite_html', 'geodir_output_favourite_html_listings', 1, 1 );
2229
function geodir_output_favourite_html_listings( $post_id ) {
2230
	geodir_favourite_html( '', $post_id );
2231
}
2232
2233
add_action( 'geodir_listing_after_pinpoint', 'geodir_output_pinpoint_html_listings', 1, 2 );
2234
function geodir_output_pinpoint_html_listings( $post_id, $post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $post_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2235
	global $wp_query;
2236
2237
	$show_pin_point = $wp_query->is_main_query();
2238
2239
	if ( ! empty( $show_pin_point ) && is_active_widget( false, "", "geodir_map_v3_listing_map" ) ) {
2240
		$term_icon_url = get_tax_meta( $post->default_category, 'ct_cat_icon', false, $post->post_type );
2241
		$marker_icon   = isset( $term_icon_url['src'] ) ? $term_icon_url['src'] : get_option( 'geodir_default_marker_icon' );
2242
		?>
2243
		<span class="geodir-pinpoint"
2244
		      style="background:url('<?php echo $marker_icon; ?>') no-repeat scroll left top transparent;background-size:auto 100%; -webkit-background-size:auto 100%;-moz-background-size:auto 100%;height:9px;width:14px;"><?php echo apply_filters( 'geodir_listing_listview_pinpoint_inner_content', '', 'listing' ); ?></span>
2245
		<a class="geodir-pinpoint-link" href="javascript:void(0)"
2246
		   onclick="openMarker('listing_map_canvas' ,'<?php echo $post->ID; ?>')"
2247
		   onmouseover="animate_marker('listing_map_canvas' ,'<?php echo $post->ID; ?>')"
2248
		   onmouseout="stop_marker_animation('listing_map_canvas' ,'<?php echo $post->ID; ?>')"><?php _e( 'Pinpoint', 'geodirectory' ); ?></a>
2249
		<?php
2250
	}
2251
}
2252
2253
function geodir_search_form_submit_button() {
2254
2255
	$new_style = get_option( 'geodir_show_search_old_search_from' ) ? false : true;
2256
2257
	if ( $new_style ) {
2258
		$default_search_button_label = '<i class="fa fa-search" aria-hidden="true"></i>';
2259
	}else{
2260
		$default_search_button_label = 'Search';
2261
	}
2262
	if ( get_option( 'geodir_search_button_label' ) && get_option( 'geodir_search_button_label' ) != 'Search' ) {
2263
		$default_search_button_label = __( get_option( 'geodir_search_button_label' ), 'geodirectory' );
2264
	}
2265
2266
	/**
2267
	 * Filter the default search button text value for the search form.
2268
	 *
2269
	 * This text can be changed via an option in settings, this is a last resort.
2270
	 *
2271
	 * @since 1.5.5
2272
	 *
2273
	 * @param string $default_search_button_label The current search button text.
2274
	 */
2275
	$default_search_button_label = apply_filters( 'geodir_search_default_search_button_text', $default_search_button_label );
2276
2277
	$fa_class = '';
2278
	if ( strpos( $default_search_button_label, '&#' ) !== false ) {
2279
		$fa_class = 'fa';
2280
	}
2281
2282
2283
	if ( $new_style ) {
2284
	?>
2285
		<button class="geodir_submit_search <?php echo $fa_class; ?>"><?php _e( $default_search_button_label ,'geodirectory'); ?></button>
2286
<?php }else{?>
2287
		<input type="button" value="<?php esc_attr_e( $default_search_button_label ); ?>"
2288
	       class="geodir_submit_search <?php echo $fa_class; ?>"/>
2289
	<?php }
2290
}
2291
2292
add_action( 'geodir_before_search_button', 'geodir_search_form_submit_button', 5000 );
2293
2294
function geodir_search_form_post_type_input() {
2295
	global $geodir_search_post_type;
2296
	$post_types     = apply_filters( 'geodir_search_form_post_types', geodir_get_posttypes( 'object' ) );
2297
	$curr_post_type = $geodir_search_post_type;
2298
2299
	if ( ! empty( $post_types ) && count( (array) $post_types ) > 1 ) {
2300
2301 View Code Duplication
		foreach ( $post_types as $post_type => $info ){
2302
			global $wpdb;
2303
			$has_posts = $wpdb->get_row( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_status='publish' LIMIT 1", $post_type ) );
2304
			if ( ! $has_posts ) {
2305
				unset($post_types->{$post_type});
2306
			}
2307
		}
2308
2309
		if ( ! empty( $post_types ) && count( (array) $post_types ) > 1 ) {
2310
2311
			$new_style = get_option( 'geodir_show_search_old_search_from' ) ? false : true;
2312
			if ( $new_style ) {
2313
				echo "<div class='gd-search-input-wrapper gd-search-field-cpt'>";
2314
			}
2315
			?>
2316
			<select name="stype" class="search_by_post">
2317
				<?php foreach ( $post_types as $post_type => $info ):
2318
					global $wpdb;
2319
					?>
2320
2321
					<option data-label="<?php echo get_post_type_archive_link( $post_type ); ?>"
2322
					        value="<?php echo $post_type; ?>" <?php if ( isset( $_REQUEST['stype'] ) ) {
2323
						if ( $post_type == $_REQUEST['stype'] ) {
2324
							echo 'selected="selected"';
2325
						}
2326
					} elseif ( $curr_post_type == $post_type ) {
2327
						echo 'selected="selected"';
2328
					} ?>><?php _e( ucfirst( $info->labels->name ), 'geodirectory' ); ?></option>
2329
2330
				<?php endforeach; ?>
2331
			</select>
2332
			<?php
2333
			if ( $new_style ) {
2334
				echo "</div>";
2335
			}
2336
		}else{
2337
			if(! empty( $post_types )){
2338
				$pt_arr = (array)$post_types;
2339
				echo '<input type="hidden" name="stype" value="' . key( $pt_arr  ) . '"  />';
2340
			}else{
2341
				echo '<input type="hidden" name="stype" value="gd_place"  />';
2342
			}
2343
2344
		}
2345
2346
	}elseif ( ! empty( $post_types ) ) {
2347
		echo '<input type="hidden" name="stype" value="gd_place"  />';
2348
	}
2349
}
2350
2351
function geodir_search_form_search_input() {
2352
2353
	$default_search_for_text = SEARCH_FOR_TEXT;
2354
	if ( get_option( 'geodir_search_field_default_text' ) ) {
2355
		$default_search_for_text = __( get_option( 'geodir_search_field_default_text' ), 'geodirectory' );
2356
	}
2357
2358
	$new_style = get_option('geodir_show_search_old_search_from') ? false : true;
2359
	if($new_style){
2360
		echo "<div class='gd-search-input-wrapper gd-search-field-search'>";
2361
	}
2362
	?>
2363
	<input class="search_text" name="s"
2364
	       value="<?php if ( isset( $_REQUEST['s'] ) && trim( $_REQUEST['s'] ) != '' ) {
2365
		       echo esc_attr( stripslashes_deep( $_REQUEST['s'] ) );
2366
	       } else {
2367
		       echo $default_search_for_text;
2368
	       } ?>" type="text"
2369
	       onblur="if (this.value.trim() == '') {this.value = '<?php echo esc_sql( $default_search_for_text ); ?>';}"
2370
	       onfocus="if (this.value == '<?php echo esc_sql( $default_search_for_text ); ?>') {this.value = '';}"
2371
	       onkeydown="javascript: if(event.keyCode == 13) geodir_click_search(this);">
2372
	<?php
2373
	if($new_style){
2374
		echo "</div>";
2375
	}
2376
}
2377
2378
function geodir_search_form_near_input() {
2379
2380
	$default_near_text = NEAR_TEXT;
2381
	if ( get_option( 'geodir_near_field_default_text' ) ) {
2382
		$default_near_text = __( get_option( 'geodir_near_field_default_text' ), 'geodirectory' );
2383
	}
2384
2385
	if ( isset( $_REQUEST['snear'] ) && $_REQUEST['snear'] != '' ) {
2386
		$near = esc_attr( stripslashes_deep( $_REQUEST['snear'] ) );
2387
	} else {
2388
		$near = $default_near_text;
2389
	}
2390
2391
2392
	global $geodir_search_post_type;
2393
	$curr_post_type = $geodir_search_post_type;
2394
	/**
2395
	 * Used to hide the near field and other things.
2396
	 *
2397
	 * @since 1.6.9
2398
	 * @param string $curr_post_type The current post type.
2399
	 */
2400
	$near_input_extra = apply_filters('geodir_near_input_extra','',$curr_post_type);
2401
2402
2403
	/**
2404
	 * Filter the "Near" text value for the search form.
2405
	 *
2406
	 * This is the input "value" attribute and can change depending on what the user searches and is not always the default value.
2407
	 *
2408
	 * @since 1.0.0
2409
	 *
2410
	 * @param string $near              The current near value.
2411
	 * @param string $default_near_text The default near value.
2412
	 */
2413
	$near = apply_filters( 'geodir_search_near_text', $near, $default_near_text );
2414
	/**
2415
	 * Filter the default "Near" text value for the search form.
2416
	 *
2417
	 * This is the default value if nothing has been searched.
2418
	 *
2419
	 * @since 1.0.0
2420
	 *
2421
	 * @param string $near              The current near value.
2422
	 * @param string $default_near_text The default near value.
2423
	 */
2424
	$default_near_text = apply_filters( 'geodir_search_default_near_text', $default_near_text, $near );
2425
	/**
2426
	 * Filter the class for the near search input.
2427
	 *
2428
	 * @since 1.0.0
2429
	 *
2430
	 * @param string $class The class for the HTML near input, default is blank.
2431
	 */
2432
	$near_class = apply_filters( 'geodir_search_near_class', '' );
2433
2434
	$new_style = get_option('geodir_show_search_old_search_from') ? false : true;
2435
	if($new_style){
2436
		echo "<div class='gd-search-input-wrapper gd-search-field-near' $near_input_extra>";
2437
		
2438
		do_action('geodir_before_near_input');
2439
	}
2440
2441
	?>
2442
	<input name="snear" class="snear <?php echo $near_class; ?>" type="text" value="<?php echo $near; ?>"
2443
	       onblur="if (this.value.trim() == '') {this.value = ('<?php echo esc_sql( $near ); ?>' != '' ? '<?php echo esc_sql( $near ); ?>' : '<?php echo $default_near_text; ?>');}"
2444
	       onfocus="if (this.value == '<?php echo $default_near_text; ?>' || this.value =='<?php echo esc_sql( $near ); ?>') {this.value = '';}"
2445
	       onkeydown="javascript: if(event.keyCode == 13) geodir_click_search(this);" <?php echo $near_input_extra;?>/>
2446
	<?php
2447
	if($new_style){
2448
		do_action('geodir_after_near_input');
2449
2450
		echo "</div>";
2451
	}
2452
}
2453
2454
add_action( 'geodir_search_form_inputs', 'geodir_search_form_post_type_input', 10 );
2455
add_action( 'geodir_search_form_inputs', 'geodir_search_form_search_input', 20 );
2456
add_action( 'geodir_search_form_inputs', 'geodir_search_form_near_input', 30 );
2457
2458
function geodir_get_search_post_type($pt=''){
2459
	global $geodir_search_post_type;
2460
2461
	if($pt!=''){return $geodir_search_post_type = $pt;}
2462
	if(!empty($geodir_search_post_type)){ return $geodir_search_post_type;}
2463
2464
	$geodir_search_post_type = geodir_get_current_posttype();
2465
2466
	if(!$geodir_search_post_type) {
2467
		$geodir_search_post_type = geodir_get_default_posttype();
2468
	}
2469
2470
2471
	return $geodir_search_post_type;
2472
}
2473
2474
function geodir_search_form(){
2475
2476
	geodir_get_search_post_type();
2477
2478
	geodir_get_template_part('listing', 'filter-form');
2479
2480
	// Always die in functions echoing ajax content
2481
	die();
2482
}
2483
2484
add_action( 'wp_ajax_geodir_search_form', 'geodir_search_form' );
2485
add_action( 'wp_ajax_nopriv_geodir_search_form', 'geodir_search_form' );
2486
2487
/**
2488
 * Check wpml active or not.
2489
 *
2490
 * @since 1.5.0
2491
 *
2492
 * @return True if WPML is active else False.
2493
 */
2494
function geodir_is_wpml() {
2495
    if (function_exists('icl_object_id')) {
2496
        return true;
2497
    }
2498
2499
    return false;
2500
}
2501
2502
/**
2503
 * Get WPML language code for current term.
2504
 *
2505
 * @since 1.5.0
2506
 *
2507
 * @global object $sitepress Sitepress WPML object.
2508
 *
2509
 * @param int $element_id Post ID or Term id.
2510
 * @param string $element_type Element type. Ex: post_gd_place or tax_gd_placecategory.
2511
 * @return Language code.
2512
 */
2513
function geodir_get_language_for_element($element_id, $element_type) {
2514
    global $sitepress;
2515
2516
    return $sitepress->get_language_for_element($element_id, $element_type);
2517
}
2518
2519
/**
2520
 * Duplicate post details for WPML translation post.
2521
 *
2522
 * @since 1.5.0
2523
 * @since 1.6.16 Sync reviews if sync comments allowed.
2524
 *
2525
 * @param int $master_post_id Original Post ID.
2526
 * @param string $lang Language code for translating post.
2527
 * @param array $postarr Array of post data.
2528
 * @param int $tr_post_id Translation Post ID.
2529
 */
2530
function geodir_icl_make_duplicate($master_post_id, $lang, $postarr, $tr_post_id) {
0 ignored issues
show
Unused Code introduced by
The parameter $postarr is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2531
    global $sitepress;
2532
2533
    $post_type = get_post_type($master_post_id);
2534
2535
    if (in_array($post_type, geodir_get_posttypes())) {
2536
        // Duplicate post details
2537
        geodir_icl_duplicate_post_details($master_post_id, $tr_post_id, $lang);
2538
        
2539
        // Duplicate taxonomies
2540
        geodir_icl_duplicate_taxonomies($master_post_id, $tr_post_id, $lang);
2541
        
2542
        // Duplicate post images
2543
        geodir_icl_duplicate_post_images($master_post_id, $tr_post_id, $lang);
2544
        
2545
        // Sync post reviews
2546
        if ($sitepress->get_setting('sync_comments_on_duplicates')) {
2547
            geodir_wpml_duplicate_post_reviews($master_post_id, $tr_post_id, $lang);
2548
        }
2549
    }
2550
}
2551
add_filter( 'icl_make_duplicate', 'geodir_icl_make_duplicate', 11, 4 );
2552
2553
/**
2554
 * Duplicate post reviews for WPML translation post.
2555
 *
2556
 * @since 1.6.16
2557
 *
2558
 * @global object $wpdb WordPress Database object.
2559
 *
2560
 * @param int $master_post_id Original Post ID.
2561
 * @param int $tr_post_id Translation Post ID.
2562
 * @param string $lang Language code for translating post.
2563
 * @return bool True for success, False for fail.
2564
 */
2565
function geodir_wpml_duplicate_post_reviews($master_post_id, $tr_post_id, $lang) {
2566
    global $wpdb;
2567
2568
    $reviews = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM " . GEODIR_REVIEW_TABLE . " WHERE post_id=%d ORDER BY id ASC", $master_post_id), ARRAY_A);
2569
2570
    if (!empty($reviews)) {
2571
        foreach ($reviews as $review) {
2572
            geodir_wpml_duplicate_post_review($review['comment_id'], $master_post_id, $tr_post_id, $lang);
2573
        }
2574
    }
2575
2576
    return false;
2577
}
2578
2579
/**
2580
 * Duplicate post general details for WPML translation post.
2581
 *
2582
 * @since 1.5.0
2583
 *
2584
 * @global object $wpdb WordPress Database object.
2585
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2586
 *
2587
 * @param int $master_post_id Original Post ID.
2588
 * @param int $tr_post_id Translation Post ID.
2589
 * @param string $lang Language code for translating post.
2590
 * @return bool True for success, False for fail.
2591
 */
2592
function geodir_icl_duplicate_post_details($master_post_id, $tr_post_id, $lang) {
0 ignored issues
show
Unused Code introduced by
The parameter $lang is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2593
    global $wpdb, $plugin_prefix;
2594
2595
    $post_type = get_post_type($master_post_id);
2596
    $post_table = $plugin_prefix . $post_type . '_detail';
2597
2598
    $query = $wpdb->prepare("SELECT * FROM " . $post_table . " WHERE post_id = %d", array($master_post_id));
2599
    $data = (array)$wpdb->get_row($query);
2600
2601
    if ( !empty( $data ) ) {
2602
        $data['post_id'] = $tr_post_id;
2603
        unset($data['default_category'], $data['marker_json'], $data['featured_image'], $data[$post_type . 'category'], $data['overall_rating'], $data['rating_count'], $data['ratings']);
2604
        
2605
        $wpdb->update($post_table, $data, array('post_id' => $tr_post_id));		
2606
        return true;
2607
    }
2608
2609
    return false;
2610
}
2611
2612
/**
2613
 * Duplicate post taxonomies for WPML translation post.
2614
 *
2615
 * @since 1.5.0
2616
 *
2617
 * @global object $sitepress Sitepress WPML object.
2618
 * @global object $wpdb WordPress Database object.
2619
 *
2620
 * @param int $master_post_id Original Post ID.
2621
 * @param int $tr_post_id Translation Post ID.
2622
 * @param string $lang Language code for translating post.
2623
 * @return bool True for success, False for fail.
2624
 */
2625
function geodir_icl_duplicate_taxonomies($master_post_id, $tr_post_id, $lang) {
2626
    global $sitepress, $wpdb;
2627
    $post_type = get_post_type($master_post_id);
2628
2629
    remove_filter('get_term', array($sitepress,'get_term_adjust_id')); // AVOID filtering to current language
2630
2631
    $taxonomies = get_object_taxonomies($post_type);
2632
    foreach ($taxonomies as $taxonomy) {
2633
        $terms = get_the_terms($master_post_id, $taxonomy);
2634
        $terms_array = array();
2635
        
2636
        if ($terms) {
2637
            foreach ($terms as $term) {
2638
                $tr_id = apply_filters( 'translate_object_id',$term->term_id, $taxonomy, false, $lang);
2639
                
2640
                if (!is_null($tr_id)){
2641
                    // not using get_term - unfiltered get_term
2642
                    $translated_term = $wpdb->get_row($wpdb->prepare("
2643
                        SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id = t.term_id WHERE t.term_id = %d AND x.taxonomy = %s", $tr_id, $taxonomy));
2644
2645
                    $terms_array[] = $translated_term->term_id;
2646
                }
2647
            }
2648
2649
            if (!is_taxonomy_hierarchical($taxonomy)){
2650
                $terms_array = array_unique( array_map( 'intval', $terms_array ) );
2651
            }
2652
2653
            wp_set_post_terms($tr_post_id, $terms_array, $taxonomy);
2654
            
2655
            if ($taxonomy == $post_type . 'category') {
2656
                geodir_set_postcat_structure($tr_post_id, $post_type . 'category');
2657
            }
2658
        }
2659
    }
2660
}
2661
2662
/**
2663
 * Duplicate post images for WPML translation post.
2664
 *
2665
 * @since 1.5.0
2666
 *
2667
 * @global object $wpdb WordPress Database object.
2668
 *
2669
 * @param int $master_post_id Original Post ID.
2670
 * @param int $tr_post_id Translation Post ID.
2671
 * @param string $lang Language code for translating post.
2672
 * @return bool True for success, False for fail.
2673
 */
2674
function geodir_icl_duplicate_post_images($master_post_id, $tr_post_id, $lang) {
0 ignored issues
show
Unused Code introduced by
The parameter $lang is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2675
    global $wpdb;
2676
2677
    $query = $wpdb->prepare("DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d", array('%image%', $tr_post_id));
2678
    $wpdb->query($query);
2679
2680
    $query = $wpdb->prepare("SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d ORDER BY menu_order ASC", array('%image%', $master_post_id));
2681
    $post_images = $wpdb->get_results($query);
2682
2683
    if ( !empty( $post_images ) ) {
2684
        foreach ( $post_images as $post_image) {
2685
            $image_data = (array)$post_image;
2686
            unset($image_data['ID']);
2687
            $image_data['post_id'] = $tr_post_id;
2688
            
2689
            $wpdb->insert(GEODIR_ATTACHMENT_TABLE, $image_data);
2690
            
2691
            geodir_set_wp_featured_image($tr_post_id);
2692
        }
2693
        
2694
        return true;
2695
    }
2696
2697
    return false;
2698
}
2699
2700
2701
/**
2702
 * Duplicate post review for WPML translation post.
2703
 *
2704
 * @since 1.6.16
2705
 *
2706
 * @global object $wpdb WordPress Database object.
2707
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2708
 *
2709
 * @param int $master_comment_id Original Comment ID.
2710
 * @param int $master_post_id Original Post ID.
2711
 * @param int $tr_post_id Translation Post ID.
2712
 * @param string $lang Language code for translating post.
2713
 * @return bool True for success, False for fail.
2714
 */
2715
function geodir_wpml_duplicate_post_review($master_comment_id, $master_post_id, $tr_post_id, $lang) {
2716
    global $wpdb, $plugin_prefix;
2717
2718
    $review = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id=%d ORDER BY id ASC", $master_comment_id), ARRAY_A);
2719
2720
    if (empty($review)) {
2721
        return false;
2722
    }
2723
    if ($review['post_id'] != $master_post_id) {
2724
        $wpdb->query($wpdb->prepare("UPDATE " . GEODIR_REVIEW_TABLE . " SET post_id=%d WHERE comment_id=%d", $master_post_id, $master_comment_id));
2725
        geodir_update_postrating($master_post_id, $post_type);
0 ignored issues
show
Bug introduced by
The variable $post_type seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
2726
    }
2727
2728
    $tr_comment_id = geodir_wpml_duplicate_comment_exists($tr_post_id, $master_comment_id);
2729
2730
    if (empty($tr_comment_id)) {
2731
        return false;
2732
    }
2733
2734
    $post_type = get_post_type($master_post_id);
2735
    $post_table = $plugin_prefix . $post_type . '_detail';
2736
2737
    $translated_post = $wpdb->get_row($wpdb->prepare("SELECT post_title, post_latitude, post_longitude, post_city, post_region, post_country FROM " . $post_table . " WHERE post_id = %d", $tr_post_id), ARRAY_A);
2738
    if (empty($translated_post)) {
2739
        return false;
2740
    }
2741
2742
    $review['comment_id'] = $tr_comment_id;
2743
    $review['post_id'] = $tr_post_id;
2744
    $review['post_title'] = $translated_post['post_title'];
2745
    $review['post_city'] = $translated_post['post_city'];
2746
    $review['post_region'] = $translated_post['post_region'];
2747
    $review['post_country'] = $translated_post['post_country'];
2748
    $review['post_latitude'] = $translated_post['post_latitude'];
2749
    $review['post_longitude'] = $translated_post['post_longitude'];
2750
2751
    if (isset($review['id'])) {
2752
        unset($review['id']);
2753
    }
2754
2755
    $tr_review_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id=%d AND post_id=%d ORDER BY id ASC", $tr_comment_id, $tr_post_id));
2756
2757
    if ($tr_review_id) { // update review
2758
        $wpdb->update(GEODIR_REVIEW_TABLE, $review, array('id' => $$tr_review_id));
2759
    } else { // insert review
2760
        $wpdb->insert(GEODIR_REVIEW_TABLE, $review);
2761
        $tr_review_id = $wpdb->insert_id;
2762
    }
2763
2764
    if ($tr_post_id) {
2765
        geodir_update_postrating($tr_post_id, $post_type);
2766
    }
2767
2768
    return $tr_review_id;
2769
}
2770
2771
/**
2772
 * Synchronize review for WPML translation post.
2773
 *
2774
 * @since 1.6.16
2775
 *
2776
 * @global object $wpdb WordPress Database object.
2777
 * @global object $sitepress Sitepress WPML object.
2778
 * @global array $gd_wpml_posttypes Geodirectory post types array.
2779
 *
2780
 * @param int $comment_id The Comment ID.
2781
 */
2782
function gepdir_wpml_sync_comment($comment_id) {
2783
    global $wpdb, $sitepress, $gd_wpml_posttypes;
2784
2785
    if (empty($gd_post_types)) {
0 ignored issues
show
Bug introduced by
The variable $gd_post_types seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
2786
        $gd_wpml_posttypes = geodir_get_posttypes();
2787
    }
2788
2789
    $comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID=%d", $comment_id), ARRAY_A);
2790
    if (empty($comment)) {
2791
        return;
2792
    }
2793
2794
    $post_id = $comment['comment_post_ID'];
2795
    $post_type = $post_id ? get_post_type($post_id) : NULL;
2796
2797
    if (!($post_type && in_array($post_type, $gd_wpml_posttypes))) {
2798
        return;
2799
    }
2800
2801
    $post_duplicates = $sitepress->get_duplicates($post_id);
2802
    if (empty($post_duplicates)) {
2803
        return;
2804
    }
2805
2806
    foreach ($post_duplicates as $lang => $dup_post_id) {
2807
        if (empty($comment['comment_parent'])) {
2808
            geodir_wpml_duplicate_post_review($comment_id, $post_id, $dup_post_id, $lang);
2809
        }
2810
    }
2811
    
2812
    return true;
2813
}
2814
2815
/**
2816
 * Get the WPML duplicate comment ID of the comment.
2817
 *
2818
 * @since 1.6.16
2819
 *
2820
 * @global object $dup_post_id WordPress Database object.
2821
 *
2822
 * @param int $dup_post_id The duplicate post ID.
2823
 * @param int $original_cid The original Comment ID.
2824
 * @return int The duplicate comment ID.
2825
 */
2826
function geodir_wpml_duplicate_comment_exists($dup_post_id, $original_cid) {
2827
    global $wpdb;
2828
2829
    $duplicate = $wpdb->get_var(
2830
        $wpdb->prepare(
2831
            "   SELECT comm.comment_ID
2832
                FROM {$wpdb->comments} comm
2833
                JOIN {$wpdb->commentmeta} cm
2834
                    ON comm.comment_ID = cm.comment_id
2835
                WHERE comm.comment_post_ID = %d
2836
                    AND cm.meta_key = '_icl_duplicate_of'
2837
                    AND cm.meta_value = %d
2838
                LIMIT 1",
2839
            $dup_post_id,
2840
            $original_cid
2841
        )
2842
    );
2843
2844
    return $duplicate;
2845
}