1990 ? sanitize_key( wp_unslash( $_REQUEST['firstRegistrationMin'] ) ) : 0;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$firstRegistrationMax = isset( $_REQUEST['firstRegistrationMax'] ) ? sanitize_key( wp_unslash( $_REQUEST['firstRegistrationMax'] ) ) : gmdate( 'Y' );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$mileageMin = isset( $_REQUEST['mileageMin'] ) ? intval( $_REQUEST['mileageMin'] ) : 0;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$mileageMax = isset( $_REQUEST['mileageMax'] ) ? intval( $_REQUEST['mileageMax'] ) : 200000;
if ( !$ajax ) :
$content .= '
';
if ( !array_key_exists( 'mobileadid', $atts ) && !array_key_exists( 'filter', $atts ) ) {
$action_url = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ).'#vehicle-filter' : '';
$content .= '
';
}
endif;
$args = array( 'post_type' => 'mobile-api-vehicle', 'paged' => $page );
if ( !empty( $category ) ) :
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
$args['tax_query'] = array( array(
'taxonomy' => 'mobile_api_vehicle_category',
'field' => 'slug',
'terms' => array_map( 'sanitize_key', explode( ',', $category ) )
) );
endif;
if ( !empty( $fuel ) )
$atts['fuel'] = $fuel;
if ( !empty( $gearbox ) )
$atts['gearbox'] = $gearbox;
if ( !empty( $firstRegistrationMin ) && !empty( $firstRegistrationMax ) )
$atts['firstRegistration'] = $firstRegistrationMin.'01,'.$firstRegistrationMax.'12';
if ( !empty( $mileageMin ) && !empty( $mileageMax ) )
$atts['mileage'] = $mileageMin.','.$mileageMax;
unset( $atts['category'], $atts['page'], $atts['ajax'], $atts['align'], $atts['limit'], $atts['posts'] );
if ( !empty( $atts ) ) :
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
$args['meta_query'] = array( 'RELATION' => 'AND' );
foreach ( $atts AS $key => $value ) :
if ( $key == 'filter' )
continue;
if ( str_contains( $value, ',' ) ) :
$args['meta_query'][] = array(
'key' => 'mobile_api_'.sanitize_key( $key ),
'value' => explode( ',', $value ),
'type' => 'NUMERIC',
'compare' => 'BETWEEN',
);
else :
$args['meta_query'][] = array(
'key' => 'mobile_api_'.sanitize_key( $key ),
'value' => sanitize_text_field( $value ),
'compare' => '=',
);
endif;
endforeach;
endif;
$orderby = get_option( 'mobile_api_orderby' );
if ( !empty( $orderby ) && $orderby == 'title' ) :
$args['order'] = 'ASC';
$args['orderby'] = $orderby;
elseif ( !empty( $orderby ) && $orderby == 'mileage' ) :
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
$args['meta_key'] = 'mobile_api_'.$orderby;
$args['order'] = 'ASC';
$args['orderby'] = 'meta_value_num';
endif;
$posts = new WP_Query( $args );
if ( !$posts->have_posts() )
return $content.'
'.esc_html__( 'No vehicle is currently available. Please visit us again soon.', 'ad-integration-for-mobile-de-api' ).'
';
while ( $posts->have_posts() ) {
$posts->the_post();
$post_id = get_the_ID();
$terms = get_the_terms( $post_id, 'mobile_api_vehicle_category' );
$price = maybe_unserialize( get_post_meta( $post_id, 'mobile_api_price', true ) );
$condition = get_post_meta( $post_id, 'mobile_api_condition', true );
$mileage = absint( get_post_meta( $post_id, 'mobile_api_mileage', true ) );
$power = absint( get_post_meta( $post_id, 'mobile_api_power', true ) );
$fuel = get_post_meta( $post_id, 'mobile_api_fuel', true );
$firstRegistration = get_post_meta( $post_id, 'mobile_api_firstRegistration', true );
$consumptions = maybe_unserialize( get_post_meta( $post_id, 'mobile_api_consumptions', true ) );
$emissions = maybe_unserialize( get_post_meta( $post_id, 'mobile_api_emissions', true ) );
$content .= '
'.esc_html( get_the_title( $post_id ) ).'
'.esc_html( implode( ' › ', wp_list_pluck( $terms, 'name' ) ) ).'
'.esc_html( get_the_title( $post_id ) ).'
'.esc_html( number_format_i18n( $price->consumerPriceGross, 0 ) ).' €';
if ( property_exists( $price, 'consumerPriceNet' ) && property_exists( $price, 'vatRate' ) ) {
// translators: %s is the formatted price and the rounded vat rate
$content .= ''.sprintf( esc_html__( '%s (net)', 'ad-integration-for-mobile-de-api' ), floatval( number_format_i18n( $price->consumerPriceNet, 2 ) ) ).', '.sprintf( esc_html__( '%s VAT', 'ad-integration-for-mobile-de-api' ), round( $price->vatRate ).'%' ).'';
} else
$content .= ''.esc_html__( 'VAT not included', 'ad-integration-for-mobile-de-api' ).'';
$content .= '
'.esc_html( mobile_api_translate_data_value( $condition ) ).'';
if ( !empty( $power ) )
$content .= ', '.esc_html( $power ).' kW ('.round( $power * 1.35962 ).' PS)';
if ( !empty( $mileage ) )
$content .= ', '.esc_html( number_format_i18n( $mileage, 0 ) ).' km';
if ( !empty( $fuel ) )
$content .= ', '.esc_html( mobile_api_translate_data_value( $fuel ) );
if ( !empty( $firstRegistration ) )
$content .= ', '.esc_html__( 'First Registration', 'ad-integration-for-mobile-de-api' ).' '.esc_html( substr( $firstRegistration, 4, 6 ) ).'/'.esc_html( substr( $firstRegistration, 0, -2 ) );
if ( !empty( $consumptions ) ) {
if ( property_exists( $consumptions, 'weightedCombinedFuel' ) && property_exists( $consumptions, 'weightedCombinedPower' ) )
$content .= ', '.esc_html__( 'Consumptions (weighted combined):', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $consumptions->weightedCombinedFuel, 1 ) ).' '.esc_html( mobile_api_translate_consumption_unit( 'fuel' ) ).' + '.esc_html( number_format_i18n( $consumptions->weightedCombinedPower, 1 ) ).' '.esc_html( mobile_api_translate_consumption_unit( 'power' ) );
foreach ( $consumptions AS $fuel => $consumption ) {
if ( !empty( $consumption ) && property_exists( $consumption, 'combined' ) ) {
if ( count( get_object_vars( $consumptions ) ) > 1 )
$content .= ', '.esc_html( mobile_api_translate_consumption_title( $fuel, true ) );
else
$content .= ', '.esc_html__( 'Consumptions:', 'ad-integration-for-mobile-de-api' );
$content .= ' '.esc_html( number_format_i18n( $consumption->combined, 1 ) ).' '.esc_html( mobile_api_translate_consumption_unit( $fuel ) ).' '.esc_html__( '(combined)', 'ad-integration-for-mobile-de-api' );
}
}
}
if ( !empty( $emissions ) && property_exists( $emissions, 'combined' ) && count( (array)$emissions->combined ) ) {
$classes = array();
foreach ( $emissions as $emission )
$classes[] = $emission->co2Class;
$content .= ', '.esc_html__( 'CO₂ emissions (combined):', 'ad-integration-for-mobile-de-api' ).' '.esc_html( $emissions->combined->co2 ).' g/km, '.esc_html__( 'CO₂ class (combined):', 'ad-integration-for-mobile-de-api' ).' '.esc_html( implode( ' + ', $classes ) );
}
$content .= '
'.esc_html__( 'More details', 'ad-integration-for-mobile-de-api' ).'
';
}
wp_reset_postdata();
$page++;
$posts_per_page = get_option( 'posts_per_page' );
$limit = $posts->max_num_pages;
if ( !$ajax && $page <= $limit ) :
$content .= ''.sprintf( _n( '%d vehicle total', '%d vehicles total', intval( $posts->found_posts ), 'ad-integration-for-mobile-de-api' ), intval( $posts->found_posts ) ).'
';
}
if ( !$ajax )
$content .= '