Test Failed
Pull Request — master (#315)
by Kiran
17:19
created

general_functions.php ➔ geodir_wpseo_replacements()   B

Complexity

Conditions 6
Paths 17

Size

Total Lines 57
Code Lines 18

Duplication

Lines 14
Ratio 24.56 %

Code Coverage

Tests 27
CRAP Score 6.0359

Importance

Changes 0
Metric Value
cc 6
eloc 18
nc 17
nop 1
dl 14
loc 57
ccs 27
cts 30
cp 0.9
crap 6.0359
rs 8.7433
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Plugin general functions
4
 *
5
 * @since   1.0.0
6
 * @package GeoDirectory
7
 */
8
9
10
/**
11
 * Get All Plugin functions from WordPress
12
 */
13
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
14
15
/*-----------------------------------------------------------------------------------*/
16
/* Helper functions */
17
/*-----------------------------------------------------------------------------------*/
18
19
/**
20
 * Return the plugin url.
21
 *
22
 * Return the plugin folder url WITHOUT TRAILING SLASH.
23
 *
24
 * @since   1.0.0
25
 * @package GeoDirectory
26
 * @return string example url eg: http://wpgeo.directory/wp-content/plugins/geodirectory
27
 */
28
function geodir_plugin_url() {
29
30
	if ( is_ssl() ) :
31 21
		return str_replace( 'http://', 'https://', WP_PLUGIN_URL ) . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) );
32
	else :
33
		return WP_PLUGIN_URL . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) );
34 21
	endif;
35
}
36
37
38
/**
39
 * Return the plugin path.
40
 *
41
 * Return the plugin folder path WITHOUT TRAILING SLASH.
42
 *
43
 * @since   1.0.0
44
 * @package GeoDirectory
45
 * @return string example url eg: /home/geo/public_html/wp-content/plugins/geodirectory
46
 */
47
function geodir_plugin_path() {
48
	if ( defined( 'GD_TESTING_MODE' ) && GD_TESTING_MODE ) {
49
		return dirname( dirname( __FILE__ ) );
50 34
	} else {
51 34
		return WP_PLUGIN_DIR . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) );
52
	}
53
}
54
55
/**
56
 * Check if a GeoDirectory addon plugin is active.
57
 *
58
 * @since   1.0.0
59
 * @package GeoDirectory
60
 *
61
 * @param string $plugin plugin uri.
62
 *
63
 * @return bool true or false.
64
 * @todo    check if this is faster than normal WP check and remove if not.
65
 */
66
function geodir_is_plugin_active( $plugin ) {
67
	$active_plugins = get_option( 'active_plugins' );
68
	foreach ( $active_plugins as $key => $active_plugin ) {
69
		if ( strstr( $active_plugin, $plugin ) ) {
70
			return true;
71
		}
72
	}
73
74
	return false;
75
}
76
77
78
/**
79
 * Return the formatted date.
80
 *
81
 * Return a formatted date from a date/time string according to WordPress date format. $date must be in format : 'Y-m-d
82
 * H:i:s'.
83
 *
84
 * @since   1.0.0
85
 * @package GeoDirectory
86
 *
87
 * @param string $date must be in format: 'Y-m-d H:i:s'.
88
 *
89
 * @return bool|int|string the formatted date.
90
 */
91
function geodir_get_formated_date( $date ) {
0 ignored issues
show
Best Practice introduced by
The function geodir_get_formated_date() has been defined more than once; this definition is ignored, only the first definition in geodirectory-functions/custom_fields_functions.php (L1513-1516) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
92
	return mysql2date( get_option( 'date_format' ), $date );
93
}
94
95
/**
96
 * Return the formatted time.
97
 *
98
 * Return a formatted time from a date/time string according to WordPress time format. $time must be in format : 'Y-m-d
99
 * H:i:s'.
100
 *
101
 * @since   1.0.0
102
 * @package GeoDirectory
103
 *
104
 * @param string $time must be in format: 'Y-m-d H:i:s'.
105
 *
106
 * @return bool|int|string the formatted time.
107
 */
108
function geodir_get_formated_time( $time ) {
0 ignored issues
show
Best Practice introduced by
The function geodir_get_formated_time() has been defined more than once; this definition is ignored, only the first definition in geodirectory-functions/custom_fields_functions.php (L1528-1531) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
109
	return mysql2date( get_option( 'time_format' ), $time, $translate = true );
110
}
111
112
113
/**
114
 * Return a formatted link with parameters.
115
 *
116
 * Returns a link with new parameters and currently used parameters regardless of ? or & in the $url parameter.
117
 *
118
 * @since   1.0.0
119
 * @package GeoDirectory
120
 *
121 15
 * @param string $url                  The main url to be used.
122 15
 * @param array $params                The arguments array.
123 15
 * @param bool $use_existing_arguments Do you want to use existing arguments? Default: false.
124 15
 *
125 15
 * @return string Formatted link.
126 15
 */
127
function geodir_getlink( $url, $params = array(), $use_existing_arguments = false ) {
128 15
	if ( $use_existing_arguments ) {
129 15
		$params = $params + $_GET;
130 15
	}
131
	if ( ! $params ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $params of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
132
		return $url;
133
	}
134
	$link = $url;
135 15
	if ( strpos( $link, '?' ) === false ) {
136
		$link .= '?';
137 15
	} //If there is no '?' add one at the end
138 15
	elseif ( strpos( $link, '//maps.google.com/maps/api/js?language=' ) ) {
139
		$link .= '&amp;';
140 15
	} //If there is no '&' at the END, add one.
141
	elseif ( ! preg_match( '/(\?|\&(amp;)?)$/', $link ) ) {
142
		$link .= '&';
143
	} //If there is no '&' at the END, add one.
144
145
	$params_arr = array();
146
	foreach ( $params as $key => $value ) {
147
		if ( gettype( $value ) == 'array' ) { //Handle array data properly
148
			foreach ( $value as $val ) {
149
				$params_arr[] = $key . '[]=' . urlencode( $val );
150
			}
151
		} else {
152
			$params_arr[] = $key . '=' . urlencode( $value );
153
		}
154
	}
155 3
	$link .= implode( '&', $params_arr );
156
157
	return $link;
158 3
}
159 3
160
161 3
/**
162
 * Returns add listing page link.
163 3
 *
164
 * @since   1.0.0
165
 * @package GeoDirectory
166
 * @global object $wpdb     WordPress Database object.
167
 *
168
 * @param string $post_type The post type.
169
 *
170
 * @return string Listing page url if valid. Otherwise home url will be returned.
171
 */
172
function geodir_get_addlisting_link( $post_type = '' ) {
173
	global $wpdb;
174
175
	//$check_pkg  = $wpdb->get_var("SELECT pid FROM ".GEODIR_PRICE_TABLE." WHERE post_type='".$post_type."' and status != '0'");
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
176
	$check_pkg = 1;
177
	if ( post_type_exists( $post_type ) && $check_pkg ) {
178 9
179 9
		$add_listing_link = get_page_link( geodir_add_listing_page_id() );
180
181
		return esc_url( add_query_arg( array( 'listing_type' => $post_type ), $add_listing_link ) );
182 9
	} else {
183 9
		return get_bloginfo( 'url' );
184
	}
185
}
186
187
/**
188
 * Get the current page URL.
189
 *
190 9
 * @since   1.0.0
191
 * @package GeoDirectory
192
 * @since   1.4.2 Removed the port number from the URL if port 80 is not being used.
193
 * @since   1.6.9 Fix $_SERVER['SERVER_NAME'] with nginx server.
194
 * @return string The current URL.
195
 */
196
function geodir_curPageURL() {
197
	$pageURL = 'http';
198
	if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) == 'on')) {
199
		$pageURL .= "s";
200
	}
201
	$pageURL .= "://";
202
	
203
	/*
204
	 * Since we are assigning the URI from the server variables, we first need
205
	 * to determine if we are running on apache or IIS.  If PHP_SELF and REQUEST_URI
206
	 * are present, we will assume we are running on apache.
207
	 */
208
	if (!empty($_SERVER['PHP_SELF']) && !empty($_SERVER['REQUEST_URI'])) {
209
		// To build the entire URI we need to prepend the protocol, and the http host
210
		// to the URI string.
211
		$pageURL .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
212
	} else {
213
		/*
214
		 * Since we do not have REQUEST_URI to work with, we will assume we are
215
		 * running on IIS and will therefore need to work some magic with the SCRIPT_NAME and
216
		 * QUERY_STRING environment variables.
217
		 *
218
		 * IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS
219
		 */
220
		$pageURL .= $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
221
		
222
		// If the query string exists append it to the URI string
223
		if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
224
			$pageURL .= '?' . $_SERVER['QUERY_STRING'];
225
		}
226
	}
227
	
228
	/**
229
	 * Filter the current page URL returned by function geodir_curPageURL().
230
	 *
231
	 * @since 1.4.1
232
	 *
233
	 * @param string $pageURL The URL of the current page.
234
	 */
235
	return apply_filters( 'geodir_curPageURL', $pageURL );
236
}
237
238
/**
239
 * Clean variables.
240
 *
241
 * This function is used to create posttype, posts, taxonomy and terms slug.
242
 *
243
 * @since   1.0.0
244
 * @package GeoDirectory
245
 *
246
 * @param string $string The variable to clean.
247
 *
248
 * @return string Cleaned variable.
249
 */
250
function geodir_clean( $string ) {
251
252
	$string = trim( strip_tags( stripslashes( $string ) ) );
253
	$string = str_replace( " ", "-", $string ); // Replaces all spaces with hyphens.
254
	$string = preg_replace( '/[^A-Za-z0-9\-\_]/', '', $string ); // Removes special chars.
255 28
	$string = preg_replace( '/-+/', '-', $string ); // Replaces multiple hyphens with single one.
256
257
	return $string;
258
}
259 28
260
/**
261 25
 * Get Week Days list.
262 1
 *
263 24
 * @since   1.0.0
264
 * @package GeoDirectory
265
 * @return array Week days.
266
 */
267 24
function geodir_get_weekday() {
268 27
	return array(
269 22
		__( 'Sunday', 'geodirectory' ),
270 22
		__( 'Monday', 'geodirectory' ),
271 1
		__( 'Tuesday', 'geodirectory' ),
272 22
		__( 'Wednesday', 'geodirectory' ),
273 21
		__( 'Thursday', 'geodirectory' ),
274 27
		__( 'Friday', 'geodirectory' ),
275 6
		__( 'Saturday', 'geodirectory' )
276 6
	);
277 5
}
278 27
279 12
/**
280 12
 * Get Weeks lists.
281 12
 *
282 12
 * @since   1.0.0
283 10
 * @package GeoDirectory
284 26
 * @return array Weeks.
285 7
 */
286 7
function geodir_get_weeks() {
287 7
	return array(
288 7
		__( 'First', 'geodirectory' ),
289
		__( 'Second', 'geodirectory' ),
290 7
		__( 'Third', 'geodirectory' ),
291 26
		__( 'Fourth', 'geodirectory' ),
292 12
		__( 'Last', 'geodirectory' )
293
	);
294
}
295
296
297 12
/**
298 12
 * Check that page is.
299 12
 *
300 12
 * @since   1.0.0
301
 * @since   1.5.6 Added to check GD invoices and GD checkout pages.
302 12
 * @since   1.5.7 Updated to validate buddypress dashboard listings page as a author page.
303 25
 * @package GeoDirectory
304
 * @global object $wp_query WordPress Query object.
305 8
 * @global object $post     The current post object.
306 8
 *
307
 * @param string $gdpage    The page type.
308 9
 *
309 25
 * @return bool If valid returns true. Otherwise false.
310 7
 */
311 7
function geodir_is_page( $gdpage = '' ) {
312 6
313 25
	global $wp_query, $post, $wp;
314 24
	//if(!is_admin()):
0 ignored issues
show
Unused Code Comprehensibility introduced by
88% 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...
315 24
316
	switch ( $gdpage ):
317 24
		case 'add-listing':
318
319
			if ( is_page() && get_query_var( 'page_id' ) == geodir_add_listing_page_id() ) {
320
				return true;
321
			} elseif ( is_page() && isset( $post->post_content ) && has_shortcode( $post->post_content, 'gd_add_listing' ) ) {
322 24
				return true;
323 25
			}
324 24
325 24
			break;
326 23
		case 'preview':
327 10
			if ( ( is_page() && get_query_var( 'page_id' ) == geodir_preview_page_id() ) && isset( $_REQUEST['listing_type'] )
328 1
			     && in_array( $_REQUEST['listing_type'], geodir_get_posttypes() )
329 1
			) {
330 1
				return true;
331 9
			}
332 9
			break;
333 9
		case 'listing-success':
334 9
			if ( is_page() && get_query_var( 'page_id' ) == geodir_success_page_id() ) {
335 7
				return true;
336
			}
337
			break;
338 View Code Duplication
		case 'detail':
339 7
			$post_type = get_query_var( 'post_type' );
340
			if ( is_array( $post_type ) ) {
341
				$post_type = reset( $post_type );
342
			}
343 7
			if ( is_single() && in_array( $post_type, geodir_get_posttypes() ) ) {
344 7
				return true;
345
			}
346
			break;
347 7 View Code Duplication
		case 'pt':
348
			$post_type = get_query_var( 'post_type' );
349
			if ( is_array( $post_type ) ) {
350
				$post_type = reset( $post_type );
351 28
			}
352
			if ( is_post_type_archive() && in_array( $post_type, geodir_get_posttypes() ) && ! is_tax() ) {
353
				return true;
354
			}
355
356
			break;
357
		case 'listing':
358
			if ( is_tax() && geodir_get_taxonomy_posttype() ) {
359
				global $current_term, $taxonomy, $term;
360
361
				return true;
362
			}
363
			$post_type = get_query_var( 'post_type' );
364
			if ( is_array( $post_type ) ) {
365
				$post_type = reset( $post_type );
366
			}
367
			if ( is_post_type_archive() && in_array( $post_type, geodir_get_posttypes() ) ) {
368
				return true;
369
			}
370
371
			break;
372
		case 'home':
373
374
			if ( ( is_page() && get_query_var( 'page_id' ) == geodir_home_page_id() ) || is_page_geodir_home() ) {
375
				return true;
376
			}
377
378
			break;
379
		case 'location':
380
			if ( is_page() && get_query_var( 'page_id' ) == geodir_location_page_id() ) {
381
				return true;
382
			}
383
			break;
384
		case 'author':
385
			if ( is_author() && isset( $_REQUEST['geodir_dashbord'] ) ) {
386
				return true;
387
			}
388
389
			if ( function_exists( 'bp_loggedin_user_id' ) && function_exists( 'bp_displayed_user_id' ) && $my_id = (int) bp_loggedin_user_id() ) {
390
				if ( ( (bool) bp_is_current_component( 'listings' ) || (bool) bp_is_current_component( 'favorites' ) ) && $my_id > 0 && $my_id == (int) bp_displayed_user_id() ) {
391
					return true;
392
				}
393
			}
394
			break;
395
		case 'search':
396
			if ( is_search() && isset( $_REQUEST['geodir_search'] ) ) {
397
				return true;
398
			}
399
			break;
400
		case 'info':
401
			if ( is_page() && get_query_var( 'page_id' ) == geodir_info_page_id() ) {
402
				return true;
403
			}
404
			break;
405
		case 'login':
406
			if ( is_page() && get_query_var( 'page_id' ) == geodir_login_page_id() ) {
407
				return true;
408
			}
409
			break;
410
		case 'checkout':
411 View Code Duplication
			if ( is_page() && function_exists( 'geodir_payment_checkout_page_id' ) && get_query_var( 'page_id' ) == geodir_payment_checkout_page_id() ) {
412
				return true;
413
			}
414
			break;
415
		case 'invoices':
416 View Code Duplication
			if ( is_page() && function_exists( 'geodir_payment_invoices_page_id' ) && get_query_var( 'page_id' ) == geodir_payment_invoices_page_id() ) {
417
				return true;
418
			}
419
			break;
420
		default:
421
			return false;
422
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
423
424
	endswitch;
425
426
	//endif;
427
428
	return false;
429
}
430
431
/**
432
 * Sets a key and value in $wp object if the current page is a geodir page.
433
 *
434
 * @since   1.0.0
435
 * @since   1.5.4 Added check for new style GD homepage.
436
 * @since   1.5.6 Added check for GD invoices and GD checkout page.
437
 * @package GeoDirectory
438
 *
439
 * @param object $wp WordPress object.
440
 */
441
function geodir_set_is_geodir_page( $wp ) {
442
	if ( ! is_admin() ) {
443
		//$wp->query_vars['gd_is_geodir_page'] = false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
444
		//print_r()
445
		if ( empty( $wp->query_vars ) || ! array_diff( array_keys( $wp->query_vars ), array(
446
				'preview',
447
				'page',
448
				'paged',
449
				'cpage'
450
			) )
451
		) {
452
			if ( geodir_is_page( 'home' ) ) {
453
				$wp->query_vars['gd_is_geodir_page'] = true;
454
			}
455
456
457
		}
458
459
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $wp->query_vars['page_id'] ) ) {
460
			if (
461
				$wp->query_vars['page_id'] == geodir_add_listing_page_id()
462
				|| $wp->query_vars['page_id'] == geodir_preview_page_id()
463
				|| $wp->query_vars['page_id'] == geodir_success_page_id()
464
				|| $wp->query_vars['page_id'] == geodir_location_page_id()
465
				|| $wp->query_vars['page_id'] == geodir_home_page_id()
466
				|| $wp->query_vars['page_id'] == geodir_info_page_id()
467
				|| $wp->query_vars['page_id'] == geodir_login_page_id()
468 30
				|| ( function_exists( 'geodir_payment_checkout_page_id' ) && $wp->query_vars['page_id'] == geodir_payment_checkout_page_id() )
469 30
				|| ( function_exists( 'geodir_payment_invoices_page_id' ) && $wp->query_vars['page_id'] == geodir_payment_invoices_page_id() )
470 30
			) {
471
				$wp->query_vars['gd_is_geodir_page'] = true;
472 30
			}
473
		}
474
475
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $wp->query_vars['pagename'] ) ) {
476
			$page = get_page_by_path( $wp->query_vars['pagename'] );
477
478
			if ( ! empty( $page ) && (
479
					$page->ID == geodir_add_listing_page_id()
480
					|| $page->ID == geodir_preview_page_id()
481
					|| $page->ID == geodir_success_page_id()
482
					|| $page->ID == geodir_location_page_id()
483
					|| ( isset( $wp->query_vars['page_id'] ) && $wp->query_vars['page_id'] == geodir_home_page_id() )
484
					|| ( isset( $wp->query_vars['page_id'] ) && $wp->query_vars['page_id'] == geodir_info_page_id() )
485
					|| ( isset( $wp->query_vars['page_id'] ) && $wp->query_vars['page_id'] == geodir_login_page_id() )
486
					|| ( isset( $wp->query_vars['page_id'] ) && function_exists( 'geodir_payment_checkout_page_id' ) && $wp->query_vars['page_id'] == geodir_payment_checkout_page_id() )
487 9
					|| ( isset( $wp->query_vars['page_id'] ) && function_exists( 'geodir_payment_invoices_page_id' ) && $wp->query_vars['page_id'] == geodir_payment_invoices_page_id() )
488 9
				)
489 9
			) {
490 9
				$wp->query_vars['gd_is_geodir_page'] = true;
491 9
			}
492
		}
493
494
495
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $wp->query_vars['post_type'] ) && $wp->query_vars['post_type'] != '' ) {
496
			$requested_post_type = $wp->query_vars['post_type'];
497
			// check if this post type is geodirectory post types
498
			$post_type_array = geodir_get_posttypes();
499 9
			if ( in_array( $requested_post_type, $post_type_array ) ) {
500
				$wp->query_vars['gd_is_geodir_page'] = true;
501 9
			}
502
		}
503
504
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) ) {
505
			$geodir_taxonomis = geodir_get_taxonomies( '', true );
506
			if ( ! empty( $geodir_taxonomis ) ) {
507
				foreach ( $geodir_taxonomis as $taxonomy ) {
0 ignored issues
show
Bug introduced by
The expression $geodir_taxonomis 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...
508 9
					if ( array_key_exists( $taxonomy, $wp->query_vars ) ) {
509
						$wp->query_vars['gd_is_geodir_page'] = true;
510
						break;
511
					}
512
				}
513
			}
514
515
		}
516
517
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $wp->query_vars['author_name'] ) && isset( $_REQUEST['geodir_dashbord'] ) ) {
518
			$wp->query_vars['gd_is_geodir_page'] = true;
519
		}
520
521
522
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $_REQUEST['geodir_search'] ) ) {
523
			$wp->query_vars['gd_is_geodir_page'] = true;
524
		}
525
526
527
//check if homepage
528
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] )
529
		     && ! isset( $wp->query_vars['page_id'] )
530
		     && ! isset( $wp->query_vars['pagename'] )
531
		     && is_page_geodir_home()
532
		) {
533
			$wp->query_vars['gd_is_geodir_page'] = true;
534
		}
535
		//echo $wp->query_vars['gd_is_geodir_page'] ;
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...
536
		/*echo "<pre>" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
537
		print_r($wp) ;
538
		echo "</pre>" ;
539
	//	exit();
540
			*/
541
	} // end of is admin
542
}
543
544
/**
545
 * Checks whether the current page is a GD page or not.
546
 *
547
 * @since   1.0.0
548
 * @package GeoDirectory
549
 * @global object $wp WordPress object.
550
 * @return bool If the page is GD page returns true. Otherwise false.
551
 */
552
function geodir_is_geodir_page() {
553
	global $wp;
554
	if ( isset( $wp->query_vars['gd_is_geodir_page'] ) && $wp->query_vars['gd_is_geodir_page'] ) {
555
		return true;
556
	} else {
557
		return false;
558
	}
559
}
560
561
if ( ! function_exists( 'geodir_get_imagesize' ) ) {
562
	/**
563
	 * Get image size using the size key .
564
	 *
565
	 * @since   1.0.0
566
	 * @package GeoDirectory
567
	 *
568
	 * @param string $size The image size key.
569
	 *
570
	 * @return array|mixed|void|WP_Error If valid returns image size. Else returns error.
571
	 */
572 1
	function geodir_get_imagesize( $size = '' ) {
573 1
574
		$imagesizes = array(
575
			'list-thumb'   => array( 'w' => 283, 'h' => 188 ),
576 1
			'thumbnail'    => array( 'w' => 125, 'h' => 125 ),
577 1
			'widget-thumb' => array( 'w' => 50, 'h' => 50 ),
578
			'slider-thumb' => array( 'w' => 100, 'h' => 100 )
579
		);
580 1
581 1
		/**
582 1
		 * Filter the image sizes array.
583
		 *
584
		 * @since 1.0.0
585
		 *
586
		 * @param array $imagesizes Image size array.
587
		 */
588
		$imagesizes = apply_filters( 'geodir_imagesizes', $imagesizes );
589
590
		if ( ! empty( $size ) && array_key_exists( $size, $imagesizes ) ) {
591
			/**
592
			 * Filters image size of the passed key.
593
			 *
594
			 * @since 1.0.0
595
			 *
596
			 * @param array $imagesizes [$size] Image size array of the passed key.
597 1
			 */
598 1
			return apply_filters( 'geodir_get_imagesize_' . $size, $imagesizes[ $size ] );
599
600
		} elseif ( ! empty( $size ) ) {
601
602
			return new WP_Error( 'geodir_no_imagesize', __( "Given image size is not valid", 'geodirectory' ) );
603
604
		}
605
606
		return $imagesizes;
607
	}
608
}
609
610
/**
611
 * Get an image size
612
 *
613
 * Variable is filtered by geodir_get_image_size_{image_size}
614
 */
