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
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:
parent
189e7b5f9f
commit
210bf9cc96
7 changed files with 138 additions and 8 deletions
61
includes/activitypub/transmogrify/class-gatherpress.php
Normal file
61
includes/activitypub/transmogrify/class-gatherpress.php
Normal 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.
|
||||
}
|
||||
}
|
|
@ -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:
|
||||
|
|
|
@ -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 '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
?>
|
||||
|
||||
<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">
|
||||
<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>
|
||||
|
|
Loading…
Reference in a new issue