HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpprotonperinggit/wp-content/themes/voiture/inc/vendors/wp-cardealer/functions.php
<?php

function voiture_get_listings( $params = array() ) {
	$params = wp_parse_args( $params, array(
		'limit' => -1,
		'post_status' => 'publish',
		'get_listings_by' => 'recent',
		'orderby' => '',
		'order' => '',
		'post__in' => array(),
		'fields' => null, // ids
		'author' => null,
		'type' => array(), 'category' => array(), 'condition' => array(), 'make' => array(), 'model' => array()
	));
	extract($params);

	$query_args = array(
		'post_type'         => 'listing',
		'posts_per_page'    => $limit,
		'post_status'       => $post_status,
		'orderby'       => $orderby,
		'order'       => $order,
	);

	$meta_query = array();
	switch ($get_listings_by) {
		case 'recent':
			$query_args['orderby'] = 'date';
			$query_args['order'] = 'DESC';
			break;
		case 'featured':
			$meta_query[] = array(
				'key' => WP_CARDEALER_LISTING_PREFIX.'featured',
	           	'value' => 'on',
	           	'compare' => '=',
			);
			break;
		case 'popular':
			$query_args['meta_key'] = WP_CARDEALER_LISTING_PREFIX.'views';
			$query_args['order'] = 'DESC';
			$query_args['orderby'] = 'meta_value_num';
			break;
	}

	if ( !empty($post__in) ) {
    	$query_args['post__in'] = $post__in;
    }

    if ( !empty($fields) ) {
    	$query_args['fields'] = $fields;
    }

    if ( !empty($author) ) {
    	$query_args['author'] = $author;
    }

    $tax_query = array();

    $tax_keys = apply_filters('voiture-listing-get-tax-keys', array('type', 'category', 'condition', 'make', 'model'));
    foreach ($tax_keys as $tax_key) {
    	if ( !empty($params[$tax_key]) ) {
    		$tax_query[] = array(
	            'taxonomy'      => 'listing_'.$tax_key,
	            'field'         => 'slug',
	            'terms'         => $params[$tax_key],
	            'operator'      => 'IN'
	        );
    	}
    }
    
    if ( !empty($tax_query) ) {
    	$query_args['tax_query'] = $tax_query;
    }
    
    if ( !empty($meta_query) ) {
    	$query_args['meta_query'] = $meta_query;
    }
    
	return new WP_Query( $query_args );
}

if ( !function_exists('voiture_listing_content_class') ) {
	function voiture_listing_content_class( $class ) {
		$prefix = 'listings';
		if ( is_singular( 'listing' ) ) {
            $prefix = 'listing';
        }
		if ( voiture_get_config($prefix.'_fullwidth') ) {
			return 'container-fluid';
		}
		return $class;
	}
}
add_filter( 'voiture_listing_content_class', 'voiture_listing_content_class', 1 , 1  );

function voiture_listing_template_folder_name($folder) {
	$folder = 'template-listings';
	return $folder;
}
add_filter( 'wp-cardealer-theme-folder-name', 'voiture_listing_template_folder_name', 10 );

if ( !function_exists('voiture_get_listings_layout_configs') ) {
	function voiture_get_listings_layout_configs() {
		$layout_sidebar = voiture_get_listings_layout_sidebar();

		$sidebar = voiture_get_listings_filter_sidebar();
		switch ( $layout_sidebar ) {
		 	case 'left-main':
		 		$configs['left'] = array( 'sidebar' => $sidebar, 'class' => 'col-md-4 col-lg-3 col-sm-12 col-xs-12'  );
		 		$configs['main'] = array( 'class' => 'col-md-8 col-lg-9 col-sm-12 col-xs-12' );
		 		break;
		 	case 'main-right':
		 	default:
		 		$configs['right'] = array( 'sidebar' => $sidebar,  'class' => 'col-md-4 col-lg-3 col-sm-12 col-xs-12' ); 
		 		$configs['main'] = array( 'class' => 'col-md-8 col-lg-9 col-sm-12 col-xs-12' );
		 		break;
	 		case 'main':
	 			$configs['main'] = array( 'class' => 'col-md-12 col-sm-12 col-xs-12' );
	 			break;
		}
		return $configs; 
	}
}

function voiture_get_listings_layout_sidebar() {
	global $post;
	if ( is_page() && is_object($post) ) {
		$layout_type = get_post_meta( $post->ID, 'apus_page_layout', true );
	}
	if ( empty($layout_type) ) {
		$layout_type = voiture_get_config('listings_layout_sidebar', 'main-right');
	}
	return apply_filters( 'voiture_get_listings_layout_sidebar', $layout_type );
}

function voiture_get_listings_layout_type() {
	global $post;
	if ( is_page() && is_object($post) ) {
		$layout_type = get_post_meta( $post->ID, 'apus_page_layout_type', true );
	}
	if ( empty($layout_type) ) {
		$layout_type = voiture_get_config('listings_layout_type', 'default');
	}
	return apply_filters( 'voiture_get_listings_layout_type', $layout_type );
}