615
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
616
function geodir_get_image_size( $image_size ) {
617
	$return = '';
618 1
	switch ($image_size) :
619
		case "list_thumbnail_size" : $return = get_option('geodirectory_list_thumbnail_size'); break;
620 1
	endswitch;
621 1
	return apply_filters( 'geodir_get_image_size_'.$image_size, $return );
622 1
}
623 1
*/
624 1
625 1
626 1
if ( ! function_exists( 'createRandomString' ) ) {
627 1
	/**
628
	 * Creates random string.
629
	 *
630
	 * @since   1.0.0
631
	 * @package GeoDirectory
632
	 * @return string Random string.
633
	 */
634
	function createRandomString() {
635
		$chars = "abcdefghijkmlnopqrstuvwxyz1023456789";
636
		srand( (double) microtime() * 1000000 );
637
		$i       = 0;
638
		$rstring = '';
639
		while ( $i <= 25 ) {
640
			$num     = rand() % 33;
641
			$tmp     = substr( $chars, $num, 1 );
642
			$rstring = $rstring . $tmp;
643
			$i ++;
644
		}
645
646
		return $rstring;
647
	}
648
}
649
650
if ( ! function_exists( 'geodir_getDistanceRadius' ) ) {
651
	/**
652 9
	 * Calculates the distance radius.
653
	 *
654
	 * @since   1.0.0
655 9
	 * @package GeoDirectory
656 9
	 *
657
	 * @param string $uom Measurement unit type.
658 9
	 *
659 2
	 * @return float The mean radius.
660 2
	 */
661 9
	function geodir_getDistanceRadius( $uom = 'km' ) {
662 2
//	Use Haversine formula to calculate the great circle distance between two points identified by longitude and latitude
663 2
		switch ( geodir_strtolower( $uom ) ):
664 7
			case 'km'    :
665 1
				$earthMeanRadius = 6371.009; // km
666 1
				break;
667 1
			case 'm'    :
668 5
			case 'meters'    :
669 2
				$earthMeanRadius = 6371.009 * 1000; // km
670 2
				break;
671 2
			case 'miles'    :
672 4
				$earthMeanRadius = 3958.761; // miles
673 1
				break;
674 1
			case 'yards'    :
675 2
			case 'yds'    :
676 1
				$earthMeanRadius = 3958.761 * 1760; // yards
677 1
				break;
678 1
			case 'feet'    :
679
			case 'ft'    :
680
				$earthMeanRadius = 3958.761 * 1760 * 3; // feet
681
				break;
682
			case 'nm'    :
683 9
				$earthMeanRadius = 3440.069; //  miles
684 9
				break;
685 9
			default:
686
				$earthMeanRadius = 3958.761; // miles
687 9
				break;
688 9
		endswitch;
689 9
690
		return $earthMeanRadius;
691 9
	}
692 9
}
693 9
694 9
695
if ( ! function_exists( 'geodir_calculateDistanceFromLatLong' ) ) {
696 9
	/**
697 9
	 * Calculate the great circle distance between two points identified by longitude and latitude.
698 1
	 *
699 1
	 * @since   1.0.0
700
	 * @package GeoDirectory
701 9
	 *
702 9
	 * @param array $point1 Latitude and Longitude of point 1.
703
	 * @param array $point2 Latitude and Longitude of point 2.
704 9
	 * @param string $uom   Unit of measurement.
705
	 *
706 9
	 * @return float The distance.
707 2
	 */
708 2
	function geodir_calculateDistanceFromLatLong( $point1, $point2, $uom = 'km' ) {
709 2
//	Use Haversine formula to calculate the great circle distance between two points identified by longitude and latitude
710 9
711 9
		$earthMeanRadius = geodir_getDistanceRadius( $uom );
712 9
713 9
		$deltaLatitude  = deg2rad( (float) $point2['latitude'] - (float) $point1['latitude'] );
714
		$deltaLongitude = deg2rad( (float) $point2['longitude'] - (float) $point1['longitude'] );
715 9
		$a              = sin( $deltaLatitude / 2 ) * sin( $deltaLatitude / 2 ) +
716 9
		                  cos( deg2rad( (float) $point1['latitude'] ) ) * cos( deg2rad( (float) $point2['latitude'] ) ) *
717 9
		                  sin( $deltaLongitude / 2 ) * sin( $deltaLongitude / 2 );
718
		$c              = 2 * atan2( sqrt( $a ), sqrt( 1 - $a ) );
719 9
		$distance       = $earthMeanRadius * $c;
720 6
721 6
		return $distance;
722
723 9
	}
724 6
}
725 6
726
727 9
if ( ! function_exists( 'geodir_sendEmail' ) ) {
728 9
	/**
729 9
	 * The main function that send transactional emails using the args provided.
730
	 *
731 9
	 * @since   1.0.0
732 9
	 * @since   1.5.7 Added db translations for notifications subject and content.
733 9
	 * @package GeoDirectory
734
	 *
735 9
	 * @param string $fromEmail     Sender email address.
736 9
	 * @param string $fromEmailName Sender name.
737 9
	 * @param string $toEmail       Receiver email address.
738 9
	 * @param string $toEmailName   Receiver name.
739
	 * @param string $to_subject    Email subject.
740 9
	 * @param string $to_message    Email content.
741
	 * @param string $extra         Not being used.
742
	 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
743
	 * @param string $post_id       The post ID.
744
	 * @param string $user_id       The user ID.
745
	 */
746
	function geodir_sendEmail( $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra = '', $message_type, $post_id = '', $user_id = '' ) {
747
		$login_details = '';
748
749
		// strip slashes from subject & message text
750
		$to_subject = stripslashes_deep( $to_subject );
751
		$to_message = stripslashes_deep( $to_message );
752
753
		if ( $message_type == 'send_friend' ) {
754
			$subject = get_option( 'geodir_email_friend_subject' );
755
			$message = get_option( 'geodir_email_friend_content' );
756
		} elseif ( $message_type == 'send_enquiry' ) {
757
			$subject = get_option( 'geodir_email_enquiry_subject' );
758
			$message = get_option( 'geodir_email_enquiry_content' );
759 9
760
			// change to name in some cases
761
			$post_author = get_post_field( 'post_author', $post_id );
762
			if(is_super_admin( $post_author  )){// if admin probably not the post author so change name
763
				$toEmailName = __('Business Owner','geodirectory');
764
			}elseif(defined('GEODIRCLAIM_VERSION') && geodir_get_post_meta($post_id,'claimed')!='1'){// if claim manager installed but listing not claimed
765
				$toEmailName = __('Business Owner','geodirectory');
766
			}
767
768
769
		} elseif ( $message_type == 'forgot_password' ) {
770
			$subject       = get_option( 'geodir_forgot_password_subject' );
771
			$message       = get_option( 'geodir_forgot_password_content' );
772
			$login_details = $to_message;
773
		} elseif ( $message_type == 'registration' ) {
774
			$subject       = get_option( 'geodir_registration_success_email_subject' );
775
			$message       = get_option( 'geodir_registration_success_email_content' );
776
			$login_details = $to_message;
777 9
		} elseif ( $message_type == 'post_submit' ) {
778
			$subject = get_option( 'geodir_post_submited_success_email_subject' );
779
			$message = get_option( 'geodir_post_submited_success_email_content' );
780
		} elseif ( $message_type == 'listing_published' ) {
781
			$subject = get_option( 'geodir_post_published_email_subject' );
782
			$message = get_option( 'geodir_post_published_email_content' );
783
		} elseif ( $message_type == 'listing_edited' ) {
784
			$subject = get_option( 'geodir_post_edited_email_subject_admin' );
785
			$message = get_option( 'geodir_post_edited_email_content_admin' );
786
		}
787
788
		if ( ! empty( $subject ) ) {
789
			$subject = __( stripslashes_deep( $subject ), 'geodirectory' );
790
		}
791
792
		if ( ! empty( $message ) ) {
793
			$message = __( stripslashes_deep( $message ), 'geodirectory' );
794
		}
795 9
796
		$to_message        = nl2br( $to_message );
797
		$sitefromEmail     = get_option( 'site_email' );
798
		$sitefromEmailName = get_site_emailName();
799
		$productlink       = get_permalink( $post_id );
800
801
		$user_login = '';
802
		if ( $user_id > 0 && $user_info = get_userdata( $user_id ) ) {
803
			$user_login = $user_info->user_login;
804
		}
805
806
		$posted_date = '';
807
		$listingLink = '';
808
809
		$post_info = get_post( $post_id );
810
811
		if ( $post_info ) {
812
			$posted_date = $post_info->post_date;
813 9
			$listingLink = '<a href="' . $productlink . '"><b>' . $post_info->post_title . '</b></a>';
814
		}
815 9
		$siteurl       = home_url();
816
		$siteurl_link  = '<a href="' . $siteurl . '">' . $siteurl . '</a>';
817 9
		$loginurl      = geodir_login_url();
818
		$loginurl_link = '<a href="' . $loginurl . '">login</a>';
819
820
		$post_author_id   = ! empty( $post_info ) ? $post_info->post_author : 0;
821
		$post_author_name = geodir_get_client_name( $post_author_id );
822
		$current_date     = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
823
824
		if ( $fromEmail == '' ) {
825
			$fromEmail = get_option( 'site_email' );
826
		}
827
828
		if ( $fromEmailName == '' ) {
829
			$fromEmailName = get_option( 'site_email_name' );
830
		}
831
832 9
		$search_array  = array(
833 9
			'[#listing_link#]',
834
			'[#site_name_url#]',
835 9
			'[#post_id#]',
836 9
			'[#site_name#]',
837 1
			'[#to_name#]',
838 1
			'[#from_name#]',
839
			'[#subject#]',
840 1
			'[#comments#]',
841 1
			'[#login_url#]',
842 1
			'[#login_details#]',
843
			'[#client_name#]',
844 1
			'[#posted_date#]',
845 1
			'[#from_email#]',
846 1
			'[#user_login#]',
847
			'[#username#]',
848 1
			'[#post_author_id#]',
849 1
			'[#post_author_name#]',
850
			'[#current_date#]'
851 1
		);
852 8
		$replace_array = array(
853 2
			$listingLink,
854 2
			$siteurl_link,
855 2
			$post_id,
856 6
			$sitefromEmailName,
857 2
			$toEmailName,
858 2
			$fromEmailName,
859 2
			$to_subject,
860 4
			$to_message,
861 2
			$loginurl_link,
862 2
			$login_details,
863 2
			$toEmailName,
864 2
			$posted_date,
865 1
			$fromEmail,
866 1
			$user_login,
867 1
			$user_login,
868
			$post_author_id,
869 9
			$post_author_name,
870 8
			$current_date
871
		);
872 8
		$message       = str_replace( $search_array, $replace_array, $message );
0 ignored issues
show
Bug introduced by
The variable $message 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...
873
874
		$search_array  = array(
875
			'[#listing_link#]',
876
			'[#site_name_url#]',
877
			'[#post_id#]',
878
			'[#site_name#]',
879
			'[#to_name#]',
880
			'[#from_name#]',
881
			'[#subject#]',
882
			'[#client_name#]',
883
			'[#posted_date#]',
884
			'[#from_email#]',
885 8
			'[#user_login#]',
886
			'[#username#]',
887 9
			'[#post_author_id#]',
888
			'[#post_author_name#]',
889
			'[#current_date#]'
890
		);
891
		$replace_array = array(
892
			$listingLink,
893
			$siteurl_link,
894
			$post_id,
895
			$sitefromEmailName,
896
			$toEmailName,
897
			$fromEmailName,
898
			$to_subject,
899
			$toEmailName,
900
			$posted_date,
901
			$fromEmail,
902
			$user_login,
903
			$user_login,
904
			$post_author_id,
905
			$post_author_name,
906
			$current_date
907
		);
908
		$subject       = str_replace( $search_array, $replace_array, $subject );
0 ignored issues
show
Bug introduced by
The variable $subject 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...
909
910
		$headers =  array();
911
		$headers[] = 'Content-type: text/html; charset=UTF-8';
912
		$headers[] = "Reply-To: " . $fromEmail;
913
		$headers[] = 'From: ' . $sitefromEmailName . ' <' . $sitefromEmail . '>';
914
915
		$to = $toEmail;
916
917
		/**
918
		 * Filter the client email to address.
919
		 *
920
		 * @since   1.6.1
921
		 * @package GeoDirectory
922
		 *
923
		 * @param string $to            The email address the email is being sent to.
924
		 * @param string $fromEmail     Sender email address.
925
		 * @param string $fromEmailName Sender name.
926
		 * @param string $toEmail       Receiver email address.
927
		 * @param string $toEmailName   Receiver name.
928
		 * @param string $to_subject    Email subject.
929
		 * @param string $to_message    Email content.
930
		 * @param string $extra         Not being used.
931
		 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
932
		 * @param string $post_id       The post ID.
933
		 * @param string $user_id       The user ID.
934
		 */
935
		$to = apply_filters( 'geodir_sendEmail_to', $to, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
936 5
		/**
937
		 * Filter the client email subject.
938
		 *
939
		 * @since   1.6.1
940
		 * @package GeoDirectory_Payment_Manager
941
		 *
942
		 * @param string $subject       The email subject.
943 5
		 * @param string $fromEmail     Sender email address.
944
		 * @param string $fromEmailName Sender name.
945 5
		 * @param string $toEmail       Receiver email address.
946 5
		 * @param string $toEmailName   Receiver name.
947 5
		 * @param string $to_subject    Email subject.
948 5
		 * @param string $to_message    Email content.
949
		 * @param string $extra         Not being used.
950
		 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
951
		 * @param string $post_id       The post ID.
952
		 * @param string $user_id       The user ID.
953
		 */
954 5
		$subject = apply_filters( 'geodir_sendEmail_subject', $subject, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
955
		/**
956 5
		 * Filter the client email message.
957 5
		 *
958
		 * @since   1.6.1
959 5
		 * @package GeoDirectory_Payment_Manager
960
		 *
961 5
		 * @param string $message       The email message text.
962
		 * @param string $fromEmail     Sender email address.
963 5
		 * @param string $fromEmailName Sender name.
964 5
		 * @param string $toEmail       Receiver email address.
965 5
		 * @param string $toEmailName   Receiver name.
966
		 * @param string $to_subject    Email subject.
967 5
		 * @param string $to_message    Email content.
968 5
		 * @param string $extra         Not being used.
969
		 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
970 5
		 * @param string $post_id       The post ID.
971 5
		 * @param string $user_id       The user ID.
972
		 */
973 5
		$message = apply_filters( 'geodir_sendEmail_message', $message, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
974 2
		/**
975 2
		 * Filter the client email headers.
976 2
		 *
977
		 * @since   1.6.1
978 2
		 * @since 1.6.11 $headers changed from string to an array.
979
		 *
980
		 * @param array $headers       The email headers.
981
		 * @param string $fromEmail     Sender email address.
982
		 * @param string $fromEmailName Sender name.
983
		 * @param string $toEmail       Receiver email address.
984
		 * @param string $toEmailName   Receiver name.
985
		 * @param string $to_subject    Email subject.
986
		 * @param string $to_message    Email content.
987
		 * @param string $extra         Not being used.
988
		 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
989
		 * @param string $post_id       The post ID.
990 2
		 * @param string $user_id       The user ID.
991
		 */
992 2
		$headers = apply_filters( 'geodir_sendEmail_headers', $headers, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
993 2
994
		$sent = wp_mail( $to, $subject, $message, $headers );
995
996
		if ( ! $sent ) {
997
			if ( is_array( $to ) ) {
998
				$to = implode( ',', $to );
999
			}
1000
			$log_message = sprintf(
1001
				__( "Email from GeoDirectory failed to send.\nMessage type: %s\nSend time: %s\nTo: %s\nSubject: %s\n\n", 'geodirectory' ),
1002
				$message_type,
1003
				date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ),
1004
				$to,
1005
				$subject
1006 2
			);
1007 2
			geodir_error_log( $log_message );
1008
		}
1009
1010
		///////// ADMIN BCC EMIALS
1011
		$adminEmail = get_bloginfo( 'admin_email' );
1012
		$to         = $adminEmail;
1013 2
1014
		$admin_bcc = false;
1015
		if ( $message_type == 'registration' ) {
1016
			$message_raw  = explode( __( "Password:", 'geodirectory' ), $message );
1017
			$message_raw2 = explode( "</p>", $message_raw[1], 2 );
1018
			$message      = $message_raw[0] . __( 'Password:', 'geodirectory' ) . ' **********</p>' . $message_raw2[1];
1019 2
		}
1020
		if ( $message_type == 'post_submit' ) {
1021
			$subject = __( stripslashes_deep( get_option( 'geodir_post_submited_success_email_subject_admin' ) ), 'geodirectory' );
1022
			$message = __( stripslashes_deep( get_option( 'geodir_post_submited_success_email_content_admin' ) ), 'geodirectory' );
1023
1024
			$search_array  = array(
1025
				'[#listing_link#]',
1026
				'[#site_name_url#]',
1027
				'[#post_id#]',
1028
				'[#site_name#]',
1029
				'[#to_name#]',
1030 2
				'[#from_name#]',
1031 2
				'[#subject#]',
1032 2
				'[#comments#]',
1033 2
				'[#login_url#]',
1034 2
				'[#login_details#]',
1035 2
				'[#client_name#]',
1036
				'[#posted_date#]',
1037
				'[#user_login#]',
1038 2
				'[#username#]'
1039 2
			);
1040 2
			$replace_array = array(
1041
				$listingLink,
1042 1
				$siteurl_link,
1043
				$post_id,
1044 2
				$sitefromEmailName,
1045 2
				$toEmailName,
1046
				$fromEmailName,
1047 2
				$to_subject,
1048
				$to_message,
1049 2
				$loginurl_link,
1050
				$login_details,
1051
				$toEmailName,
1052
				$posted_date,
1053
				$user_login,
1054
				$user_login
1055
			);
1056
			$message       = str_replace( $search_array, $replace_array, $message );
1057
1058
			$search_array  = array(
1059
				'[#listing_link#]',
1060
				'[#site_name_url#]',
1061
				'[#post_id#]',
1062
				'[#site_name#]',
1063
				'[#to_name#]',
1064
				'[#from_name#]',
1065
				'[#subject#]',
1066
				'[#client_name#]',
1067
				'[#posted_date#]',
1068
				'[#user_login#]',
1069
				'[#username#]'
1070
			);
1071
			$replace_array = array(
1072
				$listingLink,
1073
				$siteurl_link,
1074
				$post_id,
1075
				$sitefromEmailName,
1076
				$toEmailName,
1077
				$fromEmailName,
1078
				$to_subject,
1079
				$toEmailName,
1080
				$posted_date,
1081
				$user_login,
1082
				$user_login
1083
			);
1084
			$subject       = str_replace( $search_array, $replace_array, $subject );
1085
1086
			$subject .= ' - ADMIN BCC COPY';
1087
			$admin_bcc = true;
1088
1089
		} elseif ( $message_type == 'registration' && get_option( 'geodir_bcc_new_user' ) ) {
1090
			$subject .= ' - ADMIN BCC COPY';
1091
			$admin_bcc = true;
1092
		} elseif ( $message_type == 'send_friend' && get_option( 'geodir_bcc_friend' ) ) {
1093
			$subject .= ' - ADMIN BCC COPY';
1094
			$admin_bcc = true;
1095
		} elseif ( $message_type == 'send_enquiry' && get_option( 'geodir_bcc_enquiry' ) ) {
1096
			$subject .= ' - ADMIN BCC COPY';
1097
			$admin_bcc = true;
1098
		} elseif ( $message_type == 'listing_published' && get_option( 'geodir_bcc_listing_published' ) ) {
1099
			$subject .= ' - ADMIN BCC COPY';
1100
			$admin_bcc = true;
1101
		}
1102
1103
		if ( $admin_bcc === true ) {
1104
1105
			/**
1106
			 * Filter the client email subject.
1107
			 *
1108
			 * @since   1.6.1
1109
			 * @package GeoDirectory_Payment_Manager
1110
			 *
1111
			 * @param string $subject       The email subject.
1112
			 * @param string $fromEmail     Sender email address.
1113
			 * @param string $fromEmailName Sender name.
1114
			 * @param string $toEmail       Receiver email address.
1115
			 * @param string $toEmailName   Receiver name.
1116
			 * @param string $to_subject    Email subject.
1117
			 * @param string $to_message    Email content.
1118
			 * @param string $extra         Not being used.
1119
			 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
1120
			 * @param string $post_id       The post ID.
1121
			 * @param string $user_id       The user ID.
1122 2
			 */
1123
			$subject = apply_filters( 'geodir_sendEmail_subject_admin_bcc', $subject, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
1124
			/**
1125
			 * Filter the client email message.
1126
			 *
1127
			 * @since   1.6.1
1128
			 * @package GeoDirectory_Payment_Manager
1129
			 *
1130
			 * @param string $message       The email message text.
1131
			 * @param string $fromEmail     Sender email address.
1132
			 * @param string $fromEmailName Sender name.
1133
			 * @param string $toEmail       Receiver email address.
1134
			 * @param string $toEmailName   Receiver name.
1135
			 * @param string $to_subject    Email subject.
1136
			 * @param string $to_message    Email content.
1137
			 * @param string $extra         Not being used.
1138
			 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
1139
			 * @param string $post_id       The post ID.
1140
			 * @param string $user_id       The user ID.
1141
			 */
1142
			$message = apply_filters( 'geodir_sendEmail_message_admin_bcc', $message, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
1143
1144
1145
			$sent = wp_mail( $to, $subject, $message, $headers );
1146
1147
			if ( ! $sent ) {
1148
				if ( is_array( $to ) ) {
1149
					$to = implode( ',', $to );
1150
				}
1151
				$log_message = sprintf(
1152
					__( "Email from GeoDirectory failed to send.\nMessage type: %s\nSend time: %s\nTo: %s\nSubject: %s\n\n", 'geodirectory' ),
1153
					$message_type,
1154
					date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ),
1155
					$to,
1156
					$subject
1157
				);
1158
				geodir_error_log( $log_message );
1159
			}
1160
		}
1161
1162
	}
1163
}
1164
1165
1166
/**
1167
 * Generates breadcrumb for taxonomy (category, tags etc.) pages.
1168
 *
1169
 * @since   1.0.0
1170 2
 * @package GeoDirectory
1171 2
 */
1172
function geodir_taxonomy_breadcrumb() {
1173 2
1174
	$term   = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
1175
	$parent = $term->parent;
1176 5
1177 1
	while ( $parent ):
1178 1
		$parents[]  = $parent;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parents was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parents = 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...
1179 1
		$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) );
1180
		$parent     = $new_parent->parent;
1181
	endwhile;
1182
1183
	if ( ! empty( $parents ) ):
1184
		$parents = array_reverse( $parents );
1185
1186
		foreach ( $parents as $parent ):
1187
			$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) );
1188 1
			$url  = get_term_link( $item, get_query_var( 'taxonomy' ) );
1189
			echo '<li> > <a href="' . $url . '">' . $item->name . '</a></li>';
1190 1
		endforeach;
1191 1
1192
	endif;
1193 1
1194
	echo '<li> > ' . $term->name . '</li>';
1195
}
1196
1197
function geodir_wpml_post_type_archive_link($link, $post_type){
1198
1199
	if(function_exists('icl_object_id')) {
1200
		$post_types   = get_option( 'geodir_post_types' );
1201
		$slug         = $post_types[ $post_type ]['rewrite']['slug'];
1202
1203
		//echo $link.'###'.gd_wpml_get_lang_from_url( $link) ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
1204
1205
		// Alter the CPT slug if WPML is set to do so
1206
		if ( function_exists( 'icl_object_id' ) ) {
1207
			if ( gd_wpml_slug_translation_turned_on( $post_type ) && $language_code = gd_wpml_get_lang_from_url( $link) ) {
1208
1209 1
				$org_slug = $slug;
1210
				$slug     = apply_filters( 'wpml_translate_single_string',
1211 1
					$slug,
1212 4
					'WordPress',
1213
					'URL slug: ' . $slug,
1214
					$language_code );
1215
1216
				if ( ! $slug ) {
1217
					$slug = $org_slug;
0 ignored issues
show
Unused Code introduced by
$slug 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...
1218
				} else {
1219
					$link = str_replace( $org_slug, $slug, $link );
1220
				}
1221
1222 3
			}
1223 2
		}
1224
1225 2
		//echo $link.'####'.gd_wpml_get_lang_from_url( $link) ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
1226 1
	}
1227 1
1228 1
	return $link;
1229 1
}
1230 1
1231 1
//add_filter( 'post_type_archive_link','geodir_wpml_post_type_archive_link', 1000,2);
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% 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...
1232
/**
1233 2
 * Main function that generates breadcrumb for all pages.
1234 2
 *
1235 2
 * @since   1.0.0
1236 3
 * @since   1.5.7 Changes for the neighbourhood system improvement.
1237
 * @since   1.6.16 Fix: Breadcrumb formatting issue with the neighbourhood name.
1238 1
 * @package GeoDirectory
1239
 * @global object $wp_query   WordPress Query object.
1240
 * @global object $post       The current post object.
1241
 * @global object $gd_session GeoDirectory Session object.
1242 1
 */
