__( 'Cancellation policy', 'flexatech-table-reservations' ), 'booking' => __( 'Book a table', 'flexatech-table-reservations' ), 'menu' => __( 'Menu', 'flexatech-table-reservations' ), 'about' => __( 'About us', 'flexatech-table-reservations' ), 'contact' => __( 'Contact', 'flexatech-table-reservations' ), default => '', }; } /** * @param array $links Page key to the address of a page made already. * @param list,opens:string,last_seating:string}> $shifts The active shifts, for the opening hours. * @param int $party_max Largest party that books online. */ public static function content( string $key, array $links, array $shifts, int $party_max ): string { return match ( $key ) { 'policy' => self::policy(), 'booking' => self::booking( $links, $party_max ), 'menu' => self::menu( $links ), 'about' => self::about( $links ), 'contact' => self::contact( $links, $shifts ), default => '', }; } /** * @param array $links */ private static function booking( array $links, int $party_max ): string { $out = self::p( esc_html__( 'Pick a day and how many of you are coming, then choose a time. We email you as soon as your table is booked.', 'flexatech-table-reservations' ) ) . "\n\n" . self::p( esc_html( sprintf( /* translators: %d: largest party that books online */ __( 'For a party of more than %d, or for a private event, call us on [phone number].', 'flexatech-table-reservations' ), $party_max ) ) ); if ( isset( $links['policy'] ) ) { $out .= self::p( sprintf( /* translators: %s: link to the cancellation policy page */ esc_html__( 'Plans change. Read our %s before you book.', 'flexatech-table-reservations' ), self::a( $links['policy'], __( 'cancellation policy', 'flexatech-table-reservations' ) ) ) ); } return $out; } /** * @param array $links */ private static function menu( array $links ): string { $sections = [ __( 'Starters', 'flexatech-table-reservations' ) => [ [ __( 'Seasonal soup', 'flexatech-table-reservations' ), '[6.50]', __( 'Made fresh each morning, served with warm bread.', 'flexatech-table-reservations' ) ], [ __( 'Garden salad', 'flexatech-table-reservations' ), '[7.00]', __( 'Leaves, herbs, toasted seeds and a lemon dressing.', 'flexatech-table-reservations' ) ], ], __( 'Mains', 'flexatech-table-reservations' ) => [ [ __( 'Grilled fish of the day', 'flexatech-table-reservations' ), '[18.00]', __( 'With new potatoes and green beans.', 'flexatech-table-reservations' ) ], [ __( 'Slow-cooked beef', 'flexatech-table-reservations' ), '[21.00]', __( 'Braised for six hours, with mash and greens.', 'flexatech-table-reservations' ) ], [ __( 'Mushroom risotto', 'flexatech-table-reservations' ), '[15.00]', __( 'Vegetarian. Ask us for a vegan version.', 'flexatech-table-reservations' ) ], ], __( 'Desserts', 'flexatech-table-reservations' ) => [ [ __( 'Chocolate tart', 'flexatech-table-reservations' ), '[7.50]', __( 'With vanilla ice cream.', 'flexatech-table-reservations' ) ], [ __( 'Fruit plate', 'flexatech-table-reservations' ), '[6.00]', __( 'Whatever is ripe this week.', 'flexatech-table-reservations' ) ], ], ]; $out = self::p( esc_html__( '[A line about your food: where it comes from, how often the menu changes.] These dishes and prices are samples. Replace them with your own.', 'flexatech-table-reservations' ) ); foreach ( $sections as $section => $dishes ) { $out .= self::h( esc_html( $section ) ); foreach ( $dishes as [ $name, $price, $about ] ) { $out .= self::p( '' . esc_html( $name ) . ' ' . esc_html( $price ) . '
' . esc_html( $about ) ); } } $out .= self::p( esc_html__( 'Tell us about any allergy when you book. There is a box for it on the form.', 'flexatech-table-reservations' ) ); return $out . self::book_line( $links ); } /** * @param array $links */ private static function about( array $links ): string { return self::p( esc_html__( '[Who you are and how the restaurant started. Two or three sentences are enough.]', 'flexatech-table-reservations' ) ) . self::h( esc_html__( 'Our kitchen', 'flexatech-table-reservations' ) ) . self::p( esc_html__( '[What you cook, who cooks it and where the produce comes from.]', 'flexatech-table-reservations' ) ) . self::h( esc_html__( 'The room', 'flexatech-table-reservations' ) ) . self::p( esc_html__( '[Inside, the terrace, the bar: what it is like to sit there, and whether children and dogs are welcome.]', 'flexatech-table-reservations' ) ) . self::book_line( $links ); } /** * @param array $links * @param list,opens:string,last_seating:string}> $shifts */ private static function contact( array $links, array $shifts ): string { $out = self::h( esc_html__( 'Find us', 'flexatech-table-reservations' ) ) . self::p( esc_html__( '[Street and number]', 'flexatech-table-reservations' ) . '
' . esc_html__( '[Postcode and city]', 'flexatech-table-reservations' ) ) . self::p( esc_html__( 'Phone: [phone number]', 'flexatech-table-reservations' ) . '
' . esc_html__( 'Email: [email address]', 'flexatech-table-reservations' ) ) . self::h( esc_html__( 'Opening hours', 'flexatech-table-reservations' ) ); $hours = array_map( [ self::class, 'hours_line' ], $shifts ); $out .= self::p( [] === $hours ? esc_html__( '[Your opening hours. Add your shifts in Flexatech Table Reservations and the booking form shows the same times.]', 'flexatech-table-reservations' ) : implode( '
', array_map( 'esc_html', $hours ) ) ); return $out . self::book_line( $links ); } private static function policy(): string { return self::p( esc_html__( 'We keep your table for you, so please tell us if you cannot come. [Edit this page to match how your restaurant works.]', 'flexatech-table-reservations' ) ) . self::h( esc_html__( 'Changing or cancelling', 'flexatech-table-reservations' ) ) . self::p( esc_html__( 'Your confirmation email has a link where you can move your table to another time or cancel it. You can also call us.', 'flexatech-table-reservations' ) ) . self::h( esc_html__( 'Arriving late', 'flexatech-table-reservations' ) ) . self::p( esc_html__( 'We hold your table for [15] minutes. After that it may go to guests who are waiting.', 'flexatech-table-reservations' ) ) . self::h( esc_html__( 'Deposits and no-shows', 'flexatech-table-reservations' ) ) . self::p( esc_html__( '[If you take a deposit or keep a card on file: how much, for which parties or dates, until when it is refunded on a cancellation, and the fee for not coming. Delete this part if you do not.]', 'flexatech-table-reservations' ) ); } /** * "Dinner: Monday to Saturday, tables from 5:30 pm to 9:30 pm". * * @param array{name:string,days:list,opens:string,last_seating:string} $shift */ public static function hours_line( array $shift ): string { return sprintf( /* translators: 1: shift name, 2: days, such as "Monday to Friday", 3: first time, 4: last time a party sits down */ __( '%1$s: %2$s, tables from %3$s to %4$s', 'flexatech-table-reservations' ), $shift['name'], self::days( $shift['days'] ), self::time( $shift['opens'] ), self::time( $shift['last_seating'] ) ); } /** * Weekdays (0 Sunday to 6 Saturday) in a week that starts on Monday, with * runs of three or more days written as a range. * * @param list $days */ public static function days( array $days ): string { if ( 7 === count( array_unique( $days ) ) ) { return __( 'every day', 'flexatech-table-reservations' ); } $runs = []; foreach ( [ 1, 2, 3, 4, 5, 6, 0 ] as $day ) { if ( ! in_array( $day, $days, true ) ) { continue; } $last = array_key_last( $runs ); if ( null !== $last && end( $runs[ $last ] ) === self::before( $day ) ) { $runs[ $last ][] = $day; } else { $runs[] = [ $day ]; } } $parts = []; foreach ( $runs as $run ) { if ( count( $run ) >= 3 ) { /* translators: 1: first weekday, 2: last weekday */ $parts[] = sprintf( __( '%1$s to %2$s', 'flexatech-table-reservations' ), self::weekday( $run[0] ), self::weekday( (int) end( $run ) ) ); } else { foreach ( $run as $day ) { $parts[] = self::weekday( $day ); } } } return implode( ', ', $parts ); } /** The weekday before this one in a week from Monday to Sunday; Monday has none. */ private static function before( int $day ): int { return match ( $day ) { 1 => -1, 0 => 6, default => $day - 1, }; } private static function weekday( int $day ): string { global $wp_locale; return isset( $wp_locale ) ? (string) $wp_locale->get_weekday( $day ) : gmdate( 'l', gmmktime( 0, 0, 0, 1, 4 + $day, 1970 ) ); } /** "HH:MM" in the site's time format. */ private static function time( string $time ): string { $at = DateTimeImmutable::createFromFormat( '!H:i', substr( $time, 0, 5 ), new DateTimeZone( 'UTC' ) ); if ( false === $at ) { return $time; } return (string) wp_date( (string) get_option( 'time_format', 'g:i a' ), $at->getTimestamp(), new DateTimeZone( 'UTC' ) ); } /** * @param array $links */ private static function book_line( array $links ): string { if ( ! isset( $links['booking'] ) ) { return ''; } return self::p( self::a( $links['booking'], __( 'Book a table', 'flexatech-table-reservations' ) ) ); } /** A paragraph block around HTML that is already escaped. */ private static function p( string $html ): string { return "\n

{$html}

\n\n\n"; } /** A level 2 heading block around text that is already escaped. */ private static function h( string $html ): string { return "\n

{$html}

\n\n\n"; } private static function a( string $url, string $text ): string { return '' . esc_html( $text ) . ''; } }