Test Failed
Push — master ( 1a7ae9...1e0ea1 )
by Stiofan
01:39
created

general_functions.php ➔ geodir_curPageURL()   C

Complexity

Conditions 8
Paths 6

Size

Total Lines 41
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
eloc 12
nc 6
nop 0
dl 0
loc 41
ccs 0
cts 7
cp 0
crap 72
rs 5.3846
c 0
b 0
f 0
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 (L1510-1513) 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 (L1525-1528) 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 ( get_option( 'geodir_set_as_home' ) ) {
453
				$wp->query_vars['gd_is_geodir_page'] = true;
454
			}
455
			if ( geodir_is_page( 'home' ) ) {
456
				$wp->query_vars['gd_is_geodir_page'] = true;
457
			}
458
459
460
		}
461
462
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $wp->query_vars['page_id'] ) ) {
463
			if (
464
				$wp->query_vars['page_id'] == geodir_add_listing_page_id()
465
				|| $wp->query_vars['page_id'] == geodir_preview_page_id()
466
				|| $wp->query_vars['page_id'] == geodir_success_page_id()
467
				|| $wp->query_vars['page_id'] == geodir_location_page_id()
468 30
				|| $wp->query_vars['page_id'] == geodir_home_page_id()
469 30
				|| $wp->query_vars['page_id'] == geodir_info_page_id()
470 30
				|| $wp->query_vars['page_id'] == geodir_login_page_id()
471
				|| ( function_exists( 'geodir_payment_checkout_page_id' ) && $wp->query_vars['page_id'] == geodir_payment_checkout_page_id() )
472 30
				|| ( function_exists( 'geodir_payment_invoices_page_id' ) && $wp->query_vars['page_id'] == geodir_payment_invoices_page_id() )
473
			) {
474
				$wp->query_vars['gd_is_geodir_page'] = true;
475
			}
476
		}
477
478
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $wp->query_vars['pagename'] ) ) {
479
			$page = get_page_by_path( $wp->query_vars['pagename'] );
480
481
			if ( ! empty( $page ) && (
482
					$page->ID == geodir_add_listing_page_id()
483
					|| $page->ID == geodir_preview_page_id()
484
					|| $page->ID == geodir_success_page_id()
485
					|| $page->ID == geodir_location_page_id()
486
					|| ( isset( $wp->query_vars['page_id'] ) && $wp->query_vars['page_id'] == geodir_home_page_id() )
487 9
					|| ( isset( $wp->query_vars['page_id'] ) && $wp->query_vars['page_id'] == geodir_info_page_id() )
488 9
					|| ( isset( $wp->query_vars['page_id'] ) && $wp->query_vars['page_id'] == geodir_login_page_id() )
489 9
					|| ( isset( $wp->query_vars['page_id'] ) && function_exists( 'geodir_payment_checkout_page_id' ) && $wp->query_vars['page_id'] == geodir_payment_checkout_page_id() )
490 9
					|| ( isset( $wp->query_vars['page_id'] ) && function_exists( 'geodir_payment_invoices_page_id' ) && $wp->query_vars['page_id'] == geodir_payment_invoices_page_id() )
491 9
				)
492
			) {
493
				$wp->query_vars['gd_is_geodir_page'] = true;
494
			}
495
		}
496
497
498
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $wp->query_vars['post_type'] ) && $wp->query_vars['post_type'] != '' ) {
499 9
			$requested_post_type = $wp->query_vars['post_type'];
500
			// check if this post type is geodirectory post types
501 9
			$post_type_array = geodir_get_posttypes();
502
			if ( in_array( $requested_post_type, $post_type_array ) ) {
503
				$wp->query_vars['gd_is_geodir_page'] = true;
504
			}
505
		}
506
507
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) ) {
508 9
			$geodir_taxonomis = geodir_get_taxonomies( '', true );
509
			if ( ! empty( $geodir_taxonomis ) ) {
510
				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...
511
					if ( array_key_exists( $taxonomy, $wp->query_vars ) ) {
512
						$wp->query_vars['gd_is_geodir_page'] = true;
513
						break;
514
					}
515
				}
516
			}
517
518
		}
519
520
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $wp->query_vars['author_name'] ) && isset( $_REQUEST['geodir_dashbord'] ) ) {
521
			$wp->query_vars['gd_is_geodir_page'] = true;
522
		}
523
524
525
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] ) && isset( $_REQUEST['geodir_search'] ) ) {
526
			$wp->query_vars['gd_is_geodir_page'] = true;
527
		}
528
529
530
//check if homepage
531
		if ( ! isset( $wp->query_vars['gd_is_geodir_page'] )
532
		     && ! isset( $wp->query_vars['page_id'] )
533
		     && ! isset( $wp->query_vars['pagename'] )
534
		     && is_page_geodir_home()
535
		) {
536
			$wp->query_vars['gd_is_geodir_page'] = true;
537
		}
538
		//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...
539
		/*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...
540
		print_r($wp) ;
541
		echo "</pre>" ;
542
	//	exit();
543
			*/
544
	} // end of is admin
545
}
546
547
/**
548
 * Checks whether the current page is a GD page or not.
549
 *
550
 * @since   1.0.0
551
 * @package GeoDirectory
552
 * @global object $wp WordPress object.
553
 * @return bool If the page is GD page returns true. Otherwise false.
554
 */
555
function geodir_is_geodir_page() {
556
	global $wp;
557
	if ( isset( $wp->query_vars['gd_is_geodir_page'] ) && $wp->query_vars['gd_is_geodir_page'] ) {
558
		return true;
559
	} else {
560
		return false;
561
	}
562
}
563
564
if ( ! function_exists( 'geodir_get_imagesize' ) ) {
565
	/**
566
	 * Get image size using the size key .
567
	 *
568
	 * @since   1.0.0
569
	 * @package GeoDirectory
570
	 *
571
	 * @param string $size The image size key.
572 1
	 *
573 1
	 * @return array|mixed|void|WP_Error If valid returns image size. Else returns error.
574
	 */
575
	function geodir_get_imagesize( $size = '' ) {
576 1
577 1
		$imagesizes = array(
578
			'list-thumb'   => array( 'w' => 283, 'h' => 188 ),
579
			'thumbnail'    => array( 'w' => 125, 'h' => 125 ),
580 1
			'widget-thumb' => array( 'w' => 50, 'h' => 50 ),
581 1
			'slider-thumb' => array( 'w' => 100, 'h' => 100 )
582 1
		);
583
584
		/**
585
		 * Filter the image sizes array.
586
		 *
587
		 * @since 1.0.0
588
		 *
589
		 * @param array $imagesizes Image size array.
590
		 */
591
		$imagesizes = apply_filters( 'geodir_imagesizes', $imagesizes );
592
593
		if ( ! empty( $size ) && array_key_exists( $size, $imagesizes ) ) {
594
			/**
595
			 * Filters image size of the passed key.
596
			 *
597 1
			 * @since 1.0.0
598 1
			 *
599
			 * @param array $imagesizes [$size] Image size array of the passed key.
600
			 */
601
			return apply_filters( 'geodir_get_imagesize_' . $size, $imagesizes[ $size ] );
602
603
		} elseif ( ! empty( $size ) ) {
604
605
			return new WP_Error( 'geodir_no_imagesize', __( "Given image size is not valid", 'geodirectory' ) );
606
607
		}
608
609
		return $imagesizes;
610
	}
611
}
612
613
/**
614
 * Get an image size
615
 *
616
 * Variable is filtered by geodir_get_image_size_{image_size}
617
 */
618 1
/*
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...
619
function geodir_get_image_size( $image_size ) {
620 1
	$return = '';
621 1
	switch ($image_size) :
622 1
		case "list_thumbnail_size" : $return = get_option('geodirectory_list_thumbnail_size'); break;
623 1
	endswitch;
624 1
	return apply_filters( 'geodir_get_image_size_'.$image_size, $return );
625 1
}
626 1
*/
627 1
628
629
if ( ! function_exists( 'createRandomString' ) ) {
630
	/**
631
	 * Creates random string.
632
	 *
633
	 * @since   1.0.0
634
	 * @package GeoDirectory
635
	 * @return string Random string.
636
	 */
637
	function createRandomString() {
638
		$chars = "abcdefghijkmlnopqrstuvwxyz1023456789";
639
		srand( (double) microtime() * 1000000 );
640
		$i       = 0;
641
		$rstring = '';
642
		while ( $i <= 25 ) {
643
			$num     = rand() % 33;
644
			$tmp     = substr( $chars, $num, 1 );
645
			$rstring = $rstring . $tmp;
646
			$i ++;
647
		}
648
649
		return $rstring;
650
	}
651
}
652 9
653
if ( ! function_exists( 'geodir_getDistanceRadius' ) ) {
654
	/**
655 9
	 * Calculates the distance radius.
656 9
	 *
657
	 * @since   1.0.0
658 9
	 * @package GeoDirectory
659 2
	 *
660 2
	 * @param string $uom Measurement unit type.
661 9
	 *
662 2
	 * @return float The mean radius.
663 2
	 */
664 7
	function geodir_getDistanceRadius( $uom = 'km' ) {
665 1
//	Use Haversine formula to calculate the great circle distance between two points identified by longitude and latitude
666 1
		switch ( geodir_strtolower( $uom ) ):
667 1
			case 'km'    :
668 5
				$earthMeanRadius = 6371.009; // km
669 2
				break;
670 2
			case 'm'    :
671 2
			case 'meters'    :
672 4
				$earthMeanRadius = 6371.009 * 1000; // km
673 1
				break;
674 1
			case 'miles'    :
675 2
				$earthMeanRadius = 3958.761; // miles
676 1
				break;
677 1
			case 'yards'    :
678 1
			case 'yds'    :
679
				$earthMeanRadius = 3958.761 * 1760; // yards
680
				break;
681
			case 'feet'    :
682
			case 'ft'    :
683 9
				$earthMeanRadius = 3958.761 * 1760 * 3; // feet
684 9
				break;
685 9
			case 'nm'    :
686
				$earthMeanRadius = 3440.069; //  miles
687 9
				break;
688 9
			default:
689 9
				$earthMeanRadius = 3958.761; // miles
690
				break;
691 9
		endswitch;
692 9
693 9
		return $earthMeanRadius;
694 9
	}
695
}
696 9
697 9
698 1
if ( ! function_exists( 'geodir_calculateDistanceFromLatLong' ) ) {
699 1
	/**
700
	 * Calculate the great circle distance between two points identified by longitude and latitude.
701 9
	 *
702 9
	 * @since   1.0.0
703
	 * @package GeoDirectory
704 9
	 *
705
	 * @param array $point1 Latitude and Longitude of point 1.
706 9
	 * @param array $point2 Latitude and Longitude of point 2.
707 2
	 * @param string $uom   Unit of measurement.
708 2
	 *
709 2
	 * @return float The distance.
710 9
	 */
711 9
	function geodir_calculateDistanceFromLatLong( $point1, $point2, $uom = 'km' ) {
712 9
//	Use Haversine formula to calculate the great circle distance between two points identified by longitude and latitude
713 9
714
		$earthMeanRadius = geodir_getDistanceRadius( $uom );
715 9
716 9
		$deltaLatitude  = deg2rad( (float) $point2['latitude'] - (float) $point1['latitude'] );
717 9
		$deltaLongitude = deg2rad( (float) $point2['longitude'] - (float) $point1['longitude'] );
718
		$a              = sin( $deltaLatitude / 2 ) * sin( $deltaLatitude / 2 ) +
719 9
		                  cos( deg2rad( (float) $point1['latitude'] ) ) * cos( deg2rad( (float) $point2['latitude'] ) ) *
720 6
		                  sin( $deltaLongitude / 2 ) * sin( $deltaLongitude / 2 );
721 6
		$c              = 2 * atan2( sqrt( $a ), sqrt( 1 - $a ) );
722
		$distance       = $earthMeanRadius * $c;
723 9
724 6
		return $distance;
725 6
726
	}
727 9
}
728 9
729 9
730
if ( ! function_exists( 'geodir_sendEmail' ) ) {
731 9
	/**
732 9
	 * The main function that send transactional emails using the args provided.
733 9
	 *
734
	 * @since   1.0.0
735 9
	 * @since   1.5.7 Added db translations for notifications subject and content.
736 9
	 * @package GeoDirectory
737 9
	 *
738 9
	 * @param string $fromEmail     Sender email address.
739
	 * @param string $fromEmailName Sender name.
740 9
	 * @param string $toEmail       Receiver email address.
741
	 * @param string $toEmailName   Receiver name.
742
	 * @param string $to_subject    Email subject.
743
	 * @param string $to_message    Email content.
744
	 * @param string $extra         Not being used.
745
	 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
746
	 * @param string $post_id       The post ID.
747
	 * @param string $user_id       The user ID.
748
	 */
749
	function geodir_sendEmail( $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra = '', $message_type, $post_id = '', $user_id = '' ) {
750
		$login_details = '';
751
752
		// strip slashes from subject & message text
753
		$to_subject = stripslashes_deep( $to_subject );
754
		$to_message = stripslashes_deep( $to_message );
755
756
		if ( $message_type == 'send_friend' ) {
757
			$subject = get_option( 'geodir_email_friend_subject' );
758
			$message = get_option( 'geodir_email_friend_content' );
759 9
		} elseif ( $message_type == 'send_enquiry' ) {
760
			$subject = get_option( 'geodir_email_enquiry_subject' );
761
			$message = get_option( 'geodir_email_enquiry_content' );
762
		} elseif ( $message_type == 'forgot_password' ) {
763
			$subject       = get_option( 'geodir_forgot_password_subject' );
764
			$message       = get_option( 'geodir_forgot_password_content' );
765
			$login_details = $to_message;
766
		} elseif ( $message_type == 'registration' ) {
767
			$subject       = get_option( 'geodir_registration_success_email_subject' );
768
			$message       = get_option( 'geodir_registration_success_email_content' );
769
			$login_details = $to_message;
770
		} elseif ( $message_type == 'post_submit' ) {
771
			$subject = get_option( 'geodir_post_submited_success_email_subject' );
772
			$message = get_option( 'geodir_post_submited_success_email_content' );
773
		} elseif ( $message_type == 'listing_published' ) {
774
			$subject = get_option( 'geodir_post_published_email_subject' );
775
			$message = get_option( 'geodir_post_published_email_content' );
776
		} elseif ( $message_type == 'listing_edited' ) {
777 9
			$subject = get_option( 'geodir_post_edited_email_subject_admin' );
778
			$message = get_option( 'geodir_post_edited_email_content_admin' );
779
		}
780
781
		if ( ! empty( $subject ) ) {
782
			$subject = __( stripslashes_deep( $subject ), 'geodirectory' );
783
		}
784
785
		if ( ! empty( $message ) ) {
786
			$message = __( stripslashes_deep( $message ), 'geodirectory' );
787
		}
788
789
		$to_message        = nl2br( $to_message );
790
		$sitefromEmail     = get_option( 'site_email' );
791
		$sitefromEmailName = get_site_emailName();
792
		$productlink       = get_permalink( $post_id );
793
794
		$user_login = '';
795 9
		if ( $user_id > 0 && $user_info = get_userdata( $user_id ) ) {
796
			$user_login = $user_info->user_login;
797
		}
798
799
		$posted_date = '';
800
		$listingLink = '';
801
802
		$post_info = get_post( $post_id );
803
804
		if ( $post_info ) {
805
			$posted_date = $post_info->post_date;
806
			$listingLink = '<a href="' . $productlink . '"><b>' . $post_info->post_title . '</b></a>';
807
		}
808
		$siteurl       = home_url();
809
		$siteurl_link  = '<a href="' . $siteurl . '">' . $siteurl . '</a>';
810
		$loginurl      = geodir_login_url();
811
		$loginurl_link = '<a href="' . $loginurl . '">login</a>';
812
813 9
		$post_author_id   = ! empty( $post_info ) ? $post_info->post_author : 0;
814
		$post_author_name = geodir_get_client_name( $post_author_id );
815 9
		$current_date     = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
816
817 9
		if ( $fromEmail == '' ) {
818
			$fromEmail = get_option( 'site_email' );
819
		}
820
821
		if ( $fromEmailName == '' ) {
822
			$fromEmailName = get_option( 'site_email_name' );
823
		}
824
825
		$search_array  = array(
826
			'[#listing_link#]',
827
			'[#site_name_url#]',
828
			'[#post_id#]',
829
			'[#site_name#]',
830
			'[#to_name#]',
831
			'[#from_name#]',
832 9
			'[#subject#]',
833 9
			'[#comments#]',
834
			'[#login_url#]',
835 9
			'[#login_details#]',
836 9
			'[#client_name#]',
837 1
			'[#posted_date#]',
838 1
			'[#from_email#]',
839
			'[#user_login#]',
840 1
			'[#username#]',
841 1
			'[#post_author_id#]',
842 1
			'[#post_author_name#]',
843
			'[#current_date#]'
844 1
		);
845 1
		$replace_array = array(
846 1
			$listingLink,
847
			$siteurl_link,
848 1
			$post_id,
849 1
			$sitefromEmailName,
850
			$toEmailName,
851 1
			$fromEmailName,
852 8
			$to_subject,
853 2
			$to_message,
854 2
			$loginurl_link,
855 2
			$login_details,
856 6
			$toEmailName,
857 2
			$posted_date,
858 2
			$fromEmail,
859 2
			$user_login,
860 4
			$user_login,
861 2
			$post_author_id,
862 2
			$post_author_name,
863 2
			$current_date
864 2
		);
865 1
		$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...
866 1
867 1
		$search_array  = array(
868
			'[#listing_link#]',
869 9
			'[#site_name_url#]',
870 8
			'[#post_id#]',
871
			'[#site_name#]',
872 8
			'[#to_name#]',
873
			'[#from_name#]',
874
			'[#subject#]',
875
			'[#client_name#]',
876
			'[#posted_date#]',
877
			'[#from_email#]',
878
			'[#user_login#]',
879
			'[#username#]',
880
			'[#post_author_id#]',
881
			'[#post_author_name#]',
882
			'[#current_date#]'
883
		);
884
		$replace_array = array(
885 8
			$listingLink,
886
			$siteurl_link,
887 9
			$post_id,
888
			$sitefromEmailName,
889
			$toEmailName,
890
			$fromEmailName,
891
			$to_subject,
892
			$toEmailName,
893
			$posted_date,
894
			$fromEmail,
895
			$user_login,
896
			$user_login,
897
			$post_author_id,
898
			$post_author_name,
899
			$current_date
900
		);
901
		$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...
902
903
		$headers = 'MIME-Version: 1.0' . "\r\n";
904
		$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
905
		$headers .= "Reply-To: " . $fromEmail . "\r\n";
906
		$headers .= 'From: ' . $sitefromEmailName . ' <' . $sitefromEmail . '>' . "\r\n";
907
908
		$to = $toEmail;
909
910
		/**
911
		 * Filter the client email to address.
912
		 *
913
		 * @since   1.6.1
914
		 * @package GeoDirectory
915
		 *
916
		 * @param string $to            The email address the email is being sent to.
917
		 * @param string $fromEmail     Sender email address.
918
		 * @param string $fromEmailName Sender name.
919
		 * @param string $toEmail       Receiver email address.
920
		 * @param string $toEmailName   Receiver name.
921
		 * @param string $to_subject    Email subject.
922
		 * @param string $to_message    Email content.
923
		 * @param string $extra         Not being used.
924
		 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
925
		 * @param string $post_id       The post ID.
926
		 * @param string $user_id       The user ID.
927
		 */
928
		$to = apply_filters( 'geodir_sendEmail_to', $to, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
929
		/**
930
		 * Filter the client email subject.
931
		 *
932
		 * @since   1.6.1
933
		 * @package GeoDirectory_Payment_Manager
934
		 *
935
		 * @param string $subject       The email subject.
936 5
		 * @param string $fromEmail     Sender email address.
937
		 * @param string $fromEmailName Sender name.
938
		 * @param string $toEmail       Receiver email address.
939
		 * @param string $toEmailName   Receiver name.
940
		 * @param string $to_subject    Email subject.
941
		 * @param string $to_message    Email content.
942
		 * @param string $extra         Not being used.
943 5
		 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
944
		 * @param string $post_id       The post ID.
945 5
		 * @param string $user_id       The user ID.
946 5
		 */
947 5
		$subject = apply_filters( 'geodir_sendEmail_subject', $subject, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
948 5
		/**
949
		 * Filter the client email message.
950
		 *
951
		 * @since   1.6.1
952
		 * @package GeoDirectory_Payment_Manager
953
		 *
954 5
		 * @param string $message       The email message text.
955
		 * @param string $fromEmail     Sender email address.
956 5
		 * @param string $fromEmailName Sender name.
957 5
		 * @param string $toEmail       Receiver email address.
958
		 * @param string $toEmailName   Receiver name.
959 5
		 * @param string $to_subject    Email subject.
960
		 * @param string $to_message    Email content.
961 5
		 * @param string $extra         Not being used.
962
		 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
963 5
		 * @param string $post_id       The post ID.
964 5
		 * @param string $user_id       The user ID.
965 5
		 */
966
		$message = apply_filters( 'geodir_sendEmail_message', $message, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
967 5
		/**
968 5
		 * Filter the client email headers.
969
		 *
970 5
		 * @since   1.6.1
971 5
		 * @package GeoDirectory_Payment_Manager
972
		 *
973 5
		 * @param string $headers       The email headers.
974 2
		 * @param string $fromEmail     Sender email address.
975 2
		 * @param string $fromEmailName Sender name.
976 2
		 * @param string $toEmail       Receiver email address.
977
		 * @param string $toEmailName   Receiver name.
978 2
		 * @param string $to_subject    Email subject.
979
		 * @param string $to_message    Email content.
980
		 * @param string $extra         Not being used.
981
		 * @param string $message_type  The message type. Can be send_friend, send_enquiry, forgot_password, registration, post_submit, listing_published.
982
		 * @param string $post_id       The post ID.
983
		 * @param string $user_id       The user ID.
984
		 */
985
		$headers = apply_filters( 'geodir_sendEmail_headers', $headers, $fromEmail, $fromEmailName, $toEmail, $toEmailName, $to_subject, $to_message, $extra, $message_type, $post_id, $user_id );
986
987
		$sent = wp_mail( $to, $subject, $message, $headers );
988
989
		if ( ! $sent ) {
990 2
			if ( is_array( $to ) ) {
991
				$to = implode( ',', $to );
992 2
			}
993 2
			$log_message = sprintf(
994
				__( "Email from GeoDirectory failed to send.\nMessage type: %s\nSend time: %s\nTo: %s\nSubject: %s\n\n", 'geodirectory' ),
995
				$message_type,
996
				date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ),
997
				$to,
998
				$subject
999
			);
1000
			geodir_error_log( $log_message );
1001
		}
1002
1003
		///////// ADMIN BCC EMIALS
1004
		$adminEmail = get_bloginfo( 'admin_email' );
1005
		$to         = $adminEmail;
1006 2
1007 2
		$admin_bcc = false;
1008
		if ( $message_type == 'registration' ) {
1009
			$message_raw  = explode( __( "Password:", 'geodirectory' ), $message );
1010
			$message_raw2 = explode( "</p>", $message_raw[1], 2 );
1011
			$message      = $message_raw[0] . __( 'Password:', 'geodirectory' ) . ' **********</p>' . $message_raw2[1];
1012
		}
1013 2
		if ( $message_type == 'post_submit' ) {
1014
			$subject = __( stripslashes_deep( get_option( 'geodir_post_submited_success_email_subject_admin' ) ), 'geodirectory' );
1015
			$message = __( stripslashes_deep( get_option( 'geodir_post_submited_success_email_content_admin' ) ), 'geodirectory' );
1016
1017
			$search_array  = array(
1018
				'[#listing_link#]',
1019 2
				'[#site_name_url#]',
1020
				'[#post_id#]',
1021
				'[#site_name#]',
1022
				'[#to_name#]',
1023
				'[#from_name#]',
1024
				'[#subject#]',
1025
				'[#comments#]',
1026
				'[#login_url#]',
1027
				'[#login_details#]',
1028
				'[#client_name#]',
1029
				'[#posted_date#]',
1030 2
				'[#user_login#]',
1031 2
				'[#username#]'
1032 2
			);
1033 2
			$replace_array = array(
1034 2
				$listingLink,
1035 2
				$siteurl_link,
1036
				$post_id,
1037
				$sitefromEmailName,
1038 2
				$toEmailName,
1039 2
				$fromEmailName,
1040 2
				$to_subject,
1041
				$to_message,
1042 1
				$loginurl_link,
1043
				$login_details,
1044 2
				$toEmailName,
1045 2
				$posted_date,
1046
				$user_login,
1047 2
				$user_login
1048
			);
1049 2
			$message       = str_replace( $search_array, $replace_array, $message );
1050
1051
			$search_array  = array(
1052
				'[#listing_link#]',
1053
				'[#site_name_url#]',
1054
				'[#post_id#]',
1055
				'[#site_name#]',
1056
				'[#to_name#]',
1057
				'[#from_name#]',
1058
				'[#subject#]',
1059
				'[#client_name#]',
1060
				'[#posted_date#]',
1061
				'[#user_login#]',
1062
				'[#username#]'
1063
			);
1064
			$replace_array = array(
1065
				$listingLink,
1066
				$siteurl_link,
1067
				$post_id,
1068
				$sitefromEmailName,
1069
				$toEmailName,
1070
				$fromEmailName,
1071
				$to_subject,
1072
				$toEmailName,
1073
				$posted_date,
1074
				$user_login,
1075
				$user_login
1076
			);
1077
			$subject       = str_replace( $search_array, $replace_array, $subject );
1078
1079
			$subject .= ' - ADMIN BCC COPY';
1080
			$admin_bcc = true;
1081
1082
		} elseif ( $message_type == 'registration' && get_option( 'geodir_bcc_new_user' ) ) {
1083
			$subject .= ' - ADMIN BCC COPY';
1084
			$admin_bcc = true;
1085
		} elseif ( $message_type == 'send_friend' && get_option( 'geodir_bcc_friend' ) ) {
1086
			$subject .= ' - ADMIN BCC COPY';
1087
			$admin_bcc = true;
1088
		} elseif ( $message_type == 'send_enquiry' && get_option( 'geodir_bcc_enquiry' ) ) {
1089
			$subject .= ' - ADMIN BCC COPY';
1090
			$admin_bcc = true;
1091
		} elseif ( $message_type == 'listing_published' && get_option( 'geodir_bcc_listing_published' ) ) {
1092
			$subject .= ' - ADMIN BCC COPY';
1093
			$admin_bcc = true;
1094
		}
1095
1096
		if ( $admin_bcc === true ) {
1097
			$sent = wp_mail( $to, $subject, $message, $headers );
1098
1099
			if ( ! $sent ) {
1100
				if ( is_array( $to ) ) {
1101
					$to = implode( ',', $to );
1102
				}
1103
				$log_message = sprintf(
1104
					__( "Email from GeoDirectory failed to send.\nMessage type: %s\nSend time: %s\nTo: %s\nSubject: %s\n\n", 'geodirectory' ),
1105
					$message_type,
1106
					date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ),
1107
					$to,
1108
					$subject
1109
				);
1110
				geodir_error_log( $log_message );
1111
			}
1112
		}
1113
1114
	}
1115
}
1116
1117
1118
/**
1119
 * Generates breadcrumb for taxonomy (category, tags etc.) pages.
1120
 *
1121
 * @since   1.0.0
1122 2
 * @package GeoDirectory
1123
 */
1124
function geodir_taxonomy_breadcrumb() {
1125
1126
	$term   = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
1127
	$parent = $term->parent;
1128
1129
	while ( $parent ):
1130
		$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...
1131
		$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) );
