Keep track with upstream changes

This commit is contained in:
André Menrath 2024-01-17 18:02:40 +01:00
parent bb4cf2e44c
commit 27aff53371
3 changed files with 80 additions and 12 deletions

View file

@ -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;
}
}

View file

@ -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 = '';

View file

@ -0,0 +1,64 @@
<?php
/**
* Mapping of WordPress Terms(Tags) to known Event Categories
*
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use Activitypub\Activity\Event;
/**
* ActivityPub Tribe Transformer
*
* @since 1.0.0
*/
class Category_Mapper {
/**
* Static function to do the Mapping
**/
public static function map( $post_categories ) {
if ( empty( $post_categories ) ) {
return 'MEETING';
}
// Prepare an array to store all category information for comparison.
$category_info = array();
// Extract relevant category information (name, slug, description) from the categories array.
foreach ( $post_categories as $category ) {
$category_info[] = strtolower( $category->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';
}
}