diff --git a/includes/activitypub/transformer/class-my-calendar.php b/includes/activitypub/transformer/class-my-calendar.php new file mode 100644 index 0000000..a041374 --- /dev/null +++ b/includes/activitypub/transformer/class-my-calendar.php @@ -0,0 +1,123 @@ +wp_object->ID, '_mc_event_id', true ); + $this->mc_event = mc_get_event( $mc_event_id ); + + $this->mc_event_schema = mc_event_schema( $this->mc_event ); + } + + + /** + * Formats time from the plugin to the activitypub standard + */ + private function convert_time( $date_string, $time_string ): string { + // Create a DateTime object with the given date, time, and timezone. + $datetime = new DateTime( $date_string . ' ' . $time_string ); + + // Set the timezone for proper formatting. + $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); + + // Format the DateTime object as 'Y-m-d\TH:i:s\Z'. + $formatted_date = $datetime->format( 'Y-m-d\TH:i:s\Z' ); + return $formatted_date; + } + /** + * Get the start time from the events metadata. + */ + public function get_start_time(): string { + return $this->convert_time( $this->mc_event->event_begin, $this->mc_event->event_time); + } + + /** + * Get the end time from the events metadata. + */ + public function get_end_time(): ?string { + return $this->convert_time( $this->mc_event->event_end, $this->mc_event->event_endtime); + } + + /** + * Get the event location. + * + * @return Place|null The place/venue if one is set. + */ + public function get_location(): ?Place { + if ( array_key_exists('location', $this->mc_event_schema ) && $this->mc_event_schema['location']['@type'] == 'Place' ) { + $mc_place = $this->mc_event_schema['location']; + + $place = new Place(); + $place->set_name( $mc_place['name'] ); + $place->set_url( $mc_place['url'] ); + $place->set_address( $mc_place['address'] ); + + if ( ! empty( $mc_place['geo'] ) ) { + $place->set_latitude( $mc_place['geo']['latitude'] ); + $place->set_longitude( $mc_place['geo']['longitude'] ); + } + return $place; + } + return null; + } + + /** + * Get status of the event + * + * @return string status of the event + */ + public function get_status(): ?string { + return 'CONFIRMED'; # my-calender doesn't implement canceled events. + } + + + public function to_object(): Event { + $activitypub_object = parent::to_object(); + + return $activitypub_object; + } +} diff --git a/includes/class-setup.php b/includes/class-setup.php index 39a4766..fc742e5 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -128,6 +128,7 @@ class Setup { '\ActivityPub_Event_Bridge\Plugins\GatherPress', '\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar', '\ActivityPub_Event_Bridge\Plugins\VS_Event_List', + '\ActivityPub_Event_Bridge\Plugins\My_Calendar', ); /** diff --git a/includes/plugins/class-my-calendar.php b/includes/plugins/class-my-calendar.php new file mode 100644 index 0000000..4959984 --- /dev/null +++ b/includes/plugins/class-my-calendar.php @@ -0,0 +1,63 @@ +