function voiture_get_listings_display_mode() {
	global $post;
	if ( !empty($_GET['filter-display-mode']) ) {
		$display_mode = $_GET['filter-display-mode'];
	} else {
		if ( is_page() && is_object($post) ) {
			$display_mode = get_post_meta( $post->ID, 'apus_page_display_mode', true );
		}
		if ( empty($display_mode) ) {
			$display_mode = voiture_get_config('listings_display_mode', 'grid');
		}
	}
	return apply_filters( 'voiture_get_listings_display_mode', $display_mode );
}

function voiture_get_listings_inner_style() {
	global $post;
	$display_mode = voiture_get_listings_display_mode();
	if ( $display_mode == 'list' ) {
		if ( is_page() && is_object($post) ) {
			$inner_style = get_post_meta( $post->ID, 'apus_page_inner_list_style', true );
		}
		if ( empty($inner_style) ) {
			$inner_style = voiture_get_config('listings_inner_list_style', 'list');
		}
	} else {
		if ( is_page() && is_object($post) ) {
			$inner_style = get_post_meta( $post->ID, 'apus_page_inner_grid_style', true );
		}
		if ( empty($inner_style) ) {
			$inner_style = voiture_get_config('listings_inner_grid_style', 'grid');
		}
	}
	return apply_filters( 'voiture_get_listings_inner_style', $inner_style );
}

function voiture_get_listings_columns() {
	global $post;
	if ( is_page() && is_object($post) ) {
		$columns = get_post_meta( $post->ID, 'apus_page_listings_columns', true );
	}
	if ( empty($columns) ) {
		$columns = voiture_get_config('listings_columns', 3);
	}
	return apply_filters( 'voiture_get_listings_columns', $columns );
}

function voiture_get_listings_list_columns() {
	global $post;
	if ( is_page() && is_object($post) ) {
		$columns = get_post_meta( $post->ID, 'apus_page_listings_list_columns', true );
	}
	if ( empty($columns) ) {
		$columns = voiture_get_config('listings_list_columns', 3);
	}
	return apply_filters( 'voiture_get_listings_list_columns', $columns );
}

function voiture_get_listings_pagination() {
	global $post;
	if ( is_page() && is_object($post) ) {
		$pagination = get_post_meta( $post->ID, 'apus_page_listings_pagination', true );
	}
	if ( empty($pagination) ) {
		$pagination = voiture_get_config('listings_pagination', 'default');
	}
	return apply_filters( 'voiture_get_listings_pagination', $pagination );
}

function voiture_get_listing_layout_type() {
	global $post;
	if ( defined('VOITURE_DEMO_MODE') && VOITURE_DEMO_MODE ) {
		$layout_type = get_post_meta($post->ID, WP_CARDEALER_LISTING_PREFIX.'layout_type', true);
	}
	
	if ( empty($layout_type) ) {
		$layout_type = voiture_get_config('listing_layout_type', 'v1');
	}
	return apply_filters( 'voiture_get_listing_layout_type', $layout_type );
}