1243
function geodir_breadcrumb() {
1244
	global $wp_query, $geodir_add_location_url;
1245
1246 1
	/**
1247
	 * Filter breadcrumb separator.
1248
	 *
1249
	 * @since 1.0.0
1250 1
	 */
1251
	$separator = apply_filters( 'geodir_breadcrumb_separator', ' > ' );
1252
1253 1
	if ( ! geodir_is_page( 'home' ) ) {
1254
		$breadcrumb    = '';
1255
		$url_categoris = '';
0 ignored issues
show
Unused Code introduced by
$url_categoris 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...
1256 1
		$breadcrumb .= '<div class="geodir-breadcrumb clearfix"><ul id="breadcrumbs">';
1257 1
		/**
1258 1
		 * Filter breadcrumb's first link.
1259 1
		 *
1260 5
		 * @since 1.0.0
1261
		 */
1262
		$breadcrumb .= '<li>' . apply_filters( 'geodir_breadcrumb_first_link', '<a href="' . home_url() . '">' . __( 'Home', 'geodirectory' ) . '</a>' ) . '</li>';
1263
1264
		$gd_post_type   = geodir_get_current_posttype();
1265
		$post_type_info = get_post_type_object( $gd_post_type );
1266
1267
		remove_filter( 'post_type_archive_link', 'geodir_get_posttype_link' );
1268
1269 5
		$listing_link = get_post_type_archive_link( $gd_post_type );
1270 5
1271 5
		add_filter( 'post_type_archive_link', 'geodir_get_posttype_link', 10, 2 );
1272
		$listing_link = rtrim( $listing_link, '/' );
1273
		$listing_link .= '/';
1274
1275
		$post_type_for_location_link = $listing_link;
1276
		$location_terms              = geodir_get_current_location_terms( 'query_vars', $gd_post_type );
1277
1278
		global $wp, $gd_session;
1279
		$location_link = $post_type_for_location_link;
1280
1281
		if ( geodir_is_page( 'detail' ) || geodir_is_page( 'listing' ) ) {
1282
			global $post;
1283
			$location_manager     = defined( 'POST_LOCATION_TABLE' ) ? true : false;
1284
			$neighbourhood_active = $location_manager && get_option( 'location_neighbourhoods' ) ? true : false;
1285
1286 View Code Duplication
			if ( geodir_is_page( 'detail' ) && isset( $post->country_slug ) ) {
1287 1
				$location_terms = array(
1288 1
					'gd_country' => $post->country_slug,
1289 1
					'gd_region'  => $post->region_slug,
1290
					'gd_city'    => $post->city_slug
1291
				);
1292
1293
				if ( $neighbourhood_active && ! empty( $location_terms['gd_city'] ) && $gd_ses_neighbourhood = $gd_session->get( 'gd_neighbourhood' ) ) {
1294
					$location_terms['gd_neighbourhood'] = $gd_ses_neighbourhood;
1295
				}
1296
			}
1297
1298 1
			$geodir_show_location_url = get_option( 'geodir_show_location_url' );
1299
1300
			$hide_url_part = array();
1301
			if ( $location_manager ) {
1302
				$hide_country_part = get_option( 'geodir_location_hide_country_part' );
1303
				$hide_region_part  = get_option( 'geodir_location_hide_region_part' );
1304
1305
				if ( $hide_region_part && $hide_country_part ) {
1306
					$hide_url_part = array( 'gd_country', 'gd_region' );
1307
				} else if ( $hide_region_part && ! $hide_country_part ) {
1308
					$hide_url_part = array( 'gd_region' );
1309
				} else if ( ! $hide_region_part && $hide_country_part ) {
1310
					$hide_url_part = array( 'gd_country' );
1311
				}
1312
			}
1313 1
1314 1
			$hide_text_part = array();
0 ignored issues
show
Unused Code introduced by
$hide_text_part 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...
1315 1
			if ( $geodir_show_location_url == 'country_city' ) {
1316
				$hide_text_part = array( 'gd_region' );
0 ignored issues
show
Unused Code introduced by
$hide_text_part 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...
1317
1318 1
				if ( isset( $location_terms['gd_region'] ) && ! $location_manager ) {
1319 1
					unset( $location_terms['gd_region'] );
1320 1
				}
1321 1
			} else if ( $geodir_show_location_url == 'region_city' ) {
1322 1
				$hide_text_part = array( 'gd_country' );
0 ignored issues
show
Unused Code introduced by
$hide_text_part 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...
1323 1
1324 1
				if ( isset( $location_terms['gd_country'] ) && ! $location_manager ) {
1325 1
					unset( $location_terms['gd_country'] );
1326 1
				}
1327 1
			} else if ( $geodir_show_location_url == 'city' ) {
1328
				$hide_text_part = array( 'gd_country', 'gd_region' );
0 ignored issues
show
Unused Code introduced by
$hide_text_part 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...
1329 1
1330
				if ( isset( $location_terms['gd_country'] ) && ! $location_manager ) {
1331 1
					unset( $location_terms['gd_country'] );
1332
				}
1333
				if ( isset( $location_terms['gd_region'] ) && ! $location_manager ) {
1334 1
					unset( $location_terms['gd_region'] );
1335
				}
1336
			}
1337
1338 1
			$is_location_last = '';
0 ignored issues
show
Unused Code introduced by
$is_location_last 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...
1339
			$is_taxonomy_last = '';
0 ignored issues
show
Unused Code introduced by
$is_taxonomy_last 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...
1340 1
			$breadcrumb .= '<li>';
1341 1
			if ( get_query_var( $gd_post_type . 'category' ) ) {
1342 1
				$gd_taxonomy = $gd_post_type . 'category';
1343
			} elseif ( get_query_var( $gd_post_type . '_tags' ) ) {
1344
				$gd_taxonomy = $gd_post_type . '_tags';
1345 1
			}
1346
1347
			$breadcrumb .= $separator . '<a href="' . $listing_link . '">' . __( ucfirst( $post_type_info->label ), 'geodirectory' ) . '</a>';
1348 1
			if ( ! empty( $gd_taxonomy ) || geodir_is_page( 'detail' ) ) {
1349
				$is_location_last = false;
1350 1
			} else {
1351 1
				$is_location_last = true;
1352
			}
1353
1354
			if ( ! empty( $gd_taxonomy ) && geodir_is_page( 'listing' ) ) {
1355
				$is_taxonomy_last = true;
1356 1
			} else {
1357
				$is_taxonomy_last = false;
1358 1
			}
1359
1360
			if ( ! empty( $location_terms ) ) {
1361
				$geodir_get_locations = function_exists( 'get_actual_location_name' ) ? true : false;
1362 1
1363
				foreach ( $location_terms as $key => $location_term ) {
1364
					if ( $location_term != '' ) {
1365 1
						if ( ! empty( $hide_url_part ) && in_array( $key, $hide_url_part ) ) { // Hide location part from url & breadcrumb.
1366
							continue;
1367
						}
1368 1
1369
						$gd_location_link_text = preg_replace( '/-(\d+)$/', '', $location_term );
1370
						$gd_location_link_text = preg_replace( '/[_-]/', ' ', $gd_location_link_text );
1371
						$gd_location_link_text = ucfirst( $gd_location_link_text );
1372 1
1373
						$location_term_actual_country = '';
1374
						$location_term_actual_region  = '';
1375
						$location_term_actual_city    = '';
1376
						$location_term_actual_neighbourhood = '';
1377
						if ( $geodir_get_locations ) {
1378 1
							if ( $key == 'gd_country' ) {
1379 1
								$location_term_actual_country = get_actual_location_name( 'country', $location_term, true );
1380 1
							} else if ( $key == 'gd_region' ) {
1381 1
								$location_term_actual_region = get_actual_location_name( 'region', $location_term, true );
1382
							} else if ( $key == 'gd_city' ) {
1383
								$location_term_actual_city = get_actual_location_name( 'city', $location_term, true );
1384
							} else if ( $key == 'gd_neighbourhood' ) {
1385
								$location_term_actual_neighbourhood = get_actual_location_name( 'neighbourhood', $location_term, true );
1386 1
							}
1387 1
						} else {
1388
							$location_info = geodir_get_location();
1389 1
1390
							if ( ! empty( $location_info ) && isset( $location_info->location_id ) ) {
1391
								if ( $key == 'gd_country' ) {
1392
									$location_term_actual_country = __( $location_info->country, 'geodirectory' );
1393
								} else if ( $key == 'gd_region' ) {
1394
									$location_term_actual_region = __( $location_info->region, 'geodirectory' );
1395
								} else if ( $key == 'gd_city' ) {
1396
									$location_term_actual_city = __( $location_info->city, 'geodirectory' );
1397
								}
1398
							}
1399
						}
1400
1401 1
						if ( $is_location_last && $key == 'gd_country' && ! ( isset( $location_terms['gd_region'] ) && $location_terms['gd_region'] != '' ) && ! ( isset( $location_terms['gd_city'] ) && $location_terms['gd_city'] != '' ) ) {
1402
							$breadcrumb .= $location_term_actual_country != '' ? $separator . $location_term_actual_country : $separator . $gd_location_link_text;
1403 1
						} else if ( $is_location_last && $key == 'gd_region' && ! ( isset( $location_terms['gd_city'] ) && $location_terms['gd_city'] != '' ) ) {
1404
							$breadcrumb .= $location_term_actual_region != '' ? $separator . $location_term_actual_region : $separator . $gd_location_link_text;
1405
						} else if ( $is_location_last && $key == 'gd_city' && empty( $location_terms['gd_neighbourhood'] ) ) {
1406 1
							$breadcrumb .= $location_term_actual_city != '' ? $separator . $location_term_actual_city : $separator . $gd_location_link_text;
1407
						} else if ( $is_location_last && $key == 'gd_neighbourhood' ) {
1408
							$breadcrumb .= $location_term_actual_neighbourhood != '' ? $separator . $location_term_actual_neighbourhood : $separator . $gd_location_link_text;
1409
						} else {
1410
							if ( get_option( 'permalink_structure' ) != '' ) {
1411
								$location_link .= $location_term . '/';
1412
							} else {
1413
								$location_link .= "&$key=" . $location_term;
1414
							}
1415 1
1416
							if ( $key == 'gd_country' && $location_term_actual_country != '' ) {
1417
								$gd_location_link_text = $location_term_actual_country;
1418
							} else if ( $key == 'gd_region' && $location_term_actual_region != '' ) {
1419
								$gd_location_link_text = $location_term_actual_region;
1420
							} else if ( $key == 'gd_city' && $location_term_actual_city != '' ) {
1421
								$gd_location_link_text = $location_term_actual_city;
1422
							} else if ( $key == 'gd_neighbourhood' && $location_term_actual_neighbourhood != '' ) {
1423
								$gd_location_link_text = $location_term_actual_neighbourhood;
1424
							}
1425
1426
							/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
1427
                            if (geodir_is_page('detail') && !empty($hide_text_part) && in_array($key, $hide_text_part)) {
1428
                                continue;
1429 1
                            }
1430 1
                            */
1431 1
1432
							$breadcrumb .= $separator . '<a href="' . $location_link . '">' . $gd_location_link_text . '</a>';
1433
						}
1434
					}
1435
				}
1436
			}
1437
1438
			if ( ! empty( $gd_taxonomy ) ) {
1439
				$term_index = 1;
1440
1441
				//if(get_option('geodir_add_categories_url'))
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
1442
				{
1443
					if ( get_query_var( $gd_post_type . '_tags' ) ) {
1444
						$cat_link = $listing_link . 'tags/';
1445
					} else {
1446
						$cat_link = $listing_link;
1447
					}
1448
1449
					foreach ( $location_terms as $key => $location_term ) {
1450
						if ( $location_manager && in_array( $key, $hide_url_part ) ) {
1451
							continue;
1452
						}
1453
1454
						if ( $location_term != '' ) {
1455
							if ( get_option( 'permalink_structure' ) != '' ) {
1456
								$cat_link .= $location_term . '/';
1457
							}
1458
						}
1459
					}
1460
1461
					$term_array = explode( "/", trim( $wp_query->query[ $gd_taxonomy ], "/" ) );
1462
					foreach ( $term_array as $term ) {
1463
						$term_link_text = preg_replace( '/-(\d+)$/', '', $term );
1464
						$term_link_text = preg_replace( '/[_-]/', ' ', $term_link_text );
0 ignored issues
show
Unused Code introduced by
$term_link_text 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...
1465
1466
						// get term actual name
1467
						$term_info = get_term_by( 'slug', $term, $gd_taxonomy, 'ARRAY_A' );
1468
						if ( ! empty( $term_info ) && isset( $term_info['name'] ) && $term_info['name'] != '' ) {
1469
							$term_link_text = urldecode( $term_info['name'] );
1470
						} else {
1471
							continue;
1472
							//$term_link_text = wp_strip_all_tags(geodir_ucwords(urldecode($term_link_text)));
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
1473
						}
1474
1475
						if ( $term_index == count( $term_array ) && $is_taxonomy_last ) {
1476
							$breadcrumb .= $separator . $term_link_text;
1477
						} else {
1478
							$cat_link .= $term . '/';
1479
							$breadcrumb .= $separator . '<a href="' . $cat_link . '">' . $term_link_text . '</a>';
1480
						}
1481
						$term_index ++;
1482
					}
1483
				}
1484
1485
1486
			}
1487
1488
			if ( geodir_is_page( 'detail' ) ) {
1489
				$breadcrumb .= $separator . get_the_title();
1490
			}
1491
1492
			$breadcrumb .= '</li>';
1493
1494
1495
		} elseif ( geodir_is_page( 'author' ) ) {
1496
			$user_id             = get_current_user_id();
1497
			$author_link         = get_author_posts_url( $user_id );
1498
			$default_author_link = geodir_getlink( $author_link, array(
1499
				'geodir_dashbord' => 'true',
1500
				'stype'           => 'gd_place'
1501
			), false );
1502
1503
			/**
1504
			 * Filter author page link.
1505
			 *
1506
			 * @since 1.0.0
1507
			 *
1508
			 * @param string $default_author_link Default author link.
1509
			 * @param int $user_id                Author ID.
1510
			 */
1511
			$default_author_link = apply_filters( 'geodir_dashboard_author_link', $default_author_link, $user_id );
1512
1513
			$breadcrumb .= '<li>';
1514
			$breadcrumb .= $separator . '<a href="' . $default_author_link . '">' . __( 'My Dashboard', 'geodirectory' ) . '</a>';
1515
1516
			if ( isset( $_REQUEST['list'] ) ) {
1517
				$author_link = geodir_getlink( $author_link, array(
1518
					'geodir_dashbord' => 'true',
1519
					'stype'           => $_REQUEST['stype']
1520
				), false );
1521
1522
				/**
1523
				 * Filter author page link.
1524
				 *
1525
				 * @since 1.0.0
1526
				 *
1527
				 * @param string $author_link Author page link.
1528
				 * @param int $user_id        Author ID.
1529
				 * @param string $_REQUEST    ['stype'] Post type.
1530
				 */
1531
				$author_link = apply_filters( 'geodir_dashboard_author_link', $author_link, $user_id, $_REQUEST['stype'] );
1532
1533
				$breadcrumb .= $separator . '<a href="' . $author_link . '">' . __( ucfirst( $post_type_info->label ), 'geodirectory' ) . '</a>';
1534
				$breadcrumb .= $separator . ucfirst( __( 'My', 'geodirectory' ) . ' ' . $_REQUEST['list'] );
1535
			} else {
1536
				$breadcrumb .= $separator . __( ucfirst( $post_type_info->label ), 'geodirectory' );
1537
			}
1538
1539
			$breadcrumb .= '</li>';
1540
		} elseif ( is_category() || is_single() ) {
1541
			$category = get_the_category();
1542
			if ( is_category() ) {
1543
				$breadcrumb .= '<li>' . $separator . $category[0]->cat_name . '</li>';
1544
			}
1545
			if ( is_single() ) {
1546
				$breadcrumb .= '<li>' . $separator . '<a href="' . get_category_link( $category[0]->term_id ) . '">' . $category[0]->cat_name . '</a></li>';
1547
				$breadcrumb .= '<li>' . $separator . get_the_title() . '</li>';
1548
			}
1549
			/* End of my version ##################################################### */
1550
		} else if ( is_page() ) {
1551
			$page_title = get_the_title();
1552
1553
			if ( geodir_is_page( 'location' ) ) {
1554
				$location_page_id = geodir_location_page_id();
1555
				$loc_post         = get_post( $location_page_id );
1556
				$post_name        = $loc_post->post_name;
1557
				$slug             = ucwords( str_replace( '-', ' ', $post_name ) );
1558
				$page_title       = ! empty( $slug ) ? $slug : __( 'Location', 'geodirectory' );
1559
			}
1560
1561
			$breadcrumb .= '<li>' . $separator;
1562
			$breadcrumb .= stripslashes_deep( $page_title );
1563
			$breadcrumb .= '</li>';
1564
		} else if ( is_tag() ) {
1565
			$breadcrumb .= "<li> " . $separator . single_tag_title( '', false ) . '</li>';
1566
		} else if ( is_day() ) {
1567
			$breadcrumb .= "<li> " . $separator . __( " Archive for", 'geodirectory' ) . " ";
1568
			the_time( 'F jS, Y' );
1569
			$breadcrumb .= '</li>';
1570
		} else if ( is_month() ) {
1571
			$breadcrumb .= "<li> " . $separator . __( " Archive for", 'geodirectory' ) . " ";
1572
			the_time( 'F, Y' );
1573
			$breadcrumb .= '</li>';
1574
		} else if ( is_year() ) {
1575
			$breadcrumb .= "<li> " . $separator . __( " Archive for", 'geodirectory' ) . " ";
1576
			the_time( 'Y' );
1577
			$breadcrumb .= '</li>';
1578
		} else if ( is_author() ) {
1579
			$breadcrumb .= "<li> " . $separator . __( " Author Archive", 'geodirectory' );
1580
			$breadcrumb .= '</li>';
1581
		} else if ( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) {
1582
			$breadcrumb .= "<li>" . $separator . __( "Blog Archives", 'geodirectory' );
1583
			$breadcrumb .= '</li>';
1584
		} else if ( is_search() ) {
1585
			$breadcrumb .= "<li> " . $separator . __( " Search Results", 'geodirectory' );
1586
			$breadcrumb .= '</li>';
1587
		}
1588
		$breadcrumb .= '</ul></div>';
1589
1590
		/**
1591
		 * Filter breadcrumb html output.
1592
		 *
1593
		 * @since 1.0.0
1594
		 *
1595
		 * @param string $breadcrumb Breadcrumb HTML.
1596
		 * @param string $separator  Breadcrumb separator.
1597
		 */
1598
		echo $breadcrumb = apply_filters( 'geodir_breadcrumb', $breadcrumb, $separator );
1599
	}
1600
}
1601
1602
1603
add_action( "admin_init", "geodir_allow_wpadmin" ); // check user is admin
1604
if ( ! function_exists( 'geodir_allow_wpadmin' ) ) {
1605
	/**
1606
	 * Allow only admins to access wp-admin.
1607
	 *
1608
	 * Normal users will be redirected to home page.
1609
	 *
1610
	 * @since   1.0.0
1611
	 * @package GeoDirectory
1612
	 * @global object $wpdb WordPress Database object.
1613
	 */
1614
	function geodir_allow_wpadmin() {
1615
		global $wpdb;
1616
		if ( get_option( 'geodir_allow_wpadmin' ) == '0' && is_user_logged_in() && ( ! defined( 'DOING_AJAX' ) ) ) // checking action in request to allow ajax request go through
1617
		{
1618
			if ( current_user_can( 'administrator' ) ) {
1619
			} else {
1620
1621
				wp_redirect( home_url() );
1622
				exit;
1623
			}
1624
1625
		}
1626
	}
1627
}
1628
1629
1630
/**
1631
 * Move Images from a remote url to upload directory.
1632
 *
1633
 * @since   1.0.0
1634
 * @package GeoDirectory
1635
 *
1636
 * @param string $url The remote image url.
1637
 *
1638
 * @return array|WP_Error The uploaded data as array. When failure returns error.
1639
 */
1640
function fetch_remote_file( $url ) {
1641
	// extract the file name and extension from the url
1642
	require_once( ABSPATH . 'wp-includes/pluggable.php' );
1643
	$file_name = basename( $url );
1644
	if ( strpos( $file_name, '?' ) !== false ) {
1645
		list( $file_name ) = explode( '?', $file_name );
1646
	}
1647
	$dummy        = false;
1648
	$add_to_cache = false;
1649
	$key          = null;
1650
	if ( strpos( $url, '/dummy/' ) !== false ) {
1651
		$dummy = true;
1652
		$key   = "dummy_" . str_replace( '.', '_', $file_name );
1653
		$value = get_transient( 'cached_dummy_images' );
1654
		if ( $value ) {
1655
			if ( isset( $value[ $key ] ) ) {
1656
				return $value[ $key ];
1657
			} else {
1658
				$add_to_cache = true;
1659
			}
1660
		} else {
1661
			$add_to_cache = true;
1662
		}
1663
	}
1664
1665
	// get placeholder file in the upload dir with a unique, sanitized filename
1666
1667
	$post_upload_date = isset( $post['upload_date'] ) ? $post['upload_date'] : '';
0 ignored issues
show
Bug introduced by
The variable $post seems to never exist, and therefore isset should always return false. 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...
1668
1669
	$upload = wp_upload_bits( $file_name, 0, '', $post_upload_date );
1670
	if ( $upload['error'] ) {
1671
		return new WP_Error( 'upload_dir_error', $upload['error'] );
1672
	}
1673
1674
1675
	sleep( 0.3 );// if multiple remote file this can cause the remote server to timeout so we add a slight delay
1676
1677
	// fetch the remote url and write it to the placeholder file
1678
	$headers = wp_remote_get( $url, array( 'stream' => true, 'filename' => $upload['file'] ) );
1679
1680
	$log_message = '';
1681
	if ( is_wp_error( $headers ) ) {
1682
		echo 'file: ' . $url;
1683
1684
		return new WP_Error( 'import_file_error', $headers->get_error_message() );
1685
	}
1686
1687
	$filesize = filesize( $upload['file'] );
1688
	// request failed
1689
	if ( ! $headers ) {
1690
		$log_message = __( 'Remote server did not respond', 'geodirectory' );
1691
	} // make sure the fetch was successful
1692
	elseif ( $headers['response']['code'] != '200' ) {
1693
		$log_message = sprintf( __( 'Remote server returned error response %1$d %2$s', 'geodirectory' ), esc_html( $headers['response'] ), get_status_header_desc( $headers['response'] ) );
1694
	} elseif ( isset( $headers['headers']['content-length'] ) && $filesize != $headers['headers']['content-length'] ) {
1695
		$log_message = __( 'Remote file is incorrect size', 'geodirectory' );
1696
	} elseif ( 0 == $filesize ) {
1697
		$log_message = __( 'Zero size file downloaded', 'geodirectory' );
1698
	}
1699
1700
	if ( $log_message ) {
1701
		$del = unlink( $upload['file'] );
1702
		if ( ! $del ) {
1703
			geodir_error_log( __( 'GeoDirectory: fetch_remote_file() failed to delete temp file.', 'geodirectory' ) );
1704
		}
1705
1706
		return new WP_Error( 'import_file_error', $log_message );
1707
	}
1708
1709
	if ( $dummy && $add_to_cache && is_array( $upload ) ) {
1710
		$images = get_transient( 'cached_dummy_images' );
1711
		if ( is_array( $images ) ) {
1712
			$images[ $key ] = $upload;
1713
		} else {
1714
			$images = array( $key => $upload );
1715
		}
1716
1717
		//setting the cache using the WP Transient API
1718
		set_transient( 'cached_dummy_images', $images, 60 * 10 ); //10 minutes cache
1719
	}
1720
1721
	return $upload;
1722
}
1723
1724
/**
1725
 * Get maximum file upload size.
1726
 *
1727
 * @since   1.0.0
1728
 * @package GeoDirectory
1729
 * @return string|void Max upload size.
1730
 */
1731 View Code Duplication
function geodir_max_upload_size() {
0 ignored issues
show
Best Practice introduced by
The function geodir_max_upload_size() has been defined more than once; this definition is ignored, only the first definition in geodirectory-functions/custom_fields_functions.php (L1804-1815) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
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...
1732
	$max_filesize = (float) get_option( 'geodir_upload_max_filesize', 2 );
1733
1734
	if ( $max_filesize > 0 && $max_filesize < 1 ) {
1735
		$max_filesize = (int) ( $max_filesize * 1024 ) . 'kb';
1736
	} else {
1737
		$max_filesize = $max_filesize > 0 ? $max_filesize . 'mb' : '2mb';
1738
	}
1739
1740
	/**
1741
	 * Filter default image upload size limit.
1742
	 *
1743
	 * @since 1.0.0
1744
	 *
1745
	 * @param string $max_filesize Max file upload size. Ex. 10mb, 512kb.
1746
	 */
1747
	return apply_filters( 'geodir_default_image_upload_size_limit', $max_filesize );
1748
}
1749
1750
/**
1751
 * Check if dummy folder exists or not.
1752
 *
1753
 * Check if dummy folder exists or not , if not then fetch from live url.
1754
 *
1755
 * @since   1.0.0
1756
 * @package GeoDirectory
1757
 * @return bool If dummy folder exists returns true, else false.
1758
 */
1759
function geodir_dummy_folder_exists() {
1760
	$path = geodir_plugin_path() . '/geodirectory-admin/dummy/';
1761
	if ( ! is_dir( $path ) ) {
1762
		return false;
1763
	} else {
1764
		return true;
1765
	}
1766
1767
}
1768
1769
/**
1770
 * Get the author info.
1771
 *
1772
 * @since   1.0.0
1773 7
 * @package GeoDirectory
1774 7
 * @global object $wpdb WordPress Database object.
1775 7
 *
1776
 * @param int $aid      The author ID.
1777
 *
1778
 * @return object Author info.
1779
 */
1780 7
function geodir_get_author_info( $aid ) {
1781
	global $wpdb;
1782
	/*$infosql = "select * from $wpdb->users where ID=$aid";*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
1783
	$infosql = $wpdb->prepare( "select * from $wpdb->users where ID=%d", array( $aid ) );
1784
	$info    = $wpdb->get_results( $infosql );
1785
	if ( $info ) {
1786
		return $info[0];
1787
	}
1788
}
1789
1790
if ( ! function_exists( 'adminEmail' ) ) {
1791
	/**
1792
	 * Send emails to client on post submission, renew etc.
1793 7
	 *
1794
	 * @since   1.0.0
1795
	 * @package GeoDirectory
1796
	 * @global object $wpdb        WordPress Database object.
1797 7
	 *
1798
	 * @param int|string $page_id  Page ID.
1799
	 * @param int|string $user_id  User ID.
1800
	 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1801
	 * @param string $custom_1     Custom data to be sent.
1802
	 */
1803
	function adminEmail( $page_id, $user_id, $message_type, $custom_1 = '' ) {
1804
		global $wpdb;
1805
		if ( $message_type == 'expiration' ) {
1806
			$subject        = stripslashes( __( get_option( 'renew_email_subject' ), 'geodirectory' ) );
1807
			$client_message = stripslashes( __( get_option( 'renew_email_content' ), 'geodirectory' ) );
1808
		} elseif ( $message_type == 'post_submited' ) {
1809
			$subject        = __( get_option( 'post_submited_success_email_subject_admin' ), 'geodirectory' );
1810
			$client_message = __( get_option( 'post_submited_success_email_content_admin' ), 'geodirectory' );
1811
		} elseif ( $message_type == 'renew' ) {
1812
			$subject        = __( get_option( 'post_renew_success_email_subject_admin' ), 'geodirectory' );
1813
			$client_message = __( get_option( 'post_renew_success_email_content_admin' ), 'geodirectory' );
1814
		} elseif ( $message_type == 'upgrade' ) {
1815
			$subject        = __( get_option( 'post_upgrade_success_email_subject_admin' ), 'geodirectory' );
1816
			$client_message = __( get_option( 'post_upgrade_success_email_content_admin' ), 'geodirectory' );
1817 2
		} elseif ( $message_type == 'claim_approved' ) {
1818
			$subject        = __( get_option( 'claim_approved_email_subject' ), 'geodirectory' );
1819
			$client_message = __( get_option( 'claim_approved_email_content' ), 'geodirectory' );
1820
		} elseif ( $message_type == 'claim_rejected' ) {
1821
			$subject        = __( get_option( 'claim_rejected_email_subject' ), 'geodirectory' );
1822
			$client_message = __( get_option( 'claim_rejected_email_content' ), 'geodirectory' );
1823
		} elseif ( $message_type == 'claim_requested' ) {
1824
			$subject        = __( get_option( 'claim_email_subject_admin' ), 'geodirectory' );
1825
			$client_message = __( get_option( 'claim_email_content_admin' ), 'geodirectory' );
1826
		} elseif ( $message_type == 'auto_claim' ) {
1827
			$subject        = __( get_option( 'auto_claim_email_subject' ), 'geodirectory' );
1828
			$client_message = __( get_option( 'auto_claim_email_content' ), 'geodirectory' );
1829
		} elseif ( $message_type == 'payment_success' ) {
1830
			$subject        = __( get_option( 'post_payment_success_admin_email_subject' ), 'geodirectory' );
1831
			$client_message = __( get_option( 'post_payment_success_admin_email_content' ), 'geodirectory' );
1832
		} elseif ( $message_type == 'payment_fail' ) {
1833
			$subject        = __( get_option( 'post_payment_fail_admin_email_subject' ), 'geodirectory' );
1834
			$client_message = __( get_option( 'post_payment_fail_admin_email_content' ), 'geodirectory' );
1835
		}
1836
		$transaction_details = $custom_1;
1837
		$fromEmail           = get_option( 'site_email' );
1838
		$fromEmailName       = get_site_emailName();
1839
//$alivedays = get_post_meta($page_id,'alive_days',true);
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...
1840
		$pkg_limit            = get_property_price_info_listing( $page_id );
1841
		$alivedays            = $pkg_limit['days'];
1842
		$productlink          = get_permalink( $page_id );
1843
		$post_info            = get_post( $page_id );
1844
		$post_date            = date( 'dS F,Y', strtotime( $post_info->post_date ) );
1845
		$listingLink          = '<a href="' . $productlink . '"><b>' . $post_info->post_title . '</b></a>';
1846
		$loginurl             = geodir_login_url();
1847
		$loginurl_link        = '<a href="' . $loginurl . '">login</a>';
1848
		$siteurl              = home_url();
1849 18
		$siteurl_link         = '<a href="' . $siteurl . '">' . $fromEmailName . '</a>';
1850
		$user_info            = get_userdata( $user_id );
1851
		$user_email           = $user_info->user_email;
1852
		$display_name         = geodir_get_client_name( $user_id );
1853 18
		$user_login           = $user_info->user_login;
1854
		$number_of_grace_days = get_option( 'ptthemes_listing_preexpiry_notice_days' );
1855
		if ( $number_of_grace_days == '' ) {
1856
			$number_of_grace_days = 1;
1857
		}
1858
		if ( $post_info->post_type == 'event' ) {
1859
			$post_type = 'event';
1860
		} else {
1861
			$post_type = 'listing';
1862
		}
1863
		$renew_link     = '<a href="' . $siteurl . '?ptype=post_' . $post_type . '&renew=1&pid=' . $page_id . '">' . RENEW_LINK . '</a>';
1864
		$search_array   = array(
1865 18
			'[#client_name#]',
1866
			'[#listing_link#]',
1867
			'[#posted_date#]',
1868 18
			'[#number_of_days#]',
1869
			'[#number_of_grace_days#]',
1870
			'[#login_url#]',
1871
			'[#username#]',
1872
			'[#user_email#]',
1873
			'[#site_name_url#]',
1874
			'[#renew_link#]',
1875
			'[#post_id#]',
1876
			'[#site_name#]',
1877
			'[#transaction_details#]'
1878
		);
1879
		$replace_array  = array(
1880
			$display_name,
1881
			$listingLink,
1882
			$post_date,
1883
			$alivedays,
1884
			$number_of_grace_days,
1885
			$loginurl_link,
1886
			$user_login,
1887
			$user_email,
1888
			$siteurl_link,
1889
			$renew_link,
1890
			$page_id,
1891
			$fromEmailName,
1892
			$transaction_details
1893
		);
1894
		$client_message = str_replace( $search_array, $replace_array, $client_message );
0 ignored issues
show
Bug introduced by
The variable $client_message 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...
1895
		$subject        = str_replace( $search_array, $replace_array, $subject );
0 ignored issues
show
Bug introduced by
The variable $subject 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...
1896
		
1897
		
1898
		$headers  = array();
1899
		$headers[] = 'Content-type: text/html; charset=UTF-8';
1900
		$headers[] = 'From: ' . $fromEmailName . ' <' . $fromEmail . '>';
1901
1902
		$to      = $fromEmail;
1903
		$message = $client_message;
1904
1905
1906
		/**
1907
		 * Filter the admin email to address.
1908
		 *
1909
		 * @since   1.6.1
1910
		 * @package GeoDirectory
1911
		 *
1912
		 * @param string $to           The email address the email is being sent to.
1913
		 * @param int|string $page_id  Page ID.
1914
		 * @param int|string $user_id  User ID.
1915
		 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1916
		 * @param string $custom_1     Custom data to be sent.
1917
		 */
1918
		$to = apply_filters( 'geodir_adminEmail_to', $to, $page_id, $user_id, $message_type, $custom_1 );
1919
		/**
1920
		 * Filter the admin email subject.
1921
		 *
1922
		 * @since   1.6.1
1923
		 * @package GeoDirectory_Payment_Manager
1924
		 *
1925
		 * @param string $subject      The email subject.
1926
		 * @param int|string $page_id  Page ID.
1927
		 * @param int|string $user_id  User ID.
1928
		 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1929
		 * @param string $custom_1     Custom data to be sent.
1930
		 */
1931
		$subject = apply_filters( 'geodir_adminEmail_subject', $subject, $page_id, $user_id, $message_type, $custom_1 );
1932
		/**
1933
		 * Filter the admin email message.
1934
		 *
1935
		 * @since   1.6.1
1936
		 * @package GeoDirectory_Payment_Manager
1937 8
		 *
1938
		 * @param string $message      The email message text.
1939 8
		 * @param int|string $page_id  Page ID.
1940 8
		 * @param int|string $user_id  User ID.
1941
		 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1942
		 * @param string $custom_1     Custom data to be sent.
1943
		 */
1944 8
		$message = apply_filters( 'geodir_adminEmail_message', $message, $page_id, $user_id, $message_type, $custom_1 );
1945 8
		/**
1946
		 * Filter the admin email headers.
1947 8
		 *
1948
		 * @since   1.6.1
1949
		 * @since 1.6.11 $headers changed from string to an array.         
1950 8
		 *
1951 8
		 * @param array $headers      The email headers.
1952 4
		 * @param int|string $page_id  Page ID.
1953 4
		 * @param int|string $user_id  User ID.
1954 4
		 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1955
		 * @param string $custom_1     Custom data to be sent.
1956
		 */
1957 4
		$headers = apply_filters( 'geodir_adminEmail_headers', $headers, $page_id, $user_id, $message_type, $custom_1 );
1958
1959
1960 4
		$sent = wp_mail( $to, $subject, $message, $headers );
1961 3
		if ( ! $sent ) {
1962 3
			if ( is_array( $to ) ) {
1963 1
				$to = implode( ',', $to );
1964
			}
1965
			$log_message = sprintf(
1966 1
				__( "Email from GeoDirectory failed to send.\nMessage type: %s\nSend time: %s\nTo: %s\nSubject: %s\n\n", 'geodirectory' ),
1967
				$message_type,
1968
				date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ),
1969 1
				$to,
1970 1
				$subject
1971 1
			);
1972 1
			geodir_error_log( $log_message );
1973
		}
1974 8
	}
