'tableengine-block',
'render_callback' => array( $this, 'shortcode' ),
'attributes' => array(
'room' => array( 'type' => 'number', 'default' => 0 ),
'title' => array( 'type' => 'string', 'default' => '' ),
),
)
);
}
/**
* Dynamic CSS custom properties from Appearance settings.
*/
private function inline_css() {
$s = Settings::all();
$primary = $s['primary_color'];
$fonts = array(
'inherit' => 'inherit',
'system' => '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
'serif' => 'inherit',
);
$css = '.tableengine{';
$css .= '--tf-primary:' . $primary . ';';
$css .= '--tf-accent:' . $s['accent_color'] . ';';
$css .= '--tf-radius:' . (int) $s['radius'] . 'px;';
$css .= '--tf-max:' . (int) $s['max_width'] . 'px;';
$css .= '--tf-map-h:' . (int) $s['map_height'] . 'vh;';
$css .= '--tf-c-floor:' . $s['color_floor'] . ';';
$css .= '--tf-c-table:' . $s['color_table'] . ';';
$css .= '--tf-c-available:' . $s['color_available'] . ';';
$css .= '--tf-c-selected:' . $s['color_selected'] . ';';
$css .= '--tf-c-unavailable:' . $s['color_unavailable'] . ';';
$css .= '--tf-font:' . $fonts[ $s['font'] ] . ';';
$css .= '}';
if ( 'serif' === $s['font'] ) {
$css .= '.tableengine .tf-h,.tableengine .tf-title{font-family:"Playfair Display","Iowan Old Style","Palatino Linotype",Georgia,serif;letter-spacing:-.01em}';
}
if ( ! $s['shadow'] ) {
$css .= '.tableengine .tf-shell{box-shadow:none}';
}
/** The widget's generated CSS (custom properties from the Appearance settings). */
return (string) apply_filters( 'tableengine_inline_css', $css, $s );
}
public function shortcode( $atts = array() ) {
$atts = shortcode_atts(
array(
'room' => 0,
'title' => '',
'lazy' => 0,
),
(array) $atts,
'tableengine'
);
/** Runs before the widget reads settings (e.g. to switch to the requested location). */
do_action( 'tableengine_before_widget', $atts );
if ( ! wp_style_is( 'tableengine-booking', 'registered' ) ) {
$this->register_assets();
}
wp_enqueue_style( 'tableengine-booking' );
if ( 1 === ++self::$instance_count ) {
wp_add_inline_style( 'tableengine-booking', $this->inline_css() );
}
$gateway = Payments::active();
if ( $gateway ) {
$gateway->enqueue_frontend();
}
wp_enqueue_script( 'tableengine-booking' );
do_action( 'tableengine_enqueue_frontend_assets', $atts );
$config = Settings::public_config();
if ( $atts['title'] ) {
$config['ui']['title'] = sanitize_text_field( $atts['title'] );
}
// Guest "manage booking" link support.
$manage = null;
if ( isset( $_GET['tableengine_ref'], $_GET['tableengine_token'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$manage = array(
'ref' => strtoupper( sanitize_text_field( wp_unslash( $_GET['tableengine_ref'] ) ) ), // phpcs:ignore WordPress.Security.NonceVerification
'token' => sanitize_text_field( wp_unslash( $_GET['tableengine_token'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
);
}
$boot = array(
'rest' => esc_url_raw( rest_url( 'tableengine/v1/' ) ),
'config' => $config,
'room' => (int) $atts['room'],
'today' => wp_date( 'Y-m-d' ),
'manage' => $manage,
'i18n' => $this->strings(),
'locale' => str_replace( '_', '-', get_locale() ),
);
/** Boot data for one widget instance (read by booking.js from data-tableengine). */
$boot = apply_filters( 'tableengine_widget_boot', $boot, $atts );
$theme = $config['ui']['theme'];
$uid = 'tableengine-' . self::$instance_count;
$html = sprintf(
'
',
esc_attr( $theme ),
esc_attr( $uid ),
esc_attr( wp_json_encode( $boot ) ),
esc_html__( 'Please enable JavaScript to book a table.', 'tableengine' ),
$atts['lazy'] ? 'data-tableengine-lazy' : 'data-tableengine'
);
do_action( 'tableengine_after_widget', $atts );
return $html;
}
public function strings() {
return apply_filters( 'tableengine_widget_strings', array(
'steps' => array(
__( 'When', 'tableengine' ),
__( 'Table', 'tableengine' ),
__( 'Details', 'tableengine' ),
__( 'Payment', 'tableengine' ),
),
'guests' => __( 'Guests', 'tableengine' ),
'guest' => __( 'guest', 'tableengine' ),
'guestsPlural' => __( 'guests', 'tableengine' ),
'date' => __( 'Date', 'tableengine' ),
'time' => __( 'Time', 'tableengine' ),
'today' => __( 'Today', 'tableengine' ),
'tomorrow' => __( 'Tomorrow', 'tableengine' ),
'lunch' => __( 'Lunch', 'tableengine' ),
'dinner' => __( 'Dinner', 'tableengine' ),
'noSlots' => __( 'No tables left on this day. Try another date or party size.', 'tableengine' ),
'loadingSlots' => __( 'Finding available times…', 'tableengine' ),
'continue' => __( 'Continue', 'tableengine' ),
'back' => __( 'Back', 'tableengine' ),
'chooseTable' => __( 'Choose your table', 'tableengine' ),
'chooseTableSub' => __( 'Tap a highlighted table to select it.', 'tableengine' ),
'anyTable' => __( 'No preference — assign the best table for me', 'tableengine' ),
'map' => __( 'Map', 'tableengine' ),
'list' => __( 'List', 'tableengine' ),
'zoomIn' => __( 'Zoom in', 'tableengine' ),
'zoomOut' => __( 'Zoom out', 'tableengine' ),
'fit' => __( 'Fit to screen', 'tableengine' ),
'focusSelected' => __( 'Zoom to selected', 'tableengine' ),
'seats' => __( 'seats', 'tableengine' ),
'available' => __( 'Available', 'tableengine' ),
'selected' => __( 'Selected', 'tableengine' ),
'unavailable' => __( 'Unavailable', 'tableengine' ),
'booked' => __( 'Booked', 'tableengine' ),
'tooSmall' => __( 'Too small', 'tableengine' ),
'tooLarge' => __( 'Too large for party', 'tableengine' ),
'notBookable' => __( 'Walk-in only', 'tableengine' ),
'noTables' => __( 'No tables available at this time.', 'tableengine' ),
'ctrlZoom' => __( 'Use ctrl + scroll to zoom the map', 'tableengine' ),
'yourDetails' => __( 'Your details', 'tableengine' ),
'name' => __( 'Full name', 'tableengine' ),
'email' => __( 'Email', 'tableengine' ),
'phone' => __( 'Phone', 'tableengine' ),
'occasion' => __( 'Occasion', 'tableengine' ),
'none' => __( 'None', 'tableengine' ),
'requests' => __( 'Special requests', 'tableengine' ),
'optional' => __( 'optional', 'tableengine' ),
'required' => __( 'This field is required.', 'tableengine' ),
'invalidEmail' => __( 'Please enter a valid email.', 'tableengine' ),
'confirmBooking' => __( 'Confirm booking', 'tableengine' ),
/* translators: %s: deposit amount with currency, e.g. "$20.00". */
'payAndConfirm' => __( 'Pay %s & confirm', 'tableengine' ),
'payment' => __( 'Payment', 'tableengine' ),
'tableHeld' => __( 'Your table is held for', 'tableengine' ),
'holdExpired' => __( 'Your hold has expired. Please start again.', 'tableengine' ),
'processing' => __( 'Processing…', 'tableengine' ),
'confirming' => __( 'Confirming your payment…', 'tableengine' ),
'confirmed' => __( 'You’re booked!', 'tableengine' ),
'pendingTitle' => __( 'Request received', 'tableengine' ),
'reference' => __( 'Reference', 'tableengine' ),
'addCalendar' => __( 'Add to calendar', 'tableengine' ),
'google' => __( 'Google', 'tableengine' ),
'apple' => __( 'Apple / Outlook', 'tableengine' ),
'newBooking' => __( 'Make another booking', 'tableengine' ),
'manageTitle' => __( 'Your booking', 'tableengine' ),
'cancelBooking' => __( 'Cancel booking', 'tableengine' ),
'cancelConfirm' => __( 'Yes, cancel it', 'tableengine' ),
'keepBooking' => __( 'Keep booking', 'tableengine' ),
'cancelAsk' => __( 'Are you sure you want to cancel this booking?', 'tableengine' ),
'cancelled' => __( 'Booking cancelled', 'tableengine' ),
'refundNote' => __( 'Your deposit will be refunded to your original payment method.', 'tableengine' ),
'cantCancel' => __( 'Online cancellation is no longer available for this booking. Please contact us.', 'tableengine' ),
'notFound' => __( 'We couldn’t find that booking.', 'tableengine' ),
'genericError' => __( 'Something went wrong. Please try again.', 'tableengine' ),
'network' => __( 'Network error — check your connection and try again.', 'tableengine' ),
'summary' => __( 'Summary', 'tableengine' ),
'table' => __( 'Table', 'tableengine' ),
'assigned' => __( 'Best available', 'tableengine' ),
'edit' => __( 'Edit', 'tableengine' ),
/* translators: %d: number of tables still free at a time slot. */
'tablesFree' => __( '%d tables', 'tableengine' ),
'oneTableFree' => __( 'Last table', 'tableengine' ),
'full' => __( 'Full', 'tableengine' ),
'secure' => __( 'Secure payment by Stripe', 'tableengine' ),
'perGuest' => __( 'per guest', 'tableengine' ),
'total' => __( 'Total due now', 'tableengine' ),
'all' => __( 'All', 'tableengine' ),
'prevMonth' => __( 'Previous month', 'tableengine' ),
'nextMonth' => __( 'Next month', 'tableengine' ),
'room' => __( 'Room', 'tableengine' ),
'rotate' => __( 'Rotate map', 'tableengine' ),
'fill' => __( 'Fill screen', 'tableengine' ),
'select' => __( 'Select', 'tableengine' ),
'continueToPayment' => __( 'Continue to payment', 'tableengine' ),
'moreDates' => __( 'More dates', 'tableengine' ),
'hideCalendar' => __( 'Hide calendar', 'tableengine' ),
'paymentFailed' => __( 'Your payment was not completed. Please try booking again.', 'tableengine' ),
'paymentProcessing' => __( 'Your payment is processing. We’ll email you once it’s complete.', 'tableengine' ),
'invalidPhone' => __( 'Please enter a valid phone number.', 'tableengine' ),
'acceptTerms' => __( 'Please accept to continue.', 'tableengine' ),
'pickAnotherTable' => __( 'Pick another table', 'tableengine' ),
'pickAnotherTime' => __( 'Pick another time', 'tableengine' ),
'startAgain' => __( 'Start again', 'tableengine' ),
'refunded' => __( 'refunded', 'tableengine' ),
'manageBooking' => __( 'Manage booking', 'tableengine' ),
) );
}
}