add draft for allowing settings for which plugin integration is used for events sources
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 46s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m3s

This commit is contained in:
André Menrath 2024-12-08 22:36:40 +01:00
parent 189e7b5f9f
commit 210bf9cc96
7 changed files with 138 additions and 8 deletions

View file

@ -0,0 +1,61 @@
<?php
/**
* ActivityPub Transmogrify for the GatherPress event plugin.
*
* Handles converting incoming external ActivityPub events to GatherPress Events.
*
* @package Event_Bridge_For_ActivityPub
* @since 1.0.0
* @license AGPL-3.0-or-later
*/
namespace Event_Bridge_For_ActivityPub\Activitypub\Transmogrify;
use Activitypub\Activity\Extended_Object\Event;
use Activitypub\Activity\Extended_Object\Place;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use GatherPress\Core\Event as GatherPress_Event;
/**
* ActivityPub Transmogrify for the GatherPress event plugin.
*
* Handles converting incoming external ActivityPub events to GatherPress Events.
*
* @since 1.0.0
*/
class GatherPress {
/**
* The current GatherPress Event object.
*
* @var Event
*/
protected $activitypub_event;
/**
* Extend the constructor, to also set the GatherPress objects.
*
* This is a special class object form The Events Calendar which
* has a lot of useful functions, we make use of our getter functions.
*
* @param array $activitypub_event The ActivityPub Event as associative array.
*/
public function __construct( $activitypub_event ) {
$activitypub_event = Event::init_from_array( $activitypub_event );
if ( is_wp_error( $activitypub_event ) ) {
return;
}
$this->activitypub_event = $activitypub_event;
}
/**
* Save the ActivityPub event object as GatherPress Event.
*/
public function save() {
// Insert GatherPress Event here.
}
}

View file

@ -162,12 +162,11 @@ class Settings_Page {
$tab = sanitize_key( $_GET['tab'] ); $tab = sanitize_key( $_GET['tab'] );
} }
switch ( $tab ) {
case 'settings':
$plugin_setup = Setup::get_instance(); $plugin_setup = Setup::get_instance();
$event_plugins = $plugin_setup->get_active_event_plugins(); $event_plugins = $plugin_setup->get_active_event_plugins();
switch ( $tab ) {
case 'settings':
$event_terms = array(); $event_terms = array();
foreach ( $event_plugins as $event_plugin ) { 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 ); \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php', true, $args );
break; break;
case 'event-sources': 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_script( 'thickbox' );
wp_enqueue_style( '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; break;
case 'welcome': case 'welcome':
default: default:

View file

@ -103,6 +103,42 @@ class Settings {
'default' => 1, '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 '';
} }
/** /**

View file

@ -179,8 +179,6 @@ class Setup {
array( Settings_Page::class, 'settings_link' ) 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 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 ) { if ( empty( $this->active_event_plugins ) || ! $this->activitypub_plugin_is_active ) {
return; return;

View file

@ -54,6 +54,15 @@ abstract class Event_Plugin {
return array(); 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. * Get the plugins name from the main plugin-file's top-level-file-comment.
*/ */

View file

@ -66,4 +66,13 @@ final class GatherPress extends Event_Plugin {
public static function get_event_category_taxonomy(): string { public static function get_event_category_taxonomy(): string {
return class_exists( '\GatherPress\Core\Topic' ) ? \GatherPress\Core\Topic::TAXONOMY : 'gatherpress_topic'; 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;
}
} }

View file

@ -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(); $table = new \Event_Bridge_For_ActivityPub\Table\Event_Sources();
?> ?>
<div class="event-bridge-for-activitypub-settings event-bridge-for-activitypub-settings-page hide-if-no-js"> <div class="event-bridge-for-activitypub-settings event-bridge-for-activitypub-settings-page hide-if-no-js">
<?php var_dump( $args['supports_event_sources'] ); ?>
<div class="box"> <div class="box">
<h2> <?php esc_html_e( 'Federated event sources', 'event-bridge-for-activitypub' ); ?> </h2> <h2> <?php esc_html_e( 'Federated event sources', 'event-bridge-for-activitypub' ); ?> </h2>
<p> <?php esc_html_e( 'Here you can add any Fediverse Account.', 'event-bridge-for-activitypub' ); ?> </p> <p> <?php esc_html_e( 'Here you can add any Fediverse Account.', 'event-bridge-for-activitypub' ); ?> </p>