1975
}
1976
1977
/*
1978
Language translation helper functions
1979
*/
1980
1981
/**
1982
 * Function to get the translated category id's.
1983
 *
1984
 * @since   1.0.0
1985
 * @package GeoDirectory
1986
 *
1987
 * @param array $ids_array Category IDs.
1988
 * @param string $type     Category taxonomy.
1989
 *
1990
 * @return array Category IDs.
1991
 */
1992 8
function gd_lang_object_ids( $ids_array, $type ) {
1993 8
	if ( function_exists( 'icl_object_id' ) ) {
1994 8
		$res = array();
1995
		foreach ( $ids_array as $id ) {
1996 8
			$xlat = icl_object_id( $id, $type, false );
1997 8
			if ( ! is_null( $xlat ) ) {
1998
				$res[] = $xlat;
1999 8
			}
2000
		}
2001
2002
		return $res;
2003
	} else {
2004
		return $ids_array;
2005
	}
2006
}
2007
2008 8
2009
/**
2010 8
 * function to add class to body when multi post type is active.
2011
 *
2012
 * @since   1.0.0
2013
 * @since   1.5.6 Add geodir-page class to body for all gd pages.
2014 8
 * @package GeoDirectory
2015
 * @global object $wpdb  WordPress Database object.
2016
 *
2017
 * @param array $classes Body CSS classes.
2018
 *
2019
 * @return array Modified Body CSS classes.
2020
 */
2021
function geodir_custom_posts_body_class( $classes ) {
2022
	global $wpdb, $wp;
2023
	$post_types = geodir_get_posttypes( 'object' );
2024
	if ( ! empty( $post_types ) && count( (array) $post_types ) > 1 ) {
2025
		$classes[] = 'geodir_custom_posts';
2026
	}
2027
2028
	// fix body class for signup page
2029
	if ( geodir_is_page( 'login' ) ) {
2030
		$new_classes   = array();
2031 8
		$new_classes[] = 'signup page-geodir-signup';
2032
		if ( ! empty( $classes ) ) {
2033 8
			foreach ( $classes as $class ) {
2034
				if ( $class && $class != 'home' && $class != 'blog' ) {
2035 8
					$new_classes[] = $class;
2036
				}
2037
			}
2038 8
		}
2039
		$classes = $new_classes;
2040
	}
2041
2042
	if ( geodir_is_geodir_page() ) {
2043
		$classes[] = 'geodir-page';
2044
	}
2045
2046
	return $classes;
2047
}
2048
2049
add_filter( 'body_class', 'geodir_custom_posts_body_class' ); // let's add a class to the body so we can style the new addition to the search
2050
2051 8
2052 8
/**
2053
 * Returns available map zoom levels.
2054 8
 *
2055
 * @since   1.0.0
2056
 * @package GeoDirectory
2057
 * @return array Available map zoom levels.
2058
 */
2059
function geodir_map_zoom_level() {
2060
	/**
2061
	 * Filter GD map zoom level.
2062 8
	 *
2063
	 * @since 1.0.0
2064 8
	 */
2065 1
	return apply_filters( 'geodir_map_zoom_level', array(
2066 1
		1,
2067 1
		2,
2068 1
		3,
2069 1
		4,
2070 8
		5,
2071
		6,
2072
		7,
2073
		8,
2074
		9,
2075
		10,
2076
		11,
2077
		12,
2078
		13,
2079 8
		14,
2080 8
		15,
2081 8
		16,
2082
		17,
2083 8
		18,
2084
		19
2085
	) );
2086
2087
}
2088
2089
2090
/**
2091 8
 * This function takes backup of an option so they can be restored later.
2092
 *
2093 8
 * @since   1.0.0
2094 8
 * @package GeoDirectory
2095 8
 *
2096
 * @param string $geodir_option_name Option key.
2097 8
 */
2098
function geodir_option_version_backup( $geodir_option_name ) {
2099 8
	$version_date  = time();
2100 8
	$geodir_option = get_option( $geodir_option_name );
2101 8
2102 8
	if ( ! empty( $geodir_option ) ) {
2103 8
		add_option( $geodir_option_name . '_' . $version_date, $geodir_option );
2104 8
	}
2105 8
}
2106
2107
/**
2108 8
 * display add listing page for wpml.
2109 8
 *
2110
 * @since   1.0.0
2111 8
 * @package GeoDirectory
2112
 *
2113
 * @param int $page_id The page ID.
2114
 *
2115
 * @return int Page ID.
2116
 */
2117
function get_page_id_geodir_add_listing_page( $page_id ) {
2118
	if ( geodir_wpml_multilingual_status() ) {
2119
		$post_type = 'post_page';
2120
		$page_id   = geodir_get_wpml_element_id( $page_id, $post_type );
2121
	}
2122
2123
	return $page_id;
2124
}
2125
2126 8
/**
2127
 * Returns wpml multilingual status.
2128 8
 *
2129 8
 * @since   1.0.0
2130
 * @package GeoDirectory
2131
 * @return bool Returns true when sitepress multilingual CMS active. else returns false.
2132
 */
2133 8
function geodir_wpml_multilingual_status() {
2134
	if ( function_exists( 'icl_object_id' ) ) {
2135
		return true;
2136
	}
2137
2138
	return false;
2139
}
2140
2141
/**
2142
 * Returns WPML element ID.
2143
 *
2144
 * @since   1.0.0
2145
 * @package GeoDirectory
2146
 *
2147
 * @param int $page_id      The page ID.
2148 8
 * @param string $post_type The post type.
2149
 *
2150 8
 * @return int Element ID when exists. Else the page id.
2151 8
 */
2152
function geodir_get_wpml_element_id( $page_id, $post_type ) {
2153
	global $sitepress;
2154
	if ( geodir_wpml_multilingual_status() && ! empty( $sitepress ) && isset( $sitepress->queries ) ) {
2155 8
		$trid = $sitepress->get_element_trid( $page_id, $post_type );
2156 8
2157
		if ( $trid > 0 ) {
2158 8
			$translations = $sitepress->get_element_translations( $trid, $post_type );
2159
2160
			$lang = $sitepress->get_current_language();
2161
			$lang = $lang ? $lang : $sitepress->get_default_language();
2162 8
2163 4
			if ( ! empty( $translations ) && ! empty( $lang ) && isset( $translations[ $lang ] ) && isset( $translations[ $lang ]->element_id ) && ! empty( $translations[ $lang ]->element_id ) ) {
2164 4
				$page_id = $translations[ $lang ]->element_id;
2165 2
			}
2166 2
		}
2167 4
	}
2168
2169 8
	return $page_id;
2170
}
2171
2172
/**
2173
 * WPML check element ID.
2174
 *
2175
 * @since      1.0.0
2176
 * @package    GeoDirectory
2177
 * @deprecated 1.4.6 No longer needed as we handle translating GD pages as normal now.
2178
 */
2179
function geodir_wpml_check_element_id() {
2180
	global $sitepress;
2181
	if ( geodir_wpml_multilingual_status() && ! empty( $sitepress ) && isset( $sitepress->queries ) ) {
2182
		$el_type      = 'post_page';
2183
		$el_id        = get_option( 'geodir_add_listing_page' );
2184 8
		$default_lang = $sitepress->get_default_language();
2185
		$el_details   = $sitepress->get_element_language_details( $el_id, $el_type );
2186 8
2187 8
		if ( ! ( $el_id > 0 && $default_lang && ! empty( $el_details ) && isset( $el_details->language_code ) && $el_details->language_code == $default_lang ) ) {
2188
			if ( ! $el_details->source_language_code ) {
2189
				$sitepress->set_element_language_details( $el_id, $el_type, '', $default_lang );
2190 8
				$sitepress->icl_translations_cache->clear();
2191 8
			}
2192
		}
2193 8
	}
2194 8
}
2195
2196
/**
2197
 * Returns orderby SQL using the given query args.
2198 8
 *
2199
 * @since   1.0.0
2200
 * @package GeoDirectory
2201
 * @global object $wpdb          WordPress Database object.
2202 8
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2203 2
 *
2204 2
 * @param array $query_args      The query array.
2205
 *
2206 8
 * @return string Orderby SQL.
2207
 */
2208
function geodir_widget_listings_get_order( $query_args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $query_args 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...
2209
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2210 8
2211
	$query_args = $gd_query_args_widgets;
2212
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2213
		return $wpdb->posts . ".post_date DESC, ";
2214 8
	}
2215 2
2216 2
	$post_type = empty( $query_args['post_type'] ) ? 'gd_place' : $query_args['post_type'];
2217
	$table     = $plugin_prefix . $post_type . '_detail';
2218 8
2219
	$sort_by = ! empty( $query_args['order_by'] ) ? $query_args['order_by'] : '';
2220
2221
	switch ( $sort_by ) {
2222 8
		case 'latest':
2223 4
		case 'newest':
2224
			$orderby = $wpdb->posts . ".post_date DESC, ";
2225 4
			break;
2226 2
		case 'featured':
2227 2
			$orderby = $table . ".is_featured ASC, ". $wpdb->posts . ".post_date DESC, ";
2228 4
			break;
2229 8
		case 'az':
2230
			$orderby = $wpdb->posts . ".post_title ASC, ";
2231 8
			break;
2232
		case 'high_review':
2233
			$orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, ";
2234
			break;
2235
		case 'high_rating':
2236
			$orderby = "( " . $table . ".overall_rating  ) DESC, ";
2237
			break;
2238
		case 'random':
2239
			$orderby = "RAND(), ";
2240
			break;
2241
		default:
2242
			$orderby = $wpdb->posts . ".post_title ASC, ";
2243
			break;
2244
	}
2245
2246 8
	return $orderby;
2247
}
2248 8
2249 8
/**
2250
 * Retrieve listings/count using requested filter parameters.
2251
 *
2252
 * @since   1.0.0
2253 8
 * @package GeoDirectory
2254
 * @since   1.4.2 New parameter $count_only added
2255
 * @since   1.6.11 FIXED: GD listings query returns wrong total when category has sub categories.
2256
 * @global object $wpdb          WordPress Database object.
2257
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2258
 * @global string $table_prefix  WordPress Database Table prefix.
2259
 *
2260
 * @param array $query_args      The query array.
2261
 * @param  int|bool $count_only  If true returns listings count only, otherwise returns array
2262
 *
2263
 * @return mixed Result object.
2264
 */
2265
function geodir_get_widget_listings( $query_args = array(), $count_only = false ) {
2266
	global $wpdb, $plugin_prefix, $table_prefix;
2267
	$GLOBALS['gd_query_args_widgets'] = $query_args;
2268 8
	$gd_query_args_widgets            = $query_args;
2269
2270 8
	$post_type = empty( $query_args['post_type'] ) ? 'gd_place' : $query_args['post_type'];
2271 8
	$table     = $plugin_prefix . $post_type . '_detail';
2272
2273
	$fields = $wpdb->posts . ".*, " . $table . ".*";
2274
	/**
2275 8
	 * Filter widget listing fields string part that is being used for query.
2276 8
	 *
2277 8
	 * @since 1.0.0
2278
	 *
2279 8
	 * @param string $fields    Fields string.
2280
	 * @param string $table     Table name.
2281
	 * @param string $post_type Post type.
2282
	 */
2283
	$fields = apply_filters( 'geodir_filter_widget_listings_fields', $fields, $table, $post_type );
2284
2285
	$join = "INNER JOIN " . $table . " ON (" . $table . ".post_id = " . $wpdb->posts . ".ID)";
2286
2287
	########### WPML ###########
2288
2289
	if ( function_exists( 'icl_object_id' ) ) {
2290
		global $sitepress;
2291
		$lang_code = ICL_LANGUAGE_CODE;
2292
		if ( $lang_code ) {
2293 2
			$join .= " JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID";
2294 2
		}
2295 2
	}
2296
2297 2
	########### WPML ###########
2298 2
2299 2
	/**
2300
	 * Filter widget listing join clause string part that is being used for query.
2301
	 *
2302
	 * @since 1.0.0
2303
	 *
2304
	 * @param string $join      Join clause string.
2305
	 * @param string $post_type Post type.
2306
	 */
2307
	$join = apply_filters( 'geodir_filter_widget_listings_join', $join, $post_type );
2308
2309 2
	$post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : '';
2310 2
2311
	$where = " AND ( " . $wpdb->posts . ".post_status = 'publish' " . $post_status . " ) AND " . $wpdb->posts . ".post_type = '" . $post_type . "'";
2312
2313
	########### WPML ###########
2314
	if ( function_exists( 'icl_object_id' ) ) {
2315
		if ( $lang_code ) {
2316
			$where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type = 'post_$post_type' ";
0 ignored issues
show
Bug introduced by
The variable $lang_code 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...
2317
		}
2318
	}
2319
	########### WPML ###########
2320
	/**
2321
	 * Filter widget listing where clause string part that is being used for query.
2322
	 *
2323
	 * @since 1.0.0
2324 2
	 *
2325 2
	 * @param string $where     Where clause string.
2326 2
	 * @param string $post_type Post type.
2327
	 */
2328 2
	$where = apply_filters( 'geodir_filter_widget_listings_where', $where, $post_type );
2329 2
	$where = $where != '' ? " WHERE 1=1 " . $where : '';
2330 2
2331
	$groupby = " GROUP BY $wpdb->posts.ID "; //@todo is this needed? faster withotu
2332
	/**
2333
	 * Filter widget listing groupby clause string part that is being used for query.
2334
	 *
2335
	 * @since 1.0.0
2336
	 *
2337
	 * @param string $groupby   Group by clause string.
2338
	 * @param string $post_type Post type.
2339
	 */
2340 2
	$groupby = apply_filters( 'geodir_filter_widget_listings_groupby', $groupby, $post_type );
2341
2342 2
	if ( $count_only ) {
2343
		$sql  = "SELECT COUNT(DISTINCT " . $wpdb->posts . ".ID) AS total FROM " . $wpdb->posts . "
2344
			" . $join . "
2345
			" . $where;
2346
		$rows = (int) $wpdb->get_var( $sql );
2347
	} else {
2348
		$orderby = geodir_widget_listings_get_order( $query_args );
2349
		/**
2350
		 * Filter widget listing orderby clause string part that is being used for query.
2351
		 *
2352
		 * @since 1.0.0
2353
		 *
2354
		 * @param string $orderby   Order by clause string.
2355
		 * @param string $table     Table name.
2356
		 * @param string $post_type Post type.
2357
		 */
2358
		$orderby = apply_filters( 'geodir_filter_widget_listings_orderby', $orderby, $table, $post_type );
2359
		$orderby .= $wpdb->posts . ".post_title ASC";
2360
		$orderby = $orderby != '' ? " ORDER BY " . $orderby : '';
2361
2362
		$limit = ! empty( $query_args['posts_per_page'] ) ? $query_args['posts_per_page'] : 5;
2363
		/**
2364
		 * Filter widget listing limit that is being used for query.
2365
		 *
2366
		 * @since 1.0.0
2367
		 *
2368
		 * @param int $limit        Query results limit.
2369
		 * @param string $post_type Post type.
2370
		 */
2371
		$limit = apply_filters( 'geodir_filter_widget_listings_limit', $limit, $post_type );
2372
2373
		$page = ! empty( $query_args['pageno'] ) ? absint( $query_args['pageno'] ) : 1;
2374
		if ( ! $page ) {
2375
			$page = 1;
2376
		}
2377
2378
		$limit = (int) $limit > 0 ? " LIMIT " . absint( ( $page - 1 ) * (int) $limit ) . ", " . (int) $limit : "";
2379
2380
		//@todo removed SQL_CALC_FOUND_ROWS from below as don't think it is needed and query is faster without
2381
		$sql  = "SELECT " . $fields . " FROM " . $wpdb->posts . "
2382
			" . $join . "
2383
			" . $where . "
2384
			" . $groupby . "
2385
			" . $orderby . "
2386
			" . $limit;
2387
		$rows = $wpdb->get_results( $sql );
2388
	}
2389 9
2390
	unset( $GLOBALS['gd_query_args_widgets'] );
2391 9
	unset( $gd_query_args_widgets );
2392 9
2393 9
	return $rows;
2394 4
}
2395
2396 9
/**
2397 9
 * Listing query fields SQL part for widgets.
2398
 *
2399
 * @since   1.0.0
2400
 * @package GeoDirectory
2401
 * @global object $wpdb          WordPress Database object.
2402
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2403
 *
2404
 * @param string $fields         Fields SQL.
2405
 *
2406
 * @return string Modified fields SQL.
2407
 */
2408
function geodir_function_widget_listings_fields( $fields ) {
2409 8
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2410 8
2411 8
	$query_args = $gd_query_args_widgets;
2412
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2413
		return $fields;
2414 8
	}
2415 8
2416
	return $fields;
2417
}
2418 8
2419 8
/**
2420
 * Listing query join clause SQL part for widgets.
2421 8
 *
2422
 * @since   1.0.0
2423
 * @package GeoDirectory
2424 8
 * @global object $wpdb          WordPress Database object.
2425
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2426
 *
2427
 * @param string $join           Join clause SQL.
2428
 *
2429
 * @return string Modified join clause SQL.
2430
 */
2431
function geodir_function_widget_listings_join( $join ) {
2432
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2433
2434
	$query_args = $gd_query_args_widgets;
2435
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2436
		return $join;
2437
	}
2438
2439
	$post_type = empty( $query_args['post_type'] ) ? 'gd_place' : $query_args['post_type'];
2440
	$table     = $plugin_prefix . $post_type . '_detail';
2441
2442 View Code Duplication
	if ( ! empty( $query_args['with_pics_only'] ) ) {
2443
		$join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )";
2444
	}
2445
2446 View Code Duplication
	if ( ! empty( $query_args['tax_query'] ) ) {
2447
		$tax_queries = get_tax_sql( $query_args['tax_query'], $wpdb->posts, 'ID' );
2448
		if ( ! empty( $tax_queries['join'] ) && ! empty( $tax_queries['where'] ) ) {
2449
			$join .= $tax_queries['join'];
2450
		}
2451
	}
2452
2453
	return $join;
2454
}
2455
2456
/**
2457
 * Listing query where clause SQL part for widgets.
2458
 *
2459
 * @since   1.0.0
2460
 * @package GeoDirectory
2461
 * @global object $wpdb          WordPress Database object.
2462
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2463
 *
2464 7
 * @param string $where          Where clause SQL.
2465 7
 *
2466 7
 * @return string Modified where clause SQL.
2467
 */
2468
function geodir_function_widget_listings_where( $where ) {
2469 7
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2470 1
2471 1
	$query_args = $gd_query_args_widgets;
2472
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2473 7
		return $where;
2474
	}
2475
	$post_type = empty( $query_args['post_type'] ) ? 'gd_place' : $query_args['post_type'];
2476
	$table     = $plugin_prefix . $post_type . '_detail';
2477
2478
	if ( ! empty( $query_args ) ) {
2479
		if ( ! empty( $query_args['gd_location'] ) && function_exists( 'geodir_default_location_where' ) ) {
2480
			$where = geodir_default_location_where( $where, $table );
2481
		}
2482
2483
		if ( ! empty( $query_args['post_author'] ) ) {
2484
			$where .= " AND " . $wpdb->posts . ".post_author = " . (int) $query_args['post_author'];
2485
		}
2486
2487
		if ( ! empty( $query_args['show_featured_only'] ) ) {
2488
			$where .= " AND " . $table . ".is_featured = '1'";
2489
		}
2490
2491
		if ( ! empty( $query_args['show_special_only'] ) ) {
2492
			$where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )";
2493
		}
2494 3
2495 3
		if ( ! empty( $query_args['with_pics_only'] ) ) {
2496
			$where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL ";
2497 3
		}
2498
2499
		if ( ! empty( $query_args['featured_image_only'] ) ) {
2500 3
			$where .= " AND " . $table . ".featured_image IS NOT NULL AND " . $table . ".featured_image!='' ";
2501
		}
2502 3
2503
		if ( ! empty( $query_args['with_videos_only'] ) ) {
2504 3
			$where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )";
2505 3
		}
2506
2507 3 View Code Duplication
		if ( ! empty( $query_args['tax_query'] ) ) {
2508
			$tax_queries = get_tax_sql( $query_args['tax_query'], $wpdb->posts, 'ID' );
2509
2510 3
			if ( ! empty( $tax_queries['join'] ) && ! empty( $tax_queries['where'] ) ) {
2511 3
				$where .= $tax_queries['where'];
2512
			}
2513
		}
2514 3
	}
2515 3
2516
	return $where;
2517
}
2518 3
2519
/**
2520
 * Listing query orderby clause SQL part for widgets.
2521 3
 *
2522 3
 * @since   1.0.0
2523 3
 * @package GeoDirectory
2524
 * @global object $wpdb          WordPress Database object.
2525 3
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2526 3
 *
2527 3
 * @param string $orderby        Orderby clause SQL.
2528 3
 *
2529 3
 * @return string Modified orderby clause SQL.
2530
 */
2531 3
function geodir_function_widget_listings_orderby( $orderby ) {
2532 3
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2533 3
2534 3
	$query_args = $gd_query_args_widgets;
2535
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2536 3
		return $orderby;
2537
	}
2538 3
2539 3
	return $orderby;
2540
}
2541
2542
/**
2543
 * Listing query limit for widgets.
2544
 *
2545
 * @since   1.0.0
2546
 * @package GeoDirectory
2547
 * @global object $wpdb          WordPress Database object.
2548
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2549 3
 *
2550 3
 * @param int $limit             Query limit.
2551 3
 *
2552 3
 * @return int Query limit.
2553
 */
2554
function geodir_function_widget_listings_limit( $limit ) {
2555
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2556
2557 3
	$query_args = $gd_query_args_widgets;
2558
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2559 3
		return $limit;
2560
	}
2561 3
2562
	if ( ! empty( $query_args ) && ! empty( $query_args['posts_per_page'] ) ) {
2563 3
		$limit = (int) $query_args['posts_per_page'];
2564
	}
2565 3
2566
	return $limit;
2567
}
2568
2569 3
/**
2570 3
 * WP media large width.
2571 3
 *
2572 3
 * @since   1.0.0
2573 3
 * @package GeoDirectory
2574 3
 *
2575 3
 * @param int $default         Default width.
2576 3
 * @param string|array $params Image parameters.
2577
 *
2578 3
 * @return int Large size width.
2579
 */
2580 View Code Duplication
function geodir_media_image_large_width( $default = 800, $params = '' ) {
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...
2581
	$large_size_w = get_option( 'large_size_w' );
2582 3
	$large_size_w = $large_size_w > 0 ? $large_size_w : $default;
2583 3
	$large_size_w = absint( $large_size_w );
2584 3
2585 3
	if ( ! get_option( 'geodir_use_wp_media_large_size' ) ) {
2586
		$large_size_w = 800;
2587
	}
2588
2589
	/**
2590
	 * Filter large image width.
2591
	 *
2592
	 * @since 1.0.0
2593
	 *
2594
	 * @param int $large_size_w    Large image width.
2595
	 * @param int $default         Default width.
2596
	 * @param string|array $params Image parameters.
2597
	 */
2598 3
	$large_size_w = apply_filters( 'geodir_filter_media_image_large_width', $large_size_w, $default, $params );
2599 3
2600
	return $large_size_w;
2601 3
}
2602
2603
/**
2604 3
 * WP media large height.
2605 3
 *
2606 3
 * @since   1.0.0
2607
 * @package GeoDirectory
2608 3
 *
2609
 * @param int $default   Default height.
2610 3
 * @param string $params Image parameters.
2611
 *
2612 3
 * @return int Large size height.
2613 3
 */
2614 View Code Duplication
function geodir_media_image_large_height( $default = 800, $params = '' ) {
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...
2615 3
	$large_size_h = get_option( 'large_size_h' );
2616
	$large_size_h = $large_size_h > 0 ? $large_size_h : $default;
2617
	$large_size_h = absint( $large_size_h );
2618
2619
	if ( ! get_option( 'geodir_use_wp_media_large_size' ) ) {
2620
		$large_size_h = 800;
2621
	}
2622
2623
	/**
2624 3
	 * Filter large image height.
2625
	 *
2626 3
	 * @since 1.0.0
2627 3
	 *
2628 3
	 * @param int $large_size_h    Large image height.
2629 3
	 * @param int $default         Default height.
2630 3
	 * @param string|array $params Image parameters.
2631
	 */
2632
	$large_size_h = apply_filters( 'geodir_filter_media_image_large_height', $large_size_h, $default, $params );
2633
2634
	return $large_size_h;
2635
}
2636
2637
/**
2638
 * Sanitize location name.
2639
 *
2640
 * @since   1.0.0
2641
 * @package GeoDirectory
2642
 *
2643
 * @param string $type    Location type. Can be gd_country, gd_region, gd_city.
2644 2
 * @param string $name    Location name.
2645
 * @param bool $translate Do you want to translate the name? Default: true.
2646 2
 *
2647
 * @return string Sanitized name.
2648
 */