function voiture_listing_scripts() {
	
	wp_enqueue_style( 'leaflet' );
	wp_enqueue_script( 'jquery-highlight' );
    wp_enqueue_script( 'leaflet' );
    wp_enqueue_script( 'control-geocoder' );
    wp_enqueue_script( 'esri-leaflet' );
    wp_enqueue_script( 'esri-leaflet-geocoder' );
    wp_enqueue_script( 'leaflet-markercluster' );
    wp_enqueue_script( 'leaflet-HtmlIcon' );
    
    if ( wp_cardealer_get_option('map_service') == 'google-map' ) {
    	wp_enqueue_script( 'leaflet-GoogleMutant' );
    }
    
    wp_register_script( 'sticky-kit', get_template_directory_uri() . '/js/sticky-kit.min.js', array( 'jquery' ), '20150330', true );
    
	wp_register_script( 'voiture-listing', get_template_directory_uri() . '/js/listing.js', array( 'jquery', 'wp-cardealer-main', 'perfect-scrollbar', 'imagesloaded' ), '20150330', true );

	$current_currency = WP_CarDealer_Price::get_current_currency();
	$multi_currencies = WP_CarDealer_Price::get_currencies_settings();

	if ( !empty($multi_currencies) && !empty($multi_currencies[$current_currency]) ) {
		$currency_args = $multi_currencies[$current_currency];
	}

	if ( !empty($currency_args) ) {
		$currency_symbol = !empty($currency_args['custom_symbol']) ? $currency_args['custom_symbol'] : '';
		if ( empty($currency_symbol) ) {
			$currency = !empty($currency_args['currency']) ? $currency_args['currency'] : 'USD';
			$currency_symbol = WP_CarDealer_Price::currency_symbol($currency);
		}
	}

	$currency_symbol = ! empty( $currency_symbol ) ? $currency_symbol : '$';
	$dec_point = ! empty( wp_cardealer_get_option('money_dec_point') ) ? wp_cardealer_get_option('money_dec_point') : '.';
	$thousands_separator = ! empty( wp_cardealer_get_option('money_thousands_separator') ) ? wp_cardealer_get_option('money_thousands_separator') : '';

	wp_localize_script( 'voiture-listing', 'voiture_listing_opts', array(
		'ajaxurl' => admin_url( 'admin-ajax.php' ),

		'dec_point' => $dec_point,
		'thousands_separator' => $thousands_separator,
		'currency' => esc_attr($currency_symbol),
		'monthly_text' => esc_html__('Monthly Payment: ', 'voiture'),
		'compare_added_title' => esc_html__('Compared', 'voiture'),
		'compare_title' => esc_html__('Compare', 'voiture'),
		'compare_added_tooltip_title' => esc_html__('Remove Compare', 'voiture'),
		'compare_add_tooltip_title' => esc_html__('Add Compare', 'voiture'),
		'favorite_added_tooltip_title' => esc_html__('Remove Favorite', 'voiture'),
		'favorite_add_tooltip_title' => esc_html__('Add Favorite', 'voiture'),

		'template' => apply_filters( 'voiture_autocompleate_search_template', '<a href="{{url}}" class="media autocompleate-media">
			<div class="media-left media-middle">
				<img src="{{image}}" class="media-object" height="50" width="50">
			</div>
			<div class="media-body media-middle">
				<h4>{{title}}</h4>
				{{{price}}}
				</div></a>' ),
        'empty_msg' => apply_filters( 'voiture_autocompleate_search_empty_msg', esc_html__( 'Unable to find any listing that match the currenty query', 'voiture' ) ),
	));
	wp_enqueue_script( 'voiture-listing' );

	$here_map_api_key = '';
	$here_style = '';
	$mapbox_token = '';
	$mapbox_style = '';
	$custom_style = '';
	$googlemap_type = wp_cardealer_get_option('googlemap_type', 'roadmap');
	if ( empty($googlemap_type) ) {
		$googlemap_type = 'roadmap';
	}
	$map_service = wp_cardealer_get_option('map_service', '');
	if ( $map_service == 'mapbox' ) {
		$mapbox_token = wp_cardealer_get_option('mapbox_token', '');
		$mapbox_style = wp_cardealer_get_option('mapbox_style', 'streets-v11');
		if ( empty($mapbox_style) || !in_array($mapbox_style, array( 'streets-v11', 'light-v10', 'dark-v10', 'outdoors-v11', 'satellite-v9' )) ) {
			$mapbox_style = 'streets-v11';
		}
	} elseif ( $map_service == 'here' ) {
		$here_map_api_key = wp_cardealer_get_option('here_map_api_key', '');
		$here_style = wp_cardealer_get_option('here_map_style', 'normal.day');
	} else {
		$custom_style = wp_cardealer_get_option('google_map_style', '');
	}

	wp_register_script( 'voiture-listing-map', get_template_directory_uri() . '/js/listing-map.js', array( 'jquery' ), '20150330', true );
	wp_localize_script( 'voiture-listing-map', 'voiture_listing_map_opts', array(
		'map_service' => $map_service,
		'mapbox_token' => $mapbox_token,
		'mapbox_style' => $mapbox_style,
		'here_map_api_key' => $here_map_api_key,
		'here_style' => $here_style,
		'custom_style' => $custom_style,
		'googlemap_type' => $googlemap_type,
		'default_latitude' => wp_cardealer_get_option('default_maps_location_latitude', '43.6568'),
		'default_longitude' => wp_cardealer_get_option('default_maps_location_longitude', '-79.4512'),
		'default_pin' => wp_cardealer_get_option('default_maps_pin', ''),
		
	));
	wp_enqueue_script( 'voiture-listing-map' );
}
add_action( 'wp_enqueue_scripts', 'voiture_listing_scripts', 10 );

function voiture_is_listings_page() {
	if ( is_page() ) {
		$page_name = basename(get_page_template());
		if ( $page_name == 'page-listings.php' ) {
			return true;
		}
	} elseif( is_post_type_archive('listing') || is_tax('listing_category') || is_tax('listing_color') || is_tax('listing_condition') || is_tax('listing_cylinder') || is_tax('listing_door') || is_tax('listing_drive_type') || is_tax('listing_feature') || is_tax('listing_fuel_type') || is_tax('listing_location') || is_tax('listing_make') || is_tax('listing_model') || is_tax('listing_offer_type') || is_tax('listing_safety_type') || is_tax('listing_transmission') || is_tax('listing_type') ) {
		return true;
	}
	return false;
}


function voiture_listing_metaboxes($fields) {
	// listing

	if ( defined('VOITURE_DEMO_MODE') && VOITURE_DEMO_MODE ) {
		$prefix = WP_CARDEALER_LISTING_PREFIX;
		if ( !empty($fields) ) {
			$fields[ $prefix . 'tab-layout-version' ] = array(
				'id' => $prefix . 'tab-layout-version',
				'icon' => 'dashicons-admin-appearance',
				'title' => esc_html__( 'Layout Type', 'voiture' ),
				'fields' => array(
					array(
						'name'              => esc_html__( 'Layout Type', 'voiture' ),
						'id'                => $prefix . 'layout_type',
						'type'              => 'select',
						'options'			=> array(
			                '' => esc_html__('Global Settings', 'voiture'),
			                'v1' => esc_html__('Version 1', 'voiture'),
			                'v2' => esc_html__('Version 2', 'voiture'),
			                'v3' => esc_html__('Version 3', 'voiture'),
			                'v4' => esc_html__('Version 4', 'voiture'),
			                'v5' => esc_html__('Version 5', 'voiture'),
			                'v6' => esc_html__('Version 6', 'voiture'),
			            ),
					)
				)
			);
		}
	}
	
	return $fields;
}
add_filter( 'wp-cardealer-admin-custom-fields', 'voiture_listing_metaboxes' );


remove_action( 'wp_cardealer_before_listing_archive', array( 'WP_CarDealer_Listing', 'display_listings_results_filters' ), 5 );

function voiture_display_mode_form($display_mode, $form_url) {
	ob_start();
	?>
	<div class="listings-display-mode-wrapper">
		<form class="listings-display-mode" method="get" action="<?php echo esc_url($form_url); ?>">
			<div class="inner">
				<label for="filter-display-mode-grid">
					<input id="filter-display-mode-grid" type="radio" name="filter-display-mode" value="grid" <?php checked('grid', $display_mode); ?>> <i class="ti-view-grid"></i>
				</label>
				<label for="filter-display-mode-list">
					<input id="filter-display-mode-list" type="radio" name="filter-display-mode" value="list" <?php checked('list', $display_mode); ?>> <i class="ti-view-list-alt"></i>
				</label>
			</div>
			<?php WP_CarDealer_Mixes::query_string_form_fields( null, array( 'filter-display-mode', 'submit' ) ); ?>
		</form>
	</div>
	<?php
	$output = ob_get_clean();
	return $output;
}

function voiture_listings_display_mode_form() {
	$listings_page = WP_CarDealer_Mixes::get_listings_page_url();
	$display_mode = voiture_get_listings_display_mode();
	$output = voiture_display_mode_form($display_mode, $listings_page);
	
	echo trim($output);
}
add_action( 'wp_cardealer_before_listing_archive', 'voiture_listings_display_mode_form', 30 );

function voiture_listings_start_ordering_display_mode() {
	?>
	<div class="ordering-display-mode-wrapper flex-middle">
	<?php
}
function voiture_listings_end_ordering_display_mode() {
	?>
	</div>
	<?php
}
add_action( 'wp_cardealer_before_listing_archive', 'voiture_listings_start_ordering_display_mode', 20 );
add_action( 'wp_cardealer_before_listing_archive', 'voiture_listings_end_ordering_display_mode', 40 );



function voiture_compare_footer_html() {
	if ( !voiture_get_config('listing_enable_compare', true) ) {
		return;
	}
	$compare_ids = WP_CarDealer_Compare::get_compare_items(); ?>
	<div id="compare-sidebar" class="<?php echo esc_attr(count($compare_ids) > 0 ? 'active' : ''); ?>">
		<h3 class="title"><?php echo esc_html__('Compare Listings', 'voiture'); ?></h3>
		<div class="compare-sidebar-inner">
			<div class="compare-list">
				<?php
					if ( count($compare_ids) > 0 ) {
						$page_id = wp_cardealer_get_option('compare_listings_page_id');
	            		$submit_url = $page_id ? get_permalink($page_id) : home_url( '/' );
						
						foreach ($compare_ids as $listing_id) {
							$post_object = get_post( $listing_id );
	                        if ( $post_object ) {
	                            setup_postdata( $GLOBALS['post'] =& $post_object );
	                            echo WP_CarDealer_Template_Loader::get_template_part( 'listings-styles/inner-list-compare-small' );
	                        }
						}
					}
				?>
			</div>
			<?php if ( count($compare_ids) > 0 ) { ?>
				<div class="compare-actions">
					<div class="row-20 clearfix">
						<div class="col-xs-6">
						<a href="<?php echo esc_url($submit_url); ?>" class="btn btn-theme btn-block btn-sm"><?php echo esc_html__('Compare', 'voiture'); ?></a>
						</div>
						<div class="col-xs-6">
						<a href="javascript:void(0);" class="btn-remove-compare-all btn btn-danger btn-block btn-sm" data-nonce="<?php echo esc_attr(wp_create_nonce( 'wp-cardealer-remove-listing-compare-nonce' )); ?>"><?php echo esc_html__('Clear', 'voiture'); ?></a>
						</div>
					</div>
				</div>
			<?php } ?>
		</div>
		<div class="compare-sidebar-btn">
			<?php esc_html_e( 'Compare', 'voiture' ); ?> (<span class="count"><?php echo count($compare_ids); ?></span>)
		</div>
	</div><!-- .widget-area -->
<?php
}
add_action( 'wp_footer', 'voiture_compare_footer_html', 10 );

function voiture_add_remove_listing_compare_return($return) {
	$compare_ids = WP_CarDealer_Compare::get_compare_items();
	$output = '';
	if ( !empty($compare_ids) && count($compare_ids) > 0 ) {
		ob_start();
		$page_id = wp_cardealer_get_option('compare_listings_page_id');
		$submit_url = $page_id ? get_permalink($page_id) : home_url( '/' );
		?>
		<div class="compare-list">
			<?php
			foreach ($compare_ids as $listing_id) {
				$post_object = get_post( $listing_id );
                if ( $post_object ) {
                    setup_postdata( $GLOBALS['post'] =& $post_object );
                    echo WP_CarDealer_Template_Loader::get_template_part( 'listings-styles/inner-list-compare-small' );
                }
			}
			?>
		</div>
		<div class="compare-actions">
			<div class="row-20 clearfix">
				<div class="col-xs-6">
				<a href="<?php echo esc_url($submit_url); ?>" class="btn btn-theme btn-block btn-sm"><?php echo esc_html__('Compare', 'voiture'); ?></a>
				</div>
				<div class="col-xs-6">
				<a href="javascript:void(0);" class="btn-remove-compare-all btn btn-danger btn-block btn-sm" data-nonce="<?php echo esc_attr(wp_create_nonce( 'wp-cardealer-remove-listing-compare-nonce' )); ?>"><?php echo esc_html__('Clear', 'voiture'); ?></a>
				</div>
			</div>
		</div>
		<?php
		$output = ob_get_clean();
	}
	$return['html_output'] = $output;
	$return['count'] = !empty($compare_ids) ? count($compare_ids) : 0;
	

	return $return;
}
add_filter( 'wp-cardealer-process-add-listing-compare-return', 'voiture_add_remove_listing_compare_return', 10, 1 );
add_filter( 'wp-cardealer-process-remove-listing-compare-return', 'voiture_add_remove_listing_compare_return', 10, 1 );


remove_action( 'wp_cardealer_before_listing_archive', array( 'WP_CarDealer_Listing', 'display_listings_orderby_start' ), 15 );
add_action( 'wp_cardealer_before_listing_archive', array( 'WP_CarDealer_Listing', 'display_listings_orderby_start' ), 1 );



// autocomplete search listings
add_action( 'wpcd_ajax_voiture_autocomplete_search_listings', 'voiture_autocomplete_search_listings' );

function voiture_autocomplete_search_listings() {

    // Query for suggestions
    $suggestions = array();
    $args = array(
		'post_type' => 'listing',
		'posts_per_page' => 10,
		'fields' => 'ids'
	);
    $filter_params = isset($_REQUEST['data']) ? $_REQUEST['data'] : null;

	$listings = WP_CarDealer_Query::get_posts( $args, $filter_params );

	if ( !empty($listings->posts) ) {
		foreach ($listings->posts as $post_id) {
			$suggestion['title'] = get_the_title($post_id);
			$suggestion['url'] = get_permalink($post_id);

			if ( has_post_thumbnail( $post_id ) ) {
	            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' );
	            $suggestion['image'] = $image[0];
	        } else {
	            $suggestion['image'] = voiture_placeholder_img_src();
	        }
	        
	        $suggestion['price'] = voiture_listing_display_price($post_id, 'icon', false);


        	$suggestions[] = $suggestion;
		}
		wp_reset_postdata();
	}
    echo json_encode( $suggestions );
 
    exit;
}


function voiture_user_display_phone($phone, $display_type = 'no-title', $echo = true, $always_show_phone = false, $show_url = true) {
    ob_start();
    if ( $phone ) {
        $show_full = voiture_get_config('listing_show_full_phone', false);
        $hide_phone = $show_full ? false : true;
        $hide_phone = apply_filters('voiture_phone_hide_number', $hide_phone );
        if ( $always_show_phone ) {
        	$hide_phone = false;
        }
        $add_class = '';
        if ( $hide_phone ) {
            $add_class = 'phone-hide';
        }
        if ( $display_type == 'title' ) {
            ?>
            <div class="phone-wrapper agent-phone with-title <?php echo esc_attr($add_class); ?>">
                <span><?php esc_html_e('Phone: ', 'voiture'); ?></span>
            <?php
        } elseif ($display_type == 'icon') {
            ?>
            <div class="phone-wrapper agent-phone with-icon <?php echo esc_attr($add_class); ?>">
                <i class="ti-headphone-alt"></i>
        <?php
        } else {
            ?>
            <div class="phone-wrapper agent-phone <?php echo esc_attr($add_class); ?>">
            <?php
        }

        ?>
        	<?php if ( $show_url ) { ?>
            <a class="phone" href="tel:<?php echo trim($phone); ?>">
            <?php } ?>
            	<?php echo trim($phone); ?>
    		<?php if ( $show_url ) { ?>
            	</a>
        	<?php } ?>

            <?php if ( $hide_phone ) {
                $dispnum = substr($phone, 0, (strlen($phone)-3) ) . str_repeat("*", 3);
            ?>
                <span class="phone-show" onclick="this.parentNode.classList.add('show');"><?php echo trim($dispnum); ?> <span><?php esc_html_e('show', 'voiture'); ?></span></span>
            <?php } ?>
        </div>
        <?php
    }
    $output = ob_get_clean();
    if ( $echo ) {
        echo trim($output);
    } else {
        return $output;
    }
}


add_action( 'wp_ajax_nopriv_voiture_ajax_print_listing', 'voiture_ajax_print_listing' );
add_action( 'wp_ajax_voiture_ajax_print_listing', 'voiture_ajax_print_listing' );

add_action( 'wpcd_ajax_voiture_ajax_print_listing', 'voiture_ajax_print_listing' );

function voiture_ajax_print_listing () {
	if ( !isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'voiture-printer-listing-nonce' )  ) {
		exit();
	}
	if( !isset($_POST['listing_id'])|| !is_numeric($_POST['listing_id']) ){
        exit();
    }

    $listing_id = intval($_POST['listing_id']);
    $the_post = get_post( $listing_id );

    if( $the_post->post_type != 'listing' || $the_post->post_status != 'publish' ) {
        exit();
    }
    setup_postdata( $GLOBALS['post'] =& $the_post );
    global $post;

    $dir = '';
    $body_class = '';
    if ( is_rtl() ) {
    	$dir = 'dir="rtl"';
    	$body_class = 'rtl';
    }

    print  '<html '.$dir.'><head><link href="'.get_stylesheet_uri().'" rel="stylesheet" type="text/css" />';
    if( is_rtl() ) {
    	print '<link href="'.get_template_directory_uri().'/css/bootstrap-rtl.css" rel="stylesheet" type="text/css" />';
    } else {
	    print  '<html><head><link href="'.get_template_directory_uri().'/css/bootstrap.css" rel="stylesheet" type="text/css" />';
	}
    print  '<html><head><link href="'.get_template_directory_uri().'/css/all-awesome.css" rel="stylesheet" type="text/css" />';
    print  '<html><head><link href="'.get_template_directory_uri().'/css/flaticon.css" rel="stylesheet" type="text/css" />';
    print  '<html><head><link href="'.get_template_directory_uri().'/css/themify-icons.css" rel="stylesheet" type="text/css" />';
    print  '<html><head><link href="'.get_template_directory_uri().'/css/template.css" rel="stylesheet" type="text/css" />';


    print '</head>';
    print '<script>window.onload = function() { window.print(); }</script>';
    print '<body class="'.$body_class.'">';

    $print_logo = voiture_get_config('print-logo');
    if( !empty($print_logo) ) {
    	$print_logo = $print_logo;
    } else {
    	$print_logo = get_template_directory_uri().'/images/logo.svg';
    }
    $title = get_the_title( $listing_id );

    $image_id = get_post_thumbnail_id( $listing_id );
    $full_img = wp_get_attachment_image_src($image_id, 'voiture-slider');
    $full_img = $full_img [0];

    ?>

    <section id="section-body">
        <!--start detail content-->
        <section class="section-detail-content">
            <div class="detail-bar print-detail">
                
                <?php if ( voiture_get_config('show_print_header', true) ) { ?>
	            	<div class="print-header-top">
	                    <div class="inner">
                            <img src="<?php echo esc_url($print_logo); ?>" alt="<?php esc_attr_e('Logo', 'voiture'); ?>">
	                    </div>
	                </div>
	            <?php } ?>

                <div class="print-header-middle">
                    <div class="print-header-middle-left">
                        <h1><?php echo esc_attr($title); ?></h1>
                        <?php voiture_listing_display_full_location_without_url($post,'no-icon-title',true); ?>
                    </div>
                    <div class="print-header-middle-right">
                        <?php voiture_listing_display_price($post); ?>
                    </div>
                </div>

                <?php if( !empty($full_img) ) { ?>
	                <div class="print-banner">
	                    <div class="print-main-image">
                            <img src="<?php echo esc_url( $full_img ); ?>" alt="<?php echo esc_attr($title); ?>">
                            <?php if ( voiture_get_config('show_print_qrcode', true) ) { ?>
	                            <img class="qr-image" src="https://chart.googleapis.com/chart?chs=105x104&cht=qr&chl=<?php echo esc_url( get_permalink($listing_id) ); ?>&choe=UTF-8" title="<?php echo esc_attr($title); ?>" />
	                        <?php } ?>
	                    </div>
	                </div>
                <?php } ?>
                <?php
                
                if ( voiture_get_config('show_print_author', true) ) {
					$user_id = $post->post_author;
					$author_email = get_the_author_meta('user_email');
					$a_title = get_the_author_meta('display_name');
					$a_phone = get_user_meta($user_id, '_user_phone', true);
					$a_phone = voiture_user_display_phone($a_phone, 'no-title', false, true, false);
					$a_website = get_user_meta($user_id, '_user_url', true);

            	?>
                    <div class="print-block">
                    	<h3><?php esc_html_e( 'Contact Author', 'voiture' ); ?></h3>
                        <div class="agent-media">
                            <div class="media-image-left">
                                <?php echo voiture_get_avatar($post->post_author, 180); ?>
                            </div>
                            <div class="media-body-right">
                                
                                <h4 class="title"><?php echo trim($a_title); ?></h4>
								<div class="phone"><?php echo trim($a_phone); ?></div>
								<div class="email"><?php echo trim($author_email); ?></div>
								<div class="website"><?php echo trim($a_website); ?></div>

                            </div>
                        </div>
                    </div>
                <?php } ?>

                <div id="listing-single-details">
					<?php
					if ( voiture_get_config('show_print_description', true) ) {
						?>
						<div class="description inner">
						    <h3 class="title"><?php esc_html_e('Overview', 'voiture'); ?></h3>
						    <div class="description-inner">
						        <?php the_content(); ?>
						        <?php do_action('wp-cardealer-single-listing-description', $post); ?>
						    </div>
						</div>
						<?php
					}
					?>

					<?php
					if ( voiture_get_config('show_print_detail', true) ) {
						echo WP_CarDealer_Template_Loader::get_template_part( 'single-listing/detail', array('print_car' => true) );
					}
					?>

				</div>

				<?php
				if ( voiture_get_config('show_print_features', true) ) {
					echo WP_CarDealer_Template_Loader::get_template_part( 'single-listing/features' );
				}
				?>

				<?php

				$obj_listing_meta = WP_CarDealer_Listing_Meta::get_instance($post->ID);
				$gallery = $obj_listing_meta->get_post_meta( 'gallery' );
				if ( voiture_get_config('show_print_gallery', true) && $gallery ) {
				?>
					<div class="print-gallery">
						<div class="detail-title-inner">
                            <h4 class="title-inner"><?php esc_html_e('Listing images', 'voiture'); ?></h4>
                        </div>
                        <div class="row">
							<?php foreach ( $gallery as $id => $src ) { ?>
				                <div class="print-gallery-image col-xs-12 col-sm-6">
				                    <?php echo wp_get_attachment_image( $id, 'voiture-slider' ); ?>
				                </div>
			                <?php } ?>
		                </div>
		          	</div>
	          	<?php } ?>
				
            </div>
        </section>
    </section>


    <?php
    
    wp_reset_postdata();

    print '</body></html>';
    wp_die();
}


