PATH:
home
/
ediuae
/
petalwellnessspa.com
/
wp-content
/
plugins
/
simply-schedule-appointments
/
includes
<?php /** * Simply Schedule Appointments Ics Exporter. * * @since 0.0.3 * @package Simply_Schedule_Appointments */ /** * Simply Schedule Appointments Ics Exporter. * * @since 0.0.3 */ class SSA_Ics_Exporter { /** * ICS template. * * @var string */ public $template = 'customer'; /** * Appointments list to export * * @var array */ protected $appointments = array(); /** * File path * * @var string */ protected $file_path = ''; /** * UID prefix. * * @var string */ protected $uid_prefix = 'ssa_'; /** * End of line. * * @var string */ protected $eol = "\r\n"; /** * Get appointment .ics * * @param SSA_Appointment_Object $appointment Booking data. * @param string $template the ics template to use. * * @return array an array containing the appointment data and headers. */ public function get_ics_for_appointment( $appointment, $template = 'customer' ) { $this->appointments = array( $appointment ); return $this->get_ics( $this->appointments, $template ); } /** * Get .ics feed for appointments. * * @param array $appointments an array of appointments objects. * @param string $template the ics template to use. * * @return array|null an array containing the appointment data and headers if there are appointments. Null if no appointments. */ public function get_ics_feed( $appointments, $template = 'customer' ) { if ( empty( $appointments ) ) { return null; } if ( ! is_array( $appointments ) ) { $appointments = array( $appointments ); } $this->appointments = $appointments; $sitename = get_bloginfo( 'name' ); return $this->get_ics( $this->appointments, $template, $sitename ); } /** * Get .ics for appointments. * * @param array $appointments Array with SSA_Appointment_Object objects. * @param string $template the ics template to use. * @param string $filename .ics filename. * * @return string .ics path */ public function get_ics( $appointments, $template = 'customer', $filename = '' ) { $this->appointments = $appointments; $this->template = $template; if ( '' === $filename ) { $filename = 'appointment-' . time() . '-' . wp_hash( wp_json_encode( $this->appointments['0']->id ) . $this->template ); } // Create the .ics. $ics = $this->generate(); return array( 'data' => $ics, 'headers' => array( 'Content-Disposition' => 'attachment; filename="' . $filename . '.ics"', 'Content-Type' => 'text/calendar; charset=utf-8', ), ); } /** * Format the date * * @param int $timestamp Timestamp to format. * @param SSA_Appointment_Object $appointment Booking object. * * @return string Formatted date for ICS. */ protected function format_date( $timestamp, $appointment = null ) { $pattern = 'Ymd\THis'; if ( $appointment ) { $pattern = ( $appointment->is_all_day() ) ? 'Ymd' : $pattern; } $formatted_date = gmdate( $pattern, $timestamp ); $formatted_date .= 'Z'; // Zulu (UTC). return $formatted_date; } /** * Sanitize strings for .ics * * @param string $string String to sanitize. * * @return string */ protected function sanitize_string( $string ) { $clear_map = array( '</p>' => "</p>\r\n", '<br />' => "\r\n", '<br>' => "\r\n", '<br/>' => "\r\n", ); $string = str_replace( array_keys( $clear_map ), array_values( $clear_map ), $string ); $string = wp_strip_all_tags( $string ); $string = preg_replace( '/([\,;])/', '\\\$1', $string ); $string = str_replace( "\n\n\n", "\n\n", $string ); $string = str_replace( "\n", '\n', $string ); $string = sanitize_text_field( $string ); $string = html_entity_decode( $string, ENT_QUOTES | ENT_XML1, 'UTF-8' ); return $string; } /** * Generate the .ics content * * @return string */ protected function generate() { $settings = ssa()->settings->get(); $sitename = $settings['global']['company_name']; // Set the ics data. $ics = 'BEGIN:VCALENDAR' . $this->eol; $ics .= 'VERSION:2.0' . $this->eol; $ics .= 'PRODID:-//SSA//Simply Schedule Appointments ' . Simply_Schedule_Appointments::VERSION . '//EN' . $this->eol; $ics .= 'CALSCALE:GREGORIAN' . $this->eol; $ics .= 'X-ORIGINAL-URL:' . $this->sanitize_string( home_url( '/' ) ) . $this->eol; $ics .= 'X-WR-CALDESC:' . $this->sanitize_string( sprintf( __( 'Appointments from %s', 'simply-schedule-appointments' ), $sitename ) ) . $this->eol; $ics .= 'TRANSP:' . 'OPAQUE' . $this->eol; foreach ( $this->appointments as $appointment ) { if ( in_array( $this->template, array( 'customer', 'staff' ) ) ) { $url = $this->template === 'staff' ? ssa()->wp_admin->url( 'ssa/appointments' ) : ""; $summary = $appointment->get_title( $this->template ); $description = $appointment->get_description( $this->template ); $date_prefix = ( $appointment->is_all_day() ) ? ';VALUE=DATE:' : ':'; } $ics .= 'BEGIN:VEVENT' . $this->eol; $ics .= 'UID:' . $this->uid_prefix . $appointment->id . $this->template . $this->eol; $ics .= 'DTSTAMP:' . $this->format_date( time() ) . $this->eol; $location = $appointment->get_location( $this->template ); if ( ! empty( $location ) ) { $ics .= 'LOCATION:' . $location . $this->eol; } else { $ics .= 'LOCATION:' . $this->eol; } $ics .= 'DESCRIPTION:' . $this->sanitize_string( $description ) . $this->eol; $ics .= 'URL;VALUE=URI:' . $this->sanitize_string( $url ) . $this->eol; $ics .= 'SUMMARY:' . $this->sanitize_string( $summary ) . $this->eol; $ics .= 'DTSTART' . $date_prefix . $this->format_date( $appointment->start_date_timestamp, $appointment ) . $this->eol; $ics .= 'DTEND' . $date_prefix . $this->format_date( $appointment->end_date_timestamp, $appointment ) . $this->eol; $ics .= 'END:VEVENT' . $this->eol; } $ics .= 'END:VCALENDAR'; return $ics; } }
[-] class-settings.php
[edit]
[-] class-hooks.php
[edit]
[-] class-availability-query.php
[edit]
[-] class-appointment-model.php
[edit]
[-] class-beaver-builder.php
[edit]
[-] class-web-meetings.php
[edit]
[-] class-availability-model.php
[edit]
[-] class-recipient-admin.php
[edit]
[-] class-recipient-customer.php
[edit]
[-] class-constants.php
[edit]
[-] class-async-action-model.php
[edit]
[-] class-support.php
[edit]
[-] class-google-calendar-client.php
[edit]
[+]
..
[-] class-capabilities.php
[edit]
[-] class-encryption.php
[edit]
[-] class-availability-cache-invalidation.php
[edit]
[-] class-calendar-events-settings.php
[edit]
[-] class-settings-global.php
[edit]
[-] class-translation.php
[edit]
[-] class-cli.php
[edit]
[-] class-missing.php
[edit]
[-] class-action-scheduler.php
[edit]
[-] class-templates-api.php
[edit]
[-] class-blackout-dates.php
[edit]
[-] class-calendar-events-object.php
[edit]
[-] class-divi.php
[edit]
[-] class-templates.php
[edit]
[-] class-wp-admin.php
[edit]
[-] class-appointment-factory.php
[edit]
[-] class-scheduling-max-per-day.php
[edit]
[-] class-notifications-api.php
[edit]
[-] class-shortcodes.php
[edit]
[-] class-validation.php
[edit]
[-] class-resource-group-object-factory.php
[edit]
[-] class-payment-object.php
[edit]
[-] class-locale.php
[edit]
[-] class-ics-exporter.php
[edit]
[-] class-filesystem.php
[edit]
[-] class-recipient-shared.php
[edit]
[-] class-availability-schedule.php
[edit]
[-] class-block-upcoming-appointments.php
[edit]
[-] class-elementor.php
[edit]
[-] class-appointment-meta-model.php
[edit]
[-] class-revision-meta-model.php
[edit]
[+]
divi
[-] class-notifications.php
[edit]
[-] class-upgrade.php
[edit]
[-] class-utils.php
[edit]
[-] class-availability-functions.php
[edit]
[-] class-external-calendar-api.php
[edit]
[-] class-csv-exporter.php
[edit]
[-] class-external-google-calendar-api.php
[edit]
[-] class-twig-extension.php
[edit]
[-] class-bootstrap.php
[edit]
[-] class-notices.php
[edit]
[-] class-availability-schedule-factory.php
[edit]
[-] class-blackout-dates-settings.php
[edit]
[-] class-support-status.php
[edit]
[-] class-block-booking.php
[edit]
[-] class-advanced-scheduling-availability.php
[edit]
[-] class-exception.php
[edit]
[-] class-styles-settings.php
[edit]
[-] class-forms.php
[edit]
[-] class-recipient-staff.php
[edit]
[+]
beaver-builder
[-] class-users.php
[edit]
[-] class-sequence-factory.php
[edit]
[+]
third-party
[-] class-locales.php
[edit]
[-] class-db-model.php
[edit]
[-] class-db.php
[edit]
[-] class-availability-default.php
[edit]
[-] class-staff-settings.php
[edit]
[-] class-notification-model.php
[edit]
[-] class-settings-installed.php
[edit]
[-] class-appointment-object.php
[edit]
[-] class-notices-api.php
[edit]
[-] class-translation-settings.php
[edit]
[-] class-support-status-api.php
[edit]
[-] class-notices-data.php
[edit]
[-] class-appointment-type-object.php
[edit]
[-] class-appointment-type-object-factory.php
[edit]
[-] class-availability-block-factory.php
[edit]
[-] class-recipient.php
[edit]
[-] class-revision-model.php
[edit]
[-] class-customers.php
[edit]
[-] class-settings-api.php
[edit]
[-] class-cache.php
[edit]
[-] class-availability-detective-case.php
[edit]
[-] class-styles.php
[edit]
[-] class-capacity-settings.php
[edit]
[-] class-gcal-exporter.php
[edit]
[-] class-advanced-scheduling-settings.php
[edit]
[-] class-appointment-type-model.php
[edit]
[-] class-notifications-settings.php
[edit]
[-] class-period.php
[edit]
[-] class-external-api.php
[edit]
[-] class-error-notices.php
[edit]
[-] class-availability-cache.php
[edit]
[-] class-developer-settings.php
[edit]
[-] class-dashboard-upcoming-appointments-widget.php
[edit]
[-] class-availability-external-model.php
[edit]
[-] class-availability-block.php
[edit]
[-] class-customer-information.php
[edit]
[+]
elementor
[-] class-appointment-type-label-model.php
[edit]
[-] class-embed-booking-app-api.php
[edit]
[+]
lib
[-] class-sequence.php
[edit]
[-] class-debug.php
[edit]
[-] class-appointment-types-db.php
[edit]