2649 2
function geodir_sanitize_location_name( $type, $name, $translate = true ) {
2650
	if ( $name == '' ) {
2651
		return null;
2652
	}
2653
2654
	$type = $type == 'gd_country' ? 'country' : $type;
2655
	$type = $type == 'gd_region' ? 'region' : $type;
2656 2
	$type = $type == 'gd_city' ? 'city' : $type;
2657
2658
	$return = $name;
2659
	if ( function_exists( 'get_actual_location_name' ) ) {
2660
		$return = get_actual_location_name( $type, $name, $translate );
2661
	} else {
2662
		$return = preg_replace( '/-(\d+)$/', '', $return );
2663 2
		$return = preg_replace( '/[_-]/', ' ', $return );
2664
		$return = geodir_ucwords( $return );
2665
		$return = $translate ? __( $return, 'geodirectory' ) : $return;
2666
	}
2667
2668
	return $return;
2669
}
2670 2
2671
2672
/**
2673
 * Pluralize comment number.
2674
 *
2675
 * @since   1.0.0
2676
 * @package GeoDirectory
2677 2
 *
2678
 * @param int $number Comments number.
2679
 */
2680
function geodir_comments_number( $number ) {
2681
2682
	if ( $number > 1 ) {
2683
		$output = str_replace( '%', number_format_i18n( $number ), __( '% Reviews', 'geodirectory' ) );
2684 2
	} elseif ( $number == 0 || $number == '' ) {
2685
		$output = __( 'No Reviews', 'geodirectory' );
2686
	} else { // must be one
2687
		$output = __( '1 Review', 'geodirectory' );
2688
	}
2689
	echo $output;
2690
}
2691 2
2692
/**
2693
 * Checks whether the current page is geodirectory home page or not.
2694
 *
2695
 * @since   1.0.0
2696
 * @package GeoDirectory
2697
 * @global object $wpdb WordPress Database object.
2698 2
 * @return bool If current page is GD home page returns true, else false.
2699
 */
2700
function is_page_geodir_home() {
2701
	global $wpdb;
2702
	$cur_url = str_replace( array( "https://", "http://", "www." ), array( '', '', '' ), geodir_curPageURL() );
2703
	if ( function_exists( 'geodir_location_geo_home_link' ) ) {
2704
		remove_filter( 'home_url', 'geodir_location_geo_home_link', 100000 );
2705 2
	}
2706
	$home_url = home_url( '', 'http' );
2707
	if ( function_exists( 'geodir_location_geo_home_link' ) ) {
2708
		add_filter( 'home_url', 'geodir_location_geo_home_link', 100000, 2 );
2709
	}
2710
	$home_url = str_replace( "www.", "", $home_url );
2711
	if ( ( strpos( $home_url, $cur_url ) !== false || strpos( $home_url . '/', $cur_url ) !== false ) && ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && get_option( 'page_on_front' ) == get_option( 'geodir_home_page' ) ) ) {
2712 2
		return true;
2713
	} elseif ( get_query_var( 'page_id' ) == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && get_option( 'page_on_front' ) == get_option( 'geodir_home_page' ) ) {
2714
		return true;
2715
	} else {
2716
		return false;
2717
	}
2718
2719 2
}
2720
2721
2722
/**
2723
 * Returns homepage canonical url for SEO plugins.
2724
 *
2725
 * @since   1.0.0
2726 2
 * @package GeoDirectory
2727
 * @global object $post The current post object.
2728
 *
2729
 * @param string $url   The old url.
2730
 *
2731
 * @return string The canonical URL.
2732
 */
2733 2
function geodir_wpseo_homepage_canonical( $url ) {
2734
	global $post;
2735
2736
	if ( is_page_geodir_home() ) {
2737
		return home_url();
2738
	}
2739
2740 2
	return $url;
2741 2
}
2742
2743 2
add_filter( 'wpseo_canonical', 'geodir_wpseo_homepage_canonical', 10 );
2744
add_filter( 'aioseop_canonical_url', 'geodir_wpseo_homepage_canonical', 10 );
2745
2746
/**
2747
 * Add extra fields to google maps script call.
2748
 *
2749
 * @since   1.0.0
2750
 * @package GeoDirectory
2751
 * @global object $post The current post object.
2752
 *
2753
 * @param string $extra Old extra string.
2754
 *
2755
 * @return string Modified extra string.
2756
 */
2757
function geodir_googlemap_script_extra_details_page( $extra ) {
2758
	global $post;
2759
	$add_google_places_api = false;
2760
	if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'gd_add_listing' ) ) {
2761
		$add_google_places_api = true;
2762
	}
2763
	if ( ! str_replace( 'libraries=places', '', $extra ) && ( geodir_is_page( 'detail' ) || $add_google_places_api ) ) {
2764
		$extra .= "&amp;libraries=places";
2765
	}
2766
2767
	return $extra;
2768
}
2769
2770
add_filter( 'geodir_googlemap_script_extra', 'geodir_googlemap_script_extra_details_page', 101, 1 );
2771
2772
2773
/**
2774
 * Generates popular post category HTML.
2775
 *
2776
 * @since   1.0.0
2777
 * @since   1.5.1 Added option to set default post type.
2778
 * @since   1.6.9 Added option to show parent categories only.
2779
 * @package GeoDirectory
2780
 * @global object $wpdb                     WordPress Database object.
2781
 * @global string $plugin_prefix            Geodirectory plugin table prefix.
2782
 * @global string $geodir_post_category_str The geodirectory post category.
2783
 *
2784
 * @param array|string $args                Display arguments including before_title, after_title, before_widget, and
2785
 *                                          after_widget.
2786 2
 * @param array|string $instance            The settings for the particular instance of the widget.
2787 2
 */
2788 2
function geodir_popular_post_category_output( $args = '', $instance = '' ) {
2789
	// prints the widget
2790 2
	global $wpdb, $plugin_prefix, $geodir_post_category_str;
2791 2
	extract( $args, EXTR_SKIP );
2792 1
2793 1
	echo $before_widget;
2794
2795 2
	/** This filter is documented in geodirectory_widgets.php */
2796 2
	$title = empty( $instance['title'] ) ? __( 'Popular Categories', 'geodirectory' ) : apply_filters( 'widget_title', __( $instance['title'], 'geodirectory' ) );
2797
2798 2
	$gd_post_type = geodir_get_current_posttype();
2799 2
2800
	$category_limit = isset( $instance['category_limit'] ) && $instance['category_limit'] > 0 ? (int) $instance['category_limit'] : 15;
2801 2
	if (!isset($category_restrict)) {
2802
		$category_restrict = false;
2803 2
	}
2804 2
	if ( ! empty( $gd_post_type ) ) {
2805
		$default_post_type = $gd_post_type;
2806
	} elseif ( isset( $instance['default_post_type'] ) && gdsc_is_post_type_valid( $instance['default_post_type'] ) ) {
2807 2
		$default_post_type = $instance['default_post_type'];
2808
	} else {
2809 2
		$all_gd_post_type  = geodir_get_posttypes();
2810
		$default_post_type = ( isset( $all_gd_post_type[0] ) ) ? $all_gd_post_type[0] : '';
2811
	}
2812
	$parent_only = !empty( $instance['parent_only'] ) ? true : false;
2813 2
2814 2
	$taxonomy = array();
2815 1
	if ( ! empty( $gd_post_type ) ) {
2816
		$taxonomy[] = $gd_post_type . "category";
2817
	} else {
2818
		$taxonomy = geodir_get_taxonomies( $gd_post_type );
2819 1
	}
2820
    
2821 1
	$term_args = array( 'taxonomy' => $taxonomy );
2822
	if ( $parent_only ) {
2823 1
		$term_args['parent'] = 0;
2824 1
	}
2825 1
2826
	$terms   = get_terms( $term_args );
2827 1
	$a_terms = array();
2828 1
	$b_terms = array();
2829 1
2830 1
	foreach ( $terms as $term ) {
2831
		if ( $term->count > 0 ) {
2832 1
			$a_terms[ $term->taxonomy ][] = $term;
2833 1
		}
2834 1
	}
2835 1
2836 1
	if ( ! empty( $a_terms ) ) {
2837
		foreach ( $a_terms as $b_key => $b_val ) {
2838
			$b_terms[ $b_key ] = geodir_sort_terms( $b_val, 'count' );
2839 1
		}
2840
2841 1
		$default_taxonomy = $default_post_type != '' && isset( $b_terms[ $default_post_type . 'category' ] ) ? $default_post_type . 'category' : '';
2842 1
2843
		$tax_change_output = '';
2844
		if ( count( $b_terms ) > 1 ) {
2845
			$tax_change_output .= "<select data-limit='$category_limit' data-parent='" . (int)$parent_only . "' class='geodir-cat-list-tax'  onchange='geodir_get_post_term(this);'>";
2846
			foreach ( $b_terms as $key => $val ) {
2847
				$ptype    = get_post_type_object( str_replace( "category", "", $key ) );
2848
				$cpt_name = __( $ptype->labels->singular_name, 'geodirectory' );
2849
				$tax_change_output .= "<option value='$key' " . selected( $key, $default_taxonomy, false ) . ">" . sprintf( __( '%s Categories', 'geodirectory' ), $cpt_name ) . "</option>";
2850
			}
2851
			$tax_change_output .= "</select>";
2852
		}
2853
2854
		if ( ! empty( $b_terms ) ) {
2855
			$terms = $default_taxonomy != '' && isset( $b_terms[ $default_taxonomy ] ) ? $b_terms[ $default_taxonomy ] : reset( $b_terms );// get the first array
2856
			global $cat_count;//make global so we can change via function
2857
			$cat_count = 0;
2858
			?>
2859 1
			<div class="geodir-category-list-in clearfix">
2860 1
				<div class="geodir-cat-list clearfix">
2861 1
					<?php
2862 1
					echo $before_title . __( $title ) . $after_title;
2863 1
2864
					echo $tax_change_output;
2865
2866
					echo '<ul class="geodir-popular-cat-list">';
2867
2868
					geodir_helper_cat_list_output( $terms, $category_limit, $category_restrict);
2869
2870
					echo '</ul>';
2871
					?>
2872
				</div>
2873
				<?php
2874
				$hide = '';
2875
				if ( $cat_count < $category_limit ) {
2876
					$hide = 'style="display:none;"';
2877 1
				}
2878 1
				echo "<div class='geodir-cat-list-more' $hide >";
2879 1
				echo '<a href="javascript:void(0)" class="geodir-morecat geodir-showcat">' . __( 'More Categories', 'geodirectory' ) . '</a>';
2880 2
				echo '<a href="javascript:void(0)" class="geodir-morecat geodir-hidecat geodir-hide">' . __( 'Less Categories', 'geodirectory' ) . '</a>';
2881 2
				echo "</div>";
2882
				/* add scripts */
2883
				add_action( 'wp_footer', 'geodir_popular_category_add_scripts', 100 );
2884
				?>
2885
			</div>
2886
			<?php
2887
		}
2888
	}
2889
	echo $after_widget;
2890
}
2891
2892
/**
2893
 * Generates category list HTML.
2894
 *
2895
 * @since   1.0.0
2896
 * @package GeoDirectory
2897
 * @global string $geodir_post_category_str The geodirectory post category.
2898 2
 *
2899
 * @param array $terms                      An array of term objects.
2900
 * @param int $category_limit               Number of categories to display by default.
2901 2
 * @param bool $category_restrict           If the cat limit shoudl be hidden or not shown.
2902
 */
2903 2
function geodir_helper_cat_list_output( $terms, $category_limit , $category_restrict=false) {
2904 2
	global $geodir_post_category_str, $cat_count;
2905
	$term_icons = geodir_get_term_icon();
2906 2
2907 2
	$geodir_post_category_str = array();
2908
2909 2
2910 2
	foreach ( $terms as $cat ) {
2911
		$post_type     = str_replace( "category", "", $cat->taxonomy );
2912 2
		$term_icon_url = ! empty( $term_icons ) && isset( $term_icons[ $cat->term_id ] ) ? $term_icons[ $cat->term_id ] : '';
2913 2
2914
		$cat_count ++;
2915
2916
		$geodir_post_category_str[] = array( 'posttype' => $post_type, 'termid' => $cat->term_id );
2917
2918 2
		$class_row  = $cat_count > $category_limit ? 'geodir-pcat-hide geodir-hide' : 'geodir-pcat-show';
2919 2
		if($category_restrict && $cat_count > $category_limit ){
2920 2
			continue;
2921
		}
2922 2
		$total_post = $cat->count;
2923 2
2924 2
		$term_link = get_term_link( $cat, $cat->taxonomy );
2925
		/**
2926 2
		 * Filer the category term link.
2927
		 *
2928 2
		 * @since 1.4.5
2929
		 *
2930 2
		 * @param string $term_link The term permalink.
2931
		 * @param int $cat          ->term_id The term id.
2932 2
		 * @param string $post_type Wordpress post type.
2933 2
		 */
2934 2
		$term_link = apply_filters( 'geodir_category_term_link', $term_link, $cat->term_id, $post_type );
2935
2936
		echo '<li class="' . $class_row . '"><a href="' . $term_link . '">';
2937
		echo '<img alt="' . esc_attr( $cat->name ) . ' icon" style="height:20px;vertical-align:middle;" src="' . $term_icon_url . '"/> <span class="cat-link">';
2938
		echo $cat->name . '</span> <span class="geodir_term_class geodir_link_span geodir_category_class_' . $post_type . '_' . $cat->term_id . '">(' . $total_post . ')</span> ';
2939
		echo '</a></li>';
2940
	}
2941
}
2942
2943
/**
2944 2
 * Generates listing slider HTML.
2945
 *
2946 2
 * @since   1.0.0
2947
 * @package GeoDirectory
2948 2
 * @global object $post          The current post object.
2949 2
 *
2950
 * @param array|string $args     Display arguments including before_title, after_title, before_widget, and after_widget.
2951 2
 * @param array|string $instance The settings for the particular instance of the widget.
2952
 */
2953
function geodir_listing_slider_widget_output( $args = '', $instance = '' ) {
2954
	// prints the widget
2955
	extract( $args, EXTR_SKIP );
2956
2957
	echo $before_widget;
2958
2959
	/** This filter is documented in geodirectory_widgets.php */
2960
	$title = empty( $instance['title'] ) ? '' : apply_filters( 'widget_title', __( $instance['title'], 'geodirectory' ) );
2961
	/**
2962 2
	 * Filter the widget post type.
2963
	 *
2964 2
	 * @since 1.0.0
2965
	 *
2966 2
	 * @param string $instance ['post_type'] Post type of listing.
2967 2
	 */
2968
	$post_type = empty( $instance['post_type'] ) ? 'gd_place' : apply_filters( 'widget_post_type', $instance['post_type'] );
2969 2
	/**
2970
	 * Filter the widget's term.
2971
	 *
2972
	 * @since 1.0.0
2973
	 *
2974
	 * @param string $instance ['category'] Filter by term. Can be any valid term.
2975
	 */
2976
	$category = empty( $instance['category'] ) ? '0' : apply_filters( 'widget_category', $instance['category'] );
2977
	/**
2978
	 * Filter widget's "add_location_filter" value.
2979
	 *
2980
	 * @since 1.0.0
2981
	 *
2982
	 * @param string|bool $instance ['add_location_filter'] Do you want to add location filter? Can be 1 or 0.
2983
	 */
2984
	$add_location_filter = empty( $instance['add_location_filter'] ) ? '0' : apply_filters( 'widget_add_location_filter', $instance['add_location_filter'] );
2985
	/**
2986
	 * Filter the widget listings limit.
2987
	 *
2988
	 * @since 1.0.0
2989
	 *
2990
	 * @param string $instance ['post_number'] Number of listings to display.
2991
	 */
2992
	$post_number = empty( $instance['post_number'] ) ? '5' : apply_filters( 'widget_post_number', $instance['post_number'] );
2993
	/**
2994
	 * Filter the widget listings limit shown at one time.
2995
	 *
2996
	 * @since 1.5.0
2997
	 *
2998
	 * @param string $instance ['max_show'] Number of listings to display on screen.
2999
	 */
3000
	$max_show = empty( $instance['max_show'] ) ? '1' : apply_filters( 'widget_max_show', $instance['max_show'] );
3001
	/**
3002
	 * Filter the widget slide width.
3003
	 *
3004
	 * @since 1.5.0
3005
	 *
3006
	 * @param string $instance ['slide_width'] Width of the slides shown.
3007
	 */
3008
	$slide_width = empty( $instance['slide_width'] ) ? '' : apply_filters( 'widget_slide_width', $instance['slide_width'] );
3009
	/**
3010
	 * Filter widget's "show title" value.
3011 2
	 *
3012 2
	 * @since 1.0.0
3013
	 *
3014 2
	 * @param string|bool $instance ['show_title'] Do you want to display title? Can be 1 or 0.
3015 2
	 */
3016
	$show_title = empty( $instance['show_title'] ) ? '' : apply_filters( 'widget_show_title', $instance['show_title'] );
3017 2
	/**
3018 2
	 * Filter widget's "slideshow" value.
3019 2
	 *
3020 2
	 * @since 1.0.0
3021
	 *
3022 2
	 * @param int $instance ['slideshow'] Setup a slideshow for the slider to animate automatically.
3023 2
	 */
3024 1
	$slideshow = empty( $instance['slideshow'] ) ? 0 : apply_filters( 'widget_slideshow', $instance['slideshow'] );
3025 1
	/**
3026
	 * Filter widget's "animationLoop" value.
3027
	 *
3028
	 * @since 1.0.0
3029
	 *
3030
	 * @param int $instance ['animationLoop'] Gives the slider a seamless infinite loop.
3031
	 */
3032
	$animationLoop = empty( $instance['animationLoop'] ) ? 0 : apply_filters( 'widget_animationLoop', $instance['animationLoop'] );
3033
	/**
3034
	 * Filter widget's "directionNav" value.
3035 2
	 *
3036
	 * @since 1.0.0
3037 2
	 *
3038 2
	 * @param int $instance ['directionNav'] Enable previous/next arrow navigation?. Can be 1 or 0.
3039 2
	 */
3040
	$directionNav = empty( $instance['directionNav'] ) ? 0 : apply_filters( 'widget_directionNav', $instance['directionNav'] );
3041 2
	/**
3042
	 * Filter widget's "slideshowSpeed" value.
3043
	 *
3044
	 * @since 1.0.0
3045
	 *
3046
	 * @param int $instance ['slideshowSpeed'] Set the speed of the slideshow cycling, in milliseconds.
3047
	 */
3048
	$slideshowSpeed = empty( $instance['slideshowSpeed'] ) ? 5000 : apply_filters( 'widget_slideshowSpeed', $instance['slideshowSpeed'] );
3049
	/**
3050
	 * Filter widget's "animationSpeed" value.
3051
	 *
3052 2
	 * @since 1.0.0
3053 2
	 *
3054
	 * @param int $instance ['animationSpeed'] Set the speed of animations, in milliseconds.
3055 2
	 */
3056
	$animationSpeed = empty( $instance['animationSpeed'] ) ? 600 : apply_filters( 'widget_animationSpeed', $instance['animationSpeed'] );
3057
	/**
3058
	 * Filter widget's "animation" value.
3059
	 *
3060
	 * @since 1.0.0
3061
	 *
3062 2
	 * @param string $instance ['animation'] Controls the animation type, "fade" or "slide".
3063 2
	 */
3064 2
	$animation = empty( $instance['animation'] ) ? 'slide' : apply_filters( 'widget_animation', $instance['animation'] );
3065
	/**
3066
	 * Filter widget's "list_sort" type.
3067
	 *
3068
	 * @since 1.0.0
3069
	 *
3070
	 * @param string $instance ['list_sort'] Listing sort by type.
3071
	 */
3072
	$list_sort          = empty( $instance['list_sort'] ) ? 'latest' : apply_filters( 'widget_list_sort', $instance['list_sort'] );
3073
	$show_featured_only = ! empty( $instance['show_featured_only'] ) ? 1 : null;
3074
3075
	wp_enqueue_script( 'geodirectory-jquery-flexslider-js' );
3076
	?>
3077
	<script type="text/javascript">
3078
		jQuery(window).load(function () {
3079
			// chrome 53 introduced a bug, so we need to repaint the slider when shown.
3080
			jQuery('.geodir-slides').addClass('flexslider-fix-rtl');
3081
3082
			jQuery('#geodir_widget_carousel').flexslider({
3083
				animation: "slide",
3084
				selector: ".geodir-slides > li",
3085
				namespace: "geodir-",
3086
				controlNav: false,
3087
				directionNav: false,
3088
				animationLoop: false,
3089
				slideshow: false,
3090
				itemWidth: 75,
3091
				itemMargin: 5,
3092
				asNavFor: '#geodir_widget_slider',
3093
				rtl: <?php echo( is_rtl() ? 'true' : 'false' ); /* fix rtl issue */ ?>
3094
			});
3095
3096
			jQuery('#geodir_widget_slider').flexslider({
3097
				animation: "<?php echo $animation;?>",
3098
				selector: ".geodir-slides > li",
3099
				namespace: "geodir-",
3100
				controlNav: true,
3101
				animationLoop: <?php echo $animationLoop;?>,
3102
				slideshow: <?php echo $slideshow;?>,
3103
				slideshowSpeed: <?php echo $slideshowSpeed;?>,
3104
				animationSpeed: <?php echo $animationSpeed;?>,
3105
				directionNav: <?php echo $directionNav;?>,
3106
				maxItems: <?php echo $max_show;?>,
3107
				move: 1,
3108
				<?php if ( $slide_width ) {
3109
				echo "itemWidth: " . $slide_width . ",";
3110
			}?>
3111
				sync: "#geodir_widget_carousel",
3112
				start: function (slider) {
3113 2
3114 2
					// chrome 53 introduced a bug, so we need to repaint the slider when shown.
3115
					jQuery('.geodir-slides').removeClass('flexslider-fix-rtl');
3116
3117
					jQuery('.geodir-listing-flex-loader').hide();
3118
					jQuery('#geodir_widget_slider').css({'visibility': 'visible'});
3119
					jQuery('#geodir_widget_carousel').css({'visibility': 'visible'});
3120
				},
3121
				rtl: <?php echo( is_rtl() ? 'true' : 'false' ); /* fix rtl issue */ ?>
3122
			});
3123
		});
3124
	</script>
3125
	<?php
3126
	$query_args = array(
3127
		'posts_per_page' => $post_number,
3128
		'is_geodir_loop' => true,
3129
		'gd_location'    => $add_location_filter ? true : false,
3130
		'post_type'      => $post_type,
3131
		'order_by'       => $list_sort
3132 2
	);
3133
3134
	if ( $show_featured_only ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $show_featured_only 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...
3135 2
		$query_args['show_featured_only'] = 1;
3136
	}
3137 2
3138
	if ( $category != 0 || $category != '' ) {
3139
		$category_taxonomy = geodir_get_taxonomies( $post_type );
3140 2
		$tax_query         = array(
3141
			'taxonomy' => $category_taxonomy[0],
3142
			'field'    => 'id',
3143
			'terms'    => $category
3144
		);
3145
3146
		$query_args['tax_query'] = array( $tax_query );
3147 2
	}
3148
3149
	// we want listings with featured image only
3150
	$query_args['featured_image_only'] = 1;
3151
3152
	if ( $post_type == 'gd_event' ) {
3153
		$query_args['gedir_event_listing_filter'] = 'upcoming';
3154 2
	}// show only upcoming events
3155
3156
	$widget_listings = geodir_get_widget_listings( $query_args );
3157
	if ( ! empty( $widget_listings ) || ( isset( $with_no_results ) && $with_no_results ) ) {
3158
		if ( $title ) {
3159
			echo $before_title . $title . $after_title;
3160
		}
3161 2
3162
		global $post;
3163
3164
		$current_post = $post;// keep current post info
3165
3166
		$widget_main_slides = '';
3167
		$nav_slides         = '';
3168 2
		$widget_slides      = 0;
3169
3170
		foreach ( $widget_listings as $widget_listing ) {
3171
			global $gd_widget_listing_type;
3172
			$post         = $widget_listing;
3173
			$widget_image = geodir_get_featured_image( $post->ID, 'thumbnail', get_option( 'geodir_listing_no_img' ) );
3174
3175 2
			if ( ! empty( $widget_image ) ) {
3176
				if ( $widget_image->height >= 200 ) {
3177
					$widget_spacer_height = 0;
3178
				} else {
3179
					$widget_spacer_height = ( ( 200 - $widget_image->height ) / 2 );
3180
				}
3181
3182 2
				$widget_main_slides .= '<li class="geodir-listing-slider-widget"><img class="geodir-listing-slider-spacer" src="' . geodir_plugin_url() . "/geodirectory-assets/images/spacer.gif" . '" alt="' . $widget_image->title . '" title="' . $widget_image->title . '" style="max-height:' . $widget_spacer_height . 'px !important;margin:0 auto;" width="100" />';
3183
3184
				$title = '';
3185
				if ( $show_title ) {
3186
					$title_html     = '<div class="geodir-slider-title"><a href="' . get_permalink( $post->ID ) . '">' . get_the_title( $post->ID ) . '</a></div>';
3187
					$post_id        = $post->ID;
3188
					$post_permalink = get_permalink( $post->ID );
3189 2
					$post_title     = get_the_title( $post->ID );
3190 2
					/**
3191
					 * Filter the listing slider widget title.
3192
					 *
3193 2
					 * @since 1.6.1
3194 1
					 *
3195 1
					 * @param string $title_html     The html output of the title.
3196
					 * @param int $post_id           The post id.
3197
					 * @param string $post_permalink The post permalink url.
3198
					 * @param string $post_title     The post title text.
3199 1
					 */
3200
					$title = apply_filters( 'geodir_listing_slider_title', $title_html, $post_id, $post_permalink, $post_title );
3201 2
				}
3202 2
3203
				$widget_main_slides .= $title . '<img src="' . $widget_image->src . '" alt="' . $widget_image->title . '" title="' . $widget_image->title . '" style="max-height:200px;margin:0 auto;" /></li>';
3204 2
				$nav_slides .= '<li><img src="' . $widget_image->src . '" alt="' . $widget_image->title . '" title="' . $widget_image->title . '" style="max-height:48px;margin:0 auto;" /></li>';
3205 2
				$widget_slides ++;
3206
			}
3207 2
		}
3208
		?>
3209
		<div class="flex-container" style="min-height:200px;">
3210
			<div class="geodir-listing-flex-loader"><i class="fa fa-refresh fa-spin"></i></div>
3211
			<div id="geodir_widget_slider" class="geodir_flexslider">
3212
				<ul class="geodir-slides clearfix"><?php echo $widget_main_slides; ?></ul>
3213
			</div>
3214 1
			<?php if ( $widget_slides > 1 ) { ?>
3215 1
				<div id="geodir_widget_carousel" class="geodir_flexslider">
3216 1
					<ul class="geodir-slides clearfix"><?php echo $nav_slides; ?></ul>
3217
				</div>
3218
			<?php } ?>
3219 2
		</div>
3220 2
		<?php
3221 2
		$GLOBALS['post'] = $current_post;
3222
		setup_postdata( $current_post );
3223 2
	}
3224 2
	echo $after_widget;
3225 2
}
3226
3227
3228
/**
3229
 * Generates login box HTML.
3230
 *
3231
 * @since   1.0.0
3232
 * @package GeoDirectory
3233
 * @global object $current_user  Current user object.
3234
 *
3235
 * @param array|string $args     Display arguments including before_title, after_title, before_widget, and after_widget.
3236
 * @param array|string $instance The settings for the particular instance of the widget.
3237
 */
