From 49aeff105ffc6c182388d3df706ae34ff671e250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Mon, 4 Dec 2023 19:27:57 +0100 Subject: [PATCH] add license and readme --- README.md | 5 +++ activitypub-event-transformers.php | 19 +++------- activitypub/object/class-event.php | 4 +-- activitypub/object/class-place.php | 1 + activitypub/object/class-postal-address.php | 1 + activitypub/transformer/class-tribe.php | 1 + activitypub/transformer/class-vs-event.php | 39 ++++++++++----------- 7 files changed, 31 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index e69de29..1e965ae 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,5 @@ +This is a WordPress plugin that contains several example custom transformers for the [WordPress ActivityPub plugin](https://wordpress.org/plugins/activitypub/). It works like an add-on for it. + +Note that this plugin does not yet work with the latest release of the ActivityPub plugin. A pull request is already open: https://github.com/Automattic/wordpress-activitypub/pull/569 + +But if you want to test it you likely need the latest development branch of the ActivityPub plugin which you can find here: https://code.event-federation.eu/Event-Federation/wordpress-activitypub/src/branch/dev/extendable-transformers diff --git a/activitypub-event-transformers.php b/activitypub-event-transformers.php index 9fcb533..cd2702c 100644 --- a/activitypub-event-transformers.php +++ b/activitypub-event-transformers.php @@ -7,10 +7,12 @@ * Author: André Menrath * Author URI: https://graz.social/@linos * Text Domain: activitypub-event-transformers + * License: AGPL-3.0-or-later * * ActivityPub tested up to: 1.2.0 * * @package activitypub-event-transformer + * @license AGPL-3.0-or-later */ if ( ! defined( 'ABSPATH' ) ) { @@ -18,9 +20,9 @@ if ( ! defined( 'ABSPATH' ) ) { } /** - * Register Tribe Transformer. + * Register Event Transformers. * - * Include fransformer file and register transformer class. + * Include fransformer class file and register the transformer class. * * @since 1.0.0 * @param \Activitypub\Transformer\Transformer_Factory $transformers_manager ActivtiyPub transformers manager. @@ -34,17 +36,4 @@ function register_event_transformers( $transformers_manager ) { $transformers_manager->register( new \VS_Event() ); } -add_filter( - 'activitypub_json_context', - function ( $context ) { - $context[2]['commentsEnabled'] = array( - '@id' => 'pt:commentsEnabled', - '@type' => 'sc:Boolean', - ); - return $context; - }, - 10, - 2 -); - add_action( 'activitypub_transformers_register', 'register_event_transformers' ); diff --git a/activitypub/object/class-event.php b/activitypub/object/class-event.php index f2845ad..1de4d6e 100644 --- a/activitypub/object/class-event.php +++ b/activitypub/object/class-event.php @@ -3,6 +3,7 @@ * ActivityPub Object of type Event. * * @package activity-event-transformers + * @license AGPL-3.0-or-later */ use function Activitypub\snake_to_camel_case; @@ -33,7 +34,6 @@ class Event extends \Activitypub\Activity\Base_Object { * repliesModerationOption. * * @context https://joinpeertube.org/ns#commentsEnabled - * * @see https://docs.joinpeertube.org/api/activitypub#video * @see https://docs.joinmobilizon.org/contribute/activity_pub/ * @var bool|null @@ -48,7 +48,6 @@ class Event extends \Activitypub\Activity\Base_Object { /** * @context https://joinmobilizon.org/ns#repliesModerationOption - * * @see https://docs.joinmobilizon.org/contribute/activity_pub/#repliesmoderation * @var string */ @@ -56,7 +55,6 @@ class Event extends \Activitypub\Activity\Base_Object { /** * @context https://joinmobilizon.org/ns#anonymousParticipationEnabled - * * @see https://docs.joinmobilizon.org/contribute/activity_pub/#anonymousparticipationenabled * @var bool */ diff --git a/activitypub/object/class-place.php b/activitypub/object/class-place.php index 1aa5412..0643c54 100644 --- a/activitypub/object/class-place.php +++ b/activitypub/object/class-place.php @@ -4,6 +4,7 @@ * Activity Streams Event object type * * @package activity-event-transformers + * @license AGPL-3.0-or-later */ /** diff --git a/activitypub/object/class-postal-address.php b/activitypub/object/class-postal-address.php index 0c974fe..ed62739 100644 --- a/activitypub/object/class-postal-address.php +++ b/activitypub/object/class-postal-address.php @@ -4,6 +4,7 @@ * derived from https://schema.org/PostalAddress. * * @package activity-event-transformers + * @license AGPL-3.0-or-later */ /** diff --git a/activitypub/transformer/class-tribe.php b/activitypub/transformer/class-tribe.php index 0e0ba62..4c2bf3f 100644 --- a/activitypub/transformer/class-tribe.php +++ b/activitypub/transformer/class-tribe.php @@ -3,6 +3,7 @@ * ActivityPub Tribe Transformer * * @package activity-event-transformers + * @license AGPL-3.0-or-later */ if ( ! defined( 'ABSPATH' ) ) { diff --git a/activitypub/transformer/class-vs-event.php b/activitypub/transformer/class-vs-event.php index 1892133..966aea0 100644 --- a/activitypub/transformer/class-vs-event.php +++ b/activitypub/transformer/class-vs-event.php @@ -3,6 +3,7 @@ * ActivityPub Transformer for VS Event. * * @package activity-event-transformers + * @license AGPL-3.0-or-later */ require_once __DIR__ . '/../object/class-event.php'; @@ -78,23 +79,11 @@ class VS_Event extends \Activitypub\Transformer\Base { * @returns array The Place. */ public function get_event_location( $post_id ) { - $object = new Place(); - $object->set_type( 'Place' ); $address = get_post_meta( $post_id, 'event-location', true ); - $object->set_name( $address ); - $object->set_address( $address ); - return $object; - } - - /** - * Test - * - * @param string $context context. - * @return string $context context. - */ - private function add_pt_comments_enabled_context( $context ) { - $test = $context; - return $context; + return ( new Place() ) + ->set_type( 'Place' ) + ->set_name( $address ) + ->set_address( $address ); } /** @@ -111,24 +100,31 @@ 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 array( + return [ 'type' => 'Link', 'name' => 'Website', 'href' => \esc_url( get_post_meta( $post_id, 'event-location', true ) ), 'mediaType' => 'text/html', - ); + ]; } } /** - * Extends the get_attachments function to also add the event Link. + * Overrides/extends the get_attachments function to also add the event Link. */ protected function get_attachments() { $attachments = parent::get_attachments(); - $attachments[] = $this->get_event_link(); + $event_link = $this->get_event_link(); + if ( $event_link ) { + $attachments[] = $this->get_event_link(); + } return $attachments; } + private function get_category() { + return 'MEETING'; + } + /** * Transforms the VS Event WP_Post object to an ActivityPub Event Object. * @@ -192,7 +188,8 @@ class VS_Event extends \Activitypub\Transformer\Base { ->set_replies_moderation_option( 'allow_all' ) ->set_join_mode( 'external' ) ->set_external_participation_url( $this->get_url() ) - ->set_ical_status( 'CONFIRMED' ); + ->set_status( 'CONFIRMED' ) + ->set_category( 'MEETING' ); return $object; }