Compare commits

..

7 commits

Author SHA1 Message Date
0fba291706 fix readme
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 37s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m8s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m1s
2024-10-03 20:38:28 +02:00
8168df2965 remove duplicated definition of event category strings (#51)
Some checks failed
PHPUnit / PHPUnit – PHP 8.3 (push) Waiting to run
PHP Code Checker / PHP Code Checker (push) Successful in 39s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.2 (push) Has been cancelled
Reviewed-on: #51
2024-10-03 20:35:46 +02:00
8e56eb66c0 remove duplicated definition of event category strings
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 55s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m10s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m9s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m4s
2024-10-03 19:59:31 +02:00
4cc992d79b Remove actions needed for local https development
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 47s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m12s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m0s
moved to external plugin: https://code.event-federation.eu/Event-Federation/wordpress-localhost-https-development
2024-10-03 15:30:00 +02:00
17648dc664 improve documentation how to add new event plugin and write a new transformer
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 38s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m0s
2024-10-02 22:40:41 +02:00
a8627cdb02 set default status in the transformer 2024-10-02 22:40:12 +02:00
4aad867d1f Rename plugin to ActivityPub Event Bridge (#47)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 40s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m12s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m0s
See the results of the poll: https://graz.social/@linos/113214893071983918

Reviewed-on: #47
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
2024-10-02 21:54:03 +02:00
7 changed files with 64 additions and 97 deletions

View file

@ -1,7 +1,7 @@
# ActivityPub Event Bridge # ActivityPub Event Bridge
Contributors: andremenrath Contributors: andremenrath
Tags: events, fediverse, activitypub,, calendar Tags: events, fediverse, activitypub, calendar
Requires at least: 6.5 Requires at least: 6.5
Tested up to: 6.6 Tested up to: 6.6
Stable tag: 0.1.0 Stable tag: 0.1.0
@ -60,7 +60,7 @@ If youre new to the [ActivityPub plugin](https://wordpress.org/plugins/activi
### Do I need to install another event plugin to use the Event Federation plugin? ### Do I need to install another event plugin to use the Event Federation plugin?
Yes, this plugin works needs a supported event plugin such as The Events Calendar, VS Event List, or Events Manager to manage your events. It just fills the missing gap between event plugins and the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/). Yes, this plugin works as an add-on and requires both the ActivityPub plugin and a supported event plugin such as The Events Calendar, VS Event List, or Events Manager to manage your events. It just fills the missing gap between event plugins and the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/).
### What platforms can follow my events? ### What platforms can follow my events?
Your events can be followed on platforms that support ActivityPub like [Mobilizon](https://joinmobilizon.org/), [Gancio](https://gancio.org), [Friendica](https://friendi.ca), [Hubzilla](https://hubzilla.org), and [Pleroma](https://pleroma.social/). Even other applications like [Mastodon](https://joinmastodon.org), which dont fully support events yet, will display all important information about the events. Your events can be followed on platforms that support ActivityPub like [Mobilizon](https://joinmobilizon.org/), [Gancio](https://gancio.org), [Friendica](https://friendi.ca), [Hubzilla](https://hubzilla.org), and [Pleroma](https://pleroma.social/). Even other applications like [Mastodon](https://joinmastodon.org), which dont fully support events yet, will display all important information about the events.

View file

@ -34,39 +34,3 @@ ActivityPub_Event_Bridge\Autoloader::register();
// Initialize the plugin. // Initialize the plugin.
ActivityPub_Event_Bridge\Setup::get_instance(); ActivityPub_Event_Bridge\Setup::get_instance();
// BeforeFirstRelease: Remove everything after this after here.
/**
* Add a filter for http_request_host_is_external
*
* BeforeFirstRelease: Remove this for release.
*/
add_filter( 'http_request_host_is_external', 'activitypub_event_bridge_custom_http_request_host_is_external', 10, 3 );
/**
* Add a filter for http_request_host_is_external
*
* BeforeFirstRelease: Remove this for release.
*
* @param bool $is_external Whether the request is external.
*/
function activitypub_event_bridge_custom_http_request_host_is_external( $is_external ) {
$is_external = true;
return $is_external;
}
/**
* Don't verify ssl certs for testing.
*
* BeforeFirstRelease: Remove this for release.
*/
add_filter( 'https_ssl_verify', 'activitypub_event_bridge_dont_verify_local_dev_https', 10, 3 );
/**
* BeforeFirstRelease: remove it.
*/
function activitypub_event_bridge_dont_verify_local_dev_https() {
return false;
}

View file

@ -10,34 +10,48 @@ To make the WordPress ActivityPub plugin use a custom transformer simply add a f
## Add your event plugin ## Add your event plugin
First you need to add some basic information about your event plugin in the constant `SUPPORTED_EVENT_PLUGIN` in the file `includes/class-setup.php`: First you need to add some basic information about your event plugin. Just create a new file in `./includes/plugins/my-event-plugin.php`. Implement at least all abstract functions of the `Event_Plugin` class.
```php ```php
// Example from the Events Manager plugin. namespace ActivityPub_Event_Bridge\Plugins;
'events_manager' => array( // Choose any key you like.
'plugin_file' => 'events-manager/events-manager.php', // Exit if accessed directly.
'post_type' => 'event', defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
'settings_page' => 'options-general.php?page=vsel',
'transformer_class' => 'Events_Manager', // Points to the class in the file `includes/activitypub/transformer/class-events-manager.php`. /**
), * Integration information for My Event Plugin
*
* This class defines necessary meta information is for the integration of My Event Plugin with the ActivityPub plugin.
*
* @since 1.0.0
*/
final class My_Event_Plugin extends Event_Plugin {
``` ```
The Plugin takes care of applying the transformer, so you can jump right into implementing it. The ActivityPub Event Bridge then takes care of applying the transformer, so you can jump right into implementing it.
## Writing an event transformer class ## Writing an event transformer class
If you are writing a transformer for a custom post type it is recommended to start by extending the provided [event transformer](./includes/activitypub/transformer/class-event.php). It is an extension of the default generic post transformer and inherits useful default implementations for generating the [attachments](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment), rendering a proper [content](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content) in HTML from either blocks or the classic editor, extracting [tags](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag) and more. Within WordPress most content types are stored as a custom post type in the posts table. The ActivityPub plugin offers a basic support for all post types out of the box. So-called transformers take care of converting WordPress WP_Post objects to ActivityStreams JSON. The ActivityPub plugin offers a generic transformer for all post types. Additionally, custom transformers can be implemented to better fit a custom post type, and they can be easily registered with the ActivityPub plugin.
If you are writing a transformer for your event post type we recommend to start by extending the provided [event transformer](./includes/activitypub/transformer/class-event.php). It is an extension of the default generic post transformer and inherits useful default implementations for generating the [attachments](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment), rendering a proper [content](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content) in HTML from either blocks or the classic editor, extracting [tags](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag) and more. Furthermore, it offers functions which are likely to be shared by multiple event plugins, so you do not need to reimplement those, or you can fork and extend them to your needs.
So create a new file at `./includes/activitypub/transformer/my-event-plugin.php`.
```php ```php
namespace ActivityPub_Event_Bridge\Activitypub\Transformer; namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
/** /**
* ActivityPub Transformer for my_event_post_type. * ActivityPub Transformer for My Event Plugin' event post type.
*/ */
class My_Event_Post_Type_Transformer extends Event; { class My_Event_Plugin extends Event_Transformer; {
``` ```
The main function which controls the transformation is `to_object`. This one is called by the ActivityPub plugin to get the resulting ActivityPub representation as an PHP-array. The conversion to JSON-LD takes place later, and you don't need to cover that. You might just want to start by applying the parent function, but the chances are high, you don't even need to extend this functions functionality. The main function which controls the transformation is `to_object`. This one is called by the ActivityPub plugin to get the resulting ActivityStreams represented by a PHP-object (`\Activitypub\Activity\Object\Extended_Object\Event`). The conversion to the actual JSON-LD takes place later, and you don't need to cover that (> `to_array` > associative array > `to_json` > JSON).
The chances are good that you will not need to override that function.
```php ```php
/** /**
@ -52,7 +66,16 @@ public function to_object() {
} }
``` ```
The ActivityPub object classes contain dynamic getter and setter functions: `set_<property-name>` and `get_<property-name>`. Of course, the property with `property-name` must exist for these to work. The function `transform_object_properties` tries to set all properties known to the ActivityPub object where a function called `get_<property-name>` exists in the current transformer class. We also recommend extending the constructor of the transformer class and set a specialized API object of the event, if it is available. For instance:
```php
public function __construct( $wp_object, $wp_taxonomy ) {
parent::__construct( $wp_object, $wp_taxonomy );
$this->event_api = new My_Event_Object_API( $wp_object );
}
```
The ActivityPub object classes contain dynamic getter and setter functions: `set_<property>()` and `get_<property>()`. The function `transform_object_properties()` usually called by `to_object()` tries to set all properties known to the target ActivityPub object where a function called `get_<property>` exists in the current transformer class.
### How to add new properties ### How to add new properties
@ -65,7 +88,7 @@ Adding new properties is not encouraged to do at the transformer level. It's rec
You can find all available event related properties in the [event class](https://github.com/Automattic/wordpress-activitypub/blob/master/includes/activity/extended-object/class-event.php) along documentation and with links to the specifications. You can find all available event related properties in the [event class](https://github.com/Automattic/wordpress-activitypub/blob/master/includes/activity/extended-object/class-event.php) along documentation and with links to the specifications.
#### Mandatory Properties for an Event #### Mandatory fields
In order to ensure your events are compatible with other ActivityPub Event implementations there are several required properties that must be set by your transformer. In order to ensure your events are compatible with other ActivityPub Event implementations there are several required properties that must be set by your transformer.
@ -75,8 +98,12 @@ In order to ensure your events are compatible with other ActivityPub Event imple
* **[`name`](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name)**: the title of the event * **[`name`](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name)**: the title of the event
#### Recommended properties for an Event in order to achieve good interoperability with other ActivityPub platforms #### Checklist for properties you SHOULD at least consider writing a getter functions for
* **[summary](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary)**: Other ActivityPub platforms that don't natively support event should use the summary (and the `name`) to display it as a converted object type. For example Mastodon converts an `Event` object to a `Note`. It is recommended to write the summary as text-centered with minimal HTML markup and that it contains the most important event details like place, time, etc. * **`endTime`**
* **`location`** Note: the `address` within can be both a `string` or a `PostalAddress`.
* **`isOnline`**: * **`isOnline`**
* **`status`**
* **`get_tag`**
* **`timezone`**
* **`commentsEnabled`**

View file

@ -168,6 +168,13 @@ abstract class Event extends Post {
return null; return null;
} }
/**
* Default value for the event status.
*/
protected function get_status(): ?string {
return 'CONFIRMED';
}
/** /**
* Compose a human readable formatted start time. * Compose a human readable formatted start time.
*/ */

View file

@ -94,7 +94,7 @@ final class The_Events_Calendar extends Event {
* *
* @return string status of the event * @return string status of the event
*/ */
public function get_status() { public function get_status(): ?string {
if ( 'canceled' === $this->tribe_event->event_status ) { if ( 'canceled' === $this->tribe_event->event_status ) {
return 'CANCELLED'; return 'CANCELLED';
} }

View file

@ -1,6 +1,6 @@
=== ActivityPub Event Bridge === === ActivityPub Event Bridge ===
Contributors: andremenrath Contributors: andremenrath
Tags: events, fediverse, activitypub, activitystreams, calendar Tags: events, fediverse, activitypub, calendar
Requires at least: 6.5 Requires at least: 6.5
Tested up to: 6.6 Tested up to: 6.6
Stable tag: 0.1.0 Stable tag: 0.1.0
@ -50,9 +50,10 @@ If youre new to the [ActivityPub plugin](https://wordpress.org/plugins/activi
= Do I need to install another event plugin to use the Event Federation Plugin? = = Do I need to install another event plugin to use the Event Federation Plugin? =
Yes, this plugin works as an add-on and requires both the ActivityPub plugin a supported event plugin such as The Events Calendar, VS Event List, or Events Manager to manage your events. Yes, this plugin works as an add-on and requires both the ActivityPub plugin and a supported event plugin such as The Events Calendar, VS Event List, or Events Manager to manage your events.
= What platforms can follow my events? = = What platforms can follow my events? =
Your events can be followed on platforms that support ActivityPub like [Mobilizon](https://joinmobilizon.org/), [Gancio](https://gancio.org), [Friendica](https://friendi.ca), [Hubzilla](https://hubzilla.org), and [Pleroma](https://pleroma.social/). Even other applications like [Mastodon](https://joinmastodon.org), which dont fully support events yet, will display all important information about the events. Your events can be followed on platforms that support ActivityPub like [Mobilizon](https://joinmobilizon.org/), [Gancio](https://gancio.org), [Friendica](https://friendi.ca), [Hubzilla](https://hubzilla.org), and [Pleroma](https://pleroma.social/). Even other applications like [Mastodon](https://joinmastodon.org), which dont fully support events yet, will display all important information about the events.
= How much extra work is required to maintain my events across the decentralized Web? = = How much extra work is required to maintain my events across the decentralized Web? =

View file

@ -25,39 +25,7 @@ if ( ! current_user_can( 'manage_options' ) ) {
$event_terms = $args['event_terms']; $event_terms = $args['event_terms'];
$default_event_category_strings = array( require_once ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/event-categories.php';
'ARTS' => __( 'Arts', 'activitypub-event-bridge' ),
'BOOK_CLUBS' => __( 'Book clubs', 'activitypub-event-bridge' ),
'BUSINESS' => __( 'Business', 'activitypub-event-bridge' ),
'CAUSES' => __( 'Causes', 'activitypub-event-bridge' ),
'COMEDY' => __( 'Comedy', 'activitypub-event-bridge' ),
'CRAFTS' => __( 'Crafts', 'activitypub-event-bridge' ),
'FOOD_DRINK' => __( 'Food & Drink', 'activitypub-event-bridge' ),
'HEALTH' => __( 'Health', 'activitypub-event-bridge' ),
'MUSIC' => __( 'Music', 'activitypub-event-bridge' ),
'AUTO_BOAT_AIR' => __( 'Auto, boat and air', 'activitypub-event-bridge' ),
'COMMUNITY' => __( 'Community', 'activitypub-event-bridge' ),
'FAMILY_EDUCATION' => __( 'Family & Education', 'activitypub-event-bridge' ),
'FASHION_BEAUTY' => __( 'Fashion & Beauty', 'activitypub-event-bridge' ),
'FILM_MEDIA' => __( 'Film & Media', 'activitypub-event-bridge' ),
'GAMES' => __( 'Games', 'activitypub-event-bridge' ),
'LANGUAGE_CULTURE' => __( 'Language & Culture', 'activitypub-event-bridge' ),
'LEARNING' => __( 'Learning', 'activitypub-event-bridge' ),
'LGBTQ' => __( 'LGBTQ', 'activitypub-event-bridge' ),
'MOVEMENTS_POLITICS' => __( 'Movements and politics', 'activitypub-event-bridge' ),
'NETWORKING' => __( 'Networking', 'activitypub-event-bridge' ),
'PARTY' => __( 'Party', 'activitypub-event-bridge' ),
'PERFORMING_VISUAL_ARTS' => __( 'Performing & Visual Arts', 'activitypub-event-bridge' ),
'PETS' => __( 'Pets', 'activitypub-event-bridge' ),
'PHOTOGRAPHY' => __( 'Photography', 'activitypub-event-bridge' ),
'OUTDOORS_ADVENTURE' => __( 'Outdoors & Adventure', 'activitypub-event-bridge' ),
'SPIRITUALITY_RELIGION_BELIEFS' => __( 'Spirituality, Religion & Beliefs', 'activitypub-event-bridge' ),
'SCIENCE_TECH' => __( 'Science & Tech', 'activitypub-event-bridge' ),
'SPORTS' => __( 'Sports', 'activitypub-event-bridge' ),
'THEATRE' => __( 'Theatre', 'activitypub-event-bridge' ),
'MEETING' => __( 'Meeting', 'activitypub-event-bridge' ), // Default value in federation.
'DEFAULT' => __( 'Default', 'activitypub-event-bridge' ), // Internal default for overrides.
);
$selected_default_event_category = \get_option( 'activitypub_event_bridge_default_event_category', 'MEETING' ); $selected_default_event_category = \get_option( 'activitypub_event_bridge_default_event_category', 'MEETING' );
$current_category_mapping = \get_option( 'activitypub_event_bridge_event_category_mappings', array() ); $current_category_mapping = \get_option( 'activitypub_event_bridge_event_category_mappings', array() );
@ -83,7 +51,7 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
<td> <td>
<select id="activitypub_event_bridge_default_event_category" name="activitypub_event_bridge_default_event_category">'; <select id="activitypub_event_bridge_default_event_category" name="activitypub_event_bridge_default_event_category">';
<?php <?php
foreach ( $default_event_category_strings as $value => $label ) { foreach ( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES as $value => $label ) {
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $selected_default_event_category, $value, false ) . '>' . esc_html( $label ) . '</option>'; echo '<option value="' . esc_attr( $value ) . '" ' . selected( $selected_default_event_category, $value, false ) . '>' . esc_html( $label ) . '</option>';
} }
?> ?>
@ -114,13 +82,13 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
$mapping = 'DEFAULT'; $mapping = 'DEFAULT';
} }
if ( 'DEFAULT' === $mapping ) { if ( 'DEFAULT' === $mapping ) {
echo '<option value="' . esc_attr( $mapping ) . '"> -- ' . esc_html( $default_event_category_strings[ $mapping ] ) . ' -- </option>'; echo '<option value="' . esc_attr( $mapping ) . '"> -- ' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $mapping ] ) . ' -- </option>';
} else { } else {
echo '<option value="' . esc_attr( $mapping ) . '">' . esc_html( $default_event_category_strings[ $mapping ] ) . '</option>'; echo '<option value="' . esc_attr( $mapping ) . '">' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $mapping ] ) . '</option>';
} }
echo '<option value="DEFAULT" ' . selected( $selected_default_event_category, 'DEFAULT', false ) . '> -- ' . esc_html__( 'Default', 'activitypub-event-bridge' ) . ' -- </option>'; echo '<option value="DEFAULT" ' . selected( $selected_default_event_category, 'DEFAULT', false ) . '> -- ' . esc_html__( 'Default', 'activitypub-event-bridge' ) . ' -- </option>';
foreach ( Event::DEFAULT_EVENT_CATEGORIES as $event_category ) { foreach ( Event::DEFAULT_EVENT_CATEGORIES as $event_category ) {
echo '<option value="' . esc_attr( $event_category ) . '" ' . selected( $mappings[ $event_term->slug ] ?? '', $event_category, false ) . '>' . esc_html( $default_event_category_strings[ $event_category ] ) . '</option>'; echo '<option value="' . esc_attr( $event_category ) . '" ' . selected( $mappings[ $event_term->slug ] ?? '', $event_category, false ) . '>' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $event_category ] ) . '</option>';
} }
?> ?>
</select> </select>