function voiture_get_listings_show_filter_top() {
	global $post;
	if ( is_page() && is_object($post) ) {
		$show_filter_top = get_post_meta( $post->ID, 'apus_page_listings_show_filter_top', true );
	}
	if ( empty($show_filter_top) ) {
		$show_filter_top = voiture_get_config('listings_show_filter_top');
	} else {
		if ( $show_filter_top == 'yes' ) {
			$show_filter_top = true;
		} else {
			$show_filter_top = false;
		}
	}
	return apply_filters( 'voiture_get_listings_show_filter_top', $show_filter_top );
}

function voiture_get_listings_filter_sidebar() {
	global $post;
	if ( is_page() && is_object($post) ) {
		$listings_filter_sidebar = get_post_meta( $post->ID, 'apus_page_listings_filter_sidebar', true );
	}
	if ( empty($listings_filter_sidebar) ) {
		$listings_filter_sidebar = voiture_get_config('listings_filter_sidebar', 'listings-filter');
	}
	return apply_filters( 'voiture_get_listings_filter_sidebar', $listings_filter_sidebar );
}

function voiture_get_listings_filter_top_sidebar() {
	global $post;
	if ( is_page() && is_object($post) ) {
		$listings_filter_top_sidebar = get_post_meta( $post->ID, 'apus_page_listings_filter_top_sidebar', true );
	}
	if ( empty($listings_filter_top_sidebar) ) {
		$listings_filter_top_sidebar = voiture_get_config('listings_filter_top_sidebar', 'listings-filter-top');
	}
	return apply_filters( 'voiture_get_listings_filter_top_sidebar', $listings_filter_top_sidebar );
}

