From 788f1b13da287c778a8a0af988d15f487a050def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Mon, 4 Dec 2023 15:53:01 +0100 Subject: [PATCH] fix several errors in json-ld context generation --- activitypub/object/class-event.php | 91 +++++++--------------- activitypub/transformer/class-vs-event.php | 9 ++- 2 files changed, 33 insertions(+), 67 deletions(-) diff --git a/activitypub/object/class-event.php b/activitypub/object/class-event.php index 4740930..f2845ad 100644 --- a/activitypub/object/class-event.php +++ b/activitypub/object/class-event.php @@ -1,21 +1,17 @@ replies_moderation_option = $value; - } - return $this; - } - - /** - * @param array $array The array version of an object of this class. - */ - private function rename_ical_status_key( $array ) { - $array[ 'ical:status' ] = $array[ 'icalStatus' ]; - unset( $array[ 'icalStatus' ] ); - return $array; - } - - /** - * @param array $array The array version of an object of this class. - */ - public function rename_array_keys( $array ) { - if ( isset( $array[ 'icalStatus' ] ) ) { - $array = $this->rename_ical_status_key( $array ); - } - return $array; - } /** * Get the context information for a property. @@ -170,13 +140,6 @@ class Event extends \Activitypub\Activity\Base_Object { return null; } - public function filter_context( $context ) { - // if ( isset( $this->replies_moderation_option ) ) { - // $replies_moderation_option_context = $this->get_property_context( 'replies_moderation_option' ); - // } - return $context; - } - private static function compact_context( $key_context, $namespace, $abbreviation ) { $abbreviation_added = false; foreach ( $key_context as $key => $value ) { @@ -187,7 +150,7 @@ class Event extends \Activitypub\Activity\Base_Object { // Add abbreviation element for the namespace only once if ( ! $abbreviation_added ) { - $key_context = [ $abbreviation => $namespace . '/ns#' ] + $key_context; + $key_context = [ $abbreviation => $namespace ] + $key_context; $abbreviation_added = true; } } @@ -197,7 +160,7 @@ class Event extends \Activitypub\Activity\Base_Object { public static function get_context() { $class = self::class; - $transient = "activitypub_context_object_{$class}"; + $transient = "activitypub_json_context_object_{$class}"; $context = get_transient($transient); // if ( $context ) { // return $context; @@ -222,9 +185,10 @@ class Event extends \Activitypub\Activity\Base_Object { } $namespace_abbreviations = array( - 'https://joinpeertube.org/' => 'pt', - 'https://joinmobilizon.org/' => 'mz', - 'https://schema.org/' => 'sc' + 'https://joinpeertube.org/ns#' => 'pt', + 'https://joinmobilizon.org/ns#' => 'mz', + 'https://schema.org/' => 'sc', + 'http://www.w3.org/2002/12/cal/ical#' => 'ical', ); foreach ( $namespace_abbreviations as $namespace => $abbreviation ) { @@ -242,9 +206,8 @@ class Event extends \Activitypub\Activity\Base_Object { * When using this class we need to add some filters. */ public function __construct() { - $class = get_class( $this ); - $class = 'event'; - add_filter( "activitypub_activity_{$class}_object_array", [ $this, 'rename_array_keys' ] ); - add_filter( 'activitypub_json_context', [ $this, 'filter_context' ] ); + // $class = strtolower( get_class( $this ) ); + // add_filter( "activitypub_activity_{$class}_object_array", [ $this, 'filter_object_array' ] ); + // add_filter( 'activitypub_json_context', [ $this, 'filter_json_context' ] ); } } diff --git a/activitypub/transformer/class-vs-event.php b/activitypub/transformer/class-vs-event.php index 872fd62..1892133 100644 --- a/activitypub/transformer/class-vs-event.php +++ b/activitypub/transformer/class-vs-event.php @@ -8,6 +8,7 @@ require_once __DIR__ . '/../object/class-event.php'; use Activitypub\Activity\Base_Object; +use Place; use function Activitypub\get_rest_url_by_path; if ( ! defined( 'ABSPATH' ) ) { @@ -77,9 +78,11 @@ class VS_Event extends \Activitypub\Transformer\Base { * @returns array The Place. */ public function get_event_location( $post_id ) { - $object = new Base_Object(); + $object = new Place(); $object->set_type( 'Place' ); - $object->set_name( get_post_meta( $post_id, 'event-location', true ) ); + $address = get_post_meta( $post_id, 'event-location', true ); + $object->set_name( $address ); + $object->set_address( $address ); return $object; } @@ -175,7 +178,7 @@ class VS_Event extends \Activitypub\Transformer\Base { $path = sprintf( 'users/%d/followers', intval( $this->wp_post->post_author ) ); $object - ->set_location( $this->get_event_location( $this->wp_post->ID ) ) + ->set_location( $this->get_event_location( $this->wp_post->ID )->to_array() ) ->set_comments_enabled( comments_open( $this->wp_post->ID ) ) ->set_to( array(