course_id, $inv->unit_id, $inv->occurrence_id, 0, 0, 0, $inv->id, array( 'recipient.first_name' => $first, 'message.details' => $details, ), array( 'rsvp_token' => $token ) ); $parts = Renderer::resolve( array( 'subject' => $text['subject'], 'body' => $text['body'], 'format' => (int) ( $text['format'] ?? 2 ), ), $ctx ); $subject = $parts['subject']; $html = $parts['body'] . self::footer( $user_id, $token ); } else { $values = InvitationTexts::values( $inv, $first, $lang ); $facts = InvitationTexts::facts( $inv, $lang ); $body = InvitationTexts::fill( $text['body'], $values ); $paras = preg_split( '/\n{2,}/', trim( $body ) ); $html = ''; foreach ( is_array( $paras ) ? $paras : array( $body ) as $para ) { $html .= '
' . nl2br( esc_html( trim( $para ) ) ) . '
'; } if ( '' !== $facts['when'] && ! str_contains( $text['body'], '{when}' ) ) { /* translators: %s: date and time of the lesson. */ $html .= '' . esc_html( sprintf( __( 'When: %s', 'rooster-lms' ), $facts['when'] ) ) . '
'; } $html .= self::attachments( $inv ); $html .= self::buttons( $inv, $token ); $html .= self::footer( $user_id, $token ); $html .= '' . esc_html( wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ) ) . '
'; $subject = InvitationTexts::fill( $text['subject'], $values ); } if ( $reminder ) { /* translators: %s: the invitation's subject. */ $subject = sprintf( __( 'Reminder: %s', 'rooster-lms' ), $subject ); /* translators: shown at the top of a reminder to answer an invitation. */ $html = '' . esc_html__( 'We have not had your answer yet. Please let us know whether you will attend.', 'rooster-lms' ) . '
' . $html; } $html = Services::branded_renderer()->render( 0, $lang, $subject, $html ); if ( $log > 0 && Tracking::on() ) { $html = Tracking::instrument( $html, $log ); } return array( 'subject' => $subject, 'html' => $html, 'headers' => self::headers( $user_id, $token ), ); } ); } public static function subject( Invitation $inv, string $lang ): string { return Switcher::with( $lang, static function () use ( $inv, $lang ): string { $text = InvitationTexts::for_language( $inv, $lang ); if ( isset( $text['template_id'] ) ) { $ctx = new Context( 0, $lang, 0, $inv->course_id, $inv->unit_id, $inv->occurrence_id, 0, 0, 0, $inv->id, array( 'recipient.first_name' => '' ) ); return Renderer::resolve( array( 'subject' => $text['subject'], 'body' => '', 'format' => (int) ( $text['format'] ?? 2 ), ), $ctx )['subject']; } return InvitationTexts::fill( $text['subject'], InvitationTexts::values( $inv, '', $lang ) ); } ); } public static function preview( \WP_User $user, string $lang ): ?array { $id = (int) Db::value( 'SELECT /* outside-tx */ id FROM %i WHERE kind = %d ORDER BY id DESC LIMIT 1', Db::table( 'invitations' ), InvitationKind::RSVP->value ); $inv = InvitationRepository::get( $id ); return null === $inv ? null : self::message( $inv, (int) $user->ID, (string) $user->first_name, $lang, '' ); } public static function headers( int $user_id, string $token ): array { if ( $user_id > 0 ) { return Unsubscribe::headers( $user_id ); } if ( '' === $token ) { return array(); } return array( 'List-Unsubscribe: <' . esc_url_raw( RsvpRoute::stop_url( $token ) ) . '>', 'List-Unsubscribe-Post: List-Unsubscribe=One-Click', ); } public static function buttons( Invitation $inv, string $token ): string { $font = 'font-family:Arial,Helvetica,sans-serif;'; if ( ! $inv->asks() ) { $url = $inv->unit_id > 0 ? Links::unit( $inv->unit_id, $inv->course_id ) : Urls::course_url( $inv->course_id, Switcher::current() ); return '' === $url ? '' : '' . esc_html__( 'See the lesson', 'rooster-lms' ) . '
'; } $colours = array( 'yes' => '#1a7f37', 'no' => '#b32d2e', 'maybe' => '#646970', ); $html = ''; foreach ( RsvpAnswer::offered( $inv->rsvp ) as $answer ) { $url = '' === $token ? home_url( '/' ) : RsvpRoute::url( $token, $answer ); $html .= '' . esc_html( $answer->button() ) . ''; } $html .= '
'; $until = RsvpService::closes_at( $inv ); if ( '' !== $until ) { /* translators: %s: date and time. */ $html .= '' . esc_html( sprintf( __( 'You can change your answer until %s.', 'rooster-lms' ), (string) wp_date( (string) get_option( 'date_format', 'j F Y' ) . ' ' . (string) get_option( 'time_format', 'H:i' ), (int) strtotime( $until . ' UTC' ) ) ) ) . '
'; } return $html; } private static function attachments( Invitation $inv ): string { if ( array() === $inv->attachment_ids ) { return ''; } $font = 'font-family:Arial,Helvetica,sans-serif;'; $items = ''; _prime_post_caches( $inv->attachment_ids, false, true ); foreach ( $inv->attachment_ids as $id ) { $post = get_post( $id ); $url = $post instanceof \WP_Post && 'attachment' === $post->post_type && ! ProtectedFiles::is_protected( (int) $id ) ? (string) wp_get_attachment_url( $id ) : ''; if ( '' === $url ) { continue; } $title = trim( (string) get_the_title( $post ) ); $items .= '' . esc_html__( 'Programme and documents:', 'rooster-lms' ) . '
' . esc_html__( 'You get this invitation because you agreed to hear about our lessons and events.', 'rooster-lms' ); if ( '' !== $url ) { $html .= ' ' . esc_html__( 'Stop these e-mails', 'rooster-lms' ) . ''; } return $html . '
'; } }