function voiture_load_select2() {
	wp_enqueue_script('wpcd-select2');
	wp_enqueue_style('wpcd-select2');
}

add_filter( 'wp-cardealer-create-attachment-remove-image-sizes', 'voiture_property_create_attachment_remove_image_sizes', 100);
function voiture_property_create_attachment_remove_image_sizes($sizes) {
	$layout_type = voiture_get_config('property_layout_type', 'v1');
	switch ($layout_type) {
		case 'v1':
		case 'v2':
			$sizes[] = 'voiture-gallery-large2';
			$sizes[] = 'voiture-gallery-v2';
			break;
		case 'v3':
			$sizes[] = 'voiture-gallery-large';
			$sizes[] = 'voiture-gallery-v2';
			break;
		case 'v4':
			$sizes[] = 'voiture-gallery-large2';
			$sizes[] = 'voiture-gallery-large';
			$sizes[] = 'voiture-gallery-v2';
			break;
		case 'v5':
			$sizes[] = 'voiture-gallery-large2';
			$sizes[] = 'voiture-gallery-thumbs';
			break;
		case 'v6':
			$sizes[] = 'voiture-gallery-large2';
			$sizes[] = 'voiture-gallery-large';
			$sizes[] = 'voiture-gallery-v2';
			break;
	}
	$sizes[] = '1536x1536';
	$sizes[] = '2048x2048';
	$sizes[] = 'large';
	$sizes[] = 'medium_large';
	$sizes[] = 'medium';
	$sizes[] = 'voiture-agent-grid';
	return $sizes;
}

