'yacht_booking', 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_booking_status', 'value' => 'cancelled', 'compare' => '!=', ), ), ) ); $site_name = get_bloginfo( 'name' ); $domain = wp_parse_url( home_url(), PHP_URL_HOST ); header( 'Content-Type: text/calendar; charset=utf-8' ); header( 'Content-Disposition: inline; filename="yachts-all.ics"' ); header( 'Cache-Control: no-cache, must-revalidate' ); $lines = array(); $lines[] = 'BEGIN:VCALENDAR'; $lines[] = 'VERSION:2.0'; $lines[] = 'PRODID:-//YachtBooking//NONSGML v1.0//PL'; $lines[] = 'CALSCALE:GREGORIAN'; $lines[] = 'METHOD:PUBLISH'; $lines[] = 'X-WR-CALNAME:' . self::escape_ical( sprintf( /* translators: %s: site name */ __( 'Wszystkie jachty - %s', 'yacht-booking' ), $site_name ) ); $lines[] = 'X-WR-TIMEZONE:Europe/Warsaw'; foreach ( $bookings as $booking ) { // Anti-loop: pomiń eventy które zostały zaimportowane z globalnego GCal. $source = get_post_meta( $booking->ID, '_booking_source', true ); if ( ICal_Import::GLOBAL_IMPORT_SOURCE === $source ) { continue; } $yacht_id = (int) Booking::get_yacht_id( $booking->ID ); if ( ! $yacht_id ) { continue; } $yacht = get_post( $yacht_id ); if ( ! $yacht ) { continue; } $start = Booking::get_start_date( $booking->ID ); $end = Booking::get_end_date( $booking->ID ); $status = Booking::get_status( $booking->ID ); $name = Booking::get_customer_name( $booking->ID ); if ( ! $start || ! $end ) { continue; } // iCal DTEND for all-day events is exclusive. $end_exclusive = gmdate( 'Ymd', strtotime( $end . ' +1 day' ) ); $created = get_the_date( 'Ymd\THis\Z', $booking ); // Prefiks nazwy jachtu — kluczowy dla późniejszego importu po prefiksie. $summary = sprintf( '%s - %s', $yacht->post_title, $name ); if ( 'pending' === $status ) { $summary = '[' . __( 'Oczekująca', 'yacht-booking' ) . '] ' . $summary; } $lines[] = 'BEGIN:VEVENT'; $lines[] = 'UID:booking-' . $booking->ID . '@' . $domain; $lines[] = 'DTSTART;VALUE=DATE:' . gmdate( 'Ymd', strtotime( $start ) ); $lines[] = 'DTEND;VALUE=DATE:' . $end_exclusive; $lines[] = 'DTSTAMP:' . gmdate( 'Ymd\THis\Z' ); $lines[] = 'CREATED:' . $created; $lines[] = 'SUMMARY:' . self::escape_ical( $summary ); $lines[] = 'STATUS:CONFIRMED'; $lines[] = 'TRANSP:OPAQUE'; $lines[] = 'END:VEVENT'; } $lines[] = 'END:VCALENDAR'; echo implode( "\r\n", $lines ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- iCal format exit; } /** * Escape iCal text value * * @param string $text Text. * @return string */ private static function escape_ical( $text ) { $text = str_replace( '\\', '\\\\', $text ); $text = str_replace( ',', '\\,', $text ); $text = str_replace( ';', '\\;', $text ); $text = str_replace( "\n", '\\n', $text ); return $text; } }