From 02a3eb7cef3690ce0f364a6d3b064423e3ff9e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Tue, 19 Nov 2024 21:05:21 +0100 Subject: [PATCH 01/14] WIP: proof of concept --- activitypub-event-bridge.php | 4 +- assets/css/activitypub-event-bridge-admin.css | 4 + assets/js/activitypub-event-bridge-admin.js | 19 ++ .../activitypub/transformer/class-event.php | 62 ++++- .../transformer/class-the-events-calendar.php | 4 +- includes/class-event-shortcodes.php | 253 ++++++++++++++++++ includes/class-settings.php | 22 ++ templates/settings.php | 46 ++++ 8 files changed, 406 insertions(+), 8 deletions(-) create mode 100644 includes/class-event-shortcodes.php diff --git a/activitypub-event-bridge.php b/activitypub-event-bridge.php index 961af39..0276072 100644 --- a/activitypub-event-bridge.php +++ b/activitypub-event-bridge.php @@ -3,7 +3,7 @@ * Plugin Name: ActivityPub Event Bridge * Description: Integrating popular event plugins with the ActivityPub plugin. * Plugin URI: https://event-federation.eu/ - * Version: 0.2.1 + * Version: 0.2.1.4 * Author: AndrΓ© Menrath * Author URI: https://graz.social/@linos * Text Domain: activitypub-event-bridge @@ -27,6 +27,8 @@ define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) ); define( 'ACTIVITYPUB_EVENT_BRIDGE_DOMAIN', 'activitypub-event-bridge' ); define( 'ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION', '3.2.2' ); +define( 'ACTIVITYPUB_EVENT_BRIDGE_CUSTOM_SUMMARY', "\n[ap_hashcats][ap_hashtags]" ); +define( 'ACTIVITYPUB_EVENT_BRIDGE_DEFAULT_SUMMARY_TYPE', 'preset' ); // Include and register the autoloader class for automatic loading of plugin classes. require_once ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/class-autoloader.php'; diff --git a/assets/css/activitypub-event-bridge-admin.css b/assets/css/activitypub-event-bridge-admin.css index c89ec6e..043082f 100644 --- a/assets/css/activitypub-event-bridge-admin.css +++ b/assets/css/activitypub-event-bridge-admin.css @@ -177,3 +177,7 @@ code.activitypub-event-bridge-settings-example-url { overflow-x: auto; word-break: break-all; } + +#activitypub_summary_type_custom-details { + display: none; +} diff --git a/assets/js/activitypub-event-bridge-admin.js b/assets/js/activitypub-event-bridge-admin.js index bf00a1c..4716ec8 100644 --- a/assets/js/activitypub-event-bridge-admin.js +++ b/assets/js/activitypub-event-bridge-admin.js @@ -11,4 +11,23 @@ jQuery( function( $ ) { $( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false ); } } ); + + // Function to toggle visibility of custom details based on selected radio button. + function toggleCustomDetailsForSummary() { + if ($("#activitypub_summary_type_custom").is(':checked')) { + $("#activitypub_summary_type_custom-details").show(); + } else { + $("#activitypub_summary_type_custom-details").hide(); + } + } + + // Run the toggle function on page load. + $(document).ready(function() { + toggleCustomDetailsForSummary(); // Set the correct state on load. + + // Listen for changes on the radio buttons + $("input[name=activitypub_summary_type]").change(function() { + toggleCustomDetailsForSummary(); // Update visibility on change. + }); + }); } ); diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index babf2b9..6d742cd 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -14,6 +14,8 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore use Activitypub\Activity\Extended_Object\Event as Event_Object; use Activitypub\Activity\Extended_Object\Place; use Activitypub\Transformer\Post; +use ActivityPub_Event_Bridge\Event_Shortcodes; + use DateTime; /** @@ -148,14 +150,14 @@ abstract class Event extends Post { * * This is mandatory and must be implemented in the final event transformer class. */ - abstract protected function get_start_time(): string; + abstract public function get_start_time(): string; /** * Get the end time. * * This is not mandatory and therefore just return null by default. */ - protected function get_end_time(): ?string { + public function get_end_time(): ?string { return null; } @@ -164,14 +166,14 @@ abstract class Event extends Post { * * This should be overridden in the actual event transformer. */ - protected function get_location(): ?Place { + public function get_location(): ?Place { return null; } /** * Default value for the event status. */ - protected function get_status(): ?string { + public function get_status(): ?string { return 'CONFIRMED'; } @@ -255,6 +257,44 @@ abstract class Event extends Post { return ''; } + + + /** + * Get the summary. + */ + public function get_summary(): ?string { + if ( 'preset' === get_option( 'activitypub_summary_type', 'preset' ) ) { + return $this->get_preset_summary(); + } + + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + $post = $this->wp_object; + $summary = $this->get_event_summary_template(); + + // It seems that shortcodes are only applied to published posts. + if ( is_preview() ) { + $post->post_status = 'publish'; + } + + // Register our shortcodes just in time. + Event_Shortcodes::register(); + // Fill in the shortcodes. + \setup_postdata( $post ); + $summary = \do_shortcode( $summary ); + \wp_reset_postdata(); + + $summary = \wpautop( $summary ); + $summary = \preg_replace( '/[\n\r\t]/', '', $summary ); + $summary = \trim( $summary ); + + $summary = \apply_filters( 'activitypub_event_bridge_the_summary', $summary, $post ); + + // Don't need these anymore, should never appear in a post. + Event_Shortcodes::unregister(); + + return $summary; + } + /** * Create a custom summary. * @@ -263,7 +303,7 @@ abstract class Event extends Post { * * @return string $summary The custom event summary. */ - public function get_summary(): ?string { + public function get_preset_summary(): ?string { add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2 ); $excerpt = $this->retrieve_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. @@ -308,6 +348,18 @@ abstract class Event extends Post { return $summary; } + /** + * Gets the template to use to generate the summary of the ActivityStreams representation of an event post. + * + * @return string The Template. + */ + protected function get_event_summary_template() { + $summary = \get_option( 'activitypub_event_bridge_custom_summary', ACTIVITYPUB_EVENT_BRIDGE_CUSTOM_SUMMARY ); + $template = $summary ?? ACTIVITYPUB_EVENT_BRIDGE_CUSTOM_SUMMARY; + + return apply_filters( 'activitypub_event_bridge_summary_template', $template, $this->wp_object ); + } + /** * By default set the timezone of the WordPress site. * diff --git a/includes/activitypub/transformer/class-the-events-calendar.php b/includes/activitypub/transformer/class-the-events-calendar.php index f50fa29..80ac52e 100644 --- a/includes/activitypub/transformer/class-the-events-calendar.php +++ b/includes/activitypub/transformer/class-the-events-calendar.php @@ -72,7 +72,7 @@ final class The_Events_Calendar extends Event { /** * Get the end time from the event object. */ - protected function get_end_time(): ?string { + public function get_end_time(): ?string { if ( empty( $this->tribe_event->end_date ) ) { return null; } @@ -83,7 +83,7 @@ final class The_Events_Calendar extends Event { /** * Get the end time from the event object. */ - protected function get_start_time(): string { + public function get_start_time(): string { $date = date_create( $this->tribe_event->start_date, wp_timezone() ); return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() ); } diff --git a/includes/class-event-shortcodes.php b/includes/class-event-shortcodes.php new file mode 100644 index 0000000..611150f --- /dev/null +++ b/includes/class-event-shortcodes.php @@ -0,0 +1,253 @@ +getTimestamp(); + $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); + return wp_date( $datetime_format, $start_timestamp ); + } + + /** + * Generates output for the 'apeb_start_time' shortcode. + * + * @param ?array $atts The shortcodes attributes. + * + * @return string The formatted start date and time of the event. + */ + public static function start_time( $atts ) { + $transformer = self::get_transformer(); + + if ( ! $transformer ) { + return ''; + } + + $args = shortcode_atts( + array( + 'icon' => 'true', + 'title' => 'true', + ), + $atts, + 'ap_start_time' + ); + + $args['icon'] = filter_var( $args['icon'], FILTER_VALIDATE_BOOLEAN ); + $args['title'] = filter_var( $args['title'], FILTER_VALIDATE_BOOLEAN ); + + $start_timestamp = $transformer->get_start_time(); + + if ( ! $start_timestamp ) { + return ''; + } + + $start_time = array(); + + if ( $args['icon'] ) { + $start_time[] = 'πŸ—“οΈ'; + } + + if ( $args['title'] ) { + $start_time[] = __( 'Start', 'activitypub-event-bridge' ) . ':'; + } + + $start_time[] = self::format_time( $start_timestamp ); + + $start_time = implode( ' ', $start_time ); + + return $start_time; + } + + /** + * Generates output for the 'apeb_end_time' shortcode. + * + * @param ?array $atts The shortcodes attributes. + * + * @return string The formatted end date and time of the event. + */ + public static function end_time( $atts ) { + $transformer = self::get_transformer(); + + if ( ! $transformer ) { + return ''; + } + + $args = shortcode_atts( + array( + 'icon' => 'true', + 'title' => 'true', + ), + $atts, + 'ap_end_time' + ); + + $args['icon'] = filter_var( $args['icon'], FILTER_VALIDATE_BOOLEAN ); + $args['title'] = filter_var( $args['title'], FILTER_VALIDATE_BOOLEAN ); + + $end_timestamp = $transformer->get_end_time(); + + if ( ! $end_timestamp ) { + return ''; + } + + $end_time = array(); + + if ( $args['icon'] ) { + $end_time[] = '⏳'; + } + + if ( $args['title'] ) { + $end_time[] = __( 'End', 'activitypub-event-bridge' ) . ':'; + } + + $end_time[] = self::format_time( $end_timestamp ); + + $end_time = implode( ' ', $end_time ); + + return $end_time; + } + + /** + * Generates output for the 'apeb_location shortcode. + * + * @param ?array $atts The shortcodes attributes. + * + * @return string The formatted location/address of the event. + */ + public static function location( $atts ) { + $transformer = self::get_transformer(); + + if ( ! $transformer ) { + return ''; + } + + $args = shortcode_atts( + array( + 'icon' => 'true', + 'title' => 'true', + 'country' => 'true', + 'zip' => 'true', + 'city' => 'true', + 'street' => 'true', + 'name' => 'true', + ), + $atts, + 'ap_location' + ); + + foreach ( $args as $arg => $value ) { + $args[ $arg ] = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); + } + + $location = $transformer->get_location(); + + if ( ! $location ) { + return ''; + } + + $output = array(); + + if ( $args['icon'] ) { + $output[] = 'πŸ“'; + } + + if ( $args['title'] ) { + $output[] = __( 'Location', 'activitypub-event-bridge' ) . ':'; + } + + $address = $location->get_address(); + + if ( $address ) { + if ( is_string( $address ) ) { + $output[] = $address; + } + if ( is_array( $address ) ) { + if ( $args['name'] && array_key_exists( 'name', $address ) ) { + $output[] = $address['name'] . ','; + } + if ( $args['street'] && array_key_exists( 'streetAddress', $address ) ) { + $output[] = $address['streetAddress'] . ','; + } + if ( $args['zip'] && array_key_exists( 'postalCode', $address ) ) { + $output[] = $address['postalCode']; + } + if ( $args['city'] && array_key_exists( 'addressLocality', $address ) ) { + $output[] = $address['addressLocality'] . ','; + } + if ( $args['country'] && array_key_exists( 'addressCountry', $address ) ) { + $output[] = $address['addressCountry']; + } + } + } + + $output = implode( ' ', $output ); + + return $output; + } +} diff --git a/includes/class-settings.php b/includes/class-settings.php index 6cd7d2e..da1467d 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -71,6 +71,28 @@ class Settings { 'default' => 1, ) ); + + \register_setting( + 'activitypub-event-bridge', + 'activitypub_summary_type', + array( + 'type' => 'string', + 'description' => \__( 'Summary type to use for ActivityStreams', 'activitypub-event-bridge' ), + 'show_in_rest' => true, + 'default' => 'preset', + ) + ); + + \register_setting( + 'activitypub-event-bridge', + 'activitypub_event_bridge_custom_summary', + array( + 'type' => 'string', + 'description' => \__( 'Define your own custom summary template for events', 'activitypub-event-bridge' ), + 'show_in_rest' => true, + 'default' => ACTIVITYPUB_EVENT_BRIDGE_CUSTOM_SUMMARY, + ) + ); } /** diff --git a/templates/settings.php b/templates/settings.php index 309590f..e9390d1 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -42,6 +42,52 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
+
+

+

+

+ +

+

+ +

+
+ +
+ +
+
+
[ap_start_time]
+
+
[ap_end_time]
+
+
[ap_location]
+
+
[ap_hashtags]
+
+
[ap_excerpt]
+
+
[ap_content]
+
+
+
+
+
+

