From 014b2e11713d81cb6947be36c3307dcf2aa9ba7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Tue, 12 Dec 2023 17:27:43 +0100 Subject: [PATCH] add testing snippets and merging the latest versions --- activitypub-event-transformers.php | 27 +++++++++ activitypub/object/class-event.php | 27 ++++++--- activitypub/object/class-place.php | 26 ++++++--- activitypub/object/class-postal-address.php | 64 ++++++++++----------- activitypub/transformer/class-tribe.php | 10 ++-- activitypub/transformer/class-vs-event.php | 32 +++++++---- 6 files changed, 123 insertions(+), 63 deletions(-) diff --git a/activitypub-event-transformers.php b/activitypub-event-transformers.php index 18e9da6..46a6dd4 100644 --- a/activitypub-event-transformers.php +++ b/activitypub-event-transformers.php @@ -37,3 +37,30 @@ function register_event_transformers( $transformers_manager ) { } add_action( 'activitypub_transformers_register', 'register_event_transformers' ); + + + +// TODO Below here is temporary code needed to do local testing atm. + +// Add a filter for http_request_host_is_external +add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_external', 10, 3 ); + +// Your custom callback function +function custom_http_request_host_is_external( $is_external, $host, $url ) { + $is_external = true; + + return $is_external; +} + +// add_filter( 'rest_request_before_callbacks', 'change_relay_actor_to_blog_actor', 10, 3 ); + +// function change_relay_actor_to_blog_actor( $response, $handler, $request ) { + +// } + +// add_filters( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3); + + +// function dont_verify_local_dev_https($url) { +// return false; +// } diff --git a/activitypub/object/class-event.php b/activitypub/object/class-event.php index 2237ee3..c21d8c1 100644 --- a/activitypub/object/class-event.php +++ b/activitypub/object/class-event.php @@ -18,9 +18,9 @@ require_once __DIR__ . '/class-place.php'; */ class Event extends \Activitypub\Activity\Base_Object { // todo maybe rename to mobilizon event? - const REPLIES_MODERATION_OPTION_TYPES = [ 'allow_all', 'closed' ]; - const JOIN_MODE_TYPES = [ 'free', 'restricted', 'external' ]; // amd 'invite', but not used by mobilizon atm - const ICAL_EVENT_STATUS_TYPES = ["TENTATIVE", "CONFIRMED", "CANCELLED"]; + const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' ); + const JOIN_MODE_TYPES = array( 'free', 'restricted', 'external' ); // amd 'invite', but not used by mobilizon atm + const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' ); /** * Event is an implementation of one of the @@ -30,6 +30,10 @@ class Event extends \Activitypub\Activity\Base_Object { */ protected $type = 'Event'; + protected $name; + + protected $contacts; + /** * Extension invented by PeerTube whether comments/replies are * Mobilizon also implemented this as a fallback to their own @@ -81,7 +85,7 @@ class Event extends \Activitypub\Activity\Base_Object { protected $is_online; /** - * @context http://www.w3.org/2002/12/cal/ical#status + * @context https://www.w3.org/2002/12/cal/ical#status * @var enum */ protected $status; @@ -112,6 +116,13 @@ class Event extends \Activitypub\Activity\Base_Object { */ protected $maximum_attendee_capacity; + /** + * @context https://schema.org/remainingAttendeeCapacity + * @see https://docs.joinmobilizon.org/contribute/activity_pub/#remainignattendeecapacity + * @var int + */ + protected $remaining_attendee_capacity; + /** * Get the context information for a property. @@ -150,7 +161,7 @@ class Event extends \Activitypub\Activity\Base_Object { // Add abbreviation element for the namespace only once if ( ! $abbreviation_added ) { - $key_context = [ $abbreviation => $namespace ] + $key_context; + $key_context = array( $abbreviation => $namespace ) + $key_context; $abbreviation_added = true; } } @@ -163,7 +174,7 @@ class Event extends \Activitypub\Activity\Base_Object { $transient = "activitypub_json_context_object_{$class}"; $context = get_transient( $transient ); // if ( $context ) { - // return $context; + // return $context; // } $reflection_class = new ReflectionClass( self::class ); $context = array( @@ -171,7 +182,7 @@ class Event extends \Activitypub\Activity\Base_Object { 'https://w3id.org/security/v1', ); - $key_context = []; + $key_context = array(); foreach ( $reflection_class->getProperties() as $property ) { $doc_omment = $property->getDocComment(); @@ -188,7 +199,7 @@ class Event extends \Activitypub\Activity\Base_Object { 'https://joinpeertube.org/ns#' => 'pt', 'https://joinmobilizon.org/ns#' => 'mz', 'https://schema.org/' => 'sc', - 'http://www.w3.org/2002/12/cal/ical#' => 'ical', + 'https://www.w3.org/2002/12/cal/ical#' => 'ical', ); foreach ( $namespace_abbreviations as $namespace => $abbreviation ) { diff --git a/activitypub/object/class-place.php b/activitypub/object/class-place.php index 0643c54..d18a942 100644 --- a/activitypub/object/class-place.php +++ b/activitypub/object/class-place.php @@ -26,26 +26,36 @@ class Place extends \Activitypub\Activity\Base_Object { protected $type = 'Place'; /** + * Indicates the accuracy of position coordinates on a Place objects. + * Expressed in properties of percentage. e.g. "94.0" means "94.0% accurate". + * * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-accuracy - * @var float + * @var float xsd:float [>= 0.0f, <= 100.0f] */ protected $accuracy; /** + * Indicates the altitude of a place. The measurement units is indicated using the units property. + * If units is not specified, the default is assumed to be "m" indicating meters. + * * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-altitude - * @var float + * @var float xsd:float */ protected $altitude; /** + * The latitude of a place. + * * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-latitude - * @var float + * @var float xsd:float */ protected $latitude; /** + * The longitude of a place. + * * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-longitude - * @var float + * @var float xsd:float */ protected $longitude; @@ -73,8 +83,8 @@ class Place extends \Activitypub\Activity\Base_Object { */ protected $comments_enabled; - /** - * @var Postal_Address|string - */ - protected $address; + /** + * @var Postal_Address|string + */ + protected $address; } diff --git a/activitypub/object/class-postal-address.php b/activitypub/object/class-postal-address.php index ed62739..1d6490d 100644 --- a/activitypub/object/class-postal-address.php +++ b/activitypub/object/class-postal-address.php @@ -19,40 +19,40 @@ class Postal_Address extends \Activitypub\Activity\Base_Object { */ protected $type = 'PostalAddress'; - /** - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. - * - * @see http://en.wikipedia.org/wiki/ISO_3166-1 - * @var string - */ - protected $address_country; + /** + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. + * + * @see http://en.wikipedia.org/wiki/ISO_3166-1 + * @var string + */ + protected $address_country; - /** - * The locality in which the street address is, and which is in the region. For example, Mountain View. - * - * @var string - */ - protected $address_locality; + /** + * The locality in which the street address is, and which is in the region. For example, Mountain View. + * + * @var string + */ + protected $address_locality; - /** - * The region in which the locality is, and which is in the country. - * For example, California or another appropriate first-level Administrative division. - * - * @var string - */ - protected $address_region; + /** + * The region in which the locality is, and which is in the country. + * For example, California or another appropriate first-level Administrative division. + * + * @var string + */ + protected $address_region; - /** - * The postal code. For example, 94043. - * - * @var string - */ - protected $postal_code; + /** + * The postal code. For example, 94043. + * + * @var string + */ + protected $postal_code; - /** - * The street address. For example, 1600 Amphitheatre Pkwy. - * - * @var string - */ - protected $street_address; + /** + * The street address. For example, 1600 Amphitheatre Pkwy. + * + * @var string + */ + protected $street_address; } diff --git a/activitypub/transformer/class-tribe.php b/activitypub/transformer/class-tribe.php index 2c94188..f1a64dc 100644 --- a/activitypub/transformer/class-tribe.php +++ b/activitypub/transformer/class-tribe.php @@ -168,9 +168,11 @@ class Tribe extends \Activitypub\Transformer\Base { return ( new Place() ) ->set_type( 'Place' ) ->set_name( $venue->post_name ) - ->set_address( $venue->address . "\n" . - $venue->zip . ", " . $venue->city . "\n" . - $venue->country ); // todo add checks that everything exists here (lol) + ->set_address( + $venue->address . "\n" . + $venue->zip . ', ' . $venue->city . "\n" . + $venue->country + ); // todo add checks that everything exists here (lol) } /** @@ -205,7 +207,7 @@ class Tribe extends \Activitypub\Transformer\Base { // set author and location ->set_attributed_to( $this->get_attributed_to() ) - ->set_location( $this->get_event_location()->to_array()) + ->set_location( $this->get_event_location()->to_array() ) // set content ->set_name( $this->get_post_property( 'post_title' ) ) diff --git a/activitypub/transformer/class-vs-event.php b/activitypub/transformer/class-vs-event.php index b7fedec..fbd36a6 100644 --- a/activitypub/transformer/class-vs-event.php +++ b/activitypub/transformer/class-vs-event.php @@ -100,12 +100,12 @@ class VS_Event extends \Activitypub\Transformer\Base { private function get_event_link() { $event_link = get_post_meta( $this->wp_post->ID, 'event-link', true ); if ( $event_link ) { - return [ + return array( 'type' => 'Link', 'name' => 'Website', - 'href' => \esc_url( get_post_meta( $post_id, 'event-location', true ) ), + 'href' => \esc_url( $event_link ), 'mediaType' => 'text/html', - ]; + ); } } @@ -114,6 +114,8 @@ class VS_Event extends \Activitypub\Transformer\Base { */ protected function get_attachments() { $attachments = parent::get_attachments(); + $attachments[0]['type'] = 'Document'; + $attachments[0]['name'] = 'Banner'; $event_link = $this->get_event_link(); if ( $event_link ) { $attachments[] = $this->get_event_link(); @@ -121,10 +123,6 @@ class VS_Event extends \Activitypub\Transformer\Base { return $attachments; } - private function get_category() { - return 'MEETING'; - } - /** * Transforms the VS Event WP_Post object to an ActivityPub Event Object. * @@ -160,13 +158,13 @@ class VS_Event extends \Activitypub\Transformer\Base { if ( $summary ) { $object->set_summary( $summary ); } else { - $object->set_summary( $this->content ); + $object->set_summary( $this->get_content() ); } $start_time = get_post_meta( $this->wp_post->ID, 'event-start-date', true ); $object->set_start_time( \gmdate( 'Y-m-d\TH:i:s\Z', $start_time ) ); - $hide_end_time = get_post_meta( $this->wp_post->ID, 'event-hide-end-time', true); + $hide_end_time = get_post_meta( $this->wp_post->ID, 'event-hide-end-time', true ); if ( $hide_end_time != 'yes' ) { $object->set_end_time( $this->get_end_time() ); @@ -183,14 +181,26 @@ class VS_Event extends \Activitypub\Transformer\Base { get_rest_url_by_path( $path ), ) ) - ->set_cc( $this->get_cc() ) + ->set_cc( array( get_rest_url_by_path( $path ) ) ) ->set_attachment( $this->get_attachments() ) ->set_tag( $this->get_tags() ) ->set_replies_moderation_option( 'allow_all' ) ->set_join_mode( 'external' ) ->set_external_participation_url( $this->get_url() ) ->set_status( 'CONFIRMED' ) - ->set_category( 'MEETING' ); + ->set_category( 'MEETING' ) + ->set_contacts( array() ) + ->set_name( get_the_title( $this->wp_post->ID ) ) + ->set_timezone( 'Europe/Vienna' ) + ->set_is_online( false ) + ->set_in_language( 'de ' ) + ->set_actor( $this->get_attributed_to() ); + + $object->set_remaining_attendee_capacity( null ) + ->set_anonymous_participation_enabled( null ) + ->set_draft( false ); + $object->set_participant_count( 2 ); + $object->set_uuid( '1de96701-bceb-4a78-bc18-6c417f52b314' ); return $object; }