3238
function geodir_loginwidget_output( $args = '', $instance = '' ) {
3239
	//print_r($args);
3240
	//print_r($instance);
3241
	// prints the widget
3242
	extract( $args, EXTR_SKIP );
3243
3244
	/** This filter is documented in geodirectory_widgets.php */
3245
	$title = empty( $instance['title'] ) ? __( 'My Dashboard', 'geodirectory' ) : apply_filters( 'my_dashboard_widget_title', __( $instance['title'], 'geodirectory' ) );
3246
3247
	echo $before_widget;
3248
	echo $before_title . $title . $after_title;
3249
3250
	if ( is_user_logged_in() ) {
3251
		global $current_user;
3252 2
3253 2
		$author_link = get_author_posts_url( $current_user->data->ID );
3254 2
		$author_link = geodir_getlink( $author_link, array( 'geodir_dashbord' => 'true' ), false );
3255
3256
		echo '<ul class="geodir-loginbox-list">';
3257
		ob_start();
3258
		?>
3259 2
		<li><a class="signin"
3260
		       href="<?php echo wp_logout_url( home_url() ); ?>"><?php _e( 'Logout', 'geodirectory' ); ?></a></li>
3261
		<?php
3262 2
		$post_types                           = geodir_get_posttypes( 'object' );
3263
		$show_add_listing_post_types_main_nav = get_option( 'geodir_add_listing_link_user_dashboard' );
3264
		$geodir_allow_posttype_frontend       = get_option( 'geodir_allow_posttype_frontend' );
0 ignored issues
show
Unused Code introduced by
$geodir_allow_posttype_frontend 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...
3265 2
3266
		if ( ! empty( $show_add_listing_post_types_main_nav ) ) {
3267
			$addlisting_links = '';
3268
			foreach ( $post_types as $key => $postobj ) {
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...
3269
3270
				if ( in_array( $key, $show_add_listing_post_types_main_nav ) ) {
3271
3272
					if ( $add_link = geodir_get_addlisting_link( $key ) ) {
3273
3274
						$name = $postobj->labels->name;
3275
3276
						$selected = '';
3277
						if ( geodir_get_current_posttype() == $key && geodir_is_page( 'add-listing' ) ) {
3278 2
							$selected = 'selected="selected"';
3279
						}
3280
3281
						/**
3282 2
						 * Filter add listing link.
3283
						 *
3284
						 * @since 1.0.0
3285 2
						 *
3286 2
						 * @param string $add_link  Add listing link.
3287 2
						 * @param string $key       Add listing array key.
3288 2
						 * @param int $current_user ->ID Current user ID.
3289
						 */
3290 2
						$add_link = apply_filters( 'geodir_dashboard_link_add_listing', $add_link, $key, $current_user->ID );
3291
3292 2
						$addlisting_links .= '<option ' . $selected . ' value="' . $add_link . '">' . __( ucfirst( $name ), 'geodirectory' ) . '</option>';
3293 1
3294 1
					}
3295
				}
3296 2
3297 1
			}
3298 1
3299 View Code Duplication
			if ( $addlisting_links != '' ) { ?>
3300 2
3301
				<li><select id="geodir_add_listing" class="chosen_select" onchange="window.location.href=this.value"
3302
				            option-autoredirect="1" name="geodir_add_listing" option-ajaxchosen="false"
3303
				            data-placeholder="<?php echo esc_attr( __( 'Add Listing', 'geodirectory' ) ); ?>">
3304 2
						<option value="" disabled="disabled" selected="selected"
3305
						        style='display:none;'><?php echo esc_attr( __( 'Add Listing', 'geodirectory' ) ); ?></option>
3306
						<?php echo $addlisting_links; ?>
3307
					</select></li> <?php
3308
3309 2
			}
3310
3311
		}
3312 2
		// My Favourites in Dashboard
3313
		$show_favorite_link_user_dashboard = get_option( 'geodir_favorite_link_user_dashboard' );
3314 2
		$user_favourite                    = geodir_user_favourite_listing_count();
3315
3316
		if ( ! empty( $show_favorite_link_user_dashboard ) && ! empty( $user_favourite ) ) {
3317
			$favourite_links = '';
3318
3319
			foreach ( $post_types as $key => $postobj ) {
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...
3320
				if ( in_array( $key, $show_favorite_link_user_dashboard ) && array_key_exists( $key, $user_favourite ) ) {
3321
					$name           = $postobj->labels->name;
3322
					$post_type_link = geodir_getlink( $author_link, array(
3323
						'stype' => $key,
3324
						'list'  => 'favourite'
3325
					), false );
3326
3327
					$selected = '';
3328
3329 View Code Duplication
					if ( isset( $_REQUEST['list'] ) && $_REQUEST['list'] == 'favourite' && isset( $_REQUEST['stype'] ) && $_REQUEST['stype'] == $key && isset( $_REQUEST['geodir_dashbord'] ) ) {
3330
						$selected = 'selected="selected"';
3331
					}
3332 2
					/**
3333
					 * Filter favorite listing link.
3334 2
					 *
3335
					 * @since 1.0.0
3336 2
					 *
3337
					 * @param string $post_type_link Favorite listing link.
3338
					 * @param string $key            Favorite listing array key.
3339
					 * @param int $current_user      ->ID Current user ID.
3340
					 */
3341
					$post_type_link = apply_filters( 'geodir_dashboard_link_favorite_listing', $post_type_link, $key, $current_user->ID );
3342
3343
					$favourite_links .= '<option ' . $selected . ' value="' . $post_type_link . '">' . __( ucfirst( $name ), 'geodirectory' ) . '</option>';
3344
				}
3345
			}
3346
3347 View Code Duplication
			if ( $favourite_links != '' ) {
3348
				?>
3349
				<li>
3350
					<select id="geodir_my_favourites" class="chosen_select" onchange="window.location.href=this.value"
3351
					        option-autoredirect="1" name="geodir_my_favourites" option-ajaxchosen="false"
3352
					        data-placeholder="<?php echo esc_attr( __( 'My Favorites', 'geodirectory' ) ); ?>">
3353
						<option value="" disabled="disabled" selected="selected"
3354
						        style='display:none;'><?php echo esc_attr( __( 'My Favorites', 'geodirectory' ) ); ?></option>
3355
						<?php echo $favourite_links; ?>
3356
					</select>
3357
				</li>
3358
				<?php
3359
			}
3360 2
		}
3361 2
3362 2
3363 2
		$show_listing_link_user_dashboard = get_option( 'geodir_listing_link_user_dashboard' );
3364 2
		$user_listing                     = geodir_user_post_listing_count();
3365
3366
		if ( ! empty( $show_listing_link_user_dashboard ) && ! empty( $user_listing ) ) {
3367
			$listing_links = '';
3368
3369
			foreach ( $post_types as $key => $postobj ) {
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...
3370
				if ( in_array( $key, $show_listing_link_user_dashboard ) && array_key_exists( $key, $user_listing ) ) {
3371
					$name         = $postobj->labels->name;
3372
					$listing_link = geodir_getlink( $author_link, array( 'stype' => $key ), false );
3373 2
3374 2
					$selected = '';
3375 View Code Duplication
					if ( ! isset( $_REQUEST['list'] ) && isset( $_REQUEST['geodir_dashbord'] ) && isset( $_REQUEST['stype'] ) && $_REQUEST['stype'] == $key ) {
3376
						$selected = 'selected="selected"';
3377
					}
3378
3379
					/**
3380
					 * Filter my listing link.
3381
					 *
3382
					 * @since 1.0.0
3383
					 *
3384 2
					 * @param string $listing_link My listing link.
3385
					 * @param string $key          My listing array key.
3386 2
					 * @param int $current_user    ->ID Current user ID.
3387 2
					 */
3388 2
					$listing_link = apply_filters( 'geodir_dashboard_link_my_listing', $listing_link, $key, $current_user->ID );
3389 2
3390
					$listing_links .= '<option ' . $selected . ' value="' . $listing_link . '">' . __( ucfirst( $name ), 'geodirectory' ) . '</option>';
3391
				}
3392
			}
3393
3394 View Code Duplication
			if ( $listing_links != '' ) {
3395
				?>
3396 2
				<li>
3397
					<select id="geodir_my_listings" class="chosen_select" onchange="window.location.href=this.value"
3398 2
					        option-autoredirect="1" name="geodir_my_listings" option-ajaxchosen="false"
3399
					        data-placeholder="<?php echo esc_attr( __( 'My Listings', 'geodirectory' ) ); ?>">
3400 2
						<option value="" disabled="disabled" selected="selected"
3401 2
						        style='display:none;'><?php echo esc_attr( __( 'My Listings', 'geodirectory' ) ); ?></option>
3402 2
						<?php echo $listing_links; ?>
3403 2
					</select>
3404 2
				</li>
3405
				<?php
3406
			}
3407
		}
3408 2
3409 2
		$dashboard_link = ob_get_clean();
3410
		/**
3411 2
		 * Filter dashboard links HTML.
3412
		 *
3413
		 * @since 1.0.0
3414
		 *
3415
		 * @param string $dashboard_link Dashboard links HTML.
3416
		 */
3417
		echo apply_filters( 'geodir_dashboard_links', $dashboard_link );
3418
		echo '</ul>';
3419
3420
		/**
3421
		 * Called after the loginwidget form for logged in users.
3422
		 *
3423
		 * @since 1.6.6
3424
		 */
3425
		do_action( 'geodir_after_loginwidget_form_logged_in' );
3426
3427
3428
	} else {
3429
		?>
3430
		<?php
3431
		/**
3432 2
		 * Filter signup form action link.
3433
		 *
3434 2
		 * @since 1.0.0
3435
		 */
3436 2
		?>
3437
		<form name="loginform" class="loginform1"
3438
		      action="<?php echo geodir_login_url(); ?>"
3439
		      method="post">
3440
			<div class="geodir_form_row"><input placeholder="<?php _e( 'Email', 'geodirectory' ); ?>" name="log"
3441
			                                    type="text" class="textfield user_login1"/> <span
3442
					class="user_loginInfo"></span></div>
3443
			<div class="geodir_form_row"><input placeholder="<?php _e( 'Password', 'geodirectory' ); ?>"
3444
			                                    name="pwd" type="password"
3445
			                                    class="textfield user_pass1 input-text"/><span
3446
					class="user_passInfo"></span></div>
3447 2
3448
			<input type="hidden" name="redirect_to" value="<?php echo htmlspecialchars( geodir_curPageURL() ); ?>"/>
3449 2
			<input type="hidden" name="testcookie" value="1"/>
3450
3451 2
				<?php do_action( 'login_form' ); ?>
3452
3453
			<div class="geodir_form_row clearfix"><input type="submit" name="submit"
3454
			                                             value="<?php echo SIGN_IN_BUTTON; ?>" class="b_signin"/>
3455
3456
				<p class="geodir-new-forgot-link">
3457
					<?php
3458
					/**
3459
					 * Filter signup page register form link.
3460
					 *
3461
					 * @since 1.0.0
3462
					 */
3463
					?>
3464
					<a href="<?php echo geodir_login_url( array( 'signup' => true ) ); ?>"
3465
					   class="goedir-newuser-link"><?php echo NEW_USER_TEXT; ?></a>
3466
3467
					<?php
3468
					/**
3469
					 * Filter signup page forgot password form link.
3470
					 *
3471
					 * @since 1.0.0
3472
					 */
3473
					?>
3474
					<a href="<?php echo geodir_login_url( array( 'forgot' => true ) ); ?>"
3475 8
					   class="goedir-forgot-link"><?php echo FORGOT_PW_TEXT; ?></a></p></div>
3476 8
		</form>
3477
		<?php
3478
		/**
3479
		 * Called after the loginwidget form for logged out users.
3480 8
		 *
3481
		 * @since 1.6.6
3482 8
		 */
3483 7
		do_action( 'geodir_after_loginwidget_form_logged_out' );
3484 7
	}
3485 7
3486 7
	echo $after_widget;
3487 7
}
3488 7
3489
3490 7
/**
3491 2
 * Generates popular postview HTML.
3492 2
 *
3493 2
 * @since   1.0.0
3494 2
 * @since   1.5.1 View all link fixed for location filter disabled.
3495 2
 * @package GeoDirectory
3496 2
 * @global object $post                    The current post object.
3497
 * @global string $gridview_columns_widget The girdview style of the listings for widget.
3498 7
 * @global bool $geodir_is_widget_listing  Is this a widget listing?. Default: false.
3499
 * @global object $gd_session              GeoDirectory Session object.
3500 7
 *
3501 7
 * @param array|string $args               Display arguments including before_title, after_title, before_widget, and
3502
 *                                         after_widget.
3503 7
 * @param array|string $instance           The settings for the particular instance of the widget.
3504
 */
3505
function geodir_popular_postview_output( $args = '', $instance = '' ) {
3506
	global $gd_session;
3507 7
3508
	// prints the widget
3509
	extract( $args, EXTR_SKIP );
3510
3511
	echo $before_widget;
3512
3513
	/** This filter is documented in geodirectory_widgets.php */
3514
	$title = empty( $instance['title'] ) ? geodir_ucwords( $instance['category_title'] ) : apply_filters( 'widget_title', __( $instance['title'], 'geodirectory' ) );
3515
	/**
3516 7
	 * Filter the widget post type.
3517
	 *
3518
	 * @since 1.0.0
3519
	 *
3520
	 * @param string $instance ['post_type'] Post type of listing.
3521
	 */
3522
	$post_type = empty( $instance['post_type'] ) ? 'gd_place' : apply_filters( 'widget_post_type', $instance['post_type'] );
3523
	/**
3524
	 * Filter the widget's term.
3525
	 *
3526
	 * @since 1.0.0
3527
	 *
3528
	 * @param string $instance ['category'] Filter by term. Can be any valid term.
3529
	 */
3530
	$category = empty( $instance['category'] ) ? '0' : apply_filters( 'widget_category', $instance['category'] );
3531
	/**
3532
	 * Filter the widget listings limit.
3533
	 *
3534
	 * @since 1.0.0
3535
	 *
3536
	 * @param string $instance ['post_number'] Number of listings to display.
3537
	 */
3538
	$post_number = empty( $instance['post_number'] ) ? '5' : apply_filters( 'widget_post_number', $instance['post_number'] );
3539
	/**
3540
	 * Filter widget's "layout" type.
3541
	 *
3542
	 * @since 1.0.0
3543
	 *
3544 7
	 * @param string $instance ['layout'] Widget layout type.
3545
	 */
3546 7
	$layout = empty( $instance['layout'] ) ? 'gridview_onehalf' : apply_filters( 'widget_layout', $instance['layout'] );
3547 7
	/**
3548
	 * Filter widget's "add_location_filter" value.
3549 1
	 *
3550
	 * @since 1.0.0
3551
	 *
3552
	 * @param string|bool $instance ['add_location_filter'] Do you want to add location filter? Can be 1 or 0.
3553
	 */
3554
	$add_location_filter = empty( $instance['add_location_filter'] ) ? '0' : apply_filters( 'widget_add_location_filter', $instance['add_location_filter'] );
3555
	/**
3556
	 * Filter widget's listing width.
3557
	 *
3558
	 * @since 1.0.0
3559
	 *
3560
	 * @param string $instance ['listing_width'] Listing width.
3561
	 */
3562 8
	$listing_width = empty( $instance['listing_width'] ) ? '' : apply_filters( 'widget_listing_width', $instance['listing_width'] );
3563
	/**
3564
	 * Filter widget's "list_sort" type.
3565
	 *
3566 8
	 * @since 1.0.0
3567
	 *
3568
	 * @param string $instance ['list_sort'] Listing sort by type.
3569
	 */
3570 8
	$list_sort             = empty( $instance['list_sort'] ) ? 'latest' : apply_filters( 'widget_list_sort', $instance['list_sort'] );
3571 8
	$use_viewing_post_type = ! empty( $instance['use_viewing_post_type'] ) ? true : false;
3572 8
3573 2
	// set post type to current viewing post type
3574 View Code Duplication
	if ( $use_viewing_post_type ) {
3575
		$current_post_type = geodir_get_current_posttype();
3576 6
		if ( $current_post_type != '' && $current_post_type != $post_type ) {
3577
			$post_type = $current_post_type;
3578
			$category  = array(); // old post type category will not work for current changed post type
3579
		}
3580 6
	}
3581 6
	// replace widget title dynamically
3582 6
	$posttype_plural_label   = __( get_post_type_plural_label( $post_type ), 'geodirectory' );
3583 6
	$posttype_singular_label = __( get_post_type_singular_label( $post_type ), 'geodirectory' );
3584
3585 6
	$title = str_replace( "%posttype_plural_label%", $posttype_plural_label, $title );
3586 5
	$title = str_replace( "%posttype_singular_label%", $posttype_singular_label, $title );
3587 5
3588 View Code Duplication
	if ( isset( $instance['character_count'] ) ) {
3589 6
		/**
3590
		 * Filter the widget's excerpt character count.
3591
		 *
3592
		 * @since 1.0.0
3593 4
		 *
3594 4
		 * @param int $instance ['character_count'] Excerpt character count.
3595
		 */
3596
		$character_count = apply_filters( 'widget_list_character_count', $instance['character_count'] );
3597
	} else {
3598
		$character_count = '';
3599
	}
3600
3601
	if ( empty( $title ) || $title == 'All' ) {
3602
		$title .= ' ' . __( get_post_type_plural_label( $post_type ), 'geodirectory' );
3603
	}
3604
3605
	$location_url = array();
3606
	$city         = get_query_var( 'gd_city' );
3607
	if ( ! empty( $city ) ) {
3608
		$country = get_query_var( 'gd_country' );
3609
		$region  = get_query_var( 'gd_region' );
3610
3611
		$geodir_show_location_url = get_option( 'geodir_show_location_url' );
3612
3613
		if ( $geodir_show_location_url == 'all' ) {
3614
			if ( $country != '' ) {
3615
				$location_url[] = $country;
3616
			}
3617
3618
			if ( $region != '' ) {
3619
				$location_url[] = $region;
3620
			}
3621
		} else if ( $geodir_show_location_url == 'country_city' ) {
3622
			if ( $country != '' ) {
3623
				$location_url[] = $country;
3624
			}
3625
		} else if ( $geodir_show_location_url == 'region_city' ) {
3626
			if ( $region != '' ) {
3627
				$location_url[] = $region;
3628
			}
3629
		}
3630
3631
		$location_url[] = $city;
3632 4
	}
3633 4
3634
	$location_url  = implode( '/', $location_url );
3635
	$skip_location = false;
3636
	if ( ! $add_location_filter && $gd_session->get( 'gd_multi_location' ) ) {
3637
		$skip_location = true;
3638
		$gd_session->un_set( 'gd_multi_location' );
3639
	}
3640
3641
	if ( get_option( 'permalink_structure' ) ) {
3642
		$viewall_url = get_post_type_archive_link( $post_type );
3643
	} else {
3644
		$viewall_url = get_post_type_archive_link( $post_type );
3645
	}
3646 1
3647 1
	if ( ! empty( $category ) && $category[0] != '0' ) {
3648
		global $geodir_add_location_url;
3649
3650
		$geodir_add_location_url = '0';
3651
3652
		if ( $add_location_filter != '0' ) {
3653
			$geodir_add_location_url = '1';
3654
		}
3655
3656
		$viewall_url = get_term_link( (int) $category[0], $post_type . 'category' );
3657
3658
		$geodir_add_location_url = null;
3659
	}
3660
	if ( $skip_location ) {
3661 5
		$gd_session->set( 'gd_multi_location', 1 );
3662 4
	}
3663
3664 1
	if ( is_wp_error( $viewall_url ) ) {
3665 1
		$viewall_url = '';
3666
	}
3667
3668
	$query_args = array(
3669
		'posts_per_page' => $post_number,
3670
		'is_geodir_loop' => true,
3671
		'gd_location'    => $add_location_filter ? true : false,
3672
		'post_type'      => $post_type,
3673
		'order_by'       => $list_sort
3674
	);
3675
3676
	if ( $character_count ) {
3677
		$query_args['excerpt_length'] = $character_count;
3678
	}
3679
3680
	if ( ! empty( $instance['show_featured_only'] ) ) {
3681
		$query_args['show_featured_only'] = 1;
3682
	}
3683
3684
	if ( ! empty( $instance['show_special_only'] ) ) {
3685
		$query_args['show_special_only'] = 1;
3686
	}
3687
3688 View Code Duplication
	if ( ! empty( $instance['with_pics_only'] ) ) {
3689
		$query_args['with_pics_only']      = 0;
3690
		$query_args['featured_image_only'] = 1;
3691
	}
3692
3693
	if ( ! empty( $instance['with_videos_only'] ) ) {
3694
		$query_args['with_videos_only'] = 1;
3695
	}
3696
	$with_no_results = ! empty( $instance['without_no_results'] ) ? false : true;
3697 4
3698 View Code Duplication
	if ( ! empty( $category ) && $category[0] != '0' ) {
3699
		$category_taxonomy = geodir_get_taxonomies( $post_type );
3700
3701
		######### WPML #########
3702
		if ( function_exists( 'icl_object_id' ) ) {
3703
			$category = gd_lang_object_ids( $category, $category_taxonomy[0] );
3704
		}
3705
		######### WPML #########
3706
3707
		$tax_query = array(
3708
			'taxonomy' => $category_taxonomy[0],
3709
			'field'    => 'id',
3710
			'terms'    => $category
3711 1
		);
3712
3713
		$query_args['tax_query'] = array( $tax_query );
3714
	}
3715
3716
	global $gridview_columns_widget, $geodir_is_widget_listing;
3717
3718
	$widget_listings = geodir_get_widget_listings( $query_args );
3719
3720
	if ( ! empty( $widget_listings ) || $with_no_results ) {
3721
		?>
3722
		<div class="geodir_locations geodir_location_listing">
3723
3724
			<?php
3725
			/**
3726
			 * Called before the div containing the title and view all link in popular post view widget.
3727
			 *
3728
			 * @since 1.0.0
3729
			 */
3730
			do_action( 'geodir_before_view_all_link_in_widget' ); ?>
3731
			<div class="geodir_list_heading clearfix">
3732
				<?php echo $before_title . $title . $after_title; ?>
3733
				<a href="<?php echo $viewall_url; ?>"
3734
				   class="geodir-viewall"><?php _e( 'View all', 'geodirectory' ); ?></a>
3735
			</div>
3736
			<?php
3737
			/**
3738
			 * Called after the div containing the title and view all link in popular post view widget.
3739
			 *
3740
			 * @since 1.0.0
3741
			 */
3742
			do_action( 'geodir_after_view_all_link_in_widget' ); ?>
3743
			<?php
3744 View Code Duplication
			if ( strstr( $layout, 'gridview' ) ) {
3745
				$listing_view_exp        = explode( '_', $layout );
3746
				$gridview_columns_widget = $layout;
3747
				$layout                  = $listing_view_exp[0];
3748
			} else {
3749
				$gridview_columns_widget = '';
3750
			}
3751
3752
			/**
3753
			 * Filter the widget listing listview template path.
3754
			 *
3755
			 * @since 1.0.0
3756
			 */
3757
			$template = apply_filters( "geodir_template_part-widget-listing-listview", geodir_locate_template( 'widget-listing-listview' ) );
3758
			if ( ! isset( $character_count ) ) {
3759
				/**
3760
				 * Filter the widget's excerpt character count.
3761
				 *
3762
				 * @since 1.0.0
3763
				 *
3764
				 * @param int $instance ['character_count'] Excerpt character count.
3765
				 */
3766
				$character_count = $character_count == '' ? 50 : apply_filters( 'widget_character_count', $character_count );
3767
			}
3768
3769
			global $post, $map_jason, $map_canvas_arr;
3770
3771 1
			$current_post             = $post;
3772 1
			$current_map_jason        = $map_jason;
3773 1
			$current_map_canvas_arr   = $map_canvas_arr;
3774 1
			$geodir_is_widget_listing = true;
3775 1
3776 1
			/**
3777
			 * Includes related listing listview template.
3778 1
			 *
3779
			 * @since 1.0.0
3780 1
			 */
3781 1
			include( $template );
3782
3783 1
			$geodir_is_widget_listing = false;
3784 1
3785
			$GLOBALS['post'] = $current_post;
3786 1
			if ( ! empty( $current_post ) ) {
3787
				setup_postdata( $current_post );
3788
			}
3789
			$map_jason      = $current_map_jason;
3790
			$map_canvas_arr = $current_map_canvas_arr;
3791
			?>
3792
		</div>
3793
		<?php
3794
	}
3795 1
	echo $after_widget;
3796
3797 1
}
3798
3799 1
3800 1
/*-----------------------------------------------------------------------------------*/
3801 1
/*  Review count functions
3802 1
/*-----------------------------------------------------------------------------------*/
3803 1
/**
3804 1
 * Count reviews by term ID.
3805 1
 *
3806 1
 * @since   1.0.0
3807 1
 * @since   1.5.1 Added filter to change SQL.
3808 1
 * @package GeoDirectory
3809
 * @global object $wpdb          WordPress Database object.
3810 1
 * @global string $plugin_prefix Geodirectory plugin table prefix.
3811 1
 *
3812 1
 * @param int $term_id           The term ID.
3813
 * @param int $taxonomy          The taxonomy Id.
3814 1
 * @param string $post_type      The post type.
3815
 *
3816 1
 * @return int Reviews count.
3817 1
 */
3818 1
function geodir_count_reviews_by_term_id( $term_id, $taxonomy, $post_type ) {
3819 1
	global $wpdb, $plugin_prefix;
3820 1
3821 1
	$detail_table = $plugin_prefix . $post_type . '_detail';
3822 1
3823 1
	$sql = "SELECT COALESCE(SUM(rating_count),0) FROM " . $detail_table . " WHERE post_status = 'publish' AND rating_count > 0 AND FIND_IN_SET(" . $term_id . ", " . $taxonomy . ")";
3824
3825 1
	/**
3826
	 * Filter count review sql query.
3827 1
	 *
3828 1
	 * @since 1.5.1
3829
	 *
3830
	 * @param string $sql       Database sql query..
3831
	 * @param int $term_id      The term ID.
3832
	 * @param int $taxonomy     The taxonomy Id.
3833
	 * @param string $post_type The post type.
3834
	 */
3835
	$sql = apply_filters( 'geodir_count_reviews_by_term_sql', $sql, $term_id, $taxonomy, $post_type );
3836
3837
	$count = $wpdb->get_var( $sql );
3838
3839
	return $count;
3840
}
3841
3842
/**
3843
 * Count reviews by terms.
3844
 *
3845
 * @since   1.0.0
3846 1
 * @since   1.6.1 Fixed add listing page load time.
3847
 * @package GeoDirectory
3848
 *
3849 1
 * @global object $gd_session GeoDirectory Session object.
3850 1
 *
3851
 * @param bool $force_update  Force update option value?. Default.false.
3852 1
 *
3853 1
 * @return array Term array data.
3854 1
 */
