format('Y/m/d');
$eagle_booking_checkout = DateTime::createFromFormat("m/d/Y", $eagle_booking_checkout)->format('Y/m/d');
while ($eagle_booking_checkin <= $eagle_booking_checkout) {
$eagle_booking_checkin = date('Y/m/d', strtotime($eagle_booking_checkin . ' + 1 days'));
$eagle_booking_get_nights_number = $eagle_booking_get_nights_number + 1;
}
return $eagle_booking_get_nights_number - 1;
}
/* --------------------------------------------------------------------------
* @ Get PHP Date format
* @ Return Date
* @ since 1.0.6
---------------------------------------------------------------------------*/
function eagle_booking_get_php_date_format() {
$eagle_booking_date_format = eb_get_option('eagle_booking_date_format');
if ($eagle_booking_date_format == 'dd/mm/yyyy') {
$eagle_booking_php_date_format = 'd/m/Y';
} elseif ($eagle_booking_date_format == 'mm/dd/yyyy') {
$eagle_booking_php_date_format = 'm/d/Y';
} else {
$eagle_booking_php_date_format = 'Y/m/d';
}
return $eagle_booking_php_date_format;
}
/* --------------------------------------------------------------------------
* @ Get Displayd Date String and format it to system format
* @ Return Date
* @ since 1.0.6
---------------------------------------------------------------------------*/
function eagle_booking_system_date_format($eagle_booking_orginal_date) {
$eagle_booking_date = DateTime::createFromFormat(eagle_booking_get_php_date_format(), $eagle_booking_orginal_date);
$eagle_booking_system_date = $eagle_booking_date->format('m/d/Y');
// Return system date format m/d/Y
return $eagle_booking_system_date;
}
/* --------------------------------------------------------------------------
* @ Get System Date String and format it to displayd date
* @ Return Date
* @ since 1.0.6
---------------------------------------------------------------------------*/
function eagle_booking_displayd_date_format($eagle_booking_orginal_date) {
if (!empty($eagle_booking_orginal_date)) {
$eagle_booking_date = DateTime::createFromFormat('m/d/Y', $eagle_booking_orginal_date);
$eagle_booking_displayd_date = $eagle_booking_date->format(eagle_booking_get_php_date_format());
return $eagle_booking_displayd_date;
}
}
/* --------------------------------------------------------------------------
* Check room quantity availability
* @since 1.0.0
---------------------------------------------------------------------------*/
function eagle_booking_is_qnt_available($eagle_booking_strings_dates_orders, $eagle_booking_checkin, $eagle_booking_checkout, $eagle_booking_id) {
// range date
$eagle_booking_range_night = eb_total_booking_nights($eagle_booking_checkin, $eagle_booking_checkout);
// get room qnt
$eagle_booking_meta_box_qnt = get_post_meta($eagle_booking_id, 'eagle_booking_mtb_room_quantity', true);
if ($eagle_booking_meta_box_qnt == '') {
$eagle_booking_meta_box_qnt = 1;
}
// DATE FORMAT
$eagle_booking_date_count = DateTime::createFromFormat("m/d/Y", $eagle_booking_checkin)->format('Y/m/d');
if ($eagle_booking_strings_dates_orders != '') {
for ($eagle_booking_i = 1; $eagle_booking_i <= $eagle_booking_range_night; $eagle_booking_i++) {
$eagle_booking_num_reservations_per_day = substr_count($eagle_booking_strings_dates_orders, $eagle_booking_date_count);
if ($eagle_booking_num_reservations_per_day >= $eagle_booking_meta_box_qnt) {
return 0;
}
$eagle_booking_date_count = date('Y/m/d', strtotime($eagle_booking_date_count . ' + 1 days'));
}
}
return 1;
}
/* --------------------------------------------------------------------------
* Get room image
* @since 1.0.0
---------------------------------------------------------------------------*/
function eagle_booking_get_room_img_url($eagle_booking_id, $image_size) {
$eagle_booking_image_id = get_post_thumbnail_id($eagle_booking_id);
$eagle_booking_image_attributes = wp_get_attachment_image_src($eagle_booking_image_id, $image_size);
$eagle_booking_img_src = $eagle_booking_image_attributes[0];
return esc_url($eagle_booking_img_src);
}
/* --------------------------------------------------------------------------
* Get plugin options
* @since 1.0.0
---------------------------------------------------------------------------*/
if ( !function_exists('eb_get_option') ):
function eb_get_option($option) {
global $eagle_booking;
if (empty($eagle_booking_settings)) {
$eagle_booking_settings = get_option('eagle_booking_settings');
}
if (isset($eagle_booking_settings[$option])) {
return is_array($eagle_booking_settings[$option]) && isset($eagle_booking_settings[$option]['url']) ? $eagle_booking_settings[$option]['url'] : $eagle_booking_settings[$option];
} else {
return false;
}
}
endif;
/* --------------------------------------------------------------------------
* Create Sidebar
* @since 1.0.0
---------------------------------------------------------------------------*/
function eagle_booking_single_cause_sidebar() {
// Sidebar Main
register_sidebar(array(
'name' => esc_html__('Eagle Booking Sidebar', 'eagle-booking'),
'id' => 'eagle_booking_single_room_sidebar',
'before_widget' => '
';
echo'
';
include EB_PATH . '/core/admin/form-parameters.php';
echo '
';
}
}
}
/* --------------------------------------------------------------------------
* Show SlideUp search form only on none EB pages
* Since 1.3.3.6
---------------------------------------------------------------------------*/
function eb_slide_up_search_form() {
if ( is_eb_page() != true ) {
add_filter( 'wp_footer', 'eb_slide_up_search_form_dom', 100 );
}
}
add_filter( 'template_redirect', 'eb_slide_up_search_form' );
/* --------------------------------------------------------------------------
* Image Sizes
* @since 1.2
---------------------------------------------------------------------------*/
if ( !function_exists( 'eb_image_sizes' ) ):
function eb_image_sizes() {
$sizes = array(
'eagle_booking_image_size_370_485' => array( 'title' => esc_html__('370 x 485', 'eagle-booking'), 'w' => 370, 'h' => 485, 'crop' => true),
'eagle_booking_image_size_720_470' => array( 'title' => esc_html__('720 x 470', 'eagle-booking'), 'w' => 720, 'h' => 470, 'crop' => true),
'eagle_booking_image_size_1170_680' => array( 'title' => esc_html__('1170 x 680', 'eagle-booking'), 'w' => 1170, 'h' => 680, 'crop' => true),
'eagle_booking_image_size_1920_800' => array( 'title' => esc_html__('1920 x 800', 'eagle-booking'), 'w' => 1920, 'h' => 800, 'crop' => true),
);
$disable_img_sizes = eb_get_option('eb_image_sizes');
if(!empty( $disable_img_sizes )){
$disable_img_sizes = array_keys( array_filter( $disable_img_sizes ) );
}
if(!empty($disable_img_sizes) ){
foreach($disable_img_sizes as $size_id ){
unset( $sizes[$size_id]);
}
}
$sizes = apply_filters( 'eb_modify_image_sizes', $sizes );
return $sizes;
}
/* Add image sizes */
$image_sizes = eb_image_sizes();
if ( !empty( $image_sizes ) ) {
foreach ( $image_sizes as $id => $size ) {
add_image_size( $id, $size['w'], $size['h'], $size['crop'] );
}
}
endif;
/* --------------------------------------------------------------------------
* Share social media
* @since 1.2
---------------------------------------------------------------------------*/
if ( ! function_exists( 'eb_social_share' ) ) {
function eb_social_share() {
global $post;
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), false, '' );
?>
format('h:i a');
// Make the "am" & "pm" translatable
$eb_checkin_time_string = str_replace(array('am', 'pm'), array( __('am', 'eagle-booking'), __('pm', 'eagle-booking') ), $eb_checkin_time_string);
}
if( isset($eb_checkin_time_string )) echo ', '.__('from', 'eagle-booking').' '.$eb_checkin_time_string;
} else {
// Check the time format
if ( $eb_checkin_out_time_format === '24hour' && $eb_checkin_time_24hour) {
$eb_checkout_time_string = $eb_checkout_time_24hour;
} elseif ($eb_checkin_out_time_format === '12hour' && $eb_checkin_time_12hour) {
// 12hour formatS (Get 24hour format and convert it to 12hour)
$eb_checkout_time_string = (new DateTime($eb_checkout_time_12hour))->format('h:i a');
// Make the "am" & "pm" translatable
$eb_checkout_time_string = str_replace(array('am', 'pm'), array( __('am', 'eagle-booking'), __('pm', 'eagle-booking') ), $eb_checkout_time_string);
}
if( isset($eb_checkout_time_string) ) echo ', '.__('until', 'eagle-booking').' '.$eb_checkout_time_string;
}
}
}
/* --------------------------------------------------------------------------
* Services Price Type
* @since 1.2.3
---------------------------------------------------------------------------*/
if ( ! function_exists( 'eb_service_price_type' ) ) {
function eb_service_price_type() {
if (eb_get_option('eb_adults_children') == true ) {
$eb_price_type = array(
'room' => __('Room', 'eagle-booking'),
'adult' => __('Adult', 'eagle-booking'),
'children' => __('Children', 'eagle-booking'),
'adult_children' => __('Adult + Children', 'eagle-booking')
);
} else {
$eb_price_type = array(
'room' => __('Room', 'eagle-booking'),
'guest' => __('Guest', 'eagle-booking'),
);
}
return $eb_price_type;
}
}
/* --------------------------------------------------------------------------
* Breadcrumb
* @since 1.2.3
---------------------------------------------------------------------------*/
if ( !function_exists('eb_breadcrumb') ) {
function eb_breadcrumb() {
echo '
";
}
}
/* --------------------------------------------------------------------------
* Notice
* $type [info, success, error]
* @since 1.2.6
---------------------------------------------------------------------------*/
if (! function_exists('eb_notice')) {
function eb_notice($type, $message) {
if ($type == '') {
$eb_notice_class = 'eb-alert';
} else {
$eb_notice_class = 'eb-alert'.' '.'eb-alert-'.$type;
}
$eb_notice = '
';
$eb_notice .= $message;
$eb_notice .= '
';
echo $eb_notice;
}
}
/* --------------------------------------------------------------------------
* Get user IP
* Since 1.2.9.2
* Modified 1.3.3.8.2
---------------------------------------------------------------------------*/
if (! function_exists('eb_user_ip')) {
function eb_user_ip() {
foreach ( array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
if ( array_key_exists($key, $_SERVER) === true ) {
foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
$user_ip = $ip;
}
}
} else {
$user_ip = 0;
}
}
return $user_ip;
}
}
/* --------------------------------------------------------------------------
* Check if room has branch
* Since 1.2.9.6
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_room_has_branch') ) {
function eb_room_has_branch( $room_id ) {
$branches = get_the_terms( $room_id, 'eagle_branch' );
if ( $branches ) {
return true;
} else {
return false;
}
}
}
/* --------------------------------------------------------------------------
* Get Room Branch
* Since 1.2.9.6
* Modified 1.3.3
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_room_branch') ) {
function eb_room_branch( $room_id, $branch_url = '', $target = '' ) {
$branches = get_the_terms( $room_id, 'eagle_branch' );
if ( $target == true ) $target = "_blank";
if ( $branches ) {
$html = '';
foreach ( $branches as $branch ) {
$eb_branch_id = $branch->term_id;
$eb_branch_name = get_term_field( 'name', $branch );
$eb_branch_url = get_term_link($eb_branch_id);
if ( $branch_url == true ) {
$html .= '
';
$html .= esc_html( $eb_branch_name );
$html .= '';
} else {
$html .= esc_html( $eb_branch_name );
}
}
return $html;
} else {
return false;
}
}
}
/* --------------------------------------------------------------------------
* Get Branches to sort rooms by branch
* Since 1.2.9.6
* Modified 1.3.3.8.2
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_sort_by_branch') ) {
function eb_sort_by_branch( $bakery = false ) {
$args = array(
'taxonomy' => 'eagle_branch',
'hide_empty' => false,
);
$branch_query = new WP_Term_Query($args);
if ( !empty( $branch_query->terms ) ) {
if ( $bakery === 'bakery' ) {
$new_array[__('All', 'eagle-booking')] = 0 ;
} else {
$new_array['0'] = __('All', 'eagle-booking');
}
foreach ( $branch_query->terms as $eb_branch ) {
$eb_branch_id = $eb_branch->term_id;
$eb_branch_name = get_term_field( 'name', $eb_branch );
// For WP Bakery reverse
if ( $bakery === 'bakery' ) {
$new_array[$eb_branch_name] = $eb_branch_id;
// Elementor
} else {
$new_array[$eb_branch_id] = $eb_branch_name;
}
}
} else {
if ( $bakery === 'bakery' ) {
$new_array[__('No Branch', 'eagle-booking')] = 0 ;
} else {
}
}
return $new_array;
}
}
/* --------------------------------------------------------------------------
* Return the total booking price (including taxes & fees)
* Since 1.3.3
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_total_price') ) {
function eb_total_price($room_id, $trip_price, $booking_nights, $guests, $include_taxes_fees = false) {
if ( eb_get_option('price_taxes') === 'including' || $include_taxes_fees == true ) {
$eb_taxes = get_option('eb_taxes');
$eb_fees = get_option('eb_fees');
$eb_room_taxes = get_post_meta( $room_id, 'eagle_booking_mtb_room_taxes', true );
$eb_room_fees = get_post_meta( $room_id, 'eagle_booking_mtb_room_fees', true );
if ( empty( $eb_taxes ) ) $eb_taxes = array();
if ( empty( $eb_fees ) ) $eb_fees = array();
if ( empty( $eb_room_taxes ) ) $eb_room_taxes = array();
if ( empty( $eb_room_fees ) ) $eb_room_fees = array();
// Merge Taxes & Fees
$eb_entries = array_merge( $eb_taxes, $eb_fees );
$eb_room_entries = array_merge( $eb_room_taxes, $eb_room_fees );
if ( empty( $eb_room_entries ) ) $eb_room_entries = array();
$taxes_fees_total = 0;
$taxes_fees_amount = 0;
$fees_taxes = 0;
if ( $eb_entries ) {
foreach( $eb_entries as $key => $item ) {
$entry_id = !empty( $item["id"] ) ? $item["id"] : '';
$type = !empty( $item["type"] ) ? $item["type"] : '';
$amount = !empty( $item["amount"] ) ? $item["amount"] : '';
$global = !empty( $item["global"] ) ? $item["global"] : '';
$include_fee = !empty( $item["fees"] ) ? $item["fees"] : '';
// lets check if the tax is global or if is asigned to the room
if ( $global == true || in_array( $entry_id, $eb_room_entries) ) {
// Calculate the tax & fees total based on the type
if ( $type === 'per_booking' ) {
$taxes_fees_amount = $amount;
} elseif ( $type === 'per_booking_nights' ) {
$taxes_fees_amount = $amount * $booking_nights;
} elseif ( $type === 'per_booking_nights_guests' ) {
$taxes_fees_amount = $amount * $guests * $booking_nights;
} elseif ( $type === 'per_guests' ) {
$taxes_fees_amount = $amount * $guests;
// is tax
} else {
$taxes_fees_amount = $amount * $trip_price / 100;
}
// TO DO: Check if the tax is applied on the fee and add the tax fee amount to the total price (to be added)
// if ( $include_fee == true ) {
// $total_price = $taxes_fees_amount + $fees_taxes;
// } else {
// $total_price = $taxes_fees_amount;
// }
// Round each tax & fee amount separately
$taxes_fees_total += round( $taxes_fees_amount );
}
}
}
// Price including taxes & fees
$price = $trip_price + $taxes_fees_total;
} else {
// Price excluding taxes & fees
$price = $trip_price;
}
return $price;
}
}
/* --------------------------------------------------------------------------
* Check if room has taxes (global or asigned)
* Return: Boolean
* Since 1.3.2
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_room_has_taxes_fees') ) {
function eb_room_has_taxes_fees( $room_id ) {
$eb_taxes = get_option('eb_taxes');
$eb_fees = get_option('eb_fees');
$eb_room_taxes = get_post_meta( $room_id, 'eagle_booking_mtb_room_taxes', true );
$eb_room_fees = get_post_meta( $room_id, 'eagle_booking_mtb_room_fees', true );
if ( empty( $eb_taxes ) ) $eb_taxes = array();
if ( empty( $eb_fees ) ) $eb_fees = array();
if ( empty( $eb_room_taxes ) ) $eb_room_taxes = array();
if ( empty( $eb_room_fees ) ) $eb_room_fees = array();
// Merge taxees & fees
$eb_entries = array_merge( $eb_taxes, $eb_fees );
$eb_room_entries = array_merge( $eb_room_taxes, $eb_room_fees );
if ( empty( $eb_room_entries ) ) $eb_room_entries = array();
// if ( eb_get_option('total_price_taxes_fees') === 'excluding' && $eb_entries ) {
if ( eb_get_option('price_taxes') === 'excluding' && $eb_entries ) {
foreach( $eb_entries as $key => $item ) {
$entry_id = !empty( $item["id"] ) ? $item["id"] : '';
$global = !empty( $item["global"] ) ? $item["global"] : '';
// lets check if the tax is global or if is asigned to the room
if ( $global == true || in_array( $entry_id, $eb_room_entries) ) {
return true;
break;
}
}
}
}
}
/* --------------------------------------------------------------------------
* Get Room Taxes (Global & Assigned)
* Return: Array
* Since 1.3.2
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_room_taxes') ) {
function eb_room_taxes( $room_id ) {
$eb_taxes = get_option('eb_taxes');
$eb_room_taxes = get_post_meta( $room_id, 'eagle_booking_mtb_room_taxes', true );
if ( empty( $eb_taxes ) ) $eb_taxes = array();
if ( empty( $eb_room_taxes ) ) $eb_room_taxes = array();
$taxes = array();
if ( $eb_taxes ) {
foreach( $eb_taxes as $key => $item ) {
$entry_id = isset( $item["id"] ) ? $item["id"] : 0;
$global = isset( $item["global"] ) ? $item["global"] : 0;
// lets check if the tax is global or if is asigned to the room
if ( $global == true || in_array( $entry_id, $eb_room_taxes) ) {
$taxes[$key] = $entry_id;
}
}
return $taxes;
} else {
return;
}
}
}
/* --------------------------------------------------------------------------
* Get Room Fees (Global or Assigned)
* Return: Array
* Since 1.3.2
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_room_fees') ) {
function eb_room_fees( $room_id ) {
$eb_fees = get_option('eb_fees');
$eb_room_fees = get_post_meta( $room_id, 'eagle_booking_mtb_room_fees', true );
if ( empty( $eb_fees ) ) $eb_fees = array();
if ( empty( $eb_room_fees ) ) $eb_room_fees = array();
if ( $eb_fees ) {
foreach( $eb_fees as $key => $item ) {
$entry_id = !empty( $item["id"] ) ? $item["id"] : '';
$global = !empty( $item["global"] ) ? $item["global"] : '';
// lets check if the fee is global or if is asigned to the room
if ( $global == true || in_array( $entry_id, $eb_room_fees) ) {
$fees[$key] = $entry_id;
}
}
return $fees;
} else {
return;
}
}
}
/* --------------------------------------------------------------------------
* Get Room Fees Amount (Global or Assigned)
* Return: Array
* Since 1.3.2
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_room_fees_amount') ) {
function eb_room_fees_amount( $room_id, $booking_nights, $guests ) {
$eb_fees = get_option('eb_fees');
$eb_room_fees = get_post_meta( $room_id, 'eagle_booking_mtb_room_fees', true );
if ( empty( $eb_fees ) ) $eb_fees = array();
if ( empty( $eb_room_fees ) ) $eb_room_fees = array();
$total_amount = 0;
$fees_amount = 0;
if ( $eb_fees ) {
foreach( $eb_fees as $key => $item ) {
$entry_id = !empty( $item["id"] ) ? $item["id"] : '';
$type = !empty( $item["type"] ) ? $item["type"] : '';
$global = !empty( $item["global"] ) ? $item["global"] : '';
$amount = !empty( $item["amount"] ) ? $item["amount"] : '';
// lets check if the fee is global or if is asigned to the room
if ( $global == true || in_array( $entry_id, $eb_room_fees) ) {
// Calculate the tax & fees total based on the type
if ( $type === 'per_booking' ) {
$fees_amount = $amount;
} elseif ( $type === 'per_booking_nights' ) {
$fees_amount = $amount * $booking_nights;
} elseif ( $type === 'per_booking_nights_guests' ) {
$fees_amount = $amount * $guests * $booking_nights;
} elseif ( $type === 'per_guests' ) {
$fees_amount = $amount * $guests;
}
}
$total_amount += $fees_amount;
}
return $total_amount;
} else {
return;
}
}
}
/* --------------------------------------------------------------------------
* Get Room Fees Amount (Global or Assigned)
* Return: Array
* Since 1.3.4.3
---------------------------------------------------------------------------*/
if ( ! function_exists('eb_booking_source') ) {
function eb_booking_source( $eb_booking_id, $eb_booking_display_source_text = false ) {
global $wpdb;
$eb_table_meta_name = $wpdb->prefix . 'eagle_booking_meta';
$eb_booking_source = $wpdb->get_row( "SELECT * FROM $eb_table_meta_name WHERE booking_id = $eb_booking_id AND meta_key = 'booking_source'");
if ( isset( $eb_booking_source->meta_value ) ) {
$eb_booking_source = $eb_booking_source->meta_value;
switch($eb_booking_source) {
case 'bookingcom':
$eb_booking_source_text = "
";
break;
case 'airbnb':
$eb_booking_source_text = "
";
break;
case 'external':
$eb_booking_source_text = __('External', 'Eagle Booking');
break;
case 'admin':
$eb_booking_source_text = __('Admin', 'Eagle Booking');
break;
default:
$eb_booking_source_text = __('Direct', 'Eagle Booking');
break;
}
} else {
if ( $eb_booking_source == '') $eb_booking_source_text = __('Not Set', 'eagle-booking');
}
if ( $eb_booking_display_source_text == true ) {
return $eb_booking_source_text;
} else {
return $eb_booking_source;
}
}
}