1132
		$parent     = $new_parent->parent;
1133
	endwhile;
1134
1135
	if ( ! empty( $parents ) ):
1136
		$parents = array_reverse( $parents );
1137
1138
		foreach ( $parents as $parent ):
1139
			$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) );
1140
			$url  = get_term_link( $item, get_query_var( 'taxonomy' ) );
1141
			echo '<li> > <a href="' . $url . '">' . $item->name . '</a></li>';
1142
		endforeach;
1143
1144
	endif;
1145
1146
	echo '<li> > ' . $term->name . '</li>';
1147
}
1148
1149
function geodir_wpml_post_type_archive_link($link, $post_type){
1150
1151
	if(function_exists('icl_object_id')) {
1152
		$post_types   = get_option( 'geodir_post_types' );
1153
		$slug         = $post_types[ $post_type ]['rewrite']['slug'];
1154
1155
		echo $link.'###'.gd_wpml_get_lang_from_url( $link) ;
0 ignored issues
show
Security Cross-Site Scripting introduced by
$link . '###' . gd_wpml_get_lang_from_url($link) can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_REQUEST
    in geodirectory-functions/taxonomy_functions.php on line 1379
  2. gd_wpml_get_lang_from_url() returns tainted data
    in geodirectory-functions/general_functions.php on line 1155

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1156
1157
		// Alter the CPT slug if WPML is set to do so
1158
		if ( function_exists( 'icl_object_id' ) ) {
1159
			if ( gd_wpml_slug_translation_turned_on( $post_type ) && $language_code = gd_wpml_get_lang_from_url( $link) ) {
1160
1161
				$org_slug = $slug;
1162
				$slug     = apply_filters( 'wpml_translate_single_string',
1163
					$slug,
1164
					'WordPress',
1165
					'URL slug: ' . $slug,
1166
					$language_code );
1167
1168
				if ( ! $slug ) {
1169
					$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...
1170 2
				} else {
1171 2
					$link = str_replace( $org_slug, $slug, $link );
1172
				}
1173 2
1174
			}
1175
		}
1176 5
1177 1
		echo $link.'####'.gd_wpml_get_lang_from_url( $link) ;
0 ignored issues
show
Security Cross-Site Scripting introduced by
$link . '####' . gd_wpml_get_lang_from_url($link) can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_REQUEST
    in geodirectory-functions/taxonomy_functions.php on line 1379
  2. gd_wpml_get_lang_from_url() returns tainted data
    in geodirectory-functions/general_functions.php on line 1177

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
1178 1
	}
1179 1
1180
	return $link;
1181
}
1182
1183
//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...
1184
/**
1185
 * Main function that generates breadcrumb for all pages.
1186
 *
1187
 * @since   1.0.0
1188 1
 * @since   1.5.7 Changes for the neighbourhood system improvement.
1189
 * @package GeoDirectory
1190 1
 * @global object $wp_query   WordPress Query object.
1191 1
 * @global object $post       The current post object.
1192
 * @global object $gd_session GeoDirectory Session object.
1193 1
 */
1194
function geodir_breadcrumb() {
1195
	global $wp_query, $geodir_add_location_url;
1196
1197
	/**
1198
	 * Filter breadcrumb separator.
1199
	 *
1200
	 * @since 1.0.0
1201
	 */
1202
	$separator = apply_filters( 'geodir_breadcrumb_separator', ' > ' );
1203
1204
	if ( ! geodir_is_page( 'home' ) ) {
1205
		$breadcrumb    = '';
1206
		$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...
1207
		$breadcrumb .= '<div class="geodir-breadcrumb clearfix"><ul id="breadcrumbs">';
1208
		/**
1209 1
		 * Filter breadcrumb's first link.
1210
		 *
1211 1
		 * @since 1.0.0
1212 4
		 */
1213
		$breadcrumb .= '<li>' . apply_filters( 'geodir_breadcrumb_first_link', '<a href="' . home_url() . '">' . __( 'Home', 'geodirectory' ) . '</a>' ) . '</li>';
1214
1215
		$gd_post_type   = geodir_get_current_posttype();
1216
		$post_type_info = get_post_type_object( $gd_post_type );
1217
1218
		remove_filter( 'post_type_archive_link', 'geodir_get_posttype_link' );
1219
1220
		$listing_link = get_post_type_archive_link( $gd_post_type );
1221
1222 3
		add_filter( 'post_type_archive_link', 'geodir_get_posttype_link', 10, 2 );
1223 2
		$listing_link = rtrim( $listing_link, '/' );
1224
		$listing_link .= '/';
1225 2
1226 1
		$post_type_for_location_link = $listing_link;
1227 1
		$location_terms              = geodir_get_current_location_terms( 'query_vars', $gd_post_type );
1228 1
1229 1
		global $wp, $gd_session;
1230 1
		$location_link = $post_type_for_location_link;
1231 1
1232
		if ( geodir_is_page( 'detail' ) || geodir_is_page( 'listing' ) ) {
1233 2
			global $post;
1234 2
			$location_manager     = defined( 'POST_LOCATION_TABLE' ) ? true : false;
1235 2
			$neighbourhood_active = $location_manager && get_option( 'location_neighbourhoods' ) ? true : false;
1236 3
1237 View Code Duplication
			if ( geodir_is_page( 'detail' ) && isset( $post->country_slug ) ) {
1238 1
				$location_terms = array(
1239
					'gd_country' => $post->country_slug,
1240
					'gd_region'  => $post->region_slug,
1241
					'gd_city'    => $post->city_slug
1242 1
				);
1243
1244
				if ( $neighbourhood_active && ! empty( $location_terms['gd_city'] ) && $gd_ses_neighbourhood = $gd_session->get( 'gd_neighbourhood' ) ) {
1245
					$location_terms['gd_neighbourhood'] = $gd_ses_neighbourhood;
1246 1
				}
1247
			}
1248
1249
			$geodir_show_location_url = get_option( 'geodir_show_location_url' );
1250 1
1251
			$hide_url_part = array();
1252
			if ( $location_manager ) {
1253 1
				$hide_country_part = get_option( 'geodir_location_hide_country_part' );
1254
				$hide_region_part  = get_option( 'geodir_location_hide_region_part' );
1255
1256 1
				if ( $hide_region_part && $hide_country_part ) {
1257 1
					$hide_url_part = array( 'gd_country', 'gd_region' );
1258 1
				} else if ( $hide_region_part && ! $hide_country_part ) {
1259 1
					$hide_url_part = array( 'gd_region' );
1260 5
				} else if ( ! $hide_region_part && $hide_country_part ) {
1261
					$hide_url_part = array( 'gd_country' );
1262
				}
1263
			}
1264
1265
			$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...
1266
			if ( $geodir_show_location_url == 'country_city' ) {
1267
				$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...
1268
1269 5
				if ( isset( $location_terms['gd_region'] ) && ! $location_manager ) {
1270 5
					unset( $location_terms['gd_region'] );
1271 5
				}
1272
			} else if ( $geodir_show_location_url == 'region_city' ) {
1273
				$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...
1274
1275
				if ( isset( $location_terms['gd_country'] ) && ! $location_manager ) {
1276
					unset( $location_terms['gd_country'] );
1277
				}
1278
			} else if ( $geodir_show_location_url == 'city' ) {
1279
				$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...
1280
1281
				if ( isset( $location_terms['gd_country'] ) && ! $location_manager ) {
1282
					unset( $location_terms['gd_country'] );
1283
				}
1284
				if ( isset( $location_terms['gd_region'] ) && ! $location_manager ) {
1285
					unset( $location_terms['gd_region'] );
1286
				}
1287 1
			}
1288 1
1289 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...
1290
			$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...
1291
			$breadcrumb .= '<li>';
1292
			if ( get_query_var( $gd_post_type . 'category' ) ) {
1293
				$gd_taxonomy = $gd_post_type . 'category';
1294
			} elseif ( get_query_var( $gd_post_type . '_tags' ) ) {
1295
				$gd_taxonomy = $gd_post_type . '_tags';
1296
			}
1297
1298 1
			$breadcrumb .= $separator . '<a href="' . $listing_link . '">' . __( ucfirst( $post_type_info->label ), 'geodirectory' ) . '</a>';
1299
			if ( ! empty( $gd_taxonomy ) || geodir_is_page( 'detail' ) ) {
1300
				$is_location_last = false;
1301
			} else {
1302
				$is_location_last = true;
1303
			}
1304
1305
			if ( ! empty( $gd_taxonomy ) && geodir_is_page( 'listing' ) ) {
1306
				$is_taxonomy_last = true;
1307
			} else {
1308
				$is_taxonomy_last = false;
1309
			}
1310
1311
			if ( ! empty( $location_terms ) ) {
1312
				$geodir_get_locations = function_exists( 'get_actual_location_name' ) ? true : false;
1313 1
1314 1
				foreach ( $location_terms as $key => $location_term ) {
1315 1
					if ( $location_term != '' ) {
1316
						if ( ! empty( $hide_url_part ) && in_array( $key, $hide_url_part ) ) { // Hide location part from url & breadcrumb.
1317
							continue;
1318 1
						}
1319 1
1320 1
						$gd_location_link_text = preg_replace( '/-(\d+)$/', '', $location_term );
1321 1
						$gd_location_link_text = preg_replace( '/[_-]/', ' ', $gd_location_link_text );
1322 1
						$gd_location_link_text = ucfirst( $gd_location_link_text );
1323 1
1324 1
						$location_term_actual_country = '';
1325 1
						$location_term_actual_region  = '';
1326 1
						$location_term_actual_city    = '';
1327 1
						if ( $geodir_get_locations ) {
1328
							if ( $key == 'gd_country' ) {
1329 1
								$location_term_actual_country = get_actual_location_name( 'country', $location_term, true );
1330
							} else if ( $key == 'gd_region' ) {
1331 1
								$location_term_actual_region = get_actual_location_name( 'region', $location_term, true );
1332
							} else if ( $key == 'gd_city' ) {
1333
								$location_term_actual_city = get_actual_location_name( 'city', $location_term, true );
1334 1
							}
1335
						} else {
1336
							$location_info = geodir_get_location();
1337
1338 1
							if ( ! empty( $location_info ) && isset( $location_info->location_id ) ) {
1339
								if ( $key == 'gd_country' ) {
1340 1
									$location_term_actual_country = __( $location_info->country, 'geodirectory' );
1341 1
								} else if ( $key == 'gd_region' ) {
1342 1
									$location_term_actual_region = __( $location_info->region, 'geodirectory' );
1343
								} else if ( $key == 'gd_city' ) {
1344
									$location_term_actual_city = __( $location_info->city, 'geodirectory' );
1345 1
								}
1346
							}
1347
						}
1348 1
1349
						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'] != '' ) ) {
1350 1
							$breadcrumb .= $location_term_actual_country != '' ? $separator . $location_term_actual_country : $separator . $gd_location_link_text;
1351 1
						} else if ( $is_location_last && $key == 'gd_region' && ! ( isset( $location_terms['gd_city'] ) && $location_terms['gd_city'] != '' ) ) {
1352
							$breadcrumb .= $location_term_actual_region != '' ? $separator . $location_term_actual_region : $separator . $gd_location_link_text;
1353
						} else if ( $is_location_last && $key == 'gd_city' && empty( $location_terms['gd_neighbourhood'] ) ) {
1354
							$breadcrumb .= $location_term_actual_city != '' ? $separator . $location_term_actual_city : $separator . $gd_location_link_text;
1355
						} else if ( $is_location_last && $key == 'gd_neighbourhood' ) {
1356 1
							$breadcrumb .= $separator . $gd_location_link_text;
1357
						} else {
1358 1
							if ( get_option( 'permalink_structure' ) != '' ) {
1359
								$location_link .= $location_term . '/';
1360
							} else {
1361
								$location_link .= "&$key=" . $location_term;
1362 1
							}
1363
1364
							if ( $key == 'gd_country' && $location_term_actual_country != '' ) {
1365 1
								$gd_location_link_text = $location_term_actual_country;
1366
							} else if ( $key == 'gd_region' && $location_term_actual_region != '' ) {
1367
								$gd_location_link_text = $location_term_actual_region;
1368 1
							} else if ( $key == 'gd_city' && $location_term_actual_city != '' ) {
1369
								$gd_location_link_text = $location_term_actual_city;
1370
							}
1371
1372 1
							/*
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...
1373
                            if (geodir_is_page('detail') && !empty($hide_text_part) && in_array($key, $hide_text_part)) {
1374
                                continue;
1375
                            }
1376
                            */
1377
1378 1
							$breadcrumb .= $separator . '<a href="' . $location_link . '">' . $gd_location_link_text . '</a>';
1379 1
						}
1380 1
					}
1381 1
				}
1382
			}
1383
1384
			if ( ! empty( $gd_taxonomy ) ) {
1385
				$term_index = 1;
1386 1
1387 1
				//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...
1388
				{
1389 1
					if ( get_query_var( $gd_post_type . '_tags' ) ) {
1390
						$cat_link = $listing_link . 'tags/';
1391
					} else {
1392
						$cat_link = $listing_link;
1393
					}
1394
1395
					foreach ( $location_terms as $key => $location_term ) {
1396
						if ( $location_manager && in_array( $key, $hide_url_part ) ) {
1397
							continue;
1398
						}
1399
1400
						if ( $location_term != '' ) {
1401 1
							if ( get_option( 'permalink_structure' ) != '' ) {
1402
								$cat_link .= $location_term . '/';
1403 1
							}
1404
						}
1405
					}
1406 1
1407
					$term_array = explode( "/", trim( $wp_query->query[ $gd_taxonomy ], "/" ) );
1408
					foreach ( $term_array as $term ) {
1409
						$term_link_text = preg_replace( '/-(\d+)$/', '', $term );
1410
						$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...
1411
1412
						// get term actual name
1413
						$term_info = get_term_by( 'slug', $term, $gd_taxonomy, 'ARRAY_A' );
1414
						if ( ! empty( $term_info ) && isset( $term_info['name'] ) && $term_info['name'] != '' ) {
1415 1
							$term_link_text = urldecode( $term_info['name'] );
1416
						} else {
1417
							continue;
1418
							//$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...
1419
						}
1420
1421
						if ( $term_index == count( $term_array ) && $is_taxonomy_last ) {
1422
							$breadcrumb .= $separator . $term_link_text;
1423
						} else {
1424
							$cat_link .= $term . '/';
1425
							$breadcrumb .= $separator . '<a href="' . $cat_link . '">' . $term_link_text . '</a>';
1426
						}
1427
						$term_index ++;
1428
					}
1429 1
				}
1430 1
1431 1
1432
			}
1433
1434
			if ( geodir_is_page( 'detail' ) ) {
1435
				$breadcrumb .= $separator . get_the_title();
1436
			}
1437
1438
			$breadcrumb .= '</li>';
1439
1440
1441
		} elseif ( geodir_is_page( 'author' ) ) {
1442
			$user_id             = get_current_user_id();
1443
			$author_link         = get_author_posts_url( $user_id );
1444
			$default_author_link = geodir_getlink( $author_link, array(
1445
				'geodir_dashbord' => 'true',
1446
				'stype'           => 'gd_place'
1447
			), false );
1448
1449
			/**
1450
			 * Filter author page link.
1451
			 *
1452
			 * @since 1.0.0
1453
			 *
1454
			 * @param string $default_author_link Default author link.
1455
			 * @param int $user_id                Author ID.
1456
			 */
1457
			$default_author_link = apply_filters( 'geodir_dashboard_author_link', $default_author_link, $user_id );
1458
1459
			$breadcrumb .= '<li>';
1460
			$breadcrumb .= $separator . '<a href="' . $default_author_link . '">' . __( 'My Dashboard', 'geodirectory' ) . '</a>';
1461
1462
			if ( isset( $_REQUEST['list'] ) ) {
1463
				$author_link = geodir_getlink( $author_link, array(
1464
					'geodir_dashbord' => 'true',
1465
					'stype'           => $_REQUEST['stype']
1466
				), false );
1467
1468
				/**
1469
				 * Filter author page link.
1470
				 *
1471
				 * @since 1.0.0
1472
				 *
1473
				 * @param string $author_link Author page link.
1474
				 * @param int $user_id        Author ID.
1475
				 * @param string $_REQUEST    ['stype'] Post type.
1476
				 */
1477
				$author_link = apply_filters( 'geodir_dashboard_author_link', $author_link, $user_id, $_REQUEST['stype'] );
1478
1479
				$breadcrumb .= $separator . '<a href="' . $author_link . '">' . __( ucfirst( $post_type_info->label ), 'geodirectory' ) . '</a>';
1480
				$breadcrumb .= $separator . ucfirst( __( 'My', 'geodirectory' ) . ' ' . $_REQUEST['list'] );
1481
			} else {
1482
				$breadcrumb .= $separator . __( ucfirst( $post_type_info->label ), 'geodirectory' );
1483
			}
1484
1485
			$breadcrumb .= '</li>';
1486
		} elseif ( is_category() || is_single() ) {
1487
			$category = get_the_category();
1488
			if ( is_category() ) {
1489
				$breadcrumb .= '<li>' . $separator . $category[0]->cat_name . '</li>';
1490
			}
1491
			if ( is_single() ) {
1492
				$breadcrumb .= '<li>' . $separator . '<a href="' . get_category_link( $category[0]->term_id ) . '">' . $category[0]->cat_name . '</a></li>';
1493
				$breadcrumb .= '<li>' . $separator . get_the_title() . '</li>';
1494
			}
1495
			/* End of my version ##################################################### */
1496
		} else if ( is_page() ) {
1497
			$page_title = get_the_title();
1498
1499
			if ( geodir_is_page( 'location' ) ) {
1500
				$location_page_id = geodir_location_page_id();
1501
				$loc_post         = get_post( $location_page_id );
1502
				$post_name        = $loc_post->post_name;
1503
				$slug             = ucwords( str_replace( '-', ' ', $post_name ) );
1504
				$page_title       = ! empty( $slug ) ? $slug : __( 'Location', 'geodirectory' );
1505
			}
1506
1507
			$breadcrumb .= '<li>' . $separator;
1508
			$breadcrumb .= stripslashes_deep( $page_title );
1509
			$breadcrumb .= '</li>';
1510
		} else if ( is_tag() ) {
1511
			$breadcrumb .= "<li> " . $separator . single_tag_title( '', false ) . '</li>';
1512
		} else if ( is_day() ) {
1513
			$breadcrumb .= "<li> " . $separator . __( " Archive for", 'geodirectory' ) . " ";
1514
			the_time( 'F jS, Y' );
1515
			$breadcrumb .= '</li>';
1516
		} else if ( is_month() ) {
1517
			$breadcrumb .= "<li> " . $separator . __( " Archive for", 'geodirectory' ) . " ";
1518
			the_time( 'F, Y' );
1519
			$breadcrumb .= '</li>';
1520
		} else if ( is_year() ) {
1521
			$breadcrumb .= "<li> " . $separator . __( " Archive for", 'geodirectory' ) . " ";
1522
			the_time( 'Y' );
1523
			$breadcrumb .= '</li>';
1524
		} else if ( is_author() ) {
1525
			$breadcrumb .= "<li> " . $separator . __( " Author Archive", 'geodirectory' );
1526
			$breadcrumb .= '</li>';
1527
		} else if ( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) {
1528
			$breadcrumb .= "<li>" . $separator . __( "Blog Archives", 'geodirectory' );
1529
			$breadcrumb .= '</li>';
1530
		} else if ( is_search() ) {
1531
			$breadcrumb .= "<li> " . $separator . __( " Search Results", 'geodirectory' );
1532
			$breadcrumb .= '</li>';
1533
		}
1534
		$breadcrumb .= '</ul></div>';
1535
1536
		/**
1537
		 * Filter breadcrumb html output.
1538
		 *
1539
		 * @since 1.0.0
1540
		 *
1541
		 * @param string $breadcrumb Breadcrumb HTML.
1542
		 * @param string $separator  Breadcrumb separator.
1543
		 */
1544
		echo $breadcrumb = apply_filters( 'geodir_breadcrumb', $breadcrumb, $separator );
1545
	}
1546
}
1547
1548
1549
add_action( "admin_init", "geodir_allow_wpadmin" ); // check user is admin
1550
if ( ! function_exists( 'geodir_allow_wpadmin' ) ) {
1551
	/**
1552
	 * Allow only admins to access wp-admin.
1553
	 *
1554
	 * Normal users will be redirected to home page.
1555
	 *
1556
	 * @since   1.0.0
1557
	 * @package GeoDirectory
1558
	 * @global object $wpdb WordPress Database object.
1559
	 */
1560
	function geodir_allow_wpadmin() {
1561
		global $wpdb;
1562
		if ( get_option( 'geodir_allow_wpadmin' ) == '0' && is_user_logged_in() && ( ! defined( 'DOING_AJAX' ) ) ) // checking action in request to allow ajax request go through
1563
		{
1564
			if ( current_user_can( 'administrator' ) ) {
1565
			} else {
1566
1567
				wp_redirect( home_url() );
1568
				exit;
1569
			}
1570
1571
		}
1572
	}
1573
}
1574
1575
1576
/**
1577
 * Move Images from a remote url to upload directory.
1578
 *
1579
 * @since   1.0.0
1580
 * @package GeoDirectory
1581
 *
1582
 * @param string $url The remote image url.
1583
 *
1584
 * @return array|WP_Error The uploaded data as array. When failure returns error.
1585
 */