3855 1
function geodir_count_reviews_by_terms( $force_update = false, $post_ID = 0 ) {
3856
	/**
3857 1
	 * Filter review count option data.
3858 1
	 *
3859
	 * @since 1.0.0
3860 1
	 * @since 1.6.1 Added $post_ID param.
3861 1
	 *
3862
	 * @param bool $force_update Force update option value?. Default.false.
3863 1
	 * @param int $post_ID       The post id to update if any.
3864 1
	 */
3865
	$option_data = apply_filters( 'geodir_count_reviews_by_terms_before', '', $force_update, $post_ID );
3866 1
	if ( ! empty( $option_data ) ) {
3867 1
		return $option_data;
3868
	}
3869 1
3870 1
	$option_data = get_option( 'geodir_global_review_count' );
3871
3872 1
	if ( ! $option_data || $force_update ) {
3873 1
		if ( (int) $post_ID > 0 ) { // Update reviews count for specific post categories only.
3874
			global $gd_session;
3875 1
			$term_array = (array) $option_data;
3876 1
			$post_type  = get_post_type( $post_ID );
3877 1
			$taxonomy   = $post_type . 'category';
3878 1
			$terms      = wp_get_object_terms( $post_ID, $taxonomy, array( 'fields' => 'ids' ) );
3879 1
3880 1 View Code Duplication
			if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
3881 1
				foreach ( $terms as $term_id ) {
3882 1
					$count                  = geodir_count_reviews_by_term_id( $term_id, $taxonomy, $post_type );
3883 1
					$children               = get_term_children( $term_id, $taxonomy );
0 ignored issues
show
Unused Code introduced by
$children 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...
3884 1
					$term_array[ $term_id ] = $count;
3885
				}
3886
			}
3887 1
3888 1
			$session_listing = $gd_session->get( 'listing' );
3889
3890 1
			$terms = array();
3891
			if ( isset( $_POST['post_category'][ $taxonomy ] ) ) {
3892
				$terms = (array) $_POST['post_category'][ $taxonomy ];
3893
			} else if ( ! empty( $session_listing ) && isset( $session_listing['post_category'][ $taxonomy ] ) ) {
3894
				$terms = (array) $session_listing['post_category'][ $taxonomy ];
3895
			}
3896
3897 View Code Duplication
			if ( ! empty( $terms ) ) {
3898
				foreach ( $terms as $term_id ) {
3899
					if ( $term_id > 0 ) {
3900
						$count                  = geodir_count_reviews_by_term_id( $term_id, $taxonomy, $post_type );
3901
						$children               = get_term_children( $term_id, $taxonomy );
0 ignored issues
show
Unused Code introduced by
$children 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...
3902
						$term_array[ $term_id ] = $count;
3903
					}
3904 1
				}
3905
			}
3906
		} else { // Update reviews count for all post categories.
3907
			$term_array = array();
3908
			$post_types = geodir_get_posttypes();
3909
			foreach ( $post_types as $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...
3910
3911
				$taxonomy = geodir_get_taxonomies( $post_type );
3912
				$taxonomy = $taxonomy[0];
3913
3914
				$args = array(
3915
					'hide_empty' => false
3916
				);
3917
3918
				$terms = get_terms( $taxonomy, $args );
3919
3920
				foreach ( $terms as $term ) {
3921
					$count    = geodir_count_reviews_by_term_id( $term->term_id, $taxonomy, $post_type );
3922 1
					$children = get_term_children( $term->term_id, $taxonomy );
0 ignored issues
show
Unused Code introduced by
$children 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...
3923
					/*if ( is_array( $children ) ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
3924 1
                        foreach ( $children as $child_id ) {
3925
                            $child_count = geodir_count_reviews_by_term_id($child_id, $taxonomy, $post_type);
3926
                            $count = $count + $child_count;
3927
                        }
3928
                    }*/
3929
					$term_array[ $term->term_id ] = $count;
3930
				}
3931
			}
3932
		}
3933
3934
		update_option( 'geodir_global_review_count', $term_array );
3935
		//clear cache
3936
		wp_cache_delete( 'geodir_global_review_count' );
3937
3938
		return $term_array;
3939
	} else {
3940
		return $option_data;
3941
	}
3942
}
3943
3944
/**
3945
 * Force update review count.
3946
 *
3947
 * @since   1.0.0
3948
 * @since   1.6.1 Fixed add listing page load time.
3949
 * @package GeoDirectory
3950
 * @return bool
3951
 */
3952
function geodir_term_review_count_force_update( $new_status, $old_status = '', $post = '' ) {
3953
	if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'geodir_import_export' ) {
3954
		return; // do not run if importing listings
3955
	}
3956
3957
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
3958
		return;
3959
	}
3960
3961
	$post_ID = 0;
3962
	if ( ! empty( $post ) ) {
3963
		if ( isset( $post->post_type ) && strpos( $post->post_type, 'gd_' ) !== 0 ) {
3964
			return;
3965
		}
3966
3967
		if ( $new_status == 'auto-draft' && $old_status == 'new' ) {
3968
			return;
3969
		}
3970
3971
		if ( ! empty( $post->ID ) ) {
3972
			$post_ID = $post->ID;
3973
		}
3974
	}
3975
3976
	if ( $new_status != $old_status ) {
3977
		geodir_count_reviews_by_terms( true, $post_ID );
3978
	}
3979
3980
	return true;
3981
}
3982
3983
function geodir_term_review_count_force_update_single_post( $post_id ) {
3984
	geodir_count_reviews_by_terms( true, $post_id );
3985
}
3986
3987
/*-----------------------------------------------------------------------------------*/
3988
/*  Term count functions
3989
/*-----------------------------------------------------------------------------------*/
3990
/**
3991
 * Count posts by term.
3992
 *
3993
 * @since   1.0.0
3994
 * @package GeoDirectory
3995
 *
3996
 * @param array $data  Count data array.
3997
 * @param object $term The term object.
3998
 *
3999
 * @return int Post count.
4000
 */
4001
function geodir_count_posts_by_term( $data, $term ) {
4002
4003
	if ( $data ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
4004
		if ( isset( $data[ $term->term_id ] ) ) {
4005
			return $data[ $term->term_id ];
4006
		} else {
4007
			return 0;
4008
		}
4009
	} else {
4010
		return $term->count;
4011
	}
4012 9
}
4013
4014 9
/**
4015
 * Sort terms object by post count.
4016 9
 *
4017 2
 * @since   1.0.0
4018 2
 * @package GeoDirectory
4019 2
 * param array $terms An array of term objects.
4020
 * @return array Sorted terms array.
4021
 */
4022
function geodir_sort_terms_by_count( $terms ) {
4023
	usort( $terms, "geodir_sort_by_count_obj" );
4024 2
4025
	return $terms;
4026 9
}
4027
4028
/**
4029
 * Sort terms object by review count.
4030
 *
4031
 * @since   1.0.0
4032
 * @package GeoDirectory
4033
 *
4034
 * @param array $terms An array of term objects.
4035
 *
4036
 * @return array Sorted terms array.
4037
 */
4038
function geodir_sort_terms_by_review_count( $terms ) {
4039
	usort( $terms, "geodir_sort_by_review_count_obj" );
4040
4041
	return $terms;
4042
}
4043
4044
/**
4045
 * Sort terms either by post count or review count.
4046
 *
4047
 * @since   1.0.0
4048
 * @package GeoDirectory
4049
 *
4050
 * @param array $terms An array of term objects.
4051
 * @param string $sort The sort type. Can be count (Post Count) or review_count. Default. count.
4052
 *
4053
 * @return array Sorted terms array.
4054
 */
4055
function geodir_sort_terms( $terms, $sort = 'count' ) {
4056
	if ( $sort == 'count' ) {
4057
		return geodir_sort_terms_by_count( $terms );
4058
	}
4059
	if ( $sort == 'review_count' ) {
4060
		return geodir_sort_terms_by_review_count( $terms );
4061
	}
4062
}
4063
4064
/*-----------------------------------------------------------------------------------*/
4065
/*  Utils
4066
/*-----------------------------------------------------------------------------------*/
4067
/**
4068
 * Compares post count from array for sorting.
4069
 *
4070
 * @since   1.0.0
4071
 * @package GeoDirectory
4072
 *
4073
 * @param array $a The left side array to compare.
4074
 * @param array $b The right side array to compare.
4075
 *
4076
 * @return bool
4077
 */
4078
function geodir_sort_by_count( $a, $b ) {
4079
	return $a['count'] < $b['count'];
4080
}
4081
4082
/**
4083
 * Compares post count from object for sorting.
4084
 *
4085
 * @since   1.0.0
4086
 * @package GeoDirectory
4087
 *
4088
 * @param object $a The left side object to compare.
4089
 * @param object $b The right side object to compare.
4090
 *
4091
 * @return bool
4092
 */
4093
function geodir_sort_by_count_obj( $a, $b ) {
4094
	return $a->count < $b->count;
4095
}
4096
4097
/**
4098
 * Compares review count from object for sorting.
4099
 *
4100
 * @since   1.0.0
4101
 * @package GeoDirectory
4102
 *
4103
 * @param object $a The left side object to compare.
4104
 * @param object $b The right side object to compare.
4105
 *
4106
 * @return bool
4107
 */
4108
function geodir_sort_by_review_count_obj( $a, $b ) {
4109
	return $a->review_count < $b->review_count;
4110
}
4111
4112
/**
4113
 * Load geodirectory plugin textdomain.
4114
 *
4115
 * @since   1.4.2
4116
 * @package GeoDirectory
4117
 */
