diff --git a/includes/activitypub/transmogrify/class-gatherpress.php b/includes/activitypub/transmogrify/class-gatherpress.php new file mode 100644 index 0000000..b94efb5 --- /dev/null +++ b/includes/activitypub/transmogrify/class-gatherpress.php @@ -0,0 +1,61 @@ +activitypub_event = $activitypub_event; + } + + /** + * Save the ActivityPub event object as GatherPress Event. + */ + public function save() { + // Insert GatherPress Event here. + } +} diff --git a/includes/admin/class-settings-page.php b/includes/admin/class-settings-page.php index c49602b..2ad8999 100644 --- a/includes/admin/class-settings-page.php +++ b/includes/admin/class-settings-page.php @@ -162,12 +162,11 @@ class Settings_Page { $tab = sanitize_key( $_GET['tab'] ); } + $plugin_setup = Setup::get_instance(); + $event_plugins = $plugin_setup->get_active_event_plugins(); + switch ( $tab ) { case 'settings': - $plugin_setup = Setup::get_instance(); - - $event_plugins = $plugin_setup->get_active_event_plugins(); - $event_terms = array(); foreach ( $event_plugins as $event_plugin ) { @@ -182,9 +181,20 @@ class Settings_Page { \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php', true, $args ); break; case 'event-sources': + $supports_event_sources = array(); + + foreach ( $event_plugins as $event_plugin ) { + if ( $event_plugin->supports_event_sources() ) { + $supports_event_sources[ $event_plugin::class ] = $event_plugin->get_plugin_name(); + } + } + $args = array( + 'supports_event_sources' => $supports_event_sources, + ); + wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 'thickbox' ); - \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/event-sources.php', true ); + \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/event-sources.php', true, $args ); break; case 'welcome': default: diff --git a/includes/class-settings.php b/includes/class-settings.php index b895e2a..c74dddc 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -103,6 +103,42 @@ class Settings { 'default' => 1, ) ); + + \register_setting( + 'event-bridge-for-activitypub', + 'event_bridge_for_activitypub_plugin_used_for_event_source_feature', + array( + 'type' => 'array', + 'description' => \__( 'Define which plugin/integration is used for the event sources feature', 'event-bridge-for-activitypub' ), + 'default' => array(), + 'sanitize_callback' => array( self::class, 'sanitize_plugin_used_for_event_sources' ), + ) + ); + } + + /** + * Sanitize the option which event plugin. + * + * @param string $plugin The setting. + * @return string + */ + public static function sanitize_plugin_used_for_event_sources( $plugin ) { + if ( ! is_string( $plugin ) ) { + return ''; + } + $setup = Setup::get_instance(); + $active_event_plugins = $setup->get_active_event_plugins(); + + $valid_options = array(); + foreach ( $active_event_plugins as $active_event_plugin ) { + if ( $active_event_plugin->supports_event_sources() ) { + $valid_options[] = $active_event_plugin::class; + } + } + if ( in_array( $plugin, $valid_options, true ) ) { + return $plugin; + } + return ''; } /** diff --git a/includes/class-setup.php b/includes/class-setup.php index 49ac81c..68f2f49 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -179,8 +179,6 @@ class Setup { array( Settings_Page::class, 'settings_link' ) ); - add_action( 'activitypub_register_handlers', array( Handler::class, 'register_activitypub_handlers' ) ); - // If we don't have any active event plugins, or the ActivityPub plugin is not enabled, abort here. if ( empty( $this->active_event_plugins ) || ! $this->activitypub_plugin_is_active ) { return; diff --git a/includes/integrations/class-event-plugin.php b/includes/integrations/class-event-plugin.php index aba3d22..756926f 100644 --- a/includes/integrations/class-event-plugin.php +++ b/includes/integrations/class-event-plugin.php @@ -54,6 +54,15 @@ abstract class Event_Plugin { return array(); } + /** + * By default event sources are not supported by an event plugin integration. + * + * @return bool True if event sources are supported. + */ + public static function supports_event_sources(): bool { + return false; + } + /** * Get the plugins name from the main plugin-file's top-level-file-comment. */ diff --git a/includes/integrations/class-gatherpress.php b/includes/integrations/class-gatherpress.php index 57cd222..0efb319 100644 --- a/includes/integrations/class-gatherpress.php +++ b/includes/integrations/class-gatherpress.php @@ -66,4 +66,13 @@ final class GatherPress extends Event_Plugin { public static function get_event_category_taxonomy(): string { return class_exists( '\GatherPress\Core\Topic' ) ? \GatherPress\Core\Topic::TAXONOMY : 'gatherpress_topic'; } + + /** + * GatherPress supports the Event Sources feature. + * + * @return bool True if event sources are supported. + */ + public static function supports_event_sources(): bool { + return true; + } } diff --git a/templates/event-sources.php b/templates/event-sources.php index 47e2f22..cdfe441 100644 --- a/templates/event-sources.php +++ b/templates/event-sources.php @@ -18,12 +18,19 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore ) ); +if ( ! isset( $args ) || ! array_key_exists( 'supports_event_sources', $args ) ) { + return; +} + +if ( ! current_user_can( 'manage_options' ) ) { + return; +} $table = new \Event_Bridge_For_ActivityPub\Table\Event_Sources(); ?>
- +