1586
function fetch_remote_file( $url ) {
1587
	// extract the file name and extension from the url
1588
	require_once( ABSPATH . 'wp-includes/pluggable.php' );
1589
	$file_name = basename( $url );
1590
	if ( strpos( $file_name, '?' ) !== false ) {
1591
		list( $file_name ) = explode( '?', $file_name );
1592
	}
1593
	$dummy        = false;
1594
	$add_to_cache = false;
1595
	$key          = null;
1596
	if ( strpos( $url, '/dummy/' ) !== false ) {
1597
		$dummy = true;
1598
		$key   = "dummy_" . str_replace( '.', '_', $file_name );
1599
		$value = get_transient( 'cached_dummy_images' );
1600
		if ( $value ) {
1601
			if ( isset( $value[ $key ] ) ) {
1602
				return $value[ $key ];
1603
			} else {
1604
				$add_to_cache = true;
1605
			}
1606
		} else {
1607
			$add_to_cache = true;
1608
		}
1609
	}
1610
1611
	// get placeholder file in the upload dir with a unique, sanitized filename
1612
1613
	$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...
1614
1615
	$upload = wp_upload_bits( $file_name, 0, '', $post_upload_date );
1616
	if ( $upload['error'] ) {
1617
		return new WP_Error( 'upload_dir_error', $upload['error'] );
1618
	}
1619
1620
1621
	sleep( 0.3 );// if multiple remote file this can cause the remote server to timeout so we add a slight delay
1622
1623
	// fetch the remote url and write it to the placeholder file
1624
	$headers = wp_remote_get( $url, array( 'stream' => true, 'filename' => $upload['file'] ) );
1625
1626
	$log_message = '';
1627
	if ( is_wp_error( $headers ) ) {
1628
		echo 'file: ' . $url;
1629
1630
		return new WP_Error( 'import_file_error', $headers->get_error_message() );
1631
	}
1632
1633
	$filesize = filesize( $upload['file'] );
1634
	// request failed
1635
	if ( ! $headers ) {
1636
		$log_message = __( 'Remote server did not respond', 'geodirectory' );
1637
	} // make sure the fetch was successful
1638
	elseif ( $headers['response']['code'] != '200' ) {
1639
		$log_message = sprintf( __( 'Remote server returned error response %1$d %2$s', 'geodirectory' ), esc_html( $headers['response'] ), get_status_header_desc( $headers['response'] ) );
1640
	} elseif ( isset( $headers['headers']['content-length'] ) && $filesize != $headers['headers']['content-length'] ) {
1641
		$log_message = __( 'Remote file is incorrect size', 'geodirectory' );
1642
	} elseif ( 0 == $filesize ) {
1643
		$log_message = __( 'Zero size file downloaded', 'geodirectory' );
1644
	}
1645
1646
	if ( $log_message ) {
1647
		$del = unlink( $upload['file'] );
1648
		if ( ! $del ) {
1649
			geodir_error_log( __( 'GeoDirectory: fetch_remote_file() failed to delete temp file.', 'geodirectory' ) );
1650
		}
1651
1652
		return new WP_Error( 'import_file_error', $log_message );
1653
	}
1654
1655
	if ( $dummy && $add_to_cache && is_array( $upload ) ) {
1656
		$images = get_transient( 'cached_dummy_images' );
1657
		if ( is_array( $images ) ) {
1658
			$images[ $key ] = $upload;
1659
		} else {
1660
			$images = array( $key => $upload );
1661
		}
1662
1663
		//setting the cache using the WP Transient API
1664
		set_transient( 'cached_dummy_images', $images, 60 * 10 ); //10 minutes cache
1665
	}
1666
1667
	return $upload;
1668
}
1669
1670
/**
1671
 * Get maximum file upload size.
1672
 *
1673
 * @since   1.0.0
1674
 * @package GeoDirectory
1675
 * @return string|void Max upload size.
1676
 */
1677 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 (L1801-1812) 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...
1678
	$max_filesize = (float) get_option( 'geodir_upload_max_filesize', 2 );
1679
1680
	if ( $max_filesize > 0 && $max_filesize < 1 ) {
1681
		$max_filesize = (int) ( $max_filesize * 1024 ) . 'kb';
1682
	} else {
1683
		$max_filesize = $max_filesize > 0 ? $max_filesize . 'mb' : '2mb';
1684
	}
1685
1686
	/**
1687
	 * Filter default image upload size limit.
1688
	 *
1689
	 * @since 1.0.0
1690
	 *
1691
	 * @param string $max_filesize Max file upload size. Ex. 10mb, 512kb.
1692
	 */
1693
	return apply_filters( 'geodir_default_image_upload_size_limit', $max_filesize );
1694
}
1695
1696
/**
1697
 * Check if dummy folder exists or not.
1698
 *
1699
 * Check if dummy folder exists or not , if not then fetch from live url.
1700
 *
1701
 * @since   1.0.0
1702
 * @package GeoDirectory
1703
 * @return bool If dummy folder exists returns true, else false.
1704
 */
1705
function geodir_dummy_folder_exists() {
1706
	$path = geodir_plugin_path() . '/geodirectory-admin/dummy/';
1707
	if ( ! is_dir( $path ) ) {
1708
		return false;
1709
	} else {
1710
		return true;
1711
	}
1712
1713
}
1714
1715
/**
1716
 * Get the author info.
1717
 *
1718
 * @since   1.0.0
1719
 * @package GeoDirectory
1720
 * @global object $wpdb WordPress Database object.
1721
 *
1722
 * @param int $aid      The author ID.
1723
 *
1724
 * @return object Author info.
1725
 */
1726
function geodir_get_author_info( $aid ) {
1727
	global $wpdb;
1728
	/*$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...
1729
	$infosql = $wpdb->prepare( "select * from $wpdb->users where ID=%d", array( $aid ) );
1730
	$info    = $wpdb->get_results( $infosql );
1731
	if ( $info ) {
1732
		return $info[0];
1733
	}
1734
}
1735
1736
if ( ! function_exists( 'adminEmail' ) ) {
1737
	/**
1738
	 * Send emails to client on post submission, renew etc.
1739
	 *
1740
	 * @since   1.0.0
1741
	 * @package GeoDirectory
1742
	 * @global object $wpdb        WordPress Database object.
1743
	 *
1744
	 * @param int|string $page_id  Page ID.
1745
	 * @param int|string $user_id  User ID.
1746
	 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1747
	 * @param string $custom_1     Custom data to be sent.
1748
	 */
1749
	function adminEmail( $page_id, $user_id, $message_type, $custom_1 = '' ) {
1750
		global $wpdb;
1751
		if ( $message_type == 'expiration' ) {
1752
			$subject        = stripslashes( __( get_option( 'renew_email_subject' ), 'geodirectory' ) );
1753
			$client_message = stripslashes( __( get_option( 'renew_email_content' ), 'geodirectory' ) );
1754
		} elseif ( $message_type == 'post_submited' ) {
1755
			$subject        = __( get_option( 'post_submited_success_email_subject_admin' ), 'geodirectory' );
1756
			$client_message = __( get_option( 'post_submited_success_email_content_admin' ), 'geodirectory' );
1757
		} elseif ( $message_type == 'renew' ) {
1758
			$subject        = __( get_option( 'post_renew_success_email_subject_admin' ), 'geodirectory' );
1759
			$client_message = __( get_option( 'post_renew_success_email_content_admin' ), 'geodirectory' );
1760
		} elseif ( $message_type == 'upgrade' ) {
1761
			$subject        = __( get_option( 'post_upgrade_success_email_subject_admin' ), 'geodirectory' );
1762
			$client_message = __( get_option( 'post_upgrade_success_email_content_admin' ), 'geodirectory' );
1763
		} elseif ( $message_type == 'claim_approved' ) {
1764
			$subject        = __( get_option( 'claim_approved_email_subject' ), 'geodirectory' );
1765
			$client_message = __( get_option( 'claim_approved_email_content' ), 'geodirectory' );
1766
		} elseif ( $message_type == 'claim_rejected' ) {
1767
			$subject        = __( get_option( 'claim_rejected_email_subject' ), 'geodirectory' );
1768
			$client_message = __( get_option( 'claim_rejected_email_content' ), 'geodirectory' );
1769
		} elseif ( $message_type == 'claim_requested' ) {
1770
			$subject        = __( get_option( 'claim_email_subject_admin' ), 'geodirectory' );
1771
			$client_message = __( get_option( 'claim_email_content_admin' ), 'geodirectory' );
1772
		} elseif ( $message_type == 'auto_claim' ) {
1773 7
			$subject        = __( get_option( 'auto_claim_email_subject' ), 'geodirectory' );
1774 7
			$client_message = __( get_option( 'auto_claim_email_content' ), 'geodirectory' );
1775 7
		} elseif ( $message_type == 'payment_success' ) {
1776
			$subject        = __( get_option( 'post_payment_success_admin_email_subject' ), 'geodirectory' );
1777
			$client_message = __( get_option( 'post_payment_success_admin_email_content' ), 'geodirectory' );
1778
		} elseif ( $message_type == 'payment_fail' ) {
1779
			$subject        = __( get_option( 'post_payment_fail_admin_email_subject' ), 'geodirectory' );
1780 7
			$client_message = __( get_option( 'post_payment_fail_admin_email_content' ), 'geodirectory' );
1781
		}
1782
		$transaction_details = $custom_1;
1783
		$fromEmail           = get_option( 'site_email' );
1784
		$fromEmailName       = get_site_emailName();
1785
//$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...
1786
		$pkg_limit            = get_property_price_info_listing( $page_id );
1787
		$alivedays            = $pkg_limit['days'];
1788
		$productlink          = get_permalink( $page_id );
1789
		$post_info            = get_post( $page_id );
1790
		$post_date            = date( 'dS F,Y', strtotime( $post_info->post_date ) );
1791
		$listingLink          = '<a href="' . $productlink . '"><b>' . $post_info->post_title . '</b></a>';
1792
		$loginurl             = geodir_login_url();
1793 7
		$loginurl_link        = '<a href="' . $loginurl . '">login</a>';
1794
		$siteurl              = home_url();
1795
		$siteurl_link         = '<a href="' . $siteurl . '">' . $fromEmailName . '</a>';
1796
		$user_info            = get_userdata( $user_id );
1797 7
		$user_email           = $user_info->user_email;
1798
		$display_name         = geodir_get_client_name( $user_id );
1799
		$user_login           = $user_info->user_login;
1800
		$number_of_grace_days = get_option( 'ptthemes_listing_preexpiry_notice_days' );
1801
		if ( $number_of_grace_days == '' ) {
1802
			$number_of_grace_days = 1;
1803
		}
1804
		if ( $post_info->post_type == 'event' ) {
1805
			$post_type = 'event';
1806
		} else {
1807
			$post_type = 'listing';
1808
		}
1809
		$renew_link     = '<a href="' . $siteurl . '?ptype=post_' . $post_type . '&renew=1&pid=' . $page_id . '">' . RENEW_LINK . '</a>';
1810
		$search_array   = array(
1811
			'[#client_name#]',
1812
			'[#listing_link#]',
1813
			'[#posted_date#]',
1814
			'[#number_of_days#]',
1815
			'[#number_of_grace_days#]',
1816
			'[#login_url#]',
1817 2
			'[#username#]',
1818
			'[#user_email#]',
1819
			'[#site_name_url#]',
1820
			'[#renew_link#]',
1821
			'[#post_id#]',
1822
			'[#site_name#]',
1823
			'[#transaction_details#]'
1824
		);
1825
		$replace_array  = array(
1826
			$display_name,
1827
			$listingLink,
1828
			$post_date,
1829
			$alivedays,
1830
			$number_of_grace_days,
1831
			$loginurl_link,
1832
			$user_login,
1833
			$user_email,
1834
			$siteurl_link,
1835
			$renew_link,
1836
			$page_id,
1837
			$fromEmailName,
1838
			$transaction_details
1839
		);
1840
		$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...
1841
		$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...
1842
		$headers        = 'MIME-Version: 1.0' . "\r\n";
1843
		$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
1844
		$headers .= 'From: ' . $fromEmailName . ' <' . $fromEmail . '>' . "\r\n";
1845
1846
		$to      = $fromEmail;
1847
		$message = $client_message;
1848
1849 18
1850
		/**
1851
		 * Filter the admin email to address.
1852
		 *
1853 18
		 * @since   1.6.1
1854
		 * @package GeoDirectory
1855
		 *
1856
		 * @param string $to           The email address the email is being sent to.
1857
		 * @param int|string $page_id  Page ID.
1858
		 * @param int|string $user_id  User ID.
1859
		 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1860
		 * @param string $custom_1     Custom data to be sent.
1861
		 */
1862
		$to = apply_filters( 'geodir_adminEmail_to', $to, $page_id, $user_id, $message_type, $custom_1 );
1863
		/**
1864
		 * Filter the admin email subject.
1865 18
		 *
1866
		 * @since   1.6.1
1867
		 * @package GeoDirectory_Payment_Manager
1868 18
		 *
1869
		 * @param string $subject      The email subject.
1870
		 * @param int|string $page_id  Page ID.
1871
		 * @param int|string $user_id  User ID.
1872
		 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1873
		 * @param string $custom_1     Custom data to be sent.
1874
		 */
1875
		$subject = apply_filters( 'geodir_adminEmail_subject', $subject, $page_id, $user_id, $message_type, $custom_1 );
1876
		/**
1877
		 * Filter the admin email message.
1878
		 *
1879
		 * @since   1.6.1
1880
		 * @package GeoDirectory_Payment_Manager
1881
		 *
1882
		 * @param string $message      The email message text.
1883
		 * @param int|string $page_id  Page ID.
1884
		 * @param int|string $user_id  User ID.
1885
		 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1886
		 * @param string $custom_1     Custom data to be sent.
1887
		 */
1888
		$message = apply_filters( 'geodir_adminEmail_message', $message, $page_id, $user_id, $message_type, $custom_1 );
1889
		/**
1890
		 * Filter the admin email headers.
1891
		 *
1892
		 * @since   1.6.1
1893
		 * @package GeoDirectory_Payment_Manager
1894
		 *
1895
		 * @param string $headers      The email headers.
1896
		 * @param int|string $page_id  Page ID.
1897
		 * @param int|string $user_id  User ID.
1898
		 * @param string $message_type Can be 'expiration','post_submited','renew','upgrade','claim_approved','claim_rejected','claim_requested','auto_claim','payment_success','payment_fail'.
1899
		 * @param string $custom_1     Custom data to be sent.
1900
		 */
1901
		$headers = apply_filters( 'geodir_adminEmail_headers', $headers, $page_id, $user_id, $message_type, $custom_1 );
1902
1903
1904
		$sent = wp_mail( $to, $subject, $message, $headers );
1905
		if ( ! $sent ) {
1906
			if ( is_array( $to ) ) {
1907
				$to = implode( ',', $to );
1908
			}
1909
			$log_message = sprintf(
1910
				__( "Email from GeoDirectory failed to send.\nMessage type: %s\nSend time: %s\nTo: %s\nSubject: %s\n\n", 'geodirectory' ),
1911
				$message_type,
1912
				date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ),
1913
				$to,
1914
				$subject
1915
			);
1916
			geodir_error_log( $log_message );
1917
		}
1918
	}
1919
}
1920
1921
/*
1922
Language translation helper functions
1923
*/
1924
1925
/**
1926
 * Function to get the translated category id's.
1927
 *
1928
 * @since   1.0.0
1929
 * @package GeoDirectory
1930
 *
1931
 * @param array $ids_array Category IDs.
1932
 * @param string $type     Category taxonomy.
1933
 *
1934
 * @return array Category IDs.
1935
 */
1936
function gd_lang_object_ids( $ids_array, $type ) {
1937 8
	if ( function_exists( 'icl_object_id' ) ) {
1938
		$res = array();
1939 8
		foreach ( $ids_array as $id ) {
1940 8
			$xlat = icl_object_id( $id, $type, false );
1941
			if ( ! is_null( $xlat ) ) {
1942
				$res[] = $xlat;
1943
			}
1944 8
		}
1945 8
1946
		return $res;
1947 8
	} else {
1948
		return $ids_array;
1949
	}
1950 8
}
1951 8
1952 4
1953 4
/**
1954 4
 * function to add class to body when multi post type is active.
1955
 *
1956
 * @since   1.0.0
1957 4
 * @since   1.5.6 Add geodir-page class to body for all gd pages.
1958
 * @package GeoDirectory
1959
 * @global object $wpdb  WordPress Database object.
1960 4
 *
1961 3
 * @param array $classes Body CSS classes.
1962 3
 *
1963 1
 * @return array Modified Body CSS classes.
1964
 */
1965
function geodir_custom_posts_body_class( $classes ) {
1966 1
	global $wpdb, $wp;
1967
	$post_types = geodir_get_posttypes( 'object' );
1968
	if ( ! empty( $post_types ) && count( (array) $post_types ) > 1 ) {
1969 1
		$classes[] = 'geodir_custom_posts';
1970 1
	}
1971 1
1972 1
	// fix body class for signup page
1973
	if ( geodir_is_page( 'login' ) ) {
1974 8
		$new_classes   = array();
1975
		$new_classes[] = 'signup page-geodir-signup';
1976
		if ( ! empty( $classes ) ) {
1977
			foreach ( $classes as $class ) {
1978
				if ( $class && $class != 'home' && $class != 'blog' ) {
1979
					$new_classes[] = $class;
1980
				}
1981
			}
1982
		}
1983
		$classes = $new_classes;
1984
	}
1985
1986
	if ( geodir_is_geodir_page() ) {
1987
		$classes[] = 'geodir-page';
1988
	}
1989
1990
	return $classes;
1991
}
1992 8
1993 8
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
1994 8
1995
1996 8
/**
1997 8
 * Returns available map zoom levels.
1998
 *
1999 8
 * @since   1.0.0
2000
 * @package GeoDirectory
2001
 * @return array Available map zoom levels.
2002
 */
2003
function geodir_map_zoom_level() {
2004
	/**
2005
	 * Filter GD map zoom level.
2006
	 *
2007
	 * @since 1.0.0
2008 8
	 */
2009
	return apply_filters( 'geodir_map_zoom_level', array(
2010 8
		1,
2011
		2,
2012
		3,
2013
		4,
2014 8
		5,
2015
		6,
2016
		7,
2017
		8,
2018
		9,
2019
		10,
2020
		11,
2021
		12,
2022
		13,
2023
		14,
2024
		15,
2025
		16,
2026
		17,
2027
		18,
2028
		19
2029
	) );
2030
2031 8
}
2032
2033 8
2034
/**
2035 8
 * This function takes backup of an option so they can be restored later.
2036
 *
2037
 * @since   1.0.0
2038 8
 * @package GeoDirectory
2039
 *
2040
 * @param string $geodir_option_name Option key.
2041
 */
2042
function geodir_option_version_backup( $geodir_option_name ) {
2043
	$version_date  = time();
2044
	$geodir_option = get_option( $geodir_option_name );
2045
2046
	if ( ! empty( $geodir_option ) ) {
2047
		add_option( $geodir_option_name . '_' . $version_date, $geodir_option );
2048
	}
2049
}
2050
2051 8
/**
2052 8
 * display add listing page for wpml.
2053
 *
2054 8
 * @since   1.0.0
2055
 * @package GeoDirectory
2056
 *
2057
 * @param int $page_id The page ID.
2058
 *
2059
 * @return int Page ID.
2060
 */
2061
function get_page_id_geodir_add_listing_page( $page_id ) {
2062 8
	if ( geodir_wpml_multilingual_status() ) {
2063
		$post_type = 'post_page';
2064 8
		$page_id   = geodir_get_wpml_element_id( $page_id, $post_type );
2065 1
	}
2066 1
2067 1
	return $page_id;
2068 1
}
2069 1
2070 8
/**
2071
 * Returns wpml multilingual status.
2072
 *
2073
 * @since   1.0.0
2074
 * @package GeoDirectory
2075
 * @return bool Returns true when sitepress multilingual CMS active. else returns false.
2076
 */
2077
function geodir_wpml_multilingual_status() {
2078
	if ( function_exists( 'icl_object_id' ) ) {
2079 8
		return true;
2080 8
	}
2081 8
2082
	return false;
2083 8
}
2084
2085
/**
2086
 * Returns WPML element ID.
2087
 *
2088
 * @since   1.0.0
2089
 * @package GeoDirectory
2090
 *
2091 8
 * @param int $page_id      The page ID.
2092
 * @param string $post_type The post type.
2093 8
 *
2094 8
 * @return int Element ID when exists. Else the page id.
2095 8
 */
2096
function geodir_get_wpml_element_id( $page_id, $post_type ) {
2097 8
	global $sitepress;
2098
	if ( geodir_wpml_multilingual_status() && ! empty( $sitepress ) && isset( $sitepress->queries ) ) {
2099 8
		$trid = $sitepress->get_element_trid( $page_id, $post_type );
2100 8
2101 8
		if ( $trid > 0 ) {
2102 8
			$translations = $sitepress->get_element_translations( $trid, $post_type );
2103 8
2104 8
			$lang = $sitepress->get_current_language();
2105 8
			$lang = $lang ? $lang : $sitepress->get_default_language();
2106
2107
			if ( ! empty( $translations ) && ! empty( $lang ) && isset( $translations[ $lang ] ) && isset( $translations[ $lang ]->element_id ) && ! empty( $translations[ $lang ]->element_id ) ) {
2108 8
				$page_id = $translations[ $lang ]->element_id;
2109 8
			}
2110
		}
2111 8
	}
2112
2113
	return $page_id;
2114
}
2115
2116
/**
2117
 * WPML check element ID.
2118
 *
2119
 * @since      1.0.0
2120
 * @package    GeoDirectory
2121
 * @deprecated 1.4.6 No longer needed as we handle translating GD pages as normal now.
2122
 */
2123
function geodir_wpml_check_element_id() {
2124
	global $sitepress;
2125
	if ( geodir_wpml_multilingual_status() && ! empty( $sitepress ) && isset( $sitepress->queries ) ) {
2126 8
		$el_type      = 'post_page';
2127
		$el_id        = get_option( 'geodir_add_listing_page' );
2128 8
		$default_lang = $sitepress->get_default_language();
2129 8
		$el_details   = $sitepress->get_element_language_details( $el_id, $el_type );
2130
2131
		if ( ! ( $el_id > 0 && $default_lang && ! empty( $el_details ) && isset( $el_details->language_code ) && $el_details->language_code == $default_lang ) ) {
2132
			if ( ! $el_details->source_language_code ) {
2133 8
				$sitepress->set_element_language_details( $el_id, $el_type, '', $default_lang );
2134
				$sitepress->icl_translations_cache->clear();
2135
			}
2136
		}
2137
	}
2138
}
2139
2140
/**
2141
 * Returns orderby SQL using the given query args.
2142
 *
2143
 * @since   1.0.0
2144
 * @package GeoDirectory
2145
 * @global object $wpdb          WordPress Database object.
2146
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2147
 *
2148 8
 * @param array $query_args      The query array.
2149
 *
2150 8
 * @return string Orderby SQL.
2151 8
 */
2152
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...
2153
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2154
2155 8
	$query_args = $gd_query_args_widgets;
2156 8
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2157
		return $wpdb->posts . ".post_date DESC, ";
2158 8
	}
2159
2160
	$post_type = empty( $query_args['post_type'] ) ? 'gd_place' : $query_args['post_type'];
2161
	$table     = $plugin_prefix . $post_type . '_detail';
2162 8
2163 4
	$sort_by = ! empty( $query_args['order_by'] ) ? $query_args['order_by'] : '';
2164 4
2165 2
	switch ( $sort_by ) {
2166 2
		case 'latest':
2167 4
		case 'newest':
2168
			$orderby = $wpdb->posts . ".post_date DESC, ";
2169 8
			break;
2170
		case 'featured':
2171
			$orderby = $table . ".is_featured ASC, ";
2172
			break;
2173
		case 'az':
2174
			$orderby = $wpdb->posts . ".post_title ASC, ";
2175
			break;
2176
		case 'high_review':
2177
			$orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, ";
2178
			break;
2179
		case 'high_rating':
2180
			$orderby = "( " . $table . ".overall_rating  ) DESC, ";
2181
			break;
2182
		case 'random':
2183
			$orderby = "RAND(), ";
2184 8
			break;
2185
		default:
2186 8
			$orderby = $wpdb->posts . ".post_title ASC, ";
2187 8
			break;
2188
	}
2189
2190 8
	return $orderby;
2191 8
}
2192
2193 8
/**
2194 8
 * Retrieve listings/count using requested filter parameters.
2195
 *
2196
 * @since   1.0.0
2197
 * @package GeoDirectory
2198 8
 * @since   1.4.2 New parameter $count_only added
2199
 * @global object $wpdb          WordPress Database object.
2200
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2201
 * @global string $table_prefix  WordPress Database Table prefix.
2202 8
 *
2203 2
 * @param array $query_args      The query array.
2204 2
 * @param  int|bool $count_only  If true returns listings count only, otherwise returns array
2205
 *
2206 8
 * @return mixed Result object.
2207
 */
