( 'On' != get_bk_option( 'booking_legend_is_vertical' ) ) ? false : true , 'text_for_day_cell' => ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? ' ' : gmdate( 'd' ) , 'items' => $items_sort , 'resource_id' => absint( $resource_id ) ) ); } return $calendar_legend_html; } function wpbc_get_calendar_legend__content_html( $params ) { $defaults = array( 'is_vertical' => ( 'On' != get_bk_option( 'booking_legend_is_vertical' ) ) ? false : true , 'text_for_day_cell' => ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? ' ' : gmdate( 'd' ) , 'items' => array( 'available' , 'approved' , 'pending' , 'partially' ) , 'unavailable_day_cell_tag' => 'span' , 'resource_id' => 0 , 'titles' => array() ); $params = wp_parse_args( $params, $defaults ); $legend_arr = array(); // Available. if ( 1 ) { $key = 'available'; $day_cell_tag = 'a'; $legend_arr[ $key ] = '
'; $legend_arr[ $key ] .= ''; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . ''; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; } // Pending. if ( 1 ) { $key = 'pending'; $day_cell_tag = 'span'; $legend_arr[ $key ] = '
'; $legend_arr[ $key ] .= ''; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . ''; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; } // Approved. if ( 1 ) { $key = 'approved'; $day_cell_tag = 'span'; $legend_arr[ $key ] = '
'; $legend_arr[ $key ] .= ''; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . ''; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; $legend_arr[ $key ] .= '
'; } // Content for Partially booked item - "time slot" or "change over days". if ( 1 ) { $my_partially = ''; $booking_change_over_triangle = ( 'Off' !== get_bk_option( 'booking_change_over_days_triangles' ) ) ? ' wpbc_change_over_triangle' : ''; $my_partially .= ''; $my_partially .= '
'; // FixIn: 9.3.1.4. $my_partially .= ''; $is_change_over_legend = null; if ( function_exists( 'wpbc_settings_calendar__preview_is_changeover_enabled' ) ) { $is_change_over_legend = wpbc_settings_calendar__preview_is_changeover_enabled( $params['resource_id'], false ); } if ( null === $is_change_over_legend ) { $is_change_over_legend = ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) && ( wpbc_is_booking_used_check_in_out_time( false, $params['resource_id'] ) ); // FixIn: 8.9.4.10. } if ( $is_change_over_legend ) { $my_partially .= '
'; } else { $my_partially .= ''; } $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
ยท
'; $my_partially .= ' ' . esc_html( $params['text_for_day_cell'] ) . ''; $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
'; $my_partially .= '
'; } // Unavailable. if ( 1 ) { $my_unavailable = '
'; // FixIn: 9.3.1.4. $my_unavailable .= ''; $my_unavailable .= '
'; $my_unavailable .= '
'; $my_unavailable .= '
'; $my_unavailable .= '
'; $my_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . ''; $my_unavailable .= '
'; $my_unavailable .= '
'; $my_unavailable .= '
'; $my_unavailable .= '
'; $my_unavailable .= '
'; } // Resource Unavailable. if ( 1 ) { $my_resource_unavailable = '
'; // FixIn: 9.3.1.4. $my_resource_unavailable .= ''; $my_resource_unavailable .= '
'; $my_resource_unavailable .= '
'; $my_resource_unavailable .= '
'; $my_resource_unavailable .= '
'; $my_resource_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . ''; $my_resource_unavailable .= '
'; $my_resource_unavailable .= '
'; $my_resource_unavailable .= '
'; $my_resource_unavailable .= '
'; $my_resource_unavailable .= '
'; } $items_arr = array( 'available' => array( 'title' => ( ! empty( $params['titles']['available'] ) ) ? $params['titles']['available'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_available' ) ) , 'text_for_day_cell' => $legend_arr['available'] // '' . $params['text_for_day_cell'] . ''. , 'css_class' => '' // 'block_free datepick-days-cell' ) , 'approved' => array( 'title' => ( ! empty( $params['titles']['approved'] ) ) ? $params['titles']['approved'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_approved' ) ) , 'text_for_day_cell' => $legend_arr['approved'] // $params['text_for_day_cell']. , 'css_class' => '' //'block_booked date_approved' ) , 'pending' => array( 'title' => ( ! empty( $params['titles']['pending'] ) ) ? $params['titles']['pending'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_pending' ) ) , 'text_for_day_cell' => $legend_arr['pending'] // $params['text_for_day_cell']. , 'css_class' => '' //'block_pending date2approve' ) , 'partially' => array( 'title' => ( ! empty( $params['titles']['partially'] ) ) ? $params['titles']['partially'] : ( ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) ) ) ) ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) ) : __( 'Partially booked', 'booking' ) ) , 'text_for_day_cell' => $my_partially , 'css_class' => '' ) , 'unavailable' => array( // FixIn: 9.9.0.5. 'title' => ( ! empty( $params['titles']['unavailable'] ) ) ? $params['titles']['unavailable'] : ( ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) ) ) ) ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) ) : __( 'Unavailable', 'booking' ) ) , 'text_for_day_cell' => $my_unavailable , 'css_class' => '' //'datepick-days-cell datepick-unselectable date_user_unavailable' ) , 'resource_unavailable' => array( 'title' => ( ! empty( $params['titles']['resource_unavailable'] ) ) ? $params['titles']['resource_unavailable'] : __( 'Resource unavailable days', 'booking' ) , 'text_for_day_cell' => $my_resource_unavailable , 'css_class' => '' //'datepick-days-cell resource_unavailable date_user_unavailable' ) ); $calendar_legend_html = '
'; foreach ( $params['items'] as $item_name ) { if ( ! empty( $items_arr[ $item_name ] ) ) { $calendar_legend_html .= '
' . '
' . $items_arr[ $item_name ]['text_for_day_cell'] . '
' . '
' . '- ' . '
' . '
' . esc_html( $items_arr[ $item_name ]['title'] ) . '
' . '
'; } } $calendar_legend_html .= '
'; return $calendar_legend_html; } /** * Replace [calendar_legend] shortcode to HTML content in booking form from Booking > Settings > Form page * * @param string $return_form - HTML content of booking form Example: '[calendar]

