fix several errors in json-ld context generation
Some checks failed
Deploy to https://wordpress-test.event-federation.eu/ / deploy (push) Failing after 5s

This commit is contained in:
André Menrath 2023-12-04 15:53:01 +01:00
parent e91e76bf17
commit 788f1b13da
2 changed files with 33 additions and 67 deletions

View file

@ -1,21 +1,17 @@
<?php <?php
/** /**
* ActivityPub Transformer for VS Event. * ActivityPub Object of type Event.
*
* This is a file doc comments.
* *
* @package activity-event-transformers * @package activity-event-transformers
*/ */
use function Activitypub\snake_to_camel_case; use function Activitypub\snake_to_camel_case;
require_once __DIR__ . '/class-place.php';
/** /**
* Event is an implementation of one of the * Event is an implementation of one of the Activity Streams Event object type.
* Activity Streams Event object type
* *
* The Object is the primary base type for the Activity Streams * This class contains extra keys as used by Mobilizon to ensure compatibility.
* vocabulary.
* *
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
*/ */
@ -36,28 +32,31 @@ class Event extends \Activitypub\Activity\Base_Object {
* Mobilizon also implemented this as a fallback to their own * Mobilizon also implemented this as a fallback to their own
* repliesModerationOption. * repliesModerationOption.
* *
* @context https://joinpeertube.org/commentsEnabled * @context https://joinpeertube.org/ns#commentsEnabled
*
* @see https://docs.joinpeertube.org/api/activitypub#video * @see https://docs.joinpeertube.org/api/activitypub#video
* @see https://docs.joinmobilizon.org/contribute/activity_pub/ * @see https://docs.joinmobilizon.org/contribute/activity_pub/
* @var bool * @var bool|null
*/ */
protected $comments_enabled; protected $comments_enabled;
/** /**
* @context https://joinmobilizon.org/timezone * @context https://joinmobilizon.org/ns#timezone
* @var string * @var string
*/ */
protected $timezone; protected $timezone;
/** /**
* @context https://joinmobilizon.org/repliesModerationOption * @context https://joinmobilizon.org/ns#repliesModerationOption
*
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#repliesmoderation * @see https://docs.joinmobilizon.org/contribute/activity_pub/#repliesmoderation
* @var string * @var string
*/ */
protected $replies_moderation_option; protected $replies_moderation_option;
/** /**
* @context https://joinmobilizon/anonymousParticipationEnabled * @context https://joinmobilizon.org/ns#anonymousParticipationEnabled
*
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#anonymousparticipationenabled * @see https://docs.joinmobilizon.org/contribute/activity_pub/#anonymousparticipationenabled
* @var bool * @var bool
*/ */
@ -76,32 +75,32 @@ class Event extends \Activitypub\Activity\Base_Object {
protected $in_language; protected $in_language;
/** /**
* @context https://joinmobilizon.org/isOnline * @context https://joinmobilizon.org/ns#isOnline
* @var bool * @var bool
*/ */
protected $is_online; protected $is_online;
/** /**
* @context http://www.w3.org/2002/12/cal/ical# * @context http://www.w3.org/2002/12/cal/ical#status
* @var enum * @var enum
*/ */
protected $ical_status; protected $status;
/** /**
* @context https://joinmobilizon.org/externalParticipationUrl * @context https://joinmobilizon.org/ns#externalParticipationUrl
* @var string * @var string
*/ */
protected $external_participation_url; protected $external_participation_url;
/** /**
* @context https://joinmobilizon.org/joinMode * @context https://joinmobilizon.org/ns#joinMode
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#joinmode * @see https://docs.joinmobilizon.org/contribute/activity_pub/#joinmode
* @var * @var
*/ */
protected $join_mode; protected $join_mode;
/** /**
* @context https://joinmobilizon.org/participantCount * @context https://joinmobilizon.org/ns#participantCount
* @var int * @var int
*/ */
protected $participant_count; protected $participant_count;
@ -113,35 +112,6 @@ class Event extends \Activitypub\Activity\Base_Object {
*/ */
protected $maximum_attendee_capacity; protected $maximum_attendee_capacity;
/**
* Setter function that makes sure, we only set valid replies moderation options.
* @param string $value
*/
public function set_replies_moderation_option( $value ) {
if ( in_array( $value, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
$this->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. * Get the context information for a property.
@ -170,13 +140,6 @@ class Event extends \Activitypub\Activity\Base_Object {
return null; 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 ) { private static function compact_context( $key_context, $namespace, $abbreviation ) {
$abbreviation_added = false; $abbreviation_added = false;
foreach ( $key_context as $key => $value ) { 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 // Add abbreviation element for the namespace only once
if ( ! $abbreviation_added ) { if ( ! $abbreviation_added ) {
$key_context = [ $abbreviation => $namespace . '/ns#' ] + $key_context; $key_context = [ $abbreviation => $namespace ] + $key_context;
$abbreviation_added = true; $abbreviation_added = true;
} }
} }
@ -197,7 +160,7 @@ class Event extends \Activitypub\Activity\Base_Object {
public static function get_context() { public static function get_context() {
$class = self::class; $class = self::class;
$transient = "activitypub_context_object_{$class}"; $transient = "activitypub_json_context_object_{$class}";
$context = get_transient($transient); $context = get_transient($transient);
// if ( $context ) { // if ( $context ) {
// return $context; // return $context;
@ -222,9 +185,10 @@ class Event extends \Activitypub\Activity\Base_Object {
} }
$namespace_abbreviations = array( $namespace_abbreviations = array(
'https://joinpeertube.org/' => 'pt', 'https://joinpeertube.org/ns#' => 'pt',
'https://joinmobilizon.org/' => 'mz', 'https://joinmobilizon.org/ns#' => 'mz',
'https://schema.org/' => 'sc' 'https://schema.org/' => 'sc',
'http://www.w3.org/2002/12/cal/ical#' => 'ical',
); );
foreach ( $namespace_abbreviations as $namespace => $abbreviation ) { 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. * When using this class we need to add some filters.
*/ */
public function __construct() { public function __construct() {
$class = get_class( $this ); // $class = strtolower( get_class( $this ) );
$class = 'event'; // add_filter( "activitypub_activity_{$class}_object_array", [ $this, 'filter_object_array' ] );
add_filter( "activitypub_activity_{$class}_object_array", [ $this, 'rename_array_keys' ] ); // add_filter( 'activitypub_json_context', [ $this, 'filter_json_context' ] );
add_filter( 'activitypub_json_context', [ $this, 'filter_context' ] );
} }
} }

View file

@ -8,6 +8,7 @@
require_once __DIR__ . '/../object/class-event.php'; require_once __DIR__ . '/../object/class-event.php';
use Activitypub\Activity\Base_Object; use Activitypub\Activity\Base_Object;
use Place;
use function Activitypub\get_rest_url_by_path; use function Activitypub\get_rest_url_by_path;
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
@ -77,9 +78,11 @@ class VS_Event extends \Activitypub\Transformer\Base {
* @returns array The Place. * @returns array The Place.
*/ */
public function get_event_location( $post_id ) { public function get_event_location( $post_id ) {
$object = new Base_Object(); $object = new Place();
$object->set_type( '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; return $object;
} }
@ -175,7 +178,7 @@ class VS_Event extends \Activitypub\Transformer\Base {
$path = sprintf( 'users/%d/followers', intval( $this->wp_post->post_author ) ); $path = sprintf( 'users/%d/followers', intval( $this->wp_post->post_author ) );
$object $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_comments_enabled( comments_open( $this->wp_post->ID ) )
->set_to( ->set_to(
array( array(