From f99f009e2e55fd3f3f12d97f32c96adf7eda4520 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 11:42:52 +0200 Subject: [PATCH 01/42] splitted up format time function --- .../activitypub/transformer/class-event.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 893778f..f872dd6 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -161,11 +161,19 @@ abstract class Event extends Post { /** * Compose a human readable formatted start time. - * - * @param bool $is_start_time Whether format the events start or end time. */ - protected function format_time( $is_start_time = true ) { - $time = $is_start_time ? $this->get_start_time() : $this->get_end_time(); + protected function format_start_time(): ?string { + return $this->format_time( $this->get_start_time() ); + } + + /** + * Compose a human readable formatted end time. + */ + protected function format_end_time(): ?string { + return $this->format_time( $this->get_end_time() ); + } + + static protected function format_time( $time ) { if ( is_null( $time ) ) { return ''; } @@ -228,8 +236,8 @@ abstract class Event extends Post { remove_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ) ); $category = $this->format_category(); - $start_time = $this->format_time(); - $end_time = $this->format_time( false ); + $start_time = $this->format_start_time(); + $end_time = $this->format_end_time(); $address = $this->format_address(); $formatted_items = array(); -- 2.39.5 From 7c9424526dfa703456ebece817a8ae80442526ff Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 11:43:59 +0200 Subject: [PATCH 02/42] improved readability of get_summary by using ternary operator --- includes/activitypub/transformer/class-gatherpress.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index 81f2f22..397125c 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -158,13 +158,9 @@ final class GatherPress extends Event { * @return string $summary The custom event summary. */ public function get_summary(): string { - if ( $this->wp_object->excerpt ) { - $excerpt = $this->wp_object->post_excerpt; - } elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { - $excerpt = get_post_meta( $this->wp_object->ID, 'event-summary', true ); - } else { - $excerpt = $this->get_content(); - } + $excerpt = $this->wp_object->post_excerpt + ?: get_post_meta( $this->wp_object->ID, 'event-summary', true ) + ?: $this->get_content(); $address = get_post_meta( $this->wp_object->ID, 'event-location', true ); $start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true ); -- 2.39.5 From f0b73d86744503816a7c8a9be19773443b7d8c84 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 11:44:14 +0200 Subject: [PATCH 03/42] duplicated code --- includes/activitypub/transformer/class-vs-event-list.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index aef6470..e9dd247 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -113,10 +113,8 @@ final class VS_Event_List extends Event_Transformer { protected function get_excerpt(): ?string { if ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { return get_post_meta( $this->wp_object->ID, 'event-summary', true ); - } elseif ( $this->wp_object->excerpt ) { - return $this->wp_object->post_excerpt; } else { - return null; + return parent::extract_excerpt(); // todo naming not uniform } } } -- 2.39.5 From 39632560ff60c3c2c64ea7f5d36b03745ff6fd2e Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 11:44:21 +0200 Subject: [PATCH 04/42] added comments --- includes/activitypub/transformer/class-event.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index f872dd6..1d86ad7 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -226,6 +226,9 @@ abstract class Event extends Post { * @return string $summary The custom event summary. */ public function get_summary(): ?string { + // this will result in race conditions and is imho a bad idea + // - either use the (userdefined) template of the activitypub plugin as it is + // - or implement our own templating (based on the activitypub plugin templates / by reusing their code heavily) add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2 ); $excerpt = $this->extract_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. @@ -312,7 +315,7 @@ abstract class Event extends Post { $activitypub_object->set_to( array( 'https://www.w3.org/ns/activitystreams#Public', - $this->get_actor_object()->get_followers(), + $this->get_actor_object()->get_followers(), // this fails on my machine ) ); -- 2.39.5 From c469b7a00ea2ce67d0256b25ed390ccfa3df2c8c Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 11:44:47 +0200 Subject: [PATCH 05/42] made format_time() private --- includes/activitypub/transformer/class-event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 1d86ad7..8a1526a 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -173,7 +173,7 @@ abstract class Event extends Post { return $this->format_time( $this->get_end_time() ); } - static protected function format_time( $time ) { + static private function format_time( $time ) { if ( is_null( $time ) ) { return ''; } -- 2.39.5 From 516bfd33d8a9efac873ea1dc41f9ce4e0f8591d5 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 11:45:17 +0200 Subject: [PATCH 06/42] fixed wrong nullable type declaration --- includes/activitypub/transformer/class-event.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 8a1526a..f7b5b29 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -162,14 +162,14 @@ abstract class Event extends Post { /** * Compose a human readable formatted start time. */ - protected function format_start_time(): ?string { + protected function format_start_time(): string { return $this->format_time( $this->get_start_time() ); } /** * Compose a human readable formatted end time. */ - protected function format_end_time(): ?string { + protected function format_end_time(): string { return $this->format_time( $this->get_end_time() ); } -- 2.39.5 From a66dc74577eb44baabfee489f53f3ef84dae7e38 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 12:52:17 +0200 Subject: [PATCH 07/42] added comments about removing some old stuff --- includes/activitypub/transformer/class-events-manager.php | 6 +++--- includes/activitypub/transformer/class-gatherpress.php | 4 ++-- includes/activitypub/transformer/class-vs-event-list.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 8d7bfd6..df70ecb 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -45,7 +45,7 @@ final class Events_Manager extends Event_Transformer { * @access public * @return string Widget name. */ - public function get_transformer_name() { + public function get_transformer_name() { // todo can we remove this or is this in use? return 'activitypub-event-transformers/events-manager'; } @@ -58,7 +58,7 @@ final class Events_Manager extends Event_Transformer { * @access public * @return string Widget title. */ - public function get_transformer_label() { + public function get_transformer_label() { // todo can we remove this or is this in use? return 'Events Manager'; } @@ -71,7 +71,7 @@ final class Events_Manager extends Event_Transformer { * @access public * @return array Widget categories. */ - public static function get_supported_post_types() { + public static function get_supported_post_types() { // todo can we remove this or is this in use? return array(); } diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index 397125c..803b799 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -29,7 +29,7 @@ final class GatherPress extends Event { * * @var Event */ - protected $ap_object; + protected $ap_object; // todo can we remove this or is this in use? /** * The current GatherPress Event object. @@ -69,7 +69,7 @@ final class GatherPress extends Event { * @access public * @return array Widget categories. */ - public static function get_supported_post_types() { + public static function get_supported_post_types() { // todo can we remove this or is this in use? return array( GatherPress_Event::POST_TYPE ); } diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index e9dd247..95556b8 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -28,7 +28,7 @@ final class VS_Event_List extends Event_Transformer { * * @var Event */ - protected $ap_object; + protected $ap_object; // todo can we remove this or is this in use? /** * Get the event location. -- 2.39.5 From b39f9997ae30e28be54581c5fdb95f832bc92196 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 13:25:37 +0200 Subject: [PATCH 08/42] making php_codesniffer happy --- includes/activitypub/transformer/class-event.php | 13 ++++++++----- .../activitypub/transformer/class-vs-event-list.php | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index f7b5b29..9c3f49c 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -173,7 +173,10 @@ abstract class Event extends Post { return $this->format_time( $this->get_end_time() ); } - static private function format_time( $time ) { + /** + * Compose a human readable formatted time from the parameter $time. + */ + private static function format_time( $time ) { if ( is_null( $time ) ) { return ''; } @@ -226,9 +229,9 @@ abstract class Event extends Post { * @return string $summary The custom event summary. */ public function get_summary(): ?string { - // this will result in race conditions and is imho a bad idea - // - either use the (userdefined) template of the activitypub plugin as it is - // - or implement our own templating (based on the activitypub plugin templates / by reusing their code heavily) + // this will result in race conditions and is imho a bad idea. + // - either use the (userdefined) template of the activitypub plugin as it is. + // - or implement our own templating (based on the activitypub plugin templates / by reusing their code heavily). add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2 ); $excerpt = $this->extract_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. @@ -315,7 +318,7 @@ abstract class Event extends Post { $activitypub_object->set_to( array( 'https://www.w3.org/ns/activitystreams#Public', - $this->get_actor_object()->get_followers(), // this fails on my machine + $this->get_actor_object()->get_followers(), // this fails on my machine. ) ); diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index 95556b8..fafb750 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -114,7 +114,7 @@ final class VS_Event_List extends Event_Transformer { if ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { return get_post_meta( $this->wp_object->ID, 'event-summary', true ); } else { - return parent::extract_excerpt(); // todo naming not uniform + return parent::extract_excerpt(); // todo naming not uniform. } } } -- 2.39.5 From 608e18f8c192f78f2271b62153a364e5b1f85c49 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 13:45:58 +0200 Subject: [PATCH 09/42] removed unused stuff --- .../transformer/class-events-manager.php | 39 ------------------- .../transformer/class-gatherpress.php | 7 ---- .../transformer/class-vs-event-list.php | 6 --- 3 files changed, 52 deletions(-) diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index df70ecb..7d217ee 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -36,45 +36,6 @@ final class Events_Manager extends Event_Transformer { */ protected $em_event; - /** - * Get transformer name. - * - * Retrieve the transformers name. - * - * @since 1.0.0 - * @access public - * @return string Widget name. - */ - public function get_transformer_name() { // todo can we remove this or is this in use? - return 'activitypub-event-transformers/events-manager'; - } - - /** - * Get transformer title. - * - * Retrieve the transformers label. - * - * @since 1.0.0 - * @access public - * @return string Widget title. - */ - public function get_transformer_label() { // todo can we remove this or is this in use? - return 'Events Manager'; - } - - /** - * Get supported post types. - * - * Retrieve the list of supported WordPress post types this transformer widget can handle. - * - * @since 1.0.0 - * @access public - * @return array Widget categories. - */ - public static function get_supported_post_types() { // todo can we remove this or is this in use? - return array(); - } - /** * Returns whether the even is online * diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index 803b799..e4d0cdb 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -24,13 +24,6 @@ use GatherPress\Core\Event as GatherPress_Event; */ final class GatherPress extends Event { - /** - * The target ActivityPub Event object of the transformer. - * - * @var Event - */ - protected $ap_object; // todo can we remove this or is this in use? - /** * The current GatherPress Event object. * diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index fafb750..f35e3d7 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -23,12 +23,6 @@ use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transfor * @since 1.0.0 */ final class VS_Event_List extends Event_Transformer { - /** - * The target transformer ActivityPub Event object. - * - * @var Event - */ - protected $ap_object; // todo can we remove this or is this in use? /** * Get the event location. -- 2.39.5 From 20f6947bea715e1a2dc086915ee8ab9f158f0756 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 13:48:32 +0200 Subject: [PATCH 10/42] duplicated code --- includes/activitypub/transformer/class-events-manager.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 7d217ee..2b7d700 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -75,9 +75,6 @@ final class Events_Manager extends Event_Transformer { if ( $em_location->location_state ) { $address['addressRegion'] = $em_location->location_state; } - if ( $em_location->location_postcode ) { - $address['postalCode'] = $em_location->location_postcode; - } $location->set_address( $address ); return $location; @@ -124,8 +121,8 @@ final class Events_Manager extends Event_Transformer { * @return int */ public function get_remaining_attendee_capacity() { - $em_bookings = $this->em_event->get_bookings()->get_bookings(); - $remaining_attendee_capacity = $this->em_event->event_spaces - count( $em_bookings->bookings ); + $em_bookings_count = $this->get_participant_count(); + $remaining_attendee_capacity = $this->em_event->event_spaces - $em_bookings_count; return $remaining_attendee_capacity; } -- 2.39.5 From 9be7cb2ce2d0ab30a84c34952d3b79a669284435 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 13:50:52 +0200 Subject: [PATCH 11/42] removed more unused code --- .../activitypub/transformer/class-gatherpress.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index e4d0cdb..8390d1b 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -53,19 +53,6 @@ final class GatherPress extends Event { $this->gp_venue = $this->gp_event->get_venue_information(); } - /** - * Get supported post types. - * - * Retrieve the list of supported WordPress post types this transformer widget can handle. - * - * @since 1.0.0 - * @access public - * @return array Widget categories. - */ - public static function get_supported_post_types() { // todo can we remove this or is this in use? - return array( GatherPress_Event::POST_TYPE ); - } - /** * Get the event location. * -- 2.39.5 From 1b4642d92e022232b3e61851100381c9afcf8f35 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 13:56:17 +0200 Subject: [PATCH 12/42] moved getting EM event into constructor --- .../transformer/class-events-manager.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 2b7d700..1735233 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -36,6 +36,20 @@ final class Events_Manager extends Event_Transformer { */ protected $em_event; + /** + * Extend the constructor, to also set the Eventsmanager objects. + * + * This is a special class object form The Events Calendar which + * has a lot of useful functions, we make use of our getter functions. + * + * @param WP_Post $wp_object The WordPress object. + * @param string $wp_taxonomy The taxonomy slug of the event post type. + */ + public function __construct( $wp_object, $wp_taxonomy ) { + parent::__construct( $wp_object, $wp_taxonomy ); + $this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' ); + } + /** * Returns whether the even is online * @@ -225,12 +239,7 @@ final class Events_Manager extends Event_Transformer { * @return Activitypub\Activity\Event */ public function to_object(): Event { - $this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' ); - $activitypub_object = new Event(); - - $activitypub_object = $this->transform_object_properties( $activitypub_object ); - - $activitypub_object->set_external_participation_url( $this->get_url() ); + $activitypub_object = parent::to_object(); return $activitypub_object; } -- 2.39.5 From 7d979a1c5e5e5b7449671219361e291619cbc1bf Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 13:57:01 +0200 Subject: [PATCH 13/42] removed trivial to_object functions --- .../transformer/class-events-manager.php | 11 ----------- .../activitypub/transformer/class-gatherpress.php | 12 ------------ .../transformer/class-the-events-calendar.php | 13 ------------- 3 files changed, 36 deletions(-) diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 1735233..8fbd2f1 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -232,15 +232,4 @@ final class Events_Manager extends Event_Transformer { protected function get_name(): string { return $this->em_event->event_name; } - - /** - * Transform the WordPress Object into an ActivityPub Object. - * - * @return Activitypub\Activity\Event - */ - public function to_object(): Event { - $activitypub_object = parent::to_object(); - - return $activitypub_object; - } } diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index 8390d1b..db994ca 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -165,16 +165,4 @@ final class GatherPress extends Event { public function get_is_online(): bool { return $this->gp_event->maybe_get_online_event_link() ? true : false; } - - - /** - * Transform the WordPress Object into an ActivityPub Object. - * - * @return Activitypub\Activity\Event - */ - public function to_object(): Event_Object { - $activitypub_object = parent::to_object(); - - return $activitypub_object; - } } diff --git a/includes/activitypub/transformer/class-the-events-calendar.php b/includes/activitypub/transformer/class-the-events-calendar.php index eea12ac..0428c66 100644 --- a/includes/activitypub/transformer/class-the-events-calendar.php +++ b/includes/activitypub/transformer/class-the-events-calendar.php @@ -196,17 +196,4 @@ final class The_Events_Calendar extends Event { return $location; } - - /** - * Extend the default event transformers to_object function. - * - * This is the heart of the ActivityPub transformer. - * - * @return Event_Object - */ - public function to_object(): Event_Object { - $activitypub_object = parent::to_object(); - - return $activitypub_object; - } } -- 2.39.5 From 228dba06ae166f709abb955209057301da7e6c7b Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 14:04:07 +0200 Subject: [PATCH 14/42] Revert "improved readability of get_summary by using ternary operator" This reverts commit 7c9424526dfa703456ebece817a8ae80442526ff. --- includes/activitypub/transformer/class-gatherpress.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index db994ca..e08f0b4 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -138,9 +138,13 @@ final class GatherPress extends Event { * @return string $summary The custom event summary. */ public function get_summary(): string { - $excerpt = $this->wp_object->post_excerpt - ?: get_post_meta( $this->wp_object->ID, 'event-summary', true ) - ?: $this->get_content(); + if ( $this->wp_object->excerpt ) { + $excerpt = $this->wp_object->post_excerpt; + } elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { + $excerpt = get_post_meta( $this->wp_object->ID, 'event-summary', true ); + } else { + $excerpt = $this->get_content(); + } $address = get_post_meta( $this->wp_object->ID, 'event-location', true ); $start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true ); -- 2.39.5 From 24844f57c1e6300d1c80ac7f8b02c840d3118601 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 15:00:13 +0200 Subject: [PATCH 15/42] remove old get_summary from gatherpress and event manager in favour of the new one in class-event --- .../transformer/class-events-manager.php | 17 ------------- .../transformer/class-gatherpress.php | 25 ------------------- 2 files changed, 42 deletions(-) diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 8fbd2f1..60f8884 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -150,23 +150,6 @@ final class Events_Manager extends Event_Transformer { return count( $em_bookings->bookings ); } - /** - * Hardcoded function for generating a summary. - */ - public function get_summary(): ?string { - if ( $this->em_event->post_excerpt ) { - $excerpt = $this->em_event->post_excerpt; - } else { - $excerpt = $this->get_content(); - } - $address = $this->em_event->get_location()->location_name; - $start_time = strtotime( $this->get_start_time() ); - $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); - $start_time_string = wp_date( $datetime_format, $start_time ); - $summary = "๐Ÿ“ {$address}\n๐Ÿ“… {$start_time_string}\n\n{$excerpt}"; - return $summary; - } - /** * Get the event link as an ActivityPub Link object, but as an associative array. * diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index e08f0b4..e8c24d8 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -129,31 +129,6 @@ final class GatherPress extends Event { return $user->get_url(); } - /** - * Create a custom summary. - * - * It contains also the most important meta-information. The summary is often used when the - * ActivityPub object type 'Event' is not supported, e.g. in Mastodon. - * - * @return string $summary The custom event summary. - */ - public function get_summary(): string { - if ( $this->wp_object->excerpt ) { - $excerpt = $this->wp_object->post_excerpt; - } elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { - $excerpt = get_post_meta( $this->wp_object->ID, 'event-summary', true ); - } else { - $excerpt = $this->get_content(); - } - - $address = get_post_meta( $this->wp_object->ID, 'event-location', true ); - $start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true ); - $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); - $start_time_string = wp_date( $datetime_format, $start_time ); - $summary = "๐Ÿ“ {$address}\n๐Ÿ“… {$start_time_string}\n\n{$excerpt}"; - return $summary; - } - /** * Get the content. */ -- 2.39.5 From 993fc2b24f9b9914cbcc6d3189b8ec537bee327a Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 15:31:07 +0200 Subject: [PATCH 16/42] phpsniffer happy --- includes/activitypub/transformer/class-event.php | 4 +++- includes/activitypub/transformer/class-events-manager.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 9c3f49c..bb35915 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -174,7 +174,9 @@ abstract class Event extends Post { } /** - * Compose a human readable formatted time from the parameter $time. + * Compose a human readable formatted time. + * + * @param ?string $time The time which needs to be formatted */ private static function format_time( $time ) { if ( is_null( $time ) ) { diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 60f8884..a760d2e 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -47,7 +47,7 @@ final class Events_Manager extends Event_Transformer { */ public function __construct( $wp_object, $wp_taxonomy ) { parent::__construct( $wp_object, $wp_taxonomy ); - $this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' ); + $this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' ); } /** -- 2.39.5 From 5fa3876c1af63a0967d56f515ae1a77ccdcc84dd Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 15:32:50 +0200 Subject: [PATCH 17/42] added comment on bloguser --- includes/activitypub/transformer/class-event.php | 2 +- includes/activitypub/transformer/class-gatherpress.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index bb35915..babd4ee 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -176,7 +176,7 @@ abstract class Event extends Post { /** * Compose a human readable formatted time. * - * @param ?string $time The time which needs to be formatted + * @param ?string $time The time which needs to be formatted. */ private static function format_time( $time ) { if ( is_null( $time ) ) { diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index e8c24d8..39292fd 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -125,7 +125,7 @@ final class GatherPress extends Event { * @return string The User-URL. */ protected function get_attributed_to(): string { - $user = new Blog(); + $user = new Blog(); // todo is this correct? feels not right. return $user->get_url(); } -- 2.39.5 From 4f61a1c97eb1cb71625fd2c520c21e8782c42bf9 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 15:45:53 +0200 Subject: [PATCH 18/42] removed link at get_content() for all event --- .../activitypub/transformer/class-event.php | 27 +++++++++++++++++++ .../transformer/class-gatherpress.php | 7 ----- .../transformer/class-the-events-calendar.php | 12 ++++++--- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index babd4ee..ac9d7d5 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -326,4 +326,31 @@ abstract class Event extends Post { return $activitypub_object; } + + /** + * Gets the template to use to generate the content of the event. + * + * @return string The Template. + */ + protected function get_post_content_template() { + return "[ap_content]\n\n[ap_hashtags]"; + + // Decide: what kind of control does the user get? + // e.g. we could give the user way more control by only overriding (some) defaults like this: + + /** + $type = \get_option( 'activitypub_post_content_type', 'content' ); + + switch ( $type ) { + case 'content': + return "[ap_content]\n\n[ap_hashtags]"; + break; + default: + return parent::get_post_content_template(); + break; + } + **/ + + } + } diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index 39292fd..4e64072 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -129,13 +129,6 @@ final class GatherPress extends Event { return $user->get_url(); } - /** - * Get the content. - */ - public function get_content(): string { - return $this->wp_object->post_content; - } - /** * Determine whether the event is online. * diff --git a/includes/activitypub/transformer/class-the-events-calendar.php b/includes/activitypub/transformer/class-the-events-calendar.php index 0428c66..fc6c673 100644 --- a/includes/activitypub/transformer/class-the-events-calendar.php +++ b/includes/activitypub/transformer/class-the-events-calendar.php @@ -127,12 +127,16 @@ final class The_Events_Calendar extends Event { * @return string The content. */ protected function get_content() { - $content = parent::get_content(); // /BeforeFirstRelease: - // * remove link at the end of the content. - // * add organizer. - // * do add Cancelled reason in the content.s + // * [X] remove link at the end of the content. + // * [ ] add organizer. + // * [ ] do add Cancelled reason in the content. + // Add Organizer: + // $this->wp_object->post_content .= organizer_string; + // rest will be handled by parent::get_content(). + + $content = parent::get_content(); return $content; } -- 2.39.5 From b4d3a7efa026d25664807e5edb33b20ae004709a Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 15:47:46 +0200 Subject: [PATCH 19/42] changed extract_excerpt to get_excerpt --- includes/activitypub/transformer/class-event.php | 4 ++-- includes/activitypub/transformer/class-vs-event-list.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index ac9d7d5..024e25a 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -126,8 +126,8 @@ abstract class Event extends Post { * * @return ?string */ - protected function extract_excerpt(): ?string { - if ( $this->wp_object->excerpt ) { + protected function get_excerpt(): ?string { + if ( $this->wp_object->post_excerpt ) { return $this->wp_object->post_excerpt; } else { return null; diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index f35e3d7..b92846c 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -108,7 +108,7 @@ final class VS_Event_List extends Event_Transformer { if ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { return get_post_meta( $this->wp_object->ID, 'event-summary', true ); } else { - return parent::extract_excerpt(); // todo naming not uniform. + return parent::get_excerpt(); } } } -- 2.39.5 From d3f16706f8886546a6370b02ed87207ce78ab461 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 15:55:32 +0200 Subject: [PATCH 20/42] added generic get_content from wp_object to class-event --- includes/activitypub/transformer/class-event.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 024e25a..86c2e64 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -353,4 +353,7 @@ abstract class Event extends Post { } + protected function get_content() { + return $this->wp_object->post_content; + } } -- 2.39.5 From ef86fb2263fa5e63dbc25f03dc964c33acf59c20 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 16:01:28 +0200 Subject: [PATCH 21/42] forgot to rename method call --- includes/activitypub/transformer/class-event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 86c2e64..1ae2306 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -235,7 +235,7 @@ abstract class Event extends Post { // - either use the (userdefined) template of the activitypub plugin as it is. // - or implement our own templating (based on the activitypub plugin templates / by reusing their code heavily). add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2 ); - $excerpt = $this->extract_excerpt(); + $excerpt = $this->get_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. $fallback_to_content = true; if ( is_null( $excerpt ) && $fallback_to_content ) { -- 2.39.5 From 57889bca3f6c765d40ba136427ca4da88256fb86 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 17:45:52 +0200 Subject: [PATCH 22/42] fixed TEC content test --- tests/test-class-plugin-the-events-calendar.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-class-plugin-the-events-calendar.php b/tests/test-class-plugin-the-events-calendar.php index c4f5f6d..089d466 100644 --- a/tests/test-class-plugin-the-events-calendar.php +++ b/tests/test-class-plugin-the-events-calendar.php @@ -109,7 +109,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( '', $event_array['content'] ); + $this->assertEquals( 'Come to my event. Let\'s connect!', $event_array['content'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertTrue( $event_array['commentsEnabled'] ); @@ -170,7 +170,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( '', $event_array['content'] ); + $this->assertEquals( 'Come to my event. Let\'s connect!', $event_array['content'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] ); @@ -197,7 +197,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( '', $event_array['content'] ); + $this->assertEquals( 'Come to my event. Let\'s connect!', $event_array['content'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] ); -- 2.39.5 From 64bf5b2a58268411473d24c09b5a44b6a623a1fb Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Sun, 29 Sep 2024 17:48:19 +0200 Subject: [PATCH 23/42] fixed events manager content test --- tests/test-class-plugin-events-manger.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-class-plugin-events-manger.php b/tests/test-class-plugin-events-manger.php index cf4bc46..0c704ed 100644 --- a/tests/test-class-plugin-events-manger.php +++ b/tests/test-class-plugin-events-manger.php @@ -85,7 +85,7 @@ class Test_Events_Manager extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Events Manager Test event', $event_array['name'] ); - $this->assertEquals( '', $event_array['content'] ); + $this->assertEquals( 'Event description', $event_array['content'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( comments_open( $event->post_id ), $event_array['commentsEnabled'] ); $this->assertEquals( comments_open( $event->post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); @@ -131,7 +131,7 @@ class Test_Events_Manager extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Events Manager Test event', $event_array['name'] ); - $this->assertEquals( '', $event_array['content'] ); + $this->assertEquals( 'Event description', $event_array['content'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'MEETING', $event_array['category'] ); @@ -174,7 +174,7 @@ class Test_Events_Manager extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Events Manager Test event', $event_array['name'] ); - $this->assertEquals( '', $event_array['content'] ); + $this->assertEquals( 'Event description', $event_array['content'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'MEETING', $event_array['category'] ); -- 2.39.5 From 66e06655c24844beb450c89ab046103e05c45ef0 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Mon, 30 Sep 2024 18:55:59 +0200 Subject: [PATCH 24/42] changed content/summary logic and removed the racecondition --- .../activitypub/transformer/class-event.php | 54 ++++++++----------- .../transformer/class-the-events-calendar.php | 21 -------- 2 files changed, 23 insertions(+), 52 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 1ae2306..6e0c828 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -231,15 +231,13 @@ abstract class Event extends Post { * @return string $summary The custom event summary. */ public function get_summary(): ?string { - // this will result in race conditions and is imho a bad idea. - // - either use the (userdefined) template of the activitypub plugin as it is. - // - or implement our own templating (based on the activitypub plugin templates / by reusing their code heavily). - add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2 ); + // todo when do we add the filter? we could add it and just keep it? + add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2); $excerpt = $this->get_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. $fallback_to_content = true; if ( is_null( $excerpt ) && $fallback_to_content ) { - $excerpt = $this->get_content(); + $excerpt = parent::get_content(); } remove_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ) ); @@ -284,10 +282,17 @@ abstract class Event extends Post { * used when converting a object, where the URL is usually appended anyway. * * @param string $template The template string. + * @param WP_Post|WP_Comment $wp_object The wp_object which was used to select the template. + * */ - public static function remove_ap_permalink_from_template( $template ) { - $template = str_replace( '[ap_permalink]', '', $template ); - $template = str_replace( '[ap_permalink type="html"]', '', $template ); + public static function remove_ap_permalink_from_template( $template, $wp_object ) { + + // we could override the template here, to get out custom template from an option. + + if ( $wp_object->post_type === "event" ) { + $template = str_replace( '[ap_permalink]', '', $template ); + $template = str_replace( '[ap_permalink type="html"]', '', $template ); + } return $template; } @@ -328,32 +333,19 @@ abstract class Event extends Post { } /** - * Gets the template to use to generate the content of the event. + * Returns the content for the ActivityPub Item with * - * @return string The Template. + * The content will be generated based on the user settings. + * + * @return string The content. */ - protected function get_post_content_template() { - return "[ap_content]\n\n[ap_hashtags]"; - - // Decide: what kind of control does the user get? - // e.g. we could give the user way more control by only overriding (some) defaults like this: - - /** - $type = \get_option( 'activitypub_post_content_type', 'content' ); - - switch ( $type ) { - case 'content': - return "[ap_content]\n\n[ap_hashtags]"; - break; - default: - return parent::get_post_content_template(); - break; - } - **/ - - } - protected function get_content() { + // /BeforeFirstRelease: + // * [ ] remove link at the end of the content. + // * [ ] add organizer. + // * [ ] do add Cancelled reason in the content. + + // return parent::get_content(); return $this->wp_object->post_content; } } diff --git a/includes/activitypub/transformer/class-the-events-calendar.php b/includes/activitypub/transformer/class-the-events-calendar.php index fc6c673..3f4b71c 100644 --- a/includes/activitypub/transformer/class-the-events-calendar.php +++ b/includes/activitypub/transformer/class-the-events-calendar.php @@ -119,27 +119,6 @@ final class The_Events_Calendar extends Event { return false; } - /** - * Returns the content for the ActivityPub Item with - * - * The content will be generated based on the user settings. - * - * @return string The content. - */ - protected function get_content() { - // /BeforeFirstRelease: - // * [X] remove link at the end of the content. - // * [ ] add organizer. - // * [ ] do add Cancelled reason in the content. - - // Add Organizer: - // $this->wp_object->post_content .= organizer_string; - // rest will be handled by parent::get_content(). - - $content = parent::get_content(); - return $content; - } - /** * Get the event location. * -- 2.39.5 From f5df3102ad42807c1a75226e8636f0b7dc371280 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Mon, 30 Sep 2024 19:07:05 +0200 Subject: [PATCH 25/42] style guide fixes --- includes/activitypub/transformer/class-event.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 6e0c828..4786bd8 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -232,7 +232,7 @@ abstract class Event extends Post { */ public function get_summary(): ?string { // todo when do we add the filter? we could add it and just keep it? - add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2); + add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2 ); $excerpt = $this->get_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. $fallback_to_content = true; @@ -281,15 +281,14 @@ abstract class Event extends Post { * This used for the summary template, because the summary usually gets, * used when converting a object, where the URL is usually appended anyway. * - * @param string $template The template string. + * @param string $template The template string. * @param WP_Post|WP_Comment $wp_object The wp_object which was used to select the template. - * */ public static function remove_ap_permalink_from_template( $template, $wp_object ) { // we could override the template here, to get out custom template from an option. - if ( $wp_object->post_type === "event" ) { + if ( 'event' === $wp_object->post_type ) { $template = str_replace( '[ap_permalink]', '', $template ); $template = str_replace( '[ap_permalink type="html"]', '', $template ); } @@ -345,7 +344,7 @@ abstract class Event extends Post { // * [ ] add organizer. // * [ ] do add Cancelled reason in the content. - // return parent::get_content(); + // return parent::get_content();? return $this->wp_object->post_content; } } -- 2.39.5 From 1a5e19f3c1f8573dc1b80fbbb6ebb9dbeadc7073 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Mon, 30 Sep 2024 19:24:32 +0200 Subject: [PATCH 26/42] added comment --- includes/activitypub/transformer/class-event.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 4786bd8..82f6bbd 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -305,6 +305,8 @@ abstract class Event extends Post { $activitypub_object = new Event_Object(); $activitypub_object = $this->transform_object_properties( $activitypub_object ); + // maybe move the following logic (till end of the function) into getter functions. + $published = \strtotime( $this->wp_object->post_date_gmt ); $activitypub_object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) ); -- 2.39.5 From ad09fa947cd3f5647918e4d69352942f9759a8a2 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Tue, 1 Oct 2024 18:58:54 +0200 Subject: [PATCH 27/42] renamed get_excerpt back to extract_excerpt --- includes/activitypub/transformer/class-event.php | 4 ++-- includes/activitypub/transformer/class-vs-event-list.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 82f6bbd..67e7541 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -126,7 +126,7 @@ abstract class Event extends Post { * * @return ?string */ - protected function get_excerpt(): ?string { + protected function extract_excerpt(): ?string { if ( $this->wp_object->post_excerpt ) { return $this->wp_object->post_excerpt; } else { @@ -233,7 +233,7 @@ abstract class Event extends Post { public function get_summary(): ?string { // todo when do we add the filter? we could add it and just keep it? add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2 ); - $excerpt = $this->get_excerpt(); + $excerpt = $this->extract_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. $fallback_to_content = true; if ( is_null( $excerpt ) && $fallback_to_content ) { diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index b92846c..695a867 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -104,11 +104,11 @@ final class VS_Event_List extends Event_Transformer { * * @return ?string */ - protected function get_excerpt(): ?string { + protected function extract_excerpt(): ?string { if ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { return get_post_meta( $this->wp_object->ID, 'event-summary', true ); } else { - return parent::get_excerpt(); + return parent::extract_excerpt(); } } } -- 2.39.5 From b3b07d4b6ad3e45daa770effc9b64f839f3f59b5 Mon Sep 17 00:00:00 2001 From: ruru4143 Date: Tue, 1 Oct 2024 19:03:44 +0200 Subject: [PATCH 28/42] removed todo --- includes/activitypub/transformer/class-event.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 67e7541..f1182a9 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -231,7 +231,6 @@ abstract class Event extends Post { * @return string $summary The custom event summary. */ public function get_summary(): ?string { - // todo when do we add the filter? we could add it and just keep it? add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2 ); $excerpt = $this->extract_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. -- 2.39.5 From 2b93267272cd696c828bbcfbdcca1acd7a8a0e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 13:08:54 +0200 Subject: [PATCH 29/42] rename extract_excerpt to retrieve_excerpt --- includes/activitypub/transformer/class-event.php | 4 ++-- includes/activitypub/transformer/class-vs-event-list.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index f1182a9..48f5522 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -126,7 +126,7 @@ abstract class Event extends Post { * * @return ?string */ - protected function extract_excerpt(): ?string { + protected function retrieve_excerpt(): ?string { if ( $this->wp_object->post_excerpt ) { return $this->wp_object->post_excerpt; } else { @@ -232,7 +232,7 @@ abstract class Event extends Post { */ public function get_summary(): ?string { add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2 ); - $excerpt = $this->extract_excerpt(); + $excerpt = $this->retrieve_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. $fallback_to_content = true; if ( is_null( $excerpt ) && $fallback_to_content ) { diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index 695a867..dc0ae7b 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -104,11 +104,11 @@ final class VS_Event_List extends Event_Transformer { * * @return ?string */ - protected function extract_excerpt(): ?string { + protected function retrieve_excerpt(): ?string { if ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { return get_post_meta( $this->wp_object->ID, 'event-summary', true ); } else { - return parent::extract_excerpt(); + return parent::retrieve_excerpt(); } } } -- 2.39.5 From 1813a518f308e1570b21bf1894cf7518ed3d5bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 13:11:57 +0200 Subject: [PATCH 30/42] Do not set actor and do not override getAttributedTo. This was introduced to make interoperability with Mobilizon but it should be fixed on their side. --- includes/activitypub/transformer/class-event.php | 11 ----------- .../activitypub/transformer/class-gatherpress.php | 12 ------------ 2 files changed, 23 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 48f5522..a364c7e 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -31,17 +31,6 @@ abstract class Event extends Post { */ protected $wp_taxonomy; - /** - * Returns the User-URL of the Author of the Post. - * - * If `single_user` mode is enabled, the URL of the Blog-User is returned. - * - * @return string The User-URL. - */ - protected function get_actor(): ?string { - return $this->get_attributed_to(); - } - /** * Returns the ActivityStreams 2.0 Object-Type for an Event. * diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index 4e64072..8a05985 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -117,18 +117,6 @@ final class GatherPress extends Event { return $attachments; } - /** - * Returns the User-URL of the Author of the Post. - * - * If `single_user` mode is enabled, the URL of the Blog-User is returned. - * - * @return string The User-URL. - */ - protected function get_attributed_to(): string { - $user = new Blog(); // todo is this correct? feels not right. - return $user->get_url(); - } - /** * Determine whether the event is online. * -- 2.39.5 From 596e36f3099b4b30c1b907847fc9ddb6a6d5b811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 16:31:13 +0200 Subject: [PATCH 31/42] fix array in array in get_tag --- includes/activitypub/transformer/class-the-events-calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/activitypub/transformer/class-the-events-calendar.php b/includes/activitypub/transformer/class-the-events-calendar.php index 3f4b71c..0e78522 100644 --- a/includes/activitypub/transformer/class-the-events-calendar.php +++ b/includes/activitypub/transformer/class-the-events-calendar.php @@ -65,7 +65,7 @@ final class The_Events_Calendar extends Event { $tags[] = $tag; } } - $tags[] = parent::get_tag(); + $tags = array_merge( $tags, parent::get_tag() ); return $tags; } -- 2.39.5 From f76fa57665d3c52606aa6cb6e6fd01196a61c386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 16:31:32 +0200 Subject: [PATCH 32/42] improve formatting of categories --- .../activitypub/transformer/class-event.php | 69 +++++++++++-------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index a364c7e..13855b0 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -21,6 +21,11 @@ use DateTime; * * Everything that transforming several WordPress post types that represent events * have in common, as well as sane defaults for events should be defined here. + * + * BeforeFirstRelease: + * [ ] remove link at the end of the content. + * [ ] add organizer. + * [ ] do add Cancelled reason in the content. */ abstract class Event extends Post { @@ -66,7 +71,7 @@ abstract class Event extends Post { * @param WP_Post $wp_object The WordPress post object (event). * @param string $wp_taxonomy The taxonomy slug of the event post type. */ - public function __construct( $wp_object, $wp_taxonomy ) { + public function __construct( $wp_object, $wp_taxonomy = 'category' ) { parent::__construct( $wp_object ); $this->wp_taxonomy = $wp_taxonomy; } @@ -96,8 +101,13 @@ abstract class Event extends Post { /** * Set the event category, via the mapping setting. + * + * @return ?string */ public function get_category(): ?string { + if ( is_null( $this->wp_taxonomy ) ) { + return null; + } $current_category_mapping = \get_option( 'activitypub_event_extensions_event_category_mappings', array() ); $terms = \get_the_terms( $this->wp_object, $this->wp_taxonomy ); @@ -201,14 +211,29 @@ abstract class Event extends Post { /** * Format the category using the translation. */ - protected function format_category(): string { - require_once ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . '/includes/event-categories.php'; - $category = $this->get_category(); - if ( array_key_exists( $category, ACTIVITYPUB_EVENT_EXTENSIONS_EVENT_CATEGORIES ) ) { - return ACTIVITYPUB_EVENT_EXTENSIONS_EVENT_CATEGORIES[ $category ]; - } else { - return ACTIVITYPUB_EVENT_EXTENSIONS_EVENT_CATEGORIES['MEETING']; + protected function format_categories(): string { + if ( is_null( $this->wp_taxonomy ) ) { + return ''; } + $categories = array(); + + // Add the federated category string. + require_once ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . '/includes/event-categories.php'; + $federated_category = $this->get_category(); + if ( array_key_exists( $federated_category, ACTIVITYPUB_EVENT_EXTENSIONS_EVENT_CATEGORIES ) ) { + $categories[] = ACTIVITYPUB_EVENT_EXTENSIONS_EVENT_CATEGORIES[ $federated_category ]; + } + + // Add all category terms. + $terms = \get_the_terms( $this->wp_object, $this->wp_taxonomy ); + foreach ( $terms as $term ) { + $categories[] = $term->name; + } + + if ( ! empty( $categories ) ) { + return implode( ' ยท ', array_unique( $categories ) ); + } + return ''; } /** @@ -229,27 +254,28 @@ abstract class Event extends Post { } remove_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ) ); - $category = $this->format_category(); + $category = $this->format_categories(); $start_time = $this->format_start_time(); $end_time = $this->format_end_time(); $address = $this->format_address(); $formatted_items = array(); if ( ! empty( $category ) ) { - $formatted_items[] = "๐Ÿท๏ธ $category"; + $formatted_items[] = '๐Ÿท๏ธ ' . __( 'Category', 'activitypub-event-extensions' ) . ': ' . $category; } if ( ! empty( $start_time ) ) { - $formatted_items[] = "๐Ÿ—“๏ธ {$start_time}"; + $formatted_items[] = '๐Ÿ—“๏ธ ' . __( 'Start', 'activitypub-event-extensions' ) . ': ' . $start_time; } if ( ! empty( $end_time ) ) { - $formatted_items[] = "โณ {$end_time}"; + $formatted_items[] = 'โณ ' . __( 'End', 'activitypub-event-extensions' ) . ': ' . $end_time; } if ( ! empty( $address ) ) { - $formatted_items[] = "๐Ÿ“ {$address}"; + $formatted_items[] = '๐Ÿ“ ' . __( 'Address', 'activitypub-event-extensions' ) . ': ' . $address; } + // Compose the summary based on the number of meta items. if ( count( $formatted_items ) > 1 ) { $summary = '
  • ' . implode( '
  • ', $formatted_items ) . '
'; @@ -320,21 +346,4 @@ abstract class Event extends Post { return $activitypub_object; } - - /** - * Returns the content for the ActivityPub Item with - * - * The content will be generated based on the user settings. - * - * @return string The content. - */ - protected function get_content() { - // /BeforeFirstRelease: - // * [ ] remove link at the end of the content. - // * [ ] add organizer. - // * [ ] do add Cancelled reason in the content. - - // return parent::get_content();? - return $this->wp_object->post_content; - } } -- 2.39.5 From 3f7f996e109a9f775f33613bd955faa93ec24381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 17:11:14 +0200 Subject: [PATCH 33/42] fix format_categories for empty term list --- includes/activitypub/transformer/class-event.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 13855b0..7793650 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -226,8 +226,10 @@ abstract class Event extends Post { // Add all category terms. $terms = \get_the_terms( $this->wp_object, $this->wp_taxonomy ); - foreach ( $terms as $term ) { - $categories[] = $term->name; + if ( $terms && ! is_wp_error( $terms ) ) { + foreach ( $terms as $term ) { + $categories[] = $term->name; + } } if ( ! empty( $categories ) ) { -- 2.39.5 From 724a8847380089ba8f4e893fc9b5c65bc04a8b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 18:01:20 +0200 Subject: [PATCH 34/42] add_post_type_support when updating activitypub_support_post_types --- includes/class-setup.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/class-setup.php b/includes/class-setup.php index 67877fb..a02076c 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -272,6 +272,7 @@ class Setup { foreach ( $this->active_event_plugins as $event_plugin ) { if ( ! in_array( $event_plugin->get_post_type(), $activitypub_supported_post_types, true ) ) { $activitypub_supported_post_types[] = $event_plugin->get_post_type(); + add_post_type_support( $event_plugin->get_post_type(), 'activitypub' ); } } update_option( 'activitypub_support_post_types', $activitypub_supported_post_types ); -- 2.39.5 From 62c4e87fb28fd51d777109ee716580ba317d5d37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 18:07:12 +0200 Subject: [PATCH 35/42] improve tests or the events calendar --- tests/test-class-plugin-the-events-calendar.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-class-plugin-the-events-calendar.php b/tests/test-class-plugin-the-events-calendar.php index 089d466..b91321a 100644 --- a/tests/test-class-plugin-the-events-calendar.php +++ b/tests/test-class-plugin-the-events-calendar.php @@ -37,14 +37,14 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { public const MOCKUP_EVENTS = array( 'minimal_event' => array( 'title' => 'My Event', - 'content' => 'Come to my event. Let\'s connect!', + 'content' => 'Come to my event!', 'start_date' => '+10 days 15:00:00', 'duration' => HOUR_IN_SECONDS, 'status' => 'publish', ), 'complex_event' => array( 'title' => 'My Event', - 'content' => 'Come to my event. Let\'s connect!', + 'content' => 'Come to my event!', 'start_date' => '+10 days 15:00:00', 'duration' => HOUR_IN_SECONDS, 'status' => 'publish', @@ -109,7 +109,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( 'Come to my event. Let\'s connect!', $event_array['content'] ); + $this->assertEquals( 'Come to my event!', strip_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertTrue( $event_array['commentsEnabled'] ); @@ -170,7 +170,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( 'Come to my event. Let\'s connect!', $event_array['content'] ); + $this->assertEquals( 'Come to my event!', strip_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] ); @@ -197,7 +197,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( 'Come to my event. Let\'s connect!', $event_array['content'] ); + $this->assertEquals( 'Come to my event!', strip_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] ); -- 2.39.5 From 3975386a5236b151ddb611b3f9dba58345b94d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 18:10:59 +0200 Subject: [PATCH 36/42] set hardcoded template for content --- includes/activitypub/transformer/class-event.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 7793650..7b144a6 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -54,6 +54,16 @@ abstract class Event extends Post { return comments_open( $this->wp_object ); } + /** + * Set a hardcoded template for the content. + * + * This actually disabled templates for the content. + * Maybe this independent templates for events will be added later. + */ + protected function get_post_content_template(): string { + return '[ap_content]'; + } + /** * Returns the title of the event. * -- 2.39.5 From 676bb20751d9b6200c0d5afb8fb5323875ff8144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 18:13:41 +0200 Subject: [PATCH 37/42] replace strip_tags with wp_strip_all_tags in tests --- tests/test-class-plugin-the-events-calendar.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-class-plugin-the-events-calendar.php b/tests/test-class-plugin-the-events-calendar.php index b91321a..fd589f7 100644 --- a/tests/test-class-plugin-the-events-calendar.php +++ b/tests/test-class-plugin-the-events-calendar.php @@ -109,7 +109,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( 'Come to my event!', strip_tags( $event_array['content'] ) ); + $this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertTrue( $event_array['commentsEnabled'] ); @@ -170,7 +170,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( 'Come to my event!', strip_tags( $event_array['content'] ) ); + $this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] ); @@ -197,7 +197,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'My Event', $event_array['name'] ); - $this->assertEquals( 'Come to my event!', strip_tags( $event_array['content'] ) ); + $this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] ); -- 2.39.5 From 2301900baafe5e4ff3a2c71e91b31f1a84b3c67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 18:46:57 +0200 Subject: [PATCH 38/42] gatherpress: prevent gatherpress blocks from being rendered in activitystreams --- .../transformer/class-gatherpress.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index 8a05985..bfe1e92 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -117,6 +117,33 @@ final class GatherPress extends Event { return $attachments; } + /** + * Prevents gatherpress blocks from being rendered for the content. + * + * @param mixed $block_content The blocks content. + * @param mixed $block The block. + */ + public static function filter_gatherpress_blocks( $block_content, $block ) { + // Check if the block name starts with 'gatherpress'. + if ( strpos( $block['blockName'], 'gatherpress/' ) === 0 ) { + return ''; // Skip rendering this block. + } + + return $block_content; // Return the content for other blocks. + } + + /** + * Apply the filter for preventing the rendering off gatherpress blocks just in time. + * + * @return Event_Object + */ + public function to_object(): Event_Object { + add_filter( 'render_block', array( self::class, 'filter_gatherpress_blocks' ), 10, 2 ); + $activitypub_object = parent::to_object(); + remove_filter( 'render_block', array( self::class, 'filter_gatherpress_blocks' ) ); + return $activitypub_object; + } + /** * Determine whether the event is online. * -- 2.39.5 From 982c9c3e4432eab596f262e9bee87350422f1e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 18:54:27 +0200 Subject: [PATCH 39/42] strip tags within gatherpress tests --- tests/test-class-plugin-gatherpress.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-class-plugin-gatherpress.php b/tests/test-class-plugin-gatherpress.php index 504dc9c..c184a8d 100644 --- a/tests/test-class-plugin-gatherpress.php +++ b/tests/test-class-plugin-gatherpress.php @@ -94,7 +94,7 @@ class Test_GatherPress extends WP_UnitTestCase { // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Unit Test Event', $event_array['name'] ); - $this->assertEquals( 'Unit Test description.', $event_array['content'] ); + $this->assertEquals( 'Unit Test description.', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); -- 2.39.5 From 1aedb964a9a792283885ef2096bf9a354af55b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 19:03:04 +0200 Subject: [PATCH 40/42] fix gatherpress tests: event must always be published --- composer.json | 2 +- tests/test-class-plugin-gatherpress.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d091876..28fb046 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ ], "test-debug": [ "@prepare-test", - "@test-vs-event-list" + "@test-gatherpress" ], "test-vs-event-list": "phpunit --filter=vs_event_list", "test-the-events-calendar": "phpunit --filter=the_events_calendar", diff --git a/tests/test-class-plugin-gatherpress.php b/tests/test-class-plugin-gatherpress.php index c184a8d..b2ac3eb 100644 --- a/tests/test-class-plugin-gatherpress.php +++ b/tests/test-class-plugin-gatherpress.php @@ -49,6 +49,7 @@ class Test_GatherPress extends WP_UnitTestCase { 'post_title' => 'Unit Test Event', 'post_type' => 'gatherpress_event', 'post_content' => 'Unit Test description.', + 'post_status' => 'publish', ) ); $event = new \GatherPress\Core\Event( $post_id ); @@ -77,7 +78,7 @@ class Test_GatherPress extends WP_UnitTestCase { 'post_title' => 'Unit Test Event', 'post_type' => 'gatherpress_event', 'post_content' => 'Unit Test description.', - 'post_status' => 'published', + 'post_status' => 'publish', ) ); $event = new \GatherPress\Core\Event( $post_id ); -- 2.39.5 From 9d2f17583d20de940e8dd5c1fa8accaa2fa3c02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 19:06:22 +0200 Subject: [PATCH 41/42] tests for events manager: fix status --- tests/test-class-plugin-events-manger.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-class-plugin-events-manger.php b/tests/test-class-plugin-events-manger.php index 0c704ed..ab7a4bd 100644 --- a/tests/test-class-plugin-events-manger.php +++ b/tests/test-class-plugin-events-manger.php @@ -47,7 +47,7 @@ class Test_Events_Manager extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'Events Manager Test event', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => EM_POST_TYPE_EVENT, 'meta_input' => array( 'event_start_time' => strtotime( '+10 days 15:00:00' ), @@ -75,7 +75,7 @@ class Test_Events_Manager extends WP_UnitTestCase { $event->event_start_date = gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ); $event->event_start_time = '15:00:00'; $event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time ); - $event->force_status = 'published'; + $event->force_status = 'publish'; $event->event_rsvp = false; $this->assertTrue( $event->save() ); @@ -121,7 +121,7 @@ class Test_Events_Manager extends WP_UnitTestCase { $event->event_end_time = '16:00:00'; $event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time ); $event->end = strtotime( $event->event_end_date . ' ' . $event->event_end_time ); - $event->force_status = 'published'; + $event->force_status = 'publish'; $event->event_rsvp = false; $this->assertTrue( $event->save() ); @@ -164,7 +164,7 @@ class Test_Events_Manager extends WP_UnitTestCase { $event->event_end_time = '16:00:00'; $event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time ); $event->end = strtotime( $event->event_end_date . ' ' . $event->event_end_time ); - $event->force_status = 'published'; + $event->force_status = 'publish'; $event->event_rsvp = false; $this->assertTrue( $event->save() ); -- 2.39.5 From a6938edf465d72f2b8dc43514cccedfb20cadecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 2 Oct 2024 19:08:53 +0200 Subject: [PATCH 42/42] fix events manager tests: strip tags for content --- tests/test-class-plugin-events-manger.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-class-plugin-events-manger.php b/tests/test-class-plugin-events-manger.php index ab7a4bd..3d3c7d2 100644 --- a/tests/test-class-plugin-events-manger.php +++ b/tests/test-class-plugin-events-manger.php @@ -85,7 +85,7 @@ class Test_Events_Manager extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Events Manager Test event', $event_array['name'] ); - $this->assertEquals( 'Event description', $event_array['content'] ); + $this->assertEquals( 'Event description', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( comments_open( $event->post_id ), $event_array['commentsEnabled'] ); $this->assertEquals( comments_open( $event->post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); @@ -131,7 +131,7 @@ class Test_Events_Manager extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Events Manager Test event', $event_array['name'] ); - $this->assertEquals( 'Event description', $event_array['content'] ); + $this->assertEquals( 'Event description', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'MEETING', $event_array['category'] ); @@ -174,7 +174,7 @@ class Test_Events_Manager extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Events Manager Test event', $event_array['name'] ); - $this->assertEquals( 'Event description', $event_array['content'] ); + $this->assertEquals( 'Event description', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'MEETING', $event_array['category'] ); -- 2.39.5