2208
function geodir_get_widget_listings( $query_args = array(), $count_only = false ) {
2209
	global $wpdb, $plugin_prefix, $table_prefix;
2210 8
	$GLOBALS['gd_query_args_widgets'] = $query_args;
2211
	$gd_query_args_widgets            = $query_args;
2212
2213
	$post_type = empty( $query_args['post_type'] ) ? 'gd_place' : $query_args['post_type'];
2214 8
	$table     = $plugin_prefix . $post_type . '_detail';
2215 2
2216 2
	$fields = $wpdb->posts . ".*, " . $table . ".*";
2217
	/**
2218 8
	 * Filter widget listing fields string part that is being used for query.
2219
	 *
2220
	 * @since 1.0.0
2221
	 *
2222 8
	 * @param string $fields    Fields string.
2223 4
	 * @param string $table     Table name.
2224
	 * @param string $post_type Post type.
2225 4
	 */
2226 2
	$fields = apply_filters( 'geodir_filter_widget_listings_fields', $fields, $table, $post_type );
2227 2
2228 4
	$join = "INNER JOIN " . $table . " ON (" . $table . ".post_id = " . $wpdb->posts . ".ID)";
2229 8
2230
	########### WPML ###########
2231 8
2232
	if ( function_exists( 'icl_object_id' ) ) {
2233
		global $sitepress;
2234
		$lang_code = ICL_LANGUAGE_CODE;
2235
		if ( $lang_code ) {
2236
			$join .= " JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID";
2237
		}
2238
	}
2239
2240
	########### WPML ###########
2241
2242
	/**
2243
	 * Filter widget listing join clause string part that is being used for query.
2244
	 *
2245
	 * @since 1.0.0
2246 8
	 *
2247
	 * @param string $join      Join clause string.
2248 8
	 * @param string $post_type Post type.
2249 8
	 */
2250
	$join = apply_filters( 'geodir_filter_widget_listings_join', $join, $post_type );
2251
2252
	$post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : '';
2253 8
2254
	$where = " AND ( " . $wpdb->posts . ".post_status = 'publish' " . $post_status . " ) AND " . $wpdb->posts . ".post_type = '" . $post_type . "'";
2255
2256
	########### WPML ###########
2257
	if ( function_exists( 'icl_object_id' ) ) {
2258
		if ( $lang_code ) {
2259
			$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...
2260
		}
2261
	}
2262
	########### WPML ###########
2263
	/**
2264
	 * Filter widget listing where clause string part that is being used for query.
2265
	 *
2266
	 * @since 1.0.0
2267
	 *
2268 8
	 * @param string $where     Where clause string.
2269
	 * @param string $post_type Post type.
2270 8
	 */
2271 8
	$where = apply_filters( 'geodir_filter_widget_listings_where', $where, $post_type );
2272
	$where = $where != '' ? " WHERE 1=1 " . $where : '';
2273
2274
	$groupby = " GROUP BY $wpdb->posts.ID ";
2275 8
	/**
2276 8
	 * Filter widget listing groupby clause string part that is being used for query.
2277 8
	 *
2278
	 * @since 1.0.0
2279 8
	 *
2280
	 * @param string $groupby   Group by clause string.
2281
	 * @param string $post_type Post type.
2282
	 */
2283
	$groupby = apply_filters( 'geodir_filter_widget_listings_groupby', $groupby, $post_type );
2284
2285
	if ( $count_only ) {
2286
		$sql  = "SELECT COUNT(" . $wpdb->posts . ".ID) AS total FROM " . $wpdb->posts . "
2287
			" . $join . "
2288
			" . $where;
2289
		$rows = (int) $wpdb->get_var( $sql );
2290
	} else {
2291
		$orderby = geodir_widget_listings_get_order( $query_args );
2292
		/**
2293 2
		 * Filter widget listing orderby clause string part that is being used for query.
2294 2
		 *
2295 2
		 * @since 1.0.0
2296
		 *
2297 2
		 * @param string $orderby   Order by clause string.
2298 2
		 * @param string $table     Table name.
2299 2
		 * @param string $post_type Post type.
2300
		 */
2301
		$orderby = apply_filters( 'geodir_filter_widget_listings_orderby', $orderby, $table, $post_type );
2302
		$orderby .= $wpdb->posts . ".post_title ASC";
2303
		$orderby = $orderby != '' ? " ORDER BY " . $orderby : '';
2304
2305
		$limit = ! empty( $query_args['posts_per_page'] ) ? $query_args['posts_per_page'] : 5;
2306
		/**
2307
		 * Filter widget listing limit that is being used for query.
2308
		 *
2309 2
		 * @since 1.0.0
2310 2
		 *
2311
		 * @param int $limit        Query results limit.
2312
		 * @param string $post_type Post type.
2313
		 */
2314
		$limit = apply_filters( 'geodir_filter_widget_listings_limit', $limit, $post_type );
2315
2316
		$page = ! empty( $query_args['pageno'] ) ? absint( $query_args['pageno'] ) : 1;
2317
		if ( ! $page ) {
2318
			$page = 1;
2319
		}
2320
2321
		$limit = (int) $limit > 0 ? " LIMIT " . absint( ( $page - 1 ) * (int) $limit ) . ", " . (int) $limit : "";
2322
2323
		$sql  = "SELECT SQL_CALC_FOUND_ROWS " . $fields . " FROM " . $wpdb->posts . "
2324 2
			" . $join . "
2325 2
			" . $where . "
2326 2
			" . $groupby . "
2327
			" . $orderby . "
2328 2
			" . $limit;
2329 2
		$rows = $wpdb->get_results( $sql );
2330 2
	}
2331
2332
	unset( $GLOBALS['gd_query_args_widgets'] );
2333
	unset( $gd_query_args_widgets );
2334
2335
	return $rows;
2336
}
2337
2338
/**
2339
 * Listing query fields SQL part for widgets.
2340 2
 *
2341
 * @since   1.0.0
2342 2
 * @package GeoDirectory
2343
 * @global object $wpdb          WordPress Database object.
2344
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2345
 *
2346
 * @param string $fields         Fields SQL.
2347
 *
2348
 * @return string Modified fields SQL.
2349
 */
2350
function geodir_function_widget_listings_fields( $fields ) {
2351
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2352
2353
	$query_args = $gd_query_args_widgets;
2354
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2355
		return $fields;
2356
	}
2357
2358
	return $fields;
2359
}
2360
2361
/**
2362
 * Listing query join clause SQL part for widgets.
2363
 *
2364
 * @since   1.0.0
2365
 * @package GeoDirectory
2366
 * @global object $wpdb          WordPress Database object.
2367
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2368
 *
2369
 * @param string $join           Join clause SQL.
2370
 *
2371
 * @return string Modified join clause SQL.
2372
 */
2373
function geodir_function_widget_listings_join( $join ) {
2374
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2375
2376
	$query_args = $gd_query_args_widgets;
2377
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2378
		return $join;
2379
	}
2380
2381
	$post_type = empty( $query_args['post_type'] ) ? 'gd_place' : $query_args['post_type'];
2382
	$table     = $plugin_prefix . $post_type . '_detail';
2383
2384 View Code Duplication
	if ( ! empty( $query_args['with_pics_only'] ) ) {
2385
		$join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )";
2386
	}
2387
2388 View Code Duplication
	if ( ! empty( $query_args['tax_query'] ) ) {
2389 9
		$tax_queries = get_tax_sql( $query_args['tax_query'], $wpdb->posts, 'ID' );
2390
		if ( ! empty( $tax_queries['join'] ) && ! empty( $tax_queries['where'] ) ) {
2391 9
			$join .= $tax_queries['join'];
2392 9
		}
2393 9
	}
2394 4
2395
	return $join;
2396 9
}
2397 9
2398
/**
2399
 * Listing query where clause SQL part for widgets.
2400
 *
2401
 * @since   1.0.0
2402
 * @package GeoDirectory
2403
 * @global object $wpdb          WordPress Database object.
2404
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2405
 *
2406
 * @param string $where          Where clause SQL.
2407
 *
2408
 * @return string Modified where clause SQL.
2409 8
 */
2410 8
function geodir_function_widget_listings_where( $where ) {
2411 8
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2412
2413
	$query_args = $gd_query_args_widgets;
2414 8
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2415 8
		return $where;
2416
	}
2417
	$post_type = empty( $query_args['post_type'] ) ? 'gd_place' : $query_args['post_type'];
2418 8
	$table     = $plugin_prefix . $post_type . '_detail';
2419 8
2420
	if ( ! empty( $query_args ) ) {
2421 8
		if ( ! empty( $query_args['gd_location'] ) && function_exists( 'geodir_default_location_where' ) ) {
2422
			$where = geodir_default_location_where( $where, $table );
2423
		}
2424 8
2425
		if ( ! empty( $query_args['post_author'] ) ) {
2426
			$where .= " AND " . $wpdb->posts . ".post_author = " . (int) $query_args['post_author'];
2427
		}
2428
2429
		if ( ! empty( $query_args['show_featured_only'] ) ) {
2430
			$where .= " AND " . $table . ".is_featured = '1'";
2431
		}
2432
2433
		if ( ! empty( $query_args['show_special_only'] ) ) {
2434
			$where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )";
2435
		}
2436
2437
		if ( ! empty( $query_args['with_pics_only'] ) ) {
2438
			$where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL ";
2439
		}
2440
2441
		if ( ! empty( $query_args['featured_image_only'] ) ) {
2442
			$where .= " AND " . $table . ".featured_image IS NOT NULL AND " . $table . ".featured_image!='' ";
2443
		}
2444
2445
		if ( ! empty( $query_args['with_videos_only'] ) ) {
2446
			$where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )";
2447
		}
2448
2449 View Code Duplication
		if ( ! empty( $query_args['tax_query'] ) ) {
2450
			$tax_queries = get_tax_sql( $query_args['tax_query'], $wpdb->posts, 'ID' );
2451
2452
			if ( ! empty( $tax_queries['join'] ) && ! empty( $tax_queries['where'] ) ) {
2453
				$where .= $tax_queries['where'];
2454
			}
2455
		}
2456
	}
2457
2458
	return $where;
2459
}
2460
2461
/**
2462
 * Listing query orderby clause SQL part for widgets.
2463
 *
2464 7
 * @since   1.0.0
2465 7
 * @package GeoDirectory
2466 7
 * @global object $wpdb          WordPress Database object.
2467
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2468
 *
2469 7
 * @param string $orderby        Orderby clause SQL.
2470 1
 *
2471 1
 * @return string Modified orderby clause SQL.
2472
 */
2473 7
function geodir_function_widget_listings_orderby( $orderby ) {
2474
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2475
2476
	$query_args = $gd_query_args_widgets;
2477
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2478
		return $orderby;
2479
	}
2480
2481
	return $orderby;
2482
}
2483
2484
/**
2485
 * Listing query limit for widgets.
2486
 *
2487
 * @since   1.0.0
2488
 * @package GeoDirectory
2489
 * @global object $wpdb          WordPress Database object.
2490
 * @global string $plugin_prefix Geodirectory plugin table prefix.
2491
 *
2492
 * @param int $limit             Query limit.
2493
 *
2494 3
 * @return int Query limit.
2495 3
 */
2496
function geodir_function_widget_listings_limit( $limit ) {
2497 3
	global $wpdb, $plugin_prefix, $gd_query_args_widgets;
2498
2499
	$query_args = $gd_query_args_widgets;
2500 3
	if ( empty( $query_args ) || empty( $query_args['is_geodir_loop'] ) ) {
2501
		return $limit;
2502 3
	}
2503
2504 3
	if ( ! empty( $query_args ) && ! empty( $query_args['posts_per_page'] ) ) {
2505 3
		$limit = (int) $query_args['posts_per_page'];
2506
	}
2507 3
2508
	return $limit;
2509
}
2510 3
2511 3
/**
2512
 * WP media large width.
2513
 *
2514 3
 * @since   1.0.0
2515 3
 * @package GeoDirectory
2516
 *
2517
 * @param int $default         Default width.
2518 3
 * @param string|array $params Image parameters.
2519
 *
2520
 * @return int Large size width.
2521 3
 */
2522 3 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...
2523 3
	$large_size_w = get_option( 'large_size_w' );
2524
	$large_size_w = $large_size_w > 0 ? $large_size_w : $default;
2525 3
	$large_size_w = absint( $large_size_w );
2526 3
2527 3
	if ( ! get_option( 'geodir_use_wp_media_large_size' ) ) {
2528 3
		$large_size_w = 800;
2529 3
	}
2530
2531 3
	/**
2532 3
	 * Filter large image width.
2533 3
	 *
2534 3
	 * @since 1.0.0
2535
	 *
2536 3
	 * @param int $large_size_w    Large image width.
2537
	 * @param int $default         Default width.
2538 3
	 * @param string|array $params Image parameters.
2539 3
	 */
2540
	$large_size_w = apply_filters( 'geodir_filter_media_image_large_width', $large_size_w, $default, $params );
2541
2542
	return $large_size_w;
2543
}
2544
2545
/**
2546
 * WP media large height.
2547
 *
2548
 * @since   1.0.0
2549 3
 * @package GeoDirectory
2550 3
 *
2551 3
 * @param int $default   Default height.
2552 3
 * @param string $params Image parameters.
2553
 *
2554
 * @return int Large size height.
2555
 */
2556 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...
2557 3
	$large_size_h = get_option( 'large_size_h' );
2558
	$large_size_h = $large_size_h > 0 ? $large_size_h : $default;
2559 3
	$large_size_h = absint( $large_size_h );
2560
2561 3
	if ( ! get_option( 'geodir_use_wp_media_large_size' ) ) {
2562
		$large_size_h = 800;
2563 3
	}
2564
2565 3
	/**
2566
	 * Filter large image height.
2567
	 *
2568
	 * @since 1.0.0
2569 3
	 *
2570 3
	 * @param int $large_size_h    Large image height.
2571 3
	 * @param int $default         Default height.
2572 3
	 * @param string|array $params Image parameters.
2573 3
	 */
2574 3
	$large_size_h = apply_filters( 'geodir_filter_media_image_large_height', $large_size_h, $default, $params );
2575 3
2576 3
	return $large_size_h;
2577
}
2578 3
2579
/**
2580
 * Sanitize location name.
2581
 *
2582 3
 * @since   1.0.0
2583 3
 * @package GeoDirectory
2584 3
 *
2585 3
 * @param string $type    Location type. Can be gd_country, gd_region, gd_city.
2586
 * @param string $name    Location name.
2587
 * @param bool $translate Do you want to translate the name? Default: true.
2588
 *
2589
 * @return string Sanitized name.
2590
 */
2591
function geodir_sanitize_location_name( $type, $name, $translate = true ) {
2592
	if ( $name == '' ) {
2593
		return null;
2594
	}
2595
2596
	$type = $type == 'gd_country' ? 'country' : $type;
2597
	$type = $type == 'gd_region' ? 'region' : $type;
2598 3
	$type = $type == 'gd_city' ? 'city' : $type;
2599 3
2600
	$return = $name;
2601 3
	if ( function_exists( 'get_actual_location_name' ) ) {
2602
		$return = get_actual_location_name( $type, $name, $translate );
2603
	} else {
2604 3
		$return = preg_replace( '/-(\d+)$/', '', $return );
2605 3
		$return = preg_replace( '/[_-]/', ' ', $return );
2606 3
		$return = geodir_ucwords( $return );
2607
		$return = $translate ? __( $return, 'geodirectory' ) : $return;
2608 3
	}
2609
2610 3
	return $return;
2611
}
2612 3
2613 3
2614
/**
2615 3
 * Pluralize comment number.
2616
 *
2617
 * @since   1.0.0
2618
 * @package GeoDirectory
2619
 *
2620
 * @param int $number Comments number.
2621
 */
2622
function geodir_comments_number( $number ) {
2623
2624 3
	if ( $number > 1 ) {
2625
		$output = str_replace( '%', number_format_i18n( $number ), __( '% Reviews', 'geodirectory' ) );
2626 3
	} elseif ( $number == 0 || $number == '' ) {
2627 3
		$output = __( 'No Reviews', 'geodirectory' );
2628 3
	} else { // must be one
2629 3
		$output = __( '1 Review', 'geodirectory' );
2630 3
	}
2631
	echo $output;
2632
}
2633
2634
/**
2635
 * Checks whether the current page is geodirectory home page or not.
2636
 *
2637
 * @since   1.0.0
2638
 * @package GeoDirectory
2639
 * @global object $wpdb WordPress Database object.
2640
 * @return bool If current page is GD home page returns true, else false.
2641
 */
2642
function is_page_geodir_home() {
2643
	global $wpdb;
2644 2
	$cur_url = str_replace( array( "https://", "http://", "www." ), array( '', '', '' ), geodir_curPageURL() );
2645
	if ( function_exists( 'geodir_location_geo_home_link' ) ) {
2646 2
		remove_filter( 'home_url', 'geodir_location_geo_home_link', 100000 );
2647
	}
2648
	$home_url = home_url( '', 'http' );
2649 2
	if ( function_exists( 'geodir_location_geo_home_link' ) ) {
2650
		add_filter( 'home_url', 'geodir_location_geo_home_link', 100000, 2 );
2651
	}
2652
	$home_url = str_replace( "www.", "", $home_url );
2653
	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' ) ) ) {
2654
		return true;
2655
	} 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' ) ) {
2656 2
		return true;
2657
	} else {
2658
		return false;
2659
	}
2660
2661
}
2662
2663 2
2664
/**
2665
 * Returns homepage canonical url for SEO plugins.
2666
 *
2667
 * @since   1.0.0
2668
 * @package GeoDirectory
2669
 * @global object $post The current post object.
2670 2
 *
2671
 * @param string $url   The old url.
2672
 *
2673
 * @return string The canonical URL.
2674
 */
2675
function geodir_wpseo_homepage_canonical( $url ) {
2676
	global $post;
2677 2
2678
	if ( is_page_geodir_home() ) {
2679
		return home_url();
2680
	}
2681
2682
	return $url;
2683
}
2684 2
2685
add_filter( 'wpseo_canonical', 'geodir_wpseo_homepage_canonical', 10 );
2686
add_filter( 'aioseop_canonical_url', 'geodir_wpseo_homepage_canonical', 10 );
2687
2688
/**
2689
 * Add extra fields to google maps script call.
2690
 *
2691 2
 * @since   1.0.0
2692
 * @package GeoDirectory
2693
 * @global object $post The current post object.
2694
 *
2695
 * @param string $extra Old extra string.
2696
 *
2697
 * @return string Modified extra string.
2698 2
 */
2699
function geodir_googlemap_script_extra_details_page( $extra ) {
2700
	global $post;
2701
	$add_google_places_api = false;
2702
	if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'gd_add_listing' ) ) {
2703
		$add_google_places_api = true;
2704
	}
2705 2
	if ( ! str_replace( 'libraries=places', '', $extra ) && ( geodir_is_page( 'detail' ) || $add_google_places_api ) ) {
2706
		$extra .= "&amp;libraries=places";
2707
	}
2708
2709
	return $extra;
2710
}
2711
2712 2
add_filter( 'geodir_googlemap_script_extra', 'geodir_googlemap_script_extra_details_page', 101, 1 );
2713
2714
2715
/**
2716
 * Generates popular post category HTML.
2717
 *
2718
 * @since   1.0.0
2719 2
 * @since   1.5.1 Added option to set default post type.
2720
 * @since   1.6.9 Added option to show parent categories only.
2721
 * @package GeoDirectory
2722
 * @global object $wpdb                     WordPress Database object.
2723
 * @global string $plugin_prefix            Geodirectory plugin table prefix.
2724
 * @global string $geodir_post_category_str The geodirectory post category.
2725
 *
2726 2
 * @param array|string $args                Display arguments including before_title, after_title, before_widget, and
2727
 *                                          after_widget.
2728
 * @param array|string $instance            The settings for the particular instance of the widget.
2729
 */
2730
function geodir_popular_post_category_output( $args = '', $instance = '' ) {
2731
	// prints the widget
2732
	global $wpdb, $plugin_prefix, $geodir_post_category_str;
2733 2
	extract( $args, EXTR_SKIP );
2734
2735
	echo $before_widget;
2736
2737
	/** This filter is documented in geodirectory_widgets.php */
2738
	$title = empty( $instance['title'] ) ? __( 'Popular Categories', 'geodirectory' ) : apply_filters( 'widget_title', __( $instance['title'], 'geodirectory' ) );
2739
2740 2
	$gd_post_type = geodir_get_current_posttype();
2741 2
2742
	$category_limit = isset( $instance['category_limit'] ) && $instance['category_limit'] > 0 ? (int) $instance['category_limit'] : 15;
2743 2
	if ( ! empty( $gd_post_type ) ) {
2744
		$default_post_type = $gd_post_type;
2745
	} elseif ( isset( $instance['default_post_type'] ) && gdsc_is_post_type_valid( $instance['default_post_type'] ) ) {
2746
		$default_post_type = $instance['default_post_type'];
2747
	} else {
2748
		$all_gd_post_type  = geodir_get_posttypes();
2749
		$default_post_type = ( isset( $all_gd_post_type[0] ) ) ? $all_gd_post_type[0] : '';
2750
	}
2751
	$parent_only = !empty( $instance['parent_only'] ) ? true : false;
2752
2753
	$taxonomy = array();
2754
	if ( ! empty( $gd_post_type ) ) {
2755
		$taxonomy[] = $gd_post_type . "category";
2756
	} else {
2757
		$taxonomy = geodir_get_taxonomies( $gd_post_type );
2758
	}
2759
    
2760
	$term_args = array( 'taxonomy' => $taxonomy );
2761
	if ( $parent_only ) {
2762
		$term_args['parent'] = 0;
2763
	}
2764
2765
	$terms   = get_terms( $term_args );
2766
	$a_terms = array();
2767
	$b_terms = array();
2768
2769
	foreach ( $terms as $term ) {
2770
		if ( $term->count > 0 ) {
2771
			$a_terms[ $term->taxonomy ][] = $term;
2772
		}
2773
	}
2774
2775
	if ( ! empty( $a_terms ) ) {
2776
		foreach ( $a_terms as $b_key => $b_val ) {
2777
			$b_terms[ $b_key ] = geodir_sort_terms( $b_val, 'count' );
2778
		}
2779
2780
		$default_taxonomy = $default_post_type != '' && isset( $b_terms[ $default_post_type . 'category' ] ) ? $default_post_type . 'category' : '';
2781
2782
		$tax_change_output = '';
2783
		if ( count( $b_terms ) > 1 ) {
2784
			$tax_change_output .= "<select data-limit='$category_limit' data-parent='" . (int)$parent_only . "' class='geodir-cat-list-tax'  onchange='geodir_get_post_term(this);'>";
2785
			foreach ( $b_terms as $key => $val ) {
2786 2
				$ptype    = get_post_type_object( str_replace( "category", "", $key ) );
2787 2
				$cpt_name = __( $ptype->labels->singular_name, 'geodirectory' );
2788 2
				$tax_change_output .= "<option value='$key' " . selected( $key, $default_taxonomy, false ) . ">" . sprintf( __( '%s Categories', 'geodirectory' ), $cpt_name ) . "</option>";
2789
			}
2790 2
			$tax_change_output .= "</select>";
2791 2
		}
2792 1
2793 1
		if ( ! empty( $b_terms ) ) {
2794
			$terms = $default_taxonomy != '' && isset( $b_terms[ $default_taxonomy ] ) ? $b_terms[ $default_taxonomy ] : reset( $b_terms );// get the first array
2795 2
			global $cat_count;//make global so we can change via function
2796 2
			$cat_count = 0;
2797
			?>
2798 2
			<div class="geodir-category-list-in clearfix">
2799 2
				<div class="geodir-cat-list clearfix">
2800
					<?php
2801 2
					echo $before_title . __( $title ) . $after_title;
2802
2803 2
					echo $tax_change_output;
2804 2
2805
					echo '<ul class="geodir-popular-cat-list">';
2806
2807 2
					geodir_helper_cat_list_output( $terms, $category_limit );
2808
2809 2
					echo '</ul>';
2810
					?>
2811
				</div>
2812
				<?php
2813 2
				$hide = '';
2814 2
				if ( $cat_count < $category_limit ) {
2815 1
					$hide = 'style="display:none;"';
2816
				}
2817
				echo "<div class='geodir-cat-list-more' $hide >";
2818
				echo '<a href="javascript:void(0)" class="geodir-morecat geodir-showcat">' . __( 'More Categories', 'geodirectory' ) . '</a>';
2819 1
				echo '<a href="javascript:void(0)" class="geodir-morecat geodir-hidecat geodir-hide">' . __( 'Less Categories', 'geodirectory' ) . '</a>';
2820
				echo "</div>";
2821 1
				/* add scripts */
2822
				add_action( 'wp_footer', 'geodir_popular_category_add_scripts', 100 );
2823 1
				?>
2824 1
			</div>
2825 1
			<?php
2826
		}
2827 1
	}
2828 1
	echo $after_widget;
2829 1
}
2830 1
2831
/**
2832 1
 * Generates category list HTML.
2833 1
 *
2834 1
 * @since   1.0.0
2835 1
 * @package GeoDirectory
2836 1
 * @global string $geodir_post_category_str The geodirectory post category.
2837
 *
2838
 * @param array $terms                      An array of term objects.
2839 1
 * @param int $category_limit               Number of categories to display by default.
2840
 */