Dates: [selected_short_dates_hint]([days_number_hint]...' * @param int $resource_id - ID of booking resource Example: '4' * @param string $my_booking_form - name of booking form (possible usage of custom booking form) Example: 'standard' * * @return array|string|string[] * * Example of shortcode parameters: * [legend_items items="available,unavailable,pending,approved,partially" text_for_day_cell="31"] * [legend_items is_vertical="1"] * [legend_items] * [legend_items items="resource_unavailable,available,unavailable,pending,approved,partially" text_for_day_cell="31" titles="resource_unavailable={Resource unavailable days} unavailable={Season unavailable}"] * * PHP code example with escaping single and double quotes: * echo wpbc_replace_shortcodes_in_booking_form__legend_items( '[legend_items' . ' items="unavailable,available,pending,approved,partially"' . ' titles="' .' unavailable={' . htmlspecialchars( __( "Unavailable day's", 'booking' ), ENT_QUOTES ) . '}' .' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}' .'"' . ' text_for_day_cell="' . gmdate( 'd' ) . '"' . ' unavailable_day_cell_tag="a"' .']' ); */ function wpbc_replace_shortcodes_in_booking_form__legend_items( $return_form, $resource_id = 1, $my_booking_form = '' ) { // $legend__content_html = wpbc_get_calendar_legend(); //$return_form = str_replace('[legend_items]', $legend__content_html, $return_form); $pos = 0; while ( false !== strpos( $return_form, '[legend_items ' ) ) { $shortcode_params = wpbc_get_params_of_shortcode_in_string( 'legend_items', $return_form , $pos ); if ( ( isset( $shortcode_params['text_for_day_cell'] ) ) && ( empty( $shortcode_params['text_for_day_cell'] ) ) ) { $shortcode_params['text_for_day_cell'] = gmdate( 'd' ); } $shortcode_titles_params = array(); if ( ! empty( $shortcode_params['titles'] ) ){ $shortcode_titles_params = wpbc_get_params_of_shortcode_in_string( 'titles', '[titles ' . $shortcode_params['titles'] . ']' , 0 , '%\s*([^=]*)=[{]([^}]*)[}]\s*%' ); foreach ( $shortcode_titles_params as $title_name => $title_val ) { $shortcode_titles_params[ $title_name ] = htmlspecialchars_decode( $title_val ); } } $calendar_legend_html = wpbc_get_calendar_legend__content_html( array( 'is_vertical' => ( ! empty( $shortcode_params['is_vertical'] ) ) ? true : false , 'text_for_day_cell' => ( ! empty( $shortcode_params['text_for_day_cell'] ) ) ? $shortcode_params['text_for_day_cell'] : ( ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? ' ' : gmdate( 'd' ) ) , 'items' => ( ! empty( $shortcode_params['items'] ) ) ? explode( ',',$shortcode_params['items'] ) : array( 'available' , 'approved' , 'pending' , 'partially' ) , 'unavailable_day_cell_tag' => ( ! empty( $shortcode_params['unavailable_day_cell_tag'] ) ) ? $shortcode_params['unavailable_day_cell_tag'] : 'span' , 'resource_id' => absint( $resource_id ) , 'titles' => $shortcode_titles_params ) ); $return_form = substr( $return_form, 0, ( $shortcode_params['start'] - 1 ) ) . $calendar_legend_html . substr( $return_form, ( $shortcode_params['end'] + 1 ) ); $pos = $shortcode_params['end']; } return $return_form; } add_filter( 'wpbc_replace_shortcodes_in_booking_form', 'wpbc_replace_shortcodes_in_booking_form__legend_items', 10, 3 );