// demo function
function voiture_check_demo_account() {
	if ( defined('VOITURE_DEMO_MODE') && VOITURE_DEMO_MODE ) {
		$user_id = get_current_user_id();
		$user_obj = get_user_by('ID', $user_id);
		if ( strtolower($user_obj->data->user_login) == 'demo') {
			$return = array( 'status' => false, 'msg' => esc_html__('Demo users are not allowed to modify information.', 'voiture') );
		   	echo wp_json_encode($return);
		   	exit;
		}
	}
}

add_action('wp-cardealer-process-forgot-password', 'voiture_check_demo_account', 10);
add_action('wp-cardealer-process-change-password', 'voiture_check_demo_account', 10);
add_action('wp-cardealer-before-delete-profile', 'voiture_check_demo_account', 10);
add_action('wp-cardealer-before-remove-listing-alert', 'voiture_check_demo_account', 10 );
add_action('wp-cardealer-before-change-profile-normal', 'voiture_check_demo_account', 10 );
add_action('wp-cardealer-process-add-agent', 'voiture_check_demo_account', 10 );
add_action('wp-cardealer-process-remove-agent', 'voiture_check_demo_account', 10 );
add_action('wp-cardealer-process-remove-before-save', 'voiture_check_demo_account', 10);

function voiture_check_demo_account2($error) {
	if ( defined('VOITURE_DEMO_MODE') && VOITURE_DEMO_MODE ) {
		$user_id = get_current_user_id();
		$user_obj = get_user_by('ID', $user_id);
		if ( strtolower($user_obj->data->user_login) == 'demo') {
			$error[] = esc_html__('Demo users are not allowed to modify information.', 'voiture');
		}
	}
	return $error;
}
add_filter('wp-cardealer-submission-validate', 'voiture_check_demo_account2', 10, 2);
add_filter('wp-cardealer-edit-validate', 'voiture_check_demo_account2', 10, 2);