2841 1
function geodir_helper_cat_list_output( $terms, $category_limit ) {
2842 1
	global $geodir_post_category_str, $cat_count;
2843
	$term_icons = geodir_get_term_icon();
2844
2845
	$geodir_post_category_str = array();
2846
2847
2848
	foreach ( $terms as $cat ) {
2849
		$post_type     = str_replace( "category", "", $cat->taxonomy );
2850
		$term_icon_url = ! empty( $term_icons ) && isset( $term_icons[ $cat->term_id ] ) ? $term_icons[ $cat->term_id ] : '';
2851
2852
		$cat_count ++;
2853
2854
		$geodir_post_category_str[] = array( 'posttype' => $post_type, 'termid' => $cat->term_id );
2855
2856
		$class_row  = $cat_count > $category_limit ? 'geodir-pcat-hide geodir-hide' : 'geodir-pcat-show';
2857
		$total_post = $cat->count;
2858
2859 1
		$term_link = get_term_link( $cat, $cat->taxonomy );
2860 1
		/**
2861 1
		 * Filer the category term link.
2862 1
		 *
2863 1
		 * @since 1.4.5
2864
		 *
2865
		 * @param string $term_link The term permalink.
2866
		 * @param int $cat          ->term_id The term id.
2867
		 * @param string $post_type Wordpress post type.
2868
		 */
2869
		$term_link = apply_filters( 'geodir_category_term_link', $term_link, $cat->term_id, $post_type );
2870
2871
		echo '<li class="' . $class_row . '"><a href="' . $term_link . '">';
2872
		echo '<img alt="' . esc_attr( $cat->name ) . ' icon" style="height:20px;vertical-align:middle;" src="' . $term_icon_url . '"/> <span class="cat-link">';
2873
		echo $cat->name . '</span> <span class="geodir_term_class geodir_link_span geodir_category_class_' . $post_type . '_' . $cat->term_id . '">(' . $total_post . ')</span> ';
2874
		echo '</a></li>';
2875
	}
2876
}
2877 1
2878 1
/**
2879 1
 * Generates listing slider HTML.
2880 2
 *
2881 2
 * @since   1.0.0
2882
 * @package GeoDirectory
2883
 * @global object $post          The current post object.
2884
 *
2885
 * @param array|string $args     Display arguments including before_title, after_title, before_widget, and after_widget.
2886
 * @param array|string $instance The settings for the particular instance of the widget.
2887
 */
2888
function geodir_listing_slider_widget_output( $args = '', $instance = '' ) {
2889
	// prints the widget
2890
	extract( $args, EXTR_SKIP );
2891
2892
	echo $before_widget;
2893
2894
	/** This filter is documented in geodirectory_widgets.php */
2895
	$title = empty( $instance['title'] ) ? '' : apply_filters( 'widget_title', __( $instance['title'], 'geodirectory' ) );
2896
	/**
2897
	 * Filter the widget post type.
2898 2
	 *
2899
	 * @since 1.0.0
2900
	 *
2901 2
	 * @param string $instance ['post_type'] Post type of listing.
2902
	 */
2903 2
	$post_type = empty( $instance['post_type'] ) ? 'gd_place' : apply_filters( 'widget_post_type', $instance['post_type'] );
2904 2
	/**
2905
	 * Filter the widget's term.
2906 2
	 *
2907 2
	 * @since 1.0.0
2908
	 *
2909 2
	 * @param string $instance ['category'] Filter by term. Can be any valid term.
2910 2
	 */
2911
	$category = empty( $instance['category'] ) ? '0' : apply_filters( 'widget_category', $instance['category'] );
2912 2
	/**
2913 2
	 * Filter widget's "add_location_filter" value.
2914
	 *
2915
	 * @since 1.0.0
2916
	 *
2917
	 * @param string|bool $instance ['add_location_filter'] Do you want to add location filter? Can be 1 or 0.
2918 2
	 */
2919 2
	$add_location_filter = empty( $instance['add_location_filter'] ) ? '0' : apply_filters( 'widget_add_location_filter', $instance['add_location_filter'] );
2920 2
	/**
2921
	 * Filter the widget listings limit.
2922 2
	 *
2923 2
	 * @since 1.0.0
2924 2
	 *
2925
	 * @param string $instance ['post_number'] Number of listings to display.
2926 2
	 */
2927
	$post_number = empty( $instance['post_number'] ) ? '5' : apply_filters( 'widget_post_number', $instance['post_number'] );
2928 2
	/**
2929
	 * Filter the widget listings limit shown at one time.
2930 2
	 *
2931
	 * @since 1.5.0
2932 2
	 *
2933 2
	 * @param string $instance ['max_show'] Number of listings to display on screen.
2934 2
	 */
2935
	$max_show = empty( $instance['max_show'] ) ? '1' : apply_filters( 'widget_max_show', $instance['max_show'] );
2936
	/**
2937
	 * Filter the widget slide width.
2938
	 *
2939
	 * @since 1.5.0
2940
	 *
2941
	 * @param string $instance ['slide_width'] Width of the slides shown.
2942
	 */
2943
	$slide_width = empty( $instance['slide_width'] ) ? '' : apply_filters( 'widget_slide_width', $instance['slide_width'] );
2944 2
	/**
2945
	 * Filter widget's "show title" value.
2946 2
	 *
2947
	 * @since 1.0.0
2948 2
	 *
2949 2
	 * @param string|bool $instance ['show_title'] Do you want to display title? Can be 1 or 0.
2950
	 */
2951 2
	$show_title = empty( $instance['show_title'] ) ? '' : apply_filters( 'widget_show_title', $instance['show_title'] );
2952
	/**
2953
	 * Filter widget's "slideshow" value.
2954
	 *
2955
	 * @since 1.0.0
2956
	 *
2957
	 * @param int $instance ['slideshow'] Setup a slideshow for the slider to animate automatically.
2958
	 */
2959
	$slideshow = empty( $instance['slideshow'] ) ? 0 : apply_filters( 'widget_slideshow', $instance['slideshow'] );
2960
	/**
2961
	 * Filter widget's "animationLoop" value.
2962 2
	 *
2963
	 * @since 1.0.0
2964 2
	 *
2965
	 * @param int $instance ['animationLoop'] Gives the slider a seamless infinite loop.
2966 2
	 */
2967 2
	$animationLoop = empty( $instance['animationLoop'] ) ? 0 : apply_filters( 'widget_animationLoop', $instance['animationLoop'] );
2968
	/**
2969 2
	 * Filter widget's "directionNav" value.
2970
	 *
2971
	 * @since 1.0.0
2972
	 *
2973
	 * @param int $instance ['directionNav'] Enable previous/next arrow navigation?. Can be 1 or 0.
2974
	 */
2975
	$directionNav = empty( $instance['directionNav'] ) ? 0 : apply_filters( 'widget_directionNav', $instance['directionNav'] );
2976
	/**
2977
	 * Filter widget's "slideshowSpeed" value.
2978
	 *
2979
	 * @since 1.0.0
2980
	 *
2981
	 * @param int $instance ['slideshowSpeed'] Set the speed of the slideshow cycling, in milliseconds.
2982
	 */
2983
	$slideshowSpeed = empty( $instance['slideshowSpeed'] ) ? 5000 : apply_filters( 'widget_slideshowSpeed', $instance['slideshowSpeed'] );
2984
	/**
2985
	 * Filter widget's "animationSpeed" value.
2986
	 *
2987
	 * @since 1.0.0
2988
	 *
2989
	 * @param int $instance ['animationSpeed'] Set the speed of animations, in milliseconds.
2990
	 */
2991
	$animationSpeed = empty( $instance['animationSpeed'] ) ? 600 : apply_filters( 'widget_animationSpeed', $instance['animationSpeed'] );
2992
	/**
2993
	 * Filter widget's "animation" value.
2994
	 *
2995
	 * @since 1.0.0
2996
	 *
2997
	 * @param string $instance ['animation'] Controls the animation type, "fade" or "slide".
2998
	 */
2999
	$animation = empty( $instance['animation'] ) ? 'slide' : apply_filters( 'widget_animation', $instance['animation'] );
3000
	/**
3001
	 * Filter widget's "list_sort" type.
3002
	 *
3003
	 * @since 1.0.0
3004
	 *
3005
	 * @param string $instance ['list_sort'] Listing sort by type.
3006
	 */
3007
	$list_sort          = empty( $instance['list_sort'] ) ? 'latest' : apply_filters( 'widget_list_sort', $instance['list_sort'] );
3008
	$show_featured_only = ! empty( $instance['show_featured_only'] ) ? 1 : null;
3009
3010
	wp_enqueue_script( 'geodirectory-jquery-flexslider-js' );
3011 2
	?>
3012 2
	<script type="text/javascript">
3013
		jQuery(window).load(function () {
3014 2
			jQuery('#geodir_widget_carousel').flexslider({
3015 2
				animation: "slide",
3016
				selector: ".geodir-slides > li",
3017 2
				namespace: "geodir-",
3018 2
				controlNav: false,
3019 2
				directionNav: false,
3020 2
				animationLoop: false,
3021
				slideshow: false,
3022 2
				itemWidth: 75,
3023 2
				itemMargin: 5,
3024 1
				asNavFor: '#geodir_widget_slider',
3025 1
				rtl: <?php echo( is_rtl() ? 'true' : 'false' ); /* fix rtl issue */ ?>
3026
			});
3027
3028
			jQuery('#geodir_widget_slider').flexslider({
3029
				animation: "<?php echo $animation;?>",
3030
				selector: ".geodir-slides > li",
3031
				namespace: "geodir-",
3032
				controlNav: true,
3033
				animationLoop: <?php echo $animationLoop;?>,
3034
				slideshow: <?php echo $slideshow;?>,
3035 2
				slideshowSpeed: <?php echo $slideshowSpeed;?>,
3036
				animationSpeed: <?php echo $animationSpeed;?>,
3037 2
				directionNav: <?php echo $directionNav;?>,
3038 2
				maxItems: <?php echo $max_show;?>,
3039 2
				move: 1,
3040
				<?php if ( $slide_width ) {
3041 2
				echo "itemWidth: " . $slide_width . ",";
3042
			}?>
3043
				sync: "#geodir_widget_carousel",
3044
				start: function (slider) {
3045
					jQuery('.geodir-listing-flex-loader').hide();
3046
					jQuery('#geodir_widget_slider').css({'visibility': 'visible'});
3047
					jQuery('#geodir_widget_carousel').css({'visibility': 'visible'});
3048
				},
3049
				rtl: <?php echo( is_rtl() ? 'true' : 'false' ); /* fix rtl issue */ ?>
3050
			});
3051
		});
3052 2
	</script>
3053 2
	<?php
3054
	$query_args = array(
3055 2
		'posts_per_page' => $post_number,
3056
		'is_geodir_loop' => true,
3057
		'gd_location'    => $add_location_filter ? true : false,
3058
		'post_type'      => $post_type,
3059
		'order_by'       => $list_sort
3060
	);
3061
3062 2
	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...
3063 2
		$query_args['show_featured_only'] = 1;
3064 2
	}
3065
3066
	if ( $category != 0 || $category != '' ) {
3067
		$category_taxonomy = geodir_get_taxonomies( $post_type );
3068
		$tax_query         = array(
3069
			'taxonomy' => $category_taxonomy[0],
3070
			'field'    => 'id',
3071
			'terms'    => $category
3072
		);
3073
3074
		$query_args['tax_query'] = array( $tax_query );
3075
	}
3076
3077
	// we want listings with featured image only
3078
	$query_args['featured_image_only'] = 1;
3079
3080
	if ( $post_type == 'gd_event' ) {
3081
		$query_args['gedir_event_listing_filter'] = 'upcoming';
3082
	}// show only upcoming events
3083
3084
	$widget_listings = geodir_get_widget_listings( $query_args );
3085
	if ( ! empty( $widget_listings ) || ( isset( $with_no_results ) && $with_no_results ) ) {
3086
		if ( $title ) {
3087
			echo $before_title . $title . $after_title;
3088
		}
3089
3090
		global $post;
3091
3092
		$current_post = $post;// keep current post info
3093
3094
		$widget_main_slides = '';
3095
		$nav_slides         = '';
3096
		$widget_slides      = 0;
3097
3098
		foreach ( $widget_listings as $widget_listing ) {
3099
			global $gd_widget_listing_type;
3100
			$post         = $widget_listing;
3101
			$widget_image = geodir_get_featured_image( $post->ID, 'thumbnail', get_option( 'geodir_listing_no_img' ) );
3102
3103
			if ( ! empty( $widget_image ) ) {
3104
				if ( $widget_image->height >= 200 ) {
3105
					$widget_spacer_height = 0;
3106
				} else {
3107
					$widget_spacer_height = ( ( 200 - $widget_image->height ) / 2 );
3108
				}
3109
3110
				$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" />';
3111
3112
				$title = '';
3113 2
				if ( $show_title ) {
3114 2
					$title_html     = '<div class="geodir-slider-title"><a href="' . get_permalink( $post->ID ) . '">' . get_the_title( $post->ID ) . '</a></div>';
3115
					$post_id        = $post->ID;
3116
					$post_permalink = get_permalink( $post->ID );
3117
					$post_title     = get_the_title( $post->ID );
3118
					/**
3119
					 * Filter the listing slider widget title.
3120
					 *
3121
					 * @since 1.6.1
3122
					 *
3123
					 * @param string $title_html     The html output of the title.
3124
					 * @param int $post_id           The post id.
3125
					 * @param string $post_permalink The post permalink url.
3126
					 * @param string $post_title     The post title text.
3127
					 */
3128
					$title = apply_filters( 'geodir_listing_slider_title', $title_html, $post_id, $post_permalink, $post_title );
3129
				}
3130
3131
				$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>';
3132 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>';
3133
				$widget_slides ++;
3134
			}
3135 2
		}
3136
		?>
3137 2
		<div class="flex-container" style="min-height:200px;">
3138
			<div class="geodir-listing-flex-loader"><i class="fa fa-refresh fa-spin"></i></div>
3139
			<div id="geodir_widget_slider" class="geodir_flexslider">
3140 2
				<ul class="geodir-slides clearfix"><?php echo $widget_main_slides; ?></ul>
3141
			</div>
3142
			<?php if ( $widget_slides > 1 ) { ?>
3143
				<div id="geodir_widget_carousel" class="geodir_flexslider">
3144
					<ul class="geodir-slides clearfix"><?php echo $nav_slides; ?></ul>
3145
				</div>
3146
			<?php } ?>
3147 2
		</div>
3148
		<?php
3149
		$GLOBALS['post'] = $current_post;
3150
		setup_postdata( $current_post );
3151
	}
3152
	echo $after_widget;
3153
}
3154 2
3155
3156
/**
3157
 * Generates login box HTML.
3158
 *
3159
 * @since   1.0.0
3160
 * @package GeoDirectory
3161 2
 * @global object $current_user  Current user object.
3162
 *
3163
 * @param array|string $args     Display arguments including before_title, after_title, before_widget, and after_widget.
3164
 * @param array|string $instance The settings for the particular instance of the widget.
3165
 */
3166
function geodir_loginwidget_output( $args = '', $instance = '' ) {
3167
	//print_r($args);
3168 2
	//print_r($instance);
3169
	// prints the widget
3170
	extract( $args, EXTR_SKIP );
3171
3172
	/** This filter is documented in geodirectory_widgets.php */
3173
	$title = empty( $instance['title'] ) ? __( 'My Dashboard', 'geodirectory' ) : apply_filters( 'my_dashboard_widget_title', __( $instance['title'], 'geodirectory' ) );
3174
3175 2
	echo $before_widget;
3176
	echo $before_title . $title . $after_title;
3177
3178
	if ( is_user_logged_in() ) {
3179
		global $current_user;
3180
3181
		$author_link = get_author_posts_url( $current_user->data->ID );
3182 2
		$author_link = geodir_getlink( $author_link, array( 'geodir_dashbord' => 'true' ), false );
3183
3184
		echo '<ul class="geodir-loginbox-list">';
3185
		ob_start();
3186
		?>
3187
		<li><a class="signin"
3188
		       href="<?php echo wp_logout_url( home_url() ); ?>"><?php _e( 'Logout', 'geodirectory' ); ?></a></li>
3189 2
		<?php
3190 2
		$post_types                           = geodir_get_posttypes( 'object' );
3191
		$show_add_listing_post_types_main_nav = get_option( 'geodir_add_listing_link_user_dashboard' );
3192
		$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...
3193 2
3194 1
		if ( ! empty( $show_add_listing_post_types_main_nav ) ) {
3195 1
			$addlisting_links = '';
3196
			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...
3197
3198
				if ( in_array( $key, $show_add_listing_post_types_main_nav ) ) {
3199 1
3200
					if ( $add_link = geodir_get_addlisting_link( $key ) ) {
3201 2
3202 2
						$name = $postobj->labels->name;
3203
3204 2
						$selected = '';
3205 2
						if ( geodir_get_current_posttype() == $key && geodir_is_page( 'add-listing' ) ) {
3206
							$selected = 'selected="selected"';
3207 2
						}
3208
3209
						/**
3210
						 * Filter add listing link.
3211
						 *
3212
						 * @since 1.0.0
3213
						 *
3214 1
						 * @param string $add_link  Add listing link.
3215 1
						 * @param string $key       Add listing array key.
3216 1
						 * @param int $current_user ->ID Current user ID.
3217
						 */
3218
						$add_link = apply_filters( 'geodir_dashboard_link_add_listing', $add_link, $key, $current_user->ID );
3219 2
3220 2
						$addlisting_links .= '<option ' . $selected . ' value="' . $add_link . '">' . __( ucfirst( $name ), 'geodirectory' ) . '</option>';
3221 2
3222
					}
3223 2
				}
3224 2
3225 2
			}
3226
3227 View Code Duplication
			if ( $addlisting_links != '' ) { ?>
3228
3229
				<li><select id="geodir_add_listing" class="chosen_select" onchange="window.location.href=this.value"
3230
				            option-autoredirect="1" name="geodir_add_listing" option-ajaxchosen="false"
3231
				            data-placeholder="<?php echo esc_attr( __( 'Add Listing', 'geodirectory' ) ); ?>">
3232
						<option value="" disabled="disabled" selected="selected"
3233
						        style='display:none;'><?php echo esc_attr( __( 'Add Listing', 'geodirectory' ) ); ?></option>
3234
						<?php echo $addlisting_links; ?>
3235
					</select></li> <?php
3236
3237
			}
3238
3239
		}
3240
		// My Favourites in Dashboard
3241
		$show_favorite_link_user_dashboard = get_option( 'geodir_favorite_link_user_dashboard' );
3242
		$user_favourite                    = geodir_user_favourite_listing_count();
3243
3244
		if ( ! empty( $show_favorite_link_user_dashboard ) && ! empty( $user_favourite ) ) {
3245
			$favourite_links = '';
3246
3247
			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...
3248
				if ( in_array( $key, $show_favorite_link_user_dashboard ) && array_key_exists( $key, $user_favourite ) ) {
3249
					$name           = $postobj->labels->name;
3250
					$post_type_link = geodir_getlink( $author_link, array(
3251
						'stype' => $key,
3252 2
						'list'  => 'favourite'
3253 2
					), false );
3254 2
3255
					$selected = '';
3256
3257 View Code Duplication
					if ( isset( $_REQUEST['list'] ) && $_REQUEST['list'] == 'favourite' && isset( $_REQUEST['stype'] ) && $_REQUEST['stype'] == $key && isset( $_REQUEST['geodir_dashbord'] ) ) {
3258
						$selected = 'selected="selected"';
3259 2
					}
3260
					/**
3261
					 * Filter favorite listing link.
3262 2
					 *
3263
					 * @since 1.0.0
3264
					 *
3265 2
					 * @param string $post_type_link Favorite listing link.
3266
					 * @param string $key            Favorite listing array key.
3267
					 * @param int $current_user      ->ID Current user ID.
3268
					 */
3269
					$post_type_link = apply_filters( 'geodir_dashboard_link_favorite_listing', $post_type_link, $key, $current_user->ID );
3270
3271
					$favourite_links .= '<option ' . $selected . ' value="' . $post_type_link . '">' . __( ucfirst( $name ), 'geodirectory' ) . '</option>';
3272
				}
3273
			}
3274
3275 View Code Duplication
			if ( $favourite_links != '' ) {
3276
				?>
3277
				<li>
3278 2
					<select id="geodir_my_favourites" class="chosen_select" onchange="window.location.href=this.value"
3279
					        option-autoredirect="1" name="geodir_my_favourites" option-ajaxchosen="false"
3280
					        data-placeholder="<?php echo esc_attr( __( 'My Favorites', 'geodirectory' ) ); ?>">
3281
						<option value="" disabled="disabled" selected="selected"
3282 2
						        style='display:none;'><?php echo esc_attr( __( 'My Favorites', 'geodirectory' ) ); ?></option>
3283
						<?php echo $favourite_links; ?>
3284
					</select>
3285 2
				</li>
3286 2
				<?php
3287 2
			}
3288 2
		}
3289
3290 2
3291
		$show_listing_link_user_dashboard = get_option( 'geodir_listing_link_user_dashboard' );
3292 2
		$user_listing                     = geodir_user_post_listing_count();
3293 1
3294 1
		if ( ! empty( $show_listing_link_user_dashboard ) && ! empty( $user_listing ) ) {
3295
			$listing_links = '';
3296 2
3297 1
			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...
3298 1
				if ( in_array( $key, $show_listing_link_user_dashboard ) && array_key_exists( $key, $user_listing ) ) {
3299
					$name         = $postobj->labels->name;
3300 2
					$listing_link = geodir_getlink( $author_link, array( 'stype' => $key ), false );
3301
3302
					$selected = '';
3303 View Code Duplication
					if ( ! isset( $_REQUEST['list'] ) && isset( $_REQUEST['geodir_dashbord'] ) && isset( $_REQUEST['stype'] ) && $_REQUEST['stype'] == $key ) {
3304 2
						$selected = 'selected="selected"';
3305
					}
3306
3307
					/**
3308
					 * Filter my listing link.
3309 2
					 *
3310
					 * @since 1.0.0
3311
					 *
3312 2
					 * @param string $listing_link My listing link.
3313
					 * @param string $key          My listing array key.
3314 2
					 * @param int $current_user    ->ID Current user ID.
3315
					 */
3316
					$listing_link = apply_filters( 'geodir_dashboard_link_my_listing', $listing_link, $key, $current_user->ID );
3317
3318
					$listing_links .= '<option ' . $selected . ' value="' . $listing_link . '">' . __( ucfirst( $name ), 'geodirectory' ) . '</option>';
3319
				}
3320
			}
3321
3322 View Code Duplication
			if ( $listing_links != '' ) {
3323
				?>
3324
				<li>
3325
					<select id="geodir_my_listings" class="chosen_select" onchange="window.location.href=this.value"
3326
					        option-autoredirect="1" name="geodir_my_listings" option-ajaxchosen="false"
3327
					        data-placeholder="<?php echo esc_attr( __( 'My Listings', 'geodirectory' ) ); ?>">
3328
						<option value="" disabled="disabled" selected="selected"
3329
						        style='display:none;'><?php echo esc_attr( __( 'My Listings', 'geodirectory' ) ); ?></option>
3330
						<?php echo $listing_links; ?>
3331
					</select>
3332 2
				</li>
3333
				<?php
3334 2
			}
3335
		}
3336 2
3337
		$dashboard_link = ob_get_clean();
3338
		/**
3339
		 * Filter dashboard links HTML.
3340
		 *
3341
		 * @since 1.0.0
3342
		 *
3343
		 * @param string $dashboard_link Dashboard links HTML.
3344
		 */
3345
		echo apply_filters( 'geodir_dashboard_links', $dashboard_link );
3346
		echo '</ul>';
3347
3348
		/**
3349
		 * Called after the loginwidget form for logged in users.
3350
		 *
3351
		 * @since 1.6.6
3352
		 */
3353
		do_action( 'geodir_after_loginwidget_form_logged_in' );
3354
3355
3356
	} else {
3357
		?>
3358
		<?php
3359
		/**
3360 2
		 * Filter signup form action link.
3361 2
		 *
3362 2
		 * @since 1.0.0
3363 2
		 */
3364 2
		?>
3365
		<form name="loginform" class="loginform1"
3366
		      action="<?php echo geodir_login_url(); ?>"
3367
		      method="post">
3368
			<div class="geodir_form_row"><input placeholder="<?php _e( 'Email', 'geodirectory' ); ?>" name="log"
3369
			                                    type="text" class="textfield user_login1"/> <span
3370
					class="user_loginInfo"></span></div>
3371
			<div class="geodir_form_row"><input placeholder="<?php _e( 'Password', 'geodirectory' ); ?>"
3372
			                                    name="pwd" type="password"
3373 2
			                                    class="textfield user_pass1 input-text"/><span
3374 2
					class="user_passInfo"></span></div>
3375
3376
			<input type="hidden" name="redirect_to" value="<?php echo htmlspecialchars( geodir_curPageURL() ); ?>"/>
3377
			<input type="hidden" name="testcookie" value="1"/>
3378
3379
				<?php do_action( 'login_form' ); ?>
3380
3381
			<div class="geodir_form_row clearfix"><input type="submit" name="submit"
3382
			                                             value="<?php echo SIGN_IN_BUTTON; ?>" class="b_signin"/>
3383
3384 2
				<p class="geodir-new-forgot-link">
3385
					<?php
3386 2
					/**
3387 2
					 * Filter signup page register form link.
3388 2
					 *
3389 2
					 * @since 1.0.0
3390
					 */
3391
					?>
3392
					<a href="<?php echo geodir_login_url( array( 'signup' => true ) ); ?>"
3393
					   class="goedir-newuser-link"><?php echo NEW_USER_TEXT; ?></a>
3394
3395
					<?php
3396 2
					/**
3397
					 * Filter signup page forgot password form link.
3398 2
					 *
3399
					 * @since 1.0.0
3400 2
					 */
3401 2
					?>
3402 2
					<a href="<?php echo geodir_login_url( array( 'forgot' => true ) ); ?>"
3403 2
					   class="goedir-forgot-link"><?php echo FORGOT_PW_TEXT; ?></a></p></div>
3404 2
		</form>
3405
		<?php
3406
		/**
3407
		 * Called after the loginwidget form for logged out users.
3408 2
		 *
3409 2
		 * @since 1.6.6
3410
		 */
3411 2
		do_action( 'geodir_after_loginwidget_form_logged_out' );
3412
	}
