From 27aff53371f7ee3ae88746c41704027216efd878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 17 Jan 2024 18:02:40 +0100 Subject: [PATCH] Keep track with upstream changes --- .../transformer/class-events-manager.php | 16 ++--- .../transformer/class-vs-event.php | 12 +++- includes/category-mapper.php | 64 +++++++++++++++++++ 3 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 includes/category-mapper.php diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 774185a..ebb5cba 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -8,11 +8,9 @@ use EM_Event; -use Activitypub\Activity\Event; -use Activitypub\Activity\Place; +use Activitypub\Activity\Objects\Event; +use Activitypub\Activity\Objects\Place; use Activitypub\Transformer\Post; -use Activitypub\Model\Blog_user; -use function Activitypub\get_rest_url_by_path; use function Activitypub\esc_hashtag; @@ -246,7 +244,7 @@ class Events_Manager extends Post { } // Convert mobilizon categories to lowercase for case-insensitive comparison. - $mobilizon_categories = array_map( 'strtolower', Event::MOBILIZON_EVENT_CATEGORIES ); + $mobilizon_categories = array_map( 'strtolower', Event::DEFAULT_EVENT_CATEGORIES ); // Initialize variables to track the best match. $best_mobilizon_category_match = ''; @@ -301,12 +299,12 @@ class Events_Manager extends Post { */ public function to_object() { $this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' ); - $activtiypub_object = new Event(); + $activitypub_object = new Event(); - $activtiypub_object = $this->transform_object_properties( $activtiypub_object ); + $activitypub_object = $this->transform_object_properties( $activitypub_object ); - $activtiypub_object->set_external_participation_url( $this->get_url() ); + $activitypub_object->set_external_participation_url( $this->get_url() ); - return $activtiypub_object; + return $activitypub_object; } } diff --git a/includes/activitypub/transformer/class-vs-event.php b/includes/activitypub/transformer/class-vs-event.php index 0ff8f36..fda00b1 100644 --- a/includes/activitypub/transformer/class-vs-event.php +++ b/includes/activitypub/transformer/class-vs-event.php @@ -6,8 +6,8 @@ * @license AGPL-3.0-or-later */ -use Activitypub\Activity\Event; -use Activitypub\Activity\Place; +use Activitypub\Activity\Objects\Event; +use Activitypub\Activity\Objects\Place; use Activitypub\Transformer\Post; use Activitypub\Model\Blog_user; @@ -23,6 +23,12 @@ if ( ! defined( 'ABSPATH' ) ) { * @since 1.0.0 */ class VS_Event extends Post { + /** + * The target transformet ActivityPub Event object. + * @var Event + */ + protected $ap_object; + /** * Get transformer name. * @@ -158,7 +164,7 @@ class VS_Event extends Post { } // Convert mobilizon categories to lowercase for case-insensitive comparison. - $mobilizon_categories = array_map( 'strtolower', Event::MOBILIZON_EVENT_CATEGORIES ); + $mobilizon_categories = array_map( 'strtolower', Event::DEFAULT_EVENT_CATEGORIES ); // Initialize variables to track the best match. $best_mobilizon_category_match = ''; diff --git a/includes/category-mapper.php b/includes/category-mapper.php new file mode 100644 index 0000000..caf6a42 --- /dev/null +++ b/includes/category-mapper.php @@ -0,0 +1,64 @@ +name ); + $category_info[] = strtolower( $category->slug ); + $category_info[] = strtolower( $category->description ); + } + + // Convert mobilizon categories to lowercase for case-insensitive comparison. + $mobilizon_categories = array_map( 'strtolower', Event::DEFAULT_EVENT_CATEGORIES ); + + // Initialize variables to track the best match. + $best_mobilizon_category_match = ''; + $best_match_length = 0; + + // Check for the best match. + foreach ( $mobilizon_categories as $mobilizon_category ) { + foreach ( $category_info as $category ) { + foreach ( explode( '_', $mobilizon_category ) as $mobilizon_category_slice ) { + if ( stripos( $category, $mobilizon_category_slice ) !== false ) { + // Check if the current match is longer than the previous best match. + $current_match_legnth = strlen( $mobilizon_category_slice ); + if ( $current_match_legnth > $best_match_length ) { + $best_mobilizon_category_match = $mobilizon_category; + $best_match_length = $current_match_legnth; + } + } + } + } + } + + return ( '' != $best_mobilizon_category_match ) ? strtoupper( $best_mobilizon_category_match ) : 'MEETING'; + } +}