function voiture_check_demo_account3($post_id, $prefix) {
	if ( defined('VOITURE_DEMO_MODE') && VOITURE_DEMO_MODE ) {
		$user_id = get_current_user_id();
		$user_obj = get_user_by('ID', $user_id);
		if ( strtolower($user_obj->data->user_login) == 'demo') {
			$_SESSION['messages'][] = array( 'danger', esc_html__('Demo users are not allowed to modify information.', 'voiture') );
			$redirect_url = get_permalink( wp_cardealer_get_option('edit_profile_page_id') );
			WP_CarDealer_Mixes::redirect( $redirect_url );
			exit();
		}
	}
}
add_action('wp-cardealer-process-profile-before-change', 'voiture_check_demo_account3', 10, 2);

function voiture_check_demo_account4() {
	if ( defined('VOITURE_DEMO_MODE') && VOITURE_DEMO_MODE ) {
		$user_id = get_current_user_id();
		$user_obj = get_user_by('ID', $user_id);
		if ( strtolower($user_obj->data->user_login) == 'demo') {
			$return['msg'] = esc_html__('Demo users are not allowed to modify information.', 'voiture');
			$return['status'] = false;
			echo json_encode($return); exit;
		}
	}
}
add_action('wp-private-message-before-reply-message', 'voiture_check_demo_account4');
add_action('wp-private-message-before-add-message', 'voiture_check_demo_account4');
add_action('wp-private-message-before-delete-message', 'voiture_check_demo_account4');

function voiture_title_connect() {
	if ( WP_CarDealer_Mixes::check_social_login_enable() ) {
		echo '<h2 class="title">'.esc_html__('Connect With Social', 'voiture').'</h2>';
	}
}
add_action('login_form', 'voiture_title_connect', 2);