3413
3414
	echo $after_widget;
3415
}
3416
3417
3418
/**
3419
 * Generates popular postview HTML.
3420
 *
3421
 * @since   1.0.0
3422
 * @since   1.5.1 View all link fixed for location filter disabled.
3423
 * @package GeoDirectory
3424
 * @global object $post                    The current post object.
3425
 * @global string $gridview_columns_widget The girdview style of the listings for widget.
3426
 * @global bool $geodir_is_widget_listing  Is this a widget listing?. Default: false.
3427
 * @global object $gd_session              GeoDirectory Session object.
3428
 *
3429
 * @param array|string $args               Display arguments including before_title, after_title, before_widget, and
3430
 *                                         after_widget.
3431
 * @param array|string $instance           The settings for the particular instance of the widget.
3432 2
 */
3433
function geodir_popular_postview_output( $args = '', $instance = '' ) {
3434 2
	global $gd_session;
3435
3436 2
	// prints the widget
3437
	extract( $args, EXTR_SKIP );
3438
3439
	echo $before_widget;
3440
3441
	/** This filter is documented in geodirectory_widgets.php */
3442
	$title = empty( $instance['title'] ) ? geodir_ucwords( $instance['category_title'] ) : apply_filters( 'widget_title', __( $instance['title'], 'geodirectory' ) );
3443
	/**
3444
	 * Filter the widget post type.
3445
	 *
3446
	 * @since 1.0.0
3447 2
	 *
3448
	 * @param string $instance ['post_type'] Post type of listing.
3449 2
	 */
3450
	$post_type = empty( $instance['post_type'] ) ? 'gd_place' : apply_filters( 'widget_post_type', $instance['post_type'] );
3451 2
	/**
3452
	 * Filter the widget's term.
3453
	 *
3454
	 * @since 1.0.0
3455
	 *
3456
	 * @param string $instance ['category'] Filter by term. Can be any valid term.
3457
	 */
3458
	$category = empty( $instance['category'] ) ? '0' : apply_filters( 'widget_category', $instance['category'] );
3459
	/**
3460
	 * Filter the widget listings limit.
3461
	 *
3462
	 * @since 1.0.0
3463
	 *
3464
	 * @param string $instance ['post_number'] Number of listings to display.
3465
	 */
3466
	$post_number = empty( $instance['post_number'] ) ? '5' : apply_filters( 'widget_post_number', $instance['post_number'] );
3467
	/**
3468
	 * Filter widget's "layout" type.
3469
	 *
3470
	 * @since 1.0.0
3471
	 *
3472
	 * @param string $instance ['layout'] Widget layout type.
3473
	 */
3474
	$layout = empty( $instance['layout'] ) ? 'gridview_onehalf' : apply_filters( 'widget_layout', $instance['layout'] );
3475 8
	/**
3476 8
	 * Filter widget's "add_location_filter" value.
3477
	 *
3478
	 * @since 1.0.0
3479
	 *
3480 8
	 * @param string|bool $instance ['add_location_filter'] Do you want to add location filter? Can be 1 or 0.
3481
	 */
3482 8
	$add_location_filter = empty( $instance['add_location_filter'] ) ? '0' : apply_filters( 'widget_add_location_filter', $instance['add_location_filter'] );
3483 7
	/**
3484 7
	 * Filter widget's listing width.
3485 7
	 *
3486 7
	 * @since 1.0.0
3487 7
	 *
3488 7
	 * @param string $instance ['listing_width'] Listing width.
3489
	 */
3490 7
	$listing_width = empty( $instance['listing_width'] ) ? '' : apply_filters( 'widget_listing_width', $instance['listing_width'] );
3491 2
	/**
3492 2
	 * Filter widget's "list_sort" type.
3493 2
	 *
3494 2
	 * @since 1.0.0
3495 2
	 *
3496 2
	 * @param string $instance ['list_sort'] Listing sort by type.
3497
	 */
3498 7
	$list_sort             = empty( $instance['list_sort'] ) ? 'latest' : apply_filters( 'widget_list_sort', $instance['list_sort'] );
3499
	$use_viewing_post_type = ! empty( $instance['use_viewing_post_type'] ) ? true : false;
3500 7
3501 7
	// set post type to current viewing post type
3502 View Code Duplication
	if ( $use_viewing_post_type ) {
3503 7
		$current_post_type = geodir_get_current_posttype();
3504
		if ( $current_post_type != '' && $current_post_type != $post_type ) {
3505
			$post_type = $current_post_type;
3506
			$category  = array(); // old post type category will not work for current changed post type
3507 7
		}
3508
	}
3509
	// replace widget title dynamically
3510
	$posttype_plural_label   = __( get_post_type_plural_label( $post_type ), 'geodirectory' );
3511
	$posttype_singular_label = __( get_post_type_singular_label( $post_type ), 'geodirectory' );
3512
3513
	$title = str_replace( "%posttype_plural_label%", $posttype_plural_label, $title );
3514
	$title = str_replace( "%posttype_singular_label%", $posttype_singular_label, $title );
3515
3516 7 View Code Duplication
	if ( isset( $instance['character_count'] ) ) {
3517
		/**
3518
		 * Filter the widget's excerpt character count.
3519
		 *
3520
		 * @since 1.0.0
3521
		 *
3522
		 * @param int $instance ['character_count'] Excerpt character count.
3523
		 */
3524
		$character_count = apply_filters( 'widget_list_character_count', $instance['character_count'] );
3525
	} else {
3526
		$character_count = '';
3527
	}
3528
3529
	if ( empty( $title ) || $title == 'All' ) {
3530
		$title .= ' ' . __( get_post_type_plural_label( $post_type ), 'geodirectory' );
3531
	}
3532
3533
	$location_url = array();
3534
	$city         = get_query_var( 'gd_city' );
3535
	if ( ! empty( $city ) ) {
3536
		$country = get_query_var( 'gd_country' );
3537
		$region  = get_query_var( 'gd_region' );
3538
3539
		$geodir_show_location_url = get_option( 'geodir_show_location_url' );
3540
3541
		if ( $geodir_show_location_url == 'all' ) {
3542
			if ( $country != '' ) {
3543
				$location_url[] = $country;
3544 7
			}
3545
3546 7
			if ( $region != '' ) {
3547 7
				$location_url[] = $region;
3548
			}
3549 1
		} else if ( $geodir_show_location_url == 'country_city' ) {
3550
			if ( $country != '' ) {
3551
				$location_url[] = $country;
3552
			}
3553
		} else if ( $geodir_show_location_url == 'region_city' ) {
3554
			if ( $region != '' ) {
3555
				$location_url[] = $region;
3556
			}
3557
		}
3558
3559
		$location_url[] = $city;
3560
	}
3561
3562 8
	$location_url  = implode( '/', $location_url );
3563
	$skip_location = false;
3564
	if ( ! $add_location_filter && $gd_session->get( 'gd_multi_location' ) ) {
3565
		$skip_location = true;
3566 8
		$gd_session->un_set( 'gd_multi_location' );
3567
	}
3568
3569
	if ( get_option( 'permalink_structure' ) ) {
3570 8
		$viewall_url = get_post_type_archive_link( $post_type );
3571 8
	} else {
3572 8
		$viewall_url = get_post_type_archive_link( $post_type );
3573 2
	}
3574
3575
	if ( ! empty( $category ) && $category[0] != '0' ) {
3576 6
		global $geodir_add_location_url;
3577
3578
		$geodir_add_location_url = '0';
3579
3580 6
		if ( $add_location_filter != '0' ) {
3581 6
			$geodir_add_location_url = '1';
3582 6
		}
3583 6
3584
		$viewall_url = get_term_link( (int) $category[0], $post_type . 'category' );
3585 6
3586 5
		$geodir_add_location_url = null;
3587 5
	}
3588
	if ( $skip_location ) {
3589 6
		$gd_session->set( 'gd_multi_location', 1 );
3590
	}
3591
3592
	if ( is_wp_error( $viewall_url ) ) {
3593 4
		$viewall_url = '';
3594 4
	}
3595
3596
	$query_args = array(
3597
		'posts_per_page' => $post_number,
3598
		'is_geodir_loop' => true,
3599
		'gd_location'    => $add_location_filter ? true : false,
3600
		'post_type'      => $post_type,
3601
		'order_by'       => $list_sort
3602
	);
3603
3604
	if ( $character_count ) {
3605
		$query_args['excerpt_length'] = $character_count;
3606
	}
3607
3608
	if ( ! empty( $instance['show_featured_only'] ) ) {
3609
		$query_args['show_featured_only'] = 1;
3610
	}
3611
3612
	if ( ! empty( $instance['show_special_only'] ) ) {
3613
		$query_args['show_special_only'] = 1;
3614
	}
3615
3616 View Code Duplication
	if ( ! empty( $instance['with_pics_only'] ) ) {
3617
		$query_args['with_pics_only']      = 0;
3618
		$query_args['featured_image_only'] = 1;
3619
	}
3620
3621
	if ( ! empty( $instance['with_videos_only'] ) ) {
3622
		$query_args['with_videos_only'] = 1;
3623
	}
3624
	$with_no_results = ! empty( $instance['without_no_results'] ) ? false : true;
3625
3626 View Code Duplication
	if ( ! empty( $category ) && $category[0] != '0' ) {
3627
		$category_taxonomy = geodir_get_taxonomies( $post_type );
3628
3629
		######### WPML #########
3630
		if ( function_exists( 'icl_object_id' ) ) {
3631
			$category = gd_lang_object_ids( $category, $category_taxonomy[0] );
3632 4
		}
3633 4
		######### WPML #########
3634
3635
		$tax_query = array(
3636
			'taxonomy' => $category_taxonomy[0],
3637
			'field'    => 'id',
3638
			'terms'    => $category
3639
		);
3640
3641
		$query_args['tax_query'] = array( $tax_query );
3642
	}
3643
3644
	global $gridview_columns_widget, $geodir_is_widget_listing;
3645
3646 1
	$widget_listings = geodir_get_widget_listings( $query_args );
3647 1
3648
	if ( ! empty( $widget_listings ) || $with_no_results ) {
3649
		?>
3650
		<div class="geodir_locations geodir_location_listing">
3651
3652
			<?php
3653
			/**
3654
			 * Called before the div containing the title and view all link in popular post view widget.
3655
			 *
3656
			 * @since 1.0.0
3657
			 */
3658
			do_action( 'geodir_before_view_all_link_in_widget' ); ?>
3659
			<div class="geodir_list_heading clearfix">
3660
				<?php echo $before_title . $title . $after_title; ?>
3661 5
				<a href="<?php echo $viewall_url; ?>"
3662 4
				   class="geodir-viewall"><?php _e( 'View all', 'geodirectory' ); ?></a>
3663
			</div>
3664 1
			<?php
3665 1
			/**
3666
			 * Called after the div containing the title and view all link in popular post view widget.
3667
			 *
3668
			 * @since 1.0.0
3669
			 */
3670
			do_action( 'geodir_after_view_all_link_in_widget' ); ?>
3671
			<?php
3672 View Code Duplication
			if ( strstr( $layout, 'gridview' ) ) {
3673
				$listing_view_exp        = explode( '_', $layout );
3674
				$gridview_columns_widget = $layout;
3675
				$layout                  = $listing_view_exp[0];
3676
			} else {
3677
				$gridview_columns_widget = '';
3678
			}
3679
3680
			/**
3681
			 * Filter the widget listing listview template path.
3682
			 *
3683
			 * @since 1.0.0
3684
			 */
3685
			$template = apply_filters( "geodir_template_part-widget-listing-listview", geodir_locate_template( 'widget-listing-listview' ) );
3686
			if ( ! isset( $character_count ) ) {
3687
				/**
3688
				 * Filter the widget's excerpt character count.
3689
				 *
3690
				 * @since 1.0.0
3691
				 *
3692
				 * @param int $instance ['character_count'] Excerpt character count.
3693
				 */
3694
				$character_count = $character_count == '' ? 50 : apply_filters( 'widget_character_count', $character_count );
3695
			}
3696
3697 4
			global $post, $map_jason, $map_canvas_arr;
3698
3699
			$current_post             = $post;
3700
			$current_map_jason        = $map_jason;
3701
			$current_map_canvas_arr   = $map_canvas_arr;
3702
			$geodir_is_widget_listing = true;
3703
3704
			/**
3705
			 * Includes related listing listview template.
3706
			 *
3707
			 * @since 1.0.0
3708
			 */
3709
			include( $template );
3710
3711 1
			$geodir_is_widget_listing = false;
3712
3713
			$GLOBALS['post'] = $current_post;
3714
			if ( ! empty( $current_post ) ) {
3715
				setup_postdata( $current_post );
3716
			}
3717
			$map_jason      = $current_map_jason;
3718
			$map_canvas_arr = $current_map_canvas_arr;
3719
			?>
3720
		</div>
3721
		<?php
3722
	}
3723
	echo $after_widget;
3724
3725
}
3726
3727
3728
/*-----------------------------------------------------------------------------------*/
3729
/*  Review count functions
3730
/*-----------------------------------------------------------------------------------*/
3731
/**
3732
 * Count reviews by term ID.
3733
 *
3734
 * @since   1.0.0
3735
 * @since   1.5.1 Added filter to change SQL.
3736
 * @package GeoDirectory
3737
 * @global object $wpdb          WordPress Database object.
3738
 * @global string $plugin_prefix Geodirectory plugin table prefix.
3739
 *
3740
 * @param int $term_id           The term ID.
3741
 * @param int $taxonomy          The taxonomy Id.
3742
 * @param string $post_type      The post type.
3743
 *
3744
 * @return int Reviews count.
3745
 */
3746
function geodir_count_reviews_by_term_id( $term_id, $taxonomy, $post_type ) {
3747
	global $wpdb, $plugin_prefix;
3748
3749
	$detail_table = $plugin_prefix . $post_type . '_detail';
3750
3751
	$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 . ")";
3752
3753
	/**
3754
	 * Filter count review sql query.
3755
	 *
3756
	 * @since 1.5.1
3757
	 *
3758
	 * @param string $sql       Database sql query..
3759
	 * @param int $term_id      The term ID.
3760
	 * @param int $taxonomy     The taxonomy Id.
3761
	 * @param string $post_type The post type.
3762
	 */
3763
	$sql = apply_filters( 'geodir_count_reviews_by_term_sql', $sql, $term_id, $taxonomy, $post_type );
3764
3765
	$count = $wpdb->get_var( $sql );
3766
3767
	return $count;
3768
}
3769
3770
/**
3771 1
 * Count reviews by terms.
3772 1
 *
3773 1
 * @since   1.0.0
3774 1
 * @since   1.6.1 Fixed add listing page load time.
3775 1
 * @package GeoDirectory
3776 1
 *
3777
 * @global object $gd_session GeoDirectory Session object.
3778 1
 *
3779
 * @param bool $force_update  Force update option value?. Default.false.
3780 1
 *
3781 1
 * @return array Term array data.
3782
 */
3783 1
function geodir_count_reviews_by_terms( $force_update = false, $post_ID = 0 ) {
3784 1
	/**
3785
	 * Filter review count option data.
3786 1
	 *
3787
	 * @since 1.0.0
3788
	 * @since 1.6.1 Added $post_ID param.
3789
	 *
3790
	 * @param bool $force_update Force update option value?. Default.false.
3791
	 * @param int $post_ID       The post id to update if any.
3792
	 */
3793
	$option_data = apply_filters( 'geodir_count_reviews_by_terms_before', '', $force_update, $post_ID );
3794
	if ( ! empty( $option_data ) ) {
3795 1
		return $option_data;
3796
	}
3797 1
3798
	$option_data = get_option( 'geodir_global_review_count' );
3799 1
3800 1
	if ( ! $option_data || $force_update ) {
3801 1
		if ( (int) $post_ID > 0 ) { // Update reviews count for specific post categories only.
3802 1
			global $gd_session;
3803 1
			$term_array = (array) $option_data;
3804 1
			$post_type  = get_post_type( $post_ID );
3805 1
			$taxonomy   = $post_type . 'category';
3806 1
			$terms      = wp_get_object_terms( $post_ID, $taxonomy, array( 'fields' => 'ids' ) );
3807 1
3808 1 View Code Duplication
			if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
3809
				foreach ( $terms as $term_id ) {
3810 1
					$count                  = geodir_count_reviews_by_term_id( $term_id, $taxonomy, $post_type );
3811 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...
3812 1
					$term_array[ $term_id ] = $count;
3813
				}
3814 1
			}
3815
3816 1
			$session_listing = $gd_session->get( 'listing' );
3817 1
3818 1
			$terms = array();
3819 1
			if ( isset( $_POST['post_category'][ $taxonomy ] ) ) {
3820 1
				$terms = (array) $_POST['post_category'][ $taxonomy ];
3821 1
			} else if ( ! empty( $session_listing ) && isset( $session_listing['post_category'][ $taxonomy ] ) ) {
3822 1
				$terms = (array) $session_listing['post_category'][ $taxonomy ];
3823 1
			}
3824
3825 1 View Code Duplication
			if ( ! empty( $terms ) ) {
3826
				foreach ( $terms as $term_id ) {
3827 1
					if ( $term_id > 0 ) {
3828 1
						$count                  = geodir_count_reviews_by_term_id( $term_id, $taxonomy, $post_type );
3829
						$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...
3830
						$term_array[ $term_id ] = $count;
3831
					}
3832
				}
3833
			}
3834
		} else { // Update reviews count for all post categories.
3835
			$term_array = array();
3836
			$post_types = geodir_get_posttypes();
3837
			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...
3838
3839
				$taxonomy = geodir_get_taxonomies( $post_type );
3840
				$taxonomy = $taxonomy[0];
3841
3842
				$args = array(
3843
					'hide_empty' => false
3844
				);
3845
3846 1
				$terms = get_terms( $taxonomy, $args );
3847
3848
				foreach ( $terms as $term ) {
3849 1
					$count    = geodir_count_reviews_by_term_id( $term->term_id, $taxonomy, $post_type );
3850 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...
3851
					/*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...
3852 1
                        foreach ( $children as $child_id ) {
3853 1
                            $child_count = geodir_count_reviews_by_term_id($child_id, $taxonomy, $post_type);
3854 1
                            $count = $count + $child_count;
3855 1
                        }
3856
                    }*/
3857 1
					$term_array[ $term->term_id ] = $count;
3858 1
				}
3859
			}
3860 1
		}
3861 1
3862
		update_option( 'geodir_global_review_count', $term_array );
3863 1
		//clear cache
3864 1
		wp_cache_delete( 'geodir_global_review_count' );
3865
3866 1
		return $term_array;
3867 1
	} else {
3868
		return $option_data;
3869 1
	}
3870 1
}
3871
3872 1
/**
3873 1
 * Force update review count.
3874
 *
3875 1
 * @since   1.0.0
3876 1
 * @since   1.6.1 Fixed add listing page load time.
3877 1
 * @package GeoDirectory
3878 1
 * @return bool
3879 1
 */
3880 1
function geodir_term_review_count_force_update( $new_status, $old_status = '', $post = '' ) {
3881 1
	if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'geodir_import_export' ) {
3882 1
		return; // do not run if importing listings
3883 1
	}
3884 1
3885
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
3886
		return;
3887 1
	}
3888 1
3889
	$post_ID = 0;
3890 1
	if ( ! empty( $post ) ) {
3891
		if ( isset( $post->post_type ) && strpos( $post->post_type, 'gd_' ) !== 0 ) {
3892
			return;
3893
		}
3894
3895
		if ( $new_status == 'auto-draft' && $old_status == 'new' ) {
3896
			return;
3897
		}
3898
3899
		if ( ! empty( $post->ID ) ) {
3900
			$post_ID = $post->ID;
3901
		}
3902
	}
3903
3904 1
	if ( $new_status != $old_status ) {
3905
		geodir_count_reviews_by_terms( true, $post_ID );
3906
	}
3907
3908
	return true;
3909
}
3910
3911
function geodir_term_review_count_force_update_single_post( $post_id ) {
3912
	geodir_count_reviews_by_terms( true, $post_id );
3913
}
3914
3915
/*-----------------------------------------------------------------------------------*/
3916
/*  Term count functions
3917
/*-----------------------------------------------------------------------------------*/
3918
/**
3919
 * Count posts by term.
3920
 *
3921
 * @since   1.0.0
3922 1
 * @package GeoDirectory
3923
 *
3924 1
 * @param array $data  Count data array.
3925
 * @param object $term The term object.
3926
 *
3927
 * @return int Post count.
3928
 */
3929
function geodir_count_posts_by_term( $data, $term ) {
3930
3931
	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...
3932
		if ( isset( $data[ $term->term_id ] ) ) {
3933
			return $data[ $term->term_id ];
3934
		} else {
3935
			return 0;
3936
		}
3937
	} else {
3938
		return $term->count;
3939
	}
3940
}
3941
3942
/**
3943
 * Sort terms object by post count.
3944
 *
3945
 * @since   1.0.0
3946
 * @package GeoDirectory
3947
 * param array $terms An array of term objects.
3948
 * @return array Sorted terms array.
3949
 */
3950
function geodir_sort_terms_by_count( $terms ) {
3951
	usort( $terms, "geodir_sort_by_count_obj" );
3952
3953
	return $terms;
3954
}
3955
3956
/**
3957
 * Sort terms object by review count.
3958
 *
3959
 * @since   1.0.0
3960
 * @package GeoDirectory
3961
 *
3962
 * @param array $terms An array of term objects.
3963
 *
3964
 * @return array Sorted terms array.
3965
 */
3966
function geodir_sort_terms_by_review_count( $terms ) {
3967
	usort( $terms, "geodir_sort_by_review_count_obj" );
3968
3969
	return $terms;
3970
}
3971
3972
/**
3973
 * Sort terms either by post count or review count.
3974
 *
3975
 * @since   1.0.0
3976
 * @package GeoDirectory
3977
 *
3978
 * @param array $terms An array of term objects.
3979
 * @param string $sort The sort type. Can be count (Post Count) or review_count. Default. count.
3980
 *
3981
 * @return array Sorted terms array.
3982
 */
3983
function geodir_sort_terms( $terms, $sort = 'count' ) {
3984
	if ( $sort == 'count' ) {
3985
		return geodir_sort_terms_by_count( $terms );
3986
	}
3987
	if ( $sort == 'review_count' ) {
3988
		return geodir_sort_terms_by_review_count( $terms );
3989
	}
3990
}
3991
3992
/*-----------------------------------------------------------------------------------*/
3993
/*  Utils
3994
/*-----------------------------------------------------------------------------------*/
3995
/**
3996
 * Compares post count from array for sorting.
3997
 *
3998
 * @since   1.0.0
3999
 * @package GeoDirectory
4000
 *
4001
 * @param array $a The left side array to compare.
4002
 * @param array $b The right side array to compare.
4003
 *
4004
 * @return bool
4005
 */
4006
function geodir_sort_by_count( $a, $b ) {
4007
	return $a['count'] < $b['count'];
4008
}
4009
4010
/**
4011
 * Compares post count from object for sorting.
4012 9
 *
4013
 * @since   1.0.0
4014 9
 * @package GeoDirectory
4015
 *
4016 9
 * @param object $a The left side object to compare.
4017 2
 * @param object $b The right side object to compare.
4018 2
 *
4019 2
 * @return bool
4020
 */
4021
function geodir_sort_by_count_obj( $a, $b ) {
4022
	return $a->count < $b->count;
4023
}
4024 2
4025
/**
4026 9
 * Compares review count from object for sorting.
4027
 *
4028
 * @since   1.0.0
4029
 * @package GeoDirectory
4030
 *
4031
 * @param object $a The left side object to compare.
4032
 * @param object $b The right side object to compare.
4033
 *
4034
 * @return bool
4035
 */
4036
function geodir_sort_by_review_count_obj( $a, $b ) {
4037
	return $a->review_count < $b->review_count;
4038
}
4039
4040
/**
4041
 * Load geodirectory plugin textdomain.
4042
 *
4043
 * @since   1.4.2
4044
 * @package GeoDirectory
4045
 */