4118
function geodir_load_textdomain() {
4119
	/**
4120
	 * Filter the plugin locale.
4121
	 *
4122
	 * @since   1.4.2
4123
	 * @package GeoDirectory
4124
	 */
4125
	$locale = apply_filters( 'plugin_locale', get_locale(), 'geodirectory' );
4126
4127
	load_textdomain( 'geodirectory', WP_LANG_DIR . '/' . 'geodirectory' . '/' . 'geodirectory' . '-' . $locale . '.mo' );
4128
	load_plugin_textdomain( 'geodirectory', false, plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/geodirectory-languages' );
4129
4130
	/**
4131
	 * Define language constants.
4132
	 *
4133
	 * @since 1.0.0
4134
	 */
4135
	require_once( geodir_plugin_path() . '/language.php' );
4136
4137
	$language_file = geodir_plugin_path() . '/db-language.php';
4138
4139
	// Load language string file if not created yet
4140
	if ( ! file_exists( $language_file ) ) {
4141
		geodirectory_load_db_language();
4142
	}
4143
4144
	if ( file_exists( $language_file ) ) {
4145
		/**
4146
		 * Language strings from database.
4147
		 *
4148
		 * @since 1.4.2
4149
		 */
4150
		try {
4151
			require_once( $language_file );
4152
		} catch ( Exception $e ) {
4153
			error_log( 'Language Error: ' . $e->getMessage() );
4154
		}
4155
	}
4156
}
4157
4158
/**
4159
 * Load language strings in to file to translate via po editor
4160
 *
4161
 * @since   1.4.2
4162
 * @package GeoDirectory
4163
 *
4164
 * @global null|object $wp_filesystem WP_Filesystem object.
4165
 *
4166
 * @return bool True if file created otherwise false
4167
 */
4168
function geodirectory_load_db_language() {
4169
	global $wp_filesystem;
4170
	if ( empty( $wp_filesystem ) ) {
4171
		require_once( ABSPATH . '/wp-admin/includes/file.php' );
4172
		WP_Filesystem();
4173
		global $wp_filesystem;
4174
	}
4175
4176
	$language_file = geodir_plugin_path() . '/db-language.php';
4177
4178
	if ( is_file( $language_file ) && ! is_writable( $language_file ) ) {
4179
		return false;
4180
	} // Not possible to create.
4181
4182
	if ( ! is_file( $language_file ) && ! is_writable( dirname( $language_file ) ) ) {
4183
		return false;
4184
	} // Not possible to create.
4185
4186
	$contents_strings = array();
4187
4188
	/**
4189
	 * Filter the language string from database to translate via po editor
4190
	 *
4191
	 * @since 1.4.2
4192
	 * @since 1.6.16 Register the string for WPML translation.
4193
	 *
4194
	 * @param array $contents_strings Array of strings.
4195
	 */
4196
	$contents_strings = apply_filters( 'geodir_load_db_language', $contents_strings );
4197
4198
	$contents_strings = array_unique( $contents_strings );
4199
4200
	$contents_head   = array();
4201
	$contents_head[] = "<?php";
4202
	$contents_head[] = "/**";
4203
	$contents_head[] = " * Translate language string stored in database. Ex: Custom Fields";
4204
	$contents_head[] = " *";
4205
	$contents_head[] = " * @package GeoDirectory";
4206
	$contents_head[] = " * @since 1.4.2";
4207 7
	$contents_head[] = " */";
4208
	$contents_head[] = "";
4209 7
	$contents_head[] = "// Language keys";
4210 3
4211
	$contents_foot   = array();
4212
	$contents_foot[] = "";
4213 5
	$contents_foot[] = "";
4214
4215
	$contents = implode( PHP_EOL, $contents_head );
4216
4217
	if ( ! empty( $contents_strings ) ) {
4218
		foreach ( $contents_strings as $string ) {
4219
			if ( is_scalar( $string ) && $string != '' ) {
4220
				$string = str_replace( "'", "\'", $string );
4221 2
				geodir_wpml_register_string( $string );
4222 2
				$contents .= PHP_EOL . "__('" . $string . "', 'geodirectory');";
4223
			}
4224 5
		}
4225 3
	}
4226 3
4227
	$contents .= implode( PHP_EOL, $contents_foot );
4228 5
4229 5
	if ( $wp_filesystem->put_contents( $language_file, $contents, FS_CHMOD_FILE ) ) {
4230 5
		return false;
4231
	} // Failure; could not write file.
4232 5
4233
	return true;
4234
}
4235
4236 5
/**
4237
 * Get the custom fields texts for translation
4238
 *
4239
 * @since   1.4.2
4240 5
 * @since   1.5.7 Option values are translatable via db translation.
4241 2
 * @since   1.6.11 Some new labels translation for advance custom fields.
4242 5
 * @package GeoDirectory
4243 1
 *
4244 1
 * @global object $wpdb             WordPress database abstraction object.
4245 4
 *
4246 1
 * @param  array $translation_texts Array of text strings.
4247 1
 *
4248 2
 * @return array Translation texts.
4249
 */
4250
function geodir_load_custom_field_translation( $translation_texts = array() ) {
4251 5
	global $wpdb;
4252 1
4253 1
	// Custom fields table
4254 1
	$sql  = "SELECT admin_title, admin_desc, site_title, clabels, required_msg, default_value, option_values, validation_msg FROM " . GEODIR_CUSTOM_FIELDS_TABLE;
4255 1
	$rows = $wpdb->get_results( $sql );
4256
4257 1
	if ( ! empty( $rows ) ) {
4258 1
		foreach ( $rows as $row ) {
4259
			if ( ! empty( $row->admin_title ) ) {
4260 5
				$translation_texts[] = stripslashes_deep( $row->admin_title );
4261 2
			}
4262 2
4263 2
			if ( ! empty( $row->admin_desc ) ) {
4264 2
				$translation_texts[] = stripslashes_deep( $row->admin_desc );
4265
			}
4266 2
4267 2
			if ( ! empty( $row->site_title ) ) {
4268
				$translation_texts[] = stripslashes_deep( $row->site_title );
4269 5
			}
4270
4271
			if ( ! empty( $row->clabels ) ) {
4272
				$translation_texts[] = stripslashes_deep( $row->clabels );
4273
			}
4274
4275
			if ( ! empty( $row->required_msg ) ) {
4276
				$translation_texts[] = stripslashes_deep( $row->required_msg );
4277
			}
4278
            
4279
			if ( ! empty( $row->validation_msg ) ) {
4280
				$translation_texts[] = stripslashes_deep( $row->validation_msg );
4281
			}
4282
4283
			if ( ! empty( $row->default_value ) ) {
4284
				$translation_texts[] = stripslashes_deep( $row->default_value );
4285
			}
4286 5
4287
			if ( ! empty( $row->option_values ) ) {
4288
				$option_values = geodir_string_values_to_options( stripslashes_deep( $row->option_values ) );
4289
4290
				if ( ! empty( $option_values ) ) {
4291
					foreach ( $option_values as $option_value ) {
4292
						if ( ! empty( $option_value['label'] ) ) {
4293
							$translation_texts[] = $option_value['label'];
4294
						}
4295
					}
4296
				}
4297
			}
4298
		}
4299
	}
4300
4301
	// Custom sorting fields table
4302
	$sql  = "SELECT site_title, asc_title, desc_title FROM " . GEODIR_CUSTOM_SORT_FIELDS_TABLE;
4303 5
	$rows = $wpdb->get_results( $sql );
4304
4305
	if ( ! empty( $rows ) ) {
4306
		foreach ( $rows as $row ) {
4307
			if ( ! empty( $row->site_title ) ) {
4308 5
				$translation_texts[] = stripslashes_deep( $row->site_title );
4309 5
			}
4310 5
4311
			if ( ! empty( $row->asc_title ) ) {
4312
				$translation_texts[] = stripslashes_deep( $row->asc_title );
4313 5
			}
4314 5
4315
			if ( ! empty( $row->desc_title ) ) {
4316
				$translation_texts[] = stripslashes_deep( $row->desc_title );
4317
			}
4318
		}
4319
	}
4320
4321
	// Advance search filter fields table
4322
	if ( defined( 'GEODIR_ADVANCE_SEARCH_TABLE' ) ) {
4323
		$sql  = "SELECT field_site_name, front_search_title, first_search_text, last_search_text, field_desc FROM " . GEODIR_ADVANCE_SEARCH_TABLE;
4324
		$rows = $wpdb->get_results( $sql );
4325 5
4326 5
		if ( ! empty( $rows ) ) {
4327 5
			foreach ( $rows as $row ) {
4328
				if ( ! empty( $row->field_site_name ) ) {
4329
					$translation_texts[] = stripslashes_deep( $row->field_site_name );
4330
				}
4331
4332 5
				if ( ! empty( $row->front_search_title ) ) {
4333 5
					$translation_texts[] = stripslashes_deep( $row->front_search_title );
4334 5
				}
4335 5
4336
				if ( ! empty( $row->first_search_text ) ) {
4337 5
					$translation_texts[] = stripslashes_deep( $row->first_search_text );
4338
				}
4339 5
4340
				if ( ! empty( $row->last_search_text ) ) {
4341
					$translation_texts[] = stripslashes_deep( $row->last_search_text );
4342
				}
4343
4344
				if ( ! empty( $row->field_desc ) ) {
4345 5
					$translation_texts[] = stripslashes_deep( $row->field_desc );
4346
				}
4347
			}
4348
		}
4349
	}
4350
4351
	$translation_texts = ! empty( $translation_texts ) ? array_unique( $translation_texts ) : $translation_texts;
4352
4353
	return $translation_texts;
4354
}
4355 5
4356
/**
4357
 * Retrieve list of mime types and file extensions allowed for file upload.
4358
 *
4359
 * @since   1.4.7
4360
 * @package GeoDirectory
4361
 *
4362
 * @return array Array of mime types.
4363
 */
4364
function geodir_allowed_mime_types() {
4365 5
	/**
4366
	 * Filter the list of mime types and file extensions allowed for file upload.
4367
	 *
4368
	 * @since   1.4.7
4369
	 * @package GeoDirectory
4370
	 *
4371
	 * @param array $geodir_allowed_mime_types and file extensions.
4372
	 */
4373
	return apply_filters( 'geodir_allowed_mime_types', array(
4374
			'Image'       => array( // Image formats.
4375
				'jpg'  => 'image/jpeg',
4376
				'jpe'  => 'image/jpeg',
4377 5
				'jpeg' => 'image/jpeg',
4378
				'gif'  => 'image/gif',
4379
				'png'  => 'image/png',
4380
				'bmp'  => 'image/bmp',
4381
				'ico'  => 'image/x-icon',
4382
			),
4383
			'Video'       => array( // Video formats.
4384
				'asf'  => 'video/x-ms-asf',
4385
				'avi'  => 'video/avi',
4386
				'flv'  => 'video/x-flv',
4387
				'mkv'  => 'video/x-matroska',
4388
				'mp4'  => 'video/mp4',
4389
				'mpeg' => 'video/mpeg',
4390
				'mpg'  => 'video/mpeg',
4391
				'wmv'  => 'video/x-ms-wmv',
4392
				'3gp'  => 'video/3gpp',
4393
			),
4394
			'Audio'       => array( // Audio formats.
4395
				'ogg' => 'audio/ogg',
4396
				'mp3' => 'audio/mpeg',
4397
				'wav' => 'audio/wav',
4398
				'wma' => 'audio/x-ms-wma',
4399
			),
4400
			'Text'        => array( // Text formats.
4401
				'css'  => 'text/css',
4402 5
				'csv'  => 'text/csv',
4403 1
				'htm'  => 'text/html',
4404 1
				'html' => 'text/html',
4405
				'txt'  => 'text/plain',
4406
				'rtx'  => 'text/richtext',
4407 1
				'vtt'  => 'text/vtt',
4408 1
			),
4409
			'Application' => array( // Application formats.
4410 5
				'doc'  => 'application/msword',
4411 1
				'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
4412 1
				'exe'  => 'application/x-msdownload',
4413
				'js'   => 'application/javascript',
4414
				'odt'  => 'application/vnd.oasis.opendocument.text',
4415 1
				'pdf'  => 'application/pdf',
4416 1
				'pot'  => 'application/vnd.ms-powerpoint',
4417
				'ppt'  => 'application/vnd.ms-powerpoint',
4418 5
				'pptx' => 'application/vnd.ms-powerpoint',
4419 1
				'psd'  => 'application/octet-stream',
4420
				'rar'  => 'application/rar',
4421
				'rtf'  => 'application/rtf',
4422 1
				'swf'  => 'application/x-shockwave-flash',
4423 1
				'tar'  => 'application/x-tar',
4424
				'xls'  => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
4425 5
				'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
4426
				'zip'  => 'application/zip',
4427
			)
4428
		)
4429
	);
4430 5
}
4431 1
4432 1
/**
4433
 * Retrieve list of user display name for user id.
4434
 *
4435 1
 * @since 1.5.0
4436 1
 *
4437
 * @param  string $user_id The WP user id.
4438 5
 *
4439 1
 * @return string User display name.
4440 1
 */
4441
function geodir_get_client_name( $user_id ) {
4442
	$client_name = '';
4443 1
4444 1
	$user_data = get_userdata( $user_id );
4445
4446 5
	if ( ! empty( $user_data ) ) {
4447 1
		if ( isset( $user_data->display_name ) && trim( $user_data->display_name ) != '' ) {
4448 1
			$client_name = trim( $user_data->display_name );
4449 1
		} else if ( isset( $user_data->user_nicename ) && trim( $user_data->user_nicename ) != '' ) {
4450
			$client_name = trim( $user_data->user_nicename );
4451 1
		} else {
4452 1
			$client_name = trim( $user_data->user_login );
4453 1
		}
4454 1
	}
4455 1
4456 1
	return $client_name;
4457
}
4458 5
4459
4460
add_filter( 'wpseo_replacements', 'geodir_wpseo_replacements', 10, 1 );
4461
/*
4462 5
 * Add location variables to wpseo replacements.
4463
 *
4464
 * @since 1.5.4
4465
 */
4466 5
function geodir_wpseo_replacements( $vars ) {
4467
4468
	global $wp;
4469
	$title = '';
4470
	// location variables
4471 5
	$gd_post_type   = geodir_get_current_posttype();
4472 5
	$location_array = geodir_get_current_location_terms( 'query_vars', $gd_post_type );
4473 5
	/**
4474
	 * Filter the title variables location variables array
4475
	 *
4476
	 * @since   1.5.5
4477
	 * @package GeoDirectory
4478
	 *
4479
	 * @param array $location_array The array of location variables.
4480
	 * @param array $vars           The page title variables.
4481
	 */
4482
	$location_array  = apply_filters( 'geodir_filter_title_variables_location_arr_seo', $location_array, $vars );
4483
	$location_titles = array();
0 ignored issues
show
Unused Code introduced by
$location_titles 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...
4484 View Code Duplication
	if ( get_query_var( 'gd_country_full' ) ) {
4485
		if ( get_query_var( 'gd_country_full' ) ) {
4486 5
			$location_array['gd_country'] = get_query_var( 'gd_country_full' );
4487
		}
4488
		if ( get_query_var( 'gd_region_full' ) ) {
4489
			$location_array['gd_region'] = get_query_var( 'gd_region_full' );
4490
		}
4491
		if ( get_query_var( 'gd_city_full' ) ) {
4492
			$location_array['gd_city'] = get_query_var( 'gd_city_full' );
4493
		}
4494
		if ( get_query_var( 'gd_neighbourhood_full' ) ) {
4495
			$location_array['gd_neighbourhood'] = get_query_var( 'gd_neighbourhood_full' );
4496
		}
4497
	}
4498
	
4499 1
	/**
4500
	 * Filter the location terms variables.
4501 1
	 *
4502 1
	 * @since   1.6.16
4503 1
	 * @package GeoDirectory
4504 1
	 *
4505 1
	 * @param string $title         The title with variables.
4506
	 * @param array $location_array The array of location variables.
4507 1
	 * @param string $gd_page       The page being filtered.
4508 1
	 * @param string $sep           The separator, default: `|`.
4509 1
	 */
4510 1
	$title = apply_filters( 'geodir_replace_location_variables_seo', $title, $location_array, '', '' );
0 ignored issues
show
Unused Code introduced by
$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...
4511 1
4512 1
	/**
4513 1
	 * Filter the title variables after standard ones have been filtered for wpseo.
4514 1
	 *
4515 1
	 * @since   1.5.7
4516 1
	 * @package GeoDirectory
4517 1
	 *
4518 1
	 * @param string $vars          The title with variables.
4519 1
	 * @param array $location_array The array of location variables.
4520 1
	 */
4521 1
	return apply_filters( 'geodir_wpseo_replacements_vars', $vars, $location_array );
4522 1
}
4523 1
4524 1
4525 1
add_filter( 'geodir_seo_meta_title', 'geodir_filter_title_variables', 10, 3 );
4526 1
add_filter( 'geodir_seo_page_title', 'geodir_filter_title_variables', 10, 2 );
4527 1
add_filter( 'geodir_seo_meta_description_pre', 'geodir_filter_title_variables', 10, 3 );
4528 1
4529 1
/**
4530 1
 * Filter the title variables.
4531 1
 *
4532 1
 * %%date%%                        Replaced with the date of the post/page
4533 1
 * %%title%%                    Replaced with the title of the post/page
4534 1
 * %%sitename%%                    The site's name
4535 1
 * %%sitedesc%%                    The site's tagline / description
4536 1
 * %%excerpt%%                    Replaced with the post/page excerpt (or auto-generated if it does not exist)
4537 1
 * %%tag%%                        Replaced with the current tag/tags
4538 1
 * %%category%%                    Replaced with the post categories (comma separated)
4539 1
 * %%category_description%%        Replaced with the category description
4540 1
 * %%tag_description%%            Replaced with the tag description
4541
 * %%term_description%%            Replaced with the term description
4542 1
 * %%term_title%%                Replaced with the term name
4543 1
 * %%searchphrase%%                Replaced with the current search phrase
4544 1
 * %%sep%%                        The separator defined in your theme's wp_title() tag.
4545
 *
4546 1
 * ADVANCED
4547
 * %%pt_single%%                Replaced with the post type single label
4548
 * %%pt_plural%%                Replaced with the post type plural label
4549
 * %%modified%%                    Replaced with the post/page modified time
4550
 * %%id%%                        Replaced with the post/page ID
4551
 * %%name%%                        Replaced with the post/page author's 'nicename'
4552
 * %%userid%%                    Replaced with the post/page author's userid
4553 1
 * %%page%%                        Replaced with the current page number (i.e. page 2 of 4)
4554 1
 * %%pagetotal%%                Replaced with the current page total
4555 1
 * %%pagenumber%%                Replaced with the current page number
4556
 *
4557 1
 * @since   1.5.7
4558
 * @package GeoDirectory
4559
 *
4560
 * @global object $wp     WordPress object.
4561
 * @global object $post   The current post object.
4562
 *
4563
 * @param string $title   The title with variables.
4564
 * @param string $gd_page The page being filtered.
4565
 * @param string $sep     The separator, default: `|`.
4566
 *
4567
 * @return string Title after filtered variables.
4568
 */
4569
function geodir_filter_title_variables( $title, $gd_page, $sep = '' ) {
4570
	global $wp, $post;
4571
4572
	if ( ! $gd_page || ! $title ) {
4573
		return $title; // if no a GD page then bail.
4574
	}
4575
4576
	if ( $sep == '' ) {
4577
		/**
4578
		 * Filter the page title separator.
4579
		 *
4580
		 * @since   1.0.0
4581
		 * @package GeoDirectory
4582
		 *
4583
		 * @param string $sep The separator, default: `|`.
4584
		 */
4585
		$sep = apply_filters( 'geodir_page_title_separator', '|' );
4586
	}
4587
4588
	if ( strpos( $title, '%%title%%' ) !== false ) {
4589
		$title = str_replace( "%%title%%", $post->post_title, $title );
4590
	}
4591
4592 View Code Duplication
	if ( strpos( $title, '%%sitename%%' ) !== false ) {
4593
		$title = str_replace( "%%sitename%%", get_bloginfo( 'name' ), $title );
4594
	}
4595
4596 View Code Duplication
	if ( strpos( $title, '%%sitedesc%%' ) !== false ) {
4597
		$title = str_replace( "%%sitedesc%%", get_bloginfo( 'description' ), $title );
4598
	}
4599
4600
	if ( strpos( $title, '%%excerpt%%' ) !== false ) {
4601
		$title = str_replace( "%%excerpt%%", strip_tags( get_the_excerpt() ), $title );
4602
	}
4603
4604 8
	if ( $gd_page == 'search' || $gd_page == 'author' ) {
4605 7
		$post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : '';
4606
	} else if ( $gd_page == 'add-listing' ) {
4607
		$post_type = ( isset( $_REQUEST['listing_type'] ) ) ? sanitize_text_field( $_REQUEST['listing_type'] ) : '';
4608 1
		$post_type = ! $post_type && ! empty( $_REQUEST['pid'] ) ? get_post_type( (int) $_REQUEST['pid'] ) : $post_type;
4609 1
	} else if ( isset( $post->post_type ) && $post->post_type && in_array( $post->post_type, geodir_get_posttypes() ) ) {
4610 1
		$post_type = $post->post_type;
4611
	} else {
4612 1
		$post_type = get_query_var( 'post_type' );
4613
	}
4614
4615 View Code Duplication
	if ( strpos( $title, '%%pt_single%%' ) !== false ) {
4616 1
		$singular_name = '';
4617
		if ( $post_type && $singular_name = get_post_type_singular_label( $post_type ) ) {
4618
			$singular_name = __( $singular_name, 'geodirectory' );
4619
		}
4620 1
4621
		$title = str_replace( "%%pt_single%%", $singular_name, $title );
4622 1
	}
4623
4624 View Code Duplication
	if ( strpos( $title, '%%pt_plural%%' ) !== false ) {
4625
		$plural_name = '';
4626
		if ( $post_type && $plural_name = get_post_type_plural_label( $post_type ) ) {
4627
			$plural_name = __( $plural_name, 'geodirectory' );
4628
		}
4629
4630
		$title = str_replace( "%%pt_plural%%", $plural_name, $title );
4631
	}
4632
4633 View Code Duplication
	if ( strpos( $title, '%%category%%' ) !== false ) {
4634
		$cat_name = '';
4635
4636
		if ( $gd_page == 'detail' ) {
4637
			if ( $post->default_category ) {
4638
				$cat      = get_term( $post->default_category, $post->post_type . 'category' );
4639
				$cat_name = ( isset( $cat->name ) ) ? $cat->name : '';
4640
			}
4641
		} else if ( $gd_page == 'listing' ) {
4642
			$queried_object = get_queried_object();
4643
			if ( isset( $queried_object->name ) ) {
4644
				$cat_name = $queried_object->name;
4645 1
			}
4646
		}
4647
		$title = str_replace( "%%category%%", $cat_name, $title );
4648
	}
4649
4650 View Code Duplication
	if ( strpos( $title, '%%tag%%' ) !== false ) {
4651
		$cat_name = '';
4652
4653
		if ( $gd_page == 'detail' ) {
4654
			if ( $post->default_category ) {
4655
				$cat      = get_term( $post->default_category, $post->post_type . 'category' );
4656
				$cat_name = ( isset( $cat->name ) ) ? $cat->name : '';
4657
			}
4658
		} else if ( $gd_page == 'listing' ) {
4659
			$queried_object = get_queried_object();
4660
			if ( isset( $queried_object->name ) ) {
4661
				$cat_name = $queried_object->name;
4662
			}
4663
		}
4664
		$title = str_replace( "%%tag%%", $cat_name, $title );
4665
	}
4666
4667
	if ( strpos( $title, '%%id%%' ) !== false ) {
4668
		$ID    = ( isset( $post->ID ) ) ? $post->ID : '';
4669
		$title = str_replace( "%%id%%", $ID, $title );
4670
	}
4671
4672
	if ( strpos( $title, '%%sep%%' ) !== false ) {
4673
		$title = str_replace( "%%sep%%", $sep, $title );
4674
	}
4675
4676
	// location variables
4677
	$gd_post_type   = geodir_get_current_posttype();
4678
	$location_array = geodir_get_current_location_terms( 'query_vars', $gd_post_type );
4679
	
4680
	/**
4681
	 * Filter the title variables location variables array
4682
	 *
4683
	 * @since   1.5.5
4684
	 * @package GeoDirectory
4685
	 *
4686
	 * @param array $location_array The array of location variables.
4687
	 * @param string $title         The title with variables..
4688
	 * @param string $gd_page       The page being filtered.
4689
	 * @param string $sep           The separator, default: `|`.
4690
	 */
4691
	$location_array  = apply_filters( 'geodir_filter_title_variables_location_arr', $location_array, $title, $gd_page, $sep );
4692
	
4693 View Code Duplication
	if ( $gd_page == 'location' && get_query_var( 'gd_country_full' ) ) {
4694
		if ( get_query_var( 'gd_country_full' ) ) {
4695
			$location_array['gd_country'] = get_query_var( 'gd_country_full' );
4696
		}
4697
		if ( get_query_var( 'gd_region_full' ) ) {
4698
			$location_array['gd_region'] = get_query_var( 'gd_region_full' );
4699
		}
4700
		if ( get_query_var( 'gd_city_full' ) ) {
4701
			$location_array['gd_city'] = get_query_var( 'gd_city_full' );
4702
		}
4703
		if ( get_query_var( 'gd_neighbourhood_full' ) ) {
4704
			$location_array['gd_neighbourhood'] = get_query_var( 'gd_neighbourhood_full' );
4705
		}
4706
	}
4707
	
4708
	/**
4709
	 * Filter the location terms variables.
4710
	 *
4711
	 * @since   1.6.16
4712
	 * @package GeoDirectory
4713
	 *
4714
	 * @param string $title         The title with variables.
4715
	 * @param array $location_array The array of location variables.
4716
	 * @param string $gd_page       The page being filtered.
4717
	 * @param string $sep           The separator, default: `|`.
4718
	 */
4719
	$title = apply_filters( 'geodir_replace_location_variables', $title, $location_array, $gd_page, $sep );
4720
	
4721 View Code Duplication
	if ( strpos( $title, '%%search_term%%' ) !== false ) {
4722
		$search_term = '';
4723
		if ( isset( $_REQUEST['s'] ) ) {
4724
			$search_term = esc_attr( $_REQUEST['s'] );
4725
		}
4726
		$title = str_replace( "%%search_term%%", $search_term, $title );
4727
	}
4728
4729 View Code Duplication
	if ( strpos( $title, '%%search_near%%' ) !== false ) {
4730
		$search_term = '';
4731
		if ( isset( $_REQUEST['snear'] ) ) {
4732
			$search_term = esc_attr( $_REQUEST['snear'] );
4733
		}
4734
		$title = str_replace( "%%search_near%%", $search_term, $title );
4735
	}
4736
4737
	if ( strpos( $title, '%%name%%' ) !== false ) {
4738
		if ( is_author() ) {
4739
			$curauth     = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
4740
			$author_name = $curauth->display_name;
4741
		} else {
4742
			$author_name = get_the_author();
4743
		}
4744
		if ( ! $author_name || $author_name === '' ) {
4745
			$queried_object = get_queried_object();
4746
4747
			if ( isset( $queried_object->data->user_nicename ) ) {
4748
				$author_name = $queried_object->data->display_name;
4749
			}
4750
		}
4751
		$title = str_replace( "%%name%%", $author_name, $title );
4752
	}
4753
4754
	if ( strpos( $title, '%%page%%' ) !== false ) {
4755
		$page  = geodir_title_meta_page( $sep );
4756
		$title = str_replace( "%%page%%", $page, $title );
4757
	}
4758
	if ( strpos( $title, '%%pagenumber%%' ) !== false ) {
4759
		$pagenumber = geodir_title_meta_pagenumber();
4760
		$title      = str_replace( "%%pagenumber%%", $pagenumber, $title );
4761
	}
4762
	if ( strpos( $title, '%%pagetotal%%' ) !== false ) {
4763
		$pagetotal = geodir_title_meta_pagetotal();
4764
		$title     = str_replace( "%%pagetotal%%", $pagetotal, $title );
4765
	}
4766
4767
	$title = wptexturize( $title );
4768
	$title = convert_chars( $title );
4769
	$title = esc_html( $title );
4770
4771 3
	/**
4772 3
	 * Filter the title variables after standard ones have been filtered.
4773
	 *
4774
	 * @since   1.5.7
4775 3
	 * @package GeoDirectory
4776 3
	 *
4777 3
	 * @param string $title         The title with variables.
4778 3
	 * @param array $location_array The array of location variables.
4779 3
	 * @param string $gd_page       The page being filtered.
4780 3
	 * @param string $sep           The separator, default: `|`.
4781 3
	 */
4782
4783
	return apply_filters( 'geodir_filter_title_variables_vars', $title, $location_array, $gd_page, $sep );
4784
}
4785
4786
/**
4787
 * Get the cpt texts for translation.
4788
 *
4789
 * @since   1.5.5
4790
 * @package GeoDirectory
4791
 *
4792
 * @param  array $translation_texts Array of text strings.
4793
 *
4794 2
 * @return array Translation texts.
4795 1
 */
4796 1
function geodir_load_cpt_text_translation( $translation_texts = array() ) {
4797 2
	$gd_post_types = geodir_get_posttypes( 'array' );
4798
4799
	if ( ! empty( $gd_post_types ) ) {
4800
		foreach ( $gd_post_types as $post_type => $cpt_info ) {
0 ignored issues
show
Bug introduced by
The expression $gd_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...
4801
			$labels      = isset( $cpt_info['labels'] ) ? $cpt_info['labels'] : '';
4802
			$description = isset( $cpt_info['description'] ) ? $cpt_info['description'] : '';
4803
			$seo         = isset( $cpt_info['seo'] ) ? $cpt_info['seo'] : '';
4804
4805
			if ( ! empty( $labels ) ) {
4806 View Code Duplication
				if ( $labels['name'] != '' && ! in_array( $labels['name'], $translation_texts ) ) {
4807
					$translation_texts[] = $labels['name'];
4808
				}
4809 View Code Duplication
				if ( $labels['singular_name'] != '' && ! in_array( $labels['singular_name'], $translation_texts ) ) {
4810
					$translation_texts[] = $labels['singular_name'];
4811
				}
4812 View Code Duplication
				if ( $labels['add_new'] != '' && ! in_array( $labels['add_new'], $translation_texts ) ) {
4813
					$translation_texts[] = $labels['add_new'];
4814
				}
4815 View Code Duplication
				if ( $labels['add_new_item'] != '' && ! in_array( $labels['add_new_item'], $translation_texts ) ) {
4816
					$translation_texts[] = $labels['add_new_item'];
4817
				}
4818 View Code Duplication
				if ( $labels['edit_item'] != '' && ! in_array( $labels['edit_item'], $translation_texts ) ) {
4819
					$translation_texts[] = $labels['edit_item'];
4820
				}
4821 View Code Duplication
				if ( $labels['new_item'] != '' && ! in_array( $labels['new_item'], $translation_texts ) ) {
4822
					$translation_texts[] = $labels['new_item'];
4823
				}
4824 View Code Duplication
				if ( $labels['view_item'] != '' && ! in_array( $labels['view_item'], $translation_texts ) ) {
4825
					$translation_texts[] = $labels['view_item'];
4826
				}
4827 View Code Duplication
				if ( $labels['search_items'] != '' && ! in_array( $labels['search_items'], $translation_texts ) ) {
4828
					$translation_texts[] = $labels['search_items'];
4829
				}
4830 View Code Duplication
				if ( $labels['not_found'] != '' && ! in_array( $labels['not_found'], $translation_texts ) ) {
4831
					$translation_texts[] = $labels['not_found'];
4832
				}
4833 View Code Duplication
				if ( $labels['not_found_in_trash'] != '' && ! in_array( $labels['not_found_in_trash'], $translation_texts ) ) {
4834
					$translation_texts[] = $labels['not_found_in_trash'];
4835
				}
4836 View Code Duplication
				if ( isset( $labels['label_post_profile'] ) && $labels['label_post_profile'] != '' && ! in_array( $labels['label_post_profile'], $translation_texts ) ) {
4837
					$translation_texts[] = $labels['label_post_profile'];
4838
				}
4839 View Code Duplication
				if ( isset( $labels['label_post_info'] ) && $labels['label_post_info'] != '' && ! in_array( $labels['label_post_info'], $translation_texts ) ) {
4840
					$translation_texts[] = $labels['label_post_info'];
4841
				}
4842 View Code Duplication
				if ( isset( $labels['label_post_images'] ) && $labels['label_post_images'] != '' && ! in_array( $labels['label_post_images'], $translation_texts ) ) {
4843
					$translation_texts[] = $labels['label_post_images'];
4844
				}
4845 View Code Duplication
				if ( isset( $labels['label_post_map'] ) && $labels['label_post_map'] != '' && ! in_array( $labels['label_post_map'], $translation_texts ) ) {
4846
					$translation_texts[] = $labels['label_post_map'];
4847
				}
4848 View Code Duplication
				if ( isset( $labels['label_reviews'] ) && $labels['label_reviews'] != '' && ! in_array( $labels['label_reviews'], $translation_texts ) ) {
4849
					$translation_texts[] = $labels['label_reviews'];
4850
				}
4851 View Code Duplication
				if ( isset( $labels['label_related_listing'] ) && $labels['label_related_listing'] != '' && ! in_array( $labels['label_related_listing'], $translation_texts ) ) {
4852
					$translation_texts[] = $labels['label_related_listing'];
4853
				}
4854
			}
4855
4856
			if ( $description != '' && ! in_array( $description, $translation_texts ) ) {
4857
				$translation_texts[] = normalize_whitespace( $description );
4858
			}
4859
4860
			if ( ! empty( $seo ) ) {
4861 View Code Duplication
				if ( isset( $seo['meta_keyword'] ) && $seo['meta_keyword'] != '' && ! in_array( $seo['meta_keyword'], $translation_texts ) ) {
4862
					$translation_texts[] = normalize_whitespace( $seo['meta_keyword'] );
4863
				}
4864
4865 View Code Duplication
				if ( isset( $seo['meta_description'] ) && $seo['meta_description'] != '' && ! in_array( $seo['meta_description'], $translation_texts ) ) {
4866
					$translation_texts[] = normalize_whitespace( $seo['meta_description'] );
4867
				}
4868
			}
4869
		}
4870
	}
4871
	$translation_texts = ! empty( $translation_texts ) ? array_unique( $translation_texts ) : $translation_texts;
4872
4873
	return $translation_texts;
4874
}
4875
4876
/**
4877
 * Remove the location terms to hide term from location url.
4878
 *
4879
 * @since   1.5.5
4880
 * @package GeoDirectory
4881
 *
4882
 * @param  array $location_terms Array of location terms.
4883
 *
4884
 * @return array Location terms.
4885
 */
4886
function geodir_remove_location_terms( $location_terms = array() ) {
4887
	$location_manager = defined( 'POST_LOCATION_TABLE' ) ? true : false;
4888
4889
	if ( ! empty( $location_terms ) && $location_manager ) {
4890
		$hide_country_part = get_option( 'geodir_location_hide_country_part' );
4891
		$hide_region_part  = get_option( 'geodir_location_hide_region_part' );
4892
4893
		if ( $hide_region_part && $hide_country_part ) {
4894
			if ( isset( $location_terms['gd_country'] ) ) {
4895
				unset( $location_terms['gd_country'] );
4896
			}
4897
			if ( isset( $location_terms['gd_region'] ) ) {
4898
				unset( $location_terms['gd_region'] );
4899
			}
4900
		} else if ( $hide_region_part && ! $hide_country_part ) {
4901
			if ( isset( $location_terms['gd_region'] ) ) {
4902
				unset( $location_terms['gd_region'] );
4903
			}
4904
		} else if ( ! $hide_region_part && $hide_country_part ) {
4905
			if ( isset( $location_terms['gd_country'] ) ) {
4906
				unset( $location_terms['gd_country'] );
4907
			}
4908
		}
4909
	}
4910
4911
	return $location_terms;
4912
}
4913
4914
/**
4915
 * Send notification when a listing has been edited by it's author.
4916
 *
4917
 * @since   1.5.9
4918
 * @package GeoDirectory
4919
 *
4920
 * @param int $post_ID  Post ID.
4921
 * @param WP_Post $post Post object.
4922
 * @param bool $update  Whether this is an existing listing being updated or not.
4923
 */
4924
function geodir_on_wp_insert_post( $post_ID, $post, $update ) {
4925
	if ( ! $update ) {
4926
		return;
4927
	}
4928
4929
	$action      = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
4930
	$is_admin    = is_admin() && ( ! defined( 'DOING_AJAX' ) || ( defined( 'DOING_AJAX' ) && ! DOING_AJAX ) ) ? true : false;
4931
	$inline_save = $action == 'inline-save' ? true : false;
4932
4933
	if ( empty( $post->post_type ) || $is_admin || $inline_save || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) {
4934
		return;
4935
	}
4936
4937
	if ( $action != '' && in_array( $action, array( 'geodir_import_export' ) ) ) {
4938
		return;
4939
	}
4940
4941
	$user_id = (int) get_current_user_id();
4942
4943
	if ( $user_id > 0 && get_option( 'geodir_notify_post_edited' ) && ! wp_is_post_revision( $post_ID ) && in_array( $post->post_type, geodir_get_posttypes() ) ) {
4944
		$author_id = ! empty( $post->post_author ) ? $post->post_author : 0;
4945
4946
		if ( $user_id == $author_id && ! is_super_admin() ) {
4947
			$from_email   = get_option( 'site_email' );
4948
			$from_name    = get_site_emailName();
4949
			$to_email     = get_option( 'admin_email' );
4950
			$to_name      = get_option( 'name' );
4951
			$message_type = 'listing_edited';
4952
4953
			$notify_edited = true;
4954
			/**
4955
			 * Send notification when listing edited by author?
4956
			 *
4957
			 * @since 1.6.0
4958
			 *
4959
			 * @param bool $notify_edited Notify on listing edited by author?
4960
			 * @param object $post        The current post object.
4961
			 */
4962
			$notify_edited = apply_filters( 'geodir_notify_on_listing_edited', $notify_edited, $post );
0 ignored issues
show
Unused Code introduced by
$notify_edited 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...
4963
4964
			geodir_sendEmail( $from_email, $from_name, $to_email, $to_name, '', '', '', $message_type, $post_ID );
4965
		}
4966
	}
4967
}
4968
4969
/**
4970
 * Retrieve the current page start & end numbering with context (i.e. 'page 2 of 4') for use as replacement string.
4971
 *
4972
 * @since   1.6.0
4973
 * @package GeoDirectory
4974
 *
4975
 * @param string $sep The separator tag.
4976
 *
4977
 * @return string|null The current page start & end numbering.
4978
 */
4979
function geodir_title_meta_page( $sep ) {
4980
	$replacement = null;
4981
4982
	$max = geodir_title_meta_pagenumbering( 'max' );
4983
	$nr  = geodir_title_meta_pagenumbering( 'nr' );
4984
4985
	if ( $max > 1 && $nr > 1 ) {
4986
		$replacement = sprintf( $sep . ' ' . __( 'Page %1$d of %2$d', 'geodirectory' ), $nr, $max );
4987
	}
4988
4989
	return $replacement;
4990
}
4991
4992
/**
4993
 * Retrieve the current page number for use as replacement string.
4994
 *
4995
 * @since   1.6.0
4996
 * @package GeoDirectory
4997
 *
4998
 * @return string|null The current page number.
4999
 */
5000 View Code Duplication
function geodir_title_meta_pagenumber() {
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...
5001
	$replacement = null;
5002
5003
	$nr = geodir_title_meta_pagenumbering( 'nr' );
5004
	if ( isset( $nr ) && $nr > 0 ) {
5005
		$replacement = (string) $nr;
5006
	}
5007
5008
	return $replacement;
5009
}
5010
5011
/**
5012
 * Retrieve the current page total for use as replacement string.
5013
 *
5014
 * @since   1.6.0
5015
 * @package GeoDirectory
5016
 *
5017
 * @return string|null The current page total.
5018
 */
5019 View Code Duplication
function geodir_title_meta_pagetotal() {
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...
5020
	$replacement = null;
5021
5022
	$max = geodir_title_meta_pagenumbering( 'max' );
5023
	if ( isset( $max ) && $max > 0 ) {
5024
		$replacement = (string) $max;
5025
	}
5026
5027
	return $replacement;
5028
}
5029
5030
/**
5031
 * Determine the page numbering of the current post/page/cpt.
5032
 *
5033
 * @param string $request   'nr'|'max' - whether to return the page number or the max number of pages.
5034
 *
5035
 * @since   1.6.0
5036
 * @package GeoDirectory
5037
 *
5038
 * @global object $wp_query WordPress Query object.
5039
 * @global object $post     The current post object.
5040
 *
5041
 * @return int|null The current page numbering.
5042
 */
5043
function geodir_title_meta_pagenumbering( $request = 'nr' ) {
5044
	global $wp_query, $post;
5045
	$max_num_pages = null;
0 ignored issues
show
Unused Code introduced by
$max_num_pages 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...
5046
	$page_number   = null;
0 ignored issues
show
Unused Code introduced by
$page_number 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...
5047
5048
	$max_num_pages = 1;
5049
5050
	if ( ! is_singular() ) {
5051
		$page_number = get_query_var( 'paged' );
5052
		if ( $page_number === 0 || $page_number === '' ) {
5053
			$page_number = 1;
5054
		}
5055
5056
		if ( isset( $wp_query->max_num_pages ) && ( $wp_query->max_num_pages != '' && $wp_query->max_num_pages != 0 ) ) {
5057
			$max_num_pages = $wp_query->max_num_pages;
5058
		}
5059
	} else {
5060
		$page_number = get_query_var( 'page' );
5061
		if ( $page_number === 0 || $page_number === '' ) {
5062
			$page_number = 1;
5063
		}
5064
5065
		if ( isset( $post->post_content ) ) {
5066
			$max_num_pages = ( substr_count( $post->post_content, '<!--nextpage-->' ) + 1 );
5067
		}
5068
	}
5069
5070
	$return = null;
5071
5072
	switch ( $request ) {
5073
		case 'nr':
5074
			$return = $page_number;
5075
			break;
5076
		case 'max':
5077
			$return = $max_num_pages;
5078
			break;
5079
	}
5080
5081
	return $return;
5082
}
5083
5084
/**
5085
 * Filter the terms with count empty.
5086
 *
5087
 * @since 1.5.4
5088
 *
5089
 * @param array $terms Terms array.
5090
 *
5091
 * @return array Terms.
5092
 */
5093 View Code Duplication
function geodir_filter_empty_terms( $terms ) {
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...
5094
	if ( empty( $terms ) ) {
5095
		return $terms;
5096
	}
5097
5098
	$return = array();
5099
	foreach ( $terms as $term ) {
5100
		if ( isset( $term->count ) && $term->count > 0 ) {
5101
			$return[] = $term;
5102
		} else {
5103
			/**
5104
			 * Allow to filter terms with no count.
5105
			 *
5106
			 * @since 1.6.6
5107
			 *
5108
			 * @param array $return The array of terms to return.
5109
			 * @param object $term  The term object.
5110
			 */
5111
			$return = apply_filters( 'geodir_filter_empty_terms_filter', $return, $term );
5112
		}
5113
	}
5114
5115
	return $return;
5116
}
5117
5118
5119
/**
5120
 * Remove the hentry class structured data from details pages.
5121
 *
5122
 * @since 1.6.5
5123
 *
5124
 * @param $class
5125
 *
5126
 * @return array
5127
 */
5128
function geodir_remove_hentry( $class ) {
5129
	if ( geodir_is_page( 'detail' ) ) {
5130
		$class = array_diff( $class, array( 'hentry' ) );
5131
	}
5132
5133
	return $class;
5134
}
5135
5136
add_filter( 'post_class', 'geodir_remove_hentry' );
5137
5138
/**
5139
 * Registers a individual text string for WPML translation.
5140
 *
5141
 * @since 1.6.16 Details page add locations to the term links.
5142
 * @package GeoDirectory
5143
 *
5144
 * @param string $string The string that needs to be translated.
5145
 * @param string $domain The plugin domain. Default geodirectory.
5146
 * @param string $name The name of the string which helps to know what's being translated.
5147
 */
5148
function geodir_wpml_register_string( $string, $domain = 'geodirectory', $name = '' ) {
5149
    do_action( 'wpml_register_single_string', $domain, $name, $string );
5150
}
5151
5152
/**
5153
 * Retrieves an individual WPML text string translation.
5154
 *
5155
 * @since 1.6.16 Details page add locations to the term links.
5156
 * @package GeoDirectory
5157
 *
5158
 * @param string $string The string that needs to be translated.
5159
 * @param string $domain The plugin domain. Default geodirectory.
5160
 * @param string $name The name of the string which helps to know what's being translated.
5161
 * @param string $language_code Return the translation in this language. Default is NULL which returns the current language.
5162
 * @return string The translated string.
5163
 */
5164
function geodir_wpml_translate_string( $string, $domain = 'geodirectory', $name = '', $language_code = NULL ) {
5165
    return apply_filters( 'wpml_translate_single_string', $string, $domain, $name, $language_code );
5166
}