diff --git a/README.md b/README.md index bdcc0eb..8391711 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -This is a WordPress plugin that contains several example custom transformers for the [WordPress ActivityPub plugin](https://wordpress.org/plugins/activitypub/). \ No newline at end of file +This is a WordPress plugin improves the Fediverse integration of Events via the [WordPress ActivityPub plugin](https://wordpress.org/plugins/activitypub/). + +Currently supported Event plugins: + +- The Events Calendar +- VS Event List +- Events Manager diff --git a/activitypub-event-transformers.php b/activitypub-event-extensions.php similarity index 88% rename from activitypub-event-transformers.php rename to activitypub-event-extensions.php index 501dec5..f676c3d 100644 --- a/activitypub-event-transformers.php +++ b/activitypub-event-extensions.php @@ -1,17 +1,17 @@ ap_object->has( $key ) ) { + return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) ); + } + + $setter_function = 'set_' . $key; + + if ( in_array($key, get_class_methods( $this ) )) { + $getter_function = 'get_' . $key; + $this->ap_object->$setter_function( $this->$getter_function ); + } else { + $this->ap_object->$setter_function( $value ); + } + + return $this; + } + + /** + * Magic function to implement setter + * + * @param string $method The method name. + * @param string $params The method params. + * + * @return void + */ + public function __call( $method, $params ) { + $var = \strtolower( \substr( $method, 4 ) ); + + if ( \strncasecmp( $method, 'set', 3 ) === 0 ) { + return $this->set( $var, $params[0] ); + } + + // when do we need: call_user_func( array( $activitypub_object, $setter ), $value ); + + return $this; + } + /** * Transform the WordPress Object into an ActivityPub Object. * * @return Activitypub\Activity\Event */ public function to_object() { - $object = new Event(); - $object = $this->transform_object_properties( $object ); - - // Set hardcoded values/one-liners that don't have a get(ter) function defined. - return $object + $this->ap_object = new Event(); + + $this + ->set_content() + ->set_content_map() + ->set_attributed_to() + ->set_published() + ->set_start_time() + ->set_end_time() + ->set_type() + ->set_category() + ->set_attachments() + ->set_location() ->set_comments_enabled( true ) ->set_external_participation_url( $this->get_url() ) ->set_status( 'CONFIRMED' ) ->set_name( get_the_title( $this->wp_object->ID ) ) - ->set_timezone( $object->get_locale ) ->set_is_online( false ) ->set_in_language( $this->get_locale() ) ->set_actor( get_rest_url_by_path( 'application' ) ) diff --git a/readme.txt b/readme.txt index b58aed0..2edbd5c 100644 --- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@ -=== ActivityPub Event Plugin === +=== ActivityPub Event Extensions === Contributors: menrath Tags: events, fediverse, activitypub, activitystream Requires at least: 6.4 @@ -8,7 +8,7 @@ Requires PHP: 5.6 License: AGPL-3.0-or-later License URI: http://opensource.org/licenses/MIT -The ActivityPub Event Plugin is... +The ActivityPub Event Extensions == Description ==