4046
function geodir_load_textdomain() {
4047
	/**
4048
	 * Filter the plugin locale.
4049
	 *
4050
	 * @since   1.4.2
4051
	 * @package GeoDirectory
4052
	 */
4053
	$locale = apply_filters( 'plugin_locale', get_locale(), 'geodirectory' );
4054
4055
	load_textdomain( 'geodirectory', WP_LANG_DIR . '/' . 'geodirectory' . '/' . 'geodirectory' . '-' . $locale . '.mo' );
4056
	load_plugin_textdomain( 'geodirectory', false, plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/geodirectory-languages' );
4057
4058
	/**
4059
	 * Define language constants.
4060
	 *
4061
	 * @since 1.0.0
4062
	 */
4063
	require_once( geodir_plugin_path() . '/language.php' );
4064
4065
	$language_file = geodir_plugin_path() . '/db-language.php';
4066
4067
	// Load language string file if not created yet
4068
	if ( ! file_exists( $language_file ) ) {
4069
		geodirectory_load_db_language();
4070
	}
4071
4072
	if ( file_exists( $language_file ) ) {
4073
		/**
4074
		 * Language strings from database.
4075
		 *
4076
		 * @since 1.4.2
4077
		 */
4078
		try {
4079
			require_once( $language_file );
4080
		} catch ( Exception $e ) {
4081
			error_log( 'Language Error: ' . $e->getMessage() );
4082
		}
4083
	}
4084
}
4085
4086
/**
4087
 * Load language strings in to file to translate via po editor
4088
 *
4089
 * @since   1.4.2
4090
 * @package GeoDirectory
4091
 *
4092
 * @global null|object $wp_filesystem WP_Filesystem object.
4093
 *
4094
 * @return bool True if file created otherwise false
4095
 */
4096
function geodirectory_load_db_language() {
4097
	global $wp_filesystem;
4098
	if ( empty( $wp_filesystem ) ) {
4099
		require_once( ABSPATH . '/wp-admin/includes/file.php' );
4100
		WP_Filesystem();
4101
		global $wp_filesystem;
4102
	}
4103
4104
	$language_file = geodir_plugin_path() . '/db-language.php';
4105
4106
	if ( is_file( $language_file ) && ! is_writable( $language_file ) ) {
4107
		return false;
4108
	} // Not possible to create.
4109
4110
	if ( ! is_file( $language_file ) && ! is_writable( dirname( $language_file ) ) ) {
4111
		return false;
4112
	} // Not possible to create.
4113
4114
	$contents_strings = array();
4115
4116
	/**
4117
	 * Filter the language string from database to translate via po editor
4118
	 *
4119
	 * @since 1.4.2
4120
	 *
4121
	 * @param array $contents_strings Array of strings.
4122
	 */
4123
	$contents_strings = apply_filters( 'geodir_load_db_language', $contents_strings );
4124
4125
	$contents_strings = array_unique( $contents_strings );
4126
4127
	$contents_head   = array();
4128
	$contents_head[] = "<?php";
4129
	$contents_head[] = "/**";
4130
	$contents_head[] = " * Translate language string stored in database. Ex: Custom Fields";
4131
	$contents_head[] = " *";
4132
	$contents_head[] = " * @package GeoDirectory";
4133
	$contents_head[] = " * @since 1.4.2";
4134
	$contents_head[] = " */";
4135
	$contents_head[] = "";
4136
	$contents_head[] = "// Language keys";
4137
4138
	$contents_foot   = array();
4139
	$contents_foot[] = "";
4140
	$contents_foot[] = "";
4141
4142
	$contents = implode( PHP_EOL, $contents_head );
4143
4144
	if ( ! empty( $contents_strings ) ) {
4145
		foreach ( $contents_strings as $string ) {
4146
			if ( is_scalar( $string ) && $string != '' ) {
4147
				$string = str_replace( "'", "\'", $string );
4148
				$contents .= PHP_EOL . "__('" . $string . "', 'geodirectory');";
4149
			}
4150
		}
4151
	}
4152
4153
	$contents .= implode( PHP_EOL, $contents_foot );
4154
4155
	if ( $wp_filesystem->put_contents( $language_file, $contents, FS_CHMOD_FILE ) ) {
4156
		return false;
4157
	} // Failure; could not write file.
4158
4159
	return true;
4160
}
4161
4162
/**
4163
 * Get the custom fields texts for translation
4164
 *
4165
 * @since   1.4.2
4166
 * @since   1.5.7 Option values are translatable via db translation.
4167
 * @package GeoDirectory
4168
 *
4169
 * @global object $wpdb             WordPress database abstraction object.
4170
 *
4171
 * @param  array $translation_texts Array of text strings.
4172
 *
4173
 * @return array Translation texts.
4174
 */
4175
function geodir_load_custom_field_translation( $translation_texts = array() ) {
4176
	global $wpdb;
4177
4178
	// Custom fields table
4179
	$sql  = "SELECT admin_title, admin_desc, site_title, clabels, required_msg, default_value, option_values FROM " . GEODIR_CUSTOM_FIELDS_TABLE;
4180
	$rows = $wpdb->get_results( $sql );
4181
4182
	if ( ! empty( $rows ) ) {
4183
		foreach ( $rows as $row ) {
4184
			if ( ! empty( $row->admin_title ) ) {
4185
				$translation_texts[] = stripslashes_deep( $row->admin_title );
4186
			}
4187
4188
			if ( ! empty( $row->admin_desc ) ) {
4189
				$translation_texts[] = stripslashes_deep( $row->admin_desc );
4190
			}
4191
4192
			if ( ! empty( $row->site_title ) ) {
4193
				$translation_texts[] = stripslashes_deep( $row->site_title );
4194
			}
4195
4196
			if ( ! empty( $row->clabels ) ) {
4197
				$translation_texts[] = stripslashes_deep( $row->clabels );
4198
			}
4199
4200
			if ( ! empty( $row->required_msg ) ) {
4201
				$translation_texts[] = stripslashes_deep( $row->required_msg );
4202
			}
4203
4204
			if ( ! empty( $row->default_value ) ) {
4205
				$translation_texts[] = stripslashes_deep( $row->default_value );
4206
			}
4207 7
4208
			if ( ! empty( $row->option_values ) ) {
4209 7
				$option_values = geodir_string_values_to_options( stripslashes_deep( $row->option_values ) );
4210 3
4211
				if ( ! empty( $option_values ) ) {
4212
					foreach ( $option_values as $option_value ) {
4213 5
						if ( ! empty( $option_value['label'] ) ) {
4214
							$translation_texts[] = $option_value['label'];
4215
						}
4216
					}
4217
				}
4218
			}
4219
		}
4220
	}
4221 2
4222 2
	// Custom sorting fields table
4223
	$sql  = "SELECT site_title, asc_title, desc_title FROM " . GEODIR_CUSTOM_SORT_FIELDS_TABLE;
4224 5
	$rows = $wpdb->get_results( $sql );
4225 3
4226 3 View Code Duplication
	if ( ! empty( $rows ) ) {
4227
		foreach ( $rows as $row ) {
4228 5
			if ( ! empty( $row->site_title ) ) {
4229 5
				$translation_texts[] = stripslashes_deep( $row->site_title );
4230 5
			}
4231
4232 5
			if ( ! empty( $row->asc_title ) ) {
4233
				$translation_texts[] = stripslashes_deep( $row->asc_title );
4234
			}
4235
4236 5
			if ( ! empty( $row->desc_title ) ) {
4237
				$translation_texts[] = stripslashes_deep( $row->desc_title );
4238
			}
4239
		}
4240 5
	}
4241 2
4242 5
	// Advance search filter fields table
4243 1
	if ( defined( 'GEODIR_ADVANCE_SEARCH_TABLE' ) ) {
4244 1
		$sql  = "SELECT field_site_name, front_search_title, field_desc FROM " . GEODIR_ADVANCE_SEARCH_TABLE;
4245 4
		$rows = $wpdb->get_results( $sql );
4246 1
4247 1 View Code Duplication
		if ( ! empty( $rows ) ) {
4248 2
			foreach ( $rows as $row ) {
4249
				if ( ! empty( $row->field_site_name ) ) {
4250
					$translation_texts[] = stripslashes_deep( $row->field_site_name );
4251 5
				}
4252 1
4253 1
				if ( ! empty( $row->front_search_title ) ) {
4254 1
					$translation_texts[] = stripslashes_deep( $row->front_search_title );
4255 1
				}
4256
4257 1
				if ( ! empty( $row->field_desc ) ) {
4258 1
					$translation_texts[] = stripslashes_deep( $row->field_desc );
4259
				}
4260 5
			}
4261 2
		}
4262 2
	}
4263 2
4264 2
	$translation_texts = ! empty( $translation_texts ) ? array_unique( $translation_texts ) : $translation_texts;
4265
4266 2
	return $translation_texts;
4267 2
}
4268
4269 5
/**
4270
 * Retrieve list of mime types and file extensions allowed for file upload.
4271
 *
4272
 * @since   1.4.7
4273
 * @package GeoDirectory
4274
 *
4275
 * @return array Array of mime types.
4276
 */
4277
function geodir_allowed_mime_types() {
4278
	/**
4279
	 * Filter the list of mime types and file extensions allowed for file upload.
4280
	 *
4281
	 * @since   1.4.7
4282
	 * @package GeoDirectory
4283
	 *
4284
	 * @param array $geodir_allowed_mime_types and file extensions.
4285
	 */
4286 5
	return apply_filters( 'geodir_allowed_mime_types', array(
4287
			'Image'       => array( // Image formats.
4288
				'jpg'  => 'image/jpeg',
4289
				'jpe'  => 'image/jpeg',
4290
				'jpeg' => 'image/jpeg',
4291
				'gif'  => 'image/gif',
4292
				'png'  => 'image/png',
4293
				'bmp'  => 'image/bmp',
4294
				'ico'  => 'image/x-icon',
4295
			),
4296
			'Video'       => array( // Video formats.
4297
				'asf'  => 'video/x-ms-asf',
4298
				'avi'  => 'video/avi',
4299
				'flv'  => 'video/x-flv',
4300
				'mkv'  => 'video/x-matroska',
4301
				'mp4'  => 'video/mp4',
4302
				'mpeg' => 'video/mpeg',
4303 5
				'mpg'  => 'video/mpeg',
4304
				'wmv'  => 'video/x-ms-wmv',
4305
				'3gp'  => 'video/3gpp',
4306
			),
4307
			'Audio'       => array( // Audio formats.
4308 5
				'ogg' => 'audio/ogg',
4309 5
				'mp3' => 'audio/mpeg',
4310 5
				'wav' => 'audio/wav',
4311
				'wma' => 'audio/x-ms-wma',
4312
			),
4313 5
			'Text'        => array( // Text formats.
4314 5
				'css'  => 'text/css',
4315
				'csv'  => 'text/csv',
4316
				'htm'  => 'text/html',
4317
				'html' => 'text/html',
4318
				'txt'  => 'text/plain',
4319
				'rtx'  => 'text/richtext',
4320
				'vtt'  => 'text/vtt',
4321
			),
4322
			'Application' => array( // Application formats.
4323
				'doc'  => 'application/msword',
4324
				'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
4325 5
				'exe'  => 'application/x-msdownload',
4326 5
				'js'   => 'application/javascript',
4327 5
				'odt'  => 'application/vnd.oasis.opendocument.text',
4328
				'pdf'  => 'application/pdf',
4329
				'pot'  => 'application/vnd.ms-powerpoint',
4330
				'ppt'  => 'application/vnd.ms-powerpoint',
4331
				'pptx' => 'application/vnd.ms-powerpoint',
4332 5
				'psd'  => 'application/octet-stream',
4333 5
				'rar'  => 'application/rar',
4334 5
				'rtf'  => 'application/rtf',
4335 5
				'swf'  => 'application/x-shockwave-flash',
4336
				'tar'  => 'application/x-tar',
4337 5
				'xls'  => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
4338
				'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
4339 5
				'zip'  => 'application/zip',
4340
			)
4341
		)
4342
	);
4343
}
4344
4345 5
/**
4346
 * Retrieve list of user display name for user id.
4347
 *
4348
 * @since 1.5.0
4349
 *
4350
 * @param  string $user_id The WP user id.
4351
 *
4352
 * @return string User display name.
4353
 */
4354
function geodir_get_client_name( $user_id ) {
4355 5
	$client_name = '';
4356
4357
	$user_data = get_userdata( $user_id );
4358
4359
	if ( ! empty( $user_data ) ) {
4360
		if ( isset( $user_data->display_name ) && trim( $user_data->display_name ) != '' ) {
4361
			$client_name = trim( $user_data->display_name );
4362
		} else if ( isset( $user_data->user_nicename ) && trim( $user_data->user_nicename ) != '' ) {
4363
			$client_name = trim( $user_data->user_nicename );
4364
		} else {
4365 5
			$client_name = trim( $user_data->user_login );
4366
		}
4367
	}
4368
4369
	return $client_name;
4370
}
4371
4372
4373
add_filter( 'wpseo_replacements', 'geodir_wpseo_replacements', 10, 1 );
4374
/*
4375
 * Add location variables to wpseo replacements.
4376
 *
4377 5
 * @since 1.5.4
4378
 */
4379
function geodir_wpseo_replacements( $vars ) {
4380
4381
	global $wp;
4382
	$title = '';
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...
4383
	// location variables
4384
	$gd_post_type   = geodir_get_current_posttype();
4385
	$location_array = geodir_get_current_location_terms( 'query_vars', $gd_post_type );
4386
	/**
4387
	 * Filter the title variables location variables array
4388
	 *
4389
	 * @since   1.5.5
4390
	 * @package GeoDirectory
4391
	 *
4392
	 * @param array $location_array The array of location variables.
4393
	 * @param array $vars           The page title variables.
4394
	 */
4395
	$location_array  = apply_filters( 'geodir_filter_title_variables_location_arr_seo', $location_array, $vars );
4396
	$location_titles = array();
4397 View Code Duplication
	if ( get_query_var( 'gd_country_full' ) ) {
4398
		if ( get_query_var( 'gd_country_full' ) ) {
4399
			$location_array['gd_country'] = get_query_var( 'gd_country_full' );
4400
		}
4401
		if ( get_query_var( 'gd_region_full' ) ) {
4402 5
			$location_array['gd_region'] = get_query_var( 'gd_region_full' );
4403 1
		}
4404 1
		if ( get_query_var( 'gd_city_full' ) ) {
4405
			$location_array['gd_city'] = get_query_var( 'gd_city_full' );
4406
		}
4407 1
	}
4408 1
	$location_single = '';
4409
	$gd_country      = ( isset( $wp->query_vars['gd_country'] ) && $wp->query_vars['gd_country'] != '' ) ? $wp->query_vars['gd_country'] : '';
4410 5
	$gd_region       = ( isset( $wp->query_vars['gd_region'] ) && $wp->query_vars['gd_region'] != '' ) ? $wp->query_vars['gd_region'] : '';
4411 1
	$gd_city         = ( isset( $wp->query_vars['gd_city'] ) && $wp->query_vars['gd_city'] != '' ) ? $wp->query_vars['gd_city'] : '';
4412 1
4413
	$gd_country_actual = $gd_region_actual = $gd_city_actual = '';
4414
4415 1 View Code Duplication
	if ( function_exists( 'get_actual_location_name' ) ) {
4416 1
		$gd_country_actual = $gd_country != '' ? get_actual_location_name( 'country', $gd_country, true ) : $gd_country;
4417
		$gd_region_actual  = $gd_region != '' ? get_actual_location_name( 'region', $gd_region ) : $gd_region;
4418 5
		$gd_city_actual    = $gd_city != '' ? get_actual_location_name( 'city', $gd_city ) : $gd_city;
4419 1
	}
4420
4421 View Code Duplication
	if ( $gd_city != '' ) {
4422 1
		if ( $gd_city_actual != '' ) {
4423 1
			$gd_city = $gd_city_actual;
4424
		} else {
4425 5
			$gd_city = preg_replace( '/-(\d+)$/', '', $gd_city );
4426
			$gd_city = preg_replace( '/[_-]/', ' ', $gd_city );
4427
			$gd_city = __( geodir_ucwords( $gd_city ), 'geodirectory' );
4428
		}
4429
		$location_single = $gd_city;
4430 5
4431 1
	} else if ( $gd_region != '' ) {
4432 1
		if ( $gd_region_actual != '' ) {
4433
			$gd_region = $gd_region_actual;
4434
		} else {
4435 1
			$gd_region = preg_replace( '/-(\d+)$/', '', $gd_region );
4436 1
			$gd_region = preg_replace( '/[_-]/', ' ', $gd_region );
4437
			$gd_region = __( geodir_ucwords( $gd_region ), 'geodirectory' );
4438 5
		}
4439 1
4440 1
		$location_single = $gd_region;
4441
	} else if ( $gd_country != '' ) {
4442
		if ( $gd_country_actual != '' ) {
4443 1
			$gd_country = $gd_country_actual;
4444 1
		} else {
4445
			$gd_country = preg_replace( '/-(\d+)$/', '', $gd_country );
4446 5
			$gd_country = preg_replace( '/[_-]/', ' ', $gd_country );
4447 1
			$gd_country = __( geodir_ucwords( $gd_country ), 'geodirectory' );
4448 1
		}
4449 1
4450
		$location_single = $gd_country;
4451 1
	}
4452 1
4453 1 View Code Duplication
	if ( ! empty( $location_array ) ) {
4454 1
4455 1
		$actual_location_name = function_exists( 'get_actual_location_name' ) ? true : false;
4456 1
		$location_array       = array_reverse( $location_array );
4457
4458 5
		foreach ( $location_array as $location_type => $location ) {
4459
			$gd_location_link_text = preg_replace( '/-(\d+)$/', '', $location );
4460
			$gd_location_link_text = preg_replace( '/[_-]/', ' ', $gd_location_link_text );
4461
4462 5
			$location_name = geodir_ucwords( $gd_location_link_text );
4463
			$location_name = __( $location_name, 'geodirectory' );
4464
4465
			if ( $actual_location_name ) {
4466 5
				$location_type = strpos( $location_type, 'gd_' ) === 0 ? substr( $location_type, 3 ) : $location_type;
4467
				$location_name = get_actual_location_name( $location_type, $location, true );
4468
			}
4469
4470
			$location_titles[] = $location_name;
4471 5
		}
4472 5
		if ( ! empty( $location_titles ) ) {
4473 5
			$location_titles = array_unique( $location_titles );
4474
		}
4475
	}
4476
4477
4478
	if ( ! empty( $location_titles ) ) {
4479
		$vars['%%location%%'] = implode( ", ", $location_titles );
4480
	}
4481
4482
4483
	if ( ! empty( $location_titles ) ) {
4484
		$vars['%%in_location%%'] = __( 'in ', 'geodirectory' ) . implode( ", ", $location_titles );
4485
	}
4486 5
4487
4488
	if ( $location_single ) {
4489
		$vars['%%in_location_single%%'] = __( 'in', 'geodirectory' ) . ' ' . $location_single;
4490
	}
4491
4492
4493
	if ( $location_single ) {
4494
		$vars['%%location_single%%'] = $location_single;
4495
	}
4496
4497
	/**
4498
	 * Filter the title variables after standard ones have been filtered for wpseo.
4499 1
	 *
4500
	 * @since   1.5.7
4501 1
	 * @package GeoDirectory
4502 1
	 *
4503 1
	 * @param string $vars          The title with variables.
4504 1
	 * @param array $location_array The array of location variables.
4505 1
	 */
4506
	return apply_filters( 'geodir_wpseo_replacements_vars', $vars, $location_array );
4507 1
}
4508 1
4509 1
4510 1
add_filter( 'geodir_seo_meta_title', 'geodir_filter_title_variables', 10, 3 );
4511 1
add_filter( 'geodir_seo_page_title', 'geodir_filter_title_variables', 10, 2 );
4512 1
add_filter( 'geodir_seo_meta_description_pre', 'geodir_filter_title_variables', 10, 3 );
4513 1
4514 1
/**
4515 1
 * Filter the title variables.
4516 1
 *
4517 1
 * %%date%%                        Replaced with the date of the post/page
4518 1
 * %%title%%                    Replaced with the title of the post/page
4519 1
 * %%sitename%%                    The site's name
4520 1
 * %%sitedesc%%                    The site's tagline / description
4521 1
 * %%excerpt%%                    Replaced with the post/page excerpt (or auto-generated if it does not exist)
4522 1
 * %%tag%%                        Replaced with the current tag/tags
4523 1
 * %%category%%                    Replaced with the post categories (comma separated)
4524 1
 * %%category_description%%        Replaced with the category description
4525 1
 * %%tag_description%%            Replaced with the tag description
4526 1
 * %%term_description%%            Replaced with the term description
4527 1
 * %%term_title%%                Replaced with the term name
4528 1
 * %%searchphrase%%                Replaced with the current search phrase
4529 1
 * %%sep%%                        The separator defined in your theme's wp_title() tag.
4530 1
 *
4531 1
 * ADVANCED
4532 1
 * %%pt_single%%                Replaced with the post type single label
4533 1
 * %%pt_plural%%                Replaced with the post type plural label
4534 1
 * %%modified%%                    Replaced with the post/page modified time
4535 1
 * %%id%%                        Replaced with the post/page ID
4536 1
 * %%name%%                        Replaced with the post/page author's 'nicename'
4537 1
 * %%userid%%                    Replaced with the post/page author's userid
4538 1
 * %%page%%                        Replaced with the current page number (i.e. page 2 of 4)
4539 1
 * %%pagetotal%%                Replaced with the current page total
4540 1
 * %%pagenumber%%                Replaced with the current page number
4541
 *
4542 1
 * @since   1.5.7
4543 1
 * @package GeoDirectory
4544 1
 *
4545
 * @global object $wp     WordPress object.
4546 1
 * @global object $post   The current post object.
4547
 *
4548
 * @param string $title   The title with variables.
4549
 * @param string $gd_page The page being filtered.
4550
 * @param string $sep     The separator, default: `|`.
4551
 *
4552
 * @return string Title after filtered variables.
4553 1
 */
4554 1
function geodir_filter_title_variables( $title, $gd_page, $sep = '' ) {
4555 1
	global $wp, $post;
4556
4557 1
	if ( ! $gd_page || ! $title ) {
4558
		return $title; // if no a GD page then bail.
4559
	}
4560
4561
	if ( $sep == '' ) {
4562
		/**
4563
		 * Filter the page title separator.
4564
		 *
4565
		 * @since   1.0.0
4566
		 * @package GeoDirectory
4567
		 *
4568
		 * @param string $sep The separator, default: `|`.
4569
		 */
4570
		$sep = apply_filters( 'geodir_page_title_separator', '|' );
4571
	}
4572
4573
	if ( strpos( $title, '%%title%%' ) !== false ) {
4574
		$title = str_replace( "%%title%%", $post->post_title, $title );
4575
	}
4576
4577 View Code Duplication
	if ( strpos( $title, '%%sitename%%' ) !== false ) {
4578
		$title = str_replace( "%%sitename%%", get_bloginfo( 'name' ), $title );
4579
	}
4580
4581 View Code Duplication
	if ( strpos( $title, '%%sitedesc%%' ) !== false ) {
4582
		$title = str_replace( "%%sitedesc%%", get_bloginfo( 'description' ), $title );
4583
	}
4584
4585
	if ( strpos( $title, '%%excerpt%%' ) !== false ) {
4586
		$title = str_replace( "%%excerpt%%", strip_tags( get_the_excerpt() ), $title );
4587
	}
4588
4589
	if ( $gd_page == 'search' || $gd_page == 'author' ) {
4590
		$post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : '';
4591
	} else if ( $gd_page == 'add-listing' ) {
4592
		$post_type = ( isset( $_REQUEST['listing_type'] ) ) ? sanitize_text_field( $_REQUEST['listing_type'] ) : '';
4593
		$post_type = ! $post_type && ! empty( $_REQUEST['pid'] ) ? get_post_type( (int) $_REQUEST['pid'] ) : $post_type;
4594
	} else if ( isset( $post->post_type ) && $post->post_type && in_array( $post->post_type, geodir_get_posttypes() ) ) {
4595
		$post_type = $post->post_type;
4596
	} else {
4597
		$post_type = get_query_var( 'post_type' );
4598
	}
4599
4600 View Code Duplication
	if ( strpos( $title, '%%pt_single%%' ) !== false ) {
4601
		$singular_name = '';
4602
		if ( $post_type && $singular_name = get_post_type_singular_label( $post_type ) ) {
4603
			$singular_name = __( $singular_name, 'geodirectory' );
4604 8
		}
4605 7
4606
		$title = str_replace( "%%pt_single%%", $singular_name, $title );
4607
	}
4608 1
4609 1 View Code Duplication
	if ( strpos( $title, '%%pt_plural%%' ) !== false ) {
4610 1
		$plural_name = '';
4611
		if ( $post_type && $plural_name = get_post_type_plural_label( $post_type ) ) {
4612 1
			$plural_name = __( $plural_name, 'geodirectory' );
4613
		}
4614
4615
		$title = str_replace( "%%pt_plural%%", $plural_name, $title );
4616 1
	}
4617
4618 View Code Duplication
	if ( strpos( $title, '%%category%%' ) !== false ) {
4619
		$cat_name = '';
4620 1
4621
		if ( $gd_page == 'detail' ) {
4622 1
			if ( $post->default_category ) {
4623
				$cat      = get_term( $post->default_category, $post->post_type . 'category' );
4624
				$cat_name = ( isset( $cat->name ) ) ? $cat->name : '';
4625
			}
4626
		} else if ( $gd_page == 'listing' ) {
4627
			$queried_object = get_queried_object();
4628
			if ( isset( $queried_object->name ) ) {
4629
				$cat_name = $queried_object->name;
4630
			}
4631
		}
4632
		$title = str_replace( "%%category%%", $cat_name, $title );
4633
	}
4634
4635 View Code Duplication
	if ( strpos( $title, '%%tag%%' ) !== false ) {
4636
		$cat_name = '';
4637
4638
		if ( $gd_page == 'detail' ) {
4639
			if ( $post->default_category ) {
4640
				$cat      = get_term( $post->default_category, $post->post_type . 'category' );
4641
				$cat_name = ( isset( $cat->name ) ) ? $cat->name : '';
4642
			}
4643
		} else if ( $gd_page == 'listing' ) {
4644
			$queried_object = get_queried_object();
4645 1
			if ( isset( $queried_object->name ) ) {
4646
				$cat_name = $queried_object->name;
4647
			}
4648
		}
4649
		$title = str_replace( "%%tag%%", $cat_name, $title );
4650
	}
4651
4652
	if ( strpos( $title, '%%id%%' ) !== false ) {
4653
		$ID    = ( isset( $post->ID ) ) ? $post->ID : '';
4654
		$title = str_replace( "%%id%%", $ID, $title );
4655
	}
4656
4657
	if ( strpos( $title, '%%sep%%' ) !== false ) {
4658
		$title = str_replace( "%%sep%%", $sep, $title );
4659
	}
4660
4661
	// location variables
4662
	$gd_post_type   = geodir_get_current_posttype();
4663
	$location_array = geodir_get_current_location_terms( 'query_vars', $gd_post_type );
4664
	/**
4665
	 * Filter the title variables location variables array
4666
	 *
4667
	 * @since   1.5.5
4668
	 * @package GeoDirectory
4669
	 *
4670
	 * @param array $location_array The array of location variables.
4671
	 * @param string $title         The title with variables..
4672
	 * @param string $gd_page       The page being filtered.
4673
	 * @param string $sep           The separator, default: `|`.
4674
	 */
4675
	$location_array  = apply_filters( 'geodir_filter_title_variables_location_arr', $location_array, $title, $gd_page, $sep );
4676
	$location_titles = array();
4677 View Code Duplication
	if ( $gd_page == 'location' && get_query_var( 'gd_country_full' ) ) {
4678
		if ( get_query_var( 'gd_country_full' ) ) {
4679
			$location_array['gd_country'] = get_query_var( 'gd_country_full' );
4680
		}
4681
		if ( get_query_var( 'gd_region_full' ) ) {
4682
			$location_array['gd_region'] = get_query_var( 'gd_region_full' );
4683
		}
4684
		if ( get_query_var( 'gd_city_full' ) ) {
4685
			$location_array['gd_city'] = get_query_var( 'gd_city_full' );
4686
		}
4687
	}
4688
	$location_single = '';
4689
	$gd_country      = ( isset( $wp->query_vars['gd_country'] ) && $wp->query_vars['gd_country'] != '' ) ? $wp->query_vars['gd_country'] : '';
4690
	$gd_region       = ( isset( $wp->query_vars['gd_region'] ) && $wp->query_vars['gd_region'] != '' ) ? $wp->query_vars['gd_region'] : '';
4691
	$gd_city         = ( isset( $wp->query_vars['gd_city'] ) && $wp->query_vars['gd_city'] != '' ) ? $wp->query_vars['gd_city'] : '';
4692
4693
	$gd_country_actual = $gd_region_actual = $gd_city_actual = '';
4694
4695 View Code Duplication
	if ( function_exists( 'get_actual_location_name' ) ) {
4696
		$gd_country_actual = $gd_country != '' ? get_actual_location_name( 'country', $gd_country, true ) : $gd_country;
4697
		$gd_region_actual  = $gd_region != '' ? get_actual_location_name( 'region', $gd_region ) : $gd_region;
4698
		$gd_city_actual    = $gd_city != '' ? get_actual_location_name( 'city', $gd_city ) : $gd_city;
4699
	}
4700
4701 View Code Duplication
	if ( $gd_city != '' ) {
4702
		if ( $gd_city_actual != '' ) {
4703
			$gd_city = $gd_city_actual;
4704
		} else {
4705
			$gd_city = preg_replace( '/-(\d+)$/', '', $gd_city );
4706
			$gd_city = preg_replace( '/[_-]/', ' ', $gd_city );
4707
			$gd_city = __( geodir_ucwords( $gd_city ), 'geodirectory' );
4708
		}
4709
		$location_single = $gd_city;
4710
4711
	} else if ( $gd_region != '' ) {
4712
		if ( $gd_region_actual != '' ) {
4713
			$gd_region = $gd_region_actual;
4714
		} else {
4715
			$gd_region = preg_replace( '/-(\d+)$/', '', $gd_region );
4716
			$gd_region = preg_replace( '/[_-]/', ' ', $gd_region );
4717
			$gd_region = __( geodir_ucwords( $gd_region ), 'geodirectory' );
4718
		}
4719
4720
		$location_single = $gd_region;
4721
	} else if ( $gd_country != '' ) {
4722
		if ( $gd_country_actual != '' ) {
4723
			$gd_country = $gd_country_actual;
4724
		} else {
4725
			$gd_country = preg_replace( '/-(\d+)$/', '', $gd_country );
4726
			$gd_country = preg_replace( '/[_-]/', ' ', $gd_country );
4727
			$gd_country = __( geodir_ucwords( $gd_country ), 'geodirectory' );
4728
		}
4729
4730
		$location_single = $gd_country;
4731
	}
4732
4733 View Code Duplication
	if ( ! empty( $location_array ) ) {
4734
4735
		$actual_location_name = function_exists( 'get_actual_location_name' ) ? true : false;
4736
		$location_array       = array_reverse( $location_array );
4737
4738
		foreach ( $location_array as $location_type => $location ) {
4739
			$gd_location_link_text = preg_replace( '/-(\d+)$/', '', $location );
4740
			$gd_location_link_text = preg_replace( '/[_-]/', ' ', $gd_location_link_text );
4741
4742
			$location_name = geodir_ucwords( $gd_location_link_text );
4743
			$location_name = __( $location_name, 'geodirectory' );
4744
4745
			if ( $actual_location_name ) {
4746
				$location_type = strpos( $location_type, 'gd_' ) === 0 ? substr( $location_type, 3 ) : $location_type;
4747
				$location_name = get_actual_location_name( $location_type, $location, true );
4748
			}
4749
4750
			$location_titles[] = $location_name;
4751
		}
4752
		if ( ! empty( $location_titles ) ) {
4753
			$location_titles = array_unique( $location_titles );
4754
		}
4755
	}
4756
4757
4758
	if ( strpos( $title, '%%location%%' ) !== false ) {
4759
		$location = '';
4760
		if ( $location_titles ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $location_titles 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...
4761
			$location = implode( ", ", $location_titles );
4762
		}
4763
		$title = str_replace( "%%location%%", $location, $title );
4764
	}
4765
4766 View Code Duplication
	if ( strpos( $title, '%%in_location%%' ) !== false ) {
4767
		$location = '';
4768
		if ( $location_titles ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $location_titles 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...
4769
			$location = __( 'in ', 'geodirectory' ) . implode( ", ", $location_titles );
4770
		}
4771 3
		$title = str_replace( "%%in_location%%", $location, $title );
4772 3
	}
4773
4774 View Code Duplication
	if ( strpos( $title, '%%in_location_single%%' ) !== false ) {
4775 3
		if ( $location_single ) {
4776 3
			$location_single = __( 'in', 'geodirectory' ) . ' ' . $location_single;
4777 3
		}
4778 3
		$title = str_replace( "%%in_location_single%%", $location_single, $title );
4779 3
	}
4780 3
4781 3
	if ( strpos( $title, '%%location_single%%' ) !== false ) {
4782
		$title = str_replace( "%%location_single%%", $location_single, $title );
4783
	}
4784
4785
4786 View Code Duplication
	if ( strpos( $title, '%%search_term%%' ) !== false ) {
4787
		$search_term = '';
4788
		if ( isset( $_REQUEST['s'] ) ) {
4789
			$search_term = esc_attr( $_REQUEST['s'] );
4790
		}
4791
		$title = str_replace( "%%search_term%%", $search_term, $title );
4792
	}
4793
4794 2 View Code Duplication
	if ( strpos( $title, '%%search_near%%' ) !== false ) {
4795 1
		$search_term = '';
4796 1
		if ( isset( $_REQUEST['snear'] ) ) {
4797 2
			$search_term = esc_attr( $_REQUEST['snear'] );
4798
		}
4799
		$title = str_replace( "%%search_near%%", $search_term, $title );
4800
	}
4801
4802
	if ( strpos( $title, '%%name%%' ) !== false ) {
4803
		if ( is_author() ) {
4804
			$curauth     = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
4805
			$author_name = $curauth->display_name;
4806
		} else {
4807
			$author_name = get_the_author();
4808
		}
4809
		if ( ! $author_name || $author_name === '' ) {
4810
			$queried_object = get_queried_object();
4811
4812
			if ( isset( $queried_object->data->user_nicename ) ) {
4813
				$author_name = $queried_object->data->display_name;
4814
			}
4815
		}
4816
		$title = str_replace( "%%name%%", $author_name, $title );
4817
	}
4818
4819
	if ( strpos( $title, '%%page%%' ) !== false ) {
4820
		$page  = geodir_title_meta_page( $sep );
4821
		$title = str_replace( "%%page%%", $page, $title );
4822
	}
4823
	if ( strpos( $title, '%%pagenumber%%' ) !== false ) {
4824
		$pagenumber = geodir_title_meta_pagenumber();
4825
		$title      = str_replace( "%%pagenumber%%", $pagenumber, $title );
4826
	}
4827
	if ( strpos( $title, '%%pagetotal%%' ) !== false ) {
4828
		$pagetotal = geodir_title_meta_pagetotal();
4829
		$title     = str_replace( "%%pagetotal%%", $pagetotal, $title );
4830
	}
4831
4832
	$title = wptexturize( $title );
4833
	$title = convert_chars( $title );
4834
	$title = esc_html( $title );
4835
4836
	/**
4837
	 * Filter the title variables after standard ones have been filtered.
4838
	 *
4839
	 * @since   1.5.7
4840
	 * @package GeoDirectory
4841
	 *
4842
	 * @param string $title         The title with variables.
4843
	 * @param array $location_array The array of location variables.
4844
	 * @param string $gd_page       The page being filtered.
4845
	 * @param string $sep           The separator, default: `|`.
4846
	 */
4847
4848
	return apply_filters( 'geodir_filter_title_variables_vars', $title, $location_array, $gd_page, $sep );
4849
}
4850
4851
/**
4852
 * Get the cpt texts for translation.
4853
 *
4854
 * @since   1.5.5
4855
 * @package GeoDirectory
4856
 *
4857
 * @param  array $translation_texts Array of text strings.
4858
 *
4859
 * @return array Translation texts.
4860
 */
4861
function geodir_load_cpt_text_translation( $translation_texts = array() ) {
4862
	$gd_post_types = geodir_get_posttypes( 'array' );
4863
4864
	if ( ! empty( $gd_post_types ) ) {
4865
		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...
4866
			$labels      = isset( $cpt_info['labels'] ) ? $cpt_info['labels'] : '';
4867
			$description = isset( $cpt_info['description'] ) ? $cpt_info['description'] : '';
4868
			$seo         = isset( $cpt_info['seo'] ) ? $cpt_info['seo'] : '';
4869
4870
			if ( ! empty( $labels ) ) {
4871 View Code Duplication
				if ( $labels['name'] != '' && ! in_array( $labels['name'], $translation_texts ) ) {
4872
					$translation_texts[] = $labels['name'];
4873
				}
4874 View Code Duplication
				if ( $labels['singular_name'] != '' && ! in_array( $labels['singular_name'], $translation_texts ) ) {
4875
					$translation_texts[] = $labels['singular_name'];
4876
				}
4877 View Code Duplication
				if ( $labels['add_new'] != '' && ! in_array( $labels['add_new'], $translation_texts ) ) {
4878
					$translation_texts[] = $labels['add_new'];
4879
				}
4880 View Code Duplication
				if ( $labels['add_new_item'] != '' && ! in_array( $labels['add_new_item'], $translation_texts ) ) {
4881
					$translation_texts[] = $labels['add_new_item'];
4882
				}
4883 View Code Duplication
				if ( $labels['edit_item'] != '' && ! in_array( $labels['edit_item'], $translation_texts ) ) {
4884
					$translation_texts[] = $labels['edit_item'];
4885
				}
4886 View Code Duplication
				if ( $labels['new_item'] != '' && ! in_array( $labels['new_item'], $translation_texts ) ) {
4887
					$translation_texts[] = $labels['new_item'];
4888
				}
4889 View Code Duplication
				if ( $labels['view_item'] != '' && ! in_array( $labels['view_item'], $translation_texts ) ) {
4890
					$translation_texts[] = $labels['view_item'];
4891
				}
4892 View Code Duplication
				if ( $labels['search_items'] != '' && ! in_array( $labels['search_items'], $translation_texts ) ) {
4893
					$translation_texts[] = $labels['search_items'];
4894
				}
4895 View Code Duplication
				if ( $labels['not_found'] != '' && ! in_array( $labels['not_found'], $translation_texts ) ) {
4896
					$translation_texts[] = $labels['not_found'];
4897
				}
4898 View Code Duplication
				if ( $labels['not_found_in_trash'] != '' && ! in_array( $labels['not_found_in_trash'], $translation_texts ) ) {
4899
					$translation_texts[] = $labels['not_found_in_trash'];
4900
				}
4901 View Code Duplication
				if ( isset( $labels['label_post_profile'] ) && $labels['label_post_profile'] != '' && ! in_array( $labels['label_post_profile'], $translation_texts ) ) {
4902
					$translation_texts[] = $labels['label_post_profile'];
4903
				}
4904 View Code Duplication
				if ( isset( $labels['label_post_info'] ) && $labels['label_post_info'] != '' && ! in_array( $labels['label_post_info'], $translation_texts ) ) {
4905
					$translation_texts[] = $labels['label_post_info'];
4906
				}
4907 View Code Duplication
				if ( isset( $labels['label_post_images'] ) && $labels['label_post_images'] != '' && ! in_array( $labels['label_post_images'], $translation_texts ) ) {
4908
					$translation_texts[] = $labels['label_post_images'];
4909
				}
4910 View Code Duplication
				if ( isset( $labels['label_post_map'] ) && $labels['label_post_map'] != '' && ! in_array( $labels['label_post_map'], $translation_texts ) ) {
4911
					$translation_texts[] = $labels['label_post_map'];
4912
				}
4913 View Code Duplication
				if ( isset( $labels['label_reviews'] ) && $labels['label_reviews'] != '' && ! in_array( $labels['label_reviews'], $translation_texts ) ) {
4914
					$translation_texts[] = $labels['label_reviews'];
4915
				}
4916 View Code Duplication
				if ( isset( $labels['label_related_listing'] ) && $labels['label_related_listing'] != '' && ! in_array( $labels['label_related_listing'], $translation_texts ) ) {
4917
					$translation_texts[] = $labels['label_related_listing'];
4918
				}
4919
			}
4920
4921
			if ( $description != '' && ! in_array( $description, $translation_texts ) ) {
4922
				$translation_texts[] = normalize_whitespace( $description );
4923
			}
4924
4925
			if ( ! empty( $seo ) ) {
4926 View Code Duplication
				if ( isset( $seo['meta_keyword'] ) && $seo['meta_keyword'] != '' && ! in_array( $seo['meta_keyword'], $translation_texts ) ) {
4927
					$translation_texts[] = normalize_whitespace( $seo['meta_keyword'] );
4928
				}
4929
4930 View Code Duplication
				if ( isset( $seo['meta_description'] ) && $seo['meta_description'] != '' && ! in_array( $seo['meta_description'], $translation_texts ) ) {
4931
					$translation_texts[] = normalize_whitespace( $seo['meta_description'] );
4932
				}
4933
			}
4934
		}
4935
	}
4936
	$translation_texts = ! empty( $translation_texts ) ? array_unique( $translation_texts ) : $translation_texts;
4937
4938
	return $translation_texts;
4939
}
4940
4941
/**
4942
 * Remove the location terms to hide term from location url.
4943
 *
4944
 * @since   1.5.5
4945
 * @package GeoDirectory
4946
 *
4947
 * @param  array $location_terms Array of location terms.
4948
 *
4949
 * @return array Location terms.
4950
 */