-- 2.39.5 From b7b36d355e198f81c05aef12982e48fd434927fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 21 Nov 2024 14:32:43 +0100 Subject: [PATCH 02/14] move event related shortcodes to base event transformer --- .../activitypub/transformer/class-event.php | 205 ++++++++++++-- includes/class-event-shortcodes.php | 253 ------------------ 2 files changed, 183 insertions(+), 275 deletions(-) delete mode 100644 includes/class-event-shortcodes.php diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index 6d742cd..ffdac82 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -13,8 +13,8 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore use Activitypub\Activity\Extended_Object\Event as Event_Object; use Activitypub\Activity\Extended_Object\Place; +use Activitypub\Shortcodes; use Activitypub\Transformer\Post; -use ActivityPub_Event_Bridge\Event_Shortcodes; use DateTime; @@ -196,7 +196,7 @@ abstract class Event extends Post { * * @param ?string $time The time which needs to be formatted. */ - private static function format_time( $time ) { + protected static function format_time( $time ) { if ( is_null( $time ) ) { return ''; } @@ -207,24 +207,160 @@ abstract class Event extends Post { } /** - * Format a human readable address. + * Generates output for the 'ap_start_time' shortcode. + * + * @param ?array $atts The shortcode's attributes. + * @return string The formatted start date and time of the event. */ - protected function format_address(): string { + public function shortcode_start_time( $atts ) { + $start_timestamp = $this->get_start_time(); + return $this->generate_time_output( $start_timestamp, $atts, 'πŸ—“οΈ', __( 'Start', 'activitypub-event-bridge' ) ); + } + + /** + * Generates output for the 'ap_end_time' shortcode. + * + * @param ?array $atts The shortcode's attributes. + * @return string The formatted end date and time of the event. + */ + public function shortcode_end_time( $atts ) { + $end_timestamp = $this->get_end_time(); + return $this->generate_time_output( $end_timestamp, $atts, '⏳', __( 'End', 'activitypub-event-bridge' ) ); + } + + /** + * Generates the formatted time output for a shortcode. + * + * @param int|null $timestamp The timestamp for the event time. + * @param array $atts The shortcode attributes. + * @param string $icon The icon to display. + * @param string $label The label to display (e.g., 'Start', 'End'). + * @return string The formatted date and time, or an empty string if the timestamp is invalid. + */ + private function generate_time_output( $timestamp, $atts, $icon, $label ) { + if ( ! $timestamp ) { + return ''; + } + + $args = shortcode_atts( + array( + 'icon' => 'true', + 'title' => 'true', + ), + $atts + ); + + $args['icon'] = filter_var( $args['icon'], FILTER_VALIDATE_BOOLEAN ); + $args['title'] = filter_var( $args['title'], FILTER_VALIDATE_BOOLEAN ); + + $output = array(); + + if ( $args['icon'] ) { + $output[] = $icon; + } + + if ( $args['title'] ) { + $output[] = $label . ':'; + } + + $output[] = self::format_time( $timestamp ); + + return implode( ' ', $output ); + } + + /** + * Generates output for the 'ap_location' shortcode. + * + * @param ?array $atts The shortcode's attributes. + * @return string The formatted location/address of the event. + */ + public function shortcode_location( $atts ) { + $args = shortcode_atts( + array( + 'icon' => 'true', + 'title' => 'true', + 'country' => 'true', + 'zip' => 'true', + 'city' => 'true', + 'street' => 'true', + 'name' => 'true', + ), + $atts, + 'ap_location' + ); + + // Convert attributes to booleans. + $args = array_map( + function ( $value ) { + return filter_var( $value, FILTER_VALIDATE_BOOLEAN ); + }, + $args + ); + $location = $this->get_location(); - if ( is_null( $location ) ) { + if ( ! $location ) { return ''; } - $address = $location->get_address(); - if ( ! $address ) { - return $location->get_name(); + + $output = array(); + if ( $args['icon'] ) { + $output[] = 'πŸ“'; } + if ( $args['title'] ) { + $output[] = esc_html__( 'Location', 'activitypub-event-bridge' ) . ':'; + } + + $output[] = self::format_address( $location->get_address(), $args ); + + // Join output array into a single string with spaces and return. + return implode( ' ', array_filter( $output ) ); + } + + /** + * Formats the address based on provided arguments. + * + * @param mixed $address The address data, either as a string or an array. + * @param array $args The arguments for which components to include. + * @return string The formatted address. + */ + protected static function format_address( $address, $args = null) { if ( is_string( $address ) ) { - return $address; + return esc_html( $address ); } - if ( ! is_array( $address ) ) { - return ''; + + if ( is_null( $args ) ) { + $args = array( + 'icon' => 'true', + 'title' => 'true', + 'country' => 'true', + 'zip' => 'true', + 'city' => 'true', + 'street' => 'true', + 'name' => 'true', + ); } - return isset( $address['locality'] ) ? $address['locality'] : ''; + + if ( is_array( $address ) ) { + $address_parts = array(); + + $components = array( + 'name' => 'name', + 'street' => 'streetAddress', + 'zip' => 'postalCode', + 'city' => 'addressLocality', + 'country' => 'addressCountry', + ); + + foreach ( $components as $arg_key => $address_key ) { + if ( $args[ $arg_key ] && ! empty( $address[ $address_key ] ) ) { + $address_parts[] = esc_html( $address[ $address_key ] ); + } + } + + return implode( ', ', $address_parts ); + } + + return ''; } /** @@ -257,14 +393,34 @@ abstract class Event extends Post { return ''; } + /** + * Register the shortcodes. + */ + public function register_shortcodes() { + foreach ( get_class_methods( self::class ) as $function ) { + if ( 'shortcode_' === substr( $function, 0, 10 ) ) { + add_shortcode( 'ap_' . substr( $function, 10, strlen( $function ) ), array( $this, $function ) ); + } + } + } + /** + * Register the shortcodes. + */ + public function unregister_shortcodes() { + foreach ( get_class_methods( self::class ) as $function ) { + if ( 'shortcode_' === substr( $function, 0, 10 ) ) { + remove_shortcode( 'ap_' . substr( $function, 10, strlen( $function ) ), array( $this, $function ) ); + } + } + } /** * Get the summary. */ public function get_summary(): ?string { if ( 'preset' === get_option( 'activitypub_summary_type', 'preset' ) ) { - return $this->get_preset_summary(); + return $this->format_preset_summary(); } // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited @@ -277,7 +433,10 @@ abstract class Event extends Post { } // Register our shortcodes just in time. - Event_Shortcodes::register(); + + Shortcodes::register(); + $this->register_shortcodes(); + // Fill in the shortcodes. \setup_postdata( $post ); $summary = \do_shortcode( $summary ); @@ -289,8 +448,9 @@ abstract class Event extends Post { $summary = \apply_filters( 'activitypub_event_bridge_the_summary', $summary, $post ); - // Don't need these anymore, should never appear in a post. - Event_Shortcodes::unregister(); + // Unregister the shortcodes. + Shortcodes::unregister(); + $this->unregister_shortcodes(); return $summary; } @@ -303,7 +463,7 @@ abstract class Event extends Post { * * @return string $summary The custom event summary. */ - public function get_preset_summary(): ?string { + public function format_preset_summary(): ?string { add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2 ); $excerpt = $this->retrieve_excerpt(); // BeforeFirstRelease: decide whether this should be a admin setting. @@ -314,9 +474,10 @@ abstract class Event extends Post { remove_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ) ); $category = $this->format_categories(); - $start_time = $this->format_start_time(); - $end_time = $this->format_end_time(); - $address = $this->format_address(); + $start_time = $this->get_start_time(); + $end_time = $this->get_end_time(); + $address = $this->format_address( $this->get_location() ); + $time_atts = array( 'icon' => true, 'label' => true); $formatted_items = array(); if ( ! empty( $category ) ) { @@ -324,11 +485,11 @@ abstract class Event extends Post { } if ( ! empty( $start_time ) ) { - $formatted_items[] = 'πŸ—“οΈ ' . __( 'Start', 'activitypub-event-bridge' ) . ': ' . $start_time; + $formatted_items[] = $this->generate_time_output( $start_time, $time_atts, 'πŸ—“οΈ', __( 'Start', 'activitypub-event-bridge' ) ); } if ( ! empty( $end_time ) ) { - $formatted_items[] = '⏳ ' . __( 'End', 'activitypub-event-bridge' ) . ': ' . $end_time; + $formatted_items[] = $this->generate_time_output( $end_time, $time_atts, '⏳', __( 'End', 'activitypub-event-bridge' ) ); } if ( ! empty( $address ) ) { diff --git a/includes/class-event-shortcodes.php b/includes/class-event-shortcodes.php deleted file mode 100644 index 611150f..0000000 --- a/includes/class-event-shortcodes.php +++ /dev/null @@ -1,253 +0,0 @@ -getTimestamp(); - $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); - return wp_date( $datetime_format, $start_timestamp ); - } - - /** - * Generates output for the 'apeb_start_time' shortcode. - * - * @param ?array $atts The shortcodes attributes. - * - * @return string The formatted start date and time of the event. - */ - public static function start_time( $atts ) { - $transformer = self::get_transformer(); - - if ( ! $transformer ) { - return ''; - } - - $args = shortcode_atts( - array( - 'icon' => 'true', - 'title' => 'true', - ), - $atts, - 'ap_start_time' - ); - - $args['icon'] = filter_var( $args['icon'], FILTER_VALIDATE_BOOLEAN ); - $args['title'] = filter_var( $args['title'], FILTER_VALIDATE_BOOLEAN ); - - $start_timestamp = $transformer->get_start_time(); - - if ( ! $start_timestamp ) { - return ''; - } - - $start_time = array(); - - if ( $args['icon'] ) { - $start_time[] = 'πŸ—“οΈ'; - } - - if ( $args['title'] ) { - $start_time[] = __( 'Start', 'activitypub-event-bridge' ) . ':'; - } - - $start_time[] = self::format_time( $start_timestamp ); - - $start_time = implode( ' ', $start_time ); - - return $start_time; - } - - /** - * Generates output for the 'apeb_end_time' shortcode. - * - * @param ?array $atts The shortcodes attributes. - * - * @return string The formatted end date and time of the event. - */ - public static function end_time( $atts ) { - $transformer = self::get_transformer(); - - if ( ! $transformer ) { - return ''; - } - - $args = shortcode_atts( - array( - 'icon' => 'true', - 'title' => 'true', - ), - $atts, - 'ap_end_time' - ); - - $args['icon'] = filter_var( $args['icon'], FILTER_VALIDATE_BOOLEAN ); - $args['title'] = filter_var( $args['title'], FILTER_VALIDATE_BOOLEAN ); - - $end_timestamp = $transformer->get_end_time(); - - if ( ! $end_timestamp ) { - return ''; - } - - $end_time = array(); - - if ( $args['icon'] ) { - $end_time[] = '⏳'; - } - - if ( $args['title'] ) { - $end_time[] = __( 'End', 'activitypub-event-bridge' ) . ':'; - } - - $end_time[] = self::format_time( $end_timestamp ); - - $end_time = implode( ' ', $end_time ); - - return $end_time; - } - - /** - * Generates output for the 'apeb_location shortcode. - * - * @param ?array $atts The shortcodes attributes. - * - * @return string The formatted location/address of the event. - */ - public static function location( $atts ) { - $transformer = self::get_transformer(); - - if ( ! $transformer ) { - return ''; - } - - $args = shortcode_atts( - array( - 'icon' => 'true', - 'title' => 'true', - 'country' => 'true', - 'zip' => 'true', - 'city' => 'true', - 'street' => 'true', - 'name' => 'true', - ), - $atts, - 'ap_location' - ); - - foreach ( $args as $arg => $value ) { - $args[ $arg ] = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); - } - - $location = $transformer->get_location(); - - if ( ! $location ) { - return ''; - } - - $output = array(); - - if ( $args['icon'] ) { - $output[] = 'πŸ“'; - } - - if ( $args['title'] ) { - $output[] = __( 'Location', 'activitypub-event-bridge' ) . ':'; - } - - $address = $location->get_address(); - - if ( $address ) { - if ( is_string( $address ) ) { - $output[] = $address; - } - if ( is_array( $address ) ) { - if ( $args['name'] && array_key_exists( 'name', $address ) ) { - $output[] = $address['name'] . ','; - } - if ( $args['street'] && array_key_exists( 'streetAddress', $address ) ) { - $output[] = $address['streetAddress'] . ','; - } - if ( $args['zip'] && array_key_exists( 'postalCode', $address ) ) { - $output[] = $address['postalCode']; - } - if ( $args['city'] && array_key_exists( 'addressLocality', $address ) ) { - $output[] = $address['addressLocality'] . ','; - } - if ( $args['country'] && array_key_exists( 'addressCountry', $address ) ) { - $output[] = $address['addressCountry']; - } - } - } - - $output = implode( ' ', $output ); - - return $output; - } -} -- 2.39.5 From dc24f292be99ae8be93b81f4a00e9b5f13bea53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 21 Nov 2024 16:24:47 +0100 Subject: [PATCH 03/14] add tests --- .forgejo/workflows/phpunit.yml | 6 + composer.json | 3 +- .../activitypub/transformer/class-event.php | 15 +- tests/bootstrap.php | 28 ++- ...ss-activitypub-event-bridge-shortcodes.php | 193 ++++++++++++++++++ 5 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 tests/test-class-activitypub-event-bridge-shortcodes.php diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index f8e08ac..5fc523b 100644 --- a/.forgejo/workflows/phpunit.yml +++ b/.forgejo/workflows/phpunit.yml @@ -75,6 +75,12 @@ jobs: if: steps.cache-wordpress.outputs.cache-hit != 'false' run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wordpress-version }} false true true true + + - name: Run General Tests + run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=activitypub_event_bridge + env: + PHP_VERSION: ${{ matrix.php-version }} + - name: Run Integration tests for The Events Calendar run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=the_events_calendar env: diff --git a/composer.json b/composer.json index 4da8b48..6e1aff4 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ ], "test-debug": [ "@prepare-test", - "@test-gatherpress" + "@test-activitypub-event-bridge-shortcodes" ], "test-vs-event-list": "phpunit --filter=vs_event_list", "test-the-events-calendar": "phpunit --filter=the_events_calendar", @@ -67,6 +67,7 @@ "test-wp-event-manager": "phpunit --filter=wp_event_manager", "test-eventin": "phpunit --filter=eventin", "test-modern-events-calendar-lite": "phpunit --filter=modern_events_calendar_lite", + "test-activitypub-event-bridge-shortcodes": "phpunit --filter=activitypub_event_bridge_shortcodes", "test-all": "phpunit" } } diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index ffdac82..b0775f6 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -245,13 +245,13 @@ abstract class Event extends Post { $args = shortcode_atts( array( 'icon' => 'true', - 'title' => 'true', + 'label' => 'true', ), $atts ); $args['icon'] = filter_var( $args['icon'], FILTER_VALIDATE_BOOLEAN ); - $args['title'] = filter_var( $args['title'], FILTER_VALIDATE_BOOLEAN ); + $args['label'] = filter_var( $args['label'], FILTER_VALIDATE_BOOLEAN ); $output = array(); @@ -259,7 +259,7 @@ abstract class Event extends Post { $output[] = $icon; } - if ( $args['title'] ) { + if ( $args['label'] ) { $output[] = $label . ':'; } @@ -278,7 +278,7 @@ abstract class Event extends Post { $args = shortcode_atts( array( 'icon' => 'true', - 'title' => 'true', + 'label' => 'true', 'country' => 'true', 'zip' => 'true', 'city' => 'true', @@ -306,7 +306,7 @@ abstract class Event extends Post { if ( $args['icon'] ) { $output[] = 'πŸ“'; } - if ( $args['title'] ) { + if ( $args['label'] ) { $output[] = esc_html__( 'Location', 'activitypub-event-bridge' ) . ':'; } @@ -477,7 +477,10 @@ abstract class Event extends Post { $start_time = $this->get_start_time(); $end_time = $this->get_end_time(); $address = $this->format_address( $this->get_location() ); - $time_atts = array( 'icon' => true, 'label' => true); + $time_atts = array( + 'icon' => true, + 'label' => true, + ); $formatted_items = array(); if ( ! empty( $category ) ) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4262f2b..4c8b6f3 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -25,6 +25,21 @@ if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) { // Give access to tests_add_filter() function. require_once "{$_tests_dir}/includes/functions.php"; +/** + * Function to manually load an event plugin. + * + * @param string $plugin_file The main plugin file of the event plugin. + */ +function _manually_load_event_plugin( $plugin_file ) { + $plugin_dir = ABSPATH . '/wp-content/plugins/'; + require_once $plugin_dir . $plugin_file; + update_option( 'purchase_history_table_structure_migration_done', true ); + $current = get_option( 'active_plugins', array() ); + $current[] = $plugin_file; + sort( $current ); + update_option( 'active_plugins', $current ); +} + /** * Manually load the plugin being tested and its integrations. */ @@ -74,13 +89,12 @@ function _manually_load_plugin() { } if ( $plugin_file ) { - // Manually load the event plugin. - require_once $plugin_dir . $plugin_file; - update_option( 'purchase_history_table_structure_migration_done', true ); - $current = get_option( 'active_plugins', array() ); - $current[] = $plugin_file; - sort( $current ); - update_option( 'active_plugins', $current ); + _manually_load_event_plugin( $plugin_file ); + } else { + // For all other tests we mainly use the Events Calendar as a reference. + _manually_load_event_plugin( 'the-events-calendar/the-events-calendar.php' ); + _manually_load_event_plugin( 'very-simple-event-list/vsel.php' ); + } // Hot fix that allows using Events Manager within unit tests, because the em_init() is later not run as admin. diff --git a/tests/test-class-activitypub-event-bridge-shortcodes.php b/tests/test-class-activitypub-event-bridge-shortcodes.php new file mode 100644 index 0000000..0b7e1ba --- /dev/null +++ b/tests/test-class-activitypub-event-bridge-shortcodes.php @@ -0,0 +1,193 @@ +activate_activitypub_support_for_active_event_plugins(); + + // Delete all posts afterwards. + _delete_all_posts(); + } + + /** + * Test the shortcode for rendering the events start time. + */ + public function test_start_time() { + // Create a The Events Calendar Event without content. + $wp_object = tribe_events() + ->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event'] ) + ->create(); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); + + if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) { + return; + } + + $transformer->register_shortcodes(); + + $summary = '[ap_start_time]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'πŸ—“οΈ Start: December 1, 2024 3:00 pm', $summary ); + + $summary = '[ap_start_time icon="false"]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'Start: December 1, 2024 3:00 pm', $summary ); + + $summary = '[ap_start_time icon="false" label="false"]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'December 1, 2024 3:00 pm', $summary ); + + $transformer->unregister_shortcodes(); + } + + /** + * Test the shortcode for rendering the events end time. + */ + public function test_end_time() { + // Create a The Events Calendar Event without content. + $wp_object = tribe_events() + ->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event'] ) + ->create(); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); + + if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) { + return; + } + + $transformer->register_shortcodes(); + + $summary = '[ap_end_time]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( '⏳ End: December 1, 2024 4:00 pm', $summary ); + + $summary = '[ap_end_time icon="false"]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'End: December 1, 2024 4:00 pm', $summary ); + + $summary = '[ap_end_time icon="false" label="false"]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'December 1, 2024 4:00 pm', $summary ); + + $transformer->unregister_shortcodes(); + } + + /** + * Test the shortcode for rendering the events location when no location is set. + */ + public function test_location_when_no_location_is_set() { + // Create a The Events Calendar Event without content. + $wp_object = tribe_events() + ->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event'] ) + ->create(); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); + + if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) { + return; + } + + $transformer->register_shortcodes(); + + $summary = '[ap_location]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( '', $summary ); + + $transformer->unregister_shortcodes(); + } + + /** + * Test the shortcode for rendering the events location when location is set. + */ + public function test_location_when_location_is_set() { + // Create Venue. + $venue = tribe_venues()->set_args( Test_The_Events_Calendar::MOCKUP_VENUS['minimal_venue'] )->create(); + // Create a The Events Calendar Event. + $wp_object = tribe_events() + ->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['complex_event'] ) + ->set( 'venue', $venue->ID ) + ->create(); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); + + if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) { + return; + } + + $transformer->register_shortcodes(); + + $summary = '[ap_location]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'πŸ“ Location: Minimal Venue', $summary ); + + $summary = '[ap_location icon="false"]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'Location: Minimal Venue', $summary ); + + $summary = '[ap_location icon="false" label="false"]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'Minimal Venue', $summary ); + + $transformer->unregister_shortcodes(); + } + + /** + * Test the shortcode for rendering the events location when location with detailed address is set. + */ + public function test_location_when_detailed_location_is_set() { + // Create Venue. + $venue = tribe_venues()->set_args( Test_The_Events_Calendar::MOCKUP_VENUS['complex_venue'] )->create(); + // Create a The Events Calendar Event. + $wp_object = tribe_events() + ->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['complex_event'] ) + ->set( 'venue', $venue->ID ) + ->create(); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); + + if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) { + return; + } + + $transformer->register_shortcodes(); + + $summary = '[ap_location]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'πŸ“ Location: Complex Venue, Venue address, Venue zip, Venue city, Venue country', $summary ); + + $summary = '[ap_location country="false"]'; + $summary = do_shortcode( $summary ); + $this->assertEquals( 'πŸ“ Location: Complex Venue, Venue address, Venue zip, Venue city', $summary ); + + $transformer->unregister_shortcodes(); + } +} -- 2.39.5 From 9fa705576fe09a7d3c2292899ebf6acfc65cd25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 21 Nov 2024 16:26:22 +0100 Subject: [PATCH 04/14] phpcs --- includes/activitypub/transformer/class-event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index b0775f6..e6e6d3d 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -323,7 +323,7 @@ abstract class Event extends Post { * @param array $args The arguments for which components to include. * @return string The formatted address. */ - protected static function format_address( $address, $args = null) { + protected static function format_address( $address, $args = null ) { if ( is_string( $address ) ) { return esc_html( $address ); } -- 2.39.5 From 1b3e772d004c6809b6c38c0895cce30d2b237279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 21 Nov 2024 16:33:06 +0100 Subject: [PATCH 05/14] make getter for time public --- includes/activitypub/transformer/class-gatherpress.php | 4 ++-- includes/activitypub/transformer/class-vs-event-list.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index 756524a..f670c1f 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -73,14 +73,14 @@ final class GatherPress extends Event { /** * Get the end time from the event object. */ - protected function get_end_time(): ?string { + public function get_end_time(): ?string { return $this->gp_event->get_datetime_end( 'Y-m-d\TH:i:s\Z' ); } /** * Get the end time from the event object. */ - protected function get_start_time(): string { + public function get_start_time(): string { return $this->gp_event->get_datetime_start( 'Y-m-d\TH:i:s\Z' ); } diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index c476404..15370f5 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -44,7 +44,7 @@ final class VS_Event_List extends Event_Transformer { /** * Get the end time from the events metadata. */ - protected function get_end_time(): ?string { + public function get_end_time(): ?string { if ( 'yes' === get_post_meta( $this->wp_object->ID, 'event-hide-end-time', true ) ) { return null; } @@ -58,7 +58,7 @@ final class VS_Event_List extends Event_Transformer { /** * Get the end time from the events metadata. */ - protected function get_start_time(): string { + public function get_start_time(): string { $start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true ); return \gmdate( 'Y-m-d\TH:i:s\Z', $start_time ); } -- 2.39.5 From f50ee7441b917a3af64de3b51ffee9f6a4ffabec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Fri, 6 Dec 2024 16:23:10 +0100 Subject: [PATCH 06/14] Merge branch 'main' into custom_summary --- .forgejo/workflows/phpunit.yml | 30 ++- CHANGELOG.md | 13 +- Gruntfile.js | 2 +- README.md | 18 +- activitypub-event-bridge.php | 38 --- ...=> event-bridge-for-activitypub-admin.css} | 54 ++--- ... => event-bridge-for-activitypub-admin.js} | 2 +- bin/install-wp-tests.sh | 2 + composer.json | 12 +- docker-compose.yml | 2 +- docs/add_your_event_plugin.md | 18 +- event-bridge-for-activitypub.php | 38 +++ .../transformer/class-event-organiser.php | 99 ++++++++ .../activitypub/transformer/class-event.php | 28 +-- .../activitypub/transformer/class-eventin.php | 6 +- .../transformer/class-eventprime.php | 78 +++++++ .../transformer/class-events-manager.php | 6 +- .../transformer/class-gatherpress.php | 8 +- .../class-modern-events-calendar-lite.php | 6 +- .../transformer/class-the-events-calendar.php | 6 +- .../transformer/class-vs-event-list.php | 6 +- .../transformer/class-wp-event-manager.php | 8 +- .../class-event-plugin-admin-notices.php | 8 +- .../admin/class-general-admin-notices.php | 28 +-- includes/admin/class-health-check.php | 26 +-- includes/admin/class-settings-page.php | 26 +-- includes/class-autoloader.php | 10 +- includes/class-settings.php | 28 +-- includes/class-setup.php | 78 ++++--- includes/event-categories.php | 68 +++--- .../integrations/class-event-organiser.php | 69 ++++++ .../class-event-plugin.php | 8 +- .../class-eventin.php | 4 +- includes/integrations/class-eventprime.php | 218 ++++++++++++++++++ .../class-events-manager.php | 4 +- .../class-gatherpress.php | 4 +- .../class-modern-events-calendar-lite.php | 4 +- .../class-the-events-calendar.php | 4 +- .../class-vs-event-list.php | 6 +- .../class-wp-event-manager.php | 6 +- package.json | 4 +- phpcs.xml | 4 +- readme.txt | 20 +- templates/admin-header.php | 18 +- templates/settings.php | 66 +++--- templates/welcome.php | 128 +++++----- tests/bootstrap.php | 20 +- tests/test-class-plugin-event-organiser.php | 153 ++++++++++++ tests/test-class-plugin-eventin.php | 8 +- tests/test-class-plugin-eventprime.php | 186 +++++++++++++++ tests/test-class-plugin-events-manger.php | 8 +- tests/test-class-plugin-gatherpress.php | 8 +- ...ass-plugin-modern-events-calendar-lite.php | 8 +- .../test-class-plugin-the-events-calendar.php | 12 +- tests/test-class-plugin-vs-event-list.php | 12 +- tests/test-class-plugin-wp-event-manager.php | 10 +- 56 files changed, 1279 insertions(+), 465 deletions(-) delete mode 100644 activitypub-event-bridge.php rename assets/css/{activitypub-event-bridge-admin.css => event-bridge-for-activitypub-admin.css} (60%) rename assets/js/{activitypub-event-bridge-admin.js => event-bridge-for-activitypub-admin.js} (88%) create mode 100644 event-bridge-for-activitypub.php create mode 100644 includes/activitypub/transformer/class-event-organiser.php create mode 100644 includes/activitypub/transformer/class-eventprime.php create mode 100644 includes/integrations/class-event-organiser.php rename includes/{plugins => integrations}/class-event-plugin.php (89%) rename includes/{plugins => integrations}/class-eventin.php (92%) create mode 100644 includes/integrations/class-eventprime.php rename includes/{plugins => integrations}/class-events-manager.php (93%) rename includes/{plugins => integrations}/class-gatherpress.php (94%) rename includes/{plugins => integrations}/class-modern-events-calendar-lite.php (93%) rename includes/{plugins => integrations}/class-the-events-calendar.php (94%) rename includes/{plugins => integrations}/class-vs-event-list.php (90%) rename includes/{plugins => integrations}/class-wp-event-manager.php (90%) create mode 100644 tests/test-class-plugin-event-organiser.php create mode 100644 tests/test-class-plugin-eventprime.php diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index 5fc523b..a5589f9 100644 --- a/.forgejo/workflows/phpunit.yml +++ b/.forgejo/workflows/phpunit.yml @@ -21,7 +21,7 @@ jobs: MYSQL_ROOT_PASSWORD: root strategy: matrix: - php-version: ['7.4', '8.0', '8.1', '8.2', '8.3'] + php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] wordpress-version: ['6.7'] name: PHPUnit – PHP ${{ matrix.php-version }} env: @@ -38,7 +38,7 @@ jobs: path: | ${{ env.WP_CORE_DIR }} ${{ env.WP_TESTS_DIR }} - key: cache-wordpress-67-2 + key: cache-wordpress-67-4 - name: Cache Composer id: cache-composer-phpunit @@ -82,36 +82,46 @@ jobs: PHP_VERSION: ${{ matrix.php-version }} - name: Run Integration tests for The Events Calendar - run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=the_events_calendar + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=the_events_calendar env: PHP_VERSION: ${{ matrix.php-version }} - name: Run Integration tests for VS Event List - run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=vs_event_list + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=vs_event_list env: PHP_VERSION: ${{ matrix.php-version }} - name: Run Integration tests for GatherPress - run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=gatherpress + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=gatherpress env: PHP_VERSION: ${{ matrix.php-version }} - name: Run Integration tests for Events Manager - run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=events_manager + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=events_manager env: PHP_VERSION: ${{ matrix.php-version }} - name: Run Integration tests for WP Event Manager - run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=wp_event_manager + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=wp_event_manager env: PHP_VERSION: ${{ matrix.php-version }} - name: Run Integration tests for Eventin (WP Event Solution) - run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=eventin + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=eventin env: PHP_VERSION: ${{ matrix.php-version }} - name: Run Integration tests for Modern Events Calendar Lite - run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=modern_events_calendar_lite + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=modern_events_calendar_lite env: - PHP_VERSION: ${{ matrix.php-version }} \ No newline at end of file + PHP_VERSION: ${{ matrix.php-version }} + + - name: Run Integration tests for EventPrime + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=eventprime + env: + PHP_VERSION: ${{ matrix.php-version }} + + - name: Run Integration tests for Event Organiser + run: cd /workspace/Event-Federation/wordpress-event-bridge-for-activitypub/ && ./vendor/bin/phpunit --filter=event_organiser + env: + PHP_VERSION: ${{ matrix.php-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index b1f6405..dd83e8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,18 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.2.1] - 2024-11-16 - -### Added +## [0.3.1] - 2024-11-16 * Initial release on WordPress.org -### Fixed - -* Applied some WordPress best practices - -## [0.2.0] - 2024-10-20 - -### Added - -* Initial submission to WordPress.org diff --git a/Gruntfile.js b/Gruntfile.js index df4eb26..4b2c893 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,7 +4,7 @@ module.exports = function (grunt) { { checktextdomain: { options:{ - text_domain: 'activitypub-event-bridge', + text_domain: 'event-bridge-for-activitypub', keywords: [ '__:1,2d', '_e:1,2d', diff --git a/README.md b/README.md index 023e5c2..e52e4a8 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# ActivityPub Event Bridge # +# Event Bridge for ActivityPub # **Contributors:** [andremenrath](https://profiles.wordpress.org/andremenrath/) **Tags:** events, fediverse, activitypub, calendar **Requires at least:** 6.5 **Tested up to:** 6.7 -**Stable tag:** 0.2.1 +**Stable tag:** 0.3.1 **Requires PHP:** 7.4 **License:** AGPL-3.0-or-later **License URI:** https://www.gnu.org/licenses/agpl-3.0.html @@ -14,7 +14,7 @@ Integrating popular event plugins with the ActivityPub plugin. ## Description ## Make your events more discoverable, expand your reach effortlessly while being independent of other (commercial) platforms, and be a part of the growing decentralized web (the Fediverse). -With the ActivityPub Event Bridge Plugin for WordPress, your events can be automatically followed, aggregated and displayed across decentralized platforms like [Mastodon](https://joinmastodon.org) or [Gancio](https://gancio.org), without any extra work. +With the Event Bridge for ActivityPub Plugin for WordPress, your events can be automatically followed, aggregated and displayed across decentralized platforms like [Mastodon](https://joinmastodon.org) or [Gancio](https://gancio.org), without any extra work. Forget the hassle of managing multiple social media accounts just to keep your audience informed. This plugin is not an event managing plugin but an add-on to popular event plugins. It extends their functionality to fully support the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/). @@ -23,7 +23,7 @@ You retain full ownership of your content. By integrating into your existing set ### How It Works ### -With the ActivityPub Event Bridge WordPress plugin, sharing your events is effortless and automatic! +With the Event Bridge for ActivityPub WordPress plugin, sharing your events is effortless and automatic! Once you create an event on your WordPress site, it is seamlessly shared across the decentralized web using the ActivityPub protocol.

@@ -63,6 +63,8 @@ This plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/ac * [Eventin](https://de.wordpress.org/plugins/wp-event-solution/) * [Modern Events Calendar Lite](https://webnus.net/modern-events-calendar/) * [GatherPress](https://gatherpress.org/) +* [EventPrime – Events Calendar, Bookings and Tickets](https://wordpress.org/plugins/eventprime-event-calendar-management/) +* [Event Organiser](https://wordpress.org/plugins/event-organiser/) ## Configuration ## @@ -92,18 +94,16 @@ No, the Event Federation Plugin depends on the [ActivityPub plugin](https://word ### My event plugin is not supported, what can I do? ### -If you know about coding have a look at the documentation of how to add your plugin or open an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues), if we can spare some free hours we might add it. +If you know about coding have a look at the documentation of how to add your plugin or open an [issue](https://code.event-federation.eu/Event-Federation/wordpress-event-bridge-for-activitypub/issues), if we can spare some free hours we might add it. ### What if I experience problems? ### -We're always interested in your feedback. Feel free to reach out to us via [E-Mail](https://event-federation.eu/contact/) or create an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues). +We're always interested in your feedback. Feel free to reach out to us via [E-Mail](https://event-federation.eu/contact/) or create an [issue](https://code.event-federation.eu/Event-Federation/wordpress-event-bridge-for-activitypub/issues). ## Changelog ## -### [0.2.1] 2024-11-16 ### +### [0.3.1] 2024-12-05 ### * Initial release on https://wordpress.org/ -### [0.2.0] 2024-10-29 ### -* Initial submission to https://wordpress.org/ diff --git a/activitypub-event-bridge.php b/activitypub-event-bridge.php deleted file mode 100644 index 0276072..0000000 --- a/activitypub-event-bridge.php +++ /dev/null @@ -1,38 +0,0 @@ -= 3.2.2. ActivityPub plugin tested up to: 4.2.0. - * - * @package ActivityPub_Event_Bridge - * @license AGPL-3.0-or-later - */ - -// Exit if accessed directly. -defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore - -define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); -define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); -define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) ); -define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); -define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) ); -define( 'ACTIVITYPUB_EVENT_BRIDGE_DOMAIN', 'activitypub-event-bridge' ); -define( 'ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION', '3.2.2' ); -define( 'ACTIVITYPUB_EVENT_BRIDGE_CUSTOM_SUMMARY', "

    \n
  • [ap_start_time]
  • \n
  • [ap_end_time]
  • \n
  • [ap_location]
  • \n
\n[ap_hashcats][ap_hashtags]" ); -define( 'ACTIVITYPUB_EVENT_BRIDGE_DEFAULT_SUMMARY_TYPE', 'preset' ); - -// Include and register the autoloader class for automatic loading of plugin classes. -require_once ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/class-autoloader.php'; -ActivityPub_Event_Bridge\Autoloader::register(); - -// Initialize the plugin. -ActivityPub_Event_Bridge\Setup::get_instance(); diff --git a/assets/css/activitypub-event-bridge-admin.css b/assets/css/event-bridge-for-activitypub-admin.css similarity index 60% rename from assets/css/activitypub-event-bridge-admin.css rename to assets/css/event-bridge-for-activitypub-admin.css index 043082f..d619837 100644 --- a/assets/css/activitypub-event-bridge-admin.css +++ b/assets/css/event-bridge-for-activitypub-admin.css @@ -1,19 +1,19 @@ -.settings_page_activitypub-event-bridge #wpcontent { +.settings_page_event-bridge-for-activitypub #wpcontent { padding-left: 0; } -.activitypub-event-bridge-settings-page .box { +.event-bridge-for-activitypub-settings-page .box { border: 1px solid #c3c4c7; background-color: #fff; padding: 1em 1.5em; margin-bottom: 1.5em; } -.activitypub-event-bridge-settings-page .box ul.activitypub-event-bridge-list { +.event-bridge-for-activitypub-settings-page .box ul.event-bridge-for-activitypub-list { margin-left: 0.6em; } -.activitypub-event-bridge-settings-page .box pre { +.event-bridge-for-activitypub-settings-page .box pre { padding: 1rem; min-height: 200px; box-shadow: none; @@ -22,19 +22,19 @@ background-color: #f7f7f7; } -.activitypub-event-bridge-settings { +.event-bridge-for-activitypub-settings { max-width: 800px; margin: 0 auto; } -.activitypub-event-bridge-settings-header { +.event-bridge-for-activitypub-settings-header { text-align: center; margin: 0 0 1rem; background: #fff; border-bottom: 1px solid #dcdcde; } -.activitypub-event-bridge-settings-title-section { +.event-bridge-for-activitypub-settings-title-section { display: flex; align-items: center; justify-content: center; @@ -42,7 +42,7 @@ padding-top: 8px; } -.activitypub-event-bridge-settings-tabs-wrapper { +.event-bridge-for-activitypub-settings-tabs-wrapper { display: -ms-inline-grid; -ms-grid-columns: auto auto auto auto; vertical-align: top; @@ -50,12 +50,12 @@ grid-template-columns: auto auto auto auto; } -.activitypub-event-bridge-settings-tab.active { +.event-bridge-for-activitypub-settings-tab.active { box-shadow: inset 0 -3px #3582c4; font-weight: 600; } -.activitypub-event-bridge-settings-tab { +.event-bridge-for-activitypub-settings-tab { display: block; text-decoration: none; color: inherit; @@ -64,21 +64,21 @@ transition: box-shadow .5s ease-in-out; } -.activitypub-event-bridge-settings .box h3 { +.event-bridge-for-activitypub-settings .box h3 { font-size: 1.15em; margin-bottom: 0em; } -#activitypub_event_bridge_initially_activated { +#event_bridge_for_activitypub_initially_activated { display: hidden; } /* Accordions for admin pages */ -.activitypub-event-bridge-settings-accordion { +.event-bridge-for-activitypub-settings-accordion { border: 1px solid #c3c4c7; } -.activitypub-event-bridge-settings-accordion-heading { +.event-bridge-for-activitypub-settings-accordion-heading { margin: 0; border-top: 1px solid #c3c4c7; font-size: inherit; @@ -87,17 +87,17 @@ color: inherit; } -.activitypub-event-bridge-settings-accordion-heading:first-child { +.event-bridge-for-activitypub-settings-accordion-heading:first-child { border-top: none; } -.activitypub-event-bridge-settings-accordion-panel { +.event-bridge-for-activitypub-settings-accordion-panel { margin: 0; padding: 1em 1.5em; background: #fff; } -.activitypub-event-bridge-settings-accordion-trigger { +.event-bridge-for-activitypub-settings-accordion-trigger { background: #fff; border: 0; color: #2c3338; @@ -116,21 +116,21 @@ user-select: auto; } -.activitypub-event-bridge-settings-accordion-trigger { +.event-bridge-for-activitypub-settings-accordion-trigger { color: #2c3338; cursor: pointer; font-weight: 400; text-align: left; } -.activitypub-event-bridge-settings-accordion-trigger .title { +.event-bridge-for-activitypub-settings-accordion-trigger .title { pointer-events: none; font-weight: 600; flex-grow: 1; } -.activitypub-event-bridge-settings-accordion-trigger .icon, -.activitypub-event-bridge-settings-accordion-viewed .icon { +.event-bridge-for-activitypub-settings-accordion-trigger .icon, +.event-bridge-for-activitypub-settings-accordion-viewed .icon { border: solid #50575e medium; border-width: 0 2px 2px 0; height: .5rem; @@ -142,16 +142,16 @@ width: .5rem; } -.activitypub-event-bridge-settings-accordion-trigger[aria-expanded="true"] .icon { +.event-bridge-for-activitypub-settings-accordion-trigger[aria-expanded="true"] .icon { transform: translateY(-30%) rotate(-135deg); } -.activitypub-event-bridge-settings-accordion-trigger:active, -.activitypub-event-bridge-settings-accordion-trigger:hover { +.event-bridge-for-activitypub-settings-accordion-trigger:active, +.event-bridge-for-activitypub-settings-accordion-trigger:hover { background: #f6f7f7; } -.activitypub-event-bridge-settings-accordion-trigger:focus { +.event-bridge-for-activitypub-settings-accordion-trigger:focus { color: #1d2327; border: none; box-shadow: none; @@ -160,14 +160,14 @@ background-color: #f6f7f7; } -.activitypub-event-bridge-settings-inline-icon { +.event-bridge-for-activitypub-settings-inline-icon { width: 1.5em; height: 1.5em; vertical-align: middle; margin: 0 0.3em; } -code.activitypub-event-bridge-settings-example-url { +code.event-bridge-for-activitypub-settings-example-url { display: block; background: rgb(28, 29, 33); padding: 8px; diff --git a/assets/js/activitypub-event-bridge-admin.js b/assets/js/event-bridge-for-activitypub-admin.js similarity index 88% rename from assets/js/activitypub-event-bridge-admin.js rename to assets/js/event-bridge-for-activitypub-admin.js index 4716ec8..362e134 100644 --- a/assets/js/activitypub-event-bridge-admin.js +++ b/assets/js/event-bridge-for-activitypub-admin.js @@ -1,6 +1,6 @@ jQuery( function( $ ) { // Accordion handling in various areas. - $( '.activitypub-event-bridge-settings-accordion' ).on( 'click', '.activitypub-event-bridge-settings-accordion-trigger', function() { + $( '.event-bridge-for-activitypub-settings-accordion' ).on( 'click', '.event-bridge-for-activitypub-settings-accordion-trigger', function() { var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) ); if ( isExpanded ) { diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 3cc440f..95fc2e5 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -257,9 +257,11 @@ install_wp_plugins() { install_wp_plugin the-events-calendar "6.8.1" install_wp_plugin very-simple-event-list install_wp_plugin gatherpress + install_wp_plugin eventprime-event-calendar-management install_wp_plugin events-manager "6.6.3" install_wp_plugin wp-event-manager "3.1.45.1" install_wp_plugin wp-event-solution "4.0.14" + install_wp_plugin event-organiser "3.12.8" # Mec is not installable via wordpress.org, we use our own mirror. install_wp_plugin_mec } diff --git a/composer.json b/composer.json index 6e1aff4..12a8b71 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "name": "menrath/wordpress-activitypub-event-bridge", + "name": "menrath/wordpress-event-bridge-for-activitypub", "version": "1.0.0", - "description": "The ActivityPub Event Bridge help for event custom post types to federate properly.", + "description": "The Event Bridge for ActivityPub help for event custom post types to federate properly.", "type": "wordpress-plugin", "require": { "php": ">=7.4.0", @@ -33,7 +33,7 @@ } ], "extra": { - "installer-name": "activitypub-event-bridge" + "installer-name": "event-bridge-for-activitypub" }, "scripts": { "lint": [ @@ -54,7 +54,9 @@ "@test-events-manager", "@test-wp-event-manager", "@test-eventin", - "@test-modern-events-calendar-lite" + "@test-modern-events-calendar-lite", + "@test-eventprime", + "@test-event-organiser" ], "test-debug": [ "@prepare-test", @@ -68,6 +70,8 @@ "test-eventin": "phpunit --filter=eventin", "test-modern-events-calendar-lite": "phpunit --filter=modern_events_calendar_lite", "test-activitypub-event-bridge-shortcodes": "phpunit --filter=activitypub_event_bridge_shortcodes", + "test-eventprime": "phpunit --filter=eventprime", + "test-event-organiser": "phpunit --filter=event_organiser", "test-all": "phpunit" } } diff --git a/docker-compose.yml b/docker-compose.yml index d39760b..c95f996 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ version: '3' # "request": "launch", # "port": 9003, # "pathMappings": { -# "/app/": "${workspaceRoot}/wp-content/plugins/activitypub-event-bridge/", +# "/app/": "${workspaceRoot}/wp-content/plugins/event-bridge-for-activitypub/", # "/tmp/wordpress/": "${workspaceRoot}/" # }, # }, diff --git a/docs/add_your_event_plugin.md b/docs/add_your_event_plugin.md index 165f285..e104340 100644 --- a/docs/add_your_event_plugin.md +++ b/docs/add_your_event_plugin.md @@ -13,7 +13,7 @@ To make the WordPress ActivityPub plugin use a custom transformer simply add a f 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 - namespace ActivityPub_Event_Bridge\Plugins; + namespace Event_Bridge_For_ActivityPub\Integrations; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore @@ -28,16 +28,16 @@ First you need to add some basic information about your event plugin. Just creat final class My_Event_Plugin extends Event_Plugin { ``` -Then you need to tell the ActivityPub Event Bridge about that class by adding it to the `EVENT_PLUGIN_CLASSES` constant in the `includes/setup.php` file: +Then you need to tell the Event Bridge for ActivityPub about that class by adding it to the `EVENT_PLUGIN_CLASSES` constant in the `includes/setup.php` file: ```php private const EVENT_PLUGIN_CLASSES = array( ... - '\ActivityPub_Event_Bridge\Plugins\My_Event_Plugin', + '\Event_Bridge_For_ActivityPub\Integrations\My_Event_Plugin', ); ``` -The ActivityPub Event Bridge then takes care of applying the transformer, so you can jump right into implementing it. +The Event Bridge for ActivityPub then takes care of applying the transformer, so you can jump right into implementing it. ## Writing an event transformer class @@ -48,9 +48,9 @@ If you are writing a transformer for your event post type we recommend to start So create a new file at `./includes/activitypub/transformer/my-event-plugin.php`. ```php -namespace ActivityPub_Event_Bridge\Activitypub\Transformer; +namespace Event_Bridge_For_ActivityPub\Activitypub\Transformer; -use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer; +use Event_Bridge_For_ActivityPub\Activitypub\Transformer\Event as Event_Transformer; /** * ActivityPub Transformer for My Event Plugin' event post type. @@ -142,7 +142,7 @@ Implement a check whether your event plugin is active in the `set_up` function. } // Make sure that ActivityPub support is enabled for The Events Calendar. - $aec = \ActivityPub_Event_Bridge\Setup::get_instance(); + $aec = \Event_Bridge_For_ActivityPub\Setup::get_instance(); $aec->activate_activitypub_support_for_active_event_plugins(); // Delete all posts afterwards. @@ -180,7 +180,7 @@ In the pipeline we want to run each event plugins integration tests in a single To activate/load your plugin add it to the switch statement within the function `_manually_load_plugin()` within `tests/bootstrap.php`. ```php - switch ( $activitypub_event_bridge_integration_filter ) { + switch ( $event_bridge_for_activitypub_integration_filter ) { ... case 'my_event_plugin': $plugin_file = 'my-event-plugin/my-event-plugin.php'; @@ -213,7 +213,7 @@ If you are using Visual Studio Code or VSCodium you can step-debug within the te "request": "launch", "port": 9003, "pathMappings": { - "/app/": "${workspaceRoot}/wp-content/plugins/activitypub-event-bridge/", + "/app/": "${workspaceRoot}/wp-content/plugins/event-bridge-for-activitypub/", "/tmp/wordpress/": "${workspaceRoot}/" }, } diff --git a/event-bridge-for-activitypub.php b/event-bridge-for-activitypub.php new file mode 100644 index 0000000..09bbbf1 --- /dev/null +++ b/event-bridge-for-activitypub.php @@ -0,0 +1,38 @@ += 3.2.2. ActivityPub plugin tested up to: 4.3.0. + * + * @package Event_Bridge_For_ActivityPub + * @license AGPL-3.0-or-later + */ + +// Exit if accessed directly. +defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore + +define( 'EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); +define( 'EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); +define( 'EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) ); +define( 'EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); +define( 'EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) ); +define( 'EVENT_BRIDGE_FOR_ACTIVITYPUB_DOMAIN', 'event-bridge-for-activitypub' ); +define( 'EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION', '3.2.2' ); +define( 'ACTIVITYPUB_EVENT_BRIDGE_CUSTOM_SUMMARY', "
    \n
  • [ap_start_time]
  • \n
  • [ap_end_time]
  • \n
  • [ap_location]
  • \n
\n[ap_hashcats][ap_hashtags]" ); +define( 'ACTIVITYPUB_EVENT_BRIDGE_DEFAULT_SUMMARY_TYPE', 'preset' ); + +// Include and register the autoloader class for automatic loading of plugin classes. +require_once EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . '/includes/class-autoloader.php'; +Event_Bridge_For_ActivityPub\Autoloader::register(); + +// Initialize the plugin. +Event_Bridge_For_ActivityPub\Setup::get_instance(); diff --git a/includes/activitypub/transformer/class-event-organiser.php b/includes/activitypub/transformer/class-event-organiser.php new file mode 100644 index 0000000..54e8cdf --- /dev/null +++ b/includes/activitypub/transformer/class-event-organiser.php @@ -0,0 +1,99 @@ +wp_object = get_posts( + array( + 'ID' => $wp_object->ID, + 'post_type' => 'event', + 'suppress_filters' => false, + ) + )[0]; + } + + /** + * Get the end time from the event object. + */ + protected function get_end_time(): ?string { + return eo_get_the_end( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID, $this->wp_object->occurrence_id ); + } + + /** + * Get the end time from the event object. + */ + protected function get_start_time(): string { + return eo_get_the_start( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID, $this->wp_object->occurrence_id ); + } + + /** + * Get location from the event object. + */ + protected function get_location(): ?Place { + $venue_id = eo_get_venue( $this->wp_object->ID ); + + if ( ! $venue_id ) { + return null; + } + + $address = eo_get_venue_address( $venue_id ); + + $venue_name = eo_get_venue_name( $venue_id ); + + $address['streetAddress'] = $address['address']; + unset( $address['address'] ); + + $address['postalCode'] = $address['postcode']; + unset( $address['postcode'] ); + + $address['addressRegion'] = $address['state']; + unset( $address['state'] ); + + $address['addressLocality'] = $address['city']; + unset( $address['city'] ); + + $address['addressCountry'] = $address['country']; + unset( $address['country'] ); + + $address['type'] = 'PostalAddress'; + + $location = new Place(); + $location->set_name( eo_get_venue_name( $this->wp_object->ID ) ); + $location->set_latitude( eo_get_venue_lat( $this->wp_object->ID ) ?? null ); + $location->set_longitude( eo_get_venue_lng( $this->wp_object->ID ) ?? null ); + $location->set_address( $address ); + $location->set_name( $venue_name ); + $location->set_content( eo_get_venue_description( $venue_id ) ); + + return $location; + } +} diff --git a/includes/activitypub/transformer/class-event.php b/includes/activitypub/transformer/class-event.php index e6e6d3d..b08fd61 100644 --- a/includes/activitypub/transformer/class-event.php +++ b/includes/activitypub/transformer/class-event.php @@ -2,11 +2,11 @@ /** * Replace the default ActivityPub Transformer * - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @license AGPL-3.0-or-later */ -namespace ActivityPub_Event_Bridge\Activitypub\Transformer; +namespace Event_Bridge_For_ActivityPub\Activitypub\Transformer; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore @@ -120,7 +120,7 @@ abstract class Event extends Post { if ( is_null( $this->wp_taxonomy ) ) { return null; } - $current_category_mapping = \get_option( 'activitypub_event_bridge_event_category_mappings', array() ); + $current_category_mapping = \get_option( 'event_bridge_for_activitypub_event_category_mappings', array() ); $terms = \get_the_terms( $this->wp_object, $this->wp_taxonomy ); // Check if the event has a category set and if that category has a specific mapping return that one. @@ -128,7 +128,7 @@ abstract class Event extends Post { return sanitize_text_field( $current_category_mapping[ $terms[0]->slug ] ); } else { // Return the default event category. - return sanitize_text_field( \get_option( 'activitypub_event_bridge_default_event_category', 'MEETING' ) ); + return sanitize_text_field( \get_option( 'event_bridge_for_activitypub_default_event_category', 'MEETING' ) ); } } @@ -214,7 +214,7 @@ abstract class Event extends Post { */ public function shortcode_start_time( $atts ) { $start_timestamp = $this->get_start_time(); - return $this->generate_time_output( $start_timestamp, $atts, 'πŸ—“οΈ', __( 'Start', 'activitypub-event-bridge' ) ); + return $this->generate_time_output( $start_timestamp, $atts, 'πŸ—“οΈ', __( 'Start', 'event-bridge-for-activitypub' ) ); } /** @@ -225,7 +225,7 @@ abstract class Event extends Post { */ public function shortcode_end_time( $atts ) { $end_timestamp = $this->get_end_time(); - return $this->generate_time_output( $end_timestamp, $atts, '⏳', __( 'End', 'activitypub-event-bridge' ) ); + return $this->generate_time_output( $end_timestamp, $atts, '⏳', __( 'End', 'event-bridge-for-activitypub' ) ); } /** @@ -307,7 +307,7 @@ abstract class Event extends Post { $output[] = 'πŸ“'; } if ( $args['label'] ) { - $output[] = esc_html__( 'Location', 'activitypub-event-bridge' ) . ':'; + $output[] = esc_html__( 'Location', 'event-bridge-for-activitypub' ) . ':'; } $output[] = self::format_address( $location->get_address(), $args ); @@ -373,10 +373,10 @@ abstract class Event extends Post { $categories = array(); // Add the federated category string. - require_once ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/event-categories.php'; + require_once EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . '/includes/event-categories.php'; $federated_category = $this->get_category(); - if ( array_key_exists( $federated_category, ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES ) ) { - $categories[] = ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $federated_category ]; + if ( array_key_exists( $federated_category, EVENT_BRIDGE_FOR_ACTIVITYPUB_EVENT_CATEGORIES ) ) { + $categories[] = EVENT_BRIDGE_FOR_ACTIVITYPUB_EVENT_CATEGORIES[ $federated_category ]; } // Add all category terms. @@ -484,19 +484,19 @@ abstract class Event extends Post { $formatted_items = array(); if ( ! empty( $category ) ) { - $formatted_items[] = '🏷️ ' . __( 'Category', 'activitypub-event-bridge' ) . ': ' . $category; + $formatted_items[] = '🏷️ ' . __( 'Category', 'event-bridge-for-activitypub' ) . ': ' . $category; } if ( ! empty( $start_time ) ) { - $formatted_items[] = $this->generate_time_output( $start_time, $time_atts, 'πŸ—“οΈ', __( 'Start', 'activitypub-event-bridge' ) ); + $formatted_items[] = $this->generate_time_output( $start_time, $time_atts, 'πŸ—“οΈ', __( 'Start', 'event-bridge-for-activitypub' ) ); } if ( ! empty( $end_time ) ) { - $formatted_items[] = $this->generate_time_output( $end_time, $time_atts, '⏳', __( 'End', 'activitypub-event-bridge' ) ); + $formatted_items[] = $this->generate_time_output( $end_time, $time_atts, '⏳', __( 'End', 'event-bridge-for-activitypub' ) ); } if ( ! empty( $address ) ) { - $formatted_items[] = 'πŸ“ ' . __( 'Address', 'activitypub-event-bridge' ) . ': ' . $address; + $formatted_items[] = 'πŸ“ ' . __( 'Address', 'event-bridge-for-activitypub' ) . ': ' . $address; } // Compose the summary based on the number of meta items. diff --git a/includes/activitypub/transformer/class-eventin.php b/includes/activitypub/transformer/class-eventin.php index b47d93e..7b4131d 100644 --- a/includes/activitypub/transformer/class-eventin.php +++ b/includes/activitypub/transformer/class-eventin.php @@ -4,17 +4,17 @@ * * @link https://support.themewinter.com/docs/plugins/docs-category/eventin/ * - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @license AGPL-3.0-or-later */ -namespace ActivityPub_Event_Bridge\Activitypub\Transformer; +namespace Event_Bridge_For_ActivityPub\Activitypub\Transformer; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore use Activitypub\Activity\Extended_Object\Place; -use ActivityPub_Event_Bridge\Activitypub\Transformer\Event; +use Event_Bridge_For_ActivityPub\Activitypub\Transformer\Event; use DateTime; use DateTimeZone; use Etn\Core\Event\Event_Model; diff --git a/includes/activitypub/transformer/class-eventprime.php b/includes/activitypub/transformer/class-eventprime.php new file mode 100644 index 0000000..8fa5d4b --- /dev/null +++ b/includes/activitypub/transformer/class-eventprime.php @@ -0,0 +1,78 @@ +wp_object->ID, 'em_end_date', true ); + if ( $timestamp ) { + return \gmdate( 'Y-m-d\TH:i:s\Z', $timestamp ); + } else { + return null; + } + } + + /** + * Get the end time from the event object. + */ + protected function get_start_time(): string { + $timestamp = get_post_meta( $this->wp_object->ID, 'em_start_date', true ); + if ( $timestamp ) { + return \gmdate( 'Y-m-d\TH:i:s\Z', $timestamp ); + } else { + return ''; + } + } + + /** + * Get location from the event object. + */ + protected function get_location(): ?Place { + $venue_term_id = get_post_meta( $this->wp_object->ID, 'em_venue', true ); + if ( ! $venue_term_id ) { + return null; + } + + $venue = wp_get_post_terms( $this->wp_object->ID, 'em_venue' ); + + if ( empty( $venue ) ) { + return null; + } else { + $venue = $venue[0]; + } + + $place = new Place(); + + $place->set_name( $venue->name ); + $place->set_content( $venue->description ); + + $address = get_term_meta( $venue->term_id, 'em_address', true ); + $display_address = get_term_meta( $venue->term_id, 'em_display_address_on_frontend', true ); + + if ( $address && $display_address ) { + $place->set_address( get_term_meta( $venue->term_id, 'em_address', true ) ); + } + + return $place; + } +} diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 1def3f7..92fbad2 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -2,17 +2,17 @@ /** * ActivityPub Transformer for the plugin Very Simple Event List. * - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @license AGPL-3.0-or-later */ -namespace ActivityPub_Event_Bridge\Activitypub\Transformer; +namespace Event_Bridge_For_ActivityPub\Activitypub\Transformer; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore use Activitypub\Activity\Extended_Object\Place; -use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer; +use Event_Bridge_For_ActivityPub\Activitypub\Transformer\Event as Event_Transformer; use DateTime; use DateTimeZone; use EM_Event; diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index f670c1f..79eb601 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -1,19 +1,19 @@ 'Link', - 'name' => \esc_html__( 'Video URL', 'activitypub-event-bridge' ), + 'name' => \esc_html__( 'Video URL', 'event-bridge-for-activitypub' ), 'href' => \esc_url( $event_link_url ), 'mediaType' => 'text/html', ); diff --git a/includes/admin/class-event-plugin-admin-notices.php b/includes/admin/class-event-plugin-admin-notices.php index 73ed33c..823472e 100644 --- a/includes/admin/class-event-plugin-admin-notices.php +++ b/includes/admin/class-event-plugin-admin-notices.php @@ -4,17 +4,17 @@ * * Notices for guiding to proper configuration of ActivityPub with event plugins. * - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 * @license AGPL-3.0-or-later */ -namespace ActivityPub_Event_Bridge\Admin; +namespace Event_Bridge_For_ActivityPub\Admin; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore -use ActivityPub_Event_Bridge\Plugins\Event_Plugin; +use Event_Bridge_For_ActivityPub\Integrations\Event_Plugin; /** * Class responsible for Event Plugin related admin notices. @@ -76,7 +76,7 @@ class Event_Plugin_Admin_Notices { _x( 'You have installed the %1$s plugin, but the event post type of the plugin %2$s is not enabled in the %1$s settings.', 'admin notice', - 'activitypub-event-bridge' + 'event-bridge-for-activitypub' ), esc_html( $activitypub_plugin_data['Name'] ), esc_html( $event_plugin_data['Name'] ), diff --git a/includes/admin/class-general-admin-notices.php b/includes/admin/class-general-admin-notices.php index 7ab1f2b..a58c2c4 100644 --- a/includes/admin/class-general-admin-notices.php +++ b/includes/admin/class-general-admin-notices.php @@ -4,12 +4,12 @@ * * Notices for guiding to proper configuration of this plugin. * - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 * @license AGPL-3.0-or-later */ -namespace ActivityPub_Event_Bridge\Admin; +namespace Event_Bridge_For_ActivityPub\Admin; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore @@ -29,7 +29,7 @@ class General_Admin_Notices { */ const ACTIVITYPUB_PLUGIN_URL = 'https://wordpress.org/plugins/activitypub'; - const ACTIVITYPUB_EVENT_BRIDGE_SUPPORTED_EVENT_PLUGINS_URL = 'https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge#events-plugin-that-will-be-supported-at-first'; + const EVENT_BRIDGE_FOR_ACTIVITYPUB_SUPPORTED_EVENT_PLUGINS_URL = 'https://code.event-federation.eu/Event-Federation/wordpress-event-bridge-for-activitypub#events-plugin-that-will-be-supported-at-first'; /** * Allowed HTML for admin notices. @@ -54,9 +54,9 @@ class General_Admin_Notices { return sprintf( /* translators: 1: An URL that points to the ActivityPub plugin. */ _x( - 'For the ActivityPub Event Bridge to work, you will need to install and activate the ActivityPub plugin.', + 'For the Event Bridge for ActivityPub to work, you will need to install and activate the ActivityPub plugin.', 'admin notice', - 'activitypub-event-bridge' + 'event-bridge-for-activitypub' ), esc_html( self::ACTIVITYPUB_PLUGIN_URL ) ); @@ -71,12 +71,12 @@ class General_Admin_Notices { return sprintf( /* translators: 1: The name of the ActivityPub plugin. 2: The minimum required version number of the ActivityPub plugin. */ _x( - 'Please upgrade your ActivityPub plugin. At least version %2$s is required for the ActivityPub Event Bridge to work.', + 'Please upgrade your ActivityPub plugin. At least version %2$s is required for the Event Bridge for ActivityPub to work.', 'admin notice', - 'activitypub-event-bridge' + 'event-bridge-for-activitypub' ), esc_html( self::ACTIVITYPUB_PLUGIN_URL ), - esc_html( ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION ) + esc_html( EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ); } @@ -89,12 +89,12 @@ class General_Admin_Notices { return sprintf( /* translators: 1: An URL to the list of supported event plugins. */ _x( - 'The Plugin ActivityPub Event Bridge is of no use, because you do not have installed and activated a supported Event Plugin. + 'The Plugin Event Bridge for ActivityPub is of no use, because you do not have installed and activated a supported Event Plugin.
For a list of supported Event Plugins see here.', 'admin notice', - 'activitypub-event-bridge' + 'event-bridge-for-activitypub' ), - esc_html( self::ACTIVITYPUB_EVENT_BRIDGE_SUPPORTED_EVENT_PLUGINS_URL ) + esc_html( self::EVENT_BRIDGE_FOR_ACTIVITYPUB_SUPPORTED_EVENT_PLUGINS_URL ) ); } @@ -107,12 +107,12 @@ class General_Admin_Notices { return sprintf( /* translators: 1: An URL to the list of supported event plugins. */ _x( - 'The Plugin ActivityPub Event Bridge is of no use, because you do not have installed and activated a supported Event Plugin. + 'The Plugin Event Bridge for ActivityPub is of no use, because you do not have installed and activated a supported Event Plugin.
For a list of supported Event Plugins see here.', 'admin notice', - 'activitypub-event-bridge' + 'event-bridge-for-activitypub' ), - esc_html( self::ACTIVITYPUB_EVENT_BRIDGE_SUPPORTED_EVENT_PLUGINS_URL ) + esc_html( self::EVENT_BRIDGE_FOR_ACTIVITYPUB_SUPPORTED_EVENT_PLUGINS_URL ) ); } diff --git a/includes/admin/class-health-check.php b/includes/admin/class-health-check.php index daaa0e0..61faa18 100644 --- a/includes/admin/class-health-check.php +++ b/includes/admin/class-health-check.php @@ -5,11 +5,11 @@ * @package Activitypub_Event_Bridge */ -namespace ActivityPub_Event_Bridge\Admin; +namespace Event_Bridge_For_ActivityPub\Admin; use Activitypub\Transformer\Factory as Transformer_Factory; -use ActivityPub_Event_Bridge\Plugins\Event_Plugin; -use ActivityPub_Event_Bridge\Setup; +use Event_Bridge_For_ActivityPub\Integrations\Event_Plugin; +use Event_Bridge_For_ActivityPub\Setup; use WP_Query; /** @@ -32,8 +32,8 @@ class Health_Check { * @return array The filtered test array. */ public static function add_tests( $tests ) { - $tests['direct']['activitypub_event_bridge_test'] = array( - 'label' => __( 'ActivityPub Event Transformer Test', 'activitypub-event-bridge' ), + $tests['direct']['event_bridge_for_activitypub_test'] = array( + 'label' => __( 'ActivityPub Event Transformer Test', 'event-bridge-for-activitypub' ), 'test' => array( self::class, 'test_event_transformation' ), ); @@ -47,15 +47,15 @@ class Health_Check { */ public static function test_event_transformation() { $result = array( - 'label' => \__( 'Transformation of Events to a valid ActivityStreams representation.', 'activitypub-event-bridge' ), + 'label' => \__( 'Transformation of Events to a valid ActivityStreams representation.', 'event-bridge-for-activitypub' ), 'status' => 'good', 'badge' => array( - 'label' => \__( 'ActivityPub Event Bridge', 'activitypub-event-bridge' ), + 'label' => \__( 'Event Bridge for ActivityPub', 'event-bridge-for-activitypub' ), 'color' => 'green', ), 'description' => \sprintf( '

%s

', - \__( 'The transformation of your most recent events was successful.', 'activitypub-event-bridge' ) + \__( 'The transformation of your most recent events was successful.', 'event-bridge-for-activitypub' ) ), 'actions' => '', 'test' => 'test_event_transformation', @@ -68,7 +68,7 @@ class Health_Check { } $result['status'] = 'critical'; - $result['label'] = \__( 'One or more of your most recent events failed to transform to ActivityPub', 'activitypub-event-bridge' ); + $result['label'] = \__( 'One or more of your most recent events failed to transform to ActivityPub', 'event-bridge-for-activitypub' ); $result['badge']['color'] = 'red'; $result['description'] = \sprintf( '

%s

', @@ -168,12 +168,12 @@ class Health_Check { * @return array The extended information. */ public static function add_debug_information( $info ) { - $info['activitypub_event_bridge'] = array( - 'label' => __( 'ActivityPub Event Bridge', 'activitypub-event-bridge' ), + $info['event_bridge_for_activitypub'] = array( + 'label' => __( 'Event Bridge for ActivityPub', 'event-bridge-for-activitypub' ), 'fields' => array( 'plugin_version' => array( - 'label' => __( 'Plugin Version', 'activitypub-event-bridge' ), - 'value' => ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_VERSION, + 'label' => __( 'Plugin Version', 'event-bridge-for-activitypub' ), + 'value' => EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_VERSION, 'private' => true, ), 'active_event_plugins' => self::get_info_about_active_event_plugins(), diff --git a/includes/admin/class-settings-page.php b/includes/admin/class-settings-page.php index b2dbb3e..3a3903f 100644 --- a/includes/admin/class-settings-page.php +++ b/includes/admin/class-settings-page.php @@ -3,32 +3,32 @@ * General settings class. * * This file contains the General class definition, which handles the "General" settings - * page for the Activitypub Event Bridge Plugin, providing options for configuring various general settings. + * page for the Event Bridge for ActivityPub Plugin, providing options for configuring various general settings. * - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 */ -namespace ActivityPub_Event_Bridge\Admin; +namespace Event_Bridge_For_ActivityPub\Admin; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore -use ActivityPub_Event_Bridge\Plugins\Event_Plugin; -use ActivityPub_Event_Bridge\Setup; +use Event_Bridge_For_ActivityPub\Integrations\Event_Plugin; +use Event_Bridge_For_ActivityPub\Setup; /** - * Class responsible for the Activitypub Event Bridge related Settings. + * Class responsible for the Event Bridge for ActivityPub related Settings. * - * Class which handles the "General" settings page for the Activitypub Event Bridge Plugin, + * Class which handles the "General" settings page for the Event Bridge for ActivityPub Plugin, * providing options for configuring various general settings. * * @since 1.0.0 */ class Settings_Page { - const STATIC = 'ActivityPub_Event_Bridge\Admin\Settings_Page'; + const STATIC = 'Event_Bridge_For_ActivityPub\Admin\Settings_Page'; - const SETTINGS_SLUG = 'activitypub-event-bridge'; + const SETTINGS_SLUG = 'event-bridge-for-activitypub'; /** * Warning if the plugin is Active and the ActivityPub plugin is not. * @@ -36,8 +36,8 @@ class Settings_Page { */ public static function admin_menu(): void { \add_options_page( - 'Activitypub Event Bridge', - __( 'ActivityPub Event Bridge', 'activitypub-event-bridge' ), + 'Event Bridge for ActivityPub', + __( 'Event Bridge for ActivityPub', 'event-bridge-for-activitypub' ), 'manage_options', self::SETTINGS_SLUG, array( self::STATIC, 'settings_page' ), @@ -114,7 +114,7 @@ class Settings_Page { 'event_terms' => $event_terms, ); - \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/settings.php', true, $args ); + \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php', true, $args ); break; case 'welcome': default: @@ -122,7 +122,7 @@ class Settings_Page { add_thickbox(); wp_enqueue_script( 'updates' ); - \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/welcome.php', true ); + \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php', true ); break; } } diff --git a/includes/class-autoloader.php b/includes/class-autoloader.php index e0315d8..40f99cd 100644 --- a/includes/class-autoloader.php +++ b/includes/class-autoloader.php @@ -1,17 +1,17 @@ 'string', - 'description' => \__( 'Define your own custom post template', 'activitypub-event-bridge' ), + 'description' => \__( 'Define your own custom post template', 'event-bridge-for-activitypub' ), 'show_in_rest' => true, 'default' => self::DEFAULT_EVENT_CATEGORY, 'sanitize_callback' => array( self::class, 'sanitize_mapped_event_category' ), @@ -52,22 +52,22 @@ class Settings { ); \register_setting( - 'activitypub-event-bridge', - 'activitypub_event_bridge_event_category_mappings', + 'event-bridge-for-activitypub', + 'event_bridge_for_activitypub_event_category_mappings', array( 'type' => 'array', - 'description' => \__( 'Define your own custom post template', 'activitypub-event-bridge' ), + 'description' => \__( 'Define your own custom post template', 'event-bridge-for-activitypub' ), 'default' => array(), 'sanitize_callback' => array( self::class, 'sanitize_event_category_mappings' ), ) ); \register_setting( - 'activitypub-event-bridge', - 'activitypub_event_bridge_initially_activated', + 'event-bridge-for-activitypub', + 'event_bridge_for_activitypub_initially_activated', array( 'type' => 'boolean', - 'description' => \__( 'Whether the plugin just got activated for the first time.', 'activitypub-event-bridge' ), + 'description' => \__( 'Whether the plugin just got activated for the first time.', 'event-bridge-for-activitypub' ), 'default' => 1, ) ); diff --git a/includes/class-setup.php b/includes/class-setup.php index 2912002..ce6afc4 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -1,32 +1,32 @@ activitypub_plugin_is_active ) { - // deactivate_plugins( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE ); + // deactivate_plugins( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ); // return; // }. $this->active_event_plugins = self::detect_active_event_plugins(); @@ -125,13 +125,15 @@ class Setup { * @var array */ private const EVENT_PLUGIN_CLASSES = array( - '\ActivityPub_Event_Bridge\Plugins\Events_Manager', - '\ActivityPub_Event_Bridge\Plugins\GatherPress', - '\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar', - '\ActivityPub_Event_Bridge\Plugins\VS_Event_List', - '\ActivityPub_Event_Bridge\Plugins\WP_Event_Manager', - '\ActivityPub_Event_Bridge\Plugins\Eventin', - '\ActivityPub_Event_Bridge\Plugins\Modern_Events_Calendar_Lite', + '\Event_Bridge_For_ActivityPub\Integrations\Events_Manager', + '\Event_Bridge_For_ActivityPub\Integrations\GatherPress', + '\Event_Bridge_For_ActivityPub\Integrations\The_Events_Calendar', + '\Event_Bridge_For_ActivityPub\Integrations\VS_Event_List', + '\Event_Bridge_For_ActivityPub\Integrations\WP_Event_Manager', + '\Event_Bridge_For_ActivityPub\Integrations\Eventin', + '\Event_Bridge_For_ActivityPub\Integrations\Modern_Events_Calendar_Lite', + '\Event_Bridge_For_ActivityPub\Integrations\EventPrime', + '\Event_Bridge_For_ActivityPub\Integrations\Event_Organiser', ); /** @@ -164,14 +166,14 @@ class Setup { * @return void */ protected function setup_hooks(): void { - register_activation_hook( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE, array( $this, 'activate' ) ); + register_activation_hook( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE, array( $this, 'activate' ) ); add_action( 'admin_init', array( $this, 'do_admin_notices' ) ); add_action( 'admin_init', array( Settings::class, 'register_settings' ) ); add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_styles' ) ); add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) ); add_filter( - 'plugin_action_links_' . ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_BASENAME, + 'plugin_action_links_' . EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_BASENAME, array( Settings_Page::class, 'settings_link' ) ); @@ -183,7 +185,7 @@ class Setup { add_action( 'init', array( Health_Check::class, 'init' ) ); // Check if the minimum required version of the ActivityPub plugin is installed. - if ( ! version_compare( $this->activitypub_plugin_version, ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) { + if ( ! version_compare( $this->activitypub_plugin_version, EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) { return; } @@ -198,24 +200,24 @@ class Setup { * @return void */ public static function enqueue_styles( $hook_suffix ): void { - if ( false !== strpos( $hook_suffix, 'activitypub-event-bridge' ) ) { + if ( false !== strpos( $hook_suffix, 'event-bridge-for-activitypub' ) ) { wp_enqueue_style( - 'activitypub-event-bridge-admin-styles', + 'event-bridge-for-activitypub-admin-styles', plugins_url( - 'assets/css/activitypub-event-bridge-admin.css', - ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE + 'assets/css/event-bridge-for-activitypub-admin.css', + EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ), array(), - ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_VERSION + EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_VERSION ); wp_enqueue_script( - 'activitypub-event-bridge-admin-script', + 'event-bridge-for-activitypub-admin-script', plugins_url( - 'assets/js/activitypub-event-bridge-admin.js', - ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE + 'assets/js/event-bridge-for-activitypub-admin.js', + EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), - ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_VERSION, + EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_VERSION, false ); } @@ -231,15 +233,15 @@ class Setup { // Check if any general admin notices are needed and add actions to insert the needed admin notices. if ( ! $this->activitypub_plugin_is_active ) { // The ActivityPub plugin is not active. - add_action( 'admin_notices', array( 'ActivityPub_Event_Bridge\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 ); + add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 ); } - if ( ! version_compare( $this->activitypub_plugin_version, ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) { + if ( ! version_compare( $this->activitypub_plugin_version, EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) { // The ActivityPub plugin is too old. - add_action( 'admin_notices', array( 'ActivityPub_Event_Bridge\Admin\General_Admin_Notices', 'activitypub_plugin_version_too_old' ), 10, 1 ); + add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'activitypub_plugin_version_too_old' ), 10, 1 ); } if ( empty( $this->active_event_plugins ) ) { // No supported Event Plugin is active. - add_action( 'admin_notices', array( 'ActivityPub_Event_Bridge\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 ); + add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 ); } } @@ -252,7 +254,7 @@ class Setup { * * @return \Activitypub\Transformer\Base|null */ - public function register_activitypub_event_transformer( $transformer, $wp_object, $object_class ): \Activitypub\Transformer\Base { + public function register_activitypub_event_transformer( $transformer, $wp_object, $object_class ): ?\Activitypub\Transformer\Base { // If the current WordPress object is not a post (e.g., a WP_Comment), don't change the transformer. if ( 'WP_Post' !== $object_class ) { return $transformer; @@ -292,9 +294,9 @@ class Setup { } /** - * Activates the ActivityPub Event Bridge plugin. + * Activates the Event Bridge for ActivityPub plugin. * - * This method handles the activation of the ActivityPub Event Bridge plugin. + * This method handles the activation of the Event Bridge for ActivityPub plugin. * * @since 1.0.0 * @see register_activation_hook() @@ -303,7 +305,7 @@ class Setup { public function activate(): void { // Don't allow plugin activation, when the ActivityPub plugin is not activated yet. if ( ! $this->activitypub_plugin_is_active ) { - deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE ) ); + deactivate_plugins( plugin_basename( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ) ); $notice = General_Admin_Notices::get_admin_notice_activitypub_plugin_not_enabled(); wp_die( wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ), @@ -313,7 +315,7 @@ class Setup { } if ( empty( $this->active_event_plugins ) ) { - deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE ) ); + deactivate_plugins( plugin_basename( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ) ); $notice = General_Admin_Notices::get_admin_notice_no_supported_event_plugin_active(); wp_die( wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ), diff --git a/includes/event-categories.php b/includes/event-categories.php index 6350a52..15fbdcf 100644 --- a/includes/event-categories.php +++ b/includes/event-categories.php @@ -2,46 +2,46 @@ /** * File responsible for defining the event category strings. * - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 * @license AGPL-3.0-or-later */ -namespace ActivityPub_Event_Bridge; +namespace Event_Bridge_For_ActivityPub; define( - 'ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES', + 'EVENT_BRIDGE_FOR_ACTIVITYPUB_EVENT_CATEGORIES', 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. + 'ARTS' => __( 'Arts', 'event-bridge-for-activitypub' ), + 'BOOK_CLUBS' => __( 'Book clubs', 'event-bridge-for-activitypub' ), + 'BUSINESS' => __( 'Business', 'event-bridge-for-activitypub' ), + 'CAUSES' => __( 'Causes', 'event-bridge-for-activitypub' ), + 'COMEDY' => __( 'Comedy', 'event-bridge-for-activitypub' ), + 'CRAFTS' => __( 'Crafts', 'event-bridge-for-activitypub' ), + 'FOOD_DRINK' => __( 'Food & Drink', 'event-bridge-for-activitypub' ), + 'HEALTH' => __( 'Health', 'event-bridge-for-activitypub' ), + 'MUSIC' => __( 'Music', 'event-bridge-for-activitypub' ), + 'AUTO_BOAT_AIR' => __( 'Auto, boat and air', 'event-bridge-for-activitypub' ), + 'COMMUNITY' => __( 'Community', 'event-bridge-for-activitypub' ), + 'FAMILY_EDUCATION' => __( 'Family & Education', 'event-bridge-for-activitypub' ), + 'FASHION_BEAUTY' => __( 'Fashion & Beauty', 'event-bridge-for-activitypub' ), + 'FILM_MEDIA' => __( 'Film & Media', 'event-bridge-for-activitypub' ), + 'GAMES' => __( 'Games', 'event-bridge-for-activitypub' ), + 'LANGUAGE_CULTURE' => __( 'Language & Culture', 'event-bridge-for-activitypub' ), + 'LEARNING' => __( 'Learning', 'event-bridge-for-activitypub' ), + 'LGBTQ' => __( 'LGBTQ', 'event-bridge-for-activitypub' ), + 'MOVEMENTS_POLITICS' => __( 'Movements and politics', 'event-bridge-for-activitypub' ), + 'NETWORKING' => __( 'Networking', 'event-bridge-for-activitypub' ), + 'PARTY' => __( 'Party', 'event-bridge-for-activitypub' ), + 'PERFORMING_VISUAL_ARTS' => __( 'Performing & Visual Arts', 'event-bridge-for-activitypub' ), + 'PETS' => __( 'Pets', 'event-bridge-for-activitypub' ), + 'PHOTOGRAPHY' => __( 'Photography', 'event-bridge-for-activitypub' ), + 'OUTDOORS_ADVENTURE' => __( 'Outdoors & Adventure', 'event-bridge-for-activitypub' ), + 'SPIRITUALITY_RELIGION_BELIEFS' => __( 'Spirituality, Religion & Beliefs', 'event-bridge-for-activitypub' ), + 'SCIENCE_TECH' => __( 'Science & Tech', 'event-bridge-for-activitypub' ), + 'SPORTS' => __( 'Sports', 'event-bridge-for-activitypub' ), + 'THEATRE' => __( 'Theatre', 'event-bridge-for-activitypub' ), + 'MEETING' => __( 'Meeting', 'event-bridge-for-activitypub' ), // Default value in federation. + 'DEFAULT' => __( 'Default', 'event-bridge-for-activitypub' ), // Internal default for overrides. ), ); diff --git a/includes/integrations/class-event-organiser.php b/includes/integrations/class-event-organiser.php new file mode 100644 index 0000000..9278f43 --- /dev/null +++ b/includes/integrations/class-event-organiser.php @@ -0,0 +1,69 @@ +post_content && '[em_events]' !== $queried_object->post_content ) { + return false; + } + } + + // Check if header already sent. + if ( ! \headers_sent() && ACTIVITYPUB_SEND_VARY_HEADER ) { + // Send Vary header for Accept header. + \header( 'Vary: Accept' ); + } + + // One can trigger an ActivityPub request by adding ?activitypub to the URL. + if ( isset( $wp_query->query_vars['activitypub'] ) ) { + return true; + } + + /* + * The other (more common) option to make an ActivityPub request + * is to send an Accept header. + */ + if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) { + $accept = sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT'] ) ); + + /* + * $accept can be a single value, or a comma separated list of values. + * We want to support both scenarios, + * and return true when the header includes at least one of the following: + * - application/activity+json + * - application/ld+json + * - application/json + */ + if ( preg_match( '/(application\/(ld\+json|activity\+json|json))/i', $accept ) ) { + return true; + } + } + + return false; + } + + /** + * Extract the post id of the event for an EventPrime event query. + * + * @return bool|int The post ID if an event could be identified, false otherwise. + */ + private static function get_eventprime_post_id() { + $event = get_query_var( 'event' ); + if ( ! $event ) { + if ( ! empty( filter_input( INPUT_GET, 'event', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ) ) { + $event = rtrim( filter_input( INPUT_GET, 'event', FILTER_SANITIZE_FULL_SPECIAL_CHARS ), '/\\' ); + } + } + + if ( $event ) { + $ep_basic_functions = new Eventprime_Basic_Functions(); + return $ep_basic_functions->ep_get_id_by_slug( $event, 'em_event' ); + } + + return false; + } + + /** + * Add the ActivityPub template for EventPrime. + * + * @param string $template The path to the template object. + * @return string The new path to the JSON template. + */ + public static function render_activitypub_template( $template ) { + if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + return $template; + } + + // Check if the request is a page with (solely) the eventprime shortcode in it. + if ( ! self::is_eventprime_activitypub_request() ) { + return $template; + } + + if ( ! \is_singular() ) { + return $template; + } + + $post_id = self::get_eventprime_post_id(); + + if ( $post_id ) { + $preview = \get_query_var( 'preview' ); + if ( $preview ) { + $activitypub_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/post-preview.php'; + } else { + $activitypub_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/post-json.php'; + } + } + + /* + * Check if the request is authorized. + * + * @see https://www.w3.org/wiki/SocialCG/ActivityPub/Primer/Authentication_Authorization#Authorized_fetch + * @see https://swicg.github.io/activitypub-http-signature/#authorized-fetch + */ + if ( $activitypub_template && ACTIVITYPUB_AUTHORIZED_FETCH ) { + $verification = Signature::verify_http_signature( $_SERVER ); + if ( \is_wp_error( $verification ) ) { + header( 'HTTP/1.1 401 Unauthorized' ); + + // Fallback as template_loader can't return http headers. + return $template; + } + } + + if ( $activitypub_template ) { + global $post; + + $post = get_post( $post_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + + // Ensure WordPress functions use the new post data. + setup_postdata( $post ); + // Return the default ActivityPub template. + return $activitypub_template; + } + + return $template; + } +} diff --git a/includes/plugins/class-events-manager.php b/includes/integrations/class-events-manager.php similarity index 93% rename from includes/plugins/class-events-manager.php rename to includes/integrations/class-events-manager.php index 02ca060..2f22620 100644 --- a/includes/plugins/class-events-manager.php +++ b/includes/integrations/class-events-manager.php @@ -5,11 +5,11 @@ * Defines all the necessary meta information for the Events Manager WordPress Plugin. * * @link https://wordpress.org/plugins/events-manager/ - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 */ -namespace ActivityPub_Event_Bridge\Plugins; +namespace Event_Bridge_For_ActivityPub\Integrations; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore diff --git a/includes/plugins/class-gatherpress.php b/includes/integrations/class-gatherpress.php similarity index 94% rename from includes/plugins/class-gatherpress.php rename to includes/integrations/class-gatherpress.php index 6c6af0f..57cd222 100644 --- a/includes/plugins/class-gatherpress.php +++ b/includes/integrations/class-gatherpress.php @@ -5,11 +5,11 @@ * Defines all the necessary meta information for the GatherPress plugin. * * @link https://wordpress.org/plugins/gatherpress/ - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 */ -namespace ActivityPub_Event_Bridge\Plugins; +namespace Event_Bridge_For_ActivityPub\Integrations; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore diff --git a/includes/plugins/class-modern-events-calendar-lite.php b/includes/integrations/class-modern-events-calendar-lite.php similarity index 93% rename from includes/plugins/class-modern-events-calendar-lite.php rename to includes/integrations/class-modern-events-calendar-lite.php index 45f060f..02329ae 100644 --- a/includes/plugins/class-modern-events-calendar-lite.php +++ b/includes/integrations/class-modern-events-calendar-lite.php @@ -5,11 +5,11 @@ * Defines all the necessary meta information for the Modern Events Calendar (Lite). * * @link https://webnus.net/modern-events-calendar/ - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 */ -namespace ActivityPub_Event_Bridge\Plugins; +namespace Event_Bridge_For_ActivityPub\Integrations; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore diff --git a/includes/plugins/class-the-events-calendar.php b/includes/integrations/class-the-events-calendar.php similarity index 94% rename from includes/plugins/class-the-events-calendar.php rename to includes/integrations/class-the-events-calendar.php index 36ab8e0..42d295e 100644 --- a/includes/plugins/class-the-events-calendar.php +++ b/includes/integrations/class-the-events-calendar.php @@ -5,11 +5,11 @@ * Defines all the necessary meta information for the events calendar. * * @link https://wordpress.org/plugins/the-events-calendar/ - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 */ -namespace ActivityPub_Event_Bridge\Plugins; +namespace Event_Bridge_For_ActivityPub\Integrations; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore diff --git a/includes/plugins/class-vs-event-list.php b/includes/integrations/class-vs-event-list.php similarity index 90% rename from includes/plugins/class-vs-event-list.php rename to includes/integrations/class-vs-event-list.php index f1bd96b..6ce4ba6 100644 --- a/includes/plugins/class-vs-event-list.php +++ b/includes/integrations/class-vs-event-list.php @@ -6,13 +6,13 @@ * "Very Simple Events List". * * @link https://de.wordpress.org/plugins/very-simple-event-list/ - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 */ -namespace ActivityPub_Event_Bridge\Plugins; +namespace Event_Bridge_For_ActivityPub\Integrations; -use ActivityPub_Event_Bridge\Event_Plugins; +use Event_Bridge_For_ActivityPub\Event_Plugins; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore diff --git a/includes/plugins/class-wp-event-manager.php b/includes/integrations/class-wp-event-manager.php similarity index 90% rename from includes/plugins/class-wp-event-manager.php rename to includes/integrations/class-wp-event-manager.php index 28a852a..18c217d 100644 --- a/includes/plugins/class-wp-event-manager.php +++ b/includes/integrations/class-wp-event-manager.php @@ -6,13 +6,13 @@ * "WP Event Manager" * * @link https://de.wordpress.org/plugins/wp-event-manager - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub * @since 1.0.0 */ -namespace ActivityPub_Event_Bridge\Plugins; +namespace Event_Bridge_For_ActivityPub\Integrations; -use ActivityPub_Event_Bridge\Plugins\Event_Plugin; +use Event_Bridge_For_ActivityPub\Integrations\Event_Plugin; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore diff --git a/package.json b/package.json index 4db7d96..68b7757 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "activitypub-event-bridge", + "name": "event-bridge-for-activitypub", "version": "0.1.0", "author": { "name": "AndrΓ© Menrath", @@ -15,7 +15,7 @@ }, "license": "AGPL-3.0", "bugs": { - "url": "https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues" + "url": "https://code.event-federation.eu/Event-Federation/wordpress-event-bridge-for-activitypub/issues" }, "devDependencies": { "@wordpress/env": "^10.10.0", diff --git a/phpcs.xml b/phpcs.xml index e1ef42c..7839664 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -108,7 +108,7 @@ - + @@ -117,7 +117,7 @@ - + diff --git a/readme.txt b/readme.txt index 66ef1b9..3386f69 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ -=== ActivityPub Event Bridge === +=== Event Bridge for ActivityPub === Contributors: andremenrath Tags: events, fediverse, activitypub, calendar Requires at least: 6.5 Tested up to: 6.7 -Stable tag: 0.2.1 +Stable tag: 0.3.1 Requires PHP: 7.4 License: AGPL-3.0-or-later License URI: https://www.gnu.org/licenses/agpl-3.0.html @@ -12,7 +12,7 @@ Integrating popular event plugins with the ActivityPub plugin. == Description == Make your events more discoverable, expand your reach effortlessly while being independent of other (commercial) platforms, and be a part of the growing decentralized web (the Fediverse). -With the ActivityPub Event Bridge Plugin for WordPress, your events can be automatically followed, aggregated and displayed across decentralized platforms like [Mastodon](https://joinmastodon.org) or [Gancio](https://gancio.org), without any extra work. +With the Event Bridge for ActivityPub Plugin for WordPress, your events can be automatically followed, aggregated and displayed across decentralized platforms like [Mastodon](https://joinmastodon.org) or [Gancio](https://gancio.org), without any extra work. Forget the hassle of managing multiple social media accounts just to keep your audience informed. This plugin is not an event managing plugin but an add-on to popular event plugins. It extends their functionality to fully support the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/). @@ -21,7 +21,7 @@ You retain full ownership of your content. By integrating into your existing set = How It Works = -With the ActivityPub Event Bridge WordPress plugin, sharing your events is effortless and automatic! +With the Event Bridge for ActivityPub WordPress plugin, sharing your events is effortless and automatic! Once you create an event on your WordPress site, it is seamlessly shared across the decentralized web using the ActivityPub protocol. ![](./.wordpress-org/event-activitypub-publishing.gif) @@ -57,6 +57,8 @@ This plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/ac * [Eventin](https://de.wordpress.org/plugins/wp-event-solution/) * [Modern Events Calendar Lite](https://webnus.net/modern-events-calendar/) * [GatherPress](https://gatherpress.org/) +* [EventPrime – Events Calendar, Bookings and Tickets](https://wordpress.org/plugins/eventprime-event-calendar-management/) +* [Event Organiser](https://wordpress.org/plugins/event-organiser/) == Configuration == @@ -86,18 +88,14 @@ No, the Event Federation Plugin depends on the [ActivityPub plugin](https://word = My event plugin is not supported, what can I do? = -If you know about coding have a look at the documentation of how to add your plugin or open an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues), if we can spare some free hours we might add it. +If you know about coding have a look at the documentation of how to add your plugin or open an [issue](https://code.event-federation.eu/Event-Federation/wordpress-event-bridge-for-activitypub/issues), if we can spare some free hours we might add it. = What if I experience problems? = -We're always interested in your feedback. Feel free to reach out to us via [E-Mail](https://event-federation.eu/contact/) or create an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues). +We're always interested in your feedback. Feel free to reach out to us via [E-Mail](https://event-federation.eu/contact/) or create an [issue](https://code.event-federation.eu/Event-Federation/wordpress-event-bridge-for-activitypub/issues). == Changelog == -= [0.2.1] 2024-11-16 = += [0.3.1] 2024-12-05 = * Initial release on https://wordpress.org/ - -= [0.2.0] 2024-10-29 = - -* Initial submission to https://wordpress.org/ diff --git a/templates/admin-header.php b/templates/admin-header.php index 4ee283b..4c84ff2 100644 --- a/templates/admin-header.php +++ b/templates/admin-header.php @@ -2,7 +2,7 @@ /** * Template for the header and navigation of the admin pages. * - * @package ActivityPub_Event_Bridge + * @package Event_Bridge_For_ActivityPub */ // Exit if accessed directly. @@ -18,18 +18,18 @@ $args = wp_parse_args( ); ?> -
-
-

+ diff --git a/templates/settings.php b/templates/settings.php index e9390d1..f3b7641 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -1,10 +1,10 @@ -
+
- +
-

-

+

+

- +
[ap_start_time]
-
+
[ap_end_time]
-
+
[ap_location]
-
+
[ap_hashtags]
-
+
[ap_excerpt]
-
+
[ap_content]
-
+
@@ -90,15 +90,15 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
-

-

+

+

- +
- '; $label ) { + foreach ( EVENT_BRIDGE_FOR_ACTIVITYPUB_EVENT_CATEGORIES as $value => $label ) { echo ''; } ?> @@ -108,14 +108,14 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
-

-

+

+

name ); ?> - -- ' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $mapping ] ) . ' -- '; + echo ''; } else { - echo ''; + echo ''; } - echo ''; + echo ''; foreach ( Event::DEFAULT_EVENT_CATEGORIES as $event_category ) { - echo ''; + echo ''; } ?> @@ -145,7 +145,7 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_ diff --git a/templates/welcome.php b/templates/welcome.php index cb63f5c..503df4f 100644 --- a/templates/welcome.php +++ b/templates/welcome.php @@ -1,16 +1,16 @@ get_active_event_plugins(); -$activitypub_event_bridge_status_ok = true; -$example_event_post = Health_Check::get_most_recent_event_posts(); +$active_event_plugins = Setup::get_instance()->get_active_event_plugins(); +$event_bridge_for_activitypub_status_ok = true; +$example_event_post = Health_Check::get_most_recent_event_posts(); if ( empty( $example_event_post ) ) { $example_event_post = 'https://yoursite.com/events/event-name'; @@ -37,13 +37,13 @@ WP_Filesystem(); ?> -
+
-

