Compare commits

..

2 commits

Author SHA1 Message Date
a66aee49d5 rename main plugin file
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 45s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m11s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m1s
2024-10-02 20:21:10 +02:00
3f6a93e268 Rename plugin to ActivityPub Event Bridge
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 40s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 59s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 1m1s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 1m2s
2024-10-02 20:09:37 +02:00
7 changed files with 97 additions and 64 deletions

View file

@ -1,7 +1,7 @@
# ActivityPub Event Bridge
Contributors: andremenrath
Tags: events, fediverse, activitypub, calendar
Tags: events, fediverse, activitypub,, calendar
Requires at least: 6.5
Tested up to: 6.6
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?
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/).
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/).
### 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.

View file

@ -34,3 +34,39 @@ ActivityPub_Event_Bridge\Autoloader::register();
// Initialize the plugin.
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,48 +10,34 @@ To make the WordPress ActivityPub plugin use a custom transformer simply add a f
## Add your event plugin
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.
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`:
```php
namespace ActivityPub_Event_Bridge\Plugins;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/**
* 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 {
// Example from the Events Manager plugin.
'events_manager' => array( // Choose any key you like.
'plugin_file' => 'events-manager/events-manager.php',
'post_type' => 'event',
'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`.
),
```
The ActivityPub Event Bridge then takes care of applying the transformer, so you can jump right into implementing it.
The Plugin takes care of applying the transformer, so you can jump right into implementing it.
## Writing an event transformer class
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`.
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.
```php
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
/**
* ActivityPub Transformer for My Event Plugin' event post type.
* ActivityPub Transformer for my_event_post_type.
*/
class My_Event_Plugin extends Event_Transformer; {
class My_Event_Post_Type_Transformer extends Event; {
```
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.
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.
```php
/**
@ -66,16 +52,7 @@ public function to_object() {
}
```
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.
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.
### How to add new properties
@ -88,7 +65,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.
#### Mandatory fields
#### Mandatory Properties for an Event
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.
@ -98,12 +75,8 @@ 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
#### Checklist for properties you SHOULD at least consider writing a getter functions for
#### Recommended properties for an Event in order to achieve good interoperability with other ActivityPub platforms
* **`endTime`**
* **`location`** Note: the `address` within can be both a `string` or a `PostalAddress`.
* **`isOnline`**
* **`status`**
* **`get_tag`**
* **`timezone`**
* **`commentsEnabled`**
* **[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.
* **`isOnline`**:

View file

@ -168,13 +168,6 @@ abstract class Event extends Post {
return null;
}
/**
* Default value for the event status.
*/
protected function get_status(): ?string {
return 'CONFIRMED';
}
/**
* 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
*/
public function get_status(): ?string {
public function get_status() {
if ( 'canceled' === $this->tribe_event->event_status ) {
return 'CANCELLED';
}

View file

@ -1,6 +1,6 @@
=== ActivityPub Event Bridge ===
Contributors: andremenrath
Tags: events, fediverse, activitypub, calendar
Tags: events, fediverse, activitypub, activitystreams, calendar
Requires at least: 6.5
Tested up to: 6.6
Stable tag: 0.1.0
@ -50,10 +50,9 @@ 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? =
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.
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.
= 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.
= How much extra work is required to maintain my events across the decentralized Web? =

View file

@ -25,7 +25,39 @@ if ( ! current_user_can( 'manage_options' ) ) {
$event_terms = $args['event_terms'];
require_once ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/event-categories.php';
$default_event_category_strings = array(
'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' );
$current_category_mapping = \get_option( 'activitypub_event_bridge_event_category_mappings', array() );
@ -51,7 +83,7 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
<td>
<select id="activitypub_event_bridge_default_event_category" name="activitypub_event_bridge_default_event_category">';
<?php
foreach ( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES as $value => $label ) {
foreach ( $default_event_category_strings as $value => $label ) {
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $selected_default_event_category, $value, false ) . '>' . esc_html( $label ) . '</option>';
}
?>
@ -82,13 +114,13 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
$mapping = 'DEFAULT';
}
if ( 'DEFAULT' === $mapping ) {
echo '<option value="' . esc_attr( $mapping ) . '"> -- ' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $mapping ] ) . ' -- </option>';
echo '<option value="' . esc_attr( $mapping ) . '"> -- ' . esc_html( $default_event_category_strings[ $mapping ] ) . ' -- </option>';
} else {
echo '<option value="' . esc_attr( $mapping ) . '">' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $mapping ] ) . '</option>';
echo '<option value="' . esc_attr( $mapping ) . '">' . esc_html( $default_event_category_strings[ $mapping ] ) . '</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 ) {
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>';
echo '<option value="' . esc_attr( $event_category ) . '" ' . selected( $mappings[ $event_term->slug ] ?? '', $event_category, false ) . '>' . esc_html( $default_event_category_strings[ $event_category ] ) . '</option>';
}
?>
</select>