4951
function geodir_remove_location_terms( $location_terms = array() ) {
4952
	$location_manager = defined( 'POST_LOCATION_TABLE' ) ? true : false;
4953
4954
	if ( ! empty( $location_terms ) && $location_manager ) {
4955
		$hide_country_part = get_option( 'geodir_location_hide_country_part' );
4956
		$hide_region_part  = get_option( 'geodir_location_hide_region_part' );
4957
4958
		if ( $hide_region_part && $hide_country_part ) {
4959
			if ( isset( $location_terms['gd_country'] ) ) {
4960
				unset( $location_terms['gd_country'] );
4961
			}
4962
			if ( isset( $location_terms['gd_region'] ) ) {
4963
				unset( $location_terms['gd_region'] );
4964
			}
4965
		} else if ( $hide_region_part && ! $hide_country_part ) {
4966
			if ( isset( $location_terms['gd_region'] ) ) {
4967
				unset( $location_terms['gd_region'] );
4968
			}
4969
		} else if ( ! $hide_region_part && $hide_country_part ) {
4970
			if ( isset( $location_terms['gd_country'] ) ) {
4971
				unset( $location_terms['gd_country'] );
4972
			}
4973
		}
4974
	}
4975
4976
	return $location_terms;
4977
}
4978
4979
/**
4980
 * Send notification when a listing has been edited by it's author.
4981
 *
4982
 * @since   1.5.9
4983
 * @package GeoDirectory
4984
 *
4985
 * @param int $post_ID  Post ID.
4986
 * @param WP_Post $post Post object.
4987
 * @param bool $update  Whether this is an existing listing being updated or not.
4988
 */
4989
function geodir_on_wp_insert_post( $post_ID, $post, $update ) {
4990
	if ( ! $update ) {
4991
		return;
4992
	}
4993
4994
	$action      = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
4995
	$is_admin    = is_admin() && ( ! defined( 'DOING_AJAX' ) || ( defined( 'DOING_AJAX' ) && ! DOING_AJAX ) ) ? true : false;
4996
	$inline_save = $action == 'inline-save' ? true : false;
4997
4998
	if ( empty( $post->post_type ) || $is_admin || $inline_save || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) {
4999
		return;
5000
	}
5001
5002
	if ( $action != '' && in_array( $action, array( 'geodir_import_export' ) ) ) {
5003
		return;
5004
	}
5005
5006
	$user_id = (int) get_current_user_id();
5007
5008
	if ( $user_id > 0 && get_option( 'geodir_notify_post_edited' ) && ! wp_is_post_revision( $post_ID ) && in_array( $post->post_type, geodir_get_posttypes() ) ) {
5009
		$author_id = ! empty( $post->post_author ) ? $post->post_author : 0;
5010
5011
		if ( $user_id == $author_id && ! is_super_admin() ) {
5012
			$from_email   = get_option( 'site_email' );
5013
			$from_name    = get_site_emailName();
5014
			$to_email     = get_option( 'admin_email' );
5015
			$to_name      = get_option( 'name' );
5016
			$message_type = 'listing_edited';
5017
5018
			$notify_edited = true;
5019
			/**
5020
			 * Send notification when listing edited by author?
5021
			 *
5022
			 * @since 1.6.0
5023
			 *
5024
			 * @param bool $notify_edited Notify on listing edited by author?
5025
			 * @param object $post        The current post object.
5026
			 */
5027
			$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...
5028
5029
			geodir_sendEmail( $from_email, $from_name, $to_email, $to_name, '', '', '', $message_type, $post_ID );
5030
		}
5031
	}
5032
}
5033
5034
/**
5035
 * Retrieve the current page start & end numbering with context (i.e. 'page 2 of 4') for use as replacement string.
5036
 *
5037
 * @since   1.6.0
5038
 * @package GeoDirectory
5039
 *
5040
 * @param string $sep The separator tag.
5041
 *
5042
 * @return string|null The current page start & end numbering.
5043
 */
5044
function geodir_title_meta_page( $sep ) {
5045
	$replacement = null;
5046
5047
	$max = geodir_title_meta_pagenumbering( 'max' );
5048
	$nr  = geodir_title_meta_pagenumbering( 'nr' );
5049
5050
	if ( $max > 1 && $nr > 1 ) {
5051
		$replacement = sprintf( $sep . ' ' . __( 'Page %1$d of %2$d', 'geodirectory' ), $nr, $max );
5052
	}
5053
5054
	return $replacement;
5055
}
5056
5057
/**
5058
 * Retrieve the current page number for use as replacement string.
5059
 *
5060
 * @since   1.6.0
5061
 * @package GeoDirectory
5062
 *
5063
 * @return string|null The current page number.
5064
 */
5065 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...
5066
	$replacement = null;
5067
5068
	$nr = geodir_title_meta_pagenumbering( 'nr' );
5069
	if ( isset( $nr ) && $nr > 0 ) {
5070
		$replacement = (string) $nr;
5071
	}
5072
5073
	return $replacement;
5074
}
5075
5076
/**
5077
 * Retrieve the current page total for use as replacement string.
5078
 *
5079
 * @since   1.6.0
5080
 * @package GeoDirectory
5081
 *
5082
 * @return string|null The current page total.
5083
 */
5084 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...
5085
	$replacement = null;
5086
5087
	$max = geodir_title_meta_pagenumbering( 'max' );
5088
	if ( isset( $max ) && $max > 0 ) {
5089
		$replacement = (string) $max;
5090
	}
5091
5092
	return $replacement;
5093
}
5094
5095
/**
5096
 * Determine the page numbering of the current post/page/cpt.
5097
 *
5098
 * @param string $request   'nr'|'max' - whether to return the page number or the max number of pages.
5099
 *
5100
 * @since   1.6.0
5101
 * @package GeoDirectory
5102
 *
5103
 * @global object $wp_query WordPress Query object.
5104
 * @global object $post     The current post object.
5105
 *
5106
 * @return int|null The current page numbering.
5107
 */
5108
function geodir_title_meta_pagenumbering( $request = 'nr' ) {
5109
	global $wp_query, $post;
5110
	$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...
5111
	$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...
5112
5113
	$max_num_pages = 1;
5114
5115
	if ( ! is_singular() ) {
5116
		$page_number = get_query_var( 'paged' );
5117
		if ( $page_number === 0 || $page_number === '' ) {
5118
			$page_number = 1;
5119
		}
5120
5121
		if ( isset( $wp_query->max_num_pages ) && ( $wp_query->max_num_pages != '' && $wp_query->max_num_pages != 0 ) ) {
5122
			$max_num_pages = $wp_query->max_num_pages;
5123
		}
5124
	} else {
5125
		$page_number = get_query_var( 'page' );
5126
		if ( $page_number === 0 || $page_number === '' ) {
5127
			$page_number = 1;
5128
		}
5129
5130
		if ( isset( $post->post_content ) ) {
5131
			$max_num_pages = ( substr_count( $post->post_content, '<!--nextpage-->' ) + 1 );
5132
		}
5133
	}
5134
5135
	$return = null;
5136
5137
	switch ( $request ) {
5138
		case 'nr':
5139
			$return = $page_number;
5140
			break;
5141
		case 'max':
5142
			$return = $max_num_pages;
5143
			break;
5144
	}
5145
5146
	return $return;
5147
}
5148
5149
/**
5150
 * Filter the terms with count empty.
5151
 *
5152
 * @since 1.5.4
5153
 *
5154
 * @param array $terms Terms array.
5155
 *
5156
 * @return array Terms.
5157
 */
5158 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...
5159
	if ( empty( $terms ) ) {
5160
		return $terms;
5161
	}
5162
5163
	$return = array();
5164
	foreach ( $terms as $term ) {
5165
		if ( isset( $term->count ) && $term->count > 0 ) {
5166
			$return[] = $term;
5167
		} else {
5168
			/**
5169
			 * Allow to filter terms with no count.
5170
			 *
5171
			 * @since 1.6.6
5172
			 *
5173
			 * @param array $return The array of terms to return.
5174
			 * @param object $term  The term object.
5175
			 */
5176
			$return = apply_filters( 'geodir_filter_empty_terms_filter', $return, $term );
5177
		}
5178
	}
5179
5180
	return $return;
5181
}
5182
5183
5184
/**
5185
 * Remove the hentry class structured data from details pages.
5186
 *
5187
 * @since 1.6.5
5188
 *
5189
 * @param $class
5190
 *
5191
 * @return array
5192
 */
5193
function geodir_remove_hentry( $class ) {
5194
	if ( geodir_is_page( 'detail' ) ) {
5195
		$class = array_diff( $class, array( 'hentry' ) );
5196
	}
5197
5198
	return $class;
5199
}
5200
5201
add_filter( 'post_class', 'geodir_remove_hentry' );