-

+

+

get_plugin_name() ); ?>:

-
    +
    • %2$s is enabled in the %1$s settings.', 'admin notice', - 'activitypub-event-bridge' + 'event-bridge-for-activitypub' ), esc_html( get_plugin_data( ACTIVITYPUB_PLUGIN_FILE )['Name'] ), esc_html( $active_event_plugin->get_plugin_name() ), admin_url( 'options-general.php?page=activitypub&tab=settings' ) ); } else { - $activitypub_event_bridge_status_ok = false; + $event_bridge_for_activitypub_status_ok = false; echo '❌ '; $status_message_post_type_enabled = sprintf( /* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */ _x( 'The post type for events of the plugin %2$s is not enabled in the %1$s settings.', 'admin notice', - 'activitypub-event-bridge' + 'event-bridge-for-activitypub' ), esc_html( get_plugin_data( ACTIVITYPUB_PLUGIN_FILE )['Name'] ), esc_html( $active_event_plugin->get_plugin_name() ), @@ -89,11 +89,11 @@ WP_Filesystem();
    • @@ -101,95 +101,95 @@ WP_Filesystem();
- +
-

+

' . \esc_html__( 'Please fix the status issues above first.', 'activitypub-event-bridge' ) . '

'; + if ( ! $event_bridge_for_activitypub_status_ok ) { + echo '

' . \esc_html__( 'Please fix the status issues above first.', 'event-bridge-for-activitypub' ) . '

'; } ?> -

-
-

-

-